Commit 1e3ad7a1 authored by Vikram Narayanan's avatar Vikram Narayanan

add new functions for cptr. fix setup, ether_setup

Signed-off-by: Vikram Narayanan's avatarVikram Narayanan <vikram186@gmail.com>
parent b61f236b
......@@ -3665,6 +3665,12 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
unsigned char name_assign_type,
void (*setup)(struct net_device *),
unsigned int txqs, unsigned int rxqs);
struct net_device *alloc_netdev_mqs_lcd(int sizeof_priv, const char *name,
unsigned char name_assign_type,
void (*setup)(struct net_device *),
unsigned int txqs, unsigned int rxqs, u64 their_ref_cptr);
#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
......
......@@ -168,18 +168,7 @@ static void dummy_setup(struct net_device *dev)
dev->hw_features |= dev->features;
dev->hw_enc_features |= dev->features;
dev->dev_addr[1] = 0xab;
dev->dev_addr[2] = 0xcd;
dev->dev_addr[3] = 0xef;
dev->dev_addr[4] = 0xef;
dev->dev_addr[5] = 0xef;
dev->dev_addr[0] &= 0xfe; /* clear multicast bit */
dev->dev_addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
dev->addr_assign_type = NET_ADDR_RANDOM;
//eth_hw_addr_random(dev);
// eth_hw_addr_random(dev);
dummy_done = 1;
}
......@@ -260,8 +249,8 @@ int dummy_init_module(void)
// else
// dummy_done = 1;
for (i = 0; i < numdummies && !err; i++) {
// err = dummy_init_one();
// cond_resched();
err = dummy_init_one();
cond_resched();
}
/* if (err < 0)
__rtnl_link_unregister(&dummy_link_ops_container.rtnl_link_ops);
......
......@@ -358,21 +358,28 @@ void ether_setup(struct net_device *dev)
int err;
struct fipc_message *request;
struct fipc_message *response;
struct net_device_container *netdev_container;
ret = async_msg_blocking_send_start(net_async, &request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
lcd_exit(-1);
goto fail_async;
}
async_msg_set_fn_type(request, ETHER_SETUP);
//fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
netdev_container = container_of(dev, struct net_device_container, net_device);
fipc_set_reg1(request, netdev_container->other_ref.cptr);
LIBLCD_MSG("ndev other ref %lu\n", netdev_container->other_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) {
LIBLCD_ERR("thc_ipc_call");
lcd_exit(-1);
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
fail_ipc:
fail_async:
return;
}
......@@ -596,17 +603,18 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, unsigned
async_msg_set_fn_type(request, ALLOC_NETDEV_MQS);
fipc_set_reg1(request, sizeof_priv);
fipc_set_reg2(request, setup_container->other_ref.cptr);
fipc_set_reg2(request, setup_container->my_ref.cptr);
fipc_set_reg3(request, name_assign_type);
fipc_set_reg4(request, txqs);
fipc_set_reg5(request, rxqs);
fipc_set_reg6(request, ret1->my_ref.cptr);
err = thc_ipc_call(net_async, request, &response);
if (err) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
ret1->other_ref.cptr = fipc_get_reg5(response);
//ret1->other_ref.cptr = fipc_get_reg5(response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
......@@ -863,12 +871,13 @@ int setup_callee(struct fipc_message *request, struct thc_channel *channel, stru
goto fail_lookup;
}
ret = glue_cap_lookup_net_device_type(c_cspace, __cptr(fipc_get_reg1(response)), &net_dev_container);
ret = glue_cap_lookup_net_device_type(c_cspace, __cptr(fipc_get_reg1(request)), &net_dev_container);
if (ret) {
LIBLCD_ERR("lookup");
goto fail_lookup;
}
// save other ref cptr
net_dev_container->other_ref = __cptr(fipc_get_reg3(request));
setup_container->setup(&net_dev_container->net_device);
if (async_msg_blocking_send_start(channel, &response)) {
......
......@@ -25,7 +25,7 @@ void dummy_cleanup_module(void);
static void main_and_loop(void)
{
int ret;
int stop = 1;
int stop = 0;
struct fipc_message *msg;
DO_FINISH(
......
......@@ -538,6 +538,13 @@ void setup(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
goto fail_async;
}
async_msg_set_fn_type(request, SETUP);
ret = glue_cap_insert_net_device_type(c_cspace, net_dev_container, &net_dev_container->my_ref);
if (ret) {
LIBLCD_ERR("insert");
goto fail_insert;
}
/*fipc_set_reg1(request, netdev_ops_container->my_ref.cptr);
fipc_set_reg3(request, rtnl_link_ops_container->my_ref.cptr);*/
setup_container = (struct setup_container*)hidden_args->struct_container;
......@@ -545,6 +552,8 @@ void setup(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
LIBLCD_MSG("sending setup_container cptr: other_ref %lu", setup_container->other_ref.cptr);
fipc_set_reg1(request, net_dev_container->other_ref.cptr);
fipc_set_reg2(request, setup_container->other_ref.cptr);
fipc_set_reg3(request, net_dev_container->my_ref.cptr);
err = thc_ipc_call(hidden_args->async_chnl, request, &response);
if (err) {
LIBLCD_ERR("thc_ipc_call");
......@@ -552,6 +561,7 @@ void setup(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
}
fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_async:
fail_insert:
fail_ipc:
return;
}
......@@ -759,40 +769,30 @@ int register_netdevice_callee(struct fipc_message *request, struct thc_channel *
int ether_setup_callee(struct fipc_message *request, struct thc_channel *channel, struct glue_cspace *cspace, struct cptr sync_ep)
{
int ret;
struct net_device *dev;
struct net_device_container *dev;
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);
dev = kzalloc(sizeof( dev ), GFP_KERNEL);
if (!dev) {
LIBLCD_ERR("kzalloc");
lcd_exit(-1);
}
dev->netdev_ops = kzalloc(sizeof( dev->netdev_ops ), GFP_KERNEL);
if (!dev->netdev_ops) {
LIBLCD_ERR("kzalloc");
lcd_exit(-1);
}
dev->rtnl_link_ops = kzalloc(sizeof( dev->rtnl_link_ops ), GFP_KERNEL);
if (!dev->rtnl_link_ops) {
LIBLCD_ERR("kzalloc");
lcd_exit(-1);
}
/* dev->rtnl_link_ops->kind = kzalloc(sizeof( char ), GFP_KERNEL);
if (!dev->rtnl_link_ops->kind) {
LIBLCD_ERR("kzalloc");
lcd_exit(-1);
fipc_recv_msg_end(thc_channel_to_fipc(channel), request);
ret = glue_cap_lookup_net_device_type(c_cspace, __cptr(fipc_get_reg1(request)), &dev);
LIBLCD_MSG("ndev other ref %lu", dev->other_ref.cptr);
if (ret) {
LIBLCD_MSG("lookup failed");
goto fail_lookup;
}
dev->rtnl_link_ops->kind = fipc_get_reg2(request);*/
ether_setup(dev);
if (async_msg_blocking_send_start(net_async, &response)) {
LIBLCD_MSG("Calling ether_setup");
ether_setup(&dev->net_device);
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);
fail_lookup:
return ret;
}
int eth_mac_addr_callee(struct fipc_message *request, struct thc_channel *channel, struct glue_cspace *cspace, struct cptr sync_ep)
......@@ -1105,6 +1105,7 @@ int rtnl_link_unregister_callee(struct fipc_message *request, struct thc_channel
return -EIO;
}
thc_ipc_reply(channel, request_cookie, response);
return ret;
}
......@@ -1138,7 +1139,7 @@ int alloc_netdev_mqs_callee(struct fipc_message *request, struct thc_channel *ch
txqs = fipc_get_reg4(request);
rxqs = fipc_get_reg5(request);
temp->other_ref = __cptr(fipc_get_reg2(request));
temp->other_ref.cptr = fipc_get_reg2(request);
LIBLCD_MSG("received setup_container cptr: other_ref %lu", temp->other_ref.cptr);
ret = glue_cap_insert_setup_type(c_cspace, temp, &temp->my_ref);
......@@ -1172,22 +1173,22 @@ int alloc_netdev_mqs_callee(struct fipc_message *request, struct thc_channel *ch
goto fail3;
}
net_device = alloc_netdev_mqs(sizeof_priv, name, name_assign_type, (temp->setup ), txqs, rxqs);
net_device = alloc_netdev_mqs_lcd(sizeof_priv, name, name_assign_type, (temp->setup ), txqs, rxqs, fipc_get_reg6(request));
dev_container = container_of(net_device, struct net_device_container, net_device);
ret = glue_cap_insert_net_device_type(c_cspace, dev_container , &dev_container->my_ref);
/*ret = glue_cap_insert_net_device_type(c_cspace, dev_container , &dev_container->my_ref);
if (!ret) {
LIBLCD_ERR("lcd insert");
goto fail_insert;
}
}*/
if (async_msg_blocking_send_start(channel, &response)) {
LIBLCD_ERR("error getting response msg");
return -EIO;
}
fipc_set_reg5(response, dev_container->my_ref.cptr);
// fipc_set_reg5(response, dev_container->my_ref.cptr);
thc_ipc_reply(channel, request_cookie, response);
return ret;
fail_insert:
......
......@@ -7562,6 +7562,16 @@ void netdev_freemem(struct net_device *dev)
kvfree(addr);
}
typedef struct cptr {
unsigned long cptr;
} cptr_t;
struct net_device_container {
struct net_device dev;
cptr_t other_ref;
cptr_t my_ref;
};
/**
* alloc_netdev_mqs - allocate network device
* @sizeof_priv: size of private data to allocate space for
......@@ -7581,6 +7591,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
unsigned int txqs, unsigned int rxqs)
{
struct net_device *dev;
struct net_device_container *dev_c;
size_t alloc_size;
struct net_device *p;
......@@ -7598,7 +7609,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
}
#endif
alloc_size = sizeof(struct net_device);
alloc_size = sizeof(struct net_device_container);
if (sizeof_priv) {
/* ensure 32-byte alignment of private area */
alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
......@@ -7613,7 +7624,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
if (!p)
return NULL;
dev = PTR_ALIGN(p, NETDEV_ALIGN);
dev_c = PTR_ALIGN(p, NETDEV_ALIGN);
dev = &dev_c->dev;
dev->padded = (char *)dev - (char *)p;
dev->pcpu_refcnt = alloc_percpu(int);
......@@ -7683,6 +7695,119 @@ free_dev:
}
EXPORT_SYMBOL(alloc_netdev_mqs);
struct net_device *alloc_netdev_mqs_lcd(int sizeof_priv, const char *name,
unsigned char name_assign_type,
void (*setup)(struct net_device *),
unsigned int txqs, unsigned int rxqs, u64 other_ref_cptr)
{
struct net_device *dev;
struct net_device_container *dev_c;
size_t alloc_size;
struct net_device *p;
BUG_ON(strlen(name) >= sizeof(dev->name));
if (txqs < 1) {
pr_err("alloc_netdev: Unable to allocate device with zero queues\n");
return NULL;
}
#ifdef CONFIG_SYSFS
if (rxqs < 1) {
pr_err("alloc_netdev: Unable to allocate device with zero RX queues\n");
return NULL;
}
#endif
alloc_size = sizeof(struct net_device_container);
if (sizeof_priv) {
/* ensure 32-byte alignment of private area */
alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
alloc_size += sizeof_priv;
}
/* ensure 32-byte alignment of whole construct */
alloc_size += NETDEV_ALIGN - 1;
p = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
if (!p)
p = vzalloc(alloc_size);
if (!p)
return NULL;
dev_c = PTR_ALIGN(p, NETDEV_ALIGN);
dev_c->other_ref.cptr = other_ref_cptr;
dev = &dev_c->dev;
dev->padded = (char *)dev - (char *)p;
dev->pcpu_refcnt = alloc_percpu(int);
if (!dev->pcpu_refcnt)
goto free_dev;
if (dev_addr_init(dev))
goto free_pcpu;
dev_mc_init(dev);
dev_uc_init(dev);
dev_net_set(dev, &init_net);
dev->gso_max_size = GSO_MAX_SIZE;
dev->gso_max_segs = GSO_MAX_SEGS;
INIT_LIST_HEAD(&dev->napi_list);
INIT_LIST_HEAD(&dev->unreg_list);
INIT_LIST_HEAD(&dev->close_list);
INIT_LIST_HEAD(&dev->link_watch_list);
INIT_LIST_HEAD(&dev->adj_list.upper);
INIT_LIST_HEAD(&dev->adj_list.lower);
INIT_LIST_HEAD(&dev->all_adj_list.upper);
INIT_LIST_HEAD(&dev->all_adj_list.lower);
INIT_LIST_HEAD(&dev->ptype_all);
INIT_LIST_HEAD(&dev->ptype_specific);
dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
setup(dev);
if (!dev->tx_queue_len) {
dev->priv_flags |= IFF_NO_QUEUE;
dev->tx_queue_len = 1;
}
dev->num_tx_queues = txqs;
dev->real_num_tx_queues = txqs;
if (netif_alloc_netdev_queues(dev))
goto free_all;
#ifdef CONFIG_SYSFS
dev->num_rx_queues = rxqs;
dev->real_num_rx_queues = rxqs;
if (netif_alloc_rx_queues(dev))
goto free_all;
#endif
strcpy(dev->name, name);
dev->name_assign_type = name_assign_type;
dev->group = INIT_NETDEV_GROUP;
if (!dev->ethtool_ops)
dev->ethtool_ops = &default_ethtool_ops;
nf_hook_ingress_init(dev);
return dev;
free_all:
free_netdev(dev);
return NULL;
free_pcpu:
free_percpu(dev->pcpu_refcnt);
free_dev:
netdev_freemem(dev);
return NULL;
}
EXPORT_SYMBOL(alloc_netdev_mqs_lcd);
/**
* free_netdev - free network device
* @dev: device
......@@ -7695,7 +7820,6 @@ EXPORT_SYMBOL(alloc_netdev_mqs);
void free_netdev(struct net_device *dev)
{
struct napi_struct *p, *n;
might_sleep();
netif_free_tx_queues(dev);
#ifdef CONFIG_SYSFS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment