Staging: hv: make netDevice->ReceivePacketListLock a real spinlock
authorGreg Kroah-Hartman <gregkh@suse.de>
Wed, 15 Jul 2009 21:56:15 +0000 (14:56 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 15 Sep 2009 19:01:48 +0000 (12:01 -0700)
Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/NetVsc.c
drivers/staging/hv/NetVsc.h

index a915599e1c2154a25e855c943debb53fe9d823f5..7a7a382a45a2e39771e6eb3405cea28b98f639d4 100644 (file)
@@ -807,7 +807,7 @@ NetVscOnDeviceAdd(
 
        // Initialize the NetVSC channel extension
        netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE;
-       netDevice->ReceivePacketListLock = SpinlockCreate();
+       spin_lock_init(&netDevice->receive_packet_list_lock);
 
        netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE;
 
@@ -876,8 +876,6 @@ Cleanup:
                        kfree(packet);
                }
 
-               SpinlockClose(netDevice->ReceivePacketListLock);
-
                ReleaseOutboundNetDevice(Device);
                ReleaseInboundNetDevice(Device);
 
@@ -952,7 +950,6 @@ NetVscOnDeviceRemove(
                kfree(netvscPacket);
        }
 
-       SpinlockClose(netDevice->ReceivePacketListLock);
        WaitEventClose(netDevice->ChannelInitEvent);
        FreeNetDevice(netDevice);
 
@@ -1118,6 +1115,7 @@ NetVscOnReceive(
 
        int i=0, j=0;
        int count=0, bytesRemain=0;
+       unsigned long flags;
 
        DPRINT_ENTER(NETVSC);
 
@@ -1164,7 +1162,7 @@ NetVscOnReceive(
 
        // Grab free packets (range count + 1) to represent this xfer page packet. +1 to represent
        // the xfer page packet itself. We grab it here so that we know exactly how many we can fulfil
-       SpinlockAcquire(netDevice->ReceivePacketListLock);
+       spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
        while (!IsListEmpty(&netDevice->ReceivePacketList))
        {
                entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
@@ -1175,7 +1173,7 @@ NetVscOnReceive(
                if (++count == vmxferpagePacket->RangeCount + 1)
                        break;
        }
-       SpinlockRelease(netDevice->ReceivePacketListLock);
+       spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
        // We need at least 2 netvsc pkts (1 to represent the xfer page and at least 1 for the range)
        // i.e. we can handled some of the xfer page packet ranges...
@@ -1184,7 +1182,7 @@ NetVscOnReceive(
                DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. Dropping this xfer page packet completely!", count, vmxferpagePacket->RangeCount+1);
 
                // Return it to the freelist
-               SpinlockAcquire(netDevice->ReceivePacketListLock);
+               spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
                for (i=count; i != 0; i--)
                {
                        entry = REMOVE_HEAD_LIST(&listHead);
@@ -1192,7 +1190,7 @@ NetVscOnReceive(
 
                        INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &netvscPacket->ListEntry);
                }
-               SpinlockRelease(netDevice->ReceivePacketListLock);
+               spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
                NetVscSendReceiveCompletion(Device, vmxferpagePacket->d.TransactionId);
 
@@ -1346,6 +1344,7 @@ NetVscOnReceiveCompletion(
        NETVSC_DEVICE* netDevice;
        u64     transactionId=0;
        bool fSendReceiveComp = false;
+       unsigned long flags;
 
        DPRINT_ENTER(NETVSC);
 
@@ -1362,7 +1361,7 @@ NetVscOnReceiveCompletion(
        }
 
        // Overloading use of the lock.
-       SpinlockAcquire(netDevice->ReceivePacketListLock);
+       spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags);
 
        ASSERT(packet->XferPagePacket->Count > 0);
        packet->XferPagePacket->Count--;
@@ -1379,7 +1378,7 @@ NetVscOnReceiveCompletion(
 
        // Put the packet back
        INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
-       SpinlockRelease(netDevice->ReceivePacketListLock);
+       spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags);
 
        // Send a receive completion for the xfer page packet
        if (fSendReceiveComp)
index 3a7999db851f10a8a266c78a80592016b3c97ad9..d6b0d678c81c9f639c122666cfebac1671ccbd71 100644 (file)
@@ -62,7 +62,7 @@ typedef struct _NETVSC_DEVICE {
        int                                                             NumOutstandingSends;
        // List of free preallocated NETVSC_PACKET to represent receive packet
        LIST_ENTRY                                              ReceivePacketList;
-       HANDLE                                                  ReceivePacketListLock;
+       spinlock_t receive_packet_list_lock;
 
        // Send buffer allocated by us but manages by NetVSP
        void *                                                  SendBuffer;