Commit 6f3c219e authored by Vikram Narayanan's avatar Vikram Narayanan
Browse files

run boot module as a thread to make it persistent


Signed-off-by: Vikram Narayanan's avatarVikram Narayanan <vikram186@gmail.com>
parent f25d6620
......@@ -10,16 +10,20 @@
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include "../glue_helper.h"
#include <lcd_config/post_hook.h>
cptr_t net_klcd, dummy_lcd;
struct lcd_create_ctx *dummy_ctx;
cptr_t net_chnl;
cptr_t net_chnl_domain_cptr, dummy_chnl_domain_cptr;
static int boot_main(void)
{
int ret;
cptr_t net_chnl;
cptr_t net_chnl_domain_cptr, dummy_chnl_domain_cptr;
cptr_t net_klcd, dummy_lcd;
struct lcd_create_ctx *dummy_ctx;
/*
* Enter lcd mode
*/
......@@ -98,16 +102,16 @@ static int boot_main(void)
/*
* Wait for 4 seconds
*/
msleep(100000);
//msleep(100000);
/*
* Tear everything down
*/
ret = 0;
goto out;
// return
goto fail1;
/* The destroy's will free up everything ... */
out:
fail9:
fail8:
fail7:
......@@ -125,23 +129,49 @@ fail1:
return ret;
}
static int boot_init(void)
int boot_lcd_thread(void *data)
{
static unsigned once = 0;
int ret;
LCD_MAIN({
while (!kthread_should_stop()) {
if (!once) {
LCD_MAIN({
ret = boot_main();
});
}
once = 1;
schedule();
}
LIBLCD_MSG("Exiting thread");
lcd_cap_delete(dummy_lcd);
lcd_destroy_create_ctx(dummy_ctx);
msleep(10000);
lcd_destroy_module_klcd(net_klcd, "lcd_test_mod_nullnet_net_klcd");
lcd_exit(0);
return 0;
}
ret = boot_main();
struct task_struct *boot_task;
static int boot_init(void)
{
LIBLCD_MSG("%s: entering", __func__);
});
boot_task = kthread_create(boot_lcd_thread, NULL, "boot_lcd_thread");
return ret;
if (!IS_ERR(boot_task))
wake_up_process(boot_task);
return 0;
}
static void boot_exit(void)
{
/* nothing to do */
if (!IS_ERR(boot_task)) {
LIBLCD_MSG("%s: exiting", __func__);
kthread_stop(boot_task);
}
}
module_init(boot_init);
module_exit(boot_exit);
......@@ -241,14 +241,12 @@ int create_async_channel(void)
lcd_set_cr2(CAP_CPTR_NULL);
if (ret) {
LIBLCD_ERR("lcd_call");
goto fail4;
goto fail3;
}
net_async = chnl;
return ret;
fail5:
fail4:
//glue_cap_remove(c_cspace, ops_container->my_ref);
fail3:
//glue_cap_remove(c_cspace, ops_container->my_ref);
//destroy_async_channel(chnl);
fail2:
lcd_cap_delete(nullnet_sync_endpoint);
......@@ -279,7 +277,7 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
}
ops_container = container_of(ops, struct rtnl_link_ops_container, rtnl_link_ops);
LIBLCD_MSG("Retrieve container ops %p\n", ops_container);
LIBLCD_MSG("Retrieve container ops %p", ops_container);
err = glue_cap_insert_rtnl_link_ops_type(c_cspace, ops_container, &ops_container->my_ref);
if (err) {
LIBLCD_ERR("lcd insert");
......@@ -488,7 +486,6 @@ int eth_validate_addr(struct net_device *dev)
void free_netdev(struct net_device *dev)
{
int ret;
int err;
struct fipc_message *request;
struct fipc_message *response;
struct net_device_container *dev_container;
......@@ -604,7 +601,6 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, unsigned
struct fipc_message *request;
struct fipc_message *response;
struct net_device_container *ret1;
struct rtnl_link_ops *rtnl_ops;
ret1 = kzalloc(sizeof( struct net_device_container ), GFP_KERNEL);
if (!ret1) {
......@@ -810,7 +806,7 @@ int ndo_set_mac_address_callee(struct fipc_message *request, struct thc_channel
cptr_t addr_cptr;
gva_t addr_gva;
request_cookie = thc_get_request_cookie(request);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), request);
fipc_recv_msg_end(thc_channel_to_fipc(channel), request);
sync_ret = lcd_cptr_alloc(&addr_cptr);
if (sync_ret) {
LIBLCD_ERR("failed to get cptr");
......@@ -831,14 +827,14 @@ int ndo_set_mac_address_callee(struct fipc_message *request, struct thc_channel
lcd_exit(-1);
}
//ret = ndo_set_mac_address(dev, addr);
if (async_msg_blocking_send_start(net_async, &response)) {
if (async_msg_blocking_send_start(channel, &response)) {
LIBLCD_ERR("error getting response msg");
return -EIO;
}
fipc_set_reg1(response, ret);
thc_ipc_reply(net_async, request_cookie, response);
thc_ipc_reply(channel, request_cookie, response);
return ret;
}
int ndo_get_stats64_callee(struct fipc_message *request, struct thc_channel *channel, struct glue_cspace *cspace, struct cptr sync_ep)
......
......@@ -73,7 +73,7 @@ static void main_and_loop(void)
);
}
LIBLCD_MSG("PMFS EXITED DISPATCH LOOP");
LIBLCD_MSG("NULLNET EXITED DISPATCH LOOP");
);
......@@ -88,7 +88,7 @@ static void main_and_loop(void)
dummy_cleanup_module();
LIBLCD_MSG("SUCCESSFULLY UNREGISTERED PMFS!");
LIBLCD_MSG("SUCCESSFULLY UNREGISTERED NULLNET!");
);
);
......@@ -138,6 +138,8 @@ static int __dummy_lcd_init(void)
{
int ret;
LIBLCD_MSG("%s: entering", __func__);
LCD_MAIN({
ret = dummy_lcd_init();
......@@ -149,6 +151,7 @@ static int __dummy_lcd_init(void)
static void __exit dummy_lcd_exit(void)
{
LIBLCD_MSG("%s: exiting", __func__);
return;
}
......
......@@ -181,12 +181,17 @@ int ndo_init(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
struct fipc_message *response;
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return 0;
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_INIT);
......@@ -201,6 +206,7 @@ int ndo_init(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
ret = fipc_get_reg1(response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
return ret;
}
......@@ -219,24 +225,34 @@ int LCD_TRAMPOLINE_LINKAGE(ndo_init_trampoline) ndo_init_trampoline(struct net_d
void ndo_uninit(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
int ret;
int err;
struct fipc_message *request;
struct fipc_message *response;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return;
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_UNINIT);
/* fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);*/
err = thc_ipc_call(net_async, request, &response);
if (err) {
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
return;
}
......@@ -256,23 +272,34 @@ int ndo_start_xmit(struct sk_buff *skb, struct net_device *dev, struct trampolin
int ret;
struct fipc_message *request;
struct fipc_message *response;
int err;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return 0;
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_START_XMIT);
/* fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);*/
err = thc_ipc_call(net_async, request, &response);
if (err) {
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
ret = fipc_get_reg1(response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_async:
fail_ipc:
return ret;
}
......@@ -294,25 +321,34 @@ int ndo_validate_addr(struct net_device *dev, struct trampoline_hidden_args *hid
int ret;
struct fipc_message *request;
struct fipc_message *response;
int err;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return eth_validate_addr(dev);
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_VALIDATE_ADDR);
/* fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);*/
err = thc_ipc_call(net_async, request, &response);
if (err) {
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
ret = fipc_get_reg1(response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
return ret;
}
LCD_TRAMPOLINE_DATA(ndo_validate_addr_trampoline);
......@@ -329,24 +365,35 @@ int LCD_TRAMPOLINE_LINKAGE(ndo_validate_addr_trampoline) ndo_validate_addr_tramp
void ndo_set_rx_mode(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
int ret;
int err;
struct fipc_message *request;
struct fipc_message *response;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return;
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_SET_RX_MODE);
/*fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);*/
err = thc_ipc_call(net_async, request, &response);
if (err) {
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
return;
}
......@@ -370,39 +417,50 @@ int ndo_set_mac_address(struct net_device *dev, void *addr, struct trampoline_hi
unsigned long addr_mem_sz;
unsigned long addr_offset;
cptr_t addr_cptr;
int err;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return eth_mac_addr(dev, addr);
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_SET_MAC_ADDRESS);
/* fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);*/
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
sync_ret = lcd_virt_to_cptr(__gva(( unsigned long )addr), &addr_cptr, &addr_mem_sz, &addr_offset);
if (sync_ret) {
LIBLCD_ERR("virt to cptr failed");
lcd_exit(-1);
goto fail_virt;
}
err = thc_ipc_call(net_async, request, &response);
if (err) {
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
lcd_set_r0(addr_mem_sz);
lcd_set_r1(addr_offset);
lcd_set_cr0(addr_cptr);
sync_ret = lcd_sync_send(sync_ep);
sync_ret = lcd_sync_send(hidden_args->sync_ep);
lcd_set_cr0(CAP_CPTR_NULL);
if (sync_ret) {
LIBLCD_ERR("failed to send");
lcd_exit(-1);
goto fail_sync;
}
ret = fipc_get_reg1(response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
return ret;
fail_virt:
fail_sync:
fail_ipc:
fail_async:
return ret;
}
LCD_TRAMPOLINE_DATA(ndo_set_mac_address_trampoline);
......@@ -419,13 +477,13 @@ int LCD_TRAMPOLINE_LINKAGE(ndo_set_mac_address_trampoline) ndo_set_mac_address_t
struct rtnl_link_stats64 *ndo_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage, struct trampoline_hidden_args *hidden_args)
{
int ret;
int err;
struct fipc_message *request;
struct fipc_message *response;
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
storage->tx_packets = storage->tx_bytes = 0x100;
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return storage;
}
......@@ -441,8 +499,8 @@ struct rtnl_link_stats64 *ndo_get_stats64(struct net_device *dev, struct rtnl_li
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
err = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (err) {
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
......@@ -472,26 +530,34 @@ int ndo_change_carrier(struct net_device *dev, bool new_carrier, struct trampoli
int ret;
struct fipc_message *request;
struct fipc_message *response;
int err;
ret = async_msg_blocking_send_start(net_async, &request);
struct net_device_container *net_dev_container;
if (!get_current()->ptstate) {
LIBLCD_ERR("%s:Called from userland - can't process", __func__);
return 0;
}
net_dev_container = container_of(dev, struct net_device_container, net_device);
ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, NDO_CHANGE_CARRIER);
/*fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);
fipc_set_reg2(request, dev->rtnl_link_ops->kind);
fipc_set_reg4(request, new_carrier);*/
err = thc_ipc_call(net_async, request, &response);
if (err) {
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
ret = fipc_get_reg1(response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
return ret;
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_async:
fail_ipc:
return ret;
}
LCD_TRAMPOLINE_DATA(ndo_change_carrier_trampoline);
......@@ -1194,7 +1260,7 @@ int __rtnl_link_unregister_callee(struct fipc_message *request, struct thc_chann
struct fipc_message *response;
unsigned int request_cookie;
request_cookie = thc_get_request_cookie(request);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), request);
fipc_recv_msg_end(thc_channel_to_fipc(channel), request);
ops = kzalloc(sizeof( *ops ), GFP_KERNEL);
if (!ops) {
LIBLCD_ERR("kzalloc");
......@@ -1202,11 +1268,11 @@ int __rtnl_link_unregister_callee(struct fipc_message *request, struct thc_chann
}
//ops->kind = fipc_get_reg1(request);
__rtnl_link_unregister(ops);
if (async_msg_blocking_send_start(net_async, &response)) {
if (async_msg_blocking_send_start(channel, &response)) {
LIBLCD_ERR("error getting response msg");
return -EIO;
}
thc_ipc_reply(net_async, request_cookie, response);
thc_ipc_reply(channel, request_cookie, response);
return ret;
}
......@@ -1217,7 +1283,7 @@ int rtnl_link_unregister_callee(struct fipc_message *request, struct thc_channel
int err;
struct fipc_message *response;
unsigned int request_cookie;
struct trampoline_hidden_args *setup_hidden_args;
//struct trampoline_hidden_args *setup_hidden_args;
struct trampoline_hidden_args *validate_hidden_args;
request_cookie = thc_get_request_cookie(request);
fipc_recv_msg_end(thc_channel_to_fipc(channel), request);
......
......@@ -232,7 +232,7 @@ static void loop(cptr_t register_chnl)
* went bye-bye when we unloaded the vfs's .ko.)
*/
LIBLCD_MSG("EXITED VFS DO_FINISH");
LIBLCD_MSG("EXITED DUMMY DO_FINISH");
}
......@@ -294,7 +294,7 @@ fail1:
static int __net_klcd_init(void)
{
int ret;
printk("Net klcd\n");
LIBLCD_MSG("%s: entering", __func__);
LCD_MAIN({
ret = net_klcd_init();
......@@ -309,6 +309,7 @@ static int __net_klcd_init(void)
*/
static void __exit net_klcd_exit(void)
{
LIBLCD_MSG("%s: exiting", __func__);
return;
}
......