1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 #ifndef _KRRP_SVC_H
17 #define _KRRP_SVC_H
18
19 #include <sys/ddi.h>
20 #include <sys/sunddi.h>
21 #include <sys/sunldi.h>
22 #include <sys/avl.h>
23 #include <sys/sysevent/krrp.h>
24
25 #include <krrp_error.h>
26
27 #include "krrp_pdu.h"
28 #include "krrp_session.h"
29 #include "krrp_server.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #define krrp_svc_lock(a) mutex_enter(&(a)->mtx)
36 #define krrp_svc_unlock(a) mutex_exit(&(a)->mtx)
37
38 typedef enum {
39 KRRP_SVCS_UNKNOWN = 0,
40 KRRP_SVCS_CREATED,
41 KRRP_SVCS_DETACHED,
42 KRRP_SVCS_DISABLED,
43 KRRP_SVCS_ENABLING,
44 KRRP_SVCS_ENABLED,
45 KRRP_SVCS_DISABLING
46 } krrp_svc_state_t;
47
48 typedef struct krrp_svc_s {
49 krrp_svc_state_t state;
50 ldi_ident_t li;
51 dev_info_t *dip;
52 kmutex_t mtx;
53 kcondvar_t cv;
54 size_t ref_cnt;
55 avl_tree_t sessions;
56 krrp_server_t *server;
57 krrp_pdu_engine_t *ctrl_pdu_engine;
58 taskq_t *aux_taskq;
59 evchan_t *ev_chan;
60 } krrp_svc_t;
61
62 krrp_svc_t *krrp_svc_get_instance(void);
63
64 boolean_t krrp_svc_is_enabled(void);
65
66 void krrp_svc_init(void);
67 void krrp_svc_fini(void);
68
69 void krrp_svc_attach(dev_info_t *dip);
70 int krrp_svc_detach(void);
71
72 int krrp_svc_enable(krrp_error_t *);
73 int krrp_svc_disable(krrp_error_t *);
74 void krrp_svc_state(nvlist_t *);
75 int krrp_svc_config(nvlist_t *params, nvlist_t *result,
76 krrp_error_t *error);
77
78 int krrp_svc_register_session(krrp_sess_t *sess, krrp_error_t *error);
79 int krrp_svc_unregister_session(krrp_sess_t *sess, krrp_error_t *error);
80
81 void krrp_svc_post_uevent(const char *, nvlist_t *attr_list);
82
83 krrp_sess_t *krrp_svc_lookup_session(const char *sess_id);
84 void krrp_svc_list_sessions(nvlist_t *out_nvl);
85
86 int krrp_svc_ref_cnt_try_hold();
87 void krrp_svc_ref_cnt_rele();
88
89 void krrp_svc_dispatch_task(task_func_t func, void *arg);
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif /* _KRRP_SVC_H */