#else
# include <portals/list.h>
# include <string.h>
+# include <pthread.h>
#endif
#include <portals/types.h>
#include <linux/kp30.h>
#include <portals/p30.h>
+#include <portals/nal.h>
#include <portals/lib-types.h>
-#include <portals/lib-nal.h>
-#include <portals/lib-dispatch.h>
static inline int ptl_is_wire_handle_none (ptl_handle_wire_t *wh)
{
wh->wh_object_cookie == PTL_WIRE_HANDLE_NONE.wh_object_cookie);
}
-#define state_lock(nal,flagsp) \
-do { \
- CDEBUG(D_PORTALS, "taking state lock\n"); \
- nal->cb_cli(nal, flagsp); \
-} while (0)
+#ifdef __KERNEL__
+#define LIB_LOCK(nal,flags) \
+ spin_lock_irqsave(&(nal)->libnal_ni.ni_lock, flags)
+#define LIB_UNLOCK(nal,flags) \
+ spin_unlock_irqrestore(&(nal)->libnal_ni.ni_lock, flags)
+#else
+#define LIB_LOCK(nal,flags) \
+ (pthread_mutex_lock(&(nal)->libnal_ni.ni_mutex), (flags) = 0)
+#define LIB_UNLOCK(nal,flags) \
+ pthread_mutex_unlock(&(nal)->libnal_ni.ni_mutex)
+#endif
-#define state_unlock(nal,flagsp) \
-{ \
- CDEBUG(D_PORTALS, "releasing state lock\n"); \
- nal->cb_sti(nal, flagsp); \
-}
#ifdef PTL_USE_LIB_FREELIST
#define MAX_MSGS 2048 /* Outstanding messages */
#define MAX_EQS 512
-extern int lib_freelist_init (nal_cb_t *nal, lib_freelist_t *fl, int nobj, int objsize);
-extern void lib_freelist_fini (nal_cb_t *nal, lib_freelist_t *fl);
+extern int lib_freelist_init (lib_nal_t *nal, lib_freelist_t *fl, int nobj, int objsize);
+extern void lib_freelist_fini (lib_nal_t *nal, lib_freelist_t *fl);
static inline void *
lib_freelist_alloc (lib_freelist_t *fl)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_freeobj_t *o;
if (list_empty (&fl->fl_list))
static inline void
lib_freelist_free (lib_freelist_t *fl, void *obj)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_freeobj_t *o = list_entry (obj, lib_freeobj_t, fo_contents);
list_add (&o->fo_list, &fl->fl_list);
static inline lib_eq_t *
-lib_eq_alloc (nal_cb_t *nal)
+lib_eq_alloc (lib_nal_t *nal)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
unsigned long flags;
lib_eq_t *eq;
- state_lock (nal, &flags);
- eq = (lib_eq_t *)lib_freelist_alloc (&nal->ni.ni_free_eqs);
- state_unlock (nal, &flags);
+ LIB_LOCK (nal, flags);
+ eq = (lib_eq_t *)lib_freelist_alloc (&nal->libnal_ni.ni_free_eqs);
+ LIB_UNLOCK (nal, flags);
return (eq);
}
static inline void
-lib_eq_free (nal_cb_t *nal, lib_eq_t *eq)
+lib_eq_free (lib_nal_t *nal, lib_eq_t *eq)
{
- /* ALWAYS called with statelock held */
- lib_freelist_free (&nal->ni.ni_free_eqs, eq);
+ /* ALWAYS called with liblock held */
+ lib_freelist_free (&nal->libnal_ni.ni_free_eqs, eq);
}
static inline lib_md_t *
-lib_md_alloc (nal_cb_t *nal, ptl_md_t *umd)
+lib_md_alloc (lib_nal_t *nal, ptl_md_t *umd)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
unsigned long flags;
lib_md_t *md;
- state_lock (nal, &flags);
- md = (lib_md_t *)lib_freelist_alloc (&nal->ni.ni_free_mds);
- state_unlock (nal, &flags);
+ LIB_LOCK (nal, flags);
+ md = (lib_md_t *)lib_freelist_alloc (&nal->libnal_ni.ni_free_mds);
+ LIB_UNLOCK (nal, flags);
return (md);
}
static inline void
-lib_md_free (nal_cb_t *nal, lib_md_t *md)
+lib_md_free (lib_nal_t *nal, lib_md_t *md)
{
- /* ALWAYS called with statelock held */
- lib_freelist_free (&nal->ni.ni_free_mds, md);
+ /* ALWAYS called with liblock held */
+ lib_freelist_free (&nal->libnal_ni.ni_free_mds, md);
}
static inline lib_me_t *
-lib_me_alloc (nal_cb_t *nal)
+lib_me_alloc (lib_nal_t *nal)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
unsigned long flags;
lib_me_t *me;
- state_lock (nal, &flags);
- me = (lib_me_t *)lib_freelist_alloc (&nal->ni.ni_free_mes);
- state_unlock (nal, &flags);
+ LIB_LOCK (nal, flags);
+ me = (lib_me_t *)lib_freelist_alloc (&nal->libnal_ni.ni_free_mes);
+ LIB_UNLOCK (nal, flags);
return (me);
}
static inline void
-lib_me_free (nal_cb_t *nal, lib_me_t *me)
+lib_me_free (lib_nal_t *nal, lib_me_t *me)
{
- /* ALWAYS called with statelock held */
- lib_freelist_free (&nal->ni.ni_free_mes, me);
+ /* ALWAYS called with liblock held */
+ lib_freelist_free (&nal->libnal_ni.ni_free_mes, me);
}
static inline lib_msg_t *
-lib_msg_alloc (nal_cb_t *nal)
+lib_msg_alloc (lib_nal_t *nal)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
unsigned long flags;
lib_msg_t *msg;
- state_lock (nal, &flags);
- msg = (lib_msg_t *)lib_freelist_alloc (&nal->ni.ni_free_msgs);
- state_unlock (nal, &flags);
+ LIB_LOCK (nal, flags);
+ msg = (lib_msg_t *)lib_freelist_alloc (&nal->libnal_ni.ni_free_msgs);
+ LIB_UNLOCK (nal, flags);
if (msg != NULL) {
/* NULL pointers, clear flags etc */
}
static inline void
-lib_msg_free (nal_cb_t *nal, lib_msg_t *msg)
+lib_msg_free (lib_nal_t *nal, lib_msg_t *msg)
{
- /* ALWAYS called with statelock held */
- lib_freelist_free (&nal->ni.ni_free_msgs, msg);
+ /* ALWAYS called with liblock held */
+ lib_freelist_free (&nal->libnal_ni.ni_free_msgs, msg);
}
#else
static inline lib_eq_t *
-lib_eq_alloc (nal_cb_t *nal)
+lib_eq_alloc (lib_nal_t *nal)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
lib_eq_t *eq;
PORTAL_ALLOC(eq, sizeof(*eq));
}
static inline void
-lib_eq_free (nal_cb_t *nal, lib_eq_t *eq)
+lib_eq_free (lib_nal_t *nal, lib_eq_t *eq)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
PORTAL_FREE(eq, sizeof(*eq));
}
static inline lib_md_t *
-lib_md_alloc (nal_cb_t *nal, ptl_md_t *umd)
+lib_md_alloc (lib_nal_t *nal, ptl_md_t *umd)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
lib_md_t *md;
int size;
int niov;
}
static inline void
-lib_md_free (nal_cb_t *nal, lib_md_t *md)
+lib_md_free (lib_nal_t *nal, lib_md_t *md)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
int size;
if ((md->options & PTL_MD_KIOV) != 0)
}
static inline lib_me_t *
-lib_me_alloc (nal_cb_t *nal)
+lib_me_alloc (lib_nal_t *nal)
{
- /* NEVER called with statelock held */
+ /* NEVER called with liblock held */
lib_me_t *me;
PORTAL_ALLOC(me, sizeof(*me));
}
static inline void
-lib_me_free(nal_cb_t *nal, lib_me_t *me)
+lib_me_free(lib_nal_t *nal, lib_me_t *me)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
PORTAL_FREE(me, sizeof(*me));
}
static inline lib_msg_t *
-lib_msg_alloc(nal_cb_t *nal)
+lib_msg_alloc(lib_nal_t *nal)
{
- /* NEVER called with statelock held; may be in interrupt... */
+ /* NEVER called with liblock held; may be in interrupt... */
lib_msg_t *msg;
if (in_interrupt())
}
static inline void
-lib_msg_free(nal_cb_t *nal, lib_msg_t *msg)
+lib_msg_free(lib_nal_t *nal, lib_msg_t *msg)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
PORTAL_FREE(msg, sizeof(*msg));
}
#endif
-extern lib_handle_t *lib_lookup_cookie (nal_cb_t *nal, __u64 cookie, int type);
-extern void lib_initialise_handle (nal_cb_t *nal, lib_handle_t *lh, int type);
-extern void lib_invalidate_handle (nal_cb_t *nal, lib_handle_t *lh);
+extern lib_handle_t *lib_lookup_cookie (lib_nal_t *nal, __u64 cookie, int type);
+extern void lib_initialise_handle (lib_nal_t *nal, lib_handle_t *lh, int type);
+extern void lib_invalidate_handle (lib_nal_t *nal, lib_handle_t *lh);
static inline void
-ptl_eq2handle (ptl_handle_eq_t *handle, lib_eq_t *eq)
+ptl_eq2handle (ptl_handle_eq_t *handle, lib_nal_t *nal, lib_eq_t *eq)
{
+ handle->nal_idx = nal->libnal_ni.ni_api->nal_handle.nal_idx;
handle->cookie = eq->eq_lh.lh_cookie;
}
static inline lib_eq_t *
-ptl_handle2eq (ptl_handle_eq_t *handle, nal_cb_t *nal)
+ptl_handle2eq (ptl_handle_eq_t *handle, lib_nal_t *nal)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
PTL_COOKIE_TYPE_EQ);
if (lh == NULL)
}
static inline void
-ptl_md2handle (ptl_handle_md_t *handle, lib_md_t *md)
+ptl_md2handle (ptl_handle_md_t *handle, lib_nal_t *nal, lib_md_t *md)
{
+ handle->nal_idx = nal->libnal_ni.ni_api->nal_handle.nal_idx;
handle->cookie = md->md_lh.lh_cookie;
}
static inline lib_md_t *
-ptl_handle2md (ptl_handle_md_t *handle, nal_cb_t *nal)
+ptl_handle2md (ptl_handle_md_t *handle, lib_nal_t *nal)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
PTL_COOKIE_TYPE_MD);
if (lh == NULL)
}
static inline lib_md_t *
-ptl_wire_handle2md (ptl_handle_wire_t *wh, nal_cb_t *nal)
+ptl_wire_handle2md (ptl_handle_wire_t *wh, lib_nal_t *nal)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_handle_t *lh;
- if (wh->wh_interface_cookie != nal->ni.ni_interface_cookie)
+ if (wh->wh_interface_cookie != nal->libnal_ni.ni_interface_cookie)
return (NULL);
lh = lib_lookup_cookie (nal, wh->wh_object_cookie,
}
static inline void
-ptl_me2handle (ptl_handle_me_t *handle, lib_me_t *me)
+ptl_me2handle (ptl_handle_me_t *handle, lib_nal_t *nal, lib_me_t *me)
{
+ handle->nal_idx = nal->libnal_ni.ni_api->nal_handle.nal_idx;
handle->cookie = me->me_lh.lh_cookie;
}
static inline lib_me_t *
-ptl_handle2me (ptl_handle_me_t *handle, nal_cb_t *nal)
+ptl_handle2me (ptl_handle_me_t *handle, lib_nal_t *nal)
{
- /* ALWAYS called with statelock held */
+ /* ALWAYS called with liblock held */
lib_handle_t *lh = lib_lookup_cookie (nal, handle->cookie,
PTL_COOKIE_TYPE_ME);
if (lh == NULL)
return (lh_entry (lh, lib_me_t, me_lh));
}
-extern int lib_init(nal_cb_t *cb, ptl_process_id_t pid,
+extern int lib_init(lib_nal_t *libnal, nal_t *apinal,
+ ptl_process_id_t pid,
ptl_ni_limits_t *desired_limits,
ptl_ni_limits_t *actual_limits);
-extern int lib_fini(nal_cb_t * cb);
-extern void lib_dispatch(nal_cb_t * cb, void *private, int index,
- void *arg_block, void *ret_block);
-extern char *dispatch_name(int index);
+extern int lib_fini(lib_nal_t *libnal);
/*
- * When the NAL detects an incoming message, it should call
- * lib_parse() decode it. The NAL callbacks will be handed
- * the private cookie as a way for the NAL to maintain state
- * about which transaction is being processed. An extra parameter,
- * lib_cookie will contain the necessary information for
- * finalizing the message.
- *
- * After it has finished the handling the message, it should
- * call lib_finalize() with the lib_cookie parameter.
- * Call backs will be made to write events, send acks or
- * replies and so on.
+ * When the NAL detects an incoming message header, it should call
+ * lib_parse() decode it. If the message header is garbage, lib_parse()
+ * returns immediately with failure, otherwise the NAL callbacks will be
+ * called to receive the message body. They are handed the private cookie
+ * as a way for the NAL to maintain state about which transaction is being
+ * processed. An extra parameter, lib_msg contains the lib-level message
+ * state for passing to lib_finalize() when the message body has been
+ * received.
*/
-extern void lib_enq_event_locked (nal_cb_t *nal, void *private,
+extern void lib_enq_event_locked (lib_nal_t *nal, void *private,
lib_eq_t *eq, ptl_event_t *ev);
-extern void lib_finalize (nal_cb_t *nal, void *private, lib_msg_t *msg,
+extern void lib_finalize (lib_nal_t *nal, void *private, lib_msg_t *msg,
ptl_ni_fail_t ni_fail_type);
-extern void lib_parse (nal_cb_t *nal, ptl_hdr_t *hdr, void *private);
-extern lib_msg_t *lib_create_reply_msg (nal_cb_t *nal, ptl_nid_t peer_nid,
+extern ptl_err_t lib_parse (lib_nal_t *nal, ptl_hdr_t *hdr, void *private);
+extern lib_msg_t *lib_create_reply_msg (lib_nal_t *nal, ptl_nid_t peer_nid,
lib_msg_t *get_msg);
-extern void print_hdr (nal_cb_t * nal, ptl_hdr_t * hdr);
+extern void print_hdr (lib_nal_t * nal, ptl_hdr_t * hdr);
extern ptl_size_t lib_iov_nob (int niov, struct iovec *iov);
extern void lib_assert_wire_constants (void);
-extern ptl_err_t lib_recv (nal_cb_t *nal, void *private, lib_msg_t *msg, lib_md_t *md,
+extern ptl_err_t lib_recv (lib_nal_t *nal, void *private, lib_msg_t *msg, lib_md_t *md,
ptl_size_t offset, ptl_size_t mlen, ptl_size_t rlen);
-extern ptl_err_t lib_send (nal_cb_t *nal, void *private, lib_msg_t *msg,
+extern ptl_err_t lib_send (lib_nal_t *nal, void *private, lib_msg_t *msg,
ptl_hdr_t *hdr, int type, ptl_nid_t nid, ptl_pid_t pid,
lib_md_t *md, ptl_size_t offset, ptl_size_t len);
-extern void lib_md_deconstruct(nal_cb_t * nal, lib_md_t * md_in,
- ptl_md_t * md_out);
-extern void lib_md_unlink(nal_cb_t * nal, lib_md_t * md_in);
-extern void lib_me_unlink(nal_cb_t * nal, lib_me_t * me_in);
+extern int lib_api_ni_status (nal_t *nal, ptl_sr_index_t sr_idx,
+ ptl_sr_value_t *status);
+extern int lib_api_ni_dist (nal_t *nal, ptl_process_id_t *pid,
+ unsigned long *dist);
+
+extern int lib_api_eq_alloc (nal_t *nal, ptl_size_t count,
+ ptl_eq_handler_t callback,
+ ptl_handle_eq_t *handle);
+extern int lib_api_eq_free(nal_t *nal, ptl_handle_eq_t *eqh);
+extern int lib_api_eq_poll (nal_t *nal,
+ ptl_handle_eq_t *eventqs, int neq, int timeout_ms,
+ ptl_event_t *event, int *which);
+
+extern int lib_api_me_attach(nal_t *nal,
+ ptl_pt_index_t portal,
+ ptl_process_id_t match_id,
+ ptl_match_bits_t match_bits,
+ ptl_match_bits_t ignore_bits,
+ ptl_unlink_t unlink, ptl_ins_pos_t pos,
+ ptl_handle_me_t *handle);
+extern int lib_api_me_insert(nal_t *nal,
+ ptl_handle_me_t *current_meh,
+ ptl_process_id_t match_id,
+ ptl_match_bits_t match_bits,
+ ptl_match_bits_t ignore_bits,
+ ptl_unlink_t unlink, ptl_ins_pos_t pos,
+ ptl_handle_me_t *handle);
+extern int lib_api_me_unlink (nal_t *nal, ptl_handle_me_t *meh);
+extern void lib_me_unlink(lib_nal_t *nal, lib_me_t *me);
+
+extern int lib_api_get_id(nal_t *nal, ptl_process_id_t *pid);
+
+extern void lib_md_unlink(lib_nal_t *nal, lib_md_t *md);
+extern void lib_md_deconstruct(lib_nal_t *nal, lib_md_t *lmd, ptl_md_t *umd);
+extern int lib_api_md_attach(nal_t *nal, ptl_handle_me_t *meh,
+ ptl_md_t *umd, ptl_unlink_t unlink,
+ ptl_handle_md_t *handle);
+extern int lib_api_md_bind(nal_t *nal, ptl_md_t *umd, ptl_unlink_t unlink,
+ ptl_handle_md_t *handle);
+extern int lib_api_md_unlink (nal_t *nal, ptl_handle_md_t *mdh);
+extern int lib_api_md_update (nal_t *nal, ptl_handle_md_t *mdh,
+ ptl_md_t *oldumd, ptl_md_t *newumd,
+ ptl_handle_eq_t *testqh);
+
+extern int lib_api_get(nal_t *apinal, ptl_handle_md_t *mdh,
+ ptl_process_id_t *id,
+ ptl_pt_index_t portal, ptl_ac_index_t ac,
+ ptl_match_bits_t match_bits, ptl_size_t offset);
+extern int lib_api_put(nal_t *apinal, ptl_handle_md_t *mdh,
+ ptl_ack_req_t ack, ptl_process_id_t *id,
+ ptl_pt_index_t portal, ptl_ac_index_t ac,
+ ptl_match_bits_t match_bits,
+ ptl_size_t offset, ptl_hdr_data_t hdr_data);
+extern int lib_api_fail_nid(nal_t *apinal, ptl_nid_t nid, unsigned int threshold);
+
#endif