Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 268376
b: refs/heads/master
c: 2ddd5e5
h: refs/heads/master
v: v3
  • Loading branch information
K. Y. Srinivasan authored and Greg Kroah-Hartman committed Sep 16, 2011
1 parent a6e97f6 commit 2fca108
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 58 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cd654ea1cc72aed95e871971d87c4a988924fdda
refs/heads/master: 2ddd5e5fb342b9f014d61941a4f73c0bd9b50a60
2 changes: 2 additions & 0 deletions trunk/drivers/staging/hv/hyperv_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ struct netvsc_device {
struct nvsp_message revoke_packet;
/* unsigned char HwMacAddr[HW_MACADDR_LEN]; */

struct net_device *ndev;

/* Holds rndis device info */
void *extension;
};
Expand Down
86 changes: 43 additions & 43 deletions trunk/drivers/staging/hv/netvsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
static struct netvsc_device *alloc_net_device(struct hv_device *device)
{
struct netvsc_device *net_device;
struct net_device *ndev = hv_get_drvdata(device);

net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL);
if (!net_device)
Expand All @@ -43,16 +44,17 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device)

net_device->destroy = false;
net_device->dev = device;
device->ext = net_device;
net_device->ndev = ndev;

hv_set_drvdata(device, net_device);
return net_device;
}

static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
{
struct netvsc_device *net_device;

net_device = device->ext;
net_device = hv_get_drvdata(device);
if (net_device && net_device->destroy)
net_device = NULL;

Expand All @@ -63,7 +65,7 @@ static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
{
struct netvsc_device *net_device;

net_device = device->ext;
net_device = hv_get_drvdata(device);

if (!net_device)
goto get_in_err;
Expand All @@ -81,7 +83,7 @@ static int netvsc_destroy_recv_buf(struct netvsc_device *net_device)
{
struct nvsp_message *revoke_packet;
int ret = 0;
struct net_device *ndev = dev_get_drvdata(&net_device->dev->device);
struct net_device *ndev = net_device->ndev;

/*
* If we got a section count, it means we received a
Expand Down Expand Up @@ -153,14 +155,12 @@ static int netvsc_init_recv_buf(struct hv_device *device)
int t;
struct netvsc_device *net_device;
struct nvsp_message *init_packet;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

net_device = get_outbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "unable to get net device..."
"device being destroyed?\n");
if (!net_device)
return -ENODEV;
}
ndev = net_device->ndev;

net_device->recv_buf =
(void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO,
Expand Down Expand Up @@ -269,14 +269,12 @@ static int netvsc_connect_vsp(struct hv_device *device)
struct netvsc_device *net_device;
struct nvsp_message *init_packet;
int ndis_version;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

net_device = get_outbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "unable to get net device..."
"device being destroyed?\n");
if (!net_device)
return -ENODEV;
}
ndev = net_device->ndev;

init_packet = &net_device->channel_init_pkt;

Expand Down Expand Up @@ -357,7 +355,7 @@ int netvsc_device_remove(struct hv_device *device)
struct hv_netvsc_packet *netvsc_packet, *pos;
unsigned long flags;

net_device = (struct netvsc_device *)device->ext;
net_device = hv_get_drvdata(device);
spin_lock_irqsave(&device->channel->inbound_lock, flags);
net_device->destroy = true;
spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
Expand All @@ -381,7 +379,7 @@ int netvsc_device_remove(struct hv_device *device)
*/

spin_lock_irqsave(&device->channel->inbound_lock, flags);
device->ext = NULL;
hv_set_drvdata(device, NULL);
spin_unlock_irqrestore(&device->channel->inbound_lock, flags);

/* At this point, no one should be accessing netDevice except in here */
Expand All @@ -407,14 +405,12 @@ static void netvsc_send_completion(struct hv_device *device,
struct netvsc_device *net_device;
struct nvsp_message *nvsp_packet;
struct hv_netvsc_packet *nvsc_packet;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

net_device = get_inbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "unable to get net device..."
"device being destroyed?\n");
if (!net_device)
return;
}
ndev = net_device->ndev;

nvsp_packet = (struct nvsp_message *)((unsigned long)packet +
(packet->offset8 << 3));
Expand Down Expand Up @@ -452,14 +448,12 @@ int netvsc_send(struct hv_device *device,
struct netvsc_device *net_device;
int ret = 0;
struct nvsp_message sendMessage;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

net_device = get_outbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "net device (%p) shutting down..."
"ignoring outbound packets\n", net_device);
if (!net_device)
return -ENODEV;
}
ndev = net_device->ndev;

sendMessage.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT;
if (packet->is_data_pkt) {
Expand Down Expand Up @@ -506,7 +500,10 @@ static void netvsc_send_recv_completion(struct hv_device *device,
struct nvsp_message recvcompMessage;
int retries = 0;
int ret;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;
struct netvsc_device *net_device = hv_get_drvdata(device);

ndev = net_device->ndev;

recvcompMessage.hdr.msg_type =
NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE;
Expand Down Expand Up @@ -552,19 +549,17 @@ static void netvsc_receive_completion(void *context)
u64 transaction_id = 0;
bool fsend_receive_comp = false;
unsigned long flags;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

/*
* Even though it seems logical to do a GetOutboundNetDevice() here to
* send out receive completion, we are using GetInboundNetDevice()
* since we may have disable outbound traffic already.
*/
net_device = get_inbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "unable to get net device..."
"device being destroyed?\n");
if (!net_device)
return;
}
ndev = net_device->ndev;

/* Overloading use of the lock. */
spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags);
Expand Down Expand Up @@ -607,16 +602,14 @@ static void netvsc_receive(struct hv_device *device,
int i, j;
int count = 0, bytes_remain = 0;
unsigned long flags;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

LIST_HEAD(listHead);

net_device = get_inbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "unable to get net device..."
"device being destroyed?\n");
if (!net_device)
return;
}
ndev = net_device->ndev;

