Merge branches 'misc', 'eeepc-laptop' and 'bugzilla-14445' into release
[safe/jmp/linux-2.6] / drivers / staging / hv / NetVsc.c
index 13f36a7..d384c0d 100644 (file)
@@ -50,9 +50,9 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device);
 
 static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device);
 
-static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice);
+static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice);
 
-static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice);
+static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice);
 
 static int NetVscConnectToVsp(struct hv_device *Device);
 
@@ -71,11 +71,11 @@ static void NetVscSendReceiveCompletion(struct hv_device *Device,
                                        u64 TransactionId);
 
 
-static struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device)
+static struct netvsc_device *AllocNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
-       netDevice = kzalloc(sizeof(struct NETVSC_DEVICE), GFP_KERNEL);
+       netDevice = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL);
        if (!netDevice)
                return NULL;
 
@@ -88,7 +88,7 @@ static struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device)
        return netDevice;
 }
 
-static void FreeNetDevice(struct NETVSC_DEVICE *Device)
+static void FreeNetDevice(struct netvsc_device *Device)
 {
        ASSERT(atomic_read(&Device->RefCount) == 0);
        Device->Device->Extension = NULL;
@@ -97,9 +97,9 @@ static void FreeNetDevice(struct NETVSC_DEVICE *Device)
 
 
 /* Get the net device object iff exists and its refcount > 1 */
-static struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device)
+static struct netvsc_device *GetOutboundNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
        netDevice = Device->Extension;
        if (netDevice && atomic_read(&netDevice->RefCount) > 1)
@@ -111,9 +111,9 @@ static struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device)
 }
 
 /* Get the net device object iff exists and its refcount > 0 */
-static struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device)
+static struct netvsc_device *GetInboundNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
        netDevice = Device->Extension;
        if (netDevice && atomic_read(&netDevice->RefCount))
@@ -126,7 +126,7 @@ static struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device)
 
 static void PutNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
        netDevice = Device->Extension;
        ASSERT(netDevice);
@@ -134,9 +134,9 @@ static void PutNetDevice(struct hv_device *Device)
        atomic_dec(&netDevice->RefCount);
 }
 
-static struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device)
+static struct netvsc_device *ReleaseOutboundNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
        netDevice = Device->Extension;
        if (netDevice == NULL)
@@ -149,9 +149,9 @@ static struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device)
        return netDevice;
 }
 
-static struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device)
+static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
 
        netDevice = Device->Extension;
        if (netDevice == NULL)
@@ -208,7 +208,7 @@ int NetVscInitialize(struct hv_driver *drv)
 static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
 {
        int ret = 0;
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        struct nvsp_message *initPacket;
 
        DPRINT_ENTER(NETVSC);
@@ -339,7 +339,7 @@ Exit:
 static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device)
 {
        int ret = 0;
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        struct nvsp_message *initPacket;
 
        DPRINT_ENTER(NETVSC);
@@ -431,7 +431,7 @@ Exit:
        return ret;
 }
 
-static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice)
+static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
 {
        struct nvsp_message *revokePacket;
        int ret = 0;
@@ -511,7 +511,7 @@ static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice)
        return ret;
 }
 
-static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice)
+static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice)
 {
        struct nvsp_message *revokePacket;
        int ret = 0;
@@ -589,7 +589,7 @@ static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice)
 static int NetVscConnectToVsp(struct hv_device *Device)
 {
        int ret;
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        struct nvsp_message *initPacket;
        int ndisVersion;
 
@@ -693,7 +693,7 @@ Cleanup:
        return ret;
 }
 
-static void NetVscDisconnectFromVsp(struct NETVSC_DEVICE *NetDevice)
+static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice)
 {
        DPRINT_ENTER(NETVSC);
 
@@ -710,9 +710,8 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
 {
        int ret = 0;
        int i;
-       struct NETVSC_DEVICE *netDevice;
-       struct hv_netvsc_packet *packet;
-       LIST_ENTRY *entry;
+       struct netvsc_device *netDevice;
+       struct hv_netvsc_packet *packet, *pos;
        struct netvsc_driver *netDriver =
                                (struct netvsc_driver *)Device->Driver;
 
@@ -732,7 +731,7 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
 
        netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE;
 
-       INITIALIZE_LIST_HEAD(&netDevice->ReceivePacketList);
+       INIT_LIST_HEAD(&netDevice->ReceivePacketList);
 
        for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) {
                packet = kzalloc(sizeof(struct hv_netvsc_packet) +
@@ -744,9 +743,8 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
                                   NETVSC_RECEIVE_PACKETLIST_COUNT, i);
                        break;
                }
-
-               INSERT_TAIL_LIST(&netDevice->ReceivePacketList,
-                                &packet->ListEntry);
+               list_add_tail(&packet->ListEntry,
+                             &netDevice->ReceivePacketList);
        }
        netDevice->ChannelInitEvent = osd_WaitEventCreate();
 
