Commit f4888417 authored by Bill Pemberton's avatar Bill Pemberton Committed by Greg Kroah-Hartman

Staging: hv: remove wrapper functions for atomic operations

Signed-off-by: default avatarBill Pemberton <wfp5p@virginia.edu>
Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 7c369f40
...@@ -540,8 +540,8 @@ VmbusChannelEstablishGpadl( ...@@ -540,8 +540,8 @@ VmbusChannelEstablishGpadl(
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
nextGpadlHandle = gVmbusConnection.NextGpadlHandle; nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
InterlockedIncrement((int*)&gVmbusConnection.NextGpadlHandle); atomic_inc(&gVmbusConnection.NextGpadlHandle);
VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount); VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
ASSERT(msgInfo != NULL); ASSERT(msgInfo != NULL);
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
struct VMBUS_CONNECTION gVmbusConnection = { struct VMBUS_CONNECTION gVmbusConnection = {
.ConnectState = Disconnected, .ConnectState = Disconnected,
.NextGpadlHandle = 0xE1E10, .NextGpadlHandle = ATOMIC_INIT(0xE1E10),
}; };
......
...@@ -122,7 +122,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) ...@@ -122,7 +122,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device)
return NULL; return NULL;
/* Set to 2 to allow both inbound and outbound traffic */ /* Set to 2 to allow both inbound and outbound traffic */
InterlockedCompareExchange(&netDevice->RefCount, 2, 0); atomic_cmpxchg(&netDevice->RefCount, 0, 2);
netDevice->Device = Device; netDevice->Device = Device;
Device->Extension = netDevice; Device->Extension = netDevice;
...@@ -132,7 +132,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) ...@@ -132,7 +132,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device)
static inline void FreeNetDevice(struct NETVSC_DEVICE *Device) static inline void FreeNetDevice(struct NETVSC_DEVICE *Device)
{ {
ASSERT(Device->RefCount == 0); ASSERT(atomic_read(&Device->RefCount) == 0);
Device->Device->Extension = NULL; Device->Device->Extension = NULL;
kfree(Device); kfree(Device);
} }
...@@ -144,14 +144,10 @@ static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Devic ...@@ -144,14 +144,10 @@ static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Devic
struct NETVSC_DEVICE *netDevice; struct NETVSC_DEVICE *netDevice;
netDevice = (struct NETVSC_DEVICE*)Device->Extension; netDevice = (struct NETVSC_DEVICE*)Device->Extension;
if (netDevice && netDevice->RefCount > 1) if (netDevice && atomic_read(&netDevice->RefCount) > 1)
{ atomic_inc(&netDevice->RefCount);
InterlockedIncrement(&netDevice->RefCount);
}
else else
{
netDevice = NULL; netDevice = NULL;
}
return netDevice; return netDevice;
} }
...@@ -162,14 +158,10 @@ static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device ...@@ -162,14 +158,10 @@ static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device
struct NETVSC_DEVICE *netDevice; struct NETVSC_DEVICE *netDevice;
netDevice = (struct NETVSC_DEVICE*)Device->Extension; netDevice = (struct NETVSC_DEVICE*)Device->Extension;
if (netDevice && netDevice->RefCount) if (netDevice && atomic_read(&netDevice->RefCount))
{ atomic_inc(&netDevice->RefCount);
InterlockedIncrement(&netDevice->RefCount);
}
else else
{
netDevice = NULL; netDevice = NULL;
}
return netDevice; return netDevice;
} }
...@@ -181,7 +173,7 @@ static inline void PutNetDevice(struct hv_device *Device) ...@@ -181,7 +173,7 @@ static inline void PutNetDevice(struct hv_device *Device)
netDevice = (struct NETVSC_DEVICE*)Device->Extension; netDevice = (struct NETVSC_DEVICE*)Device->Extension;
ASSERT(netDevice); ASSERT(netDevice);
InterlockedDecrement(&netDevice->RefCount); atomic_dec(&netDevice->RefCount);
} }
static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device) static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device)
...@@ -193,7 +185,7 @@ static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *D ...@@ -193,7 +185,7 @@ static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *D
return NULL; return NULL;
/* Busy wait until the ref drop to 2, then set it to 1 */ /* Busy wait until the ref drop to 2, then set it to 1 */
while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2) while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2)
{ {
udelay(100); udelay(100);
} }
...@@ -210,7 +202,7 @@ static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *De ...@@ -210,7 +202,7 @@ static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *De
return NULL; return NULL;
/* Busy wait until the ref drop to 1, then set it to 0 */ /* Busy wait until the ref drop to 1, then set it to 0 */
while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1) while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1)
{ {
udelay(100); udelay(100);
} }
...@@ -932,9 +924,9 @@ NetVscOnDeviceRemove( ...@@ -932,9 +924,9 @@ NetVscOnDeviceRemove(
} }
/* Wait for all send completions */ /* Wait for all send completions */
while (netDevice->NumOutstandingSends) while (atomic_read(&netDevice->NumOutstandingSends))
{ {
DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends); DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", atomic_read(&netDevice->NumOutstandingSends));
udelay(100); udelay(100);
} }
...@@ -1032,7 +1024,7 @@ NetVscOnSendCompletion( ...@@ -1032,7 +1024,7 @@ NetVscOnSendCompletion(
/* Notify the layer above us */ /* Notify the layer above us */
nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext);
InterlockedDecrement(&netDevice->NumOutstandingSends); atomic_dec(&netDevice->NumOutstandingSends);
} }
else else
{ {
...@@ -1101,7 +1093,7 @@ NetVscOnSend( ...@@ -1101,7 +1093,7 @@ NetVscOnSend(
DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret); DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret);
} }
InterlockedIncrement(&netDevice->NumOutstandingSends); atomic_inc(&netDevice->NumOutstandingSends);
PutNetDevice(Device); PutNetDevice(Device);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
......
...@@ -57,9 +57,8 @@ ...@@ -57,9 +57,8 @@
struct NETVSC_DEVICE { struct NETVSC_DEVICE {
struct hv_device *Device; struct hv_device *Device;
int RefCount; atomic_t RefCount;
atomic_t NumOutstandingSends;
int NumOutstandingSends;
/* List of free preallocated hv_netvsc_packet to represent receive packet */ /* List of free preallocated hv_netvsc_packet to represent receive packet */
LIST_ENTRY ReceivePacketList; LIST_ENTRY ReceivePacketList;
spinlock_t receive_packet_list_lock; spinlock_t receive_packet_list_lock;
......
...@@ -50,7 +50,7 @@ typedef struct _RNDIS_DEVICE { ...@@ -50,7 +50,7 @@ typedef struct _RNDIS_DEVICE {
RNDIS_DEVICE_STATE State; RNDIS_DEVICE_STATE State;
u32 LinkStatus; u32 LinkStatus;
u32 NewRequestId; atomic_t NewRequestId;
spinlock_t request_lock; spinlock_t request_lock;
LIST_ENTRY RequestList; LIST_ENTRY RequestList;
...@@ -255,7 +255,7 @@ static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageTy ...@@ -255,7 +255,7 @@ static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageTy
/* Set the request id. This field is always after the rndis header for request/response packet types so */ /* Set the request id. This field is always after the rndis header for request/response packet types so */
/* we just used the SetRequest as a template */ /* we just used the SetRequest as a template */
set = &rndisMessage->Message.SetRequest; set = &rndisMessage->Message.SetRequest;
set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); set->RequestId = atomic_inc_return(&Device->NewRequestId);
/* Add to the request list */ /* Add to the request list */
spin_lock_irqsave(&Device->request_lock, flags); spin_lock_irqsave(&Device->request_lock, flags);
...@@ -863,7 +863,7 @@ RndisFilterHaltDevice( ...@@ -863,7 +863,7 @@ RndisFilterHaltDevice(
/* Setup the rndis set */ /* Setup the rndis set */
halt = &request->RequestMessage.Message.HaltRequest; halt = &request->RequestMessage.Message.HaltRequest;
halt->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); halt->RequestId = atomic_inc_return(&Device->NewRequestId);
/* Ignore return since this msg is optional. */ /* Ignore return since this msg is optional. */
RndisFilterSendRequest(Device, request); RndisFilterSendRequest(Device, request);
......
...@@ -57,9 +57,9 @@ typedef struct _STORVSC_REQUEST_EXTENSION { ...@@ -57,9 +57,9 @@ typedef struct _STORVSC_REQUEST_EXTENSION {
typedef struct _STORVSC_DEVICE{ typedef struct _STORVSC_DEVICE{
struct hv_device *Device; struct hv_device *Device;
int RefCount; /* 0 indicates the device is being destroyed */ atomic_t RefCount; /* 0 indicates the device is being destroyed */
int NumOutstandingRequests; atomic_t NumOutstandingRequests;
/* /*
* Each unique Port/Path/Target represents 1 channel ie scsi * Each unique Port/Path/Target represents 1 channel ie scsi
...@@ -155,7 +155,7 @@ static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device) ...@@ -155,7 +155,7 @@ static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device)
/* Set to 2 to allow both inbound and outbound traffics */ /* Set to 2 to allow both inbound and outbound traffics */
/* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */ /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
InterlockedCompareExchange(&storDevice->RefCount, 2, 0); atomic_cmpxchg(&storDevice->RefCount, 0, 2);
storDevice->Device = Device; storDevice->Device = Device;
Device->Extension = storDevice; Device->Extension = storDevice;
...@@ -165,7 +165,7 @@ static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device) ...@@ -165,7 +165,7 @@ static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device)
static inline void FreeStorDevice(STORVSC_DEVICE *Device) static inline void FreeStorDevice(STORVSC_DEVICE *Device)
{ {
ASSERT(Device->RefCount == 0); ASSERT( atomic_read(&Device->RefCount) == 0);
kfree(Device); kfree(Device);
} }
...@@ -175,14 +175,10 @@ static inline STORVSC_DEVICE* GetStorDevice(struct hv_device *Device) ...@@ -175,14 +175,10 @@ static inline STORVSC_DEVICE* GetStorDevice(struct hv_device *Device)
STORVSC_DEVICE *storDevice; STORVSC_DEVICE *storDevice;
storDevice = (STORVSC_DEVICE*)Device->Extension; storDevice = (STORVSC_DEVICE*)Device->Extension;
if (storDevice && storDevice->RefCount > 1) if (storDevice && atomic_read(&storDevice->RefCount) > 1)
{ atomic_inc(&storDevice->RefCount);
InterlockedIncrement(&storDevice->RefCount);
}
else else
{
storDevice = NULL; storDevice = NULL;
}
return storDevice; return storDevice;
} }
...@@ -193,14 +189,10 @@ static inline STORVSC_DEVICE* MustGetStorDevice(struct hv_device *Device) ...@@ -193,14 +189,10 @@ static inline STORVSC_DEVICE* MustGetStorDevice(struct hv_device *Device)
STORVSC_DEVICE *storDevice; STORVSC_DEVICE *storDevice;
storDevice = (STORVSC_DEVICE*)Device->Extension; storDevice = (STORVSC_DEVICE*)Device->Extension;
if (storDevice && storDevice->RefCount) if (storDevice && atomic_read(&storDevice->RefCount))
{ atomic_inc(&storDevice->RefCount);
InterlockedIncrement(&storDevice->RefCount);
}
else else
{
storDevice = NULL; storDevice = NULL;
}
return storDevice; return storDevice;
} }
...@@ -212,8 +204,8 @@ static inline void PutStorDevice(struct hv_device *Device) ...@@ -212,8 +204,8 @@ static inline void PutStorDevice(struct hv_device *Device)
storDevice = (STORVSC_DEVICE*)Device->Extension; storDevice = (STORVSC_DEVICE*)Device->Extension;
ASSERT(storDevice); ASSERT(storDevice);
InterlockedDecrement(&storDevice->RefCount); atomic_dec(&storDevice->RefCount);
ASSERT(storDevice->RefCount); ASSERT(atomic_read(&storDevice->RefCount));
} }
/* Drop ref count to 1 to effectively disable GetStorDevice() */ /* Drop ref count to 1 to effectively disable GetStorDevice() */
...@@ -225,7 +217,7 @@ static inline STORVSC_DEVICE* ReleaseStorDevice(struct hv_device *Device) ...@@ -225,7 +217,7 @@ static inline STORVSC_DEVICE* ReleaseStorDevice(struct hv_device *Device)
ASSERT(storDevice); ASSERT(storDevice);
/* Busy wait until the ref drop to 2, then set it to 1 */ /* Busy wait until the ref drop to 2, then set it to 1 */
while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2) while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2)
{ {
udelay(100); udelay(100);
} }
...@@ -242,7 +234,7 @@ static inline STORVSC_DEVICE* FinalReleaseStorDevice(struct hv_device *Device) ...@@ -242,7 +234,7 @@ static inline STORVSC_DEVICE* FinalReleaseStorDevice(struct hv_device *Device)
ASSERT(storDevice); ASSERT(storDevice);
/* Busy wait until the ref drop to 1, then set it to 0 */ /* Busy wait until the ref drop to 1, then set it to 0 */
while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1) while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1)
{ {
udelay(100); udelay(100);
} }
...@@ -591,9 +583,9 @@ StorVscOnDeviceRemove( ...@@ -591,9 +583,9 @@ StorVscOnDeviceRemove(
* only allow inbound traffic (responses) to proceed so that * only allow inbound traffic (responses) to proceed so that
* outstanding requests can be completed. * outstanding requests can be completed.
*/ */
while (storDevice->NumOutstandingRequests) while (atomic_read(&storDevice->NumOutstandingRequests))
{ {
DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests); DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", atomic_read(&storDevice->NumOutstandingRequests));
udelay(100); udelay(100);
} }
...@@ -788,7 +780,7 @@ StorVscOnIORequest( ...@@ -788,7 +780,7 @@ StorVscOnIORequest(
DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret); DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret);
} }
InterlockedIncrement(&storDevice->NumOutstandingRequests); atomic_inc(&storDevice->NumOutstandingRequests);
PutStorDevice(Device); PutStorDevice(Device);
...@@ -877,7 +869,7 @@ StorVscOnIOCompletion( ...@@ -877,7 +869,7 @@ StorVscOnIOCompletion(
request->OnIOCompletion(request); request->OnIOCompletion(request);
InterlockedDecrement(&storDevice->NumOutstandingRequests); atomic_dec(&storDevice->NumOutstandingRequests);
PutStorDevice(Device); PutStorDevice(Device);
......
...@@ -67,7 +67,7 @@ struct VMBUS_CONNECTION { ...@@ -67,7 +67,7 @@ struct VMBUS_CONNECTION {
enum VMBUS_CONNECT_STATE ConnectState; enum VMBUS_CONNECT_STATE ConnectState;
u32 NextGpadlHandle; atomic_t NextGpadlHandle;
/* /*
* Represents channel interrupts. Each bit position represents * Represents channel interrupts. Each bit position represents
......
...@@ -109,10 +109,6 @@ static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *eb ...@@ -109,10 +109,6 @@ static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *eb
/* Osd routines */ /* Osd routines */
extern int InterlockedIncrement(int *val);
extern int InterlockedDecrement(int *val);
extern int InterlockedCompareExchange(int *val, int new, int curr);
extern void* VirtualAllocExec(unsigned int size); extern void* VirtualAllocExec(unsigned int size);
extern void VirtualFree(void* VirtAddr); extern void VirtualFree(void* VirtAddr);
......
...@@ -56,26 +56,6 @@ struct osd_callback_struct { ...@@ -56,26 +56,6 @@ struct osd_callback_struct {
void *data; void *data;
}; };
int InterlockedIncrement(int *val)
{
return atomic_inc_return((atomic_t*)val);
}
int InterlockedDecrement(int *val)
{
return atomic_dec_return((atomic_t*)val);
}
#ifndef atomic_cmpxchg
#define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new))
#endif
int InterlockedCompareExchange(int *val, int new, int curr)
{
/* return ((int)cmpxchg(((atomic_t*)val), curr, new)); */
return atomic_cmpxchg((atomic_t*)val, curr, new);
}
void* VirtualAllocExec(unsigned int size) void* VirtualAllocExec(unsigned int size)
{ {
#ifdef __x86_64__ #ifdef __x86_64__
......
...@@ -606,7 +606,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, struct ...@@ -606,7 +606,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, struct
int ret=0; int ret=0;
struct device_context *root_device_ctx = to_device_context(root_device_obj); struct device_context *root_device_ctx = to_device_context(root_device_obj);
struct device_context *child_device_ctx = to_device_context(child_device_obj); struct device_context *child_device_ctx = to_device_context(child_device_obj);
static int device_num=0; static atomic_t device_num = ATOMIC_INIT(0);
DPRINT_ENTER(VMBUS_DRV); DPRINT_ENTER(VMBUS_DRV);
...@@ -623,7 +623,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, struct ...@@ -623,7 +623,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, struct
} }
/* Set the device bus id. Otherwise, device_register()will fail. */ /* Set the device bus id. Otherwise, device_register()will fail. */
dev_set_name(&child_device_ctx->device, "vmbus_0_%d", InterlockedIncrement(&device_num)); dev_set_name(&child_device_ctx->device, "vmbus_0_%d", atomic_inc_return(&device_num));
/* The new device belongs to this bus */ /* The new device belongs to this bus */
child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
......
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