summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cgroup-v2.txt11
-rw-r--r--Documentation/devicetree/bindings/powerpc/4xx/emac.txt62
-rw-r--r--Documentation/networking/ip-sysctl.txt3
-rw-r--r--arch/powerpc/boot/zImage.lds.S1
-rw-r--r--arch/powerpc/crypto/crc32c-vpmsum_glue.c2
-rw-r--r--arch/powerpc/include/asm/bitops.h4
-rw-r--r--arch/powerpc/include/asm/mce.h108
-rw-r--r--arch/powerpc/kernel/cputable.c3
-rw-r--r--arch/powerpc/kernel/mce.c88
-rw-r--r--arch/powerpc/kernel/mce_power.c237
-rw-r--r--arch/powerpc/perf/core-book3s.c2
-rw-r--r--arch/powerpc/perf/isa207-common.c43
-rw-r--r--arch/powerpc/perf/isa207-common.h1
-rw-r--r--arch/powerpc/platforms/powernv/opal.c21
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c20
-rw-r--r--block/bio.c12
-rw-r--r--block/blk-core.c30
-rw-r--r--block/blk-mq-tag.c3
-rw-r--r--block/blk-mq.c9
-rw-r--r--crypto/af_alg.c9
-rw-r--r--crypto/algif_hash.c9
-rw-r--r--drivers/ata/ahci_qoriq.c6
-rw-r--r--drivers/ata/libata-sff.c1
-rw-r--r--drivers/ata/libata-transport.c9
-rw-r--r--drivers/char/hw_random/omap-rng.c16
-rw-r--r--drivers/crypto/s5p-sss.c132
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c3
-rw-r--r--drivers/macintosh/macio_asic.c1
-rw-r--r--drivers/md/dm.c29
-rw-r--r--drivers/md/raid10.c3
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-drv.c10
-rw-r--r--drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c36
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c24
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h1
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c40
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c25
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.h1
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c2
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.c206
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.h16
-rw-r--r--drivers/net/ethernet/cavium/liquidio/lio_main.c110
-rw-r--r--drivers/net/ethernet/cavium/liquidio/lio_vf_main.c104
-rw-r--r--drivers/net/ethernet/cavium/liquidio/octeon_config.h6
-rw-r--r--drivers/net/ethernet/cavium/liquidio/octeon_droq.c17
-rw-r--r--drivers/net/ethernet/cavium/liquidio/octeon_droq.h4
-rw-r--r--drivers/net/ethernet/cavium/liquidio/octeon_main.h42
-rw-r--r--drivers/net/ethernet/cavium/liquidio/octeon_network.h43
-rw-r--r--drivers/net/ethernet/cavium/thunder/nic.h1
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_main.c12
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.c184
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.h4
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.c64
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.h1
-rw-r--r--drivers/net/ethernet/ibm/emac/core.c25
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c43
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.h1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/Kconfig1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c33
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_core.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/reg.h4
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c4
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_cxt.c3
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_dev.c5
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_iscsi.c31
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_ll2.c13
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_ooo.c2
-rw-r--r--drivers/net/ethernet/smsc/smc91x.c47
-rw-r--r--drivers/net/hyperv/hyperv_net.h3
-rw-r--r--drivers/net/hyperv/netvsc.c8
-rw-r--r--drivers/net/hyperv/netvsc_drv.c11
-rw-r--r--drivers/net/phy/marvell.c15
-rw-r--r--drivers/net/phy/phy_device.c2
-rw-r--r--drivers/net/phy/spi_ks8995.c3
-rw-r--r--drivers/net/team/team.c1
-rw-r--r--drivers/net/tun.c19
-rw-r--r--drivers/net/vrf.c3
-rw-r--r--drivers/net/vxlan.c73
-rw-r--r--drivers/net/wan/fsl_ucc_hdlc.c4
-rw-r--r--drivers/net/wimax/i2400m/usb.c3
-rw-r--r--drivers/net/xen-netback/interface.c26
-rw-r--r--drivers/net/xen-netback/netback.c2
-rw-r--r--drivers/net/xen-netback/xenbus.c20
-rw-r--r--drivers/platform/x86/asus-nb-wmi.c49
-rw-r--r--drivers/platform/x86/asus-wmi.c22
-rw-r--r--drivers/platform/x86/asus-wmi.h1
-rw-r--r--drivers/platform/x86/fujitsu-laptop.c451
-rw-r--r--drivers/scsi/Kconfig19
-rw-r--r--drivers/scsi/aacraid/src.c2
-rw-r--r--drivers/scsi/libiscsi.c26
-rw-r--r--drivers/scsi/lpfc/lpfc.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c9
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.c22
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c22
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c24
-rw-r--r--drivers/scsi/lpfc/lpfc_hw4.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c128
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_nvme.c107
-rw-r--r--drivers/scsi/lpfc/lpfc_nvme.h1
-rw-r--r--drivers/scsi/lpfc/lpfc_nvmet.c43
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c4
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c68
-rw-r--r--drivers/scsi/lpfc/lpfc_sli4.h6
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_base.h3
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c19
-rw-r--r--drivers/scsi/qedf/qedf_dbg.h13
-rw-r--r--drivers/scsi/qedf/qedf_fip.c2
-rw-r--r--drivers/scsi/qedf/qedf_io.c4
-rw-r--r--drivers/scsi/qedf/qedf_main.c4
-rw-r--r--drivers/scsi/qedi/qedi_debugfs.c16
-rw-r--r--drivers/scsi/qedi/qedi_fw.c4
-rw-r--r--drivers/scsi/qedi/qedi_gbl.h8
-rw-r--r--drivers/scsi/qedi/qedi_iscsi.c8
-rw-r--r--drivers/scsi/qedi/qedi_main.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.c12
-rw-r--r--drivers/scsi/scsi_lib.c14
-rw-r--r--drivers/scsi/scsi_priv.h3
-rw-r--r--drivers/scsi/sd.c17
-rw-r--r--drivers/scsi/storvsc_drv.c27
-rw-r--r--drivers/scsi/ufs/ufs.h22
-rw-r--r--drivers/scsi/ufs/ufshcd.c231
-rw-r--r--drivers/scsi/ufs/ufshcd.h15
-rw-r--r--drivers/scsi/vmw_pvscsi.c2
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-socket.c4
-rw-r--r--fs/dlm/lowcomms.c2
-rw-r--r--fs/fs-writeback.c35
-rw-r--r--fs/gfs2/incore.h2
-rw-r--r--fs/ocfs2/cluster/tcp.c2
-rw-r--r--include/crypto/if_alg.h2
-rw-r--r--include/linux/dccp.h1
-rw-r--r--include/linux/filter.h16
-rw-r--r--include/linux/list_nulls.h5
-rw-r--r--include/linux/net.h2
-rw-r--r--include/linux/phy.h4
-rw-r--r--include/linux/rculist_nulls.h14
-rw-r--r--include/net/inet_common.h3
-rw-r--r--include/net/inet_connection_sock.h2
-rw-r--r--include/net/sctp/structs.h3
-rw-r--r--include/net/sock.h9
-rw-r--r--include/scsi/libiscsi.h1
-rw-r--r--include/scsi/scsi_device.h4
-rw-r--r--include/uapi/linux/packet_diag.h2
-rw-r--r--kernel/bpf/hashtab.c119
-rw-r--r--kernel/bpf/lpm_trie.c6
-rw-r--r--kernel/cgroup/cgroup-v1.c2
-rw-r--r--kernel/cgroup/pids.c2
-rw-r--r--kernel/sched/core.c201
-rw-r--r--kernel/sched/deadline.c63
-rw-r--r--kernel/sched/fair.c385
-rw-r--r--kernel/sched/features.h7
-rw-r--r--kernel/sched/loadavg.c20
-rw-r--r--kernel/sched/rt.c81
-rw-r--r--kernel/sched/sched.h65
-rw-r--r--kernel/workqueue.c1
-rw-r--r--mm/gup.c2
-rw-r--r--mm/percpu-vm.c7
-rw-r--r--mm/percpu.c5
-rw-r--r--net/atm/svc.c5
-rw-r--r--net/ax25/af_ax25.c3
-rw-r--r--net/bluetooth/l2cap_sock.c2
-rw-r--r--net/bluetooth/rfcomm/sock.c3
-rw-r--r--net/bluetooth/sco.c2
-rw-r--r--net/bridge/br_input.c1
-rw-r--r--net/bridge/br_netfilter_hooks.c21
-rw-r--r--net/core/dev.c1
-rw-r--r--net/core/net-sysfs.c6
-rw-r--r--net/core/skbuff.c30
-rw-r--r--net/core/sock.c106
-rw-r--r--net/dccp/ccids/ccid2.c1
-rw-r--r--net/dccp/ipv4.c3
-rw-r--r--net/dccp/ipv6.c8
-rw-r--r--net/dccp/minisocks.c24
-rw-r--r--net/decnet/af_decnet.c5
-rw-r--r--net/ipv4/af_inet.c9
-rw-r--r--net/ipv4/inet_connection_sock.c2
-rw-r--r--net/ipv4/ip_output.c2
-rw-r--r--net/ipv4/tcp_ipv4.c10
-rw-r--r--net/ipv4/tcp_timer.c6
-rw-r--r--net/ipv6/af_inet6.c10
-rw-r--r--net/ipv6/ip6_fib.c2
-rw-r--r--net/ipv6/ip6_offload.c4
-rw-r--r--net/ipv6/ip6_output.c9
-rw-r--r--net/ipv6/ip6_vti.c8
-rw-r--r--net/ipv6/route.c11
-rw-r--r--net/ipv6/tcp_ipv6.c8
-rw-r--r--net/irda/af_irda.c5
-rw-r--r--net/iucv/af_iucv.c2
-rw-r--r--net/llc/af_llc.c4
-rw-r--r--net/mpls/af_mpls.c4
-rw-r--r--net/netrom/af_netrom.c3
-rw-r--r--net/nfc/llcp_sock.c2
-rw-r--r--net/phonet/pep.c6
-rw-r--r--net/phonet/socket.c4
-rw-r--r--net/rds/connection.c1
-rw-r--r--net/rds/ib_cm.c47
-rw-r--r--net/rds/rds.h6
-rw-r--r--net/rds/tcp.c38
-rw-r--r--net/rds/tcp.h2
-rw-r--r--net/rds/tcp_listen.c11
-rw-r--r--net/rose/af_rose.c3
-rw-r--r--net/rxrpc/input.c27
-rw-r--r--net/rxrpc/recvmsg.c4
-rw-r--r--net/rxrpc/sendmsg.c49
-rw-r--r--net/sched/act_connmark.c3
-rw-r--r--net/sched/act_skbmod.c1
-rw-r--r--net/sctp/ipv6.c5
-rw-r--r--net/sctp/protocol.c5
-rw-r--r--net/sctp/socket.c4
-rw-r--r--net/smc/af_smc.c2
-rw-r--r--net/socket.c5
-rw-r--r--net/tipc/socket.c8
-rw-r--r--net/unix/af_unix.c5
-rw-r--r--net/vmw_vsock/af_vsock.c3
-rw-r--r--net/x25/af_x25.c3
-rw-r--r--net/xfrm/xfrm_policy.c19
-rw-r--r--tools/include/uapi/linux/bpf_perf_event.h18
-rw-r--r--tools/testing/selftests/bpf/Makefile4
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c4
-rw-r--r--tools/testing/selftests/powerpc/include/vsx_asm.h48
226 files changed, 3614 insertions, 1830 deletions
diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
index 3b8449f8ac7e..49d7c997fa1e 100644
--- a/Documentation/cgroup-v2.txt
+++ b/Documentation/cgroup-v2.txt
@@ -1142,16 +1142,17 @@ used by the kernel.
1142 1142
1143 pids.max 1143 pids.max
1144 1144
1145 A read-write single value file which exists on non-root cgroups. The 1145 A read-write single value file which exists on non-root
1146 default is "max". 1146 cgroups. The default is "max".
1147 1147
1148 Hard limit of number of processes. 1148 Hard limit of number of processes.
1149 1149
1150 pids.current 1150 pids.current
1151 1151
1152 A read-only single value file which exists on all cgroups. 1152 A read-only single value file which exists on all cgroups.
1153 1153
1154 The number of processes currently in the cgroup and its descendants. 1154 The number of processes currently in the cgroup and its
1155 descendants.
1155 1156
1156Organisational operations are not blocked by cgroup policies, so it is 1157Organisational operations are not blocked by cgroup policies, so it is
1157possible to have pids.current > pids.max. This can be done by either 1158possible to have pids.current > pids.max. This can be done by either
diff --git a/Documentation/devicetree/bindings/powerpc/4xx/emac.txt b/Documentation/devicetree/bindings/powerpc/4xx/emac.txt
index 712baf6c3e24..44b842b6ca15 100644
--- a/Documentation/devicetree/bindings/powerpc/4xx/emac.txt
+++ b/Documentation/devicetree/bindings/powerpc/4xx/emac.txt
@@ -71,6 +71,9 @@
71 For Axon it can be absent, though my current driver 71 For Axon it can be absent, though my current driver
72 doesn't handle phy-address yet so for now, keep 72 doesn't handle phy-address yet so for now, keep
73 0x00ffffff in it. 73 0x00ffffff in it.
74 - phy-handle : Used to describe configurations where a external PHY
75 is used. Please refer to:
76 Documentation/devicetree/bindings/net/ethernet.txt
74 - rx-fifo-size-gige : 1 cell, Rx fifo size in bytes for 1000 Mb/sec 77 - rx-fifo-size-gige : 1 cell, Rx fifo size in bytes for 1000 Mb/sec
75 operations (if absent the value is the same as 78 operations (if absent the value is the same as
76 rx-fifo-size). For Axon, either absent or 2048. 79 rx-fifo-size). For Axon, either absent or 2048.
@@ -81,8 +84,22 @@
81 offload, phandle of the TAH device node. 84 offload, phandle of the TAH device node.
82 - tah-channel : 1 cell, optional. If appropriate, channel used on the 85 - tah-channel : 1 cell, optional. If appropriate, channel used on the
83 TAH engine. 86 TAH engine.
87 - fixed-link : Fixed-link subnode describing a link to a non-MDIO
88 managed entity. See
89 Documentation/devicetree/bindings/net/fixed-link.txt
90 for details.
91 - mdio subnode : When the EMAC has a phy connected to its local
92 mdio, which us supported by the kernel's network
93 PHY library in drivers/net/phy, there must be device
94 tree subnode with the following required properties:
95 - #address-cells: Must be <1>.
96 - #size-cells: Must be <0>.
84 97
85 Example: 98 For PHY definitions: Please refer to
99 Documentation/devicetree/bindings/net/phy.txt and
100 Documentation/devicetree/bindings/net/ethernet.txt
101
102 Examples:
86 103
87 EMAC0: ethernet@40000800 { 104 EMAC0: ethernet@40000800 {
88 device_type = "network"; 105 device_type = "network";
@@ -104,6 +121,48 @@
104 zmii-channel = <0>; 121 zmii-channel = <0>;
105 }; 122 };
106 123
124 EMAC1: ethernet@ef600c00 {
125 device_type = "network";
126 compatible = "ibm,emac-apm821xx", "ibm,emac4sync";
127 interrupt-parent = <&EMAC1>;
128 interrupts = <0 1>;
129 #interrupt-cells = <1>;
130 #address-cells = <0>;
131 #size-cells = <0>;
132 interrupt-map = <0 &UIC2 0x10 IRQ_TYPE_LEVEL_HIGH /* Status */
133 1 &UIC2 0x14 IRQ_TYPE_LEVEL_HIGH /* Wake */>;
134 reg = <0xef600c00 0x000000c4>;
135 local-mac-address = [000000000000]; /* Filled in by U-Boot */
136 mal-device = <&MAL0>;
137 mal-tx-channel = <0>;
138 mal-rx-channel = <0>;
139 cell-index = <0>;
140 max-frame-size = <9000>;
141 rx-fifo-size = <16384>;
142 tx-fifo-size = <2048>;
143 fifo-entry-size = <10>;
144 phy-mode = "rgmii";
145 phy-handle = <&phy0>;
146 phy-map = <0x00000000>;
147 rgmii-device = <&RGMII0>;
148 rgmii-channel = <0>;
149 tah-device = <&TAH0>;
150 tah-channel = <0>;
151 has-inverted-stacr-oc;
152 has-new-stacr-staopc;
153
154 mdio {
155 #address-cells = <1>;
156 #size-cells = <0>;
157
158 phy0: ethernet-phy@0 {
159 compatible = "ethernet-phy-ieee802.3-c22";
160 reg = <0>;
161 };
162 };
163 };
164
165
107 ii) McMAL node 166 ii) McMAL node
108 167
109 Required properties: 168 Required properties:
@@ -145,4 +204,3 @@
145 - revision : as provided by the RGMII new version register if 204 - revision : as provided by the RGMII new version register if
146 available. 205 available.
147 For Axon: 0x0000012a 206 For Axon: 0x0000012a
148
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index fc73eeb7b3b8..ab0230461377 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -1006,7 +1006,8 @@ accept_redirects - BOOLEAN
1006 FALSE (router) 1006 FALSE (router)
1007 1007
1008forwarding - BOOLEAN 1008forwarding - BOOLEAN
1009 Enable IP forwarding on this interface. 1009 Enable IP forwarding on this interface. This controls whether packets
1010 received _on_ this interface can be forwarded.
1010 1011
1011mc_forwarding - BOOLEAN 1012mc_forwarding - BOOLEAN
1012 Do multicast routing. The kernel needs to be compiled with CONFIG_MROUTE 1013 Do multicast routing. The kernel needs to be compiled with CONFIG_MROUTE
diff --git a/arch/powerpc/boot/zImage.lds.S b/arch/powerpc/boot/zImage.lds.S
index 861e72109df2..f080abfc2f83 100644
--- a/arch/powerpc/boot/zImage.lds.S
+++ b/arch/powerpc/boot/zImage.lds.S
@@ -68,6 +68,7 @@ SECTIONS
68 } 68 }
69 69
70#ifdef CONFIG_PPC64_BOOT_WRAPPER 70#ifdef CONFIG_PPC64_BOOT_WRAPPER
71 . = ALIGN(256);
71 .got : 72 .got :
72 { 73 {
73 __toc_start = .; 74 __toc_start = .;
diff --git a/arch/powerpc/crypto/crc32c-vpmsum_glue.c b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
index 9fa046d56eba..411994551afc 100644
--- a/arch/powerpc/crypto/crc32c-vpmsum_glue.c
+++ b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
@@ -52,7 +52,7 @@ static int crc32c_vpmsum_cra_init(struct crypto_tfm *tfm)
52{ 52{
53 u32 *key = crypto_tfm_ctx(tfm); 53 u32 *key = crypto_tfm_ctx(tfm);
54 54
55 *key = 0; 55 *key = ~0;
56 56
57 return 0; 57 return 0;
58} 58}
diff --git a/arch/powerpc/include/asm/bitops.h b/arch/powerpc/include/asm/bitops.h
index 73eb794d6163..bc5fdfd22788 100644
--- a/arch/powerpc/include/asm/bitops.h
+++ b/arch/powerpc/include/asm/bitops.h
@@ -51,6 +51,10 @@
51#define PPC_BIT(bit) (1UL << PPC_BITLSHIFT(bit)) 51#define PPC_BIT(bit) (1UL << PPC_BITLSHIFT(bit))
52#define PPC_BITMASK(bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) 52#define PPC_BITMASK(bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs))
53 53
54/* Put a PPC bit into a "normal" bit position */
55#define PPC_BITEXTRACT(bits, ppc_bit, dst_bit) \
56 ((((bits) >> PPC_BITLSHIFT(ppc_bit)) & 1) << (dst_bit))
57
54#include <asm/barrier.h> 58#include <asm/barrier.h>
55 59
56/* Macro for generating the ***_bits() functions */ 60/* Macro for generating the ***_bits() functions */
diff --git a/arch/powerpc/include/asm/mce.h b/arch/powerpc/include/asm/mce.h
index f97d8cb6bdf6..ed62efe01e49 100644
--- a/arch/powerpc/include/asm/mce.h
+++ b/arch/powerpc/include/asm/mce.h
@@ -66,6 +66,55 @@
66 66
67#define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \ 67#define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \
68 P8_DSISR_MC_ERAT_MULTIHIT_SEC) 68 P8_DSISR_MC_ERAT_MULTIHIT_SEC)
69
70/*
71 * Machine Check bits on power9
72 */
73#define P9_SRR1_MC_LOADSTORE(srr1) (((srr1) >> PPC_BITLSHIFT(42)) & 1)
74
75#define P9_SRR1_MC_IFETCH(srr1) ( \
76 PPC_BITEXTRACT(srr1, 45, 0) | \
77 PPC_BITEXTRACT(srr1, 44, 1) | \
78 PPC_BITEXTRACT(srr1, 43, 2) | \
79 PPC_BITEXTRACT(srr1, 36, 3) )
80
81/* 0 is reserved */
82#define P9_SRR1_MC_IFETCH_UE 1
83#define P9_SRR1_MC_IFETCH_SLB_PARITY 2
84#define P9_SRR1_MC_IFETCH_SLB_MULTIHIT 3
85#define P9_SRR1_MC_IFETCH_ERAT_MULTIHIT 4
86#define P9_SRR1_MC_IFETCH_TLB_MULTIHIT 5
87#define P9_SRR1_MC_IFETCH_UE_TLB_RELOAD 6
88/* 7 is reserved */
89#define P9_SRR1_MC_IFETCH_LINK_TIMEOUT 8
90#define P9_SRR1_MC_IFETCH_LINK_TABLEWALK_TIMEOUT 9
91/* 10 ? */
92#define P9_SRR1_MC_IFETCH_RA 11
93#define P9_SRR1_MC_IFETCH_RA_TABLEWALK 12
94#define P9_SRR1_MC_IFETCH_RA_ASYNC_STORE 13
95#define P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT 14
96#define P9_SRR1_MC_IFETCH_RA_TABLEWALK_FOREIGN 15
97
98/* DSISR bits for machine check (On Power9) */
99#define P9_DSISR_MC_UE (PPC_BIT(48))
100#define P9_DSISR_MC_UE_TABLEWALK (PPC_BIT(49))
101#define P9_DSISR_MC_LINK_LOAD_TIMEOUT (PPC_BIT(50))
102#define P9_DSISR_MC_LINK_TABLEWALK_TIMEOUT (PPC_BIT(51))
103#define P9_DSISR_MC_ERAT_MULTIHIT (PPC_BIT(52))
104#define P9_DSISR_MC_TLB_MULTIHIT_MFTLB (PPC_BIT(53))
105#define P9_DSISR_MC_USER_TLBIE (PPC_BIT(54))
106#define P9_DSISR_MC_SLB_PARITY_MFSLB (PPC_BIT(55))
107#define P9_DSISR_MC_SLB_MULTIHIT_MFSLB (PPC_BIT(56))
108#define P9_DSISR_MC_RA_LOAD (PPC_BIT(57))
109#define P9_DSISR_MC_RA_TABLEWALK (PPC_BIT(58))
110#define P9_DSISR_MC_RA_TABLEWALK_FOREIGN (PPC_BIT(59))
111#define P9_DSISR_MC_RA_FOREIGN (PPC_BIT(60))
112
113/* SLB error bits */
114#define P9_DSISR_MC_SLB_ERRORS (P9_DSISR_MC_ERAT_MULTIHIT | \
115 P9_DSISR_MC_SLB_PARITY_MFSLB | \
116 P9_DSISR_MC_SLB_MULTIHIT_MFSLB)
117
69enum MCE_Version { 118enum MCE_Version {
70 MCE_V1 = 1, 119 MCE_V1 = 1,
71}; 120};
@@ -93,6 +142,9 @@ enum MCE_ErrorType {
93 MCE_ERROR_TYPE_SLB = 2, 142 MCE_ERROR_TYPE_SLB = 2,
94 MCE_ERROR_TYPE_ERAT = 3, 143 MCE_ERROR_TYPE_ERAT = 3,
95 MCE_ERROR_TYPE_TLB = 4, 144 MCE_ERROR_TYPE_TLB = 4,
145 MCE_ERROR_TYPE_USER = 5,
146 MCE_ERROR_TYPE_RA = 6,
147 MCE_ERROR_TYPE_LINK = 7,
96}; 148};
97 149
98enum MCE_UeErrorType { 150enum MCE_UeErrorType {
@@ -121,6 +173,32 @@ enum MCE_TlbErrorType {
121 MCE_TLB_ERROR_MULTIHIT = 2, 173 MCE_TLB_ERROR_MULTIHIT = 2,
122}; 174};
123 175
176enum MCE_UserErrorType {
177 MCE_USER_ERROR_INDETERMINATE = 0,
178 MCE_USER_ERROR_TLBIE = 1,
179};
180
181enum MCE_RaErrorType {
182 MCE_RA_ERROR_INDETERMINATE = 0,
183 MCE_RA_ERROR_IFETCH = 1,
184 MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
185 MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN = 3,
186 MCE_RA_ERROR_LOAD = 4,
187 MCE_RA_ERROR_STORE = 5,
188 MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 6,
189 MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN = 7,
190 MCE_RA_ERROR_LOAD_STORE_FOREIGN = 8,
191};
192
193enum MCE_LinkErrorType {
194 MCE_LINK_ERROR_INDETERMINATE = 0,
195 MCE_LINK_ERROR_IFETCH_TIMEOUT = 1,
196 MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT = 2,
197 MCE_LINK_ERROR_LOAD_TIMEOUT = 3,
198 MCE_LINK_ERROR_STORE_TIMEOUT = 4,
199 MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT = 5,
200};
201
124struct machine_check_event { 202struct machine_check_event {
125 enum MCE_Version version:8; /* 0x00 */ 203 enum MCE_Version version:8; /* 0x00 */
126 uint8_t in_use; /* 0x01 */ 204 uint8_t in_use; /* 0x01 */
@@ -166,6 +244,30 @@ struct machine_check_event {
166 uint64_t effective_address; 244 uint64_t effective_address;
167 uint8_t reserved_2[16]; 245 uint8_t reserved_2[16];
168 } tlb_error; 246 } tlb_error;
247
248 struct {
249 enum MCE_UserErrorType user_error_type:8;
250 uint8_t effective_address_provided;
251 uint8_t reserved_1[6];
252 uint64_t effective_address;
253 uint8_t reserved_2[16];
254 } user_error;
255
256 struct {
257 enum MCE_RaErrorType ra_error_type:8;
258 uint8_t effective_address_provided;
259 uint8_t reserved_1[6];
260 uint64_t effective_address;
261 uint8_t reserved_2[16];
262 } ra_error;
263
264 struct {
265 enum MCE_LinkErrorType link_error_type:8;
266 uint8_t effective_address_provided;
267 uint8_t reserved_1[6];
268 uint64_t effective_address;
269 uint8_t reserved_2[16];
270 } link_error;
169 } u; 271 } u;
170}; 272};
171 273
@@ -176,8 +278,12 @@ struct mce_error_info {
176 enum MCE_SlbErrorType slb_error_type:8; 278 enum MCE_SlbErrorType slb_error_type:8;
177 enum MCE_EratErrorType erat_error_type:8; 279 enum MCE_EratErrorType erat_error_type:8;
178 enum MCE_TlbErrorType tlb_error_type:8; 280 enum MCE_TlbErrorType tlb_error_type:8;
281 enum MCE_UserErrorType user_error_type:8;
282 enum MCE_RaErrorType ra_error_type:8;
283 enum MCE_LinkErrorType link_error_type:8;
179 } u; 284 } u;
180 uint8_t reserved[2]; 285 enum MCE_Severity severity:8;
286 enum MCE_Initiator initiator:8;
181}; 287};
182 288
183#define MAX_MC_EVT 100 289#define MAX_MC_EVT 100
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index bb7a1890aeb7..e79b9daa873c 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -77,6 +77,7 @@ extern void __flush_tlb_power8(unsigned int action);
77extern void __flush_tlb_power9(unsigned int action); 77extern void __flush_tlb_power9(unsigned int action);
78extern long __machine_check_early_realmode_p7(struct pt_regs *regs); 78extern long __machine_check_early_realmode_p7(struct pt_regs *regs);
79extern long __machine_check_early_realmode_p8(struct pt_regs *regs); 79extern long __machine_check_early_realmode_p8(struct pt_regs *regs);
80extern long __machine_check_early_realmode_p9(struct pt_regs *regs);
80#endif /* CONFIG_PPC64 */ 81#endif /* CONFIG_PPC64 */
81#if defined(CONFIG_E500) 82#if defined(CONFIG_E500)
82extern void __setup_cpu_e5500(unsigned long offset, struct cpu_spec* spec); 83extern void __setup_cpu_e5500(unsigned long offset, struct cpu_spec* spec);
@@ -540,6 +541,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
540 .cpu_setup = __setup_cpu_power9, 541 .cpu_setup = __setup_cpu_power9,
541 .cpu_restore = __restore_cpu_power9, 542 .cpu_restore = __restore_cpu_power9,
542 .flush_tlb = __flush_tlb_power9, 543 .flush_tlb = __flush_tlb_power9,
544 .machine_check_early = __machine_check_early_realmode_p9,
543 .platform = "power9", 545 .platform = "power9",
544 }, 546 },
545 { /* Power9 */ 547 { /* Power9 */
@@ -559,6 +561,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
559 .cpu_setup = __setup_cpu_power9, 561 .cpu_setup = __setup_cpu_power9,
560 .cpu_restore = __restore_cpu_power9, 562 .cpu_restore = __restore_cpu_power9,
561 .flush_tlb = __flush_tlb_power9, 563 .flush_tlb = __flush_tlb_power9,
564 .machine_check_early = __machine_check_early_realmode_p9,
562 .platform = "power9", 565 .platform = "power9",
563 }, 566 },
564 { /* Cell Broadband Engine */ 567 { /* Cell Broadband Engine */
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index c6923ff45131..a1475e6aef3a 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -58,6 +58,15 @@ static void mce_set_error_info(struct machine_check_event *mce,
58 case MCE_ERROR_TYPE_TLB: 58 case MCE_ERROR_TYPE_TLB:
59 mce->u.tlb_error.tlb_error_type = mce_err->u.tlb_error_type; 59 mce->u.tlb_error.tlb_error_type = mce_err->u.tlb_error_type;
60 break; 60 break;
61 case MCE_ERROR_TYPE_USER:
62 mce->u.user_error.user_error_type = mce_err->u.user_error_type;
63 break;
64 case MCE_ERROR_TYPE_RA:
65 mce->u.ra_error.ra_error_type = mce_err->u.ra_error_type;
66 break;
67 case MCE_ERROR_TYPE_LINK:
68 mce->u.link_error.link_error_type = mce_err->u.link_error_type;
69 break;
61 case MCE_ERROR_TYPE_UNKNOWN: 70 case MCE_ERROR_TYPE_UNKNOWN:
62 default: 71 default:
63 break; 72 break;
@@ -90,13 +99,14 @@ void save_mce_event(struct pt_regs *regs, long handled,
90 mce->gpr3 = regs->gpr[3]; 99 mce->gpr3 = regs->gpr[3];
91 mce->in_use = 1; 100 mce->in_use = 1;
92 101
93 mce->initiator = MCE_INITIATOR_CPU;
94 /* Mark it recovered if we have handled it and MSR(RI=1). */ 102 /* Mark it recovered if we have handled it and MSR(RI=1). */
95 if (handled && (regs->msr & MSR_RI)) 103 if (handled && (regs->msr & MSR_RI))
96 mce->disposition = MCE_DISPOSITION_RECOVERED; 104 mce->disposition = MCE_DISPOSITION_RECOVERED;
97 else 105 else
98 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED; 106 mce->disposition = MCE_DISPOSITION_NOT_RECOVERED;
99 mce->severity = MCE_SEV_ERROR_SYNC; 107
108 mce->initiator = mce_err->initiator;
109 mce->severity = mce_err->severity;
100 110
101 /* 111 /*
102 * Populate the mce error_type and type-specific error_type. 112 * Populate the mce error_type and type-specific error_type.
@@ -115,6 +125,15 @@ void save_mce_event(struct pt_regs *regs, long handled,
115 } else if (mce->error_type == MCE_ERROR_TYPE_ERAT) { 125 } else if (mce->error_type == MCE_ERROR_TYPE_ERAT) {
116 mce->u.erat_error.effective_address_provided = true; 126 mce->u.erat_error.effective_address_provided = true;
117 mce->u.erat_error.effective_address = addr; 127 mce->u.erat_error.effective_address = addr;
128 } else if (mce->error_type == MCE_ERROR_TYPE_USER) {
129 mce->u.user_error.effective_address_provided = true;
130 mce->u.user_error.effective_address = addr;
131 } else if (mce->error_type == MCE_ERROR_TYPE_RA) {
132 mce->u.ra_error.effective_address_provided = true;
133 mce->u.ra_error.effective_address = addr;
134 } else if (mce->error_type == MCE_ERROR_TYPE_LINK) {
135 mce->u.link_error.effective_address_provided = true;
136 mce->u.link_error.effective_address = addr;
118 } else if (mce->error_type == MCE_ERROR_TYPE_UE) { 137 } else if (mce->error_type == MCE_ERROR_TYPE_UE) {
119 mce->u.ue_error.effective_address_provided = true; 138 mce->u.ue_error.effective_address_provided = true;
120 mce->u.ue_error.effective_address = addr; 139 mce->u.ue_error.effective_address = addr;
@@ -239,6 +258,29 @@ void machine_check_print_event_info(struct machine_check_event *evt)
239 "Parity", 258 "Parity",
240 "Multihit", 259 "Multihit",
241 }; 260 };
261 static const char *mc_user_types[] = {
262 "Indeterminate",
263 "tlbie(l) invalid",
264 };
265 static const char *mc_ra_types[] = {
266 "Indeterminate",
267 "Instruction fetch (bad)",
268 "Page table walk ifetch (bad)",
269 "Page table walk ifetch (foreign)",
270 "Load (bad)",
271 "Store (bad)",
272 "Page table walk Load/Store (bad)",
273 "Page table walk Load/Store (foreign)",
274 "Load/Store (foreign)",
275 };
276 static const char *mc_link_types[] = {
277 "Indeterminate",
278 "Instruction fetch (timeout)",
279 "Page table walk ifetch (timeout)",
280 "Load (timeout)",
281 "Store (timeout)",
282 "Page table walk Load/Store (timeout)",
283 };
242 284
243 /* Print things out */ 285 /* Print things out */
244 if (evt->version != MCE_V1) { 286 if (evt->version != MCE_V1) {
@@ -315,6 +357,36 @@ void machine_check_print_event_info(struct machine_check_event *evt)
315 printk("%s Effective address: %016llx\n", 357 printk("%s Effective address: %016llx\n",
316 level, evt->u.tlb_error.effective_address); 358 level, evt->u.tlb_error.effective_address);
317 break; 359 break;
360 case MCE_ERROR_TYPE_USER:
361 subtype = evt->u.user_error.user_error_type <
362 ARRAY_SIZE(mc_user_types) ?
363 mc_user_types[evt->u.user_error.user_error_type]
364 : "Unknown";
365 printk("%s Error type: User [%s]\n", level, subtype);
366 if (evt->u.user_error.effective_address_provided)
367 printk("%s Effective address: %016llx\n",
368 level, evt->u.user_error.effective_address);
369 break;
370 case MCE_ERROR_TYPE_RA:
371 subtype = evt->u.ra_error.ra_error_type <
372 ARRAY_SIZE(mc_ra_types) ?
373 mc_ra_types[evt->u.ra_error.ra_error_type]
374 : "Unknown";
375 printk("%s Error type: Real address [%s]\n", level, subtype);
376 if (evt->u.ra_error.effective_address_provided)
377 printk("%s Effective address: %016llx\n",
378 level, evt->u.ra_error.effective_address);
379 break;
380 case MCE_ERROR_TYPE_LINK:
381 subtype = evt->u.link_error.link_error_type <
382 ARRAY_SIZE(mc_link_types) ?
383 mc_link_types[evt->u.link_error.link_error_type]
384 : "Unknown";
385 printk("%s Error type: Link [%s]\n", level, subtype);
386 if (evt->u.link_error.effective_address_provided)
387 printk("%s Effective address: %016llx\n",
388 level, evt->u.link_error.effective_address);
389 break;
318 default: 390 default:
319 case MCE_ERROR_TYPE_UNKNOWN: 391 case MCE_ERROR_TYPE_UNKNOWN:
320 printk("%s Error type: Unknown\n", level); 392 printk("%s Error type: Unknown\n", level);
@@ -341,6 +413,18 @@ uint64_t get_mce_fault_addr(struct machine_check_event *evt)
341 if (evt->u.tlb_error.effective_address_provided) 413 if (evt->u.tlb_error.effective_address_provided)
342 return evt->u.tlb_error.effective_address; 414 return evt->u.tlb_error.effective_address;
343 break; 415 break;
416 case MCE_ERROR_TYPE_USER:
417 if (evt->u.user_error.effective_address_provided)
418 return evt->u.user_error.effective_address;
419 break;
420 case MCE_ERROR_TYPE_RA:
421 if (evt->u.ra_error.effective_address_provided)
422 return evt->u.ra_error.effective_address;
423 break;
424 case MCE_ERROR_TYPE_LINK:
425 if (evt->u.link_error.effective_address_provided)
426 return evt->u.link_error.effective_address;
427 break;
344 default: 428 default:
345 case MCE_ERROR_TYPE_UNKNOWN: 429 case MCE_ERROR_TYPE_UNKNOWN:
346 break; 430 break;
diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
index 7353991c4ece..763d6f58caa8 100644
--- a/arch/powerpc/kernel/mce_power.c
+++ b/arch/powerpc/kernel/mce_power.c
@@ -116,6 +116,51 @@ static void flush_and_reload_slb(void)
116} 116}
117#endif 117#endif
118 118
119static void flush_erat(void)
120{
121 asm volatile(PPC_INVALIDATE_ERAT : : :"memory");
122}
123
124#define MCE_FLUSH_SLB 1
125#define MCE_FLUSH_TLB 2
126#define MCE_FLUSH_ERAT 3
127
128static int mce_flush(int what)
129{
130#ifdef CONFIG_PPC_STD_MMU_64
131 if (what == MCE_FLUSH_SLB) {
132 flush_and_reload_slb();
133 return 1;
134 }
135#endif
136 if (what == MCE_FLUSH_ERAT) {
137 flush_erat();
138 return 1;
139 }
140 if (what == MCE_FLUSH_TLB) {
141 if (cur_cpu_spec && cur_cpu_spec->flush_tlb) {
142 cur_cpu_spec->flush_tlb(TLB_INVAL_SCOPE_GLOBAL);
143 return 1;
144 }
145 }
146
147 return 0;
148}
149
150static int mce_handle_flush_derrors(uint64_t dsisr, uint64_t slb, uint64_t tlb, uint64_t erat)
151{
152 if ((dsisr & slb) && mce_flush(MCE_FLUSH_SLB))
153 dsisr &= ~slb;
154 if ((dsisr & erat) && mce_flush(MCE_FLUSH_ERAT))
155 dsisr &= ~erat;
156 if ((dsisr & tlb) && mce_flush(MCE_FLUSH_TLB))
157 dsisr &= ~tlb;
158 /* Any other errors we don't understand? */
159 if (dsisr)
160 return 0;
161 return 1;
162}
163
119static long mce_handle_derror(uint64_t dsisr, uint64_t slb_error_bits) 164static long mce_handle_derror(uint64_t dsisr, uint64_t slb_error_bits)
120{ 165{
121 long handled = 1; 166 long handled = 1;
@@ -281,6 +326,9 @@ long __machine_check_early_realmode_p7(struct pt_regs *regs)
281 long handled = 1; 326 long handled = 1;
282 struct mce_error_info mce_error_info = { 0 }; 327 struct mce_error_info mce_error_info = { 0 };
283 328
329 mce_error_info.severity = MCE_SEV_ERROR_SYNC;
330 mce_error_info.initiator = MCE_INITIATOR_CPU;
331
284 srr1 = regs->msr; 332 srr1 = regs->msr;
285 nip = regs->nip; 333 nip = regs->nip;
286 334
@@ -352,6 +400,9 @@ long __machine_check_early_realmode_p8(struct pt_regs *regs)
352 long handled = 1; 400 long handled = 1;
353 struct mce_error_info mce_error_info = { 0 }; 401 struct mce_error_info mce_error_info = { 0 };
354 402
403 mce_error_info.severity = MCE_SEV_ERROR_SYNC;
404 mce_error_info.initiator = MCE_INITIATOR_CPU;
405
355 srr1 = regs->msr; 406 srr1 = regs->msr;
356 nip = regs->nip; 407 nip = regs->nip;
357 408
@@ -372,3 +423,189 @@ long __machine_check_early_realmode_p8(struct pt_regs *regs)
372 save_mce_event(regs, handled, &mce_error_info, nip, addr); 423 save_mce_event(regs, handled, &mce_error_info, nip, addr);
373 return handled; 424 return handled;
374} 425}
426
427static int mce_handle_derror_p9(struct pt_regs *regs)
428{
429 uint64_t dsisr = regs->dsisr;
430
431 return mce_handle_flush_derrors(dsisr,
432 P9_DSISR_MC_SLB_PARITY_MFSLB |
433 P9_DSISR_MC_SLB_MULTIHIT_MFSLB,
434
435 P9_DSISR_MC_TLB_MULTIHIT_MFTLB,
436
437 P9_DSISR_MC_ERAT_MULTIHIT);
438}
439
440static int mce_handle_ierror_p9(struct pt_regs *regs)
441{
442 uint64_t srr1 = regs->msr;
443
444 switch (P9_SRR1_MC_IFETCH(srr1)) {
445 case P9_SRR1_MC_IFETCH_SLB_PARITY:
446 case P9_SRR1_MC_IFETCH_SLB_MULTIHIT:
447 return mce_flush(MCE_FLUSH_SLB);
448 case P9_SRR1_MC_IFETCH_TLB_MULTIHIT:
449 return mce_flush(MCE_FLUSH_TLB);
450 case P9_SRR1_MC_IFETCH_ERAT_MULTIHIT:
451 return mce_flush(MCE_FLUSH_ERAT);
452 default:
453 return 0;
454 }
455}
456
457static void mce_get_derror_p9(struct pt_regs *regs,
458 struct mce_error_info *mce_err, uint64_t *addr)
459{
460 uint64_t dsisr = regs->dsisr;
461
462 mce_err->severity = MCE_SEV_ERROR_SYNC;
463 mce_err->initiator = MCE_INITIATOR_CPU;
464
465 if (dsisr & P9_DSISR_MC_USER_TLBIE)
466 *addr = regs->nip;
467 else
468 *addr = regs->dar;
469
470 if (dsisr & P9_DSISR_MC_UE) {
471 mce_err->error_type = MCE_ERROR_TYPE_UE;
472 mce_err->u.ue_error_type = MCE_UE_ERROR_LOAD_STORE;
473 } else if (dsisr & P9_DSISR_MC_UE_TABLEWALK) {
474 mce_err->error_type = MCE_ERROR_TYPE_UE;
475 mce_err->u.ue_error_type = MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE;
476 } else if (dsisr & P9_DSISR_MC_LINK_LOAD_TIMEOUT) {
477 mce_err->error_type = MCE_ERROR_TYPE_LINK;
478 mce_err->u.link_error_type = MCE_LINK_ERROR_LOAD_TIMEOUT;
479 } else if (dsisr & P9_DSISR_MC_LINK_TABLEWALK_TIMEOUT) {
480 mce_err->error_type = MCE_ERROR_TYPE_LINK;
481 mce_err->u.link_error_type = MCE_LINK_ERROR_PAGE_TABLE_WALK_LOAD_STORE_TIMEOUT;
482 } else if (dsisr & P9_DSISR_MC_ERAT_MULTIHIT) {
483 mce_err->error_type = MCE_ERROR_TYPE_ERAT;
484 mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
485 } else if (dsisr & P9_DSISR_MC_TLB_MULTIHIT_MFTLB) {
486 mce_err->error_type = MCE_ERROR_TYPE_TLB;
487 mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
488 } else if (dsisr & P9_DSISR_MC_USER_TLBIE) {
489 mce_err->error_type = MCE_ERROR_TYPE_USER;
490 mce_err->u.user_error_type = MCE_USER_ERROR_TLBIE;
491 } else if (dsisr & P9_DSISR_MC_SLB_PARITY_MFSLB) {
492 mce_err->error_type = MCE_ERROR_TYPE_SLB;
493 mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
494 } else if (dsisr & P9_DSISR_MC_SLB_MULTIHIT_MFSLB) {
495 mce_err->error_type = MCE_ERROR_TYPE_SLB;
496 mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
497 } else if (dsisr & P9_DSISR_MC_RA_LOAD) {
498 mce_err->error_type = MCE_ERROR_TYPE_RA;
499 mce_err->u.ra_error_type = MCE_RA_ERROR_LOAD;
500 } else if (dsisr & P9_DSISR_MC_RA_TABLEWALK) {
501 mce_err->error_type = MCE_ERROR_TYPE_RA;
502 mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE;
503 } else if (dsisr & P9_DSISR_MC_RA_TABLEWALK_FOREIGN) {
504 mce_err->error_type = MCE_ERROR_TYPE_RA;
505 mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_LOAD_STORE_FOREIGN;
506 } else if (dsisr & P9_DSISR_MC_RA_FOREIGN) {
507 mce_err->error_type = MCE_ERROR_TYPE_RA;
508 mce_err->u.ra_error_type = MCE_RA_ERROR_LOAD_STORE_FOREIGN;
509 }
510}
511
512static void mce_get_ierror_p9(struct pt_regs *regs,
513 struct mce_error_info *mce_err, uint64_t *addr)
514{
515 uint64_t srr1 = regs->msr;
516
517 switch (P9_SRR1_MC_IFETCH(srr1)) {
518 case P9_SRR1_MC_IFETCH_RA_ASYNC_STORE:
519 case P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT:
520 mce_err->severity = MCE_SEV_FATAL;
521 break;
522 default:
523 mce_err->severity = MCE_SEV_ERROR_SYNC;
524 break;
525 }
526
527 mce_err->initiator = MCE_INITIATOR_CPU;
528
529 *addr = regs->nip;
530
531 switch (P9_SRR1_MC_IFETCH(srr1)) {
532 case P9_SRR1_MC_IFETCH_UE:
533 mce_err->error_type = MCE_ERROR_TYPE_UE;
534 mce_err->u.ue_error_type = MCE_UE_ERROR_IFETCH;
535 break;
536 case P9_SRR1_MC_IFETCH_SLB_PARITY:
537 mce_err->error_type = MCE_ERROR_TYPE_SLB;
538 mce_err->u.slb_error_type = MCE_SLB_ERROR_PARITY;
539 break;
540 case P9_SRR1_MC_IFETCH_SLB_MULTIHIT:
541 mce_err->error_type = MCE_ERROR_TYPE_SLB;
542 mce_err->u.slb_error_type = MCE_SLB_ERROR_MULTIHIT;
543 break;
544 case P9_SRR1_MC_IFETCH_ERAT_MULTIHIT:
545 mce_err->error_type = MCE_ERROR_TYPE_ERAT;
546 mce_err->u.erat_error_type = MCE_ERAT_ERROR_MULTIHIT;
547 break;
548 case P9_SRR1_MC_IFETCH_TLB_MULTIHIT:
549 mce_err->error_type = MCE_ERROR_TYPE_TLB;
550 mce_err->u.tlb_error_type = MCE_TLB_ERROR_MULTIHIT;
551 break;
552 case P9_SRR1_MC_IFETCH_UE_TLB_RELOAD:
553 mce_err->error_type = MCE_ERROR_TYPE_UE;
554 mce_err->u.ue_error_type = MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH;
555 break;
556 case P9_SRR1_MC_IFETCH_LINK_TIMEOUT:
557 mce_err->error_type = MCE_ERROR_TYPE_LINK;
558 mce_err->u.link_error_type = MCE_LINK_ERROR_IFETCH_TIMEOUT;
559 break;
560 case P9_SRR1_MC_IFETCH_LINK_TABLEWALK_TIMEOUT:
561 mce_err->error_type = MCE_ERROR_TYPE_LINK;
562 mce_err->u.link_error_type = MCE_LINK_ERROR_PAGE_TABLE_WALK_IFETCH_TIMEOUT;
563 break;
564 case P9_SRR1_MC_IFETCH_RA:
565 mce_err->error_type = MCE_ERROR_TYPE_RA;
566 mce_err->u.ra_error_type = MCE_RA_ERROR_IFETCH;
567 break;
568 case P9_SRR1_MC_IFETCH_RA_TABLEWALK:
569 mce_err->error_type = MCE_ERROR_TYPE_RA;
570 mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH;
571 break;
572 case P9_SRR1_MC_IFETCH_RA_ASYNC_STORE:
573 mce_err->error_type = MCE_ERROR_TYPE_RA;
574 mce_err->u.ra_error_type = MCE_RA_ERROR_STORE;
575 break;
576 case P9_SRR1_MC_IFETCH_LINK_ASYNC_STORE_TIMEOUT:
577 mce_err->error_type = MCE_ERROR_TYPE_LINK;
578 mce_err->u.link_error_type = MCE_LINK_ERROR_STORE_TIMEOUT;
579 break;
580 case P9_SRR1_MC_IFETCH_RA_TABLEWALK_FOREIGN:
581 mce_err->error_type = MCE_ERROR_TYPE_RA;
582 mce_err->u.ra_error_type = MCE_RA_ERROR_PAGE_TABLE_WALK_IFETCH_FOREIGN;
583 break;
584 default:
585 break;
586 }
587}
588
589long __machine_check_early_realmode_p9(struct pt_regs *regs)
590{
591 uint64_t nip, addr;
592 long handled;
593 struct mce_error_info mce_error_info = { 0 };
594
595 nip = regs->nip;
596
597 if (P9_SRR1_MC_LOADSTORE(regs->msr)) {
598 handled = mce_handle_derror_p9(regs);
599 mce_get_derror_p9(regs, &mce_error_info, &addr);
600 } else {
601 handled = mce_handle_ierror_p9(regs);
602 mce_get_ierror_p9(regs, &mce_error_info, &addr);
603 }
604
605 /* Handle UE error. */
606 if (mce_error_info.error_type == MCE_ERROR_TYPE_UE)
607 handled = mce_handle_ue_error(regs);
608
609 save_mce_event(regs, handled, &mce_error_info, nip, addr);
610 return handled;
611}
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 595dd718ea87..2ff13249f87a 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -188,6 +188,8 @@ static inline void perf_get_data_addr(struct pt_regs *regs, u64 *addrp)
188 sdsync = POWER7P_MMCRA_SDAR_VALID; 188 sdsync = POWER7P_MMCRA_SDAR_VALID;
189 else if (ppmu->flags & PPMU_ALT_SIPR) 189 else if (ppmu->flags & PPMU_ALT_SIPR)
190 sdsync = POWER6_MMCRA_SDSYNC; 190 sdsync = POWER6_MMCRA_SDSYNC;
191 else if (ppmu->flags & PPMU_NO_SIAR)
192 sdsync = MMCRA_SAMPLE_ENABLE;
191 else 193 else
192 sdsync = MMCRA_SDSYNC; 194 sdsync = MMCRA_SDSYNC;
193 195
diff --git a/arch/powerpc/perf/isa207-common.c b/arch/powerpc/perf/isa207-common.c
index e79fb5fb817d..cd951fd231c4 100644
--- a/arch/powerpc/perf/isa207-common.c
+++ b/arch/powerpc/perf/isa207-common.c
@@ -65,12 +65,41 @@ static bool is_event_valid(u64 event)
65 return !(event & ~valid_mask); 65 return !(event & ~valid_mask);
66} 66}
67 67
68static u64 mmcra_sdar_mode(u64 event) 68static inline bool is_event_marked(u64 event)
69{ 69{
70 if (cpu_has_feature(CPU_FTR_ARCH_300) && !cpu_has_feature(CPU_FTR_POWER9_DD1)) 70 if (event & EVENT_IS_MARKED)
71 return p9_SDAR_MODE(event) << MMCRA_SDAR_MODE_SHIFT; 71 return true;
72
73 return false;
74}
72 75
73 return MMCRA_SDAR_MODE_TLB; 76static void mmcra_sdar_mode(u64 event, unsigned long *mmcra)
77{
78 /*
79 * MMCRA[SDAR_MODE] specifices how the SDAR should be updated in
80 * continous sampling mode.
81 *
82 * Incase of Power8:
83 * MMCRA[SDAR_MODE] will be programmed as "0b01" for continous sampling
84 * mode and will be un-changed when setting MMCRA[63] (Marked events).
85 *
86 * Incase of Power9:
87 * Marked event: MMCRA[SDAR_MODE] will be set to 0b00 ('No Updates'),
88 * or if group already have any marked events.
89 * Non-Marked events (for DD1):
90 * MMCRA[SDAR_MODE] will be set to 0b01
91 * For rest
92 * MMCRA[SDAR_MODE] will be set from event code.
93 */
94 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
95 if (is_event_marked(event) || (*mmcra & MMCRA_SAMPLE_ENABLE))
96 *mmcra &= MMCRA_SDAR_MODE_NO_UPDATES;
97 else if (!cpu_has_feature(CPU_FTR_POWER9_DD1))
98 *mmcra |= p9_SDAR_MODE(event) << MMCRA_SDAR_MODE_SHIFT;
99 else if (cpu_has_feature(CPU_FTR_POWER9_DD1))
100 *mmcra |= MMCRA_SDAR_MODE_TLB;
101 } else
102 *mmcra |= MMCRA_SDAR_MODE_TLB;
74} 103}
75 104
76static u64 thresh_cmp_val(u64 value) 105static u64 thresh_cmp_val(u64 value)
@@ -180,7 +209,7 @@ int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp)
180 value |= CNST_L1_QUAL_VAL(cache); 209 value |= CNST_L1_QUAL_VAL(cache);
181 } 210 }
182 211
183 if (event & EVENT_IS_MARKED) { 212 if (is_event_marked(event)) {
184 mask |= CNST_SAMPLE_MASK; 213 mask |= CNST_SAMPLE_MASK;
185 value |= CNST_SAMPLE_VAL(event >> EVENT_SAMPLE_SHIFT); 214 value |= CNST_SAMPLE_VAL(event >> EVENT_SAMPLE_SHIFT);
186 } 215 }
@@ -276,7 +305,7 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
276 } 305 }
277 306
278 /* In continuous sampling mode, update SDAR on TLB miss */ 307 /* In continuous sampling mode, update SDAR on TLB miss */
279 mmcra |= mmcra_sdar_mode(event[i]); 308 mmcra_sdar_mode(event[i], &mmcra);
280 309
281 if (event[i] & EVENT_IS_L1) { 310 if (event[i] & EVENT_IS_L1) {
282 cache = event[i] >> EVENT_CACHE_SEL_SHIFT; 311 cache = event[i] >> EVENT_CACHE_SEL_SHIFT;
@@ -285,7 +314,7 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
285 mmcr1 |= (cache & 1) << MMCR1_DC_QUAL_SHIFT; 314 mmcr1 |= (cache & 1) << MMCR1_DC_QUAL_SHIFT;
286 } 315 }
287 316
288 if (event[i] & EVENT_IS_MARKED) { 317 if (is_event_marked(event[i])) {
289 mmcra |= MMCRA_SAMPLE_ENABLE; 318 mmcra |= MMCRA_SAMPLE_ENABLE;
290 319
291 val = (event[i] >> EVENT_SAMPLE_SHIFT) & EVENT_SAMPLE_MASK; 320 val = (event[i] >> EVENT_SAMPLE_SHIFT) & EVENT_SAMPLE_MASK;
diff --git a/arch/powerpc/perf/isa207-common.h b/arch/powerpc/perf/isa207-common.h
index cf9bd8990159..899210f14ee4 100644
--- a/arch/powerpc/perf/isa207-common.h
+++ b/arch/powerpc/perf/isa207-common.h
@@ -246,6 +246,7 @@
246#define MMCRA_THR_CMP_SHIFT 32 246#define MMCRA_THR_CMP_SHIFT 32
247#define MMCRA_SDAR_MODE_SHIFT 42 247#define MMCRA_SDAR_MODE_SHIFT 42
248#define MMCRA_SDAR_MODE_TLB (1ull << MMCRA_SDAR_MODE_SHIFT) 248#define MMCRA_SDAR_MODE_TLB (1ull << MMCRA_SDAR_MODE_SHIFT)
249#define MMCRA_SDAR_MODE_NO_UPDATES ~(0x3ull << MMCRA_SDAR_MODE_SHIFT)
249#define MMCRA_IFM_SHIFT 30 250#define MMCRA_IFM_SHIFT 30
250 251
251/* MMCR1 Threshold Compare bit constant for power9 */ 252/* MMCR1 Threshold Compare bit constant for power9 */
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 86d9fde93c17..e0f856bfbfe8 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -395,7 +395,6 @@ static int opal_recover_mce(struct pt_regs *regs,
395 struct machine_check_event *evt) 395 struct machine_check_event *evt)
396{ 396{
397 int recovered = 0; 397 int recovered = 0;
398 uint64_t ea = get_mce_fault_addr(evt);
399 398
400 if (!(regs->msr & MSR_RI)) { 399 if (!(regs->msr & MSR_RI)) {
401 /* If MSR_RI isn't set, we cannot recover */ 400 /* If MSR_RI isn't set, we cannot recover */
@@ -404,26 +403,18 @@ static int opal_recover_mce(struct pt_regs *regs,
404 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) { 403 } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
405 /* Platform corrected itself */ 404 /* Platform corrected itself */
406 recovered = 1; 405 recovered = 1;
407 } else if (ea && !is_kernel_addr(ea)) { 406 } else if (evt->severity == MCE_SEV_FATAL) {
407 /* Fatal machine check */
408 pr_err("Machine check interrupt is fatal\n");
409 recovered = 0;
410 } else if ((evt->severity == MCE_SEV_ERROR_SYNC) &&
411 (user_mode(regs) && !is_global_init(current))) {
408 /* 412 /*
409 * Faulting address is not in kernel text. We should be fine.
410 * We need to find which process uses this address.
411 * For now, kill the task if we have received exception when 413 * For now, kill the task if we have received exception when
412 * in userspace. 414 * in userspace.
413 * 415 *
414 * TODO: Queue up this address for hwpoisioning later. 416 * TODO: Queue up this address for hwpoisioning later.
415 */ 417 */
416 if (user_mode(regs) && !is_global_init(current)) {
417 _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
418 recovered = 1;
419 } else
420 recovered = 0;
421 } else if (user_mode(regs) && !is_global_init(current) &&
422 evt->severity == MCE_SEV_ERROR_SYNC) {
423 /*
424 * If we have received a synchronous error when in userspace
425 * kill the task.
426 */
427 _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); 418 _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
428 recovered = 1; 419 recovered = 1;
429 } 420 }
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 6901a06da2f9..e36738291c32 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1775,17 +1775,20 @@ static u64 pnv_pci_ioda_dma_get_required_mask(struct pci_dev *pdev)
1775} 1775}
1776 1776
1777static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, 1777static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe,
1778 struct pci_bus *bus) 1778 struct pci_bus *bus,
1779 bool add_to_group)
1779{ 1780{
1780 struct pci_dev *dev; 1781 struct pci_dev *dev;
1781 1782
1782 list_for_each_entry(dev, &bus->devices, bus_list) { 1783 list_for_each_entry(dev, &bus->devices, bus_list) {
1783 set_iommu_table_base(&dev->dev, pe->table_group.tables[0]); 1784 set_iommu_table_base(&dev->dev, pe->table_group.tables[0]);
1784 set_dma_offset(&dev->dev, pe->tce_bypass_base); 1785 set_dma_offset(&dev->dev, pe->tce_bypass_base);
1785 iommu_add_device(&dev->dev); 1786 if (add_to_group)
1787 iommu_add_device(&dev->dev);
1786 1788
1787 if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate) 1789 if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate)
1788 pnv_ioda_setup_bus_dma(pe, dev->subordinate); 1790 pnv_ioda_setup_bus_dma(pe, dev->subordinate,
1791 add_to_group);
1789 } 1792 }
1790} 1793}
1791 1794
@@ -2191,7 +2194,7 @@ found:
2191 set_iommu_table_base(&pe->pdev->dev, tbl); 2194 set_iommu_table_base(&pe->pdev->dev, tbl);
2192 iommu_add_device(&pe->pdev->dev); 2195 iommu_add_device(&pe->pdev->dev);
2193 } else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL)) 2196 } else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL))
2194 pnv_ioda_setup_bus_dma(pe, pe->pbus); 2197 pnv_ioda_setup_bus_dma(pe, pe->pbus, true);
2195 2198
2196 return; 2199 return;
2197 fail: 2200 fail:
@@ -2426,6 +2429,8 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group)
2426 2429
2427 pnv_pci_ioda2_set_bypass(pe, false); 2430 pnv_pci_ioda2_set_bypass(pe, false);
2428 pnv_pci_ioda2_unset_window(&pe->table_group, 0); 2431 pnv_pci_ioda2_unset_window(&pe->table_group, 0);
2432 if (pe->pbus)
2433 pnv_ioda_setup_bus_dma(pe, pe->pbus, false);
2429 pnv_ioda2_table_free(tbl); 2434 pnv_ioda2_table_free(tbl);
2430} 2435}
2431 2436
@@ -2435,6 +2440,8 @@ static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group)
2435 table_group); 2440 table_group);
2436 2441
2437 pnv_pci_ioda2_setup_default_config(pe); 2442 pnv_pci_ioda2_setup_default_config(pe);
2443 if (pe->pbus)
2444 pnv_ioda_setup_bus_dma(pe, pe->pbus, false);
2438} 2445}
2439 2446
2440static struct iommu_table_group_ops pnv_pci_ioda2_ops = { 2447static struct iommu_table_group_ops pnv_pci_ioda2_ops = {
@@ -2624,6 +2631,9 @@ static long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
2624 level_shift = entries_shift + 3; 2631 level_shift = entries_shift + 3;
2625 level_shift = max_t(unsigned, level_shift, PAGE_SHIFT); 2632 level_shift = max_t(unsigned, level_shift, PAGE_SHIFT);
2626 2633
2634 if ((level_shift - 3) * levels + page_shift >= 60)
2635 return -EINVAL;
2636
2627 /* Allocate TCE table */ 2637 /* Allocate TCE table */
2628 addr = pnv_pci_ioda2_table_do_alloc_pages(nid, level_shift, 2638 addr = pnv_pci_ioda2_table_do_alloc_pages(nid, level_shift,
2629 levels, tce_table_size, &offset, &total_allocated); 2639 levels, tce_table_size, &offset, &total_allocated);
@@ -2728,7 +2738,7 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
2728 if (pe->flags & PNV_IODA_PE_DEV) 2738 if (pe->flags & PNV_IODA_PE_DEV)
2729 iommu_add_device(&pe->pdev->dev); 2739 iommu_add_device(&pe->pdev->dev);
2730 else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL)) 2740 else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL))
2731 pnv_ioda_setup_bus_dma(pe, pe->pbus); 2741 pnv_ioda_setup_bus_dma(pe, pe->pbus, true);
2732} 2742}
2733 2743
2734#ifdef CONFIG_PCI_MSI 2744#ifdef CONFIG_PCI_MSI
diff --git a/block/bio.c b/block/bio.c
index 5eec5e08417f..e75878f8b14a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -376,10 +376,14 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
376 bio_list_init(&punt); 376 bio_list_init(&punt);
377 bio_list_init(&nopunt); 377 bio_list_init(&nopunt);
378 378
379 while ((bio = bio_list_pop(current->bio_list))) 379 while ((bio = bio_list_pop(&current->bio_list[0])))
380 bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio); 380 bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
381 current->bio_list[0] = nopunt;
381 382
382 *current->bio_list = nopunt; 383 bio_list_init(&nopunt);
384 while ((bio = bio_list_pop(&current->bio_list[1])))
385 bio_list_add(bio->bi_pool == bs ? &punt : &nopunt, bio);
386 current->bio_list[1] = nopunt;
383 387
384 spin_lock(&bs->rescue_lock); 388 spin_lock(&bs->rescue_lock);
385 bio_list_merge(&bs->rescue_list, &punt); 389 bio_list_merge(&bs->rescue_list, &punt);
@@ -466,7 +470,9 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
466 * we retry with the original gfp_flags. 470 * we retry with the original gfp_flags.
467 */ 471 */
468 472
469 if (current->bio_list && !bio_list_empty(current->bio_list)) 473 if (current->bio_list &&
474 (!bio_list_empty(&current->bio_list[0]) ||
475 !bio_list_empty(&current->bio_list[1])))
470 gfp_mask &= ~__GFP_DIRECT_RECLAIM; 476 gfp_mask &= ~__GFP_DIRECT_RECLAIM;
471 477
472 p = mempool_alloc(bs->bio_pool, gfp_mask); 478 p = mempool_alloc(bs->bio_pool, gfp_mask);
diff --git a/block/blk-core.c b/block/blk-core.c
index 0eeb99ef654f..d772c221cc17 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1973,7 +1973,14 @@ end_io:
1973 */ 1973 */
1974blk_qc_t generic_make_request(struct bio *bio) 1974blk_qc_t generic_make_request(struct bio *bio)
1975{ 1975{
1976 struct bio_list bio_list_on_stack; 1976 /*
1977 * bio_list_on_stack[0] contains bios submitted by the current
1978 * make_request_fn.
1979 * bio_list_on_stack[1] contains bios that were submitted before
1980 * the current make_request_fn, but that haven't been processed
1981 * yet.
1982 */
1983 struct bio_list bio_list_on_stack[2];
1977 blk_qc_t ret = BLK_QC_T_NONE; 1984 blk_qc_t ret = BLK_QC_T_NONE;
1978 1985
1979 if (!generic_make_request_checks(bio)) 1986 if (!generic_make_request_checks(bio))
@@ -1990,7 +1997,7 @@ blk_qc_t generic_make_request(struct bio *bio)
1990 * should be added at the tail 1997 * should be added at the tail
1991 */ 1998 */
1992 if (current->bio_list) { 1999 if (current->bio_list) {
1993 bio_list_add(current->bio_list, bio); 2000 bio_list_add(&current->bio_list[0], bio);
1994 goto out; 2001 goto out;
1995 } 2002 }
1996 2003
@@ -2009,18 +2016,17 @@ blk_qc_t generic_make_request(struct bio *bio)
2009 * bio_list, and call into ->make_request() again. 2016 * bio_list, and call into ->make_request() again.
2010 */ 2017 */
2011 BUG_ON(bio->bi_next); 2018 BUG_ON(bio->bi_next);
2012 bio_list_init(&bio_list_on_stack); 2019 bio_list_init(&bio_list_on_stack[0]);
2013 current->bio_list = &bio_list_on_stack; 2020 current->bio_list = bio_list_on_stack;
2014 do { 2021 do {
2015 struct request_queue *q = bdev_get_queue(bio->bi_bdev); 2022 struct request_queue *q = bdev_get_queue(bio->bi_bdev);
2016 2023
2017 if (likely(blk_queue_enter(q, false) == 0)) { 2024 if (likely(blk_queue_enter(q, false) == 0)) {
2018 struct bio_list hold;
2019 struct bio_list lower, same; 2025 struct bio_list lower, same;
2020 2026
2021 /* Create a fresh bio_list for all subordinate requests */ 2027 /* Create a fresh bio_list for all subordinate requests */
2022 hold = bio_list_on_stack; 2028 bio_list_on_stack[1] = bio_list_on_stack[0];
2023 bio_list_init(&bio_list_on_stack); 2029 bio_list_init(&bio_list_on_stack[0]);
2024 ret = q->make_request_fn(q, bio); 2030 ret = q->make_request_fn(q, bio);
2025 2031
2026 blk_queue_exit(q); 2032 blk_queue_exit(q);
@@ -2030,19 +2036,19 @@ blk_qc_t generic_make_request(struct bio *bio)
2030 */ 2036 */
2031 bio_list_init(&lower); 2037 bio_list_init(&lower);
2032 bio_list_init(&same); 2038 bio_list_init(&same);
2033 while ((bio = bio_list_pop(&bio_list_on_stack)) != NULL) 2039 while ((bio = bio_list_pop(&bio_list_on_stack[0])) != NULL)
2034 if (q == bdev_get_queue(bio->bi_bdev)) 2040 if (q == bdev_get_queue(bio->bi_bdev))
2035 bio_list_add(&same, bio); 2041 bio_list_add(&same, bio);
2036 else 2042 else
2037 bio_list_add(&lower, bio); 2043 bio_list_add(&lower, bio);
2038 /* now assemble so we handle the lowest level first */ 2044 /* now assemble so we handle the lowest level first */
2039 bio_list_merge(&bio_list_on_stack, &lower); 2045 bio_list_merge(&bio_list_on_stack[0], &lower);
2040 bio_list_merge(&bio_list_on_stack, &same); 2046 bio_list_merge(&bio_list_on_stack[0], &same);
2041 bio_list_merge(&bio_list_on_stack, &hold); 2047 bio_list_merge(&bio_list_on_stack[0], &bio_list_on_stack[1]);
2042 } else { 2048 } else {
2043 bio_io_error(bio); 2049 bio_io_error(bio);
2044 } 2050 }
2045 bio = bio_list_pop(current->bio_list); 2051 bio = bio_list_pop(&bio_list_on_stack[0]);
2046 } while (bio); 2052 } while (bio);
2047 current->bio_list = NULL; /* deactivate */ 2053 current->bio_list = NULL; /* deactivate */
2048 2054
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index e48bc2c72615..9d97bfc4d465 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -295,6 +295,9 @@ int blk_mq_reinit_tagset(struct blk_mq_tag_set *set)
295 for (i = 0; i < set->nr_hw_queues; i++) { 295 for (i = 0; i < set->nr_hw_queues; i++) {
296 struct blk_mq_tags *tags = set->tags[i]; 296 struct blk_mq_tags *tags = set->tags[i];
297 297
298 if (!tags)
299 continue;
300
298 for (j = 0; j < tags->nr_tags; j++) { 301 for (j = 0; j < tags->nr_tags; j++) {
299 if (!tags->static_rqs[j]) 302 if (!tags->static_rqs[j])
300 continue; 303 continue;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 159187a28d66..a4546f060e80 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1434,7 +1434,8 @@ static blk_qc_t request_to_qc_t(struct blk_mq_hw_ctx *hctx, struct request *rq)
1434 return blk_tag_to_qc_t(rq->internal_tag, hctx->queue_num, true); 1434 return blk_tag_to_qc_t(rq->internal_tag, hctx->queue_num, true);
1435} 1435}
1436 1436
1437static void blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie) 1437static void blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie,
1438 bool may_sleep)
1438{ 1439{
1439 struct request_queue *q = rq->q; 1440 struct request_queue *q = rq->q;
1440 struct blk_mq_queue_data bd = { 1441 struct blk_mq_queue_data bd = {
@@ -1475,7 +1476,7 @@ static void blk_mq_try_issue_directly(struct request *rq, blk_qc_t *cookie)
1475 } 1476 }
1476 1477
1477insert: 1478insert:
1478 blk_mq_sched_insert_request(rq, false, true, true, false); 1479 blk_mq_sched_insert_request(rq, false, true, false, may_sleep);
1479} 1480}
1480 1481
1481/* 1482/*
@@ -1569,11 +1570,11 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
1569 1570
1570 if (!(data.hctx->flags & BLK_MQ_F_BLOCKING)) { 1571 if (!(data.hctx->flags & BLK_MQ_F_BLOCKING)) {
1571 rcu_read_lock(); 1572 rcu_read_lock();
1572 blk_mq_try_issue_directly(old_rq, &cookie); 1573 blk_mq_try_issue_directly(old_rq, &cookie, false);
1573 rcu_read_unlock(); 1574 rcu_read_unlock();
1574 } else { 1575 } else {
1575 srcu_idx = srcu_read_lock(&data.hctx->queue_rq_srcu); 1576 srcu_idx = srcu_read_lock(&data.hctx->queue_rq_srcu);
1576 blk_mq_try_issue_directly(old_rq, &cookie); 1577 blk_mq_try_issue_directly(old_rq, &cookie, true);
1577 srcu_read_unlock(&data.hctx->queue_rq_srcu, srcu_idx); 1578 srcu_read_unlock(&data.hctx->queue_rq_srcu, srcu_idx);
1578 } 1579 }
1579 goto done; 1580 goto done;
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index f5e18c2a4852..690deca17c35 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -266,7 +266,7 @@ unlock:
266 return err; 266 return err;
267} 267}
268 268
269int af_alg_accept(struct sock *sk, struct socket *newsock) 269int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
270{ 270{
271 struct alg_sock *ask = alg_sk(sk); 271 struct alg_sock *ask = alg_sk(sk);
272 const struct af_alg_type *type; 272 const struct af_alg_type *type;
@@ -281,7 +281,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
281 if (!type) 281 if (!type)
282 goto unlock; 282 goto unlock;
283 283
284 sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, 0); 284 sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, kern);
285 err = -ENOMEM; 285 err = -ENOMEM;
286 if (!sk2) 286 if (!sk2)
287 goto unlock; 287 goto unlock;
@@ -323,9 +323,10 @@ unlock:
323} 323}
324EXPORT_SYMBOL_GPL(af_alg_accept); 324EXPORT_SYMBOL_GPL(af_alg_accept);
325 325
326static int alg_accept(struct socket *sock, struct socket *newsock, int flags) 326static int alg_accept(struct socket *sock, struct socket *newsock, int flags,
327 bool kern)
327{ 328{
328 return af_alg_accept(sock->sk, newsock); 329 return af_alg_accept(sock->sk, newsock, kern);
329} 330}
330 331
331static const struct proto_ops alg_proto_ops = { 332static const struct proto_ops alg_proto_ops = {
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 54fc90e8339c..5e92bd275ef3 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -239,7 +239,8 @@ unlock:
239 return err ?: len; 239 return err ?: len;
240} 240}
241 241
242static int hash_accept(struct socket *sock, struct socket *newsock, int flags) 242static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
243 bool kern)
243{ 244{
244 struct sock *sk = sock->sk; 245 struct sock *sk = sock->sk;
245 struct alg_sock *ask = alg_sk(sk); 246 struct alg_sock *ask = alg_sk(sk);
@@ -260,7 +261,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
260 if (err) 261 if (err)
261 return err; 262 return err;
262 263
263 err = af_alg_accept(ask->parent, newsock); 264 err = af_alg_accept(ask->parent, newsock, kern);
264 if (err) 265 if (err)
265 return err; 266 return err;
266 267
@@ -378,7 +379,7 @@ static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
378} 379}
379 380
380static int hash_accept_nokey(struct socket *sock, struct socket *newsock, 381static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
381 int flags) 382 int flags, bool kern)
382{ 383{
383 int err; 384 int err;
384 385
@@ -386,7 +387,7 @@ static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
386 if (err) 387 if (err)
387 return err; 388 return err;
388 389
389 return hash_accept(sock, newsock, flags); 390 return hash_accept(sock, newsock, flags, kern);
390} 391}
391 392
392static struct proto_ops algif_hash_ops_nokey = { 393static struct proto_ops algif_hash_ops_nokey = {
diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c
index 85d833289f28..4c96f3ac4976 100644
--- a/drivers/ata/ahci_qoriq.c
+++ b/drivers/ata/ahci_qoriq.c
@@ -177,7 +177,8 @@ static int ahci_qoriq_phy_init(struct ahci_host_priv *hpriv)
177 case AHCI_LS1043A: 177 case AHCI_LS1043A:
178 if (!qpriv->ecc_addr) 178 if (!qpriv->ecc_addr)
179 return -EINVAL; 179 return -EINVAL;
180 writel(ECC_DIS_ARMV8_CH2, qpriv->ecc_addr); 180 writel(readl(qpriv->ecc_addr) | ECC_DIS_ARMV8_CH2,
181 qpriv->ecc_addr);
181 writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); 182 writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1);
182 writel(AHCI_PORT_TRANS_CFG, reg_base + PORT_TRANS); 183 writel(AHCI_PORT_TRANS_CFG, reg_base + PORT_TRANS);
183 if (qpriv->is_dmacoherent) 184 if (qpriv->is_dmacoherent)
@@ -194,7 +195,8 @@ static int ahci_qoriq_phy_init(struct ahci_host_priv *hpriv)
194 case AHCI_LS1046A: 195 case AHCI_LS1046A:
195 if (!qpriv->ecc_addr) 196 if (!qpriv->ecc_addr)
196 return -EINVAL; 197 return -EINVAL;
197 writel(ECC_DIS_ARMV8_CH2, qpriv->ecc_addr); 198 writel(readl(qpriv->ecc_addr) | ECC_DIS_ARMV8_CH2,
199 qpriv->ecc_addr);
198 writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); 200 writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1);
199 writel(AHCI_PORT_TRANS_CFG, reg_base + PORT_TRANS); 201 writel(AHCI_PORT_TRANS_CFG, reg_base + PORT_TRANS);
200 if (qpriv->is_dmacoherent) 202 if (qpriv->is_dmacoherent)
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 2bd92dca3e62..274d6d7193d7 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1482,7 +1482,6 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1482 break; 1482 break;
1483 1483
1484 default: 1484 default:
1485 WARN_ON_ONCE(1);
1486 return AC_ERR_SYSTEM; 1485 return AC_ERR_SYSTEM;
1487 } 1486 }
1488 1487
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index 46698232e6bf..19e6e539a061 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -224,7 +224,6 @@ static DECLARE_TRANSPORT_CLASS(ata_port_class,
224 224
225static void ata_tport_release(struct device *dev) 225static void ata_tport_release(struct device *dev)
226{ 226{
227 put_device(dev->parent);
228} 227}
229 228
230/** 229/**
@@ -284,7 +283,7 @@ int ata_tport_add(struct device *parent,
284 device_initialize(dev); 283 device_initialize(dev);
285 dev->type = &ata_port_type; 284 dev->type = &ata_port_type;
286 285
287 dev->parent = get_device(parent); 286 dev->parent = parent;
288 dev->release = ata_tport_release; 287 dev->release = ata_tport_release;
289 dev_set_name(dev, "ata%d", ap->print_id); 288 dev_set_name(dev, "ata%d", ap->print_id);
290 transport_setup_device(dev); 289 transport_setup_device(dev);
@@ -348,7 +347,6 @@ static DECLARE_TRANSPORT_CLASS(ata_link_class,
348 347
349static void ata_tlink_release(struct device *dev) 348static void ata_tlink_release(struct device *dev)
350{ 349{
351 put_device(dev->parent);
352} 350}
353 351
354/** 352/**
@@ -410,7 +408,7 @@ int ata_tlink_add(struct ata_link *link)
410 int error; 408 int error;
411 409
412 device_initialize(dev); 410 device_initialize(dev);
413 dev->parent = get_device(&ap->tdev); 411 dev->parent = &ap->tdev;
414 dev->release = ata_tlink_release; 412 dev->release = ata_tlink_release;
415 if (ata_is_host_link(link)) 413 if (ata_is_host_link(link))
416 dev_set_name(dev, "link%d", ap->print_id); 414 dev_set_name(dev, "link%d", ap->print_id);
@@ -589,7 +587,6 @@ static DECLARE_TRANSPORT_CLASS(ata_dev_class,
589 587
590static void ata_tdev_release(struct device *dev) 588static void ata_tdev_release(struct device *dev)
591{ 589{
592 put_device(dev->parent);
593} 590}
594 591
595/** 592/**
@@ -662,7 +659,7 @@ static int ata_tdev_add(struct ata_device *ata_dev)
662 int error; 659 int error;
663 660
664 device_initialize(dev); 661 device_initialize(dev);
665 dev->parent = get_device(&link->tdev); 662 dev->parent = &link->tdev;
666 dev->release = ata_tdev_release; 663 dev->release = ata_tdev_release;
667 if (ata_is_host_link(link)) 664 if (ata_is_host_link(link))
668 dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno); 665 dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 3ad86fdf954e..b1ad12552b56 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -397,9 +397,8 @@ static int of_get_omap_rng_device_details(struct omap_rng_dev *priv,
397 irq, err); 397 irq, err);
398 return err; 398 return err;
399 } 399 }
400 omap_rng_write(priv, RNG_INTMASK_REG, RNG_SHUTDOWN_OFLO_MASK);
401 400
402 priv->clk = of_clk_get(pdev->dev.of_node, 0); 401 priv->clk = devm_clk_get(&pdev->dev, NULL);
403 if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER) 402 if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -EPROBE_DEFER)
404 return -EPROBE_DEFER; 403 return -EPROBE_DEFER;
405 if (!IS_ERR(priv->clk)) { 404 if (!IS_ERR(priv->clk)) {
@@ -408,6 +407,19 @@ static int of_get_omap_rng_device_details(struct omap_rng_dev *priv,
408 dev_err(&pdev->dev, "unable to enable the clk, " 407 dev_err(&pdev->dev, "unable to enable the clk, "
409 "err = %d\n", err); 408 "err = %d\n", err);
410 } 409 }
410
411 /*
412 * On OMAP4, enabling the shutdown_oflo interrupt is
413 * done in the interrupt mask register. There is no
414 * such register on EIP76, and it's enabled by the
415 * same bit in the control register
416 */
417 if (priv->pdata->regs[RNG_INTMASK_REG])
418 omap_rng_write(priv, RNG_INTMASK_REG,
419 RNG_SHUTDOWN_OFLO_MASK);
420 else
421 omap_rng_write(priv, RNG_CONTROL_REG,
422 RNG_SHUTDOWN_OFLO_MASK);
411 } 423 }
412 return 0; 424 return 0;
413} 425}
diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
index dce1af0ce85c..1b9da3dc799b 100644
--- a/drivers/crypto/s5p-sss.c
+++ b/drivers/crypto/s5p-sss.c
@@ -270,7 +270,7 @@ static void s5p_sg_copy_buf(void *buf, struct scatterlist *sg,
270 scatterwalk_done(&walk, out, 0); 270 scatterwalk_done(&walk, out, 0);
271} 271}
272 272
273static void s5p_aes_complete(struct s5p_aes_dev *dev, int err) 273static void s5p_sg_done(struct s5p_aes_dev *dev)
274{ 274{
275 if (dev->sg_dst_cpy) { 275 if (dev->sg_dst_cpy) {
276 dev_dbg(dev->dev, 276 dev_dbg(dev->dev,
@@ -281,8 +281,11 @@ static void s5p_aes_complete(struct s5p_aes_dev *dev, int err)
281 } 281 }
282 s5p_free_sg_cpy(dev, &dev->sg_src_cpy); 282 s5p_free_sg_cpy(dev, &dev->sg_src_cpy);
283 s5p_free_sg_cpy(dev, &dev->sg_dst_cpy); 283 s5p_free_sg_cpy(dev, &dev->sg_dst_cpy);
284}
284 285
285 /* holding a lock outside */ 286/* Calls the completion. Cannot be called with dev->lock hold. */
287static void s5p_aes_complete(struct s5p_aes_dev *dev, int err)
288{
286 dev->req->base.complete(&dev->req->base, err); 289 dev->req->base.complete(&dev->req->base, err);
287 dev->busy = false; 290 dev->busy = false;
288} 291}
@@ -368,51 +371,44 @@ exit:
368} 371}
369 372
370/* 373/*
371 * Returns true if new transmitting (output) data is ready and its 374 * Returns -ERRNO on error (mapping of new data failed).
372 * address+length have to be written to device (by calling 375 * On success returns:
373 * s5p_set_dma_outdata()). False otherwise. 376 * - 0 if there is no more data,
377 * - 1 if new transmitting (output) data is ready and its address+length
378 * have to be written to device (by calling s5p_set_dma_outdata()).
374 */ 379 */
375static bool s5p_aes_tx(struct s5p_aes_dev *dev) 380static int s5p_aes_tx(struct s5p_aes_dev *dev)
376{ 381{
377 int err = 0; 382 int ret = 0;
378 bool ret = false;
379 383
380 s5p_unset_outdata(dev); 384 s5p_unset_outdata(dev);
381 385
382 if (!sg_is_last(dev->sg_dst)) { 386 if (!sg_is_last(dev->sg_dst)) {
383 err = s5p_set_outdata(dev, sg_next(dev->sg_dst)); 387 ret = s5p_set_outdata(dev, sg_next(dev->sg_dst));
384 if (err) 388 if (!ret)
385 s5p_aes_complete(dev, err); 389 ret = 1;
386 else
387 ret = true;
388 } else {
389 s5p_aes_complete(dev, err);
390
391 dev->busy = true;
392 tasklet_schedule(&dev->tasklet);
393 } 390 }
394 391
395 return ret; 392 return ret;
396} 393}
397 394
398/* 395/*
399 * Returns true if new receiving (input) data is ready and its 396 * Returns -ERRNO on error (mapping of new data failed).
400 * address+length have to be written to device (by calling 397 * On success returns:
401 * s5p_set_dma_indata()). False otherwise. 398 * - 0 if there is no more data,
399 * - 1 if new receiving (input) data is ready and its address+length
400 * have to be written to device (by calling s5p_set_dma_indata()).
402 */ 401 */
403static bool s5p_aes_rx(struct s5p_aes_dev *dev) 402static int s5p_aes_rx(struct s5p_aes_dev *dev/*, bool *set_dma*/)
404{ 403{
405 int err; 404 int ret = 0;
406 bool ret = false;
407 405
408 s5p_unset_indata(dev); 406 s5p_unset_indata(dev);
409 407
410 if (!sg_is_last(dev->sg_src)) { 408 if (!sg_is_last(dev->sg_src)) {
411 err = s5p_set_indata(dev, sg_next(dev->sg_src)); 409 ret = s5p_set_indata(dev, sg_next(dev->sg_src));
412 if (err) 410 if (!ret)
413 s5p_aes_complete(dev, err); 411 ret = 1;
414 else
415 ret = true;
416 } 412 }
417 413
418 return ret; 414 return ret;
@@ -422,33 +418,73 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id)
422{ 418{
423 struct platform_device *pdev = dev_id; 419 struct platform_device *pdev = dev_id;
424 struct s5p_aes_dev *dev = platform_get_drvdata(pdev); 420 struct s5p_aes_dev *dev = platform_get_drvdata(pdev);
425 bool set_dma_tx = false; 421 int err_dma_tx = 0;
426 bool set_dma_rx = false; 422 int err_dma_rx = 0;
423 bool tx_end = false;
427 unsigned long flags; 424 unsigned long flags;
428 uint32_t status; 425 uint32_t status;
426 int err;
429 427
430 spin_lock_irqsave(&dev->lock, flags); 428 spin_lock_irqsave(&dev->lock, flags);
431 429
430 /*
431 * Handle rx or tx interrupt. If there is still data (scatterlist did not
432 * reach end), then map next scatterlist entry.
433 * In case of such mapping error, s5p_aes_complete() should be called.
434 *
435 * If there is no more data in tx scatter list, call s5p_aes_complete()
436 * and schedule new tasklet.
437 */
432 status = SSS_READ(dev, FCINTSTAT); 438 status = SSS_READ(dev, FCINTSTAT);
433 if (status & SSS_FCINTSTAT_BRDMAINT) 439 if (status & SSS_FCINTSTAT_BRDMAINT)
434 set_dma_rx = s5p_aes_rx(dev); 440 err_dma_rx = s5p_aes_rx(dev);
435 if (status & SSS_FCINTSTAT_BTDMAINT) 441
436 set_dma_tx = s5p_aes_tx(dev); 442 if (status & SSS_FCINTSTAT_BTDMAINT) {
443 if (sg_is_last(dev->sg_dst))
444 tx_end = true;
445 err_dma_tx = s5p_aes_tx(dev);
446 }
437 447
438 SSS_WRITE(dev, FCINTPEND, status); 448 SSS_WRITE(dev, FCINTPEND, status);
439 449
440 /* 450 if (err_dma_rx < 0) {
441 * Writing length of DMA block (either receiving or transmitting) 451 err = err_dma_rx;
442 * will start the operation immediately, so this should be done 452 goto error;
443 * at the end (even after clearing pending interrupts to not miss the 453 }
444 * interrupt). 454 if (err_dma_tx < 0) {
445 */ 455 err = err_dma_tx;
446 if (set_dma_tx) 456 goto error;
447 s5p_set_dma_outdata(dev, dev->sg_dst); 457 }
448 if (set_dma_rx) 458
449 s5p_set_dma_indata(dev, dev->sg_src); 459 if (tx_end) {
460 s5p_sg_done(dev);
461
462 spin_unlock_irqrestore(&dev->lock, flags);
463
464 s5p_aes_complete(dev, 0);
465 dev->busy = true;
466 tasklet_schedule(&dev->tasklet);
467 } else {
468 /*
469 * Writing length of DMA block (either receiving or
470 * transmitting) will start the operation immediately, so this
471 * should be done at the end (even after clearing pending
472 * interrupts to not miss the interrupt).
473 */
474 if (err_dma_tx == 1)
475 s5p_set_dma_outdata(dev, dev->sg_dst);
476 if (err_dma_rx == 1)
477 s5p_set_dma_indata(dev, dev->sg_src);
450 478
479 spin_unlock_irqrestore(&dev->lock, flags);
480 }
481
482 return IRQ_HANDLED;
483
484error:
485 s5p_sg_done(dev);
451 spin_unlock_irqrestore(&dev->lock, flags); 486 spin_unlock_irqrestore(&dev->lock, flags);
487 s5p_aes_complete(dev, err);
452 488
453 return IRQ_HANDLED; 489 return IRQ_HANDLED;
454} 490}
@@ -597,8 +633,9 @@ outdata_error:
597 s5p_unset_indata(dev); 633 s5p_unset_indata(dev);
598 634
599indata_error: 635indata_error:
600 s5p_aes_complete(dev, err); 636 s5p_sg_done(dev);
601 spin_unlock_irqrestore(&dev->lock, flags); 637 spin_unlock_irqrestore(&dev->lock, flags);
638 s5p_aes_complete(dev, err);
602} 639}
603 640
604static void s5p_tasklet_cb(unsigned long data) 641static void s5p_tasklet_cb(unsigned long data)
@@ -805,8 +842,9 @@ static int s5p_aes_probe(struct platform_device *pdev)
805 dev_warn(dev, "feed control interrupt is not available.\n"); 842 dev_warn(dev, "feed control interrupt is not available.\n");
806 goto err_irq; 843 goto err_irq;
807 } 844 }
808 err = devm_request_irq(dev, pdata->irq_fc, s5p_aes_interrupt, 845 err = devm_request_threaded_irq(dev, pdata->irq_fc, NULL,
809 IRQF_SHARED, pdev->name, pdev); 846 s5p_aes_interrupt, IRQF_ONESHOT,
847 pdev->name, pdev);
810 if (err < 0) { 848 if (err < 0) {
811 dev_warn(dev, "feed control interrupt is not available.\n"); 849 dev_warn(dev, "feed control interrupt is not available.\n");
812 goto err_irq; 850 goto err_irq;
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 11e13c56126f..2da3ff650e1d 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -2317,6 +2317,9 @@ static int gigaset_probe(struct usb_interface *interface,
2317 return -ENODEV; 2317 return -ENODEV;
2318 } 2318 }
2319 2319
2320 if (hostif->desc.bNumEndpoints < 1)
2321 return -ENODEV;
2322
2320 dev_info(&udev->dev, 2323 dev_info(&udev->dev,
2321 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n", 2324 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
2322 __func__, le16_to_cpu(udev->descriptor.idVendor), 2325 __func__, le16_to_cpu(udev->descriptor.idVendor),
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 3f041b187033..f757cef293f8 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -392,6 +392,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
392 * To get all the fields, copy all archdata 392 * To get all the fields, copy all archdata
393 */ 393 */
394 dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata; 394 dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
395 dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops;
395#endif /* CONFIG_PCI */ 396#endif /* CONFIG_PCI */
396 397
397#ifdef DEBUG 398#ifdef DEBUG
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f4ffd1eb8f44..dfb75979e455 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -989,26 +989,29 @@ static void flush_current_bio_list(struct blk_plug_cb *cb, bool from_schedule)
989 struct dm_offload *o = container_of(cb, struct dm_offload, cb); 989 struct dm_offload *o = container_of(cb, struct dm_offload, cb);
990 struct bio_list list; 990 struct bio_list list;
991 struct bio *bio; 991 struct bio *bio;
992 int i;
992 993
993 INIT_LIST_HEAD(&o->cb.list); 994 INIT_LIST_HEAD(&o->cb.list);
994 995
995 if (unlikely(!current->bio_list)) 996 if (unlikely(!current->bio_list))
996 return; 997 return;
997 998
998 list = *current->bio_list; 999 for (i = 0; i < 2; i++) {
999 bio_list_init(current->bio_list); 1000 list = current->bio_list[i];
1000 1001 bio_list_init(&current->bio_list[i]);
1001 while ((bio = bio_list_pop(&list))) { 1002
1002 struct bio_set *bs = bio->bi_pool; 1003 while ((bio = bio_list_pop(&list))) {
1003 if (unlikely(!bs) || bs == fs_bio_set) { 1004 struct bio_set *bs = bio->bi_pool;
1004 bio_list_add(current->bio_list, bio); 1005 if (unlikely(!bs) || bs == fs_bio_set) {
1005 continue; 1006 bio_list_add(&current->bio_list[i], bio);
1007 continue;
1008 }
1009
1010 spin_lock(&bs->rescue_lock);
1011 bio_list_add(&bs->rescue_list, bio);
1012 queue_work(bs->rescue_workqueue, &bs->rescue_work);
1013 spin_unlock(&bs->rescue_lock);
1006 } 1014 }
1007
1008 spin_lock(&bs->rescue_lock);
1009 bio_list_add(&bs->rescue_list, bio);
1010 queue_work(bs->rescue_workqueue, &bs->rescue_work);
1011 spin_unlock(&bs->rescue_lock);
1012 } 1015 }
1013} 1016}
1014 1017
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 063c43d83b72..0536658c9d40 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -974,7 +974,8 @@ static void wait_barrier(struct r10conf *conf)
974 !conf->barrier || 974 !conf->barrier ||
975 (atomic_read(&conf->nr_pending) && 975 (atomic_read(&conf->nr_pending) &&
976 current->bio_list && 976 current->bio_list &&
977 !bio_list_empty(current->bio_list)), 977 (!bio_list_empty(&current->bio_list[0]) ||
978 !bio_list_empty(&current->bio_list[1]))),
978 conf->resync_lock); 979 conf->resync_lock);
979 conf->nr_waiting--; 980 conf->nr_waiting--;
980 if (!conf->nr_waiting) 981 if (!conf->nr_waiting)
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index 248f60d171a5..ffea9859f5a7 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -2272,10 +2272,7 @@ static int xgbe_one_poll(struct napi_struct *napi, int budget)
2272 processed = xgbe_rx_poll(channel, budget); 2272 processed = xgbe_rx_poll(channel, budget);
2273 2273
2274 /* If we processed everything, we are done */ 2274 /* If we processed everything, we are done */
2275 if (processed < budget) { 2275 if ((processed < budget) && napi_complete_done(napi, processed)) {
2276 /* Turn off polling */
2277 napi_complete_done(napi, processed);
2278
2279 /* Enable Tx and Rx interrupts */ 2276 /* Enable Tx and Rx interrupts */
2280 if (pdata->channel_irq_mode) 2277 if (pdata->channel_irq_mode)
2281 xgbe_enable_rx_tx_int(pdata, channel); 2278 xgbe_enable_rx_tx_int(pdata, channel);
@@ -2317,10 +2314,7 @@ static int xgbe_all_poll(struct napi_struct *napi, int budget)
2317 } while ((processed < budget) && (processed != last_processed)); 2314 } while ((processed < budget) && (processed != last_processed));
2318 2315
2319 /* If we processed everything, we are done */ 2316 /* If we processed everything, we are done */
2320 if (processed < budget) { 2317 if ((processed < budget) && napi_complete_done(napi, processed)) {
2321 /* Turn off polling */
2322 napi_complete_done(napi, processed);
2323
2324 /* Enable Tx and Rx interrupts */ 2318 /* Enable Tx and Rx interrupts */
2325 xgbe_enable_rx_tx_ints(pdata); 2319 xgbe_enable_rx_tx_ints(pdata);
2326 } 2320 }
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
index 581de71a958a..4c6c882c6a1c 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
@@ -213,9 +213,9 @@ void aq_pci_func_free_irqs(struct aq_pci_func_s *self)
213 if (!((1U << i) & self->msix_entry_mask)) 213 if (!((1U << i) & self->msix_entry_mask))
214 continue; 214 continue;
215 215
216 free_irq(pci_irq_vector(pdev, i), self->aq_vec[i]);
217 if (pdev->msix_enabled) 216 if (pdev->msix_enabled)
218 irq_set_affinity_hint(pci_irq_vector(pdev, i), NULL); 217 irq_set_affinity_hint(pci_irq_vector(pdev, i), NULL);
218 free_irq(pci_irq_vector(pdev, i), self->aq_vec[i]);
219 self->msix_entry_mask &= ~(1U << i); 219 self->msix_entry_mask &= ~(1U << i);
220 } 220 }
221} 221}
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index d8d06fdfc42b..ac76fc251d26 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13292,17 +13292,15 @@ static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
13292 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 13292 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
13293 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; 13293 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
13294 13294
13295 /* VF with OLD Hypervisor or old PF do not support filtering */
13296 if (IS_PF(bp)) { 13295 if (IS_PF(bp)) {
13297 if (chip_is_e1x) 13296 if (chip_is_e1x)
13298 bp->accept_any_vlan = true; 13297 bp->accept_any_vlan = true;
13299 else 13298 else
13300 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; 13299 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
13301#ifdef CONFIG_BNX2X_SRIOV
13302 } else if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
13303 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
13304#endif
13305 } 13300 }
13301 /* For VF we'll know whether to enable VLAN filtering after
13302 * getting a response to CHANNEL_TLV_ACQUIRE from PF.
13303 */
13306 13304
13307 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX; 13305 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
13308 dev->features |= NETIF_F_HIGHDMA; 13306 dev->features |= NETIF_F_HIGHDMA;
@@ -13738,7 +13736,7 @@ static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
13738 if (!netif_running(bp->dev)) { 13736 if (!netif_running(bp->dev)) {
13739 DP(BNX2X_MSG_PTP, 13737 DP(BNX2X_MSG_PTP,
13740 "PTP adjfreq called while the interface is down\n"); 13738 "PTP adjfreq called while the interface is down\n");
13741 return -EFAULT; 13739 return -ENETDOWN;
13742 } 13740 }
13743 13741
13744 if (ppb < 0) { 13742 if (ppb < 0) {
@@ -13797,6 +13795,12 @@ static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
13797{ 13795{
13798 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info); 13796 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13799 13797
13798 if (!netif_running(bp->dev)) {
13799 DP(BNX2X_MSG_PTP,
13800 "PTP adjtime called while the interface is down\n");
13801 return -ENETDOWN;
13802 }
13803
13800 DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta); 13804 DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
13801 13805
13802 timecounter_adjtime(&bp->timecounter, delta); 13806 timecounter_adjtime(&bp->timecounter, delta);
@@ -13809,6 +13813,12 @@ static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
13809 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info); 13813 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13810 u64 ns; 13814 u64 ns;
13811 13815
13816 if (!netif_running(bp->dev)) {
13817 DP(BNX2X_MSG_PTP,
13818 "PTP gettime called while the interface is down\n");
13819 return -ENETDOWN;
13820 }
13821
13812 ns = timecounter_read(&bp->timecounter); 13822 ns = timecounter_read(&bp->timecounter);
13813 13823
13814 DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns); 13824 DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
@@ -13824,6 +13834,12 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
13824 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info); 13834 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
13825 u64 ns; 13835 u64 ns;
13826 13836
13837 if (!netif_running(bp->dev)) {
13838 DP(BNX2X_MSG_PTP,
13839 "PTP settime called while the interface is down\n");
13840 return -ENETDOWN;
13841 }
13842
13827 ns = timespec64_to_ns(ts); 13843 ns = timespec64_to_ns(ts);
13828 13844
13829 DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns); 13845 DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
@@ -13991,6 +14007,14 @@ static int bnx2x_init_one(struct pci_dev *pdev,
13991 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count); 14007 rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
13992 if (rc) 14008 if (rc)
13993 goto init_one_freemem; 14009 goto init_one_freemem;
14010
14011#ifdef CONFIG_BNX2X_SRIOV
14012 /* VF with OLD Hypervisor or old PF do not support filtering */
14013 if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
14014 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
14015 dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
14016 }
14017#endif
13994 } 14018 }
13995 14019
13996 /* Enable SRIOV if capability found in configuration space */ 14020 /* Enable SRIOV if capability found in configuration space */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
index 6fad22adbbb9..bdfd53b46bc5 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
@@ -434,7 +434,9 @@ static int bnx2x_vf_mac_vlan_config(struct bnx2x *bp,
434 434
435 /* Add/Remove the filter */ 435 /* Add/Remove the filter */
436 rc = bnx2x_config_vlan_mac(bp, &ramrod); 436 rc = bnx2x_config_vlan_mac(bp, &ramrod);
437 if (rc && rc != -EEXIST) { 437 if (rc == -EEXIST)
438 return 0;
439 if (rc) {
438 BNX2X_ERR("Failed to %s %s\n", 440 BNX2X_ERR("Failed to %s %s\n",
439 filter->add ? "add" : "delete", 441 filter->add ? "add" : "delete",
440 (filter->type == BNX2X_VF_FILTER_VLAN_MAC) ? 442 (filter->type == BNX2X_VF_FILTER_VLAN_MAC) ?
@@ -444,6 +446,8 @@ static int bnx2x_vf_mac_vlan_config(struct bnx2x *bp,
444 return rc; 446 return rc;
445 } 447 }
446 448
449 filter->applied = true;
450
447 return 0; 451 return 0;
448} 452}
449 453
@@ -469,8 +473,10 @@ int bnx2x_vf_mac_vlan_config_list(struct bnx2x *bp, struct bnx2x_virtf *vf,
469 /* Rollback if needed */ 473 /* Rollback if needed */
470 if (i != filters->count) { 474 if (i != filters->count) {
471 BNX2X_ERR("Managed only %d/%d filters - rolling back\n", 475 BNX2X_ERR("Managed only %d/%d filters - rolling back\n",
472 i, filters->count + 1); 476 i, filters->count);
473 while (--i >= 0) { 477 while (--i >= 0) {
478 if (!filters->filters[i].applied)
479 continue;
474 filters->filters[i].add = !filters->filters[i].add; 480 filters->filters[i].add = !filters->filters[i].add;
475 bnx2x_vf_mac_vlan_config(bp, vf, qid, 481 bnx2x_vf_mac_vlan_config(bp, vf, qid,
476 &filters->filters[i], 482 &filters->filters[i],
@@ -1899,7 +1905,8 @@ void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
1899 continue; 1905 continue;
1900 } 1906 }
1901 1907
1902 DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid); 1908 DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS),
1909 "add addresses for vf %d\n", vf->abs_vfid);
1903 for_each_vfq(vf, j) { 1910 for_each_vfq(vf, j) {
1904 struct bnx2x_vf_queue *rxq = vfq_get(vf, j); 1911 struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
1905 1912
@@ -1920,11 +1927,12 @@ void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
1920 cpu_to_le32(U64_HI(q_stats_addr)); 1927 cpu_to_le32(U64_HI(q_stats_addr));
1921 cur_query_entry->address.lo = 1928 cur_query_entry->address.lo =
1922 cpu_to_le32(U64_LO(q_stats_addr)); 1929 cpu_to_le32(U64_LO(q_stats_addr));
1923 DP(BNX2X_MSG_IOV, 1930 DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS),
1924 "added address %x %x for vf %d queue %d client %d\n", 1931 "added address %x %x for vf %d queue %d client %d\n",
1925 cur_query_entry->address.hi, 1932 cur_query_entry->address.hi,
1926 cur_query_entry->address.lo, cur_query_entry->funcID, 1933 cur_query_entry->address.lo,
1927 j, cur_query_entry->index); 1934 cur_query_entry->funcID,
1935 j, cur_query_entry->index);
1928 cur_query_entry++; 1936 cur_query_entry++;
1929 cur_data_offset += sizeof(struct per_queue_stats); 1937 cur_data_offset += sizeof(struct per_queue_stats);
1930 stats_count++; 1938 stats_count++;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
index 7a6d406f4c11..888d0b6632e8 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
@@ -114,6 +114,7 @@ struct bnx2x_vf_mac_vlan_filter {
114 (BNX2X_VF_FILTER_MAC | BNX2X_VF_FILTER_VLAN) /*shortcut*/ 114 (BNX2X_VF_FILTER_MAC | BNX2X_VF_FILTER_VLAN) /*shortcut*/
115 115
116 bool add; 116 bool add;
117 bool applied;
117 u8 *mac; 118 u8 *mac;
118 u16 vid; 119 u16 vid;
119}; 120};
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
index bfae300cf25f..76a4668c50fe 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
@@ -868,7 +868,7 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev)
868 struct bnx2x *bp = netdev_priv(dev); 868 struct bnx2x *bp = netdev_priv(dev);
869 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; 869 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
870 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 870 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
871 int rc, i = 0; 871 int rc = 0, i = 0;
872 struct netdev_hw_addr *ha; 872 struct netdev_hw_addr *ha;
873 873
874 if (bp->state != BNX2X_STATE_OPEN) { 874 if (bp->state != BNX2X_STATE_OPEN) {
@@ -883,6 +883,15 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev)
883 /* Get Rx mode requested */ 883 /* Get Rx mode requested */
884 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); 884 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
885 885
886 /* We support PFVF_MAX_MULTICAST_PER_VF mcast addresses tops */
887 if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) {
888 DP(NETIF_MSG_IFUP,
889 "VF supports not more than %d multicast MAC addresses\n",
890 PFVF_MAX_MULTICAST_PER_VF);
891 rc = -EINVAL;
892 goto out;
893 }
894
886 netdev_for_each_mc_addr(ha, dev) { 895 netdev_for_each_mc_addr(ha, dev) {
887 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", 896 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
888 bnx2x_mc_addr(ha)); 897 bnx2x_mc_addr(ha));
@@ -890,16 +899,6 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev)
890 i++; 899 i++;
891 } 900 }
892 901
893 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
894 * addresses tops
895 */
896 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
897 DP(NETIF_MSG_IFUP,
898 "VF supports not more than %d multicast MAC addresses\n",
899 PFVF_MAX_MULTICAST_PER_VF);
900 return -EINVAL;
901 }
902
903 req->n_multicast = i; 902 req->n_multicast = i;
904 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED; 903 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
905 req->vf_qid = 0; 904 req->vf_qid = 0;
@@ -924,7 +923,7 @@ int bnx2x_vfpf_set_mcast(struct net_device *dev)
924out: 923out:
925 bnx2x_vfpf_finalize(bp, &req->first_tlv); 924 bnx2x_vfpf_finalize(bp, &req->first_tlv);
926 925
927 return 0; 926 return rc;
928} 927}
929 928
930/* request pf to add a vlan for the vf */ 929/* request pf to add a vlan for the vf */
@@ -1778,6 +1777,23 @@ static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1778 goto op_err; 1777 goto op_err;
1779 } 1778 }
1780 1779
1780 /* build vlan list */
1781 fl = NULL;
1782
1783 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1784 VFPF_VLAN_FILTER);
1785 if (rc)
1786 goto op_err;
1787
1788 if (fl) {
1789 /* set vlan list */
1790 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1791 msg->vf_qid,
1792 false);
1793 if (rc)
1794 goto op_err;
1795 }
1796
1781 } 1797 }
1782 1798
1783 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) { 1799 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 235733e91c79..32de4589d16a 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -4465,6 +4465,10 @@ static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
4465 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; 4465 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
4466 } 4466 }
4467#endif 4467#endif
4468 if (BNXT_PF(bp) && (le16_to_cpu(resp->flags) &
4469 FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED))
4470 bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
4471
4468 switch (resp->port_partition_type) { 4472 switch (resp->port_partition_type) {
4469 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0: 4473 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
4470 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5: 4474 case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
@@ -5507,8 +5511,9 @@ static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
5507 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) & 5511 bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
5508 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK; 5512 PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
5509 } 5513 }
5510 link_info->support_auto_speeds = 5514 if (resp->supported_speeds_auto_mode)
5511 le16_to_cpu(resp->supported_speeds_auto_mode); 5515 link_info->support_auto_speeds =
5516 le16_to_cpu(resp->supported_speeds_auto_mode);
5512 5517
5513hwrm_phy_qcaps_exit: 5518hwrm_phy_qcaps_exit:
5514 mutex_unlock(&bp->hwrm_cmd_lock); 5519 mutex_unlock(&bp->hwrm_cmd_lock);
@@ -6495,8 +6500,14 @@ static void bnxt_reset_task(struct bnxt *bp, bool silent)
6495 if (!silent) 6500 if (!silent)
6496 bnxt_dbg_dump_states(bp); 6501 bnxt_dbg_dump_states(bp);
6497 if (netif_running(bp->dev)) { 6502 if (netif_running(bp->dev)) {
6503 int rc;
6504
6505 if (!silent)
6506 bnxt_ulp_stop(bp);
6498 bnxt_close_nic(bp, false, false); 6507 bnxt_close_nic(bp, false, false);
6499 bnxt_open_nic(bp, false, false); 6508 rc = bnxt_open_nic(bp, false, false);
6509 if (!silent && !rc)
6510 bnxt_ulp_start(bp);
6500 } 6511 }
6501} 6512}
6502 6513
@@ -7444,6 +7455,10 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7444 if (rc) 7455 if (rc)
7445 goto init_err_pci_clean; 7456 goto init_err_pci_clean;
7446 7457
7458 rc = bnxt_hwrm_func_reset(bp);
7459 if (rc)
7460 goto init_err_pci_clean;
7461
7447 bnxt_hwrm_fw_set_time(bp); 7462 bnxt_hwrm_fw_set_time(bp);
7448 7463
7449 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | 7464 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
@@ -7554,10 +7569,6 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7554 if (rc) 7569 if (rc)
7555 goto init_err_pci_clean; 7570 goto init_err_pci_clean;
7556 7571
7557 rc = bnxt_hwrm_func_reset(bp);
7558 if (rc)
7559 goto init_err_pci_clean;
7560
7561 rc = bnxt_init_int_mode(bp); 7572 rc = bnxt_init_int_mode(bp);
7562 if (rc) 7573 if (rc)
7563 goto init_err_pci_clean; 7574 goto init_err_pci_clean;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index faf26a2f726b..c7a5b84a5cb2 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -993,6 +993,7 @@ struct bnxt {
993 BNXT_FLAG_ROCEV2_CAP) 993 BNXT_FLAG_ROCEV2_CAP)
994 #define BNXT_FLAG_NO_AGG_RINGS 0x20000 994 #define BNXT_FLAG_NO_AGG_RINGS 0x20000
995 #define BNXT_FLAG_RX_PAGE_MODE 0x40000 995 #define BNXT_FLAG_RX_PAGE_MODE 0x40000
996 #define BNXT_FLAG_FW_LLDP_AGENT 0x80000
996 #define BNXT_FLAG_CHIP_NITRO_A0 0x1000000 997 #define BNXT_FLAG_CHIP_NITRO_A0 0x1000000
997 998
998 #define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA | \ 999 #define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA | \
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
index fdf2d8caf7bf..03532061d211 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
@@ -474,7 +474,7 @@ void bnxt_dcb_init(struct bnxt *bp)
474 return; 474 return;
475 475
476 bp->dcbx_cap = DCB_CAP_DCBX_VER_IEEE; 476 bp->dcbx_cap = DCB_CAP_DCBX_VER_IEEE;
477 if (BNXT_PF(bp)) 477 if (BNXT_PF(bp) && !(bp->flags & BNXT_FLAG_FW_LLDP_AGENT))
478 bp->dcbx_cap |= DCB_CAP_DCBX_HOST; 478 bp->dcbx_cap |= DCB_CAP_DCBX_HOST;
479 else 479 else
480 bp->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED; 480 bp->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index f92896835d2a..69015fa50f20 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Broadcom GENET (Gigabit Ethernet) controller driver 2 * Broadcom GENET (Gigabit Ethernet) controller driver
3 * 3 *
4 * Copyright (c) 2014 Broadcom Corporation 4 * Copyright (c) 2014-2017 Broadcom
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
@@ -450,6 +450,22 @@ static inline void bcmgenet_rdma_ring_writel(struct bcmgenet_priv *priv,
450 genet_dma_ring_regs[r]); 450 genet_dma_ring_regs[r]);
451} 451}
452 452
453static int bcmgenet_begin(struct net_device *dev)
454{
455 struct bcmgenet_priv *priv = netdev_priv(dev);
456
457 /* Turn on the clock */
458 return clk_prepare_enable(priv->clk);
459}
460
461static void bcmgenet_complete(struct net_device *dev)
462{
463 struct bcmgenet_priv *priv = netdev_priv(dev);
464
465 /* Turn off the clock */
466 clk_disable_unprepare(priv->clk);
467}
468
453static int bcmgenet_get_link_ksettings(struct net_device *dev, 469static int bcmgenet_get_link_ksettings(struct net_device *dev,
454 struct ethtool_link_ksettings *cmd) 470 struct ethtool_link_ksettings *cmd)
455{ 471{
@@ -778,8 +794,9 @@ static const struct bcmgenet_stats bcmgenet_gstrings_stats[] = {
778 STAT_GENET_RUNT("rx_runt_bytes", mib.rx_runt_bytes), 794 STAT_GENET_RUNT("rx_runt_bytes", mib.rx_runt_bytes),
779 /* Misc UniMAC counters */ 795 /* Misc UniMAC counters */
780 STAT_GENET_MISC("rbuf_ovflow_cnt", mib.rbuf_ovflow_cnt, 796 STAT_GENET_MISC("rbuf_ovflow_cnt", mib.rbuf_ovflow_cnt,
781 UMAC_RBUF_OVFL_CNT), 797 UMAC_RBUF_OVFL_CNT_V1),
782 STAT_GENET_MISC("rbuf_err_cnt", mib.rbuf_err_cnt, UMAC_RBUF_ERR_CNT), 798 STAT_GENET_MISC("rbuf_err_cnt", mib.rbuf_err_cnt,
799 UMAC_RBUF_ERR_CNT_V1),
783 STAT_GENET_MISC("mdf_err_cnt", mib.mdf_err_cnt, UMAC_MDF_ERR_CNT), 800 STAT_GENET_MISC("mdf_err_cnt", mib.mdf_err_cnt, UMAC_MDF_ERR_CNT),
784 STAT_GENET_SOFT_MIB("alloc_rx_buff_failed", mib.alloc_rx_buff_failed), 801 STAT_GENET_SOFT_MIB("alloc_rx_buff_failed", mib.alloc_rx_buff_failed),
785 STAT_GENET_SOFT_MIB("rx_dma_failed", mib.rx_dma_failed), 802 STAT_GENET_SOFT_MIB("rx_dma_failed", mib.rx_dma_failed),
@@ -821,6 +838,45 @@ static void bcmgenet_get_strings(struct net_device *dev, u32 stringset,
821 } 838 }
822} 839}
823 840
841static u32 bcmgenet_update_stat_misc(struct bcmgenet_priv *priv, u16 offset)
842{
843 u16 new_offset;
844 u32 val;
845
846 switch (offset) {
847 case UMAC_RBUF_OVFL_CNT_V1:
848 if (GENET_IS_V2(priv))
849 new_offset = RBUF_OVFL_CNT_V2;
850 else
851 new_offset = RBUF_OVFL_CNT_V3PLUS;
852
853 val = bcmgenet_rbuf_readl(priv, new_offset);
854 /* clear if overflowed */
855 if (val == ~0)
856 bcmgenet_rbuf_writel(priv, 0, new_offset);
857 break;
858 case UMAC_RBUF_ERR_CNT_V1:
859 if (GENET_IS_V2(priv))
860 new_offset = RBUF_ERR_CNT_V2;
861 else
862 new_offset = RBUF_ERR_CNT_V3PLUS;
863
864 val = bcmgenet_rbuf_readl(priv, new_offset);
865 /* clear if overflowed */
866 if (val == ~0)
867 bcmgenet_rbuf_writel(priv, 0, new_offset);
868 break;
869 default:
870 val = bcmgenet_umac_readl(priv, offset);
871 /* clear if overflowed */
872 if (val == ~0)
873 bcmgenet_umac_writel(priv, 0, offset);
874 break;
875 }
876
877 return val;
878}
879
824static void bcmgenet_update_mib_counters(struct bcmgenet_priv *priv) 880static void bcmgenet_update_mib_counters(struct bcmgenet_priv *priv)
825{ 881{
826 int i, j = 0; 882 int i, j = 0;
@@ -836,19 +892,28 @@ static void bcmgenet_update_mib_counters(struct bcmgenet_priv *priv)
836 case BCMGENET_STAT_NETDEV: 892 case BCMGENET_STAT_NETDEV:
837 case BCMGENET_STAT_SOFT: 893 case BCMGENET_STAT_SOFT:
838 continue; 894 continue;
839 case BCMGENET_STAT_MIB_RX:
840 case BCMGENET_STAT_MIB_TX:
841 case BCMGENET_STAT_RUNT: 895 case BCMGENET_STAT_RUNT:
842 if (s->type != BCMGENET_STAT_MIB_RX) 896 offset += BCMGENET_STAT_OFFSET;
843 offset = BCMGENET_STAT_OFFSET; 897 /* fall through */
898 case BCMGENET_STAT_MIB_TX:
899 offset += BCMGENET_STAT_OFFSET;
900 /* fall through */
901 case BCMGENET_STAT_MIB_RX:
844 val = bcmgenet_umac_readl(priv, 902 val = bcmgenet_umac_readl(priv,
845 UMAC_MIB_START + j + offset); 903 UMAC_MIB_START + j + offset);
904 offset = 0; /* Reset Offset */
846 break; 905 break;
847 case BCMGENET_STAT_MISC: 906 case BCMGENET_STAT_MISC:
848 val = bcmgenet_umac_readl(priv, s->reg_offset); 907 if (GENET_IS_V1(priv)) {
849 /* clear if overflowed */ 908 val = bcmgenet_umac_readl(priv, s->reg_offset);
850 if (val == ~0) 909 /* clear if overflowed */
851 bcmgenet_umac_writel(priv, 0, s->reg_offset); 910 if (val == ~0)
911 bcmgenet_umac_writel(priv, 0,
912 s->reg_offset);
913 } else {
914 val = bcmgenet_update_stat_misc(priv,
915 s->reg_offset);
916 }
852 break; 917 break;
853 } 918 }
854 919
@@ -973,6 +1038,8 @@ static int bcmgenet_set_eee(struct net_device *dev, struct ethtool_eee *e)
973 1038
974/* standard ethtool support functions. */ 1039/* standard ethtool support functions. */
975static const struct ethtool_ops bcmgenet_ethtool_ops = { 1040static const struct ethtool_ops bcmgenet_ethtool_ops = {
1041 .begin = bcmgenet_begin,
1042 .complete = bcmgenet_complete,
976 .get_strings = bcmgenet_get_strings, 1043 .get_strings = bcmgenet_get_strings,
977 .get_sset_count = bcmgenet_get_sset_count, 1044 .get_sset_count = bcmgenet_get_sset_count,
978 .get_ethtool_stats = bcmgenet_get_ethtool_stats, 1045 .get_ethtool_stats = bcmgenet_get_ethtool_stats,
@@ -1167,7 +1234,6 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
1167 struct bcmgenet_priv *priv = netdev_priv(dev); 1234 struct bcmgenet_priv *priv = netdev_priv(dev);
1168 struct device *kdev = &priv->pdev->dev; 1235 struct device *kdev = &priv->pdev->dev;
1169 struct enet_cb *tx_cb_ptr; 1236 struct enet_cb *tx_cb_ptr;
1170 struct netdev_queue *txq;
1171 unsigned int pkts_compl = 0; 1237 unsigned int pkts_compl = 0;
1172 unsigned int bytes_compl = 0; 1238 unsigned int bytes_compl = 0;
1173 unsigned int c_index; 1239 unsigned int c_index;
@@ -1219,13 +1285,8 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
1219 dev->stats.tx_packets += pkts_compl; 1285 dev->stats.tx_packets += pkts_compl;
1220 dev->stats.tx_bytes += bytes_compl; 1286 dev->stats.tx_bytes += bytes_compl;
1221 1287
1222 txq = netdev_get_tx_queue(dev, ring->queue); 1288 netdev_tx_completed_queue(netdev_get_tx_queue(dev, ring->queue),
1223 netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); 1289 pkts_compl, bytes_compl);
1224
1225 if (ring->free_bds > (MAX_SKB_FRAGS + 1)) {
1226 if (netif_tx_queue_stopped(txq))
1227 netif_tx_wake_queue(txq);
1228 }
1229 1290
1230 return pkts_compl; 1291 return pkts_compl;
1231} 1292}
@@ -1248,8 +1309,16 @@ static int bcmgenet_tx_poll(struct napi_struct *napi, int budget)
1248 struct bcmgenet_tx_ring *ring = 1309 struct bcmgenet_tx_ring *ring =
1249 container_of(napi, struct bcmgenet_tx_ring, napi); 1310 container_of(napi, struct bcmgenet_tx_ring, napi);
1250 unsigned int work_done = 0; 1311 unsigned int work_done = 0;
1312 struct netdev_queue *txq;
1313 unsigned long flags;
1251 1314
1252 work_done = bcmgenet_tx_reclaim(ring->priv->dev, ring); 1315 spin_lock_irqsave(&ring->lock, flags);
1316 work_done = __bcmgenet_tx_reclaim(ring->priv->dev, ring);
1317 if (ring->free_bds > (MAX_SKB_FRAGS + 1)) {
1318 txq = netdev_get_tx_queue(ring->priv->dev, ring->queue);
1319 netif_tx_wake_queue(txq);
1320 }
1321 spin_unlock_irqrestore(&ring->lock, flags);
1253 1322
1254 if (work_done == 0) { 1323 if (work_done == 0) {
1255 napi_complete(napi); 1324 napi_complete(napi);
@@ -2457,24 +2526,28 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv)
2457/* Interrupt bottom half */ 2526/* Interrupt bottom half */
2458static void bcmgenet_irq_task(struct work_struct *work) 2527static void bcmgenet_irq_task(struct work_struct *work)
2459{ 2528{
2529 unsigned long flags;
2530 unsigned int status;
2460 struct bcmgenet_priv *priv = container_of( 2531 struct bcmgenet_priv *priv = container_of(
2461 work, struct bcmgenet_priv, bcmgenet_irq_work); 2532 work, struct bcmgenet_priv, bcmgenet_irq_work);
2462 2533
2463 netif_dbg(priv, intr, priv->dev, "%s\n", __func__); 2534 netif_dbg(priv, intr, priv->dev, "%s\n", __func__);
2464 2535
2465 if (priv->irq0_stat & UMAC_IRQ_MPD_R) { 2536 spin_lock_irqsave(&priv->lock, flags);
2466 priv->irq0_stat &= ~UMAC_IRQ_MPD_R; 2537 status = priv->irq0_stat;
2538 priv->irq0_stat = 0;
2539 spin_unlock_irqrestore(&priv->lock, flags);
2540
2541 if (status & UMAC_IRQ_MPD_R) {
2467 netif_dbg(priv, wol, priv->dev, 2542 netif_dbg(priv, wol, priv->dev,
2468 "magic packet detected, waking up\n"); 2543 "magic packet detected, waking up\n");
2469 bcmgenet_power_up(priv, GENET_POWER_WOL_MAGIC); 2544 bcmgenet_power_up(priv, GENET_POWER_WOL_MAGIC);
2470 } 2545 }
2471 2546
2472 /* Link UP/DOWN event */ 2547 /* Link UP/DOWN event */
2473 if (priv->irq0_stat & UMAC_IRQ_LINK_EVENT) { 2548 if (status & UMAC_IRQ_LINK_EVENT)
2474 phy_mac_interrupt(priv->phydev, 2549 phy_mac_interrupt(priv->phydev,
2475 !!(priv->irq0_stat & UMAC_IRQ_LINK_UP)); 2550 !!(status & UMAC_IRQ_LINK_UP));
2476 priv->irq0_stat &= ~UMAC_IRQ_LINK_EVENT;
2477 }
2478} 2551}
2479 2552
2480/* bcmgenet_isr1: handle Rx and Tx priority queues */ 2553/* bcmgenet_isr1: handle Rx and Tx priority queues */
@@ -2483,22 +2556,21 @@ static irqreturn_t bcmgenet_isr1(int irq, void *dev_id)
2483 struct bcmgenet_priv *priv = dev_id; 2556 struct bcmgenet_priv *priv = dev_id;
2484 struct bcmgenet_rx_ring *rx_ring; 2557 struct bcmgenet_rx_ring *rx_ring;
2485 struct bcmgenet_tx_ring *tx_ring; 2558 struct bcmgenet_tx_ring *tx_ring;
2486 unsigned int index; 2559 unsigned int index, status;
2487 2560
2488 /* Save irq status for bottom-half processing. */ 2561 /* Read irq status */
2489 priv->irq1_stat = 2562 status = bcmgenet_intrl2_1_readl(priv, INTRL2_CPU_STAT) &
2490 bcmgenet_intrl2_1_readl(priv, INTRL2_CPU_STAT) &
2491 ~bcmgenet_intrl2_1_readl(priv, INTRL2_CPU_MASK_STATUS); 2563 ~bcmgenet_intrl2_1_readl(priv, INTRL2_CPU_MASK_STATUS);
2492 2564
2493 /* clear interrupts */ 2565 /* clear interrupts */
2494 bcmgenet_intrl2_1_writel(priv, priv->irq1_stat, INTRL2_CPU_CLEAR); 2566 bcmgenet_intrl2_1_writel(priv, status, INTRL2_CPU_CLEAR);
2495 2567
2496 netif_dbg(priv, intr, priv->dev, 2568 netif_dbg(priv, intr, priv->dev,
2497 "%s: IRQ=0x%x\n", __func__, priv->irq1_stat); 2569 "%s: IRQ=0x%x\n", __func__, status);
2498 2570
2499 /* Check Rx priority queue interrupts */ 2571 /* Check Rx priority queue interrupts */
2500 for (index = 0; index < priv->hw_params->rx_queues; index++) { 2572 for (index = 0; index < priv->hw_params->rx_queues; index++) {
2501 if (!(priv->irq1_stat & BIT(UMAC_IRQ1_RX_INTR_SHIFT + index))) 2573 if (!(status & BIT(UMAC_IRQ1_RX_INTR_SHIFT + index)))
2502 continue; 2574 continue;
2503 2575
2504 rx_ring = &priv->rx_rings[index]; 2576 rx_ring = &priv->rx_rings[index];
@@ -2511,7 +2583,7 @@ static irqreturn_t bcmgenet_isr1(int irq, void *dev_id)
2511 2583
2512 /* Check Tx priority queue interrupts */ 2584 /* Check Tx priority queue interrupts */
2513 for (index = 0; index < priv->hw_params->tx_queues; index++) { 2585 for (index = 0; index < priv->hw_params->tx_queues; index++) {
2514 if (!(priv->irq1_stat & BIT(index))) 2586 if (!(status & BIT(index)))
2515 continue; 2587 continue;
2516 2588
2517 tx_ring = &priv->tx_rings[index]; 2589 tx_ring = &priv->tx_rings[index];
@@ -2531,19 +2603,20 @@ static irqreturn_t bcmgenet_isr0(int irq, void *dev_id)
2531 struct bcmgenet_priv *priv = dev_id; 2603 struct bcmgenet_priv *priv = dev_id;
2532 struct bcmgenet_rx_ring *rx_ring; 2604 struct bcmgenet_rx_ring *rx_ring;
2533 struct bcmgenet_tx_ring *tx_ring; 2605 struct bcmgenet_tx_ring *tx_ring;
2606 unsigned int status;
2607 unsigned long flags;
2534 2608
2535 /* Save irq status for bottom-half processing. */ 2609 /* Read irq status */
2536 priv->irq0_stat = 2610 status = bcmgenet_intrl2_0_readl(priv, INTRL2_CPU_STAT) &
2537 bcmgenet_intrl2_0_readl(priv, INTRL2_CPU_STAT) &
2538 ~bcmgenet_intrl2_0_readl(priv, INTRL2_CPU_MASK_STATUS); 2611 ~bcmgenet_intrl2_0_readl(priv, INTRL2_CPU_MASK_STATUS);
2539 2612
2540 /* clear interrupts */ 2613 /* clear interrupts */
2541 bcmgenet_intrl2_0_writel(priv, priv->irq0_stat, INTRL2_CPU_CLEAR); 2614 bcmgenet_intrl2_0_writel(priv, status, INTRL2_CPU_CLEAR);
2542 2615
2543 netif_dbg(priv, intr, priv->dev, 2616 netif_dbg(priv, intr, priv->dev,
2544 "IRQ=0x%x\n", priv->irq0_stat); 2617 "IRQ=0x%x\n", status);
2545 2618
2546 if (priv->irq0_stat & UMAC_IRQ_RXDMA_DONE) { 2619 if (status & UMAC_IRQ_RXDMA_DONE) {
2547 rx_ring = &priv->rx_rings[DESC_INDEX]; 2620 rx_ring = &priv->rx_rings[DESC_INDEX];
2548 2621
2549 if (likely(napi_schedule_prep(&rx_ring->napi))) { 2622 if (likely(napi_schedule_prep(&rx_ring->napi))) {
@@ -2552,7 +2625,7 @@ static irqreturn_t bcmgenet_isr0(int irq, void *dev_id)
2552 } 2625 }
2553 } 2626 }
2554 2627
2555 if (priv->irq0_stat & UMAC_IRQ_TXDMA_DONE) { 2628 if (status & UMAC_IRQ_TXDMA_DONE) {
2556 tx_ring = &priv->tx_rings[DESC_INDEX]; 2629 tx_ring = &priv->tx_rings[DESC_INDEX];
2557 2630
2558 if (likely(napi_schedule_prep(&tx_ring->napi))) { 2631 if (likely(napi_schedule_prep(&tx_ring->napi))) {
@@ -2561,22 +2634,23 @@ static irqreturn_t bcmgenet_isr0(int irq, void *dev_id)
2561 } 2634 }
2562 } 2635 }
2563 2636
2564 if (priv->irq0_stat & (UMAC_IRQ_PHY_DET_R |
2565 UMAC_IRQ_PHY_DET_F |
2566 UMAC_IRQ_LINK_EVENT |
2567 UMAC_IRQ_HFB_SM |
2568 UMAC_IRQ_HFB_MM |
2569 UMAC_IRQ_MPD_R)) {
2570 /* all other interested interrupts handled in bottom half */
2571 schedule_work(&priv->bcmgenet_irq_work);
2572 }
2573
2574 if ((priv->hw_params->flags & GENET_HAS_MDIO_INTR) && 2637 if ((priv->hw_params->flags & GENET_HAS_MDIO_INTR) &&
2575 priv->irq0_stat & (UMAC_IRQ_MDIO_DONE | UMAC_IRQ_MDIO_ERROR)) { 2638 status & (UMAC_IRQ_MDIO_DONE | UMAC_IRQ_MDIO_ERROR)) {
2576 priv->irq0_stat &= ~(UMAC_IRQ_MDIO_DONE | UMAC_IRQ_MDIO_ERROR);
2577 wake_up(&priv->wq); 2639 wake_up(&priv->wq);
2578 } 2640 }
2579 2641
2642 /* all other interested interrupts handled in bottom half */
2643 status &= (UMAC_IRQ_LINK_EVENT |
2644 UMAC_IRQ_MPD_R);
2645 if (status) {
2646 /* Save irq status for bottom-half processing. */
2647 spin_lock_irqsave(&priv->lock, flags);
2648 priv->irq0_stat |= status;
2649 spin_unlock_irqrestore(&priv->lock, flags);
2650
2651 schedule_work(&priv->bcmgenet_irq_work);
2652 }
2653
2580 return IRQ_HANDLED; 2654 return IRQ_HANDLED;
2581} 2655}
2582 2656
@@ -2801,6 +2875,8 @@ err_irq0:
2801err_fini_dma: 2875err_fini_dma:
2802 bcmgenet_fini_dma(priv); 2876 bcmgenet_fini_dma(priv);
2803err_clk_disable: 2877err_clk_disable:
2878 if (priv->internal_phy)
2879 bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
2804 clk_disable_unprepare(priv->clk); 2880 clk_disable_unprepare(priv->clk);
2805 return ret; 2881 return ret;
2806} 2882}
@@ -3177,6 +3253,12 @@ static void bcmgenet_set_hw_params(struct bcmgenet_priv *priv)
3177 */ 3253 */
3178 gphy_rev = reg & 0xffff; 3254 gphy_rev = reg & 0xffff;
3179 3255
3256 /* This is reserved so should require special treatment */
3257 if (gphy_rev == 0 || gphy_rev == 0x01ff) {
3258 pr_warn("Invalid GPHY revision detected: 0x%04x\n", gphy_rev);
3259 return;
3260 }
3261
3180 /* This is the good old scheme, just GPHY major, no minor nor patch */ 3262 /* This is the good old scheme, just GPHY major, no minor nor patch */
3181 if ((gphy_rev & 0xf0) != 0) 3263 if ((gphy_rev & 0xf0) != 0)
3182 priv->gphy_rev = gphy_rev << 8; 3264 priv->gphy_rev = gphy_rev << 8;
@@ -3185,12 +3267,6 @@ static void bcmgenet_set_hw_params(struct bcmgenet_priv *priv)
3185 else if ((gphy_rev & 0xff00) != 0) 3267 else if ((gphy_rev & 0xff00) != 0)
3186 priv->gphy_rev = gphy_rev; 3268 priv->gphy_rev = gphy_rev;
3187 3269
3188 /* This is reserved so should require special treatment */
3189 else if (gphy_rev == 0 || gphy_rev == 0x01ff) {
3190 pr_warn("Invalid GPHY revision detected: 0x%04x\n", gphy_rev);
3191 return;
3192 }
3193
3194#ifdef CONFIG_PHYS_ADDR_T_64BIT 3270#ifdef CONFIG_PHYS_ADDR_T_64BIT
3195 if (!(params->flags & GENET_HAS_40BITS)) 3271 if (!(params->flags & GENET_HAS_40BITS))
3196 pr_warn("GENET does not support 40-bits PA\n"); 3272 pr_warn("GENET does not support 40-bits PA\n");
@@ -3233,6 +3309,7 @@ static int bcmgenet_probe(struct platform_device *pdev)
3233 const void *macaddr; 3309 const void *macaddr;
3234 struct resource *r; 3310 struct resource *r;
3235 int err = -EIO; 3311 int err = -EIO;
3312 const char *phy_mode_str;
3236 3313
3237 /* Up to GENET_MAX_MQ_CNT + 1 TX queues and RX queues */ 3314 /* Up to GENET_MAX_MQ_CNT + 1 TX queues and RX queues */
3238 dev = alloc_etherdev_mqs(sizeof(*priv), GENET_MAX_MQ_CNT + 1, 3315 dev = alloc_etherdev_mqs(sizeof(*priv), GENET_MAX_MQ_CNT + 1,
@@ -3276,6 +3353,8 @@ static int bcmgenet_probe(struct platform_device *pdev)
3276 goto err; 3353 goto err;
3277 } 3354 }
3278 3355
3356 spin_lock_init(&priv->lock);
3357
3279 SET_NETDEV_DEV(dev, &pdev->dev); 3358 SET_NETDEV_DEV(dev, &pdev->dev);
3280 dev_set_drvdata(&pdev->dev, dev); 3359 dev_set_drvdata(&pdev->dev, dev);
3281 ether_addr_copy(dev->dev_addr, macaddr); 3360 ether_addr_copy(dev->dev_addr, macaddr);
@@ -3338,6 +3417,13 @@ static int bcmgenet_probe(struct platform_device *pdev)
3338 priv->clk_eee = NULL; 3417 priv->clk_eee = NULL;
3339 } 3418 }
3340 3419
3420 /* If this is an internal GPHY, power it on now, before UniMAC is
3421 * brought out of reset as absolutely no UniMAC activity is allowed
3422 */
3423 if (dn && !of_property_read_string(dn, "phy-mode", &phy_mode_str) &&
3424 !strcasecmp(phy_mode_str, "internal"))
3425 bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
3426
3341 err = reset_umac(priv); 3427 err = reset_umac(priv);
3342 if (err) 3428 if (err)
3343 goto err_clk_disable; 3429 goto err_clk_disable;
@@ -3502,6 +3588,8 @@ static int bcmgenet_resume(struct device *d)
3502 return 0; 3588 return 0;
3503 3589
3504out_clk_disable: 3590out_clk_disable:
3591 if (priv->internal_phy)
3592 bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
3505 clk_disable_unprepare(priv->clk); 3593 clk_disable_unprepare(priv->clk);
3506 return ret; 3594 return ret;
3507} 3595}
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index 1e2dc34d331a..db7f289d65ae 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2014 Broadcom Corporation 2 * Copyright (c) 2014-2017 Broadcom
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as 5 * it under the terms of the GNU General Public License version 2 as
@@ -214,7 +214,9 @@ struct bcmgenet_mib_counters {
214#define MDIO_REG_SHIFT 16 214#define MDIO_REG_SHIFT 16
215#define MDIO_REG_MASK 0x1F 215#define MDIO_REG_MASK 0x1F
216 216
217#define UMAC_RBUF_OVFL_CNT 0x61C 217#define UMAC_RBUF_OVFL_CNT_V1 0x61C
218#define RBUF_OVFL_CNT_V2 0x80
219#define RBUF_OVFL_CNT_V3PLUS 0x94
218 220
219#define UMAC_MPD_CTRL 0x620 221#define UMAC_MPD_CTRL 0x620
220#define MPD_EN (1 << 0) 222#define MPD_EN (1 << 0)
@@ -224,7 +226,9 @@ struct bcmgenet_mib_counters {
224 226
225#define UMAC_MPD_PW_MS 0x624 227#define UMAC_MPD_PW_MS 0x624
226#define UMAC_MPD_PW_LS 0x628 228#define UMAC_MPD_PW_LS 0x628
227#define UMAC_RBUF_ERR_CNT 0x634 229#define UMAC_RBUF_ERR_CNT_V1 0x634
230#define RBUF_ERR_CNT_V2 0x84
231#define RBUF_ERR_CNT_V3PLUS 0x98
228#define UMAC_MDF_ERR_CNT 0x638 232#define UMAC_MDF_ERR_CNT 0x638
229#define UMAC_MDF_CTRL 0x650 233#define UMAC_MDF_CTRL 0x650
230#define UMAC_MDF_ADDR 0x654 234#define UMAC_MDF_ADDR 0x654
@@ -619,11 +623,13 @@ struct bcmgenet_priv {
619 struct work_struct bcmgenet_irq_work; 623 struct work_struct bcmgenet_irq_work;
620 int irq0; 624 int irq0;
621 int irq1; 625 int irq1;
622 unsigned int irq0_stat;
623 unsigned int irq1_stat;
624 int wol_irq; 626 int wol_irq;
625 bool wol_irq_disabled; 627 bool wol_irq_disabled;
626 628
629 /* shared status */
630 spinlock_t lock;
631 unsigned int irq0_stat;
632
627 /* HW descriptors/checksum variables */ 633 /* HW descriptors/checksum variables */
628 bool desc_64b_en; 634 bool desc_64b_en;
629 bool desc_rxchk_en; 635 bool desc_rxchk_en;
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c
index be9c0e3f5ade..92f46b1375c3 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
@@ -152,7 +152,7 @@ struct octnic_gather {
152 */ 152 */
153 struct octeon_sg_entry *sg; 153 struct octeon_sg_entry *sg;
154 154
155 u64 sg_dma_ptr; 155 dma_addr_t sg_dma_ptr;
156}; 156};
157 157
158struct handshake { 158struct handshake {
@@ -734,6 +734,9 @@ static void delete_glists(struct lio *lio)
734 struct octnic_gather *g; 734 struct octnic_gather *g;
735 int i; 735 int i;
736 736
737 kfree(lio->glist_lock);
738 lio->glist_lock = NULL;
739
737 if (!lio->glist) 740 if (!lio->glist)
738 return; 741 return;
739 742
@@ -741,23 +744,26 @@ static void delete_glists(struct lio *lio)
741 do { 744 do {
742 g = (struct octnic_gather *) 745 g = (struct octnic_gather *)
743 list_delete_head(&lio->glist[i]); 746 list_delete_head(&lio->glist[i]);
744 if (g) { 747 if (g)
745 if (g->sg) {
746 dma_unmap_single(&lio->oct_dev->
747 pci_dev->dev,
748 g->sg_dma_ptr,
749 g->sg_size,
750 DMA_TO_DEVICE);
751 kfree((void *)((unsigned long)g->sg -
752 g->adjust));
753 }
754 kfree(g); 748 kfree(g);
755 }
756 } while (g); 749 } while (g);
750
751 if (lio->glists_virt_base && lio->glists_virt_base[i]) {
752 lio_dma_free(lio->oct_dev,
753 lio->glist_entry_size * lio->tx_qsize,
754 lio->glists_virt_base[i],
755 lio->glists_dma_base[i]);
756 }
757 } 757 }
758 758
759 kfree((void *)lio->glist); 759 kfree(lio->glists_virt_base);
760 kfree((void *)lio->glist_lock); 760 lio->glists_virt_base = NULL;
761
762 kfree(lio->glists_dma_base);
763 lio->glists_dma_base = NULL;
764
765 kfree(lio->glist);
766 lio->glist = NULL;
761} 767}
762 768
763/** 769/**
@@ -772,13 +778,30 @@ static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
772 lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock), 778 lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock),
773 GFP_KERNEL); 779 GFP_KERNEL);
774 if (!lio->glist_lock) 780 if (!lio->glist_lock)
775 return 1; 781 return -ENOMEM;
776 782
777 lio->glist = kcalloc(num_iqs, sizeof(*lio->glist), 783 lio->glist = kcalloc(num_iqs, sizeof(*lio->glist),
778 GFP_KERNEL); 784 GFP_KERNEL);
779 if (!lio->glist) { 785 if (!lio->glist) {
780 kfree((void *)lio->glist_lock); 786 kfree(lio->glist_lock);
781 return 1; 787 lio->glist_lock = NULL;
788 return -ENOMEM;
789 }
790
791 lio->glist_entry_size =
792 ROUNDUP8((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
793
794 /* allocate memory to store virtual and dma base address of
795 * per glist consistent memory
796 */
797 lio->glists_virt_base = kcalloc(num_iqs, sizeof(*lio->glists_virt_base),
798 GFP_KERNEL);
799 lio->glists_dma_base = kcalloc(num_iqs, sizeof(*lio->glists_dma_base),
800 GFP_KERNEL);
801
802 if (!lio->glists_virt_base || !lio->glists_dma_base) {
803 delete_glists(lio);
804 return -ENOMEM;
782 } 805 }
783 806
784 for (i = 0; i < num_iqs; i++) { 807 for (i = 0; i < num_iqs; i++) {
@@ -788,6 +811,16 @@ static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
788 811
789 INIT_LIST_HEAD(&lio->glist[i]); 812 INIT_LIST_HEAD(&lio->glist[i]);
790 813
814 lio->glists_virt_base[i] =
815 lio_dma_alloc(oct,
816 lio->glist_entry_size * lio->tx_qsize,
817 &lio->glists_dma_base[i]);
818
819 if (!lio->glists_virt_base[i]) {
820 delete_glists(lio);
821 return -ENOMEM;
822 }
823
791 for (j = 0; j < lio->tx_qsize; j++) { 824 for (j = 0; j < lio->tx_qsize; j++) {
792 g = kzalloc_node(sizeof(*g), GFP_KERNEL, 825 g = kzalloc_node(sizeof(*g), GFP_KERNEL,
793 numa_node); 826 numa_node);
@@ -796,43 +829,18 @@ static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
796 if (!g) 829 if (!g)
797 break; 830 break;
798 831
799 g->sg_size = ((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * 832 g->sg = lio->glists_virt_base[i] +
800 OCT_SG_ENTRY_SIZE); 833 (j * lio->glist_entry_size);
801 834
802 g->sg = kmalloc_node(g->sg_size + 8, 835 g->sg_dma_ptr = lio->glists_dma_base[i] +
803 GFP_KERNEL, numa_node); 836 (j * lio->glist_entry_size);
804 if (!g->sg)
805 g->sg = kmalloc(g->sg_size + 8, GFP_KERNEL);
806 if (!g->sg) {
807 kfree(g);
808 break;
809 }
810
811 /* The gather component should be aligned on 64-bit
812 * boundary
813 */
814 if (((unsigned long)g->sg) & 7) {
815 g->adjust = 8 - (((unsigned long)g->sg) & 7);
816 g->sg = (struct octeon_sg_entry *)
817 ((unsigned long)g->sg + g->adjust);
818 }
819 g->sg_dma_ptr = dma_map_single(&oct->pci_dev->dev,
820 g->sg, g->sg_size,
821 DMA_TO_DEVICE);
822 if (dma_mapping_error(&oct->pci_dev->dev,
823 g->sg_dma_ptr)) {
824 kfree((void *)((unsigned long)g->sg -
825 g->adjust));
826 kfree(g);
827 break;
828 }
829 837
830 list_add_tail(&g->list, &lio->glist[i]); 838 list_add_tail(&g->list, &lio->glist[i]);
831 } 839 }
832 840
833 if (j != lio->tx_qsize) { 841 if (j != lio->tx_qsize) {
834 delete_glists(lio); 842 delete_glists(lio);
835 return 1; 843 return -ENOMEM;
836 } 844 }
837 } 845 }
838 846
@@ -1885,9 +1893,6 @@ static void free_netsgbuf(void *buf)
1885 i++; 1893 i++;
1886 } 1894 }
1887 1895
1888 dma_sync_single_for_cpu(&lio->oct_dev->pci_dev->dev,
1889 g->sg_dma_ptr, g->sg_size, DMA_TO_DEVICE);
1890
1891 iq = skb_iq(lio, skb); 1896 iq = skb_iq(lio, skb);
1892 spin_lock(&lio->glist_lock[iq]); 1897 spin_lock(&lio->glist_lock[iq]);
1893 list_add_tail(&g->list, &lio->glist[iq]); 1898 list_add_tail(&g->list, &lio->glist[iq]);
@@ -1933,9 +1938,6 @@ static void free_netsgbuf_with_resp(void *buf)
1933 i++; 1938 i++;
1934 } 1939 }
1935 1940
1936 dma_sync_single_for_cpu(&lio->oct_dev->pci_dev->dev,
1937 g->sg_dma_ptr, g->sg_size, DMA_TO_DEVICE);
1938
1939 iq = skb_iq(lio, skb); 1941 iq = skb_iq(lio, skb);
1940 1942
1941 spin_lock(&lio->glist_lock[iq]); 1943 spin_lock(&lio->glist_lock[iq]);
@@ -3273,8 +3275,6 @@ static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
3273 i++; 3275 i++;
3274 } 3276 }
3275 3277
3276 dma_sync_single_for_device(&oct->pci_dev->dev, g->sg_dma_ptr,
3277 g->sg_size, DMA_TO_DEVICE);
3278 dptr = g->sg_dma_ptr; 3278 dptr = g->sg_dma_ptr;
3279 3279
3280 if (OCTEON_CN23XX_PF(oct)) 3280 if (OCTEON_CN23XX_PF(oct))
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
index 9d5e03502c76..7b83be4ce1fe 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
@@ -108,6 +108,8 @@ struct octnic_gather {
108 * received from the IP layer. 108 * received from the IP layer.
109 */ 109 */
110 struct octeon_sg_entry *sg; 110 struct octeon_sg_entry *sg;
111
112 dma_addr_t sg_dma_ptr;
111}; 113};
112 114
113struct octeon_device_priv { 115struct octeon_device_priv {
@@ -490,6 +492,9 @@ static void delete_glists(struct lio *lio)
490 struct octnic_gather *g; 492 struct octnic_gather *g;
491 int i; 493 int i;
492 494
495 kfree(lio->glist_lock);
496 lio->glist_lock = NULL;
497
493 if (!lio->glist) 498 if (!lio->glist)
494 return; 499 return;
495 500
@@ -497,17 +502,26 @@ static void delete_glists(struct lio *lio)
497 do { 502 do {
498 g = (struct octnic_gather *) 503 g = (struct octnic_gather *)
499 list_delete_head(&lio->glist[i]); 504 list_delete_head(&lio->glist[i]);
500 if (g) { 505 if (g)
501 if (g->sg)
502 kfree((void *)((unsigned long)g->sg -
503 g->adjust));
504 kfree(g); 506 kfree(g);
505 }
506 } while (g); 507 } while (g);
508
509 if (lio->glists_virt_base && lio->glists_virt_base[i]) {
510 lio_dma_free(lio->oct_dev,
511 lio->glist_entry_size * lio->tx_qsize,
512 lio->glists_virt_base[i],
513 lio->glists_dma_base[i]);
514 }
507 } 515 }
508 516
517 kfree(lio->glists_virt_base);
518 lio->glists_virt_base = NULL;
519
520 kfree(lio->glists_dma_base);
521 lio->glists_dma_base = NULL;
522
509 kfree(lio->glist); 523 kfree(lio->glist);
510 kfree(lio->glist_lock); 524 lio->glist = NULL;
511} 525}
512 526
513/** 527/**
@@ -522,13 +536,30 @@ static int setup_glists(struct lio *lio, int num_iqs)
522 lio->glist_lock = 536 lio->glist_lock =
523 kzalloc(sizeof(*lio->glist_lock) * num_iqs, GFP_KERNEL); 537 kzalloc(sizeof(*lio->glist_lock) * num_iqs, GFP_KERNEL);
524 if (!lio->glist_lock) 538 if (!lio->glist_lock)
525 return 1; 539 return -ENOMEM;
526 540
527 lio->glist = 541 lio->glist =
528 kzalloc(sizeof(*lio->glist) * num_iqs, GFP_KERNEL); 542 kzalloc(sizeof(*lio->glist) * num_iqs, GFP_KERNEL);
529 if (!lio->glist) { 543 if (!lio->glist) {
530 kfree(lio->glist_lock); 544 kfree(lio->glist_lock);
531 return 1; 545 lio->glist_lock = NULL;
546 return -ENOMEM;
547 }
548
549 lio->glist_entry_size =
550 ROUNDUP8((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
551
552 /* allocate memory to store virtual and dma base address of
553 * per glist consistent memory
554 */
555 lio->glists_virt_base = kcalloc(num_iqs, sizeof(*lio->glists_virt_base),
556 GFP_KERNEL);
557 lio->glists_dma_base = kcalloc(num_iqs, sizeof(*lio->glists_dma_base),
558 GFP_KERNEL);
559
560 if (!lio->glists_virt_base || !lio->glists_dma_base) {
561 delete_glists(lio);
562 return -ENOMEM;
532 } 563 }
533 564
534 for (i = 0; i < num_iqs; i++) { 565 for (i = 0; i < num_iqs; i++) {
@@ -536,34 +567,33 @@ static int setup_glists(struct lio *lio, int num_iqs)
536 567
537 INIT_LIST_HEAD(&lio->glist[i]); 568 INIT_LIST_HEAD(&lio->glist[i]);
538 569
570 lio->glists_virt_base[i] =
571 lio_dma_alloc(lio->oct_dev,
572 lio->glist_entry_size * lio->tx_qsize,
573 &lio->glists_dma_base[i]);
574
575 if (!lio->glists_virt_base[i]) {
576 delete_glists(lio);
577 return -ENOMEM;
578 }
579
539 for (j = 0; j < lio->tx_qsize; j++) { 580 for (j = 0; j < lio->tx_qsize; j++) {
540 g = kzalloc(sizeof(*g), GFP_KERNEL); 581 g = kzalloc(sizeof(*g), GFP_KERNEL);
541 if (!g) 582 if (!g)
542 break; 583 break;
543 584
544 g->sg_size = ((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * 585 g->sg = lio->glists_virt_base[i] +
545 OCT_SG_ENTRY_SIZE); 586 (j * lio->glist_entry_size);
546 587
547 g->sg = kmalloc(g->sg_size + 8, GFP_KERNEL); 588 g->sg_dma_ptr = lio->glists_dma_base[i] +
548 if (!g->sg) { 589 (j * lio->glist_entry_size);
549 kfree(g);
550 break;
551 }
552 590
553 /* The gather component should be aligned on 64-bit
554 * boundary
555 */
556 if (((unsigned long)g->sg) & 7) {
557 g->adjust = 8 - (((unsigned long)g->sg) & 7);
558 g->sg = (struct octeon_sg_entry *)
559 ((unsigned long)g->sg + g->adjust);
560 }
561 list_add_tail(&g->list, &lio->glist[i]); 591 list_add_tail(&g->list, &lio->glist[i]);
562 } 592 }
563 593
564 if (j != lio->tx_qsize) { 594 if (j != lio->tx_qsize) {
565 delete_glists(lio); 595 delete_glists(lio);
566 return 1; 596 return -ENOMEM;
567 } 597 }
568 } 598 }
569 599
@@ -1324,10 +1354,6 @@ static void free_netsgbuf(void *buf)
1324 i++; 1354 i++;
1325 } 1355 }
1326 1356
1327 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1328 finfo->dptr, g->sg_size,
1329 DMA_TO_DEVICE);
1330
1331 iq = skb_iq(lio, skb); 1357 iq = skb_iq(lio, skb);
1332 1358
1333 spin_lock(&lio->glist_lock[iq]); 1359 spin_lock(&lio->glist_lock[iq]);
@@ -1374,10 +1400,6 @@ static void free_netsgbuf_with_resp(void *buf)
1374 i++; 1400 i++;
1375 } 1401 }
1376 1402
1377 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1378 finfo->dptr, g->sg_size,
1379 DMA_TO_DEVICE);
1380
1381 iq = skb_iq(lio, skb); 1403 iq = skb_iq(lio, skb);
1382 1404
1383 spin_lock(&lio->glist_lock[iq]); 1405 spin_lock(&lio->glist_lock[iq]);
@@ -2382,23 +2404,7 @@ static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
2382 i++; 2404 i++;
2383 } 2405 }
2384 2406
2385 dptr = dma_map_single(&oct->pci_dev->dev, 2407 dptr = g->sg_dma_ptr;
2386 g->sg, g->sg_size,
2387 DMA_TO_DEVICE);
2388 if (dma_mapping_error(&oct->pci_dev->dev, dptr)) {
2389 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 4\n",
2390 __func__);
2391 dma_unmap_single(&oct->pci_dev->dev, g->sg[0].ptr[0],
2392 skb->len - skb->data_len,
2393 DMA_TO_DEVICE);
2394 for (j = 1; j <= frags; j++) {
2395 frag = &skb_shinfo(skb)->frags[j - 1];
2396 dma_unmap_page(&oct->pci_dev->dev,
2397 g->sg[j >> 2].ptr[j & 3],
2398 frag->size, DMA_TO_DEVICE);
2399 }
2400 return NETDEV_TX_BUSY;
2401 }
2402 2408
2403 ndata.cmd.cmd3.dptr = dptr; 2409 ndata.cmd.cmd3.dptr = dptr;
2404 finfo->dptr = dptr; 2410 finfo->dptr = dptr;
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_config.h b/drivers/net/ethernet/cavium/liquidio/octeon_config.h
index b3dc2e9651a8..d29ebc531151 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_config.h
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_config.h
@@ -71,17 +71,17 @@
71#define CN23XX_MAX_RINGS_PER_VF 8 71#define CN23XX_MAX_RINGS_PER_VF 8
72 72
73#define CN23XX_MAX_INPUT_QUEUES CN23XX_MAX_RINGS_PER_PF 73#define CN23XX_MAX_INPUT_QUEUES CN23XX_MAX_RINGS_PER_PF
74#define CN23XX_MAX_IQ_DESCRIPTORS 2048 74#define CN23XX_MAX_IQ_DESCRIPTORS 512
75#define CN23XX_DB_MIN 1 75#define CN23XX_DB_MIN 1
76#define CN23XX_DB_MAX 8 76#define CN23XX_DB_MAX 8
77#define CN23XX_DB_TIMEOUT 1 77#define CN23XX_DB_TIMEOUT 1
78 78
79#define CN23XX_MAX_OUTPUT_QUEUES CN23XX_MAX_RINGS_PER_PF 79#define CN23XX_MAX_OUTPUT_QUEUES CN23XX_MAX_RINGS_PER_PF
80#define CN23XX_MAX_OQ_DESCRIPTORS 2048 80#define CN23XX_MAX_OQ_DESCRIPTORS 512
81#define CN23XX_OQ_BUF_SIZE 1536 81#define CN23XX_OQ_BUF_SIZE 1536
82#define CN23XX_OQ_PKTSPER_INTR 128 82#define CN23XX_OQ_PKTSPER_INTR 128
83/*#define CAVIUM_ONLY_CN23XX_RX_PERF*/ 83/*#define CAVIUM_ONLY_CN23XX_RX_PERF*/
84#define CN23XX_OQ_REFIL_THRESHOLD 128 84#define CN23XX_OQ_REFIL_THRESHOLD 16
85 85
86#define CN23XX_OQ_INTR_PKT 64 86#define CN23XX_OQ_INTR_PKT 64
87#define CN23XX_OQ_INTR_TIME 100 87#define CN23XX_OQ_INTR_TIME 100
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c
index 0be87d119a97..79f809479af6 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_droq.c
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_droq.c
@@ -155,11 +155,6 @@ octeon_droq_destroy_ring_buffers(struct octeon_device *oct,
155 recv_buffer_destroy(droq->recv_buf_list[i].buffer, 155 recv_buffer_destroy(droq->recv_buf_list[i].buffer,
156 pg_info); 156 pg_info);
157 157
158 if (droq->desc_ring && droq->desc_ring[i].info_ptr)
159 lio_unmap_ring_info(oct->pci_dev,
160 (u64)droq->
161 desc_ring[i].info_ptr,
162 OCT_DROQ_INFO_SIZE);
163 droq->recv_buf_list[i].buffer = NULL; 158 droq->recv_buf_list[i].buffer = NULL;
164 } 159 }
165 160
@@ -211,10 +206,7 @@ int octeon_delete_droq(struct octeon_device *oct, u32 q_no)
211 vfree(droq->recv_buf_list); 206 vfree(droq->recv_buf_list);
212 207
213 if (droq->info_base_addr) 208 if (droq->info_base_addr)
214 cnnic_free_aligned_dma(oct->pci_dev, droq->info_list, 209 lio_free_info_buffer(oct, droq);
215 droq->info_alloc_size,
216 droq->info_base_addr,
217 droq->info_list_dma);
218 210
219 if (droq->desc_ring) 211 if (droq->desc_ring)
220 lio_dma_free(oct, (droq->max_count * OCT_DROQ_DESC_SIZE), 212 lio_dma_free(oct, (droq->max_count * OCT_DROQ_DESC_SIZE),
@@ -294,12 +286,7 @@ int octeon_init_droq(struct octeon_device *oct,
294 dev_dbg(&oct->pci_dev->dev, "droq[%d]: num_desc: %d\n", q_no, 286 dev_dbg(&oct->pci_dev->dev, "droq[%d]: num_desc: %d\n", q_no,
295 droq->max_count); 287 droq->max_count);
296 288
297 droq->info_list = 289 droq->info_list = lio_alloc_info_buffer(oct, droq);
298 cnnic_numa_alloc_aligned_dma((droq->max_count *
299 OCT_DROQ_INFO_SIZE),
300 &droq->info_alloc_size,
301 &droq->info_base_addr,
302 numa_node);
303 if (!droq->info_list) { 290 if (!droq->info_list) {
304 dev_err(&oct->pci_dev->dev, "Cannot allocate memory for info list.\n"); 291 dev_err(&oct->pci_dev->dev, "Cannot allocate memory for info list.\n");
305 lio_dma_free(oct, (droq->max_count * OCT_DROQ_DESC_SIZE), 292 lio_dma_free(oct, (droq->max_count * OCT_DROQ_DESC_SIZE),
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_droq.h b/drivers/net/ethernet/cavium/liquidio/octeon_droq.h
index e62074090681..6982c0af5ecc 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_droq.h
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_droq.h
@@ -325,10 +325,10 @@ struct octeon_droq {
325 size_t desc_ring_dma; 325 size_t desc_ring_dma;
326 326
327 /** Info ptr list are allocated at this virtual address. */ 327 /** Info ptr list are allocated at this virtual address. */
328 size_t info_base_addr; 328 void *info_base_addr;
329 329
330 /** DMA mapped address of the info list */ 330 /** DMA mapped address of the info list */
331 size_t info_list_dma; 331 dma_addr_t info_list_dma;
332 332
333 /** Allocated size of info list. */ 333 /** Allocated size of info list. */
334 u32 info_alloc_size; 334 u32 info_alloc_size;
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_main.h b/drivers/net/ethernet/cavium/liquidio/octeon_main.h
index aa36e9ae7676..bed9ef17bc26 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_main.h
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_main.h
@@ -140,48 +140,6 @@ err_release_region:
140 return 1; 140 return 1;
141} 141}
142 142
143static inline void *
144cnnic_numa_alloc_aligned_dma(u32 size,
145 u32 *alloc_size,
146 size_t *orig_ptr,
147 int numa_node)
148{
149 int retries = 0;
150 void *ptr = NULL;
151
152#define OCTEON_MAX_ALLOC_RETRIES 1
153 do {
154 struct page *page = NULL;
155
156 page = alloc_pages_node(numa_node,
157 GFP_KERNEL,
158 get_order(size));
159 if (!page)
160 page = alloc_pages(GFP_KERNEL,
161 get_order(size));
162 ptr = (void *)page_address(page);
163 if ((unsigned long)ptr & 0x07) {
164 __free_pages(page, get_order(size));
165 ptr = NULL;
166 /* Increment the size required if the first
167 * attempt failed.
168 */
169 if (!retries)
170 size += 7;
171 }
172 retries++;
173 } while ((retries <= OCTEON_MAX_ALLOC_RETRIES) && !ptr);
174
175 *alloc_size = size;
176 *orig_ptr = (unsigned long)ptr;
177 if ((unsigned long)ptr & 0x07)
178 ptr = (void *)(((unsigned long)ptr + 7) & ~(7UL));
179 return ptr;
180}
181
182#define cnnic_free_aligned_dma(pci_dev, ptr, size, orig_ptr, dma_addr) \
183 free_pages(orig_ptr, get_order(size))
184
185static inline int 143static inline int
186sleep_cond(wait_queue_head_t *wait_queue, int *condition) 144sleep_cond(wait_queue_head_t *wait_queue, int *condition)
187{ 145{
diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_network.h b/drivers/net/ethernet/cavium/liquidio/octeon_network.h
index 6bb89419006e..eef2a1e8a7e3 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_network.h
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_network.h
@@ -62,6 +62,9 @@ struct lio {
62 62
63 /** Array of gather component linked lists */ 63 /** Array of gather component linked lists */
64 struct list_head *glist; 64 struct list_head *glist;
65 void **glists_virt_base;
66 dma_addr_t *glists_dma_base;
67 u32 glist_entry_size;
65 68
66 /** Pointer to the NIC properties for the Octeon device this network 69 /** Pointer to the NIC properties for the Octeon device this network
67 * interface is associated with. 70 * interface is associated with.
@@ -344,6 +347,29 @@ static inline void tx_buffer_free(void *buffer)
344#define lio_dma_free(oct, size, virt_addr, dma_addr) \ 347#define lio_dma_free(oct, size, virt_addr, dma_addr) \
345 dma_free_coherent(&(oct)->pci_dev->dev, size, virt_addr, dma_addr) 348 dma_free_coherent(&(oct)->pci_dev->dev, size, virt_addr, dma_addr)
346 349
350static inline void *
351lio_alloc_info_buffer(struct octeon_device *oct,
352 struct octeon_droq *droq)
353{
354 void *virt_ptr;
355
356 virt_ptr = lio_dma_alloc(oct, (droq->max_count * OCT_DROQ_INFO_SIZE),
357 &droq->info_list_dma);
358 if (virt_ptr) {
359 droq->info_alloc_size = droq->max_count * OCT_DROQ_INFO_SIZE;
360 droq->info_base_addr = virt_ptr;
361 }
362
363 return virt_ptr;
364}
365
366static inline void lio_free_info_buffer(struct octeon_device *oct,
367 struct octeon_droq *droq)
368{
369 lio_dma_free(oct, droq->info_alloc_size, droq->info_base_addr,
370 droq->info_list_dma);
371}
372
347static inline 373static inline
348void *get_rbd(struct sk_buff *skb) 374void *get_rbd(struct sk_buff *skb)
349{ 375{
@@ -359,22 +385,7 @@ void *get_rbd(struct sk_buff *skb)
359static inline u64 385static inline u64
360lio_map_ring_info(struct octeon_droq *droq, u32 i) 386lio_map_ring_info(struct octeon_droq *droq, u32 i)
361{ 387{
362 dma_addr_t dma_addr; 388 return droq->info_list_dma + (i * sizeof(struct octeon_droq_info));
363 struct octeon_device *oct = droq->oct_dev;
364
365 dma_addr = dma_map_single(&oct->pci_dev->dev, &droq->info_list[i],
366 OCT_DROQ_INFO_SIZE, DMA_FROM_DEVICE);
367
368 WARN_ON(dma_mapping_error(&oct->pci_dev->dev, dma_addr));
369
370 return (u64)dma_addr;
371}
372
373static inline void
374lio_unmap_ring_info(struct pci_dev *pci_dev,
375 u64 info_ptr, u32 size)
376{
377 dma_unmap_single(&pci_dev->dev, info_ptr, size, DMA_FROM_DEVICE);
378} 389}
379 390
380static inline u64 391static inline u64
diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h
index e739c7153562..2269ff562d95 100644
--- a/drivers/net/ethernet/cavium/thunder/nic.h
+++ b/drivers/net/ethernet/cavium/thunder/nic.h
@@ -269,6 +269,7 @@ struct nicvf {
269#define MAX_QUEUES_PER_QSET 8 269#define MAX_QUEUES_PER_QSET 8
270 struct queue_set *qs; 270 struct queue_set *qs;
271 struct nicvf_cq_poll *napi[8]; 271 struct nicvf_cq_poll *napi[8];
272 void *iommu_domain;
272 u8 vf_id; 273 u8 vf_id;
273 u8 sqs_id; 274 u8 sqs_id;
274 bool sqs_mode; 275 bool sqs_mode;
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index 6feaa24bcfd4..24017588f531 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -16,6 +16,7 @@
16#include <linux/log2.h> 16#include <linux/log2.h>
17#include <linux/prefetch.h> 17#include <linux/prefetch.h>
18#include <linux/irq.h> 18#include <linux/irq.h>
19#include <linux/iommu.h>
19 20
20#include "nic_reg.h" 21#include "nic_reg.h"
21#include "nic.h" 22#include "nic.h"
@@ -525,7 +526,12 @@ static void nicvf_snd_pkt_handler(struct net_device *netdev,
525 /* Get actual TSO descriptors and free them */ 526 /* Get actual TSO descriptors and free them */
526 tso_sqe = 527 tso_sqe =
527 (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, hdr->rsvd2); 528 (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, hdr->rsvd2);
529 nicvf_unmap_sndq_buffers(nic, sq, hdr->rsvd2,
530 tso_sqe->subdesc_cnt);
528 nicvf_put_sq_desc(sq, tso_sqe->subdesc_cnt + 1); 531 nicvf_put_sq_desc(sq, tso_sqe->subdesc_cnt + 1);
532 } else {
533 nicvf_unmap_sndq_buffers(nic, sq, cqe_tx->sqe_ptr,
534 hdr->subdesc_cnt);
529 } 535 }
530 nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1); 536 nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1);
531 prefetch(skb); 537 prefetch(skb);
@@ -576,6 +582,7 @@ static void nicvf_rcv_pkt_handler(struct net_device *netdev,
576{ 582{
577 struct sk_buff *skb; 583 struct sk_buff *skb;
578 struct nicvf *nic = netdev_priv(netdev); 584 struct nicvf *nic = netdev_priv(netdev);
585 struct nicvf *snic = nic;
579 int err = 0; 586 int err = 0;
580 int rq_idx; 587 int rq_idx;
581 588
@@ -592,7 +599,7 @@ static void nicvf_rcv_pkt_handler(struct net_device *netdev,
592 if (err && !cqe_rx->rb_cnt) 599 if (err && !cqe_rx->rb_cnt)
593 return; 600 return;
594 601
595 skb = nicvf_get_rcv_skb(nic, cqe_rx); 602 skb = nicvf_get_rcv_skb(snic, cqe_rx);
596 if (!skb) { 603 if (!skb) {
597 netdev_dbg(nic->netdev, "Packet not received\n"); 604 netdev_dbg(nic->netdev, "Packet not received\n");
598 return; 605 return;
@@ -1643,6 +1650,9 @@ static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1643 if (!pass1_silicon(nic->pdev)) 1650 if (!pass1_silicon(nic->pdev))
1644 nic->hw_tso = true; 1651 nic->hw_tso = true;
1645 1652
1653 /* Get iommu domain for iova to physical addr conversion */
1654 nic->iommu_domain = iommu_get_domain_for_dev(dev);
1655
1646 pci_read_config_word(nic->pdev, PCI_SUBSYSTEM_ID, &sdevid); 1656 pci_read_config_word(nic->pdev, PCI_SUBSYSTEM_ID, &sdevid);
1647 if (sdevid == 0xA134) 1657 if (sdevid == 0xA134)
1648 nic->t88 = true; 1658 nic->t88 = true;
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
index ac0390be3b12..f13289f0d238 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
@@ -10,6 +10,7 @@
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/ip.h> 11#include <linux/ip.h>
12#include <linux/etherdevice.h> 12#include <linux/etherdevice.h>
13#include <linux/iommu.h>
13#include <net/ip.h> 14#include <net/ip.h>
14#include <net/tso.h> 15#include <net/tso.h>
15 16
@@ -18,6 +19,16 @@
18#include "q_struct.h" 19#include "q_struct.h"
19#include "nicvf_queues.h" 20#include "nicvf_queues.h"
20 21
22#define NICVF_PAGE_ORDER ((PAGE_SIZE <= 4096) ? PAGE_ALLOC_COSTLY_ORDER : 0)
23
24static inline u64 nicvf_iova_to_phys(struct nicvf *nic, dma_addr_t dma_addr)
25{
26 /* Translation is installed only when IOMMU is present */
27 if (nic->iommu_domain)
28 return iommu_iova_to_phys(nic->iommu_domain, dma_addr);
29 return dma_addr;
30}
31
21static void nicvf_get_page(struct nicvf *nic) 32static void nicvf_get_page(struct nicvf *nic)
22{ 33{
23 if (!nic->rb_pageref || !nic->rb_page) 34 if (!nic->rb_pageref || !nic->rb_page)
@@ -87,7 +98,7 @@ static void nicvf_free_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem)
87static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp, 98static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
88 u32 buf_len, u64 **rbuf) 99 u32 buf_len, u64 **rbuf)
89{ 100{
90 int order = (PAGE_SIZE <= 4096) ? PAGE_ALLOC_COSTLY_ORDER : 0; 101 int order = NICVF_PAGE_ORDER;
91 102
92 /* Check if request can be accomodated in previous allocated page */ 103 /* Check if request can be accomodated in previous allocated page */
93 if (nic->rb_page && 104 if (nic->rb_page &&
@@ -97,22 +108,27 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
97 } 108 }
98 109
99 nicvf_get_page(nic); 110 nicvf_get_page(nic);
100 nic->rb_page = NULL;
101 111
102 /* Allocate a new page */ 112 /* Allocate a new page */
113 nic->rb_page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
114 order);
103 if (!nic->rb_page) { 115 if (!nic->rb_page) {
104 nic->rb_page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN, 116 this_cpu_inc(nic->pnicvf->drv_stats->rcv_buffer_alloc_failures);
105 order); 117 return -ENOMEM;
106 if (!nic->rb_page) {
107 this_cpu_inc(nic->pnicvf->drv_stats->
108 rcv_buffer_alloc_failures);
109 return -ENOMEM;
110 }
111 nic->rb_page_offset = 0;
112 } 118 }
113 119 nic->rb_page_offset = 0;
114ret: 120ret:
115 *rbuf = (u64 *)((u64)page_address(nic->rb_page) + nic->rb_page_offset); 121 /* HW will ensure data coherency, CPU sync not required */
122 *rbuf = (u64 *)((u64)dma_map_page_attrs(&nic->pdev->dev, nic->rb_page,
123 nic->rb_page_offset, buf_len,
124 DMA_FROM_DEVICE,
125 DMA_ATTR_SKIP_CPU_SYNC));
126 if (dma_mapping_error(&nic->pdev->dev, (dma_addr_t)*rbuf)) {
127 if (!nic->rb_page_offset)
128 __free_pages(nic->rb_page, order);
129 nic->rb_page = NULL;
130 return -ENOMEM;
131 }
116 nic->rb_page_offset += buf_len; 132 nic->rb_page_offset += buf_len;
117 133
118 return 0; 134 return 0;
@@ -158,16 +174,21 @@ static int nicvf_init_rbdr(struct nicvf *nic, struct rbdr *rbdr,
158 rbdr->dma_size = buf_size; 174 rbdr->dma_size = buf_size;
159 rbdr->enable = true; 175 rbdr->enable = true;
160 rbdr->thresh = RBDR_THRESH; 176 rbdr->thresh = RBDR_THRESH;
177 rbdr->head = 0;
178 rbdr->tail = 0;
161 179
162 nic->rb_page = NULL; 180 nic->rb_page = NULL;
163 for (idx = 0; idx < ring_len; idx++) { 181 for (idx = 0; idx < ring_len; idx++) {
164 err = nicvf_alloc_rcv_buffer(nic, GFP_KERNEL, RCV_FRAG_LEN, 182 err = nicvf_alloc_rcv_buffer(nic, GFP_KERNEL, RCV_FRAG_LEN,
165 &rbuf); 183 &rbuf);
166 if (err) 184 if (err) {
185 /* To free already allocated and mapped ones */
186 rbdr->tail = idx - 1;
167 return err; 187 return err;
188 }
168 189
169 desc = GET_RBDR_DESC(rbdr, idx); 190 desc = GET_RBDR_DESC(rbdr, idx);
170 desc->buf_addr = virt_to_phys(rbuf) >> NICVF_RCV_BUF_ALIGN; 191 desc->buf_addr = (u64)rbuf >> NICVF_RCV_BUF_ALIGN;
171 } 192 }
172 193
173 nicvf_get_page(nic); 194 nicvf_get_page(nic);
@@ -179,7 +200,7 @@ static int nicvf_init_rbdr(struct nicvf *nic, struct rbdr *rbdr,
179static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr) 200static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
180{ 201{
181 int head, tail; 202 int head, tail;
182 u64 buf_addr; 203 u64 buf_addr, phys_addr;
183 struct rbdr_entry_t *desc; 204 struct rbdr_entry_t *desc;
184 205
185 if (!rbdr) 206 if (!rbdr)
@@ -192,18 +213,26 @@ static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
192 head = rbdr->head; 213 head = rbdr->head;
193 tail = rbdr->tail; 214 tail = rbdr->tail;
194 215
195 /* Free SKBs */ 216 /* Release page references */
196 while (head != tail) { 217 while (head != tail) {
197 desc = GET_RBDR_DESC(rbdr, head); 218 desc = GET_RBDR_DESC(rbdr, head);
198 buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN; 219 buf_addr = ((u64)desc->buf_addr) << NICVF_RCV_BUF_ALIGN;
199 put_page(virt_to_page(phys_to_virt(buf_addr))); 220 phys_addr = nicvf_iova_to_phys(nic, buf_addr);
221 dma_unmap_page_attrs(&nic->pdev->dev, buf_addr, RCV_FRAG_LEN,
222 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
223 if (phys_addr)
224 put_page(virt_to_page(phys_to_virt(phys_addr)));
200 head++; 225 head++;
201 head &= (rbdr->dmem.q_len - 1); 226 head &= (rbdr->dmem.q_len - 1);
202 } 227 }
203 /* Free SKB of tail desc */ 228 /* Release buffer of tail desc */
204 desc = GET_RBDR_DESC(rbdr, tail); 229 desc = GET_RBDR_DESC(rbdr, tail);
205 buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN; 230 buf_addr = ((u64)desc->buf_addr) << NICVF_RCV_BUF_ALIGN;
206 put_page(virt_to_page(phys_to_virt(buf_addr))); 231 phys_addr = nicvf_iova_to_phys(nic, buf_addr);
232 dma_unmap_page_attrs(&nic->pdev->dev, buf_addr, RCV_FRAG_LEN,
233 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
234 if (phys_addr)
235 put_page(virt_to_page(phys_to_virt(phys_addr)));
207 236
208 /* Free RBDR ring */ 237 /* Free RBDR ring */
209 nicvf_free_q_desc_mem(nic, &rbdr->dmem); 238 nicvf_free_q_desc_mem(nic, &rbdr->dmem);
@@ -250,7 +279,7 @@ refill:
250 break; 279 break;
251 280
252 desc = GET_RBDR_DESC(rbdr, tail); 281 desc = GET_RBDR_DESC(rbdr, tail);
253 desc->buf_addr = virt_to_phys(rbuf) >> NICVF_RCV_BUF_ALIGN; 282 desc->buf_addr = (u64)rbuf >> NICVF_RCV_BUF_ALIGN;
254 refill_rb_cnt--; 283 refill_rb_cnt--;
255 new_rb++; 284 new_rb++;
256 } 285 }
@@ -361,9 +390,29 @@ static int nicvf_init_snd_queue(struct nicvf *nic,
361 return 0; 390 return 0;
362} 391}
363 392
393void nicvf_unmap_sndq_buffers(struct nicvf *nic, struct snd_queue *sq,
394 int hdr_sqe, u8 subdesc_cnt)
395{
396 u8 idx;
397 struct sq_gather_subdesc *gather;
398
399 /* Unmap DMA mapped skb data buffers */
400 for (idx = 0; idx < subdesc_cnt; idx++) {
401 hdr_sqe++;
402 hdr_sqe &= (sq->dmem.q_len - 1);
403 gather = (struct sq_gather_subdesc *)GET_SQ_DESC(sq, hdr_sqe);
404 /* HW will ensure data coherency, CPU sync not required */
405 dma_unmap_page_attrs(&nic->pdev->dev, gather->addr,
406 gather->size, DMA_TO_DEVICE,
407 DMA_ATTR_SKIP_CPU_SYNC);
408 }
409}
410
364static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq) 411static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
365{ 412{
366 struct sk_buff *skb; 413 struct sk_buff *skb;
414 struct sq_hdr_subdesc *hdr;
415 struct sq_hdr_subdesc *tso_sqe;
367 416
368 if (!sq) 417 if (!sq)
369 return; 418 return;
@@ -379,8 +428,22 @@ static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
379 smp_rmb(); 428 smp_rmb();
380 while (sq->head != sq->tail) { 429 while (sq->head != sq->tail) {
381 skb = (struct sk_buff *)sq->skbuff[sq->head]; 430 skb = (struct sk_buff *)sq->skbuff[sq->head];
382 if (skb) 431 if (!skb)
383 dev_kfree_skb_any(skb); 432 goto next;
433 hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, sq->head);
434 /* Check for dummy descriptor used for HW TSO offload on 88xx */
435 if (hdr->dont_send) {
436 /* Get actual TSO descriptors and unmap them */
437 tso_sqe =
438 (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, hdr->rsvd2);
439 nicvf_unmap_sndq_buffers(nic, sq, hdr->rsvd2,
440 tso_sqe->subdesc_cnt);
441 } else {
442 nicvf_unmap_sndq_buffers(nic, sq, sq->head,
443 hdr->subdesc_cnt);
444 }
445 dev_kfree_skb_any(skb);
446next:
384 sq->head++; 447 sq->head++;
385 sq->head &= (sq->dmem.q_len - 1); 448 sq->head &= (sq->dmem.q_len - 1);
386 } 449 }
@@ -559,9 +622,11 @@ static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
559 nicvf_send_msg_to_pf(nic, &mbx); 622 nicvf_send_msg_to_pf(nic, &mbx);
560 623
561 if (!nic->sqs_mode && (qidx == 0)) { 624 if (!nic->sqs_mode && (qidx == 0)) {
562 /* Enable checking L3/L4 length and TCP/UDP checksums */ 625 /* Enable checking L3/L4 length and TCP/UDP checksums
626 * Also allow IPv6 pkts with zero UDP checksum.
627 */
563 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0, 628 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0,
564 (BIT(24) | BIT(23) | BIT(21))); 629 (BIT(24) | BIT(23) | BIT(21) | BIT(20)));
565 nicvf_config_vlan_stripping(nic, nic->netdev->features); 630 nicvf_config_vlan_stripping(nic, nic->netdev->features);
566 } 631 }
567 632
@@ -882,6 +947,14 @@ static inline int nicvf_get_sq_desc(struct snd_queue *sq, int desc_cnt)
882 return qentry; 947 return qentry;
883} 948}
884 949
950/* Rollback to previous tail pointer when descriptors not used */
951static inline void nicvf_rollback_sq_desc(struct snd_queue *sq,
952 int qentry, int desc_cnt)
953{
954 sq->tail = qentry;
955 atomic_add(desc_cnt, &sq->free_cnt);
956}
957
885/* Free descriptor back to SQ for future use */ 958/* Free descriptor back to SQ for future use */
886void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt) 959void nicvf_put_sq_desc(struct snd_queue *sq, int desc_cnt)
887{ 960{
@@ -1207,8 +1280,9 @@ int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
1207 struct sk_buff *skb, u8 sq_num) 1280 struct sk_buff *skb, u8 sq_num)
1208{ 1281{
1209 int i, size; 1282 int i, size;
1210 int subdesc_cnt, tso_sqe = 0; 1283 int subdesc_cnt, hdr_sqe = 0;
1211 int qentry; 1284 int qentry;
1285 u64 dma_addr;
1212 1286
1213 subdesc_cnt = nicvf_sq_subdesc_required(nic, skb); 1287 subdesc_cnt = nicvf_sq_subdesc_required(nic, skb);
1214 if (subdesc_cnt > atomic_read(&sq->free_cnt)) 1288 if (subdesc_cnt > atomic_read(&sq->free_cnt))
@@ -1223,12 +1297,21 @@ int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
1223 /* Add SQ header subdesc */ 1297 /* Add SQ header subdesc */
1224 nicvf_sq_add_hdr_subdesc(nic, sq, qentry, subdesc_cnt - 1, 1298 nicvf_sq_add_hdr_subdesc(nic, sq, qentry, subdesc_cnt - 1,
1225 skb, skb->len); 1299 skb, skb->len);
1226 tso_sqe = qentry; 1300 hdr_sqe = qentry;
1227 1301
1228 /* Add SQ gather subdescs */ 1302 /* Add SQ gather subdescs */
1229 qentry = nicvf_get_nxt_sqentry(sq, qentry); 1303 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1230 size = skb_is_nonlinear(skb) ? skb_headlen(skb) : skb->len; 1304 size = skb_is_nonlinear(skb) ? skb_headlen(skb) : skb->len;
1231 nicvf_sq_add_gather_subdesc(sq, qentry, size, virt_to_phys(skb->data)); 1305 /* HW will ensure data coherency, CPU sync not required */
1306 dma_addr = dma_map_page_attrs(&nic->pdev->dev, virt_to_page(skb->data),
1307 offset_in_page(skb->data), size,
1308 DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
1309 if (dma_mapping_error(&nic->pdev->dev, dma_addr)) {
1310 nicvf_rollback_sq_desc(sq, qentry, subdesc_cnt);
1311 return 0;
1312 }
1313
1314 nicvf_sq_add_gather_subdesc(sq, qentry, size, dma_addr);
1232 1315
1233 /* Check for scattered buffer */ 1316 /* Check for scattered buffer */
1234 if (!skb_is_nonlinear(skb)) 1317 if (!skb_is_nonlinear(skb))
@@ -1241,15 +1324,26 @@ int nicvf_sq_append_skb(struct nicvf *nic, struct snd_queue *sq,
1241 1324
1242 qentry = nicvf_get_nxt_sqentry(sq, qentry); 1325 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1243 size = skb_frag_size(frag); 1326 size = skb_frag_size(frag);
1244 nicvf_sq_add_gather_subdesc(sq, qentry, size, 1327 dma_addr = dma_map_page_attrs(&nic->pdev->dev,
1245 virt_to_phys( 1328 skb_frag_page(frag),
1246 skb_frag_address(frag))); 1329 frag->page_offset, size,
1330 DMA_TO_DEVICE,
1331 DMA_ATTR_SKIP_CPU_SYNC);
1332 if (dma_mapping_error(&nic->pdev->dev, dma_addr)) {
1333 /* Free entire chain of mapped buffers
1334 * here 'i' = frags mapped + above mapped skb->data
1335 */
1336 nicvf_unmap_sndq_buffers(nic, sq, hdr_sqe, i);
1337 nicvf_rollback_sq_desc(sq, qentry, subdesc_cnt);
1338 return 0;
1339 }
1340 nicvf_sq_add_gather_subdesc(sq, qentry, size, dma_addr);
1247 } 1341 }
1248 1342
1249doorbell: 1343doorbell:
1250 if (nic->t88 && skb_shinfo(skb)->gso_size) { 1344 if (nic->t88 && skb_shinfo(skb)->gso_size) {
1251 qentry = nicvf_get_nxt_sqentry(sq, qentry); 1345 qentry = nicvf_get_nxt_sqentry(sq, qentry);
1252 nicvf_sq_add_cqe_subdesc(sq, qentry, tso_sqe, skb); 1346 nicvf_sq_add_cqe_subdesc(sq, qentry, hdr_sqe, skb);
1253 } 1347 }
1254 1348
1255 nicvf_sq_doorbell(nic, skb, sq_num, subdesc_cnt); 1349 nicvf_sq_doorbell(nic, skb, sq_num, subdesc_cnt);
@@ -1282,6 +1376,7 @@ struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1282 int offset; 1376 int offset;
1283 u16 *rb_lens = NULL; 1377 u16 *rb_lens = NULL;
1284 u64 *rb_ptrs = NULL; 1378 u64 *rb_ptrs = NULL;
1379 u64 phys_addr;
1285 1380
1286 rb_lens = (void *)cqe_rx + (3 * sizeof(u64)); 1381 rb_lens = (void *)cqe_rx + (3 * sizeof(u64));
1287 /* Except 88xx pass1 on all other chips CQE_RX2_S is added to 1382 /* Except 88xx pass1 on all other chips CQE_RX2_S is added to
@@ -1296,15 +1391,23 @@ struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1296 else 1391 else
1297 rb_ptrs = (void *)cqe_rx + (7 * sizeof(u64)); 1392 rb_ptrs = (void *)cqe_rx + (7 * sizeof(u64));
1298 1393
1299 netdev_dbg(nic->netdev, "%s rb_cnt %d rb0_ptr %llx rb0_sz %d\n",
1300 __func__, cqe_rx->rb_cnt, cqe_rx->rb0_ptr, cqe_rx->rb0_sz);
1301
1302 for (frag = 0; frag < cqe_rx->rb_cnt; frag++) { 1394 for (frag = 0; frag < cqe_rx->rb_cnt; frag++) {
1303 payload_len = rb_lens[frag_num(frag)]; 1395 payload_len = rb_lens[frag_num(frag)];
1396 phys_addr = nicvf_iova_to_phys(nic, *rb_ptrs);
1397 if (!phys_addr) {
1398 if (skb)
1399 dev_kfree_skb_any(skb);
1400 return NULL;
1401 }
1402
1304 if (!frag) { 1403 if (!frag) {
1305 /* First fragment */ 1404 /* First fragment */
1405 dma_unmap_page_attrs(&nic->pdev->dev,
1406 *rb_ptrs - cqe_rx->align_pad,
1407 RCV_FRAG_LEN, DMA_FROM_DEVICE,
1408 DMA_ATTR_SKIP_CPU_SYNC);
1306 skb = nicvf_rb_ptr_to_skb(nic, 1409 skb = nicvf_rb_ptr_to_skb(nic,
1307 *rb_ptrs - cqe_rx->align_pad, 1410 phys_addr - cqe_rx->align_pad,
1308 payload_len); 1411 payload_len);
1309 if (!skb) 1412 if (!skb)
1310 return NULL; 1413 return NULL;
@@ -1312,8 +1415,11 @@ struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1312 skb_put(skb, payload_len); 1415 skb_put(skb, payload_len);
1313 } else { 1416 } else {
1314 /* Add fragments */ 1417 /* Add fragments */
1315 page = virt_to_page(phys_to_virt(*rb_ptrs)); 1418 dma_unmap_page_attrs(&nic->pdev->dev, *rb_ptrs,
1316 offset = phys_to_virt(*rb_ptrs) - page_address(page); 1419 RCV_FRAG_LEN, DMA_FROM_DEVICE,
1420 DMA_ATTR_SKIP_CPU_SYNC);
1421 page = virt_to_page(phys_to_virt(phys_addr));
1422 offset = phys_to_virt(phys_addr) - page_address(page);
1317 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 1423 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1318 offset, payload_len, RCV_FRAG_LEN); 1424 offset, payload_len, RCV_FRAG_LEN);
1319 } 1425 }
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
index 5cb84da99a2d..10cb4b84625b 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
@@ -87,7 +87,7 @@
87#define RCV_BUF_COUNT (1ULL << (RBDR_SIZE + 13)) 87#define RCV_BUF_COUNT (1ULL << (RBDR_SIZE + 13))
88#define MAX_RCV_BUF_COUNT (1ULL << (RBDR_SIZE6 + 13)) 88#define MAX_RCV_BUF_COUNT (1ULL << (RBDR_SIZE6 + 13))
89#define RBDR_THRESH (RCV_BUF_COUNT / 2) 89#define RBDR_THRESH (RCV_BUF_COUNT / 2)
90#define DMA_BUFFER_LEN 2048 /* In multiples of 128bytes */ 90#define DMA_BUFFER_LEN 1536 /* In multiples of 128bytes */
91#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \ 91#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
92 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 92 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
93 93
@@ -301,6 +301,8 @@ struct queue_set {
301 301
302#define CQ_ERR_MASK (CQ_WR_FULL | CQ_WR_DISABLE | CQ_WR_FAULT) 302#define CQ_ERR_MASK (CQ_WR_FULL | CQ_WR_DISABLE | CQ_WR_FAULT)
303 303
304void nicvf_unmap_sndq_buffers(struct nicvf *nic, struct snd_queue *sq,
305 int hdr_sqe, u8 subdesc_cnt);
304void nicvf_config_vlan_stripping(struct nicvf *nic, 306void nicvf_config_vlan_stripping(struct nicvf *nic,
305 netdev_features_t features); 307 netdev_features_t features);
306int nicvf_set_qset_resources(struct nicvf *nic); 308int nicvf_set_qset_resources(struct nicvf *nic);
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 4c8e8cf730bb..64a1095e4d14 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -123,14 +123,44 @@ static int bgx_poll_reg(struct bgx *bgx, u8 lmac, u64 reg, u64 mask, bool zero)
123 return 1; 123 return 1;
124} 124}
125 125
126static int max_bgx_per_node;
127static void set_max_bgx_per_node(struct pci_dev *pdev)
128{
129 u16 sdevid;
130
131 if (max_bgx_per_node)
132 return;
133
134 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdevid);
135 switch (sdevid) {
136 case PCI_SUBSYS_DEVID_81XX_BGX:
137 max_bgx_per_node = MAX_BGX_PER_CN81XX;
138 break;
139 case PCI_SUBSYS_DEVID_83XX_BGX:
140 max_bgx_per_node = MAX_BGX_PER_CN83XX;
141 break;
142 case PCI_SUBSYS_DEVID_88XX_BGX:
143 default:
144 max_bgx_per_node = MAX_BGX_PER_CN88XX;
145 break;
146 }
147}
148
149static struct bgx *get_bgx(int node, int bgx_idx)
150{
151 int idx = (node * max_bgx_per_node) + bgx_idx;
152
153 return bgx_vnic[idx];
154}
155
126/* Return number of BGX present in HW */ 156/* Return number of BGX present in HW */
127unsigned bgx_get_map(int node) 157unsigned bgx_get_map(int node)
128{ 158{
129 int i; 159 int i;
130 unsigned map = 0; 160 unsigned map = 0;
131 161
132 for (i = 0; i < MAX_BGX_PER_NODE; i++) { 162 for (i = 0; i < max_bgx_per_node; i++) {
133 if (bgx_vnic[(node * MAX_BGX_PER_NODE) + i]) 163 if (bgx_vnic[(node * max_bgx_per_node) + i])
134 map |= (1 << i); 164 map |= (1 << i);
135 } 165 }
136 166
@@ -143,7 +173,7 @@ int bgx_get_lmac_count(int node, int bgx_idx)
143{ 173{
144 struct bgx *bgx; 174 struct bgx *bgx;
145 175
146 bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 176 bgx = get_bgx(node, bgx_idx);
147 if (bgx) 177 if (bgx)
148 return bgx->lmac_count; 178 return bgx->lmac_count;
149 179
@@ -158,7 +188,7 @@ void bgx_get_lmac_link_state(int node, int bgx_idx, int lmacid, void *status)
158 struct bgx *bgx; 188 struct bgx *bgx;
159 struct lmac *lmac; 189 struct lmac *lmac;
160 190
161 bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 191 bgx = get_bgx(node, bgx_idx);
162 if (!bgx) 192 if (!bgx)
163 return; 193 return;
164 194
@@ -172,7 +202,7 @@ EXPORT_SYMBOL(bgx_get_lmac_link_state);
172 202
173const u8 *bgx_get_lmac_mac(int node, int bgx_idx, int lmacid) 203const u8 *bgx_get_lmac_mac(int node, int bgx_idx, int lmacid)
174{ 204{
175 struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 205 struct bgx *bgx = get_bgx(node, bgx_idx);
176 206
177 if (bgx) 207 if (bgx)
178 return bgx->lmac[lmacid].mac; 208 return bgx->lmac[lmacid].mac;
@@ -183,7 +213,7 @@ EXPORT_SYMBOL(bgx_get_lmac_mac);
183 213
184void bgx_set_lmac_mac(int node, int bgx_idx, int lmacid, const u8 *mac) 214void bgx_set_lmac_mac(int node, int bgx_idx, int lmacid, const u8 *mac)
185{ 215{
186 struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 216 struct bgx *bgx = get_bgx(node, bgx_idx);
187 217
188 if (!bgx) 218 if (!bgx)
189 return; 219 return;
@@ -194,7 +224,7 @@ EXPORT_SYMBOL(bgx_set_lmac_mac);
194 224
195void bgx_lmac_rx_tx_enable(int node, int bgx_idx, int lmacid, bool enable) 225void bgx_lmac_rx_tx_enable(int node, int bgx_idx, int lmacid, bool enable)
196{ 226{
197 struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 227 struct bgx *bgx = get_bgx(node, bgx_idx);
198 struct lmac *lmac; 228 struct lmac *lmac;
199 u64 cfg; 229 u64 cfg;
200 230
@@ -217,7 +247,7 @@ EXPORT_SYMBOL(bgx_lmac_rx_tx_enable);
217void bgx_lmac_get_pfc(int node, int bgx_idx, int lmacid, void *pause) 247void bgx_lmac_get_pfc(int node, int bgx_idx, int lmacid, void *pause)
218{ 248{
219 struct pfc *pfc = (struct pfc *)pause; 249 struct pfc *pfc = (struct pfc *)pause;
220 struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_CN88XX) + bgx_idx]; 250 struct bgx *bgx = get_bgx(node, bgx_idx);
221 struct lmac *lmac; 251 struct lmac *lmac;
222 u64 cfg; 252 u64 cfg;
223 253
@@ -237,7 +267,7 @@ EXPORT_SYMBOL(bgx_lmac_get_pfc);
237void bgx_lmac_set_pfc(int node, int bgx_idx, int lmacid, void *pause) 267void bgx_lmac_set_pfc(int node, int bgx_idx, int lmacid, void *pause)
238{ 268{
239 struct pfc *pfc = (struct pfc *)pause; 269 struct pfc *pfc = (struct pfc *)pause;
240 struct bgx *bgx = bgx_vnic[(node * MAX_BGX_PER_CN88XX) + bgx_idx]; 270 struct bgx *bgx = get_bgx(node, bgx_idx);
241 struct lmac *lmac; 271 struct lmac *lmac;
242 u64 cfg; 272 u64 cfg;
243 273
@@ -369,7 +399,7 @@ u64 bgx_get_rx_stats(int node, int bgx_idx, int lmac, int idx)
369{ 399{
370 struct bgx *bgx; 400 struct bgx *bgx;
371 401
372 bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 402 bgx = get_bgx(node, bgx_idx);
373 if (!bgx) 403 if (!bgx)
374 return 0; 404 return 0;
375 405
@@ -383,7 +413,7 @@ u64 bgx_get_tx_stats(int node, int bgx_idx, int lmac, int idx)
383{ 413{
384 struct bgx *bgx; 414 struct bgx *bgx;
385 415
386 bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 416 bgx = get_bgx(node, bgx_idx);
387 if (!bgx) 417 if (!bgx)
388 return 0; 418 return 0;
389 419
@@ -411,7 +441,7 @@ void bgx_lmac_internal_loopback(int node, int bgx_idx,
411 struct lmac *lmac; 441 struct lmac *lmac;
412 u64 cfg; 442 u64 cfg;
413 443
414 bgx = bgx_vnic[(node * MAX_BGX_PER_NODE) + bgx_idx]; 444 bgx = get_bgx(node, bgx_idx);
415 if (!bgx) 445 if (!bgx)
416 return; 446 return;
417 447
@@ -1011,12 +1041,6 @@ static void bgx_print_qlm_mode(struct bgx *bgx, u8 lmacid)
1011 dev_info(dev, "%s: 40G_KR4\n", (char *)str); 1041 dev_info(dev, "%s: 40G_KR4\n", (char *)str);
1012 break; 1042 break;
1013 case BGX_MODE_QSGMII: 1043 case BGX_MODE_QSGMII:
1014 if ((lmacid == 0) &&
1015 (bgx_get_lane2sds_cfg(bgx, lmac) != lmacid))
1016 return;
1017 if ((lmacid == 2) &&
1018 (bgx_get_lane2sds_cfg(bgx, lmac) == lmacid))
1019 return;
1020 dev_info(dev, "%s: QSGMII\n", (char *)str); 1044 dev_info(dev, "%s: QSGMII\n", (char *)str);
1021 break; 1045 break;
1022 case BGX_MODE_RGMII: 1046 case BGX_MODE_RGMII:
@@ -1334,11 +1358,13 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1334 goto err_release_regions; 1358 goto err_release_regions;
1335 } 1359 }
1336 1360
1361 set_max_bgx_per_node(pdev);
1362
1337 pci_read_config_word(pdev, PCI_DEVICE_ID, &sdevid); 1363 pci_read_config_word(pdev, PCI_DEVICE_ID, &sdevid);
1338 if (sdevid != PCI_DEVICE_ID_THUNDER_RGX) { 1364 if (sdevid != PCI_DEVICE_ID_THUNDER_RGX) {
1339 bgx->bgx_id = (pci_resource_start(pdev, 1365 bgx->bgx_id = (pci_resource_start(pdev,
1340 PCI_CFG_REG_BAR_NUM) >> 24) & BGX_ID_MASK; 1366 PCI_CFG_REG_BAR_NUM) >> 24) & BGX_ID_MASK;
1341 bgx->bgx_id += nic_get_node_id(pdev) * MAX_BGX_PER_NODE; 1367 bgx->bgx_id += nic_get_node_id(pdev) * max_bgx_per_node;
1342 bgx->max_lmac = MAX_LMAC_PER_BGX; 1368 bgx->max_lmac = MAX_LMAC_PER_BGX;
1343 bgx_vnic[bgx->bgx_id] = bgx; 1369 bgx_vnic[bgx->bgx_id] = bgx;
1344 } else { 1370 } else {
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
index a60f189429bb..c5080f2cead5 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
@@ -22,7 +22,6 @@
22#define MAX_BGX_PER_CN88XX 2 22#define MAX_BGX_PER_CN88XX 2
23#define MAX_BGX_PER_CN81XX 3 /* 2 BGXs + 1 RGX */ 23#define MAX_BGX_PER_CN81XX 3 /* 2 BGXs + 1 RGX */
24#define MAX_BGX_PER_CN83XX 4 24#define MAX_BGX_PER_CN83XX 4
25#define MAX_BGX_PER_NODE 4
26#define MAX_LMAC_PER_BGX 4 25#define MAX_LMAC_PER_BGX 4
27#define MAX_BGX_CHANS_PER_LMAC 16 26#define MAX_BGX_CHANS_PER_LMAC 16
28#define MAX_DMAC_PER_LMAC 8 27#define MAX_DMAC_PER_LMAC 8
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 275c2e2349ad..c44036d5761a 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2589,8 +2589,6 @@ static int emac_dt_mdio_probe(struct emac_instance *dev)
2589static int emac_dt_phy_connect(struct emac_instance *dev, 2589static int emac_dt_phy_connect(struct emac_instance *dev,
2590 struct device_node *phy_handle) 2590 struct device_node *phy_handle)
2591{ 2591{
2592 int res;
2593
2594 dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def), 2592 dev->phy.def = devm_kzalloc(&dev->ofdev->dev, sizeof(*dev->phy.def),
2595 GFP_KERNEL); 2593 GFP_KERNEL);
2596 if (!dev->phy.def) 2594 if (!dev->phy.def)
@@ -2617,7 +2615,7 @@ static int emac_dt_phy_probe(struct emac_instance *dev)
2617{ 2615{
2618 struct device_node *np = dev->ofdev->dev.of_node; 2616 struct device_node *np = dev->ofdev->dev.of_node;
2619 struct device_node *phy_handle; 2617 struct device_node *phy_handle;
2620 int res = 0; 2618 int res = 1;
2621 2619
2622 phy_handle = of_parse_phandle(np, "phy-handle", 0); 2620 phy_handle = of_parse_phandle(np, "phy-handle", 0);
2623 2621
@@ -2714,13 +2712,24 @@ static int emac_init_phy(struct emac_instance *dev)
2714 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { 2712 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) {
2715 int res = emac_dt_phy_probe(dev); 2713 int res = emac_dt_phy_probe(dev);
2716 2714
2717 mutex_unlock(&emac_phy_map_lock); 2715 switch (res) {
2718 if (!res) 2716 case 1:
2717 /* No phy-handle property configured.
2718 * Continue with the existing phy probe
2719 * and setup code.
2720 */
2721 break;
2722
2723 case 0:
2724 mutex_unlock(&emac_phy_map_lock);
2719 goto init_phy; 2725 goto init_phy;
2720 2726
2721 dev_err(&dev->ofdev->dev, "failed to attach dt phy (%d).\n", 2727 default:
2722 res); 2728 mutex_unlock(&emac_phy_map_lock);
2723 return res; 2729 dev_err(&dev->ofdev->dev, "failed to attach dt phy (%d).\n",
2730 res);
2731 return res;
2732 }
2724 } 2733 }
2725 2734
2726 if (dev->phy_address != 0xffffffff) 2735 if (dev->phy_address != 0xffffffff)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 9198e6bd5160..5f11b4dc95d2 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -404,7 +404,7 @@ static int ibmvnic_open(struct net_device *netdev)
404 send_map_query(adapter); 404 send_map_query(adapter);
405 for (i = 0; i < rxadd_subcrqs; i++) { 405 for (i = 0; i < rxadd_subcrqs; i++) {
406 init_rx_pool(adapter, &adapter->rx_pool[i], 406 init_rx_pool(adapter, &adapter->rx_pool[i],
407 IBMVNIC_BUFFS_PER_POOL, i, 407 adapter->req_rx_add_entries_per_subcrq, i,
408 be64_to_cpu(size_array[i]), 1); 408 be64_to_cpu(size_array[i]), 1);
409 if (alloc_rx_pool(adapter, &adapter->rx_pool[i])) { 409 if (alloc_rx_pool(adapter, &adapter->rx_pool[i])) {
410 dev_err(dev, "Couldn't alloc rx pool\n"); 410 dev_err(dev, "Couldn't alloc rx pool\n");
@@ -419,23 +419,23 @@ static int ibmvnic_open(struct net_device *netdev)
419 for (i = 0; i < tx_subcrqs; i++) { 419 for (i = 0; i < tx_subcrqs; i++) {
420 tx_pool = &adapter->tx_pool[i]; 420 tx_pool = &adapter->tx_pool[i];
421 tx_pool->tx_buff = 421 tx_pool->tx_buff =
422 kcalloc(adapter->max_tx_entries_per_subcrq, 422 kcalloc(adapter->req_tx_entries_per_subcrq,
423 sizeof(struct ibmvnic_tx_buff), GFP_KERNEL); 423 sizeof(struct ibmvnic_tx_buff), GFP_KERNEL);
424 if (!tx_pool->tx_buff) 424 if (!tx_pool->tx_buff)
425 goto tx_pool_alloc_failed; 425 goto tx_pool_alloc_failed;
426 426
427 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff, 427 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
428 adapter->max_tx_entries_per_subcrq * 428 adapter->req_tx_entries_per_subcrq *
429 adapter->req_mtu)) 429 adapter->req_mtu))
430 goto tx_ltb_alloc_failed; 430 goto tx_ltb_alloc_failed;
431 431
432 tx_pool->free_map = 432 tx_pool->free_map =
433 kcalloc(adapter->max_tx_entries_per_subcrq, 433 kcalloc(adapter->req_tx_entries_per_subcrq,
434 sizeof(int), GFP_KERNEL); 434 sizeof(int), GFP_KERNEL);
435 if (!tx_pool->free_map) 435 if (!tx_pool->free_map)
436 goto tx_fm_alloc_failed; 436 goto tx_fm_alloc_failed;
437 437
438 for (j = 0; j < adapter->max_tx_entries_per_subcrq; j++) 438 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
439 tx_pool->free_map[j] = j; 439 tx_pool->free_map[j] = j;
440 440
441 tx_pool->consumer_index = 0; 441 tx_pool->consumer_index = 0;
@@ -705,6 +705,7 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
705 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req; 705 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
706 struct device *dev = &adapter->vdev->dev; 706 struct device *dev = &adapter->vdev->dev;
707 struct ibmvnic_tx_buff *tx_buff = NULL; 707 struct ibmvnic_tx_buff *tx_buff = NULL;
708 struct ibmvnic_sub_crq_queue *tx_scrq;
708 struct ibmvnic_tx_pool *tx_pool; 709 struct ibmvnic_tx_pool *tx_pool;
709 unsigned int tx_send_failed = 0; 710 unsigned int tx_send_failed = 0;
710 unsigned int tx_map_failed = 0; 711 unsigned int tx_map_failed = 0;
@@ -724,6 +725,7 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
724 int ret = 0; 725 int ret = 0;
725 726
726 tx_pool = &adapter->tx_pool[queue_num]; 727 tx_pool = &adapter->tx_pool[queue_num];
728 tx_scrq = adapter->tx_scrq[queue_num];
727 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb)); 729 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
728 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + 730 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
729 be32_to_cpu(adapter->login_rsp_buf-> 731 be32_to_cpu(adapter->login_rsp_buf->
@@ -744,7 +746,7 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
744 746
745 tx_pool->consumer_index = 747 tx_pool->consumer_index =
746 (tx_pool->consumer_index + 1) % 748 (tx_pool->consumer_index + 1) %
747 adapter->max_tx_entries_per_subcrq; 749 adapter->req_tx_entries_per_subcrq;
748 750
749 tx_buff = &tx_pool->tx_buff[index]; 751 tx_buff = &tx_pool->tx_buff[index];
750 tx_buff->skb = skb; 752 tx_buff->skb = skb;
@@ -817,7 +819,7 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
817 819
818 if (tx_pool->consumer_index == 0) 820 if (tx_pool->consumer_index == 0)
819 tx_pool->consumer_index = 821 tx_pool->consumer_index =
820 adapter->max_tx_entries_per_subcrq - 1; 822 adapter->req_tx_entries_per_subcrq - 1;
821 else 823 else
822 tx_pool->consumer_index--; 824 tx_pool->consumer_index--;
823 825
@@ -826,6 +828,14 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
826 ret = NETDEV_TX_BUSY; 828 ret = NETDEV_TX_BUSY;
827 goto out; 829 goto out;
828 } 830 }
831
832 atomic_inc(&tx_scrq->used);
833
834 if (atomic_read(&tx_scrq->used) >= adapter->req_tx_entries_per_subcrq) {
835 netdev_info(netdev, "Stopping queue %d\n", queue_num);
836 netif_stop_subqueue(netdev, queue_num);
837 }
838
829 tx_packets++; 839 tx_packets++;
830 tx_bytes += skb->len; 840 tx_bytes += skb->len;
831 txq->trans_start = jiffies; 841 txq->trans_start = jiffies;
@@ -1213,6 +1223,7 @@ static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1213 scrq->adapter = adapter; 1223 scrq->adapter = adapter;
1214 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs); 1224 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
1215 scrq->cur = 0; 1225 scrq->cur = 0;
1226 atomic_set(&scrq->used, 0);
1216 scrq->rx_skb_top = NULL; 1227 scrq->rx_skb_top = NULL;
1217 spin_lock_init(&scrq->lock); 1228 spin_lock_init(&scrq->lock);
1218 1229
@@ -1355,14 +1366,28 @@ restart_loop:
1355 DMA_TO_DEVICE); 1366 DMA_TO_DEVICE);
1356 } 1367 }
1357 1368
1358 if (txbuff->last_frag) 1369 if (txbuff->last_frag) {
1370 atomic_dec(&scrq->used);
1371
1372 if (atomic_read(&scrq->used) <=
1373 (adapter->req_tx_entries_per_subcrq / 2) &&
1374 netif_subqueue_stopped(adapter->netdev,
1375 txbuff->skb)) {
1376 netif_wake_subqueue(adapter->netdev,
1377 scrq->pool_index);
1378 netdev_dbg(adapter->netdev,
1379 "Started queue %d\n",
1380 scrq->pool_index);
1381 }
1382
1359 dev_kfree_skb_any(txbuff->skb); 1383 dev_kfree_skb_any(txbuff->skb);
1384 }
1360 1385
1361 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool]. 1386 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1362 producer_index] = index; 1387 producer_index] = index;
1363 adapter->tx_pool[pool].producer_index = 1388 adapter->tx_pool[pool].producer_index =
1364 (adapter->tx_pool[pool].producer_index + 1) % 1389 (adapter->tx_pool[pool].producer_index + 1) %
1365 adapter->max_tx_entries_per_subcrq; 1390 adapter->req_tx_entries_per_subcrq;
1366 } 1391 }
1367 /* remove tx_comp scrq*/ 1392 /* remove tx_comp scrq*/
1368 next->tx_comp.first = 0; 1393 next->tx_comp.first = 0;
diff --git a/drivers/net/ethernet/ibm/ibmvnic.h b/drivers/net/ethernet/ibm/ibmvnic.h
index 422824f1f42a..1993b42666f7 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.h
+++ b/drivers/net/ethernet/ibm/ibmvnic.h
@@ -863,6 +863,7 @@ struct ibmvnic_sub_crq_queue {
863 spinlock_t lock; 863 spinlock_t lock;
864 struct sk_buff *rx_skb_top; 864 struct sk_buff *rx_skb_top;
865 struct ibmvnic_adapter *adapter; 865 struct ibmvnic_adapter *adapter;
866 atomic_t used;
866}; 867};
867 868
868struct ibmvnic_long_term_buff { 869struct ibmvnic_long_term_buff {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
index ddb4ca4ff930..117170014e88 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
+++ b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
@@ -14,6 +14,7 @@ config MLX5_CORE
14config MLX5_CORE_EN 14config MLX5_CORE_EN
15 bool "Mellanox Technologies ConnectX-4 Ethernet support" 15 bool "Mellanox Technologies ConnectX-4 Ethernet support"
16 depends on NETDEVICES && ETHERNET && PCI && MLX5_CORE 16 depends on NETDEVICES && ETHERNET && PCI && MLX5_CORE
17 depends on IPV6=y || IPV6=n || MLX5_CORE=m
17 imply PTP_1588_CLOCK 18 imply PTP_1588_CLOCK
18 default n 19 default n
19 ---help--- 20 ---help---
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c b/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
index 0523ed47f597..8fa23f6a1f67 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
@@ -302,6 +302,9 @@ static u8 mlx5e_dcbnl_setdcbx(struct net_device *dev, u8 mode)
302 struct mlx5e_priv *priv = netdev_priv(dev); 302 struct mlx5e_priv *priv = netdev_priv(dev);
303 struct mlx5e_dcbx *dcbx = &priv->dcbx; 303 struct mlx5e_dcbx *dcbx = &priv->dcbx;
304 304
305 if (mode & DCB_CAP_DCBX_LLD_MANAGED)
306 return 1;
307
305 if ((!mode) && MLX5_CAP_GEN(priv->mdev, dcbx)) { 308 if ((!mode) && MLX5_CAP_GEN(priv->mdev, dcbx)) {
306 if (dcbx->mode == MLX5E_DCBX_PARAM_VER_OPER_AUTO) 309 if (dcbx->mode == MLX5E_DCBX_PARAM_VER_OPER_AUTO)
307 return 0; 310 return 0;
@@ -315,13 +318,10 @@ static u8 mlx5e_dcbnl_setdcbx(struct net_device *dev, u8 mode)
315 return 1; 318 return 1;
316 } 319 }
317 320
318 if (mlx5e_dcbnl_switch_to_host_mode(netdev_priv(dev))) 321 if (!(mode & DCB_CAP_DCBX_HOST))
319 return 1; 322 return 1;
320 323
321 if ((mode & DCB_CAP_DCBX_LLD_MANAGED) || 324 if (mlx5e_dcbnl_switch_to_host_mode(netdev_priv(dev)))
322 !(mode & DCB_CAP_DCBX_VER_CEE) ||
323 !(mode & DCB_CAP_DCBX_VER_IEEE) ||
324 !(mode & DCB_CAP_DCBX_HOST))
325 return 1; 325 return 1;
326 326
327 return 0; 327 return 0;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
index 31e3cb7ee5fe..5621dcfda4f1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c
@@ -204,9 +204,6 @@ mlx5e_test_loopback_validate(struct sk_buff *skb,
204 struct iphdr *iph; 204 struct iphdr *iph;
205 205
206 /* We are only going to peek, no need to clone the SKB */ 206 /* We are only going to peek, no need to clone the SKB */
207 if (skb->protocol != htons(ETH_P_IP))
208 goto out;
209
210 if (MLX5E_TEST_PKT_SIZE - ETH_HLEN > skb_headlen(skb)) 207 if (MLX5E_TEST_PKT_SIZE - ETH_HLEN > skb_headlen(skb))
211 goto out; 208 goto out;
212 209
@@ -249,7 +246,7 @@ static int mlx5e_test_loopback_setup(struct mlx5e_priv *priv,
249 lbtp->loopback_ok = false; 246 lbtp->loopback_ok = false;
250 init_completion(&lbtp->comp); 247 init_completion(&lbtp->comp);
251 248
252 lbtp->pt.type = htons(ETH_P_ALL); 249 lbtp->pt.type = htons(ETH_P_IP);
253 lbtp->pt.func = mlx5e_test_loopback_validate; 250 lbtp->pt.func = mlx5e_test_loopback_validate;
254 lbtp->pt.dev = priv->netdev; 251 lbtp->pt.dev = priv->netdev;
255 lbtp->pt.af_packet_priv = lbtp; 252 lbtp->pt.af_packet_priv = lbtp;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 44406a5ec15d..79481f4cf264 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -48,9 +48,14 @@
48#include "eswitch.h" 48#include "eswitch.h"
49#include "vxlan.h" 49#include "vxlan.h"
50 50
51enum {
52 MLX5E_TC_FLOW_ESWITCH = BIT(0),
53};
54
51struct mlx5e_tc_flow { 55struct mlx5e_tc_flow {
52 struct rhash_head node; 56 struct rhash_head node;
53 u64 cookie; 57 u64 cookie;
58 u8 flags;
54 struct mlx5_flow_handle *rule; 59 struct mlx5_flow_handle *rule;
55 struct list_head encap; /* flows sharing the same encap */ 60 struct list_head encap; /* flows sharing the same encap */
56 struct mlx5_esw_flow_attr *attr; 61 struct mlx5_esw_flow_attr *attr;
@@ -177,7 +182,7 @@ static void mlx5e_tc_del_flow(struct mlx5e_priv *priv,
177 mlx5_fc_destroy(priv->mdev, counter); 182 mlx5_fc_destroy(priv->mdev, counter);
178 } 183 }
179 184
180 if (esw && esw->mode == SRIOV_OFFLOADS) { 185 if (flow->flags & MLX5E_TC_FLOW_ESWITCH) {
181 mlx5_eswitch_del_vlan_action(esw, flow->attr); 186 mlx5_eswitch_del_vlan_action(esw, flow->attr);
182 if (flow->attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP) 187 if (flow->attr->action & MLX5_FLOW_CONTEXT_ACTION_ENCAP)
183 mlx5e_detach_encap(priv, flow); 188 mlx5e_detach_encap(priv, flow);
@@ -598,6 +603,7 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
598} 603}
599 604
600static int parse_cls_flower(struct mlx5e_priv *priv, 605static int parse_cls_flower(struct mlx5e_priv *priv,
606 struct mlx5e_tc_flow *flow,
601 struct mlx5_flow_spec *spec, 607 struct mlx5_flow_spec *spec,
602 struct tc_cls_flower_offload *f) 608 struct tc_cls_flower_offload *f)
603{ 609{
@@ -609,7 +615,7 @@ static int parse_cls_flower(struct mlx5e_priv *priv,
609 615
610 err = __parse_cls_flower(priv, spec, f, &min_inline); 616 err = __parse_cls_flower(priv, spec, f, &min_inline);
611 617
612 if (!err && esw->mode == SRIOV_OFFLOADS && 618 if (!err && (flow->flags & MLX5E_TC_FLOW_ESWITCH) &&
613 rep->vport != FDB_UPLINK_VPORT) { 619 rep->vport != FDB_UPLINK_VPORT) {
614 if (min_inline > esw->offloads.inline_mode) { 620 if (min_inline > esw->offloads.inline_mode) {
615 netdev_warn(priv->netdev, 621 netdev_warn(priv->netdev,
@@ -1132,23 +1138,19 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
1132 struct tc_cls_flower_offload *f) 1138 struct tc_cls_flower_offload *f)
1133{ 1139{
1134 struct mlx5e_tc_table *tc = &priv->fs.tc; 1140 struct mlx5e_tc_table *tc = &priv->fs.tc;
1135 int err = 0; 1141 int err, attr_size = 0;
1136 bool fdb_flow = false;
1137 u32 flow_tag, action; 1142 u32 flow_tag, action;
1138 struct mlx5e_tc_flow *flow; 1143 struct mlx5e_tc_flow *flow;
1139 struct mlx5_flow_spec *spec; 1144 struct mlx5_flow_spec *spec;
1140 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; 1145 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
1146 u8 flow_flags = 0;
1141 1147
1142 if (esw && esw->mode == SRIOV_OFFLOADS) 1148 if (esw && esw->mode == SRIOV_OFFLOADS) {
1143 fdb_flow = true; 1149 flow_flags = MLX5E_TC_FLOW_ESWITCH;
1144 1150 attr_size = sizeof(struct mlx5_esw_flow_attr);
1145 if (fdb_flow) 1151 }
1146 flow = kzalloc(sizeof(*flow) +
1147 sizeof(struct mlx5_esw_flow_attr),
1148 GFP_KERNEL);
1149 else
1150 flow = kzalloc(sizeof(*flow), GFP_KERNEL);
1151 1152
1153 flow = kzalloc(sizeof(*flow) + attr_size, GFP_KERNEL);
1152 spec = mlx5_vzalloc(sizeof(*spec)); 1154 spec = mlx5_vzalloc(sizeof(*spec));
1153 if (!spec || !flow) { 1155 if (!spec || !flow) {
1154 err = -ENOMEM; 1156 err = -ENOMEM;
@@ -1156,12 +1158,13 @@ int mlx5e_configure_flower(struct mlx5e_priv *priv, __be16 protocol,
1156 } 1158 }
1157 1159
1158 flow->cookie = f->cookie; 1160 flow->cookie = f->cookie;
1161 flow->flags = flow_flags;
1159 1162
1160 err = parse_cls_flower(priv, spec, f); 1163 err = parse_cls_flower(priv, flow, spec, f);
1161 if (err < 0) 1164 if (err < 0)
1162 goto err_free; 1165 goto err_free;
1163 1166
1164 if (fdb_flow) { 1167 if (flow->flags & MLX5E_TC_FLOW_ESWITCH) {
1165 flow->attr = (struct mlx5_esw_flow_attr *)(flow + 1); 1168 flow->attr = (struct mlx5_esw_flow_attr *)(flow + 1);
1166 err = parse_tc_fdb_actions(priv, f->exts, flow); 1169 err = parse_tc_fdb_actions(priv, f->exts, flow);
1167 if (err < 0) 1170 if (err < 0)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
index 2478516a61e2..ded27bb9a3b6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
@@ -1136,7 +1136,7 @@ static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
1136 u32 *match_criteria) 1136 u32 *match_criteria)
1137{ 1137{
1138 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); 1138 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1139 struct list_head *prev = ft->node.children.prev; 1139 struct list_head *prev = &ft->node.children;
1140 unsigned int candidate_index = 0; 1140 unsigned int candidate_index = 0;
1141 struct mlx5_flow_group *fg; 1141 struct mlx5_flow_group *fg;
1142 void *match_criteria_addr; 1142 void *match_criteria_addr;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index c4242a4e8130..e2bd600d19de 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1352,6 +1352,7 @@ static int init_one(struct pci_dev *pdev,
1352 if (err) 1352 if (err)
1353 goto clean_load; 1353 goto clean_load;
1354 1354
1355 pci_save_state(pdev);
1355 return 0; 1356 return 0;
1356 1357
1357clean_load: 1358clean_load:
@@ -1407,9 +1408,8 @@ static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev,
1407 1408
1408 mlx5_enter_error_state(dev); 1409 mlx5_enter_error_state(dev);
1409 mlx5_unload_one(dev, priv, false); 1410 mlx5_unload_one(dev, priv, false);
1410 /* In case of kernel call save the pci state and drain the health wq */ 1411 /* In case of kernel call drain the health wq */
1411 if (state) { 1412 if (state) {
1412 pci_save_state(pdev);
1413 mlx5_drain_health_wq(dev); 1413 mlx5_drain_health_wq(dev);
1414 mlx5_pci_disable_device(dev); 1414 mlx5_pci_disable_device(dev);
1415 } 1415 }
@@ -1461,6 +1461,7 @@ static pci_ers_result_t mlx5_pci_slot_reset(struct pci_dev *pdev)
1461 1461
1462 pci_set_master(pdev); 1462 pci_set_master(pdev);
1463 pci_restore_state(pdev); 1463 pci_restore_state(pdev);
1464 pci_save_state(pdev);
1464 1465
1465 if (wait_vital(pdev)) { 1466 if (wait_vital(pdev)) {
1466 dev_err(&pdev->dev, "%s: wait_vital timed out\n", __func__); 1467 dev_err(&pdev->dev, "%s: wait_vital timed out\n", __func__);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h
index 0899e2d310e2..d9616daf8a70 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/reg.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h
@@ -769,7 +769,7 @@ static inline void mlxsw_reg_spvid_pack(char *payload, u8 local_port, u16 pvid)
769#define MLXSW_REG_SPVM_ID 0x200F 769#define MLXSW_REG_SPVM_ID 0x200F
770#define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */ 770#define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
771#define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */ 771#define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
772#define MLXSW_REG_SPVM_REC_MAX_COUNT 256 772#define MLXSW_REG_SPVM_REC_MAX_COUNT 255
773#define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN + \ 773#define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN + \
774 MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT) 774 MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
775 775
@@ -1702,7 +1702,7 @@ static inline void mlxsw_reg_sfmr_pack(char *payload,
1702#define MLXSW_REG_SPVMLR_ID 0x2020 1702#define MLXSW_REG_SPVMLR_ID 0x2020
1703#define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */ 1703#define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */
1704#define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */ 1704#define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */
1705#define MLXSW_REG_SPVMLR_REC_MAX_COUNT 256 1705#define MLXSW_REG_SPVMLR_REC_MAX_COUNT 255
1706#define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \ 1706#define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \
1707 MLXSW_REG_SPVMLR_REC_LEN * \ 1707 MLXSW_REG_SPVMLR_REC_LEN * \
1708 MLXSW_REG_SPVMLR_REC_MAX_COUNT) 1708 MLXSW_REG_SPVMLR_REC_MAX_COUNT)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
index 22ab42925377..ae6cccc666e4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -303,11 +303,11 @@ void mlxsw_sp_flower_destroy(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
303 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, mlxsw_sp_port->dev, 303 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, mlxsw_sp_port->dev,
304 ingress, 304 ingress,
305 MLXSW_SP_ACL_PROFILE_FLOWER); 305 MLXSW_SP_ACL_PROFILE_FLOWER);
306 if (WARN_ON(IS_ERR(ruleset))) 306 if (IS_ERR(ruleset))
307 return; 307 return;
308 308
309 rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie); 309 rule = mlxsw_sp_acl_rule_lookup(mlxsw_sp, ruleset, f->cookie);
310 if (!WARN_ON(!rule)) { 310 if (rule) {
311 mlxsw_sp_acl_rule_del(mlxsw_sp, rule); 311 mlxsw_sp_acl_rule_del(mlxsw_sp, rule);
312 mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule); 312 mlxsw_sp_acl_rule_destroy(mlxsw_sp, rule);
313 } 313 }
diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
index d42d03df751a..7e3a6fed3da6 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
@@ -422,8 +422,9 @@ static void qed_cxt_set_proto_cid_count(struct qed_hwfn *p_hwfn,
422 u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val; 422 u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val;
423 u32 cxt_size = CONN_CXT_SIZE(p_hwfn); 423 u32 cxt_size = CONN_CXT_SIZE(p_hwfn);
424 u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size; 424 u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
425 u32 align = elems_per_page * DQ_RANGE_ALIGN;
425 426
426 p_conn->cid_count = roundup(p_conn->cid_count, elems_per_page); 427 p_conn->cid_count = roundup(p_conn->cid_count, align);
427 } 428 }
428} 429}
429 430
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c
index e2a081ceaf52..e518f914eab1 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dev.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c
@@ -2389,9 +2389,8 @@ qed_chain_alloc_sanity_check(struct qed_dev *cdev,
2389 * size/capacity fields are of a u32 type. 2389 * size/capacity fields are of a u32 type.
2390 */ 2390 */
2391 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 && 2391 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
2392 chain_size > 0x10000) || 2392 chain_size > ((u32)U16_MAX + 1)) ||
2393 (cnt_type == QED_CHAIN_CNT_TYPE_U32 && 2393 (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
2394 chain_size > 0x100000000ULL)) {
2395 DP_NOTICE(cdev, 2394 DP_NOTICE(cdev,
2396 "The actual chain size (0x%llx) is larger than the maximal possible value\n", 2395 "The actual chain size (0x%llx) is larger than the maximal possible value\n",
2397 chain_size); 2396 chain_size);
diff --git a/drivers/net/ethernet/qlogic/qed/qed_iscsi.c b/drivers/net/ethernet/qlogic/qed/qed_iscsi.c
index 3a44d6b395fa..098766f7fe88 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_iscsi.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_iscsi.c
@@ -190,6 +190,9 @@ qed_sp_iscsi_func_start(struct qed_hwfn *p_hwfn,
190 p_init->num_sq_pages_in_ring = p_params->num_sq_pages_in_ring; 190 p_init->num_sq_pages_in_ring = p_params->num_sq_pages_in_ring;
191 p_init->num_r2tq_pages_in_ring = p_params->num_r2tq_pages_in_ring; 191 p_init->num_r2tq_pages_in_ring = p_params->num_r2tq_pages_in_ring;
192 p_init->num_uhq_pages_in_ring = p_params->num_uhq_pages_in_ring; 192 p_init->num_uhq_pages_in_ring = p_params->num_uhq_pages_in_ring;
193 p_init->ooo_enable = p_params->ooo_enable;
194 p_init->ll2_rx_queue_id = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] +
195 p_params->ll2_ooo_queue_id;
193 p_init->func_params.log_page_size = p_params->log_page_size; 196 p_init->func_params.log_page_size = p_params->log_page_size;
194 val = p_params->num_tasks; 197 val = p_params->num_tasks;
195 p_init->func_params.num_tasks = cpu_to_le16(val); 198 p_init->func_params.num_tasks = cpu_to_le16(val);
@@ -786,6 +789,23 @@ static void qed_iscsi_release_connection(struct qed_hwfn *p_hwfn,
786 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock); 789 spin_unlock_bh(&p_hwfn->p_iscsi_info->lock);
787} 790}
788 791
792void qed_iscsi_free_connection(struct qed_hwfn *p_hwfn,
793 struct qed_iscsi_conn *p_conn)
794{
795 qed_chain_free(p_hwfn->cdev, &p_conn->xhq);
796 qed_chain_free(p_hwfn->cdev, &p_conn->uhq);
797 qed_chain_free(p_hwfn->cdev, &p_conn->r2tq);
798 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
799 sizeof(struct tcp_upload_params),
800 p_conn->tcp_upload_params_virt_addr,
801 p_conn->tcp_upload_params_phys_addr);
802 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
803 sizeof(struct scsi_terminate_extra_params),
804 p_conn->queue_cnts_virt_addr,
805 p_conn->queue_cnts_phys_addr);
806 kfree(p_conn);
807}
808
789struct qed_iscsi_info *qed_iscsi_alloc(struct qed_hwfn *p_hwfn) 809struct qed_iscsi_info *qed_iscsi_alloc(struct qed_hwfn *p_hwfn)
790{ 810{
791 struct qed_iscsi_info *p_iscsi_info; 811 struct qed_iscsi_info *p_iscsi_info;
@@ -807,6 +827,17 @@ void qed_iscsi_setup(struct qed_hwfn *p_hwfn,
807void qed_iscsi_free(struct qed_hwfn *p_hwfn, 827void qed_iscsi_free(struct qed_hwfn *p_hwfn,
808 struct qed_iscsi_info *p_iscsi_info) 828 struct qed_iscsi_info *p_iscsi_info)
809{ 829{
830 struct qed_iscsi_conn *p_conn = NULL;
831
832 while (!list_empty(&p_hwfn->p_iscsi_info->free_list)) {
833 p_conn = list_first_entry(&p_hwfn->p_iscsi_info->free_list,
834 struct qed_iscsi_conn, list_entry);
835 if (p_conn) {
836 list_del(&p_conn->list_entry);
837 qed_iscsi_free_connection(p_hwfn, p_conn);
838 }
839 }
840
810 kfree(p_iscsi_info); 841 kfree(p_iscsi_info);
811} 842}
812 843
diff --git a/drivers/net/ethernet/qlogic/qed/qed_ll2.c b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
index 9a0b9af10a57..0d3cef409c96 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ll2.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
@@ -211,6 +211,8 @@ static void qed_ll2b_complete_rx_packet(struct qed_hwfn *p_hwfn,
211 /* If need to reuse or there's no replacement buffer, repost this */ 211 /* If need to reuse or there's no replacement buffer, repost this */
212 if (rc) 212 if (rc)
213 goto out_post; 213 goto out_post;
214 dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
215 cdev->ll2->rx_size, DMA_FROM_DEVICE);
214 216
215 skb = build_skb(buffer->data, 0); 217 skb = build_skb(buffer->data, 0);
216 if (!skb) { 218 if (!skb) {
@@ -474,7 +476,7 @@ qed_ll2_rxq_completion_gsi(struct qed_hwfn *p_hwfn,
474static int qed_ll2_rxq_completion_reg(struct qed_hwfn *p_hwfn, 476static int qed_ll2_rxq_completion_reg(struct qed_hwfn *p_hwfn,
475 struct qed_ll2_info *p_ll2_conn, 477 struct qed_ll2_info *p_ll2_conn,
476 union core_rx_cqe_union *p_cqe, 478 union core_rx_cqe_union *p_cqe,
477 unsigned long lock_flags, 479 unsigned long *p_lock_flags,
478 bool b_last_cqe) 480 bool b_last_cqe)
479{ 481{
480 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue; 482 struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
@@ -495,10 +497,10 @@ static int qed_ll2_rxq_completion_reg(struct qed_hwfn *p_hwfn,
495 "Mismatch between active_descq and the LL2 Rx chain\n"); 497 "Mismatch between active_descq and the LL2 Rx chain\n");
496 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq); 498 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
497 499
498 spin_unlock_irqrestore(&p_rx->lock, lock_flags); 500 spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags);
499 qed_ll2b_complete_rx_packet(p_hwfn, p_ll2_conn->my_id, 501 qed_ll2b_complete_rx_packet(p_hwfn, p_ll2_conn->my_id,
500 p_pkt, &p_cqe->rx_cqe_fp, b_last_cqe); 502 p_pkt, &p_cqe->rx_cqe_fp, b_last_cqe);
501 spin_lock_irqsave(&p_rx->lock, lock_flags); 503 spin_lock_irqsave(&p_rx->lock, *p_lock_flags);
502 504
503 return 0; 505 return 0;
504} 506}
@@ -538,7 +540,8 @@ static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie)
538 break; 540 break;
539 case CORE_RX_CQE_TYPE_REGULAR: 541 case CORE_RX_CQE_TYPE_REGULAR:
540 rc = qed_ll2_rxq_completion_reg(p_hwfn, p_ll2_conn, 542 rc = qed_ll2_rxq_completion_reg(p_hwfn, p_ll2_conn,
541 cqe, flags, b_last_cqe); 543 cqe, &flags,
544 b_last_cqe);
542 break; 545 break;
543 default: 546 default:
544 rc = -EIO; 547 rc = -EIO;
@@ -968,7 +971,7 @@ static int qed_ll2_start_ooo(struct qed_dev *cdev,
968{ 971{
969 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 972 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
970 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id; 973 u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
971 struct qed_ll2_conn ll2_info; 974 struct qed_ll2_conn ll2_info = { 0 };
972 int rc; 975 int rc;
973 976
974 ll2_info.conn_type = QED_LL2_TYPE_ISCSI_OOO; 977 ll2_info.conn_type = QED_LL2_TYPE_ISCSI_OOO;
diff --git a/drivers/net/ethernet/qlogic/qed/qed_ooo.c b/drivers/net/ethernet/qlogic/qed/qed_ooo.c
index 7d731c6cb892..378afce58b3f 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ooo.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_ooo.c
@@ -159,6 +159,8 @@ struct qed_ooo_info *qed_ooo_alloc(struct qed_hwfn *p_hwfn)
159 if (!p_ooo_info->ooo_history.p_cqes) 159 if (!p_ooo_info->ooo_history.p_cqes)
160 goto no_history_mem; 160 goto no_history_mem;
161 161
162 p_ooo_info->ooo_history.num_of_cqes = QED_MAX_NUM_OOO_HISTORY_ENTRIES;
163
162 return p_ooo_info; 164 return p_ooo_info;
163 165
164no_history_mem: 166no_history_mem:
diff --git a/drivers/net/ethernet/smsc/smc91x.c b/drivers/net/ethernet/smsc/smc91x.c
index 65077c77082a..91e9bd7159ab 100644
--- a/drivers/net/ethernet/smsc/smc91x.c
+++ b/drivers/net/ethernet/smsc/smc91x.c
@@ -1535,32 +1535,33 @@ static int smc_close(struct net_device *dev)
1535 * Ethtool support 1535 * Ethtool support
1536 */ 1536 */
1537static int 1537static int
1538smc_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd) 1538smc_ethtool_get_link_ksettings(struct net_device *dev,
1539 struct ethtool_link_ksettings *cmd)
1539{ 1540{
1540 struct smc_local *lp = netdev_priv(dev); 1541 struct smc_local *lp = netdev_priv(dev);
1541 int ret; 1542 int ret;
1542 1543
1543 cmd->maxtxpkt = 1;
1544 cmd->maxrxpkt = 1;
1545
1546 if (lp->phy_type != 0) { 1544 if (lp->phy_type != 0) {
1547 spin_lock_irq(&lp->lock); 1545 spin_lock_irq(&lp->lock);
1548 ret = mii_ethtool_gset(&lp->mii, cmd); 1546 ret = mii_ethtool_get_link_ksettings(&lp->mii, cmd);
1549 spin_unlock_irq(&lp->lock); 1547 spin_unlock_irq(&lp->lock);
1550 } else { 1548 } else {
1551 cmd->supported = SUPPORTED_10baseT_Half | 1549 u32 supported = SUPPORTED_10baseT_Half |
1552 SUPPORTED_10baseT_Full | 1550 SUPPORTED_10baseT_Full |
1553 SUPPORTED_TP | SUPPORTED_AUI; 1551 SUPPORTED_TP | SUPPORTED_AUI;
1554 1552
1555 if (lp->ctl_rspeed == 10) 1553 if (lp->ctl_rspeed == 10)
1556 ethtool_cmd_speed_set(cmd, SPEED_10); 1554 cmd->base.speed = SPEED_10;
1557 else if (lp->ctl_rspeed == 100) 1555 else if (lp->ctl_rspeed == 100)
1558 ethtool_cmd_speed_set(cmd, SPEED_100); 1556 cmd->base.speed = SPEED_100;
1557
1558 cmd->base.autoneg = AUTONEG_DISABLE;
1559 cmd->base.port = 0;
1560 cmd->base.duplex = lp->tcr_cur_mode & TCR_SWFDUP ?
1561 DUPLEX_FULL : DUPLEX_HALF;
1559 1562
1560 cmd->autoneg = AUTONEG_DISABLE; 1563 ethtool_convert_legacy_u32_to_link_mode(
1561 cmd->transceiver = XCVR_INTERNAL; 1564 cmd->link_modes.supported, supported);
1562 cmd->port = 0;
1563 cmd->duplex = lp->tcr_cur_mode & TCR_SWFDUP ? DUPLEX_FULL : DUPLEX_HALF;
1564 1565
1565 ret = 0; 1566 ret = 0;
1566 } 1567 }
@@ -1569,24 +1570,26 @@ smc_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1569} 1570}
1570 1571
1571static int 1572static int
1572smc_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd) 1573smc_ethtool_set_link_ksettings(struct net_device *dev,
1574 const struct ethtool_link_ksettings *cmd)
1573{ 1575{
1574 struct smc_local *lp = netdev_priv(dev); 1576 struct smc_local *lp = netdev_priv(dev);
1575 int ret; 1577 int ret;
1576 1578
1577 if (lp->phy_type != 0) { 1579 if (lp->phy_type != 0) {
1578 spin_lock_irq(&lp->lock); 1580 spin_lock_irq(&lp->lock);
1579 ret = mii_ethtool_sset(&lp->mii, cmd); 1581 ret = mii_ethtool_set_link_ksettings(&lp->mii, cmd);
1580 spin_unlock_irq(&lp->lock); 1582 spin_unlock_irq(&lp->lock);
1581 } else { 1583 } else {
1582 if (cmd->autoneg != AUTONEG_DISABLE || 1584 if (cmd->base.autoneg != AUTONEG_DISABLE ||
1583 cmd->speed != SPEED_10 || 1585 cmd->base.speed != SPEED_10 ||
1584 (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) || 1586 (cmd->base.duplex != DUPLEX_HALF &&
1585 (cmd->port != PORT_TP && cmd->port != PORT_AUI)) 1587 cmd->base.duplex != DUPLEX_FULL) ||
1588 (cmd->base.port != PORT_TP && cmd->base.port != PORT_AUI))
1586 return -EINVAL; 1589 return -EINVAL;
1587 1590
1588// lp->port = cmd->port; 1591// lp->port = cmd->base.port;
1589 lp->ctl_rfduplx = cmd->duplex == DUPLEX_FULL; 1592 lp->ctl_rfduplx = cmd->base.duplex == DUPLEX_FULL;
1590 1593
1591// if (netif_running(dev)) 1594// if (netif_running(dev))
1592// smc_set_port(dev); 1595// smc_set_port(dev);
@@ -1744,8 +1747,6 @@ static int smc_ethtool_seteeprom(struct net_device *dev,
1744 1747
1745 1748
1746static const struct ethtool_ops smc_ethtool_ops = { 1749static const struct ethtool_ops smc_ethtool_ops = {
1747 .get_settings = smc_ethtool_getsettings,
1748 .set_settings = smc_ethtool_setsettings,
1749 .get_drvinfo = smc_ethtool_getdrvinfo, 1750 .get_drvinfo = smc_ethtool_getdrvinfo,
1750 1751
1751 .get_msglevel = smc_ethtool_getmsglevel, 1752 .get_msglevel = smc_ethtool_getmsglevel,
@@ -1755,6 +1756,8 @@ static const struct ethtool_ops smc_ethtool_ops = {
1755 .get_eeprom_len = smc_ethtool_geteeprom_len, 1756 .get_eeprom_len = smc_ethtool_geteeprom_len,
1756 .get_eeprom = smc_ethtool_geteeprom, 1757 .get_eeprom = smc_ethtool_geteeprom,
1757 .set_eeprom = smc_ethtool_seteeprom, 1758 .set_eeprom = smc_ethtool_seteeprom,
1759 .get_link_ksettings = smc_ethtool_get_link_ksettings,
1760 .set_link_ksettings = smc_ethtool_set_link_ksettings,
1758}; 1761};
1759 1762
1760static const struct net_device_ops smc_netdev_ops = { 1763static const struct net_device_ops smc_netdev_ops = {
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index d3e73ac158ae..f9f3dba7a588 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -700,6 +700,8 @@ struct net_device_context {
700 700
701 u32 tx_checksum_mask; 701 u32 tx_checksum_mask;
702 702
703 u32 tx_send_table[VRSS_SEND_TAB_SIZE];
704
703 /* Ethtool settings */ 705 /* Ethtool settings */
704 u8 duplex; 706 u8 duplex;
705 u32 speed; 707 u32 speed;
@@ -757,7 +759,6 @@ struct netvsc_device {
757 759
758 struct nvsp_message revoke_packet; 760 struct nvsp_message revoke_packet;
759 761
760 u32 send_table[VRSS_SEND_TAB_SIZE];
761 u32 max_chn; 762 u32 max_chn;
762 u32 num_chn; 763 u32 num_chn;
763 spinlock_t sc_lock; /* Protects num_sc_offered variable */ 764 spinlock_t sc_lock; /* Protects num_sc_offered variable */
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index d35ebd993b38..4c1d8cca247b 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -1136,15 +1136,11 @@ static void netvsc_receive(struct net_device *ndev,
1136static void netvsc_send_table(struct hv_device *hdev, 1136static void netvsc_send_table(struct hv_device *hdev,
1137 struct nvsp_message *nvmsg) 1137 struct nvsp_message *nvmsg)
1138{ 1138{
1139 struct netvsc_device *nvscdev;
1140 struct net_device *ndev = hv_get_drvdata(hdev); 1139 struct net_device *ndev = hv_get_drvdata(hdev);
1140 struct net_device_context *net_device_ctx = netdev_priv(ndev);
1141 int i; 1141 int i;
1142 u32 count, *tab; 1142 u32 count, *tab;
1143 1143
1144 nvscdev = get_outbound_net_device(hdev);
1145 if (!nvscdev)
1146 return;
1147
1148 count = nvmsg->msg.v5_msg.send_table.count; 1144 count = nvmsg->msg.v5_msg.send_table.count;
1149 if (count != VRSS_SEND_TAB_SIZE) { 1145 if (count != VRSS_SEND_TAB_SIZE) {
1150 netdev_err(ndev, "Received wrong send-table size:%u\n", count); 1146 netdev_err(ndev, "Received wrong send-table size:%u\n", count);
@@ -1155,7 +1151,7 @@ static void netvsc_send_table(struct hv_device *hdev,
1155 nvmsg->msg.v5_msg.send_table.offset); 1151 nvmsg->msg.v5_msg.send_table.offset);
1156 1152
1157 for (i = 0; i < count; i++) 1153 for (i = 0; i < count; i++)
1158 nvscdev->send_table[i] = tab[i]; 1154 net_device_ctx->tx_send_table[i] = tab[i];
1159} 1155}
1160 1156
1161static void netvsc_send_vf(struct net_device_context *net_device_ctx, 1157static void netvsc_send_vf(struct net_device_context *net_device_ctx,
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index bc05c895d958..5ede87f30463 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -206,17 +206,15 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
206 void *accel_priv, select_queue_fallback_t fallback) 206 void *accel_priv, select_queue_fallback_t fallback)
207{ 207{
208 struct net_device_context *net_device_ctx = netdev_priv(ndev); 208 struct net_device_context *net_device_ctx = netdev_priv(ndev);
209 struct netvsc_device *nvsc_dev = net_device_ctx->nvdev; 209 unsigned int num_tx_queues = ndev->real_num_tx_queues;
210 struct sock *sk = skb->sk; 210 struct sock *sk = skb->sk;
211 int q_idx = sk_tx_queue_get(sk); 211 int q_idx = sk_tx_queue_get(sk);
212 212
213 if (q_idx < 0 || skb->ooo_okay || 213 if (q_idx < 0 || skb->ooo_okay || q_idx >= num_tx_queues) {
214 q_idx >= ndev->real_num_tx_queues) {
215 u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE); 214 u16 hash = __skb_tx_hash(ndev, skb, VRSS_SEND_TAB_SIZE);
216 int new_idx; 215 int new_idx;
217 216
218 new_idx = nvsc_dev->send_table[hash] 217 new_idx = net_device_ctx->tx_send_table[hash] % num_tx_queues;
219 % nvsc_dev->num_chn;
220 218
221 if (q_idx != new_idx && sk && 219 if (q_idx != new_idx && sk &&
222 sk_fullsock(sk) && rcu_access_pointer(sk->sk_dst_cache)) 220 sk_fullsock(sk) && rcu_access_pointer(sk->sk_dst_cache))
@@ -225,9 +223,6 @@ static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
225 q_idx = new_idx; 223 q_idx = new_idx;
226 } 224 }
227 225
228 if (unlikely(!nvsc_dev->chan_table[q_idx].channel))
229 q_idx = 0;
230
231 return q_idx; 226 return q_idx;
232} 227}
233 228
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index f9d0fa315a47..272b051a0199 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -1883,17 +1883,6 @@ static int m88e1510_probe(struct phy_device *phydev)
1883 return m88e1510_hwmon_probe(phydev); 1883 return m88e1510_hwmon_probe(phydev);
1884} 1884}
1885 1885
1886static void marvell_remove(struct phy_device *phydev)
1887{
1888#ifdef CONFIG_HWMON
1889
1890 struct marvell_priv *priv = phydev->priv;
1891
1892 if (priv && priv->hwmon_dev)
1893 hwmon_device_unregister(priv->hwmon_dev);
1894#endif
1895}
1896
1897static struct phy_driver marvell_drivers[] = { 1886static struct phy_driver marvell_drivers[] = {
1898 { 1887 {
1899 .phy_id = MARVELL_PHY_ID_88E1101, 1888 .phy_id = MARVELL_PHY_ID_88E1101,
@@ -1974,7 +1963,6 @@ static struct phy_driver marvell_drivers[] = {
1974 .features = PHY_GBIT_FEATURES, 1963 .features = PHY_GBIT_FEATURES,
1975 .flags = PHY_HAS_INTERRUPT, 1964 .flags = PHY_HAS_INTERRUPT,
1976 .probe = &m88e1121_probe, 1965 .probe = &m88e1121_probe,
1977 .remove = &marvell_remove,
1978 .config_init = &m88e1121_config_init, 1966 .config_init = &m88e1121_config_init,
1979 .config_aneg = &m88e1121_config_aneg, 1967 .config_aneg = &m88e1121_config_aneg,
1980 .read_status = &marvell_read_status, 1968 .read_status = &marvell_read_status,
@@ -2087,7 +2075,6 @@ static struct phy_driver marvell_drivers[] = {
2087 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE, 2075 .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE,
2088 .flags = PHY_HAS_INTERRUPT, 2076 .flags = PHY_HAS_INTERRUPT,
2089 .probe = &m88e1510_probe, 2077 .probe = &m88e1510_probe,
2090 .remove = &marvell_remove,
2091 .config_init = &m88e1510_config_init, 2078 .config_init = &m88e1510_config_init,
2092 .config_aneg = &m88e1510_config_aneg, 2079 .config_aneg = &m88e1510_config_aneg,
2093 .read_status = &marvell_read_status, 2080 .read_status = &marvell_read_status,
@@ -2109,7 +2096,6 @@ static struct phy_driver marvell_drivers[] = {
2109 .features = PHY_GBIT_FEATURES, 2096 .features = PHY_GBIT_FEATURES,
2110 .flags = PHY_HAS_INTERRUPT, 2097 .flags = PHY_HAS_INTERRUPT,
2111 .probe = m88e1510_probe, 2098 .probe = m88e1510_probe,
2112 .remove = &marvell_remove,
2113 .config_init = &marvell_config_init, 2099 .config_init = &marvell_config_init,
2114 .config_aneg = &m88e1510_config_aneg, 2100 .config_aneg = &m88e1510_config_aneg,
2115 .read_status = &marvell_read_status, 2101 .read_status = &marvell_read_status,
@@ -2127,7 +2113,6 @@ static struct phy_driver marvell_drivers[] = {
2127 .phy_id_mask = MARVELL_PHY_ID_MASK, 2113 .phy_id_mask = MARVELL_PHY_ID_MASK,
2128 .name = "Marvell 88E1545", 2114 .name = "Marvell 88E1545",
2129 .probe = m88e1510_probe, 2115 .probe = m88e1510_probe,
2130 .remove = &marvell_remove,
2131 .features = PHY_GBIT_FEATURES, 2116 .features = PHY_GBIT_FEATURES,
2132 .flags = PHY_HAS_INTERRUPT, 2117 .flags = PHY_HAS_INTERRUPT,
2133 .config_init = &marvell_config_init, 2118 .config_init = &marvell_config_init,
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index daec6555f3b1..5198ccfa347f 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1864,7 +1864,7 @@ static struct phy_driver genphy_driver[] = {
1864 .phy_id = 0xffffffff, 1864 .phy_id = 0xffffffff,
1865 .phy_id_mask = 0xffffffff, 1865 .phy_id_mask = 0xffffffff,
1866 .name = "Generic PHY", 1866 .name = "Generic PHY",
1867 .soft_reset = genphy_soft_reset, 1867 .soft_reset = genphy_no_soft_reset,
1868 .config_init = genphy_config_init, 1868 .config_init = genphy_config_init,
1869 .features = PHY_GBIT_FEATURES | SUPPORTED_MII | 1869 .features = PHY_GBIT_FEATURES | SUPPORTED_MII |
1870 SUPPORTED_AUI | SUPPORTED_FIBRE | 1870 SUPPORTED_AUI | SUPPORTED_FIBRE |
diff --git a/drivers/net/phy/spi_ks8995.c b/drivers/net/phy/spi_ks8995.c
index 93ffedfa2994..1e2d4f1179da 100644
--- a/drivers/net/phy/spi_ks8995.c
+++ b/drivers/net/phy/spi_ks8995.c
@@ -491,13 +491,14 @@ static int ks8995_probe(struct spi_device *spi)
491 if (err) 491 if (err)
492 return err; 492 return err;
493 493
494 ks->regs_attr.size = ks->chip->regs_size;
495 memcpy(&ks->regs_attr, &ks8995_registers_attr, sizeof(ks->regs_attr)); 494 memcpy(&ks->regs_attr, &ks8995_registers_attr, sizeof(ks->regs_attr));
495 ks->regs_attr.size = ks->chip->regs_size;
496 496
497 err = ks8995_reset(ks); 497 err = ks8995_reset(ks);
498 if (err) 498 if (err)
499 return err; 499 return err;
500 500
501 sysfs_attr_init(&ks->regs_attr.attr);
501 err = sysfs_create_bin_file(&spi->dev.kobj, &ks->regs_attr); 502 err = sysfs_create_bin_file(&spi->dev.kobj, &ks->regs_attr);
502 if (err) { 503 if (err) {
503 dev_err(&spi->dev, "unable to create sysfs file, err=%d\n", 504 dev_err(&spi->dev, "unable to create sysfs file, err=%d\n",
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 4a24b5d15f5a..1b52520715ae 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -2072,6 +2072,7 @@ static int team_dev_type_check_change(struct net_device *dev,
2072static void team_setup(struct net_device *dev) 2072static void team_setup(struct net_device *dev)
2073{ 2073{
2074 ether_setup(dev); 2074 ether_setup(dev);
2075 dev->max_mtu = ETH_MAX_MTU;
2075 2076
2076 dev->netdev_ops = &team_netdev_ops; 2077 dev->netdev_ops = &team_netdev_ops;
2077 dev->ethtool_ops = &team_ethtool_ops; 2078 dev->ethtool_ops = &team_ethtool_ops;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index dc1b1dd9157c..34cc3c590aa5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -822,7 +822,18 @@ static void tun_net_uninit(struct net_device *dev)
822/* Net device open. */ 822/* Net device open. */
823static int tun_net_open(struct net_device *dev) 823static int tun_net_open(struct net_device *dev)
824{ 824{
825 struct tun_struct *tun = netdev_priv(dev);
826 int i;
827
825 netif_tx_start_all_queues(dev); 828 netif_tx_start_all_queues(dev);
829
830 for (i = 0; i < tun->numqueues; i++) {
831 struct tun_file *tfile;
832
833 tfile = rtnl_dereference(tun->tfiles[i]);
834 tfile->socket.sk->sk_write_space(tfile->socket.sk);
835 }
836
826 return 0; 837 return 0;
827} 838}
828 839
@@ -1103,9 +1114,10 @@ static unsigned int tun_chr_poll(struct file *file, poll_table *wait)
1103 if (!skb_array_empty(&tfile->tx_array)) 1114 if (!skb_array_empty(&tfile->tx_array))
1104 mask |= POLLIN | POLLRDNORM; 1115 mask |= POLLIN | POLLRDNORM;
1105 1116
1106 if (sock_writeable(sk) || 1117 if (tun->dev->flags & IFF_UP &&
1107 (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) && 1118 (sock_writeable(sk) ||
1108 sock_writeable(sk))) 1119 (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) &&
1120 sock_writeable(sk))))
1109 mask |= POLLOUT | POLLWRNORM; 1121 mask |= POLLOUT | POLLWRNORM;
1110 1122
1111 if (tun->dev->reg_state != NETREG_REGISTERED) 1123 if (tun->dev->reg_state != NETREG_REGISTERED)
@@ -2570,7 +2582,6 @@ static int __init tun_init(void)
2570 int ret = 0; 2582 int ret = 0;
2571 2583
2572 pr_info("%s, %s\n", DRV_DESCRIPTION, DRV_VERSION); 2584 pr_info("%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
2573 pr_info("%s\n", DRV_COPYRIGHT);
2574 2585
2575 ret = rtnl_link_register(&tun_link_ops); 2586 ret = rtnl_link_register(&tun_link_ops);
2576 if (ret) { 2587 if (ret) {
diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 22379da63400..fea687f35b5a 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -340,6 +340,7 @@ static netdev_tx_t is_ip_tx_frame(struct sk_buff *skb, struct net_device *dev)
340 340
341static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev) 341static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev)
342{ 342{
343 int len = skb->len;
343 netdev_tx_t ret = is_ip_tx_frame(skb, dev); 344 netdev_tx_t ret = is_ip_tx_frame(skb, dev);
344 345
345 if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) { 346 if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
@@ -347,7 +348,7 @@ static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev)
347 348
348 u64_stats_update_begin(&dstats->syncp); 349 u64_stats_update_begin(&dstats->syncp);
349 dstats->tx_pkts++; 350 dstats->tx_pkts++;
350 dstats->tx_bytes += skb->len; 351 dstats->tx_bytes += len;
351 u64_stats_update_end(&dstats->syncp); 352 u64_stats_update_end(&dstats->syncp);
352 } else { 353 } else {
353 this_cpu_inc(dev->dstats->tx_drps); 354 this_cpu_inc(dev->dstats->tx_drps);
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index e375560cc74e..bdb6ae16d4a8 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2976,6 +2976,44 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
2976 return 0; 2976 return 0;
2977} 2977}
2978 2978
2979static int __vxlan_dev_create(struct net *net, struct net_device *dev,
2980 struct vxlan_config *conf)
2981{
2982 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
2983 struct vxlan_dev *vxlan = netdev_priv(dev);
2984 int err;
2985
2986 err = vxlan_dev_configure(net, dev, conf, false);
2987 if (err)
2988 return err;
2989
2990 dev->ethtool_ops = &vxlan_ethtool_ops;
2991
2992 /* create an fdb entry for a valid default destination */
2993 if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) {
2994 err = vxlan_fdb_create(vxlan, all_zeros_mac,
2995 &vxlan->default_dst.remote_ip,
2996 NUD_REACHABLE | NUD_PERMANENT,
2997 NLM_F_EXCL | NLM_F_CREATE,
2998 vxlan->cfg.dst_port,
2999 vxlan->default_dst.remote_vni,
3000 vxlan->default_dst.remote_vni,
3001 vxlan->default_dst.remote_ifindex,
3002 NTF_SELF);
3003 if (err)
3004 return err;
3005 }
3006
3007 err = register_netdevice(dev);
3008 if (err) {
3009 vxlan_fdb_delete_default(vxlan, vxlan->default_dst.remote_vni);
3010 return err;
3011 }
3012
3013 list_add(&vxlan->next, &vn->vxlan_list);
3014 return 0;
3015}
3016
2979static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], 3017static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
2980 struct net_device *dev, struct vxlan_config *conf, 3018 struct net_device *dev, struct vxlan_config *conf,
2981 bool changelink) 3019 bool changelink)
@@ -3172,8 +3210,6 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
3172static int vxlan_newlink(struct net *src_net, struct net_device *dev, 3210static int vxlan_newlink(struct net *src_net, struct net_device *dev,
3173 struct nlattr *tb[], struct nlattr *data[]) 3211 struct nlattr *tb[], struct nlattr *data[])
3174{ 3212{
3175 struct vxlan_net *vn = net_generic(src_net, vxlan_net_id);
3176 struct vxlan_dev *vxlan = netdev_priv(dev);
3177 struct vxlan_config conf; 3213 struct vxlan_config conf;
3178 int err; 3214 int err;
3179 3215
@@ -3181,36 +3217,7 @@ static int vxlan_newlink(struct net *src_net, struct net_device *dev,
3181 if (err) 3217 if (err)
3182 return err; 3218 return err;
3183 3219
3184 err = vxlan_dev_configure(src_net, dev, &conf, false); 3220 return __vxlan_dev_create(src_net, dev, &conf);
3185 if (err)
3186 return err;
3187
3188 dev->ethtool_ops = &vxlan_ethtool_ops;
3189
3190 /* create an fdb entry for a valid default destination */
3191 if (!vxlan_addr_any(&vxlan->default_dst.remote_ip)) {
3192 err = vxlan_fdb_create(vxlan, all_zeros_mac,
3193 &vxlan->default_dst.remote_ip,
3194 NUD_REACHABLE | NUD_PERMANENT,
3195 NLM_F_EXCL | NLM_F_CREATE,
3196 vxlan->cfg.dst_port,
3197 vxlan->default_dst.remote_vni,
3198 vxlan->default_dst.remote_vni,
3199 vxlan->default_dst.remote_ifindex,
3200 NTF_SELF);
3201 if (err)
3202 return err;
3203 }
3204
3205 err = register_netdevice(dev);
3206 if (err) {
3207 vxlan_fdb_delete_default(vxlan, vxlan->default_dst.remote_vni);
3208 return err;
3209 }
3210
3211 list_add(&vxlan->next, &vn->vxlan_list);
3212
3213 return 0;
3214} 3221}
3215 3222
3216static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], 3223static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
@@ -3440,7 +3447,7 @@ struct net_device *vxlan_dev_create(struct net *net, const char *name,
3440 if (IS_ERR(dev)) 3447 if (IS_ERR(dev))
3441 return dev; 3448 return dev;
3442 3449
3443 err = vxlan_dev_configure(net, dev, conf, false); 3450 err = __vxlan_dev_create(net, dev, conf);
3444 if (err < 0) { 3451 if (err < 0) {
3445 free_netdev(dev); 3452 free_netdev(dev);
3446 return ERR_PTR(err); 3453 return ERR_PTR(err);
diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
index a5045b5279d7..6742ae605660 100644
--- a/drivers/net/wan/fsl_ucc_hdlc.c
+++ b/drivers/net/wan/fsl_ucc_hdlc.c
@@ -381,8 +381,8 @@ static netdev_tx_t ucc_hdlc_tx(struct sk_buff *skb, struct net_device *dev)
381 /* set bd status and length */ 381 /* set bd status and length */
382 bd_status = (bd_status & T_W_S) | T_R_S | T_I_S | T_L_S | T_TC_S; 382 bd_status = (bd_status & T_W_S) | T_R_S | T_I_S | T_L_S | T_TC_S;
383 383
384 iowrite16be(bd_status, &bd->status);
385 iowrite16be(skb->len, &bd->length); 384 iowrite16be(skb->len, &bd->length);
385 iowrite16be(bd_status, &bd->status);
386 386
387 /* Move to next BD in the ring */ 387 /* Move to next BD in the ring */
388 if (!(bd_status & T_W_S)) 388 if (!(bd_status & T_W_S))
@@ -457,7 +457,7 @@ static int hdlc_rx_done(struct ucc_hdlc_private *priv, int rx_work_limit)
457 struct sk_buff *skb; 457 struct sk_buff *skb;
458 hdlc_device *hdlc = dev_to_hdlc(dev); 458 hdlc_device *hdlc = dev_to_hdlc(dev);
459 struct qe_bd *bd; 459 struct qe_bd *bd;
460 u32 bd_status; 460 u16 bd_status;
461 u16 length, howmany = 0; 461 u16 length, howmany = 0;
462 u8 *bdbuffer; 462 u8 *bdbuffer;
463 int i; 463 int i;
diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c
index e7f5910a6519..f8eb66ef2944 100644
--- a/drivers/net/wimax/i2400m/usb.c
+++ b/drivers/net/wimax/i2400m/usb.c
@@ -467,6 +467,9 @@ int i2400mu_probe(struct usb_interface *iface,
467 struct i2400mu *i2400mu; 467 struct i2400mu *i2400mu;
468 struct usb_device *usb_dev = interface_to_usbdev(iface); 468 struct usb_device *usb_dev = interface_to_usbdev(iface);
469 469
470 if (iface->cur_altsetting->desc.bNumEndpoints < 4)
471 return -ENODEV;
472
470 if (usb_dev->speed != USB_SPEED_HIGH) 473 if (usb_dev->speed != USB_SPEED_HIGH)
471 dev_err(dev, "device not connected as high speed\n"); 474 dev_err(dev, "device not connected as high speed\n");
472 475
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 829b26cd4549..8397f6c92451 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -165,13 +165,17 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
165{ 165{
166 struct xenvif *vif = netdev_priv(dev); 166 struct xenvif *vif = netdev_priv(dev);
167 struct xenvif_queue *queue = NULL; 167 struct xenvif_queue *queue = NULL;
168 unsigned int num_queues = vif->num_queues; 168 unsigned int num_queues;
169 u16 index; 169 u16 index;
170 struct xenvif_rx_cb *cb; 170 struct xenvif_rx_cb *cb;
171 171
172 BUG_ON(skb->dev != dev); 172 BUG_ON(skb->dev != dev);
173 173
174 /* Drop the packet if queues are not set up */ 174 /* Drop the packet if queues are not set up.
175 * This handler should be called inside an RCU read section
176 * so we don't need to enter it here explicitly.
177 */
178 num_queues = READ_ONCE(vif->num_queues);
175 if (num_queues < 1) 179 if (num_queues < 1)
176 goto drop; 180 goto drop;
177 181
@@ -222,18 +226,18 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
222{ 226{
223 struct xenvif *vif = netdev_priv(dev); 227 struct xenvif *vif = netdev_priv(dev);
224 struct xenvif_queue *queue = NULL; 228 struct xenvif_queue *queue = NULL;
229 unsigned int num_queues;
225 u64 rx_bytes = 0; 230 u64 rx_bytes = 0;
226 u64 rx_packets = 0; 231 u64 rx_packets = 0;
227 u64 tx_bytes = 0; 232 u64 tx_bytes = 0;
228 u64 tx_packets = 0; 233 u64 tx_packets = 0;
229 unsigned int index; 234 unsigned int index;
230 235
231 spin_lock(&vif->lock); 236 rcu_read_lock();
232 if (vif->queues == NULL) 237 num_queues = READ_ONCE(vif->num_queues);
233 goto out;
234 238
235 /* Aggregate tx and rx stats from each queue */ 239 /* Aggregate tx and rx stats from each queue */
236 for (index = 0; index < vif->num_queues; ++index) { 240 for (index = 0; index < num_queues; ++index) {
237 queue = &vif->queues[index]; 241 queue = &vif->queues[index];
238 rx_bytes += queue->stats.rx_bytes; 242 rx_bytes += queue->stats.rx_bytes;
239 rx_packets += queue->stats.rx_packets; 243 rx_packets += queue->stats.rx_packets;
@@ -241,8 +245,7 @@ static struct net_device_stats *xenvif_get_stats(struct net_device *dev)
241 tx_packets += queue->stats.tx_packets; 245 tx_packets += queue->stats.tx_packets;
242 } 246 }
243 247
244out: 248 rcu_read_unlock();
245 spin_unlock(&vif->lock);
246 249
247 vif->dev->stats.rx_bytes = rx_bytes; 250 vif->dev->stats.rx_bytes = rx_bytes;
248 vif->dev->stats.rx_packets = rx_packets; 251 vif->dev->stats.rx_packets = rx_packets;
@@ -378,10 +381,13 @@ static void xenvif_get_ethtool_stats(struct net_device *dev,
378 struct ethtool_stats *stats, u64 * data) 381 struct ethtool_stats *stats, u64 * data)
379{ 382{
380 struct xenvif *vif = netdev_priv(dev); 383 struct xenvif *vif = netdev_priv(dev);
381 unsigned int num_queues = vif->num_queues; 384 unsigned int num_queues;
382 int i; 385 int i;
383 unsigned int queue_index; 386 unsigned int queue_index;
384 387
388 rcu_read_lock();
389 num_queues = READ_ONCE(vif->num_queues);
390
385 for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++) { 391 for (i = 0; i < ARRAY_SIZE(xenvif_stats); i++) {
386 unsigned long accum = 0; 392 unsigned long accum = 0;
387 for (queue_index = 0; queue_index < num_queues; ++queue_index) { 393 for (queue_index = 0; queue_index < num_queues; ++queue_index) {
@@ -390,6 +396,8 @@ static void xenvif_get_ethtool_stats(struct net_device *dev,
390 } 396 }
391 data[i] = accum; 397 data[i] = accum;
392 } 398 }
399
400 rcu_read_unlock();
393} 401}
394 402
395static void xenvif_get_strings(struct net_device *dev, u32 stringset, u8 * data) 403static void xenvif_get_strings(struct net_device *dev, u32 stringset, u8 * data)
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index f9bcf4a665bc..602d408fa25e 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -214,7 +214,7 @@ static void xenvif_fatal_tx_err(struct xenvif *vif)
214 netdev_err(vif->dev, "fatal error; disabling device\n"); 214 netdev_err(vif->dev, "fatal error; disabling device\n");
215 vif->disabled = true; 215 vif->disabled = true;
216 /* Disable the vif from queue 0's kthread */ 216 /* Disable the vif from queue 0's kthread */
217 if (vif->queues) 217 if (vif->num_queues)
218 xenvif_kick_thread(&vif->queues[0]); 218 xenvif_kick_thread(&vif->queues[0]);
219} 219}
220 220
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index d2d7cd9145b1..a56d3eab35dd 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -495,26 +495,26 @@ static void backend_disconnect(struct backend_info *be)
495 struct xenvif *vif = be->vif; 495 struct xenvif *vif = be->vif;
496 496
497 if (vif) { 497 if (vif) {
498 unsigned int num_queues = vif->num_queues;
498 unsigned int queue_index; 499 unsigned int queue_index;
499 struct xenvif_queue *queues;
500 500
501 xen_unregister_watchers(vif); 501 xen_unregister_watchers(vif);
502#ifdef CONFIG_DEBUG_FS 502#ifdef CONFIG_DEBUG_FS
503 xenvif_debugfs_delif(vif); 503 xenvif_debugfs_delif(vif);
504#endif /* CONFIG_DEBUG_FS */ 504#endif /* CONFIG_DEBUG_FS */
505 xenvif_disconnect_data(vif); 505 xenvif_disconnect_data(vif);
506 for (queue_index = 0;
507 queue_index < vif->num_queues;
508 ++queue_index)
509 xenvif_deinit_queue(&vif->queues[queue_index]);
510 506
511 spin_lock(&vif->lock); 507 /* At this point some of the handlers may still be active
512 queues = vif->queues; 508 * so we need to have additional synchronization here.
509 */
513 vif->num_queues = 0; 510 vif->num_queues = 0;
514 vif->queues = NULL; 511 synchronize_net();
515 spin_unlock(&vif->lock);
516 512
517 vfree(queues); 513 for (queue_index = 0; queue_index < num_queues; ++queue_index)
514 xenvif_deinit_queue(&vif->queues[queue_index]);
515
516 vfree(vif->queues);
517 vif->queues = NULL;
518 518
519 xenvif_disconnect_ctrl(vif); 519 xenvif_disconnect_ctrl(vif);
520 } 520 }
diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c
index 5be4783e40d4..dea98ffb6f60 100644
--- a/drivers/platform/x86/asus-nb-wmi.c
+++ b/drivers/platform/x86/asus-nb-wmi.c
@@ -103,15 +103,6 @@ static struct quirk_entry quirk_asus_x200ca = {
103 .wapf = 2, 103 .wapf = 2,
104}; 104};
105 105
106static struct quirk_entry quirk_no_rfkill = {
107 .no_rfkill = true,
108};
109
110static struct quirk_entry quirk_no_rfkill_wapf4 = {
111 .wapf = 4,
112 .no_rfkill = true,
113};
114
115static struct quirk_entry quirk_asus_ux303ub = { 106static struct quirk_entry quirk_asus_ux303ub = {
116 .wmi_backlight_native = true, 107 .wmi_backlight_native = true,
117}; 108};
@@ -194,7 +185,7 @@ static const struct dmi_system_id asus_quirks[] = {
194 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 185 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
195 DMI_MATCH(DMI_PRODUCT_NAME, "X456UA"), 186 DMI_MATCH(DMI_PRODUCT_NAME, "X456UA"),
196 }, 187 },
197 .driver_data = &quirk_no_rfkill_wapf4, 188 .driver_data = &quirk_asus_wapf4,
198 }, 189 },
199 { 190 {
200 .callback = dmi_matched, 191 .callback = dmi_matched,
@@ -203,7 +194,7 @@ static const struct dmi_system_id asus_quirks[] = {
203 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 194 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
204 DMI_MATCH(DMI_PRODUCT_NAME, "X456UF"), 195 DMI_MATCH(DMI_PRODUCT_NAME, "X456UF"),
205 }, 196 },
206 .driver_data = &quirk_no_rfkill_wapf4, 197 .driver_data = &quirk_asus_wapf4,
207 }, 198 },
208 { 199 {
209 .callback = dmi_matched, 200 .callback = dmi_matched,
@@ -369,42 +360,6 @@ static const struct dmi_system_id asus_quirks[] = {
369 }, 360 },
370 { 361 {
371 .callback = dmi_matched, 362 .callback = dmi_matched,
372 .ident = "ASUSTeK COMPUTER INC. X555UB",
373 .matches = {
374 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
375 DMI_MATCH(DMI_PRODUCT_NAME, "X555UB"),
376 },
377 .driver_data = &quirk_no_rfkill,
378 },
379 {
380 .callback = dmi_matched,
381 .ident = "ASUSTeK COMPUTER INC. N552VW",
382 .matches = {
383 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
384 DMI_MATCH(DMI_PRODUCT_NAME, "N552VW"),
385 },
386 .driver_data = &quirk_no_rfkill,
387 },
388 {
389 .callback = dmi_matched,
390 .ident = "ASUSTeK COMPUTER INC. U303LB",
391 .matches = {
392 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
393 DMI_MATCH(DMI_PRODUCT_NAME, "U303LB"),
394 },
395 .driver_data = &quirk_no_rfkill,
396 },
397 {
398 .callback = dmi_matched,
399 .ident = "ASUSTeK COMPUTER INC. Z550MA",
400 .matches = {
401 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Z550MA"),
403 },
404 .driver_data = &quirk_no_rfkill,
405 },
406 {
407 .callback = dmi_matched,
408 .ident = "ASUSTeK COMPUTER INC. UX303UB", 363 .ident = "ASUSTeK COMPUTER INC. UX303UB",
409 .matches = { 364 .matches = {
410 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 365 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 43cb680adbb4..8fe5890bf539 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -159,6 +159,8 @@ MODULE_LICENSE("GPL");
159#define USB_INTEL_XUSB2PR 0xD0 159#define USB_INTEL_XUSB2PR 0xD0
160#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 160#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
161 161
162static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
163
162struct bios_args { 164struct bios_args {
163 u32 arg0; 165 u32 arg0;
164 u32 arg1; 166 u32 arg1;
@@ -2051,6 +2053,16 @@ static int asus_wmi_fan_init(struct asus_wmi *asus)
2051 return 0; 2053 return 0;
2052} 2054}
2053 2055
2056static bool ashs_present(void)
2057{
2058 int i = 0;
2059 while (ashs_ids[i]) {
2060 if (acpi_dev_found(ashs_ids[i++]))
2061 return true;
2062 }
2063 return false;
2064}
2065
2054/* 2066/*
2055 * WMI Driver 2067 * WMI Driver
2056 */ 2068 */
@@ -2095,7 +2107,11 @@ static int asus_wmi_add(struct platform_device *pdev)
2095 if (err) 2107 if (err)
2096 goto fail_leds; 2108 goto fail_leds;
2097 2109
2098 if (!asus->driver->quirks->no_rfkill) { 2110 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
2111 if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
2112 asus->driver->wlan_ctrl_by_user = 1;
2113
2114 if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) {
2099 err = asus_wmi_rfkill_init(asus); 2115 err = asus_wmi_rfkill_init(asus);
2100 if (err) 2116 if (err)
2101 goto fail_rfkill; 2117 goto fail_rfkill;
@@ -2134,10 +2150,6 @@ static int asus_wmi_add(struct platform_device *pdev)
2134 if (err) 2150 if (err)
2135 goto fail_debugfs; 2151 goto fail_debugfs;
2136 2152
2137 asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
2138 if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
2139 asus->driver->wlan_ctrl_by_user = 1;
2140
2141 return 0; 2153 return 0;
2142 2154
2143fail_debugfs: 2155fail_debugfs:
diff --git a/drivers/platform/x86/asus-wmi.h b/drivers/platform/x86/asus-wmi.h
index fdff626c3b51..c9589d9342bb 100644
--- a/drivers/platform/x86/asus-wmi.h
+++ b/drivers/platform/x86/asus-wmi.h
@@ -39,7 +39,6 @@ struct key_entry;
39struct asus_wmi; 39struct asus_wmi;
40 40
41struct quirk_entry { 41struct quirk_entry {
42 bool no_rfkill;
43 bool hotplug_wireless; 42 bool hotplug_wireless;
44 bool scalar_panel_brightness; 43 bool scalar_panel_brightness;
45 bool store_backlight_power; 44 bool store_backlight_power;
diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 2b218b1d13e5..e12cc3504d48 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -78,18 +78,18 @@
78 78
79#define FUJITSU_LCD_N_LEVELS 8 79#define FUJITSU_LCD_N_LEVELS 8
80 80
81#define ACPI_FUJITSU_CLASS "fujitsu" 81#define ACPI_FUJITSU_CLASS "fujitsu"
82#define ACPI_FUJITSU_HID "FUJ02B1" 82#define ACPI_FUJITSU_BL_HID "FUJ02B1"
83#define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver" 83#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
84#define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" 84#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
85#define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3" 85#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
86#define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver" 86#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
87#define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3" 87#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
88 88
89#define ACPI_FUJITSU_NOTIFY_CODE1 0x80 89#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
90 90
91/* FUNC interface - command values */ 91/* FUNC interface - command values */
92#define FUNC_RFKILL 0x1000 92#define FUNC_FLAGS 0x1000
93#define FUNC_LEDS 0x1001 93#define FUNC_LEDS 0x1001
94#define FUNC_BUTTONS 0x1002 94#define FUNC_BUTTONS 0x1002
95#define FUNC_BACKLIGHT 0x1004 95#define FUNC_BACKLIGHT 0x1004
@@ -97,6 +97,11 @@
97/* FUNC interface - responses */ 97/* FUNC interface - responses */
98#define UNSUPPORTED_CMD 0x80000000 98#define UNSUPPORTED_CMD 0x80000000
99 99
100/* FUNC interface - status flags */
101#define FLAG_RFKILL 0x020
102#define FLAG_LID 0x100
103#define FLAG_DOCK 0x200
104
100#if IS_ENABLED(CONFIG_LEDS_CLASS) 105#if IS_ENABLED(CONFIG_LEDS_CLASS)
101/* FUNC interface - LED control */ 106/* FUNC interface - LED control */
102#define FUNC_LED_OFF 0x1 107#define FUNC_LED_OFF 0x1
@@ -136,7 +141,7 @@
136#endif 141#endif
137 142
138/* Device controlling the backlight and associated keys */ 143/* Device controlling the backlight and associated keys */
139struct fujitsu_t { 144struct fujitsu_bl {
140 acpi_handle acpi_handle; 145 acpi_handle acpi_handle;
141 struct acpi_device *dev; 146 struct acpi_device *dev;
142 struct input_dev *input; 147 struct input_dev *input;
@@ -150,12 +155,12 @@ struct fujitsu_t {
150 unsigned int brightness_level; 155 unsigned int brightness_level;
151}; 156};
152 157
153static struct fujitsu_t *fujitsu; 158static struct fujitsu_bl *fujitsu_bl;
154static int use_alt_lcd_levels = -1; 159static int use_alt_lcd_levels = -1;
155static int disable_brightness_adjust = -1; 160static int disable_brightness_adjust = -1;
156 161
157/* Device used to access other hotkeys on the laptop */ 162/* Device used to access hotkeys and other features on the laptop */
158struct fujitsu_hotkey_t { 163struct fujitsu_laptop {
159 acpi_handle acpi_handle; 164 acpi_handle acpi_handle;
160 struct acpi_device *dev; 165 struct acpi_device *dev;
161 struct input_dev *input; 166 struct input_dev *input;
@@ -163,17 +168,15 @@ struct fujitsu_hotkey_t {
163 struct platform_device *pf_device; 168 struct platform_device *pf_device;
164 struct kfifo fifo; 169 struct kfifo fifo;
165 spinlock_t fifo_lock; 170 spinlock_t fifo_lock;
166 int rfkill_supported; 171 int flags_supported;
167 int rfkill_state; 172 int flags_state;
168 int logolamp_registered; 173 int logolamp_registered;
169 int kblamps_registered; 174 int kblamps_registered;
170 int radio_led_registered; 175 int radio_led_registered;
171 int eco_led_registered; 176 int eco_led_registered;
172}; 177};
173 178
174static struct fujitsu_hotkey_t *fujitsu_hotkey; 179static struct fujitsu_laptop *fujitsu_laptop;
175
176static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event);
177 180
178#if IS_ENABLED(CONFIG_LEDS_CLASS) 181#if IS_ENABLED(CONFIG_LEDS_CLASS)
179static enum led_brightness logolamp_get(struct led_classdev *cdev); 182static enum led_brightness logolamp_get(struct led_classdev *cdev);
@@ -222,8 +225,6 @@ static struct led_classdev eco_led = {
222static u32 dbg_level = 0x03; 225static u32 dbg_level = 0x03;
223#endif 226#endif
224 227
225static void acpi_fujitsu_notify(struct acpi_device *device, u32 event);
226
227/* Fujitsu ACPI interface function */ 228/* Fujitsu ACPI interface function */
228 229
229static int call_fext_func(int cmd, int arg0, int arg1, int arg2) 230static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
@@ -239,7 +240,7 @@ static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
239 unsigned long long value; 240 unsigned long long value;
240 acpi_handle handle = NULL; 241 acpi_handle handle = NULL;
241 242
242 status = acpi_get_handle(fujitsu_hotkey->acpi_handle, "FUNC", &handle); 243 status = acpi_get_handle(fujitsu_laptop->acpi_handle, "FUNC", &handle);
243 if (ACPI_FAILURE(status)) { 244 if (ACPI_FAILURE(status)) {
244 vdbg_printk(FUJLAPTOP_DBG_ERROR, 245 vdbg_printk(FUJLAPTOP_DBG_ERROR,
245 "FUNC interface is not present\n"); 246 "FUNC interface is not present\n");
@@ -300,9 +301,9 @@ static int radio_led_set(struct led_classdev *cdev,
300 enum led_brightness brightness) 301 enum led_brightness brightness)
301{ 302{
302 if (brightness >= LED_FULL) 303 if (brightness >= LED_FULL)
303 return call_fext_func(FUNC_RFKILL, 0x5, RADIO_LED_ON, RADIO_LED_ON); 304 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
304 else 305 else
305 return call_fext_func(FUNC_RFKILL, 0x5, RADIO_LED_ON, 0x0); 306 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
306} 307}
307 308
308static int eco_led_set(struct led_classdev *cdev, 309static int eco_led_set(struct led_classdev *cdev,
@@ -346,7 +347,7 @@ static enum led_brightness radio_led_get(struct led_classdev *cdev)
346{ 347{
347 enum led_brightness brightness = LED_OFF; 348 enum led_brightness brightness = LED_OFF;
348 349
349 if (call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0) & RADIO_LED_ON) 350 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
350 brightness = LED_FULL; 351 brightness = LED_FULL;
351 352
352 return brightness; 353 return brightness;
@@ -373,10 +374,10 @@ static int set_lcd_level(int level)
373 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n", 374 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
374 level); 375 level);
375 376
376 if (level < 0 || level >= fujitsu->max_brightness) 377 if (level < 0 || level >= fujitsu_bl->max_brightness)
377 return -EINVAL; 378 return -EINVAL;
378 379
379 status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); 380 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
380 if (ACPI_FAILURE(status)) { 381 if (ACPI_FAILURE(status)) {
381 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n"); 382 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
382 return -ENODEV; 383 return -ENODEV;
@@ -398,10 +399,10 @@ static int set_lcd_level_alt(int level)
398 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n", 399 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
399 level); 400 level);
400 401
401 if (level < 0 || level >= fujitsu->max_brightness) 402 if (level < 0 || level >= fujitsu_bl->max_brightness)
402 return -EINVAL; 403 return -EINVAL;
403 404
404 status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle); 405 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
405 if (ACPI_FAILURE(status)) { 406 if (ACPI_FAILURE(status)) {
406 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n"); 407 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
407 return -ENODEV; 408 return -ENODEV;
@@ -421,19 +422,19 @@ static int get_lcd_level(void)
421 422
422 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n"); 423 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
423 424
424 status = 425 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
425 acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); 426 &state);
426 if (ACPI_FAILURE(status)) 427 if (ACPI_FAILURE(status))
427 return 0; 428 return 0;
428 429
429 fujitsu->brightness_level = state & 0x0fffffff; 430 fujitsu_bl->brightness_level = state & 0x0fffffff;
430 431
431 if (state & 0x80000000) 432 if (state & 0x80000000)
432 fujitsu->brightness_changed = 1; 433 fujitsu_bl->brightness_changed = 1;
433 else 434 else
434 fujitsu->brightness_changed = 0; 435 fujitsu_bl->brightness_changed = 0;
435 436
436 return fujitsu->brightness_level; 437 return fujitsu_bl->brightness_level;
437} 438}
438 439
439static int get_max_brightness(void) 440static int get_max_brightness(void)
@@ -443,14 +444,14 @@ static int get_max_brightness(void)
443 444
444 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n"); 445 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
445 446
446 status = 447 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
447 acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state); 448 &state);
448 if (ACPI_FAILURE(status)) 449 if (ACPI_FAILURE(status))
449 return -1; 450 return -1;
450 451
451 fujitsu->max_brightness = state; 452 fujitsu_bl->max_brightness = state;
452 453
453 return fujitsu->max_brightness; 454 return fujitsu_bl->max_brightness;
454} 455}
455 456
456/* Backlight device stuff */ 457/* Backlight device stuff */
@@ -483,7 +484,7 @@ static int bl_update_status(struct backlight_device *b)
483 return ret; 484 return ret;
484} 485}
485 486
486static const struct backlight_ops fujitsubl_ops = { 487static const struct backlight_ops fujitsu_bl_ops = {
487 .get_brightness = bl_get_brightness, 488 .get_brightness = bl_get_brightness,
488 .update_status = bl_update_status, 489 .update_status = bl_update_status,
489}; 490};
@@ -511,7 +512,7 @@ show_brightness_changed(struct device *dev,
511 512
512 int ret; 513 int ret;
513 514
514 ret = fujitsu->brightness_changed; 515 ret = fujitsu_bl->brightness_changed;
515 if (ret < 0) 516 if (ret < 0)
516 return ret; 517 return ret;
517 518
@@ -539,7 +540,7 @@ static ssize_t store_lcd_level(struct device *dev,
539 int level, ret; 540 int level, ret;
540 541
541 if (sscanf(buf, "%i", &level) != 1 542 if (sscanf(buf, "%i", &level) != 1
542 || (level < 0 || level >= fujitsu->max_brightness)) 543 || (level < 0 || level >= fujitsu_bl->max_brightness))
543 return -EINVAL; 544 return -EINVAL;
544 545
545 if (use_alt_lcd_levels) 546 if (use_alt_lcd_levels)
@@ -567,9 +568,9 @@ static ssize_t
567show_lid_state(struct device *dev, 568show_lid_state(struct device *dev,
568 struct device_attribute *attr, char *buf) 569 struct device_attribute *attr, char *buf)
569{ 570{
570 if (!(fujitsu_hotkey->rfkill_supported & 0x100)) 571 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
571 return sprintf(buf, "unknown\n"); 572 return sprintf(buf, "unknown\n");
572 if (fujitsu_hotkey->rfkill_state & 0x100) 573 if (fujitsu_laptop->flags_state & FLAG_LID)
573 return sprintf(buf, "open\n"); 574 return sprintf(buf, "open\n");
574 else 575 else
575 return sprintf(buf, "closed\n"); 576 return sprintf(buf, "closed\n");
@@ -579,9 +580,9 @@ static ssize_t
579show_dock_state(struct device *dev, 580show_dock_state(struct device *dev,
580 struct device_attribute *attr, char *buf) 581 struct device_attribute *attr, char *buf)
581{ 582{
582 if (!(fujitsu_hotkey->rfkill_supported & 0x200)) 583 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
583 return sprintf(buf, "unknown\n"); 584 return sprintf(buf, "unknown\n");
584 if (fujitsu_hotkey->rfkill_state & 0x200) 585 if (fujitsu_laptop->flags_state & FLAG_DOCK)
585 return sprintf(buf, "docked\n"); 586 return sprintf(buf, "docked\n");
586 else 587 else
587 return sprintf(buf, "undocked\n"); 588 return sprintf(buf, "undocked\n");
@@ -591,9 +592,9 @@ static ssize_t
591show_radios_state(struct device *dev, 592show_radios_state(struct device *dev,
592 struct device_attribute *attr, char *buf) 593 struct device_attribute *attr, char *buf)
593{ 594{
594 if (!(fujitsu_hotkey->rfkill_supported & 0x20)) 595 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
595 return sprintf(buf, "unknown\n"); 596 return sprintf(buf, "unknown\n");
596 if (fujitsu_hotkey->rfkill_state & 0x20) 597 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
597 return sprintf(buf, "on\n"); 598 return sprintf(buf, "on\n");
598 else 599 else
599 return sprintf(buf, "killed\n"); 600 return sprintf(buf, "killed\n");
@@ -607,7 +608,7 @@ static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
607static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store); 608static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
608static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store); 609static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
609 610
610static struct attribute *fujitsupf_attributes[] = { 611static struct attribute *fujitsu_pf_attributes[] = {
611 &dev_attr_brightness_changed.attr, 612 &dev_attr_brightness_changed.attr,
612 &dev_attr_max_brightness.attr, 613 &dev_attr_max_brightness.attr,
613 &dev_attr_lcd_level.attr, 614 &dev_attr_lcd_level.attr,
@@ -617,11 +618,11 @@ static struct attribute *fujitsupf_attributes[] = {
617 NULL 618 NULL
618}; 619};
619 620
620static struct attribute_group fujitsupf_attribute_group = { 621static struct attribute_group fujitsu_pf_attribute_group = {
621 .attrs = fujitsupf_attributes 622 .attrs = fujitsu_pf_attributes
622}; 623};
623 624
624static struct platform_driver fujitsupf_driver = { 625static struct platform_driver fujitsu_pf_driver = {
625 .driver = { 626 .driver = {
626 .name = "fujitsu-laptop", 627 .name = "fujitsu-laptop",
627 } 628 }
@@ -630,39 +631,30 @@ static struct platform_driver fujitsupf_driver = {
630static void __init dmi_check_cb_common(const struct dmi_system_id *id) 631static void __init dmi_check_cb_common(const struct dmi_system_id *id)
631{ 632{
632 pr_info("Identified laptop model '%s'\n", id->ident); 633 pr_info("Identified laptop model '%s'\n", id->ident);
633 if (use_alt_lcd_levels == -1) {
634 if (acpi_has_method(NULL,
635 "\\_SB.PCI0.LPCB.FJEX.SBL2"))
636 use_alt_lcd_levels = 1;
637 else
638 use_alt_lcd_levels = 0;
639 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as "
640 "%i\n", use_alt_lcd_levels);
641 }
642} 634}
643 635
644static int __init dmi_check_cb_s6410(const struct dmi_system_id *id) 636static int __init dmi_check_cb_s6410(const struct dmi_system_id *id)
645{ 637{
646 dmi_check_cb_common(id); 638 dmi_check_cb_common(id);
647 fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ 639 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
648 fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ 640 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
649 return 1; 641 return 1;
650} 642}
651 643
652static int __init dmi_check_cb_s6420(const struct dmi_system_id *id) 644static int __init dmi_check_cb_s6420(const struct dmi_system_id *id)
653{ 645{
654 dmi_check_cb_common(id); 646 dmi_check_cb_common(id);
655 fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ 647 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
656 fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ 648 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
657 return 1; 649 return 1;
658} 650}
659 651
660static int __init dmi_check_cb_p8010(const struct dmi_system_id *id) 652static int __init dmi_check_cb_p8010(const struct dmi_system_id *id)
661{ 653{
662 dmi_check_cb_common(id); 654 dmi_check_cb_common(id);
663 fujitsu->keycode1 = KEY_HELP; /* "Support" */ 655 fujitsu_bl->keycode1 = KEY_HELP; /* "Support" */
664 fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */ 656 fujitsu_bl->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
665 fujitsu->keycode4 = KEY_WWW; /* "Internet" */ 657 fujitsu_bl->keycode4 = KEY_WWW; /* "Internet" */
666 return 1; 658 return 1;
667} 659}
668 660
@@ -693,7 +685,7 @@ static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
693 685
694/* ACPI device for LCD brightness control */ 686/* ACPI device for LCD brightness control */
695 687
696static int acpi_fujitsu_add(struct acpi_device *device) 688static int acpi_fujitsu_bl_add(struct acpi_device *device)
697{ 689{
698 int state = 0; 690 int state = 0;
699 struct input_dev *input; 691 struct input_dev *input;
@@ -702,22 +694,22 @@ static int acpi_fujitsu_add(struct acpi_device *device)
702 if (!device) 694 if (!device)
703 return -EINVAL; 695 return -EINVAL;
704 696
705 fujitsu->acpi_handle = device->handle; 697 fujitsu_bl->acpi_handle = device->handle;
706 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME); 698 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
707 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); 699 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
708 device->driver_data = fujitsu; 700 device->driver_data = fujitsu_bl;
709 701
710 fujitsu->input = input = input_allocate_device(); 702 fujitsu_bl->input = input = input_allocate_device();
711 if (!input) { 703 if (!input) {
712 error = -ENOMEM; 704 error = -ENOMEM;
713 goto err_stop; 705 goto err_stop;
714 } 706 }
715 707
716 snprintf(fujitsu->phys, sizeof(fujitsu->phys), 708 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
717 "%s/video/input0", acpi_device_hid(device)); 709 "%s/video/input0", acpi_device_hid(device));
718 710
719 input->name = acpi_device_name(device); 711 input->name = acpi_device_name(device);
720 input->phys = fujitsu->phys; 712 input->phys = fujitsu_bl->phys;
721 input->id.bustype = BUS_HOST; 713 input->id.bustype = BUS_HOST;
722 input->id.product = 0x06; 714 input->id.product = 0x06;
723 input->dev.parent = &device->dev; 715 input->dev.parent = &device->dev;
@@ -730,7 +722,7 @@ static int acpi_fujitsu_add(struct acpi_device *device)
730 if (error) 722 if (error)
731 goto err_free_input_dev; 723 goto err_free_input_dev;
732 724
733 error = acpi_bus_update_power(fujitsu->acpi_handle, &state); 725 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
734 if (error) { 726 if (error) {
735 pr_err("Error reading power state\n"); 727 pr_err("Error reading power state\n");
736 goto err_unregister_input_dev; 728 goto err_unregister_input_dev;
@@ -740,7 +732,7 @@ static int acpi_fujitsu_add(struct acpi_device *device)
740 acpi_device_name(device), acpi_device_bid(device), 732 acpi_device_name(device), acpi_device_bid(device),
741 !device->power.state ? "on" : "off"); 733 !device->power.state ? "on" : "off");
742 734
743 fujitsu->dev = device; 735 fujitsu_bl->dev = device;
744 736
745 if (acpi_has_method(device->handle, METHOD_NAME__INI)) { 737 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
746 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); 738 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
@@ -750,6 +742,15 @@ static int acpi_fujitsu_add(struct acpi_device *device)
750 pr_err("_INI Method failed\n"); 742 pr_err("_INI Method failed\n");
751 } 743 }
752 744
745 if (use_alt_lcd_levels == -1) {
746 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
747 use_alt_lcd_levels = 1;
748 else
749 use_alt_lcd_levels = 0;
750 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
751 use_alt_lcd_levels);
752 }
753
753 /* do config (detect defaults) */ 754 /* do config (detect defaults) */
754 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0; 755 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
755 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0; 756 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
@@ -758,7 +759,7 @@ static int acpi_fujitsu_add(struct acpi_device *device)
758 use_alt_lcd_levels, disable_brightness_adjust); 759 use_alt_lcd_levels, disable_brightness_adjust);
759 760
760 if (get_max_brightness() <= 0) 761 if (get_max_brightness() <= 0)
761 fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS; 762 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
762 get_lcd_level(); 763 get_lcd_level();
763 764
764 return 0; 765 return 0;
@@ -772,38 +773,38 @@ err_stop:
772 return error; 773 return error;
773} 774}
774 775
775static int acpi_fujitsu_remove(struct acpi_device *device) 776static int acpi_fujitsu_bl_remove(struct acpi_device *device)
776{ 777{
777 struct fujitsu_t *fujitsu = acpi_driver_data(device); 778 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
778 struct input_dev *input = fujitsu->input; 779 struct input_dev *input = fujitsu_bl->input;
779 780
780 input_unregister_device(input); 781 input_unregister_device(input);
781 782
782 fujitsu->acpi_handle = NULL; 783 fujitsu_bl->acpi_handle = NULL;
783 784
784 return 0; 785 return 0;
785} 786}
786 787
787/* Brightness notify */ 788/* Brightness notify */
788 789
789static void acpi_fujitsu_notify(struct acpi_device *device, u32 event) 790static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
790{ 791{
791 struct input_dev *input; 792 struct input_dev *input;
792 int keycode; 793 int keycode;
793 int oldb, newb; 794 int oldb, newb;
794 795
795 input = fujitsu->input; 796 input = fujitsu_bl->input;
796 797
797 switch (event) { 798 switch (event) {
798 case ACPI_FUJITSU_NOTIFY_CODE1: 799 case ACPI_FUJITSU_NOTIFY_CODE1:
799 keycode = 0; 800 keycode = 0;
800 oldb = fujitsu->brightness_level; 801 oldb = fujitsu_bl->brightness_level;
801 get_lcd_level(); 802 get_lcd_level();
802 newb = fujitsu->brightness_level; 803 newb = fujitsu_bl->brightness_level;
803 804
804 vdbg_printk(FUJLAPTOP_DBG_TRACE, 805 vdbg_printk(FUJLAPTOP_DBG_TRACE,
805 "brightness button event [%i -> %i (%i)]\n", 806 "brightness button event [%i -> %i (%i)]\n",
806 oldb, newb, fujitsu->brightness_changed); 807 oldb, newb, fujitsu_bl->brightness_changed);
807 808
808 if (oldb < newb) { 809 if (oldb < newb) {
809 if (disable_brightness_adjust != 1) { 810 if (disable_brightness_adjust != 1) {
@@ -840,7 +841,7 @@ static void acpi_fujitsu_notify(struct acpi_device *device, u32 event)
840 841
841/* ACPI device for hotkey handling */ 842/* ACPI device for hotkey handling */
842 843
843static int acpi_fujitsu_hotkey_add(struct acpi_device *device) 844static int acpi_fujitsu_laptop_add(struct acpi_device *device)
844{ 845{
845 int result = 0; 846 int result = 0;
846 int state = 0; 847 int state = 0;
@@ -851,42 +852,42 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
851 if (!device) 852 if (!device)
852 return -EINVAL; 853 return -EINVAL;
853 854
854 fujitsu_hotkey->acpi_handle = device->handle; 855 fujitsu_laptop->acpi_handle = device->handle;
855 sprintf(acpi_device_name(device), "%s", 856 sprintf(acpi_device_name(device), "%s",
856 ACPI_FUJITSU_HOTKEY_DEVICE_NAME); 857 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
857 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); 858 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
858 device->driver_data = fujitsu_hotkey; 859 device->driver_data = fujitsu_laptop;
859 860
860 /* kfifo */ 861 /* kfifo */
861 spin_lock_init(&fujitsu_hotkey->fifo_lock); 862 spin_lock_init(&fujitsu_laptop->fifo_lock);
862 error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int), 863 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
863 GFP_KERNEL); 864 GFP_KERNEL);
864 if (error) { 865 if (error) {
865 pr_err("kfifo_alloc failed\n"); 866 pr_err("kfifo_alloc failed\n");
866 goto err_stop; 867 goto err_stop;
867 } 868 }
868 869
869 fujitsu_hotkey->input = input = input_allocate_device(); 870 fujitsu_laptop->input = input = input_allocate_device();
870 if (!input) { 871 if (!input) {
871 error = -ENOMEM; 872 error = -ENOMEM;
872 goto err_free_fifo; 873 goto err_free_fifo;
873 } 874 }
874 875
875 snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys), 876 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
876 "%s/video/input0", acpi_device_hid(device)); 877 "%s/video/input0", acpi_device_hid(device));
877 878
878 input->name = acpi_device_name(device); 879 input->name = acpi_device_name(device);
879 input->phys = fujitsu_hotkey->phys; 880 input->phys = fujitsu_laptop->phys;
880 input->id.bustype = BUS_HOST; 881 input->id.bustype = BUS_HOST;
881 input->id.product = 0x06; 882 input->id.product = 0x06;
882 input->dev.parent = &device->dev; 883 input->dev.parent = &device->dev;
883 884
884 set_bit(EV_KEY, input->evbit); 885 set_bit(EV_KEY, input->evbit);
885 set_bit(fujitsu->keycode1, input->keybit); 886 set_bit(fujitsu_bl->keycode1, input->keybit);
886 set_bit(fujitsu->keycode2, input->keybit); 887 set_bit(fujitsu_bl->keycode2, input->keybit);
887 set_bit(fujitsu->keycode3, input->keybit); 888 set_bit(fujitsu_bl->keycode3, input->keybit);
888 set_bit(fujitsu->keycode4, input->keybit); 889 set_bit(fujitsu_bl->keycode4, input->keybit);
889 set_bit(fujitsu->keycode5, input->keybit); 890 set_bit(fujitsu_bl->keycode5, input->keybit);
890 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit); 891 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
891 set_bit(KEY_UNKNOWN, input->keybit); 892 set_bit(KEY_UNKNOWN, input->keybit);
892 893
@@ -894,7 +895,7 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
894 if (error) 895 if (error)
895 goto err_free_input_dev; 896 goto err_free_input_dev;
896 897
897 error = acpi_bus_update_power(fujitsu_hotkey->acpi_handle, &state); 898 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
898 if (error) { 899 if (error) {
899 pr_err("Error reading power state\n"); 900 pr_err("Error reading power state\n");
900 goto err_unregister_input_dev; 901 goto err_unregister_input_dev;
@@ -904,7 +905,7 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
904 acpi_device_name(device), acpi_device_bid(device), 905 acpi_device_name(device), acpi_device_bid(device),
905 !device->power.state ? "on" : "off"); 906 !device->power.state ? "on" : "off");
906 907
907 fujitsu_hotkey->dev = device; 908 fujitsu_laptop->dev = device;
908 909
909 if (acpi_has_method(device->handle, METHOD_NAME__INI)) { 910 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
910 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); 911 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
@@ -920,27 +921,27 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
920 ; /* No action, result is discarded */ 921 ; /* No action, result is discarded */
921 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i); 922 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
922 923
923 fujitsu_hotkey->rfkill_supported = 924 fujitsu_laptop->flags_supported =
924 call_fext_func(FUNC_RFKILL, 0x0, 0x0, 0x0); 925 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
925 926
926 /* Make sure our bitmask of supported functions is cleared if the 927 /* Make sure our bitmask of supported functions is cleared if the
927 RFKILL function block is not implemented, like on the S7020. */ 928 RFKILL function block is not implemented, like on the S7020. */
928 if (fujitsu_hotkey->rfkill_supported == UNSUPPORTED_CMD) 929 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
929 fujitsu_hotkey->rfkill_supported = 0; 930 fujitsu_laptop->flags_supported = 0;
930 931
931 if (fujitsu_hotkey->rfkill_supported) 932 if (fujitsu_laptop->flags_supported)
932 fujitsu_hotkey->rfkill_state = 933 fujitsu_laptop->flags_state =
933 call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); 934 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
934 935
935 /* Suspect this is a keymap of the application panel, print it */ 936 /* Suspect this is a keymap of the application panel, print it */
936 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0)); 937 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
937 938
938#if IS_ENABLED(CONFIG_LEDS_CLASS) 939#if IS_ENABLED(CONFIG_LEDS_CLASS)
939 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) { 940 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
940 result = led_classdev_register(&fujitsu->pf_device->dev, 941 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
941 &logolamp_led); 942 &logolamp_led);
942 if (result == 0) { 943 if (result == 0) {
943 fujitsu_hotkey->logolamp_registered = 1; 944 fujitsu_laptop->logolamp_registered = 1;
944 } else { 945 } else {
945 pr_err("Could not register LED handler for logo lamp, error %i\n", 946 pr_err("Could not register LED handler for logo lamp, error %i\n",
946 result); 947 result);
@@ -949,10 +950,10 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
949 950
950 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) && 951 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
951 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) { 952 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
952 result = led_classdev_register(&fujitsu->pf_device->dev, 953 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
953 &kblamps_led); 954 &kblamps_led);
954 if (result == 0) { 955 if (result == 0) {
955 fujitsu_hotkey->kblamps_registered = 1; 956 fujitsu_laptop->kblamps_registered = 1;
956 } else { 957 } else {
957 pr_err("Could not register LED handler for keyboard lamps, error %i\n", 958 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
958 result); 959 result);
@@ -966,10 +967,10 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
966 * that an RF LED is present. 967 * that an RF LED is present.
967 */ 968 */
968 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) { 969 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
969 result = led_classdev_register(&fujitsu->pf_device->dev, 970 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
970 &radio_led); 971 &radio_led);
971 if (result == 0) { 972 if (result == 0) {
972 fujitsu_hotkey->radio_led_registered = 1; 973 fujitsu_laptop->radio_led_registered = 1;
973 } else { 974 } else {
974 pr_err("Could not register LED handler for radio LED, error %i\n", 975 pr_err("Could not register LED handler for radio LED, error %i\n",
975 result); 976 result);
@@ -983,10 +984,10 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
983 */ 984 */
984 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) && 985 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
985 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) { 986 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
986 result = led_classdev_register(&fujitsu->pf_device->dev, 987 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
987 &eco_led); 988 &eco_led);
988 if (result == 0) { 989 if (result == 0) {
989 fujitsu_hotkey->eco_led_registered = 1; 990 fujitsu_laptop->eco_led_registered = 1;
990 } else { 991 } else {
991 pr_err("Could not register LED handler for eco LED, error %i\n", 992 pr_err("Could not register LED handler for eco LED, error %i\n",
992 result); 993 result);
@@ -1002,47 +1003,47 @@ err_unregister_input_dev:
1002err_free_input_dev: 1003err_free_input_dev:
1003 input_free_device(input); 1004 input_free_device(input);
1004err_free_fifo: 1005err_free_fifo:
1005 kfifo_free(&fujitsu_hotkey->fifo); 1006 kfifo_free(&fujitsu_laptop->fifo);
1006err_stop: 1007err_stop:
1007 return error; 1008 return error;
1008} 1009}
1009 1010
1010static int acpi_fujitsu_hotkey_remove(struct acpi_device *device) 1011static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
1011{ 1012{
1012 struct fujitsu_hotkey_t *fujitsu_hotkey = acpi_driver_data(device); 1013 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
1013 struct input_dev *input = fujitsu_hotkey->input; 1014 struct input_dev *input = fujitsu_laptop->input;
1014 1015
1015#if IS_ENABLED(CONFIG_LEDS_CLASS) 1016#if IS_ENABLED(CONFIG_LEDS_CLASS)
1016 if (fujitsu_hotkey->logolamp_registered) 1017 if (fujitsu_laptop->logolamp_registered)
1017 led_classdev_unregister(&logolamp_led); 1018 led_classdev_unregister(&logolamp_led);
1018 1019
1019 if (fujitsu_hotkey->kblamps_registered) 1020 if (fujitsu_laptop->kblamps_registered)
1020 led_classdev_unregister(&kblamps_led); 1021 led_classdev_unregister(&kblamps_led);
1021 1022
1022 if (fujitsu_hotkey->radio_led_registered) 1023 if (fujitsu_laptop->radio_led_registered)
1023 led_classdev_unregister(&radio_led); 1024 led_classdev_unregister(&radio_led);
1024 1025
1025 if (fujitsu_hotkey->eco_led_registered) 1026 if (fujitsu_laptop->eco_led_registered)
1026 led_classdev_unregister(&eco_led); 1027 led_classdev_unregister(&eco_led);
1027#endif 1028#endif
1028 1029
1029 input_unregister_device(input); 1030 input_unregister_device(input);
1030 1031
1031 kfifo_free(&fujitsu_hotkey->fifo); 1032 kfifo_free(&fujitsu_laptop->fifo);
1032 1033
1033 fujitsu_hotkey->acpi_handle = NULL; 1034 fujitsu_laptop->acpi_handle = NULL;
1034 1035
1035 return 0; 1036 return 0;
1036} 1037}
1037 1038
1038static void acpi_fujitsu_hotkey_press(int keycode) 1039static void acpi_fujitsu_laptop_press(int keycode)
1039{ 1040{
1040 struct input_dev *input = fujitsu_hotkey->input; 1041 struct input_dev *input = fujitsu_laptop->input;
1041 int status; 1042 int status;
1042 1043
1043 status = kfifo_in_locked(&fujitsu_hotkey->fifo, 1044 status = kfifo_in_locked(&fujitsu_laptop->fifo,
1044 (unsigned char *)&keycode, sizeof(keycode), 1045 (unsigned char *)&keycode, sizeof(keycode),
1045 &fujitsu_hotkey->fifo_lock); 1046 &fujitsu_laptop->fifo_lock);
1046 if (status != sizeof(keycode)) { 1047 if (status != sizeof(keycode)) {
1047 vdbg_printk(FUJLAPTOP_DBG_WARN, 1048 vdbg_printk(FUJLAPTOP_DBG_WARN,
1048 "Could not push keycode [0x%x]\n", keycode); 1049 "Could not push keycode [0x%x]\n", keycode);
@@ -1054,16 +1055,16 @@ static void acpi_fujitsu_hotkey_press(int keycode)
1054 "Push keycode into ringbuffer [%d]\n", keycode); 1055 "Push keycode into ringbuffer [%d]\n", keycode);
1055} 1056}
1056 1057
1057static void acpi_fujitsu_hotkey_release(void) 1058static void acpi_fujitsu_laptop_release(void)
1058{ 1059{
1059 struct input_dev *input = fujitsu_hotkey->input; 1060 struct input_dev *input = fujitsu_laptop->input;
1060 int keycode, status; 1061 int keycode, status;
1061 1062
1062 while (true) { 1063 while (true) {
1063 status = kfifo_out_locked(&fujitsu_hotkey->fifo, 1064 status = kfifo_out_locked(&fujitsu_laptop->fifo,
1064 (unsigned char *)&keycode, 1065 (unsigned char *)&keycode,
1065 sizeof(keycode), 1066 sizeof(keycode),
1066 &fujitsu_hotkey->fifo_lock); 1067 &fujitsu_laptop->fifo_lock);
1067 if (status != sizeof(keycode)) 1068 if (status != sizeof(keycode))
1068 return; 1069 return;
1069 input_report_key(input, keycode, 0); 1070 input_report_key(input, keycode, 0);
@@ -1073,14 +1074,14 @@ static void acpi_fujitsu_hotkey_release(void)
1073 } 1074 }
1074} 1075}
1075 1076
1076static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) 1077static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
1077{ 1078{
1078 struct input_dev *input; 1079 struct input_dev *input;
1079 int keycode; 1080 int keycode;
1080 unsigned int irb = 1; 1081 unsigned int irb = 1;
1081 int i; 1082 int i;
1082 1083
1083 input = fujitsu_hotkey->input; 1084 input = fujitsu_laptop->input;
1084 1085
1085 if (event != ACPI_FUJITSU_NOTIFY_CODE1) { 1086 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
1086 keycode = KEY_UNKNOWN; 1087 keycode = KEY_UNKNOWN;
@@ -1093,9 +1094,9 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event)
1093 return; 1094 return;
1094 } 1095 }
1095 1096
1096 if (fujitsu_hotkey->rfkill_supported) 1097 if (fujitsu_laptop->flags_supported)
1097 fujitsu_hotkey->rfkill_state = 1098 fujitsu_laptop->flags_state =
1098 call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0); 1099 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
1099 1100
1100 i = 0; 1101 i = 0;
1101 while ((irb = 1102 while ((irb =
@@ -1103,19 +1104,19 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event)
1103 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) { 1104 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1104 switch (irb & 0x4ff) { 1105 switch (irb & 0x4ff) {
1105 case KEY1_CODE: 1106 case KEY1_CODE:
1106 keycode = fujitsu->keycode1; 1107 keycode = fujitsu_bl->keycode1;
1107 break; 1108 break;
1108 case KEY2_CODE: 1109 case KEY2_CODE:
1109 keycode = fujitsu->keycode2; 1110 keycode = fujitsu_bl->keycode2;
1110 break; 1111 break;
1111 case KEY3_CODE: 1112 case KEY3_CODE:
1112 keycode = fujitsu->keycode3; 1113 keycode = fujitsu_bl->keycode3;
1113 break; 1114 break;
1114 case KEY4_CODE: 1115 case KEY4_CODE:
1115 keycode = fujitsu->keycode4; 1116 keycode = fujitsu_bl->keycode4;
1116 break; 1117 break;
1117 case KEY5_CODE: 1118 case KEY5_CODE:
1118 keycode = fujitsu->keycode5; 1119 keycode = fujitsu_bl->keycode5;
1119 break; 1120 break;
1120 case 0: 1121 case 0:
1121 keycode = 0; 1122 keycode = 0;
@@ -1128,17 +1129,17 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event)
1128 } 1129 }
1129 1130
1130 if (keycode > 0) 1131 if (keycode > 0)
1131 acpi_fujitsu_hotkey_press(keycode); 1132 acpi_fujitsu_laptop_press(keycode);
1132 else if (keycode == 0) 1133 else if (keycode == 0)
1133 acpi_fujitsu_hotkey_release(); 1134 acpi_fujitsu_laptop_release();
1134 } 1135 }
1135 1136
1136 /* On some models (first seen on the Skylake-based Lifebook 1137 /* On some models (first seen on the Skylake-based Lifebook
1137 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is 1138 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
1138 * handled in software; its state is queried using FUNC_RFKILL 1139 * handled in software; its state is queried using FUNC_FLAGS
1139 */ 1140 */
1140 if ((fujitsu_hotkey->rfkill_supported & BIT(26)) && 1141 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1141 (call_fext_func(FUNC_RFKILL, 0x1, 0x0, 0x0) & BIT(26))) { 1142 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
1142 keycode = KEY_TOUCHPAD_TOGGLE; 1143 keycode = KEY_TOUCHPAD_TOGGLE;
1143 input_report_key(input, keycode, 1); 1144 input_report_key(input, keycode, 1);
1144 input_sync(input); 1145 input_sync(input);
@@ -1150,83 +1151,81 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event)
1150 1151
1151/* Initialization */ 1152/* Initialization */
1152 1153
1153static const struct acpi_device_id fujitsu_device_ids[] = { 1154static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1154 {ACPI_FUJITSU_HID, 0}, 1155 {ACPI_FUJITSU_BL_HID, 0},
1155 {"", 0}, 1156 {"", 0},
1156}; 1157};
1157 1158
1158static struct acpi_driver acpi_fujitsu_driver = { 1159static struct acpi_driver acpi_fujitsu_bl_driver = {
1159 .name = ACPI_FUJITSU_DRIVER_NAME, 1160 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
1160 .class = ACPI_FUJITSU_CLASS, 1161 .class = ACPI_FUJITSU_CLASS,
1161 .ids = fujitsu_device_ids, 1162 .ids = fujitsu_bl_device_ids,
1162 .ops = { 1163 .ops = {
1163 .add = acpi_fujitsu_add, 1164 .add = acpi_fujitsu_bl_add,
1164 .remove = acpi_fujitsu_remove, 1165 .remove = acpi_fujitsu_bl_remove,
1165 .notify = acpi_fujitsu_notify, 1166 .notify = acpi_fujitsu_bl_notify,
1166 }, 1167 },
1167}; 1168};
1168 1169
1169static const struct acpi_device_id fujitsu_hotkey_device_ids[] = { 1170static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1170 {ACPI_FUJITSU_HOTKEY_HID, 0}, 1171 {ACPI_FUJITSU_LAPTOP_HID, 0},
1171 {"", 0}, 1172 {"", 0},
1172}; 1173};
1173 1174
1174static struct acpi_driver acpi_fujitsu_hotkey_driver = { 1175static struct acpi_driver acpi_fujitsu_laptop_driver = {
1175 .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME, 1176 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
1176 .class = ACPI_FUJITSU_CLASS, 1177 .class = ACPI_FUJITSU_CLASS,
1177 .ids = fujitsu_hotkey_device_ids, 1178 .ids = fujitsu_laptop_device_ids,
1178 .ops = { 1179 .ops = {
1179 .add = acpi_fujitsu_hotkey_add, 1180 .add = acpi_fujitsu_laptop_add,
1180 .remove = acpi_fujitsu_hotkey_remove, 1181 .remove = acpi_fujitsu_laptop_remove,
1181 .notify = acpi_fujitsu_hotkey_notify, 1182 .notify = acpi_fujitsu_laptop_notify,
1182 }, 1183 },
1183}; 1184};
1184 1185
1185static const struct acpi_device_id fujitsu_ids[] __used = { 1186static const struct acpi_device_id fujitsu_ids[] __used = {
1186 {ACPI_FUJITSU_HID, 0}, 1187 {ACPI_FUJITSU_BL_HID, 0},
1187 {ACPI_FUJITSU_HOTKEY_HID, 0}, 1188 {ACPI_FUJITSU_LAPTOP_HID, 0},
1188 {"", 0} 1189 {"", 0}
1189}; 1190};
1190MODULE_DEVICE_TABLE(acpi, fujitsu_ids); 1191MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1191 1192
1192static int __init fujitsu_init(void) 1193static int __init fujitsu_init(void)
1193{ 1194{
1194 int ret, result, max_brightness; 1195 int ret, max_brightness;
1195 1196
1196 if (acpi_disabled) 1197 if (acpi_disabled)
1197 return -ENODEV; 1198 return -ENODEV;
1198 1199
1199 fujitsu = kzalloc(sizeof(struct fujitsu_t), GFP_KERNEL); 1200 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1200 if (!fujitsu) 1201 if (!fujitsu_bl)
1201 return -ENOMEM; 1202 return -ENOMEM;
1202 fujitsu->keycode1 = KEY_PROG1; 1203 fujitsu_bl->keycode1 = KEY_PROG1;
1203 fujitsu->keycode2 = KEY_PROG2; 1204 fujitsu_bl->keycode2 = KEY_PROG2;
1204 fujitsu->keycode3 = KEY_PROG3; 1205 fujitsu_bl->keycode3 = KEY_PROG3;
1205 fujitsu->keycode4 = KEY_PROG4; 1206 fujitsu_bl->keycode4 = KEY_PROG4;
1206 fujitsu->keycode5 = KEY_RFKILL; 1207 fujitsu_bl->keycode5 = KEY_RFKILL;
1207 dmi_check_system(fujitsu_dmi_table); 1208 dmi_check_system(fujitsu_dmi_table);
1208 1209
1209 result = acpi_bus_register_driver(&acpi_fujitsu_driver); 1210 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1210 if (result < 0) { 1211 if (ret)
1211 ret = -ENODEV;
1212 goto fail_acpi; 1212 goto fail_acpi;
1213 }
1214 1213
1215 /* Register platform stuff */ 1214 /* Register platform stuff */
1216 1215
1217 fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); 1216 fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
1218 if (!fujitsu->pf_device) { 1217 if (!fujitsu_bl->pf_device) {
1219 ret = -ENOMEM; 1218 ret = -ENOMEM;
1220 goto fail_platform_driver; 1219 goto fail_platform_driver;
1221 } 1220 }
1222 1221
1223 ret = platform_device_add(fujitsu->pf_device); 1222 ret = platform_device_add(fujitsu_bl->pf_device);
1224 if (ret) 1223 if (ret)
1225 goto fail_platform_device1; 1224 goto fail_platform_device1;
1226 1225
1227 ret = 1226 ret =
1228 sysfs_create_group(&fujitsu->pf_device->dev.kobj, 1227 sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
1229 &fujitsupf_attribute_group); 1228 &fujitsu_pf_attribute_group);
1230 if (ret) 1229 if (ret)
1231 goto fail_platform_device2; 1230 goto fail_platform_device2;
1232 1231
@@ -1236,90 +1235,88 @@ static int __init fujitsu_init(void)
1236 struct backlight_properties props; 1235 struct backlight_properties props;
1237 1236
1238 memset(&props, 0, sizeof(struct backlight_properties)); 1237 memset(&props, 0, sizeof(struct backlight_properties));
1239 max_brightness = fujitsu->max_brightness; 1238 max_brightness = fujitsu_bl->max_brightness;
1240 props.type = BACKLIGHT_PLATFORM; 1239 props.type = BACKLIGHT_PLATFORM;
1241 props.max_brightness = max_brightness - 1; 1240 props.max_brightness = max_brightness - 1;
1242 fujitsu->bl_device = backlight_device_register("fujitsu-laptop", 1241 fujitsu_bl->bl_device = backlight_device_register("fujitsu-laptop",
1243 NULL, NULL, 1242 NULL, NULL,
1244 &fujitsubl_ops, 1243 &fujitsu_bl_ops,
1245 &props); 1244 &props);
1246 if (IS_ERR(fujitsu->bl_device)) { 1245 if (IS_ERR(fujitsu_bl->bl_device)) {
1247 ret = PTR_ERR(fujitsu->bl_device); 1246 ret = PTR_ERR(fujitsu_bl->bl_device);
1248 fujitsu->bl_device = NULL; 1247 fujitsu_bl->bl_device = NULL;
1249 goto fail_sysfs_group; 1248 goto fail_sysfs_group;
1250 } 1249 }
1251 fujitsu->bl_device->props.brightness = fujitsu->brightness_level; 1250 fujitsu_bl->bl_device->props.brightness = fujitsu_bl->brightness_level;
1252 } 1251 }
1253 1252
1254 ret = platform_driver_register(&fujitsupf_driver); 1253 ret = platform_driver_register(&fujitsu_pf_driver);
1255 if (ret) 1254 if (ret)
1256 goto fail_backlight; 1255 goto fail_backlight;
1257 1256
1258 /* Register hotkey driver */ 1257 /* Register laptop driver */
1259 1258
1260 fujitsu_hotkey = kzalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL); 1259 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1261 if (!fujitsu_hotkey) { 1260 if (!fujitsu_laptop) {
1262 ret = -ENOMEM; 1261 ret = -ENOMEM;
1263 goto fail_hotkey; 1262 goto fail_laptop;
1264 } 1263 }
1265 1264
1266 result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver); 1265 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1267 if (result < 0) { 1266 if (ret)
1268 ret = -ENODEV; 1267 goto fail_laptop1;
1269 goto fail_hotkey1;
1270 }
1271 1268
1272 /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */ 1269 /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */
1273 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { 1270 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
1274 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3) 1271 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
1275 fujitsu->bl_device->props.power = FB_BLANK_POWERDOWN; 1272 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
1276 else 1273 else
1277 fujitsu->bl_device->props.power = FB_BLANK_UNBLANK; 1274 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
1278 } 1275 }
1279 1276
1280 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n"); 1277 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
1281 1278
1282 return 0; 1279 return 0;
1283 1280
1284fail_hotkey1: 1281fail_laptop1:
1285 kfree(fujitsu_hotkey); 1282 kfree(fujitsu_laptop);
1286fail_hotkey: 1283fail_laptop:
1287 platform_driver_unregister(&fujitsupf_driver); 1284 platform_driver_unregister(&fujitsu_pf_driver);
1288fail_backlight: 1285fail_backlight:
1289 backlight_device_unregister(fujitsu->bl_device); 1286 backlight_device_unregister(fujitsu_bl->bl_device);
1290fail_sysfs_group: 1287fail_sysfs_group:
1291 sysfs_remove_group(&fujitsu->pf_device->dev.kobj, 1288 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
1292 &fujitsupf_attribute_group); 1289 &fujitsu_pf_attribute_group);
1293fail_platform_device2: 1290fail_platform_device2:
1294 platform_device_del(fujitsu->pf_device); 1291 platform_device_del(fujitsu_bl->pf_device);
1295fail_platform_device1: 1292fail_platform_device1:
1296 platform_device_put(fujitsu->pf_device); 1293 platform_device_put(fujitsu_bl->pf_device);
1297fail_platform_driver: 1294fail_platform_driver:
1298 acpi_bus_unregister_driver(&acpi_fujitsu_driver); 1295 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
1299fail_acpi: 1296fail_acpi:
1300 kfree(fujitsu); 1297 kfree(fujitsu_bl);
1301 1298
1302 return ret; 1299 return ret;
1303} 1300}
1304 1301
1305static void __exit fujitsu_cleanup(void) 1302static void __exit fujitsu_cleanup(void)
1306{ 1303{
1307 acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver); 1304 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
1308 1305
1309 kfree(fujitsu_hotkey); 1306 kfree(fujitsu_laptop);
1310 1307
1311 platform_driver_unregister(&fujitsupf_driver); 1308 platform_driver_unregister(&fujitsu_pf_driver);
1312 1309
1313 backlight_device_unregister(fujitsu->bl_device); 1310 backlight_device_unregister(fujitsu_bl->bl_device);
1314 1311
1315 sysfs_remove_group(&fujitsu->pf_device->dev.kobj, 1312 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
1316 &fujitsupf_attribute_group); 1313 &fujitsu_pf_attribute_group);
1317 1314
1318 platform_device_unregister(fujitsu->pf_device); 1315 platform_device_unregister(fujitsu_bl->pf_device);
1319 1316
1320 acpi_bus_unregister_driver(&acpi_fujitsu_driver); 1317 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
1321 1318
1322 kfree(fujitsu); 1319 kfree(fujitsu_bl);
1323 1320
1324 pr_info("driver unloaded\n"); 1321 pr_info("driver unloaded\n");
1325} 1322}
@@ -1341,7 +1338,3 @@ MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
1341MODULE_DESCRIPTION("Fujitsu laptop extras support"); 1338MODULE_DESCRIPTION("Fujitsu laptop extras support");
1342MODULE_VERSION(FUJITSU_DRIVER_VERSION); 1339MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1343MODULE_LICENSE("GPL"); 1340MODULE_LICENSE("GPL");
1344
1345MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1346MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
1347MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 230043c1c90f..4bf55b5d78be 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1241,19 +1241,32 @@ config SCSI_LPFC
1241 tristate "Emulex LightPulse Fibre Channel Support" 1241 tristate "Emulex LightPulse Fibre Channel Support"
1242 depends on PCI && SCSI 1242 depends on PCI && SCSI
1243 depends on SCSI_FC_ATTRS 1243 depends on SCSI_FC_ATTRS
1244 depends on NVME_FC && NVME_TARGET_FC
1245 select CRC_T10DIF 1244 select CRC_T10DIF
1246 help 1245 ---help---
1247 This lpfc driver supports the Emulex LightPulse 1246 This lpfc driver supports the Emulex LightPulse
1248 Family of Fibre Channel PCI host adapters. 1247 Family of Fibre Channel PCI host adapters.
1249 1248
1250config SCSI_LPFC_DEBUG_FS 1249config SCSI_LPFC_DEBUG_FS
1251 bool "Emulex LightPulse Fibre Channel debugfs Support" 1250 bool "Emulex LightPulse Fibre Channel debugfs Support"
1252 depends on SCSI_LPFC && DEBUG_FS 1251 depends on SCSI_LPFC && DEBUG_FS
1253 help 1252 ---help---
1254 This makes debugging information from the lpfc driver 1253 This makes debugging information from the lpfc driver
1255 available via the debugfs filesystem. 1254 available via the debugfs filesystem.
1256 1255
1256config LPFC_NVME_INITIATOR
1257 bool "Emulex LightPulse Fibre Channel NVME Initiator Support"
1258 depends on SCSI_LPFC && NVME_FC
1259 ---help---
1260 This enables NVME Initiator support in the Emulex lpfc driver.
1261
1262config LPFC_NVME_TARGET
1263 bool "Emulex LightPulse Fibre Channel NVME Initiator Support"
1264 depends on SCSI_LPFC && NVME_TARGET_FC
1265 ---help---
1266 This enables NVME Target support in the Emulex lpfc driver.
1267 Target enablement must still be enabled on a per adapter
1268 basis by module parameters.
1269
1257config SCSI_SIM710 1270config SCSI_SIM710
1258 tristate "Simple 53c710 SCSI support (Compaq, NCR machines)" 1271 tristate "Simple 53c710 SCSI support (Compaq, NCR machines)"
1259 depends on (EISA || MCA) && SCSI 1272 depends on (EISA || MCA) && SCSI
diff --git a/drivers/scsi/aacraid/src.c b/drivers/scsi/aacraid/src.c
index 2e5338dec621..7b0410e0f569 100644
--- a/drivers/scsi/aacraid/src.c
+++ b/drivers/scsi/aacraid/src.c
@@ -468,7 +468,7 @@ err_out:
468 return -1; 468 return -1;
469 469
470err_blink: 470err_blink:
471 return (status > 16) & 0xFF; 471 return (status >> 16) & 0xFF;
472} 472}
473 473
474static inline u32 aac_get_vector(struct aac_dev *dev) 474static inline u32 aac_get_vector(struct aac_dev *dev)
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 07c08ce68d70..894b1e3ebd56 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -561,8 +561,12 @@ static void iscsi_complete_task(struct iscsi_task *task, int state)
561 WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); 561 WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
562 task->state = state; 562 task->state = state;
563 563
564 if (!list_empty(&task->running)) 564 spin_lock_bh(&conn->taskqueuelock);
565 if (!list_empty(&task->running)) {
566 pr_debug_once("%s while task on list", __func__);
565 list_del_init(&task->running); 567 list_del_init(&task->running);
568 }
569 spin_unlock_bh(&conn->taskqueuelock);
566 570
567 if (conn->task == task) 571 if (conn->task == task)
568 conn->task = NULL; 572 conn->task = NULL;
@@ -784,7 +788,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
784 if (session->tt->xmit_task(task)) 788 if (session->tt->xmit_task(task))
785 goto free_task; 789 goto free_task;
786 } else { 790 } else {
791 spin_lock_bh(&conn->taskqueuelock);
787 list_add_tail(&task->running, &conn->mgmtqueue); 792 list_add_tail(&task->running, &conn->mgmtqueue);
793 spin_unlock_bh(&conn->taskqueuelock);
788 iscsi_conn_queue_work(conn); 794 iscsi_conn_queue_work(conn);
789 } 795 }
790 796
@@ -1475,8 +1481,10 @@ void iscsi_requeue_task(struct iscsi_task *task)
1475 * this may be on the requeue list already if the xmit_task callout 1481 * this may be on the requeue list already if the xmit_task callout
1476 * is handling the r2ts while we are adding new ones 1482 * is handling the r2ts while we are adding new ones
1477 */ 1483 */
1484 spin_lock_bh(&conn->taskqueuelock);
1478 if (list_empty(&task->running)) 1485 if (list_empty(&task->running))
1479 list_add_tail(&task->running, &conn->requeue); 1486 list_add_tail(&task->running, &conn->requeue);
1487 spin_unlock_bh(&conn->taskqueuelock);
1480 iscsi_conn_queue_work(conn); 1488 iscsi_conn_queue_work(conn);
1481} 1489}
1482EXPORT_SYMBOL_GPL(iscsi_requeue_task); 1490EXPORT_SYMBOL_GPL(iscsi_requeue_task);
@@ -1513,22 +1521,26 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
1513 * only have one nop-out as a ping from us and targets should not 1521 * only have one nop-out as a ping from us and targets should not
1514 * overflow us with nop-ins 1522 * overflow us with nop-ins
1515 */ 1523 */
1524 spin_lock_bh(&conn->taskqueuelock);
1516check_mgmt: 1525check_mgmt:
1517 while (!list_empty(&conn->mgmtqueue)) { 1526 while (!list_empty(&conn->mgmtqueue)) {
1518 conn->task = list_entry(conn->mgmtqueue.next, 1527 conn->task = list_entry(conn->mgmtqueue.next,
1519 struct iscsi_task, running); 1528 struct iscsi_task, running);
1520 list_del_init(&conn->task->running); 1529 list_del_init(&conn->task->running);
1530 spin_unlock_bh(&conn->taskqueuelock);
1521 if (iscsi_prep_mgmt_task(conn, conn->task)) { 1531 if (iscsi_prep_mgmt_task(conn, conn->task)) {
1522 /* regular RX path uses back_lock */ 1532 /* regular RX path uses back_lock */
1523 spin_lock_bh(&conn->session->back_lock); 1533 spin_lock_bh(&conn->session->back_lock);
1524 __iscsi_put_task(conn->task); 1534 __iscsi_put_task(conn->task);
1525 spin_unlock_bh(&conn->session->back_lock); 1535 spin_unlock_bh(&conn->session->back_lock);
1526 conn->task = NULL; 1536 conn->task = NULL;
1537 spin_lock_bh(&conn->taskqueuelock);
1527 continue; 1538 continue;
1528 } 1539 }
1529 rc = iscsi_xmit_task(conn); 1540 rc = iscsi_xmit_task(conn);
1530 if (rc) 1541 if (rc)
1531 goto done; 1542 goto done;
1543 spin_lock_bh(&conn->taskqueuelock);
1532 } 1544 }
1533 1545
1534 /* process pending command queue */ 1546 /* process pending command queue */
@@ -1536,19 +1548,24 @@ check_mgmt:
1536 conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task, 1548 conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task,
1537 running); 1549 running);
1538 list_del_init(&conn->task->running); 1550 list_del_init(&conn->task->running);
1551 spin_unlock_bh(&conn->taskqueuelock);
1539 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) { 1552 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) {
1540 fail_scsi_task(conn->task, DID_IMM_RETRY); 1553 fail_scsi_task(conn->task, DID_IMM_RETRY);
1554 spin_lock_bh(&conn->taskqueuelock);
1541 continue; 1555 continue;
1542 } 1556 }
1543 rc = iscsi_prep_scsi_cmd_pdu(conn->task); 1557 rc = iscsi_prep_scsi_cmd_pdu(conn->task);
1544 if (rc) { 1558 if (rc) {
1545 if (rc == -ENOMEM || rc == -EACCES) { 1559 if (rc == -ENOMEM || rc == -EACCES) {
1560 spin_lock_bh(&conn->taskqueuelock);
1546 list_add_tail(&conn->task->running, 1561 list_add_tail(&conn->task->running,
1547 &conn->cmdqueue); 1562 &conn->cmdqueue);
1548 conn->task = NULL; 1563 conn->task = NULL;
1564 spin_unlock_bh(&conn->taskqueuelock);
1549 goto done; 1565 goto done;
1550 } else 1566 } else
1551 fail_scsi_task(conn->task, DID_ABORT); 1567 fail_scsi_task(conn->task, DID_ABORT);
1568 spin_lock_bh(&conn->taskqueuelock);
1552 continue; 1569 continue;
1553 } 1570 }
1554 rc = iscsi_xmit_task(conn); 1571 rc = iscsi_xmit_task(conn);
@@ -1559,6 +1576,7 @@ check_mgmt:
1559 * we need to check the mgmt queue for nops that need to 1576 * we need to check the mgmt queue for nops that need to
1560 * be sent to aviod starvation 1577 * be sent to aviod starvation
1561 */ 1578 */
1579 spin_lock_bh(&conn->taskqueuelock);
1562 if (!list_empty(&conn->mgmtqueue)) 1580 if (!list_empty(&conn->mgmtqueue))
1563 goto check_mgmt; 1581 goto check_mgmt;
1564 } 1582 }
@@ -1578,12 +1596,15 @@ check_mgmt:
1578 conn->task = task; 1596 conn->task = task;
1579 list_del_init(&conn->task->running); 1597 list_del_init(&conn->task->running);
1580 conn->task->state = ISCSI_TASK_RUNNING; 1598 conn->task->state = ISCSI_TASK_RUNNING;
1599 spin_unlock_bh(&conn->taskqueuelock);
1581 rc = iscsi_xmit_task(conn); 1600 rc = iscsi_xmit_task(conn);
1582 if (rc) 1601 if (rc)
1583 goto done; 1602 goto done;
1603 spin_lock_bh(&conn->taskqueuelock);
1584 if (!list_empty(&conn->mgmtqueue)) 1604 if (!list_empty(&conn->mgmtqueue))
1585 goto check_mgmt; 1605 goto check_mgmt;
1586 } 1606 }
1607 spin_unlock_bh(&conn->taskqueuelock);
1587 spin_unlock_bh(&conn->session->frwd_lock); 1608 spin_unlock_bh(&conn->session->frwd_lock);
1588 return -ENODATA; 1609 return -ENODATA;
1589 1610
@@ -1739,7 +1760,9 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
1739 goto prepd_reject; 1760 goto prepd_reject;
1740 } 1761 }
1741 } else { 1762 } else {
1763 spin_lock_bh(&conn->taskqueuelock);
1742 list_add_tail(&task->running, &conn->cmdqueue); 1764 list_add_tail(&task->running, &conn->cmdqueue);
1765 spin_unlock_bh(&conn->taskqueuelock);
1743 iscsi_conn_queue_work(conn); 1766 iscsi_conn_queue_work(conn);
1744 } 1767 }
1745 1768
@@ -2897,6 +2920,7 @@ iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
2897 INIT_LIST_HEAD(&conn->mgmtqueue); 2920 INIT_LIST_HEAD(&conn->mgmtqueue);
2898 INIT_LIST_HEAD(&conn->cmdqueue); 2921 INIT_LIST_HEAD(&conn->cmdqueue);
2899 INIT_LIST_HEAD(&conn->requeue); 2922 INIT_LIST_HEAD(&conn->requeue);
2923 spin_lock_init(&conn->taskqueuelock);
2900 INIT_WORK(&conn->xmitwork, iscsi_xmitworker); 2924 INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
2901 2925
2902 /* allocate login_task used for the login/text sequences */ 2926 /* allocate login_task used for the login/text sequences */
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 0bba2e30b4f0..257bbdd0f0b8 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -99,12 +99,13 @@ struct lpfc_sli2_slim;
99#define FC_MAX_ADPTMSG 64 99#define FC_MAX_ADPTMSG 64
100 100
101#define MAX_HBAEVT 32 101#define MAX_HBAEVT 32
102#define MAX_HBAS_NO_RESET 16
102 103
103/* Number of MSI-X vectors the driver uses */ 104/* Number of MSI-X vectors the driver uses */
104#define LPFC_MSIX_VECTORS 2 105#define LPFC_MSIX_VECTORS 2
105 106
106/* lpfc wait event data ready flag */ 107/* lpfc wait event data ready flag */
107#define LPFC_DATA_READY (1<<0) 108#define LPFC_DATA_READY 0 /* bit 0 */
108 109
109/* queue dump line buffer size */ 110/* queue dump line buffer size */
110#define LPFC_LBUF_SZ 128 111#define LPFC_LBUF_SZ 128
@@ -692,6 +693,7 @@ struct lpfc_hba {
692 * capability 693 * capability
693 */ 694 */
694#define HBA_NVME_IOQ_FLUSH 0x80000 /* NVME IO queues flushed. */ 695#define HBA_NVME_IOQ_FLUSH 0x80000 /* NVME IO queues flushed. */
696#define NVME_XRI_ABORT_EVENT 0x100000
695 697
696 uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/ 698 uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
697 struct lpfc_dmabuf slim2p; 699 struct lpfc_dmabuf slim2p;
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 5c783ef7f260..5c3be3e6f5e2 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -3010,6 +3010,12 @@ MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3010static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, 3010static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3011 lpfc_poll_show, lpfc_poll_store); 3011 lpfc_poll_show, lpfc_poll_store);
3012 3012
3013int lpfc_no_hba_reset_cnt;
3014unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3015 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3016module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3017MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3018
3013LPFC_ATTR(sli_mode, 0, 0, 3, 3019LPFC_ATTR(sli_mode, 0, 0, 3,
3014 "SLI mode selector:" 3020 "SLI mode selector:"
3015 " 0 - auto (SLI-3 if supported)," 3021 " 0 - auto (SLI-3 if supported),"
@@ -4451,7 +4457,8 @@ lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4451 return -EINVAL; 4457 return -EINVAL;
4452 4458
4453 phba->cfg_fcp_imax = (uint32_t)val; 4459 phba->cfg_fcp_imax = (uint32_t)val;
4454 for (i = 0; i < phba->io_channel_irqs; i++) 4460
4461 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4455 lpfc_modify_hba_eq_delay(phba, i); 4462 lpfc_modify_hba_eq_delay(phba, i);
4456 4463
4457 return strlen(buf); 4464 return strlen(buf);
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 843dd73004da..54e6ac42fbcd 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -384,7 +384,7 @@ void lpfc_free_sysfs_attr(struct lpfc_vport *);
384extern struct device_attribute *lpfc_hba_attrs[]; 384extern struct device_attribute *lpfc_hba_attrs[];
385extern struct device_attribute *lpfc_vport_attrs[]; 385extern struct device_attribute *lpfc_vport_attrs[];
386extern struct scsi_host_template lpfc_template; 386extern struct scsi_host_template lpfc_template;
387extern struct scsi_host_template lpfc_template_s3; 387extern struct scsi_host_template lpfc_template_no_hr;
388extern struct scsi_host_template lpfc_template_nvme; 388extern struct scsi_host_template lpfc_template_nvme;
389extern struct scsi_host_template lpfc_vport_template; 389extern struct scsi_host_template lpfc_vport_template;
390extern struct fc_function_template lpfc_transport_functions; 390extern struct fc_function_template lpfc_transport_functions;
@@ -554,3 +554,5 @@ void lpfc_nvme_abort_fcreq_cmpl(struct lpfc_hba *phba,
554 struct lpfc_wcqe_complete *abts_cmpl); 554 struct lpfc_wcqe_complete *abts_cmpl);
555extern int lpfc_enable_nvmet_cnt; 555extern int lpfc_enable_nvmet_cnt;
556extern unsigned long long lpfc_enable_nvmet[]; 556extern unsigned long long lpfc_enable_nvmet[];
557extern int lpfc_no_hba_reset_cnt;
558extern unsigned long lpfc_no_hba_reset[];
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index c22bb3f887e1..d3e9af983015 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -939,8 +939,8 @@ lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
939 "FC4 x%08x, Data: x%08x x%08x\n", 939 "FC4 x%08x, Data: x%08x x%08x\n",
940 ndlp, did, ndlp->nlp_fc4_type, 940 ndlp, did, ndlp->nlp_fc4_type,
941 FC_TYPE_FCP, FC_TYPE_NVME); 941 FC_TYPE_FCP, FC_TYPE_NVME);
942 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
942 } 943 }
943 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
944 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); 944 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
945 lpfc_issue_els_prli(vport, ndlp, 0); 945 lpfc_issue_els_prli(vport, ndlp, 0);
946 } else 946 } else
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index 9f4798e9d938..913eed822cb8 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -3653,17 +3653,6 @@ lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3653 idiag.ptr_private = phba->sli4_hba.nvmels_cq; 3653 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3654 goto pass_check; 3654 goto pass_check;
3655 } 3655 }
3656 /* NVME LS complete queue */
3657 if (phba->sli4_hba.nvmels_cq &&
3658 phba->sli4_hba.nvmels_cq->queue_id == queid) {
3659 /* Sanity check */
3660 rc = lpfc_idiag_que_param_check(
3661 phba->sli4_hba.nvmels_cq, index, count);
3662 if (rc)
3663 goto error_out;
3664 idiag.ptr_private = phba->sli4_hba.nvmels_cq;
3665 goto pass_check;
3666 }
3667 /* FCP complete queue */ 3656 /* FCP complete queue */
3668 if (phba->sli4_hba.fcp_cq) { 3657 if (phba->sli4_hba.fcp_cq) {
3669 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; 3658 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
@@ -3738,17 +3727,6 @@ lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
3738 idiag.ptr_private = phba->sli4_hba.nvmels_wq; 3727 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3739 goto pass_check; 3728 goto pass_check;
3740 } 3729 }
3741 /* NVME LS work queue */
3742 if (phba->sli4_hba.nvmels_wq &&
3743 phba->sli4_hba.nvmels_wq->queue_id == queid) {
3744 /* Sanity check */
3745 rc = lpfc_idiag_que_param_check(
3746 phba->sli4_hba.nvmels_wq, index, count);
3747 if (rc)
3748 goto error_out;
3749 idiag.ptr_private = phba->sli4_hba.nvmels_wq;
3750 goto pass_check;
3751 }
3752 /* FCP work queue */ 3730 /* FCP work queue */
3753 if (phba->sli4_hba.fcp_wq) { 3731 if (phba->sli4_hba.fcp_wq) {
3754 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; 3732 for (qidx = 0; qidx < phba->cfg_fcp_io_channel;
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 2d26440e6f2f..d9c61d030034 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -5177,15 +5177,15 @@ lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5177 5177
5178static uint32_t 5178static uint32_t
5179lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc, 5179lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5180 struct lpfc_hba *phba) 5180 struct lpfc_vport *vport)
5181{ 5181{
5182 5182
5183 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG); 5183 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5184 5184
5185 memcpy(desc->port_names.wwnn, phba->wwnn, 5185 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5186 sizeof(desc->port_names.wwnn)); 5186 sizeof(desc->port_names.wwnn));
5187 5187
5188 memcpy(desc->port_names.wwpn, phba->wwpn, 5188 memcpy(desc->port_names.wwpn, &vport->fc_portname,
5189 sizeof(desc->port_names.wwpn)); 5189 sizeof(desc->port_names.wwpn));
5190 5190
5191 desc->length = cpu_to_be32(sizeof(desc->port_names)); 5191 desc->length = cpu_to_be32(sizeof(desc->port_names));
@@ -5279,7 +5279,7 @@ lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5279 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *) 5279 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5280 (len + pcmd), &rdp_context->link_stat); 5280 (len + pcmd), &rdp_context->link_stat);
5281 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *) 5281 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5282 (len + pcmd), phba); 5282 (len + pcmd), vport);
5283 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *) 5283 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5284 (len + pcmd), vport, ndlp); 5284 (len + pcmd), vport, ndlp);
5285 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd), 5285 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
@@ -8371,11 +8371,17 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8371 spin_lock_irq(shost->host_lock); 8371 spin_lock_irq(shost->host_lock);
8372 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 8372 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8373 spin_unlock_irq(shost->host_lock); 8373 spin_unlock_irq(shost->host_lock);
8374 if (vport->port_type == LPFC_PHYSICAL_PORT 8374 if (mb->mbxStatus == MBX_NOT_FINISHED)
8375 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) 8375 break;
8376 lpfc_issue_init_vfi(vport); 8376 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8377 else 8377 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8378 if (phba->sli_rev == LPFC_SLI_REV4)
8379 lpfc_issue_init_vfi(vport);
8380 else
8381 lpfc_initial_flogi(vport);
8382 } else {
8378 lpfc_initial_fdisc(vport); 8383 lpfc_initial_fdisc(vport);
8384 }
8379 break; 8385 break;
8380 } 8386 }
8381 } else { 8387 } else {
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 194a14d5f8a9..180b072beef6 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -313,8 +313,7 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
313 ndlp->nlp_state, ndlp->nlp_rpi); 313 ndlp->nlp_state, ndlp->nlp_rpi);
314 } 314 }
315 315
316 if (!(vport->load_flag & FC_UNLOADING) && 316 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
317 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
318 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) && 317 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
319 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && 318 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
320 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) && 319 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
@@ -641,6 +640,8 @@ lpfc_work_done(struct lpfc_hba *phba)
641 lpfc_handle_rrq_active(phba); 640 lpfc_handle_rrq_active(phba);
642 if (phba->hba_flag & FCP_XRI_ABORT_EVENT) 641 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
643 lpfc_sli4_fcp_xri_abort_event_proc(phba); 642 lpfc_sli4_fcp_xri_abort_event_proc(phba);
643 if (phba->hba_flag & NVME_XRI_ABORT_EVENT)
644 lpfc_sli4_nvme_xri_abort_event_proc(phba);
644 if (phba->hba_flag & ELS_XRI_ABORT_EVENT) 645 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
645 lpfc_sli4_els_xri_abort_event_proc(phba); 646 lpfc_sli4_els_xri_abort_event_proc(phba);
646 if (phba->hba_flag & ASYNC_EVENT) 647 if (phba->hba_flag & ASYNC_EVENT)
@@ -2173,7 +2174,7 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2173 uint32_t boot_flag, addr_mode; 2174 uint32_t boot_flag, addr_mode;
2174 uint16_t fcf_index, next_fcf_index; 2175 uint16_t fcf_index, next_fcf_index;
2175 struct lpfc_fcf_rec *fcf_rec = NULL; 2176 struct lpfc_fcf_rec *fcf_rec = NULL;
2176 uint16_t vlan_id; 2177 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2177 bool select_new_fcf; 2178 bool select_new_fcf;
2178 int rc; 2179 int rc;
2179 2180
@@ -4020,9 +4021,11 @@ lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4020 rdata = rport->dd_data; 4021 rdata = rport->dd_data;
4021 /* break the link before dropping the ref */ 4022 /* break the link before dropping the ref */
4022 ndlp->rport = NULL; 4023 ndlp->rport = NULL;
4023 if (rdata && rdata->pnode == ndlp) 4024 if (rdata) {
4024 lpfc_nlp_put(ndlp); 4025 if (rdata->pnode == ndlp)
4025 rdata->pnode = NULL; 4026 lpfc_nlp_put(ndlp);
4027 rdata->pnode = NULL;
4028 }
4026 /* drop reference for earlier registeration */ 4029 /* drop reference for earlier registeration */
4027 put_device(&rport->dev); 4030 put_device(&rport->dev);
4028 } 4031 }
@@ -4344,9 +4347,8 @@ lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4344{ 4347{
4345 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); 4348 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4346 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp); 4349 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4347 init_timer(&ndlp->nlp_delayfunc); 4350 setup_timer(&ndlp->nlp_delayfunc, lpfc_els_retry_delay,
4348 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay; 4351 (unsigned long)ndlp);
4349 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4350 ndlp->nlp_DID = did; 4352 ndlp->nlp_DID = did;
4351 ndlp->vport = vport; 4353 ndlp->vport = vport;
4352 ndlp->phba = vport->phba; 4354 ndlp->phba = vport->phba;
@@ -4606,9 +4608,9 @@ lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4606 pring = qp->pring; 4608 pring = qp->pring;
4607 if (!pring) 4609 if (!pring)
4608 continue; 4610 continue;
4609 spin_lock_irq(&pring->ring_lock); 4611 spin_lock(&pring->ring_lock);
4610 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list); 4612 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
4611 spin_unlock_irq(&pring->ring_lock); 4613 spin_unlock(&pring->ring_lock);
4612 } 4614 }
4613 spin_unlock_irq(&phba->hbalock); 4615 spin_unlock_irq(&phba->hbalock);
4614} 4616}
diff --git a/drivers/scsi/lpfc/lpfc_hw4.h b/drivers/scsi/lpfc/lpfc_hw4.h
index cfdb068a3bfc..15277705cb6b 100644
--- a/drivers/scsi/lpfc/lpfc_hw4.h
+++ b/drivers/scsi/lpfc/lpfc_hw4.h
@@ -1001,7 +1001,7 @@ struct eq_delay_info {
1001 uint32_t phase; 1001 uint32_t phase;
1002 uint32_t delay_multi; 1002 uint32_t delay_multi;
1003}; 1003};
1004#define LPFC_MAX_EQ_DELAY 8 1004#define LPFC_MAX_EQ_DELAY_EQID_CNT 8
1005 1005
1006struct sgl_page_pairs { 1006struct sgl_page_pairs {
1007 uint32_t sgl_pg0_addr_lo; 1007 uint32_t sgl_pg0_addr_lo;
@@ -1070,7 +1070,7 @@ struct lpfc_mbx_modify_eq_delay {
1070 union { 1070 union {
1071 struct { 1071 struct {
1072 uint32_t num_eq; 1072 uint32_t num_eq;
1073 struct eq_delay_info eq[LPFC_MAX_EQ_DELAY]; 1073 struct eq_delay_info eq[LPFC_MAX_EQ_DELAY_EQID_CNT];
1074 } request; 1074 } request;
1075 struct { 1075 struct {
1076 uint32_t word0; 1076 uint32_t word0;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 0ee429d773f3..2697d49da4d7 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -3555,6 +3555,44 @@ out_free_mem:
3555 return rc; 3555 return rc;
3556} 3556}
3557 3557
3558static uint64_t
3559lpfc_get_wwpn(struct lpfc_hba *phba)
3560{
3561 uint64_t wwn;
3562 int rc;
3563 LPFC_MBOXQ_t *mboxq;
3564 MAILBOX_t *mb;
3565
3566
3567 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3568 GFP_KERNEL);
3569 if (!mboxq)
3570 return (uint64_t)-1;
3571
3572 /* First get WWN of HBA instance */
3573 lpfc_read_nv(phba, mboxq);
3574 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3575 if (rc != MBX_SUCCESS) {
3576 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3577 "6019 Mailbox failed , mbxCmd x%x "
3578 "READ_NV, mbxStatus x%x\n",
3579 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3580 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3581 mempool_free(mboxq, phba->mbox_mem_pool);
3582 return (uint64_t) -1;
3583 }
3584 mb = &mboxq->u.mb;
3585 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3586 /* wwn is WWPN of HBA instance */
3587 mempool_free(mboxq, phba->mbox_mem_pool);
3588 if (phba->sli_rev == LPFC_SLI_REV4)
3589 return be64_to_cpu(wwn);
3590 else
3591 return (((wwn & 0xffffffff00000000) >> 32) |
3592 ((wwn & 0x00000000ffffffff) << 32));
3593
3594}
3595
3558/** 3596/**
3559 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping 3597 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3560 * @phba: pointer to lpfc hba data structure. 3598 * @phba: pointer to lpfc hba data structure.
@@ -3676,17 +3714,32 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3676 struct lpfc_vport *vport; 3714 struct lpfc_vport *vport;
3677 struct Scsi_Host *shost = NULL; 3715 struct Scsi_Host *shost = NULL;
3678 int error = 0; 3716 int error = 0;
3717 int i;
3718 uint64_t wwn;
3719 bool use_no_reset_hba = false;
3720
3721 wwn = lpfc_get_wwpn(phba);
3722
3723 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3724 if (wwn == lpfc_no_hba_reset[i]) {
3725 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3726 "6020 Setting use_no_reset port=%llx\n",
3727 wwn);
3728 use_no_reset_hba = true;
3729 break;
3730 }
3731 }
3679 3732
3680 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { 3733 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3681 if (dev != &phba->pcidev->dev) { 3734 if (dev != &phba->pcidev->dev) {
3682 shost = scsi_host_alloc(&lpfc_vport_template, 3735 shost = scsi_host_alloc(&lpfc_vport_template,
3683 sizeof(struct lpfc_vport)); 3736 sizeof(struct lpfc_vport));
3684 } else { 3737 } else {
3685 if (phba->sli_rev == LPFC_SLI_REV4) 3738 if (!use_no_reset_hba)
3686 shost = scsi_host_alloc(&lpfc_template, 3739 shost = scsi_host_alloc(&lpfc_template,
3687 sizeof(struct lpfc_vport)); 3740 sizeof(struct lpfc_vport));
3688 else 3741 else
3689 shost = scsi_host_alloc(&lpfc_template_s3, 3742 shost = scsi_host_alloc(&lpfc_template_no_hr,
3690 sizeof(struct lpfc_vport)); 3743 sizeof(struct lpfc_vport));
3691 } 3744 }
3692 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { 3745 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
@@ -3734,17 +3787,14 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
3734 INIT_LIST_HEAD(&vport->rcv_buffer_list); 3787 INIT_LIST_HEAD(&vport->rcv_buffer_list);
3735 spin_lock_init(&vport->work_port_lock); 3788 spin_lock_init(&vport->work_port_lock);
3736 3789
3737 init_timer(&vport->fc_disctmo); 3790 setup_timer(&vport->fc_disctmo, lpfc_disc_timeout,
3738 vport->fc_disctmo.function = lpfc_disc_timeout; 3791 (unsigned long)vport);
3739 vport->fc_disctmo.data = (unsigned long)vport;
3740 3792
3741 init_timer(&vport->els_tmofunc); 3793 setup_timer(&vport->els_tmofunc, lpfc_els_timeout,
3742 vport->els_tmofunc.function = lpfc_els_timeout; 3794 (unsigned long)vport);
3743 vport->els_tmofunc.data = (unsigned long)vport;
3744 3795
3745 init_timer(&vport->delayed_disc_tmo); 3796 setup_timer(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo,
3746 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; 3797 (unsigned long)vport);
3747 vport->delayed_disc_tmo.data = (unsigned long)vport;
3748 3798
3749 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); 3799 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
3750 if (error) 3800 if (error)
@@ -5406,21 +5456,15 @@ lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5406 INIT_LIST_HEAD(&phba->luns); 5456 INIT_LIST_HEAD(&phba->luns);
5407 5457
5408 /* MBOX heartbeat timer */ 5458 /* MBOX heartbeat timer */
5409 init_timer(&psli->mbox_tmo); 5459 setup_timer(&psli->mbox_tmo, lpfc_mbox_timeout, (unsigned long)phba);
5410 psli->mbox_tmo.function = lpfc_mbox_timeout;
5411 psli->mbox_tmo.data = (unsigned long) phba;
5412 /* Fabric block timer */ 5460 /* Fabric block timer */
5413 init_timer(&phba->fabric_block_timer); 5461 setup_timer(&phba->fabric_block_timer, lpfc_fabric_block_timeout,
5414 phba->fabric_block_timer.function = lpfc_fabric_block_timeout; 5462 (unsigned long)phba);
5415 phba->fabric_block_timer.data = (unsigned long) phba;
5416 /* EA polling mode timer */ 5463 /* EA polling mode timer */
5417 init_timer(&phba->eratt_poll); 5464 setup_timer(&phba->eratt_poll, lpfc_poll_eratt,
5418 phba->eratt_poll.function = lpfc_poll_eratt; 5465 (unsigned long)phba);
5419 phba->eratt_poll.data = (unsigned long) phba;
5420 /* Heartbeat timer */ 5466 /* Heartbeat timer */
5421 init_timer(&phba->hb_tmofunc); 5467 setup_timer(&phba->hb_tmofunc, lpfc_hb_timeout, (unsigned long)phba);
5422 phba->hb_tmofunc.function = lpfc_hb_timeout;
5423 phba->hb_tmofunc.data = (unsigned long)phba;
5424 5468
5425 return 0; 5469 return 0;
5426} 5470}
@@ -5446,9 +5490,8 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5446 */ 5490 */
5447 5491
5448 /* FCP polling mode timer */ 5492 /* FCP polling mode timer */
5449 init_timer(&phba->fcp_poll_timer); 5493 setup_timer(&phba->fcp_poll_timer, lpfc_poll_timeout,
5450 phba->fcp_poll_timer.function = lpfc_poll_timeout; 5494 (unsigned long)phba);
5451 phba->fcp_poll_timer.data = (unsigned long) phba;
5452 5495
5453 /* Host attention work mask setup */ 5496 /* Host attention work mask setup */
5454 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); 5497 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
@@ -5482,7 +5525,8 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5482 5525
5483 /* Initialize the host templates the configured values. */ 5526 /* Initialize the host templates the configured values. */
5484 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; 5527 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5485 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt; 5528 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5529 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5486 5530
5487 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ 5531 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5488 if (phba->cfg_enable_bg) { 5532 if (phba->cfg_enable_bg) {
@@ -5617,14 +5661,11 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5617 * Initialize timers used by driver 5661 * Initialize timers used by driver
5618 */ 5662 */
5619 5663
5620 init_timer(&phba->rrq_tmr); 5664 setup_timer(&phba->rrq_tmr, lpfc_rrq_timeout, (unsigned long)phba);
5621 phba->rrq_tmr.function = lpfc_rrq_timeout;
5622 phba->rrq_tmr.data = (unsigned long)phba;
5623 5665
5624 /* FCF rediscover timer */ 5666 /* FCF rediscover timer */
5625 init_timer(&phba->fcf.redisc_wait); 5667 setup_timer(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo,
5626 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; 5668 (unsigned long)phba);
5627 phba->fcf.redisc_wait.data = (unsigned long)phba;
5628 5669
5629 /* 5670 /*
5630 * Control structure for handling external multi-buffer mailbox 5671 * Control structure for handling external multi-buffer mailbox
@@ -5706,6 +5747,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5706 /* Initialize the host templates with the updated values. */ 5747 /* Initialize the host templates with the updated values. */
5707 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; 5748 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5708 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; 5749 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5750 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5709 5751
5710 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) 5752 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5711 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; 5753 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
@@ -5736,6 +5778,8 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5736 /* Initialize the Abort nvme buffer list used by driver */ 5778 /* Initialize the Abort nvme buffer list used by driver */
5737 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock); 5779 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5738 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list); 5780 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5781 /* Fast-path XRI aborted CQ Event work queue list */
5782 INIT_LIST_HEAD(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue);
5739 } 5783 }
5740 5784
5741 /* This abort list used by worker thread */ 5785 /* This abort list used by worker thread */
@@ -8712,12 +8756,9 @@ lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8712 } 8756 }
8713 } 8757 }
8714 8758
8715 /* 8759 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
8716 * Configure EQ delay multipier for interrupt coalescing using
8717 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8718 */
8719 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY)
8720 lpfc_modify_hba_eq_delay(phba, qidx); 8760 lpfc_modify_hba_eq_delay(phba, qidx);
8761
8721 return 0; 8762 return 0;
8722 8763
8723out_destroy: 8764out_destroy:
@@ -8973,6 +9014,11 @@ lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8973 /* Pending ELS XRI abort events */ 9014 /* Pending ELS XRI abort events */
8974 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, 9015 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8975 &cqelist); 9016 &cqelist);
9017 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9018 /* Pending NVME XRI abort events */
9019 list_splice_init(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue,
9020 &cqelist);
9021 }
8976 /* Pending asynnc events */ 9022 /* Pending asynnc events */
8977 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, 9023 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8978 &cqelist); 9024 &cqelist);
@@ -10400,12 +10446,7 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
10400 fc_remove_host(shost); 10446 fc_remove_host(shost);
10401 scsi_remove_host(shost); 10447 scsi_remove_host(shost);
10402 10448
10403 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
10404 * localports are destroyed after to cleanup all transport memory.
10405 */
10406 lpfc_cleanup(vport); 10449 lpfc_cleanup(vport);
10407 lpfc_nvmet_destroy_targetport(phba);
10408 lpfc_nvme_destroy_localport(vport);
10409 10450
10410 /* 10451 /*
10411 * Bring down the SLI Layer. This step disable all interrupts, 10452 * Bring down the SLI Layer. This step disable all interrupts,
@@ -12018,6 +12059,7 @@ static struct pci_driver lpfc_driver = {
12018 .id_table = lpfc_id_table, 12059 .id_table = lpfc_id_table,
12019 .probe = lpfc_pci_probe_one, 12060 .probe = lpfc_pci_probe_one,
12020 .remove = lpfc_pci_remove_one, 12061 .remove = lpfc_pci_remove_one,
12062 .shutdown = lpfc_pci_remove_one,
12021 .suspend = lpfc_pci_suspend_one, 12063 .suspend = lpfc_pci_suspend_one,
12022 .resume = lpfc_pci_resume_one, 12064 .resume = lpfc_pci_resume_one,
12023 .err_handler = &lpfc_err_handler, 12065 .err_handler = &lpfc_err_handler,
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index c61d8d692ede..5986c7957199 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -646,7 +646,6 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
646 } 646 }
647 647
648 dma_buf->iocbq = lpfc_sli_get_iocbq(phba); 648 dma_buf->iocbq = lpfc_sli_get_iocbq(phba);
649 dma_buf->iocbq->iocb_flag = LPFC_IO_NVMET;
650 if (!dma_buf->iocbq) { 649 if (!dma_buf->iocbq) {
651 kfree(dma_buf->context); 650 kfree(dma_buf->context);
652 pci_pool_free(phba->lpfc_drb_pool, dma_buf->dbuf.virt, 651 pci_pool_free(phba->lpfc_drb_pool, dma_buf->dbuf.virt,
@@ -658,6 +657,7 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
658 "2621 Ran out of nvmet iocb/WQEs\n"); 657 "2621 Ran out of nvmet iocb/WQEs\n");
659 return NULL; 658 return NULL;
660 } 659 }
660 dma_buf->iocbq->iocb_flag = LPFC_IO_NVMET;
661 nvmewqe = dma_buf->iocbq; 661 nvmewqe = dma_buf->iocbq;
662 wqe = (union lpfc_wqe128 *)&nvmewqe->wqe; 662 wqe = (union lpfc_wqe128 *)&nvmewqe->wqe;
663 /* Initialize WQE */ 663 /* Initialize WQE */
diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
index 609a908ea9db..0a4c19081409 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.c
+++ b/drivers/scsi/lpfc/lpfc_nvme.c
@@ -316,7 +316,7 @@ lpfc_nvme_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
316 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0); 316 bf_set(wqe_dfctl, &wqe->gen_req.wge_ctl, 0);
317 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1); 317 bf_set(wqe_si, &wqe->gen_req.wge_ctl, 1);
318 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1); 318 bf_set(wqe_la, &wqe->gen_req.wge_ctl, 1);
319 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_DD_UNSOL_CTL); 319 bf_set(wqe_rctl, &wqe->gen_req.wge_ctl, FC_RCTL_ELS4_REQ);
320 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME); 320 bf_set(wqe_type, &wqe->gen_req.wge_ctl, FC_TYPE_NVME);
321 321
322 /* Word 6 */ 322 /* Word 6 */
@@ -620,15 +620,15 @@ lpfc_nvme_adj_fcp_sgls(struct lpfc_vport *vport,
620 * Embed the payload in the last half of the WQE 620 * Embed the payload in the last half of the WQE
621 * WQE words 16-30 get the NVME CMD IU payload 621 * WQE words 16-30 get the NVME CMD IU payload
622 * 622 *
623 * WQE Word 16 is already setup with flags 623 * WQE words 16-19 get payload Words 1-4
624 * WQE words 17-19 get payload Words 2-4
625 * WQE words 20-21 get payload Words 6-7 624 * WQE words 20-21 get payload Words 6-7
626 * WQE words 22-29 get payload Words 16-23 625 * WQE words 22-29 get payload Words 16-23
627 */ 626 */
628 wptr = &wqe->words[17]; /* WQE ptr */ 627 wptr = &wqe->words[16]; /* WQE ptr */
629 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */ 628 dptr = (uint32_t *)nCmd->cmdaddr; /* payload ptr */
630 dptr += 2; /* Skip Words 0-1 in payload */ 629 dptr++; /* Skip Word 0 in payload */
631 630
631 *wptr++ = *dptr++; /* Word 1 */
632 *wptr++ = *dptr++; /* Word 2 */ 632 *wptr++ = *dptr++; /* Word 2 */
633 *wptr++ = *dptr++; /* Word 3 */ 633 *wptr++ = *dptr++; /* Word 3 */
634 *wptr++ = *dptr++; /* Word 4 */ 634 *wptr++ = *dptr++; /* Word 4 */
@@ -978,9 +978,6 @@ lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
978 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 978 bf_set(wqe_cmd_type, &wqe->generic.wqe_com,
979 NVME_WRITE_CMD); 979 NVME_WRITE_CMD);
980 980
981 /* Word 16 */
982 wqe->words[16] = LPFC_NVME_EMBED_WRITE;
983
984 phba->fc4NvmeOutputRequests++; 981 phba->fc4NvmeOutputRequests++;
985 } else { 982 } else {
986 /* Word 7 */ 983 /* Word 7 */
@@ -1002,9 +999,6 @@ lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1002 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 999 bf_set(wqe_cmd_type, &wqe->generic.wqe_com,
1003 NVME_READ_CMD); 1000 NVME_READ_CMD);
1004 1001
1005 /* Word 16 */
1006 wqe->words[16] = LPFC_NVME_EMBED_READ;
1007
1008 phba->fc4NvmeInputRequests++; 1002 phba->fc4NvmeInputRequests++;
1009 } 1003 }
1010 } else { 1004 } else {
@@ -1026,9 +1020,6 @@ lpfc_nvme_prep_io_cmd(struct lpfc_vport *vport,
1026 /* Word 11 */ 1020 /* Word 11 */
1027 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, NVME_READ_CMD); 1021 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, NVME_READ_CMD);
1028 1022
1029 /* Word 16 */
1030 wqe->words[16] = LPFC_NVME_EMBED_CMD;
1031
1032 phba->fc4NvmeControlRequests++; 1023 phba->fc4NvmeControlRequests++;
1033 } 1024 }
1034 /* 1025 /*
@@ -1286,6 +1277,7 @@ lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1286 pnvme_fcreq->private = (void *)lpfc_ncmd; 1277 pnvme_fcreq->private = (void *)lpfc_ncmd;
1287 lpfc_ncmd->nvmeCmd = pnvme_fcreq; 1278 lpfc_ncmd->nvmeCmd = pnvme_fcreq;
1288 lpfc_ncmd->nrport = rport; 1279 lpfc_ncmd->nrport = rport;
1280 lpfc_ncmd->ndlp = ndlp;
1289 lpfc_ncmd->start_time = jiffies; 1281 lpfc_ncmd->start_time = jiffies;
1290 1282
1291 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp); 1283 lpfc_nvme_prep_io_cmd(vport, lpfc_ncmd, ndlp);
@@ -1319,7 +1311,7 @@ lpfc_nvme_fcp_io_submit(struct nvme_fc_local_port *pnvme_lport,
1319 "sid: x%x did: x%x oxid: x%x\n", 1311 "sid: x%x did: x%x oxid: x%x\n",
1320 ret, vport->fc_myDID, ndlp->nlp_DID, 1312 ret, vport->fc_myDID, ndlp->nlp_DID,
1321 lpfc_ncmd->cur_iocbq.sli4_xritag); 1313 lpfc_ncmd->cur_iocbq.sli4_xritag);
1322 ret = -EINVAL; 1314 ret = -EBUSY;
1323 goto out_free_nvme_buf; 1315 goto out_free_nvme_buf;
1324 } 1316 }
1325 1317
@@ -1821,10 +1813,10 @@ lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
1821 pdma_phys_sgl1, cur_xritag); 1813 pdma_phys_sgl1, cur_xritag);
1822 if (status) { 1814 if (status) {
1823 /* failure, put on abort nvme list */ 1815 /* failure, put on abort nvme list */
1824 lpfc_ncmd->exch_busy = 1; 1816 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1825 } else { 1817 } else {
1826 /* success, put on NVME buffer list */ 1818 /* success, put on NVME buffer list */
1827 lpfc_ncmd->exch_busy = 0; 1819 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1828 lpfc_ncmd->status = IOSTAT_SUCCESS; 1820 lpfc_ncmd->status = IOSTAT_SUCCESS;
1829 num_posted++; 1821 num_posted++;
1830 } 1822 }
@@ -1854,10 +1846,10 @@ lpfc_post_nvme_sgl_list(struct lpfc_hba *phba,
1854 struct lpfc_nvme_buf, list); 1846 struct lpfc_nvme_buf, list);
1855 if (status) { 1847 if (status) {
1856 /* failure, put on abort nvme list */ 1848 /* failure, put on abort nvme list */
1857 lpfc_ncmd->exch_busy = 1; 1849 lpfc_ncmd->flags |= LPFC_SBUF_XBUSY;
1858 } else { 1850 } else {
1859 /* success, put on NVME buffer list */ 1851 /* success, put on NVME buffer list */
1860 lpfc_ncmd->exch_busy = 0; 1852 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
1861 lpfc_ncmd->status = IOSTAT_SUCCESS; 1853 lpfc_ncmd->status = IOSTAT_SUCCESS;
1862 num_posted++; 1854 num_posted++;
1863 } 1855 }
@@ -2099,7 +2091,7 @@ lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2099 unsigned long iflag = 0; 2091 unsigned long iflag = 0;
2100 2092
2101 lpfc_ncmd->nonsg_phys = 0; 2093 lpfc_ncmd->nonsg_phys = 0;
2102 if (lpfc_ncmd->exch_busy) { 2094 if (lpfc_ncmd->flags & LPFC_SBUF_XBUSY) {
2103 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock, 2095 spin_lock_irqsave(&phba->sli4_hba.abts_nvme_buf_list_lock,
2104 iflag); 2096 iflag);
2105 lpfc_ncmd->nvmeCmd = NULL; 2097 lpfc_ncmd->nvmeCmd = NULL;
@@ -2135,11 +2127,12 @@ lpfc_release_nvme_buf(struct lpfc_hba *phba, struct lpfc_nvme_buf *lpfc_ncmd)
2135int 2127int
2136lpfc_nvme_create_localport(struct lpfc_vport *vport) 2128lpfc_nvme_create_localport(struct lpfc_vport *vport)
2137{ 2129{
2130 int ret = 0;
2138 struct lpfc_hba *phba = vport->phba; 2131 struct lpfc_hba *phba = vport->phba;
2139 struct nvme_fc_port_info nfcp_info; 2132 struct nvme_fc_port_info nfcp_info;
2140 struct nvme_fc_local_port *localport; 2133 struct nvme_fc_local_port *localport;
2141 struct lpfc_nvme_lport *lport; 2134 struct lpfc_nvme_lport *lport;
2142 int len, ret = 0; 2135 int len;
2143 2136
2144 /* Initialize this localport instance. The vport wwn usage ensures 2137 /* Initialize this localport instance. The vport wwn usage ensures
2145 * that NPIV is accounted for. 2138 * that NPIV is accounted for.
@@ -2156,8 +2149,12 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
2156 /* localport is allocated from the stack, but the registration 2149 /* localport is allocated from the stack, but the registration
2157 * call allocates heap memory as well as the private area. 2150 * call allocates heap memory as well as the private area.
2158 */ 2151 */
2152#ifdef CONFIG_LPFC_NVME_INITIATOR
2159 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template, 2153 ret = nvme_fc_register_localport(&nfcp_info, &lpfc_nvme_template,
2160 &vport->phba->pcidev->dev, &localport); 2154 &vport->phba->pcidev->dev, &localport);
2155#else
2156 ret = -ENOMEM;
2157#endif
2161 if (!ret) { 2158 if (!ret) {
2162 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC, 2159 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME | LOG_NVME_DISC,
2163 "6005 Successfully registered local " 2160 "6005 Successfully registered local "
@@ -2173,10 +2170,10 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
2173 lport->vport = vport; 2170 lport->vport = vport;
2174 INIT_LIST_HEAD(&lport->rport_list); 2171 INIT_LIST_HEAD(&lport->rport_list);
2175 vport->nvmei_support = 1; 2172 vport->nvmei_support = 1;
2173 len = lpfc_new_nvme_buf(vport, phba->sli4_hba.nvme_xri_max);
2174 vport->phba->total_nvme_bufs += len;
2176 } 2175 }
2177 2176
2178 len = lpfc_new_nvme_buf(vport, phba->sli4_hba.nvme_xri_max);
2179 vport->phba->total_nvme_bufs += len;
2180 return ret; 2177 return ret;
2181} 2178}
2182 2179
@@ -2193,6 +2190,7 @@ lpfc_nvme_create_localport(struct lpfc_vport *vport)
2193void 2190void
2194lpfc_nvme_destroy_localport(struct lpfc_vport *vport) 2191lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2195{ 2192{
2193#ifdef CONFIG_LPFC_NVME_INITIATOR
2196 struct nvme_fc_local_port *localport; 2194 struct nvme_fc_local_port *localport;
2197 struct lpfc_nvme_lport *lport; 2195 struct lpfc_nvme_lport *lport;
2198 struct lpfc_nvme_rport *rport = NULL, *rport_next = NULL; 2196 struct lpfc_nvme_rport *rport = NULL, *rport_next = NULL;
@@ -2208,7 +2206,6 @@ lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2208 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME, 2206 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME,
2209 "6011 Destroying NVME localport %p\n", 2207 "6011 Destroying NVME localport %p\n",
2210 localport); 2208 localport);
2211
2212 list_for_each_entry_safe(rport, rport_next, &lport->rport_list, list) { 2209 list_for_each_entry_safe(rport, rport_next, &lport->rport_list, list) {
2213 /* The last node ref has to get released now before the rport 2210 /* The last node ref has to get released now before the rport
2214 * private memory area is released by the transport. 2211 * private memory area is released by the transport.
@@ -2222,6 +2219,7 @@ lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2222 "6008 rport fail destroy %x\n", ret); 2219 "6008 rport fail destroy %x\n", ret);
2223 wait_for_completion_timeout(&rport->rport_unreg_done, 5); 2220 wait_for_completion_timeout(&rport->rport_unreg_done, 5);
2224 } 2221 }
2222
2225 /* lport's rport list is clear. Unregister 2223 /* lport's rport list is clear. Unregister
2226 * lport and release resources. 2224 * lport and release resources.
2227 */ 2225 */
@@ -2245,6 +2243,7 @@ lpfc_nvme_destroy_localport(struct lpfc_vport *vport)
2245 "Failed, status x%x\n", 2243 "Failed, status x%x\n",
2246 ret); 2244 ret);
2247 } 2245 }
2246#endif
2248} 2247}
2249 2248
2250void 2249void
@@ -2275,6 +2274,7 @@ lpfc_nvme_update_localport(struct lpfc_vport *vport)
2275int 2274int
2276lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 2275lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2277{ 2276{
2277#ifdef CONFIG_LPFC_NVME_INITIATOR
2278 int ret = 0; 2278 int ret = 0;
2279 struct nvme_fc_local_port *localport; 2279 struct nvme_fc_local_port *localport;
2280 struct lpfc_nvme_lport *lport; 2280 struct lpfc_nvme_lport *lport;
@@ -2348,7 +2348,6 @@ lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2348 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR; 2348 rpinfo.port_role |= FC_PORT_ROLE_NVME_INITIATOR;
2349 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); 2349 rpinfo.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2350 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); 2350 rpinfo.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2351
2352 ret = nvme_fc_register_remoteport(localport, &rpinfo, 2351 ret = nvme_fc_register_remoteport(localport, &rpinfo,
2353 &remote_port); 2352 &remote_port);
2354 if (!ret) { 2353 if (!ret) {
@@ -2384,6 +2383,9 @@ lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2384 ndlp->nlp_type, ndlp->nlp_DID, ndlp); 2383 ndlp->nlp_type, ndlp->nlp_DID, ndlp);
2385 } 2384 }
2386 return ret; 2385 return ret;
2386#else
2387 return 0;
2388#endif
2387} 2389}
2388 2390
2389/* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport. 2391/* lpfc_nvme_unregister_port - unbind the DID and port_role from this rport.
@@ -2401,6 +2403,7 @@ lpfc_nvme_register_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2401void 2403void
2402lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) 2404lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2403{ 2405{
2406#ifdef CONFIG_LPFC_NVME_INITIATOR
2404 int ret; 2407 int ret;
2405 struct nvme_fc_local_port *localport; 2408 struct nvme_fc_local_port *localport;
2406 struct lpfc_nvme_lport *lport; 2409 struct lpfc_nvme_lport *lport;
@@ -2458,7 +2461,61 @@ lpfc_nvme_unregister_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2458 return; 2461 return;
2459 2462
2460 input_err: 2463 input_err:
2464#endif
2461 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC, 2465 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME_DISC,
2462 "6168: State error: lport %p, rport%p FCID x%06x\n", 2466 "6168: State error: lport %p, rport%p FCID x%06x\n",
2463 vport->localport, ndlp->rport, ndlp->nlp_DID); 2467 vport->localport, ndlp->rport, ndlp->nlp_DID);
2464} 2468}
2469
2470/**
2471 * lpfc_sli4_nvme_xri_aborted - Fast-path process of NVME xri abort
2472 * @phba: pointer to lpfc hba data structure.
2473 * @axri: pointer to the fcp xri abort wcqe structure.
2474 *
2475 * This routine is invoked by the worker thread to process a SLI4 fast-path
2476 * FCP aborted xri.
2477 **/
2478void
2479lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
2480 struct sli4_wcqe_xri_aborted *axri)
2481{
2482 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
2483 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
2484 struct lpfc_nvme_buf *lpfc_ncmd, *next_lpfc_ncmd;
2485 struct lpfc_nodelist *ndlp;
2486 unsigned long iflag = 0;
2487 int rrq_empty = 0;
2488
2489 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
2490 return;
2491 spin_lock_irqsave(&phba->hbalock, iflag);
2492 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2493 list_for_each_entry_safe(lpfc_ncmd, next_lpfc_ncmd,
2494 &phba->sli4_hba.lpfc_abts_nvme_buf_list,
2495 list) {
2496 if (lpfc_ncmd->cur_iocbq.sli4_xritag == xri) {
2497 list_del(&lpfc_ncmd->list);
2498 lpfc_ncmd->flags &= ~LPFC_SBUF_XBUSY;
2499 lpfc_ncmd->status = IOSTAT_SUCCESS;
2500 spin_unlock(
2501 &phba->sli4_hba.abts_nvme_buf_list_lock);
2502
2503 rrq_empty = list_empty(&phba->active_rrq_list);
2504 spin_unlock_irqrestore(&phba->hbalock, iflag);
2505 ndlp = lpfc_ncmd->ndlp;
2506 if (ndlp) {
2507 lpfc_set_rrq_active(
2508 phba, ndlp,
2509 lpfc_ncmd->cur_iocbq.sli4_lxritag,
2510 rxid, 1);
2511 lpfc_sli4_abts_err_handler(phba, ndlp, axri);
2512 }
2513 lpfc_release_nvme_buf(phba, lpfc_ncmd);
2514 if (rrq_empty)
2515 lpfc_worker_wake_up(phba);
2516 return;
2517 }
2518 }
2519 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
2520 spin_unlock_irqrestore(&phba->hbalock, iflag);
2521}
diff --git a/drivers/scsi/lpfc/lpfc_nvme.h b/drivers/scsi/lpfc/lpfc_nvme.h
index b2fae5e813f8..1347deb8dd6c 100644
--- a/drivers/scsi/lpfc/lpfc_nvme.h
+++ b/drivers/scsi/lpfc/lpfc_nvme.h
@@ -57,6 +57,7 @@ struct lpfc_nvme_buf {
57 struct list_head list; 57 struct list_head list;
58 struct nvmefc_fcp_req *nvmeCmd; 58 struct nvmefc_fcp_req *nvmeCmd;
59 struct lpfc_nvme_rport *nrport; 59 struct lpfc_nvme_rport *nrport;
60 struct lpfc_nodelist *ndlp;
60 61
61 uint32_t timeout; 62 uint32_t timeout;
62 63
diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index c421e1738ee9..b7739a554fe0 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -571,6 +571,7 @@ lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport,
571 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 571 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
572 "6102 Bad state IO x%x aborted\n", 572 "6102 Bad state IO x%x aborted\n",
573 ctxp->oxid); 573 ctxp->oxid);
574 rc = -ENXIO;
574 goto aerr; 575 goto aerr;
575 } 576 }
576 577
@@ -580,6 +581,7 @@ lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport,
580 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 581 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
581 "6152 FCP Drop IO x%x: Prep\n", 582 "6152 FCP Drop IO x%x: Prep\n",
582 ctxp->oxid); 583 ctxp->oxid);
584 rc = -ENXIO;
583 goto aerr; 585 goto aerr;
584 } 586 }
585 587
@@ -618,8 +620,9 @@ lpfc_nvmet_xmt_fcp_op(struct nvmet_fc_target_port *tgtport,
618 ctxp->wqeq->hba_wqidx = 0; 620 ctxp->wqeq->hba_wqidx = 0;
619 nvmewqeq->context2 = NULL; 621 nvmewqeq->context2 = NULL;
620 nvmewqeq->context3 = NULL; 622 nvmewqeq->context3 = NULL;
623 rc = -EBUSY;
621aerr: 624aerr:
622 return -ENXIO; 625 return rc;
623} 626}
624 627
625static void 628static void
@@ -668,9 +671,13 @@ lpfc_nvmet_create_targetport(struct lpfc_hba *phba)
668 lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP | 671 lpfc_tgttemplate.target_features = NVMET_FCTGTFEAT_READDATA_RSP |
669 NVMET_FCTGTFEAT_NEEDS_CMD_CPUSCHED; 672 NVMET_FCTGTFEAT_NEEDS_CMD_CPUSCHED;
670 673
674#ifdef CONFIG_LPFC_NVME_TARGET
671 error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate, 675 error = nvmet_fc_register_targetport(&pinfo, &lpfc_tgttemplate,
672 &phba->pcidev->dev, 676 &phba->pcidev->dev,
673 &phba->targetport); 677 &phba->targetport);
678#else
679 error = -ENOMEM;
680#endif
674 if (error) { 681 if (error) {
675 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, 682 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
676 "6025 Cannot register NVME targetport " 683 "6025 Cannot register NVME targetport "
@@ -731,9 +738,25 @@ lpfc_nvmet_update_targetport(struct lpfc_hba *phba)
731 return 0; 738 return 0;
732} 739}
733 740
741/**
742 * lpfc_sli4_nvmet_xri_aborted - Fast-path process of nvmet xri abort
743 * @phba: pointer to lpfc hba data structure.
744 * @axri: pointer to the nvmet xri abort wcqe structure.
745 *
746 * This routine is invoked by the worker thread to process a SLI4 fast-path
747 * NVMET aborted xri.
748 **/
749void
750lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba,
751 struct sli4_wcqe_xri_aborted *axri)
752{
753 /* TODO: work in progress */
754}
755
734void 756void
735lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba) 757lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba)
736{ 758{
759#ifdef CONFIG_LPFC_NVME_TARGET
737 struct lpfc_nvmet_tgtport *tgtp; 760 struct lpfc_nvmet_tgtport *tgtp;
738 761
739 if (phba->nvmet_support == 0) 762 if (phba->nvmet_support == 0)
@@ -745,6 +768,7 @@ lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba)
745 wait_for_completion_timeout(&tgtp->tport_unreg_done, 5); 768 wait_for_completion_timeout(&tgtp->tport_unreg_done, 5);
746 } 769 }
747 phba->targetport = NULL; 770 phba->targetport = NULL;
771#endif
748} 772}
749 773
750/** 774/**
@@ -764,6 +788,7 @@ static void
764lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 788lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
765 struct hbq_dmabuf *nvmebuf) 789 struct hbq_dmabuf *nvmebuf)
766{ 790{
791#ifdef CONFIG_LPFC_NVME_TARGET
767 struct lpfc_nvmet_tgtport *tgtp; 792 struct lpfc_nvmet_tgtport *tgtp;
768 struct fc_frame_header *fc_hdr; 793 struct fc_frame_header *fc_hdr;
769 struct lpfc_nvmet_rcv_ctx *ctxp; 794 struct lpfc_nvmet_rcv_ctx *ctxp;
@@ -844,6 +869,7 @@ dropit:
844 869
845 atomic_inc(&tgtp->xmt_ls_abort); 870 atomic_inc(&tgtp->xmt_ls_abort);
846 lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid); 871 lpfc_nvmet_unsol_ls_issue_abort(phba, ctxp, sid, oxid);
872#endif
847} 873}
848 874
849/** 875/**
@@ -865,6 +891,7 @@ lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba,
865 struct rqb_dmabuf *nvmebuf, 891 struct rqb_dmabuf *nvmebuf,
866 uint64_t isr_timestamp) 892 uint64_t isr_timestamp)
867{ 893{
894#ifdef CONFIG_LPFC_NVME_TARGET
868 struct lpfc_nvmet_rcv_ctx *ctxp; 895 struct lpfc_nvmet_rcv_ctx *ctxp;
869 struct lpfc_nvmet_tgtport *tgtp; 896 struct lpfc_nvmet_tgtport *tgtp;
870 struct fc_frame_header *fc_hdr; 897 struct fc_frame_header *fc_hdr;
@@ -955,7 +982,7 @@ lpfc_nvmet_unsol_fcp_buffer(struct lpfc_hba *phba,
955 982
956 atomic_inc(&tgtp->rcv_fcp_cmd_drop); 983 atomic_inc(&tgtp->rcv_fcp_cmd_drop);
957 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, 984 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR,
958 "6159 FCP Drop IO x%x: nvmet_fc_rcv_fcp_req x%x\n", 985 "6159 FCP Drop IO x%x: err x%x\n",
959 ctxp->oxid, rc); 986 ctxp->oxid, rc);
960dropit: 987dropit:
961 lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n", 988 lpfc_nvmeio_data(phba, "NVMET FCP DROP: xri x%x sz %d from %06x\n",
@@ -970,6 +997,7 @@ dropit:
970 /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */ 997 /* We assume a rcv'ed cmd ALWAYs fits into 1 buffer */
971 lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf); 998 lpfc_nvmet_rq_post(phba, NULL, &nvmebuf->hbuf);
972 } 999 }
1000#endif
973} 1001}
974 1002
975/** 1003/**
@@ -1114,7 +1142,7 @@ lpfc_nvmet_prep_ls_wqe(struct lpfc_hba *phba,
1114 bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0); 1142 bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0);
1115 bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1); 1143 bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, 1);
1116 bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0); 1144 bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 0);
1117 bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_DD_SOL_CTL); 1145 bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, FC_RCTL_ELS4_REP);
1118 bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME); 1146 bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_NVME);
1119 1147
1120 /* Word 6 */ 1148 /* Word 6 */
@@ -1445,7 +1473,6 @@ lpfc_nvmet_prep_fcp_wqe(struct lpfc_hba *phba,
1445 1473
1446 case NVMET_FCOP_RSP: 1474 case NVMET_FCOP_RSP:
1447 /* Words 0 - 2 */ 1475 /* Words 0 - 2 */
1448 sgel = &rsp->sg[0];
1449 physaddr = rsp->rspdma; 1476 physaddr = rsp->rspdma;
1450 wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; 1477 wqe->fcp_trsp.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1451 wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen; 1478 wqe->fcp_trsp.bde.tus.f.bdeSize = rsp->rsplen;
@@ -1681,8 +1708,8 @@ lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba,
1681 struct lpfc_nodelist *ndlp; 1708 struct lpfc_nodelist *ndlp;
1682 1709
1683 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS, 1710 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_ABTS,
1684 "6067 %s: Entrypoint: sid %x xri %x\n", __func__, 1711 "6067 Abort: sid %x xri x%x/x%x\n",
1685 sid, xri); 1712 sid, xri, ctxp->wqeq->sli4_xritag);
1686 1713
1687 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; 1714 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
1688 1715
@@ -1693,7 +1720,7 @@ lpfc_nvmet_unsol_issue_abort(struct lpfc_hba *phba,
1693 atomic_inc(&tgtp->xmt_abort_rsp_error); 1720 atomic_inc(&tgtp->xmt_abort_rsp_error);
1694 lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1721 lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS,
1695 "6134 Drop ABTS - wrong NDLP state x%x.\n", 1722 "6134 Drop ABTS - wrong NDLP state x%x.\n",
1696 ndlp->nlp_state); 1723 (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE);
1697 1724
1698 /* No failure to an ABTS request. */ 1725 /* No failure to an ABTS request. */
1699 return 0; 1726 return 0;
@@ -1791,7 +1818,7 @@ lpfc_nvmet_sol_fcp_issue_abort(struct lpfc_hba *phba,
1791 atomic_inc(&tgtp->xmt_abort_rsp_error); 1818 atomic_inc(&tgtp->xmt_abort_rsp_error);
1792 lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS, 1819 lpfc_printf_log(phba, KERN_WARNING, LOG_NVME_ABTS,
1793 "6160 Drop ABTS - wrong NDLP state x%x.\n", 1820 "6160 Drop ABTS - wrong NDLP state x%x.\n",
1794 ndlp->nlp_state); 1821 (ndlp) ? ndlp->nlp_state : NLP_STE_MAX_STATE);
1795 1822
1796 /* No failure to an ABTS request. */ 1823 /* No failure to an ABTS request. */
1797 return 0; 1824 return 0;
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 9d6384af9fce..54fd0c81ceaf 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -5953,12 +5953,13 @@ struct scsi_host_template lpfc_template_nvme = {
5953 .track_queue_depth = 0, 5953 .track_queue_depth = 0,
5954}; 5954};
5955 5955
5956struct scsi_host_template lpfc_template_s3 = { 5956struct scsi_host_template lpfc_template_no_hr = {
5957 .module = THIS_MODULE, 5957 .module = THIS_MODULE,
5958 .name = LPFC_DRIVER_NAME, 5958 .name = LPFC_DRIVER_NAME,
5959 .proc_name = LPFC_DRIVER_NAME, 5959 .proc_name = LPFC_DRIVER_NAME,
5960 .info = lpfc_info, 5960 .info = lpfc_info,
5961 .queuecommand = lpfc_queuecommand, 5961 .queuecommand = lpfc_queuecommand,
5962 .eh_timed_out = fc_eh_timed_out,
5962 .eh_abort_handler = lpfc_abort_handler, 5963 .eh_abort_handler = lpfc_abort_handler,
5963 .eh_device_reset_handler = lpfc_device_reset_handler, 5964 .eh_device_reset_handler = lpfc_device_reset_handler,
5964 .eh_target_reset_handler = lpfc_target_reset_handler, 5965 .eh_target_reset_handler = lpfc_target_reset_handler,
@@ -6015,7 +6016,6 @@ struct scsi_host_template lpfc_vport_template = {
6015 .eh_abort_handler = lpfc_abort_handler, 6016 .eh_abort_handler = lpfc_abort_handler,
6016 .eh_device_reset_handler = lpfc_device_reset_handler, 6017 .eh_device_reset_handler = lpfc_device_reset_handler,
6017 .eh_target_reset_handler = lpfc_target_reset_handler, 6018 .eh_target_reset_handler = lpfc_target_reset_handler,
6018 .eh_bus_reset_handler = lpfc_bus_reset_handler,
6019 .slave_alloc = lpfc_slave_alloc, 6019 .slave_alloc = lpfc_slave_alloc,
6020 .slave_configure = lpfc_slave_configure, 6020 .slave_configure = lpfc_slave_configure,
6021 .slave_destroy = lpfc_slave_destroy, 6021 .slave_destroy = lpfc_slave_destroy,
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index e43e5e23c24b..1c9fa45df7eb 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -1,3 +1,4 @@
1
1/******************************************************************* 2/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 3 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 4 * Fibre Channel Host Bus Adapters. *
@@ -952,7 +953,7 @@ __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
952 start_sglq = sglq; 953 start_sglq = sglq;
953 while (!found) { 954 while (!found) {
954 if (!sglq) 955 if (!sglq)
955 return NULL; 956 break;
956 if (ndlp && ndlp->active_rrqs_xri_bitmap && 957 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
957 test_bit(sglq->sli4_lxritag, 958 test_bit(sglq->sli4_lxritag,
958 ndlp->active_rrqs_xri_bitmap)) { 959 ndlp->active_rrqs_xri_bitmap)) {
@@ -12213,6 +12214,41 @@ void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
12213} 12214}
12214 12215
12215/** 12216/**
12217 * lpfc_sli4_nvme_xri_abort_event_proc - Process nvme xri abort event
12218 * @phba: pointer to lpfc hba data structure.
12219 *
12220 * This routine is invoked by the worker thread to process all the pending
12221 * SLI4 NVME abort XRI events.
12222 **/
12223void lpfc_sli4_nvme_xri_abort_event_proc(struct lpfc_hba *phba)
12224{
12225 struct lpfc_cq_event *cq_event;
12226
12227 /* First, declare the fcp xri abort event has been handled */
12228 spin_lock_irq(&phba->hbalock);
12229 phba->hba_flag &= ~NVME_XRI_ABORT_EVENT;
12230 spin_unlock_irq(&phba->hbalock);
12231 /* Now, handle all the fcp xri abort events */
12232 while (!list_empty(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue)) {
12233 /* Get the first event from the head of the event queue */
12234 spin_lock_irq(&phba->hbalock);
12235 list_remove_head(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue,
12236 cq_event, struct lpfc_cq_event, list);
12237 spin_unlock_irq(&phba->hbalock);
12238 /* Notify aborted XRI for NVME work queue */
12239 if (phba->nvmet_support) {
12240 lpfc_sli4_nvmet_xri_aborted(phba,
12241 &cq_event->cqe.wcqe_axri);
12242 } else {
12243 lpfc_sli4_nvme_xri_aborted(phba,
12244 &cq_event->cqe.wcqe_axri);
12245 }
12246 /* Free the event processed back to the free pool */
12247 lpfc_sli4_cq_event_release(phba, cq_event);
12248 }
12249}
12250
12251/**
12216 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event 12252 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12217 * @phba: pointer to lpfc hba data structure. 12253 * @phba: pointer to lpfc hba data structure.
12218 * 12254 *
@@ -12709,10 +12745,22 @@ lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
12709 spin_unlock_irqrestore(&phba->hbalock, iflags); 12745 spin_unlock_irqrestore(&phba->hbalock, iflags);
12710 workposted = true; 12746 workposted = true;
12711 break; 12747 break;
12748 case LPFC_NVME:
12749 spin_lock_irqsave(&phba->hbalock, iflags);
12750 list_add_tail(&cq_event->list,
12751 &phba->sli4_hba.sp_nvme_xri_aborted_work_queue);
12752 /* Set the nvme xri abort event flag */
12753 phba->hba_flag |= NVME_XRI_ABORT_EVENT;
12754 spin_unlock_irqrestore(&phba->hbalock, iflags);
12755 workposted = true;
12756 break;
12712 default: 12757 default:
12713 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 12758 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12714 "0603 Invalid work queue CQE subtype (x%x)\n", 12759 "0603 Invalid CQ subtype %d: "
12715 cq->subtype); 12760 "%08x %08x %08x %08x\n",
12761 cq->subtype, wcqe->word0, wcqe->parameter,
12762 wcqe->word2, wcqe->word3);
12763 lpfc_sli4_cq_event_release(phba, cq_event);
12716 workposted = false; 12764 workposted = false;
12717 break; 12765 break;
12718 } 12766 }
@@ -13827,6 +13875,8 @@ lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
13827 * @startq: The starting FCP EQ to modify 13875 * @startq: The starting FCP EQ to modify
13828 * 13876 *
13829 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. 13877 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
13878 * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be
13879 * updated in one mailbox command.
13830 * 13880 *
13831 * The @phba struct is used to send mailbox command to HBA. The @startq 13881 * The @phba struct is used to send mailbox command to HBA. The @startq
13832 * is used to get the starting FCP EQ to change. 13882 * is used to get the starting FCP EQ to change.
@@ -13879,7 +13929,7 @@ lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq)
13879 eq_delay->u.request.eq[cnt].phase = 0; 13929 eq_delay->u.request.eq[cnt].phase = 0;
13880 eq_delay->u.request.eq[cnt].delay_multi = dmult; 13930 eq_delay->u.request.eq[cnt].delay_multi = dmult;
13881 cnt++; 13931 cnt++;
13882 if (cnt >= LPFC_MAX_EQ_DELAY) 13932 if (cnt >= LPFC_MAX_EQ_DELAY_EQID_CNT)
13883 break; 13933 break;
13884 } 13934 }
13885 eq_delay->u.request.num_eq = cnt; 13935 eq_delay->u.request.num_eq = cnt;
@@ -15185,17 +15235,17 @@ lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
15185 drq = drqp[idx]; 15235 drq = drqp[idx];
15186 cq = cqp[idx]; 15236 cq = cqp[idx];
15187 15237
15188 if (hrq->entry_count != drq->entry_count) {
15189 status = -EINVAL;
15190 goto out;
15191 }
15192
15193 /* sanity check on queue memory */ 15238 /* sanity check on queue memory */
15194 if (!hrq || !drq || !cq) { 15239 if (!hrq || !drq || !cq) {
15195 status = -ENODEV; 15240 status = -ENODEV;
15196 goto out; 15241 goto out;
15197 } 15242 }
15198 15243
15244 if (hrq->entry_count != drq->entry_count) {
15245 status = -EINVAL;
15246 goto out;
15247 }
15248
15199 if (idx == 0) { 15249 if (idx == 0) {
15200 bf_set(lpfc_mbx_rq_create_num_pages, 15250 bf_set(lpfc_mbx_rq_create_num_pages,
15201 &rq_create->u.request, 15251 &rq_create->u.request,
diff --git a/drivers/scsi/lpfc/lpfc_sli4.h b/drivers/scsi/lpfc/lpfc_sli4.h
index 91153c9f6d18..710458cf11d6 100644
--- a/drivers/scsi/lpfc/lpfc_sli4.h
+++ b/drivers/scsi/lpfc/lpfc_sli4.h
@@ -642,6 +642,7 @@ struct lpfc_sli4_hba {
642 struct list_head sp_asynce_work_queue; 642 struct list_head sp_asynce_work_queue;
643 struct list_head sp_fcp_xri_aborted_work_queue; 643 struct list_head sp_fcp_xri_aborted_work_queue;
644 struct list_head sp_els_xri_aborted_work_queue; 644 struct list_head sp_els_xri_aborted_work_queue;
645 struct list_head sp_nvme_xri_aborted_work_queue;
645 struct list_head sp_unsol_work_queue; 646 struct list_head sp_unsol_work_queue;
646 struct lpfc_sli4_link link_state; 647 struct lpfc_sli4_link link_state;
647 struct lpfc_sli4_lnk_info lnk_info; 648 struct lpfc_sli4_lnk_info lnk_info;
@@ -794,9 +795,14 @@ void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *);
794int lpfc_sli4_resume_rpi(struct lpfc_nodelist *, 795int lpfc_sli4_resume_rpi(struct lpfc_nodelist *,
795 void (*)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *); 796 void (*)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *);
796void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *); 797void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *);
798void lpfc_sli4_nvme_xri_abort_event_proc(struct lpfc_hba *phba);
797void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *); 799void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *);
798void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *, 800void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *,
799 struct sli4_wcqe_xri_aborted *); 801 struct sli4_wcqe_xri_aborted *);
802void lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
803 struct sli4_wcqe_xri_aborted *axri);
804void lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba,
805 struct sli4_wcqe_xri_aborted *axri);
800void lpfc_sli4_els_xri_aborted(struct lpfc_hba *, 806void lpfc_sli4_els_xri_aborted(struct lpfc_hba *,
801 struct sli4_wcqe_xri_aborted *); 807 struct sli4_wcqe_xri_aborted *);
802void lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *); 808void lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *);
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 86c6c9b26b82..d4e95e28f4e3 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -20,7 +20,7 @@
20 * included with this package. * 20 * included with this package. *
21 *******************************************************************/ 21 *******************************************************************/
22 22
23#define LPFC_DRIVER_VERSION "11.2.0.7" 23#define LPFC_DRIVER_VERSION "11.2.0.10"
24#define LPFC_DRIVER_NAME "lpfc" 24#define LPFC_DRIVER_NAME "lpfc"
25 25
26/* Used for SLI 2/3 */ 26/* Used for SLI 2/3 */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 7fe7e6ed595b..8981806fb13f 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1442,9 +1442,6 @@ void mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc,
1442 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate); 1442 u64 sas_address, u16 handle, u8 phy_number, u8 link_rate);
1443extern struct sas_function_template mpt3sas_transport_functions; 1443extern struct sas_function_template mpt3sas_transport_functions;
1444extern struct scsi_transport_template *mpt3sas_transport_template; 1444extern struct scsi_transport_template *mpt3sas_transport_template;
1445extern int scsi_internal_device_block(struct scsi_device *sdev);
1446extern int scsi_internal_device_unblock(struct scsi_device *sdev,
1447 enum scsi_device_state new_state);
1448/* trigger data externs */ 1445/* trigger data externs */
1449void mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc, 1446void mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
1450 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data); 1447 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 46e866c36c8a..919ba2bb15f1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -2859,7 +2859,7 @@ _scsih_internal_device_block(struct scsi_device *sdev,
2859 sas_device_priv_data->sas_target->handle); 2859 sas_device_priv_data->sas_target->handle);
2860 sas_device_priv_data->block = 1; 2860 sas_device_priv_data->block = 1;
2861 2861
2862 r = scsi_internal_device_block(sdev); 2862 r = scsi_internal_device_block(sdev, false);
2863 if (r == -EINVAL) 2863 if (r == -EINVAL)
2864 sdev_printk(KERN_WARNING, sdev, 2864 sdev_printk(KERN_WARNING, sdev,
2865 "device_block failed with return(%d) for handle(0x%04x)\n", 2865 "device_block failed with return(%d) for handle(0x%04x)\n",
@@ -2895,7 +2895,7 @@ _scsih_internal_device_unblock(struct scsi_device *sdev,
2895 "performing a block followed by an unblock\n", 2895 "performing a block followed by an unblock\n",
2896 r, sas_device_priv_data->sas_target->handle); 2896 r, sas_device_priv_data->sas_target->handle);
2897 sas_device_priv_data->block = 1; 2897 sas_device_priv_data->block = 1;
2898 r = scsi_internal_device_block(sdev); 2898 r = scsi_internal_device_block(sdev, false);
2899 if (r) 2899 if (r)
2900 sdev_printk(KERN_WARNING, sdev, "retried device_block " 2900 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2901 "failed with return(%d) for handle(0x%04x)\n", 2901 "failed with return(%d) for handle(0x%04x)\n",
@@ -4677,7 +4677,6 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4677 struct MPT3SAS_DEVICE *sas_device_priv_data; 4677 struct MPT3SAS_DEVICE *sas_device_priv_data;
4678 u32 response_code = 0; 4678 u32 response_code = 0;
4679 unsigned long flags; 4679 unsigned long flags;
4680 unsigned int sector_sz;
4681 4680
4682 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); 4681 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4683 4682
@@ -4742,20 +4741,6 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4742 } 4741 }
4743 4742
4744 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); 4743 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4745
4746 /* In case of bogus fw or device, we could end up having
4747 * unaligned partial completion. We can force alignment here,
4748 * then scsi-ml does not need to handle this misbehavior.
4749 */
4750 sector_sz = scmd->device->sector_size;
4751 if (unlikely(!blk_rq_is_passthrough(scmd->request) && sector_sz &&
4752 xfer_cnt % sector_sz)) {
4753 sdev_printk(KERN_INFO, scmd->device,
4754 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4755 xfer_cnt, sector_sz);
4756 xfer_cnt = round_down(xfer_cnt, sector_sz);
4757 }
4758
4759 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt); 4744 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4760 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) 4745 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4761 log_info = le32_to_cpu(mpi_reply->IOCLogInfo); 4746 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
diff --git a/drivers/scsi/qedf/qedf_dbg.h b/drivers/scsi/qedf/qedf_dbg.h
index 23bd70628a2f..7d173f48a81e 100644
--- a/drivers/scsi/qedf/qedf_dbg.h
+++ b/drivers/scsi/qedf/qedf_dbg.h
@@ -81,14 +81,17 @@ struct qedf_dbg_ctx {
81#define QEDF_INFO(pdev, level, fmt, ...) \ 81#define QEDF_INFO(pdev, level, fmt, ...) \
82 qedf_dbg_info(pdev, __func__, __LINE__, level, fmt, \ 82 qedf_dbg_info(pdev, __func__, __LINE__, level, fmt, \
83 ## __VA_ARGS__) 83 ## __VA_ARGS__)
84 84__printf(4, 5)
85extern void qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line, 85void qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
86 const char *fmt, ...); 86 const char *fmt, ...);
87extern void qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line, 87__printf(4, 5)
88void qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
88 const char *, ...); 89 const char *, ...);
89extern void qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, 90__printf(4, 5)
91void qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func,
90 u32 line, const char *, ...); 92 u32 line, const char *, ...);
91extern void qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line, 93__printf(5, 6)
94void qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line,
92 u32 info, const char *fmt, ...); 95 u32 info, const char *fmt, ...);
93 96
94/* GRC Dump related defines */ 97/* GRC Dump related defines */
diff --git a/drivers/scsi/qedf/qedf_fip.c b/drivers/scsi/qedf/qedf_fip.c
index 868d423380d1..ed58b9104f58 100644
--- a/drivers/scsi/qedf/qedf_fip.c
+++ b/drivers/scsi/qedf/qedf_fip.c
@@ -203,7 +203,7 @@ void qedf_fip_recv(struct qedf_ctx *qedf, struct sk_buff *skb)
203 case FIP_DT_MAC: 203 case FIP_DT_MAC:
204 mp = (struct fip_mac_desc *)desc; 204 mp = (struct fip_mac_desc *)desc;
205 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, 205 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2,
206 "fd_mac=%pM.\n", __func__, mp->fd_mac); 206 "fd_mac=%pM\n", mp->fd_mac);
207 ether_addr_copy(cvl_mac, mp->fd_mac); 207 ether_addr_copy(cvl_mac, mp->fd_mac);
208 break; 208 break;
209 case FIP_DT_NAME: 209 case FIP_DT_NAME:
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index ee0dcf9d3aba..46debe5034af 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -1342,7 +1342,7 @@ void qedf_scsi_completion(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
1342 } else { 1342 } else {
1343 refcount = kref_read(&io_req->refcount); 1343 refcount = kref_read(&io_req->refcount);
1344 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, 1344 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO,
1345 "%d:0:%d:%d xid=0x%0x op=0x%02x " 1345 "%d:0:%d:%lld xid=0x%0x op=0x%02x "
1346 "lba=%02x%02x%02x%02x cdb_status=%d " 1346 "lba=%02x%02x%02x%02x cdb_status=%d "
1347 "fcp_resid=0x%x refcount=%d.\n", 1347 "fcp_resid=0x%x refcount=%d.\n",
1348 qedf->lport->host->host_no, sc_cmd->device->id, 1348 qedf->lport->host->host_no, sc_cmd->device->id,
@@ -1426,7 +1426,7 @@ void qedf_scsi_done(struct qedf_ctx *qedf, struct qedf_ioreq *io_req,
1426 1426
1427 sc_cmd->result = result << 16; 1427 sc_cmd->result = result << 16;
1428 refcount = kref_read(&io_req->refcount); 1428 refcount = kref_read(&io_req->refcount);
1429 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "%d:0:%d:%d: Completing " 1429 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_IO, "%d:0:%d:%lld: Completing "
1430 "sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, " 1430 "sc_cmd=%p result=0x%08x op=0x%02x lba=0x%02x%02x%02x%02x, "
1431 "allowed=%d retries=%d refcount=%d.\n", 1431 "allowed=%d retries=%d refcount=%d.\n",
1432 qedf->lport->host->host_no, sc_cmd->device->id, 1432 qedf->lport->host->host_no, sc_cmd->device->id,
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index d9d7a86b5f8b..8e2a160490e6 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2456,8 +2456,8 @@ static int qedf_alloc_bdq(struct qedf_ctx *qedf)
2456 } 2456 }
2457 2457
2458 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, 2458 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC,
2459 "BDQ PBL addr=0x%p dma=0x%llx.\n", qedf->bdq_pbl, 2459 "BDQ PBL addr=0x%p dma=%pad\n",
2460 qedf->bdq_pbl_dma); 2460 qedf->bdq_pbl, &qedf->bdq_pbl_dma);
2461 2461
2462 /* 2462 /*
2463 * Populate BDQ PBL with physical and virtual address of individual 2463 * Populate BDQ PBL with physical and virtual address of individual
diff --git a/drivers/scsi/qedi/qedi_debugfs.c b/drivers/scsi/qedi/qedi_debugfs.c
index 955936274241..59417199bf36 100644
--- a/drivers/scsi/qedi/qedi_debugfs.c
+++ b/drivers/scsi/qedi/qedi_debugfs.c
@@ -14,7 +14,7 @@
14#include <linux/debugfs.h> 14#include <linux/debugfs.h>
15#include <linux/module.h> 15#include <linux/module.h>
16 16
17int do_not_recover; 17int qedi_do_not_recover;
18static struct dentry *qedi_dbg_root; 18static struct dentry *qedi_dbg_root;
19 19
20void 20void
@@ -74,22 +74,22 @@ qedi_dbg_exit(void)
74static ssize_t 74static ssize_t
75qedi_dbg_do_not_recover_enable(struct qedi_dbg_ctx *qedi_dbg) 75qedi_dbg_do_not_recover_enable(struct qedi_dbg_ctx *qedi_dbg)
76{ 76{
77 if (!do_not_recover) 77 if (!qedi_do_not_recover)
78 do_not_recover = 1; 78 qedi_do_not_recover = 1;
79 79
80 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n", 80 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n",
81 do_not_recover); 81 qedi_do_not_recover);
82 return 0; 82 return 0;
83} 83}
84 84
85static ssize_t 85static ssize_t
86qedi_dbg_do_not_recover_disable(struct qedi_dbg_ctx *qedi_dbg) 86qedi_dbg_do_not_recover_disable(struct qedi_dbg_ctx *qedi_dbg)
87{ 87{
88 if (do_not_recover) 88 if (qedi_do_not_recover)
89 do_not_recover = 0; 89 qedi_do_not_recover = 0;
90 90
91 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n", 91 QEDI_INFO(qedi_dbg, QEDI_LOG_DEBUGFS, "do_not_recover=%d\n",
92 do_not_recover); 92 qedi_do_not_recover);
93 return 0; 93 return 0;
94} 94}
95 95
@@ -141,7 +141,7 @@ qedi_dbg_do_not_recover_cmd_read(struct file *filp, char __user *buffer,
141 if (*ppos) 141 if (*ppos)
142 return 0; 142 return 0;
143 143
144 cnt = sprintf(buffer, "do_not_recover=%d\n", do_not_recover); 144 cnt = sprintf(buffer, "do_not_recover=%d\n", qedi_do_not_recover);
145 cnt = min_t(int, count, cnt - *ppos); 145 cnt = min_t(int, count, cnt - *ppos);
146 *ppos += cnt; 146 *ppos += cnt;
147 return cnt; 147 return cnt;
diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
index c9f0ef4e11b3..2bce3efc66a4 100644
--- a/drivers/scsi/qedi/qedi_fw.c
+++ b/drivers/scsi/qedi/qedi_fw.c
@@ -1461,9 +1461,9 @@ static void qedi_tmf_work(struct work_struct *work)
1461 get_itt(tmf_hdr->rtt), get_itt(ctask->itt), cmd->task_id, 1461 get_itt(tmf_hdr->rtt), get_itt(ctask->itt), cmd->task_id,
1462 qedi_conn->iscsi_conn_id); 1462 qedi_conn->iscsi_conn_id);
1463 1463
1464 if (do_not_recover) { 1464 if (qedi_do_not_recover) {
1465 QEDI_ERR(&qedi->dbg_ctx, "DONT SEND CLEANUP/ABORT %d\n", 1465 QEDI_ERR(&qedi->dbg_ctx, "DONT SEND CLEANUP/ABORT %d\n",
1466 do_not_recover); 1466 qedi_do_not_recover);
1467 goto abort_ret; 1467 goto abort_ret;
1468 } 1468 }
1469 1469
diff --git a/drivers/scsi/qedi/qedi_gbl.h b/drivers/scsi/qedi/qedi_gbl.h
index 8e488de88ece..63d793f46064 100644
--- a/drivers/scsi/qedi/qedi_gbl.h
+++ b/drivers/scsi/qedi/qedi_gbl.h
@@ -12,8 +12,14 @@
12 12
13#include "qedi_iscsi.h" 13#include "qedi_iscsi.h"
14 14
15#ifdef CONFIG_DEBUG_FS
16extern int qedi_do_not_recover;
17#else
18#define qedi_do_not_recover (0)
19#endif
20
15extern uint qedi_io_tracing; 21extern uint qedi_io_tracing;
16extern int do_not_recover; 22
17extern struct scsi_host_template qedi_host_template; 23extern struct scsi_host_template qedi_host_template;
18extern struct iscsi_transport qedi_iscsi_transport; 24extern struct iscsi_transport qedi_iscsi_transport;
19extern const struct qed_iscsi_ops *qedi_ops; 25extern const struct qed_iscsi_ops *qedi_ops;
diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c
index b9f79d36142d..4cc474364c50 100644
--- a/drivers/scsi/qedi/qedi_iscsi.c
+++ b/drivers/scsi/qedi/qedi_iscsi.c
@@ -833,7 +833,7 @@ qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
833 return ERR_PTR(ret); 833 return ERR_PTR(ret);
834 } 834 }
835 835
836 if (do_not_recover) { 836 if (qedi_do_not_recover) {
837 ret = -ENOMEM; 837 ret = -ENOMEM;
838 return ERR_PTR(ret); 838 return ERR_PTR(ret);
839 } 839 }
@@ -957,7 +957,7 @@ static int qedi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
957 struct qedi_endpoint *qedi_ep; 957 struct qedi_endpoint *qedi_ep;
958 int ret = 0; 958 int ret = 0;
959 959
960 if (do_not_recover) 960 if (qedi_do_not_recover)
961 return 1; 961 return 1;
962 962
963 qedi_ep = ep->dd_data; 963 qedi_ep = ep->dd_data;
@@ -1025,7 +1025,7 @@ static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1025 } 1025 }
1026 1026
1027 if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) { 1027 if (test_bit(QEDI_IN_RECOVERY, &qedi->flags)) {
1028 if (do_not_recover) { 1028 if (qedi_do_not_recover) {
1029 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO, 1029 QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_INFO,
1030 "Do not recover cid=0x%x\n", 1030 "Do not recover cid=0x%x\n",
1031 qedi_ep->iscsi_cid); 1031 qedi_ep->iscsi_cid);
@@ -1039,7 +1039,7 @@ static void qedi_ep_disconnect(struct iscsi_endpoint *ep)
1039 } 1039 }
1040 } 1040 }
1041 1041
1042 if (do_not_recover) 1042 if (qedi_do_not_recover)
1043 goto ep_exit_recover; 1043 goto ep_exit_recover;
1044 1044
1045 switch (qedi_ep->state) { 1045 switch (qedi_ep->state) {
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index 5eda21d903e9..8e3d92807cb8 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1805,7 +1805,7 @@ static int __qedi_probe(struct pci_dev *pdev, int mode)
1805 */ 1805 */
1806 qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params); 1806 qedi_ops->common->update_pf_params(qedi->cdev, &qedi->pf_params);
1807 1807
1808 qedi_setup_int(qedi); 1808 rc = qedi_setup_int(qedi);
1809 if (rc) 1809 if (rc)
1810 goto stop_iscsi_func; 1810 goto stop_iscsi_func;
1811 1811
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 21d9fb7fc887..51b4179469d1 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -2707,13 +2707,9 @@ ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2707 "%-+5d 0 1 2 3 4 5 6 7 8 9 A B C D E F\n", size); 2707 "%-+5d 0 1 2 3 4 5 6 7 8 9 A B C D E F\n", size);
2708 ql_dbg(level, vha, id, 2708 ql_dbg(level, vha, id,
2709 "----- -----------------------------------------------\n"); 2709 "----- -----------------------------------------------\n");
2710 for (cnt = 0; cnt < size; cnt++, buf++) { 2710 for (cnt = 0; cnt < size; cnt += 16) {
2711 if (cnt % 16 == 0) 2711 ql_dbg(level, vha, id, "%04x: ", cnt);
2712 ql_dbg(level, vha, id, "%04x:", cnt & ~0xFU); 2712 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1,
2713 printk(" %02x", *buf); 2713 buf + cnt, min(16U, size - cnt), false);
2714 if (cnt % 16 == 15)
2715 printk("\n");
2716 } 2714 }
2717 if (cnt % 16 != 0)
2718 printk("\n");
2719} 2715}
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ba2286652ff6..19125d72f322 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2932,6 +2932,8 @@ EXPORT_SYMBOL(scsi_target_resume);
2932/** 2932/**
2933 * scsi_internal_device_block - internal function to put a device temporarily into the SDEV_BLOCK state 2933 * scsi_internal_device_block - internal function to put a device temporarily into the SDEV_BLOCK state
2934 * @sdev: device to block 2934 * @sdev: device to block
2935 * @wait: Whether or not to wait until ongoing .queuecommand() /
2936 * .queue_rq() calls have finished.
2935 * 2937 *
2936 * Block request made by scsi lld's to temporarily stop all 2938 * Block request made by scsi lld's to temporarily stop all
2937 * scsi commands on the specified device. May sleep. 2939 * scsi commands on the specified device. May sleep.
@@ -2949,7 +2951,7 @@ EXPORT_SYMBOL(scsi_target_resume);
2949 * remove the rport mutex lock and unlock calls from srp_queuecommand(). 2951 * remove the rport mutex lock and unlock calls from srp_queuecommand().
2950 */ 2952 */
2951int 2953int
2952scsi_internal_device_block(struct scsi_device *sdev) 2954scsi_internal_device_block(struct scsi_device *sdev, bool wait)
2953{ 2955{
2954 struct request_queue *q = sdev->request_queue; 2956 struct request_queue *q = sdev->request_queue;
2955 unsigned long flags; 2957 unsigned long flags;
@@ -2969,12 +2971,16 @@ scsi_internal_device_block(struct scsi_device *sdev)
2969 * request queue. 2971 * request queue.
2970 */ 2972 */
2971 if (q->mq_ops) { 2973 if (q->mq_ops) {
2972 blk_mq_quiesce_queue(q); 2974 if (wait)
2975 blk_mq_quiesce_queue(q);
2976 else
2977 blk_mq_stop_hw_queues(q);
2973 } else { 2978 } else {
2974 spin_lock_irqsave(q->queue_lock, flags); 2979 spin_lock_irqsave(q->queue_lock, flags);
2975 blk_stop_queue(q); 2980 blk_stop_queue(q);
2976 spin_unlock_irqrestore(q->queue_lock, flags); 2981 spin_unlock_irqrestore(q->queue_lock, flags);
2977 scsi_wait_for_queuecommand(sdev); 2982 if (wait)
2983 scsi_wait_for_queuecommand(sdev);
2978 } 2984 }
2979 2985
2980 return 0; 2986 return 0;
@@ -3036,7 +3042,7 @@ EXPORT_SYMBOL_GPL(scsi_internal_device_unblock);
3036static void 3042static void
3037device_block(struct scsi_device *sdev, void *data) 3043device_block(struct scsi_device *sdev, void *data)
3038{ 3044{
3039 scsi_internal_device_block(sdev); 3045 scsi_internal_device_block(sdev, true);
3040} 3046}
3041 3047
3042static int 3048static int
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 99bfc985e190..f11bd102d6d5 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -188,8 +188,5 @@ static inline void scsi_dh_remove_device(struct scsi_device *sdev) { }
188 */ 188 */
189 189
190#define SCSI_DEVICE_BLOCK_MAX_TIMEOUT 600 /* units in seconds */ 190#define SCSI_DEVICE_BLOCK_MAX_TIMEOUT 600 /* units in seconds */
191extern int scsi_internal_device_block(struct scsi_device *sdev);
192extern int scsi_internal_device_unblock(struct scsi_device *sdev,
193 enum scsi_device_state new_state);
194 191
195#endif /* _SCSI_PRIV_H */ 192#endif /* _SCSI_PRIV_H */
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index d277e8620e3e..fcfeddc79331 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1783,6 +1783,8 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1783{ 1783{
1784 int result = SCpnt->result; 1784 int result = SCpnt->result;
1785 unsigned int good_bytes = result ? 0 : scsi_bufflen(SCpnt); 1785 unsigned int good_bytes = result ? 0 : scsi_bufflen(SCpnt);
1786 unsigned int sector_size = SCpnt->device->sector_size;
1787 unsigned int resid;
1786 struct scsi_sense_hdr sshdr; 1788 struct scsi_sense_hdr sshdr;
1787 struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk); 1789 struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk);
1788 struct request *req = SCpnt->request; 1790 struct request *req = SCpnt->request;
@@ -1813,6 +1815,21 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1813 scsi_set_resid(SCpnt, blk_rq_bytes(req)); 1815 scsi_set_resid(SCpnt, blk_rq_bytes(req));
1814 } 1816 }
1815 break; 1817 break;
1818 default:
1819 /*
1820 * In case of bogus fw or device, we could end up having
1821 * an unaligned partial completion. Check this here and force
1822 * alignment.
1823 */
1824 resid = scsi_get_resid(SCpnt);
1825 if (resid & (sector_size - 1)) {
1826 sd_printk(KERN_INFO, sdkp,
1827 "Unaligned partial completion (resid=%u, sector_sz=%u)\n",
1828 resid, sector_size);
1829 resid = min(scsi_bufflen(SCpnt),
1830 round_up(resid, sector_size));
1831 scsi_set_resid(SCpnt, resid);
1832 }
1816 } 1833 }
1817 1834
1818 if (result) { 1835 if (result) {
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 638e5f427c90..016639d7fef1 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -400,8 +400,6 @@ MODULE_PARM_DESC(storvsc_vcpus_per_sub_channel, "Ratio of VCPUs to subchannels")
400 */ 400 */
401static int storvsc_timeout = 180; 401static int storvsc_timeout = 180;
402 402
403static int msft_blist_flags = BLIST_TRY_VPD_PAGES;
404
405#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS) 403#if IS_ENABLED(CONFIG_SCSI_FC_ATTRS)
406static struct scsi_transport_template *fc_transport_template; 404static struct scsi_transport_template *fc_transport_template;
407#endif 405#endif
@@ -1383,6 +1381,22 @@ static int storvsc_do_io(struct hv_device *device,
1383 return ret; 1381 return ret;
1384} 1382}
1385 1383
1384static int storvsc_device_alloc(struct scsi_device *sdevice)
1385{
1386 /*
1387 * Set blist flag to permit the reading of the VPD pages even when
1388 * the target may claim SPC-2 compliance. MSFT targets currently
1389 * claim SPC-2 compliance while they implement post SPC-2 features.
1390 * With this flag we can correctly handle WRITE_SAME_16 issues.
1391 *
1392 * Hypervisor reports SCSI_UNKNOWN type for DVD ROM device but
1393 * still supports REPORT LUN.
1394 */
1395 sdevice->sdev_bflags = BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES;
1396
1397 return 0;
1398}
1399
1386static int storvsc_device_configure(struct scsi_device *sdevice) 1400static int storvsc_device_configure(struct scsi_device *sdevice)
1387{ 1401{
1388 1402
@@ -1396,14 +1410,6 @@ static int storvsc_device_configure(struct scsi_device *sdevice)
1396 sdevice->no_write_same = 1; 1410 sdevice->no_write_same = 1;
1397 1411
1398 /* 1412 /*
1399 * Add blist flags to permit the reading of the VPD pages even when
1400 * the target may claim SPC-2 compliance. MSFT targets currently
1401 * claim SPC-2 compliance while they implement post SPC-2 features.
1402 * With this patch we can correctly handle WRITE_SAME_16 issues.
1403 */
1404 sdevice->sdev_bflags |= msft_blist_flags;
1405
1406 /*
1407 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3 1413 * If the host is WIN8 or WIN8 R2, claim conformance to SPC-3
1408 * if the device is a MSFT virtual device. If the host is 1414 * if the device is a MSFT virtual device. If the host is
1409 * WIN10 or newer, allow write_same. 1415 * WIN10 or newer, allow write_same.
@@ -1661,6 +1667,7 @@ static struct scsi_host_template scsi_driver = {
1661 .eh_host_reset_handler = storvsc_host_reset_handler, 1667 .eh_host_reset_handler = storvsc_host_reset_handler,
1662 .proc_name = "storvsc_host", 1668 .proc_name = "storvsc_host",
1663 .eh_timed_out = storvsc_eh_timed_out, 1669 .eh_timed_out = storvsc_eh_timed_out,
1670 .slave_alloc = storvsc_device_alloc,
1664 .slave_configure = storvsc_device_configure, 1671 .slave_configure = storvsc_device_configure,
1665 .cmd_per_lun = 255, 1672 .cmd_per_lun = 255,
1666 .this_id = -1, 1673 .this_id = -1,
diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
index 318e4a1f76c9..54deeb754db5 100644
--- a/drivers/scsi/ufs/ufs.h
+++ b/drivers/scsi/ufs/ufs.h
@@ -146,7 +146,7 @@ enum attr_idn {
146/* Descriptor idn for Query requests */ 146/* Descriptor idn for Query requests */
147enum desc_idn { 147enum desc_idn {
148 QUERY_DESC_IDN_DEVICE = 0x0, 148 QUERY_DESC_IDN_DEVICE = 0x0,
149 QUERY_DESC_IDN_CONFIGURAION = 0x1, 149 QUERY_DESC_IDN_CONFIGURATION = 0x1,
150 QUERY_DESC_IDN_UNIT = 0x2, 150 QUERY_DESC_IDN_UNIT = 0x2,
151 QUERY_DESC_IDN_RFU_0 = 0x3, 151 QUERY_DESC_IDN_RFU_0 = 0x3,
152 QUERY_DESC_IDN_INTERCONNECT = 0x4, 152 QUERY_DESC_IDN_INTERCONNECT = 0x4,
@@ -162,19 +162,13 @@ enum desc_header_offset {
162 QUERY_DESC_DESC_TYPE_OFFSET = 0x01, 162 QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
163}; 163};
164 164
165enum ufs_desc_max_size { 165enum ufs_desc_def_size {
166 QUERY_DESC_DEVICE_MAX_SIZE = 0x40, 166 QUERY_DESC_DEVICE_DEF_SIZE = 0x40,
167 QUERY_DESC_CONFIGURAION_MAX_SIZE = 0x90, 167 QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90,
168 QUERY_DESC_UNIT_MAX_SIZE = 0x23, 168 QUERY_DESC_UNIT_DEF_SIZE = 0x23,
169 QUERY_DESC_INTERCONNECT_MAX_SIZE = 0x06, 169 QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06,
170 /* 170 QUERY_DESC_GEOMETRY_DEF_SIZE = 0x44,
171 * Max. 126 UNICODE characters (2 bytes per character) plus 2 bytes 171 QUERY_DESC_POWER_DEF_SIZE = 0x62,
172 * of descriptor header.
173 */
174 QUERY_DESC_STRING_MAX_SIZE = 0xFE,
175 QUERY_DESC_GEOMETRY_MAX_SIZE = 0x44,
176 QUERY_DESC_POWER_MAX_SIZE = 0x62,
177 QUERY_DESC_RFU_MAX_SIZE = 0x00,
178}; 172};
179 173
180/* Unit descriptor parameters offsets in bytes*/ 174/* Unit descriptor parameters offsets in bytes*/
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index dc6efbd1be8e..1359913bf840 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -100,19 +100,6 @@
100#define ufshcd_hex_dump(prefix_str, buf, len) \ 100#define ufshcd_hex_dump(prefix_str, buf, len) \
101print_hex_dump(KERN_ERR, prefix_str, DUMP_PREFIX_OFFSET, 16, 4, buf, len, false) 101print_hex_dump(KERN_ERR, prefix_str, DUMP_PREFIX_OFFSET, 16, 4, buf, len, false)
102 102
103static u32 ufs_query_desc_max_size[] = {
104 QUERY_DESC_DEVICE_MAX_SIZE,
105 QUERY_DESC_CONFIGURAION_MAX_SIZE,
106 QUERY_DESC_UNIT_MAX_SIZE,
107 QUERY_DESC_RFU_MAX_SIZE,
108 QUERY_DESC_INTERCONNECT_MAX_SIZE,
109 QUERY_DESC_STRING_MAX_SIZE,
110 QUERY_DESC_RFU_MAX_SIZE,
111 QUERY_DESC_GEOMETRY_MAX_SIZE,
112 QUERY_DESC_POWER_MAX_SIZE,
113 QUERY_DESC_RFU_MAX_SIZE,
114};
115
116enum { 103enum {
117 UFSHCD_MAX_CHANNEL = 0, 104 UFSHCD_MAX_CHANNEL = 0,
118 UFSHCD_MAX_ID = 1, 105 UFSHCD_MAX_ID = 1,
@@ -2857,7 +2844,7 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba,
2857 goto out; 2844 goto out;
2858 } 2845 }
2859 2846
2860 if (*buf_len <= QUERY_DESC_MIN_SIZE || *buf_len > QUERY_DESC_MAX_SIZE) { 2847 if (*buf_len < QUERY_DESC_MIN_SIZE || *buf_len > QUERY_DESC_MAX_SIZE) {
2861 dev_err(hba->dev, "%s: descriptor buffer size (%d) is out of range\n", 2848 dev_err(hba->dev, "%s: descriptor buffer size (%d) is out of range\n",
2862 __func__, *buf_len); 2849 __func__, *buf_len);
2863 err = -EINVAL; 2850 err = -EINVAL;
@@ -2938,6 +2925,92 @@ static int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
2938} 2925}
2939 2926
2940/** 2927/**
2928 * ufshcd_read_desc_length - read the specified descriptor length from header
2929 * @hba: Pointer to adapter instance
2930 * @desc_id: descriptor idn value
2931 * @desc_index: descriptor index
2932 * @desc_length: pointer to variable to read the length of descriptor
2933 *
2934 * Return 0 in case of success, non-zero otherwise
2935 */
2936static int ufshcd_read_desc_length(struct ufs_hba *hba,
2937 enum desc_idn desc_id,
2938 int desc_index,
2939 int *desc_length)
2940{
2941 int ret;
2942 u8 header[QUERY_DESC_HDR_SIZE];
2943 int header_len = QUERY_DESC_HDR_SIZE;
2944
2945 if (desc_id >= QUERY_DESC_IDN_MAX)
2946 return -EINVAL;
2947
2948 ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC,
2949 desc_id, desc_index, 0, header,
2950 &header_len);
2951
2952 if (ret) {
2953 dev_err(hba->dev, "%s: Failed to get descriptor header id %d",
2954 __func__, desc_id);
2955 return ret;
2956 } else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET]) {
2957 dev_warn(hba->dev, "%s: descriptor header id %d and desc_id %d mismatch",
2958 __func__, header[QUERY_DESC_DESC_TYPE_OFFSET],
2959 desc_id);
2960 ret = -EINVAL;
2961 }
2962
2963 *desc_length = header[QUERY_DESC_LENGTH_OFFSET];
2964 return ret;
2965
2966}
2967
2968/**
2969 * ufshcd_map_desc_id_to_length - map descriptor IDN to its length
2970 * @hba: Pointer to adapter instance
2971 * @desc_id: descriptor idn value
2972 * @desc_len: mapped desc length (out)
2973 *
2974 * Return 0 in case of success, non-zero otherwise
2975 */
2976int ufshcd_map_desc_id_to_length(struct ufs_hba *hba,
2977 enum desc_idn desc_id, int *desc_len)
2978{
2979 switch (desc_id) {
2980 case QUERY_DESC_IDN_DEVICE:
2981 *desc_len = hba->desc_size.dev_desc;
2982 break;
2983 case QUERY_DESC_IDN_POWER:
2984 *desc_len = hba->desc_size.pwr_desc;
2985 break;
2986 case QUERY_DESC_IDN_GEOMETRY:
2987 *desc_len = hba->desc_size.geom_desc;
2988 break;
2989 case QUERY_DESC_IDN_CONFIGURATION:
2990 *desc_len = hba->desc_size.conf_desc;
2991 break;
2992 case QUERY_DESC_IDN_UNIT:
2993 *desc_len = hba->desc_size.unit_desc;
2994 break;
2995 case QUERY_DESC_IDN_INTERCONNECT:
2996 *desc_len = hba->desc_size.interc_desc;
2997 break;
2998 case QUERY_DESC_IDN_STRING:
2999 *desc_len = QUERY_DESC_MAX_SIZE;
3000 break;
3001 case QUERY_DESC_IDN_RFU_0:
3002 case QUERY_DESC_IDN_RFU_1:
3003 *desc_len = 0;
3004 break;
3005 default:
3006 *desc_len = 0;
3007 return -EINVAL;
3008 }
3009 return 0;
3010}
3011EXPORT_SYMBOL(ufshcd_map_desc_id_to_length);
3012
3013/**
2941 * ufshcd_read_desc_param - read the specified descriptor parameter 3014 * ufshcd_read_desc_param - read the specified descriptor parameter
2942 * @hba: Pointer to adapter instance 3015 * @hba: Pointer to adapter instance
2943 * @desc_id: descriptor idn value 3016 * @desc_id: descriptor idn value
@@ -2951,42 +3024,49 @@ static int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
2951static int ufshcd_read_desc_param(struct ufs_hba *hba, 3024static int ufshcd_read_desc_param(struct ufs_hba *hba,
2952 enum desc_idn desc_id, 3025 enum desc_idn desc_id,
2953 int desc_index, 3026 int desc_index,
2954 u32 param_offset, 3027 u8 param_offset,
2955 u8 *param_read_buf, 3028 u8 *param_read_buf,
2956 u32 param_size) 3029 u8 param_size)
2957{ 3030{
2958 int ret; 3031 int ret;
2959 u8 *desc_buf; 3032 u8 *desc_buf;
2960 u32 buff_len; 3033 int buff_len;
2961 bool is_kmalloc = true; 3034 bool is_kmalloc = true;
2962 3035
2963 /* safety checks */ 3036 /* Safety check */
2964 if (desc_id >= QUERY_DESC_IDN_MAX) 3037 if (desc_id >= QUERY_DESC_IDN_MAX || !param_size)
2965 return -EINVAL; 3038 return -EINVAL;
2966 3039
2967 buff_len = ufs_query_desc_max_size[desc_id]; 3040 /* Get the max length of descriptor from structure filled up at probe
2968 if ((param_offset + param_size) > buff_len) 3041 * time.
2969 return -EINVAL; 3042 */
3043 ret = ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len);
2970 3044
2971 if (!param_offset && (param_size == buff_len)) { 3045 /* Sanity checks */
2972 /* memory space already available to hold full descriptor */ 3046 if (ret || !buff_len) {
2973 desc_buf = param_read_buf; 3047 dev_err(hba->dev, "%s: Failed to get full descriptor length",
2974 is_kmalloc = false; 3048 __func__);
2975 } else { 3049 return ret;
2976 /* allocate memory to hold full descriptor */ 3050 }
3051
3052 /* Check whether we need temp memory */
3053 if (param_offset != 0 || param_size < buff_len) {
2977 desc_buf = kmalloc(buff_len, GFP_KERNEL); 3054 desc_buf = kmalloc(buff_len, GFP_KERNEL);
2978 if (!desc_buf) 3055 if (!desc_buf)
2979 return -ENOMEM; 3056 return -ENOMEM;
3057 } else {
3058 desc_buf = param_read_buf;
3059 is_kmalloc = false;
2980 } 3060 }
2981 3061
3062 /* Request for full descriptor */
2982 ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, 3063 ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC,
2983 desc_id, desc_index, 0, desc_buf, 3064 desc_id, desc_index, 0,
2984 &buff_len); 3065 desc_buf, &buff_len);
2985 3066
2986 if (ret) { 3067 if (ret) {
2987 dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d", 3068 dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d",
2988 __func__, desc_id, desc_index, param_offset, ret); 3069 __func__, desc_id, desc_index, param_offset, ret);
2989
2990 goto out; 3070 goto out;
2991 } 3071 }
2992 3072
@@ -2998,25 +3078,9 @@ static int ufshcd_read_desc_param(struct ufs_hba *hba,
2998 goto out; 3078 goto out;
2999 } 3079 }
3000 3080
3001 /* 3081 /* Check wherher we will not copy more data, than available */
3002 * While reading variable size descriptors (like string descriptor), 3082 if (is_kmalloc && param_size > buff_len)
3003 * some UFS devices may report the "LENGTH" (field in "Transaction 3083 param_size = buff_len;
3004 * Specific fields" of Query Response UPIU) same as what was requested
3005 * in Query Request UPIU instead of reporting the actual size of the
3006 * variable size descriptor.
3007 * Although it's safe to ignore the "LENGTH" field for variable size
3008 * descriptors as we can always derive the length of the descriptor from
3009 * the descriptor header fields. Hence this change impose the length
3010 * match check only for fixed size descriptors (for which we always
3011 * request the correct size as part of Query Request UPIU).
3012 */
3013 if ((desc_id != QUERY_DESC_IDN_STRING) &&
3014 (buff_len != desc_buf[QUERY_DESC_LENGTH_OFFSET])) {
3015 dev_err(hba->dev, "%s: desc_buf length mismatch: buff_len %d, buff_len(desc_header) %d",
3016 __func__, buff_len, desc_buf[QUERY_DESC_LENGTH_OFFSET]);
3017 ret = -EINVAL;
3018 goto out;
3019 }
3020 3084
3021 if (is_kmalloc) 3085 if (is_kmalloc)
3022 memcpy(param_read_buf, &desc_buf[param_offset], param_size); 3086 memcpy(param_read_buf, &desc_buf[param_offset], param_size);
@@ -5919,8 +5983,8 @@ static int ufshcd_set_icc_levels_attr(struct ufs_hba *hba, u32 icc_level)
5919static void ufshcd_init_icc_levels(struct ufs_hba *hba) 5983static void ufshcd_init_icc_levels(struct ufs_hba *hba)
5920{ 5984{
5921 int ret; 5985 int ret;
5922 int buff_len = QUERY_DESC_POWER_MAX_SIZE; 5986 int buff_len = hba->desc_size.pwr_desc;
5923 u8 desc_buf[QUERY_DESC_POWER_MAX_SIZE]; 5987 u8 desc_buf[hba->desc_size.pwr_desc];
5924 5988
5925 ret = ufshcd_read_power_desc(hba, desc_buf, buff_len); 5989 ret = ufshcd_read_power_desc(hba, desc_buf, buff_len);
5926 if (ret) { 5990 if (ret) {
@@ -6017,11 +6081,10 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
6017{ 6081{
6018 int err; 6082 int err;
6019 u8 model_index; 6083 u8 model_index;
6020 u8 str_desc_buf[QUERY_DESC_STRING_MAX_SIZE + 1] = {0}; 6084 u8 str_desc_buf[QUERY_DESC_MAX_SIZE + 1] = {0};
6021 u8 desc_buf[QUERY_DESC_DEVICE_MAX_SIZE]; 6085 u8 desc_buf[hba->desc_size.dev_desc];
6022 6086
6023 err = ufshcd_read_device_desc(hba, desc_buf, 6087 err = ufshcd_read_device_desc(hba, desc_buf, hba->desc_size.dev_desc);
6024 QUERY_DESC_DEVICE_MAX_SIZE);
6025 if (err) { 6088 if (err) {
6026 dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", 6089 dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n",
6027 __func__, err); 6090 __func__, err);
@@ -6038,14 +6101,14 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
6038 model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME]; 6101 model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
6039 6102
6040 err = ufshcd_read_string_desc(hba, model_index, str_desc_buf, 6103 err = ufshcd_read_string_desc(hba, model_index, str_desc_buf,
6041 QUERY_DESC_STRING_MAX_SIZE, ASCII_STD); 6104 QUERY_DESC_MAX_SIZE, ASCII_STD);
6042 if (err) { 6105 if (err) {
6043 dev_err(hba->dev, "%s: Failed reading Product Name. err = %d\n", 6106 dev_err(hba->dev, "%s: Failed reading Product Name. err = %d\n",
6044 __func__, err); 6107 __func__, err);
6045 goto out; 6108 goto out;
6046 } 6109 }
6047 6110
6048 str_desc_buf[QUERY_DESC_STRING_MAX_SIZE] = '\0'; 6111 str_desc_buf[QUERY_DESC_MAX_SIZE] = '\0';
6049 strlcpy(dev_desc->model, (str_desc_buf + QUERY_DESC_HDR_SIZE), 6112 strlcpy(dev_desc->model, (str_desc_buf + QUERY_DESC_HDR_SIZE),
6050 min_t(u8, str_desc_buf[QUERY_DESC_LENGTH_OFFSET], 6113 min_t(u8, str_desc_buf[QUERY_DESC_LENGTH_OFFSET],
6051 MAX_MODEL_LEN)); 6114 MAX_MODEL_LEN));
@@ -6251,6 +6314,51 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba)
6251 hba->req_abort_count = 0; 6314 hba->req_abort_count = 0;
6252} 6315}
6253 6316
6317static void ufshcd_init_desc_sizes(struct ufs_hba *hba)
6318{
6319 int err;
6320
6321 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_DEVICE, 0,
6322 &hba->desc_size.dev_desc);
6323 if (err)
6324 hba->desc_size.dev_desc = QUERY_DESC_DEVICE_DEF_SIZE;
6325
6326 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_POWER, 0,
6327 &hba->desc_size.pwr_desc);
6328 if (err)
6329 hba->desc_size.pwr_desc = QUERY_DESC_POWER_DEF_SIZE;
6330
6331 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_INTERCONNECT, 0,
6332 &hba->desc_size.interc_desc);
6333 if (err)
6334 hba->desc_size.interc_desc = QUERY_DESC_INTERCONNECT_DEF_SIZE;
6335
6336 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_CONFIGURATION, 0,
6337 &hba->desc_size.conf_desc);
6338 if (err)
6339 hba->desc_size.conf_desc = QUERY_DESC_CONFIGURATION_DEF_SIZE;
6340
6341 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_UNIT, 0,
6342 &hba->desc_size.unit_desc);
6343 if (err)
6344 hba->desc_size.unit_desc = QUERY_DESC_UNIT_DEF_SIZE;
6345
6346 err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_GEOMETRY, 0,
6347 &hba->desc_size.geom_desc);
6348 if (err)
6349 hba->desc_size.geom_desc = QUERY_DESC_GEOMETRY_DEF_SIZE;
6350}
6351
6352static void ufshcd_def_desc_sizes(struct ufs_hba *hba)
6353{
6354 hba->desc_size.dev_desc = QUERY_DESC_DEVICE_DEF_SIZE;
6355 hba->desc_size.pwr_desc = QUERY_DESC_POWER_DEF_SIZE;
6356 hba->desc_size.interc_desc = QUERY_DESC_INTERCONNECT_DEF_SIZE;
6357 hba->desc_size.conf_desc = QUERY_DESC_CONFIGURATION_DEF_SIZE;
6358 hba->desc_size.unit_desc = QUERY_DESC_UNIT_DEF_SIZE;
6359 hba->desc_size.geom_desc = QUERY_DESC_GEOMETRY_DEF_SIZE;
6360}
6361
6254/** 6362/**
6255 * ufshcd_probe_hba - probe hba to detect device and initialize 6363 * ufshcd_probe_hba - probe hba to detect device and initialize
6256 * @hba: per-adapter instance 6364 * @hba: per-adapter instance
@@ -6285,6 +6393,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
6285 if (ret) 6393 if (ret)
6286 goto out; 6394 goto out;
6287 6395
6396 /* Init check for device descriptor sizes */
6397 ufshcd_init_desc_sizes(hba);
6398
6288 ret = ufs_get_device_desc(hba, &card); 6399 ret = ufs_get_device_desc(hba, &card);
6289 if (ret) { 6400 if (ret) {
6290 dev_err(hba->dev, "%s: Failed getting device info. err = %d\n", 6401 dev_err(hba->dev, "%s: Failed getting device info. err = %d\n",
@@ -6320,6 +6431,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
6320 6431
6321 /* set the state as operational after switching to desired gear */ 6432 /* set the state as operational after switching to desired gear */
6322 hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; 6433 hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
6434
6323 /* 6435 /*
6324 * If we are in error handling context or in power management callbacks 6436 * If we are in error handling context or in power management callbacks
6325 * context, no need to scan the host 6437 * context, no need to scan the host
@@ -7774,6 +7886,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
7774 hba->mmio_base = mmio_base; 7886 hba->mmio_base = mmio_base;
7775 hba->irq = irq; 7887 hba->irq = irq;
7776 7888
7889 /* Set descriptor lengths to specification defaults */
7890 ufshcd_def_desc_sizes(hba);
7891
7777 err = ufshcd_hba_init(hba); 7892 err = ufshcd_hba_init(hba);
7778 if (err) 7893 if (err)
7779 goto out_error; 7894 goto out_error;
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 7630600217a2..cdc8bd05f7df 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -220,6 +220,15 @@ struct ufs_dev_cmd {
220 struct ufs_query query; 220 struct ufs_query query;
221}; 221};
222 222
223struct ufs_desc_size {
224 int dev_desc;
225 int pwr_desc;
226 int geom_desc;
227 int interc_desc;
228 int unit_desc;
229 int conf_desc;
230};
231
223/** 232/**
224 * struct ufs_clk_info - UFS clock related info 233 * struct ufs_clk_info - UFS clock related info
225 * @list: list headed by hba->clk_list_head 234 * @list: list headed by hba->clk_list_head
@@ -483,6 +492,7 @@ struct ufs_stats {
483 * @clk_list_head: UFS host controller clocks list node head 492 * @clk_list_head: UFS host controller clocks list node head
484 * @pwr_info: holds current power mode 493 * @pwr_info: holds current power mode
485 * @max_pwr_info: keeps the device max valid pwm 494 * @max_pwr_info: keeps the device max valid pwm
495 * @desc_size: descriptor sizes reported by device
486 * @urgent_bkops_lvl: keeps track of urgent bkops level for device 496 * @urgent_bkops_lvl: keeps track of urgent bkops level for device
487 * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for 497 * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for
488 * device is known or not. 498 * device is known or not.
@@ -666,6 +676,7 @@ struct ufs_hba {
666 bool is_urgent_bkops_lvl_checked; 676 bool is_urgent_bkops_lvl_checked;
667 677
668 struct rw_semaphore clk_scaling_lock; 678 struct rw_semaphore clk_scaling_lock;
679 struct ufs_desc_size desc_size;
669}; 680};
670 681
671/* Returns true if clocks can be gated. Otherwise false */ 682/* Returns true if clocks can be gated. Otherwise false */
@@ -832,6 +843,10 @@ int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
832 enum flag_idn idn, bool *flag_res); 843 enum flag_idn idn, bool *flag_res);
833int ufshcd_hold(struct ufs_hba *hba, bool async); 844int ufshcd_hold(struct ufs_hba *hba, bool async);
834void ufshcd_release(struct ufs_hba *hba); 845void ufshcd_release(struct ufs_hba *hba);
846
847int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
848 int *desc_length);
849
835u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); 850u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba);
836 851
837/* Wrapper functions for safely calling variant operations */ 852/* Wrapper functions for safely calling variant operations */
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index ef474a748744..c374e3b5c678 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -1487,7 +1487,7 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1487 irq_flag &= ~PCI_IRQ_MSI; 1487 irq_flag &= ~PCI_IRQ_MSI;
1488 1488
1489 error = pci_alloc_irq_vectors(adapter->dev, 1, 1, irq_flag); 1489 error = pci_alloc_irq_vectors(adapter->dev, 1, 1, irq_flag);
1490 if (error) 1490 if (error < 0)
1491 goto out_reset_adapter; 1491 goto out_reset_adapter;
1492 1492
1493 adapter->use_req_threshold = pvscsi_setup_req_threshold(adapter, true); 1493 adapter->use_req_threshold = pvscsi_setup_req_threshold(adapter, true);
diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c
index b7b87ecefcdf..9fca8d225ee0 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-socket.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c
@@ -532,7 +532,7 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
532 532
533 newsock->ops = sock->ops; 533 newsock->ops = sock->ops;
534 534
535 rc = sock->ops->accept(sock, newsock, O_NONBLOCK); 535 rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false);
536 if (rc == -EAGAIN) { 536 if (rc == -EAGAIN) {
537 /* Nothing ready, so wait for activity */ 537 /* Nothing ready, so wait for activity */
538 init_waitqueue_entry(&wait, current); 538 init_waitqueue_entry(&wait, current);
@@ -540,7 +540,7 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
540 set_current_state(TASK_INTERRUPTIBLE); 540 set_current_state(TASK_INTERRUPTIBLE);
541 schedule(); 541 schedule();
542 remove_wait_queue(sk_sleep(sock->sk), &wait); 542 remove_wait_queue(sk_sleep(sock->sk), &wait);
543 rc = sock->ops->accept(sock, newsock, O_NONBLOCK); 543 rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false);
544 } 544 }
545 545
546 if (rc) 546 if (rc)
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 7d398d300e97..9382db998ec9 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -743,7 +743,7 @@ static int tcp_accept_from_sock(struct connection *con)
743 newsock->type = con->sock->type; 743 newsock->type = con->sock->type;
744 newsock->ops = con->sock->ops; 744 newsock->ops = con->sock->ops;
745 745
746 result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK); 746 result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK, true);
747 if (result < 0) 747 if (result < 0)
748 goto accept_err; 748 goto accept_err;
749 749
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index ef600591d96f..63ee2940775c 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -173,19 +173,33 @@ static void wb_wakeup(struct bdi_writeback *wb)
173 spin_unlock_bh(&wb->work_lock); 173 spin_unlock_bh(&wb->work_lock);
174} 174}
175 175
176static void finish_writeback_work(struct bdi_writeback *wb,
177 struct wb_writeback_work *work)
178{
179 struct wb_completion *done = work->done;
180
181 if (work->auto_free)
182 kfree(work);
183 if (done && atomic_dec_and_test(&done->cnt))
184 wake_up_all(&wb->bdi->wb_waitq);
185}
186
176static void wb_queue_work(struct bdi_writeback *wb, 187static void wb_queue_work(struct bdi_writeback *wb,
177 struct wb_writeback_work *work) 188 struct wb_writeback_work *work)
178{ 189{
179 trace_writeback_queue(wb, work); 190 trace_writeback_queue(wb, work);
180 191
181 spin_lock_bh(&wb->work_lock);
182 if (!test_bit(WB_registered, &wb->state))
183 goto out_unlock;
184 if (work->done) 192 if (work->done)
185 atomic_inc(&work->done->cnt); 193 atomic_inc(&work->done->cnt);
186 list_add_tail(&work->list, &wb->work_list); 194
187 mod_delayed_work(bdi_wq, &wb->dwork, 0); 195 spin_lock_bh(&wb->work_lock);
188out_unlock: 196
197 if (test_bit(WB_registered, &wb->state)) {
198 list_add_tail(&work->list, &wb->work_list);
199 mod_delayed_work(bdi_wq, &wb->dwork, 0);
200 } else
201 finish_writeback_work(wb, work);
202
189 spin_unlock_bh(&wb->work_lock); 203 spin_unlock_bh(&wb->work_lock);
190} 204}
191 205
@@ -1873,16 +1887,9 @@ static long wb_do_writeback(struct bdi_writeback *wb)
1873 1887
1874 set_bit(WB_writeback_running, &wb->state); 1888 set_bit(WB_writeback_running, &wb->state);
1875 while ((work = get_next_work_item(wb)) != NULL) { 1889 while ((work = get_next_work_item(wb)) != NULL) {
1876 struct wb_completion *done = work->done;
1877
1878 trace_writeback_exec(wb, work); 1890 trace_writeback_exec(wb, work);
1879
1880 wrote += wb_writeback(wb, work); 1891 wrote += wb_writeback(wb, work);
1881 1892 finish_writeback_work(wb, work);
1882 if (work->auto_free)
1883 kfree(work);
1884 if (done && atomic_dec_and_test(&done->cnt))
1885 wake_up_all(&wb->bdi->wb_waitq);
1886 } 1893 }
1887 1894
1888 /* 1895 /*
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index c45084ac642d..511e1ed7e2de 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -207,7 +207,7 @@ struct lm_lockname {
207 struct gfs2_sbd *ln_sbd; 207 struct gfs2_sbd *ln_sbd;
208 u64 ln_number; 208 u64 ln_number;
209 unsigned int ln_type; 209 unsigned int ln_type;
210}; 210} __packed __aligned(sizeof(int));
211 211
212#define lm_name_equal(name1, name2) \ 212#define lm_name_equal(name1, name2) \
213 (((name1)->ln_number == (name2)->ln_number) && \ 213 (((name1)->ln_number == (name2)->ln_number) && \
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index 4348027384f5..d0ab7e56d0b4 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -1863,7 +1863,7 @@ static int o2net_accept_one(struct socket *sock, int *more)
1863 1863
1864 new_sock->type = sock->type; 1864 new_sock->type = sock->type;
1865 new_sock->ops = sock->ops; 1865 new_sock->ops = sock->ops;
1866 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); 1866 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, false);
1867 if (ret < 0) 1867 if (ret < 0)
1868 goto out; 1868 goto out;
1869 1869
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index a2bfd7843f18..e2b9c6fe2714 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -73,7 +73,7 @@ int af_alg_unregister_type(const struct af_alg_type *type);
73 73
74int af_alg_release(struct socket *sock); 74int af_alg_release(struct socket *sock);
75void af_alg_release_parent(struct sock *sk); 75void af_alg_release_parent(struct sock *sk);
76int af_alg_accept(struct sock *sk, struct socket *newsock); 76int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern);
77 77
78int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); 78int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
79void af_alg_free_sg(struct af_alg_sgl *sgl); 79void af_alg_free_sg(struct af_alg_sgl *sgl);
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 61d042bbbf60..68449293c4b6 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -163,6 +163,7 @@ struct dccp_request_sock {
163 __u64 dreq_isr; 163 __u64 dreq_isr;
164 __u64 dreq_gsr; 164 __u64 dreq_gsr;
165 __be32 dreq_service; 165 __be32 dreq_service;
166 spinlock_t dreq_lock;
166 struct list_head dreq_featneg; 167 struct list_head dreq_featneg;
167 __u32 dreq_timestamp_echo; 168 __u32 dreq_timestamp_echo;
168 __u32 dreq_timestamp_time; 169 __u32 dreq_timestamp_time;
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 0c167fdee5f7..fbf7b39e8103 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -409,6 +409,7 @@ struct bpf_prog {
409 u16 pages; /* Number of allocated pages */ 409 u16 pages; /* Number of allocated pages */
410 kmemcheck_bitfield_begin(meta); 410 kmemcheck_bitfield_begin(meta);
411 u16 jited:1, /* Is our filter JIT'ed? */ 411 u16 jited:1, /* Is our filter JIT'ed? */
412 locked:1, /* Program image locked? */
412 gpl_compatible:1, /* Is filter GPL compatible? */ 413 gpl_compatible:1, /* Is filter GPL compatible? */
413 cb_access:1, /* Is control block accessed? */ 414 cb_access:1, /* Is control block accessed? */
414 dst_needed:1, /* Do we need dst entry? */ 415 dst_needed:1, /* Do we need dst entry? */
@@ -554,22 +555,29 @@ static inline bool bpf_prog_was_classic(const struct bpf_prog *prog)
554#ifdef CONFIG_ARCH_HAS_SET_MEMORY 555#ifdef CONFIG_ARCH_HAS_SET_MEMORY
555static inline void bpf_prog_lock_ro(struct bpf_prog *fp) 556static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
556{ 557{
557 set_memory_ro((unsigned long)fp, fp->pages); 558 fp->locked = 1;
559 WARN_ON_ONCE(set_memory_ro((unsigned long)fp, fp->pages));
558} 560}
559 561
560static inline void bpf_prog_unlock_ro(struct bpf_prog *fp) 562static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
561{ 563{
562 set_memory_rw((unsigned long)fp, fp->pages); 564 if (fp->locked) {
565 WARN_ON_ONCE(set_memory_rw((unsigned long)fp, fp->pages));
566 /* In case set_memory_rw() fails, we want to be the first
567 * to crash here instead of some random place later on.
568 */
569 fp->locked = 0;
570 }
563} 571}
564 572
565static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr) 573static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
566{ 574{
567 set_memory_ro((unsigned long)hdr, hdr->pages); 575 WARN_ON_ONCE(set_memory_ro((unsigned long)hdr, hdr->pages));
568} 576}
569 577
570static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr) 578static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr)
571{ 579{
572 set_memory_rw((unsigned long)hdr, hdr->pages); 580 WARN_ON_ONCE(set_memory_rw((unsigned long)hdr, hdr->pages));
573} 581}
574#else 582#else
575static inline void bpf_prog_lock_ro(struct bpf_prog *fp) 583static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
diff --git a/include/linux/list_nulls.h b/include/linux/list_nulls.h
index b01fe1009084..87ff4f58a2f0 100644
--- a/include/linux/list_nulls.h
+++ b/include/linux/list_nulls.h
@@ -29,6 +29,11 @@ struct hlist_nulls_node {
29 ((ptr)->first = (struct hlist_nulls_node *) NULLS_MARKER(nulls)) 29 ((ptr)->first = (struct hlist_nulls_node *) NULLS_MARKER(nulls))
30 30
31#define hlist_nulls_entry(ptr, type, member) container_of(ptr,type,member) 31#define hlist_nulls_entry(ptr, type, member) container_of(ptr,type,member)
32
33#define hlist_nulls_entry_safe(ptr, type, member) \
34 ({ typeof(ptr) ____ptr = (ptr); \
35 !is_a_nulls(____ptr) ? hlist_nulls_entry(____ptr, type, member) : NULL; \
36 })
32/** 37/**
33 * ptr_is_a_nulls - Test if a ptr is a nulls 38 * ptr_is_a_nulls - Test if a ptr is a nulls
34 * @ptr: ptr to be tested 39 * @ptr: ptr to be tested
diff --git a/include/linux/net.h b/include/linux/net.h
index cd0c8bd0a1de..0620f5e18c96 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -146,7 +146,7 @@ struct proto_ops {
146 int (*socketpair)(struct socket *sock1, 146 int (*socketpair)(struct socket *sock1,
147 struct socket *sock2); 147 struct socket *sock2);
148 int (*accept) (struct socket *sock, 148 int (*accept) (struct socket *sock,
149 struct socket *newsock, int flags); 149 struct socket *newsock, int flags, bool kern);
150 int (*getname) (struct socket *sock, 150 int (*getname) (struct socket *sock,
151 struct sockaddr *addr, 151 struct sockaddr *addr,
152 int *sockaddr_len, int peer); 152 int *sockaddr_len, int peer);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 772476028a65..43a774873aa9 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -837,6 +837,10 @@ int genphy_read_status(struct phy_device *phydev);
837int genphy_suspend(struct phy_device *phydev); 837int genphy_suspend(struct phy_device *phydev);
838int genphy_resume(struct phy_device *phydev); 838int genphy_resume(struct phy_device *phydev);
839int genphy_soft_reset(struct phy_device *phydev); 839int genphy_soft_reset(struct phy_device *phydev);
840static inline int genphy_no_soft_reset(struct phy_device *phydev)
841{
842 return 0;
843}
840void phy_driver_unregister(struct phy_driver *drv); 844void phy_driver_unregister(struct phy_driver *drv);
841void phy_drivers_unregister(struct phy_driver *drv, int n); 845void phy_drivers_unregister(struct phy_driver *drv, int n);
842int phy_driver_register(struct phy_driver *new_driver, struct module *owner); 846int phy_driver_register(struct phy_driver *new_driver, struct module *owner);
diff --git a/include/linux/rculist_nulls.h b/include/linux/rculist_nulls.h
index 4ae95f7e8597..a23a33153180 100644
--- a/include/linux/rculist_nulls.h
+++ b/include/linux/rculist_nulls.h
@@ -156,5 +156,19 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
156 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1; }); \ 156 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1; }); \
157 pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos))) 157 pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos)))
158 158
159/**
160 * hlist_nulls_for_each_entry_safe -
161 * iterate over list of given type safe against removal of list entry
162 * @tpos: the type * to use as a loop cursor.
163 * @pos: the &struct hlist_nulls_node to use as a loop cursor.
164 * @head: the head for your list.
165 * @member: the name of the hlist_nulls_node within the struct.
166 */
167#define hlist_nulls_for_each_entry_safe(tpos, pos, head, member) \
168 for (({barrier();}), \
169 pos = rcu_dereference_raw(hlist_nulls_first_rcu(head)); \
170 (!is_a_nulls(pos)) && \
171 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); \
172 pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos)); 1; });)
159#endif 173#endif
160#endif 174#endif
diff --git a/include/net/inet_common.h b/include/net/inet_common.h
index b7952d55b9c0..f39ae697347f 100644
--- a/include/net/inet_common.h
+++ b/include/net/inet_common.h
@@ -20,7 +20,8 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
20 int addr_len, int flags, int is_sendmsg); 20 int addr_len, int flags, int is_sendmsg);
21int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr, 21int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
22 int addr_len, int flags); 22 int addr_len, int flags);
23int inet_accept(struct socket *sock, struct socket *newsock, int flags); 23int inet_accept(struct socket *sock, struct socket *newsock, int flags,
24 bool kern);
24int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size); 25int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
25ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset, 26ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
26 size_t size, int flags); 27 size_t size, int flags);
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 826f198374f8..c7a577976bec 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -258,7 +258,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
258 return (unsigned long)min_t(u64, when, max_when); 258 return (unsigned long)min_t(u64, when, max_when);
259} 259}
260 260
261struct sock *inet_csk_accept(struct sock *sk, int flags, int *err); 261struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
262 262
263int inet_csk_get_port(struct sock *sk, unsigned short snum); 263int inet_csk_get_port(struct sock *sk, unsigned short snum);
264 264
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index a244db5e5ff7..07a0b128625a 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -476,7 +476,8 @@ struct sctp_pf {
476 int (*send_verify) (struct sctp_sock *, union sctp_addr *); 476 int (*send_verify) (struct sctp_sock *, union sctp_addr *);
477 int (*supported_addrs)(const struct sctp_sock *, __be16 *); 477 int (*supported_addrs)(const struct sctp_sock *, __be16 *);
478 struct sock *(*create_accept_sk) (struct sock *sk, 478 struct sock *(*create_accept_sk) (struct sock *sk,
479 struct sctp_association *asoc); 479 struct sctp_association *asoc,
480 bool kern);
480 int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr); 481 int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);
481 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk); 482 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
482 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk); 483 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
diff --git a/include/net/sock.h b/include/net/sock.h
index 5e5997654db6..03252d53975d 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -236,6 +236,7 @@ struct sock_common {
236 * @sk_shutdown: mask of %SEND_SHUTDOWN and/or %RCV_SHUTDOWN 236 * @sk_shutdown: mask of %SEND_SHUTDOWN and/or %RCV_SHUTDOWN
237 * @sk_userlocks: %SO_SNDBUF and %SO_RCVBUF settings 237 * @sk_userlocks: %SO_SNDBUF and %SO_RCVBUF settings
238 * @sk_lock: synchronizer 238 * @sk_lock: synchronizer
239 * @sk_kern_sock: True if sock is using kernel lock classes
239 * @sk_rcvbuf: size of receive buffer in bytes 240 * @sk_rcvbuf: size of receive buffer in bytes
240 * @sk_wq: sock wait queue and async head 241 * @sk_wq: sock wait queue and async head
241 * @sk_rx_dst: receive input route used by early demux 242 * @sk_rx_dst: receive input route used by early demux
@@ -430,7 +431,8 @@ struct sock {
430#endif 431#endif
431 432
432 kmemcheck_bitfield_begin(flags); 433 kmemcheck_bitfield_begin(flags);
433 unsigned int sk_padding : 2, 434 unsigned int sk_padding : 1,
435 sk_kern_sock : 1,
434 sk_no_check_tx : 1, 436 sk_no_check_tx : 1,
435 sk_no_check_rx : 1, 437 sk_no_check_rx : 1,
436 sk_userlocks : 4, 438 sk_userlocks : 4,
@@ -1015,7 +1017,8 @@ struct proto {
1015 int addr_len); 1017 int addr_len);
1016 int (*disconnect)(struct sock *sk, int flags); 1018 int (*disconnect)(struct sock *sk, int flags);
1017 1019
1018 struct sock * (*accept)(struct sock *sk, int flags, int *err); 1020 struct sock * (*accept)(struct sock *sk, int flags, int *err,
1021 bool kern);
1019 1022
1020 int (*ioctl)(struct sock *sk, int cmd, 1023 int (*ioctl)(struct sock *sk, int cmd,
1021 unsigned long arg); 1024 unsigned long arg);
@@ -1573,7 +1576,7 @@ int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
1573int sock_no_bind(struct socket *, struct sockaddr *, int); 1576int sock_no_bind(struct socket *, struct sockaddr *, int);
1574int sock_no_connect(struct socket *, struct sockaddr *, int, int); 1577int sock_no_connect(struct socket *, struct sockaddr *, int, int);
1575int sock_no_socketpair(struct socket *, struct socket *); 1578int sock_no_socketpair(struct socket *, struct socket *);
1576int sock_no_accept(struct socket *, struct socket *, int); 1579int sock_no_accept(struct socket *, struct socket *, int, bool);
1577int sock_no_getname(struct socket *, struct sockaddr *, int *, int); 1580int sock_no_getname(struct socket *, struct sockaddr *, int *, int);
1578unsigned int sock_no_poll(struct file *, struct socket *, 1581unsigned int sock_no_poll(struct file *, struct socket *,
1579 struct poll_table_struct *); 1582 struct poll_table_struct *);
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index b0e275de6dec..583875ea136a 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -196,6 +196,7 @@ struct iscsi_conn {
196 struct iscsi_task *task; /* xmit task in progress */ 196 struct iscsi_task *task; /* xmit task in progress */
197 197
198 /* xmit */ 198 /* xmit */
199 spinlock_t taskqueuelock; /* protects the next three lists */
199 struct list_head mgmtqueue; /* mgmt (control) xmit queue */ 200 struct list_head mgmtqueue; /* mgmt (control) xmit queue */
200 struct list_head cmdqueue; /* data-path cmd queue */ 201 struct list_head cmdqueue; /* data-path cmd queue */
201 struct list_head requeue; /* tasks needing another run */ 202 struct list_head requeue; /* tasks needing another run */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 6f22b39f1b0c..080c7ce9bae8 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -472,6 +472,10 @@ static inline int scsi_device_created(struct scsi_device *sdev)
472 sdev->sdev_state == SDEV_CREATED_BLOCK; 472 sdev->sdev_state == SDEV_CREATED_BLOCK;
473} 473}
474 474
475int scsi_internal_device_block(struct scsi_device *sdev, bool wait);
476int scsi_internal_device_unblock(struct scsi_device *sdev,
477 enum scsi_device_state new_state);
478
475/* accessor functions for the SCSI parameters */ 479/* accessor functions for the SCSI parameters */
476static inline int scsi_device_sync(struct scsi_device *sdev) 480static inline int scsi_device_sync(struct scsi_device *sdev)
477{ 481{
diff --git a/include/uapi/linux/packet_diag.h b/include/uapi/linux/packet_diag.h
index d08c63f3dd6f..0c5d5dd61b6a 100644
--- a/include/uapi/linux/packet_diag.h
+++ b/include/uapi/linux/packet_diag.h
@@ -64,7 +64,7 @@ struct packet_diag_mclist {
64 __u32 pdmc_count; 64 __u32 pdmc_count;
65 __u16 pdmc_type; 65 __u16 pdmc_type;
66 __u16 pdmc_alen; 66 __u16 pdmc_alen;
67 __u8 pdmc_addr[MAX_ADDR_LEN]; 67 __u8 pdmc_addr[32]; /* MAX_ADDR_LEN */
68}; 68};
69 69
70struct packet_diag_ring { 70struct packet_diag_ring {
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 3ea87fb19a94..afe5bab376c9 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -13,11 +13,12 @@
13#include <linux/bpf.h> 13#include <linux/bpf.h>
14#include <linux/jhash.h> 14#include <linux/jhash.h>
15#include <linux/filter.h> 15#include <linux/filter.h>
16#include <linux/rculist_nulls.h>
16#include "percpu_freelist.h" 17#include "percpu_freelist.h"
17#include "bpf_lru_list.h" 18#include "bpf_lru_list.h"
18 19
19struct bucket { 20struct bucket {
20 struct hlist_head head; 21 struct hlist_nulls_head head;
21 raw_spinlock_t lock; 22 raw_spinlock_t lock;
22}; 23};
23 24
@@ -44,9 +45,14 @@ enum extra_elem_state {
44/* each htab element is struct htab_elem + key + value */ 45/* each htab element is struct htab_elem + key + value */
45struct htab_elem { 46struct htab_elem {
46 union { 47 union {
47 struct hlist_node hash_node; 48 struct hlist_nulls_node hash_node;
48 struct bpf_htab *htab; 49 struct {
49 struct pcpu_freelist_node fnode; 50 void *padding;
51 union {
52 struct bpf_htab *htab;
53 struct pcpu_freelist_node fnode;
54 };
55 };
50 }; 56 };
51 union { 57 union {
52 struct rcu_head rcu; 58 struct rcu_head rcu;
@@ -162,7 +168,8 @@ skip_percpu_elems:
162 offsetof(struct htab_elem, lru_node), 168 offsetof(struct htab_elem, lru_node),
163 htab->elem_size, htab->map.max_entries); 169 htab->elem_size, htab->map.max_entries);
164 else 170 else
165 pcpu_freelist_populate(&htab->freelist, htab->elems, 171 pcpu_freelist_populate(&htab->freelist,
172 htab->elems + offsetof(struct htab_elem, fnode),
166 htab->elem_size, htab->map.max_entries); 173 htab->elem_size, htab->map.max_entries);
167 174
168 return 0; 175 return 0;
@@ -217,6 +224,11 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
217 int err, i; 224 int err, i;
218 u64 cost; 225 u64 cost;
219 226
227 BUILD_BUG_ON(offsetof(struct htab_elem, htab) !=
228 offsetof(struct htab_elem, hash_node.pprev));
229 BUILD_BUG_ON(offsetof(struct htab_elem, fnode.next) !=
230 offsetof(struct htab_elem, hash_node.pprev));
231
220 if (lru && !capable(CAP_SYS_ADMIN)) 232 if (lru && !capable(CAP_SYS_ADMIN))
221 /* LRU implementation is much complicated than other 233 /* LRU implementation is much complicated than other
222 * maps. Hence, limit to CAP_SYS_ADMIN for now. 234 * maps. Hence, limit to CAP_SYS_ADMIN for now.
@@ -326,7 +338,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
326 goto free_htab; 338 goto free_htab;
327 339
328 for (i = 0; i < htab->n_buckets; i++) { 340 for (i = 0; i < htab->n_buckets; i++) {
329 INIT_HLIST_HEAD(&htab->buckets[i].head); 341 INIT_HLIST_NULLS_HEAD(&htab->buckets[i].head, i);
330 raw_spin_lock_init(&htab->buckets[i].lock); 342 raw_spin_lock_init(&htab->buckets[i].lock);
331 } 343 }
332 344
@@ -366,20 +378,44 @@ static inline struct bucket *__select_bucket(struct bpf_htab *htab, u32 hash)
366 return &htab->buckets[hash & (htab->n_buckets - 1)]; 378 return &htab->buckets[hash & (htab->n_buckets - 1)];
367} 379}
368 380
369static inline struct hlist_head *select_bucket(struct bpf_htab *htab, u32 hash) 381static inline struct hlist_nulls_head *select_bucket(struct bpf_htab *htab, u32 hash)
370{ 382{
371 return &__select_bucket(htab, hash)->head; 383 return &__select_bucket(htab, hash)->head;
372} 384}
373 385
374static struct htab_elem *lookup_elem_raw(struct hlist_head *head, u32 hash, 386/* this lookup function can only be called with bucket lock taken */
387static struct htab_elem *lookup_elem_raw(struct hlist_nulls_head *head, u32 hash,
375 void *key, u32 key_size) 388 void *key, u32 key_size)
376{ 389{
390 struct hlist_nulls_node *n;
391 struct htab_elem *l;
392
393 hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
394 if (l->hash == hash && !memcmp(&l->key, key, key_size))
395 return l;
396
397 return NULL;
398}
399
400/* can be called without bucket lock. it will repeat the loop in
401 * the unlikely event when elements moved from one bucket into another
402 * while link list is being walked
403 */
404static struct htab_elem *lookup_nulls_elem_raw(struct hlist_nulls_head *head,
405 u32 hash, void *key,
406 u32 key_size, u32 n_buckets)
407{
408 struct hlist_nulls_node *n;
377 struct htab_elem *l; 409 struct htab_elem *l;
378 410
379 hlist_for_each_entry_rcu(l, head, hash_node) 411again:
412 hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
380 if (l->hash == hash && !memcmp(&l->key, key, key_size)) 413 if (l->hash == hash && !memcmp(&l->key, key, key_size))
381 return l; 414 return l;
382 415
416 if (unlikely(get_nulls_value(n) != (hash & (n_buckets - 1))))
417 goto again;
418
383 return NULL; 419 return NULL;
384} 420}
385 421
@@ -387,7 +423,7 @@ static struct htab_elem *lookup_elem_raw(struct hlist_head *head, u32 hash,
387static void *__htab_map_lookup_elem(struct bpf_map *map, void *key) 423static void *__htab_map_lookup_elem(struct bpf_map *map, void *key)
388{ 424{
389 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 425 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
390 struct hlist_head *head; 426 struct hlist_nulls_head *head;
391 struct htab_elem *l; 427 struct htab_elem *l;
392 u32 hash, key_size; 428 u32 hash, key_size;
393 429
@@ -400,7 +436,7 @@ static void *__htab_map_lookup_elem(struct bpf_map *map, void *key)
400 436
401 head = select_bucket(htab, hash); 437 head = select_bucket(htab, hash);
402 438
403 l = lookup_elem_raw(head, hash, key, key_size); 439 l = lookup_nulls_elem_raw(head, hash, key, key_size, htab->n_buckets);
404 440
405 return l; 441 return l;
406} 442}
@@ -433,8 +469,9 @@ static void *htab_lru_map_lookup_elem(struct bpf_map *map, void *key)
433static bool htab_lru_map_delete_node(void *arg, struct bpf_lru_node *node) 469static bool htab_lru_map_delete_node(void *arg, struct bpf_lru_node *node)
434{ 470{
435 struct bpf_htab *htab = (struct bpf_htab *)arg; 471 struct bpf_htab *htab = (struct bpf_htab *)arg;
436 struct htab_elem *l, *tgt_l; 472 struct htab_elem *l = NULL, *tgt_l;
437 struct hlist_head *head; 473 struct hlist_nulls_head *head;
474 struct hlist_nulls_node *n;
438 unsigned long flags; 475 unsigned long flags;
439 struct bucket *b; 476 struct bucket *b;
440 477
@@ -444,9 +481,9 @@ static bool htab_lru_map_delete_node(void *arg, struct bpf_lru_node *node)
444 481
445 raw_spin_lock_irqsave(&b->lock, flags); 482 raw_spin_lock_irqsave(&b->lock, flags);
446 483
447 hlist_for_each_entry_rcu(l, head, hash_node) 484 hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
448 if (l == tgt_l) { 485 if (l == tgt_l) {
449 hlist_del_rcu(&l->hash_node); 486 hlist_nulls_del_rcu(&l->hash_node);
450 break; 487 break;
451 } 488 }
452 489
@@ -459,7 +496,7 @@ static bool htab_lru_map_delete_node(void *arg, struct bpf_lru_node *node)
459static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key) 496static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
460{ 497{
461 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 498 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
462 struct hlist_head *head; 499 struct hlist_nulls_head *head;
463 struct htab_elem *l, *next_l; 500 struct htab_elem *l, *next_l;
464 u32 hash, key_size; 501 u32 hash, key_size;
465 int i; 502 int i;
@@ -473,7 +510,7 @@ static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
473 head = select_bucket(htab, hash); 510 head = select_bucket(htab, hash);
474 511
475 /* lookup the key */ 512 /* lookup the key */
476 l = lookup_elem_raw(head, hash, key, key_size); 513 l = lookup_nulls_elem_raw(head, hash, key, key_size, htab->n_buckets);
477 514
478 if (!l) { 515 if (!l) {
479 i = 0; 516 i = 0;
@@ -481,7 +518,7 @@ static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
481 } 518 }
482 519
483 /* key was found, get next key in the same bucket */ 520 /* key was found, get next key in the same bucket */
484 next_l = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(&l->hash_node)), 521 next_l = hlist_nulls_entry_safe(rcu_dereference_raw(hlist_nulls_next_rcu(&l->hash_node)),
485 struct htab_elem, hash_node); 522 struct htab_elem, hash_node);
486 523
487 if (next_l) { 524 if (next_l) {
@@ -500,7 +537,7 @@ find_first_elem:
500 head = select_bucket(htab, i); 537 head = select_bucket(htab, i);
501 538
502 /* pick first element in the bucket */ 539 /* pick first element in the bucket */
503 next_l = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)), 540 next_l = hlist_nulls_entry_safe(rcu_dereference_raw(hlist_nulls_first_rcu(head)),
504 struct htab_elem, hash_node); 541 struct htab_elem, hash_node);
505 if (next_l) { 542 if (next_l) {
506 /* if it's not empty, just return it */ 543 /* if it's not empty, just return it */
@@ -582,9 +619,13 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,
582 int err = 0; 619 int err = 0;
583 620
584 if (prealloc) { 621 if (prealloc) {
585 l_new = (struct htab_elem *)pcpu_freelist_pop(&htab->freelist); 622 struct pcpu_freelist_node *l;
586 if (!l_new) 623
624 l = pcpu_freelist_pop(&htab->freelist);
625 if (!l)
587 err = -E2BIG; 626 err = -E2BIG;
627 else
628 l_new = container_of(l, struct htab_elem, fnode);
588 } else { 629 } else {
589 if (atomic_inc_return(&htab->count) > htab->map.max_entries) { 630 if (atomic_inc_return(&htab->count) > htab->map.max_entries) {
590 atomic_dec(&htab->count); 631 atomic_dec(&htab->count);
@@ -661,7 +702,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
661{ 702{
662 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 703 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
663 struct htab_elem *l_new = NULL, *l_old; 704 struct htab_elem *l_new = NULL, *l_old;
664 struct hlist_head *head; 705 struct hlist_nulls_head *head;
665 unsigned long flags; 706 unsigned long flags;
666 struct bucket *b; 707 struct bucket *b;
667 u32 key_size, hash; 708 u32 key_size, hash;
@@ -700,9 +741,9 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value,
700 /* add new element to the head of the list, so that 741 /* add new element to the head of the list, so that
701 * concurrent search will find it before old elem 742 * concurrent search will find it before old elem
702 */ 743 */
703 hlist_add_head_rcu(&l_new->hash_node, head); 744 hlist_nulls_add_head_rcu(&l_new->hash_node, head);
704 if (l_old) { 745 if (l_old) {
705 hlist_del_rcu(&l_old->hash_node); 746 hlist_nulls_del_rcu(&l_old->hash_node);
706 free_htab_elem(htab, l_old); 747 free_htab_elem(htab, l_old);
707 } 748 }
708 ret = 0; 749 ret = 0;
@@ -716,7 +757,7 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value,
716{ 757{
717 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 758 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
718 struct htab_elem *l_new, *l_old = NULL; 759 struct htab_elem *l_new, *l_old = NULL;
719 struct hlist_head *head; 760 struct hlist_nulls_head *head;
720 unsigned long flags; 761 unsigned long flags;
721 struct bucket *b; 762 struct bucket *b;
722 u32 key_size, hash; 763 u32 key_size, hash;
@@ -757,10 +798,10 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value,
757 /* add new element to the head of the list, so that 798 /* add new element to the head of the list, so that
758 * concurrent search will find it before old elem 799 * concurrent search will find it before old elem
759 */ 800 */
760 hlist_add_head_rcu(&l_new->hash_node, head); 801 hlist_nulls_add_head_rcu(&l_new->hash_node, head);
761 if (l_old) { 802 if (l_old) {
762 bpf_lru_node_set_ref(&l_new->lru_node); 803 bpf_lru_node_set_ref(&l_new->lru_node);
763 hlist_del_rcu(&l_old->hash_node); 804 hlist_nulls_del_rcu(&l_old->hash_node);
764 } 805 }
765 ret = 0; 806 ret = 0;
766 807
@@ -781,7 +822,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
781{ 822{
782 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 823 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
783 struct htab_elem *l_new = NULL, *l_old; 824 struct htab_elem *l_new = NULL, *l_old;
784 struct hlist_head *head; 825 struct hlist_nulls_head *head;
785 unsigned long flags; 826 unsigned long flags;
786 struct bucket *b; 827 struct bucket *b;
787 u32 key_size, hash; 828 u32 key_size, hash;
@@ -820,7 +861,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
820 ret = PTR_ERR(l_new); 861 ret = PTR_ERR(l_new);
821 goto err; 862 goto err;
822 } 863 }
823 hlist_add_head_rcu(&l_new->hash_node, head); 864 hlist_nulls_add_head_rcu(&l_new->hash_node, head);
824 } 865 }
825 ret = 0; 866 ret = 0;
826err: 867err:
@@ -834,7 +875,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
834{ 875{
835 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 876 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
836 struct htab_elem *l_new = NULL, *l_old; 877 struct htab_elem *l_new = NULL, *l_old;
837 struct hlist_head *head; 878 struct hlist_nulls_head *head;
838 unsigned long flags; 879 unsigned long flags;
839 struct bucket *b; 880 struct bucket *b;
840 u32 key_size, hash; 881 u32 key_size, hash;
@@ -882,7 +923,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
882 } else { 923 } else {
883 pcpu_copy_value(htab, htab_elem_get_ptr(l_new, key_size), 924 pcpu_copy_value(htab, htab_elem_get_ptr(l_new, key_size),
884 value, onallcpus); 925 value, onallcpus);
885 hlist_add_head_rcu(&l_new->hash_node, head); 926 hlist_nulls_add_head_rcu(&l_new->hash_node, head);
886 l_new = NULL; 927 l_new = NULL;
887 } 928 }
888 ret = 0; 929 ret = 0;
@@ -910,7 +951,7 @@ static int htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
910static int htab_map_delete_elem(struct bpf_map *map, void *key) 951static int htab_map_delete_elem(struct bpf_map *map, void *key)
911{ 952{
912 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 953 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
913 struct hlist_head *head; 954 struct hlist_nulls_head *head;
914 struct bucket *b; 955 struct bucket *b;
915 struct htab_elem *l; 956 struct htab_elem *l;
916 unsigned long flags; 957 unsigned long flags;
@@ -930,7 +971,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key)
930 l = lookup_elem_raw(head, hash, key, key_size); 971 l = lookup_elem_raw(head, hash, key, key_size);
931 972
932 if (l) { 973 if (l) {
933 hlist_del_rcu(&l->hash_node); 974 hlist_nulls_del_rcu(&l->hash_node);
934 free_htab_elem(htab, l); 975 free_htab_elem(htab, l);
935 ret = 0; 976 ret = 0;
936 } 977 }
@@ -942,7 +983,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key)
942static int htab_lru_map_delete_elem(struct bpf_map *map, void *key) 983static int htab_lru_map_delete_elem(struct bpf_map *map, void *key)
943{ 984{
944 struct bpf_htab *htab = container_of(map, struct bpf_htab, map); 985 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
945 struct hlist_head *head; 986 struct hlist_nulls_head *head;
946 struct bucket *b; 987 struct bucket *b;
947 struct htab_elem *l; 988 struct htab_elem *l;
948 unsigned long flags; 989 unsigned long flags;
@@ -962,7 +1003,7 @@ static int htab_lru_map_delete_elem(struct bpf_map *map, void *key)
962 l = lookup_elem_raw(head, hash, key, key_size); 1003 l = lookup_elem_raw(head, hash, key, key_size);
963 1004
964 if (l) { 1005 if (l) {
965 hlist_del_rcu(&l->hash_node); 1006 hlist_nulls_del_rcu(&l->hash_node);
966 ret = 0; 1007 ret = 0;
967 } 1008 }
968 1009
@@ -977,12 +1018,12 @@ static void delete_all_elements(struct bpf_htab *htab)
977 int i; 1018 int i;
978 1019
979 for (i = 0; i < htab->n_buckets; i++) { 1020 for (i = 0; i < htab->n_buckets; i++) {
980 struct hlist_head *head = select_bucket(htab, i); 1021 struct hlist_nulls_head *head = select_bucket(htab, i);
981 struct hlist_node *n; 1022 struct hlist_nulls_node *n;
982 struct htab_elem *l; 1023 struct htab_elem *l;
983 1024
984 hlist_for_each_entry_safe(l, n, head, hash_node) { 1025 hlist_nulls_for_each_entry_safe(l, n, head, hash_node) {
985 hlist_del_rcu(&l->hash_node); 1026 hlist_nulls_del_rcu(&l->hash_node);
986 if (l->state != HTAB_EXTRA_ELEM_USED) 1027 if (l->state != HTAB_EXTRA_ELEM_USED)
987 htab_elem_free(htab, l); 1028 htab_elem_free(htab, l);
988 } 1029 }
diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
index 8bfe0afaee10..b37bd9ab7f57 100644
--- a/kernel/bpf/lpm_trie.c
+++ b/kernel/bpf/lpm_trie.c
@@ -500,9 +500,15 @@ unlock:
500 raw_spin_unlock(&trie->lock); 500 raw_spin_unlock(&trie->lock);
501} 501}
502 502
503static int trie_get_next_key(struct bpf_map *map, void *key, void *next_key)
504{
505 return -ENOTSUPP;
506}
507
503static const struct bpf_map_ops trie_ops = { 508static const struct bpf_map_ops trie_ops = {
504 .map_alloc = trie_alloc, 509 .map_alloc = trie_alloc,
505 .map_free = trie_free, 510 .map_free = trie_free,
511 .map_get_next_key = trie_get_next_key,
506 .map_lookup_elem = trie_lookup_elem, 512 .map_lookup_elem = trie_lookup_elem,
507 .map_update_elem = trie_update_elem, 513 .map_update_elem = trie_update_elem,
508 .map_delete_elem = trie_delete_elem, 514 .map_delete_elem = trie_delete_elem,
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index 56eba9caa632..1dc22f6b49f5 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -1329,7 +1329,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
1329 struct task_struct *task; 1329 struct task_struct *task;
1330 int count = 0; 1330 int count = 0;
1331 1331
1332 seq_printf(seq, "css_set %p\n", cset); 1332 seq_printf(seq, "css_set %pK\n", cset);
1333 1333
1334 list_for_each_entry(task, &cset->tasks, cg_list) { 1334 list_for_each_entry(task, &cset->tasks, cg_list) {
1335 if (count++ > MAX_TASKS_SHOWN_PER_CSS) 1335 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c
index e756dae49300..2237201d66d5 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -229,7 +229,7 @@ static int pids_can_fork(struct task_struct *task)
229 /* Only log the first time events_limit is incremented. */ 229 /* Only log the first time events_limit is incremented. */
230 if (atomic64_inc_return(&pids->events_limit) == 1) { 230 if (atomic64_inc_return(&pids->events_limit) == 1) {
231 pr_info("cgroup: fork rejected by pids controller in "); 231 pr_info("cgroup: fork rejected by pids controller in ");
232 pr_cont_cgroup_path(task_cgroup(current, pids_cgrp_id)); 232 pr_cont_cgroup_path(css->cgroup);
233 pr_cont("\n"); 233 pr_cont("\n");
234 } 234 }
235 cgroup_file_notify(&pids->events_file); 235 cgroup_file_notify(&pids->events_file);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3b31fc05a0f1..ab9f6ac099a7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -86,21 +86,6 @@ int sysctl_sched_rt_runtime = 950000;
86cpumask_var_t cpu_isolated_map; 86cpumask_var_t cpu_isolated_map;
87 87
88/* 88/*
89 * this_rq_lock - lock this runqueue and disable interrupts.
90 */
91static struct rq *this_rq_lock(void)
92 __acquires(rq->lock)
93{
94 struct rq *rq;
95
96 local_irq_disable();
97 rq = this_rq();
98 raw_spin_lock(&rq->lock);
99
100 return rq;
101}
102
103/*
104 * __task_rq_lock - lock the rq @p resides on. 89 * __task_rq_lock - lock the rq @p resides on.
105 */ 90 */
106struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf) 91struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf)
@@ -233,8 +218,11 @@ void update_rq_clock(struct rq *rq)
233 return; 218 return;
234 219
235#ifdef CONFIG_SCHED_DEBUG 220#ifdef CONFIG_SCHED_DEBUG
221 if (sched_feat(WARN_DOUBLE_CLOCK))
222 SCHED_WARN_ON(rq->clock_update_flags & RQCF_UPDATED);
236 rq->clock_update_flags |= RQCF_UPDATED; 223 rq->clock_update_flags |= RQCF_UPDATED;
237#endif 224#endif
225
238 delta = sched_clock_cpu(cpu_of(rq)) - rq->clock; 226 delta = sched_clock_cpu(cpu_of(rq)) - rq->clock;
239 if (delta < 0) 227 if (delta < 0)
240 return; 228 return;
@@ -261,13 +249,14 @@ static void hrtick_clear(struct rq *rq)
261static enum hrtimer_restart hrtick(struct hrtimer *timer) 249static enum hrtimer_restart hrtick(struct hrtimer *timer)
262{ 250{
263 struct rq *rq = container_of(timer, struct rq, hrtick_timer); 251 struct rq *rq = container_of(timer, struct rq, hrtick_timer);
252 struct rq_flags rf;
264 253
265 WARN_ON_ONCE(cpu_of(rq) != smp_processor_id()); 254 WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
266 255
267 raw_spin_lock(&rq->lock); 256 rq_lock(rq, &rf);
268 update_rq_clock(rq); 257 update_rq_clock(rq);
269 rq->curr->sched_class->task_tick(rq, rq->curr, 1); 258 rq->curr->sched_class->task_tick(rq, rq->curr, 1);
270 raw_spin_unlock(&rq->lock); 259 rq_unlock(rq, &rf);
271 260
272 return HRTIMER_NORESTART; 261 return HRTIMER_NORESTART;
273} 262}
@@ -287,11 +276,12 @@ static void __hrtick_restart(struct rq *rq)
287static void __hrtick_start(void *arg) 276static void __hrtick_start(void *arg)
288{ 277{
289 struct rq *rq = arg; 278 struct rq *rq = arg;
279 struct rq_flags rf;
290 280
291 raw_spin_lock(&rq->lock); 281 rq_lock(rq, &rf);
292 __hrtick_restart(rq); 282 __hrtick_restart(rq);
293 rq->hrtick_csd_pending = 0; 283 rq->hrtick_csd_pending = 0;
294 raw_spin_unlock(&rq->lock); 284 rq_unlock(rq, &rf);
295} 285}
296 286
297/* 287/*
@@ -762,17 +752,23 @@ static void set_load_weight(struct task_struct *p)
762 752
763static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags) 753static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
764{ 754{
765 update_rq_clock(rq); 755 if (!(flags & ENQUEUE_NOCLOCK))
756 update_rq_clock(rq);
757
766 if (!(flags & ENQUEUE_RESTORE)) 758 if (!(flags & ENQUEUE_RESTORE))
767 sched_info_queued(rq, p); 759 sched_info_queued(rq, p);
760
768 p->sched_class->enqueue_task(rq, p, flags); 761 p->sched_class->enqueue_task(rq, p, flags);
769} 762}
770 763
771static inline void dequeue_task(struct rq *rq, struct task_struct *p, int flags) 764static inline void dequeue_task(struct rq *rq, struct task_struct *p, int flags)
772{ 765{
773 update_rq_clock(rq); 766 if (!(flags & DEQUEUE_NOCLOCK))
767 update_rq_clock(rq);
768
774 if (!(flags & DEQUEUE_SAVE)) 769 if (!(flags & DEQUEUE_SAVE))
775 sched_info_dequeued(rq, p); 770 sched_info_dequeued(rq, p);
771
776 p->sched_class->dequeue_task(rq, p, flags); 772 p->sched_class->dequeue_task(rq, p, flags);
777} 773}
778 774
@@ -946,18 +942,19 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
946 * 942 *
947 * Returns (locked) new rq. Old rq's lock is released. 943 * Returns (locked) new rq. Old rq's lock is released.
948 */ 944 */
949static struct rq *move_queued_task(struct rq *rq, struct task_struct *p, int new_cpu) 945static struct rq *move_queued_task(struct rq *rq, struct rq_flags *rf,
946 struct task_struct *p, int new_cpu)
950{ 947{
951 lockdep_assert_held(&rq->lock); 948 lockdep_assert_held(&rq->lock);
952 949
953 p->on_rq = TASK_ON_RQ_MIGRATING; 950 p->on_rq = TASK_ON_RQ_MIGRATING;
954 dequeue_task(rq, p, 0); 951 dequeue_task(rq, p, DEQUEUE_NOCLOCK);
955 set_task_cpu(p, new_cpu); 952 set_task_cpu(p, new_cpu);
956 raw_spin_unlock(&rq->lock); 953 rq_unlock(rq, rf);
957 954
958 rq = cpu_rq(new_cpu); 955 rq = cpu_rq(new_cpu);
959 956
960 raw_spin_lock(&rq->lock); 957 rq_lock(rq, rf);
961 BUG_ON(task_cpu(p) != new_cpu); 958 BUG_ON(task_cpu(p) != new_cpu);
962 enqueue_task(rq, p, 0); 959 enqueue_task(rq, p, 0);
963 p->on_rq = TASK_ON_RQ_QUEUED; 960 p->on_rq = TASK_ON_RQ_QUEUED;
@@ -980,7 +977,8 @@ struct migration_arg {
980 * So we race with normal scheduler movements, but that's OK, as long 977 * So we race with normal scheduler movements, but that's OK, as long
981 * as the task is no longer on this CPU. 978 * as the task is no longer on this CPU.
982 */ 979 */
983static struct rq *__migrate_task(struct rq *rq, struct task_struct *p, int dest_cpu) 980static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
981 struct task_struct *p, int dest_cpu)
984{ 982{
985 if (unlikely(!cpu_active(dest_cpu))) 983 if (unlikely(!cpu_active(dest_cpu)))
986 return rq; 984 return rq;
@@ -989,7 +987,8 @@ static struct rq *__migrate_task(struct rq *rq, struct task_struct *p, int dest_
989 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) 987 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
990 return rq; 988 return rq;
991 989
992 rq = move_queued_task(rq, p, dest_cpu); 990 update_rq_clock(rq);
991 rq = move_queued_task(rq, rf, p, dest_cpu);
993 992
994 return rq; 993 return rq;
995} 994}
@@ -1004,6 +1003,7 @@ static int migration_cpu_stop(void *data)
1004 struct migration_arg *arg = data; 1003 struct migration_arg *arg = data;
1005 struct task_struct *p = arg->task; 1004 struct task_struct *p = arg->task;
1006 struct rq *rq = this_rq(); 1005 struct rq *rq = this_rq();
1006 struct rq_flags rf;
1007 1007
1008 /* 1008 /*
1009 * The original target CPU might have gone down and we might 1009 * The original target CPU might have gone down and we might
@@ -1018,7 +1018,7 @@ static int migration_cpu_stop(void *data)
1018 sched_ttwu_pending(); 1018 sched_ttwu_pending();
1019 1019
1020 raw_spin_lock(&p->pi_lock); 1020 raw_spin_lock(&p->pi_lock);
1021 raw_spin_lock(&rq->lock); 1021 rq_lock(rq, &rf);
1022 /* 1022 /*
1023 * If task_rq(p) != rq, it cannot be migrated here, because we're 1023 * If task_rq(p) != rq, it cannot be migrated here, because we're
1024 * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because 1024 * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because
@@ -1026,11 +1026,11 @@ static int migration_cpu_stop(void *data)
1026 */ 1026 */
1027 if (task_rq(p) == rq) { 1027 if (task_rq(p) == rq) {
1028 if (task_on_rq_queued(p)) 1028 if (task_on_rq_queued(p))
1029 rq = __migrate_task(rq, p, arg->dest_cpu); 1029 rq = __migrate_task(rq, &rf, p, arg->dest_cpu);
1030 else 1030 else
1031 p->wake_cpu = arg->dest_cpu; 1031 p->wake_cpu = arg->dest_cpu;
1032 } 1032 }
1033 raw_spin_unlock(&rq->lock); 1033 rq_unlock(rq, &rf);
1034 raw_spin_unlock(&p->pi_lock); 1034 raw_spin_unlock(&p->pi_lock);
1035 1035
1036 local_irq_enable(); 1036 local_irq_enable();
@@ -1063,7 +1063,7 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
1063 * holding rq->lock. 1063 * holding rq->lock.
1064 */ 1064 */
1065 lockdep_assert_held(&rq->lock); 1065 lockdep_assert_held(&rq->lock);
1066 dequeue_task(rq, p, DEQUEUE_SAVE); 1066 dequeue_task(rq, p, DEQUEUE_SAVE | DEQUEUE_NOCLOCK);
1067 } 1067 }
1068 if (running) 1068 if (running)
1069 put_prev_task(rq, p); 1069 put_prev_task(rq, p);
@@ -1071,7 +1071,7 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
1071 p->sched_class->set_cpus_allowed(p, new_mask); 1071 p->sched_class->set_cpus_allowed(p, new_mask);
1072 1072
1073 if (queued) 1073 if (queued)
1074 enqueue_task(rq, p, ENQUEUE_RESTORE); 1074 enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
1075 if (running) 1075 if (running)
1076 set_curr_task(rq, p); 1076 set_curr_task(rq, p);
1077} 1077}
@@ -1150,9 +1150,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
1150 * OK, since we're going to drop the lock immediately 1150 * OK, since we're going to drop the lock immediately
1151 * afterwards anyway. 1151 * afterwards anyway.
1152 */ 1152 */
1153 rq_unpin_lock(rq, &rf); 1153 rq = move_queued_task(rq, &rf, p, dest_cpu);
1154 rq = move_queued_task(rq, p, dest_cpu);
1155 rq_repin_lock(rq, &rf);
1156 } 1154 }
1157out: 1155out:
1158 task_rq_unlock(rq, p, &rf); 1156 task_rq_unlock(rq, p, &rf);
@@ -1217,16 +1215,24 @@ static void __migrate_swap_task(struct task_struct *p, int cpu)
1217{ 1215{
1218 if (task_on_rq_queued(p)) { 1216 if (task_on_rq_queued(p)) {
1219 struct rq *src_rq, *dst_rq; 1217 struct rq *src_rq, *dst_rq;
1218 struct rq_flags srf, drf;
1220 1219
1221 src_rq = task_rq(p); 1220 src_rq = task_rq(p);
1222 dst_rq = cpu_rq(cpu); 1221 dst_rq = cpu_rq(cpu);
1223 1222
1223 rq_pin_lock(src_rq, &srf);
1224 rq_pin_lock(dst_rq, &drf);
1225
1224 p->on_rq = TASK_ON_RQ_MIGRATING; 1226 p->on_rq = TASK_ON_RQ_MIGRATING;
1225 deactivate_task(src_rq, p, 0); 1227 deactivate_task(src_rq, p, 0);
1226 set_task_cpu(p, cpu); 1228 set_task_cpu(p, cpu);
1227 activate_task(dst_rq, p, 0); 1229 activate_task(dst_rq, p, 0);
1228 p->on_rq = TASK_ON_RQ_QUEUED; 1230 p->on_rq = TASK_ON_RQ_QUEUED;
1229 check_preempt_curr(dst_rq, p, 0); 1231 check_preempt_curr(dst_rq, p, 0);
1232
1233 rq_unpin_lock(dst_rq, &drf);
1234 rq_unpin_lock(src_rq, &srf);
1235
1230 } else { 1236 } else {
1231 /* 1237 /*
1232 * Task isn't running anymore; make it appear like we migrated 1238 * Task isn't running anymore; make it appear like we migrated
@@ -1680,7 +1686,7 @@ static void
1680ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, 1686ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
1681 struct rq_flags *rf) 1687 struct rq_flags *rf)
1682{ 1688{
1683 int en_flags = ENQUEUE_WAKEUP; 1689 int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK;
1684 1690
1685 lockdep_assert_held(&rq->lock); 1691 lockdep_assert_held(&rq->lock);
1686 1692
@@ -1726,14 +1732,13 @@ void sched_ttwu_pending(void)
1726 struct rq *rq = this_rq(); 1732 struct rq *rq = this_rq();
1727 struct llist_node *llist = llist_del_all(&rq->wake_list); 1733 struct llist_node *llist = llist_del_all(&rq->wake_list);
1728 struct task_struct *p; 1734 struct task_struct *p;
1729 unsigned long flags;
1730 struct rq_flags rf; 1735 struct rq_flags rf;
1731 1736
1732 if (!llist) 1737 if (!llist)
1733 return; 1738 return;
1734 1739
1735 raw_spin_lock_irqsave(&rq->lock, flags); 1740 rq_lock_irqsave(rq, &rf);
1736 rq_pin_lock(rq, &rf); 1741 update_rq_clock(rq);
1737 1742
1738 while (llist) { 1743 while (llist) {
1739 int wake_flags = 0; 1744 int wake_flags = 0;
@@ -1747,8 +1752,7 @@ void sched_ttwu_pending(void)
1747 ttwu_do_activate(rq, p, wake_flags, &rf); 1752 ttwu_do_activate(rq, p, wake_flags, &rf);
1748 } 1753 }
1749 1754
1750 rq_unpin_lock(rq, &rf); 1755 rq_unlock_irqrestore(rq, &rf);
1751 raw_spin_unlock_irqrestore(&rq->lock, flags);
1752} 1756}
1753 1757
1754void scheduler_ipi(void) 1758void scheduler_ipi(void)
@@ -1806,7 +1810,7 @@ static void ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags)
1806void wake_up_if_idle(int cpu) 1810void wake_up_if_idle(int cpu)
1807{ 1811{
1808 struct rq *rq = cpu_rq(cpu); 1812 struct rq *rq = cpu_rq(cpu);
1809 unsigned long flags; 1813 struct rq_flags rf;
1810 1814
1811 rcu_read_lock(); 1815 rcu_read_lock();
1812 1816
@@ -1816,11 +1820,11 @@ void wake_up_if_idle(int cpu)
1816 if (set_nr_if_polling(rq->idle)) { 1820 if (set_nr_if_polling(rq->idle)) {
1817 trace_sched_wake_idle_without_ipi(cpu); 1821 trace_sched_wake_idle_without_ipi(cpu);
1818 } else { 1822 } else {
1819 raw_spin_lock_irqsave(&rq->lock, flags); 1823 rq_lock_irqsave(rq, &rf);
1820 if (is_idle_task(rq->curr)) 1824 if (is_idle_task(rq->curr))
1821 smp_send_reschedule(cpu); 1825 smp_send_reschedule(cpu);
1822 /* Else CPU is not idle, do nothing here: */ 1826 /* Else CPU is not idle, do nothing here: */
1823 raw_spin_unlock_irqrestore(&rq->lock, flags); 1827 rq_unlock_irqrestore(rq, &rf);
1824 } 1828 }
1825 1829
1826out: 1830out:
@@ -1846,11 +1850,10 @@ static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags)
1846 } 1850 }
1847#endif 1851#endif
1848 1852
1849 raw_spin_lock(&rq->lock); 1853 rq_lock(rq, &rf);
1850 rq_pin_lock(rq, &rf); 1854 update_rq_clock(rq);
1851 ttwu_do_activate(rq, p, wake_flags, &rf); 1855 ttwu_do_activate(rq, p, wake_flags, &rf);
1852 rq_unpin_lock(rq, &rf); 1856 rq_unlock(rq, &rf);
1853 raw_spin_unlock(&rq->lock);
1854} 1857}
1855 1858
1856/* 1859/*
@@ -2097,11 +2100,9 @@ static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf)
2097 * disabled avoiding further scheduler activity on it and we've 2100 * disabled avoiding further scheduler activity on it and we've
2098 * not yet picked a replacement task. 2101 * not yet picked a replacement task.
2099 */ 2102 */
2100 rq_unpin_lock(rq, rf); 2103 rq_unlock(rq, rf);
2101 raw_spin_unlock(&rq->lock);
2102 raw_spin_lock(&p->pi_lock); 2104 raw_spin_lock(&p->pi_lock);
2103 raw_spin_lock(&rq->lock); 2105 rq_relock(rq, rf);
2104 rq_repin_lock(rq, rf);
2105 } 2106 }
2106 2107
2107 if (!(p->state & TASK_NORMAL)) 2108 if (!(p->state & TASK_NORMAL))
@@ -2114,7 +2115,7 @@ static void try_to_wake_up_local(struct task_struct *p, struct rq_flags *rf)
2114 delayacct_blkio_end(); 2115 delayacct_blkio_end();
2115 atomic_dec(&rq->nr_iowait); 2116 atomic_dec(&rq->nr_iowait);
2116 } 2117 }
2117 ttwu_activate(rq, p, ENQUEUE_WAKEUP); 2118 ttwu_activate(rq, p, ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK);
2118 } 2119 }
2119 2120
2120 ttwu_do_wakeup(rq, p, 0, rf); 2121 ttwu_do_wakeup(rq, p, 0, rf);
@@ -2555,7 +2556,7 @@ void wake_up_new_task(struct task_struct *p)
2555 update_rq_clock(rq); 2556 update_rq_clock(rq);
2556 post_init_entity_util_avg(&p->se); 2557 post_init_entity_util_avg(&p->se);
2557 2558
2558 activate_task(rq, p, 0); 2559 activate_task(rq, p, ENQUEUE_NOCLOCK);
2559 p->on_rq = TASK_ON_RQ_QUEUED; 2560 p->on_rq = TASK_ON_RQ_QUEUED;
2560 trace_sched_wakeup_new(p); 2561 trace_sched_wakeup_new(p);
2561 check_preempt_curr(rq, p, WF_FORK); 2562 check_preempt_curr(rq, p, WF_FORK);
@@ -3093,15 +3094,18 @@ void scheduler_tick(void)
3093 int cpu = smp_processor_id(); 3094 int cpu = smp_processor_id();
3094 struct rq *rq = cpu_rq(cpu); 3095 struct rq *rq = cpu_rq(cpu);
3095 struct task_struct *curr = rq->curr; 3096 struct task_struct *curr = rq->curr;
3097 struct rq_flags rf;
3096 3098
3097 sched_clock_tick(); 3099 sched_clock_tick();
3098 3100
3099 raw_spin_lock(&rq->lock); 3101 rq_lock(rq, &rf);
3102
3100 update_rq_clock(rq); 3103 update_rq_clock(rq);
3101 curr->sched_class->task_tick(rq, curr, 0); 3104 curr->sched_class->task_tick(rq, curr, 0);
3102 cpu_load_update_active(rq); 3105 cpu_load_update_active(rq);
3103 calc_global_load_tick(rq); 3106 calc_global_load_tick(rq);
3104 raw_spin_unlock(&rq->lock); 3107
3108 rq_unlock(rq, &rf);
3105 3109
3106 perf_event_task_tick(); 3110 perf_event_task_tick();
3107 3111
@@ -3386,18 +3390,18 @@ static void __sched notrace __schedule(bool preempt)
3386 * done by the caller to avoid the race with signal_wake_up(). 3390 * done by the caller to avoid the race with signal_wake_up().
3387 */ 3391 */
3388 smp_mb__before_spinlock(); 3392 smp_mb__before_spinlock();
3389 raw_spin_lock(&rq->lock); 3393 rq_lock(rq, &rf);
3390 rq_pin_lock(rq, &rf);
3391 3394
3392 /* Promote REQ to ACT */ 3395 /* Promote REQ to ACT */
3393 rq->clock_update_flags <<= 1; 3396 rq->clock_update_flags <<= 1;
3397 update_rq_clock(rq);
3394 3398
3395 switch_count = &prev->nivcsw; 3399 switch_count = &prev->nivcsw;
3396 if (!preempt && prev->state) { 3400 if (!preempt && prev->state) {
3397 if (unlikely(signal_pending_state(prev->state, prev))) { 3401 if (unlikely(signal_pending_state(prev->state, prev))) {
3398 prev->state = TASK_RUNNING; 3402 prev->state = TASK_RUNNING;
3399 } else { 3403 } else {
3400 deactivate_task(rq, prev, DEQUEUE_SLEEP); 3404 deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK);
3401 prev->on_rq = 0; 3405 prev->on_rq = 0;
3402 3406
3403 if (prev->in_iowait) { 3407 if (prev->in_iowait) {
@@ -3421,9 +3425,6 @@ static void __sched notrace __schedule(bool preempt)
3421 switch_count = &prev->nvcsw; 3425 switch_count = &prev->nvcsw;
3422 } 3426 }
3423 3427
3424 if (task_on_rq_queued(prev))
3425 update_rq_clock(rq);
3426
3427 next = pick_next_task(rq, prev, &rf); 3428 next = pick_next_task(rq, prev, &rf);
3428 clear_tsk_need_resched(prev); 3429 clear_tsk_need_resched(prev);
3429 clear_preempt_need_resched(); 3430 clear_preempt_need_resched();
@@ -3439,8 +3440,7 @@ static void __sched notrace __schedule(bool preempt)
3439 rq = context_switch(rq, prev, next, &rf); 3440 rq = context_switch(rq, prev, next, &rf);
3440 } else { 3441 } else {
3441 rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); 3442 rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP);
3442 rq_unpin_lock(rq, &rf); 3443 rq_unlock_irq(rq, &rf);
3443 raw_spin_unlock_irq(&rq->lock);
3444 } 3444 }
3445 3445
3446 balance_callback(rq); 3446 balance_callback(rq);
@@ -3684,7 +3684,8 @@ EXPORT_SYMBOL(default_wake_function);
3684 */ 3684 */
3685void rt_mutex_setprio(struct task_struct *p, int prio) 3685void rt_mutex_setprio(struct task_struct *p, int prio)
3686{ 3686{
3687 int oldprio, queued, running, queue_flag = DEQUEUE_SAVE | DEQUEUE_MOVE; 3687 int oldprio, queued, running, queue_flag =
3688 DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
3688 const struct sched_class *prev_class; 3689 const struct sched_class *prev_class;
3689 struct rq_flags rf; 3690 struct rq_flags rf;
3690 struct rq *rq; 3691 struct rq *rq;
@@ -3805,7 +3806,7 @@ void set_user_nice(struct task_struct *p, long nice)
3805 queued = task_on_rq_queued(p); 3806 queued = task_on_rq_queued(p);
3806 running = task_current(rq, p); 3807 running = task_current(rq, p);
3807 if (queued) 3808 if (queued)
3808 dequeue_task(rq, p, DEQUEUE_SAVE); 3809 dequeue_task(rq, p, DEQUEUE_SAVE | DEQUEUE_NOCLOCK);
3809 if (running) 3810 if (running)
3810 put_prev_task(rq, p); 3811 put_prev_task(rq, p);
3811 3812
@@ -3816,7 +3817,7 @@ void set_user_nice(struct task_struct *p, long nice)
3816 delta = p->prio - old_prio; 3817 delta = p->prio - old_prio;
3817 3818
3818 if (queued) { 3819 if (queued) {
3819 enqueue_task(rq, p, ENQUEUE_RESTORE); 3820 enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
3820 /* 3821 /*
3821 * If the task increased its priority or is running and 3822 * If the task increased its priority or is running and
3822 * lowered its priority, then reschedule its CPU: 3823 * lowered its priority, then reschedule its CPU:
@@ -4126,7 +4127,7 @@ static int __sched_setscheduler(struct task_struct *p,
4126 const struct sched_class *prev_class; 4127 const struct sched_class *prev_class;
4127 struct rq_flags rf; 4128 struct rq_flags rf;
4128 int reset_on_fork; 4129 int reset_on_fork;
4129 int queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE; 4130 int queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
4130 struct rq *rq; 4131 struct rq *rq;
4131 4132
4132 /* May grab non-irq protected spin_locks: */ 4133 /* May grab non-irq protected spin_locks: */
@@ -4923,7 +4924,12 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
4923 */ 4924 */
4924SYSCALL_DEFINE0(sched_yield) 4925SYSCALL_DEFINE0(sched_yield)
4925{ 4926{
4926 struct rq *rq = this_rq_lock(); 4927 struct rq_flags rf;
4928 struct rq *rq;
4929
4930 local_irq_disable();
4931 rq = this_rq();
4932 rq_lock(rq, &rf);
4927 4933
4928 schedstat_inc(rq->yld_count); 4934 schedstat_inc(rq->yld_count);
4929 current->sched_class->yield_task(rq); 4935 current->sched_class->yield_task(rq);
@@ -4932,9 +4938,8 @@ SYSCALL_DEFINE0(sched_yield)
4932 * Since we are going to call schedule() anyway, there's 4938 * Since we are going to call schedule() anyway, there's
4933 * no need to preempt or enable interrupts: 4939 * no need to preempt or enable interrupts:
4934 */ 4940 */
4935 __release(rq->lock); 4941 preempt_disable();
4936 spin_release(&rq->lock.dep_map, 1, _THIS_IP_); 4942 rq_unlock(rq, &rf);
4937 do_raw_spin_unlock(&rq->lock);
4938 sched_preempt_enable_no_resched(); 4943 sched_preempt_enable_no_resched();
4939 4944
4940 schedule(); 4945 schedule();
@@ -5514,7 +5519,7 @@ void sched_setnuma(struct task_struct *p, int nid)
5514 p->numa_preferred_nid = nid; 5519 p->numa_preferred_nid = nid;
5515 5520
5516 if (queued) 5521 if (queued)
5517 enqueue_task(rq, p, ENQUEUE_RESTORE); 5522 enqueue_task(rq, p, ENQUEUE_RESTORE | ENQUEUE_NOCLOCK);
5518 if (running) 5523 if (running)
5519 set_curr_task(rq, p); 5524 set_curr_task(rq, p);
5520 task_rq_unlock(rq, p, &rf); 5525 task_rq_unlock(rq, p, &rf);
@@ -5579,11 +5584,11 @@ static struct task_struct fake_task = {
5579 * there's no concurrency possible, we hold the required locks anyway 5584 * there's no concurrency possible, we hold the required locks anyway
5580 * because of lock validation efforts. 5585 * because of lock validation efforts.
5581 */ 5586 */
5582static void migrate_tasks(struct rq *dead_rq) 5587static void migrate_tasks(struct rq *dead_rq, struct rq_flags *rf)
5583{ 5588{
5584 struct rq *rq = dead_rq; 5589 struct rq *rq = dead_rq;
5585 struct task_struct *next, *stop = rq->stop; 5590 struct task_struct *next, *stop = rq->stop;
5586 struct rq_flags rf; 5591 struct rq_flags orf = *rf;
5587 int dest_cpu; 5592 int dest_cpu;
5588 5593
5589 /* 5594 /*
@@ -5602,9 +5607,7 @@ static void migrate_tasks(struct rq *dead_rq)
5602 * class method both need to have an up-to-date 5607 * class method both need to have an up-to-date
5603 * value of rq->clock[_task] 5608 * value of rq->clock[_task]
5604 */ 5609 */
5605 rq_pin_lock(rq, &rf);
5606 update_rq_clock(rq); 5610 update_rq_clock(rq);
5607 rq_unpin_lock(rq, &rf);
5608 5611
5609 for (;;) { 5612 for (;;) {
5610 /* 5613 /*
@@ -5617,8 +5620,7 @@ static void migrate_tasks(struct rq *dead_rq)
5617 /* 5620 /*
5618 * pick_next_task() assumes pinned rq->lock: 5621 * pick_next_task() assumes pinned rq->lock:
5619 */ 5622 */
5620 rq_repin_lock(rq, &rf); 5623 next = pick_next_task(rq, &fake_task, rf);
5621 next = pick_next_task(rq, &fake_task, &rf);
5622 BUG_ON(!next); 5624 BUG_ON(!next);
5623 next->sched_class->put_prev_task(rq, next); 5625 next->sched_class->put_prev_task(rq, next);
5624 5626
@@ -5631,10 +5633,9 @@ static void migrate_tasks(struct rq *dead_rq)
5631 * because !cpu_active at this point, which means load-balance 5633 * because !cpu_active at this point, which means load-balance
5632 * will not interfere. Also, stop-machine. 5634 * will not interfere. Also, stop-machine.
5633 */ 5635 */
5634 rq_unpin_lock(rq, &rf); 5636 rq_unlock(rq, rf);
5635 raw_spin_unlock(&rq->lock);
5636 raw_spin_lock(&next->pi_lock); 5637 raw_spin_lock(&next->pi_lock);
5637 raw_spin_lock(&rq->lock); 5638 rq_relock(rq, rf);
5638 5639
5639 /* 5640 /*
5640 * Since we're inside stop-machine, _nothing_ should have 5641 * Since we're inside stop-machine, _nothing_ should have
@@ -5648,12 +5649,12 @@ static void migrate_tasks(struct rq *dead_rq)
5648 5649
5649 /* Find suitable destination for @next, with force if needed. */ 5650 /* Find suitable destination for @next, with force if needed. */
5650 dest_cpu = select_fallback_rq(dead_rq->cpu, next); 5651 dest_cpu = select_fallback_rq(dead_rq->cpu, next);
5651 5652 rq = __migrate_task(rq, rf, next, dest_cpu);
5652 rq = __migrate_task(rq, next, dest_cpu);
5653 if (rq != dead_rq) { 5653 if (rq != dead_rq) {
5654 raw_spin_unlock(&rq->lock); 5654 rq_unlock(rq, rf);
5655 rq = dead_rq; 5655 rq = dead_rq;
5656 raw_spin_lock(&rq->lock); 5656 *rf = orf;
5657 rq_relock(rq, rf);
5657 } 5658 }
5658 raw_spin_unlock(&next->pi_lock); 5659 raw_spin_unlock(&next->pi_lock);
5659 } 5660 }
@@ -5766,7 +5767,7 @@ static int cpuset_cpu_inactive(unsigned int cpu)
5766int sched_cpu_activate(unsigned int cpu) 5767int sched_cpu_activate(unsigned int cpu)
5767{ 5768{
5768 struct rq *rq = cpu_rq(cpu); 5769 struct rq *rq = cpu_rq(cpu);
5769 unsigned long flags; 5770 struct rq_flags rf;
5770 5771
5771 set_cpu_active(cpu, true); 5772 set_cpu_active(cpu, true);
5772 5773
@@ -5784,12 +5785,12 @@ int sched_cpu_activate(unsigned int cpu)
5784 * 2) At runtime, if cpuset_cpu_active() fails to rebuild the 5785 * 2) At runtime, if cpuset_cpu_active() fails to rebuild the
5785 * domains. 5786 * domains.
5786 */ 5787 */
5787 raw_spin_lock_irqsave(&rq->lock, flags); 5788 rq_lock_irqsave(rq, &rf);
5788 if (rq->rd) { 5789 if (rq->rd) {
5789 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); 5790 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
5790 set_rq_online(rq); 5791 set_rq_online(rq);
5791 } 5792 }
5792 raw_spin_unlock_irqrestore(&rq->lock, flags); 5793 rq_unlock_irqrestore(rq, &rf);
5793 5794
5794 update_max_interval(); 5795 update_max_interval();
5795 5796
@@ -5847,18 +5848,20 @@ int sched_cpu_starting(unsigned int cpu)
5847int sched_cpu_dying(unsigned int cpu) 5848int sched_cpu_dying(unsigned int cpu)
5848{ 5849{
5849 struct rq *rq = cpu_rq(cpu); 5850 struct rq *rq = cpu_rq(cpu);
5850 unsigned long flags; 5851 struct rq_flags rf;
5851 5852
5852 /* Handle pending wakeups and then migrate everything off */ 5853 /* Handle pending wakeups and then migrate everything off */
5853 sched_ttwu_pending(); 5854 sched_ttwu_pending();
5854 raw_spin_lock_irqsave(&rq->lock, flags); 5855
5856 rq_lock_irqsave(rq, &rf);
5855 if (rq->rd) { 5857 if (rq->rd) {
5856 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); 5858 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
5857 set_rq_offline(rq); 5859 set_rq_offline(rq);
5858 } 5860 }
5859 migrate_tasks(rq); 5861 migrate_tasks(rq, &rf);
5860 BUG_ON(rq->nr_running != 1); 5862 BUG_ON(rq->nr_running != 1);
5861 raw_spin_unlock_irqrestore(&rq->lock, flags); 5863 rq_unlock_irqrestore(rq, &rf);
5864
5862 calc_load_migrate(rq); 5865 calc_load_migrate(rq);
5863 update_max_interval(); 5866 update_max_interval();
5864 nohz_balance_exit_idle(cpu); 5867 nohz_balance_exit_idle(cpu);
@@ -6412,7 +6415,8 @@ static void sched_change_group(struct task_struct *tsk, int type)
6412 */ 6415 */
6413void sched_move_task(struct task_struct *tsk) 6416void sched_move_task(struct task_struct *tsk)
6414{ 6417{
6415 int queued, running; 6418 int queued, running, queue_flags =
6419 DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
6416 struct rq_flags rf; 6420 struct rq_flags rf;
6417 struct rq *rq; 6421 struct rq *rq;
6418 6422
@@ -6423,14 +6427,14 @@ void sched_move_task(struct task_struct *tsk)
6423 queued = task_on_rq_queued(tsk); 6427 queued = task_on_rq_queued(tsk);
6424 6428
6425 if (queued) 6429 if (queued)
6426 dequeue_task(rq, tsk, DEQUEUE_SAVE | DEQUEUE_MOVE); 6430 dequeue_task(rq, tsk, queue_flags);
6427 if (running) 6431 if (running)
6428 put_prev_task(rq, tsk); 6432 put_prev_task(rq, tsk);
6429 6433
6430 sched_change_group(tsk, TASK_MOVE_GROUP); 6434 sched_change_group(tsk, TASK_MOVE_GROUP);
6431 6435
6432 if (queued) 6436 if (queued)
6433 enqueue_task(rq, tsk, ENQUEUE_RESTORE | ENQUEUE_MOVE); 6437 enqueue_task(rq, tsk, queue_flags);
6434 if (running) 6438 if (running)
6435 set_curr_task(rq, tsk); 6439 set_curr_task(rq, tsk);
6436 6440
@@ -7008,14 +7012,15 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota)
7008 for_each_online_cpu(i) { 7012 for_each_online_cpu(i) {
7009 struct cfs_rq *cfs_rq = tg->cfs_rq[i]; 7013 struct cfs_rq *cfs_rq = tg->cfs_rq[i];
7010 struct rq *rq = cfs_rq->rq; 7014 struct rq *rq = cfs_rq->rq;
7015 struct rq_flags rf;
7011 7016
7012 raw_spin_lock_irq(&rq->lock); 7017 rq_lock_irq(rq, &rf);
7013 cfs_rq->runtime_enabled = runtime_enabled; 7018 cfs_rq->runtime_enabled = runtime_enabled;
7014 cfs_rq->runtime_remaining = 0; 7019 cfs_rq->runtime_remaining = 0;
7015 7020
7016 if (cfs_rq->throttled) 7021 if (cfs_rq->throttled)
7017 unthrottle_cfs_rq(cfs_rq); 7022 unthrottle_cfs_rq(cfs_rq);
7018 raw_spin_unlock_irq(&rq->lock); 7023 rq_unlock_irq(rq, &rf);
7019 } 7024 }
7020 if (runtime_was_enabled && !runtime_enabled) 7025 if (runtime_was_enabled && !runtime_enabled)
7021 cfs_bandwidth_usage_dec(); 7026 cfs_bandwidth_usage_dec();
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 99b2c33a9fbc..a2ce59015642 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -445,13 +445,13 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se,
445 * 445 *
446 * This function returns true if: 446 * This function returns true if:
447 * 447 *
448 * runtime / (deadline - t) > dl_runtime / dl_period , 448 * runtime / (deadline - t) > dl_runtime / dl_deadline ,
449 * 449 *
450 * IOW we can't recycle current parameters. 450 * IOW we can't recycle current parameters.
451 * 451 *
452 * Notice that the bandwidth check is done against the period. For 452 * Notice that the bandwidth check is done against the deadline. For
453 * task with deadline equal to period this is the same of using 453 * task with deadline equal to period this is the same of using
454 * dl_deadline instead of dl_period in the equation above. 454 * dl_period instead of dl_deadline in the equation above.
455 */ 455 */
456static bool dl_entity_overflow(struct sched_dl_entity *dl_se, 456static bool dl_entity_overflow(struct sched_dl_entity *dl_se,
457 struct sched_dl_entity *pi_se, u64 t) 457 struct sched_dl_entity *pi_se, u64 t)
@@ -476,7 +476,7 @@ static bool dl_entity_overflow(struct sched_dl_entity *dl_se,
476 * of anything below microseconds resolution is actually fiction 476 * of anything below microseconds resolution is actually fiction
477 * (but still we want to give the user that illusion >;). 477 * (but still we want to give the user that illusion >;).
478 */ 478 */
479 left = (pi_se->dl_period >> DL_SCALE) * (dl_se->runtime >> DL_SCALE); 479 left = (pi_se->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE);
480 right = ((dl_se->deadline - t) >> DL_SCALE) * 480 right = ((dl_se->deadline - t) >> DL_SCALE) *
481 (pi_se->dl_runtime >> DL_SCALE); 481 (pi_se->dl_runtime >> DL_SCALE);
482 482
@@ -505,10 +505,15 @@ static void update_dl_entity(struct sched_dl_entity *dl_se,
505 } 505 }
506} 506}
507 507
508static inline u64 dl_next_period(struct sched_dl_entity *dl_se)
509{
510 return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period;
511}
512
508/* 513/*
509 * If the entity depleted all its runtime, and if we want it to sleep 514 * If the entity depleted all its runtime, and if we want it to sleep
510 * while waiting for some new execution time to become available, we 515 * while waiting for some new execution time to become available, we
511 * set the bandwidth enforcement timer to the replenishment instant 516 * set the bandwidth replenishment timer to the replenishment instant
512 * and try to activate it. 517 * and try to activate it.
513 * 518 *
514 * Notice that it is important for the caller to know if the timer 519 * Notice that it is important for the caller to know if the timer
@@ -530,7 +535,7 @@ static int start_dl_timer(struct task_struct *p)
530 * that it is actually coming from rq->clock and not from 535 * that it is actually coming from rq->clock and not from
531 * hrtimer's time base reading. 536 * hrtimer's time base reading.
532 */ 537 */
533 act = ns_to_ktime(dl_se->deadline); 538 act = ns_to_ktime(dl_next_period(dl_se));
534 now = hrtimer_cb_get_time(timer); 539 now = hrtimer_cb_get_time(timer);
535 delta = ktime_to_ns(now) - rq_clock(rq); 540 delta = ktime_to_ns(now) - rq_clock(rq);
536 act = ktime_add_ns(act, delta); 541 act = ktime_add_ns(act, delta);
@@ -638,6 +643,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
638 lockdep_unpin_lock(&rq->lock, rf.cookie); 643 lockdep_unpin_lock(&rq->lock, rf.cookie);
639 rq = dl_task_offline_migration(rq, p); 644 rq = dl_task_offline_migration(rq, p);
640 rf.cookie = lockdep_pin_lock(&rq->lock); 645 rf.cookie = lockdep_pin_lock(&rq->lock);
646 update_rq_clock(rq);
641 647
642 /* 648 /*
643 * Now that the task has been migrated to the new RQ and we 649 * Now that the task has been migrated to the new RQ and we
@@ -689,6 +695,37 @@ void init_dl_task_timer(struct sched_dl_entity *dl_se)
689 timer->function = dl_task_timer; 695 timer->function = dl_task_timer;
690} 696}
691 697
698/*
699 * During the activation, CBS checks if it can reuse the current task's
700 * runtime and period. If the deadline of the task is in the past, CBS
701 * cannot use the runtime, and so it replenishes the task. This rule
702 * works fine for implicit deadline tasks (deadline == period), and the
703 * CBS was designed for implicit deadline tasks. However, a task with
704 * constrained deadline (deadine < period) might be awakened after the
705 * deadline, but before the next period. In this case, replenishing the
706 * task would allow it to run for runtime / deadline. As in this case
707 * deadline < period, CBS enables a task to run for more than the
708 * runtime / period. In a very loaded system, this can cause a domino
709 * effect, making other tasks miss their deadlines.
710 *
711 * To avoid this problem, in the activation of a constrained deadline
712 * task after the deadline but before the next period, throttle the
713 * task and set the replenishing timer to the begin of the next period,
714 * unless it is boosted.
715 */
716static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se)
717{
718 struct task_struct *p = dl_task_of(dl_se);
719 struct rq *rq = rq_of_dl_rq(dl_rq_of_se(dl_se));
720
721 if (dl_time_before(dl_se->deadline, rq_clock(rq)) &&
722 dl_time_before(rq_clock(rq), dl_next_period(dl_se))) {
723 if (unlikely(dl_se->dl_boosted || !start_dl_timer(p)))
724 return;
725 dl_se->dl_throttled = 1;
726 }
727}
728
692static 729static
693int dl_runtime_exceeded(struct sched_dl_entity *dl_se) 730int dl_runtime_exceeded(struct sched_dl_entity *dl_se)
694{ 731{
@@ -922,6 +959,11 @@ static void dequeue_dl_entity(struct sched_dl_entity *dl_se)
922 __dequeue_dl_entity(dl_se); 959 __dequeue_dl_entity(dl_se);
923} 960}
924 961
962static inline bool dl_is_constrained(struct sched_dl_entity *dl_se)
963{
964 return dl_se->dl_deadline < dl_se->dl_period;
965}
966
925static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) 967static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
926{ 968{
927 struct task_struct *pi_task = rt_mutex_get_top_task(p); 969 struct task_struct *pi_task = rt_mutex_get_top_task(p);
@@ -948,6 +990,15 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
948 } 990 }
949 991
950 /* 992 /*
993 * Check if a constrained deadline task was activated
994 * after the deadline but before the next period.
995 * If that is the case, the task will be throttled and
996 * the replenishment timer will be set to the next period.
997 */
998 if (!p->dl.dl_throttled && dl_is_constrained(&p->dl))
999 dl_check_constrained_dl(&p->dl);
1000
1001 /*
951 * If p is throttled, we do nothing. In fact, if it exhausted 1002 * If p is throttled, we do nothing. In fact, if it exhausted
952 * its budget it needs a replenishment and, since it now is on 1003 * its budget it needs a replenishment and, since it now is on
953 * its rq, the bandwidth timer callback (which clearly has not 1004 * its rq, the bandwidth timer callback (which clearly has not
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index dea138964b91..76f67b3e34d6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2767,7 +2767,7 @@ static const u32 __accumulated_sum_N32[] = {
2767 * Approximate: 2767 * Approximate:
2768 * val * y^n, where y^32 ~= 0.5 (~1 scheduling period) 2768 * val * y^n, where y^32 ~= 0.5 (~1 scheduling period)
2769 */ 2769 */
2770static __always_inline u64 decay_load(u64 val, u64 n) 2770static u64 decay_load(u64 val, u64 n)
2771{ 2771{
2772 unsigned int local_n; 2772 unsigned int local_n;
2773 2773
@@ -2795,32 +2795,113 @@ static __always_inline u64 decay_load(u64 val, u64 n)
2795 return val; 2795 return val;
2796} 2796}
2797 2797
2798/* 2798static u32 __accumulate_sum(u64 periods, u32 period_contrib, u32 remainder)
2799 * For updates fully spanning n periods, the contribution to runnable
2800 * average will be: \Sum 1024*y^n
2801 *
2802 * We can compute this reasonably efficiently by combining:
2803 * y^PERIOD = 1/2 with precomputed \Sum 1024*y^n {for n <PERIOD}
2804 */
2805static u32 __compute_runnable_contrib(u64 n)
2806{ 2799{
2807 u32 contrib = 0; 2800 u32 c1, c2, c3 = remainder; /* y^0 == 1 */
2801
2802 if (!periods)
2803 return remainder - period_contrib;
2808 2804
2809 if (likely(n <= LOAD_AVG_PERIOD)) 2805 if (unlikely(periods >= LOAD_AVG_MAX_N))
2810 return runnable_avg_yN_sum[n];
2811 else if (unlikely(n >= LOAD_AVG_MAX_N))
2812 return LOAD_AVG_MAX; 2806 return LOAD_AVG_MAX;
2813 2807
2814 /* Since n < LOAD_AVG_MAX_N, n/LOAD_AVG_PERIOD < 11 */ 2808 /*
2815 contrib = __accumulated_sum_N32[n/LOAD_AVG_PERIOD]; 2809 * c1 = d1 y^(p+1)
2816 n %= LOAD_AVG_PERIOD; 2810 */
2817 contrib = decay_load(contrib, n); 2811 c1 = decay_load((u64)(1024 - period_contrib), periods);
2818 return contrib + runnable_avg_yN_sum[n]; 2812
2813 periods -= 1;
2814 /*
2815 * For updates fully spanning n periods, the contribution to runnable
2816 * average will be:
2817 *
2818 * c2 = 1024 \Sum y^n
2819 *
2820 * We can compute this reasonably efficiently by combining:
2821 *
2822 * y^PERIOD = 1/2 with precomputed 1024 \Sum y^n {for: n < PERIOD}
2823 */
2824 if (likely(periods <= LOAD_AVG_PERIOD)) {
2825 c2 = runnable_avg_yN_sum[periods];
2826 } else {
2827 c2 = __accumulated_sum_N32[periods/LOAD_AVG_PERIOD];
2828 periods %= LOAD_AVG_PERIOD;
2829 c2 = decay_load(c2, periods);
2830 c2 += runnable_avg_yN_sum[periods];
2831 }
2832
2833 return c1 + c2 + c3;
2819} 2834}
2820 2835
2821#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT) 2836#define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
2822 2837
2823/* 2838/*
2839 * Accumulate the three separate parts of the sum; d1 the remainder
2840 * of the last (incomplete) period, d2 the span of full periods and d3
2841 * the remainder of the (incomplete) current period.
2842 *
2843 * d1 d2 d3
2844 * ^ ^ ^
2845 * | | |
2846 * |<->|<----------------->|<--->|
2847 * ... |---x---|------| ... |------|-----x (now)
2848 *
2849 * p
2850 * u' = (u + d1) y^(p+1) + 1024 \Sum y^n + d3 y^0
2851 * n=1
2852 *
2853 * = u y^(p+1) + (Step 1)
2854 *
2855 * p
2856 * d1 y^(p+1) + 1024 \Sum y^n + d3 y^0 (Step 2)
2857 * n=1
2858 */
2859static __always_inline u32
2860accumulate_sum(u64 delta, int cpu, struct sched_avg *sa,
2861 unsigned long weight, int running, struct cfs_rq *cfs_rq)
2862{
2863 unsigned long scale_freq, scale_cpu;
2864 u64 periods;
2865 u32 contrib;
2866
2867 scale_freq = arch_scale_freq_capacity(NULL, cpu);
2868 scale_cpu = arch_scale_cpu_capacity(NULL, cpu);
2869
2870 delta += sa->period_contrib;
2871 periods = delta / 1024; /* A period is 1024us (~1ms) */
2872
2873 /*
2874 * Step 1: decay old *_sum if we crossed period boundaries.
2875 */
2876 if (periods) {
2877 sa->load_sum = decay_load(sa->load_sum, periods);
2878 if (cfs_rq) {
2879 cfs_rq->runnable_load_sum =
2880 decay_load(cfs_rq->runnable_load_sum, periods);
2881 }
2882 sa->util_sum = decay_load((u64)(sa->util_sum), periods);
2883 }
2884
2885 /*
2886 * Step 2
2887 */
2888 delta %= 1024;
2889 contrib = __accumulate_sum(periods, sa->period_contrib, delta);
2890 sa->period_contrib = delta;
2891
2892 contrib = cap_scale(contrib, scale_freq);
2893 if (weight) {
2894 sa->load_sum += weight * contrib;
2895 if (cfs_rq)
2896 cfs_rq->runnable_load_sum += weight * contrib;
2897 }
2898 if (running)
2899 sa->util_sum += contrib * scale_cpu;
2900
2901 return periods;
2902}
2903
2904/*
2824 * We can represent the historical contribution to runnable average as the 2905 * We can represent the historical contribution to runnable average as the
2825 * coefficients of a geometric series. To do this we sub-divide our runnable 2906 * coefficients of a geometric series. To do this we sub-divide our runnable
2826 * history into segments of approximately 1ms (1024us); label the segment that 2907 * history into segments of approximately 1ms (1024us); label the segment that
@@ -2849,13 +2930,10 @@ static u32 __compute_runnable_contrib(u64 n)
2849 * = u_0 + u_1*y + u_2*y^2 + ... [re-labeling u_i --> u_{i+1}] 2930 * = u_0 + u_1*y + u_2*y^2 + ... [re-labeling u_i --> u_{i+1}]
2850 */ 2931 */
2851static __always_inline int 2932static __always_inline int
2852__update_load_avg(u64 now, int cpu, struct sched_avg *sa, 2933___update_load_avg(u64 now, int cpu, struct sched_avg *sa,
2853 unsigned long weight, int running, struct cfs_rq *cfs_rq) 2934 unsigned long weight, int running, struct cfs_rq *cfs_rq)
2854{ 2935{
2855 u64 delta, scaled_delta, periods; 2936 u64 delta;
2856 u32 contrib;
2857 unsigned int delta_w, scaled_delta_w, decayed = 0;
2858 unsigned long scale_freq, scale_cpu;
2859 2937
2860 delta = now - sa->last_update_time; 2938 delta = now - sa->last_update_time;
2861 /* 2939 /*
@@ -2876,81 +2954,49 @@ __update_load_avg(u64 now, int cpu, struct sched_avg *sa,
2876 return 0; 2954 return 0;
2877 sa->last_update_time = now; 2955 sa->last_update_time = now;
2878 2956
2879 scale_freq = arch_scale_freq_capacity(NULL, cpu); 2957 /*
2880 scale_cpu = arch_scale_cpu_capacity(NULL, cpu); 2958 * Now we know we crossed measurement unit boundaries. The *_avg
2881 2959 * accrues by two steps:
2882 /* delta_w is the amount already accumulated against our next period */ 2960 *
2883 delta_w = sa->period_contrib; 2961 * Step 1: accumulate *_sum since last_update_time. If we haven't
2884 if (delta + delta_w >= 1024) { 2962 * crossed period boundaries, finish.
2885 decayed = 1; 2963 */
2886 2964 if (!accumulate_sum(delta, cpu, sa, weight, running, cfs_rq))
2887 /* how much left for next period will start over, we don't know yet */ 2965 return 0;
2888 sa->period_contrib = 0;
2889
2890 /*
2891 * Now that we know we're crossing a period boundary, figure
2892 * out how much from delta we need to complete the current
2893 * period and accrue it.
2894 */
2895 delta_w = 1024 - delta_w;
2896 scaled_delta_w = cap_scale(delta_w, scale_freq);
2897 if (weight) {
2898 sa->load_sum += weight * scaled_delta_w;
2899 if (cfs_rq) {
2900 cfs_rq->runnable_load_sum +=
2901 weight * scaled_delta_w;
2902 }
2903 }
2904 if (running)
2905 sa->util_sum += scaled_delta_w * scale_cpu;
2906
2907 delta -= delta_w;
2908
2909 /* Figure out how many additional periods this update spans */
2910 periods = delta / 1024;
2911 delta %= 1024;
2912 2966
2913 sa->load_sum = decay_load(sa->load_sum, periods + 1); 2967 /*
2914 if (cfs_rq) { 2968 * Step 2: update *_avg.
2915 cfs_rq->runnable_load_sum = 2969 */
2916 decay_load(cfs_rq->runnable_load_sum, periods + 1); 2970 sa->load_avg = div_u64(sa->load_sum, LOAD_AVG_MAX);
2917 } 2971 if (cfs_rq) {
2918 sa->util_sum = decay_load((u64)(sa->util_sum), periods + 1); 2972 cfs_rq->runnable_load_avg =
2919 2973 div_u64(cfs_rq->runnable_load_sum, LOAD_AVG_MAX);
2920 /* Efficiently calculate \sum (1..n_period) 1024*y^i */
2921 contrib = __compute_runnable_contrib(periods);
2922 contrib = cap_scale(contrib, scale_freq);
2923 if (weight) {
2924 sa->load_sum += weight * contrib;
2925 if (cfs_rq)
2926 cfs_rq->runnable_load_sum += weight * contrib;
2927 }
2928 if (running)
2929 sa->util_sum += contrib * scale_cpu;
2930 } 2974 }
2975 sa->util_avg = sa->util_sum / LOAD_AVG_MAX;
2931 2976
2932 /* Remainder of delta accrued against u_0` */ 2977 return 1;
2933 scaled_delta = cap_scale(delta, scale_freq); 2978}
2934 if (weight) {
2935 sa->load_sum += weight * scaled_delta;
2936 if (cfs_rq)
2937 cfs_rq->runnable_load_sum += weight * scaled_delta;
2938 }
2939 if (running)
2940 sa->util_sum += scaled_delta * scale_cpu;
2941 2979
2942 sa->period_contrib += delta; 2980static int
2981__update_load_avg_blocked_se(u64 now, int cpu, struct sched_entity *se)
2982{
2983 return ___update_load_avg(now, cpu, &se->avg, 0, 0, NULL);
2984}
2943 2985
2944 if (decayed) { 2986static int
2945 sa->load_avg = div_u64(sa->load_sum, LOAD_AVG_MAX); 2987__update_load_avg_se(u64 now, int cpu, struct cfs_rq *cfs_rq, struct sched_entity *se)
2946 if (cfs_rq) { 2988{
2947 cfs_rq->runnable_load_avg = 2989 return ___update_load_avg(now, cpu, &se->avg,
2948 div_u64(cfs_rq->runnable_load_sum, LOAD_AVG_MAX); 2990 se->on_rq * scale_load_down(se->load.weight),
2949 } 2991 cfs_rq->curr == se, NULL);
2950 sa->util_avg = sa->util_sum / LOAD_AVG_MAX; 2992}
2951 }
2952 2993
2953 return decayed; 2994static int
2995__update_load_avg_cfs_rq(u64 now, int cpu, struct cfs_rq *cfs_rq)
2996{
2997 return ___update_load_avg(now, cpu, &cfs_rq->avg,
2998 scale_load_down(cfs_rq->load.weight),
2999 cfs_rq->curr != NULL, cfs_rq);
2954} 3000}
2955 3001
2956/* 3002/*
@@ -3014,6 +3060,9 @@ static inline void update_tg_load_avg(struct cfs_rq *cfs_rq, int force)
3014void set_task_rq_fair(struct sched_entity *se, 3060void set_task_rq_fair(struct sched_entity *se,
3015 struct cfs_rq *prev, struct cfs_rq *next) 3061 struct cfs_rq *prev, struct cfs_rq *next)
3016{ 3062{
3063 u64 p_last_update_time;
3064 u64 n_last_update_time;
3065
3017 if (!sched_feat(ATTACH_AGE_LOAD)) 3066 if (!sched_feat(ATTACH_AGE_LOAD))
3018 return; 3067 return;
3019 3068
@@ -3024,11 +3073,11 @@ void set_task_rq_fair(struct sched_entity *se,
3024 * time. This will result in the wakee task is less decayed, but giving 3073 * time. This will result in the wakee task is less decayed, but giving
3025 * the wakee more load sounds not bad. 3074 * the wakee more load sounds not bad.
3026 */ 3075 */
3027 if (se->avg.last_update_time && prev) { 3076 if (!(se->avg.last_update_time && prev))
3028 u64 p_last_update_time; 3077 return;
3029 u64 n_last_update_time;
3030 3078
3031#ifndef CONFIG_64BIT 3079#ifndef CONFIG_64BIT
3080 {
3032 u64 p_last_update_time_copy; 3081 u64 p_last_update_time_copy;
3033 u64 n_last_update_time_copy; 3082 u64 n_last_update_time_copy;
3034 3083
@@ -3043,14 +3092,13 @@ void set_task_rq_fair(struct sched_entity *se,
3043 3092
3044 } while (p_last_update_time != p_last_update_time_copy || 3093 } while (p_last_update_time != p_last_update_time_copy ||
3045 n_last_update_time != n_last_update_time_copy); 3094 n_last_update_time != n_last_update_time_copy);
3095 }
3046#else 3096#else
3047 p_last_update_time = prev->avg.last_update_time; 3097 p_last_update_time = prev->avg.last_update_time;
3048 n_last_update_time = next->avg.last_update_time; 3098 n_last_update_time = next->avg.last_update_time;
3049#endif 3099#endif
3050 __update_load_avg(p_last_update_time, cpu_of(rq_of(prev)), 3100 __update_load_avg_blocked_se(p_last_update_time, cpu_of(rq_of(prev)), se);
3051 &se->avg, 0, 0, NULL); 3101 se->avg.last_update_time = n_last_update_time;
3052 se->avg.last_update_time = n_last_update_time;
3053 }
3054} 3102}
3055 3103
3056/* Take into account change of utilization of a child task group */ 3104/* Take into account change of utilization of a child task group */
@@ -3173,6 +3221,36 @@ static inline int propagate_entity_load_avg(struct sched_entity *se)
3173 return 1; 3221 return 1;
3174} 3222}
3175 3223
3224/*
3225 * Check if we need to update the load and the utilization of a blocked
3226 * group_entity:
3227 */
3228static inline bool skip_blocked_update(struct sched_entity *se)
3229{
3230 struct cfs_rq *gcfs_rq = group_cfs_rq(se);
3231
3232 /*
3233 * If sched_entity still have not zero load or utilization, we have to
3234 * decay it:
3235 */
3236 if (se->avg.load_avg || se->avg.util_avg)
3237 return false;
3238
3239 /*
3240 * If there is a pending propagation, we have to update the load and
3241 * the utilization of the sched_entity:
3242 */
3243 if (gcfs_rq->propagate_avg)
3244 return false;
3245
3246 /*
3247 * Otherwise, the load and the utilization of the sched_entity is
3248 * already zero and there is no pending propagation, so it will be a
3249 * waste of time to try to decay it:
3250 */
3251 return true;
3252}
3253
3176#else /* CONFIG_FAIR_GROUP_SCHED */ 3254#else /* CONFIG_FAIR_GROUP_SCHED */
3177 3255
3178static inline void update_tg_load_avg(struct cfs_rq *cfs_rq, int force) {} 3256static inline void update_tg_load_avg(struct cfs_rq *cfs_rq, int force) {}
@@ -3265,8 +3343,7 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq, bool update_freq)
3265 set_tg_cfs_propagate(cfs_rq); 3343 set_tg_cfs_propagate(cfs_rq);
3266 } 3344 }
3267 3345
3268 decayed = __update_load_avg(now, cpu_of(rq_of(cfs_rq)), sa, 3346 decayed = __update_load_avg_cfs_rq(now, cpu_of(rq_of(cfs_rq)), cfs_rq);
3269 scale_load_down(cfs_rq->load.weight), cfs_rq->curr != NULL, cfs_rq);
3270 3347
3271#ifndef CONFIG_64BIT 3348#ifndef CONFIG_64BIT
3272 smp_wmb(); 3349 smp_wmb();
@@ -3298,11 +3375,8 @@ static inline void update_load_avg(struct sched_entity *se, int flags)
3298 * Track task load average for carrying it to new CPU after migrated, and 3375 * Track task load average for carrying it to new CPU after migrated, and
3299 * track group sched_entity load average for task_h_load calc in migration 3376 * track group sched_entity load average for task_h_load calc in migration
3300 */ 3377 */
3301 if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD)) { 3378 if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD))
3302 __update_load_avg(now, cpu, &se->avg, 3379 __update_load_avg_se(now, cpu, cfs_rq, se);
3303 se->on_rq * scale_load_down(se->load.weight),
3304 cfs_rq->curr == se, NULL);
3305 }
3306 3380
3307 decayed = update_cfs_rq_load_avg(now, cfs_rq, true); 3381 decayed = update_cfs_rq_load_avg(now, cfs_rq, true);
3308 decayed |= propagate_entity_load_avg(se); 3382 decayed |= propagate_entity_load_avg(se);
@@ -3407,7 +3481,7 @@ void sync_entity_load_avg(struct sched_entity *se)
3407 u64 last_update_time; 3481 u64 last_update_time;
3408 3482
3409 last_update_time = cfs_rq_last_update_time(cfs_rq); 3483 last_update_time = cfs_rq_last_update_time(cfs_rq);
3410 __update_load_avg(last_update_time, cpu_of(rq_of(cfs_rq)), &se->avg, 0, 0, NULL); 3484 __update_load_avg_blocked_se(last_update_time, cpu_of(rq_of(cfs_rq)), se);
3411} 3485}
3412 3486
3413/* 3487/*
@@ -4271,8 +4345,9 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b,
4271 list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq, 4345 list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq,
4272 throttled_list) { 4346 throttled_list) {
4273 struct rq *rq = rq_of(cfs_rq); 4347 struct rq *rq = rq_of(cfs_rq);
4348 struct rq_flags rf;
4274 4349
4275 raw_spin_lock(&rq->lock); 4350 rq_lock(rq, &rf);
4276 if (!cfs_rq_throttled(cfs_rq)) 4351 if (!cfs_rq_throttled(cfs_rq))
4277 goto next; 4352 goto next;
4278 4353
@@ -4289,7 +4364,7 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b,
4289 unthrottle_cfs_rq(cfs_rq); 4364 unthrottle_cfs_rq(cfs_rq);
4290 4365
4291next: 4366next:
4292 raw_spin_unlock(&rq->lock); 4367 rq_unlock(rq, &rf);
4293 4368
4294 if (!remaining) 4369 if (!remaining)
4295 break; 4370 break;
@@ -5097,15 +5172,16 @@ void cpu_load_update_nohz_stop(void)
5097 unsigned long curr_jiffies = READ_ONCE(jiffies); 5172 unsigned long curr_jiffies = READ_ONCE(jiffies);
5098 struct rq *this_rq = this_rq(); 5173 struct rq *this_rq = this_rq();
5099 unsigned long load; 5174 unsigned long load;
5175 struct rq_flags rf;
5100 5176
5101 if (curr_jiffies == this_rq->last_load_update_tick) 5177 if (curr_jiffies == this_rq->last_load_update_tick)
5102 return; 5178 return;
5103 5179
5104 load = weighted_cpuload(cpu_of(this_rq)); 5180 load = weighted_cpuload(cpu_of(this_rq));
5105 raw_spin_lock(&this_rq->lock); 5181 rq_lock(this_rq, &rf);
5106 update_rq_clock(this_rq); 5182 update_rq_clock(this_rq);
5107 cpu_load_update_nohz(this_rq, curr_jiffies, load); 5183 cpu_load_update_nohz(this_rq, curr_jiffies, load);
5108 raw_spin_unlock(&this_rq->lock); 5184 rq_unlock(this_rq, &rf);
5109} 5185}
5110#else /* !CONFIG_NO_HZ_COMMON */ 5186#else /* !CONFIG_NO_HZ_COMMON */
5111static inline void cpu_load_update_nohz(struct rq *this_rq, 5187static inline void cpu_load_update_nohz(struct rq *this_rq,
@@ -6769,7 +6845,7 @@ static void detach_task(struct task_struct *p, struct lb_env *env)
6769 lockdep_assert_held(&env->src_rq->lock); 6845 lockdep_assert_held(&env->src_rq->lock);
6770 6846
6771 p->on_rq = TASK_ON_RQ_MIGRATING; 6847 p->on_rq = TASK_ON_RQ_MIGRATING;
6772 deactivate_task(env->src_rq, p, 0); 6848 deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK);
6773 set_task_cpu(p, env->dst_cpu); 6849 set_task_cpu(p, env->dst_cpu);
6774} 6850}
6775 6851
@@ -6902,7 +6978,7 @@ static void attach_task(struct rq *rq, struct task_struct *p)
6902 lockdep_assert_held(&rq->lock); 6978 lockdep_assert_held(&rq->lock);
6903 6979
6904 BUG_ON(task_rq(p) != rq); 6980 BUG_ON(task_rq(p) != rq);
6905 activate_task(rq, p, 0); 6981 activate_task(rq, p, ENQUEUE_NOCLOCK);
6906 p->on_rq = TASK_ON_RQ_QUEUED; 6982 p->on_rq = TASK_ON_RQ_QUEUED;
6907 check_preempt_curr(rq, p, 0); 6983 check_preempt_curr(rq, p, 0);
6908} 6984}
@@ -6913,9 +6989,12 @@ static void attach_task(struct rq *rq, struct task_struct *p)
6913 */ 6989 */
6914static void attach_one_task(struct rq *rq, struct task_struct *p) 6990static void attach_one_task(struct rq *rq, struct task_struct *p)
6915{ 6991{
6916 raw_spin_lock(&rq->lock); 6992 struct rq_flags rf;
6993
6994 rq_lock(rq, &rf);
6995 update_rq_clock(rq);
6917 attach_task(rq, p); 6996 attach_task(rq, p);
6918 raw_spin_unlock(&rq->lock); 6997 rq_unlock(rq, &rf);
6919} 6998}
6920 6999
6921/* 7000/*
@@ -6926,8 +7005,10 @@ static void attach_tasks(struct lb_env *env)
6926{ 7005{
6927 struct list_head *tasks = &env->tasks; 7006 struct list_head *tasks = &env->tasks;
6928 struct task_struct *p; 7007 struct task_struct *p;
7008 struct rq_flags rf;
6929 7009
6930 raw_spin_lock(&env->dst_rq->lock); 7010 rq_lock(env->dst_rq, &rf);
7011 update_rq_clock(env->dst_rq);
6931 7012
6932 while (!list_empty(tasks)) { 7013 while (!list_empty(tasks)) {
6933 p = list_first_entry(tasks, struct task_struct, se.group_node); 7014 p = list_first_entry(tasks, struct task_struct, se.group_node);
@@ -6936,7 +7017,7 @@ static void attach_tasks(struct lb_env *env)
6936 attach_task(env->dst_rq, p); 7017 attach_task(env->dst_rq, p);
6937 } 7018 }
6938 7019
6939 raw_spin_unlock(&env->dst_rq->lock); 7020 rq_unlock(env->dst_rq, &rf);
6940} 7021}
6941 7022
6942#ifdef CONFIG_FAIR_GROUP_SCHED 7023#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -6944,9 +7025,9 @@ static void update_blocked_averages(int cpu)
6944{ 7025{
6945 struct rq *rq = cpu_rq(cpu); 7026 struct rq *rq = cpu_rq(cpu);
6946 struct cfs_rq *cfs_rq; 7027 struct cfs_rq *cfs_rq;
6947 unsigned long flags; 7028 struct rq_flags rf;
6948 7029
6949 raw_spin_lock_irqsave(&rq->lock, flags); 7030 rq_lock_irqsave(rq, &rf);
6950 update_rq_clock(rq); 7031 update_rq_clock(rq);
6951 7032
6952 /* 7033 /*
@@ -6954,6 +7035,8 @@ static void update_blocked_averages(int cpu)
6954 * list_add_leaf_cfs_rq() for details. 7035 * list_add_leaf_cfs_rq() for details.
6955 */ 7036 */
6956 for_each_leaf_cfs_rq(rq, cfs_rq) { 7037 for_each_leaf_cfs_rq(rq, cfs_rq) {
7038 struct sched_entity *se;
7039
6957 /* throttled entities do not contribute to load */ 7040 /* throttled entities do not contribute to load */
6958 if (throttled_hierarchy(cfs_rq)) 7041 if (throttled_hierarchy(cfs_rq))
6959 continue; 7042 continue;
@@ -6961,11 +7044,12 @@ static void update_blocked_averages(int cpu)
6961 if (update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, true)) 7044 if (update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, true))
6962 update_tg_load_avg(cfs_rq, 0); 7045 update_tg_load_avg(cfs_rq, 0);
6963 7046
6964 /* Propagate pending load changes to the parent */ 7047 /* Propagate pending load changes to the parent, if any: */
6965 if (cfs_rq->tg->se[cpu]) 7048 se = cfs_rq->tg->se[cpu];
6966 update_load_avg(cfs_rq->tg->se[cpu], 0); 7049 if (se && !skip_blocked_update(se))
7050 update_load_avg(se, 0);
6967 } 7051 }
6968 raw_spin_unlock_irqrestore(&rq->lock, flags); 7052 rq_unlock_irqrestore(rq, &rf);
6969} 7053}
6970 7054
6971/* 7055/*
@@ -7019,12 +7103,12 @@ static inline void update_blocked_averages(int cpu)
7019{ 7103{
7020 struct rq *rq = cpu_rq(cpu); 7104 struct rq *rq = cpu_rq(cpu);
7021 struct cfs_rq *cfs_rq = &rq->cfs; 7105 struct cfs_rq *cfs_rq = &rq->cfs;
7022 unsigned long flags; 7106 struct rq_flags rf;
7023 7107
7024 raw_spin_lock_irqsave(&rq->lock, flags); 7108 rq_lock_irqsave(rq, &rf);
7025 update_rq_clock(rq); 7109 update_rq_clock(rq);
7026 update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, true); 7110 update_cfs_rq_load_avg(cfs_rq_clock_task(cfs_rq), cfs_rq, true);
7027 raw_spin_unlock_irqrestore(&rq->lock, flags); 7111 rq_unlock_irqrestore(rq, &rf);
7028} 7112}
7029 7113
7030static unsigned long task_h_load(struct task_struct *p) 7114static unsigned long task_h_load(struct task_struct *p)
@@ -7525,6 +7609,7 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd
7525{ 7609{
7526 struct sched_domain *child = env->sd->child; 7610 struct sched_domain *child = env->sd->child;
7527 struct sched_group *sg = env->sd->groups; 7611 struct sched_group *sg = env->sd->groups;
7612 struct sg_lb_stats *local = &sds->local_stat;
7528 struct sg_lb_stats tmp_sgs; 7613 struct sg_lb_stats tmp_sgs;
7529 int load_idx, prefer_sibling = 0; 7614 int load_idx, prefer_sibling = 0;
7530 bool overload = false; 7615 bool overload = false;
@@ -7541,7 +7626,7 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd
7541 local_group = cpumask_test_cpu(env->dst_cpu, sched_group_cpus(sg)); 7626 local_group = cpumask_test_cpu(env->dst_cpu, sched_group_cpus(sg));
7542 if (local_group) { 7627 if (local_group) {
7543 sds->local = sg; 7628 sds->local = sg;
7544 sgs = &sds->local_stat; 7629 sgs = local;
7545 7630
7546 if (env->idle != CPU_NEWLY_IDLE || 7631 if (env->idle != CPU_NEWLY_IDLE ||
7547 time_after_eq(jiffies, sg->sgc->next_update)) 7632 time_after_eq(jiffies, sg->sgc->next_update))
@@ -7565,8 +7650,8 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd
7565 * the tasks on the system). 7650 * the tasks on the system).
7566 */ 7651 */
7567 if (prefer_sibling && sds->local && 7652 if (prefer_sibling && sds->local &&
7568 group_has_capacity(env, &sds->local_stat) && 7653 group_has_capacity(env, local) &&
7569 (sgs->sum_nr_running > 1)) { 7654 (sgs->sum_nr_running > local->sum_nr_running + 1)) {
7570 sgs->group_no_capacity = 1; 7655 sgs->group_no_capacity = 1;
7571 sgs->group_type = group_classify(sg, sgs); 7656 sgs->group_type = group_classify(sg, sgs);
7572 } 7657 }
@@ -8042,7 +8127,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
8042 struct sched_domain *sd_parent = sd->parent; 8127 struct sched_domain *sd_parent = sd->parent;
8043 struct sched_group *group; 8128 struct sched_group *group;
8044 struct rq *busiest; 8129 struct rq *busiest;
8045 unsigned long flags; 8130 struct rq_flags rf;
8046 struct cpumask *cpus = this_cpu_cpumask_var_ptr(load_balance_mask); 8131 struct cpumask *cpus = this_cpu_cpumask_var_ptr(load_balance_mask);
8047 8132
8048 struct lb_env env = { 8133 struct lb_env env = {
@@ -8105,7 +8190,7 @@ redo:
8105 env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running); 8190 env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running);
8106 8191
8107more_balance: 8192more_balance:
8108 raw_spin_lock_irqsave(&busiest->lock, flags); 8193 rq_lock_irqsave(busiest, &rf);
8109 update_rq_clock(busiest); 8194 update_rq_clock(busiest);
8110 8195
8111 /* 8196 /*
@@ -8122,14 +8207,14 @@ more_balance:
8122 * See task_rq_lock() family for the details. 8207 * See task_rq_lock() family for the details.
8123 */ 8208 */
8124 8209
8125 raw_spin_unlock(&busiest->lock); 8210 rq_unlock(busiest, &rf);
8126 8211
8127 if (cur_ld_moved) { 8212 if (cur_ld_moved) {
8128 attach_tasks(&env); 8213 attach_tasks(&env);
8129 ld_moved += cur_ld_moved; 8214 ld_moved += cur_ld_moved;
8130 } 8215 }
8131 8216
8132 local_irq_restore(flags); 8217 local_irq_restore(rf.flags);
8133 8218
8134 if (env.flags & LBF_NEED_BREAK) { 8219 if (env.flags & LBF_NEED_BREAK) {
8135 env.flags &= ~LBF_NEED_BREAK; 8220 env.flags &= ~LBF_NEED_BREAK;
@@ -8207,6 +8292,8 @@ more_balance:
8207 sd->nr_balance_failed++; 8292 sd->nr_balance_failed++;
8208 8293
8209 if (need_active_balance(&env)) { 8294 if (need_active_balance(&env)) {
8295 unsigned long flags;
8296
8210 raw_spin_lock_irqsave(&busiest->lock, flags); 8297 raw_spin_lock_irqsave(&busiest->lock, flags);
8211 8298
8212 /* don't kick the active_load_balance_cpu_stop, 8299 /* don't kick the active_load_balance_cpu_stop,
@@ -8444,8 +8531,9 @@ static int active_load_balance_cpu_stop(void *data)
8444 struct rq *target_rq = cpu_rq(target_cpu); 8531 struct rq *target_rq = cpu_rq(target_cpu);
8445 struct sched_domain *sd; 8532 struct sched_domain *sd;
8446 struct task_struct *p = NULL; 8533 struct task_struct *p = NULL;
8534 struct rq_flags rf;
8447 8535
8448 raw_spin_lock_irq(&busiest_rq->lock); 8536 rq_lock_irq(busiest_rq, &rf);
8449 8537
8450 /* make sure the requested cpu hasn't gone down in the meantime */ 8538 /* make sure the requested cpu hasn't gone down in the meantime */
8451 if (unlikely(busiest_cpu != smp_processor_id() || 8539 if (unlikely(busiest_cpu != smp_processor_id() ||
@@ -8496,7 +8584,7 @@ static int active_load_balance_cpu_stop(void *data)
8496 rcu_read_unlock(); 8584 rcu_read_unlock();
8497out_unlock: 8585out_unlock:
8498 busiest_rq->active_balance = 0; 8586 busiest_rq->active_balance = 0;
8499 raw_spin_unlock(&busiest_rq->lock); 8587 rq_unlock(busiest_rq, &rf);
8500 8588
8501 if (p) 8589 if (p)
8502 attach_one_task(target_rq, p); 8590 attach_one_task(target_rq, p);
@@ -8794,10 +8882,13 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
8794 * do the balance. 8882 * do the balance.
8795 */ 8883 */
8796 if (time_after_eq(jiffies, rq->next_balance)) { 8884 if (time_after_eq(jiffies, rq->next_balance)) {
8797 raw_spin_lock_irq(&rq->lock); 8885 struct rq_flags rf;
8886
8887 rq_lock_irq(rq, &rf);
8798 update_rq_clock(rq); 8888 update_rq_clock(rq);
8799 cpu_load_update_idle(rq); 8889 cpu_load_update_idle(rq);
8800 raw_spin_unlock_irq(&rq->lock); 8890 rq_unlock_irq(rq, &rf);
8891
8801 rebalance_domains(rq, CPU_IDLE); 8892 rebalance_domains(rq, CPU_IDLE);
8802 } 8893 }
8803 8894
@@ -8988,8 +9079,9 @@ static void task_fork_fair(struct task_struct *p)
8988 struct cfs_rq *cfs_rq; 9079 struct cfs_rq *cfs_rq;
8989 struct sched_entity *se = &p->se, *curr; 9080 struct sched_entity *se = &p->se, *curr;
8990 struct rq *rq = this_rq(); 9081 struct rq *rq = this_rq();
9082 struct rq_flags rf;
8991 9083
8992 raw_spin_lock(&rq->lock); 9084 rq_lock(rq, &rf);
8993 update_rq_clock(rq); 9085 update_rq_clock(rq);
8994 9086
8995 cfs_rq = task_cfs_rq(current); 9087 cfs_rq = task_cfs_rq(current);
@@ -9010,7 +9102,7 @@ static void task_fork_fair(struct task_struct *p)
9010 } 9102 }
9011 9103
9012 se->vruntime -= cfs_rq->min_vruntime; 9104 se->vruntime -= cfs_rq->min_vruntime;
9013 raw_spin_unlock(&rq->lock); 9105 rq_unlock(rq, &rf);
9014} 9106}
9015 9107
9016/* 9108/*
@@ -9372,7 +9464,6 @@ static DEFINE_MUTEX(shares_mutex);
9372int sched_group_set_shares(struct task_group *tg, unsigned long shares) 9464int sched_group_set_shares(struct task_group *tg, unsigned long shares)
9373{ 9465{
9374 int i; 9466 int i;
9375 unsigned long flags;
9376 9467
9377 /* 9468 /*
9378 * We can't change the weight of the root cgroup. 9469 * We can't change the weight of the root cgroup.
@@ -9389,19 +9480,17 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
9389 tg->shares = shares; 9480 tg->shares = shares;
9390 for_each_possible_cpu(i) { 9481 for_each_possible_cpu(i) {
9391 struct rq *rq = cpu_rq(i); 9482 struct rq *rq = cpu_rq(i);
9392 struct sched_entity *se; 9483 struct sched_entity *se = tg->se[i];
9484 struct rq_flags rf;
9393 9485
9394 se = tg->se[i];
9395 /* Propagate contribution to hierarchy */ 9486 /* Propagate contribution to hierarchy */
9396 raw_spin_lock_irqsave(&rq->lock, flags); 9487 rq_lock_irqsave(rq, &rf);
9397
9398 /* Possible calls to update_curr() need rq clock */
9399 update_rq_clock(rq); 9488 update_rq_clock(rq);
9400 for_each_sched_entity(se) { 9489 for_each_sched_entity(se) {
9401 update_load_avg(se, UPDATE_TG); 9490 update_load_avg(se, UPDATE_TG);
9402 update_cfs_shares(se); 9491 update_cfs_shares(se);
9403 } 9492 }
9404 raw_spin_unlock_irqrestore(&rq->lock, flags); 9493 rq_unlock_irqrestore(rq, &rf);
9405 } 9494 }
9406 9495
9407done: 9496done:
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index 1b3c8189b286..11192e0cb122 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -56,6 +56,13 @@ SCHED_FEAT(TTWU_QUEUE, true)
56 */ 56 */
57SCHED_FEAT(SIS_AVG_CPU, false) 57SCHED_FEAT(SIS_AVG_CPU, false)
58 58
59/*
60 * Issue a WARN when we do multiple update_rq_clock() calls
61 * in a single rq->lock section. Default disabled because the
62 * annotations are not complete.
63 */
64SCHED_FEAT(WARN_DOUBLE_CLOCK, false)
65
59#ifdef HAVE_RT_PUSH_IPI 66#ifdef HAVE_RT_PUSH_IPI
60/* 67/*
61 * In order to avoid a thundering herd attack of CPUs that are 68 * In order to avoid a thundering herd attack of CPUs that are
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index 7296b7308eca..f15fb2bdbc0d 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -169,7 +169,7 @@ static inline int calc_load_write_idx(void)
169 * If the folding window started, make sure we start writing in the 169 * If the folding window started, make sure we start writing in the
170 * next idle-delta. 170 * next idle-delta.
171 */ 171 */
172 if (!time_before(jiffies, calc_load_update)) 172 if (!time_before(jiffies, READ_ONCE(calc_load_update)))
173 idx++; 173 idx++;
174 174
175 return idx & 1; 175 return idx & 1;
@@ -202,8 +202,9 @@ void calc_load_exit_idle(void)
202 struct rq *this_rq = this_rq(); 202 struct rq *this_rq = this_rq();
203 203
204 /* 204 /*
205 * If we're still before the sample window, we're done. 205 * If we're still before the pending sample window, we're done.
206 */ 206 */
207 this_rq->calc_load_update = READ_ONCE(calc_load_update);
207 if (time_before(jiffies, this_rq->calc_load_update)) 208 if (time_before(jiffies, this_rq->calc_load_update))
208 return; 209 return;
209 210
@@ -212,7 +213,6 @@ void calc_load_exit_idle(void)
212 * accounted through the nohz accounting, so skip the entire deal and 213 * accounted through the nohz accounting, so skip the entire deal and
213 * sync up for the next window. 214 * sync up for the next window.
214 */ 215 */
215 this_rq->calc_load_update = calc_load_update;
216 if (time_before(jiffies, this_rq->calc_load_update + 10)) 216 if (time_before(jiffies, this_rq->calc_load_update + 10))
217 this_rq->calc_load_update += LOAD_FREQ; 217 this_rq->calc_load_update += LOAD_FREQ;
218} 218}
@@ -308,13 +308,15 @@ calc_load_n(unsigned long load, unsigned long exp,
308 */ 308 */
309static void calc_global_nohz(void) 309static void calc_global_nohz(void)
310{ 310{
311 unsigned long sample_window;
311 long delta, active, n; 312 long delta, active, n;
312 313
313 if (!time_before(jiffies, calc_load_update + 10)) { 314 sample_window = READ_ONCE(calc_load_update);
315 if (!time_before(jiffies, sample_window + 10)) {
314 /* 316 /*
315 * Catch-up, fold however many we are behind still 317 * Catch-up, fold however many we are behind still
316 */ 318 */
317 delta = jiffies - calc_load_update - 10; 319 delta = jiffies - sample_window - 10;
318 n = 1 + (delta / LOAD_FREQ); 320 n = 1 + (delta / LOAD_FREQ);
319 321
320 active = atomic_long_read(&calc_load_tasks); 322 active = atomic_long_read(&calc_load_tasks);
@@ -324,7 +326,7 @@ static void calc_global_nohz(void)
324 avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n); 326 avenrun[1] = calc_load_n(avenrun[1], EXP_5, active, n);
325 avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n); 327 avenrun[2] = calc_load_n(avenrun[2], EXP_15, active, n);
326 328
327 calc_load_update += n * LOAD_FREQ; 329 WRITE_ONCE(calc_load_update, sample_window + n * LOAD_FREQ);
328 } 330 }
329 331
330 /* 332 /*
@@ -352,9 +354,11 @@ static inline void calc_global_nohz(void) { }
352 */ 354 */
353void calc_global_load(unsigned long ticks) 355void calc_global_load(unsigned long ticks)
354{ 356{
357 unsigned long sample_window;
355 long active, delta; 358 long active, delta;
356 359
357 if (time_before(jiffies, calc_load_update + 10)) 360 sample_window = READ_ONCE(calc_load_update);
361 if (time_before(jiffies, sample_window + 10))
358 return; 362 return;
359 363
360 /* 364 /*
@@ -371,7 +375,7 @@ void calc_global_load(unsigned long ticks)
371 avenrun[1] = calc_load(avenrun[1], EXP_5, active); 375 avenrun[1] = calc_load(avenrun[1], EXP_5, active);
372 avenrun[2] = calc_load(avenrun[2], EXP_15, active); 376 avenrun[2] = calc_load(avenrun[2], EXP_15, active);
373 377
374 calc_load_update += LOAD_FREQ; 378 WRITE_ONCE(calc_load_update, sample_window + LOAD_FREQ);
375 379
376 /* 380 /*
377 * In case we idled for multiple LOAD_FREQ intervals, catch up in bulk. 381 * In case we idled for multiple LOAD_FREQ intervals, catch up in bulk.
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 9f3e40226dec..979b7341008a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1927,6 +1927,87 @@ static int find_next_push_cpu(struct rq *rq)
1927#define RT_PUSH_IPI_EXECUTING 1 1927#define RT_PUSH_IPI_EXECUTING 1
1928#define RT_PUSH_IPI_RESTART 2 1928#define RT_PUSH_IPI_RESTART 2
1929 1929
1930/*
1931 * When a high priority task schedules out from a CPU and a lower priority
1932 * task is scheduled in, a check is made to see if there's any RT tasks
1933 * on other CPUs that are waiting to run because a higher priority RT task
1934 * is currently running on its CPU. In this case, the CPU with multiple RT
1935 * tasks queued on it (overloaded) needs to be notified that a CPU has opened
1936 * up that may be able to run one of its non-running queued RT tasks.
1937 *
1938 * On large CPU boxes, there's the case that several CPUs could schedule
1939 * a lower priority task at the same time, in which case it will look for
1940 * any overloaded CPUs that it could pull a task from. To do this, the runqueue
1941 * lock must be taken from that overloaded CPU. Having 10s of CPUs all fighting
1942 * for a single overloaded CPU's runqueue lock can produce a large latency.
1943 * (This has actually been observed on large boxes running cyclictest).
1944 * Instead of taking the runqueue lock of the overloaded CPU, each of the
1945 * CPUs that scheduled a lower priority task simply sends an IPI to the
1946 * overloaded CPU. An IPI is much cheaper than taking an runqueue lock with
1947 * lots of contention. The overloaded CPU will look to push its non-running
1948 * RT task off, and if it does, it can then ignore the other IPIs coming
1949 * in, and just pass those IPIs off to any other overloaded CPU.
1950 *
1951 * When a CPU schedules a lower priority task, it only sends an IPI to
1952 * the "next" CPU that has overloaded RT tasks. This prevents IPI storms,
1953 * as having 10 CPUs scheduling lower priority tasks and 10 CPUs with
1954 * RT overloaded tasks, would cause 100 IPIs to go out at once.
1955 *
1956 * The overloaded RT CPU, when receiving an IPI, will try to push off its
1957 * overloaded RT tasks and then send an IPI to the next CPU that has
1958 * overloaded RT tasks. This stops when all CPUs with overloaded RT tasks
1959 * have completed. Just because a CPU may have pushed off its own overloaded
1960 * RT task does not mean it should stop sending the IPI around to other
1961 * overloaded CPUs. There may be another RT task waiting to run on one of
1962 * those CPUs that are of higher priority than the one that was just
1963 * pushed.
1964 *
1965 * An optimization that could possibly be made is to make a CPU array similar
1966 * to the cpupri array mask of all running RT tasks, but for the overloaded
1967 * case, then the IPI could be sent to only the CPU with the highest priority
1968 * RT task waiting, and that CPU could send off further IPIs to the CPU with
1969 * the next highest waiting task. Since the overloaded case is much less likely
1970 * to happen, the complexity of this implementation may not be worth it.
1971 * Instead, just send an IPI around to all overloaded CPUs.
1972 *
1973 * The rq->rt.push_flags holds the status of the IPI that is going around.
1974 * A run queue can only send out a single IPI at a time. The possible flags
1975 * for rq->rt.push_flags are:
1976 *
1977 * (None or zero): No IPI is going around for the current rq
1978 * RT_PUSH_IPI_EXECUTING: An IPI for the rq is being passed around
1979 * RT_PUSH_IPI_RESTART: The priority of the running task for the rq
1980 * has changed, and the IPI should restart
1981 * circulating the overloaded CPUs again.
1982 *
1983 * rq->rt.push_cpu contains the CPU that is being sent the IPI. It is updated
1984 * before sending to the next CPU.
1985 *
1986 * Instead of having all CPUs that schedule a lower priority task send
1987 * an IPI to the same "first" CPU in the RT overload mask, they send it
1988 * to the next overloaded CPU after their own CPU. This helps distribute
1989 * the work when there's more than one overloaded CPU and multiple CPUs
1990 * scheduling in lower priority tasks.
1991 *
1992 * When a rq schedules a lower priority task than what was currently
1993 * running, the next CPU with overloaded RT tasks is examined first.
1994 * That is, if CPU 1 and 5 are overloaded, and CPU 3 schedules a lower
1995 * priority task, it will send an IPI first to CPU 5, then CPU 5 will
1996 * send to CPU 1 if it is still overloaded. CPU 1 will clear the
1997 * rq->rt.push_flags if RT_PUSH_IPI_RESTART is not set.
1998 *
1999 * The first CPU to notice IPI_RESTART is set, will clear that flag and then
2000 * send an IPI to the next overloaded CPU after the rq->cpu and not the next
2001 * CPU after push_cpu. That is, if CPU 1, 4 and 5 are overloaded when CPU 3
2002 * schedules a lower priority task, and the IPI_RESTART gets set while the
2003 * handling is being done on CPU 5, it will clear the flag and send it back to
2004 * CPU 4 instead of CPU 1.
2005 *
2006 * Note, the above logic can be disabled by turning off the sched_feature
2007 * RT_PUSH_IPI. Then the rq lock of the overloaded CPU will simply be
2008 * taken by the CPU requesting a pull and the waiting RT task will be pulled
2009 * by that CPU. This may be fine for machines with few CPUs.
2010 */
1930static void tell_cpu_to_push(struct rq *rq) 2011static void tell_cpu_to_push(struct rq *rq)
1931{ 2012{
1932 int cpu; 2013 int cpu;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 5cbf92214ad8..de4b934ba974 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1331,15 +1331,17 @@ extern const u32 sched_prio_to_wmult[40];
1331#define DEQUEUE_SLEEP 0x01 1331#define DEQUEUE_SLEEP 0x01
1332#define DEQUEUE_SAVE 0x02 /* matches ENQUEUE_RESTORE */ 1332#define DEQUEUE_SAVE 0x02 /* matches ENQUEUE_RESTORE */
1333#define DEQUEUE_MOVE 0x04 /* matches ENQUEUE_MOVE */ 1333#define DEQUEUE_MOVE 0x04 /* matches ENQUEUE_MOVE */
1334#define DEQUEUE_NOCLOCK 0x08 /* matches ENQUEUE_NOCLOCK */
1334 1335
1335#define ENQUEUE_WAKEUP 0x01 1336#define ENQUEUE_WAKEUP 0x01
1336#define ENQUEUE_RESTORE 0x02 1337#define ENQUEUE_RESTORE 0x02
1337#define ENQUEUE_MOVE 0x04 1338#define ENQUEUE_MOVE 0x04
1339#define ENQUEUE_NOCLOCK 0x08
1338 1340
1339#define ENQUEUE_HEAD 0x08 1341#define ENQUEUE_HEAD 0x10
1340#define ENQUEUE_REPLENISH 0x10 1342#define ENQUEUE_REPLENISH 0x20
1341#ifdef CONFIG_SMP 1343#ifdef CONFIG_SMP
1342#define ENQUEUE_MIGRATED 0x20 1344#define ENQUEUE_MIGRATED 0x40
1343#else 1345#else
1344#define ENQUEUE_MIGRATED 0x00 1346#define ENQUEUE_MIGRATED 0x00
1345#endif 1347#endif
@@ -1624,6 +1626,7 @@ static inline void sched_avg_update(struct rq *rq) { }
1624 1626
1625struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf) 1627struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf)
1626 __acquires(rq->lock); 1628 __acquires(rq->lock);
1629
1627struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf) 1630struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf)
1628 __acquires(p->pi_lock) 1631 __acquires(p->pi_lock)
1629 __acquires(rq->lock); 1632 __acquires(rq->lock);
@@ -1645,6 +1648,62 @@ task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf)
1645 raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags); 1648 raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags);
1646} 1649}
1647 1650
1651static inline void
1652rq_lock_irqsave(struct rq *rq, struct rq_flags *rf)
1653 __acquires(rq->lock)
1654{
1655 raw_spin_lock_irqsave(&rq->lock, rf->flags);
1656 rq_pin_lock(rq, rf);
1657}
1658
1659static inline void
1660rq_lock_irq(struct rq *rq, struct rq_flags *rf)
1661 __acquires(rq->lock)
1662{
1663 raw_spin_lock_irq(&rq->lock);
1664 rq_pin_lock(rq, rf);
1665}
1666
1667static inline void
1668rq_lock(struct rq *rq, struct rq_flags *rf)
1669 __acquires(rq->lock)
1670{
1671 raw_spin_lock(&rq->lock);
1672 rq_pin_lock(rq, rf);
1673}
1674
1675static inline void
1676rq_relock(struct rq *rq, struct rq_flags *rf)
1677 __acquires(rq->lock)
1678{
1679 raw_spin_lock(&rq->lock);
1680 rq_repin_lock(rq, rf);
1681}
1682
1683static inline void
1684rq_unlock_irqrestore(struct rq *rq, struct rq_flags *rf)
1685 __releases(rq->lock)
1686{
1687 rq_unpin_lock(rq, rf);
1688 raw_spin_unlock_irqrestore(&rq->lock, rf->flags);
1689}
1690
1691static inline void
1692rq_unlock_irq(struct rq *rq, struct rq_flags *rf)
1693 __releases(rq->lock)
1694{
1695 rq_unpin_lock(rq, rf);
1696 raw_spin_unlock_irq(&rq->lock);
1697}
1698
1699static inline void
1700rq_unlock(struct rq *rq, struct rq_flags *rf)
1701 __releases(rq->lock)
1702{
1703 rq_unpin_lock(rq, rf);
1704 raw_spin_unlock(&rq->lock);
1705}
1706
1648#ifdef CONFIG_SMP 1707#ifdef CONFIG_SMP
1649#ifdef CONFIG_PREEMPT 1708#ifdef CONFIG_PREEMPT
1650 1709
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 072cbc9b175d..c0168b7da1ea 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1507,6 +1507,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
1507 struct timer_list *timer = &dwork->timer; 1507 struct timer_list *timer = &dwork->timer;
1508 struct work_struct *work = &dwork->work; 1508 struct work_struct *work = &dwork->work;
1509 1509
1510 WARN_ON_ONCE(!wq);
1510 WARN_ON_ONCE(timer->function != delayed_work_timer_fn || 1511 WARN_ON_ONCE(timer->function != delayed_work_timer_fn ||
1511 timer->data != (unsigned long)dwork); 1512 timer->data != (unsigned long)dwork);
1512 WARN_ON_ONCE(timer_pending(timer)); 1513 WARN_ON_ONCE(timer_pending(timer));
diff --git a/mm/gup.c b/mm/gup.c
index c74bad1bf6e8..04aa405350dc 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1455,7 +1455,7 @@ static int gup_p4d_range(pgd_t pgd, unsigned long addr, unsigned long end,
1455 if (!gup_huge_pd(__hugepd(p4d_val(p4d)), addr, 1455 if (!gup_huge_pd(__hugepd(p4d_val(p4d)), addr,
1456 P4D_SHIFT, next, write, pages, nr)) 1456 P4D_SHIFT, next, write, pages, nr))
1457 return 0; 1457 return 0;
1458 } else if (!gup_p4d_range(p4d, addr, next, write, pages, nr)) 1458 } else if (!gup_pud_range(p4d, addr, next, write, pages, nr))
1459 return 0; 1459 return 0;
1460 } while (p4dp++, addr = next, addr != end); 1460 } while (p4dp++, addr = next, addr != end);
1461 1461
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
index 538998a137d2..9ac639499bd1 100644
--- a/mm/percpu-vm.c
+++ b/mm/percpu-vm.c
@@ -21,7 +21,6 @@ static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
21 21
22/** 22/**
23 * pcpu_get_pages - get temp pages array 23 * pcpu_get_pages - get temp pages array
24 * @chunk: chunk of interest
25 * 24 *
26 * Returns pointer to array of pointers to struct page which can be indexed 25 * Returns pointer to array of pointers to struct page which can be indexed
27 * with pcpu_page_idx(). Note that there is only one array and accesses 26 * with pcpu_page_idx(). Note that there is only one array and accesses
@@ -30,7 +29,7 @@ static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
30 * RETURNS: 29 * RETURNS:
31 * Pointer to temp pages array on success. 30 * Pointer to temp pages array on success.
32 */ 31 */
33static struct page **pcpu_get_pages(struct pcpu_chunk *chunk_alloc) 32static struct page **pcpu_get_pages(void)
34{ 33{
35 static struct page **pages; 34 static struct page **pages;
36 size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]); 35 size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]);
@@ -275,7 +274,7 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk,
275{ 274{
276 struct page **pages; 275 struct page **pages;
277 276
278 pages = pcpu_get_pages(chunk); 277 pages = pcpu_get_pages();
279 if (!pages) 278 if (!pages)
280 return -ENOMEM; 279 return -ENOMEM;
281 280
@@ -313,7 +312,7 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk,
313 * successful population attempt so the temp pages array must 312 * successful population attempt so the temp pages array must
314 * be available now. 313 * be available now.
315 */ 314 */
316 pages = pcpu_get_pages(chunk); 315 pages = pcpu_get_pages();
317 BUG_ON(!pages); 316 BUG_ON(!pages);
318 317
319 /* unmap and free */ 318 /* unmap and free */
diff --git a/mm/percpu.c b/mm/percpu.c
index bd7416752819..e0aa8ae7bde7 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1011,8 +1011,11 @@ area_found:
1011 mutex_unlock(&pcpu_alloc_mutex); 1011 mutex_unlock(&pcpu_alloc_mutex);
1012 } 1012 }
1013 1013
1014 if (chunk != pcpu_reserved_chunk) 1014 if (chunk != pcpu_reserved_chunk) {
1015 spin_lock_irqsave(&pcpu_lock, flags);
1015 pcpu_nr_empty_pop_pages -= occ_pages; 1016 pcpu_nr_empty_pop_pages -= occ_pages;
1017 spin_unlock_irqrestore(&pcpu_lock, flags);
1018 }
1016 1019
1017 if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW) 1020 if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
1018 pcpu_schedule_balance_work(); 1021 pcpu_schedule_balance_work();
diff --git a/net/atm/svc.c b/net/atm/svc.c
index db9794ec61d8..5589de7086af 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -318,7 +318,8 @@ out:
318 return error; 318 return error;
319} 319}
320 320
321static int svc_accept(struct socket *sock, struct socket *newsock, int flags) 321static int svc_accept(struct socket *sock, struct socket *newsock, int flags,
322 bool kern)
322{ 323{
323 struct sock *sk = sock->sk; 324 struct sock *sk = sock->sk;
324 struct sk_buff *skb; 325 struct sk_buff *skb;
@@ -329,7 +330,7 @@ static int svc_accept(struct socket *sock, struct socket *newsock, int flags)
329 330
330 lock_sock(sk); 331 lock_sock(sk);
331 332
332 error = svc_create(sock_net(sk), newsock, 0, 0); 333 error = svc_create(sock_net(sk), newsock, 0, kern);
333 if (error) 334 if (error)
334 goto out; 335 goto out;
335 336
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index a8e42cedf1db..b7c486752b3a 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1320,7 +1320,8 @@ out_release:
1320 return err; 1320 return err;
1321} 1321}
1322 1322
1323static int ax25_accept(struct socket *sock, struct socket *newsock, int flags) 1323static int ax25_accept(struct socket *sock, struct socket *newsock, int flags,
1324 bool kern)
1324{ 1325{
1325 struct sk_buff *skb; 1326 struct sk_buff *skb;
1326 struct sock *newsk; 1327 struct sock *newsk;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f307b145ea54..507b80d59dec 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -301,7 +301,7 @@ done:
301} 301}
302 302
303static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, 303static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
304 int flags) 304 int flags, bool kern)
305{ 305{
306 DEFINE_WAIT_FUNC(wait, woken_wake_function); 306 DEFINE_WAIT_FUNC(wait, woken_wake_function);
307 struct sock *sk = sock->sk, *nsk; 307 struct sock *sk = sock->sk, *nsk;
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index aa1a814ceddc..ac3c650cb234 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -471,7 +471,8 @@ done:
471 return err; 471 return err;
472} 472}
473 473
474static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags) 474static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags,
475 bool kern)
475{ 476{
476 DEFINE_WAIT_FUNC(wait, woken_wake_function); 477 DEFINE_WAIT_FUNC(wait, woken_wake_function);
477 struct sock *sk = sock->sk, *nsk; 478 struct sock *sk = sock->sk, *nsk;
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e4e9a2da1e7e..728e0c8dc8e7 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -627,7 +627,7 @@ done:
627} 627}
628 628
629static int sco_sock_accept(struct socket *sock, struct socket *newsock, 629static int sco_sock_accept(struct socket *sock, struct socket *newsock,
630 int flags) 630 int flags, bool kern)
631{ 631{
632 DEFINE_WAIT_FUNC(wait, woken_wake_function); 632 DEFINE_WAIT_FUNC(wait, woken_wake_function);
633 struct sock *sk = sock->sk, *ch; 633 struct sock *sk = sock->sk, *ch;
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 236f34244dbe..013f2290bfa5 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -30,6 +30,7 @@ EXPORT_SYMBOL(br_should_route_hook);
30static int 30static int
31br_netif_receive_skb(struct net *net, struct sock *sk, struct sk_buff *skb) 31br_netif_receive_skb(struct net *net, struct sock *sk, struct sk_buff *skb)
32{ 32{
33 br_drop_fake_rtable(skb);
33 return netif_receive_skb(skb); 34 return netif_receive_skb(skb);
34} 35}
35 36
diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c
index 95087e6e8258..fa87fbd62bb7 100644
--- a/net/bridge/br_netfilter_hooks.c
+++ b/net/bridge/br_netfilter_hooks.c
@@ -521,21 +521,6 @@ static unsigned int br_nf_pre_routing(void *priv,
521} 521}
522 522
523 523
524/* PF_BRIDGE/LOCAL_IN ************************************************/
525/* The packet is locally destined, which requires a real
526 * dst_entry, so detach the fake one. On the way up, the
527 * packet would pass through PRE_ROUTING again (which already
528 * took place when the packet entered the bridge), but we
529 * register an IPv4 PRE_ROUTING 'sabotage' hook that will
530 * prevent this from happening. */
531static unsigned int br_nf_local_in(void *priv,
532 struct sk_buff *skb,
533 const struct nf_hook_state *state)
534{
535 br_drop_fake_rtable(skb);
536 return NF_ACCEPT;
537}
538
539/* PF_BRIDGE/FORWARD *************************************************/ 524/* PF_BRIDGE/FORWARD *************************************************/
540static int br_nf_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb) 525static int br_nf_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
541{ 526{
@@ -908,12 +893,6 @@ static struct nf_hook_ops br_nf_ops[] __read_mostly = {
908 .priority = NF_BR_PRI_BRNF, 893 .priority = NF_BR_PRI_BRNF,
909 }, 894 },
910 { 895 {
911 .hook = br_nf_local_in,
912 .pf = NFPROTO_BRIDGE,
913 .hooknum = NF_BR_LOCAL_IN,
914 .priority = NF_BR_PRI_BRNF,
915 },
916 {
917 .hook = br_nf_forward_ip, 896 .hook = br_nf_forward_ip,
918 .pf = NFPROTO_BRIDGE, 897 .pf = NFPROTO_BRIDGE,
919 .hooknum = NF_BR_FORWARD, 898 .hooknum = NF_BR_FORWARD,
diff --git a/net/core/dev.c b/net/core/dev.c
index 8637b2b71f3d..7869ae3837ca 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1304,6 +1304,7 @@ void netdev_notify_peers(struct net_device *dev)
1304{ 1304{
1305 rtnl_lock(); 1305 rtnl_lock();
1306 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev); 1306 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
1307 call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
1307 rtnl_unlock(); 1308 rtnl_unlock();
1308} 1309}
1309EXPORT_SYMBOL(netdev_notify_peers); 1310EXPORT_SYMBOL(netdev_notify_peers);
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 3945821e9c1f..65ea0ff4017c 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -953,7 +953,7 @@ net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
953 while (--i >= new_num) { 953 while (--i >= new_num) {
954 struct kobject *kobj = &dev->_rx[i].kobj; 954 struct kobject *kobj = &dev->_rx[i].kobj;
955 955
956 if (!list_empty(&dev_net(dev)->exit_list)) 956 if (!atomic_read(&dev_net(dev)->count))
957 kobj->uevent_suppress = 1; 957 kobj->uevent_suppress = 1;
958 if (dev->sysfs_rx_queue_group) 958 if (dev->sysfs_rx_queue_group)
959 sysfs_remove_group(kobj, dev->sysfs_rx_queue_group); 959 sysfs_remove_group(kobj, dev->sysfs_rx_queue_group);
@@ -1371,7 +1371,7 @@ netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
1371 while (--i >= new_num) { 1371 while (--i >= new_num) {
1372 struct netdev_queue *queue = dev->_tx + i; 1372 struct netdev_queue *queue = dev->_tx + i;
1373 1373
1374 if (!list_empty(&dev_net(dev)->exit_list)) 1374 if (!atomic_read(&dev_net(dev)->count))
1375 queue->kobj.uevent_suppress = 1; 1375 queue->kobj.uevent_suppress = 1;
1376#ifdef CONFIG_BQL 1376#ifdef CONFIG_BQL
1377 sysfs_remove_group(&queue->kobj, &dql_group); 1377 sysfs_remove_group(&queue->kobj, &dql_group);
@@ -1558,7 +1558,7 @@ void netdev_unregister_kobject(struct net_device *ndev)
1558{ 1558{
1559 struct device *dev = &(ndev->dev); 1559 struct device *dev = &(ndev->dev);
1560 1560
1561 if (!list_empty(&dev_net(ndev)->exit_list)) 1561 if (!atomic_read(&dev_net(ndev)->count))
1562 dev_set_uevent_suppress(dev, 1); 1562 dev_set_uevent_suppress(dev, 1);
1563 1563
1564 kobject_get(&dev->kobj); 1564 kobject_get(&dev->kobj);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f3557958e9bf..cd4ba8c6b609 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3828,13 +3828,14 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
3828 if (!skb_may_tx_timestamp(sk, false)) 3828 if (!skb_may_tx_timestamp(sk, false))
3829 return; 3829 return;
3830 3830
3831 /* take a reference to prevent skb_orphan() from freeing the socket */ 3831 /* Take a reference to prevent skb_orphan() from freeing the socket,
3832 sock_hold(sk); 3832 * but only if the socket refcount is not zero.
3833 3833 */
3834 *skb_hwtstamps(skb) = *hwtstamps; 3834 if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
3835 __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND); 3835 *skb_hwtstamps(skb) = *hwtstamps;
3836 3836 __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
3837 sock_put(sk); 3837 sock_put(sk);
3838 }
3838} 3839}
3839EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp); 3840EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);
3840 3841
@@ -3893,7 +3894,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
3893{ 3894{
3894 struct sock *sk = skb->sk; 3895 struct sock *sk = skb->sk;
3895 struct sock_exterr_skb *serr; 3896 struct sock_exterr_skb *serr;
3896 int err; 3897 int err = 1;
3897 3898
3898 skb->wifi_acked_valid = 1; 3899 skb->wifi_acked_valid = 1;
3899 skb->wifi_acked = acked; 3900 skb->wifi_acked = acked;
@@ -3903,14 +3904,15 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
3903 serr->ee.ee_errno = ENOMSG; 3904 serr->ee.ee_errno = ENOMSG;
3904 serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS; 3905 serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
3905 3906
3906 /* take a reference to prevent skb_orphan() from freeing the socket */ 3907 /* Take a reference to prevent skb_orphan() from freeing the socket,
3907 sock_hold(sk); 3908 * but only if the socket refcount is not zero.
3908 3909 */
3909 err = sock_queue_err_skb(sk, skb); 3910 if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
3911 err = sock_queue_err_skb(sk, skb);
3912 sock_put(sk);
3913 }
3910 if (err) 3914 if (err)
3911 kfree_skb(skb); 3915 kfree_skb(skb);
3912
3913 sock_put(sk);
3914} 3916}
3915EXPORT_SYMBOL_GPL(skb_complete_wifi_ack); 3917EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);
3916 3918
diff --git a/net/core/sock.c b/net/core/sock.c
index f6fd79f33097..a96d5f7a5734 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -197,66 +197,55 @@ EXPORT_SYMBOL(sk_net_capable);
197 197
198/* 198/*
199 * Each address family might have different locking rules, so we have 199 * Each address family might have different locking rules, so we have
200 * one slock key per address family: 200 * one slock key per address family and separate keys for internal and
201 * userspace sockets.
201 */ 202 */
202static struct lock_class_key af_family_keys[AF_MAX]; 203static struct lock_class_key af_family_keys[AF_MAX];
204static struct lock_class_key af_family_kern_keys[AF_MAX];
203static struct lock_class_key af_family_slock_keys[AF_MAX]; 205static struct lock_class_key af_family_slock_keys[AF_MAX];
206static struct lock_class_key af_family_kern_slock_keys[AF_MAX];
204 207
205/* 208/*
206 * Make lock validator output more readable. (we pre-construct these 209 * Make lock validator output more readable. (we pre-construct these
207 * strings build-time, so that runtime initialization of socket 210 * strings build-time, so that runtime initialization of socket
208 * locks is fast): 211 * locks is fast):
209 */ 212 */
213
214#define _sock_locks(x) \
215 x "AF_UNSPEC", x "AF_UNIX" , x "AF_INET" , \
216 x "AF_AX25" , x "AF_IPX" , x "AF_APPLETALK", \
217 x "AF_NETROM", x "AF_BRIDGE" , x "AF_ATMPVC" , \
218 x "AF_X25" , x "AF_INET6" , x "AF_ROSE" , \
219 x "AF_DECnet", x "AF_NETBEUI" , x "AF_SECURITY" , \
220 x "AF_KEY" , x "AF_NETLINK" , x "AF_PACKET" , \
221 x "AF_ASH" , x "AF_ECONET" , x "AF_ATMSVC" , \
222 x "AF_RDS" , x "AF_SNA" , x "AF_IRDA" , \
223 x "AF_PPPOX" , x "AF_WANPIPE" , x "AF_LLC" , \
224 x "27" , x "28" , x "AF_CAN" , \
225 x "AF_TIPC" , x "AF_BLUETOOTH", x "IUCV" , \
226 x "AF_RXRPC" , x "AF_ISDN" , x "AF_PHONET" , \
227 x "AF_IEEE802154", x "AF_CAIF" , x "AF_ALG" , \
228 x "AF_NFC" , x "AF_VSOCK" , x "AF_KCM" , \
229 x "AF_QIPCRTR", x "AF_SMC" , x "AF_MAX"
230
210static const char *const af_family_key_strings[AF_MAX+1] = { 231static const char *const af_family_key_strings[AF_MAX+1] = {
211 "sk_lock-AF_UNSPEC", "sk_lock-AF_UNIX" , "sk_lock-AF_INET" , 232 _sock_locks("sk_lock-")
212 "sk_lock-AF_AX25" , "sk_lock-AF_IPX" , "sk_lock-AF_APPLETALK",
213 "sk_lock-AF_NETROM", "sk_lock-AF_BRIDGE" , "sk_lock-AF_ATMPVC" ,
214 "sk_lock-AF_X25" , "sk_lock-AF_INET6" , "sk_lock-AF_ROSE" ,
215 "sk_lock-AF_DECnet", "sk_lock-AF_NETBEUI" , "sk_lock-AF_SECURITY" ,
216 "sk_lock-AF_KEY" , "sk_lock-AF_NETLINK" , "sk_lock-AF_PACKET" ,
217 "sk_lock-AF_ASH" , "sk_lock-AF_ECONET" , "sk_lock-AF_ATMSVC" ,
218 "sk_lock-AF_RDS" , "sk_lock-AF_SNA" , "sk_lock-AF_IRDA" ,
219 "sk_lock-AF_PPPOX" , "sk_lock-AF_WANPIPE" , "sk_lock-AF_LLC" ,
220 "sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" ,
221 "sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" ,
222 "sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" ,
223 "sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , "sk_lock-AF_ALG" ,
224 "sk_lock-AF_NFC" , "sk_lock-AF_VSOCK" , "sk_lock-AF_KCM" ,
225 "sk_lock-AF_QIPCRTR", "sk_lock-AF_SMC" , "sk_lock-AF_MAX"
226}; 233};
227static const char *const af_family_slock_key_strings[AF_MAX+1] = { 234static const char *const af_family_slock_key_strings[AF_MAX+1] = {
228 "slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" , 235 _sock_locks("slock-")
229 "slock-AF_AX25" , "slock-AF_IPX" , "slock-AF_APPLETALK",
230 "slock-AF_NETROM", "slock-AF_BRIDGE" , "slock-AF_ATMPVC" ,
231 "slock-AF_X25" , "slock-AF_INET6" , "slock-AF_ROSE" ,
232 "slock-AF_DECnet", "slock-AF_NETBEUI" , "slock-AF_SECURITY" ,
233 "slock-AF_KEY" , "slock-AF_NETLINK" , "slock-AF_PACKET" ,
234 "slock-AF_ASH" , "slock-AF_ECONET" , "slock-AF_ATMSVC" ,
235 "slock-AF_RDS" , "slock-AF_SNA" , "slock-AF_IRDA" ,
236 "slock-AF_PPPOX" , "slock-AF_WANPIPE" , "slock-AF_LLC" ,
237 "slock-27" , "slock-28" , "slock-AF_CAN" ,
238 "slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" ,
239 "slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" ,
240 "slock-AF_IEEE802154", "slock-AF_CAIF" , "slock-AF_ALG" ,
241 "slock-AF_NFC" , "slock-AF_VSOCK" ,"slock-AF_KCM" ,
242 "slock-AF_QIPCRTR", "slock-AF_SMC" , "slock-AF_MAX"
243}; 236};
244static const char *const af_family_clock_key_strings[AF_MAX+1] = { 237static const char *const af_family_clock_key_strings[AF_MAX+1] = {
245 "clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" , 238 _sock_locks("clock-")
246 "clock-AF_AX25" , "clock-AF_IPX" , "clock-AF_APPLETALK", 239};
247 "clock-AF_NETROM", "clock-AF_BRIDGE" , "clock-AF_ATMPVC" , 240
248 "clock-AF_X25" , "clock-AF_INET6" , "clock-AF_ROSE" , 241static const char *const af_family_kern_key_strings[AF_MAX+1] = {
249 "clock-AF_DECnet", "clock-AF_NETBEUI" , "clock-AF_SECURITY" , 242 _sock_locks("k-sk_lock-")
250 "clock-AF_KEY" , "clock-AF_NETLINK" , "clock-AF_PACKET" , 243};
251 "clock-AF_ASH" , "clock-AF_ECONET" , "clock-AF_ATMSVC" , 244static const char *const af_family_kern_slock_key_strings[AF_MAX+1] = {
252 "clock-AF_RDS" , "clock-AF_SNA" , "clock-AF_IRDA" , 245 _sock_locks("k-slock-")
253 "clock-AF_PPPOX" , "clock-AF_WANPIPE" , "clock-AF_LLC" , 246};
254 "clock-27" , "clock-28" , "clock-AF_CAN" , 247static const char *const af_family_kern_clock_key_strings[AF_MAX+1] = {
255 "clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" , 248 _sock_locks("k-clock-")
256 "clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" ,
257 "clock-AF_IEEE802154", "clock-AF_CAIF" , "clock-AF_ALG" ,
258 "clock-AF_NFC" , "clock-AF_VSOCK" , "clock-AF_KCM" ,
259 "clock-AF_QIPCRTR", "clock-AF_SMC" , "clock-AF_MAX"
260}; 249};
261 250
262/* 251/*
@@ -264,6 +253,7 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {
264 * so split the lock classes by using a per-AF key: 253 * so split the lock classes by using a per-AF key:
265 */ 254 */
266static struct lock_class_key af_callback_keys[AF_MAX]; 255static struct lock_class_key af_callback_keys[AF_MAX];
256static struct lock_class_key af_kern_callback_keys[AF_MAX];
267 257
268/* Take into consideration the size of the struct sk_buff overhead in the 258/* Take into consideration the size of the struct sk_buff overhead in the
269 * determination of these values, since that is non-constant across 259 * determination of these values, since that is non-constant across
@@ -1293,7 +1283,16 @@ lenout:
1293 */ 1283 */
1294static inline void sock_lock_init(struct sock *sk) 1284static inline void sock_lock_init(struct sock *sk)
1295{ 1285{
1296 sock_lock_init_class_and_name(sk, 1286 if (sk->sk_kern_sock)
1287 sock_lock_init_class_and_name(
1288 sk,
1289 af_family_kern_slock_key_strings[sk->sk_family],
1290 af_family_kern_slock_keys + sk->sk_family,
1291 af_family_kern_key_strings[sk->sk_family],
1292 af_family_kern_keys + sk->sk_family);
1293 else
1294 sock_lock_init_class_and_name(
1295 sk,
1297 af_family_slock_key_strings[sk->sk_family], 1296 af_family_slock_key_strings[sk->sk_family],
1298 af_family_slock_keys + sk->sk_family, 1297 af_family_slock_keys + sk->sk_family,
1299 af_family_key_strings[sk->sk_family], 1298 af_family_key_strings[sk->sk_family],
@@ -1399,6 +1398,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
1399 * why we need sk_prot_creator -acme 1398 * why we need sk_prot_creator -acme
1400 */ 1399 */
1401 sk->sk_prot = sk->sk_prot_creator = prot; 1400 sk->sk_prot = sk->sk_prot_creator = prot;
1401 sk->sk_kern_sock = kern;
1402 sock_lock_init(sk); 1402 sock_lock_init(sk);
1403 sk->sk_net_refcnt = kern ? 0 : 1; 1403 sk->sk_net_refcnt = kern ? 0 : 1;
1404 if (likely(sk->sk_net_refcnt)) 1404 if (likely(sk->sk_net_refcnt))
@@ -2277,7 +2277,8 @@ int sock_no_socketpair(struct socket *sock1, struct socket *sock2)
2277} 2277}
2278EXPORT_SYMBOL(sock_no_socketpair); 2278EXPORT_SYMBOL(sock_no_socketpair);
2279 2279
2280int sock_no_accept(struct socket *sock, struct socket *newsock, int flags) 2280int sock_no_accept(struct socket *sock, struct socket *newsock, int flags,
2281 bool kern)
2281{ 2282{
2282 return -EOPNOTSUPP; 2283 return -EOPNOTSUPP;
2283} 2284}
@@ -2481,7 +2482,14 @@ void sock_init_data(struct socket *sock, struct sock *sk)
2481 } 2482 }
2482 2483
2483 rwlock_init(&sk->sk_callback_lock); 2484 rwlock_init(&sk->sk_callback_lock);
2484 lockdep_set_class_and_name(&sk->sk_callback_lock, 2485 if (sk->sk_kern_sock)
2486 lockdep_set_class_and_name(
2487 &sk->sk_callback_lock,
2488 af_kern_callback_keys + sk->sk_family,
2489 af_family_kern_clock_key_strings[sk->sk_family]);
2490 else
2491 lockdep_set_class_and_name(
2492 &sk->sk_callback_lock,
2485 af_callback_keys + sk->sk_family, 2493 af_callback_keys + sk->sk_family,
2486 af_family_clock_key_strings[sk->sk_family]); 2494 af_family_clock_key_strings[sk->sk_family]);
2487 2495
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index f053198e730c..5e3a7302f774 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -749,6 +749,7 @@ static void ccid2_hc_tx_exit(struct sock *sk)
749 for (i = 0; i < hc->tx_seqbufc; i++) 749 for (i = 0; i < hc->tx_seqbufc; i++)
750 kfree(hc->tx_seqbuf[i]); 750 kfree(hc->tx_seqbuf[i]);
751 hc->tx_seqbufc = 0; 751 hc->tx_seqbufc = 0;
752 dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks);
752} 753}
753 754
754static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 755static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 409d0cfd3447..b99168b0fabf 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -289,7 +289,8 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
289 289
290 switch (type) { 290 switch (type) {
291 case ICMP_REDIRECT: 291 case ICMP_REDIRECT:
292 dccp_do_redirect(skb, sk); 292 if (!sock_owned_by_user(sk))
293 dccp_do_redirect(skb, sk);
293 goto out; 294 goto out;
294 case ICMP_SOURCE_QUENCH: 295 case ICMP_SOURCE_QUENCH:
295 /* Just silently ignore these. */ 296 /* Just silently ignore these. */
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 233b57367758..d9b6a4e403e7 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -122,10 +122,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
122 np = inet6_sk(sk); 122 np = inet6_sk(sk);
123 123
124 if (type == NDISC_REDIRECT) { 124 if (type == NDISC_REDIRECT) {
125 struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie); 125 if (!sock_owned_by_user(sk)) {
126 struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
126 127
127 if (dst) 128 if (dst)
128 dst->ops->redirect(dst, sk, skb); 129 dst->ops->redirect(dst, sk, skb);
130 }
129 goto out; 131 goto out;
130 } 132 }
131 133
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index e267e6f4c9a5..abd07a443219 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -142,6 +142,13 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
142 struct dccp_request_sock *dreq = dccp_rsk(req); 142 struct dccp_request_sock *dreq = dccp_rsk(req);
143 bool own_req; 143 bool own_req;
144 144
145 /* TCP/DCCP listeners became lockless.
146 * DCCP stores complex state in its request_sock, so we need
147 * a protection for them, now this code runs without being protected
148 * by the parent (listener) lock.
149 */
150 spin_lock_bh(&dreq->dreq_lock);
151
145 /* Check for retransmitted REQUEST */ 152 /* Check for retransmitted REQUEST */
146 if (dccp_hdr(skb)->dccph_type == DCCP_PKT_REQUEST) { 153 if (dccp_hdr(skb)->dccph_type == DCCP_PKT_REQUEST) {
147 154
@@ -156,7 +163,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
156 inet_rtx_syn_ack(sk, req); 163 inet_rtx_syn_ack(sk, req);
157 } 164 }
158 /* Network Duplicate, discard packet */ 165 /* Network Duplicate, discard packet */
159 return NULL; 166 goto out;
160 } 167 }
161 168
162 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR; 169 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
@@ -182,20 +189,20 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
182 189
183 child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL, 190 child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL,
184 req, &own_req); 191 req, &own_req);
185 if (!child) 192 if (child) {
186 goto listen_overflow; 193 child = inet_csk_complete_hashdance(sk, child, req, own_req);
187 194 goto out;
188 return inet_csk_complete_hashdance(sk, child, req, own_req); 195 }
189 196
190listen_overflow:
191 dccp_pr_debug("listen_overflow!\n");
192 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY; 197 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY;
193drop: 198drop:
194 if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET) 199 if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET)
195 req->rsk_ops->send_reset(sk, skb); 200 req->rsk_ops->send_reset(sk, skb);
196 201
197 inet_csk_reqsk_queue_drop(sk, req); 202 inet_csk_reqsk_queue_drop(sk, req);
198 return NULL; 203out:
204 spin_unlock_bh(&dreq->dreq_lock);
205 return child;
199} 206}
200 207
201EXPORT_SYMBOL_GPL(dccp_check_req); 208EXPORT_SYMBOL_GPL(dccp_check_req);
@@ -246,6 +253,7 @@ int dccp_reqsk_init(struct request_sock *req,
246{ 253{
247 struct dccp_request_sock *dreq = dccp_rsk(req); 254 struct dccp_request_sock *dreq = dccp_rsk(req);
248 255
256 spin_lock_init(&dreq->dreq_lock);
249 inet_rsk(req)->ir_rmt_port = dccp_hdr(skb)->dccph_sport; 257 inet_rsk(req)->ir_rmt_port = dccp_hdr(skb)->dccph_sport;
250 inet_rsk(req)->ir_num = ntohs(dccp_hdr(skb)->dccph_dport); 258 inet_rsk(req)->ir_num = ntohs(dccp_hdr(skb)->dccph_dport);
251 inet_rsk(req)->acked = 0; 259 inet_rsk(req)->acked = 0;
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index e6e79eda9763..7de5b40a5d0d 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -1070,7 +1070,8 @@ static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
1070 return skb == NULL ? ERR_PTR(err) : skb; 1070 return skb == NULL ? ERR_PTR(err) : skb;
1071} 1071}
1072 1072
1073static int dn_accept(struct socket *sock, struct socket *newsock, int flags) 1073static int dn_accept(struct socket *sock, struct socket *newsock, int flags,
1074 bool kern)
1074{ 1075{
1075 struct sock *sk = sock->sk, *newsk; 1076 struct sock *sk = sock->sk, *newsk;
1076 struct sk_buff *skb = NULL; 1077 struct sk_buff *skb = NULL;
@@ -1099,7 +1100,7 @@ static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
1099 1100
1100 cb = DN_SKB_CB(skb); 1101 cb = DN_SKB_CB(skb);
1101 sk->sk_ack_backlog--; 1102 sk->sk_ack_backlog--;
1102 newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, 0); 1103 newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, kern);
1103 if (newsk == NULL) { 1104 if (newsk == NULL) {
1104 release_sock(sk); 1105 release_sock(sk);
1105 kfree_skb(skb); 1106 kfree_skb(skb);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 602d40f43687..6b1fc6e4278e 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -689,11 +689,12 @@ EXPORT_SYMBOL(inet_stream_connect);
689 * Accept a pending connection. The TCP layer now gives BSD semantics. 689 * Accept a pending connection. The TCP layer now gives BSD semantics.
690 */ 690 */
691 691
692int inet_accept(struct socket *sock, struct socket *newsock, int flags) 692int inet_accept(struct socket *sock, struct socket *newsock, int flags,
693 bool kern)
693{ 694{
694 struct sock *sk1 = sock->sk; 695 struct sock *sk1 = sock->sk;
695 int err = -EINVAL; 696 int err = -EINVAL;
696 struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err); 697 struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err, kern);
697 698
698 if (!sk2) 699 if (!sk2)
699 goto do_err; 700 goto do_err;
@@ -1487,8 +1488,10 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff)
1487 int proto = iph->protocol; 1488 int proto = iph->protocol;
1488 int err = -ENOSYS; 1489 int err = -ENOSYS;
1489 1490
1490 if (skb->encapsulation) 1491 if (skb->encapsulation) {
1492 skb_set_inner_protocol(skb, cpu_to_be16(ETH_P_IP));
1491 skb_set_inner_network_header(skb, nhoff); 1493 skb_set_inner_network_header(skb, nhoff);
1494 }
1492 1495
1493 csum_replace2(&iph->check, iph->tot_len, newlen); 1496 csum_replace2(&iph->check, iph->tot_len, newlen);
1494 iph->tot_len = newlen; 1497 iph->tot_len = newlen;
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index b4d5980ade3b..5e313c1ac94f 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -424,7 +424,7 @@ static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
424/* 424/*
425 * This will accept the next outstanding connection. 425 * This will accept the next outstanding connection.
426 */ 426 */
427struct sock *inet_csk_accept(struct sock *sk, int flags, int *err) 427struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
428{ 428{
429 struct inet_connection_sock *icsk = inet_csk(sk); 429 struct inet_connection_sock *icsk = inet_csk(sk);
430 struct request_sock_queue *queue = &icsk->icsk_accept_queue; 430 struct request_sock_queue *queue = &icsk->icsk_accept_queue;
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 737ce826d7ec..7a3fd25e8913 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -966,7 +966,7 @@ static int __ip_append_data(struct sock *sk,
966 cork->length += length; 966 cork->length += length;
967 if ((((length + fragheaderlen) > mtu) || (skb && skb_is_gso(skb))) && 967 if ((((length + fragheaderlen) > mtu) || (skb && skb_is_gso(skb))) &&
968 (sk->sk_protocol == IPPROTO_UDP) && 968 (sk->sk_protocol == IPPROTO_UDP) &&
969 (rt->dst.dev->features & NETIF_F_UFO) && !rt->dst.header_len && 969 (rt->dst.dev->features & NETIF_F_UFO) && !dst_xfrm(&rt->dst) &&
970 (sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx) { 970 (sk->sk_type == SOCK_DGRAM) && !sk->sk_no_check_tx) {
971 err = ip_ufo_append_data(sk, queue, getfrag, from, length, 971 err = ip_ufo_append_data(sk, queue, getfrag, from, length,
972 hh_len, fragheaderlen, transhdrlen, 972 hh_len, fragheaderlen, transhdrlen,
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 9a89b8deafae..575e19dcc017 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -279,10 +279,13 @@ EXPORT_SYMBOL(tcp_v4_connect);
279 */ 279 */
280void tcp_v4_mtu_reduced(struct sock *sk) 280void tcp_v4_mtu_reduced(struct sock *sk)
281{ 281{
282 struct dst_entry *dst;
283 struct inet_sock *inet = inet_sk(sk); 282 struct inet_sock *inet = inet_sk(sk);
284 u32 mtu = tcp_sk(sk)->mtu_info; 283 struct dst_entry *dst;
284 u32 mtu;
285 285
286 if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
287 return;
288 mtu = tcp_sk(sk)->mtu_info;
286 dst = inet_csk_update_pmtu(sk, mtu); 289 dst = inet_csk_update_pmtu(sk, mtu);
287 if (!dst) 290 if (!dst)
288 return; 291 return;
@@ -428,7 +431,8 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
428 431
429 switch (type) { 432 switch (type) {
430 case ICMP_REDIRECT: 433 case ICMP_REDIRECT:
431 do_redirect(icmp_skb, sk); 434 if (!sock_owned_by_user(sk))
435 do_redirect(icmp_skb, sk);
432 goto out; 436 goto out;
433 case ICMP_SOURCE_QUENCH: 437 case ICMP_SOURCE_QUENCH:
434 /* Just silently ignore these. */ 438 /* Just silently ignore these. */
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 40d893556e67..b2ab411c6d37 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -249,7 +249,8 @@ void tcp_delack_timer_handler(struct sock *sk)
249 249
250 sk_mem_reclaim_partial(sk); 250 sk_mem_reclaim_partial(sk);
251 251
252 if (sk->sk_state == TCP_CLOSE || !(icsk->icsk_ack.pending & ICSK_ACK_TIMER)) 252 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
253 !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
253 goto out; 254 goto out;
254 255
255 if (time_after(icsk->icsk_ack.timeout, jiffies)) { 256 if (time_after(icsk->icsk_ack.timeout, jiffies)) {
@@ -552,7 +553,8 @@ void tcp_write_timer_handler(struct sock *sk)
552 struct inet_connection_sock *icsk = inet_csk(sk); 553 struct inet_connection_sock *icsk = inet_csk(sk);
553 int event; 554 int event;
554 555
555 if (sk->sk_state == TCP_CLOSE || !icsk->icsk_pending) 556 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
557 !icsk->icsk_pending)
556 goto out; 558 goto out;
557 559
558 if (time_after(icsk->icsk_timeout, jiffies)) { 560 if (time_after(icsk->icsk_timeout, jiffies)) {
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 04db40620ea6..a9a9553ee63d 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -920,12 +920,12 @@ static int __init inet6_init(void)
920 err = register_pernet_subsys(&inet6_net_ops); 920 err = register_pernet_subsys(&inet6_net_ops);
921 if (err) 921 if (err)
922 goto register_pernet_fail; 922 goto register_pernet_fail;
923 err = icmpv6_init();
924 if (err)
925 goto icmp_fail;
926 err = ip6_mr_init(); 923 err = ip6_mr_init();
927 if (err) 924 if (err)
928 goto ipmr_fail; 925 goto ipmr_fail;
926 err = icmpv6_init();
927 if (err)
928 goto icmp_fail;
929 err = ndisc_init(); 929 err = ndisc_init();
930 if (err) 930 if (err)
931 goto ndisc_fail; 931 goto ndisc_fail;
@@ -1061,10 +1061,10 @@ igmp_fail:
1061 ndisc_cleanup(); 1061 ndisc_cleanup();
1062ndisc_fail: 1062ndisc_fail:
1063 ip6_mr_cleanup(); 1063 ip6_mr_cleanup();
1064ipmr_fail:
1065 icmpv6_cleanup();
1066icmp_fail: 1064icmp_fail:
1067 unregister_pernet_subsys(&inet6_net_ops); 1065 unregister_pernet_subsys(&inet6_net_ops);
1066ipmr_fail:
1067 icmpv6_cleanup();
1068register_pernet_fail: 1068register_pernet_fail:
1069 sock_unregister(PF_INET6); 1069 sock_unregister(PF_INET6);
1070 rtnl_unregister_all(PF_INET6); 1070 rtnl_unregister_all(PF_INET6);
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index e4266746e4a2..d4bf2c68a545 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -923,6 +923,8 @@ add:
923 ins = &rt->dst.rt6_next; 923 ins = &rt->dst.rt6_next;
924 iter = *ins; 924 iter = *ins;
925 while (iter) { 925 while (iter) {
926 if (iter->rt6i_metric > rt->rt6i_metric)
927 break;
926 if (rt6_qualify_for_ecmp(iter)) { 928 if (rt6_qualify_for_ecmp(iter)) {
927 *ins = iter->dst.rt6_next; 929 *ins = iter->dst.rt6_next;
928 fib6_purge_rt(iter, fn, info->nl_net); 930 fib6_purge_rt(iter, fn, info->nl_net);
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
index 0838e6d01d2e..93e58a5e1837 100644
--- a/net/ipv6/ip6_offload.c
+++ b/net/ipv6/ip6_offload.c
@@ -294,8 +294,10 @@ static int ipv6_gro_complete(struct sk_buff *skb, int nhoff)
294 struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + nhoff); 294 struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + nhoff);
295 int err = -ENOSYS; 295 int err = -ENOSYS;
296 296
297 if (skb->encapsulation) 297 if (skb->encapsulation) {
298 skb_set_inner_protocol(skb, cpu_to_be16(ETH_P_IPV6));
298 skb_set_inner_network_header(skb, nhoff); 299 skb_set_inner_network_header(skb, nhoff);
300 }
299 301
300 iph->payload_len = htons(skb->len - nhoff - sizeof(*iph)); 302 iph->payload_len = htons(skb->len - nhoff - sizeof(*iph));
301 303
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 528b3c1f3fde..58f6288e9ba5 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -768,13 +768,14 @@ slow_path:
768 * Fragment the datagram. 768 * Fragment the datagram.
769 */ 769 */
770 770
771 *prevhdr = NEXTHDR_FRAGMENT;
772 troom = rt->dst.dev->needed_tailroom; 771 troom = rt->dst.dev->needed_tailroom;
773 772
774 /* 773 /*
775 * Keep copying data until we run out. 774 * Keep copying data until we run out.
776 */ 775 */
777 while (left > 0) { 776 while (left > 0) {
777 u8 *fragnexthdr_offset;
778
778 len = left; 779 len = left;
779 /* IF: it doesn't fit, use 'mtu' - the data space left */ 780 /* IF: it doesn't fit, use 'mtu' - the data space left */
780 if (len > mtu) 781 if (len > mtu)
@@ -819,6 +820,10 @@ slow_path:
819 */ 820 */
820 skb_copy_from_linear_data(skb, skb_network_header(frag), hlen); 821 skb_copy_from_linear_data(skb, skb_network_header(frag), hlen);
821 822
823 fragnexthdr_offset = skb_network_header(frag);
824 fragnexthdr_offset += prevhdr - skb_network_header(skb);
825 *fragnexthdr_offset = NEXTHDR_FRAGMENT;
826
822 /* 827 /*
823 * Build fragment header. 828 * Build fragment header.
824 */ 829 */
@@ -1385,7 +1390,7 @@ emsgsize:
1385 if ((((length + fragheaderlen) > mtu) || 1390 if ((((length + fragheaderlen) > mtu) ||
1386 (skb && skb_is_gso(skb))) && 1391 (skb && skb_is_gso(skb))) &&
1387 (sk->sk_protocol == IPPROTO_UDP) && 1392 (sk->sk_protocol == IPPROTO_UDP) &&
1388 (rt->dst.dev->features & NETIF_F_UFO) && !rt->dst.header_len && 1393 (rt->dst.dev->features & NETIF_F_UFO) && !dst_xfrm(&rt->dst) &&
1389 (sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk)) { 1394 (sk->sk_type == SOCK_DGRAM) && !udp_get_no_check6_tx(sk)) {
1390 err = ip6_ufo_append_data(sk, queue, getfrag, from, length, 1395 err = ip6_ufo_append_data(sk, queue, getfrag, from, length,
1391 hh_len, fragheaderlen, exthdrlen, 1396 hh_len, fragheaderlen, exthdrlen,
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index 644ba59fbd9d..3d8a3b63b4fd 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -485,11 +485,15 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
485 if (!skb->ignore_df && skb->len > mtu) { 485 if (!skb->ignore_df && skb->len > mtu) {
486 skb_dst(skb)->ops->update_pmtu(dst, NULL, skb, mtu); 486 skb_dst(skb)->ops->update_pmtu(dst, NULL, skb, mtu);
487 487
488 if (skb->protocol == htons(ETH_P_IPV6)) 488 if (skb->protocol == htons(ETH_P_IPV6)) {
489 if (mtu < IPV6_MIN_MTU)
490 mtu = IPV6_MIN_MTU;
491
489 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); 492 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
490 else 493 } else {
491 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, 494 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
492 htonl(mtu)); 495 htonl(mtu));
496 }
493 497
494 return -EMSGSIZE; 498 return -EMSGSIZE;
495 } 499 }
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 229bfcc451ef..35c58b669ebd 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3299,7 +3299,6 @@ static size_t rt6_nlmsg_size(struct rt6_info *rt)
3299 nexthop_len = nla_total_size(0) /* RTA_MULTIPATH */ 3299 nexthop_len = nla_total_size(0) /* RTA_MULTIPATH */
3300 + NLA_ALIGN(sizeof(struct rtnexthop)) 3300 + NLA_ALIGN(sizeof(struct rtnexthop))
3301 + nla_total_size(16) /* RTA_GATEWAY */ 3301 + nla_total_size(16) /* RTA_GATEWAY */
3302 + nla_total_size(4) /* RTA_OIF */
3303 + lwtunnel_get_encap_size(rt->dst.lwtstate); 3302 + lwtunnel_get_encap_size(rt->dst.lwtstate);
3304 3303
3305 nexthop_len *= rt->rt6i_nsiblings; 3304 nexthop_len *= rt->rt6i_nsiblings;
@@ -3323,7 +3322,7 @@ static size_t rt6_nlmsg_size(struct rt6_info *rt)
3323} 3322}
3324 3323
3325static int rt6_nexthop_info(struct sk_buff *skb, struct rt6_info *rt, 3324static int rt6_nexthop_info(struct sk_buff *skb, struct rt6_info *rt,
3326 unsigned int *flags) 3325 unsigned int *flags, bool skip_oif)
3327{ 3326{
3328 if (!netif_running(rt->dst.dev) || !netif_carrier_ok(rt->dst.dev)) { 3327 if (!netif_running(rt->dst.dev) || !netif_carrier_ok(rt->dst.dev)) {
3329 *flags |= RTNH_F_LINKDOWN; 3328 *flags |= RTNH_F_LINKDOWN;
@@ -3336,7 +3335,8 @@ static int rt6_nexthop_info(struct sk_buff *skb, struct rt6_info *rt,
3336 goto nla_put_failure; 3335 goto nla_put_failure;
3337 } 3336 }
3338 3337
3339 if (rt->dst.dev && 3338 /* not needed for multipath encoding b/c it has a rtnexthop struct */
3339 if (!skip_oif && rt->dst.dev &&
3340 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex)) 3340 nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex))
3341 goto nla_put_failure; 3341 goto nla_put_failure;
3342 3342
@@ -3350,6 +3350,7 @@ nla_put_failure:
3350 return -EMSGSIZE; 3350 return -EMSGSIZE;
3351} 3351}
3352 3352
3353/* add multipath next hop */
3353static int rt6_add_nexthop(struct sk_buff *skb, struct rt6_info *rt) 3354static int rt6_add_nexthop(struct sk_buff *skb, struct rt6_info *rt)
3354{ 3355{
3355 struct rtnexthop *rtnh; 3356 struct rtnexthop *rtnh;
@@ -3362,7 +3363,7 @@ static int rt6_add_nexthop(struct sk_buff *skb, struct rt6_info *rt)
3362 rtnh->rtnh_hops = 0; 3363 rtnh->rtnh_hops = 0;
3363 rtnh->rtnh_ifindex = rt->dst.dev ? rt->dst.dev->ifindex : 0; 3364 rtnh->rtnh_ifindex = rt->dst.dev ? rt->dst.dev->ifindex : 0;
3364 3365
3365 if (rt6_nexthop_info(skb, rt, &flags) < 0) 3366 if (rt6_nexthop_info(skb, rt, &flags, true) < 0)
3366 goto nla_put_failure; 3367 goto nla_put_failure;
3367 3368
3368 rtnh->rtnh_flags = flags; 3369 rtnh->rtnh_flags = flags;
@@ -3515,7 +3516,7 @@ static int rt6_fill_node(struct net *net,
3515 3516
3516 nla_nest_end(skb, mp); 3517 nla_nest_end(skb, mp);
3517 } else { 3518 } else {
3518 if (rt6_nexthop_info(skb, rt, &rtm->rtm_flags) < 0) 3519 if (rt6_nexthop_info(skb, rt, &rtm->rtm_flags, false) < 0)
3519 goto nla_put_failure; 3520 goto nla_put_failure;
3520 } 3521 }
3521 3522
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 60a5295a7de6..49fa2e8c3fa9 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -391,10 +391,12 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
391 np = inet6_sk(sk); 391 np = inet6_sk(sk);
392 392
393 if (type == NDISC_REDIRECT) { 393 if (type == NDISC_REDIRECT) {
394 struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie); 394 if (!sock_owned_by_user(sk)) {
395 struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
395 396
396 if (dst) 397 if (dst)
397 dst->ops->redirect(dst, sk, skb); 398 dst->ops->redirect(dst, sk, skb);
399 }
398 goto out; 400 goto out;
399 } 401 }
400 402
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 81adc29a448d..8d77ad5cadaf 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -828,7 +828,8 @@ out:
828 * Wait for incoming connection 828 * Wait for incoming connection
829 * 829 *
830 */ 830 */
831static int irda_accept(struct socket *sock, struct socket *newsock, int flags) 831static int irda_accept(struct socket *sock, struct socket *newsock, int flags,
832 bool kern)
832{ 833{
833 struct sock *sk = sock->sk; 834 struct sock *sk = sock->sk;
834 struct irda_sock *new, *self = irda_sk(sk); 835 struct irda_sock *new, *self = irda_sk(sk);
@@ -836,7 +837,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
836 struct sk_buff *skb = NULL; 837 struct sk_buff *skb = NULL;
837 int err; 838 int err;
838 839
839 err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0); 840 err = irda_create(sock_net(sk), newsock, sk->sk_protocol, kern);
840 if (err) 841 if (err)
841 return err; 842 return err;
842 843
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 89bbde1081ce..84de7b6326dc 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -938,7 +938,7 @@ done:
938 938
939/* Accept a pending connection */ 939/* Accept a pending connection */
940static int iucv_sock_accept(struct socket *sock, struct socket *newsock, 940static int iucv_sock_accept(struct socket *sock, struct socket *newsock,
941 int flags) 941 int flags, bool kern)
942{ 942{
943 DECLARE_WAITQUEUE(wait, current); 943 DECLARE_WAITQUEUE(wait, current);
944 struct sock *sk = sock->sk, *nsk; 944 struct sock *sk = sock->sk, *nsk;
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 06186d608a27..cb4fff785cbf 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -641,11 +641,13 @@ static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb)
641 * @sock: Socket which connections arrive on. 641 * @sock: Socket which connections arrive on.
642 * @newsock: Socket to move incoming connection to. 642 * @newsock: Socket to move incoming connection to.
643 * @flags: User specified operational flags. 643 * @flags: User specified operational flags.
644 * @kern: If the socket is kernel internal
644 * 645 *
645 * Accept a new incoming connection. 646 * Accept a new incoming connection.
646 * Returns 0 upon success, negative otherwise. 647 * Returns 0 upon success, negative otherwise.
647 */ 648 */
648static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags) 649static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags,
650 bool kern)
649{ 651{
650 struct sock *sk = sock->sk, *newsk; 652 struct sock *sk = sock->sk, *newsk;
651 struct llc_sock *llc, *newllc; 653 struct llc_sock *llc, *newllc;
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 3818686182b2..33211f9a2656 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -1288,7 +1288,8 @@ static void mpls_ifdown(struct net_device *dev, int event)
1288 /* fall through */ 1288 /* fall through */
1289 case NETDEV_CHANGE: 1289 case NETDEV_CHANGE:
1290 nh->nh_flags |= RTNH_F_LINKDOWN; 1290 nh->nh_flags |= RTNH_F_LINKDOWN;
1291 ACCESS_ONCE(rt->rt_nhn_alive) = rt->rt_nhn_alive - 1; 1291 if (event != NETDEV_UNREGISTER)
1292 ACCESS_ONCE(rt->rt_nhn_alive) = rt->rt_nhn_alive - 1;
1292 break; 1293 break;
1293 } 1294 }
1294 if (event == NETDEV_UNREGISTER) 1295 if (event == NETDEV_UNREGISTER)
@@ -2028,6 +2029,7 @@ static void mpls_net_exit(struct net *net)
2028 for (index = 0; index < platform_labels; index++) { 2029 for (index = 0; index < platform_labels; index++) {
2029 struct mpls_route *rt = rtnl_dereference(platform_label[index]); 2030 struct mpls_route *rt = rtnl_dereference(platform_label[index]);
2030 RCU_INIT_POINTER(platform_label[index], NULL); 2031 RCU_INIT_POINTER(platform_label[index], NULL);
2032 mpls_notify_route(net, index, rt, NULL, NULL);
2031 mpls_rt_free(rt); 2033 mpls_rt_free(rt);
2032 } 2034 }
2033 rtnl_unlock(); 2035 rtnl_unlock();
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 4bbf4526b885..ebf16f7f9089 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -765,7 +765,8 @@ out_release:
765 return err; 765 return err;
766} 766}
767 767
768static int nr_accept(struct socket *sock, struct socket *newsock, int flags) 768static int nr_accept(struct socket *sock, struct socket *newsock, int flags,
769 bool kern)
769{ 770{
770 struct sk_buff *skb; 771 struct sk_buff *skb;
771 struct sock *newsk; 772 struct sock *newsk;
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 879885b31cce..2ffb18e73df6 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -441,7 +441,7 @@ struct sock *nfc_llcp_accept_dequeue(struct sock *parent,
441} 441}
442 442
443static int llcp_sock_accept(struct socket *sock, struct socket *newsock, 443static int llcp_sock_accept(struct socket *sock, struct socket *newsock,
444 int flags) 444 int flags, bool kern)
445{ 445{
446 DECLARE_WAITQUEUE(wait, current); 446 DECLARE_WAITQUEUE(wait, current);
447 struct sock *sk = sock->sk, *new_sk; 447 struct sock *sk = sock->sk, *new_sk;
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 222bedcd9575..e81537991ddf 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -772,7 +772,8 @@ static void pep_sock_close(struct sock *sk, long timeout)
772 sock_put(sk); 772 sock_put(sk);
773} 773}
774 774
775static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp) 775static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
776 bool kern)
776{ 777{
777 struct pep_sock *pn = pep_sk(sk), *newpn; 778 struct pep_sock *pn = pep_sk(sk), *newpn;
778 struct sock *newsk = NULL; 779 struct sock *newsk = NULL;
@@ -846,7 +847,8 @@ static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
846 } 847 }
847 848
848 /* Create a new to-be-accepted sock */ 849 /* Create a new to-be-accepted sock */
849 newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot, 0); 850 newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot,
851 kern);
850 if (!newsk) { 852 if (!newsk) {
851 pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL); 853 pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL);
852 err = -ENOBUFS; 854 err = -ENOBUFS;
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index a6c8da3ee893..64634e3ec2fc 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -305,7 +305,7 @@ out:
305} 305}
306 306
307static int pn_socket_accept(struct socket *sock, struct socket *newsock, 307static int pn_socket_accept(struct socket *sock, struct socket *newsock,
308 int flags) 308 int flags, bool kern)
309{ 309{
310 struct sock *sk = sock->sk; 310 struct sock *sk = sock->sk;
311 struct sock *newsk; 311 struct sock *newsk;
@@ -314,7 +314,7 @@ static int pn_socket_accept(struct socket *sock, struct socket *newsock,
314 if (unlikely(sk->sk_state != TCP_LISTEN)) 314 if (unlikely(sk->sk_state != TCP_LISTEN))
315 return -EINVAL; 315 return -EINVAL;
316 316
317 newsk = sk->sk_prot->accept(sk, flags, &err); 317 newsk = sk->sk_prot->accept(sk, flags, &err, kern);
318 if (!newsk) 318 if (!newsk)
319 return err; 319 return err;
320 320
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 0e04dcceb1d4..1fa75ab7b733 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -429,6 +429,7 @@ void rds_conn_destroy(struct rds_connection *conn)
429 */ 429 */
430 rds_cong_remove_conn(conn); 430 rds_cong_remove_conn(conn);
431 431
432 put_net(conn->c_net);
432 kmem_cache_free(rds_conn_slab, conn); 433 kmem_cache_free(rds_conn_slab, conn);
433 434
434 spin_lock_irqsave(&rds_conn_lock, flags); 435 spin_lock_irqsave(&rds_conn_lock, flags);
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index ce3775abc6e7..1c38d2c7caa8 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -442,7 +442,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
442 ic->i_send_cq = NULL; 442 ic->i_send_cq = NULL;
443 ibdev_put_vector(rds_ibdev, ic->i_scq_vector); 443 ibdev_put_vector(rds_ibdev, ic->i_scq_vector);
444 rdsdebug("ib_create_cq send failed: %d\n", ret); 444 rdsdebug("ib_create_cq send failed: %d\n", ret);
445 goto out; 445 goto rds_ibdev_out;
446 } 446 }
447 447
448 ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev); 448 ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev);
@@ -456,19 +456,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
456 ic->i_recv_cq = NULL; 456 ic->i_recv_cq = NULL;
457 ibdev_put_vector(rds_ibdev, ic->i_rcq_vector); 457 ibdev_put_vector(rds_ibdev, ic->i_rcq_vector);
458 rdsdebug("ib_create_cq recv failed: %d\n", ret); 458 rdsdebug("ib_create_cq recv failed: %d\n", ret);
459 goto out; 459 goto send_cq_out;
460 } 460 }
461 461
462 ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP); 462 ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP);
463 if (ret) { 463 if (ret) {
464 rdsdebug("ib_req_notify_cq send failed: %d\n", ret); 464 rdsdebug("ib_req_notify_cq send failed: %d\n", ret);
465 goto out; 465 goto recv_cq_out;
466 } 466 }
467 467
468 ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED); 468 ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
469 if (ret) { 469 if (ret) {
470 rdsdebug("ib_req_notify_cq recv failed: %d\n", ret); 470 rdsdebug("ib_req_notify_cq recv failed: %d\n", ret);
471 goto out; 471 goto recv_cq_out;
472 } 472 }
473 473
474 /* XXX negotiate max send/recv with remote? */ 474 /* XXX negotiate max send/recv with remote? */
@@ -494,7 +494,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
494 ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr); 494 ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
495 if (ret) { 495 if (ret) {
496 rdsdebug("rdma_create_qp failed: %d\n", ret); 496 rdsdebug("rdma_create_qp failed: %d\n", ret);
497 goto out; 497 goto recv_cq_out;
498 } 498 }
499 499
500 ic->i_send_hdrs = ib_dma_alloc_coherent(dev, 500 ic->i_send_hdrs = ib_dma_alloc_coherent(dev,
@@ -504,7 +504,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
504 if (!ic->i_send_hdrs) { 504 if (!ic->i_send_hdrs) {
505 ret = -ENOMEM; 505 ret = -ENOMEM;
506 rdsdebug("ib_dma_alloc_coherent send failed\n"); 506 rdsdebug("ib_dma_alloc_coherent send failed\n");
507 goto out; 507 goto qp_out;
508 } 508 }
509 509
510 ic->i_recv_hdrs = ib_dma_alloc_coherent(dev, 510 ic->i_recv_hdrs = ib_dma_alloc_coherent(dev,
@@ -514,7 +514,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
514 if (!ic->i_recv_hdrs) { 514 if (!ic->i_recv_hdrs) {
515 ret = -ENOMEM; 515 ret = -ENOMEM;
516 rdsdebug("ib_dma_alloc_coherent recv failed\n"); 516 rdsdebug("ib_dma_alloc_coherent recv failed\n");
517 goto out; 517 goto send_hdrs_dma_out;
518 } 518 }
519 519
520 ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header), 520 ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
@@ -522,7 +522,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
522 if (!ic->i_ack) { 522 if (!ic->i_ack) {
523 ret = -ENOMEM; 523 ret = -ENOMEM;
524 rdsdebug("ib_dma_alloc_coherent ack failed\n"); 524 rdsdebug("ib_dma_alloc_coherent ack failed\n");
525 goto out; 525 goto recv_hdrs_dma_out;
526 } 526 }
527 527
528 ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work), 528 ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work),
@@ -530,7 +530,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
530 if (!ic->i_sends) { 530 if (!ic->i_sends) {
531 ret = -ENOMEM; 531 ret = -ENOMEM;
532 rdsdebug("send allocation failed\n"); 532 rdsdebug("send allocation failed\n");
533 goto out; 533 goto ack_dma_out;
534 } 534 }
535 535
536 ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_recv_work), 536 ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_recv_work),
@@ -538,7 +538,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
538 if (!ic->i_recvs) { 538 if (!ic->i_recvs) {
539 ret = -ENOMEM; 539 ret = -ENOMEM;
540 rdsdebug("recv allocation failed\n"); 540 rdsdebug("recv allocation failed\n");
541 goto out; 541 goto sends_out;
542 } 542 }
543 543
544 rds_ib_recv_init_ack(ic); 544 rds_ib_recv_init_ack(ic);
@@ -546,8 +546,33 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
546 rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd, 546 rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
547 ic->i_send_cq, ic->i_recv_cq); 547 ic->i_send_cq, ic->i_recv_cq);
548 548
549out: 549 return ret;
550
551sends_out:
552 vfree(ic->i_sends);
553ack_dma_out:
554 ib_dma_free_coherent(dev, sizeof(struct rds_header),
555 ic->i_ack, ic->i_ack_dma);
556recv_hdrs_dma_out:
557 ib_dma_free_coherent(dev, ic->i_recv_ring.w_nr *
558 sizeof(struct rds_header),
559 ic->i_recv_hdrs, ic->i_recv_hdrs_dma);
560send_hdrs_dma_out:
561 ib_dma_free_coherent(dev, ic->i_send_ring.w_nr *
562 sizeof(struct rds_header),
563 ic->i_send_hdrs, ic->i_send_hdrs_dma);
564qp_out:
565 rdma_destroy_qp(ic->i_cm_id);
566recv_cq_out:
567 if (!ib_destroy_cq(ic->i_recv_cq))
568 ic->i_recv_cq = NULL;
569send_cq_out:
570 if (!ib_destroy_cq(ic->i_send_cq))
571 ic->i_send_cq = NULL;
572rds_ibdev_out:
573 rds_ib_remove_conn(rds_ibdev, conn);
550 rds_ib_dev_put(rds_ibdev); 574 rds_ib_dev_put(rds_ibdev);
575
551 return ret; 576 return ret;
552} 577}
553 578
diff --git a/net/rds/rds.h b/net/rds/rds.h
index 39518ef7af4d..82d38ccf5e8b 100644
--- a/net/rds/rds.h
+++ b/net/rds/rds.h
@@ -147,7 +147,7 @@ struct rds_connection {
147 147
148 /* Protocol version */ 148 /* Protocol version */
149 unsigned int c_version; 149 unsigned int c_version;
150 possible_net_t c_net; 150 struct net *c_net;
151 151
152 struct list_head c_map_item; 152 struct list_head c_map_item;
153 unsigned long c_map_queued; 153 unsigned long c_map_queued;
@@ -162,13 +162,13 @@ struct rds_connection {
162static inline 162static inline
163struct net *rds_conn_net(struct rds_connection *conn) 163struct net *rds_conn_net(struct rds_connection *conn)
164{ 164{
165 return read_pnet(&conn->c_net); 165 return conn->c_net;
166} 166}
167 167
168static inline 168static inline
169void rds_conn_net_set(struct rds_connection *conn, struct net *net) 169void rds_conn_net_set(struct rds_connection *conn, struct net *net)
170{ 170{
171 write_pnet(&conn->c_net, net); 171 conn->c_net = get_net(net);
172} 172}
173 173
174#define RDS_FLAG_CONG_BITMAP 0x01 174#define RDS_FLAG_CONG_BITMAP 0x01
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index a973d3b4dff0..225690076773 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -484,9 +484,10 @@ static void __net_exit rds_tcp_exit_net(struct net *net)
484 * we do need to clean up the listen socket here. 484 * we do need to clean up the listen socket here.
485 */ 485 */
486 if (rtn->rds_tcp_listen_sock) { 486 if (rtn->rds_tcp_listen_sock) {
487 rds_tcp_listen_stop(rtn->rds_tcp_listen_sock); 487 struct socket *lsock = rtn->rds_tcp_listen_sock;
488
488 rtn->rds_tcp_listen_sock = NULL; 489 rtn->rds_tcp_listen_sock = NULL;
489 flush_work(&rtn->rds_tcp_accept_w); 490 rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
490 } 491 }
491} 492}
492 493
@@ -523,13 +524,13 @@ static void rds_tcp_kill_sock(struct net *net)
523 struct rds_tcp_connection *tc, *_tc; 524 struct rds_tcp_connection *tc, *_tc;
524 LIST_HEAD(tmp_list); 525 LIST_HEAD(tmp_list);
525 struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); 526 struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
527 struct socket *lsock = rtn->rds_tcp_listen_sock;
526 528
527 rds_tcp_listen_stop(rtn->rds_tcp_listen_sock);
528 rtn->rds_tcp_listen_sock = NULL; 529 rtn->rds_tcp_listen_sock = NULL;
529 flush_work(&rtn->rds_tcp_accept_w); 530 rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
530 spin_lock_irq(&rds_tcp_conn_lock); 531 spin_lock_irq(&rds_tcp_conn_lock);
531 list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) { 532 list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
532 struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net); 533 struct net *c_net = tc->t_cpath->cp_conn->c_net;
533 534
534 if (net != c_net || !tc->t_sock) 535 if (net != c_net || !tc->t_sock)
535 continue; 536 continue;
@@ -546,8 +547,12 @@ static void rds_tcp_kill_sock(struct net *net)
546void *rds_tcp_listen_sock_def_readable(struct net *net) 547void *rds_tcp_listen_sock_def_readable(struct net *net)
547{ 548{
548 struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); 549 struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
550 struct socket *lsock = rtn->rds_tcp_listen_sock;
551
552 if (!lsock)
553 return NULL;
549 554
550 return rtn->rds_tcp_listen_sock->sk->sk_user_data; 555 return lsock->sk->sk_user_data;
551} 556}
552 557
553static int rds_tcp_dev_event(struct notifier_block *this, 558static int rds_tcp_dev_event(struct notifier_block *this,
@@ -584,7 +589,7 @@ static void rds_tcp_sysctl_reset(struct net *net)
584 589
585 spin_lock_irq(&rds_tcp_conn_lock); 590 spin_lock_irq(&rds_tcp_conn_lock);
586 list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) { 591 list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
587 struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net); 592 struct net *c_net = tc->t_cpath->cp_conn->c_net;
588 593
589 if (net != c_net || !tc->t_sock) 594 if (net != c_net || !tc->t_sock)
590 continue; 595 continue;
@@ -638,19 +643,19 @@ static int rds_tcp_init(void)
638 goto out; 643 goto out;
639 } 644 }
640 645
641 ret = register_netdevice_notifier(&rds_tcp_dev_notifier); 646 ret = rds_tcp_recv_init();
642 if (ret) { 647 if (ret)
643 pr_warn("could not register rds_tcp_dev_notifier\n");
644 goto out_slab; 648 goto out_slab;
645 }
646 649
647 ret = register_pernet_subsys(&rds_tcp_net_ops); 650 ret = register_pernet_subsys(&rds_tcp_net_ops);
648 if (ret) 651 if (ret)
649 goto out_notifier; 652 goto out_recv;
650 653
651 ret = rds_tcp_recv_init(); 654 ret = register_netdevice_notifier(&rds_tcp_dev_notifier);
652 if (ret) 655 if (ret) {
656 pr_warn("could not register rds_tcp_dev_notifier\n");
653 goto out_pernet; 657 goto out_pernet;
658 }
654 659
655 rds_trans_register(&rds_tcp_transport); 660 rds_trans_register(&rds_tcp_transport);
656 661
@@ -660,9 +665,8 @@ static int rds_tcp_init(void)
660 665
661out_pernet: 666out_pernet:
662 unregister_pernet_subsys(&rds_tcp_net_ops); 667 unregister_pernet_subsys(&rds_tcp_net_ops);
663out_notifier: 668out_recv:
664 if (unregister_netdevice_notifier(&rds_tcp_dev_notifier)) 669 rds_tcp_recv_exit();
665 pr_warn("could not unregister rds_tcp_dev_notifier\n");
666out_slab: 670out_slab:
667 kmem_cache_destroy(rds_tcp_conn_slab); 671 kmem_cache_destroy(rds_tcp_conn_slab);
668out: 672out:
diff --git a/net/rds/tcp.h b/net/rds/tcp.h
index 9a1cc8906576..56ea6620fcf9 100644
--- a/net/rds/tcp.h
+++ b/net/rds/tcp.h
@@ -66,7 +66,7 @@ void rds_tcp_state_change(struct sock *sk);
66 66
67/* tcp_listen.c */ 67/* tcp_listen.c */
68struct socket *rds_tcp_listen_init(struct net *); 68struct socket *rds_tcp_listen_init(struct net *);
69void rds_tcp_listen_stop(struct socket *); 69void rds_tcp_listen_stop(struct socket *sock, struct work_struct *acceptor);
70void rds_tcp_listen_data_ready(struct sock *sk); 70void rds_tcp_listen_data_ready(struct sock *sk);
71int rds_tcp_accept_one(struct socket *sock); 71int rds_tcp_accept_one(struct socket *sock);
72int rds_tcp_keepalive(struct socket *sock); 72int rds_tcp_keepalive(struct socket *sock);
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 67d0929c7d3d..507678853e6c 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -133,7 +133,7 @@ int rds_tcp_accept_one(struct socket *sock)
133 133
134 new_sock->type = sock->type; 134 new_sock->type = sock->type;
135 new_sock->ops = sock->ops; 135 new_sock->ops = sock->ops;
136 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK); 136 ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true);
137 if (ret < 0) 137 if (ret < 0)
138 goto out; 138 goto out;
139 139
@@ -223,6 +223,9 @@ void rds_tcp_listen_data_ready(struct sock *sk)
223 * before it has been accepted and the accepter has set up their 223 * before it has been accepted and the accepter has set up their
224 * data_ready.. we only want to queue listen work for our listening 224 * data_ready.. we only want to queue listen work for our listening
225 * socket 225 * socket
226 *
227 * (*ready)() may be null if we are racing with netns delete, and
228 * the listen socket is being torn down.
226 */ 229 */
227 if (sk->sk_state == TCP_LISTEN) 230 if (sk->sk_state == TCP_LISTEN)
228 rds_tcp_accept_work(sk); 231 rds_tcp_accept_work(sk);
@@ -231,7 +234,8 @@ void rds_tcp_listen_data_ready(struct sock *sk)
231 234
232out: 235out:
233 read_unlock_bh(&sk->sk_callback_lock); 236 read_unlock_bh(&sk->sk_callback_lock);
234 ready(sk); 237 if (ready)
238 ready(sk);
235} 239}
236 240
237struct socket *rds_tcp_listen_init(struct net *net) 241struct socket *rds_tcp_listen_init(struct net *net)
@@ -271,7 +275,7 @@ out:
271 return NULL; 275 return NULL;
272} 276}
273 277
274void rds_tcp_listen_stop(struct socket *sock) 278void rds_tcp_listen_stop(struct socket *sock, struct work_struct *acceptor)
275{ 279{
276 struct sock *sk; 280 struct sock *sk;
277 281
@@ -292,5 +296,6 @@ void rds_tcp_listen_stop(struct socket *sock)
292 296
293 /* wait for accepts to stop and close the socket */ 297 /* wait for accepts to stop and close the socket */
294 flush_workqueue(rds_wq); 298 flush_workqueue(rds_wq);
299 flush_work(acceptor);
295 sock_release(sock); 300 sock_release(sock);
296} 301}
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index b8a1df2c9785..4a9729257023 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -871,7 +871,8 @@ out_release:
871 return err; 871 return err;
872} 872}
873 873
874static int rose_accept(struct socket *sock, struct socket *newsock, int flags) 874static int rose_accept(struct socket *sock, struct socket *newsock, int flags,
875 bool kern)
875{ 876{
876 struct sk_buff *skb; 877 struct sk_buff *skb;
877 struct sock *newsk; 878 struct sock *newsk;
diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
index 9f4cfa25af7c..18b2ad8be8e2 100644
--- a/net/rxrpc/input.c
+++ b/net/rxrpc/input.c
@@ -420,6 +420,7 @@ static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb,
420 u16 skew) 420 u16 skew)
421{ 421{
422 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 422 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
423 enum rxrpc_call_state state;
423 unsigned int offset = sizeof(struct rxrpc_wire_header); 424 unsigned int offset = sizeof(struct rxrpc_wire_header);
424 unsigned int ix; 425 unsigned int ix;
425 rxrpc_serial_t serial = sp->hdr.serial, ack_serial = 0; 426 rxrpc_serial_t serial = sp->hdr.serial, ack_serial = 0;
@@ -434,14 +435,15 @@ static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb,
434 _proto("Rx DATA %%%u { #%u f=%02x }", 435 _proto("Rx DATA %%%u { #%u f=%02x }",
435 sp->hdr.serial, seq, sp->hdr.flags); 436 sp->hdr.serial, seq, sp->hdr.flags);
436 437
437 if (call->state >= RXRPC_CALL_COMPLETE) 438 state = READ_ONCE(call->state);
439 if (state >= RXRPC_CALL_COMPLETE)
438 return; 440 return;
439 441
440 /* Received data implicitly ACKs all of the request packets we sent 442 /* Received data implicitly ACKs all of the request packets we sent
441 * when we're acting as a client. 443 * when we're acting as a client.
442 */ 444 */
443 if ((call->state == RXRPC_CALL_CLIENT_SEND_REQUEST || 445 if ((state == RXRPC_CALL_CLIENT_SEND_REQUEST ||
444 call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) && 446 state == RXRPC_CALL_CLIENT_AWAIT_REPLY) &&
445 !rxrpc_receiving_reply(call)) 447 !rxrpc_receiving_reply(call))
446 return; 448 return;
447 449
@@ -650,6 +652,7 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
650 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 652 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
651 struct rxrpc_peer *peer; 653 struct rxrpc_peer *peer;
652 unsigned int mtu; 654 unsigned int mtu;
655 bool wake = false;
653 u32 rwind = ntohl(ackinfo->rwind); 656 u32 rwind = ntohl(ackinfo->rwind);
654 657
655 _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }", 658 _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
@@ -657,9 +660,14 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
657 ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU), 660 ntohl(ackinfo->rxMTU), ntohl(ackinfo->maxMTU),
658 rwind, ntohl(ackinfo->jumbo_max)); 661 rwind, ntohl(ackinfo->jumbo_max));
659 662
660 if (rwind > RXRPC_RXTX_BUFF_SIZE - 1) 663 if (call->tx_winsize != rwind) {
661 rwind = RXRPC_RXTX_BUFF_SIZE - 1; 664 if (rwind > RXRPC_RXTX_BUFF_SIZE - 1)
662 call->tx_winsize = rwind; 665 rwind = RXRPC_RXTX_BUFF_SIZE - 1;
666 if (rwind > call->tx_winsize)
667 wake = true;
668 call->tx_winsize = rwind;
669 }
670
663 if (call->cong_ssthresh > rwind) 671 if (call->cong_ssthresh > rwind)
664 call->cong_ssthresh = rwind; 672 call->cong_ssthresh = rwind;
665 673
@@ -673,6 +681,9 @@ static void rxrpc_input_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
673 spin_unlock_bh(&peer->lock); 681 spin_unlock_bh(&peer->lock);
674 _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata); 682 _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
675 } 683 }
684
685 if (wake)
686 wake_up(&call->waitq);
676} 687}
677 688
678/* 689/*
@@ -799,7 +810,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
799 return rxrpc_proto_abort("AK0", call, 0); 810 return rxrpc_proto_abort("AK0", call, 0);
800 811
801 /* Ignore ACKs unless we are or have just been transmitting. */ 812 /* Ignore ACKs unless we are or have just been transmitting. */
802 switch (call->state) { 813 switch (READ_ONCE(call->state)) {
803 case RXRPC_CALL_CLIENT_SEND_REQUEST: 814 case RXRPC_CALL_CLIENT_SEND_REQUEST:
804 case RXRPC_CALL_CLIENT_AWAIT_REPLY: 815 case RXRPC_CALL_CLIENT_AWAIT_REPLY:
805 case RXRPC_CALL_SERVER_SEND_REPLY: 816 case RXRPC_CALL_SERVER_SEND_REPLY:
@@ -940,7 +951,7 @@ static void rxrpc_input_call_packet(struct rxrpc_call *call,
940static void rxrpc_input_implicit_end_call(struct rxrpc_connection *conn, 951static void rxrpc_input_implicit_end_call(struct rxrpc_connection *conn,
941 struct rxrpc_call *call) 952 struct rxrpc_call *call)
942{ 953{
943 switch (call->state) { 954 switch (READ_ONCE(call->state)) {
944 case RXRPC_CALL_SERVER_AWAIT_ACK: 955 case RXRPC_CALL_SERVER_AWAIT_ACK:
945 rxrpc_call_completed(call); 956 rxrpc_call_completed(call);
946 break; 957 break;
diff --git a/net/rxrpc/recvmsg.c b/net/rxrpc/recvmsg.c
index 6491ca46a03f..3e2f1a8e9c5b 100644
--- a/net/rxrpc/recvmsg.c
+++ b/net/rxrpc/recvmsg.c
@@ -527,7 +527,7 @@ try_again:
527 msg->msg_namelen = len; 527 msg->msg_namelen = len;
528 } 528 }
529 529
530 switch (call->state) { 530 switch (READ_ONCE(call->state)) {
531 case RXRPC_CALL_SERVER_ACCEPTING: 531 case RXRPC_CALL_SERVER_ACCEPTING:
532 ret = rxrpc_recvmsg_new_call(rx, call, msg, flags); 532 ret = rxrpc_recvmsg_new_call(rx, call, msg, flags);
533 break; 533 break;
@@ -640,7 +640,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
640 640
641 mutex_lock(&call->user_mutex); 641 mutex_lock(&call->user_mutex);
642 642
643 switch (call->state) { 643 switch (READ_ONCE(call->state)) {
644 case RXRPC_CALL_CLIENT_RECV_REPLY: 644 case RXRPC_CALL_CLIENT_RECV_REPLY:
645 case RXRPC_CALL_SERVER_RECV_REQUEST: 645 case RXRPC_CALL_SERVER_RECV_REQUEST:
646 case RXRPC_CALL_SERVER_ACK_REQUEST: 646 case RXRPC_CALL_SERVER_ACK_REQUEST:
diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
index bc2d3dcff9de..97ab214ca411 100644
--- a/net/rxrpc/sendmsg.c
+++ b/net/rxrpc/sendmsg.c
@@ -488,6 +488,7 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
488int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) 488int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
489 __releases(&rx->sk.sk_lock.slock) 489 __releases(&rx->sk.sk_lock.slock)
490{ 490{
491 enum rxrpc_call_state state;
491 enum rxrpc_command cmd; 492 enum rxrpc_command cmd;
492 struct rxrpc_call *call; 493 struct rxrpc_call *call;
493 unsigned long user_call_ID = 0; 494 unsigned long user_call_ID = 0;
@@ -526,13 +527,17 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
526 return PTR_ERR(call); 527 return PTR_ERR(call);
527 /* ... and we have the call lock. */ 528 /* ... and we have the call lock. */
528 } else { 529 } else {
529 ret = -EBUSY; 530 switch (READ_ONCE(call->state)) {
530 if (call->state == RXRPC_CALL_UNINITIALISED || 531 case RXRPC_CALL_UNINITIALISED:
531 call->state == RXRPC_CALL_CLIENT_AWAIT_CONN || 532 case RXRPC_CALL_CLIENT_AWAIT_CONN:
532 call->state == RXRPC_CALL_SERVER_PREALLOC || 533 case RXRPC_CALL_SERVER_PREALLOC:
533 call->state == RXRPC_CALL_SERVER_SECURING || 534 case RXRPC_CALL_SERVER_SECURING:
534 call->state == RXRPC_CALL_SERVER_ACCEPTING) 535 case RXRPC_CALL_SERVER_ACCEPTING:
536 ret = -EBUSY;
535 goto error_release_sock; 537 goto error_release_sock;
538 default:
539 break;
540 }
536 541
537 ret = mutex_lock_interruptible(&call->user_mutex); 542 ret = mutex_lock_interruptible(&call->user_mutex);
538 release_sock(&rx->sk); 543 release_sock(&rx->sk);
@@ -542,10 +547,11 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
542 } 547 }
543 } 548 }
544 549
550 state = READ_ONCE(call->state);
545 _debug("CALL %d USR %lx ST %d on CONN %p", 551 _debug("CALL %d USR %lx ST %d on CONN %p",
546 call->debug_id, call->user_call_ID, call->state, call->conn); 552 call->debug_id, call->user_call_ID, state, call->conn);
547 553
548 if (call->state >= RXRPC_CALL_COMPLETE) { 554 if (state >= RXRPC_CALL_COMPLETE) {
549 /* it's too late for this call */ 555 /* it's too late for this call */
550 ret = -ESHUTDOWN; 556 ret = -ESHUTDOWN;
551 } else if (cmd == RXRPC_CMD_SEND_ABORT) { 557 } else if (cmd == RXRPC_CMD_SEND_ABORT) {
@@ -555,12 +561,12 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
555 } else if (cmd != RXRPC_CMD_SEND_DATA) { 561 } else if (cmd != RXRPC_CMD_SEND_DATA) {
556 ret = -EINVAL; 562 ret = -EINVAL;
557 } else if (rxrpc_is_client_call(call) && 563 } else if (rxrpc_is_client_call(call) &&
558 call->state != RXRPC_CALL_CLIENT_SEND_REQUEST) { 564 state != RXRPC_CALL_CLIENT_SEND_REQUEST) {
559 /* request phase complete for this client call */ 565 /* request phase complete for this client call */
560 ret = -EPROTO; 566 ret = -EPROTO;
561 } else if (rxrpc_is_service_call(call) && 567 } else if (rxrpc_is_service_call(call) &&
562 call->state != RXRPC_CALL_SERVER_ACK_REQUEST && 568 state != RXRPC_CALL_SERVER_ACK_REQUEST &&
563 call->state != RXRPC_CALL_SERVER_SEND_REPLY) { 569 state != RXRPC_CALL_SERVER_SEND_REPLY) {
564 /* Reply phase not begun or not complete for service call. */ 570 /* Reply phase not begun or not complete for service call. */
565 ret = -EPROTO; 571 ret = -EPROTO;
566 } else { 572 } else {
@@ -605,14 +611,21 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
605 _debug("CALL %d USR %lx ST %d on CONN %p", 611 _debug("CALL %d USR %lx ST %d on CONN %p",
606 call->debug_id, call->user_call_ID, call->state, call->conn); 612 call->debug_id, call->user_call_ID, call->state, call->conn);
607 613
608 if (call->state >= RXRPC_CALL_COMPLETE) { 614 switch (READ_ONCE(call->state)) {
609 ret = -ESHUTDOWN; /* it's too late for this call */ 615 case RXRPC_CALL_CLIENT_SEND_REQUEST:
610 } else if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST && 616 case RXRPC_CALL_SERVER_ACK_REQUEST:
611 call->state != RXRPC_CALL_SERVER_ACK_REQUEST && 617 case RXRPC_CALL_SERVER_SEND_REPLY:
612 call->state != RXRPC_CALL_SERVER_SEND_REPLY) {
613 ret = -EPROTO; /* request phase complete for this client call */
614 } else {
615 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len); 618 ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len);
619 break;
620 case RXRPC_CALL_COMPLETE:
621 read_lock_bh(&call->state_lock);
622 ret = -call->error;
623 read_unlock_bh(&call->state_lock);
624 break;
625 default:
626 /* Request phase complete for this client call */
627 ret = -EPROTO;
628 break;
616 } 629 }
617 630
618 mutex_unlock(&call->user_mutex); 631 mutex_unlock(&call->user_mutex);
diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index ab8062909962..f9bb43c25697 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -113,6 +113,9 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
113 if (ret < 0) 113 if (ret < 0)
114 return ret; 114 return ret;
115 115
116 if (!tb[TCA_CONNMARK_PARMS])
117 return -EINVAL;
118
116 parm = nla_data(tb[TCA_CONNMARK_PARMS]); 119 parm = nla_data(tb[TCA_CONNMARK_PARMS]);
117 120
118 if (!tcf_hash_check(tn, parm->index, a, bind)) { 121 if (!tcf_hash_check(tn, parm->index, a, bind)) {
diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index 3b7074e23024..c736627f8f4a 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -228,7 +228,6 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
228 228
229 return skb->len; 229 return skb->len;
230nla_put_failure: 230nla_put_failure:
231 rcu_read_unlock();
232 nlmsg_trim(skb, b); 231 nlmsg_trim(skb, b);
233 return -1; 232 return -1;
234} 233}
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 063baac5b9fe..961ee59f696a 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -640,14 +640,15 @@ static sctp_scope_t sctp_v6_scope(union sctp_addr *addr)
640 640
641/* Create and initialize a new sk for the socket to be returned by accept(). */ 641/* Create and initialize a new sk for the socket to be returned by accept(). */
642static struct sock *sctp_v6_create_accept_sk(struct sock *sk, 642static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
643 struct sctp_association *asoc) 643 struct sctp_association *asoc,
644 bool kern)
644{ 645{
645 struct sock *newsk; 646 struct sock *newsk;
646 struct ipv6_pinfo *newnp, *np = inet6_sk(sk); 647 struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
647 struct sctp6_sock *newsctp6sk; 648 struct sctp6_sock *newsctp6sk;
648 struct ipv6_txoptions *opt; 649 struct ipv6_txoptions *opt;
649 650
650 newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, 0); 651 newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, kern);
651 if (!newsk) 652 if (!newsk)
652 goto out; 653 goto out;
653 654
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 1b6d4574d2b0..989a900383b5 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -575,10 +575,11 @@ static int sctp_v4_is_ce(const struct sk_buff *skb)
575 575
576/* Create and initialize a new sk for the socket returned by accept(). */ 576/* Create and initialize a new sk for the socket returned by accept(). */
577static struct sock *sctp_v4_create_accept_sk(struct sock *sk, 577static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
578 struct sctp_association *asoc) 578 struct sctp_association *asoc,
579 bool kern)
579{ 580{
580 struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL, 581 struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL,
581 sk->sk_prot, 0); 582 sk->sk_prot, kern);
582 struct inet_sock *newinet; 583 struct inet_sock *newinet;
583 584
584 if (!newsk) 585 if (!newsk)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 6f0a9be50f50..0f378ea2ae38 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4116,7 +4116,7 @@ static int sctp_disconnect(struct sock *sk, int flags)
4116 * descriptor will be returned from accept() to represent the newly 4116 * descriptor will be returned from accept() to represent the newly
4117 * formed association. 4117 * formed association.
4118 */ 4118 */
4119static struct sock *sctp_accept(struct sock *sk, int flags, int *err) 4119static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
4120{ 4120{
4121 struct sctp_sock *sp; 4121 struct sctp_sock *sp;
4122 struct sctp_endpoint *ep; 4122 struct sctp_endpoint *ep;
@@ -4151,7 +4151,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err)
4151 */ 4151 */
4152 asoc = list_entry(ep->asocs.next, struct sctp_association, asocs); 4152 asoc = list_entry(ep->asocs.next, struct sctp_association, asocs);
4153 4153
4154 newsk = sp->pf->create_accept_sk(sk, asoc); 4154 newsk = sp->pf->create_accept_sk(sk, asoc, kern);
4155 if (!newsk) { 4155 if (!newsk) {
4156 error = -ENOMEM; 4156 error = -ENOMEM;
4157 goto out; 4157 goto out;
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 85837ab90e89..093803786eac 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -944,7 +944,7 @@ out:
944} 944}
945 945
946static int smc_accept(struct socket *sock, struct socket *new_sock, 946static int smc_accept(struct socket *sock, struct socket *new_sock,
947 int flags) 947 int flags, bool kern)
948{ 948{
949 struct sock *sk = sock->sk, *nsk; 949 struct sock *sk = sock->sk, *nsk;
950 DECLARE_WAITQUEUE(wait, current); 950 DECLARE_WAITQUEUE(wait, current);
diff --git a/net/socket.c b/net/socket.c
index 2c1e8677ff2d..e034fe4164be 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1506,7 +1506,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
1506 if (err) 1506 if (err)
1507 goto out_fd; 1507 goto out_fd;
1508 1508
1509 err = sock->ops->accept(sock, newsock, sock->file->f_flags); 1509 err = sock->ops->accept(sock, newsock, sock->file->f_flags, false);
1510 if (err < 0) 1510 if (err < 0)
1511 goto out_fd; 1511 goto out_fd;
1512 1512
@@ -1731,6 +1731,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
1731 /* We assume all kernel code knows the size of sockaddr_storage */ 1731 /* We assume all kernel code knows the size of sockaddr_storage */
1732 msg.msg_namelen = 0; 1732 msg.msg_namelen = 0;
1733 msg.msg_iocb = NULL; 1733 msg.msg_iocb = NULL;
1734 msg.msg_flags = 0;
1734 if (sock->file->f_flags & O_NONBLOCK) 1735 if (sock->file->f_flags & O_NONBLOCK)
1735 flags |= MSG_DONTWAIT; 1736 flags |= MSG_DONTWAIT;
1736 err = sock_recvmsg(sock, &msg, flags); 1737 err = sock_recvmsg(sock, &msg, flags);
@@ -3238,7 +3239,7 @@ int kernel_accept(struct socket *sock, struct socket **newsock, int flags)
3238 if (err < 0) 3239 if (err < 0)
3239 goto done; 3240 goto done;
3240 3241
3241 err = sock->ops->accept(sock, *newsock, flags); 3242 err = sock->ops->accept(sock, *newsock, flags, true);
3242 if (err < 0) { 3243 if (err < 0) {
3243 sock_release(*newsock); 3244 sock_release(*newsock);
3244 *newsock = NULL; 3245 *newsock = NULL;
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 43e4045e72bc..7130e73bd42c 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -115,7 +115,8 @@ static void tipc_data_ready(struct sock *sk);
115static void tipc_write_space(struct sock *sk); 115static void tipc_write_space(struct sock *sk);
116static void tipc_sock_destruct(struct sock *sk); 116static void tipc_sock_destruct(struct sock *sk);
117static int tipc_release(struct socket *sock); 117static int tipc_release(struct socket *sock);
118static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); 118static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
119 bool kern);
119static void tipc_sk_timeout(unsigned long data); 120static void tipc_sk_timeout(unsigned long data);
120static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, 121static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
121 struct tipc_name_seq const *seq); 122 struct tipc_name_seq const *seq);
@@ -2029,7 +2030,8 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
2029 * 2030 *
2030 * Returns 0 on success, errno otherwise 2031 * Returns 0 on success, errno otherwise
2031 */ 2032 */
2032static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) 2033static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
2034 bool kern)
2033{ 2035{
2034 struct sock *new_sk, *sk = sock->sk; 2036 struct sock *new_sk, *sk = sock->sk;
2035 struct sk_buff *buf; 2037 struct sk_buff *buf;
@@ -2051,7 +2053,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
2051 2053
2052 buf = skb_peek(&sk->sk_receive_queue); 2054 buf = skb_peek(&sk->sk_receive_queue);
2053 2055
2054 res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 0); 2056 res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, kern);
2055 if (res) 2057 if (res)
2056 goto exit; 2058 goto exit;
2057 security_sk_clone(sock->sk, new_sock->sk); 2059 security_sk_clone(sock->sk, new_sock->sk);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ee37b390260a..928691c43408 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -636,7 +636,7 @@ static int unix_bind(struct socket *, struct sockaddr *, int);
636static int unix_stream_connect(struct socket *, struct sockaddr *, 636static int unix_stream_connect(struct socket *, struct sockaddr *,
637 int addr_len, int flags); 637 int addr_len, int flags);
638static int unix_socketpair(struct socket *, struct socket *); 638static int unix_socketpair(struct socket *, struct socket *);
639static int unix_accept(struct socket *, struct socket *, int); 639static int unix_accept(struct socket *, struct socket *, int, bool);
640static int unix_getname(struct socket *, struct sockaddr *, int *, int); 640static int unix_getname(struct socket *, struct sockaddr *, int *, int);
641static unsigned int unix_poll(struct file *, struct socket *, poll_table *); 641static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
642static unsigned int unix_dgram_poll(struct file *, struct socket *, 642static unsigned int unix_dgram_poll(struct file *, struct socket *,
@@ -1402,7 +1402,8 @@ static void unix_sock_inherit_flags(const struct socket *old,
1402 set_bit(SOCK_PASSSEC, &new->flags); 1402 set_bit(SOCK_PASSSEC, &new->flags);
1403} 1403}
1404 1404
1405static int unix_accept(struct socket *sock, struct socket *newsock, int flags) 1405static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
1406 bool kern)
1406{ 1407{
1407 struct sock *sk = sock->sk; 1408 struct sock *sk = sock->sk;
1408 struct sock *tsk; 1409 struct sock *tsk;
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 9192ead66751..9f770f33c100 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1250,7 +1250,8 @@ out:
1250 return err; 1250 return err;
1251} 1251}
1252 1252
1253static int vsock_accept(struct socket *sock, struct socket *newsock, int flags) 1253static int vsock_accept(struct socket *sock, struct socket *newsock, int flags,
1254 bool kern)
1254{ 1255{
1255 struct sock *listener; 1256 struct sock *listener;
1256 int err; 1257 int err;
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index fd28a49dbe8f..8b911c29860e 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -852,7 +852,8 @@ static int x25_wait_for_data(struct sock *sk, long timeout)
852 return rc; 852 return rc;
853} 853}
854 854
855static int x25_accept(struct socket *sock, struct socket *newsock, int flags) 855static int x25_accept(struct socket *sock, struct socket *newsock, int flags,
856 bool kern)
856{ 857{
857 struct sock *sk = sock->sk; 858 struct sock *sk = sock->sk;
858 struct sock *newsk; 859 struct sock *newsk;
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 0806dccdf507..236cbbc0ab9c 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1243,7 +1243,7 @@ static inline int policy_to_flow_dir(int dir)
1243} 1243}
1244 1244
1245static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir, 1245static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
1246 const struct flowi *fl) 1246 const struct flowi *fl, u16 family)
1247{ 1247{
1248 struct xfrm_policy *pol; 1248 struct xfrm_policy *pol;
1249 1249
@@ -1251,8 +1251,7 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
1251 again: 1251 again:
1252 pol = rcu_dereference(sk->sk_policy[dir]); 1252 pol = rcu_dereference(sk->sk_policy[dir]);
1253 if (pol != NULL) { 1253 if (pol != NULL) {
1254 bool match = xfrm_selector_match(&pol->selector, fl, 1254 bool match = xfrm_selector_match(&pol->selector, fl, family);
1255 sk->sk_family);
1256 int err = 0; 1255 int err = 0;
1257 1256
1258 if (match) { 1257 if (match) {
@@ -2239,7 +2238,7 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
2239 sk = sk_const_to_full_sk(sk); 2238 sk = sk_const_to_full_sk(sk);
2240 if (sk && sk->sk_policy[XFRM_POLICY_OUT]) { 2239 if (sk && sk->sk_policy[XFRM_POLICY_OUT]) {
2241 num_pols = 1; 2240 num_pols = 1;
2242 pols[0] = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl); 2241 pols[0] = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl, family);
2243 err = xfrm_expand_policies(fl, family, pols, 2242 err = xfrm_expand_policies(fl, family, pols,
2244 &num_pols, &num_xfrms); 2243 &num_pols, &num_xfrms);
2245 if (err < 0) 2244 if (err < 0)
@@ -2518,7 +2517,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
2518 pol = NULL; 2517 pol = NULL;
2519 sk = sk_to_full_sk(sk); 2518 sk = sk_to_full_sk(sk);
2520 if (sk && sk->sk_policy[dir]) { 2519 if (sk && sk->sk_policy[dir]) {
2521 pol = xfrm_sk_policy_lookup(sk, dir, &fl); 2520 pol = xfrm_sk_policy_lookup(sk, dir, &fl, family);
2522 if (IS_ERR(pol)) { 2521 if (IS_ERR(pol)) {
2523 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR); 2522 XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
2524 return 0; 2523 return 0;
@@ -3069,6 +3068,11 @@ static int __net_init xfrm_net_init(struct net *net)
3069{ 3068{
3070 int rv; 3069 int rv;
3071 3070
3071 /* Initialize the per-net locks here */
3072 spin_lock_init(&net->xfrm.xfrm_state_lock);
3073 spin_lock_init(&net->xfrm.xfrm_policy_lock);
3074 mutex_init(&net->xfrm.xfrm_cfg_mutex);
3075
3072 rv = xfrm_statistics_init(net); 3076 rv = xfrm_statistics_init(net);
3073 if (rv < 0) 3077 if (rv < 0)
3074 goto out_statistics; 3078 goto out_statistics;
@@ -3085,11 +3089,6 @@ static int __net_init xfrm_net_init(struct net *net)
3085 if (rv < 0) 3089 if (rv < 0)
3086 goto out; 3090 goto out;
3087 3091
3088 /* Initialize the per-net locks here */
3089 spin_lock_init(&net->xfrm.xfrm_state_lock);
3090 spin_lock_init(&net->xfrm.xfrm_policy_lock);
3091 mutex_init(&net->xfrm.xfrm_cfg_mutex);
3092
3093 return 0; 3092 return 0;
3094 3093
3095out: 3094out:
diff --git a/tools/include/uapi/linux/bpf_perf_event.h b/tools/include/uapi/linux/bpf_perf_event.h
new file mode 100644
index 000000000000..067427259820
--- /dev/null
+++ b/tools/include/uapi/linux/bpf_perf_event.h
@@ -0,0 +1,18 @@
1/* Copyright (c) 2016 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#ifndef _UAPI__LINUX_BPF_PERF_EVENT_H__
8#define _UAPI__LINUX_BPF_PERF_EVENT_H__
9
10#include <linux/types.h>
11#include <linux/ptrace.h>
12
13struct bpf_perf_event_data {
14 struct pt_regs regs;
15 __u64 sample_period;
16};
17
18#endif /* _UAPI__LINUX_BPF_PERF_EVENT_H__ */
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 4b498265dae6..67531f47781b 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -1,12 +1,14 @@
1LIBDIR := ../../../lib 1LIBDIR := ../../../lib
2BPFOBJ := $(LIBDIR)/bpf/bpf.o 2BPFOBJ := $(LIBDIR)/bpf/bpf.o
3 3
4CFLAGS += -Wall -O2 -lcap -I../../../include/uapi -I$(LIBDIR) 4CFLAGS += -Wall -O2 -lcap -I../../../include/uapi -I$(LIBDIR) $(BPFOBJ)
5 5
6TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map 6TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map
7 7
8TEST_PROGS := test_kmod.sh 8TEST_PROGS := test_kmod.sh
9 9
10all: $(TEST_GEN_PROGS)
11
10.PHONY: all clean force 12.PHONY: all clean force
11 13
12# force a rebuild of BPFOBJ when its dependencies are updated 14# force a rebuild of BPFOBJ when its dependencies are updated
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index e1f5b9eea1e8..d1555e4240c0 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -8,6 +8,8 @@
8 * License as published by the Free Software Foundation. 8 * License as published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <asm/types.h>
12#include <linux/types.h>
11#include <stdint.h> 13#include <stdint.h>
12#include <stdio.h> 14#include <stdio.h>
13#include <stdlib.h> 15#include <stdlib.h>
@@ -4583,10 +4585,12 @@ static bool is_admin(void)
4583 cap_flag_value_t sysadmin = CAP_CLEAR; 4585 cap_flag_value_t sysadmin = CAP_CLEAR;
4584 const cap_value_t cap_val = CAP_SYS_ADMIN; 4586 const cap_value_t cap_val = CAP_SYS_ADMIN;
4585 4587
4588#ifdef CAP_IS_SUPPORTED
4586 if (!CAP_IS_SUPPORTED(CAP_SETFCAP)) { 4589 if (!CAP_IS_SUPPORTED(CAP_SETFCAP)) {
4587 perror("cap_get_flag"); 4590 perror("cap_get_flag");
4588 return false; 4591 return false;
4589 } 4592 }
4593#endif
4590 caps = cap_get_proc(); 4594 caps = cap_get_proc();
4591 if (!caps) { 4595 if (!caps) {
4592 perror("cap_get_proc"); 4596 perror("cap_get_proc");
diff --git a/tools/testing/selftests/powerpc/include/vsx_asm.h b/tools/testing/selftests/powerpc/include/vsx_asm.h
index d828bfb6ef2d..54064ced9e95 100644
--- a/tools/testing/selftests/powerpc/include/vsx_asm.h
+++ b/tools/testing/selftests/powerpc/include/vsx_asm.h
@@ -16,56 +16,56 @@
16 */ 16 */
17FUNC_START(load_vsx) 17FUNC_START(load_vsx)
18 li r5,0 18 li r5,0
19 lxvx vs20,r5,r3 19 lxvd2x vs20,r5,r3
20 addi r5,r5,16 20 addi r5,r5,16
21 lxvx vs21,r5,r3 21 lxvd2x vs21,r5,r3
22 addi r5,r5,16 22 addi r5,r5,16
23 lxvx vs22,r5,r3 23 lxvd2x vs22,r5,r3
24 addi r5,r5,16 24 addi r5,r5,16
25 lxvx vs23,r5,r3 25 lxvd2x vs23,r5,r3
26 addi r5,r5,16 26 addi r5,r5,16
27 lxvx vs24,r5,r3 27 lxvd2x vs24,r5,r3
28 addi r5,r5,16 28 addi r5,r5,16
29 lxvx vs25,r5,r3 29 lxvd2x vs25,r5,r3
30 addi r5,r5,16 30 addi r5,r5,16
31 lxvx vs26,r5,r3 31 lxvd2x vs26,r5,r3
32 addi r5,r5,16 32 addi r5,r5,16
33 lxvx vs27,r5,r3 33 lxvd2x vs27,r5,r3
34 addi r5,r5,16 34 addi r5,r5,16
35 lxvx vs28,r5,r3 35 lxvd2x vs28,r5,r3
36 addi r5,r5,16 36 addi r5,r5,16
37 lxvx vs29,r5,r3 37 lxvd2x vs29,r5,r3
38 addi r5,r5,16 38 addi r5,r5,16
39 lxvx vs30,r5,r3 39 lxvd2x vs30,r5,r3
40 addi r5,r5,16 40 addi r5,r5,16
41 lxvx vs31,r5,r3 41 lxvd2x vs31,r5,r3
42 blr 42 blr
43FUNC_END(load_vsx) 43FUNC_END(load_vsx)
44 44
45FUNC_START(store_vsx) 45FUNC_START(store_vsx)
46 li r5,0 46 li r5,0
47 stxvx vs20,r5,r3 47 stxvd2x vs20,r5,r3
48 addi r5,r5,16 48 addi r5,r5,16
49 stxvx vs21,r5,r3 49 stxvd2x vs21,r5,r3
50 addi r5,r5,16 50 addi r5,r5,16
51 stxvx vs22,r5,r3 51 stxvd2x vs22,r5,r3
52 addi r5,r5,16 52 addi r5,r5,16
53 stxvx vs23,r5,r3 53 stxvd2x vs23,r5,r3
54 addi r5,r5,16 54 addi r5,r5,16
55 stxvx vs24,r5,r3 55 stxvd2x vs24,r5,r3
56 addi r5,r5,16 56 addi r5,r5,16
57 stxvx vs25,r5,r3 57 stxvd2x vs25,r5,r3
58 addi r5,r5,16 58 addi r5,r5,16
59 stxvx vs26,r5,r3 59 stxvd2x vs26,r5,r3
60 addi r5,r5,16 60 addi r5,r5,16
61 stxvx vs27,r5,r3 61 stxvd2x vs27,r5,r3
62 addi r5,r5,16 62 addi r5,r5,16
63 stxvx vs28,r5,r3 63 stxvd2x vs28,r5,r3
64 addi r5,r5,16 64 addi r5,r5,16
65 stxvx vs29,r5,r3 65 stxvd2x vs29,r5,r3
66 addi r5,r5,16 66 addi r5,r5,16
67 stxvx vs30,r5,r3 67 stxvd2x vs30,r5,r3
68 addi r5,r5,16 68 addi r5,r5,16
69 stxvx vs31,r5,r3 69 stxvd2x vs31,r5,r3
70 blr 70 blr
71FUNC_END(store_vsx) 71FUNC_END(store_vsx)