@@ -790,11 +788,10 @@ Cleanup:
        if (netDevice) {
                kfree(netDevice->ChannelInitEvent);
 
-               while (!IsListEmpty(&netDevice->ReceivePacketList)) {
-                       entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-                       packet = CONTAINING_RECORD(entry,
-                                                  struct hv_netvsc_packet,
-                                                  ListEntry);
+               list_for_each_entry_safe(packet, pos,
+                                        &netDevice->ReceivePacketList,
+                                        ListEntry) {
+                       list_del(&packet->ListEntry);
                        kfree(packet);
                }
 
@@ -813,9 +810,8 @@ Cleanup:
  */
 static int NetVscOnDeviceRemove(struct hv_device *Device)
 {
-       struct NETVSC_DEVICE *netDevice;
-       struct hv_netvsc_packet *netvscPacket;
-       LIST_ENTRY *entry;
+       struct netvsc_device *netDevice;
+       struct hv_netvsc_packet *netvscPacket, *pos;
 
        DPRINT_ENTER(NETVSC);
 
@@ -853,12 +849,9 @@ static int NetVscOnDeviceRemove(struct hv_device *Device)
        Device->Driver->VmbusChannelInterface.Close(Device);
 
        /* Release all resources */
-       while (!IsListEmpty(&netDevice->ReceivePacketList)) {
-               entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-               netvscPacket = CONTAINING_RECORD(entry,
-                                                struct hv_netvsc_packet,
-                                                ListEntry);
-
+       list_for_each_entry_safe(netvscPacket, pos,
+                                &netDevice->ReceivePacketList, ListEntry) {
+               list_del(&netvscPacket->ListEntry);
                kfree(netvscPacket);
        }
 
@@ -881,7 +874,7 @@ static void NetVscOnCleanup(struct hv_driver *drv)
 static void NetVscOnSendCompletion(struct hv_device *Device,
                                   struct vmpacket_descriptor *Packet)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        struct nvsp_message *nvspPacket;
        struct hv_netvsc_packet *nvscPacket;
 
@@ -931,7 +924,7 @@ static void NetVscOnSendCompletion(struct hv_device *Device,
 static int NetVscOnSend(struct hv_device *Device,
                        struct hv_netvsc_packet *Packet)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        int ret = 0;
 
        struct nvsp_message sendMessage;
@@ -990,19 +983,18 @@ static int NetVscOnSend(struct hv_device *Device,
 static void NetVscOnReceive(struct hv_device *Device,
                            struct vmpacket_descriptor *Packet)
 {
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        struct vmtransfer_page_packet_header *vmxferpagePacket;
        struct nvsp_message *nvspPacket;
        struct hv_netvsc_packet *netvscPacket = NULL;
-       LIST_ENTRY *entry;
        unsigned long start;
        unsigned long end, endVirtual;
        /* struct netvsc_driver *netvscDriver; */
        struct xferpage_packet *xferpagePacket = NULL;
-       LIST_ENTRY listHead;
        int i, j;
        int count = 0, bytesRemain = 0;
        unsigned long flags;
+       LIST_HEAD(listHead);
 
        DPRINT_ENTER(NETVSC);
 
@@ -1052,8 +1044,6 @@ static void NetVscOnReceive(struct hv_device *Device,
        DPRINT_DBG(NETVSC, "xfer page - range count %d",
                   vmxferpagePacket->RangeCount);
 
-       INITIALIZE_LIST_HEAD(&listHead);
-
        /*
         * Grab free packets (range count + 1) to represent this xfer
         * page packet. +1 to represent the xfer page packet itself.
@@ -1061,14 +1051,8 @@ static void NetVscOnReceive(struct hv_device *Device,
         * fulfil
         */
        spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
-       while (!IsListEmpty(&netDevice->ReceivePacketList)) {
-               entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-               netvscPacket = CONTAINING_RECORD(entry,
-                                                struct hv_netvsc_packet,
-                                                ListEntry);
-
-               INSERT_TAIL_LIST(&listHead, &netvscPacket->ListEntry);
-
+       while (!list_empty(&netDevice->ReceivePacketList)) {
+               list_move_tail(netDevice->ReceivePacketList.next, &listHead);
                if (++count == vmxferpagePacket->RangeCount + 1)
                        break;
        }
@@ -1087,13 +1071,8 @@ static void NetVscOnReceive(struct hv_device *Device,
                /* Return it to the freelist */
                spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
                for (i = count; i != 0; i--) {
-                       entry = REMOVE_HEAD_LIST(&listHead);
-                       netvscPacket = CONTAINING_RECORD(entry,
-                                               struct hv_netvsc_packet,
-                                               ListEntry);
-
-                       INSERT_TAIL_LIST(&netDevice->ReceivePacketList,
-                                        &netvscPacket->ListEntry);
+                       list_move_tail(listHead.next,
+                                      &netDevice->ReceivePacketList);
                }
                spin_unlock_irqrestore(&netDevice->receive_packet_list_lock,
                                       flags);
@@ -1106,9 +1085,9 @@ static void NetVscOnReceive(struct hv_device *Device,
        }
 
        /* Remove the 1st packet to represent the xfer page packet itself */
-       entry = REMOVE_HEAD_LIST(&listHead);
-       xferpagePacket = CONTAINING_RECORD(entry, struct xferpage_packet,
-                                          ListEntry);
+       xferpagePacket = (struct xferpage_packet*)listHead.next;
+       list_del(&xferpagePacket->ListEntry);
+
        /* This is how much we can satisfy */
        xferpagePacket->Count = count - 1;
        ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <=
@@ -1122,10 +1101,8 @@ static void NetVscOnReceive(struct hv_device *Device,
 
        /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
        for (i = 0; i < (count - 1); i++) {
-               entry = REMOVE_HEAD_LIST(&listHead);
-               netvscPacket = CONTAINING_RECORD(entry,
-                                                struct hv_netvsc_packet,
-                                                ListEntry);
+               netvscPacket = (struct hv_netvsc_packet*)listHead.next;
+               list_del(&netvscPacket->ListEntry);
 
                /* Initialize the netvsc packet */
                netvscPacket->XferPagePacket = xferpagePacket;
@@ -1198,7 +1175,7 @@ static void NetVscOnReceive(struct hv_device *Device,
                NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext);
        }
 
-       ASSERT(IsListEmpty(&listHead));
+       ASSERT(list_empty(&listHead));
 
        PutNetDevice(Device);
        DPRINT_EXIT(NETVSC);
@@ -1255,7 +1232,7 @@ static void NetVscOnReceiveCompletion(void *Context)
 {
        struct hv_netvsc_packet *packet = Context;
        struct hv_device *device = (struct hv_device *)packet->Device;
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        u64 transactionId = 0;
        bool fSendReceiveComp = false;
        unsigned long flags;
@@ -1290,13 +1267,13 @@ static void NetVscOnReceiveCompletion(void *Context)
        if (packet->XferPagePacket->Count == 0) {
                fSendReceiveComp = true;
                transactionId = packet->Completion.Recv.ReceiveCompletionTid;
+               list_add_tail(&packet->XferPagePacket->ListEntry,
+                             &netDevice->ReceivePacketList);
 
-               INSERT_TAIL_LIST(&netDevice->ReceivePacketList,
-                                &packet->XferPagePacket->ListEntry);
        }
 
        /* Put the packet back */
-       INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
+       list_add_tail(&packet->ListEntry, &netDevice->ReceivePacketList);
        spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
        /* Send a receive completion for the xfer page packet */
@@ -1312,7 +1289,7 @@ void NetVscOnChannelCallback(void *Context)
        const int netPacketSize = 2048;
        int ret;
        struct hv_device *device = Context;
-       struct NETVSC_DEVICE *netDevice;
+       struct netvsc_device *netDevice;
        u32 bytesRecvd;
        u64 requestId;
        unsigned char packet[netPacketSize];