Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 1 | /* |
| 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-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 29 | #include "List.h" |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 30 | |
| 31 | /* Defines */ |
| 32 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 33 | #define NETVSC_DEVICE_RING_BUFFER_SIZE 64*PAGE_SIZE |
| 34 | |
| 35 | #define HW_MACADDR_LEN 6 |
| 36 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 37 | |
| 38 | /* Fwd declaration */ |
| 39 | |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 40 | struct hv_netvsc_packet; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 41 | |
| 42 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 43 | |
| 44 | /* Data types */ |
| 45 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 46 | |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 47 | typedef int (*PFN_ON_OPEN)(struct hv_device *Device); |
| 48 | typedef int (*PFN_ON_CLOSE)(struct hv_device *Device); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 49 | |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 50 | typedef void (*PFN_QUERY_LINKSTATUS)(struct hv_device *Device); |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 51 | typedef int (*PFN_ON_SEND)(struct hv_device *dev, struct hv_netvsc_packet *packet); |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 52 | typedef void (*PFN_ON_SENDRECVCOMPLETION)(void * Context); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 53 | |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 54 | typedef int (*PFN_ON_RECVCALLBACK)(struct hv_device *dev, struct hv_netvsc_packet *packet); |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 55 | typedef void (*PFN_ON_LINKSTATUS_CHANGED)(struct hv_device *dev, u32 Status); |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 56 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 57 | /* Represent the xfer page packet which contains 1 or more netvsc packet */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 58 | typedef struct _XFERPAGE_PACKET { |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 59 | LIST_ENTRY ListEntry; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 60 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 61 | /* # of netvsc packets this xfer packet contains */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 62 | u32 Count; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 63 | } XFERPAGE_PACKET; |
| 64 | |
| 65 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 66 | /* The number of pages which are enough to cover jumbo frame buffer. */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 67 | #define NETVSC_PACKET_MAXPAGE 4 |
| 68 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 69 | /* |
| 70 | * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame |
| 71 | * within the RNDIS |
| 72 | */ |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 73 | struct hv_netvsc_packet { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 74 | /* Bookkeeping stuff */ |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 75 | LIST_ENTRY ListEntry; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 76 | |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 77 | struct hv_device *Device; |
Greg Kroah-Hartman | 27274e5 | 2009-07-14 15:13:46 -0700 | [diff] [blame] | 78 | bool IsDataPacket; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 79 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 80 | /* |
| 81 | * Valid only for receives when we break a xfer page packet |
| 82 | * into multiple netvsc packets |
| 83 | */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 84 | XFERPAGE_PACKET *XferPagePacket; |
| 85 | |
| 86 | union { |
| 87 | struct{ |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 88 | u64 ReceiveCompletionTid; |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 89 | void * ReceiveCompletionContext; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 90 | PFN_ON_SENDRECVCOMPLETION OnReceiveCompletion; |
| 91 | } Recv; |
| 92 | struct{ |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 93 | u64 SendCompletionTid; |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 94 | void * SendCompletionContext; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 95 | PFN_ON_SENDRECVCOMPLETION OnSendCompletion; |
| 96 | } Send; |
| 97 | } Completion; |
| 98 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 99 | /* This points to the memory after PageBuffers */ |
Greg Kroah-Hartman | 8282c40 | 2009-07-14 15:06:28 -0700 | [diff] [blame] | 100 | void * Extension; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 101 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 102 | u32 TotalDataBufferLength; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 103 | /* Points to the send/receive buffer where the ethernet frame is */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 104 | u32 PageBufferCount; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 105 | PAGE_BUFFER PageBuffers[NETVSC_PACKET_MAXPAGE]; |
| 106 | |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 107 | }; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 108 | |
| 109 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 110 | /* Represents the net vsc driver */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 111 | typedef struct _NETVSC_DRIVER_OBJECT { |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 112 | struct hv_driver Base; /* Must be the first field */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 113 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 114 | u32 RingBufferSize; |
| 115 | u32 RequestExtSize; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 116 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 117 | /* Additional num of page buffers to allocate */ |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 118 | u32 AdditionalRequestPageBufferCount; |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 119 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 120 | /* |
| 121 | * This is set by the caller to allow us to callback when we |
| 122 | * receive a packet from the "wire" |
| 123 | */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 124 | PFN_ON_RECVCALLBACK OnReceiveCallback; |
| 125 | |
| 126 | PFN_ON_LINKSTATUS_CHANGED OnLinkStatusChanged; |
| 127 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 128 | /* Specific to this driver */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 129 | PFN_ON_OPEN OnOpen; |
| 130 | PFN_ON_CLOSE OnClose; |
| 131 | PFN_ON_SEND OnSend; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 132 | /* PFN_ON_RECVCOMPLETION OnReceiveCompletion; */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 133 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 134 | /* PFN_QUERY_LINKSTATUS QueryLinkStatus; */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 135 | |
| 136 | void* Context; |
| 137 | } NETVSC_DRIVER_OBJECT; |
| 138 | |
| 139 | |
| 140 | typedef struct _NETVSC_DEVICE_INFO { |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 141 | unsigned char MacAddr[6]; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 142 | bool LinkState; /* 0 - link up, 1 - link down */ |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 143 | } NETVSC_DEVICE_INFO; |
| 144 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 145 | |
| 146 | /* Interface */ |
| 147 | |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 148 | int |
| 149 | NetVscInitialize( |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 150 | struct hv_driver *drv |
Hank Janssen | ab05778 | 2009-07-13 15:19:28 -0700 | [diff] [blame] | 151 | ); |
| 152 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 153 | #endif /* _NETVSC_API_H_ */ |