00001
00002
00003
00004
00005
00006
00007
00008 #include "local.h"
00009 #include "list.h"
00010
00011 static LIST_HEAD(dsi_packet_list);
00012
00013 typedef struct
00014 {
00015 struct list_head list;
00016 void *addr;
00017 l4_size_t size;
00018 dsi_packet_t *pack;
00019 dsi_socket_t *sock;
00020 } ore_dsi_desc;
00021
00022 void __l4ore_remember_packet(dsi_socket_t *sock, dsi_packet_t *pack, void *addr, l4_size_t size)
00023 {
00024 ore_dsi_desc *d = malloc(sizeof(ore_dsi_desc));
00025
00026 if (!d)
00027 return;
00028
00029 d->addr = addr;
00030 d->size = size;
00031 d->pack = pack;
00032 d->sock = sock;
00033
00034 list_add_tail(&d->list, &dsi_packet_list);
00035 }
00036
00037 void l4ore_packet_to_pool(void *addr)
00038 {
00039 struct list_head *p, *h, *n;
00040 h = &dsi_packet_list;
00041
00042 if (!addr)
00043 return;
00044
00045 list_for_each_safe(p,n,h)
00046 {
00047 ore_dsi_desc *d = list_entry(p, ore_dsi_desc, list);
00048 if (d->addr <= addr && (d->addr + d->size) > addr)
00049 {
00050 dsi_packet_commit(d->sock, d->pack);
00051 list_del(p);
00052 free(d);
00053 return;
00054 }
00055 }
00056 }
00057
00058
00059 int __l4ore_init_send_socket(l4ore_handle_t server, l4ore_config *conf, dsi_socket_t **sock, void **addr)
00060 {
00061 dsi_jcp_stream_t jcp;
00062 dsi_stream_cfg_t cfg;
00063 int flags, ret = 0;
00064 l4_threadid_t worker = l4_myself();
00065 l4_threadid_t sync = L4_INVALID_ID;
00066 int size, a;
00067
00068 LOG_Enter();
00069
00070
00071 flags = DSI_SOCKET_SEND | DSI_SOCKET_BLOCK;
00072 cfg.num_packets = 100;
00073 cfg.max_sg = 2;
00074 conf->ro_send_ctl_ds = L4DM_INVALID_DATASPACE;
00075
00076
00077 ret = dsi_socket_create(jcp, cfg, &conf->ro_send_ctl_ds,
00078 &conf->ro_send_ds, worker, &sync, flags, sock);
00079 LOG("socket_create: %d", ret);
00080 if (ret)
00081 {
00082 LOG("dsi_socket_create failed: %d (%s)", ret, l4env_strerror(-ret));
00083 return ret;
00084 }
00085
00086
00087 ret = dsi_socket_get_ref(*sock, &conf->ro_send_client_socketref);
00088 LOG("socket_get_ref: %d", ret);
00089 if (ret)
00090 {
00091 LOG("dsi_socket_get_ref failed: %d (%s)", ret, l4env_strerror(-ret));
00092 return ret;
00093 }
00094
00095 ret = dsi_socket_get_data_area(*sock, addr, &size);
00096 LOG("got data area of size %d: %p", size, *addr);
00097 if (ret)
00098 {
00099 LOG("get_data_area failed: %d", ret);
00100 return ret;
00101 }
00102
00103 a = 0;
00104 while (a < size)
00105 {
00106 *((int*)(*addr+a)) = 0;
00107 a += L4_PAGESIZE;
00108 }
00109
00110 LOG_SOCKETREF(&conf->ro_send_client_socketref);
00111
00112
00113
00114 ret = dsi_socket_share_ds(*sock, server);
00115 LOG("socket_share_ds: %d", ret);
00116 if (ret)
00117 {
00118 LOG("dsi_socket_share failed: %d (%s)", ret, l4env_strerror(-ret));
00119 return ret;
00120 }
00121
00122 ret = l4dm_share(&conf->ro_send_ctl_ds, server, L4DM_RW);
00123 LOG("share ctl_ds: %d", ret);
00124 if (ret)
00125 {
00126 LOG("sharing ctl ds failed. %d (%s)", ret,
00127 l4env_strerror(-ret));
00128 return ret;
00129 }
00130
00131 ret = l4dm_share(&conf->ro_send_ds, server, L4DM_RW);
00132 LOG("share send_ds: %d", ret);
00133 if (ret)
00134 {
00135 LOG("sharing ctl ds failed. %d (%s)", ret,
00136 l4env_strerror(-ret));
00137 return ret;
00138 }
00139
00140 return 0;
00141 }
00142
00143 int __l4ore_init_recv_socket(l4ore_handle_t server, l4ore_config *conf, dsi_socket_t **sock, void **addr)
00144 {
00145 dsi_jcp_stream_t jcp;
00146 dsi_stream_cfg_t cfg;
00147 int flags, ret = 0;
00148 l4_threadid_t worker = l4_myself();
00149 l4_threadid_t sync = L4_INVALID_ID;
00150 int size, a;
00151
00152 LOG_Enter();
00153
00154
00155 flags = DSI_SOCKET_RECEIVE | DSI_SOCKET_BLOCK;
00156 cfg.num_packets = 100;
00157 cfg.max_sg = 2;
00158 conf->ro_recv_ctl_ds = L4DM_INVALID_DATASPACE;
00159
00160
00161 ret = dsi_socket_create(jcp, cfg, &conf->ro_recv_ctl_ds,
00162 &conf->ro_recv_ds, worker, &sync, flags, sock);
00163 LOG("socket_create: %d", ret);
00164 if (ret)
00165 {
00166 LOG("dsi_socket_create failed: %d (%s)", ret, l4env_strerror(-ret));
00167 return ret;
00168 }
00169
00170
00171 ret = dsi_socket_get_ref(*sock, &conf->ro_recv_client_socketref);
00172 LOG("socket_get_ref: %d", ret);
00173 if (ret)
00174 {
00175 LOG("dsi_socket_get_ref failed: %d (%s)", ret, l4env_strerror(-ret));
00176 return ret;
00177 }
00178
00179 ret = dsi_socket_get_data_area(*sock, addr, &size);
00180 LOG("got data area of size %d: %p", size, *addr);
00181 if (ret)
00182 {
00183 LOG("get_data_area failed: %d", ret);
00184 return ret;
00185 }
00186
00187 a = 0;
00188 while (a < size)
00189 {
00190 *((int*)(*addr+a)) = 0;
00191 a += L4_PAGESIZE;
00192 }
00193
00194 LOG_SOCKETREF(&conf->ro_recv_client_socketref);
00195
00196
00197 ret = dsi_socket_share_ds(*sock, server);
00198 LOG("socket_share_ds: %d", ret);
00199 if (ret)
00200 {
00201 LOG("dsi_socket_share failed: %d (%s)", ret, l4env_strerror(-ret));
00202 return ret;
00203 }
00204
00205 ret = l4dm_share(&conf->ro_recv_ctl_ds, server, L4DM_RW);
00206 LOG("share ctl_ds: %d", ret);
00207 if (ret)
00208 {
00209 LOG("sharing ctl ds failed. %d (%s)", ret,
00210 l4env_strerror(-ret));
00211 return ret;
00212 }
00213
00214 ret = l4dm_share(&conf->ro_recv_ds, server, L4DM_RW);
00215 LOG("share send_ds: %d", ret);
00216 if (ret)
00217 {
00218 LOG("sharing ctl ds failed. %d (%s)", ret,
00219 l4env_strerror(-ret));
00220 return ret;
00221 }
00222
00223 return 0;}