Commit 0120ee0d authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Staging: hv: coding style cleanup for RndisFilter.c

It's much better now.

Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ff568d3a
/* /*
*
* Copyright (c) 2009, Microsoft Corporation. * Copyright (c) 2009, Microsoft Corporation.
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
...@@ -18,20 +17,15 @@ ...@@ -18,20 +17,15 @@
* Authors: * Authors:
* Haiyang Zhang <haiyangz@microsoft.com> * Haiyang Zhang <haiyangz@microsoft.com>
* Hank Janssen <hjanssen@microsoft.com> * Hank Janssen <hjanssen@microsoft.com>
*
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <asm/kmap_types.h> #include <linux/io.h>
#include <asm/io.h>
#include "osd.h" #include "osd.h"
#include "logging.h" #include "logging.h"
#include "NetVscApi.h" #include "NetVscApi.h"
#include "RndisFilter.h" #include "RndisFilter.h"
/* Data types */ /* Data types */
struct rndis_filter_driver_object { struct rndis_filter_driver_object {
/* The original driver */ /* The original driver */
...@@ -58,13 +52,15 @@ struct rndis_device { ...@@ -58,13 +52,15 @@ struct rndis_device {
unsigned char HwMacAddr[HW_MACADDR_LEN]; unsigned char HwMacAddr[HW_MACADDR_LEN];
}; };
struct rndis_request { struct rndis_request {
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
struct osd_waitevent *WaitEvent; struct osd_waitevent *WaitEvent;
/* FIXME: We assumed a fixed size response here. If we do ever need to handle a bigger response, */ /*
/* we can either define a max response message or add a response buffer variable above this field */ * FIXME: We assumed a fixed size response here. If we do ever need to
* handle a bigger response, we can either define a max response
* message or add a response buffer variable above this field
*/
struct rndis_message ResponseMessage; struct rndis_message ResponseMessage;
/* Simplify allocation by having a netvsc packet inline */ /* Simplify allocation by having a netvsc packet inline */
...@@ -78,131 +74,39 @@ struct rndis_request { ...@@ -78,131 +74,39 @@ struct rndis_request {
struct rndis_filter_packet { struct rndis_filter_packet {
void *CompletionContext; void *CompletionContext;
PFN_ON_SENDRECVCOMPLETION OnCompletion; PFN_ON_SENDRECVCOMPLETION OnCompletion;
struct rndis_message Message; struct rndis_message Message;
}; };
/* Internal routines */ static int RndisFilterOnDeviceAdd(struct hv_device *Device,
void *AdditionalInfo);
static int static int RndisFilterOnDeviceRemove(struct hv_device *Device);
RndisFilterSendRequest(
struct rndis_device *Device,
struct rndis_request *Request
);
static void RndisFilterReceiveResponse(struct rndis_device *Device, static void RndisFilterOnCleanup(struct hv_driver *Driver);
struct rndis_message *Response);
static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device, static int RndisFilterOnOpen(struct hv_device *Device);
struct rndis_message *Response);
static void RndisFilterReceiveData(struct rndis_device *Device, static int RndisFilterOnClose(struct hv_device *Device);
struct rndis_message *Message,
static int RndisFilterOnSend(struct hv_device *Device,
struct hv_netvsc_packet *Packet); struct hv_netvsc_packet *Packet);
static int RndisFilterOnReceive( static void RndisFilterOnSendCompletion(void *Context);
struct hv_device *Device,
struct hv_netvsc_packet *Packet static void RndisFilterOnSendRequestCompletion(void *Context);
);
static int
RndisFilterQueryDevice(
struct rndis_device *Device,
u32 Oid,
void *Result,
u32 *ResultSize
);
static inline int
RndisFilterQueryDeviceMac(
struct rndis_device *Device
);
static inline int
RndisFilterQueryDeviceLinkStatus(
struct rndis_device *Device
);
static int
RndisFilterSetPacketFilter(
struct rndis_device *Device,
u32 NewFilter
);
static int
RndisFilterInitDevice(
struct rndis_device *Device
);
static int
RndisFilterOpenDevice(
struct rndis_device *Device
);
static int
RndisFilterCloseDevice(
struct rndis_device *Device
);
static int
RndisFilterOnDeviceAdd(
struct hv_device *Device,
void *AdditionalInfo
);
static int
RndisFilterOnDeviceRemove(
struct hv_device *Device
);
static void
RndisFilterOnCleanup(
struct hv_driver *Driver
);
static int
RndisFilterOnOpen(
struct hv_device *Device
);
static int
RndisFilterOnClose(
struct hv_device *Device
);
static int
RndisFilterOnSend(
struct hv_device *Device,
struct hv_netvsc_packet *Packet
);
static void
RndisFilterOnSendCompletion(
void *Context
);
static void
RndisFilterOnSendRequestCompletion(
void *Context
);
/* Global var */
/* The one and only */ /* The one and only */
static struct rndis_filter_driver_object gRndisFilter; static struct rndis_filter_driver_object gRndisFilter;
static inline struct rndis_device *GetRndisDevice(void) static struct rndis_device *GetRndisDevice(void)
{ {
struct rndis_device *device; struct rndis_device *device;
device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL); device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
if (!device) if (!device)
{
return NULL; return NULL;
}
spin_lock_init(&device->request_lock); spin_lock_init(&device->request_lock);
...@@ -213,12 +117,9 @@ static inline struct rndis_device *GetRndisDevice(void) ...@@ -213,12 +117,9 @@ static inline struct rndis_device *GetRndisDevice(void)
return device; return device;
} }
static inline void PutRndisDevice(struct rndis_device *Device) static struct rndis_request *GetRndisRequest(struct rndis_device *Device,
{ u32 MessageType,
kfree(Device); u32 MessageLength)
}
static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device, u32 MessageType, u32 MessageLength)
{ {
struct rndis_request *request; struct rndis_request *request;
struct rndis_message *rndisMessage; struct rndis_message *rndisMessage;
...@@ -227,13 +128,10 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device, ...@@ -227,13 +128,10 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device,
request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL); request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
if (!request) if (!request)
{
return NULL; return NULL;
}
request->WaitEvent = osd_WaitEventCreate(); request->WaitEvent = osd_WaitEventCreate();
if (!request->WaitEvent) if (!request->WaitEvent) {
{
kfree(request); kfree(request);
return NULL; return NULL;
} }
...@@ -242,8 +140,11 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device, ...@@ -242,8 +140,11 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device,
rndisMessage->NdisMessageType = MessageType; rndisMessage->NdisMessageType = MessageType;
rndisMessage->MessageLength = MessageLength; rndisMessage->MessageLength = MessageLength;
/* 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 */ * 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
*/
set = &rndisMessage->Message.SetRequest; set = &rndisMessage->Message.SetRequest;
set->RequestId = atomic_inc_return(&Device->NewRequestId); set->RequestId = atomic_inc_return(&Device->NewRequestId);
...@@ -255,7 +156,8 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device, ...@@ -255,7 +156,8 @@ static inline struct rndis_request *GetRndisRequest(struct rndis_device *Device,
return request; return request;
} }
static inline void PutRndisRequest(struct rndis_device *Device, struct rndis_request *Request) static void PutRndisRequest(struct rndis_device *Device,
struct rndis_request *Request)
{ {
unsigned long flags; unsigned long flags;
...@@ -267,12 +169,14 @@ static inline void PutRndisRequest(struct rndis_device *Device, struct rndis_req ...@@ -267,12 +169,14 @@ static inline void PutRndisRequest(struct rndis_device *Device, struct rndis_req
kfree(Request); kfree(Request);
} }
static inline void DumpRndisMessage(struct rndis_message *RndisMessage) static void DumpRndisMessage(struct rndis_message *RndisMessage)
{ {
switch (RndisMessage->NdisMessageType) switch (RndisMessage->NdisMessageType) {
{
case REMOTE_NDIS_PACKET_MSG: case REMOTE_NDIS_PACKET_MSG:
DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, data offset %u data len %u, # oob %u, oob offset %u, oob len %u, pkt offset %u, pkt len %u", DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, "
"data offset %u data len %u, # oob %u, "
"oob offset %u, oob len %u, pkt offset %u, "
"pkt len %u",
RndisMessage->MessageLength, RndisMessage->MessageLength,
RndisMessage->Message.Packet.DataOffset, RndisMessage->Message.Packet.DataOffset,
RndisMessage->Message.Packet.DataLength, RndisMessage->Message.Packet.DataLength,
...@@ -284,7 +188,10 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage) ...@@ -284,7 +188,10 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage)
break; break;
case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_INITIALIZE_CMPLT:
DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT (len %u, id 0x%x, status 0x%x, major %d, minor %d, device flags %d, max xfer size 0x%x, max pkts %u, pkt aligned %u)", DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT "
"(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
"device flags %d, max xfer size 0x%x, max pkts %u, "
"pkt aligned %u)",
RndisMessage->MessageLength, RndisMessage->MessageLength,
RndisMessage->Message.InitializeComplete.RequestId, RndisMessage->Message.InitializeComplete.RequestId,
RndisMessage->Message.InitializeComplete.Status, RndisMessage->Message.InitializeComplete.Status,
...@@ -297,7 +204,9 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage) ...@@ -297,7 +204,9 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage)
break; break;
case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_QUERY_CMPLT:
DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT (len %u, id 0x%x, status 0x%x, buf len %u, buf offset %u)", DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT "
"(len %u, id 0x%x, status 0x%x, buf len %u, "
"buf offset %u)",
RndisMessage->MessageLength, RndisMessage->MessageLength,
RndisMessage->Message.QueryComplete.RequestId, RndisMessage->Message.QueryComplete.RequestId,
RndisMessage->Message.QueryComplete.Status, RndisMessage->Message.QueryComplete.Status,
...@@ -306,14 +215,16 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage) ...@@ -306,14 +215,16 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage)
break; break;
case REMOTE_NDIS_SET_CMPLT: case REMOTE_NDIS_SET_CMPLT:
DPRINT_DBG(NETVSC, "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", DPRINT_DBG(NETVSC,
"REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)",
RndisMessage->MessageLength, RndisMessage->MessageLength,
RndisMessage->Message.SetComplete.RequestId, RndisMessage->Message.SetComplete.RequestId,
RndisMessage->Message.SetComplete.Status); RndisMessage->Message.SetComplete.Status);
break; break;
case REMOTE_NDIS_INDICATE_STATUS_MSG: case REMOTE_NDIS_INDICATE_STATUS_MSG:
DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG (len %u, status 0x%x, buf len %u, buf offset %u)", DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG "
"(len %u, status 0x%x, buf len %u, buf offset %u)",
RndisMessage->MessageLength, RndisMessage->MessageLength,
RndisMessage->Message.IndicateStatus.Status, RndisMessage->Message.IndicateStatus.Status,
RndisMessage->Message.IndicateStatus.StatusBufferLength, RndisMessage->Message.IndicateStatus.StatusBufferLength,
...@@ -328,13 +239,10 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage) ...@@ -328,13 +239,10 @@ static inline void DumpRndisMessage(struct rndis_message *RndisMessage)
} }
} }
static int static int RndisFilterSendRequest(struct rndis_device *Device,
RndisFilterSendRequest( struct rndis_request *Request)
struct rndis_device *Device,
struct rndis_request *Request
)
{ {
int ret=0; int ret;
struct hv_netvsc_packet *packet; struct hv_netvsc_packet *packet;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
...@@ -346,12 +254,15 @@ RndisFilterSendRequest( ...@@ -346,12 +254,15 @@ RndisFilterSendRequest(
packet->TotalDataBufferLength = Request->RequestMessage.MessageLength; packet->TotalDataBufferLength = Request->RequestMessage.MessageLength;
packet->PageBufferCount = 1; packet->PageBufferCount = 1;
packet->PageBuffers[0].Pfn = virt_to_phys(&Request->RequestMessage) >> PAGE_SHIFT; packet->PageBuffers[0].Pfn = virt_to_phys(&Request->RequestMessage) >>
PAGE_SHIFT;
packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength; packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength;
packet->PageBuffers[0].Offset = (unsigned long)&Request->RequestMessage & (PAGE_SIZE -1); packet->PageBuffers[0].Offset =
(unsigned long)&Request->RequestMessage & (PAGE_SIZE - 1);
packet->Completion.Send.SendCompletionContext = Request;/* packet; */ packet->Completion.Send.SendCompletionContext = Request;/* packet; */
packet->Completion.Send.OnSendCompletion = RndisFilterOnSendRequestCompletion; packet->Completion.Send.OnSendCompletion =
RndisFilterOnSendRequestCompletion;
packet->Completion.Send.SendCompletionTid = (unsigned long)Device; packet->Completion.Send.SendCompletionTid = (unsigned long)Device;
ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet);
...@@ -359,7 +270,6 @@ RndisFilterSendRequest( ...@@ -359,7 +270,6 @@ RndisFilterSendRequest(
return ret; return ret;
} }
static void RndisFilterReceiveResponse(struct rndis_device *Device, static void RndisFilterReceiveResponse(struct rndis_device *Device,
struct rndis_message *Response) struct rndis_message *Response)
{ {
...@@ -372,15 +282,22 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device, ...@@ -372,15 +282,22 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device,
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
spin_lock_irqsave(&Device->request_lock, flags); spin_lock_irqsave(&Device->request_lock, flags);
ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList) ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList) {
{ request = CONTAINING_RECORD(curr, struct rndis_request,
request = CONTAINING_RECORD(curr, struct rndis_request, ListEntry); ListEntry);
/* All request/response message contains RequestId as the 1st field */ /*
if (request->RequestMessage.Message.InitializeRequest.RequestId == Response->Message.InitializeComplete.RequestId) * All request/response message contains RequestId as the 1st
{ * field
DPRINT_DBG(NETVSC, "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)", */
request->RequestMessage.Message.InitializeRequest.RequestId, request->RequestMessage.NdisMessageType, Response->NdisMessageType); if (request->RequestMessage.Message.InitializeRequest.RequestId
== Response->Message.InitializeComplete.RequestId) {
DPRINT_DBG(NETVSC, "found rndis request for "
"this response (id 0x%x req type 0x%x res "
"type 0x%x)",
request->RequestMessage.Message.InitializeRequest.RequestId,
request->RequestMessage.NdisMessageType,
Response->NdisMessageType);
found = true; found = true;
break; break;
...@@ -388,32 +305,31 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device, ...@@ -388,32 +305,31 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device,
} }
spin_unlock_irqrestore(&Device->request_lock, flags); spin_unlock_irqrestore(&Device->request_lock, flags);
if (found) if (found) {
{ if (Response->MessageLength <= sizeof(struct rndis_message)) {
if (Response->MessageLength <= sizeof(struct rndis_message)) memcpy(&request->ResponseMessage, Response,
{ Response->MessageLength);
memcpy(&request->ResponseMessage, Response, Response->MessageLength); } else {
} DPRINT_ERR(NETVSC, "rndis response buffer overflow "
else "detected (size %u max %zu)",
{ Response->MessageLength,
DPRINT_ERR(NETVSC, "rndis response buffer overflow detected (size %u max %zu)", Response->MessageLength, sizeof(struct rndis_filter_packet)); sizeof(struct rndis_filter_packet));
if (Response->NdisMessageType == REMOTE_NDIS_RESET_CMPLT) /* does not have a request id field */ if (Response->NdisMessageType ==
{ REMOTE_NDIS_RESET_CMPLT) {
/* does not have a request id field */
request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW; request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW;
} } else {
else
{
request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW; request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW;
} }
} }
osd_WaitEventSet(request->WaitEvent); osd_WaitEventSet(request->WaitEvent);
} } else {
else DPRINT_ERR(NETVSC, "no rndis request found for this response "
{ "(id 0x%x res type 0x%x)",
DPRINT_ERR(NETVSC, "no rndis request found for this response (id 0x%x res type 0x%x)", Response->Message.InitializeComplete.RequestId,
Response->Message.InitializeComplete.RequestId, Response->NdisMessageType); Response->NdisMessageType);
} }
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
...@@ -422,19 +338,17 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device, ...@@ -422,19 +338,17 @@ static void RndisFilterReceiveResponse(struct rndis_device *Device,
static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device, static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device,
struct rndis_message *Response) struct rndis_message *Response)
{ {
struct rndis_indicate_status *indicate = &Response->Message.IndicateStatus; struct rndis_indicate_status *indicate =
&Response->Message.IndicateStatus;
if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) {
{
gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1); gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1);
} } else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) {
else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT)
{
gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0); gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0);
} } else {
else /*
{ * TODO:
/* TODO: */ */
} }
} }
...@@ -448,12 +362,15 @@ static void RndisFilterReceiveData(struct rndis_device *Device, ...@@ -448,12 +362,15 @@ static void RndisFilterReceiveData(struct rndis_device *Device,
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
/* empty ethernet frame ?? */ /* empty ethernet frame ?? */
ASSERT(Packet->PageBuffers[0].Length > RNDIS_MESSAGE_SIZE(struct rndis_packet)); ASSERT(Packet->PageBuffers[0].Length >
RNDIS_MESSAGE_SIZE(struct rndis_packet));
rndisPacket = &Message->Message.Packet; rndisPacket = &Message->Message.Packet;
/* FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this */ /*
/* netvsc packet (ie TotalDataBufferLength != MessageLength) */ * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
* netvsc packet (ie TotalDataBufferLength != MessageLength)
*/
/* Remove the rndis header and pass it back up the stack */ /* Remove the rndis header and pass it back up the stack */
dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset; dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset;
...@@ -464,18 +381,16 @@ static void RndisFilterReceiveData(struct rndis_device *Device, ...@@ -464,18 +381,16 @@ static void RndisFilterReceiveData(struct rndis_device *Device,
Packet->IsDataPacket = true; Packet->IsDataPacket = true;
gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, Packet); gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device,
Packet);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
} }
static int static int RndisFilterOnReceive(struct hv_device *Device,
RndisFilterOnReceive( struct hv_netvsc_packet *Packet)
struct hv_device *Device,
struct hv_netvsc_packet *Packet
)
{ {
struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; struct NETVSC_DEVICE *netDevice = Device->Extension;
struct rndis_device *rndisDevice; struct rndis_device *rndisDevice;
struct rndis_message rndisMessage; struct rndis_message rndisMessage;
struct rndis_message *rndisHeader; struct rndis_message *rndisHeader;
...@@ -484,74 +399,87 @@ RndisFilterOnReceive( ...@@ -484,74 +399,87 @@ RndisFilterOnReceive(
ASSERT(netDevice); ASSERT(netDevice);
/* Make sure the rndis device state is initialized */ /* Make sure the rndis device state is initialized */
if (!netDevice->Extension) if (!netDevice->Extension) {
{ DPRINT_ERR(NETVSC, "got rndis message but no rndis device..."
DPRINT_ERR(NETVSC, "got rndis message but no rndis device...dropping this message!"); "dropping this message!");
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return -1; return -1;
} }
rndisDevice = (struct rndis_device*)netDevice->Extension; rndisDevice = (struct rndis_device *)netDevice->Extension;
if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) {
{ DPRINT_ERR(NETVSC, "got rndis message but rndis device "
DPRINT_ERR(NETVSC, "got rndis message but rndis device uninitialized...dropping this message!"); "uninitialized...dropping this message!");
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return -1; return -1;
} }
rndisHeader = (struct rndis_message *)kmap_atomic(pfn_to_page(Packet->PageBuffers[0].Pfn), KM_IRQ0); rndisHeader = (struct rndis_message *)kmap_atomic(
pfn_to_page(Packet->PageBuffers[0].Pfn), KM_IRQ0);
rndisHeader = (void*)((unsigned long)rndisHeader + Packet->PageBuffers[0].Offset); rndisHeader = (void *)((unsigned long)rndisHeader +
Packet->PageBuffers[0].Offset);
/* Make sure we got a valid rndis message */ /* Make sure we got a valid rndis message */
/* FIXME: There seems to be a bug in set completion msg where its MessageLength is 16 bytes but */ /*
/* the ByteCount field in the xfer page range shows 52 bytes */ * FIXME: There seems to be a bug in set completion msg where its
* MessageLength is 16 bytes but the ByteCount field in the xfer page
* range shows 52 bytes
* */
#if 0 #if 0
if ( Packet->TotalDataBufferLength != rndisHeader->MessageLength ) if (Packet->TotalDataBufferLength != rndisHeader->MessageLength) {
{ kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset,
kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, KM_IRQ0); KM_IRQ0);
DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u bytes got %u)...dropping this message!", DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u "
rndisHeader->MessageLength, Packet->TotalDataBufferLength); "bytes got %u)...dropping this message!",
rndisHeader->MessageLength,
Packet->TotalDataBufferLength);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return -1; return -1;
} }
#endif #endif
if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && (rndisHeader->MessageLength > sizeof(struct rndis_message))) if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) &&
{ (rndisHeader->MessageLength > sizeof(struct rndis_message))) {
DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow detected (got %u, max %zu)...marking it an error!", DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow "
rndisHeader->MessageLength, sizeof(struct rndis_message)); "detected (got %u, max %zu)...marking it an error!",
rndisHeader->MessageLength,
sizeof(struct rndis_message));
} }
memcpy(&rndisMessage, rndisHeader, (rndisHeader->MessageLength > sizeof(struct rndis_message))?sizeof(struct rndis_message):rndisHeader->MessageLength); memcpy(&rndisMessage, rndisHeader,
(rndisHeader->MessageLength > sizeof(struct rndis_message)) ?
sizeof(struct rndis_message) :
rndisHeader->MessageLength);
kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, KM_IRQ0); kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, KM_IRQ0);
DumpRndisMessage(&rndisMessage); DumpRndisMessage(&rndisMessage);
switch (rndisMessage.NdisMessageType) switch (rndisMessage.NdisMessageType) {
{
/* data msg */
case REMOTE_NDIS_PACKET_MSG: case REMOTE_NDIS_PACKET_MSG:
/* data msg */
RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet); RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet);
break; break;
/* completion msgs */
case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_INITIALIZE_CMPLT:
case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_QUERY_CMPLT:
case REMOTE_NDIS_SET_CMPLT: case REMOTE_NDIS_SET_CMPLT:
/* case REMOTE_NDIS_RESET_CMPLT: */ /* case REMOTE_NDIS_RESET_CMPLT: */
/* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */
/* completion msgs */
RndisFilterReceiveResponse(rndisDevice, &rndisMessage); RndisFilterReceiveResponse(rndisDevice, &rndisMessage);
break; break;
/* notification msgs */
case REMOTE_NDIS_INDICATE_STATUS_MSG: case REMOTE_NDIS_INDICATE_STATUS_MSG:
/* notification msgs */
RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage); RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage);
break; break;
default: default:
DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", rndisMessage.NdisMessageType, rndisMessage.MessageLength); DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)",
rndisMessage.NdisMessageType,
rndisMessage.MessageLength);
break; break;
} }
...@@ -559,29 +487,23 @@ RndisFilterOnReceive( ...@@ -559,29 +487,23 @@ RndisFilterOnReceive(
return 0; return 0;
} }
static int RndisFilterQueryDevice(struct rndis_device *Device, u32 Oid,
static int void *Result, u32 *ResultSize)
RndisFilterQueryDevice(
struct rndis_device *Device,
u32 Oid,
void *Result,
u32 *ResultSize
)
{ {
struct rndis_request *request; struct rndis_request *request;
u32 inresultSize = *ResultSize; u32 inresultSize = *ResultSize;
struct rndis_query_request *query; struct rndis_query_request *query;
struct rndis_query_complete *queryComplete; struct rndis_query_complete *queryComplete;
int ret=0; int ret = 0;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
ASSERT(Result); ASSERT(Result);
*ResultSize = 0; *ResultSize = 0;
request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, RNDIS_MESSAGE_SIZE(struct rndis_query_request)); request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG,
if (!request) RNDIS_MESSAGE_SIZE(struct rndis_query_request));
{ if (!request) {
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
...@@ -595,62 +517,53 @@ RndisFilterQueryDevice( ...@@ -595,62 +517,53 @@ RndisFilterQueryDevice(
ret = RndisFilterSendRequest(Device, request); ret = RndisFilterSendRequest(Device, request);
if (ret != 0) if (ret != 0)
{
goto Cleanup; goto Cleanup;
}
osd_WaitEventWait(request->WaitEvent); osd_WaitEventWait(request->WaitEvent);
/* Copy the response back */ /* Copy the response back */
queryComplete = &request->ResponseMessage.Message.QueryComplete; queryComplete = &request->ResponseMessage.Message.QueryComplete;
if (queryComplete->InformationBufferLength > inresultSize) if (queryComplete->InformationBufferLength > inresultSize) {
{
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
memcpy(Result, memcpy(Result,
(void*)((unsigned long)queryComplete + queryComplete->InformationBufferOffset), (void *)((unsigned long)queryComplete +
queryComplete->InformationBufferOffset),
queryComplete->InformationBufferLength); queryComplete->InformationBufferLength);
*ResultSize = queryComplete->InformationBufferLength; *ResultSize = queryComplete->InformationBufferLength;
Cleanup: Cleanup:
if (request) if (request)
{
PutRndisRequest(Device, request); PutRndisRequest(Device, request);
}
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
static inline int RndisFilterQueryDeviceMac(struct rndis_device *Device) static int RndisFilterQueryDeviceMac(struct rndis_device *Device)
{ {
u32 size=HW_MACADDR_LEN; u32 size = HW_MACADDR_LEN;
return RndisFilterQueryDevice(Device, return RndisFilterQueryDevice(Device,
RNDIS_OID_802_3_PERMANENT_ADDRESS, RNDIS_OID_802_3_PERMANENT_ADDRESS,
Device->HwMacAddr, Device->HwMacAddr, &size);
&size);
} }
static inline int RndisFilterQueryDeviceLinkStatus(struct rndis_device *Device) static int RndisFilterQueryDeviceLinkStatus(struct rndis_device *Device)
{ {
u32 size=sizeof(u32); u32 size = sizeof(u32);
return RndisFilterQueryDevice(Device, return RndisFilterQueryDevice(Device,
RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
&Device->LinkStatus, &Device->LinkStatus, &size);
&size);
} }
static int static int RndisFilterSetPacketFilter(struct rndis_device *Device,
RndisFilterSetPacketFilter( u32 NewFilter)
struct rndis_device *Device,
u32 NewFilter
)
{ {
struct rndis_request *request; struct rndis_request *request;
struct rndis_set_request *set; struct rndis_set_request *set;
...@@ -660,11 +573,13 @@ RndisFilterSetPacketFilter( ...@@ -660,11 +573,13 @@ RndisFilterSetPacketFilter(
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= sizeof(struct rndis_message)); ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <=
sizeof(struct rndis_message));
request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32)); request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG,
if (!request) RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
{ sizeof(u32));
if (!request) {
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
...@@ -675,37 +590,32 @@ RndisFilterSetPacketFilter( ...@@ -675,37 +590,32 @@ RndisFilterSetPacketFilter(
set->InformationBufferLength = sizeof(u32); set->InformationBufferLength = sizeof(u32);
set->InformationBufferOffset = sizeof(struct rndis_set_request); set->InformationBufferOffset = sizeof(struct rndis_set_request);
memcpy((void*)(unsigned long)set + sizeof(struct rndis_set_request), &NewFilter, sizeof(u32)); memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
&NewFilter, sizeof(u32));
ret = RndisFilterSendRequest(Device, request); ret = RndisFilterSendRequest(Device, request);
if (ret != 0) if (ret != 0)
{
goto Cleanup; goto Cleanup;
}
ret = osd_WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/); ret = osd_WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/);
if (!ret) if (!ret) {
{
ret = -1; ret = -1;
DPRINT_ERR(NETVSC, "timeout before we got a set response..."); DPRINT_ERR(NETVSC, "timeout before we got a set response...");
/* We cant deallocate the request since we may still receive a send completion for it. */ /*
* We cant deallocate the request since we may still receive a
* send completion for it.
*/
goto Exit; goto Exit;
} } else {
else
{
if (ret > 0) if (ret > 0)
{
ret = 0; ret = 0;
}
setComplete = &request->ResponseMessage.Message.SetComplete; setComplete = &request->ResponseMessage.Message.SetComplete;
status = setComplete->Status; status = setComplete->Status;
} }
Cleanup: Cleanup:
if (request) if (request)
{
PutRndisRequest(Device, request); PutRndisRequest(Device, request);
}
Exit: Exit:
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
...@@ -716,7 +626,8 @@ int RndisFilterInit(struct netvsc_driver *Driver) ...@@ -716,7 +626,8 @@ int RndisFilterInit(struct netvsc_driver *Driver)
{ {
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd", sizeof(struct rndis_filter_packet)); DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd",
sizeof(struct rndis_filter_packet));
Driver->RequestExtSize = sizeof(struct rndis_filter_packet); Driver->RequestExtSize = sizeof(struct rndis_filter_packet);
Driver->AdditionalRequestPageBufferCount = 1; /* For rndis header */ Driver->AdditionalRequestPageBufferCount = 1; /* For rndis header */
...@@ -732,14 +643,16 @@ int RndisFilterInit(struct netvsc_driver *Driver) ...@@ -732,14 +643,16 @@ int RndisFilterInit(struct netvsc_driver *Driver)
/* Save the original dispatch handlers before we override it */ /* Save the original dispatch handlers before we override it */
gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd; gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd;
gRndisFilter.InnerDriver.Base.OnDeviceRemove = Driver->Base.OnDeviceRemove; gRndisFilter.InnerDriver.Base.OnDeviceRemove =
Driver->Base.OnDeviceRemove;
gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup; gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup;
ASSERT(Driver->OnSend); ASSERT(Driver->OnSend);
ASSERT(Driver->OnReceiveCallback); ASSERT(Driver->OnReceiveCallback);
gRndisFilter.InnerDriver.OnSend = Driver->OnSend; gRndisFilter.InnerDriver.OnSend = Driver->OnSend;
gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback; gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback;
gRndisFilter.InnerDriver.OnLinkStatusChanged = Driver->OnLinkStatusChanged; gRndisFilter.InnerDriver.OnLinkStatusChanged =
Driver->OnLinkStatusChanged;
/* Override */ /* Override */
Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd; Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd;
...@@ -766,9 +679,9 @@ static int RndisFilterInitDevice(struct rndis_device *Device) ...@@ -766,9 +679,9 @@ static int RndisFilterInitDevice(struct rndis_device *Device)
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG,
if (!request) RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
{ if (!request) {
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
...@@ -777,13 +690,13 @@ static int RndisFilterInitDevice(struct rndis_device *Device) ...@@ -777,13 +690,13 @@ static int RndisFilterInitDevice(struct rndis_device *Device)
init = &request->RequestMessage.Message.InitializeRequest; init = &request->RequestMessage.Message.InitializeRequest;
init->MajorVersion = RNDIS_MAJOR_VERSION; init->MajorVersion = RNDIS_MAJOR_VERSION;
init->MinorVersion = RNDIS_MINOR_VERSION; init->MinorVersion = RNDIS_MINOR_VERSION;
init->MaxTransferSize = 2048; /* FIXME: Use 1536 - rounded ethernet frame size */ /* FIXME: Use 1536 - rounded ethernet frame size */
init->MaxTransferSize = 2048;
Device->State = RNDIS_DEV_INITIALIZING; Device->State = RNDIS_DEV_INITIALIZING;
ret = RndisFilterSendRequest(Device, request); ret = RndisFilterSendRequest(Device, request);
if (ret != 0) if (ret != 0) {
{
Device->State = RNDIS_DEV_UNINITIALIZED; Device->State = RNDIS_DEV_UNINITIALIZED;
goto Cleanup; goto Cleanup;
} }
...@@ -792,22 +705,17 @@ static int RndisFilterInitDevice(struct rndis_device *Device) ...@@ -792,22 +705,17 @@ static int RndisFilterInitDevice(struct rndis_device *Device)
initComplete = &request->ResponseMessage.Message.InitializeComplete; initComplete = &request->ResponseMessage.Message.InitializeComplete;
status = initComplete->Status; status = initComplete->Status;
if (status == RNDIS_STATUS_SUCCESS) if (status == RNDIS_STATUS_SUCCESS) {
{
Device->State = RNDIS_DEV_INITIALIZED; Device->State = RNDIS_DEV_INITIALIZED;
ret = 0; ret = 0;
} } else {
else
{
Device->State = RNDIS_DEV_UNINITIALIZED; Device->State = RNDIS_DEV_UNINITIALIZED;
ret = -1; ret = -1;
} }
Cleanup: Cleanup:
if (request) if (request)
{
PutRndisRequest(Device, request); PutRndisRequest(Device, request);
}
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
...@@ -821,11 +729,10 @@ static void RndisFilterHaltDevice(struct rndis_device *Device) ...@@ -821,11 +729,10 @@ static void RndisFilterHaltDevice(struct rndis_device *Device)
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
/* Attempt to do a rndis device halt */ /* Attempt to do a rndis device halt */
request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG,
RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
if (!request) if (!request)
{
goto Cleanup; goto Cleanup;
}
/* Setup the rndis set */ /* Setup the rndis set */
halt = &request->RequestMessage.Message.HaltRequest; halt = &request->RequestMessage.Message.HaltRequest;
...@@ -838,28 +745,25 @@ static void RndisFilterHaltDevice(struct rndis_device *Device) ...@@ -838,28 +745,25 @@ static void RndisFilterHaltDevice(struct rndis_device *Device)
Cleanup: Cleanup:
if (request) if (request)
{
PutRndisRequest(Device, request); PutRndisRequest(Device, request);
}
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return; return;
} }
static int RndisFilterOpenDevice(struct rndis_device *Device) static int RndisFilterOpenDevice(struct rndis_device *Device)
{ {
int ret=0; int ret;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
if (Device->State != RNDIS_DEV_INITIALIZED) if (Device->State != RNDIS_DEV_INITIALIZED)
return 0; return 0;
ret = RndisFilterSetPacketFilter(Device, NDIS_PACKET_TYPE_BROADCAST|NDIS_PACKET_TYPE_DIRECTED); ret = RndisFilterSetPacketFilter(Device,
NDIS_PACKET_TYPE_BROADCAST |
NDIS_PACKET_TYPE_DIRECTED);
if (ret == 0) if (ret == 0)
{
Device->State = RNDIS_DEV_DATAINITIALIZED; Device->State = RNDIS_DEV_DATAINITIALIZED;
}
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
...@@ -876,53 +780,46 @@ static int RndisFilterCloseDevice(struct rndis_device *Device) ...@@ -876,53 +780,46 @@ static int RndisFilterCloseDevice(struct rndis_device *Device)
ret = RndisFilterSetPacketFilter(Device, 0); ret = RndisFilterSetPacketFilter(Device, 0);
if (ret == 0) if (ret == 0)
{
Device->State = RNDIS_DEV_INITIALIZED; Device->State = RNDIS_DEV_INITIALIZED;
}
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
static int RndisFilterOnDeviceAdd(struct hv_device *Device,
static int void *AdditionalInfo)
RndisFilterOnDeviceAdd(
struct hv_device *Device,
void *AdditionalInfo
)
{ {
int ret; int ret;
struct NETVSC_DEVICE *netDevice; struct NETVSC_DEVICE *netDevice;
struct rndis_device *rndisDevice; struct rndis_device *rndisDevice;
struct netvsc_device_info *deviceInfo = (struct netvsc_device_info *)AdditionalInfo; struct netvsc_device_info *deviceInfo = AdditionalInfo;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
rndisDevice = GetRndisDevice(); rndisDevice = GetRndisDevice();
if (!rndisDevice) if (!rndisDevice) {
{
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return -1; return -1;
} }
DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice); DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice);
/* Let the inner driver handle this first to create the netvsc channel */ /*
/* NOTE! Once the channel is created, we may get a receive callback */ * Let the inner driver handle this first to create the netvsc channel
/* (RndisFilterOnReceive()) before this call is completed */ * NOTE! Once the channel is created, we may get a receive callback
* (RndisFilterOnReceive()) before this call is completed
*/
ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo); ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo);
if (ret != 0) if (ret != 0) {
{ kfree(rndisDevice);
PutRndisDevice(rndisDevice);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
/* Initialize the rndis device */ /* Initialize the rndis device */
netDevice = Device->Extension;
netDevice = (struct NETVSC_DEVICE*)Device->Extension;
ASSERT(netDevice); ASSERT(netDevice);
ASSERT(netDevice->Device); ASSERT(netDevice->Device);
...@@ -931,16 +828,19 @@ RndisFilterOnDeviceAdd( ...@@ -931,16 +828,19 @@ RndisFilterOnDeviceAdd(
/* Send the rndis initialization message */ /* Send the rndis initialization message */
ret = RndisFilterInitDevice(rndisDevice); ret = RndisFilterInitDevice(rndisDevice);
if (ret != 0) if (ret != 0) {
{ /*
/* TODO: If rndis init failed, we will need to shut down the channel */ * TODO: If rndis init failed, we will need to shut down the
* channel
*/
} }
/* Get the mac address */ /* Get the mac address */
ret = RndisFilterQueryDeviceMac(rndisDevice); ret = RndisFilterQueryDeviceMac(rndisDevice);
if (ret != 0) if (ret != 0) {
{ /*
/* TODO: shutdown rndis device and the channel */ * TODO: shutdown rndis device and the channel
*/
} }
DPRINT_INFO(NETVSC, "Device 0x%p mac addr %02x%02x%02x%02x%02x%02x", DPRINT_INFO(NETVSC, "Device 0x%p mac addr %02x%02x%02x%02x%02x%02x",
...@@ -957,28 +857,25 @@ RndisFilterOnDeviceAdd( ...@@ -957,28 +857,25 @@ RndisFilterOnDeviceAdd(
RndisFilterQueryDeviceLinkStatus(rndisDevice); RndisFilterQueryDeviceLinkStatus(rndisDevice);
deviceInfo->LinkState = rndisDevice->LinkStatus; deviceInfo->LinkState = rndisDevice->LinkStatus;
DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, ((deviceInfo->LinkState)?("down"):("up"))); DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice,
((deviceInfo->LinkState) ? ("down") : ("up")));
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
static int RndisFilterOnDeviceRemove(struct hv_device *Device)
static int
RndisFilterOnDeviceRemove(
struct hv_device *Device
)
{ {
struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; struct NETVSC_DEVICE *netDevice = Device->Extension;
struct rndis_device *rndisDevice = (struct rndis_device *)netDevice->Extension; struct rndis_device *rndisDevice = netDevice->Extension;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
/* Halt and release the rndis device */ /* Halt and release the rndis device */
RndisFilterHaltDevice(rndisDevice); RndisFilterHaltDevice(rndisDevice);
PutRndisDevice(rndisDevice); kfree(rndisDevice);
netDevice->Extension = NULL; netDevice->Extension = NULL;
/* Pass control to inner driver to remove the device */ /* Pass control to inner driver to remove the device */
...@@ -989,61 +886,47 @@ RndisFilterOnDeviceRemove( ...@@ -989,61 +886,47 @@ RndisFilterOnDeviceRemove(
return 0; return 0;
} }
static void RndisFilterOnCleanup(struct hv_driver *Driver)
static void
RndisFilterOnCleanup(
struct hv_driver *Driver
)
{ {
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
} }
static int static int RndisFilterOnOpen(struct hv_device *Device)
RndisFilterOnOpen(
struct hv_device *Device
)
{ {
int ret; int ret;
struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; struct NETVSC_DEVICE *netDevice = Device->Extension;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
ASSERT(netDevice); ASSERT(netDevice);
ret = RndisFilterOpenDevice((struct rndis_device *)netDevice->Extension); ret = RndisFilterOpenDevice(netDevice->Extension);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
static int static int RndisFilterOnClose(struct hv_device *Device)
RndisFilterOnClose(
struct hv_device *Device
)
{ {
int ret; int ret;
struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; struct NETVSC_DEVICE *netDevice = Device->Extension;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
ASSERT(netDevice); ASSERT(netDevice);
ret = RndisFilterCloseDevice((struct rndis_device *)netDevice->Extension); ret = RndisFilterCloseDevice(netDevice->Extension);
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
return ret; return ret;
} }
static int RndisFilterOnSend(struct hv_device *Device,
static int struct hv_netvsc_packet *Packet)
RndisFilterOnSend(
struct hv_device *Device,
struct hv_netvsc_packet *Packet
)
{ {
int ret=0; int ret;
struct rndis_filter_packet *filterPacket; struct rndis_filter_packet *filterPacket;
struct rndis_message *rndisMessage; struct rndis_message *rndisMessage;
struct rndis_packet *rndisPacket; struct rndis_packet *rndisPacket;
...@@ -1061,7 +944,8 @@ RndisFilterOnSend( ...@@ -1061,7 +944,8 @@ RndisFilterOnSend(
rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet); rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet);
rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG; rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG;
rndisMessage->MessageLength = Packet->TotalDataBufferLength + rndisMessageSize; rndisMessage->MessageLength = Packet->TotalDataBufferLength +
rndisMessageSize;
rndisPacket = &rndisMessage->Message.Packet; rndisPacket = &rndisMessage->Message.Packet;
rndisPacket->DataOffset = sizeof(struct rndis_packet); rndisPacket->DataOffset = sizeof(struct rndis_packet);
...@@ -1069,23 +953,29 @@ RndisFilterOnSend( ...@@ -1069,23 +953,29 @@ RndisFilterOnSend(
Packet->IsDataPacket = true; Packet->IsDataPacket = true;
Packet->PageBuffers[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; Packet->PageBuffers[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT;
Packet->PageBuffers[0].Offset = (unsigned long)rndisMessage & (PAGE_SIZE-1); Packet->PageBuffers[0].Offset =
(unsigned long)rndisMessage & (PAGE_SIZE-1);
Packet->PageBuffers[0].Length = rndisMessageSize; Packet->PageBuffers[0].Length = rndisMessageSize;
/* Save the packet send completion and context */ /* Save the packet send completion and context */
filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion; filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion;
filterPacket->CompletionContext = Packet->Completion.Send.SendCompletionContext; filterPacket->CompletionContext =
Packet->Completion.Send.SendCompletionContext;
/* Use ours */ /* Use ours */
Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion; Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion;
Packet->Completion.Send.SendCompletionContext = filterPacket; Packet->Completion.Send.SendCompletionContext = filterPacket;
ret = gRndisFilter.InnerDriver.OnSend(Device, Packet); ret = gRndisFilter.InnerDriver.OnSend(Device, Packet);
if (ret != 0) if (ret != 0) {
{ /*
/* Reset the completion to originals to allow retries from above */ * Reset the completion to originals to allow retries from
Packet->Completion.Send.OnSendCompletion = filterPacket->OnCompletion; * above
Packet->Completion.Send.SendCompletionContext = filterPacket->CompletionContext; */
Packet->Completion.Send.OnSendCompletion =
filterPacket->OnCompletion;
Packet->Completion.Send.SendCompletionContext =
filterPacket->CompletionContext;
} }
DPRINT_EXIT(NETVSC); DPRINT_EXIT(NETVSC);
...@@ -1093,11 +983,9 @@ RndisFilterOnSend( ...@@ -1093,11 +983,9 @@ RndisFilterOnSend(
return ret; return ret;
} }
static void static void RndisFilterOnSendCompletion(void *Context)
RndisFilterOnSendCompletion(
void *Context)
{ {
struct rndis_filter_packet *filterPacket = (struct rndis_filter_packet *)Context; struct rndis_filter_packet *filterPacket = Context;
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
...@@ -1108,10 +996,7 @@ RndisFilterOnSendCompletion( ...@@ -1108,10 +996,7 @@ RndisFilterOnSendCompletion(
} }
static void static void RndisFilterOnSendRequestCompletion(void *Context)
RndisFilterOnSendRequestCompletion(
void *Context
)
{ {
DPRINT_ENTER(NETVSC); DPRINT_ENTER(NETVSC);
......
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