/*
* All inbound packets other than send completion should be xfer page
Expand Down Expand Up @@ -784,7 +777,7 @@ static void netvsc_channel_cb(void *context)
struct vmpacket_descriptor *desc;
unsigned char *buffer;
int bufferlen = NETVSC_PACKET_SIZE;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char),
GFP_ATOMIC);
Expand All @@ -793,11 +786,9 @@ static void netvsc_channel_cb(void *context)
buffer = packet;

net_device = get_inbound_net_device(device);
if (!net_device) {
netdev_err(ndev, "net device (%p) shutting down..."
"ignoring inbound packets\n", net_device);
if (!net_device)
goto out;
}
ndev = net_device->ndev;

do {
ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen,
Expand Down Expand Up @@ -871,14 +862,23 @@ int netvsc_device_add(struct hv_device *device, void *additional_info)
((struct netvsc_device_info *)additional_info)->ring_size;
struct netvsc_device *net_device;
struct hv_netvsc_packet *packet, *pos;
struct net_device *ndev = dev_get_drvdata(&device->device);
struct net_device *ndev;

net_device = alloc_net_device(device);
if (!net_device) {
ret = -ENOMEM;
goto cleanup;
}

/*
* Coming into this function, struct net_device * is
* registered as the driver private data.
* In alloc_net_device(), we register struct netvsc_device *
* as the driver private data and stash away struct net_device *
* in struct netvsc_device *.
*/
ndev = net_device->ndev;

/* Initialize the NetVSC channel extension */
net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE;
spin_lock_init(&net_device->recv_pkt_list_lock);
Expand Down
24 changes: 19 additions & 5 deletions trunk/drivers/staging/hv/netvsc_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
void netvsc_linkstatus_callback(struct hv_device *device_obj,
unsigned int status)
{
struct net_device *net = dev_get_drvdata(&device_obj->device);
struct net_device *net;
struct net_device_context *ndev_ctx;
struct netvsc_device *net_device;

net_device = hv_get_drvdata(device_obj);
net = net_device->ndev;

if (!net) {
netdev_err(net, "got link status but net device "
Expand Down Expand Up @@ -236,6 +240,10 @@ int netvsc_recv_callback(struct hv_device *device_obj,
void *data;
int i;
unsigned long flags;
struct netvsc_device *net_device;

net_device = hv_get_drvdata(device_obj);
net = net_device->ndev;

if (!net) {
netdev_err(net, "got receive callback but net device"
Expand Down Expand Up @@ -322,9 +330,11 @@ static void netvsc_send_garp(struct work_struct *w)
{
struct net_device_context *ndev_ctx;
struct net_device *net;
struct netvsc_device *net_device;

ndev_ctx = container_of(w, struct net_device_context, dwork.work);
net = dev_get_drvdata(&ndev_ctx->device_ctx->device);
net_device = hv_get_drvdata(ndev_ctx->device_ctx);
net = net_device->ndev;
netif_notify_peers(net);
}

Expand All @@ -347,7 +357,7 @@ static int netvsc_probe(struct hv_device *dev,
net_device_ctx = netdev_priv(net);
net_device_ctx->device_ctx = dev;
atomic_set(&net_device_ctx->avail, ring_size);
dev_set_drvdata(&dev->device, net);
hv_set_drvdata(dev, net);
INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp);

net->netdev_ops = &device_ops;
Expand All @@ -373,7 +383,7 @@ static int netvsc_probe(struct hv_device *dev,
netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
unregister_netdev(net);
free_netdev(net);
dev_set_drvdata(&dev->device, NULL);
hv_set_drvdata(dev, NULL);
return ret;
}
memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
Expand All @@ -386,8 +396,12 @@ static int netvsc_probe(struct hv_device *dev,

static int netvsc_remove(struct hv_device *dev)
{
struct net_device *net = dev_get_drvdata(&dev->device);
struct net_device *net;
struct net_device_context *ndev_ctx;
struct netvsc_device *net_device;

net_device = hv_get_drvdata(dev);
net = net_device->ndev;

if (net == NULL) {
dev_err(&dev->device, "No net device to remove\n");
Expand Down
Loading

0 comments on commit 2fca108

Please sign in to comment.