4 * Peer-to-peer transcendent memory
6 * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
13 * format of remote pampd:
15 * bit 1 == is_remote... if this bit is set, then
16 * bit 2-9 == remotenode
20 #define FAKE_PAMPD_INTRANSIT_BITS 1
21 #define FAKE_PAMPD_ISREMOTE_BITS 1
22 #define FAKE_PAMPD_REMOTENODE_BITS 8
23 #define FAKE_PAMPD_REMOTESIZE_BITS 13
24 #define FAKE_PAMPD_CHECKSUM_BITS 8
26 #define FAKE_PAMPD_INTRANSIT_SHIFT 0
27 #define FAKE_PAMPD_ISREMOTE_SHIFT (FAKE_PAMPD_INTRANSIT_SHIFT + \
28 FAKE_PAMPD_INTRANSIT_BITS)
29 #define FAKE_PAMPD_REMOTENODE_SHIFT (FAKE_PAMPD_ISREMOTE_SHIFT + \
30 FAKE_PAMPD_ISREMOTE_BITS)
31 #define FAKE_PAMPD_REMOTESIZE_SHIFT (FAKE_PAMPD_REMOTENODE_SHIFT + \
32 FAKE_PAMPD_REMOTENODE_BITS)
33 #define FAKE_PAMPD_CHECKSUM_SHIFT (FAKE_PAMPD_REMOTESIZE_SHIFT + \
34 FAKE_PAMPD_REMOTESIZE_BITS)
36 #define FAKE_PAMPD_MASK(x) ((1UL << (x)) - 1)
38 static inline void *pampd_make_remote(int remotenode
, size_t size
,
41 unsigned long fake_pampd
= 0;
42 fake_pampd
|= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT
;
43 fake_pampd
|= ((unsigned long)remotenode
&
44 FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS
)) <<
45 FAKE_PAMPD_REMOTENODE_SHIFT
;
46 fake_pampd
|= ((unsigned long)size
&
47 FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS
)) <<
48 FAKE_PAMPD_REMOTESIZE_SHIFT
;
49 fake_pampd
|= ((unsigned long)cksum
&
50 FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS
)) <<
51 FAKE_PAMPD_CHECKSUM_SHIFT
;
52 return (void *)fake_pampd
;
55 static inline unsigned int pampd_remote_node(void *pampd
)
57 unsigned long fake_pampd
= (unsigned long)pampd
;
58 return (fake_pampd
>> FAKE_PAMPD_REMOTENODE_SHIFT
) &
59 FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTENODE_BITS
);
62 static inline unsigned int pampd_remote_size(void *pampd
)
64 unsigned long fake_pampd
= (unsigned long)pampd
;
65 return (fake_pampd
>> FAKE_PAMPD_REMOTESIZE_SHIFT
) &
66 FAKE_PAMPD_MASK(FAKE_PAMPD_REMOTESIZE_BITS
);
69 static inline unsigned char pampd_remote_cksum(void *pampd
)
71 unsigned long fake_pampd
= (unsigned long)pampd
;
72 return (fake_pampd
>> FAKE_PAMPD_CHECKSUM_SHIFT
) &
73 FAKE_PAMPD_MASK(FAKE_PAMPD_CHECKSUM_BITS
);
76 static inline bool pampd_is_remote(void *pampd
)
78 unsigned long fake_pampd
= (unsigned long)pampd
;
79 return (fake_pampd
>> FAKE_PAMPD_ISREMOTE_SHIFT
) &
80 FAKE_PAMPD_MASK(FAKE_PAMPD_ISREMOTE_BITS
);
83 static inline bool pampd_is_intransit(void *pampd
)
85 unsigned long fake_pampd
= (unsigned long)pampd
;
86 return (fake_pampd
>> FAKE_PAMPD_INTRANSIT_SHIFT
) &
87 FAKE_PAMPD_MASK(FAKE_PAMPD_INTRANSIT_BITS
);
90 /* note that it is a BUG for intransit to be set without isremote also set */
91 static inline void *pampd_mark_intransit(void *pampd
)
93 unsigned long fake_pampd
= (unsigned long)pampd
;
95 fake_pampd
|= 1UL << FAKE_PAMPD_ISREMOTE_SHIFT
;
96 fake_pampd
|= 1UL << FAKE_PAMPD_INTRANSIT_SHIFT
;
97 return (void *)fake_pampd
;
100 static inline void *pampd_mask_intransit_and_remote(void *marked_pampd
)
102 unsigned long pampd
= (unsigned long)marked_pampd
;
104 pampd
&= ~(1UL << FAKE_PAMPD_INTRANSIT_SHIFT
);
105 pampd
&= ~(1UL << FAKE_PAMPD_ISREMOTE_SHIFT
);
106 return (void *)pampd
;
109 extern int ramster_remote_async_get(struct tmem_xhandle
*,
110 bool, int, size_t, uint8_t, void *extra
);
111 extern int ramster_remote_put(struct tmem_xhandle
*, char *, size_t,
113 extern int ramster_remote_flush(struct tmem_xhandle
*, int);
114 extern int ramster_remote_flush_object(struct tmem_xhandle
*, int);
115 extern int r2net_register_handlers(void);
116 extern int r2net_remote_target_node_set(int);