1 From: Dean Nelson <dcn@sgi.com>
2 Subject: [PATCH] Add the code to create the activate and notify gru message queues
5 For UV add the code to create the activate and notify gru message queues.
7 Signed-off-by: Dean Nelson <dcn@sgi.com>
8 Acked-by: Bernhard Walle <bwalle@suse.de>
12 drivers/misc/sgi-xp/xpc.h | 12 +
13 drivers/misc/sgi-xp/xpc_uv.c | 259 ++++++++++++++++++++++++++++++++++---------
14 2 files changed, 218 insertions(+), 53 deletions(-)
16 --- a/drivers/misc/sgi-xp/xpc.h
17 +++ b/drivers/misc/sgi-xp/xpc.h
18 @@ -181,6 +181,18 @@ struct xpc_vars_part_sn2 {
19 xpc_nasid_mask_nlongs))
22 + * Info pertinent to a GRU message queue using a watch list for irq generation.
24 +struct xpc_gru_mq_uv {
25 + void *address; /* address of GRU message queue */
26 + unsigned int order; /* size of GRU message queue as a power of 2 */
27 + int irq; /* irq raised when message is received in mq */
28 + int mmr_blade; /* blade where watchlist was allocated from */
29 + unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
30 + int watchlist_num; /* number of watchlist allocatd by BIOS */
34 * The activate_mq is used to send/receive GRU messages that affect XPC's
35 * heartbeat, partition active state, and channel state. This is UV only.
37 --- a/drivers/misc/sgi-xp/xpc_uv.c
38 +++ b/drivers/misc/sgi-xp/xpc_uv.c
40 #include <linux/interrupt.h>
41 #include <linux/delay.h>
42 #include <linux/device.h>
43 +#include <linux/err.h>
44 #include <asm/uv/uv_hub.h>
45 +#if defined CONFIG_X86_64
46 +#include <asm/uv/bios.h>
47 +#include <asm/uv/uv_irq.h>
48 +#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
49 +#include <asm/sn/intr.h>
50 +#include <asm/sn/sn_sal.h>
52 #include "../sgi-gru/gru.h"
53 #include "../sgi-gru/grukservices.h"
55 @@ -27,15 +35,17 @@ static atomic64_t xpc_heartbeat_uv;
56 static DECLARE_BITMAP(xpc_heartbeating_to_mask_uv, XP_MAX_NPARTITIONS_UV);
58 #define XPC_ACTIVATE_MSG_SIZE_UV (1 * GRU_CACHE_LINE_BYTES)
59 -#define XPC_NOTIFY_MSG_SIZE_UV (2 * GRU_CACHE_LINE_BYTES)
60 +#define XPC_ACTIVATE_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
61 + XPC_ACTIVATE_MSG_SIZE_UV)
62 +#define XPC_ACTIVATE_IRQ_NAME "xpc_activate"
64 -#define XPC_ACTIVATE_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
65 - XPC_ACTIVATE_MSG_SIZE_UV)
66 -#define XPC_NOTIFY_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
67 - XPC_NOTIFY_MSG_SIZE_UV)
68 +#define XPC_NOTIFY_MSG_SIZE_UV (2 * GRU_CACHE_LINE_BYTES)
69 +#define XPC_NOTIFY_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
70 + XPC_NOTIFY_MSG_SIZE_UV)
71 +#define XPC_NOTIFY_IRQ_NAME "xpc_notify"
73 -static void *xpc_activate_mq_uv;
74 -static void *xpc_notify_mq_uv;
75 +static struct xpc_gru_mq_uv *xpc_activate_mq_uv;
76 +static struct xpc_gru_mq_uv *xpc_notify_mq_uv;
79 xpc_setup_partitions_sn_uv(void)
80 @@ -52,62 +62,209 @@ xpc_setup_partitions_sn_uv(void)
85 -xpc_create_gru_mq_uv(unsigned int mq_size, int cpuid, unsigned int irq,
87 +xpc_get_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq, int cpu, char *irq_name)
89 +#if defined CONFIG_X86_64
90 + mq->irq = uv_setup_irq(irq_name, cpu, mq->mmr_blade, mq->mmr_offset);
92 + dev_err(xpc_part, "uv_setup_irq() returned error=%d\n",
96 +#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
98 + unsigned long mmr_value;
100 + if (strcmp(irq_name, XPC_ACTIVATE_IRQ_NAME) == 0)
101 + mq->irq = SGI_XPC_ACTIVATE;
102 + else if (strcmp(irq_name, XPC_NOTIFY_IRQ_NAME) == 0)
103 + mq->irq = SGI_XPC_NOTIFY;
107 + mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
108 + mmr_value = (unsigned long)cpu_physical_id(cpu) << 32 | mq->irq;
110 + uv_write_global_mmr64(mmr_pnode, mq->mmr_offset, mmr_value);
112 + #error not a supported configuration
119 +xpc_release_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq)
121 +#if defined CONFIG_X86_64
122 + uv_teardown_irq(mq->irq, mq->mmr_blade, mq->mmr_offset);
124 +#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
126 + unsigned long mmr_value;
128 + mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
129 + mmr_value = 1UL << 16;
131 + uv_write_global_mmr64(mmr_pnode, mq->mmr_offset, mmr_value);
133 + #error not a supported configuration
138 +xpc_gru_mq_watchlist_alloc_uv(struct xpc_gru_mq_uv *mq)
142 +#if defined CONFIG_X86_64
143 + ret = uv_bios_mq_watchlist_alloc(mq->mmr_blade, mq->address, mq->order,
146 + dev_err(xpc_part, "uv_bios_mq_watchlist_alloc() failed, "
150 +#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
151 + ret = sn_mq_watchlist_alloc(mq->mmr_blade, mq->address, mq->order,
154 + dev_err(xpc_part, "sn_mq_watchlist_alloc() failed, ret=%d\n",
159 + #error not a supported configuration
162 + mq->watchlist_num = ret;
167 +xpc_gru_mq_watchlist_free_uv(struct xpc_gru_mq_uv *mq)
171 +#if defined CONFIG_X86_64
172 + ret = uv_bios_mq_watchlist_free(mq->mmr_blade, mq->watchlist_num);
173 + BUG_ON(ret != BIOS_STATUS_SUCCESS);
174 +#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
175 + ret = sn_mq_watchlist_free(mq->mmr_blade, mq->watchlist_num);
176 + BUG_ON(ret != SALRET_OK);
178 + #error not a supported configuration
182 +static struct xpc_gru_mq_uv *
183 +xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
184 irq_handler_t irq_handler)
186 + enum xp_retval xp_ret;
193 + struct xpc_gru_mq_uv *mq;
195 + mq = kmalloc(sizeof(struct xpc_gru_mq_uv), GFP_KERNEL);
197 + dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() "
198 + "a xpc_gru_mq_uv structure\n");
203 + pg_order = get_order(mq_size);
204 + mq->order = pg_order + PAGE_SHIFT;
205 + mq_size = 1UL << mq->order;
207 - nid = cpu_to_node(cpuid);
208 - mq_order = get_order(mq_size);
209 + mq->mmr_blade = uv_cpu_to_blade_id(cpu);
211 + nid = cpu_to_node(cpu);
212 page = alloc_pages_node(nid, GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
216 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
217 "bytes of memory on nid=%d for GRU mq\n", mq_size, nid);
222 + mq->address = page_address(page);
224 - mq = page_address(page);
225 - ret = gru_create_message_queue(mq, mq_size);
226 + ret = gru_create_message_queue(mq->address, mq_size);
228 dev_err(xpc_part, "gru_create_message_queue() returned "
230 - free_pages((unsigned long)mq, mq_order);
236 - /* !!! Need to do some other things to set up IRQ */
237 + /* enable generation of irq when GRU mq operation occurs to this mq */
238 + ret = xpc_gru_mq_watchlist_alloc_uv(mq);
242 + ret = xpc_get_gru_mq_irq_uv(mq, cpu, irq_name);
246 - ret = request_irq(irq, irq_handler, 0, "xpc", NULL);
247 + ret = request_irq(mq->irq, irq_handler, 0, irq_name, NULL);
249 dev_err(xpc_part, "request_irq(irq=%d) returned error=%d\n",
251 - free_pages((unsigned long)mq, mq_order);
257 - /* !!! enable generation of irq when GRU mq op occurs to this mq */
259 - /* ??? allow other partitions to access GRU mq? */
260 + /* allow other partitions to access this GRU mq */
261 + xp_ret = xp_expand_memprotect(xp_pa(mq->address), mq_size);
262 + if (xp_ret != xpSuccess) {
269 + /* something went wrong */
271 + free_irq(mq->irq, NULL);
273 + xpc_release_gru_mq_irq_uv(mq);
275 + xpc_gru_mq_watchlist_free_uv(mq);
277 + free_pages((unsigned long)mq->address, pg_order);
281 + return ERR_PTR(ret);
285 -xpc_destroy_gru_mq_uv(void *mq, unsigned int mq_size, unsigned int irq)
286 +xpc_destroy_gru_mq_uv(struct xpc_gru_mq_uv *mq)
288 - /* ??? disallow other partitions to access GRU mq? */
289 + unsigned int mq_size;
293 + /* disallow other partitions to access GRU mq */
294 + mq_size = 1UL << mq->order;
295 + ret = xp_restrict_memprotect(xp_pa(mq->address), mq_size);
296 + BUG_ON(ret != xpSuccess);
298 + /* unregister irq handler and release mq irq/vector mapping */
299 + free_irq(mq->irq, NULL);
300 + xpc_release_gru_mq_irq_uv(mq);
302 - /* !!! disable generation of irq when GRU mq op occurs to this mq */
303 + /* disable generation of irq when GRU mq op occurs to this mq */
304 + xpc_gru_mq_watchlist_free_uv(mq);
306 - free_irq(irq, NULL);
307 + pg_order = mq->order - PAGE_SHIFT;
308 + free_pages((unsigned long)mq->address, pg_order);
310 - free_pages((unsigned long)mq, get_order(mq_size));
314 static enum xp_retval
315 @@ -402,7 +559,10 @@ xpc_handle_activate_IRQ_uv(int irq, void
316 struct xpc_partition *part;
317 int wakeup_hb_checker = 0;
319 - while ((msg_hdr = gru_get_next_message(xpc_activate_mq_uv)) != NULL) {
321 + msg_hdr = gru_get_next_message(xpc_activate_mq_uv->address);
322 + if (msg_hdr == NULL)
325 partid = msg_hdr->partid;
326 if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
327 @@ -418,7 +578,7 @@ xpc_handle_activate_IRQ_uv(int irq, void
331 - gru_free_message(xpc_activate_mq_uv, msg_hdr);
332 + gru_free_message(xpc_activate_mq_uv->address, msg_hdr);
335 if (wakeup_hb_checker)
336 @@ -507,7 +667,7 @@ xpc_get_partition_rsvd_page_pa_uv(void *
338 xpc_setup_rsvd_page_sn_uv(struct xpc_rsvd_page *rp)
340 - rp->sn.activate_mq_gpa = uv_gpa(xpc_activate_mq_uv);
341 + rp->sn.activate_mq_gpa = uv_gpa(xpc_activate_mq_uv->address);
345 @@ -1410,22 +1570,18 @@ xpc_init_uv(void)
349 - /* ??? The cpuid argument's value is 0, is that what we want? */
350 - /* !!! The irq argument's value isn't correct. */
351 - xpc_activate_mq_uv = xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, 0, 0,
352 + xpc_activate_mq_uv = xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, 0,
353 + XPC_ACTIVATE_IRQ_NAME,
354 xpc_handle_activate_IRQ_uv);
355 - if (xpc_activate_mq_uv == NULL)
357 + if (IS_ERR(xpc_activate_mq_uv))
358 + return PTR_ERR(xpc_activate_mq_uv);
360 - /* ??? The cpuid argument's value is 0, is that what we want? */
361 - /* !!! The irq argument's value isn't correct. */
362 - xpc_notify_mq_uv = xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, 0, 0,
363 + xpc_notify_mq_uv = xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, 0,
364 + XPC_NOTIFY_IRQ_NAME,
365 xpc_handle_notify_IRQ_uv);
366 - if (xpc_notify_mq_uv == NULL) {
367 - /* !!! The irq argument's value isn't correct. */
368 - xpc_destroy_gru_mq_uv(xpc_activate_mq_uv,
369 - XPC_ACTIVATE_MQ_SIZE_UV, 0);
371 + if (IS_ERR(xpc_notify_mq_uv)) {
372 + xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
373 + return PTR_ERR(xpc_notify_mq_uv);
377 @@ -1434,9 +1590,6 @@ xpc_init_uv(void)
381 - /* !!! The irq argument's value isn't correct. */
382 - xpc_destroy_gru_mq_uv(xpc_notify_mq_uv, XPC_NOTIFY_MQ_SIZE_UV, 0);
384 - /* !!! The irq argument's value isn't correct. */
385 - xpc_destroy_gru_mq_uv(xpc_activate_mq_uv, XPC_ACTIVATE_MQ_SIZE_UV, 0);
386 + xpc_destroy_gru_mq_uv(xpc_notify_mq_uv);
387 + xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);