1 /*- 2 * Copyright (c) 2016 Microsoft Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _IF_HNVAR_H_ 30 #define _IF_HNVAR_H_ 31 32 #define HN_USE_TXDESC_BUFRING 33 34 #define HN_CHIM_SIZE (15 * 1024 * 1024) 35 36 #define HN_RXBUF_SIZE (16 * 1024 * 1024) 37 #define HN_RXBUF_SIZE_COMPAT (15 * 1024 * 1024) 38 39 /* Claimed to be 12232B */ 40 #define HN_MTU_MAX (9 * 1024) 41 42 #define HN_TXBR_SIZE (128 * PAGE_SIZE) 43 #define HN_RXBR_SIZE (128 * PAGE_SIZE) 44 45 #define HN_XACT_REQ_PGCNT 2 46 #define HN_XACT_RESP_PGCNT 2 47 #define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE) 48 #define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE) 49 50 #define HN_GPACNT_MAX 32 51 52 struct hn_txdesc; 53 #ifndef HN_USE_TXDESC_BUFRING 54 SLIST_HEAD(hn_txdesc_list, hn_txdesc); 55 #else 56 struct buf_ring; 57 #endif 58 struct hn_tx_ring; 59 60 struct hn_rx_ring { 61 struct ifnet *hn_ifp; 62 struct hn_tx_ring *hn_txr; 63 void *hn_pktbuf; 64 int hn_pktbuf_len; 65 uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */ 66 int hn_rx_idx; 67 68 /* Trust csum verification on host side */ 69 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */ 70 struct lro_ctrl hn_lro; 71 72 u_long hn_csum_ip; 73 u_long hn_csum_tcp; 74 u_long hn_csum_udp; 75 u_long hn_csum_trusted; 76 u_long hn_lro_tried; 77 u_long hn_small_pkts; 78 u_long hn_pkts; 79 u_long hn_rss_pkts; 80 u_long hn_ack_failed; 81 82 /* Rarely used stuffs */ 83 struct sysctl_oid *hn_rx_sysctl_tree; 84 int hn_rx_flags; 85 86 void *hn_br; /* TX/RX bufring */ 87 struct hyperv_dma hn_br_dma; 88 } __aligned(CACHE_LINE_SIZE); 89 90 #define HN_TRUST_HCSUM_IP 0x0001 91 #define HN_TRUST_HCSUM_TCP 0x0002 92 #define HN_TRUST_HCSUM_UDP 0x0004 93 94 #define HN_RX_FLAG_ATTACHED 0x1 95 96 struct hn_tx_ring { 97 #ifndef HN_USE_TXDESC_BUFRING 98 struct mtx hn_txlist_spin; 99 struct hn_txdesc_list hn_txlist; 100 #else 101 struct buf_ring *hn_txdesc_br; 102 #endif 103 int hn_txdesc_cnt; 104 int hn_txdesc_avail; 105 u_short hn_has_txeof; 106 u_short hn_txdone_cnt; 107 108 int hn_sched_tx; 109 void (*hn_txeof)(struct hn_tx_ring *); 110 struct taskqueue *hn_tx_taskq; 111 struct task hn_tx_task; 112 struct task hn_txeof_task; 113 114 struct buf_ring *hn_mbuf_br; 115 int hn_oactive; 116 int hn_tx_idx; 117 int hn_tx_flags; 118 119 struct mtx hn_tx_lock; 120 struct hn_softc *hn_sc; 121 struct vmbus_channel *hn_chan; 122 123 int hn_direct_tx_size; 124 int hn_chim_size; 125 bus_dma_tag_t hn_tx_data_dtag; 126 uint64_t hn_csum_assist; 127 128 int (*hn_sendpkt)(struct hn_tx_ring *, struct hn_txdesc *); 129 int hn_suspended; 130 int hn_gpa_cnt; 131 struct vmbus_gpa hn_gpa[HN_GPACNT_MAX]; 132 133 u_long hn_no_txdescs; 134 u_long hn_send_failed; 135 u_long hn_txdma_failed; 136 u_long hn_tx_collapsed; 137 u_long hn_tx_chimney_tried; 138 u_long hn_tx_chimney; 139 u_long hn_pkts; 140 141 /* Rarely used stuffs */ 142 struct hn_txdesc *hn_txdesc; 143 bus_dma_tag_t hn_tx_rndis_dtag; 144 struct sysctl_oid *hn_tx_sysctl_tree; 145 } __aligned(CACHE_LINE_SIZE); 146 147 #define HN_TX_FLAG_ATTACHED 0x1 148 #define HN_TX_FLAG_HASHVAL 0x2 /* support HASHVAL pktinfo */ 149 150 /* 151 * Device-specific softc structure 152 */ 153 struct hn_softc { 154 struct ifnet *hn_ifp; 155 struct ifmedia hn_media; 156 device_t hn_dev; 157 int hn_if_flags; 158 struct sx hn_lock; 159 struct vmbus_channel *hn_prichan; 160 161 int hn_rx_ring_cnt; 162 int hn_rx_ring_inuse; 163 struct hn_rx_ring *hn_rx_ring; 164 165 int hn_tx_ring_cnt; 166 int hn_tx_ring_inuse; 167 struct hn_tx_ring *hn_tx_ring; 168 169 uint8_t *hn_chim; 170 u_long *hn_chim_bmap; 171 int hn_chim_bmap_cnt; 172 int hn_chim_cnt; 173 int hn_chim_szmax; 174 175 int hn_cpu; 176 struct taskqueue *hn_tx_taskq; 177 struct sysctl_oid *hn_tx_sysctl_tree; 178 struct sysctl_oid *hn_rx_sysctl_tree; 179 struct vmbus_xact_ctx *hn_xact; 180 uint32_t hn_nvs_ver; 181 uint32_t hn_rx_filter; 182 183 struct taskqueue *hn_mgmt_taskq; 184 struct taskqueue *hn_mgmt_taskq0; 185 struct task hn_link_task; 186 struct task hn_netchg_init; 187 struct timeout_task hn_netchg_status; 188 uint32_t hn_link_flags; /* HN_LINK_FLAG_ */ 189 190 uint32_t hn_caps; /* HN_CAP_ */ 191 uint32_t hn_flags; /* HN_FLAG_ */ 192 void *hn_rxbuf; 193 uint32_t hn_rxbuf_gpadl; 194 struct hyperv_dma hn_rxbuf_dma; 195 196 uint32_t hn_chim_gpadl; 197 struct hyperv_dma hn_chim_dma; 198 199 uint32_t hn_rndis_rid; 200 uint32_t hn_ndis_ver; 201 int hn_ndis_tso_szmax; 202 int hn_ndis_tso_sgmin; 203 204 int hn_rss_ind_size; 205 uint32_t hn_rss_hash; /* NDIS_HASH_ */ 206 struct ndis_rssprm_toeplitz hn_rss; 207 }; 208 209 #define HN_FLAG_RXBUF_CONNECTED 0x0001 210 #define HN_FLAG_CHIM_CONNECTED 0x0002 211 #define HN_FLAG_HAS_RSSKEY 0x0004 212 #define HN_FLAG_HAS_RSSIND 0x0008 213 #define HN_FLAG_SYNTH_ATTACHED 0x0010 214 215 #define HN_CAP_VLAN 0x0001 216 #define HN_CAP_MTU 0x0002 217 #define HN_CAP_IPCS 0x0004 218 #define HN_CAP_TCP4CS 0x0008 219 #define HN_CAP_TCP6CS 0x0010 220 #define HN_CAP_UDP4CS 0x0020 221 #define HN_CAP_UDP6CS 0x0040 222 #define HN_CAP_TSO4 0x0080 223 #define HN_CAP_TSO6 0x0100 224 #define HN_CAP_HASHVAL 0x0200 225 226 /* Capability description for use with printf(9) %b identifier. */ 227 #define HN_CAP_BITS \ 228 "\020\1VLAN\2MTU\3IPCS\4TCP4CS\5TCP6CS" \ 229 "\6UDP4CS\7UDP6CS\10TSO4\11TSO6\12HASHVAL" 230 231 #define HN_LINK_FLAG_LINKUP 0x0001 232 #define HN_LINK_FLAG_NETCHG 0x0002 233 234 #endif /* !_IF_HNVAR_H_ */ 235