blob: f83c6fc8ed18f7cfdd7bc5956fa7dd4da93cccf6 [file] [log] [blame]
Hank Janssenab057782009-07-13 15:19:28 -07001/*
2 *
3 * Copyright (c) 2009, Microsoft Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 *
22 */
23
24
25#ifndef _NETVSC_API_H_
26#define _NETVSC_API_H_
27
28#include "VmbusApi.h"
Greg Kroah-Hartmancaf26a32009-08-19 16:17:03 -070029#include "List.h"
Bill Pemberton454f18a2009-07-27 16:47:24 -040030
31/* Defines */
32
Hank Janssenab057782009-07-13 15:19:28 -070033#define NETVSC_DEVICE_RING_BUFFER_SIZE 64*PAGE_SIZE
34
35#define HW_MACADDR_LEN 6
36
Bill Pemberton454f18a2009-07-27 16:47:24 -040037
38/* Fwd declaration */
39
Nicolas Palix4193d4f2009-07-29 14:10:10 +020040struct hv_netvsc_packet;
Hank Janssenab057782009-07-13 15:19:28 -070041
42
Bill Pemberton454f18a2009-07-27 16:47:24 -040043
44/* Data types */
45
Hank Janssenab057782009-07-13 15:19:28 -070046
Nicolas Palix3d3b5512009-07-28 17:32:53 +020047typedef int (*PFN_ON_OPEN)(struct hv_device *Device);
48typedef int (*PFN_ON_CLOSE)(struct hv_device *Device);
Hank Janssenab057782009-07-13 15:19:28 -070049
Nicolas Palix3d3b5512009-07-28 17:32:53 +020050typedef void (*PFN_QUERY_LINKSTATUS)(struct hv_device *Device);
Nicolas Palix4193d4f2009-07-29 14:10:10 +020051typedef int (*PFN_ON_SEND)(struct hv_device *dev, struct hv_netvsc_packet *packet);
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070052typedef void (*PFN_ON_SENDRECVCOMPLETION)(void * Context);
Hank Janssenab057782009-07-13 15:19:28 -070053
Nicolas Palix4193d4f2009-07-29 14:10:10 +020054typedef int (*PFN_ON_RECVCALLBACK)(struct hv_device *dev, struct hv_netvsc_packet *packet);
Nicolas Palix3d3b5512009-07-28 17:32:53 +020055typedef void (*PFN_ON_LINKSTATUS_CHANGED)(struct hv_device *dev, u32 Status);
Hank Janssenab057782009-07-13 15:19:28 -070056
Bill Pemberton454f18a2009-07-27 16:47:24 -040057/* Represent the xfer page packet which contains 1 or more netvsc packet */
Hank Janssenab057782009-07-13 15:19:28 -070058typedef struct _XFERPAGE_PACKET {
Greg Kroah-Hartmancaf26a32009-08-19 16:17:03 -070059 LIST_ENTRY ListEntry;
Hank Janssenab057782009-07-13 15:19:28 -070060
Bill Pemberton454f18a2009-07-27 16:47:24 -040061 /* # of netvsc packets this xfer packet contains */
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -070062 u32 Count;
Hank Janssenab057782009-07-13 15:19:28 -070063} XFERPAGE_PACKET;
64
65
Bill Pemberton454f18a2009-07-27 16:47:24 -040066/* The number of pages which are enough to cover jumbo frame buffer. */
Hank Janssenab057782009-07-13 15:19:28 -070067#define NETVSC_PACKET_MAXPAGE 4
68
Bill Pemberton454f18a2009-07-27 16:47:24 -040069/*
70 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
71 * within the RNDIS
72 */
Nicolas Palix4193d4f2009-07-29 14:10:10 +020073struct hv_netvsc_packet {
Bill Pemberton454f18a2009-07-27 16:47:24 -040074 /* Bookkeeping stuff */
Greg Kroah-Hartmancaf26a32009-08-19 16:17:03 -070075 LIST_ENTRY ListEntry;
Hank Janssenab057782009-07-13 15:19:28 -070076
Nicolas Palix3d3b5512009-07-28 17:32:53 +020077 struct hv_device *Device;
Greg Kroah-Hartman27274e52009-07-14 15:13:46 -070078 bool IsDataPacket;
Hank Janssenab057782009-07-13 15:19:28 -070079
Bill Pemberton454f18a2009-07-27 16:47:24 -040080 /*
81 * Valid only for receives when we break a xfer page packet
82 * into multiple netvsc packets
83 */
Hank Janssenab057782009-07-13 15:19:28 -070084 XFERPAGE_PACKET *XferPagePacket;
85
86 union {
87 struct{
Greg Kroah-Hartman59471432009-07-14 15:10:26 -070088 u64 ReceiveCompletionTid;
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070089 void * ReceiveCompletionContext;
Hank Janssenab057782009-07-13 15:19:28 -070090 PFN_ON_SENDRECVCOMPLETION OnReceiveCompletion;
91 } Recv;
92 struct{
Greg Kroah-Hartman59471432009-07-14 15:10:26 -070093 u64 SendCompletionTid;
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -070094 void * SendCompletionContext;
Hank Janssenab057782009-07-13 15:19:28 -070095 PFN_ON_SENDRECVCOMPLETION OnSendCompletion;
96 } Send;
97 } Completion;
98
Bill Pemberton454f18a2009-07-27 16:47:24 -040099 /* This points to the memory after PageBuffers */
Greg Kroah-Hartman8282c402009-07-14 15:06:28 -0700100 void * Extension;
Hank Janssenab057782009-07-13 15:19:28 -0700101
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700102 u32 TotalDataBufferLength;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400103 /* Points to the send/receive buffer where the ethernet frame is */
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700104 u32 PageBufferCount;
Hank Janssenab057782009-07-13 15:19:28 -0700105 PAGE_BUFFER PageBuffers[NETVSC_PACKET_MAXPAGE];
106
Nicolas Palix4193d4f2009-07-29 14:10:10 +0200107};
Hank Janssenab057782009-07-13 15:19:28 -0700108
109
Bill Pemberton454f18a2009-07-27 16:47:24 -0400110/* Represents the net vsc driver */
Hank Janssenab057782009-07-13 15:19:28 -0700111typedef struct _NETVSC_DRIVER_OBJECT {
Nicolas Palix775ef252009-07-29 14:09:45 +0200112 struct hv_driver Base; /* Must be the first field */
Hank Janssenab057782009-07-13 15:19:28 -0700113
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700114 u32 RingBufferSize;
115 u32 RequestExtSize;
Hank Janssenab057782009-07-13 15:19:28 -0700116
Bill Pemberton454f18a2009-07-27 16:47:24 -0400117 /* Additional num of page buffers to allocate */
Greg Kroah-Hartman4d643112009-07-14 15:09:36 -0700118 u32 AdditionalRequestPageBufferCount;
Hank Janssenab057782009-07-13 15:19:28 -0700119
Bill Pemberton454f18a2009-07-27 16:47:24 -0400120 /*
121 * This is set by the caller to allow us to callback when we
122 * receive a packet from the "wire"
123 */
Hank Janssenab057782009-07-13 15:19:28 -0700124 PFN_ON_RECVCALLBACK OnReceiveCallback;
125
126 PFN_ON_LINKSTATUS_CHANGED OnLinkStatusChanged;
127
Bill Pemberton454f18a2009-07-27 16:47:24 -0400128 /* Specific to this driver */
Hank Janssenab057782009-07-13 15:19:28 -0700129 PFN_ON_OPEN OnOpen;
130 PFN_ON_CLOSE OnClose;
131 PFN_ON_SEND OnSend;
Bill Pemberton454f18a2009-07-27 16:47:24 -0400132 /* PFN_ON_RECVCOMPLETION OnReceiveCompletion; */
Hank Janssenab057782009-07-13 15:19:28 -0700133
Bill Pemberton454f18a2009-07-27 16:47:24 -0400134 /* PFN_QUERY_LINKSTATUS QueryLinkStatus; */
Hank Janssenab057782009-07-13 15:19:28 -0700135
136 void* Context;
137} NETVSC_DRIVER_OBJECT;
138
139
140typedef struct _NETVSC_DEVICE_INFO {
Greg Kroah-Hartman59471432009-07-14 15:10:26 -0700141 unsigned char MacAddr[6];
Bill Pemberton454f18a2009-07-27 16:47:24 -0400142 bool LinkState; /* 0 - link up, 1 - link down */
Hank Janssenab057782009-07-13 15:19:28 -0700143} NETVSC_DEVICE_INFO;
144
Bill Pemberton454f18a2009-07-27 16:47:24 -0400145
146/* Interface */
147
Hank Janssenab057782009-07-13 15:19:28 -0700148int
149NetVscInitialize(
Nicolas Palix775ef252009-07-29 14:09:45 +0200150 struct hv_driver *drv
Hank Janssenab057782009-07-13 15:19:28 -0700151 );
152
Bill Pemberton454f18a2009-07-27 16:47:24 -0400153#endif /* _NETVSC_API_H_ */