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)
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;
}
{
struct netvsc_device *net_device;
- net_device = device->ext;
+ net_device = hv_get_drvdata(device);
if (net_device && net_device->destroy)
net_device = NULL;
{
struct netvsc_device *net_device;
- net_device = device->ext;
+ net_device = hv_get_drvdata(device);
if (!net_device)
goto get_in_err;
{
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
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,
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;
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);
*/
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 */
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));
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) {
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;
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
* 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);
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
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);
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,
((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) {
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);
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 "
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"
{
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);
}
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;
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);
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");
static void dump_rndis_message(struct hv_device *hv_dev,
struct rndis_message *rndis_msg)
{
- struct net_device *netdev = dev_get_drvdata(&hv_dev->device);
+ struct net_device *netdev;
+ struct netvsc_device *net_device;
+
+ net_device = hv_get_drvdata(hv_dev);
+ netdev = net_device->ndev;
switch (rndis_msg->ndis_msg_type) {
case REMOTE_NDIS_PACKET_MSG:
struct rndis_request *request = NULL;
bool found = false;
unsigned long flags;
- struct net_device *ndev = dev_get_drvdata(&dev->net_dev->dev->device);
+ struct net_device *ndev;
+
+ ndev = dev->net_dev->ndev;
spin_lock_irqsave(&dev->request_lock, flags);
list_for_each_entry(request, &dev->req_list, list_ent) {
int rndis_filter_receive(struct hv_device *dev,
struct hv_netvsc_packet *pkt)
{
- struct netvsc_device *net_dev = dev->ext;
+ struct netvsc_device *net_dev = hv_get_drvdata(dev);
struct rndis_device *rndis_dev;
struct rndis_message rndis_msg;
struct rndis_message *rndis_hdr;
- struct net_device *ndev = dev_get_drvdata(&dev->device);
+ struct net_device *ndev;
+
+ ndev = net_dev->ndev;
if (!net_dev)
return -EINVAL;
struct rndis_set_complete *set_complete;
u32 status;
int ret, t;
- struct net_device *ndev = dev_get_drvdata(&dev->net_dev->dev->device);
+ struct net_device *ndev;
+
+ ndev = dev->net_dev->ndev;
request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG,
RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
/* Initialize the rndis device */
- netDevice = dev->ext;
+ netDevice = hv_get_drvdata(dev);
netDevice->extension = rndisDevice;
rndisDevice->net_dev = netDevice;
void rndis_filter_device_remove(struct hv_device *dev)
{
- struct netvsc_device *net_dev = dev->ext;
+ struct netvsc_device *net_dev = hv_get_drvdata(dev);
struct rndis_device *rndis_dev = net_dev->extension;
/* Halt and release the rndis device */
int rndis_filter_open(struct hv_device *dev)
{
- struct netvsc_device *netDevice = dev->ext;
+ struct netvsc_device *netDevice = hv_get_drvdata(dev);
if (!netDevice)
return -EINVAL;
int rndis_filter_close(struct hv_device *dev)
{
- struct netvsc_device *netDevice = dev->ext;
+ struct netvsc_device *netDevice = hv_get_drvdata(dev);
if (!netDevice)
return -EINVAL;