Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Robin Holt | a374c57 | 2009-04-13 14:40:18 -0700 | [diff] [blame] | 6 | * Copyright (c) 2008-2009 Silicon Graphics, Inc. All Rights Reserved. |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Cross Partition Communication (XPC) sn2-based functions. |
| 11 | * |
| 12 | * Architecture specific implementation of common functions. |
| 13 | * |
| 14 | */ |
| 15 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 18 | #include <asm/uncached.h> |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 19 | #include <asm/sn/mspec.h> |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 20 | #include <asm/sn/sn_sal.h> |
| 21 | #include "xpc.h" |
| 22 | |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Define the number of u64s required to represent all the C-brick nasids |
| 25 | * as a bitmap. The cross-partition kernel modules deal only with |
| 26 | * C-brick nasids, thus the need for bitmaps which don't account for |
| 27 | * odd-numbered (non C-brick) nasids. |
| 28 | */ |
| 29 | #define XPC_MAX_PHYSNODES_SN2 (MAX_NUMALINK_NODES / 2) |
| 30 | #define XP_NASID_MASK_BYTES_SN2 ((XPC_MAX_PHYSNODES_SN2 + 7) / 8) |
| 31 | #define XP_NASID_MASK_WORDS_SN2 ((XPC_MAX_PHYSNODES_SN2 + 63) / 64) |
| 32 | |
| 33 | /* |
| 34 | * Memory for XPC's amo variables is allocated by the MSPEC driver. These |
| 35 | * pages are located in the lowest granule. The lowest granule uses 4k pages |
| 36 | * for cached references and an alternate TLB handler to never provide a |
| 37 | * cacheable mapping for the entire region. This will prevent speculative |
| 38 | * reading of cached copies of our lines from being issued which will cause |
| 39 | * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64 |
| 40 | * amo variables (based on XP_MAX_NPARTITIONS_SN2) to identify the senders of |
| 41 | * NOTIFY IRQs, 128 amo variables (based on XP_NASID_MASK_WORDS_SN2) to identify |
| 42 | * the senders of ACTIVATE IRQs, 1 amo variable to identify which remote |
| 43 | * partitions (i.e., XPCs) consider themselves currently engaged with the |
| 44 | * local XPC and 1 amo variable to request partition deactivation. |
| 45 | */ |
| 46 | #define XPC_NOTIFY_IRQ_AMOS_SN2 0 |
| 47 | #define XPC_ACTIVATE_IRQ_AMOS_SN2 (XPC_NOTIFY_IRQ_AMOS_SN2 + \ |
| 48 | XP_MAX_NPARTITIONS_SN2) |
| 49 | #define XPC_ENGAGED_PARTITIONS_AMO_SN2 (XPC_ACTIVATE_IRQ_AMOS_SN2 + \ |
| 50 | XP_NASID_MASK_WORDS_SN2) |
| 51 | #define XPC_DEACTIVATE_REQUEST_AMO_SN2 (XPC_ENGAGED_PARTITIONS_AMO_SN2 + 1) |
| 52 | |
| 53 | /* |
| 54 | * Buffer used to store a local copy of portions of a remote partition's |
| 55 | * reserved page (either its header and part_nasids mask, or its vars). |
| 56 | */ |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 57 | static void *xpc_remote_copy_buffer_base_sn2; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 58 | static char *xpc_remote_copy_buffer_sn2; |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 59 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 60 | static struct xpc_vars_sn2 *xpc_vars_sn2; |
| 61 | static struct xpc_vars_part_sn2 *xpc_vars_part_sn2; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 62 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 63 | static int |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 64 | xpc_setup_partitions_sn2(void) |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 65 | { |
| 66 | /* nothing needs to be done */ |
| 67 | return 0; |
| 68 | } |
| 69 | |
Jack Steiner | 6f2584f | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 70 | static void |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 71 | xpc_teardown_partitions_sn2(void) |
Jack Steiner | 6f2584f | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 72 | { |
| 73 | /* nothing needs to be done */ |
| 74 | } |
| 75 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 76 | /* SH_IPI_ACCESS shub register value on startup */ |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 77 | static u64 xpc_sh1_IPI_access_sn2; |
| 78 | static u64 xpc_sh2_IPI_access0_sn2; |
| 79 | static u64 xpc_sh2_IPI_access1_sn2; |
| 80 | static u64 xpc_sh2_IPI_access2_sn2; |
| 81 | static u64 xpc_sh2_IPI_access3_sn2; |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Change protections to allow IPI operations. |
| 85 | */ |
| 86 | static void |
| 87 | xpc_allow_IPI_ops_sn2(void) |
| 88 | { |
| 89 | int node; |
| 90 | int nasid; |
| 91 | |
Dean Nelson | ea57f80 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 92 | /* !!! The following should get moved into SAL. */ |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 93 | if (is_shub2()) { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 94 | xpc_sh2_IPI_access0_sn2 = |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 95 | (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0)); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 96 | xpc_sh2_IPI_access1_sn2 = |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 97 | (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1)); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 98 | xpc_sh2_IPI_access2_sn2 = |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 99 | (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2)); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 100 | xpc_sh2_IPI_access3_sn2 = |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 101 | (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3)); |
| 102 | |
| 103 | for_each_online_node(node) { |
| 104 | nasid = cnodeid_to_nasid(node); |
| 105 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0), |
| 106 | -1UL); |
| 107 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1), |
| 108 | -1UL); |
| 109 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2), |
| 110 | -1UL); |
| 111 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3), |
| 112 | -1UL); |
| 113 | } |
| 114 | } else { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 115 | xpc_sh1_IPI_access_sn2 = |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 116 | (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS)); |
| 117 | |
| 118 | for_each_online_node(node) { |
| 119 | nasid = cnodeid_to_nasid(node); |
| 120 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS), |
| 121 | -1UL); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Restrict protections to disallow IPI operations. |
| 128 | */ |
| 129 | static void |
| 130 | xpc_disallow_IPI_ops_sn2(void) |
| 131 | { |
| 132 | int node; |
| 133 | int nasid; |
| 134 | |
Dean Nelson | ea57f80 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 135 | /* !!! The following should get moved into SAL. */ |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 136 | if (is_shub2()) { |
| 137 | for_each_online_node(node) { |
| 138 | nasid = cnodeid_to_nasid(node); |
| 139 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0), |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 140 | xpc_sh2_IPI_access0_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 141 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1), |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 142 | xpc_sh2_IPI_access1_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 143 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2), |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 144 | xpc_sh2_IPI_access2_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 145 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3), |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 146 | xpc_sh2_IPI_access3_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 147 | } |
| 148 | } else { |
| 149 | for_each_online_node(node) { |
| 150 | nasid = cnodeid_to_nasid(node); |
| 151 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS), |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 152 | xpc_sh1_IPI_access_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 157 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 158 | * The following set of functions are used for the sending and receiving of |
| 159 | * IRQs (also known as IPIs). There are two flavors of IRQs, one that is |
| 160 | * associated with partition activity (SGI_XPC_ACTIVATE) and the other that |
| 161 | * is associated with channel activity (SGI_XPC_NOTIFY). |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 162 | */ |
| 163 | |
| 164 | static u64 |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 165 | xpc_receive_IRQ_amo_sn2(struct amo *amo) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 166 | { |
| 167 | return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_CLEAR); |
| 168 | } |
| 169 | |
| 170 | static enum xp_retval |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 171 | xpc_send_IRQ_sn2(struct amo *amo, u64 flag, int nasid, int phys_cpuid, |
| 172 | int vector) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 173 | { |
| 174 | int ret = 0; |
| 175 | unsigned long irq_flags; |
| 176 | |
| 177 | local_irq_save(irq_flags); |
| 178 | |
| 179 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, flag); |
| 180 | sn_send_IPI_phys(nasid, phys_cpuid, vector, 0); |
| 181 | |
| 182 | /* |
| 183 | * We must always use the nofault function regardless of whether we |
| 184 | * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we |
| 185 | * didn't, we'd never know that the other partition is down and would |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 186 | * keep sending IRQs and amos to it until the heartbeat times out. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 187 | */ |
| 188 | ret = xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->variable), |
| 189 | xp_nofault_PIOR_target)); |
| 190 | |
| 191 | local_irq_restore(irq_flags); |
| 192 | |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 193 | return (ret == 0) ? xpSuccess : xpPioReadError; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 196 | static struct amo * |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 197 | xpc_init_IRQ_amo_sn2(int index) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 198 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 199 | struct amo *amo = xpc_vars_sn2->amos_page + index; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 200 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 201 | (void)xpc_receive_IRQ_amo_sn2(amo); /* clear amo variable */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 202 | return amo; |
| 203 | } |
| 204 | |
| 205 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 206 | * Functions associated with SGI_XPC_ACTIVATE IRQ. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 207 | */ |
| 208 | |
| 209 | /* |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 210 | * Notify the heartbeat check thread that an activate IRQ has been received. |
| 211 | */ |
| 212 | static irqreturn_t |
| 213 | xpc_handle_activate_IRQ_sn2(int irq, void *dev_id) |
| 214 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 215 | unsigned long irq_flags; |
| 216 | |
| 217 | spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 218 | xpc_activate_IRQ_rcvd++; |
| 219 | spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 220 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 221 | wake_up_interruptible(&xpc_activate_IRQ_wq); |
| 222 | return IRQ_HANDLED; |
| 223 | } |
| 224 | |
| 225 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 226 | * Flag the appropriate amo variable and send an IRQ to the specified node. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 227 | */ |
| 228 | static void |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 229 | xpc_send_activate_IRQ_sn2(unsigned long amos_page_pa, int from_nasid, |
| 230 | int to_nasid, int to_phys_cpuid) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 231 | { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 232 | struct amo *amos = (struct amo *)__va(amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 233 | (XPC_ACTIVATE_IRQ_AMOS_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 234 | sizeof(struct amo))); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 235 | |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 236 | (void)xpc_send_IRQ_sn2(&amos[BIT_WORD(from_nasid / 2)], |
| 237 | BIT_MASK(from_nasid / 2), to_nasid, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 238 | to_phys_cpuid, SGI_XPC_ACTIVATE); |
| 239 | } |
| 240 | |
| 241 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 242 | xpc_send_local_activate_IRQ_sn2(int from_nasid) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 243 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 244 | unsigned long irq_flags; |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 245 | struct amo *amos = (struct amo *)__va(xpc_vars_sn2->amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 246 | (XPC_ACTIVATE_IRQ_AMOS_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 247 | sizeof(struct amo))); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 248 | |
| 249 | /* fake the sending and receipt of an activate IRQ from remote nasid */ |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 250 | FETCHOP_STORE_OP(TO_AMO((u64)&amos[BIT_WORD(from_nasid / 2)].variable), |
| 251 | FETCHOP_OR, BIT_MASK(from_nasid / 2)); |
| 252 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 253 | spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 254 | xpc_activate_IRQ_rcvd++; |
| 255 | spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 256 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 257 | wake_up_interruptible(&xpc_activate_IRQ_wq); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 260 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 261 | * Functions associated with SGI_XPC_NOTIFY IRQ. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 262 | */ |
| 263 | |
| 264 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 265 | * Check to see if any chctl flags were sent from the specified partition. |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 266 | */ |
| 267 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 268 | xpc_check_for_sent_chctl_flags_sn2(struct xpc_partition *part) |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 269 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 270 | union xpc_channel_ctl_flags chctl; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 271 | unsigned long irq_flags; |
| 272 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 273 | chctl.all_flags = xpc_receive_IRQ_amo_sn2(part->sn.sn2. |
| 274 | local_chctl_amo_va); |
| 275 | if (chctl.all_flags == 0) |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 276 | return; |
| 277 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 278 | spin_lock_irqsave(&part->chctl_lock, irq_flags); |
| 279 | part->chctl.all_flags |= chctl.all_flags; |
| 280 | spin_unlock_irqrestore(&part->chctl_lock, irq_flags); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 281 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 282 | dev_dbg(xpc_chan, "received notify IRQ from partid=%d, chctl.all_flags=" |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 283 | "0x%llx\n", XPC_PARTID(part), chctl.all_flags); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 284 | |
| 285 | xpc_wakeup_channel_mgr(part); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified |
| 290 | * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 291 | * than one partition, we use an amo structure per partition to indicate |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 292 | * whether a partition has sent an IRQ or not. If it has, then wake up the |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 293 | * associated kthread to handle it. |
| 294 | * |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 295 | * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IRQs sent by XPC |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 296 | * running on other partitions. |
| 297 | * |
| 298 | * Noteworthy Arguments: |
| 299 | * |
| 300 | * irq - Interrupt ReQuest number. NOT USED. |
| 301 | * |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 302 | * dev_id - partid of IRQ's potential sender. |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 303 | */ |
| 304 | static irqreturn_t |
| 305 | xpc_handle_notify_IRQ_sn2(int irq, void *dev_id) |
| 306 | { |
| 307 | short partid = (short)(u64)dev_id; |
| 308 | struct xpc_partition *part = &xpc_partitions[partid]; |
| 309 | |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 310 | DBUG_ON(partid < 0 || partid >= XP_MAX_NPARTITIONS_SN2); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 311 | |
| 312 | if (xpc_part_ref(part)) { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 313 | xpc_check_for_sent_chctl_flags_sn2(part); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 314 | |
| 315 | xpc_part_deref(part); |
| 316 | } |
| 317 | return IRQ_HANDLED; |
| 318 | } |
| 319 | |
| 320 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 321 | * Check to see if xpc_handle_notify_IRQ_sn2() dropped any IRQs on the floor |
| 322 | * because the write to their associated amo variable completed after the IRQ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 323 | * was received. |
| 324 | */ |
| 325 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 326 | xpc_check_for_dropped_notify_IRQ_sn2(struct xpc_partition *part) |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 327 | { |
| 328 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
| 329 | |
| 330 | if (xpc_part_ref(part)) { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 331 | xpc_check_for_sent_chctl_flags_sn2(part); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 332 | |
| 333 | part_sn2->dropped_notify_IRQ_timer.expires = jiffies + |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 334 | XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 335 | add_timer(&part_sn2->dropped_notify_IRQ_timer); |
| 336 | xpc_part_deref(part); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 341 | * Send a notify IRQ to the remote partition that is associated with the |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 342 | * specified channel. |
| 343 | */ |
| 344 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 345 | xpc_send_notify_IRQ_sn2(struct xpc_channel *ch, u8 chctl_flag, |
| 346 | char *chctl_flag_string, unsigned long *irq_flags) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 347 | { |
| 348 | struct xpc_partition *part = &xpc_partitions[ch->partid]; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 349 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 350 | union xpc_channel_ctl_flags chctl = { 0 }; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 351 | enum xp_retval ret; |
| 352 | |
Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 353 | if (likely(part->act_state != XPC_P_AS_DEACTIVATING)) { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 354 | chctl.flags[ch->number] = chctl_flag; |
| 355 | ret = xpc_send_IRQ_sn2(part_sn2->remote_chctl_amo_va, |
| 356 | chctl.all_flags, |
| 357 | part_sn2->notify_IRQ_nasid, |
| 358 | part_sn2->notify_IRQ_phys_cpuid, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 359 | SGI_XPC_NOTIFY); |
| 360 | dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n", |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 361 | chctl_flag_string, ch->partid, ch->number, ret); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 362 | if (unlikely(ret != xpSuccess)) { |
| 363 | if (irq_flags != NULL) |
| 364 | spin_unlock_irqrestore(&ch->lock, *irq_flags); |
| 365 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 366 | if (irq_flags != NULL) |
| 367 | spin_lock_irqsave(&ch->lock, *irq_flags); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 372 | #define XPC_SEND_NOTIFY_IRQ_SN2(_ch, _ipi_f, _irq_f) \ |
| 373 | xpc_send_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f, _irq_f) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 374 | |
| 375 | /* |
| 376 | * Make it look like the remote partition, which is associated with the |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 377 | * specified channel, sent us a notify IRQ. This faked IRQ will be handled |
| 378 | * by xpc_check_for_dropped_notify_IRQ_sn2(). |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 379 | */ |
| 380 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 381 | xpc_send_local_notify_IRQ_sn2(struct xpc_channel *ch, u8 chctl_flag, |
| 382 | char *chctl_flag_string) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 383 | { |
| 384 | struct xpc_partition *part = &xpc_partitions[ch->partid]; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 385 | union xpc_channel_ctl_flags chctl = { 0 }; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 386 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 387 | chctl.flags[ch->number] = chctl_flag; |
| 388 | FETCHOP_STORE_OP(TO_AMO((u64)&part->sn.sn2.local_chctl_amo_va-> |
| 389 | variable), FETCHOP_OR, chctl.all_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 390 | dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n", |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 391 | chctl_flag_string, ch->partid, ch->number); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 394 | #define XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(_ch, _ipi_f) \ |
| 395 | xpc_send_local_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 396 | |
| 397 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 398 | xpc_send_chctl_closerequest_sn2(struct xpc_channel *ch, |
| 399 | unsigned long *irq_flags) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 400 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 401 | struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 402 | |
| 403 | args->reason = ch->reason; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 404 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_CLOSEREQUEST, irq_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 408 | xpc_send_chctl_closereply_sn2(struct xpc_channel *ch, unsigned long *irq_flags) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 409 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 410 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_CLOSEREPLY, irq_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 414 | xpc_send_chctl_openrequest_sn2(struct xpc_channel *ch, unsigned long *irq_flags) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 415 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 416 | struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 417 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 418 | args->entry_size = ch->entry_size; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 419 | args->local_nentries = ch->local_nentries; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 420 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENREQUEST, irq_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 424 | xpc_send_chctl_openreply_sn2(struct xpc_channel *ch, unsigned long *irq_flags) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 425 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 426 | struct xpc_openclose_args *args = ch->sn.sn2.local_openclose_args; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 427 | |
| 428 | args->remote_nentries = ch->remote_nentries; |
| 429 | args->local_nentries = ch->local_nentries; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 430 | args->local_msgqueue_pa = xp_pa(ch->sn.sn2.local_msgqueue); |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 431 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENREPLY, irq_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void |
Robin Holt | efdd06e | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 435 | xpc_send_chctl_opencomplete_sn2(struct xpc_channel *ch, |
| 436 | unsigned long *irq_flags) |
| 437 | { |
| 438 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_OPENCOMPLETE, irq_flags); |
| 439 | } |
| 440 | |
| 441 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 442 | xpc_send_chctl_msgrequest_sn2(struct xpc_channel *ch) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 443 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 444 | XPC_SEND_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_MSGREQUEST, NULL); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 448 | xpc_send_chctl_local_msgrequest_sn2(struct xpc_channel *ch) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 449 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 450 | XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(ch, XPC_CHCTL_MSGREQUEST); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Jack Steiner | 6f2584f | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 453 | static enum xp_retval |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 454 | xpc_save_remote_msgqueue_pa_sn2(struct xpc_channel *ch, |
| 455 | unsigned long msgqueue_pa) |
| 456 | { |
| 457 | ch->sn.sn2.remote_msgqueue_pa = msgqueue_pa; |
Jack Steiner | 6f2584f | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 458 | return xpSuccess; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 461 | /* |
| 462 | * This next set of functions are used to keep track of when a partition is |
| 463 | * potentially engaged in accessing memory belonging to another partition. |
| 464 | */ |
| 465 | |
| 466 | static void |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 467 | xpc_indicate_partition_engaged_sn2(struct xpc_partition *part) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 468 | { |
| 469 | unsigned long irq_flags; |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 470 | struct amo *amo = (struct amo *)__va(part->sn.sn2.remote_amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 471 | (XPC_ENGAGED_PARTITIONS_AMO_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 472 | sizeof(struct amo))); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 473 | |
| 474 | local_irq_save(irq_flags); |
| 475 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 476 | /* set bit corresponding to our partid in remote partition's amo */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 477 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 478 | BIT(sn_partition_id)); |
| 479 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 480 | /* |
| 481 | * We must always use the nofault function regardless of whether we |
| 482 | * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we |
| 483 | * didn't, we'd never know that the other partition is down and would |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 484 | * keep sending IRQs and amos to it until the heartbeat times out. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 485 | */ |
| 486 | (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo-> |
| 487 | variable), |
| 488 | xp_nofault_PIOR_target)); |
| 489 | |
| 490 | local_irq_restore(irq_flags); |
| 491 | } |
| 492 | |
| 493 | static void |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 494 | xpc_indicate_partition_disengaged_sn2(struct xpc_partition *part) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 495 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 496 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 497 | unsigned long irq_flags; |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 498 | struct amo *amo = (struct amo *)__va(part_sn2->remote_amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 499 | (XPC_ENGAGED_PARTITIONS_AMO_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 500 | sizeof(struct amo))); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 501 | |
| 502 | local_irq_save(irq_flags); |
| 503 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 504 | /* clear bit corresponding to our partid in remote partition's amo */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 505 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND, |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 506 | ~BIT(sn_partition_id)); |
| 507 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 508 | /* |
| 509 | * We must always use the nofault function regardless of whether we |
| 510 | * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we |
| 511 | * didn't, we'd never know that the other partition is down and would |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 512 | * keep sending IRQs and amos to it until the heartbeat times out. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 513 | */ |
| 514 | (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo-> |
| 515 | variable), |
| 516 | xp_nofault_PIOR_target)); |
| 517 | |
| 518 | local_irq_restore(irq_flags); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 519 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 520 | /* |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 521 | * Send activate IRQ to get other side to see that we've cleared our |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 522 | * bit in their engaged partitions amo. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 523 | */ |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 524 | xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa, |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 525 | cnodeid_to_nasid(0), |
| 526 | part_sn2->activate_IRQ_nasid, |
| 527 | part_sn2->activate_IRQ_phys_cpuid); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 530 | static void |
| 531 | xpc_assume_partition_disengaged_sn2(short partid) |
| 532 | { |
| 533 | struct amo *amo = xpc_vars_sn2->amos_page + |
| 534 | XPC_ENGAGED_PARTITIONS_AMO_SN2; |
| 535 | |
| 536 | /* clear bit(s) based on partid mask in our partition's amo */ |
| 537 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND, |
| 538 | ~BIT(partid)); |
| 539 | } |
| 540 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 541 | static int |
| 542 | xpc_partition_engaged_sn2(short partid) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 543 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 544 | struct amo *amo = xpc_vars_sn2->amos_page + |
| 545 | XPC_ENGAGED_PARTITIONS_AMO_SN2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 546 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 547 | /* our partition's amo variable ANDed with partid mask */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 548 | return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) & |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 549 | BIT(partid)) != 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 552 | static int |
| 553 | xpc_any_partition_engaged_sn2(void) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 554 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 555 | struct amo *amo = xpc_vars_sn2->amos_page + |
| 556 | XPC_ENGAGED_PARTITIONS_AMO_SN2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 557 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 558 | /* our partition's amo variable */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 559 | return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) != 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 562 | /* original protection values for each node */ |
| 563 | static u64 xpc_prot_vec_sn2[MAX_NUMNODES]; |
| 564 | |
| 565 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 566 | * Change protections to allow amo operations on non-Shub 1.1 systems. |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 567 | */ |
| 568 | static enum xp_retval |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 569 | xpc_allow_amo_ops_sn2(struct amo *amos_page) |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 570 | { |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 571 | enum xp_retval ret = xpSuccess; |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 572 | |
| 573 | /* |
| 574 | * On SHUB 1.1, we cannot call sn_change_memprotect() since the BIST |
| 575 | * collides with memory operations. On those systems we call |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 576 | * xpc_allow_amo_ops_shub_wars_1_1_sn2() instead. |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 577 | */ |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 578 | if (!enable_shub_wars_1_1()) |
| 579 | ret = xp_expand_memprotect(ia64_tpa((u64)amos_page), PAGE_SIZE); |
| 580 | |
| 581 | return ret; |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 585 | * Change protections to allow amo operations on Shub 1.1 systems. |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 586 | */ |
| 587 | static void |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 588 | xpc_allow_amo_ops_shub_wars_1_1_sn2(void) |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 589 | { |
| 590 | int node; |
| 591 | int nasid; |
| 592 | |
| 593 | if (!enable_shub_wars_1_1()) |
| 594 | return; |
| 595 | |
| 596 | for_each_online_node(node) { |
| 597 | nasid = cnodeid_to_nasid(node); |
| 598 | /* save current protection values */ |
| 599 | xpc_prot_vec_sn2[node] = |
| 600 | (u64)HUB_L((u64 *)GLOBAL_MMR_ADDR(nasid, |
| 601 | SH1_MD_DQLP_MMR_DIR_PRIVEC0)); |
| 602 | /* open up everything */ |
| 603 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, |
| 604 | SH1_MD_DQLP_MMR_DIR_PRIVEC0), |
| 605 | -1UL); |
| 606 | HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, |
| 607 | SH1_MD_DQRP_MMR_DIR_PRIVEC0), |
| 608 | -1UL); |
| 609 | } |
| 610 | } |
| 611 | |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 612 | static enum xp_retval |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 613 | xpc_get_partition_rsvd_page_pa_sn2(void *buf, u64 *cookie, unsigned long *rp_pa, |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 614 | size_t *len) |
| 615 | { |
| 616 | s64 status; |
| 617 | enum xp_retval ret; |
| 618 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 619 | status = sn_partition_reserved_page_pa((u64)buf, cookie, |
| 620 | (u64 *)rp_pa, (u64 *)len); |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 621 | if (status == SALRET_OK) |
| 622 | ret = xpSuccess; |
| 623 | else if (status == SALRET_MORE_PASSES) |
| 624 | ret = xpNeedMoreInfo; |
| 625 | else |
| 626 | ret = xpSalError; |
| 627 | |
| 628 | return ret; |
| 629 | } |
| 630 | |
| 631 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 632 | static int |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 633 | xpc_setup_rsvd_page_sn2(struct xpc_rsvd_page *rp) |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 634 | { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 635 | struct amo *amos_page; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 636 | int i; |
| 637 | int ret; |
| 638 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 639 | xpc_vars_sn2 = XPC_RP_VARS(rp); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 640 | |
Robin Holt | a374c57 | 2009-04-13 14:40:18 -0700 | [diff] [blame] | 641 | rp->sn.sn2.vars_pa = xp_pa(xpc_vars_sn2); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 642 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 643 | /* vars_part array follows immediately after vars */ |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 644 | xpc_vars_part_sn2 = (struct xpc_vars_part_sn2 *)((u8 *)XPC_RP_VARS(rp) + |
| 645 | XPC_RP_VARS_SIZE); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 646 | |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 647 | /* |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 648 | * Before clearing xpc_vars_sn2, see if a page of amos had been |
| 649 | * previously allocated. If not we'll need to allocate one and set |
| 650 | * permissions so that cross-partition amos are allowed. |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 651 | * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 652 | * The allocated amo page needs MCA reporting to remain disabled after |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 653 | * XPC has unloaded. To make this work, we keep a copy of the pointer |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 654 | * to this page (i.e., amos_page) in the struct xpc_vars_sn2 structure, |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 655 | * which is pointed to by the reserved page, and re-use that saved copy |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 656 | * on subsequent loads of XPC. This amo page is never freed, and its |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 657 | * memory protections are never restricted. |
| 658 | */ |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 659 | amos_page = xpc_vars_sn2->amos_page; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 660 | if (amos_page == NULL) { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 661 | amos_page = (struct amo *)TO_AMO(uncached_alloc_page(0, 1)); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 662 | if (amos_page == NULL) { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 663 | dev_err(xpc_part, "can't allocate page of amos\n"); |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 664 | return -ENOMEM; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 668 | * Open up amo-R/W to cpu. This is done on Shub 1.1 systems |
| 669 | * when xpc_allow_amo_ops_shub_wars_1_1_sn2() is called. |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 670 | */ |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 671 | ret = xpc_allow_amo_ops_sn2(amos_page); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 672 | if (ret != xpSuccess) { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 673 | dev_err(xpc_part, "can't allow amo operations\n"); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 674 | uncached_free_page(__IA64_UNCACHED_OFFSET | |
| 675 | TO_PHYS((u64)amos_page), 1); |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 676 | return -EPERM; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 680 | /* clear xpc_vars_sn2 */ |
| 681 | memset(xpc_vars_sn2, 0, sizeof(struct xpc_vars_sn2)); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 682 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 683 | xpc_vars_sn2->version = XPC_V_VERSION; |
| 684 | xpc_vars_sn2->activate_IRQ_nasid = cpuid_to_nasid(0); |
| 685 | xpc_vars_sn2->activate_IRQ_phys_cpuid = cpu_physical_id(0); |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 686 | xpc_vars_sn2->vars_part_pa = xp_pa(xpc_vars_part_sn2); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 687 | xpc_vars_sn2->amos_page_pa = ia64_tpa((u64)amos_page); |
| 688 | xpc_vars_sn2->amos_page = amos_page; /* save for next load of XPC */ |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 689 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 690 | /* clear xpc_vars_part_sn2 */ |
| 691 | memset((u64 *)xpc_vars_part_sn2, 0, sizeof(struct xpc_vars_part_sn2) * |
Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 692 | XP_MAX_NPARTITIONS_SN2); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 693 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 694 | /* initialize the activate IRQ related amo variables */ |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 695 | for (i = 0; i < xpc_nasid_mask_nlongs; i++) |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 696 | (void)xpc_init_IRQ_amo_sn2(XPC_ACTIVATE_IRQ_AMOS_SN2 + i); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 697 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 698 | /* initialize the engaged remote partitions related amo variables */ |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 699 | (void)xpc_init_IRQ_amo_sn2(XPC_ENGAGED_PARTITIONS_AMO_SN2); |
| 700 | (void)xpc_init_IRQ_amo_sn2(XPC_DEACTIVATE_REQUEST_AMO_SN2); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 701 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 702 | return 0; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Robin Holt | a374c57 | 2009-04-13 14:40:18 -0700 | [diff] [blame] | 705 | static int |
| 706 | xpc_hb_allowed_sn2(short partid, void *heartbeating_to_mask) |
| 707 | { |
| 708 | return test_bit(partid, heartbeating_to_mask); |
| 709 | } |
| 710 | |
| 711 | static void |
| 712 | xpc_allow_hb_sn2(short partid) |
| 713 | { |
| 714 | DBUG_ON(xpc_vars_sn2 == NULL); |
| 715 | set_bit(partid, xpc_vars_sn2->heartbeating_to_mask); |
| 716 | } |
| 717 | |
| 718 | static void |
| 719 | xpc_disallow_hb_sn2(short partid) |
| 720 | { |
| 721 | DBUG_ON(xpc_vars_sn2 == NULL); |
| 722 | clear_bit(partid, xpc_vars_sn2->heartbeating_to_mask); |
| 723 | } |
| 724 | |
| 725 | static void |
| 726 | xpc_disallow_all_hbs_sn2(void) |
| 727 | { |
| 728 | DBUG_ON(xpc_vars_sn2 == NULL); |
| 729 | bitmap_zero(xpc_vars_sn2->heartbeating_to_mask, xp_max_npartitions); |
| 730 | } |
| 731 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 732 | static void |
| 733 | xpc_increment_heartbeat_sn2(void) |
| 734 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 735 | xpc_vars_sn2->heartbeat++; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static void |
| 739 | xpc_offline_heartbeat_sn2(void) |
| 740 | { |
| 741 | xpc_increment_heartbeat_sn2(); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 742 | xpc_vars_sn2->heartbeat_offline = 1; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | static void |
| 746 | xpc_online_heartbeat_sn2(void) |
| 747 | { |
| 748 | xpc_increment_heartbeat_sn2(); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 749 | xpc_vars_sn2->heartbeat_offline = 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | static void |
| 753 | xpc_heartbeat_init_sn2(void) |
| 754 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 755 | DBUG_ON(xpc_vars_sn2 == NULL); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 756 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 757 | bitmap_zero(xpc_vars_sn2->heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 758 | xpc_online_heartbeat_sn2(); |
| 759 | } |
| 760 | |
| 761 | static void |
| 762 | xpc_heartbeat_exit_sn2(void) |
| 763 | { |
| 764 | xpc_offline_heartbeat_sn2(); |
| 765 | } |
| 766 | |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 767 | static enum xp_retval |
| 768 | xpc_get_remote_heartbeat_sn2(struct xpc_partition *part) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 769 | { |
| 770 | struct xpc_vars_sn2 *remote_vars; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 771 | enum xp_retval ret; |
| 772 | |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 773 | remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer_sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 774 | |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 775 | /* pull the remote vars structure that contains the heartbeat */ |
| 776 | ret = xp_remote_memcpy(xp_pa(remote_vars), |
| 777 | part->sn.sn2.remote_vars_pa, |
| 778 | XPC_RP_VARS_SIZE); |
| 779 | if (ret != xpSuccess) |
| 780 | return ret; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 781 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 782 | dev_dbg(xpc_part, "partid=%d, heartbeat=%lld, last_heartbeat=%lld, " |
| 783 | "heartbeat_offline=%lld, HB_mask[0]=0x%lx\n", XPC_PARTID(part), |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 784 | remote_vars->heartbeat, part->last_heartbeat, |
| 785 | remote_vars->heartbeat_offline, |
| 786 | remote_vars->heartbeating_to_mask[0]); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 787 | |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 788 | if ((remote_vars->heartbeat == part->last_heartbeat && |
Robin Holt | a374c57 | 2009-04-13 14:40:18 -0700 | [diff] [blame] | 789 | !remote_vars->heartbeat_offline) || |
| 790 | !xpc_hb_allowed_sn2(sn_partition_id, |
| 791 | remote_vars->heartbeating_to_mask)) { |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 792 | ret = xpNoHeartbeat; |
| 793 | } else { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 794 | part->last_heartbeat = remote_vars->heartbeat; |
| 795 | } |
Dean Nelson | 61deb86 | 2008-07-29 22:34:17 -0700 | [diff] [blame] | 796 | |
| 797 | return ret; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Get a copy of the remote partition's XPC variables from the reserved page. |
| 802 | * |
| 803 | * remote_vars points to a buffer that is cacheline aligned for BTE copies and |
| 804 | * assumed to be of size XPC_RP_VARS_SIZE. |
| 805 | */ |
| 806 | static enum xp_retval |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 807 | xpc_get_remote_vars_sn2(unsigned long remote_vars_pa, |
| 808 | struct xpc_vars_sn2 *remote_vars) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 809 | { |
| 810 | enum xp_retval ret; |
| 811 | |
| 812 | if (remote_vars_pa == 0) |
| 813 | return xpVarsNotSet; |
| 814 | |
| 815 | /* pull over the cross partition variables */ |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 816 | ret = xp_remote_memcpy(xp_pa(remote_vars), remote_vars_pa, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 817 | XPC_RP_VARS_SIZE); |
| 818 | if (ret != xpSuccess) |
| 819 | return ret; |
| 820 | |
| 821 | if (XPC_VERSION_MAJOR(remote_vars->version) != |
| 822 | XPC_VERSION_MAJOR(XPC_V_VERSION)) { |
| 823 | return xpBadVersion; |
| 824 | } |
| 825 | |
| 826 | return xpSuccess; |
| 827 | } |
| 828 | |
| 829 | static void |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 830 | xpc_request_partition_activation_sn2(struct xpc_rsvd_page *remote_rp, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 831 | unsigned long remote_rp_pa, int nasid) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 832 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 833 | xpc_send_local_activate_IRQ_sn2(nasid); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static void |
| 837 | xpc_request_partition_reactivation_sn2(struct xpc_partition *part) |
| 838 | { |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 839 | xpc_send_local_activate_IRQ_sn2(part->sn.sn2.activate_IRQ_nasid); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static void |
| 843 | xpc_request_partition_deactivation_sn2(struct xpc_partition *part) |
| 844 | { |
| 845 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
| 846 | unsigned long irq_flags; |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 847 | struct amo *amo = (struct amo *)__va(part_sn2->remote_amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 848 | (XPC_DEACTIVATE_REQUEST_AMO_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 849 | sizeof(struct amo))); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 850 | |
| 851 | local_irq_save(irq_flags); |
| 852 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 853 | /* set bit corresponding to our partid in remote partition's amo */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 854 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 855 | BIT(sn_partition_id)); |
| 856 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 857 | /* |
| 858 | * We must always use the nofault function regardless of whether we |
| 859 | * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we |
| 860 | * didn't, we'd never know that the other partition is down and would |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 861 | * keep sending IRQs and amos to it until the heartbeat times out. |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 862 | */ |
| 863 | (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo-> |
| 864 | variable), |
| 865 | xp_nofault_PIOR_target)); |
| 866 | |
| 867 | local_irq_restore(irq_flags); |
| 868 | |
| 869 | /* |
| 870 | * Send activate IRQ to get other side to see that we've set our |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 871 | * bit in their deactivate request amo. |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 872 | */ |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 873 | xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa, |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 874 | cnodeid_to_nasid(0), |
| 875 | part_sn2->activate_IRQ_nasid, |
| 876 | part_sn2->activate_IRQ_phys_cpuid); |
| 877 | } |
| 878 | |
| 879 | static void |
| 880 | xpc_cancel_partition_deactivation_request_sn2(struct xpc_partition *part) |
| 881 | { |
| 882 | unsigned long irq_flags; |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 883 | struct amo *amo = (struct amo *)__va(part->sn.sn2.remote_amos_page_pa + |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 884 | (XPC_DEACTIVATE_REQUEST_AMO_SN2 * |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 885 | sizeof(struct amo))); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 886 | |
| 887 | local_irq_save(irq_flags); |
| 888 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 889 | /* clear bit corresponding to our partid in remote partition's amo */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 890 | FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND, |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 891 | ~BIT(sn_partition_id)); |
| 892 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 893 | /* |
| 894 | * We must always use the nofault function regardless of whether we |
| 895 | * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we |
| 896 | * didn't, we'd never know that the other partition is down and would |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 897 | * keep sending IRQs and amos to it until the heartbeat times out. |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 898 | */ |
| 899 | (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo-> |
| 900 | variable), |
| 901 | xp_nofault_PIOR_target)); |
| 902 | |
| 903 | local_irq_restore(irq_flags); |
| 904 | } |
| 905 | |
| 906 | static int |
| 907 | xpc_partition_deactivation_requested_sn2(short partid) |
| 908 | { |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 909 | struct amo *amo = xpc_vars_sn2->amos_page + |
| 910 | XPC_DEACTIVATE_REQUEST_AMO_SN2; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 911 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 912 | /* our partition's amo variable ANDed with partid mask */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 913 | return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) & |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 914 | BIT(partid)) != 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /* |
| 918 | * Update the remote partition's info. |
| 919 | */ |
| 920 | static void |
| 921 | xpc_update_partition_info_sn2(struct xpc_partition *part, u8 remote_rp_version, |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 922 | unsigned long *remote_rp_ts_jiffies, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 923 | unsigned long remote_rp_pa, |
| 924 | unsigned long remote_vars_pa, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 925 | struct xpc_vars_sn2 *remote_vars) |
| 926 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 927 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
| 928 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 929 | part->remote_rp_version = remote_rp_version; |
| 930 | dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n", |
| 931 | part->remote_rp_version); |
| 932 | |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 933 | part->remote_rp_ts_jiffies = *remote_rp_ts_jiffies; |
| 934 | dev_dbg(xpc_part, " remote_rp_ts_jiffies = 0x%016lx\n", |
| 935 | part->remote_rp_ts_jiffies); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 936 | |
| 937 | part->remote_rp_pa = remote_rp_pa; |
| 938 | dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa); |
| 939 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 940 | part_sn2->remote_vars_pa = remote_vars_pa; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 941 | dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n", |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 942 | part_sn2->remote_vars_pa); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 943 | |
Dean Nelson | 158bc69 | 2009-01-15 13:50:57 -0800 | [diff] [blame] | 944 | part->last_heartbeat = remote_vars->heartbeat - 1; |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 945 | dev_dbg(xpc_part, " last_heartbeat = 0x%016llx\n", |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 946 | part->last_heartbeat); |
| 947 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 948 | part_sn2->remote_vars_part_pa = remote_vars->vars_part_pa; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 949 | dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n", |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 950 | part_sn2->remote_vars_part_pa); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 951 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 952 | part_sn2->activate_IRQ_nasid = remote_vars->activate_IRQ_nasid; |
| 953 | dev_dbg(xpc_part, " activate_IRQ_nasid = 0x%x\n", |
| 954 | part_sn2->activate_IRQ_nasid); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 955 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 956 | part_sn2->activate_IRQ_phys_cpuid = |
| 957 | remote_vars->activate_IRQ_phys_cpuid; |
| 958 | dev_dbg(xpc_part, " activate_IRQ_phys_cpuid = 0x%x\n", |
| 959 | part_sn2->activate_IRQ_phys_cpuid); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 960 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 961 | part_sn2->remote_amos_page_pa = remote_vars->amos_page_pa; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 962 | dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n", |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 963 | part_sn2->remote_amos_page_pa); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 964 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 965 | part_sn2->remote_vars_version = remote_vars->version; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 966 | dev_dbg(xpc_part, " remote_vars_version = 0x%x\n", |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 967 | part_sn2->remote_vars_version); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 971 | * Prior code has determined the nasid which generated a activate IRQ. |
| 972 | * Inspect that nasid to determine if its partition needs to be activated |
| 973 | * or deactivated. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 974 | * |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 975 | * A partition is considered "awaiting activation" if our partition |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 976 | * flags indicate it is not active and it has a heartbeat. A |
| 977 | * partition is considered "awaiting deactivation" if our partition |
| 978 | * flags indicate it is active but it has no heartbeat or it is not |
| 979 | * sending its heartbeat to us. |
| 980 | * |
| 981 | * To determine the heartbeat, the remote nasid must have a properly |
| 982 | * initialized reserved page. |
| 983 | */ |
| 984 | static void |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 985 | xpc_identify_activate_IRQ_req_sn2(int nasid) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 986 | { |
| 987 | struct xpc_rsvd_page *remote_rp; |
| 988 | struct xpc_vars_sn2 *remote_vars; |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 989 | unsigned long remote_rp_pa; |
| 990 | unsigned long remote_vars_pa; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 991 | int remote_rp_version; |
| 992 | int reactivate = 0; |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 993 | unsigned long remote_rp_ts_jiffies = 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 994 | short partid; |
| 995 | struct xpc_partition *part; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 996 | struct xpc_partition_sn2 *part_sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 997 | enum xp_retval ret; |
| 998 | |
| 999 | /* pull over the reserved page structure */ |
| 1000 | |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1001 | remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer_sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1002 | |
| 1003 | ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa); |
| 1004 | if (ret != xpSuccess) { |
| 1005 | dev_warn(xpc_part, "unable to get reserved page from nasid %d, " |
| 1006 | "which sent interrupt, reason=%d\n", nasid, ret); |
| 1007 | return; |
| 1008 | } |
| 1009 | |
Robin Holt | a374c57 | 2009-04-13 14:40:18 -0700 | [diff] [blame] | 1010 | remote_vars_pa = remote_rp->sn.sn2.vars_pa; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1011 | remote_rp_version = remote_rp->version; |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 1012 | remote_rp_ts_jiffies = remote_rp->ts_jiffies; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1013 | |
| 1014 | partid = remote_rp->SAL_partid; |
| 1015 | part = &xpc_partitions[partid]; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1016 | part_sn2 = &part->sn.sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1017 | |
| 1018 | /* pull over the cross partition variables */ |
| 1019 | |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1020 | remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer_sn2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1021 | |
| 1022 | ret = xpc_get_remote_vars_sn2(remote_vars_pa, remote_vars); |
| 1023 | if (ret != xpSuccess) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1024 | dev_warn(xpc_part, "unable to get XPC variables from nasid %d, " |
| 1025 | "which sent interrupt, reason=%d\n", nasid, ret); |
| 1026 | |
| 1027 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1028 | return; |
| 1029 | } |
| 1030 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1031 | part->activate_IRQ_rcvd++; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1032 | |
| 1033 | dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = " |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1034 | "%lld:0x%lx\n", (int)nasid, (int)partid, |
| 1035 | part->activate_IRQ_rcvd, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1036 | remote_vars->heartbeat, remote_vars->heartbeating_to_mask[0]); |
| 1037 | |
| 1038 | if (xpc_partition_disengaged(part) && |
Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1039 | part->act_state == XPC_P_AS_INACTIVE) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1040 | |
| 1041 | xpc_update_partition_info_sn2(part, remote_rp_version, |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 1042 | &remote_rp_ts_jiffies, |
| 1043 | remote_rp_pa, remote_vars_pa, |
| 1044 | remote_vars); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1045 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1046 | if (xpc_partition_deactivation_requested_sn2(partid)) { |
| 1047 | /* |
| 1048 | * Other side is waiting on us to deactivate even though |
| 1049 | * we already have. |
| 1050 | */ |
| 1051 | return; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | xpc_activate_partition(part); |
| 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | DBUG_ON(part->remote_rp_version == 0); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1059 | DBUG_ON(part_sn2->remote_vars_version == 0); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1060 | |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 1061 | if (remote_rp_ts_jiffies != part->remote_rp_ts_jiffies) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1062 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1063 | /* the other side rebooted */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1064 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1065 | DBUG_ON(xpc_partition_engaged_sn2(partid)); |
| 1066 | DBUG_ON(xpc_partition_deactivation_requested_sn2(partid)); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1067 | |
| 1068 | xpc_update_partition_info_sn2(part, remote_rp_version, |
Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 1069 | &remote_rp_ts_jiffies, |
| 1070 | remote_rp_pa, remote_vars_pa, |
| 1071 | remote_vars); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1072 | reactivate = 1; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1075 | if (part->disengage_timeout > 0 && !xpc_partition_disengaged(part)) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1076 | /* still waiting on other side to disengage from us */ |
| 1077 | return; |
| 1078 | } |
| 1079 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1080 | if (reactivate) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1081 | XPC_DEACTIVATE_PARTITION(part, xpReactivating); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1082 | else if (xpc_partition_deactivation_requested_sn2(partid)) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1083 | XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1087 | * Loop through the activation amo variables and process any bits |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1088 | * which are set. Each bit indicates a nasid sending a partition |
| 1089 | * activation or deactivation request. |
| 1090 | * |
| 1091 | * Return #of IRQs detected. |
| 1092 | */ |
| 1093 | int |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1094 | xpc_identify_activate_IRQ_sender_sn2(void) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1095 | { |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1096 | int l; |
| 1097 | int b; |
| 1098 | unsigned long nasid_mask_long; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1099 | u64 nasid; /* remote nasid */ |
| 1100 | int n_IRQs_detected = 0; |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1101 | struct amo *act_amos; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1102 | |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1103 | act_amos = xpc_vars_sn2->amos_page + XPC_ACTIVATE_IRQ_AMOS_SN2; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1104 | |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1105 | /* scan through activate amo variables looking for non-zero entries */ |
| 1106 | for (l = 0; l < xpc_nasid_mask_nlongs; l++) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1107 | |
| 1108 | if (xpc_exiting) |
| 1109 | break; |
| 1110 | |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1111 | nasid_mask_long = xpc_receive_IRQ_amo_sn2(&act_amos[l]); |
| 1112 | |
| 1113 | b = find_first_bit(&nasid_mask_long, BITS_PER_LONG); |
| 1114 | if (b >= BITS_PER_LONG) { |
| 1115 | /* no IRQs from nasids in this amo variable */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1116 | continue; |
| 1117 | } |
| 1118 | |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1119 | dev_dbg(xpc_part, "amo[%d] gave back 0x%lx\n", l, |
| 1120 | nasid_mask_long); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1121 | |
| 1122 | /* |
| 1123 | * If this nasid has been added to the machine since |
| 1124 | * our partition was reset, this will retain the |
| 1125 | * remote nasid in our reserved pages machine mask. |
| 1126 | * This is used in the event of module reload. |
| 1127 | */ |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1128 | xpc_mach_nasids[l] |= nasid_mask_long; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1129 | |
| 1130 | /* locate the nasid(s) which sent interrupts */ |
| 1131 | |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1132 | do { |
| 1133 | n_IRQs_detected++; |
| 1134 | nasid = (l * BITS_PER_LONG + b) * 2; |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1135 | dev_dbg(xpc_part, "interrupt from nasid %lld\n", nasid); |
Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1136 | xpc_identify_activate_IRQ_req_sn2(nasid); |
| 1137 | |
| 1138 | b = find_next_bit(&nasid_mask_long, BITS_PER_LONG, |
| 1139 | b + 1); |
| 1140 | } while (b < BITS_PER_LONG); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1141 | } |
| 1142 | return n_IRQs_detected; |
| 1143 | } |
| 1144 | |
| 1145 | static void |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1146 | xpc_process_activate_IRQ_rcvd_sn2(void) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1147 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1148 | unsigned long irq_flags; |
| 1149 | int n_IRQs_expected; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1150 | int n_IRQs_detected; |
| 1151 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1152 | spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 1153 | n_IRQs_expected = xpc_activate_IRQ_rcvd; |
| 1154 | xpc_activate_IRQ_rcvd = 0; |
| 1155 | spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags); |
| 1156 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1157 | n_IRQs_detected = xpc_identify_activate_IRQ_sender_sn2(); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1158 | if (n_IRQs_detected < n_IRQs_expected) { |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1159 | /* retry once to help avoid missing amo */ |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1160 | (void)xpc_identify_activate_IRQ_sender_sn2(); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1164 | /* |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1165 | * Setup the channel structures that are sn2 specific. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1166 | */ |
| 1167 | static enum xp_retval |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 1168 | xpc_setup_ch_structures_sn2(struct xpc_partition *part) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1169 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1170 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1171 | struct xpc_channel_sn2 *ch_sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1172 | enum xp_retval retval; |
| 1173 | int ret; |
| 1174 | int cpuid; |
| 1175 | int ch_number; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1176 | struct timer_list *timer; |
| 1177 | short partid = XPC_PARTID(part); |
| 1178 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1179 | /* allocate all the required GET/PUT values */ |
| 1180 | |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1181 | part_sn2->local_GPs = |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1182 | xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, GFP_KERNEL, |
| 1183 | &part_sn2->local_GPs_base); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1184 | if (part_sn2->local_GPs == NULL) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1185 | dev_err(xpc_chan, "can't get memory for local get/put " |
| 1186 | "values\n"); |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1187 | return xpNoMemory; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1190 | part_sn2->remote_GPs = |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1191 | xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, GFP_KERNEL, |
| 1192 | &part_sn2->remote_GPs_base); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1193 | if (part_sn2->remote_GPs == NULL) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1194 | dev_err(xpc_chan, "can't get memory for remote get/put " |
| 1195 | "values\n"); |
| 1196 | retval = xpNoMemory; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1197 | goto out_1; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1200 | part_sn2->remote_GPs_pa = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1201 | |
| 1202 | /* allocate all the required open and close args */ |
| 1203 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1204 | part_sn2->local_openclose_args = |
| 1205 | xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE, |
| 1206 | GFP_KERNEL, &part_sn2-> |
| 1207 | local_openclose_args_base); |
| 1208 | if (part_sn2->local_openclose_args == NULL) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1209 | dev_err(xpc_chan, "can't get memory for local connect args\n"); |
| 1210 | retval = xpNoMemory; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1211 | goto out_2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1214 | part_sn2->remote_openclose_args_pa = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1215 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1216 | part_sn2->local_chctl_amo_va = xpc_init_IRQ_amo_sn2(partid); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1217 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1218 | part_sn2->notify_IRQ_nasid = 0; |
| 1219 | part_sn2->notify_IRQ_phys_cpuid = 0; |
| 1220 | part_sn2->remote_chctl_amo_va = NULL; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1221 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1222 | sprintf(part_sn2->notify_IRQ_owner, "xpc%02d", partid); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1223 | ret = request_irq(SGI_XPC_NOTIFY, xpc_handle_notify_IRQ_sn2, |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1224 | IRQF_SHARED, part_sn2->notify_IRQ_owner, |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1225 | (void *)(u64)partid); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1226 | if (ret != 0) { |
| 1227 | dev_err(xpc_chan, "can't register NOTIFY IRQ handler, " |
| 1228 | "errno=%d\n", -ret); |
| 1229 | retval = xpLackOfResources; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1230 | goto out_3; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1233 | /* Setup a timer to check for dropped notify IRQs */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1234 | timer = &part_sn2->dropped_notify_IRQ_timer; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1235 | init_timer(timer); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1236 | timer->function = |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1237 | (void (*)(unsigned long))xpc_check_for_dropped_notify_IRQ_sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1238 | timer->data = (unsigned long)part; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1239 | timer->expires = jiffies + XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1240 | add_timer(timer); |
| 1241 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1242 | for (ch_number = 0; ch_number < part->nchannels; ch_number++) { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1243 | ch_sn2 = &part->channels[ch_number].sn.sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1244 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1245 | ch_sn2->local_GP = &part_sn2->local_GPs[ch_number]; |
| 1246 | ch_sn2->local_openclose_args = |
| 1247 | &part_sn2->local_openclose_args[ch_number]; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1248 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1249 | mutex_init(&ch_sn2->msg_to_pull_mutex); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | /* |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1253 | * Setup the per partition specific variables required by the |
| 1254 | * remote partition to establish channel connections with us. |
| 1255 | * |
| 1256 | * The setting of the magic # indicates that these per partition |
| 1257 | * specific variables are ready to be used. |
| 1258 | */ |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1259 | xpc_vars_part_sn2[partid].GPs_pa = xp_pa(part_sn2->local_GPs); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1260 | xpc_vars_part_sn2[partid].openclose_args_pa = |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1261 | xp_pa(part_sn2->local_openclose_args); |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1262 | xpc_vars_part_sn2[partid].chctl_amo_pa = |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1263 | xp_pa(part_sn2->local_chctl_amo_va); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1264 | cpuid = raw_smp_processor_id(); /* any CPU in this partition will do */ |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1265 | xpc_vars_part_sn2[partid].notify_IRQ_nasid = cpuid_to_nasid(cpuid); |
| 1266 | xpc_vars_part_sn2[partid].notify_IRQ_phys_cpuid = |
| 1267 | cpu_physical_id(cpuid); |
| 1268 | xpc_vars_part_sn2[partid].nchannels = part->nchannels; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1269 | xpc_vars_part_sn2[partid].magic = XPC_VP_MAGIC1_SN2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1270 | |
| 1271 | return xpSuccess; |
| 1272 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1273 | /* setup of ch structures failed */ |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1274 | out_3: |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1275 | kfree(part_sn2->local_openclose_args_base); |
| 1276 | part_sn2->local_openclose_args = NULL; |
| 1277 | out_2: |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1278 | kfree(part_sn2->remote_GPs_base); |
| 1279 | part_sn2->remote_GPs = NULL; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1280 | out_1: |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1281 | kfree(part_sn2->local_GPs_base); |
| 1282 | part_sn2->local_GPs = NULL; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1283 | return retval; |
| 1284 | } |
| 1285 | |
| 1286 | /* |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1287 | * Teardown the channel structures that are sn2 specific. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1288 | */ |
| 1289 | static void |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 1290 | xpc_teardown_ch_structures_sn2(struct xpc_partition *part) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1291 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1292 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1293 | short partid = XPC_PARTID(part); |
| 1294 | |
| 1295 | /* |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1296 | * Indicate that the variables specific to the remote partition are no |
| 1297 | * longer available for its use. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1298 | */ |
Dean Nelson | 8e85c23 | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 1299 | xpc_vars_part_sn2[partid].magic = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1300 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1301 | /* in case we've still got outstanding timers registered... */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1302 | del_timer_sync(&part_sn2->dropped_notify_IRQ_timer); |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1303 | free_irq(SGI_XPC_NOTIFY, (void *)(u64)partid); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1304 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1305 | kfree(part_sn2->local_openclose_args_base); |
| 1306 | part_sn2->local_openclose_args = NULL; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1307 | kfree(part_sn2->remote_GPs_base); |
| 1308 | part_sn2->remote_GPs = NULL; |
| 1309 | kfree(part_sn2->local_GPs_base); |
| 1310 | part_sn2->local_GPs = NULL; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1311 | part_sn2->local_chctl_amo_va = NULL; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /* |
| 1315 | * Create a wrapper that hides the underlying mechanism for pulling a cacheline |
| 1316 | * (or multiple cachelines) from a remote partition. |
| 1317 | * |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1318 | * src_pa must be a cacheline aligned physical address on the remote partition. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1319 | * dst must be a cacheline aligned virtual address on this partition. |
| 1320 | * cnt must be cacheline sized |
| 1321 | */ |
Dean Nelson | ea57f80 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 1322 | /* ??? Replace this function by call to xp_remote_memcpy() or bte_copy()? */ |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1323 | static enum xp_retval |
| 1324 | xpc_pull_remote_cachelines_sn2(struct xpc_partition *part, void *dst, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1325 | const unsigned long src_pa, size_t cnt) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1326 | { |
| 1327 | enum xp_retval ret; |
| 1328 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1329 | DBUG_ON(src_pa != L1_CACHE_ALIGN(src_pa)); |
| 1330 | DBUG_ON((unsigned long)dst != L1_CACHE_ALIGN((unsigned long)dst)); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1331 | DBUG_ON(cnt != L1_CACHE_ALIGN(cnt)); |
| 1332 | |
Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1333 | if (part->act_state == XPC_P_AS_DEACTIVATING) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1334 | return part->reason; |
| 1335 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1336 | ret = xp_remote_memcpy(xp_pa(dst), src_pa, cnt); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1337 | if (ret != xpSuccess) { |
| 1338 | dev_dbg(xpc_chan, "xp_remote_memcpy() from partition %d failed," |
| 1339 | " ret=%d\n", XPC_PARTID(part), ret); |
| 1340 | } |
| 1341 | return ret; |
| 1342 | } |
| 1343 | |
| 1344 | /* |
| 1345 | * Pull the remote per partition specific variables from the specified |
| 1346 | * partition. |
| 1347 | */ |
| 1348 | static enum xp_retval |
| 1349 | xpc_pull_remote_vars_part_sn2(struct xpc_partition *part) |
| 1350 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1351 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1352 | u8 buffer[L1_CACHE_BYTES * 2]; |
| 1353 | struct xpc_vars_part_sn2 *pulled_entry_cacheline = |
| 1354 | (struct xpc_vars_part_sn2 *)L1_CACHE_ALIGN((u64)buffer); |
| 1355 | struct xpc_vars_part_sn2 *pulled_entry; |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1356 | unsigned long remote_entry_cacheline_pa; |
| 1357 | unsigned long remote_entry_pa; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1358 | short partid = XPC_PARTID(part); |
| 1359 | enum xp_retval ret; |
| 1360 | |
| 1361 | /* pull the cacheline that contains the variables we're interested in */ |
| 1362 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1363 | DBUG_ON(part_sn2->remote_vars_part_pa != |
| 1364 | L1_CACHE_ALIGN(part_sn2->remote_vars_part_pa)); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1365 | DBUG_ON(sizeof(struct xpc_vars_part_sn2) != L1_CACHE_BYTES / 2); |
| 1366 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1367 | remote_entry_pa = part_sn2->remote_vars_part_pa + |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1368 | sn_partition_id * sizeof(struct xpc_vars_part_sn2); |
| 1369 | |
| 1370 | remote_entry_cacheline_pa = (remote_entry_pa & ~(L1_CACHE_BYTES - 1)); |
| 1371 | |
| 1372 | pulled_entry = (struct xpc_vars_part_sn2 *)((u64)pulled_entry_cacheline |
| 1373 | + (remote_entry_pa & |
| 1374 | (L1_CACHE_BYTES - 1))); |
| 1375 | |
| 1376 | ret = xpc_pull_remote_cachelines_sn2(part, pulled_entry_cacheline, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1377 | remote_entry_cacheline_pa, |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1378 | L1_CACHE_BYTES); |
| 1379 | if (ret != xpSuccess) { |
| 1380 | dev_dbg(xpc_chan, "failed to pull XPC vars_part from " |
| 1381 | "partition %d, ret=%d\n", partid, ret); |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
| 1385 | /* see if they've been set up yet */ |
| 1386 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1387 | if (pulled_entry->magic != XPC_VP_MAGIC1_SN2 && |
| 1388 | pulled_entry->magic != XPC_VP_MAGIC2_SN2) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1389 | |
| 1390 | if (pulled_entry->magic != 0) { |
| 1391 | dev_dbg(xpc_chan, "partition %d's XPC vars_part for " |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1392 | "partition %d has bad magic value (=0x%llx)\n", |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1393 | partid, sn_partition_id, pulled_entry->magic); |
| 1394 | return xpBadMagic; |
| 1395 | } |
| 1396 | |
| 1397 | /* they've not been initialized yet */ |
| 1398 | return xpRetry; |
| 1399 | } |
| 1400 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1401 | if (xpc_vars_part_sn2[partid].magic == XPC_VP_MAGIC1_SN2) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1402 | |
| 1403 | /* validate the variables */ |
| 1404 | |
| 1405 | if (pulled_entry->GPs_pa == 0 || |
| 1406 | pulled_entry->openclose_args_pa == 0 || |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1407 | pulled_entry->chctl_amo_pa == 0) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1408 | |
| 1409 | dev_err(xpc_chan, "partition %d's XPC vars_part for " |
| 1410 | "partition %d are not valid\n", partid, |
| 1411 | sn_partition_id); |
| 1412 | return xpInvalidAddress; |
| 1413 | } |
| 1414 | |
| 1415 | /* the variables we imported look to be valid */ |
| 1416 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1417 | part_sn2->remote_GPs_pa = pulled_entry->GPs_pa; |
| 1418 | part_sn2->remote_openclose_args_pa = |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1419 | pulled_entry->openclose_args_pa; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1420 | part_sn2->remote_chctl_amo_va = |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1421 | (struct amo *)__va(pulled_entry->chctl_amo_pa); |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1422 | part_sn2->notify_IRQ_nasid = pulled_entry->notify_IRQ_nasid; |
| 1423 | part_sn2->notify_IRQ_phys_cpuid = |
| 1424 | pulled_entry->notify_IRQ_phys_cpuid; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1425 | |
| 1426 | if (part->nchannels > pulled_entry->nchannels) |
| 1427 | part->nchannels = pulled_entry->nchannels; |
| 1428 | |
| 1429 | /* let the other side know that we've pulled their variables */ |
| 1430 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1431 | xpc_vars_part_sn2[partid].magic = XPC_VP_MAGIC2_SN2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1434 | if (pulled_entry->magic == XPC_VP_MAGIC1_SN2) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1435 | return xpRetry; |
| 1436 | |
| 1437 | return xpSuccess; |
| 1438 | } |
| 1439 | |
| 1440 | /* |
| 1441 | * Establish first contact with the remote partititon. This involves pulling |
| 1442 | * the XPC per partition variables from the remote partition and waiting for |
| 1443 | * the remote partition to pull ours. |
| 1444 | */ |
| 1445 | static enum xp_retval |
| 1446 | xpc_make_first_contact_sn2(struct xpc_partition *part) |
| 1447 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1448 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1449 | enum xp_retval ret; |
| 1450 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1451 | /* |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1452 | * Register the remote partition's amos with SAL so it can handle |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1453 | * and cleanup errors within that address range should the remote |
| 1454 | * partition go down. We don't unregister this range because it is |
| 1455 | * difficult to tell when outstanding writes to the remote partition |
| 1456 | * are finished and thus when it is safe to unregister. This should |
| 1457 | * not result in wasted space in the SAL xp_addr_region table because |
| 1458 | * we should get the same page for remote_amos_page_pa after module |
| 1459 | * reloads and system reboots. |
| 1460 | */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1461 | if (sn_register_xp_addr_region(part_sn2->remote_amos_page_pa, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1462 | PAGE_SIZE, 1) < 0) { |
| 1463 | dev_warn(xpc_part, "xpc_activating(%d) failed to register " |
| 1464 | "xp_addr region\n", XPC_PARTID(part)); |
| 1465 | |
| 1466 | ret = xpPhysAddrRegFailed; |
| 1467 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1468 | return ret; |
| 1469 | } |
| 1470 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1471 | /* |
| 1472 | * Send activate IRQ to get other side to activate if they've not |
| 1473 | * already begun to do so. |
| 1474 | */ |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1475 | xpc_send_activate_IRQ_sn2(part_sn2->remote_amos_page_pa, |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1476 | cnodeid_to_nasid(0), |
| 1477 | part_sn2->activate_IRQ_nasid, |
| 1478 | part_sn2->activate_IRQ_phys_cpuid); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 1479 | |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1480 | while ((ret = xpc_pull_remote_vars_part_sn2(part)) != xpSuccess) { |
| 1481 | if (ret != xpRetry) { |
| 1482 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | dev_dbg(xpc_part, "waiting to make first contact with " |
| 1487 | "partition %d\n", XPC_PARTID(part)); |
| 1488 | |
| 1489 | /* wait a 1/4 of a second or so */ |
| 1490 | (void)msleep_interruptible(250); |
| 1491 | |
Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1492 | if (part->act_state == XPC_P_AS_DEACTIVATING) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1493 | return part->reason; |
| 1494 | } |
| 1495 | |
| 1496 | return xpSuccess; |
| 1497 | } |
| 1498 | |
| 1499 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1500 | * Get the chctl flags and pull the openclose args and/or remote GPs as needed. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1501 | */ |
| 1502 | static u64 |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1503 | xpc_get_chctl_all_flags_sn2(struct xpc_partition *part) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1504 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1505 | struct xpc_partition_sn2 *part_sn2 = &part->sn.sn2; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1506 | unsigned long irq_flags; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1507 | union xpc_channel_ctl_flags chctl; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1508 | enum xp_retval ret; |
| 1509 | |
| 1510 | /* |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1511 | * See if there are any chctl flags to be handled. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1512 | */ |
| 1513 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1514 | spin_lock_irqsave(&part->chctl_lock, irq_flags); |
| 1515 | chctl = part->chctl; |
| 1516 | if (chctl.all_flags != 0) |
| 1517 | part->chctl.all_flags = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1518 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1519 | spin_unlock_irqrestore(&part->chctl_lock, irq_flags); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1520 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1521 | if (xpc_any_openclose_chctl_flags_set(&chctl)) { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1522 | ret = xpc_pull_remote_cachelines_sn2(part, part-> |
| 1523 | remote_openclose_args, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1524 | part_sn2-> |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1525 | remote_openclose_args_pa, |
| 1526 | XPC_OPENCLOSE_ARGS_SIZE); |
| 1527 | if (ret != xpSuccess) { |
| 1528 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1529 | |
| 1530 | dev_dbg(xpc_chan, "failed to pull openclose args from " |
| 1531 | "partition %d, ret=%d\n", XPC_PARTID(part), |
| 1532 | ret); |
| 1533 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1534 | /* don't bother processing chctl flags anymore */ |
| 1535 | chctl.all_flags = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1539 | if (xpc_any_msg_chctl_flags_set(&chctl)) { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1540 | ret = xpc_pull_remote_cachelines_sn2(part, part_sn2->remote_GPs, |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1541 | part_sn2->remote_GPs_pa, |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1542 | XPC_GP_SIZE); |
| 1543 | if (ret != xpSuccess) { |
| 1544 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1545 | |
| 1546 | dev_dbg(xpc_chan, "failed to pull GPs from partition " |
| 1547 | "%d, ret=%d\n", XPC_PARTID(part), ret); |
| 1548 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1549 | /* don't bother processing chctl flags anymore */ |
| 1550 | chctl.all_flags = 0; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1554 | return chctl.all_flags; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1557 | /* |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1558 | * Allocate the local message queue and the notify queue. |
| 1559 | */ |
| 1560 | static enum xp_retval |
| 1561 | xpc_allocate_local_msgqueue_sn2(struct xpc_channel *ch) |
| 1562 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1563 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1564 | unsigned long irq_flags; |
| 1565 | int nentries; |
| 1566 | size_t nbytes; |
| 1567 | |
| 1568 | for (nentries = ch->local_nentries; nentries > 0; nentries--) { |
| 1569 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1570 | nbytes = nentries * ch->entry_size; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1571 | ch_sn2->local_msgqueue = |
| 1572 | xpc_kzalloc_cacheline_aligned(nbytes, GFP_KERNEL, |
| 1573 | &ch_sn2->local_msgqueue_base); |
| 1574 | if (ch_sn2->local_msgqueue == NULL) |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1575 | continue; |
| 1576 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1577 | nbytes = nentries * sizeof(struct xpc_notify_sn2); |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1578 | ch_sn2->notify_queue = kzalloc(nbytes, GFP_KERNEL); |
| 1579 | if (ch_sn2->notify_queue == NULL) { |
| 1580 | kfree(ch_sn2->local_msgqueue_base); |
| 1581 | ch_sn2->local_msgqueue = NULL; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1582 | continue; |
| 1583 | } |
| 1584 | |
| 1585 | spin_lock_irqsave(&ch->lock, irq_flags); |
| 1586 | if (nentries < ch->local_nentries) { |
| 1587 | dev_dbg(xpc_chan, "nentries=%d local_nentries=%d, " |
| 1588 | "partid=%d, channel=%d\n", nentries, |
| 1589 | ch->local_nentries, ch->partid, ch->number); |
| 1590 | |
| 1591 | ch->local_nentries = nentries; |
| 1592 | } |
| 1593 | spin_unlock_irqrestore(&ch->lock, irq_flags); |
| 1594 | return xpSuccess; |
| 1595 | } |
| 1596 | |
| 1597 | dev_dbg(xpc_chan, "can't get memory for local message queue and notify " |
| 1598 | "queue, partid=%d, channel=%d\n", ch->partid, ch->number); |
| 1599 | return xpNoMemory; |
| 1600 | } |
| 1601 | |
| 1602 | /* |
| 1603 | * Allocate the cached remote message queue. |
| 1604 | */ |
| 1605 | static enum xp_retval |
| 1606 | xpc_allocate_remote_msgqueue_sn2(struct xpc_channel *ch) |
| 1607 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1608 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1609 | unsigned long irq_flags; |
| 1610 | int nentries; |
| 1611 | size_t nbytes; |
| 1612 | |
| 1613 | DBUG_ON(ch->remote_nentries <= 0); |
| 1614 | |
| 1615 | for (nentries = ch->remote_nentries; nentries > 0; nentries--) { |
| 1616 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1617 | nbytes = nentries * ch->entry_size; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1618 | ch_sn2->remote_msgqueue = |
| 1619 | xpc_kzalloc_cacheline_aligned(nbytes, GFP_KERNEL, &ch_sn2-> |
| 1620 | remote_msgqueue_base); |
| 1621 | if (ch_sn2->remote_msgqueue == NULL) |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1622 | continue; |
| 1623 | |
| 1624 | spin_lock_irqsave(&ch->lock, irq_flags); |
| 1625 | if (nentries < ch->remote_nentries) { |
| 1626 | dev_dbg(xpc_chan, "nentries=%d remote_nentries=%d, " |
| 1627 | "partid=%d, channel=%d\n", nentries, |
| 1628 | ch->remote_nentries, ch->partid, ch->number); |
| 1629 | |
| 1630 | ch->remote_nentries = nentries; |
| 1631 | } |
| 1632 | spin_unlock_irqrestore(&ch->lock, irq_flags); |
| 1633 | return xpSuccess; |
| 1634 | } |
| 1635 | |
| 1636 | dev_dbg(xpc_chan, "can't get memory for cached remote message queue, " |
| 1637 | "partid=%d, channel=%d\n", ch->partid, ch->number); |
| 1638 | return xpNoMemory; |
| 1639 | } |
| 1640 | |
| 1641 | /* |
| 1642 | * Allocate message queues and other stuff associated with a channel. |
| 1643 | * |
| 1644 | * Note: Assumes all of the channel sizes are filled in. |
| 1645 | */ |
| 1646 | static enum xp_retval |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1647 | xpc_setup_msg_structures_sn2(struct xpc_channel *ch) |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1648 | { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1649 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1650 | enum xp_retval ret; |
| 1651 | |
| 1652 | DBUG_ON(ch->flags & XPC_C_SETUP); |
| 1653 | |
| 1654 | ret = xpc_allocate_local_msgqueue_sn2(ch); |
| 1655 | if (ret == xpSuccess) { |
| 1656 | |
| 1657 | ret = xpc_allocate_remote_msgqueue_sn2(ch); |
| 1658 | if (ret != xpSuccess) { |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1659 | kfree(ch_sn2->local_msgqueue_base); |
| 1660 | ch_sn2->local_msgqueue = NULL; |
| 1661 | kfree(ch_sn2->notify_queue); |
| 1662 | ch_sn2->notify_queue = NULL; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
| 1668 | /* |
| 1669 | * Free up message queues and other stuff that were allocated for the specified |
| 1670 | * channel. |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1671 | */ |
| 1672 | static void |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1673 | xpc_teardown_msg_structures_sn2(struct xpc_channel *ch) |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1674 | { |
| 1675 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
| 1676 | |
| 1677 | DBUG_ON(!spin_is_locked(&ch->lock)); |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1678 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1679 | ch_sn2->remote_msgqueue_pa = 0; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1680 | |
| 1681 | ch_sn2->local_GP->get = 0; |
| 1682 | ch_sn2->local_GP->put = 0; |
| 1683 | ch_sn2->remote_GP.get = 0; |
| 1684 | ch_sn2->remote_GP.put = 0; |
| 1685 | ch_sn2->w_local_GP.get = 0; |
| 1686 | ch_sn2->w_local_GP.put = 0; |
| 1687 | ch_sn2->w_remote_GP.get = 0; |
| 1688 | ch_sn2->w_remote_GP.put = 0; |
| 1689 | ch_sn2->next_msg_to_pull = 0; |
| 1690 | |
| 1691 | if (ch->flags & XPC_C_SETUP) { |
| 1692 | dev_dbg(xpc_chan, "ch->flags=0x%x, partid=%d, channel=%d\n", |
| 1693 | ch->flags, ch->partid, ch->number); |
| 1694 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1695 | kfree(ch_sn2->local_msgqueue_base); |
| 1696 | ch_sn2->local_msgqueue = NULL; |
| 1697 | kfree(ch_sn2->remote_msgqueue_base); |
| 1698 | ch_sn2->remote_msgqueue = NULL; |
| 1699 | kfree(ch_sn2->notify_queue); |
| 1700 | ch_sn2->notify_queue = NULL; |
Dean Nelson | 185c3a1 | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | /* |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1705 | * Notify those who wanted to be notified upon delivery of their message. |
| 1706 | */ |
| 1707 | static void |
| 1708 | xpc_notify_senders_sn2(struct xpc_channel *ch, enum xp_retval reason, s64 put) |
| 1709 | { |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1710 | struct xpc_notify_sn2 *notify; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1711 | u8 notify_type; |
| 1712 | s64 get = ch->sn.sn2.w_remote_GP.get - 1; |
| 1713 | |
| 1714 | while (++get < put && atomic_read(&ch->n_to_notify) > 0) { |
| 1715 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1716 | notify = &ch->sn.sn2.notify_queue[get % ch->local_nentries]; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1717 | |
| 1718 | /* |
| 1719 | * See if the notify entry indicates it was associated with |
| 1720 | * a message who's sender wants to be notified. It is possible |
| 1721 | * that it is, but someone else is doing or has done the |
| 1722 | * notification. |
| 1723 | */ |
| 1724 | notify_type = notify->type; |
| 1725 | if (notify_type == 0 || |
| 1726 | cmpxchg(¬ify->type, notify_type, 0) != notify_type) { |
| 1727 | continue; |
| 1728 | } |
| 1729 | |
| 1730 | DBUG_ON(notify_type != XPC_N_CALL); |
| 1731 | |
| 1732 | atomic_dec(&ch->n_to_notify); |
| 1733 | |
| 1734 | if (notify->func != NULL) { |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1735 | dev_dbg(xpc_chan, "notify->func() called, notify=0x%p " |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1736 | "msg_number=%lld partid=%d channel=%d\n", |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1737 | (void *)notify, get, ch->partid, ch->number); |
| 1738 | |
| 1739 | notify->func(reason, ch->partid, ch->number, |
| 1740 | notify->key); |
| 1741 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1742 | dev_dbg(xpc_chan, "notify->func() returned, notify=0x%p" |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1743 | " msg_number=%lld partid=%d channel=%d\n", |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1744 | (void *)notify, get, ch->partid, ch->number); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | static void |
| 1750 | xpc_notify_senders_of_disconnect_sn2(struct xpc_channel *ch) |
| 1751 | { |
| 1752 | xpc_notify_senders_sn2(ch, ch->reason, ch->sn.sn2.w_local_GP.put); |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * Clear some of the msg flags in the local message queue. |
| 1757 | */ |
| 1758 | static inline void |
| 1759 | xpc_clear_local_msgqueue_flags_sn2(struct xpc_channel *ch) |
| 1760 | { |
| 1761 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1762 | struct xpc_msg_sn2 *msg; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1763 | s64 get; |
| 1764 | |
| 1765 | get = ch_sn2->w_remote_GP.get; |
| 1766 | do { |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1767 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->local_msgqueue + |
| 1768 | (get % ch->local_nentries) * |
| 1769 | ch->entry_size); |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 1770 | DBUG_ON(!(msg->flags & XPC_M_SN2_READY)); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1771 | msg->flags = 0; |
| 1772 | } while (++get < ch_sn2->remote_GP.get); |
| 1773 | } |
| 1774 | |
| 1775 | /* |
| 1776 | * Clear some of the msg flags in the remote message queue. |
| 1777 | */ |
| 1778 | static inline void |
| 1779 | xpc_clear_remote_msgqueue_flags_sn2(struct xpc_channel *ch) |
| 1780 | { |
| 1781 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1782 | struct xpc_msg_sn2 *msg; |
Robin Holt | 6e873ec | 2009-04-02 16:59:14 -0700 | [diff] [blame] | 1783 | s64 put, remote_nentries = ch->remote_nentries; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1784 | |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 1785 | /* flags are zeroed when the buffer is allocated */ |
Robin Holt | 6e873ec | 2009-04-02 16:59:14 -0700 | [diff] [blame] | 1786 | if (ch_sn2->remote_GP.put < remote_nentries) |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 1787 | return; |
| 1788 | |
Robin Holt | 6e873ec | 2009-04-02 16:59:14 -0700 | [diff] [blame] | 1789 | put = max(ch_sn2->w_remote_GP.put, remote_nentries); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1790 | do { |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1791 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue + |
Robin Holt | 6e873ec | 2009-04-02 16:59:14 -0700 | [diff] [blame] | 1792 | (put % remote_nentries) * |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1793 | ch->entry_size); |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 1794 | DBUG_ON(!(msg->flags & XPC_M_SN2_READY)); |
| 1795 | DBUG_ON(!(msg->flags & XPC_M_SN2_DONE)); |
Robin Holt | 6e873ec | 2009-04-02 16:59:14 -0700 | [diff] [blame] | 1796 | DBUG_ON(msg->number != put - remote_nentries); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1797 | msg->flags = 0; |
| 1798 | } while (++put < ch_sn2->remote_GP.put); |
| 1799 | } |
| 1800 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1801 | static int |
| 1802 | xpc_n_of_deliverable_payloads_sn2(struct xpc_channel *ch) |
| 1803 | { |
| 1804 | return ch->sn.sn2.w_remote_GP.put - ch->sn.sn2.w_local_GP.get; |
| 1805 | } |
| 1806 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1807 | static void |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 1808 | xpc_process_msg_chctl_flags_sn2(struct xpc_partition *part, int ch_number) |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1809 | { |
| 1810 | struct xpc_channel *ch = &part->channels[ch_number]; |
| 1811 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1812 | int npayloads_sent; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1813 | |
| 1814 | ch_sn2->remote_GP = part->sn.sn2.remote_GPs[ch_number]; |
| 1815 | |
| 1816 | /* See what, if anything, has changed for each connected channel */ |
| 1817 | |
| 1818 | xpc_msgqueue_ref(ch); |
| 1819 | |
| 1820 | if (ch_sn2->w_remote_GP.get == ch_sn2->remote_GP.get && |
| 1821 | ch_sn2->w_remote_GP.put == ch_sn2->remote_GP.put) { |
| 1822 | /* nothing changed since GPs were last pulled */ |
| 1823 | xpc_msgqueue_deref(ch); |
| 1824 | return; |
| 1825 | } |
| 1826 | |
| 1827 | if (!(ch->flags & XPC_C_CONNECTED)) { |
| 1828 | xpc_msgqueue_deref(ch); |
| 1829 | return; |
| 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * First check to see if messages recently sent by us have been |
| 1834 | * received by the other side. (The remote GET value will have |
| 1835 | * changed since we last looked at it.) |
| 1836 | */ |
| 1837 | |
| 1838 | if (ch_sn2->w_remote_GP.get != ch_sn2->remote_GP.get) { |
| 1839 | |
| 1840 | /* |
| 1841 | * We need to notify any senders that want to be notified |
| 1842 | * that their sent messages have been received by their |
| 1843 | * intended recipients. We need to do this before updating |
| 1844 | * w_remote_GP.get so that we don't allocate the same message |
| 1845 | * queue entries prematurely (see xpc_allocate_msg()). |
| 1846 | */ |
| 1847 | if (atomic_read(&ch->n_to_notify) > 0) { |
| 1848 | /* |
| 1849 | * Notify senders that messages sent have been |
| 1850 | * received and delivered by the other side. |
| 1851 | */ |
| 1852 | xpc_notify_senders_sn2(ch, xpMsgDelivered, |
| 1853 | ch_sn2->remote_GP.get); |
| 1854 | } |
| 1855 | |
| 1856 | /* |
| 1857 | * Clear msg->flags in previously sent messages, so that |
| 1858 | * they're ready for xpc_allocate_msg(). |
| 1859 | */ |
| 1860 | xpc_clear_local_msgqueue_flags_sn2(ch); |
| 1861 | |
| 1862 | ch_sn2->w_remote_GP.get = ch_sn2->remote_GP.get; |
| 1863 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1864 | dev_dbg(xpc_chan, "w_remote_GP.get changed to %lld, partid=%d, " |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1865 | "channel=%d\n", ch_sn2->w_remote_GP.get, ch->partid, |
| 1866 | ch->number); |
| 1867 | |
| 1868 | /* |
| 1869 | * If anyone was waiting for message queue entries to become |
| 1870 | * available, wake them up. |
| 1871 | */ |
| 1872 | if (atomic_read(&ch->n_on_msg_allocate_wq) > 0) |
| 1873 | wake_up(&ch->msg_allocate_wq); |
| 1874 | } |
| 1875 | |
| 1876 | /* |
| 1877 | * Now check for newly sent messages by the other side. (The remote |
| 1878 | * PUT value will have changed since we last looked at it.) |
| 1879 | */ |
| 1880 | |
| 1881 | if (ch_sn2->w_remote_GP.put != ch_sn2->remote_GP.put) { |
| 1882 | /* |
| 1883 | * Clear msg->flags in previously received messages, so that |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1884 | * they're ready for xpc_get_deliverable_payload_sn2(). |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1885 | */ |
| 1886 | xpc_clear_remote_msgqueue_flags_sn2(ch); |
| 1887 | |
Robin Holt | 69b3bb6 | 2009-01-29 14:25:06 -0800 | [diff] [blame] | 1888 | smp_wmb(); /* ensure flags have been cleared before bte_copy */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1889 | ch_sn2->w_remote_GP.put = ch_sn2->remote_GP.put; |
| 1890 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1891 | dev_dbg(xpc_chan, "w_remote_GP.put changed to %lld, partid=%d, " |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1892 | "channel=%d\n", ch_sn2->w_remote_GP.put, ch->partid, |
| 1893 | ch->number); |
| 1894 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1895 | npayloads_sent = xpc_n_of_deliverable_payloads_sn2(ch); |
| 1896 | if (npayloads_sent > 0) { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1897 | dev_dbg(xpc_chan, "msgs waiting to be copied and " |
| 1898 | "delivered=%d, partid=%d, channel=%d\n", |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1899 | npayloads_sent, ch->partid, ch->number); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1900 | |
| 1901 | if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1902 | xpc_activate_kthreads(ch, npayloads_sent); |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | xpc_msgqueue_deref(ch); |
| 1907 | } |
| 1908 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1909 | static struct xpc_msg_sn2 * |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1910 | xpc_pull_remote_msg_sn2(struct xpc_channel *ch, s64 get) |
| 1911 | { |
| 1912 | struct xpc_partition *part = &xpc_partitions[ch->partid]; |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1913 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1914 | unsigned long remote_msg_pa; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1915 | struct xpc_msg_sn2 *msg; |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1916 | u32 msg_index; |
| 1917 | u32 nmsgs; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1918 | u64 msg_offset; |
| 1919 | enum xp_retval ret; |
| 1920 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1921 | if (mutex_lock_interruptible(&ch_sn2->msg_to_pull_mutex) != 0) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1922 | /* we were interrupted by a signal */ |
| 1923 | return NULL; |
| 1924 | } |
| 1925 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1926 | while (get >= ch_sn2->next_msg_to_pull) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1927 | |
| 1928 | /* pull as many messages as are ready and able to be pulled */ |
| 1929 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1930 | msg_index = ch_sn2->next_msg_to_pull % ch->remote_nentries; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1931 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1932 | DBUG_ON(ch_sn2->next_msg_to_pull >= ch_sn2->w_remote_GP.put); |
| 1933 | nmsgs = ch_sn2->w_remote_GP.put - ch_sn2->next_msg_to_pull; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1934 | if (msg_index + nmsgs > ch->remote_nentries) { |
| 1935 | /* ignore the ones that wrap the msg queue for now */ |
| 1936 | nmsgs = ch->remote_nentries - msg_index; |
| 1937 | } |
| 1938 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1939 | msg_offset = msg_index * ch->entry_size; |
| 1940 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue + |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 1941 | msg_offset); |
| 1942 | remote_msg_pa = ch_sn2->remote_msgqueue_pa + msg_offset; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1943 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 1944 | ret = xpc_pull_remote_cachelines_sn2(part, msg, remote_msg_pa, |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1945 | nmsgs * ch->entry_size); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1946 | if (ret != xpSuccess) { |
| 1947 | |
| 1948 | dev_dbg(xpc_chan, "failed to pull %d msgs starting with" |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 1949 | " msg %lld from partition %d, channel=%d, " |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1950 | "ret=%d\n", nmsgs, ch_sn2->next_msg_to_pull, |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1951 | ch->partid, ch->number, ret); |
| 1952 | |
| 1953 | XPC_DEACTIVATE_PARTITION(part, ret); |
| 1954 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1955 | mutex_unlock(&ch_sn2->msg_to_pull_mutex); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1956 | return NULL; |
| 1957 | } |
| 1958 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1959 | ch_sn2->next_msg_to_pull += nmsgs; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1962 | mutex_unlock(&ch_sn2->msg_to_pull_mutex); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1963 | |
| 1964 | /* return the message we were looking for */ |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1965 | msg_offset = (get % ch->remote_nentries) * ch->entry_size; |
| 1966 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->remote_msgqueue + msg_offset); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1967 | |
| 1968 | return msg; |
| 1969 | } |
| 1970 | |
| 1971 | /* |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1972 | * Get the next deliverable message's payload. |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1973 | */ |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1974 | static void * |
| 1975 | xpc_get_deliverable_payload_sn2(struct xpc_channel *ch) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1976 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1977 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 1978 | struct xpc_msg_sn2 *msg; |
| 1979 | void *payload = NULL; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1980 | s64 get; |
| 1981 | |
| 1982 | do { |
| 1983 | if (ch->flags & XPC_C_DISCONNECTING) |
| 1984 | break; |
| 1985 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1986 | get = ch_sn2->w_local_GP.get; |
Robin Holt | 69b3bb6 | 2009-01-29 14:25:06 -0800 | [diff] [blame] | 1987 | smp_rmb(); /* guarantee that .get loads before .put */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1988 | if (get == ch_sn2->w_remote_GP.put) |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1989 | break; |
| 1990 | |
| 1991 | /* There are messages waiting to be pulled and delivered. |
| 1992 | * We need to try to secure one for ourselves. We'll do this |
| 1993 | * by trying to increment w_local_GP.get and hope that no one |
| 1994 | * else beats us to it. If they do, we'll we'll simply have |
| 1995 | * to try again for the next one. |
| 1996 | */ |
| 1997 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 1998 | if (cmpxchg(&ch_sn2->w_local_GP.get, get, get + 1) == get) { |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 1999 | /* we got the entry referenced by get */ |
| 2000 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 2001 | dev_dbg(xpc_chan, "w_local_GP.get changed to %lld, " |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 2002 | "partid=%d, channel=%d\n", get + 1, |
| 2003 | ch->partid, ch->number); |
| 2004 | |
| 2005 | /* pull the message from the remote partition */ |
| 2006 | |
| 2007 | msg = xpc_pull_remote_msg_sn2(ch, get); |
| 2008 | |
Robin Holt | 17e2161 | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 2009 | if (msg != NULL) { |
| 2010 | DBUG_ON(msg->number != get); |
| 2011 | DBUG_ON(msg->flags & XPC_M_SN2_DONE); |
| 2012 | DBUG_ON(!(msg->flags & XPC_M_SN2_READY)); |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 2013 | |
Robin Holt | 17e2161 | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 2014 | payload = &msg->payload; |
| 2015 | } |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | } while (1); |
| 2020 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2021 | return payload; |
Dean Nelson | e17d416 | 2008-07-29 22:34:06 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2024 | /* |
| 2025 | * Now we actually send the messages that are ready to be sent by advancing |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2026 | * the local message queue's Put value and then send a chctl msgrequest to the |
| 2027 | * recipient partition. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2028 | */ |
| 2029 | static void |
| 2030 | xpc_send_msgs_sn2(struct xpc_channel *ch, s64 initial_put) |
| 2031 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2032 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2033 | struct xpc_msg_sn2 *msg; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2034 | s64 put = initial_put + 1; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2035 | int send_msgrequest = 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2036 | |
| 2037 | while (1) { |
| 2038 | |
| 2039 | while (1) { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2040 | if (put == ch_sn2->w_local_GP.put) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2041 | break; |
| 2042 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2043 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2-> |
| 2044 | local_msgqueue + (put % |
| 2045 | ch->local_nentries) * |
| 2046 | ch->entry_size); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2047 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2048 | if (!(msg->flags & XPC_M_SN2_READY)) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2049 | break; |
| 2050 | |
| 2051 | put++; |
| 2052 | } |
| 2053 | |
| 2054 | if (put == initial_put) { |
| 2055 | /* nothing's changed */ |
| 2056 | break; |
| 2057 | } |
| 2058 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2059 | if (cmpxchg_rel(&ch_sn2->local_GP->put, initial_put, put) != |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2060 | initial_put) { |
| 2061 | /* someone else beat us to it */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2062 | DBUG_ON(ch_sn2->local_GP->put < initial_put); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | |
| 2066 | /* we just set the new value of local_GP->put */ |
| 2067 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 2068 | dev_dbg(xpc_chan, "local_GP->put changed to %lld, partid=%d, " |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2069 | "channel=%d\n", put, ch->partid, ch->number); |
| 2070 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2071 | send_msgrequest = 1; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2072 | |
| 2073 | /* |
| 2074 | * We need to ensure that the message referenced by |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2075 | * local_GP->put is not XPC_M_SN2_READY or that local_GP->put |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2076 | * equals w_local_GP.put, so we'll go have a look. |
| 2077 | */ |
| 2078 | initial_put = put; |
| 2079 | } |
| 2080 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2081 | if (send_msgrequest) |
| 2082 | xpc_send_chctl_msgrequest_sn2(ch); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | /* |
| 2086 | * Allocate an entry for a message from the message queue associated with the |
| 2087 | * specified channel. |
| 2088 | */ |
| 2089 | static enum xp_retval |
| 2090 | xpc_allocate_msg_sn2(struct xpc_channel *ch, u32 flags, |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2091 | struct xpc_msg_sn2 **address_of_msg) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2092 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2093 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2094 | struct xpc_msg_sn2 *msg; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2095 | enum xp_retval ret; |
| 2096 | s64 put; |
| 2097 | |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2098 | /* |
| 2099 | * Get the next available message entry from the local message queue. |
| 2100 | * If none are available, we'll make sure that we grab the latest |
| 2101 | * GP values. |
| 2102 | */ |
| 2103 | ret = xpTimeout; |
| 2104 | |
| 2105 | while (1) { |
| 2106 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2107 | put = ch_sn2->w_local_GP.put; |
Robin Holt | 69b3bb6 | 2009-01-29 14:25:06 -0800 | [diff] [blame] | 2108 | smp_rmb(); /* guarantee that .put loads before .get */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2109 | if (put - ch_sn2->w_remote_GP.get < ch->local_nentries) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2110 | |
| 2111 | /* There are available message entries. We need to try |
| 2112 | * to secure one for ourselves. We'll do this by trying |
| 2113 | * to increment w_local_GP.put as long as someone else |
| 2114 | * doesn't beat us to it. If they do, we'll have to |
| 2115 | * try again. |
| 2116 | */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2117 | if (cmpxchg(&ch_sn2->w_local_GP.put, put, put + 1) == |
| 2118 | put) { |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2119 | /* we got the entry referenced by put */ |
| 2120 | break; |
| 2121 | } |
| 2122 | continue; /* try again */ |
| 2123 | } |
| 2124 | |
| 2125 | /* |
| 2126 | * There aren't any available msg entries at this time. |
| 2127 | * |
| 2128 | * In waiting for a message entry to become available, |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2129 | * we set a timeout in case the other side is not sending |
| 2130 | * completion interrupts. This lets us fake a notify IRQ |
| 2131 | * that will cause the notify IRQ handler to fetch the latest |
| 2132 | * GP values as if an interrupt was sent by the other side. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2133 | */ |
| 2134 | if (ret == xpTimeout) |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2135 | xpc_send_chctl_local_msgrequest_sn2(ch); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2136 | |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2137 | if (flags & XPC_NOWAIT) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2138 | return xpNoWait; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2139 | |
| 2140 | ret = xpc_allocate_msg_wait(ch); |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2141 | if (ret != xpInterrupted && ret != xpTimeout) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2142 | return ret; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /* get the message's address and initialize it */ |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2146 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2->local_msgqueue + |
| 2147 | (put % ch->local_nentries) * |
| 2148 | ch->entry_size); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2149 | |
| 2150 | DBUG_ON(msg->flags != 0); |
| 2151 | msg->number = put; |
| 2152 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 2153 | dev_dbg(xpc_chan, "w_local_GP.put changed to %lld; msg=0x%p, " |
| 2154 | "msg_number=%lld, partid=%d, channel=%d\n", put + 1, |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2155 | (void *)msg, msg->number, ch->partid, ch->number); |
| 2156 | |
| 2157 | *address_of_msg = msg; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2158 | return xpSuccess; |
| 2159 | } |
| 2160 | |
| 2161 | /* |
| 2162 | * Common code that does the actual sending of the message by advancing the |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2163 | * local message queue's Put value and sends a chctl msgrequest to the |
| 2164 | * partition the message is being sent to. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2165 | */ |
| 2166 | static enum xp_retval |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2167 | xpc_send_payload_sn2(struct xpc_channel *ch, u32 flags, void *payload, |
| 2168 | u16 payload_size, u8 notify_type, xpc_notify_func func, |
| 2169 | void *key) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2170 | { |
| 2171 | enum xp_retval ret = xpSuccess; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 2172 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2173 | struct xpc_msg_sn2 *msg = msg; |
| 2174 | struct xpc_notify_sn2 *notify = notify; |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2175 | s64 msg_number; |
| 2176 | s64 put; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2177 | |
| 2178 | DBUG_ON(notify_type == XPC_N_CALL && func == NULL); |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2179 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2180 | if (XPC_MSG_SIZE(payload_size) > ch->entry_size) |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2181 | return xpPayloadTooBig; |
| 2182 | |
| 2183 | xpc_msgqueue_ref(ch); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2184 | |
| 2185 | if (ch->flags & XPC_C_DISCONNECTING) { |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2186 | ret = ch->reason; |
| 2187 | goto out_1; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2188 | } |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2189 | if (!(ch->flags & XPC_C_CONNECTED)) { |
| 2190 | ret = xpNotConnected; |
| 2191 | goto out_1; |
| 2192 | } |
| 2193 | |
| 2194 | ret = xpc_allocate_msg_sn2(ch, flags, &msg); |
| 2195 | if (ret != xpSuccess) |
| 2196 | goto out_1; |
| 2197 | |
| 2198 | msg_number = msg->number; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2199 | |
| 2200 | if (notify_type != 0) { |
| 2201 | /* |
| 2202 | * Tell the remote side to send an ACK interrupt when the |
| 2203 | * message has been delivered. |
| 2204 | */ |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2205 | msg->flags |= XPC_M_SN2_INTERRUPT; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2206 | |
| 2207 | atomic_inc(&ch->n_to_notify); |
| 2208 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 2209 | notify = &ch_sn2->notify_queue[msg_number % ch->local_nentries]; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2210 | notify->func = func; |
| 2211 | notify->key = key; |
| 2212 | notify->type = notify_type; |
| 2213 | |
Dean Nelson | ea57f80 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 2214 | /* ??? Is a mb() needed here? */ |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2215 | |
| 2216 | if (ch->flags & XPC_C_DISCONNECTING) { |
| 2217 | /* |
| 2218 | * An error occurred between our last error check and |
| 2219 | * this one. We will try to clear the type field from |
| 2220 | * the notify entry. If we succeed then |
| 2221 | * xpc_disconnect_channel() didn't already process |
| 2222 | * the notify entry. |
| 2223 | */ |
| 2224 | if (cmpxchg(¬ify->type, notify_type, 0) == |
| 2225 | notify_type) { |
| 2226 | atomic_dec(&ch->n_to_notify); |
| 2227 | ret = ch->reason; |
| 2228 | } |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2229 | goto out_1; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2233 | memcpy(&msg->payload, payload, payload_size); |
| 2234 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2235 | msg->flags |= XPC_M_SN2_READY; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2236 | |
| 2237 | /* |
| 2238 | * The preceding store of msg->flags must occur before the following |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2239 | * load of local_GP->put. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2240 | */ |
Robin Holt | 69b3bb6 | 2009-01-29 14:25:06 -0800 | [diff] [blame] | 2241 | smp_mb(); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2242 | |
| 2243 | /* see if the message is next in line to be sent, if so send it */ |
| 2244 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 2245 | put = ch_sn2->local_GP->put; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2246 | if (put == msg_number) |
| 2247 | xpc_send_msgs_sn2(ch, put); |
| 2248 | |
Dean Nelson | 97bf1aa | 2008-07-29 22:34:08 -0700 | [diff] [blame] | 2249 | out_1: |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2250 | xpc_msgqueue_deref(ch); |
| 2251 | return ret; |
| 2252 | } |
| 2253 | |
| 2254 | /* |
| 2255 | * Now we actually acknowledge the messages that have been delivered and ack'd |
| 2256 | * by advancing the cached remote message queue's Get value and if requested |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2257 | * send a chctl msgrequest to the message sender's partition. |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2258 | * |
| 2259 | * If a message has XPC_M_SN2_INTERRUPT set, send an interrupt to the partition |
| 2260 | * that sent the message. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2261 | */ |
| 2262 | static void |
| 2263 | xpc_acknowledge_msgs_sn2(struct xpc_channel *ch, s64 initial_get, u8 msg_flags) |
| 2264 | { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2265 | struct xpc_channel_sn2 *ch_sn2 = &ch->sn.sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2266 | struct xpc_msg_sn2 *msg; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2267 | s64 get = initial_get + 1; |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2268 | int send_msgrequest = 0; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2269 | |
| 2270 | while (1) { |
| 2271 | |
| 2272 | while (1) { |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2273 | if (get == ch_sn2->w_local_GP.get) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2274 | break; |
| 2275 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2276 | msg = (struct xpc_msg_sn2 *)((u64)ch_sn2-> |
| 2277 | remote_msgqueue + (get % |
| 2278 | ch->remote_nentries) * |
| 2279 | ch->entry_size); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2280 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2281 | if (!(msg->flags & XPC_M_SN2_DONE)) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2282 | break; |
| 2283 | |
| 2284 | msg_flags |= msg->flags; |
| 2285 | get++; |
| 2286 | } |
| 2287 | |
| 2288 | if (get == initial_get) { |
| 2289 | /* nothing's changed */ |
| 2290 | break; |
| 2291 | } |
| 2292 | |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2293 | if (cmpxchg_rel(&ch_sn2->local_GP->get, initial_get, get) != |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2294 | initial_get) { |
| 2295 | /* someone else beat us to it */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2296 | DBUG_ON(ch_sn2->local_GP->get <= initial_get); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | |
| 2300 | /* we just set the new value of local_GP->get */ |
| 2301 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 2302 | dev_dbg(xpc_chan, "local_GP->get changed to %lld, partid=%d, " |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2303 | "channel=%d\n", get, ch->partid, ch->number); |
| 2304 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2305 | send_msgrequest = (msg_flags & XPC_M_SN2_INTERRUPT); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2306 | |
| 2307 | /* |
| 2308 | * We need to ensure that the message referenced by |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2309 | * local_GP->get is not XPC_M_SN2_DONE or that local_GP->get |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2310 | * equals w_local_GP.get, so we'll go have a look. |
| 2311 | */ |
| 2312 | initial_get = get; |
| 2313 | } |
| 2314 | |
Dean Nelson | 7fb5e59 | 2008-07-29 22:34:10 -0700 | [diff] [blame] | 2315 | if (send_msgrequest) |
| 2316 | xpc_send_chctl_msgrequest_sn2(ch); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | static void |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2320 | xpc_received_payload_sn2(struct xpc_channel *ch, void *payload) |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2321 | { |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2322 | struct xpc_msg_sn2 *msg; |
| 2323 | s64 msg_number; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2324 | s64 get; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2325 | |
| 2326 | msg = container_of(payload, struct xpc_msg_sn2, payload); |
| 2327 | msg_number = msg->number; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2328 | |
Randy Dunlap | f509e34 | 2009-09-04 17:02:59 -0700 | [diff] [blame] | 2329 | dev_dbg(xpc_chan, "msg=0x%p, msg_number=%lld, partid=%d, channel=%d\n", |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2330 | (void *)msg, msg_number, ch->partid, ch->number); |
| 2331 | |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 2332 | DBUG_ON((((u64)msg - (u64)ch->sn.sn2.remote_msgqueue) / ch->entry_size) != |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2333 | msg_number % ch->remote_nentries); |
Robin Holt | 252523e | 2009-01-29 14:25:07 -0800 | [diff] [blame] | 2334 | DBUG_ON(!(msg->flags & XPC_M_SN2_READY)); |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2335 | DBUG_ON(msg->flags & XPC_M_SN2_DONE); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2336 | |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2337 | msg->flags |= XPC_M_SN2_DONE; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2338 | |
| 2339 | /* |
| 2340 | * The preceding store of msg->flags must occur before the following |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2341 | * load of local_GP->get. |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2342 | */ |
Robin Holt | 69b3bb6 | 2009-01-29 14:25:06 -0800 | [diff] [blame] | 2343 | smp_mb(); |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2344 | |
| 2345 | /* |
| 2346 | * See if this message is next in line to be acknowledged as having |
| 2347 | * been delivered. |
| 2348 | */ |
Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2349 | get = ch->sn.sn2.local_GP->get; |
Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 2350 | if (get == msg_number) |
| 2351 | xpc_acknowledge_msgs_sn2(ch, get, msg->flags); |
| 2352 | } |
| 2353 | |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 2354 | static struct xpc_arch_operations xpc_arch_ops_sn2 = { |
| 2355 | .setup_partitions = xpc_setup_partitions_sn2, |
| 2356 | .teardown_partitions = xpc_teardown_partitions_sn2, |
| 2357 | .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2, |
| 2358 | .get_partition_rsvd_page_pa = xpc_get_partition_rsvd_page_pa_sn2, |
| 2359 | .setup_rsvd_page = xpc_setup_rsvd_page_sn2, |
| 2360 | |
| 2361 | .allow_hb = xpc_allow_hb_sn2, |
| 2362 | .disallow_hb = xpc_disallow_hb_sn2, |
| 2363 | .disallow_all_hbs = xpc_disallow_all_hbs_sn2, |
| 2364 | .increment_heartbeat = xpc_increment_heartbeat_sn2, |
| 2365 | .offline_heartbeat = xpc_offline_heartbeat_sn2, |
| 2366 | .online_heartbeat = xpc_online_heartbeat_sn2, |
| 2367 | .heartbeat_init = xpc_heartbeat_init_sn2, |
| 2368 | .heartbeat_exit = xpc_heartbeat_exit_sn2, |
| 2369 | .get_remote_heartbeat = xpc_get_remote_heartbeat_sn2, |
| 2370 | |
| 2371 | .request_partition_activation = |
| 2372 | xpc_request_partition_activation_sn2, |
| 2373 | .request_partition_reactivation = |
| 2374 | xpc_request_partition_reactivation_sn2, |
| 2375 | .request_partition_deactivation = |
| 2376 | xpc_request_partition_deactivation_sn2, |
| 2377 | .cancel_partition_deactivation_request = |
| 2378 | xpc_cancel_partition_deactivation_request_sn2, |
| 2379 | |
| 2380 | .setup_ch_structures = xpc_setup_ch_structures_sn2, |
| 2381 | .teardown_ch_structures = xpc_teardown_ch_structures_sn2, |
| 2382 | |
| 2383 | .make_first_contact = xpc_make_first_contact_sn2, |
| 2384 | |
| 2385 | .get_chctl_all_flags = xpc_get_chctl_all_flags_sn2, |
| 2386 | .send_chctl_closerequest = xpc_send_chctl_closerequest_sn2, |
| 2387 | .send_chctl_closereply = xpc_send_chctl_closereply_sn2, |
| 2388 | .send_chctl_openrequest = xpc_send_chctl_openrequest_sn2, |
| 2389 | .send_chctl_openreply = xpc_send_chctl_openreply_sn2, |
| 2390 | .send_chctl_opencomplete = xpc_send_chctl_opencomplete_sn2, |
| 2391 | .process_msg_chctl_flags = xpc_process_msg_chctl_flags_sn2, |
| 2392 | |
| 2393 | .save_remote_msgqueue_pa = xpc_save_remote_msgqueue_pa_sn2, |
| 2394 | |
| 2395 | .setup_msg_structures = xpc_setup_msg_structures_sn2, |
| 2396 | .teardown_msg_structures = xpc_teardown_msg_structures_sn2, |
| 2397 | |
| 2398 | .indicate_partition_engaged = xpc_indicate_partition_engaged_sn2, |
| 2399 | .indicate_partition_disengaged = xpc_indicate_partition_disengaged_sn2, |
| 2400 | .partition_engaged = xpc_partition_engaged_sn2, |
| 2401 | .any_partition_engaged = xpc_any_partition_engaged_sn2, |
| 2402 | .assume_partition_disengaged = xpc_assume_partition_disengaged_sn2, |
| 2403 | |
| 2404 | .n_of_deliverable_payloads = xpc_n_of_deliverable_payloads_sn2, |
| 2405 | .send_payload = xpc_send_payload_sn2, |
| 2406 | .get_deliverable_payload = xpc_get_deliverable_payload_sn2, |
| 2407 | .received_payload = xpc_received_payload_sn2, |
| 2408 | .notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_sn2, |
| 2409 | }; |
| 2410 | |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2411 | int |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 2412 | xpc_init_sn2(void) |
| 2413 | { |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2414 | int ret; |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 2415 | size_t buf_size; |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2416 | |
Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 2417 | xpc_arch_ops = xpc_arch_ops_sn2; |
Dean Nelson | bd3e64c | 2008-07-29 22:34:19 -0700 | [diff] [blame] | 2418 | |
| 2419 | if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) { |
| 2420 | dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is " |
| 2421 | "larger than %d\n", XPC_MSG_HDR_MAX_SIZE); |
| 2422 | return -E2BIG; |
| 2423 | } |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2424 | |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 2425 | buf_size = max(XPC_RP_VARS_SIZE, |
| 2426 | XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES_SN2); |
| 2427 | xpc_remote_copy_buffer_sn2 = xpc_kmalloc_cacheline_aligned(buf_size, |
| 2428 | GFP_KERNEL, |
| 2429 | &xpc_remote_copy_buffer_base_sn2); |
| 2430 | if (xpc_remote_copy_buffer_sn2 == NULL) { |
| 2431 | dev_err(xpc_part, "can't get memory for remote copy buffer\n"); |
| 2432 | return -ENOMEM; |
| 2433 | } |
| 2434 | |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 2435 | /* open up protections for IPI and [potentially] amo operations */ |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2436 | xpc_allow_IPI_ops_sn2(); |
Dean Nelson | c39838c | 2008-07-29 22:34:11 -0700 | [diff] [blame] | 2437 | xpc_allow_amo_ops_shub_wars_1_1_sn2(); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2438 | |
| 2439 | /* |
| 2440 | * This is safe to do before the xpc_hb_checker thread has started |
| 2441 | * because the handler releases a wait queue. If an interrupt is |
| 2442 | * received before the thread is waiting, it will not go to sleep, |
| 2443 | * but rather immediately process the interrupt. |
| 2444 | */ |
| 2445 | ret = request_irq(SGI_XPC_ACTIVATE, xpc_handle_activate_IRQ_sn2, 0, |
| 2446 | "xpc hb", NULL); |
| 2447 | if (ret != 0) { |
| 2448 | dev_err(xpc_part, "can't register ACTIVATE IRQ handler, " |
| 2449 | "errno=%d\n", -ret); |
| 2450 | xpc_disallow_IPI_ops_sn2(); |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 2451 | kfree(xpc_remote_copy_buffer_base_sn2); |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2452 | } |
| 2453 | return ret; |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | void |
| 2457 | xpc_exit_sn2(void) |
| 2458 | { |
Dean Nelson | 6e41017 | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 2459 | free_irq(SGI_XPC_ACTIVATE, NULL); |
| 2460 | xpc_disallow_IPI_ops_sn2(); |
Dean Nelson | ee6665e | 2008-07-29 22:34:13 -0700 | [diff] [blame] | 2461 | kfree(xpc_remote_copy_buffer_base_sn2); |
Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 2462 | } |