aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/sgi-xp
diff options
context:
space:
mode:
authorDean Nelson <dcn@sgi.com>2008-07-30 01:34:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-30 12:41:49 -0400
commit33ba3c7724be79f7cdbfc611335572c056d9a05a (patch)
treedb0371c031b0bbab13ccb2aeaf015424633cf2d8 /drivers/misc/sgi-xp
parente17d416b1bc947df68499863f13b401fb42b48f6 (diff)
sgi-xp: isolate xpc_vars structure to sn2 only
Isolate the xpc_vars structure of XPC's reserved page to sn2 only. Signed-off-by: Dean Nelson <dcn@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/misc/sgi-xp')
-rw-r--r--drivers/misc/sgi-xp/xpc.h529
-rw-r--r--drivers/misc/sgi-xp/xpc_channel.c315
-rw-r--r--drivers/misc/sgi-xp/xpc_main.c152
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c454
-rw-r--r--drivers/misc/sgi-xp/xpc_sn2.c1181
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c57
6 files changed, 1433 insertions, 1255 deletions
diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
index e8c2a162960..a3a67485cf8 100644
--- a/drivers/misc/sgi-xp/xpc.h
+++ b/drivers/misc/sgi-xp/xpc.h
@@ -159,10 +159,10 @@ xpc_compare_stamps(struct timespec *stamp1, struct timespec *stamp2)
159 * reflected by incrementing either the major or minor version numbers 159 * reflected by incrementing either the major or minor version numbers
160 * of struct xpc_vars. 160 * of struct xpc_vars.
161 */ 161 */
162struct xpc_vars { 162struct xpc_vars_sn2 {
163 u8 version; 163 u8 version;
164 u64 heartbeat; 164 u64 heartbeat;
165 u64 heartbeating_to_mask; 165 DECLARE_BITMAP(heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);
166 u64 heartbeat_offline; /* if 0, heartbeat should be changing */ 166 u64 heartbeat_offline; /* if 0, heartbeat should be changing */
167 int act_nasid; 167 int act_nasid;
168 int act_phys_cpuid; 168 int act_phys_cpuid;
@@ -176,46 +176,23 @@ struct xpc_vars {
176#define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \ 176#define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \
177 (_version >= _XPC_VERSION(3, 1)) 177 (_version >= _XPC_VERSION(3, 1))
178 178
179static inline int
180xpc_hb_allowed(short partid, struct xpc_vars *vars)
181{
182 return ((vars->heartbeating_to_mask & (1UL << partid)) != 0);
183}
184
185static inline void
186xpc_allow_hb(short partid, struct xpc_vars *vars)
187{
188 u64 old_mask, new_mask;
189
190 do {
191 old_mask = vars->heartbeating_to_mask;
192 new_mask = (old_mask | (1UL << partid));
193 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
194 old_mask);
195}
196
197static inline void
198xpc_disallow_hb(short partid, struct xpc_vars *vars)
199{
200 u64 old_mask, new_mask;
201
202 do {
203 old_mask = vars->heartbeating_to_mask;
204 new_mask = (old_mask & ~(1UL << partid));
205 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
206 old_mask);
207}
208
209/* 179/*
210 * The AMOs page consists of a number of AMO variables which are divided into 180 * The following pertains to ia64-sn2 only.
211 * four groups, The first two groups are used to identify an IRQ's sender. 181 *
212 * These two groups consist of 64 and 128 AMO variables respectively. The last 182 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
213 * two groups, consisting of just one AMO variable each, are used to identify 183 * pages are located in the lowest granule. The lowest granule uses 4k pages
214 * the remote partitions that are currently engaged (from the viewpoint of 184 * for cached references and an alternate TLB handler to never provide a
215 * the XPC running on the remote partition). 185 * cacheable mapping for the entire region. This will prevent speculative
186 * reading of cached copies of our lines from being issued which will cause
187 * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
188 * AMO variables (based on XP_MAX_NPARTITIONS_SN2) to identify the senders of
189 * NOTIFY IRQs, 128 AMO variables (based on XP_NASID_MASK_WORDS) to identify
190 * the senders of ACTIVATE IRQs, and 2 AMO variables to identify which remote
191 * partitions (i.e., XPCs) consider themselves currently engaged with the
192 * local XPC.
216 */ 193 */
217#define XPC_NOTIFY_IRQ_AMOS 0 194#define XPC_NOTIFY_IRQ_AMOS 0
218#define XPC_ACTIVATE_IRQ_AMOS (XPC_NOTIFY_IRQ_AMOS + XP_MAX_NPARTITIONS_SN2) 195#define XPC_ACTIVATE_IRQ_AMOS (XPC_NOTIFY_IRQ_AMOS + XP_MAX_NPARTITIONS_SN2)
219#define XPC_ENGAGED_PARTITIONS_AMO (XPC_ACTIVATE_IRQ_AMOS + XP_NASID_MASK_WORDS) 196#define XPC_ENGAGED_PARTITIONS_AMO (XPC_ACTIVATE_IRQ_AMOS + XP_NASID_MASK_WORDS)
220#define XPC_DISENGAGE_REQUEST_AMO (XPC_ENGAGED_PARTITIONS_AMO + 1) 197#define XPC_DISENGAGE_REQUEST_AMO (XPC_ENGAGED_PARTITIONS_AMO + 1)
221 198
@@ -259,11 +236,11 @@ struct xpc_vars_part_sn2 {
259/* the reserved page sizes and offsets */ 236/* the reserved page sizes and offsets */
260 237
261#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)) 238#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
262#define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars)) 239#define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars_sn2))
263 240
264#define XPC_RP_PART_NASIDS(_rp) ((u64 *)((u8 *)(_rp) + XPC_RP_HEADER_SIZE)) 241#define XPC_RP_PART_NASIDS(_rp) ((u64 *)((u8 *)(_rp) + XPC_RP_HEADER_SIZE))
265#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + xp_nasid_mask_words) 242#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + xp_nasid_mask_words)
266#define XPC_RP_VARS(_rp) ((struct xpc_vars *)(XPC_RP_MACH_NASIDS(_rp) + \ 243#define XPC_RP_VARS(_rp) ((struct xpc_vars_sn2 *)(XPC_RP_MACH_NASIDS(_rp) + \
267 xp_nasid_mask_words)) 244 xp_nasid_mask_words))
268 245
269/* 246/*
@@ -344,6 +321,7 @@ struct xpc_notify {
344 * allocated at the time a partition becomes active. The array contains one 321 * allocated at the time a partition becomes active. The array contains one
345 * of these structures for each potential channel connection to that partition. 322 * of these structures for each potential channel connection to that partition.
346 * 323 *
324>>> sn2 only!!!
347 * Each of these structures manages two message queues (circular buffers). 325 * Each of these structures manages two message queues (circular buffers).
348 * They are allocated at the time a channel connection is made. One of 326 * They are allocated at the time a channel connection is made. One of
349 * these message queues (local_msgqueue) holds the locally created messages 327 * these message queues (local_msgqueue) holds the locally created messages
@@ -622,6 +600,9 @@ extern struct device *xpc_part;
622extern struct device *xpc_chan; 600extern struct device *xpc_chan;
623extern int xpc_disengage_request_timelimit; 601extern int xpc_disengage_request_timelimit;
624extern int xpc_disengage_request_timedout; 602extern int xpc_disengage_request_timedout;
603extern atomic_t xpc_act_IRQ_rcvd;
604extern wait_queue_head_t xpc_act_IRQ_wq;
605extern void *xpc_heartbeating_to_mask;
625extern irqreturn_t xpc_notify_IRQ_handler(int, void *); 606extern irqreturn_t xpc_notify_IRQ_handler(int, void *);
626extern void xpc_dropped_IPI_check(struct xpc_partition *); 607extern void xpc_dropped_IPI_check(struct xpc_partition *);
627extern void xpc_activate_partition(struct xpc_partition *); 608extern void xpc_activate_partition(struct xpc_partition *);
@@ -629,15 +610,48 @@ extern void xpc_activate_kthreads(struct xpc_channel *, int);
629extern void xpc_create_kthreads(struct xpc_channel *, int, int); 610extern void xpc_create_kthreads(struct xpc_channel *, int, int);
630extern void xpc_disconnect_wait(int); 611extern void xpc_disconnect_wait(int);
631extern enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *); 612extern enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *);
613extern void (*xpc_heartbeat_init) (void);
614extern void (*xpc_heartbeat_exit) (void);
615extern void (*xpc_increment_heartbeat) (void);
616extern void (*xpc_offline_heartbeat) (void);
617extern void (*xpc_online_heartbeat) (void);
618extern void (*xpc_check_remote_hb) (void);
632extern enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *); 619extern enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *);
633extern u64 (*xpc_get_IPI_flags) (struct xpc_partition *); 620extern u64 (*xpc_get_IPI_flags) (struct xpc_partition *);
634extern struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *); 621extern struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *);
622extern void (*xpc_initiate_partition_activation) (struct xpc_rsvd_page *, u64,
623 int);
624extern void (*xpc_process_act_IRQ_rcvd) (int);
635extern enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *); 625extern enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *);
636extern void (*xpc_teardown_infrastructure) (struct xpc_partition *); 626extern void (*xpc_teardown_infrastructure) (struct xpc_partition *);
627extern void (*xpc_mark_partition_engaged) (struct xpc_partition *);
628extern void (*xpc_mark_partition_disengaged) (struct xpc_partition *);
629extern void (*xpc_request_partition_disengage) (struct xpc_partition *);
630extern void (*xpc_cancel_partition_disengage_request) (struct xpc_partition *);
631extern u64 (*xpc_partition_engaged) (u64);
632extern u64 (*xpc_partition_disengage_requested) (u64);;
633extern void (*xpc_clear_partition_engaged) (u64);
634extern void (*xpc_clear_partition_disengage_request) (u64);
635
636extern void (*xpc_IPI_send_local_activate) (int);
637extern void (*xpc_IPI_send_activated) (struct xpc_partition *);
638extern void (*xpc_IPI_send_local_reactivate) (int);
639extern void (*xpc_IPI_send_disengage) (struct xpc_partition *);
640
641extern void (*xpc_IPI_send_closerequest) (struct xpc_channel *,
642 unsigned long *);
643extern void (*xpc_IPI_send_closereply) (struct xpc_channel *, unsigned long *);
644extern void (*xpc_IPI_send_openrequest) (struct xpc_channel *, unsigned long *);
645extern void (*xpc_IPI_send_openreply) (struct xpc_channel *, unsigned long *);
646
647extern enum xp_retval (*xpc_allocate_msg) (struct xpc_channel *, u32,
648 struct xpc_msg **);
649extern enum xp_retval (*xpc_send_msg) (struct xpc_channel *, struct xpc_msg *,
650 u8, xpc_notify_func, void *);
651extern void (*xpc_received_msg) (struct xpc_channel *, struct xpc_msg *);
637 652
638/* found in xpc_sn2.c */ 653/* found in xpc_sn2.c */
639extern void xpc_init_sn2(void); 654extern void xpc_init_sn2(void);
640extern struct xpc_vars *xpc_vars; /*>>> eliminate from here */
641 655
642/* found in xpc_uv.c */ 656/* found in xpc_uv.c */
643extern void xpc_init_uv(void); 657extern void xpc_init_uv(void);
@@ -646,6 +660,7 @@ extern void xpc_init_uv(void);
646extern int xpc_exiting; 660extern int xpc_exiting;
647extern int xp_nasid_mask_words; 661extern int xp_nasid_mask_words;
648extern struct xpc_rsvd_page *xpc_rsvd_page; 662extern struct xpc_rsvd_page *xpc_rsvd_page;
663extern u64 *xpc_mach_nasids;
649extern struct xpc_partition *xpc_partitions; 664extern struct xpc_partition *xpc_partitions;
650extern char *xpc_remote_copy_buffer; 665extern char *xpc_remote_copy_buffer;
651extern void *xpc_remote_copy_buffer_base; 666extern void *xpc_remote_copy_buffer_base;
@@ -658,7 +673,8 @@ extern int xpc_partition_disengaged(struct xpc_partition *);
658extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *); 673extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
659extern void xpc_mark_partition_inactive(struct xpc_partition *); 674extern void xpc_mark_partition_inactive(struct xpc_partition *);
660extern void xpc_discovery(void); 675extern void xpc_discovery(void);
661extern void xpc_check_remote_hb(void); 676extern enum xp_retval xpc_get_remote_rp(int, u64 *, struct xpc_rsvd_page *,
677 u64 *);
662extern void xpc_deactivate_partition(const int, struct xpc_partition *, 678extern void xpc_deactivate_partition(const int, struct xpc_partition *,
663 enum xp_retval); 679 enum xp_retval);
664extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *); 680extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
@@ -667,6 +683,7 @@ extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
667extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **); 683extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
668extern void xpc_initiate_connect(int); 684extern void xpc_initiate_connect(int);
669extern void xpc_initiate_disconnect(int); 685extern void xpc_initiate_disconnect(int);
686extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
670extern enum xp_retval xpc_initiate_allocate(short, int, u32, void **); 687extern enum xp_retval xpc_initiate_allocate(short, int, u32, void **);
671extern enum xp_retval xpc_initiate_send(short, int, void *); 688extern enum xp_retval xpc_initiate_send(short, int, void *);
672extern enum xp_retval xpc_initiate_send_notify(short, int, void *, 689extern enum xp_retval xpc_initiate_send_notify(short, int, void *,
@@ -680,6 +697,40 @@ extern void xpc_disconnect_channel(const int, struct xpc_channel *,
680extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval); 697extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
681extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval); 698extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
682 699
700static inline int
701xpc_hb_allowed(short partid, void *heartbeating_to_mask)
702{
703 return test_bit(partid, heartbeating_to_mask);
704}
705
706static inline int
707xpc_any_hbs_allowed(void)
708{
709 DBUG_ON(xpc_heartbeating_to_mask == NULL);
710 return !bitmap_empty(xpc_heartbeating_to_mask, xp_max_npartitions);
711}
712
713static inline void
714xpc_allow_hb(short partid)
715{
716 DBUG_ON(xpc_heartbeating_to_mask == NULL);
717 set_bit(partid, xpc_heartbeating_to_mask);
718}
719
720static inline void
721xpc_disallow_hb(short partid)
722{
723 DBUG_ON(xpc_heartbeating_to_mask == NULL);
724 clear_bit(partid, xpc_heartbeating_to_mask);
725}
726
727static inline void
728xpc_disallow_all_hbs(void)
729{
730 DBUG_ON(xpc_heartbeating_to_mask == NULL);
731 bitmap_zero(xpc_heartbeating_to_mask, xp_max_npartitions);
732}
733
683static inline void 734static inline void
684xpc_wakeup_channel_mgr(struct xpc_partition *part) 735xpc_wakeup_channel_mgr(struct xpc_partition *part)
685{ 736{
@@ -749,297 +800,7 @@ xpc_part_ref(struct xpc_partition *part)
749 } 800 }
750 801
751/* 802/*
752 * This next set of inlines are used to keep track of when a partition is 803 * The sending and receiving of IPIs includes the setting of an >>>AMO variable
753 * potentially engaged in accessing memory belonging to another partition.
754 */
755
756static inline void
757xpc_mark_partition_engaged(struct xpc_partition *part)
758{
759 unsigned long irq_flags;
760 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
761 (XPC_ENGAGED_PARTITIONS_AMO *
762 sizeof(AMO_t)));
763
764 local_irq_save(irq_flags);
765
766 /* set bit corresponding to our partid in remote partition's AMO */
767 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
768 (1UL << sn_partition_id));
769 /*
770 * We must always use the nofault function regardless of whether we
771 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
772 * didn't, we'd never know that the other partition is down and would
773 * keep sending IPIs and AMOs to it until the heartbeat times out.
774 */
775 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
776 variable),
777 xp_nofault_PIOR_target));
778
779 local_irq_restore(irq_flags);
780}
781
782static inline void
783xpc_mark_partition_disengaged(struct xpc_partition *part)
784{
785 unsigned long irq_flags;
786 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
787 (XPC_ENGAGED_PARTITIONS_AMO *
788 sizeof(AMO_t)));
789
790 local_irq_save(irq_flags);
791
792 /* clear bit corresponding to our partid in remote partition's AMO */
793 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
794 ~(1UL << sn_partition_id));
795 /*
796 * We must always use the nofault function regardless of whether we
797 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
798 * didn't, we'd never know that the other partition is down and would
799 * keep sending IPIs and AMOs to it until the heartbeat times out.
800 */
801 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
802 variable),
803 xp_nofault_PIOR_target));
804
805 local_irq_restore(irq_flags);
806}
807
808static inline void
809xpc_request_partition_disengage(struct xpc_partition *part)
810{
811 unsigned long irq_flags;
812 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
813 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
814
815 local_irq_save(irq_flags);
816
817 /* set bit corresponding to our partid in remote partition's AMO */
818 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
819 (1UL << sn_partition_id));
820 /*
821 * We must always use the nofault function regardless of whether we
822 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
823 * didn't, we'd never know that the other partition is down and would
824 * keep sending IPIs and AMOs to it until the heartbeat times out.
825 */
826 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
827 variable),
828 xp_nofault_PIOR_target));
829
830 local_irq_restore(irq_flags);
831}
832
833static inline void
834xpc_cancel_partition_disengage_request(struct xpc_partition *part)
835{
836 unsigned long irq_flags;
837 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
838 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
839
840 local_irq_save(irq_flags);
841
842 /* clear bit corresponding to our partid in remote partition's AMO */
843 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
844 ~(1UL << sn_partition_id));
845 /*
846 * We must always use the nofault function regardless of whether we
847 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
848 * didn't, we'd never know that the other partition is down and would
849 * keep sending IPIs and AMOs to it until the heartbeat times out.
850 */
851 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
852 variable),
853 xp_nofault_PIOR_target));
854
855 local_irq_restore(irq_flags);
856}
857
858static inline u64
859xpc_partition_engaged(u64 partid_mask)
860{
861 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
862
863 /* return our partition's AMO variable ANDed with partid_mask */
864 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
865 partid_mask);
866}
867
868static inline u64
869xpc_partition_disengage_requested(u64 partid_mask)
870{
871 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
872
873 /* return our partition's AMO variable ANDed with partid_mask */
874 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
875 partid_mask);
876}
877
878static inline void
879xpc_clear_partition_engaged(u64 partid_mask)
880{
881 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
882
883 /* clear bit(s) based on partid_mask in our partition's AMO */
884 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
885 ~partid_mask);
886}
887
888static inline void
889xpc_clear_partition_disengage_request(u64 partid_mask)
890{
891 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
892
893 /* clear bit(s) based on partid_mask in our partition's AMO */
894 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
895 ~partid_mask);
896}
897
898/*
899 * The following set of macros and inlines are used for the sending and
900 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
901 * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
902 * the other that is associated with channel activity (SGI_XPC_NOTIFY).
903 */
904
905static inline u64
906xpc_IPI_receive(AMO_t *amo)
907{
908 return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_CLEAR);
909}
910
911static inline enum xp_retval
912xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
913{
914 int ret = 0;
915 unsigned long irq_flags;
916
917 local_irq_save(irq_flags);
918
919 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, flag);
920 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
921
922 /*
923 * We must always use the nofault function regardless of whether we
924 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
925 * didn't, we'd never know that the other partition is down and would
926 * keep sending IPIs and AMOs to it until the heartbeat times out.
927 */
928 ret = xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
929 xp_nofault_PIOR_target));
930
931 local_irq_restore(irq_flags);
932
933 return ((ret == 0) ? xpSuccess : xpPioReadError);
934}
935
936/*
937 * IPIs associated with SGI_XPC_ACTIVATE IRQ.
938 */
939
940/*
941 * Flag the appropriate AMO variable and send an IPI to the specified node.
942 */
943static inline void
944xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid,
945 int to_phys_cpuid)
946{
947 int w_index = XPC_NASID_W_INDEX(from_nasid);
948 int b_index = XPC_NASID_B_INDEX(from_nasid);
949 AMO_t *amos = (AMO_t *)__va(amos_page_pa +
950 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
951
952 (void)xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
953 to_phys_cpuid, SGI_XPC_ACTIVATE);
954}
955
956static inline void
957xpc_IPI_send_activate(struct xpc_vars *vars)
958{
959 xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
960 vars->act_nasid, vars->act_phys_cpuid);
961}
962
963static inline void
964xpc_IPI_send_activated(struct xpc_partition *part)
965{
966 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
967 part->remote_act_nasid,
968 part->remote_act_phys_cpuid);
969}
970
971static inline void
972xpc_IPI_send_reactivate(struct xpc_partition *part)
973{
974 xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
975 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
976}
977
978static inline void
979xpc_IPI_send_disengage(struct xpc_partition *part)
980{
981 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
982 part->remote_act_nasid,
983 part->remote_act_phys_cpuid);
984}
985
986/*
987 * IPIs associated with SGI_XPC_NOTIFY IRQ.
988 */
989
990/*
991 * Send an IPI to the remote partition that is associated with the
992 * specified channel.
993 */
994#define XPC_NOTIFY_IRQ_SEND(_ch, _ipi_f, _irq_f) \
995 xpc_notify_IRQ_send(_ch, _ipi_f, #_ipi_f, _irq_f)
996
997static inline void
998xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
999 unsigned long *irq_flags)
1000{
1001 struct xpc_partition *part = &xpc_partitions[ch->partid];
1002 enum xp_retval ret;
1003
1004 if (likely(part->act_state != XPC_P_DEACTIVATING)) {
1005 ret = xpc_IPI_send(part->remote_IPI_amo_va,
1006 (u64)ipi_flag << (ch->number * 8),
1007 part->remote_IPI_nasid,
1008 part->remote_IPI_phys_cpuid, SGI_XPC_NOTIFY);
1009 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
1010 ipi_flag_string, ch->partid, ch->number, ret);
1011 if (unlikely(ret != xpSuccess)) {
1012 if (irq_flags != NULL)
1013 spin_unlock_irqrestore(&ch->lock, *irq_flags);
1014 XPC_DEACTIVATE_PARTITION(part, ret);
1015 if (irq_flags != NULL)
1016 spin_lock_irqsave(&ch->lock, *irq_flags);
1017 }
1018 }
1019}
1020
1021/*
1022 * Make it look like the remote partition, which is associated with the
1023 * specified channel, sent us an IPI. This faked IPI will be handled
1024 * by xpc_dropped_IPI_check().
1025 */
1026#define XPC_NOTIFY_IRQ_SEND_LOCAL(_ch, _ipi_f) \
1027 xpc_notify_IRQ_send_local(_ch, _ipi_f, #_ipi_f)
1028
1029static inline void
1030xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1031 char *ipi_flag_string)
1032{
1033 struct xpc_partition *part = &xpc_partitions[ch->partid];
1034
1035 FETCHOP_STORE_OP(TO_AMO((u64)&part->local_IPI_amo_va->variable),
1036 FETCHOP_OR, ((u64)ipi_flag << (ch->number * 8)));
1037 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
1038 ipi_flag_string, ch->partid, ch->number);
1039}
1040
1041/*
1042 * The sending and receiving of IPIs includes the setting of an AMO variable
1043 * to indicate the reason the IPI was sent. The 64-bit variable is divided 804 * to indicate the reason the IPI was sent. The 64-bit variable is divided
1044 * up into eight bytes, ordered from right to left. Byte zero pertains to 805 * up into eight bytes, ordered from right to left. Byte zero pertains to
1045 * channel 0, byte one to channel 1, and so on. Each byte is described by 806 * channel 0, byte one to channel 1, and so on. Each byte is described by
@@ -1052,107 +813,11 @@ xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1052#define XPC_IPI_OPENREPLY 0x08 813#define XPC_IPI_OPENREPLY 0x08
1053#define XPC_IPI_MSGREQUEST 0x10 814#define XPC_IPI_MSGREQUEST 0x10
1054 815
1055/* given an AMO variable and a channel#, get its associated IPI flags */ 816/* given an >>>AMO variable and a channel#, get its associated IPI flags */
1056#define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff)) 817#define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
1057#define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8)) 818#define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8))
1058 819
1059#define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0fUL) 820#define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0fUL)
1060#define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010UL) 821#define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010UL)
1061 822
1062static inline void
1063xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
1064{
1065 struct xpc_openclose_args *args = ch->local_openclose_args;
1066
1067 args->reason = ch->reason;
1068
1069 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
1070}
1071
1072static inline void
1073xpc_IPI_send_closereply(struct xpc_channel *ch, unsigned long *irq_flags)
1074{
1075 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREPLY, irq_flags);
1076}
1077
1078static inline void
1079xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
1080{
1081 struct xpc_openclose_args *args = ch->local_openclose_args;
1082
1083 args->msg_size = ch->msg_size;
1084 args->local_nentries = ch->local_nentries;
1085
1086 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREQUEST, irq_flags);
1087}
1088
1089static inline void
1090xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
1091{
1092 struct xpc_openclose_args *args = ch->local_openclose_args;
1093
1094 args->remote_nentries = ch->remote_nentries;
1095 args->local_nentries = ch->local_nentries;
1096 args->local_msgqueue_pa = __pa(ch->local_msgqueue);
1097
1098 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREPLY, irq_flags);
1099}
1100
1101static inline void
1102xpc_IPI_send_msgrequest(struct xpc_channel *ch)
1103{
1104 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_MSGREQUEST, NULL);
1105}
1106
1107static inline void
1108xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
1109{
1110 XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
1111}
1112
1113/*
1114>>> this block comment needs to be moved and re-written.
1115 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
1116 * pages are located in the lowest granule. The lowest granule uses 4k pages
1117 * for cached references and an alternate TLB handler to never provide a
1118 * cacheable mapping for the entire region. This will prevent speculative
1119 * reading of cached copies of our lines from being issued which will cause
1120 * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
1121 * AMO variables (based on xp_max_npartitions) for message notification and an
1122 * additional 128 AMO variables (based on XP_NASID_MASK_WORDS) for partition
1123 * activation and 2 AMO variables for partition deactivation.
1124 */
1125static inline AMO_t *
1126xpc_IPI_init(int index)
1127{
1128 AMO_t *amo = xpc_vars->amos_page + index;
1129
1130 (void)xpc_IPI_receive(amo); /* clear AMO variable */
1131 return amo;
1132}
1133
1134/*
1135 * Check to see if there is any channel activity to/from the specified
1136 * partition.
1137 */
1138static inline void
1139xpc_check_for_channel_activity(struct xpc_partition *part)
1140{
1141 u64 IPI_amo;
1142 unsigned long irq_flags;
1143
1144 IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
1145 if (IPI_amo == 0)
1146 return;
1147
1148 spin_lock_irqsave(&part->IPI_lock, irq_flags);
1149 part->local_IPI_amo |= IPI_amo;
1150 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
1151
1152 dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
1153 XPC_PARTID(part), IPI_amo);
1154
1155 xpc_wakeup_channel_mgr(part);
1156}
1157
1158#endif /* _DRIVERS_MISC_SGIXP_XPC_H */ 823#endif /* _DRIVERS_MISC_SGIXP_XPC_H */
diff --git a/drivers/misc/sgi-xp/xpc_channel.c b/drivers/misc/sgi-xp/xpc_channel.c
index 8081e8155df..26c5e12c122 100644
--- a/drivers/misc/sgi-xp/xpc_channel.c
+++ b/drivers/misc/sgi-xp/xpc_channel.c
@@ -1165,7 +1165,7 @@ xpc_disconnect_callout(struct xpc_channel *ch, enum xp_retval reason)
1165 * Wait for a message entry to become available for the specified channel, 1165 * Wait for a message entry to become available for the specified channel,
1166 * but don't wait any longer than 1 jiffy. 1166 * but don't wait any longer than 1 jiffy.
1167 */ 1167 */
1168static enum xp_retval 1168enum xp_retval
1169xpc_allocate_msg_wait(struct xpc_channel *ch) 1169xpc_allocate_msg_wait(struct xpc_channel *ch)
1170{ 1170{
1171 enum xp_retval ret; 1171 enum xp_retval ret;
@@ -1193,96 +1193,6 @@ xpc_allocate_msg_wait(struct xpc_channel *ch)
1193 1193
1194/* 1194/*
1195 * Allocate an entry for a message from the message queue associated with the 1195 * Allocate an entry for a message from the message queue associated with the
1196 * specified channel.
1197 */
1198static enum xp_retval
1199xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1200 struct xpc_msg **address_of_msg)
1201{
1202 struct xpc_msg *msg;
1203 enum xp_retval ret;
1204 s64 put;
1205
1206 /* this reference will be dropped in xpc_send_msg() */
1207 xpc_msgqueue_ref(ch);
1208
1209 if (ch->flags & XPC_C_DISCONNECTING) {
1210 xpc_msgqueue_deref(ch);
1211 return ch->reason;
1212 }
1213 if (!(ch->flags & XPC_C_CONNECTED)) {
1214 xpc_msgqueue_deref(ch);
1215 return xpNotConnected;
1216 }
1217
1218 /*
1219 * Get the next available message entry from the local message queue.
1220 * If none are available, we'll make sure that we grab the latest
1221 * GP values.
1222 */
1223 ret = xpTimeout;
1224
1225 while (1) {
1226
1227 put = ch->w_local_GP.put;
1228 rmb(); /* guarantee that .put loads before .get */
1229 if (put - ch->w_remote_GP.get < ch->local_nentries) {
1230
1231 /* There are available message entries. We need to try
1232 * to secure one for ourselves. We'll do this by trying
1233 * to increment w_local_GP.put as long as someone else
1234 * doesn't beat us to it. If they do, we'll have to
1235 * try again.
1236 */
1237 if (cmpxchg(&ch->w_local_GP.put, put, put + 1) == put) {
1238 /* we got the entry referenced by put */
1239 break;
1240 }
1241 continue; /* try again */
1242 }
1243
1244 /*
1245 * There aren't any available msg entries at this time.
1246 *
1247 * In waiting for a message entry to become available,
1248 * we set a timeout in case the other side is not
1249 * sending completion IPIs. This lets us fake an IPI
1250 * that will cause the IPI handler to fetch the latest
1251 * GP values as if an IPI was sent by the other side.
1252 */
1253 if (ret == xpTimeout)
1254 xpc_IPI_send_local_msgrequest(ch);
1255
1256 if (flags & XPC_NOWAIT) {
1257 xpc_msgqueue_deref(ch);
1258 return xpNoWait;
1259 }
1260
1261 ret = xpc_allocate_msg_wait(ch);
1262 if (ret != xpInterrupted && ret != xpTimeout) {
1263 xpc_msgqueue_deref(ch);
1264 return ret;
1265 }
1266 }
1267
1268 /* get the message's address and initialize it */
1269 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1270 (put % ch->local_nentries) * ch->msg_size);
1271
1272 DBUG_ON(msg->flags != 0);
1273 msg->number = put;
1274
1275 dev_dbg(xpc_chan, "w_local_GP.put changed to %ld; msg=0x%p, "
1276 "msg_number=%ld, partid=%d, channel=%d\n", put + 1,
1277 (void *)msg, msg->number, ch->partid, ch->number);
1278
1279 *address_of_msg = msg;
1280
1281 return xpSuccess;
1282}
1283
1284/*
1285 * Allocate an entry for a message from the message queue associated with the
1286 * specified channel. NOTE that this routine can sleep waiting for a message 1196 * specified channel. NOTE that this routine can sleep waiting for a message
1287 * entry to become available. To not sleep, pass in the XPC_NOWAIT flag. 1197 * entry to become available. To not sleep, pass in the XPC_NOWAIT flag.
1288 * 1198 *
@@ -1318,144 +1228,6 @@ xpc_initiate_allocate(short partid, int ch_number, u32 flags, void **payload)
1318} 1228}
1319 1229
1320/* 1230/*
1321 * Now we actually send the messages that are ready to be sent by advancing
1322 * the local message queue's Put value and then send an IPI to the recipient
1323 * partition.
1324 */
1325static void
1326xpc_send_msgs(struct xpc_channel *ch, s64 initial_put)
1327{
1328 struct xpc_msg *msg;
1329 s64 put = initial_put + 1;
1330 int send_IPI = 0;
1331
1332 while (1) {
1333
1334 while (1) {
1335 if (put == ch->w_local_GP.put)
1336 break;
1337
1338 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1339 (put % ch->local_nentries) *
1340 ch->msg_size);
1341
1342 if (!(msg->flags & XPC_M_READY))
1343 break;
1344
1345 put++;
1346 }
1347
1348 if (put == initial_put) {
1349 /* nothing's changed */
1350 break;
1351 }
1352
1353 if (cmpxchg_rel(&ch->local_GP->put, initial_put, put) !=
1354 initial_put) {
1355 /* someone else beat us to it */
1356 DBUG_ON(ch->local_GP->put < initial_put);
1357 break;
1358 }
1359
1360 /* we just set the new value of local_GP->put */
1361
1362 dev_dbg(xpc_chan, "local_GP->put changed to %ld, partid=%d, "
1363 "channel=%d\n", put, ch->partid, ch->number);
1364
1365 send_IPI = 1;
1366
1367 /*
1368 * We need to ensure that the message referenced by
1369 * local_GP->put is not XPC_M_READY or that local_GP->put
1370 * equals w_local_GP.put, so we'll go have a look.
1371 */
1372 initial_put = put;
1373 }
1374
1375 if (send_IPI)
1376 xpc_IPI_send_msgrequest(ch);
1377}
1378
1379/*
1380 * Common code that does the actual sending of the message by advancing the
1381 * local message queue's Put value and sends an IPI to the partition the
1382 * message is being sent to.
1383 */
1384static enum xp_retval
1385xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1386 xpc_notify_func func, void *key)
1387{
1388 enum xp_retval ret = xpSuccess;
1389 struct xpc_notify *notify = notify;
1390 s64 put, msg_number = msg->number;
1391
1392 DBUG_ON(notify_type == XPC_N_CALL && func == NULL);
1393 DBUG_ON((((u64)msg - (u64)ch->local_msgqueue) / ch->msg_size) !=
1394 msg_number % ch->local_nentries);
1395 DBUG_ON(msg->flags & XPC_M_READY);
1396
1397 if (ch->flags & XPC_C_DISCONNECTING) {
1398 /* drop the reference grabbed in xpc_allocate_msg() */
1399 xpc_msgqueue_deref(ch);
1400 return ch->reason;
1401 }
1402
1403 if (notify_type != 0) {
1404 /*
1405 * Tell the remote side to send an ACK interrupt when the
1406 * message has been delivered.
1407 */
1408 msg->flags |= XPC_M_INTERRUPT;
1409
1410 atomic_inc(&ch->n_to_notify);
1411
1412 notify = &ch->notify_queue[msg_number % ch->local_nentries];
1413 notify->func = func;
1414 notify->key = key;
1415 notify->type = notify_type;
1416
1417 /* >>> is a mb() needed here? */
1418
1419 if (ch->flags & XPC_C_DISCONNECTING) {
1420 /*
1421 * An error occurred between our last error check and
1422 * this one. We will try to clear the type field from
1423 * the notify entry. If we succeed then
1424 * xpc_disconnect_channel() didn't already process
1425 * the notify entry.
1426 */
1427 if (cmpxchg(&notify->type, notify_type, 0) ==
1428 notify_type) {
1429 atomic_dec(&ch->n_to_notify);
1430 ret = ch->reason;
1431 }
1432
1433 /* drop the reference grabbed in xpc_allocate_msg() */
1434 xpc_msgqueue_deref(ch);
1435 return ret;
1436 }
1437 }
1438
1439 msg->flags |= XPC_M_READY;
1440
1441 /*
1442 * The preceding store of msg->flags must occur before the following
1443 * load of ch->local_GP->put.
1444 */
1445 mb();
1446
1447 /* see if the message is next in line to be sent, if so send it */
1448
1449 put = ch->local_GP->put;
1450 if (put == msg_number)
1451 xpc_send_msgs(ch, put);
1452
1453 /* drop the reference grabbed in xpc_allocate_msg() */
1454 xpc_msgqueue_deref(ch);
1455 return ret;
1456}
1457
1458/*
1459 * Send a message previously allocated using xpc_initiate_allocate() on the 1231 * Send a message previously allocated using xpc_initiate_allocate() on the
1460 * specified channel connected to the specified partition. 1232 * specified channel connected to the specified partition.
1461 * 1233 *
@@ -1586,66 +1358,6 @@ xpc_deliver_msg(struct xpc_channel *ch)
1586} 1358}
1587 1359
1588/* 1360/*
1589 * Now we actually acknowledge the messages that have been delivered and ack'd
1590 * by advancing the cached remote message queue's Get value and if requested
1591 * send an IPI to the message sender's partition.
1592 */
1593static void
1594xpc_acknowledge_msgs(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
1595{
1596 struct xpc_msg *msg;
1597 s64 get = initial_get + 1;
1598 int send_IPI = 0;
1599
1600 while (1) {
1601
1602 while (1) {
1603 if (get == ch->w_local_GP.get)
1604 break;
1605
1606 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue +
1607 (get % ch->remote_nentries) *
1608 ch->msg_size);
1609
1610 if (!(msg->flags & XPC_M_DONE))
1611 break;
1612
1613 msg_flags |= msg->flags;
1614 get++;
1615 }
1616
1617 if (get == initial_get) {
1618 /* nothing's changed */
1619 break;
1620 }
1621
1622 if (cmpxchg_rel(&ch->local_GP->get, initial_get, get) !=
1623 initial_get) {
1624 /* someone else beat us to it */
1625 DBUG_ON(ch->local_GP->get <= initial_get);
1626 break;
1627 }
1628
1629 /* we just set the new value of local_GP->get */
1630
1631 dev_dbg(xpc_chan, "local_GP->get changed to %ld, partid=%d, "
1632 "channel=%d\n", get, ch->partid, ch->number);
1633
1634 send_IPI = (msg_flags & XPC_M_INTERRUPT);
1635
1636 /*
1637 * We need to ensure that the message referenced by
1638 * local_GP->get is not XPC_M_DONE or that local_GP->get
1639 * equals w_local_GP.get, so we'll go have a look.
1640 */
1641 initial_get = get;
1642 }
1643
1644 if (send_IPI)
1645 xpc_IPI_send_msgrequest(ch);
1646}
1647
1648/*
1649 * Acknowledge receipt of a delivered message. 1361 * Acknowledge receipt of a delivered message.
1650 * 1362 *
1651 * If a message has XPC_M_INTERRUPT set, send an interrupt to the partition 1363 * If a message has XPC_M_INTERRUPT set, send an interrupt to the partition
@@ -1668,35 +1380,12 @@ xpc_initiate_received(short partid, int ch_number, void *payload)
1668 struct xpc_partition *part = &xpc_partitions[partid]; 1380 struct xpc_partition *part = &xpc_partitions[partid];
1669 struct xpc_channel *ch; 1381 struct xpc_channel *ch;
1670 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload); 1382 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload);
1671 s64 get, msg_number = msg->number;
1672 1383
1673 DBUG_ON(partid < 0 || partid >= xp_max_npartitions); 1384 DBUG_ON(partid < 0 || partid >= xp_max_npartitions);
1674 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels); 1385 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
1675 1386
1676 ch = &part->channels[ch_number]; 1387 ch = &part->channels[ch_number];
1677 1388 xpc_received_msg(ch, msg);
1678 dev_dbg(xpc_chan, "msg=0x%p, msg_number=%ld, partid=%d, channel=%d\n",
1679 (void *)msg, msg_number, ch->partid, ch->number);
1680
1681 DBUG_ON((((u64)msg - (u64)ch->remote_msgqueue) / ch->msg_size) !=
1682 msg_number % ch->remote_nentries);
1683 DBUG_ON(msg->flags & XPC_M_DONE);
1684
1685 msg->flags |= XPC_M_DONE;
1686
1687 /*
1688 * The preceding store of msg->flags must occur before the following
1689 * load of ch->local_GP->get.
1690 */
1691 mb();
1692
1693 /*
1694 * See if this message is next in line to be acknowledged as having
1695 * been delivered.
1696 */
1697 get = ch->local_GP->get;
1698 if (get == msg_number)
1699 xpc_acknowledge_msgs(ch, get, msg->flags);
1700 1389
1701 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_msg() */ 1390 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_msg() */
1702 xpc_msgqueue_deref(ch); 1391 xpc_msgqueue_deref(ch);
diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index be3a4853930..10dac3652b2 100644
--- a/drivers/misc/sgi-xp/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -148,12 +148,14 @@ static struct ctl_table_header *xpc_sysctl;
148int xpc_disengage_request_timedout; 148int xpc_disengage_request_timedout;
149 149
150/* #of IRQs received */ 150/* #of IRQs received */
151static atomic_t xpc_act_IRQ_rcvd; 151atomic_t xpc_act_IRQ_rcvd;
152 152
153/* IRQ handler notifies this wait queue on receipt of an IRQ */ 153/* IRQ handler notifies this wait queue on receipt of an IRQ */
154static DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq); 154DECLARE_WAIT_QUEUE_HEAD(xpc_act_IRQ_wq);
155 155
156static unsigned long xpc_hb_check_timeout; 156static unsigned long xpc_hb_check_timeout;
157static struct timer_list xpc_hb_timer;
158void *xpc_heartbeating_to_mask;
157 159
158/* notification that the xpc_hb_checker thread has exited */ 160/* notification that the xpc_hb_checker thread has exited */
159static DECLARE_COMPLETION(xpc_hb_checker_exited); 161static DECLARE_COMPLETION(xpc_hb_checker_exited);
@@ -161,8 +163,6 @@ static DECLARE_COMPLETION(xpc_hb_checker_exited);
161/* notification that the xpc_discovery thread has exited */ 163/* notification that the xpc_discovery thread has exited */
162static DECLARE_COMPLETION(xpc_discovery_exited); 164static DECLARE_COMPLETION(xpc_discovery_exited);
163 165
164static struct timer_list xpc_hb_timer;
165
166static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *); 166static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
167 167
168static int xpc_system_reboot(struct notifier_block *, unsigned long, void *); 168static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
@@ -176,12 +176,54 @@ static struct notifier_block xpc_die_notifier = {
176}; 176};
177 177
178enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *rp); 178enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *rp);
179void (*xpc_heartbeat_init) (void);
180void (*xpc_heartbeat_exit) (void);
181void (*xpc_increment_heartbeat) (void);
182void (*xpc_offline_heartbeat) (void);
183void (*xpc_online_heartbeat) (void);
184void (*xpc_check_remote_hb) (void);
185
179enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *part); 186enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *part);
180u64 (*xpc_get_IPI_flags) (struct xpc_partition *part); 187u64 (*xpc_get_IPI_flags) (struct xpc_partition *part);
181struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *ch); 188struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *ch);
189
190void (*xpc_initiate_partition_activation) (struct xpc_rsvd_page *remote_rp,
191 u64 remote_rp_pa, int nasid);
192
193void (*xpc_process_act_IRQ_rcvd) (int n_IRQs_expected);
182enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *part); 194enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *part);
183void (*xpc_teardown_infrastructure) (struct xpc_partition *part); 195void (*xpc_teardown_infrastructure) (struct xpc_partition *part);
184 196
197void (*xpc_mark_partition_engaged) (struct xpc_partition *part);
198void (*xpc_mark_partition_disengaged) (struct xpc_partition *part);
199void (*xpc_request_partition_disengage) (struct xpc_partition *part);
200void (*xpc_cancel_partition_disengage_request) (struct xpc_partition *part);
201u64 (*xpc_partition_engaged) (u64 partid_mask);
202u64 (*xpc_partition_disengage_requested) (u64 partid_mask);
203void (*xpc_clear_partition_engaged) (u64 partid_mask);
204void (*xpc_clear_partition_disengage_request) (u64 partid_mask);
205
206void (*xpc_IPI_send_local_activate) (int from_nasid);
207void (*xpc_IPI_send_activated) (struct xpc_partition *part);
208void (*xpc_IPI_send_local_reactivate) (int from_nasid);
209void (*xpc_IPI_send_disengage) (struct xpc_partition *part);
210
211void (*xpc_IPI_send_closerequest) (struct xpc_channel *ch,
212 unsigned long *irq_flags);
213void (*xpc_IPI_send_closereply) (struct xpc_channel *ch,
214 unsigned long *irq_flags);
215void (*xpc_IPI_send_openrequest) (struct xpc_channel *ch,
216 unsigned long *irq_flags);
217void (*xpc_IPI_send_openreply) (struct xpc_channel *ch,
218 unsigned long *irq_flags);
219
220enum xp_retval (*xpc_allocate_msg) (struct xpc_channel *ch, u32 flags,
221 struct xpc_msg **address_of_msg);
222
223enum xp_retval (*xpc_send_msg) (struct xpc_channel *ch, struct xpc_msg *msg,
224 u8 notify_type, xpc_notify_func func,
225 void *key);
226void (*xpc_received_msg) (struct xpc_channel *ch, struct xpc_msg *msg);
185 227
186/* 228/*
187 * Timer function to enforce the timelimit on the partition disengage request. 229 * Timer function to enforce the timelimit on the partition disengage request.
@@ -218,7 +260,7 @@ xpc_act_IRQ_handler(int irq, void *dev_id)
218static void 260static void
219xpc_hb_beater(unsigned long dummy) 261xpc_hb_beater(unsigned long dummy)
220{ 262{
221 xpc_vars->heartbeat++; 263 xpc_increment_heartbeat();
222 264
223 if (time_after_eq(jiffies, xpc_hb_check_timeout)) 265 if (time_after_eq(jiffies, xpc_hb_check_timeout))
224 wake_up_interruptible(&xpc_act_IRQ_wq); 266 wake_up_interruptible(&xpc_act_IRQ_wq);
@@ -227,6 +269,22 @@ xpc_hb_beater(unsigned long dummy)
227 add_timer(&xpc_hb_timer); 269 add_timer(&xpc_hb_timer);
228} 270}
229 271
272static void
273xpc_start_hb_beater(void)
274{
275 xpc_heartbeat_init();
276 init_timer(&xpc_hb_timer);
277 xpc_hb_timer.function = xpc_hb_beater;
278 xpc_hb_beater(0);
279}
280
281static void
282xpc_stop_hb_beater(void)
283{
284 del_timer_sync(&xpc_hb_timer);
285 xpc_heartbeat_exit();
286}
287
230/* 288/*
231 * This thread is responsible for nearly all of the partition 289 * This thread is responsible for nearly all of the partition
232 * activation/deactivation. 290 * activation/deactivation.
@@ -244,7 +302,7 @@ xpc_hb_checker(void *ignore)
244 302
245 /* set our heartbeating to other partitions into motion */ 303 /* set our heartbeating to other partitions into motion */
246 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ); 304 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
247 xpc_hb_beater(0); 305 xpc_start_hb_beater();
248 306
249 while (!xpc_exiting) { 307 while (!xpc_exiting) {
250 308
@@ -274,11 +332,8 @@ xpc_hb_checker(void *ignore)
274 dev_dbg(xpc_part, "found an IRQ to process; will be " 332 dev_dbg(xpc_part, "found an IRQ to process; will be "
275 "resetting xpc_hb_check_timeout\n"); 333 "resetting xpc_hb_check_timeout\n");
276 334
277 last_IRQ_count += xpc_identify_act_IRQ_sender(); 335 xpc_process_act_IRQ_rcvd(new_IRQ_count -
278 if (last_IRQ_count < new_IRQ_count) { 336 last_IRQ_count);
279 /* retry once to help avoid missing AMO */
280 (void)xpc_identify_act_IRQ_sender();
281 }
282 last_IRQ_count = new_IRQ_count; 337 last_IRQ_count = new_IRQ_count;
283 338
284 xpc_hb_check_timeout = jiffies + 339 xpc_hb_check_timeout = jiffies +
@@ -294,6 +349,8 @@ xpc_hb_checker(void *ignore)
294 xpc_exiting)); 349 xpc_exiting));
295 } 350 }
296 351
352 xpc_stop_hb_beater();
353
297 dev_dbg(xpc_part, "heartbeat checker is exiting\n"); 354 dev_dbg(xpc_part, "heartbeat checker is exiting\n");
298 355
299 /* mark this thread as having exited */ 356 /* mark this thread as having exited */
@@ -401,31 +458,7 @@ xpc_activating(void *__partid)
401 458
402 dev_dbg(xpc_part, "activating partition %d\n", partid); 459 dev_dbg(xpc_part, "activating partition %d\n", partid);
403 460
404 /* 461 xpc_allow_hb(partid);
405 * Register the remote partition's AMOs with SAL so it can handle
406 * and cleanup errors within that address range should the remote
407 * partition go down. We don't unregister this range because it is
408 * difficult to tell when outstanding writes to the remote partition
409 * are finished and thus when it is safe to unregister. This should
410 * not result in wasted space in the SAL xp_addr_region table because
411 * we should get the same page for remote_amos_page_pa after module
412 * reloads and system reboots.
413 */
414 if (sn_register_xp_addr_region(part->remote_amos_page_pa,
415 PAGE_SIZE, 1) < 0) {
416 dev_warn(xpc_part, "xpc_activating(%d) failed to register "
417 "xp_addr region\n", partid);
418
419 spin_lock_irqsave(&part->act_lock, irq_flags);
420 part->act_state = XPC_P_INACTIVE;
421 XPC_SET_REASON(part, xpPhysAddrRegFailed, __LINE__);
422 spin_unlock_irqrestore(&part->act_lock, irq_flags);
423 part->remote_rp_pa = 0;
424 return 0;
425 }
426
427 xpc_allow_hb(partid, xpc_vars);
428 xpc_IPI_send_activated(part);
429 462
430 if (xpc_setup_infrastructure(part) == xpSuccess) { 463 if (xpc_setup_infrastructure(part) == xpSuccess) {
431 (void)xpc_part_ref(part); /* this will always succeed */ 464 (void)xpc_part_ref(part); /* this will always succeed */
@@ -440,12 +473,12 @@ xpc_activating(void *__partid)
440 xpc_teardown_infrastructure(part); 473 xpc_teardown_infrastructure(part);
441 } 474 }
442 475
443 xpc_disallow_hb(partid, xpc_vars); 476 xpc_disallow_hb(partid);
444 xpc_mark_partition_inactive(part); 477 xpc_mark_partition_inactive(part);
445 478
446 if (part->reason == xpReactivating) { 479 if (part->reason == xpReactivating) {
447 /* interrupting ourselves results in activating partition */ 480 /* interrupting ourselves results in activating partition */
448 xpc_IPI_send_reactivate(part); 481 xpc_IPI_send_local_reactivate(part->reactivate_nasid);
449 } 482 }
450 483
451 return 0; 484 return 0;
@@ -478,6 +511,32 @@ xpc_activate_partition(struct xpc_partition *part)
478} 511}
479 512
480/* 513/*
514 * Check to see if there is any channel activity to/from the specified
515 * partition.
516 */
517static void
518xpc_check_for_channel_activity(struct xpc_partition *part)
519{
520 u64 IPI_amo;
521 unsigned long irq_flags;
522
523/* this needs to be uncommented, but I'm thinking this function and the */
524/* ones that call it need to be moved into xpc_sn2.c... */
525 IPI_amo = 0; /* = xpc_IPI_receive(part->local_IPI_amo_va); */
526 if (IPI_amo == 0)
527 return;
528
529 spin_lock_irqsave(&part->IPI_lock, irq_flags);
530 part->local_IPI_amo |= IPI_amo;
531 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
532
533 dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
534 XPC_PARTID(part), IPI_amo);
535
536 xpc_wakeup_channel_mgr(part);
537}
538
539/*
481 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified 540 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
482 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more 541 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
483 * than one partition, we use an AMO_t structure per partition to indicate 542 * than one partition, we use an AMO_t structure per partition to indicate
@@ -902,14 +961,11 @@ xpc_do_exit(enum xp_retval reason)
902 } while (1); 961 } while (1);
903 962
904 DBUG_ON(xpc_partition_engaged(-1UL)); 963 DBUG_ON(xpc_partition_engaged(-1UL));
964 DBUG_ON(xpc_any_hbs_allowed() != 0);
905 965
906 /* indicate to others that our reserved page is uninitialized */ 966 /* indicate to others that our reserved page is uninitialized */
907 xpc_rsvd_page->stamp = ZERO_STAMP; 967 xpc_rsvd_page->stamp = ZERO_STAMP;
908 968
909 /* now it's time to eliminate our heartbeat */
910 del_timer_sync(&xpc_hb_timer);
911 DBUG_ON(xpc_vars->heartbeating_to_mask != 0);
912
913 if (reason == xpUnloading) { 969 if (reason == xpUnloading) {
914 (void)unregister_die_notifier(&xpc_die_notifier); 970 (void)unregister_die_notifier(&xpc_die_notifier);
915 (void)unregister_reboot_notifier(&xpc_reboot_notifier); 971 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
@@ -968,7 +1024,7 @@ xpc_die_disengage(void)
968 /* keep xpc_hb_checker thread from doing anything (just in case) */ 1024 /* keep xpc_hb_checker thread from doing anything (just in case) */
969 xpc_exiting = 1; 1025 xpc_exiting = 1;
970 1026
971 xpc_vars->heartbeating_to_mask = 0; /* indicate we're deactivated */ 1027 xpc_disallow_all_hbs(); /*indicate we're deactivated */
972 1028
973 for (partid = 0; partid < xp_max_npartitions; partid++) { 1029 for (partid = 0; partid < xp_max_npartitions; partid++) {
974 part = &xpc_partitions[partid]; 1030 part = &xpc_partitions[partid];
@@ -1054,8 +1110,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1054 /* fall through */ 1110 /* fall through */
1055 case DIE_MCA_MONARCH_ENTER: 1111 case DIE_MCA_MONARCH_ENTER:
1056 case DIE_INIT_MONARCH_ENTER: 1112 case DIE_INIT_MONARCH_ENTER:
1057 xpc_vars->heartbeat++; 1113 xpc_offline_heartbeat();
1058 xpc_vars->heartbeat_offline = 1;
1059 break; 1114 break;
1060 1115
1061 case DIE_KDEBUG_LEAVE: 1116 case DIE_KDEBUG_LEAVE:
@@ -1066,8 +1121,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1066 /* fall through */ 1121 /* fall through */
1067 case DIE_MCA_MONARCH_LEAVE: 1122 case DIE_MCA_MONARCH_LEAVE:
1068 case DIE_INIT_MONARCH_LEAVE: 1123 case DIE_INIT_MONARCH_LEAVE:
1069 xpc_vars->heartbeat++; 1124 xpc_online_heartbeat();
1070 xpc_vars->heartbeat_offline = 0;
1071 break; 1125 break;
1072 } 1126 }
1073 1127
@@ -1202,9 +1256,6 @@ xpc_init(void)
1202 if (ret != 0) 1256 if (ret != 0)
1203 dev_warn(xpc_part, "can't register die notifier\n"); 1257 dev_warn(xpc_part, "can't register die notifier\n");
1204 1258
1205 init_timer(&xpc_hb_timer);
1206 xpc_hb_timer.function = xpc_hb_beater;
1207
1208 /* 1259 /*
1209 * The real work-horse behind xpc. This processes incoming 1260 * The real work-horse behind xpc. This processes incoming
1210 * interrupts and monitors remote heartbeats. 1261 * interrupts and monitors remote heartbeats.
@@ -1246,7 +1297,6 @@ out_4:
1246 /* indicate to others that our reserved page is uninitialized */ 1297 /* indicate to others that our reserved page is uninitialized */
1247 xpc_rsvd_page->stamp = ZERO_STAMP; 1298 xpc_rsvd_page->stamp = ZERO_STAMP;
1248 1299
1249 del_timer_sync(&xpc_hb_timer);
1250 (void)unregister_die_notifier(&xpc_die_notifier); 1300 (void)unregister_die_notifier(&xpc_die_notifier);
1251 (void)unregister_reboot_notifier(&xpc_reboot_notifier); 1301 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
1252out_3: 1302out_3:
diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index be5b7547dab..4e14effdedd 100644
--- a/drivers/misc/sgi-xp/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -42,7 +42,7 @@ u64 xpc_prot_vec[MAX_NUMNODES];
42/* this partition's reserved page pointers */ 42/* this partition's reserved page pointers */
43struct xpc_rsvd_page *xpc_rsvd_page; 43struct xpc_rsvd_page *xpc_rsvd_page;
44static u64 *xpc_part_nasids; 44static u64 *xpc_part_nasids;
45static u64 *xpc_mach_nasids; 45u64 *xpc_mach_nasids;
46 46
47/* >>> next two variables should be 'xpc_' if they remain here */ 47/* >>> next two variables should be 'xpc_' if they remain here */
48static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */ 48static int xp_sizeof_nasid_mask; /* actual size in bytes of nasid mask */
@@ -318,69 +318,13 @@ xpc_restrict_IPI_ops(void)
318} 318}
319 319
320/* 320/*
321 * At periodic intervals, scan through all active partitions and ensure
322 * their heartbeat is still active. If not, the partition is deactivated.
323 */
324void
325xpc_check_remote_hb(void)
326{
327 struct xpc_vars *remote_vars;
328 struct xpc_partition *part;
329 short partid;
330 enum xp_retval ret;
331
332 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
333
334 for (partid = 0; partid < xp_max_npartitions; partid++) {
335
336 if (xpc_exiting)
337 break;
338
339 if (partid == sn_partition_id)
340 continue;
341
342 part = &xpc_partitions[partid];
343
344 if (part->act_state == XPC_P_INACTIVE ||
345 part->act_state == XPC_P_DEACTIVATING) {
346 continue;
347 }
348
349 /* pull the remote_hb cache line */
350 ret = xp_remote_memcpy(remote_vars,
351 (void *)part->remote_vars_pa,
352 XPC_RP_VARS_SIZE);
353 if (ret != xpSuccess) {
354 XPC_DEACTIVATE_PARTITION(part, ret);
355 continue;
356 }
357
358 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
359 " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n",
360 partid, remote_vars->heartbeat, part->last_heartbeat,
361 remote_vars->heartbeat_offline,
362 remote_vars->heartbeating_to_mask);
363
364 if (((remote_vars->heartbeat == part->last_heartbeat) &&
365 (remote_vars->heartbeat_offline == 0)) ||
366 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
367
368 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
369 continue;
370 }
371
372 part->last_heartbeat = remote_vars->heartbeat;
373 }
374}
375
376/*
377 * Get a copy of a portion of the remote partition's rsvd page. 321 * Get a copy of a portion of the remote partition's rsvd page.
378 * 322 *
379 * remote_rp points to a buffer that is cacheline aligned for BTE copies and 323 * remote_rp points to a buffer that is cacheline aligned for BTE copies and
380 * is large enough to contain a copy of their reserved page header and 324 * is large enough to contain a copy of their reserved page header and
381 * part_nasids mask. 325 * part_nasids mask.
382 */ 326 */
383static enum xp_retval 327enum xp_retval
384xpc_get_remote_rp(int nasid, u64 *discovered_nasids, 328xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
385 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa) 329 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
386{ 330{
@@ -432,322 +376,6 @@ xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
432} 376}
433 377
434/* 378/*
435 * Get a copy of the remote partition's XPC variables from the reserved page.
436 *
437 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
438 * assumed to be of size XPC_RP_VARS_SIZE.
439 */
440static enum xp_retval
441xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
442{
443 enum xp_retval ret;
444
445 if (remote_vars_pa == 0)
446 return xpVarsNotSet;
447
448 /* pull over the cross partition variables */
449 ret = xp_remote_memcpy(remote_vars, (void *)remote_vars_pa,
450 XPC_RP_VARS_SIZE);
451 if (ret != xpSuccess)
452 return ret;
453
454 if (XPC_VERSION_MAJOR(remote_vars->version) !=
455 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
456 return xpBadVersion;
457 }
458
459 return xpSuccess;
460}
461
462/*
463 * Update the remote partition's info.
464 */
465static void
466xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
467 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
468 u64 remote_vars_pa, struct xpc_vars *remote_vars)
469{
470 part->remote_rp_version = remote_rp_version;
471 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
472 part->remote_rp_version);
473
474 part->remote_rp_stamp = *remote_rp_stamp;
475 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
476 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
477
478 part->remote_rp_pa = remote_rp_pa;
479 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
480
481 part->remote_vars_pa = remote_vars_pa;
482 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
483 part->remote_vars_pa);
484
485 part->last_heartbeat = remote_vars->heartbeat;
486 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
487 part->last_heartbeat);
488
489/* >>> remote_vars_part_pa and vars_part_pa are sn2 only!!! */
490 part->remote_vars_part_pa = remote_vars->vars_part_pa;
491 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
492 part->remote_vars_part_pa);
493
494 part->remote_act_nasid = remote_vars->act_nasid;
495 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
496 part->remote_act_nasid);
497
498 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
499 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
500 part->remote_act_phys_cpuid);
501
502 part->remote_amos_page_pa = remote_vars->amos_page_pa;
503 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
504 part->remote_amos_page_pa);
505
506 part->remote_vars_version = remote_vars->version;
507 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
508 part->remote_vars_version);
509}
510
511/*
512 * Prior code has determined the nasid which generated an IPI. Inspect
513 * that nasid to determine if its partition needs to be activated or
514 * deactivated.
515 *
516 * A partition is consider "awaiting activation" if our partition
517 * flags indicate it is not active and it has a heartbeat. A
518 * partition is considered "awaiting deactivation" if our partition
519 * flags indicate it is active but it has no heartbeat or it is not
520 * sending its heartbeat to us.
521 *
522 * To determine the heartbeat, the remote nasid must have a properly
523 * initialized reserved page.
524 */
525static void
526xpc_identify_act_IRQ_req(int nasid)
527{
528 struct xpc_rsvd_page *remote_rp;
529 struct xpc_vars *remote_vars;
530 u64 remote_rp_pa;
531 u64 remote_vars_pa;
532 int remote_rp_version;
533 int reactivate = 0;
534 int stamp_diff;
535 struct timespec remote_rp_stamp = { 0, 0 }; /*>>> ZERO_STAMP */
536 short partid;
537 struct xpc_partition *part;
538 enum xp_retval ret;
539
540 /* pull over the reserved page structure */
541
542 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
543
544 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
545 if (ret != xpSuccess) {
546 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
547 "which sent interrupt, reason=%d\n", nasid, ret);
548 return;
549 }
550
551 remote_vars_pa = remote_rp->sn.vars_pa;
552 remote_rp_version = remote_rp->version;
553 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
554 remote_rp_stamp = remote_rp->stamp;
555
556 partid = remote_rp->SAL_partid;
557 part = &xpc_partitions[partid];
558
559 /* pull over the cross partition variables */
560
561 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
562
563 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
564 if (ret != xpSuccess) {
565
566 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
567 "which sent interrupt, reason=%d\n", nasid, ret);
568
569 XPC_DEACTIVATE_PARTITION(part, ret);
570 return;
571 }
572
573 part->act_IRQ_rcvd++;
574
575 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
576 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
577 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
578
579 if (xpc_partition_disengaged(part) &&
580 part->act_state == XPC_P_INACTIVE) {
581
582 xpc_update_partition_info(part, remote_rp_version,
583 &remote_rp_stamp, remote_rp_pa,
584 remote_vars_pa, remote_vars);
585
586 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
587 if (xpc_partition_disengage_requested(1UL << partid)) {
588 /*
589 * Other side is waiting on us to disengage,
590 * even though we already have.
591 */
592 return;
593 }
594 } else {
595 /* other side doesn't support disengage requests */
596 xpc_clear_partition_disengage_request(1UL << partid);
597 }
598
599 xpc_activate_partition(part);
600 return;
601 }
602
603 DBUG_ON(part->remote_rp_version == 0);
604 DBUG_ON(part->remote_vars_version == 0);
605
606 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
607 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
608 remote_vars_version));
609
610 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
611 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
612 version));
613 /* see if the other side rebooted */
614 if (part->remote_amos_page_pa ==
615 remote_vars->amos_page_pa &&
616 xpc_hb_allowed(sn_partition_id, remote_vars)) {
617 /* doesn't look that way, so ignore the IPI */
618 return;
619 }
620 }
621
622 /*
623 * Other side rebooted and previous XPC didn't support the
624 * disengage request, so we don't need to do anything special.
625 */
626
627 xpc_update_partition_info(part, remote_rp_version,
628 &remote_rp_stamp, remote_rp_pa,
629 remote_vars_pa, remote_vars);
630 part->reactivate_nasid = nasid;
631 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
632 return;
633 }
634
635 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
636
637 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
638 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
639
640 /*
641 * Other side rebooted and previous XPC did support the
642 * disengage request, but the new one doesn't.
643 */
644
645 xpc_clear_partition_engaged(1UL << partid);
646 xpc_clear_partition_disengage_request(1UL << partid);
647
648 xpc_update_partition_info(part, remote_rp_version,
649 &remote_rp_stamp, remote_rp_pa,
650 remote_vars_pa, remote_vars);
651 reactivate = 1;
652
653 } else {
654 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
655
656 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
657 &remote_rp_stamp);
658 if (stamp_diff != 0) {
659 DBUG_ON(stamp_diff >= 0);
660
661 /*
662 * Other side rebooted and the previous XPC did support
663 * the disengage request, as does the new one.
664 */
665
666 DBUG_ON(xpc_partition_engaged(1UL << partid));
667 DBUG_ON(xpc_partition_disengage_requested(1UL <<
668 partid));
669
670 xpc_update_partition_info(part, remote_rp_version,
671 &remote_rp_stamp,
672 remote_rp_pa, remote_vars_pa,
673 remote_vars);
674 reactivate = 1;
675 }
676 }
677
678 if (part->disengage_request_timeout > 0 &&
679 !xpc_partition_disengaged(part)) {
680 /* still waiting on other side to disengage from us */
681 return;
682 }
683
684 if (reactivate) {
685 part->reactivate_nasid = nasid;
686 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
687
688 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
689 xpc_partition_disengage_requested(1UL << partid)) {
690 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
691 }
692}
693
694/*
695 * Loop through the activation AMO variables and process any bits
696 * which are set. Each bit indicates a nasid sending a partition
697 * activation or deactivation request.
698 *
699 * Return #of IRQs detected.
700 */
701int
702xpc_identify_act_IRQ_sender(void)
703{
704 int word, bit;
705 u64 nasid_mask;
706 u64 nasid; /* remote nasid */
707 int n_IRQs_detected = 0;
708 AMO_t *act_amos;
709
710 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
711
712 /* scan through act AMO variable looking for non-zero entries */
713 for (word = 0; word < xp_nasid_mask_words; word++) {
714
715 if (xpc_exiting)
716 break;
717
718 nasid_mask = xpc_IPI_receive(&act_amos[word]);
719 if (nasid_mask == 0) {
720 /* no IRQs from nasids in this variable */
721 continue;
722 }
723
724 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
725 nasid_mask);
726
727 /*
728 * If this nasid has been added to the machine since
729 * our partition was reset, this will retain the
730 * remote nasid in our reserved pages machine mask.
731 * This is used in the event of module reload.
732 */
733 xpc_mach_nasids[word] |= nasid_mask;
734
735 /* locate the nasid(s) which sent interrupts */
736
737 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
738 if (nasid_mask & (1UL << bit)) {
739 n_IRQs_detected++;
740 nasid = XPC_NASID_FROM_W_B(word, bit);
741 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
742 nasid);
743 xpc_identify_act_IRQ_req(nasid);
744 }
745 }
746 }
747 return n_IRQs_detected;
748}
749
750/*
751 * See if the other side has responded to a partition disengage request 379 * See if the other side has responded to a partition disengage request
752 * from us. 380 * from us.
753 */ 381 */
@@ -836,7 +464,7 @@ xpc_deactivate_partition(const int line, struct xpc_partition *part,
836 spin_unlock_irqrestore(&part->act_lock, irq_flags); 464 spin_unlock_irqrestore(&part->act_lock, irq_flags);
837 if (reason == xpReactivating) { 465 if (reason == xpReactivating) {
838 /* we interrupt ourselves to reactivate partition */ 466 /* we interrupt ourselves to reactivate partition */
839 xpc_IPI_send_reactivate(part); 467 xpc_IPI_send_local_reactivate(part->reactivate_nasid);
840 } 468 }
841 return; 469 return;
842 } 470 }
@@ -903,16 +531,12 @@ xpc_discovery(void)
903{ 531{
904 void *remote_rp_base; 532 void *remote_rp_base;
905 struct xpc_rsvd_page *remote_rp; 533 struct xpc_rsvd_page *remote_rp;
906 struct xpc_vars *remote_vars;
907 u64 remote_rp_pa; 534 u64 remote_rp_pa;
908 u64 remote_vars_pa;
909 int region; 535 int region;
910 int region_size; 536 int region_size;
911 int max_regions; 537 int max_regions;
912 int nasid; 538 int nasid;
913 struct xpc_rsvd_page *rp; 539 struct xpc_rsvd_page *rp;
914 short partid;
915 struct xpc_partition *part;
916 u64 *discovered_nasids; 540 u64 *discovered_nasids;
917 enum xp_retval ret; 541 enum xp_retval ret;
918 542
@@ -922,8 +546,6 @@ xpc_discovery(void)
922 if (remote_rp == NULL) 546 if (remote_rp == NULL)
923 return; 547 return;
924 548
925 remote_vars = (struct xpc_vars *)remote_rp;
926
927 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words, 549 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
928 GFP_KERNEL); 550 GFP_KERNEL);
929 if (discovered_nasids == NULL) { 551 if (discovered_nasids == NULL) {
@@ -988,7 +610,7 @@ xpc_discovery(void)
988 continue; 610 continue;
989 } 611 }
990 612
991 /* pull over the reserved page structure */ 613 /* pull over the rsvd page header & part_nasids mask */
992 614
993 ret = xpc_get_remote_rp(nasid, discovered_nasids, 615 ret = xpc_get_remote_rp(nasid, discovered_nasids,
994 remote_rp, &remote_rp_pa); 616 remote_rp, &remote_rp_pa);
@@ -1003,72 +625,8 @@ xpc_discovery(void)
1003 continue; 625 continue;
1004 } 626 }
1005 627
1006 remote_vars_pa = remote_rp->sn.vars_pa; 628 xpc_initiate_partition_activation(remote_rp,
1007 629 remote_rp_pa, nasid);
1008 partid = remote_rp->SAL_partid;
1009 part = &xpc_partitions[partid];
1010
1011 /* pull over the cross partition variables */
1012
1013 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
1014 if (ret != xpSuccess) {
1015 dev_dbg(xpc_part, "unable to get XPC variables "
1016 "from nasid %d, reason=%d\n", nasid,
1017 ret);
1018
1019 XPC_DEACTIVATE_PARTITION(part, ret);
1020 continue;
1021 }
1022
1023 if (part->act_state != XPC_P_INACTIVE) {
1024 dev_dbg(xpc_part, "partition %d on nasid %d is "
1025 "already activating\n", partid, nasid);
1026 break;
1027 }
1028
1029 /*
1030 * Register the remote partition's AMOs with SAL so it
1031 * can handle and cleanup errors within that address
1032 * range should the remote partition go down. We don't
1033 * unregister this range because it is difficult to
1034 * tell when outstanding writes to the remote partition
1035 * are finished and thus when it is thus safe to
1036 * unregister. This should not result in wasted space
1037 * in the SAL xp_addr_region table because we should
1038 * get the same page for remote_act_amos_pa after
1039 * module reloads and system reboots.
1040 */
1041 if (sn_register_xp_addr_region
1042 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1043 dev_dbg(xpc_part,
1044 "partition %d failed to "
1045 "register xp_addr region 0x%016lx\n",
1046 partid, remote_vars->amos_page_pa);
1047
1048 XPC_SET_REASON(part, xpPhysAddrRegFailed,
1049 __LINE__);
1050 break;
1051 }
1052
1053 /*
1054 * The remote nasid is valid and available.
1055 * Send an interrupt to that nasid to notify
1056 * it that we are ready to begin activation.
1057 */
1058 dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, "
1059 "nasid %d, phys_cpuid 0x%x\n",
1060 remote_vars->amos_page_pa,
1061 remote_vars->act_nasid,
1062 remote_vars->act_phys_cpuid);
1063
1064 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
1065 version)) {
1066 part->remote_amos_page_pa =
1067 remote_vars->amos_page_pa;
1068 xpc_mark_partition_disengaged(part);
1069 xpc_cancel_partition_disengage_request(part);
1070 }
1071 xpc_IPI_send_activate(remote_vars);
1072 } 630 }
1073 } 631 }
1074 632
diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
index ee28e231dc4..89c0bb9a27f 100644
--- a/drivers/misc/sgi-xp/xpc_sn2.c
+++ b/drivers/misc/sgi-xp/xpc_sn2.c
@@ -19,9 +19,370 @@
19#include <asm/sn/sn_sal.h> 19#include <asm/sn/sn_sal.h>
20#include "xpc.h" 20#include "xpc.h"
21 21
22struct xpc_vars *xpc_vars; 22static struct xpc_vars_sn2 *xpc_vars; /* >>> Add _sn2 suffix? */
23static struct xpc_vars_part_sn2 *xpc_vars_part; /* >>> Add _sn2 suffix? */ 23static struct xpc_vars_part_sn2 *xpc_vars_part; /* >>> Add _sn2 suffix? */
24 24
25/*
26 * The following set of macros and functions are used for the sending and
27 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
28 * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
29 * the other that is associated with channel activity (SGI_XPC_NOTIFY).
30 */
31
32static u64
33xpc_IPI_receive_sn2(AMO_t *amo)
34{
35 return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_CLEAR);
36}
37
38static enum xp_retval
39xpc_IPI_send_sn2(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
40{
41 int ret = 0;
42 unsigned long irq_flags;
43
44 local_irq_save(irq_flags);
45
46 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, flag);
47 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
48
49 /*
50 * We must always use the nofault function regardless of whether we
51 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
52 * didn't, we'd never know that the other partition is down and would
53 * keep sending IPIs and AMOs to it until the heartbeat times out.
54 */
55 ret = xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
56 xp_nofault_PIOR_target));
57
58 local_irq_restore(irq_flags);
59
60 return ((ret == 0) ? xpSuccess : xpPioReadError);
61}
62
63static AMO_t *
64xpc_IPI_init_sn2(int index)
65{
66 AMO_t *amo = xpc_vars->amos_page + index;
67
68 (void)xpc_IPI_receive_sn2(amo); /* clear AMO variable */
69 return amo;
70}
71
72/*
73 * IPIs associated with SGI_XPC_ACTIVATE IRQ.
74 */
75
76/*
77 * Flag the appropriate AMO variable and send an IPI to the specified node.
78 */
79static void
80xpc_activate_IRQ_send_sn2(u64 amos_page_pa, int from_nasid, int to_nasid,
81 int to_phys_cpuid)
82{
83 int w_index = XPC_NASID_W_INDEX(from_nasid);
84 int b_index = XPC_NASID_B_INDEX(from_nasid);
85 AMO_t *amos = (AMO_t *)__va(amos_page_pa +
86 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
87
88 (void)xpc_IPI_send_sn2(&amos[w_index], (1UL << b_index), to_nasid,
89 to_phys_cpuid, SGI_XPC_ACTIVATE);
90}
91
92static void
93xpc_activate_IRQ_send_local_sn2(int from_nasid)
94{
95 int w_index = XPC_NASID_W_INDEX(from_nasid);
96 int b_index = XPC_NASID_B_INDEX(from_nasid);
97 AMO_t *amos = (AMO_t *)__va(xpc_vars->amos_page_pa +
98 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
99
100 /* fake the sending and receipt of an activate IRQ from remote nasid */
101 FETCHOP_STORE_OP(TO_AMO((u64)&amos[w_index].variable), FETCHOP_OR,
102 (1UL << b_index));
103 atomic_inc(&xpc_act_IRQ_rcvd);
104 wake_up_interruptible(&xpc_act_IRQ_wq);
105}
106
107static void
108xpc_IPI_send_local_activate_sn2(int from_nasid)
109{
110 xpc_activate_IRQ_send_local_sn2(from_nasid);
111}
112
113static void
114xpc_IPI_send_activated_sn2(struct xpc_partition *part)
115{
116 xpc_activate_IRQ_send_sn2(part->remote_amos_page_pa,
117 cnodeid_to_nasid(0), part->remote_act_nasid,
118 part->remote_act_phys_cpuid);
119}
120
121static void
122xpc_IPI_send_local_reactivate_sn2(int from_nasid)
123{
124 xpc_activate_IRQ_send_local_sn2(from_nasid);
125}
126
127static void
128xpc_IPI_send_disengage_sn2(struct xpc_partition *part)
129{
130 xpc_activate_IRQ_send_sn2(part->remote_amos_page_pa,
131 cnodeid_to_nasid(0), part->remote_act_nasid,
132 part->remote_act_phys_cpuid);
133}
134
135/*
136 * IPIs associated with SGI_XPC_NOTIFY IRQ.
137 */
138
139/*
140 * Send an IPI to the remote partition that is associated with the
141 * specified channel.
142 */
143static void
144xpc_notify_IRQ_send_sn2(struct xpc_channel *ch, u8 ipi_flag,
145 char *ipi_flag_string, unsigned long *irq_flags)
146{
147 struct xpc_partition *part = &xpc_partitions[ch->partid];
148 enum xp_retval ret;
149
150 if (likely(part->act_state != XPC_P_DEACTIVATING)) {
151 ret = xpc_IPI_send_sn2(part->remote_IPI_amo_va,
152 (u64)ipi_flag << (ch->number * 8),
153 part->remote_IPI_nasid,
154 part->remote_IPI_phys_cpuid,
155 SGI_XPC_NOTIFY);
156 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
157 ipi_flag_string, ch->partid, ch->number, ret);
158 if (unlikely(ret != xpSuccess)) {
159 if (irq_flags != NULL)
160 spin_unlock_irqrestore(&ch->lock, *irq_flags);
161 XPC_DEACTIVATE_PARTITION(part, ret);
162 if (irq_flags != NULL)
163 spin_lock_irqsave(&ch->lock, *irq_flags);
164 }
165 }
166}
167
168#define XPC_NOTIFY_IRQ_SEND_SN2(_ch, _ipi_f, _irq_f) \
169 xpc_notify_IRQ_send_sn2(_ch, _ipi_f, #_ipi_f, _irq_f)
170
171/*
172 * Make it look like the remote partition, which is associated with the
173 * specified channel, sent us an IPI. This faked IPI will be handled
174 * by xpc_dropped_IPI_check().
175 */
176static void
177xpc_notify_IRQ_send_local_sn2(struct xpc_channel *ch, u8 ipi_flag,
178 char *ipi_flag_string)
179{
180 struct xpc_partition *part = &xpc_partitions[ch->partid];
181
182 FETCHOP_STORE_OP(TO_AMO((u64)&part->local_IPI_amo_va->variable),
183 FETCHOP_OR, ((u64)ipi_flag << (ch->number * 8)));
184 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
185 ipi_flag_string, ch->partid, ch->number);
186}
187
188#define XPC_NOTIFY_IRQ_SEND_LOCAL_SN2(_ch, _ipi_f) \
189 xpc_notify_IRQ_send_local_sn2(_ch, _ipi_f, #_ipi_f)
190
191static void
192xpc_IPI_send_closerequest_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
193{
194 struct xpc_openclose_args *args = ch->local_openclose_args;
195
196 args->reason = ch->reason;
197 XPC_NOTIFY_IRQ_SEND_SN2(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
198}
199
200static void
201xpc_IPI_send_closereply_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
202{
203 XPC_NOTIFY_IRQ_SEND_SN2(ch, XPC_IPI_CLOSEREPLY, irq_flags);
204}
205
206static void
207xpc_IPI_send_openrequest_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
208{
209 struct xpc_openclose_args *args = ch->local_openclose_args;
210
211 args->msg_size = ch->msg_size;
212 args->local_nentries = ch->local_nentries;
213 XPC_NOTIFY_IRQ_SEND_SN2(ch, XPC_IPI_OPENREQUEST, irq_flags);
214}
215
216static void
217xpc_IPI_send_openreply_sn2(struct xpc_channel *ch, unsigned long *irq_flags)
218{
219 struct xpc_openclose_args *args = ch->local_openclose_args;
220
221 args->remote_nentries = ch->remote_nentries;
222 args->local_nentries = ch->local_nentries;
223 args->local_msgqueue_pa = __pa(ch->local_msgqueue);
224 XPC_NOTIFY_IRQ_SEND_SN2(ch, XPC_IPI_OPENREPLY, irq_flags);
225}
226
227static void
228xpc_IPI_send_msgrequest_sn2(struct xpc_channel *ch)
229{
230 XPC_NOTIFY_IRQ_SEND_SN2(ch, XPC_IPI_MSGREQUEST, NULL);
231}
232
233static void
234xpc_IPI_send_local_msgrequest_sn2(struct xpc_channel *ch)
235{
236 XPC_NOTIFY_IRQ_SEND_LOCAL_SN2(ch, XPC_IPI_MSGREQUEST);
237}
238
239/*
240 * This next set of functions are used to keep track of when a partition is
241 * potentially engaged in accessing memory belonging to another partition.
242 */
243
244static void
245xpc_mark_partition_engaged_sn2(struct xpc_partition *part)
246{
247 unsigned long irq_flags;
248 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
249 (XPC_ENGAGED_PARTITIONS_AMO *
250 sizeof(AMO_t)));
251
252 local_irq_save(irq_flags);
253
254 /* set bit corresponding to our partid in remote partition's AMO */
255 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
256 (1UL << sn_partition_id));
257 /*
258 * We must always use the nofault function regardless of whether we
259 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
260 * didn't, we'd never know that the other partition is down and would
261 * keep sending IPIs and AMOs to it until the heartbeat times out.
262 */
263 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
264 variable),
265 xp_nofault_PIOR_target));
266
267 local_irq_restore(irq_flags);
268}
269
270static void
271xpc_mark_partition_disengaged_sn2(struct xpc_partition *part)
272{
273 unsigned long irq_flags;
274 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
275 (XPC_ENGAGED_PARTITIONS_AMO *
276 sizeof(AMO_t)));
277
278 local_irq_save(irq_flags);
279
280 /* clear bit corresponding to our partid in remote partition's AMO */
281 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
282 ~(1UL << sn_partition_id));
283 /*
284 * We must always use the nofault function regardless of whether we
285 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
286 * didn't, we'd never know that the other partition is down and would
287 * keep sending IPIs and AMOs to it until the heartbeat times out.
288 */
289 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
290 variable),
291 xp_nofault_PIOR_target));
292
293 local_irq_restore(irq_flags);
294}
295
296static void
297xpc_request_partition_disengage_sn2(struct xpc_partition *part)
298{
299 unsigned long irq_flags;
300 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
301 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
302
303 local_irq_save(irq_flags);
304
305 /* set bit corresponding to our partid in remote partition's AMO */
306 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
307 (1UL << sn_partition_id));
308 /*
309 * We must always use the nofault function regardless of whether we
310 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
311 * didn't, we'd never know that the other partition is down and would
312 * keep sending IPIs and AMOs to it until the heartbeat times out.
313 */
314 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
315 variable),
316 xp_nofault_PIOR_target));
317
318 local_irq_restore(irq_flags);
319}
320
321static void
322xpc_cancel_partition_disengage_request_sn2(struct xpc_partition *part)
323{
324 unsigned long irq_flags;
325 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
326 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
327
328 local_irq_save(irq_flags);
329
330 /* clear bit corresponding to our partid in remote partition's AMO */
331 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
332 ~(1UL << sn_partition_id));
333 /*
334 * We must always use the nofault function regardless of whether we
335 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
336 * didn't, we'd never know that the other partition is down and would
337 * keep sending IPIs and AMOs to it until the heartbeat times out.
338 */
339 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
340 variable),
341 xp_nofault_PIOR_target));
342
343 local_irq_restore(irq_flags);
344}
345
346static u64
347xpc_partition_engaged_sn2(u64 partid_mask)
348{
349 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
350
351 /* return our partition's AMO variable ANDed with partid_mask */
352 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
353 partid_mask);
354}
355
356static u64
357xpc_partition_disengage_requested_sn2(u64 partid_mask)
358{
359 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
360
361 /* return our partition's AMO variable ANDed with partid_mask */
362 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
363 partid_mask);
364}
365
366static void
367xpc_clear_partition_engaged_sn2(u64 partid_mask)
368{
369 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
370
371 /* clear bit(s) based on partid_mask in our partition's AMO */
372 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
373 ~partid_mask);
374}
375
376static void
377xpc_clear_partition_disengage_request_sn2(u64 partid_mask)
378{
379 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
380
381 /* clear bit(s) based on partid_mask in our partition's AMO */
382 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
383 ~partid_mask);
384}
385
25static enum xp_retval 386static enum xp_retval
26xpc_rsvd_page_init_sn2(struct xpc_rsvd_page *rp) 387xpc_rsvd_page_init_sn2(struct xpc_rsvd_page *rp)
27{ 388{
@@ -79,7 +440,7 @@ xpc_rsvd_page_init_sn2(struct xpc_rsvd_page *rp)
79 } 440 }
80 441
81 /* clear xpc_vars */ 442 /* clear xpc_vars */
82 memset(xpc_vars, 0, sizeof(struct xpc_vars)); 443 memset(xpc_vars, 0, sizeof(struct xpc_vars_sn2));
83 444
84 xpc_vars->version = XPC_V_VERSION; 445 xpc_vars->version = XPC_V_VERSION;
85 xpc_vars->act_nasid = cpuid_to_nasid(0); 446 xpc_vars->act_nasid = cpuid_to_nasid(0);
@@ -94,15 +455,446 @@ xpc_rsvd_page_init_sn2(struct xpc_rsvd_page *rp)
94 455
95 /* initialize the activate IRQ related AMO variables */ 456 /* initialize the activate IRQ related AMO variables */
96 for (i = 0; i < xp_nasid_mask_words; i++) 457 for (i = 0; i < xp_nasid_mask_words; i++)
97 (void)xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i); 458 (void)xpc_IPI_init_sn2(XPC_ACTIVATE_IRQ_AMOS + i);
98 459
99 /* initialize the engaged remote partitions related AMO variables */ 460 /* initialize the engaged remote partitions related AMO variables */
100 (void)xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO); 461 (void)xpc_IPI_init_sn2(XPC_ENGAGED_PARTITIONS_AMO);
101 (void)xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO); 462 (void)xpc_IPI_init_sn2(XPC_DISENGAGE_REQUEST_AMO);
463
464 return xpSuccess;
465}
466
467static void
468xpc_increment_heartbeat_sn2(void)
469{
470 xpc_vars->heartbeat++;
471}
472
473static void
474xpc_offline_heartbeat_sn2(void)
475{
476 xpc_increment_heartbeat_sn2();
477 xpc_vars->heartbeat_offline = 1;
478}
479
480static void
481xpc_online_heartbeat_sn2(void)
482{
483 xpc_increment_heartbeat_sn2();
484 xpc_vars->heartbeat_offline = 0;
485}
486
487static void
488xpc_heartbeat_init_sn2(void)
489{
490 DBUG_ON(xpc_vars == NULL);
491
492 bitmap_zero(xpc_vars->heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);
493 xpc_heartbeating_to_mask = &xpc_vars->heartbeating_to_mask[0];
494 xpc_online_heartbeat_sn2();
495}
496
497static void
498xpc_heartbeat_exit_sn2(void)
499{
500 xpc_offline_heartbeat_sn2();
501}
502
503/*
504 * At periodic intervals, scan through all active partitions and ensure
505 * their heartbeat is still active. If not, the partition is deactivated.
506 */
507static void
508xpc_check_remote_hb_sn2(void)
509{
510 struct xpc_vars_sn2 *remote_vars;
511 struct xpc_partition *part;
512 short partid;
513 enum xp_retval ret;
514
515 remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer;
516
517 for (partid = 0; partid < xp_max_npartitions; partid++) {
518
519 if (xpc_exiting)
520 break;
521
522 if (partid == sn_partition_id)
523 continue;
524
525 part = &xpc_partitions[partid];
526
527 if (part->act_state == XPC_P_INACTIVE ||
528 part->act_state == XPC_P_DEACTIVATING) {
529 continue;
530 }
531
532 /* pull the remote_hb cache line */
533 ret = xp_remote_memcpy(remote_vars,
534 (void *)part->remote_vars_pa,
535 XPC_RP_VARS_SIZE);
536 if (ret != xpSuccess) {
537 XPC_DEACTIVATE_PARTITION(part, ret);
538 continue;
539 }
540
541 dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat"
542 " = %ld, heartbeat_offline = %ld, HB_mask[0] = 0x%lx\n",
543 partid, remote_vars->heartbeat, part->last_heartbeat,
544 remote_vars->heartbeat_offline,
545 remote_vars->heartbeating_to_mask[0]);
546
547 if (((remote_vars->heartbeat == part->last_heartbeat) &&
548 (remote_vars->heartbeat_offline == 0)) ||
549 !xpc_hb_allowed(sn_partition_id,
550 &remote_vars->heartbeating_to_mask)) {
551
552 XPC_DEACTIVATE_PARTITION(part, xpNoHeartbeat);
553 continue;
554 }
555
556 part->last_heartbeat = remote_vars->heartbeat;
557 }
558}
559
560/*
561 * Get a copy of the remote partition's XPC variables from the reserved page.
562 *
563 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
564 * assumed to be of size XPC_RP_VARS_SIZE.
565 */
566static enum xp_retval
567xpc_get_remote_vars_sn2(u64 remote_vars_pa, struct xpc_vars_sn2 *remote_vars)
568{
569 enum xp_retval ret;
570
571 if (remote_vars_pa == 0)
572 return xpVarsNotSet;
573
574 /* pull over the cross partition variables */
575 ret = xp_remote_memcpy(remote_vars, (void *)remote_vars_pa,
576 XPC_RP_VARS_SIZE);
577 if (ret != xpSuccess)
578 return ret;
579
580 if (XPC_VERSION_MAJOR(remote_vars->version) !=
581 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
582 return xpBadVersion;
583 }
102 584
103 return xpSuccess; 585 return xpSuccess;
104} 586}
105 587
588static void
589xpc_initiate_partition_activation_sn2(struct xpc_rsvd_page *remote_rp,
590 u64 remote_rp_pa, int nasid)
591{
592 xpc_IPI_send_local_activate(nasid);
593}
594
595/*
596 * Update the remote partition's info.
597 */
598static void
599xpc_update_partition_info_sn2(struct xpc_partition *part, u8 remote_rp_version,
600 struct timespec *remote_rp_stamp,
601 u64 remote_rp_pa, u64 remote_vars_pa,
602 struct xpc_vars_sn2 *remote_vars)
603{
604 part->remote_rp_version = remote_rp_version;
605 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
606 part->remote_rp_version);
607
608 part->remote_rp_stamp = *remote_rp_stamp;
609 dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n",
610 part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
611
612 part->remote_rp_pa = remote_rp_pa;
613 dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa);
614
615 part->remote_vars_pa = remote_vars_pa;
616 dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
617 part->remote_vars_pa);
618
619 part->last_heartbeat = remote_vars->heartbeat;
620 dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
621 part->last_heartbeat);
622
623 part->remote_vars_part_pa = remote_vars->vars_part_pa;
624 dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n",
625 part->remote_vars_part_pa);
626
627 part->remote_act_nasid = remote_vars->act_nasid;
628 dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n",
629 part->remote_act_nasid);
630
631 part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid;
632 dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n",
633 part->remote_act_phys_cpuid);
634
635 part->remote_amos_page_pa = remote_vars->amos_page_pa;
636 dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n",
637 part->remote_amos_page_pa);
638
639 part->remote_vars_version = remote_vars->version;
640 dev_dbg(xpc_part, " remote_vars_version = 0x%x\n",
641 part->remote_vars_version);
642}
643
644/*
645 * Prior code has determined the nasid which generated an IPI. Inspect
646 * that nasid to determine if its partition needs to be activated or
647 * deactivated.
648 *
649 * A partition is consider "awaiting activation" if our partition
650 * flags indicate it is not active and it has a heartbeat. A
651 * partition is considered "awaiting deactivation" if our partition
652 * flags indicate it is active but it has no heartbeat or it is not
653 * sending its heartbeat to us.
654 *
655 * To determine the heartbeat, the remote nasid must have a properly
656 * initialized reserved page.
657 */
658static void
659xpc_identify_act_IRQ_req_sn2(int nasid)
660{
661 struct xpc_rsvd_page *remote_rp;
662 struct xpc_vars_sn2 *remote_vars;
663 u64 remote_rp_pa;
664 u64 remote_vars_pa;
665 int remote_rp_version;
666 int reactivate = 0;
667 int stamp_diff;
668 struct timespec remote_rp_stamp = { 0, 0 }; /*>>> ZERO_STAMP */
669 short partid;
670 struct xpc_partition *part;
671 enum xp_retval ret;
672
673 /* pull over the reserved page structure */
674
675 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
676
677 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
678 if (ret != xpSuccess) {
679 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
680 "which sent interrupt, reason=%d\n", nasid, ret);
681 return;
682 }
683
684 remote_vars_pa = remote_rp->sn.vars_pa;
685 remote_rp_version = remote_rp->version;
686 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
687 remote_rp_stamp = remote_rp->stamp;
688
689 partid = remote_rp->SAL_partid;
690 part = &xpc_partitions[partid];
691
692 /* pull over the cross partition variables */
693
694 remote_vars = (struct xpc_vars_sn2 *)xpc_remote_copy_buffer;
695
696 ret = xpc_get_remote_vars_sn2(remote_vars_pa, remote_vars);
697 if (ret != xpSuccess) {
698
699 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
700 "which sent interrupt, reason=%d\n", nasid, ret);
701
702 XPC_DEACTIVATE_PARTITION(part, ret);
703 return;
704 }
705
706 part->act_IRQ_rcvd++;
707
708 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
709 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
710 remote_vars->heartbeat, remote_vars->heartbeating_to_mask[0]);
711
712 if (xpc_partition_disengaged(part) &&
713 part->act_state == XPC_P_INACTIVE) {
714
715 xpc_update_partition_info_sn2(part, remote_rp_version,
716 &remote_rp_stamp, remote_rp_pa,
717 remote_vars_pa, remote_vars);
718
719 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
720 if (xpc_partition_disengage_requested(1UL << partid)) {
721 /*
722 * Other side is waiting on us to disengage,
723 * even though we already have.
724 */
725 return;
726 }
727
728 } else {
729 /* other side doesn't support disengage requests */
730 xpc_clear_partition_disengage_request(1UL << partid);
731 }
732
733 xpc_activate_partition(part);
734 return;
735 }
736
737 DBUG_ON(part->remote_rp_version == 0);
738 DBUG_ON(part->remote_vars_version == 0);
739
740 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
741 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
742 remote_vars_version));
743
744 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
745 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
746 version));
747 /* see if the other side rebooted */
748 if (part->remote_amos_page_pa ==
749 remote_vars->amos_page_pa &&
750 xpc_hb_allowed(sn_partition_id,
751 &remote_vars->heartbeating_to_mask)) {
752 /* doesn't look that way, so ignore the IPI */
753 return;
754 }
755 }
756
757 /*
758 * Other side rebooted and previous XPC didn't support the
759 * disengage request, so we don't need to do anything special.
760 */
761
762 xpc_update_partition_info_sn2(part, remote_rp_version,
763 &remote_rp_stamp, remote_rp_pa,
764 remote_vars_pa, remote_vars);
765 part->reactivate_nasid = nasid;
766 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
767 return;
768 }
769
770 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version));
771
772 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
773 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
774
775 /*
776 * Other side rebooted and previous XPC did support the
777 * disengage request, but the new one doesn't.
778 */
779
780 xpc_clear_partition_engaged(1UL << partid);
781 xpc_clear_partition_disengage_request(1UL << partid);
782
783 xpc_update_partition_info_sn2(part, remote_rp_version,
784 &remote_rp_stamp, remote_rp_pa,
785 remote_vars_pa, remote_vars);
786 reactivate = 1;
787
788 } else {
789 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
790
791 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
792 &remote_rp_stamp);
793 if (stamp_diff != 0) {
794 DBUG_ON(stamp_diff >= 0);
795
796 /*
797 * Other side rebooted and the previous XPC did support
798 * the disengage request, as does the new one.
799 */
800
801 DBUG_ON(xpc_partition_engaged(1UL << partid));
802 DBUG_ON(xpc_partition_disengage_requested(1UL <<
803 partid));
804
805 xpc_update_partition_info_sn2(part, remote_rp_version,
806 &remote_rp_stamp,
807 remote_rp_pa,
808 remote_vars_pa,
809 remote_vars);
810 reactivate = 1;
811 }
812 }
813
814 if (part->disengage_request_timeout > 0 &&
815 !xpc_partition_disengaged(part)) {
816 /* still waiting on other side to disengage from us */
817 return;
818 }
819
820 if (reactivate) {
821 part->reactivate_nasid = nasid;
822 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
823
824 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
825 xpc_partition_disengage_requested(1UL << partid)) {
826 XPC_DEACTIVATE_PARTITION(part, xpOtherGoingDown);
827 }
828}
829
830/*
831 * Loop through the activation AMO variables and process any bits
832 * which are set. Each bit indicates a nasid sending a partition
833 * activation or deactivation request.
834 *
835 * Return #of IRQs detected.
836 */
837int
838xpc_identify_act_IRQ_sender_sn2(void)
839{
840 int word, bit;
841 u64 nasid_mask;
842 u64 nasid; /* remote nasid */
843 int n_IRQs_detected = 0;
844 AMO_t *act_amos;
845
846 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
847
848 /* scan through act AMO variable looking for non-zero entries */
849 for (word = 0; word < xp_nasid_mask_words; word++) {
850
851 if (xpc_exiting)
852 break;
853
854 nasid_mask = xpc_IPI_receive_sn2(&act_amos[word]);
855 if (nasid_mask == 0) {
856 /* no IRQs from nasids in this variable */
857 continue;
858 }
859
860 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
861 nasid_mask);
862
863 /*
864 * If this nasid has been added to the machine since
865 * our partition was reset, this will retain the
866 * remote nasid in our reserved pages machine mask.
867 * This is used in the event of module reload.
868 */
869 xpc_mach_nasids[word] |= nasid_mask;
870
871 /* locate the nasid(s) which sent interrupts */
872
873 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
874 if (nasid_mask & (1UL << bit)) {
875 n_IRQs_detected++;
876 nasid = XPC_NASID_FROM_W_B(word, bit);
877 dev_dbg(xpc_part, "interrupt from nasid %ld\n",
878 nasid);
879 xpc_identify_act_IRQ_req_sn2(nasid);
880 }
881 }
882 }
883 return n_IRQs_detected;
884}
885
886static void
887xpc_process_act_IRQ_rcvd_sn2(int n_IRQs_expected)
888{
889 int n_IRQs_detected;
890
891 n_IRQs_detected = xpc_identify_act_IRQ_sender_sn2();
892 if (n_IRQs_detected < n_IRQs_expected) {
893 /* retry once to help avoid missing AMO */
894 (void)xpc_identify_act_IRQ_sender_sn2();
895 }
896}
897
106/* 898/*
107 * Setup the infrastructure necessary to support XPartition Communication 899 * Setup the infrastructure necessary to support XPartition Communication
108 * between the specified remote partition and the local one. 900 * between the specified remote partition and the local one.
@@ -177,7 +969,7 @@ xpc_setup_infrastructure_sn2(struct xpc_partition *part)
177 969
178 part->remote_openclose_args_pa = 0; 970 part->remote_openclose_args_pa = 0;
179 971
180 part->local_IPI_amo_va = xpc_IPI_init(partid); 972 part->local_IPI_amo_va = xpc_IPI_init_sn2(partid);
181 part->local_IPI_amo = 0; 973 part->local_IPI_amo = 0;
182 spin_lock_init(&part->IPI_lock); 974 spin_lock_init(&part->IPI_lock);
183 975
@@ -468,6 +1260,28 @@ xpc_make_first_contact_sn2(struct xpc_partition *part)
468{ 1260{
469 enum xp_retval ret; 1261 enum xp_retval ret;
470 1262
1263 /*
1264 * Register the remote partition's AMOs with SAL so it can handle
1265 * and cleanup errors within that address range should the remote
1266 * partition go down. We don't unregister this range because it is
1267 * difficult to tell when outstanding writes to the remote partition
1268 * are finished and thus when it is safe to unregister. This should
1269 * not result in wasted space in the SAL xp_addr_region table because
1270 * we should get the same page for remote_amos_page_pa after module
1271 * reloads and system reboots.
1272 */
1273 if (sn_register_xp_addr_region(part->remote_amos_page_pa,
1274 PAGE_SIZE, 1) < 0) {
1275 dev_warn(xpc_part, "xpc_activating(%d) failed to register "
1276 "xp_addr region\n", XPC_PARTID(part));
1277
1278 ret = xpPhysAddrRegFailed;
1279 XPC_DEACTIVATE_PARTITION(part, ret);
1280 return ret;
1281 }
1282
1283 xpc_IPI_send_activated(part);
1284
471 while ((ret = xpc_pull_remote_vars_part_sn2(part)) != xpSuccess) { 1285 while ((ret = xpc_pull_remote_vars_part_sn2(part)) != xpSuccess) {
472 if (ret != xpRetry) { 1286 if (ret != xpRetry) {
473 XPC_DEACTIVATE_PARTITION(part, ret); 1287 XPC_DEACTIVATE_PARTITION(part, ret);
@@ -651,15 +1465,370 @@ xpc_get_deliverable_msg_sn2(struct xpc_channel *ch)
651 return msg; 1465 return msg;
652} 1466}
653 1467
1468/*
1469 * Now we actually send the messages that are ready to be sent by advancing
1470 * the local message queue's Put value and then send an IPI to the recipient
1471 * partition.
1472 */
1473static void
1474xpc_send_msgs_sn2(struct xpc_channel *ch, s64 initial_put)
1475{
1476 struct xpc_msg *msg;
1477 s64 put = initial_put + 1;
1478 int send_IPI = 0;
1479
1480 while (1) {
1481
1482 while (1) {
1483 if (put == ch->w_local_GP.put)
1484 break;
1485
1486 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1487 (put % ch->local_nentries) *
1488 ch->msg_size);
1489
1490 if (!(msg->flags & XPC_M_READY))
1491 break;
1492
1493 put++;
1494 }
1495
1496 if (put == initial_put) {
1497 /* nothing's changed */
1498 break;
1499 }
1500
1501 if (cmpxchg_rel(&ch->local_GP->put, initial_put, put) !=
1502 initial_put) {
1503 /* someone else beat us to it */
1504 DBUG_ON(ch->local_GP->put < initial_put);
1505 break;
1506 }
1507
1508 /* we just set the new value of local_GP->put */
1509
1510 dev_dbg(xpc_chan, "local_GP->put changed to %ld, partid=%d, "
1511 "channel=%d\n", put, ch->partid, ch->number);
1512
1513 send_IPI = 1;
1514
1515 /*
1516 * We need to ensure that the message referenced by
1517 * local_GP->put is not XPC_M_READY or that local_GP->put
1518 * equals w_local_GP.put, so we'll go have a look.
1519 */
1520 initial_put = put;
1521 }
1522
1523 if (send_IPI)
1524 xpc_IPI_send_msgrequest_sn2(ch);
1525}
1526
1527/*
1528 * Allocate an entry for a message from the message queue associated with the
1529 * specified channel.
1530 */
1531static enum xp_retval
1532xpc_allocate_msg_sn2(struct xpc_channel *ch, u32 flags,
1533 struct xpc_msg **address_of_msg)
1534{
1535 struct xpc_msg *msg;
1536 enum xp_retval ret;
1537 s64 put;
1538
1539 /* this reference will be dropped in xpc_send_msg_sn2() */
1540 xpc_msgqueue_ref(ch);
1541
1542 if (ch->flags & XPC_C_DISCONNECTING) {
1543 xpc_msgqueue_deref(ch);
1544 return ch->reason;
1545 }
1546 if (!(ch->flags & XPC_C_CONNECTED)) {
1547 xpc_msgqueue_deref(ch);
1548 return xpNotConnected;
1549 }
1550
1551 /*
1552 * Get the next available message entry from the local message queue.
1553 * If none are available, we'll make sure that we grab the latest
1554 * GP values.
1555 */
1556 ret = xpTimeout;
1557
1558 while (1) {
1559
1560 put = ch->w_local_GP.put;
1561 rmb(); /* guarantee that .put loads before .get */
1562 if (put - ch->w_remote_GP.get < ch->local_nentries) {
1563
1564 /* There are available message entries. We need to try
1565 * to secure one for ourselves. We'll do this by trying
1566 * to increment w_local_GP.put as long as someone else
1567 * doesn't beat us to it. If they do, we'll have to
1568 * try again.
1569 */
1570 if (cmpxchg(&ch->w_local_GP.put, put, put + 1) == put) {
1571 /* we got the entry referenced by put */
1572 break;
1573 }
1574 continue; /* try again */
1575 }
1576
1577 /*
1578 * There aren't any available msg entries at this time.
1579 *
1580 * In waiting for a message entry to become available,
1581 * we set a timeout in case the other side is not
1582 * sending completion IPIs. This lets us fake an IPI
1583 * that will cause the IPI handler to fetch the latest
1584 * GP values as if an IPI was sent by the other side.
1585 */
1586 if (ret == xpTimeout)
1587 xpc_IPI_send_local_msgrequest_sn2(ch);
1588
1589 if (flags & XPC_NOWAIT) {
1590 xpc_msgqueue_deref(ch);
1591 return xpNoWait;
1592 }
1593
1594 ret = xpc_allocate_msg_wait(ch);
1595 if (ret != xpInterrupted && ret != xpTimeout) {
1596 xpc_msgqueue_deref(ch);
1597 return ret;
1598 }
1599 }
1600
1601 /* get the message's address and initialize it */
1602 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1603 (put % ch->local_nentries) * ch->msg_size);
1604
1605 DBUG_ON(msg->flags != 0);
1606 msg->number = put;
1607
1608 dev_dbg(xpc_chan, "w_local_GP.put changed to %ld; msg=0x%p, "
1609 "msg_number=%ld, partid=%d, channel=%d\n", put + 1,
1610 (void *)msg, msg->number, ch->partid, ch->number);
1611
1612 *address_of_msg = msg;
1613
1614 return xpSuccess;
1615}
1616
1617/*
1618 * Common code that does the actual sending of the message by advancing the
1619 * local message queue's Put value and sends an IPI to the partition the
1620 * message is being sent to.
1621 */
1622static enum xp_retval
1623xpc_send_msg_sn2(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1624 xpc_notify_func func, void *key)
1625{
1626 enum xp_retval ret = xpSuccess;
1627 struct xpc_notify *notify = notify;
1628 s64 put, msg_number = msg->number;
1629
1630 DBUG_ON(notify_type == XPC_N_CALL && func == NULL);
1631 DBUG_ON((((u64)msg - (u64)ch->local_msgqueue) / ch->msg_size) !=
1632 msg_number % ch->local_nentries);
1633 DBUG_ON(msg->flags & XPC_M_READY);
1634
1635 if (ch->flags & XPC_C_DISCONNECTING) {
1636 /* drop the reference grabbed in xpc_allocate_msg_sn2() */
1637 xpc_msgqueue_deref(ch);
1638 return ch->reason;
1639 }
1640
1641 if (notify_type != 0) {
1642 /*
1643 * Tell the remote side to send an ACK interrupt when the
1644 * message has been delivered.
1645 */
1646 msg->flags |= XPC_M_INTERRUPT;
1647
1648 atomic_inc(&ch->n_to_notify);
1649
1650 notify = &ch->notify_queue[msg_number % ch->local_nentries];
1651 notify->func = func;
1652 notify->key = key;
1653 notify->type = notify_type;
1654
1655 /* >>> is a mb() needed here? */
1656
1657 if (ch->flags & XPC_C_DISCONNECTING) {
1658 /*
1659 * An error occurred between our last error check and
1660 * this one. We will try to clear the type field from
1661 * the notify entry. If we succeed then
1662 * xpc_disconnect_channel() didn't already process
1663 * the notify entry.
1664 */
1665 if (cmpxchg(&notify->type, notify_type, 0) ==
1666 notify_type) {
1667 atomic_dec(&ch->n_to_notify);
1668 ret = ch->reason;
1669 }
1670
1671 /* drop reference grabbed in xpc_allocate_msg_sn2() */
1672 xpc_msgqueue_deref(ch);
1673 return ret;
1674 }
1675 }
1676
1677 msg->flags |= XPC_M_READY;
1678
1679 /*
1680 * The preceding store of msg->flags must occur before the following
1681 * load of ch->local_GP->put.
1682 */
1683 mb();
1684
1685 /* see if the message is next in line to be sent, if so send it */
1686
1687 put = ch->local_GP->put;
1688 if (put == msg_number)
1689 xpc_send_msgs_sn2(ch, put);
1690
1691 /* drop the reference grabbed in xpc_allocate_msg_sn2() */
1692 xpc_msgqueue_deref(ch);
1693 return ret;
1694}
1695
1696/*
1697 * Now we actually acknowledge the messages that have been delivered and ack'd
1698 * by advancing the cached remote message queue's Get value and if requested
1699 * send an IPI to the message sender's partition.
1700 */
1701static void
1702xpc_acknowledge_msgs_sn2(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
1703{
1704 struct xpc_msg *msg;
1705 s64 get = initial_get + 1;
1706 int send_IPI = 0;
1707
1708 while (1) {
1709
1710 while (1) {
1711 if (get == ch->w_local_GP.get)
1712 break;
1713
1714 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue +
1715 (get % ch->remote_nentries) *
1716 ch->msg_size);
1717
1718 if (!(msg->flags & XPC_M_DONE))
1719 break;
1720
1721 msg_flags |= msg->flags;
1722 get++;
1723 }
1724
1725 if (get == initial_get) {
1726 /* nothing's changed */
1727 break;
1728 }
1729
1730 if (cmpxchg_rel(&ch->local_GP->get, initial_get, get) !=
1731 initial_get) {
1732 /* someone else beat us to it */
1733 DBUG_ON(ch->local_GP->get <= initial_get);
1734 break;
1735 }
1736
1737 /* we just set the new value of local_GP->get */
1738
1739 dev_dbg(xpc_chan, "local_GP->get changed to %ld, partid=%d, "
1740 "channel=%d\n", get, ch->partid, ch->number);
1741
1742 send_IPI = (msg_flags & XPC_M_INTERRUPT);
1743
1744 /*
1745 * We need to ensure that the message referenced by
1746 * local_GP->get is not XPC_M_DONE or that local_GP->get
1747 * equals w_local_GP.get, so we'll go have a look.
1748 */
1749 initial_get = get;
1750 }
1751
1752 if (send_IPI)
1753 xpc_IPI_send_msgrequest_sn2(ch);
1754}
1755
1756static void
1757xpc_received_msg_sn2(struct xpc_channel *ch, struct xpc_msg *msg)
1758{
1759 s64 get;
1760 s64 msg_number = msg->number;
1761
1762 dev_dbg(xpc_chan, "msg=0x%p, msg_number=%ld, partid=%d, channel=%d\n",
1763 (void *)msg, msg_number, ch->partid, ch->number);
1764
1765 DBUG_ON((((u64)msg - (u64)ch->remote_msgqueue) / ch->msg_size) !=
1766 msg_number % ch->remote_nentries);
1767 DBUG_ON(msg->flags & XPC_M_DONE);
1768
1769 msg->flags |= XPC_M_DONE;
1770
1771 /*
1772 * The preceding store of msg->flags must occur before the following
1773 * load of ch->local_GP->get.
1774 */
1775 mb();
1776
1777 /*
1778 * See if this message is next in line to be acknowledged as having
1779 * been delivered.
1780 */
1781 get = ch->local_GP->get;
1782 if (get == msg_number)
1783 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
1784}
1785
654void 1786void
655xpc_init_sn2(void) 1787xpc_init_sn2(void)
656{ 1788{
657 xpc_rsvd_page_init = xpc_rsvd_page_init_sn2; 1789 xpc_rsvd_page_init = xpc_rsvd_page_init_sn2;
1790 xpc_increment_heartbeat = xpc_increment_heartbeat_sn2;
1791 xpc_offline_heartbeat = xpc_offline_heartbeat_sn2;
1792 xpc_online_heartbeat = xpc_online_heartbeat_sn2;
1793 xpc_heartbeat_init = xpc_heartbeat_init_sn2;
1794 xpc_heartbeat_exit = xpc_heartbeat_exit_sn2;
1795 xpc_check_remote_hb = xpc_check_remote_hb_sn2;
1796
1797 xpc_initiate_partition_activation =
1798 xpc_initiate_partition_activation_sn2;
1799 xpc_process_act_IRQ_rcvd = xpc_process_act_IRQ_rcvd_sn2;
658 xpc_setup_infrastructure = xpc_setup_infrastructure_sn2; 1800 xpc_setup_infrastructure = xpc_setup_infrastructure_sn2;
659 xpc_teardown_infrastructure = xpc_teardown_infrastructure_sn2; 1801 xpc_teardown_infrastructure = xpc_teardown_infrastructure_sn2;
660 xpc_make_first_contact = xpc_make_first_contact_sn2; 1802 xpc_make_first_contact = xpc_make_first_contact_sn2;
661 xpc_get_IPI_flags = xpc_get_IPI_flags_sn2; 1803 xpc_get_IPI_flags = xpc_get_IPI_flags_sn2;
662 xpc_get_deliverable_msg = xpc_get_deliverable_msg_sn2; 1804 xpc_get_deliverable_msg = xpc_get_deliverable_msg_sn2;
1805
1806 xpc_mark_partition_engaged = xpc_mark_partition_engaged_sn2;
1807 xpc_mark_partition_disengaged = xpc_mark_partition_disengaged_sn2;
1808 xpc_request_partition_disengage = xpc_request_partition_disengage_sn2;
1809 xpc_cancel_partition_disengage_request =
1810 xpc_cancel_partition_disengage_request_sn2;
1811 xpc_partition_engaged = xpc_partition_engaged_sn2;
1812 xpc_partition_disengage_requested =
1813 xpc_partition_disengage_requested_sn2;
1814 xpc_clear_partition_engaged = xpc_clear_partition_engaged_sn2;
1815 xpc_clear_partition_disengage_request =
1816 xpc_clear_partition_disengage_request_sn2;
1817
1818 xpc_IPI_send_local_activate = xpc_IPI_send_local_activate_sn2;
1819 xpc_IPI_send_activated = xpc_IPI_send_activated_sn2;
1820 xpc_IPI_send_local_reactivate = xpc_IPI_send_local_reactivate_sn2;
1821 xpc_IPI_send_disengage = xpc_IPI_send_disengage_sn2;
1822
1823 xpc_IPI_send_closerequest = xpc_IPI_send_closerequest_sn2;
1824 xpc_IPI_send_closereply = xpc_IPI_send_closereply_sn2;
1825 xpc_IPI_send_openrequest = xpc_IPI_send_openrequest_sn2;
1826 xpc_IPI_send_openreply = xpc_IPI_send_openreply_sn2;
1827
1828 xpc_allocate_msg = xpc_allocate_msg_sn2;
1829
1830 xpc_send_msg = xpc_send_msg_sn2;
1831 xpc_received_msg = xpc_received_msg_sn2;
663} 1832}
664 1833
665void 1834void
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index 770f0a8c669..32c577b8d0d 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -19,15 +19,22 @@
19/* >>> uv_gpa() is defined in <gru/grukservices.h> */ 19/* >>> uv_gpa() is defined in <gru/grukservices.h> */
20#define uv_gpa(_a) ((unsigned long)_a) 20#define uv_gpa(_a) ((unsigned long)_a)
21 21
22/* >>> temporarily define next three items for xpc.h */
23#define SGI_XPC_ACTIVATE 23
24#define SGI_XPC_NOTIFY 24
25#define sn_send_IPI_phys(_a, _b, _c, _d)
26
27#include "xpc.h" 22#include "xpc.h"
28 23
24static DECLARE_BITMAP(xpc_heartbeating_to_mask_uv, XP_MAX_NPARTITIONS_UV);
25
29static void *xpc_activate_mq; 26static void *xpc_activate_mq;
30 27
28static void
29xpc_IPI_send_local_activate_uv(struct xpc_partition *part)
30{
31 /*
32 * >>> make our side think that the remote parition sent an activate
33 * >>> message our way. Also do what the activate IRQ handler would
34 * >>> do had one really been sent.
35 */
36}
37
31static enum xp_retval 38static enum xp_retval
32xpc_rsvd_page_init_uv(struct xpc_rsvd_page *rp) 39xpc_rsvd_page_init_uv(struct xpc_rsvd_page *rp)
33{ 40{
@@ -36,6 +43,41 @@ xpc_rsvd_page_init_uv(struct xpc_rsvd_page *rp)
36 return xpSuccess; 43 return xpSuccess;
37} 44}
38 45
46static void
47xpc_increment_heartbeat_uv(void)
48{
49 /* >>> send heartbeat msg to xpc_heartbeating_to_mask partids */
50}
51
52static void
53xpc_heartbeat_init_uv(void)
54{
55 bitmap_zero(xpc_heartbeating_to_mask_uv, XP_MAX_NPARTITIONS_UV);
56 xpc_heartbeating_to_mask = &xpc_heartbeating_to_mask_uv[0];
57}
58
59static void
60xpc_heartbeat_exit_uv(void)
61{
62 /* >>> send heartbeat_offline msg to xpc_heartbeating_to_mask partids */
63}
64
65static void
66xpc_initiate_partition_activation_uv(struct xpc_rsvd_page *remote_rp,
67 u64 remote_rp_pa, int nasid)
68{
69 short partid = remote_rp->SAL_partid;
70 struct xpc_partition *part = &xpc_partitions[partid];
71
72/*
73 * >>> setup part structure with the bits of info we can glean from the rp
74 * >>> part->remote_rp_pa = remote_rp_pa;
75 * >>> part->sn.uv.activate_mq_gpa = remote_rp->sn.activate_mq_gpa;
76 */
77
78 xpc_IPI_send_local_activate_uv(part);
79}
80
39/* 81/*
40 * Setup the infrastructure necessary to support XPartition Communication 82 * Setup the infrastructure necessary to support XPartition Communication
41 * between the specified remote partition and the local one. 83 * between the specified remote partition and the local one.
@@ -83,6 +125,11 @@ void
83xpc_init_uv(void) 125xpc_init_uv(void)
84{ 126{
85 xpc_rsvd_page_init = xpc_rsvd_page_init_uv; 127 xpc_rsvd_page_init = xpc_rsvd_page_init_uv;
128 xpc_increment_heartbeat = xpc_increment_heartbeat_uv;
129 xpc_heartbeat_init = xpc_heartbeat_init_uv;
130 xpc_heartbeat_exit = xpc_heartbeat_exit_uv;
131 xpc_initiate_partition_activation =
132 xpc_initiate_partition_activation_uv;
86 xpc_setup_infrastructure = xpc_setup_infrastructure_uv; 133 xpc_setup_infrastructure = xpc_setup_infrastructure_uv;
87 xpc_teardown_infrastructure = xpc_teardown_infrastructure_uv; 134 xpc_teardown_infrastructure = xpc_teardown_infrastructure_uv;
88 xpc_make_first_contact = xpc_make_first_contact_uv; 135 xpc_make_first_contact = xpc_make_first_contact_uv;