1
/*********************************************************
2
* Copyright (C) 2007 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation version 2 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* You should have received a copy of the GNU General Public License along
14
* with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
*********************************************************/
19
#ifndef _VMXNET3_INT_H
20
#define _VMXNET3_INT_H
22
#define INCLUDE_ALLOW_MODULE
23
#include "includeCheck.h"
25
#include "vmxnet3_defs.h"
27
typedef struct vmxnet3_cmd_ring {
28
Vmxnet3_GenericDesc *base;
37
vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
40
if (UNLIKELY(ring->next2fill == ring->size)) {
42
VMXNET3_FLIP_RING_GEN(ring->gen);
47
vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
49
VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
53
vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
55
return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
56
ring->next2comp - ring->next2fill - 1;
59
typedef struct vmxnet3_comp_ring {
60
Vmxnet3_GenericDesc *base;
69
vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
72
if (UNLIKELY(ring->next2proc == ring->size)) {
74
VMXNET3_FLIP_RING_GEN(ring->gen);
78
struct vmxnet3_tx_data_ring {
79
Vmxnet3_TxDataDesc *base;
84
enum vmxnet3_buf_map_type {
85
VMXNET3_MAP_INVALID = 0,
91
struct vmxnet3_tx_buf_info {
99
struct vmxnet3_tq_driver_stats {
100
uint64 drop_total; /* # of pkts dropped by the driver, the
101
* counters below track droppings due to
104
uint64 drop_too_many_frags;
105
uint64 drop_oversized_hdr;
106
uint64 drop_hdr_inspect_err;
110
uint64 linearized; /* # of pkts linearized */
111
uint64 copy_skb_header; /* # of times we have to copy skb header */
112
uint64 oversized_hdr;
115
struct vmxnet3_tx_ctx {
119
uint32 eth_ip_hdr_size; /* only valid for pkts requesting tso or csum offloading */
120
uint32 l4_hdr_size; /* only valid if mss != 0 */
121
uint32 copy_size; /* # of bytes copied into the data ring */
122
Vmxnet3_GenericDesc *sop_txd;
123
Vmxnet3_GenericDesc *eop_txd;
126
struct vmxnet3_tx_queue {
128
struct vmxnet3_cmd_ring tx_ring;
129
struct vmxnet3_tx_buf_info *buf_info;
130
struct vmxnet3_tx_data_ring data_ring;
131
struct vmxnet3_comp_ring comp_ring;
132
Vmxnet3_TxQueueCtrl *shared;
133
struct vmxnet3_tq_driver_stats stats;
135
int num_stop; /* # of time queue is stopped */
136
} __attribute__((__aligned__(SMP_CACHE_BYTES)));
138
enum vmxnet3_rx_buf_type {
139
VMXNET3_RX_BUF_NONE = 0,
140
VMXNET3_RX_BUF_SKB = 1,
141
VMXNET3_RX_BUF_PAGE = 2
144
struct vmxnet3_rx_buf_info {
145
enum vmxnet3_rx_buf_type buf_type;
154
struct vmxnet3_rx_ctx {
159
struct vmxnet3_rq_driver_stats {
163
uint64 rx_buf_alloc_failure;
166
struct vmxnet3_rx_queue {
167
struct vmxnet3_cmd_ring rx_ring[2];
168
struct vmxnet3_comp_ring comp_ring;
169
struct vmxnet3_rx_ctx rx_ctx;
170
uint32 qid; /* rqID in RCD for buffer from 1st ring */
171
uint32 qid2; /* rqID in RCD for buffer from 2nd ring */
172
uint32 uncommitted[2]; /* # of buffers allocated since last RXPROD update */
173
struct vmxnet3_rx_buf_info *buf_info[2];
174
Vmxnet3_RxQueueCtrl *shared;
175
struct vmxnet3_rq_driver_stats stats;
176
} __attribute__((__aligned__(SMP_CACHE_BYTES)));
178
#define VMXNET3_LINUX_MAX_MSIX_VECT 1
180
struct vmxnet3_intr {
181
enum vmxnet3_intr_mask_mode mask_mode;
182
enum vmxnet3_intr_type type; /* MSI-X, MSI, or INTx? */
183
uint8 num_intrs; /* # of intr vectors */
184
uint8 event_intr_idx; /* idx of the intr vector for event */
185
uint8 mod_levels[VMXNET3_LINUX_MAX_MSIX_VECT]; /* moderation level */
186
#ifdef CONFIG_PCI_MSI
187
struct msix_entry msix_entries[VMXNET3_LINUX_MAX_MSIX_VECT];
191
#define VMXNET3_STATE_BIT_RESETTING 0
192
#define VMXNET3_STATE_BIT_QUIESCED 1
193
struct vmxnet3_adapter {
194
struct vmxnet3_tx_queue tx_queue;
195
struct vmxnet3_rx_queue rx_queue;
197
struct napi_struct napi;
199
struct vlan_group *vlan_grp;
201
struct vmxnet3_intr intr;
203
struct Vmxnet3_DriverShared *shared;
204
struct Vmxnet3_PMConf *pm_conf;
205
struct Vmxnet3_TxQueueDesc *tqd_start; /* first tx queue desc */
206
struct Vmxnet3_RxQueueDesc *rqd_start; /* first rx queue desc */;
207
struct net_device *netdev;
208
struct net_device_stats net_stats;
209
struct pci_dev *pdev;
211
uint8 *hw_addr0; /* for BAR 0 */
212
uint8 *hw_addr1; /* for BAR 1 */
214
/* feature control */
219
/* rx buffer related */
220
unsigned skb_buf_size;
221
int rx_buf_per_pkt; /* only apply to the 1st ring */
222
dma_addr_t shared_pa;
223
dma_addr_t queue_desc_pa;
229
uint32 link_speed; /* in mbps */
231
uint64 tx_timeout_count;
234
unsigned long state; /* VMXNET3_STATE_BIT_xxx */
237
struct vmxnet3_stat_desc {
238
char desc[ETH_GSTRING_LEN];
242
#define VMXNET3_WRITE_BAR0_REG(adapter, reg, val) \
243
writel((val), (adapter)->hw_addr0 + (reg))
244
#define VMXNET3_READ_BAR0_REG(adapter, reg) \
245
readl((adapter)->hw_addr0 + (reg))
247
#define VMXNET3_WRITE_BAR1_REG(adapter, reg, val) \
248
writel((val), (adapter)->hw_addr1 + (reg))
249
#define VMXNET3_READ_BAR1_REG(adapter, reg) \
250
readl((adapter)->hw_addr1 + (reg))
252
#define VMXNET3_WAKE_QUEUE_THRESHOLD(tq) (5)
253
#define VMXNET3_RX_ALLOC_THRESHOLD(rq, ring_idx, adapter) \
254
((rq)->rx_ring[ring_idx].size >> 3)
256
#define VMXNET3_TX_OK 0
257
#define VMXNET3_TX_DROPPED 1
258
#define VMXNET3_TX_FULL 2
260
#define VMXNET3_GET_ADDR_LO(dma) ((uint32)(dma))
261
#define VMXNET3_GET_ADDR_HI(dma) ((uint32)(((uint64)(dma)) >> 32))
263
/* must be a multiple of VMXNET3_RING_SIZE_ALIGN */
264
#define VMXNET3_DEF_TX_RING_SIZE 512
265
#define VMXNET3_DEF_RX_RING_SIZE 256
267
/* FIXME: what's the right value for this? */
268
#define VMXNET3_MAX_ETH_HDR_SIZE 22
270
#define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)