1/*
2 * IBM Power Virtual Ethernet Device Driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) IBM Corporation, 2003, 2010
18 *
19 * Authors: Dave Larson <larson1@us.ibm.com>
20 *	    Santiago Leon <santil@linux.vnet.ibm.com>
21 *	    Brian King <brking@linux.vnet.ibm.com>
22 *	    Robert Jennings <rcj@linux.vnet.ibm.com>
23 *	    Anton Blanchard <anton@au.ibm.com>
24 */
25
26#ifndef _IBMVETH_H
27#define _IBMVETH_H
28
29/* constants for H_MULTICAST_CTRL */
30#define IbmVethMcastReceptionModifyBit     0x80000UL
31#define IbmVethMcastReceptionEnableBit     0x20000UL
32#define IbmVethMcastFilterModifyBit        0x40000UL
33#define IbmVethMcastFilterEnableBit        0x10000UL
34
35#define IbmVethMcastEnableRecv       (IbmVethMcastReceptionModifyBit | IbmVethMcastReceptionEnableBit)
36#define IbmVethMcastDisableRecv      (IbmVethMcastReceptionModifyBit)
37#define IbmVethMcastEnableFiltering  (IbmVethMcastFilterModifyBit | IbmVethMcastFilterEnableBit)
38#define IbmVethMcastDisableFiltering (IbmVethMcastFilterModifyBit)
39#define IbmVethMcastAddFilter        0x1UL
40#define IbmVethMcastRemoveFilter     0x2UL
41#define IbmVethMcastClearFilterTable 0x3UL
42
43#define IBMVETH_ILLAN_PADDED_PKT_CSUM	0x0000000000002000UL
44#define IBMVETH_ILLAN_TRUNK_PRI_MASK	0x0000000000000F00UL
45#define IBMVETH_ILLAN_IPV6_TCP_CSUM		0x0000000000000004UL
46#define IBMVETH_ILLAN_IPV4_TCP_CSUM		0x0000000000000002UL
47#define IBMVETH_ILLAN_ACTIVE_TRUNK		0x0000000000000001UL
48
49/* hcall macros */
50#define h_register_logical_lan(ua, buflst, rxq, fltlst, mac) \
51  plpar_hcall_norets(H_REGISTER_LOGICAL_LAN, ua, buflst, rxq, fltlst, mac)
52
53#define h_free_logical_lan(ua) \
54  plpar_hcall_norets(H_FREE_LOGICAL_LAN, ua)
55
56#define h_add_logical_lan_buffer(ua, buf) \
57  plpar_hcall_norets(H_ADD_LOGICAL_LAN_BUFFER, ua, buf)
58
59static inline long h_send_logical_lan(unsigned long unit_address,
60		unsigned long desc1, unsigned long desc2, unsigned long desc3,
61		unsigned long desc4, unsigned long desc5, unsigned long desc6,
62		unsigned long corellator_in, unsigned long *corellator_out)
63{
64	long rc;
65	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
66
67	rc = plpar_hcall9(H_SEND_LOGICAL_LAN, retbuf, unit_address, desc1,
68			desc2, desc3, desc4, desc5, desc6, corellator_in);
69
70	*corellator_out = retbuf[0];
71
72	return rc;
73}
74
75static inline long h_illan_attributes(unsigned long unit_address,
76				      unsigned long reset_mask, unsigned long set_mask,
77				      unsigned long *ret_attributes)
78{
79	long rc;
80	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
81
82	rc = plpar_hcall(H_ILLAN_ATTRIBUTES, retbuf, unit_address,
83			 reset_mask, set_mask);
84
85	*ret_attributes = retbuf[0];
86
87	return rc;
88}
89
90#define h_multicast_ctrl(ua, cmd, mac) \
91  plpar_hcall_norets(H_MULTICAST_CTRL, ua, cmd, mac)
92
93#define h_change_logical_lan_mac(ua, mac) \
94  plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac)
95
96#define IBMVETH_NUM_BUFF_POOLS 5
97#define IBMVETH_IO_ENTITLEMENT_DEFAULT 4243456 /* MTU of 1500 needs 4.2Mb */
98#define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */
99#define IBMVETH_MIN_MTU 68
100#define IBMVETH_MAX_POOL_COUNT 4096
101#define IBMVETH_BUFF_LIST_SIZE 4096
102#define IBMVETH_FILT_LIST_SIZE 4096
103#define IBMVETH_MAX_BUF_SIZE (1024 * 128)
104
105static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 };
106static int pool_count[] = { 256, 512, 256, 256, 256 };
107static int pool_active[] = { 1, 1, 0, 0, 0};
108
109#define IBM_VETH_INVALID_MAP ((u16)0xffff)
110
111struct ibmveth_buff_pool {
112    u32 size;
113    u32 index;
114    u32 buff_size;
115    u32 threshold;
116    atomic_t available;
117    u32 consumer_index;
118    u32 producer_index;
119    u16 *free_map;
120    dma_addr_t *dma_addr;
121    struct sk_buff **skbuff;
122    int active;
123    struct kobject kobj;
124};
125
126struct ibmveth_rx_q {
127    u64        index;
128    u64        num_slots;
129    u64        toggle;
130    dma_addr_t queue_dma;
131    u32        queue_len;
132    struct ibmveth_rx_q_entry *queue_addr;
133};
134
135struct ibmveth_adapter {
136    struct vio_dev *vdev;
137    struct net_device *netdev;
138    struct napi_struct napi;
139    struct net_device_stats stats;
140    unsigned int mcastFilterSize;
141    void * buffer_list_addr;
142    void * filter_list_addr;
143    dma_addr_t buffer_list_dma;
144    dma_addr_t filter_list_dma;
145    struct ibmveth_buff_pool rx_buff_pool[IBMVETH_NUM_BUFF_POOLS];
146    struct ibmveth_rx_q rx_queue;
147    int pool_config;
148    int rx_csum;
149    void *bounce_buffer;
150    dma_addr_t bounce_buffer_dma;
151
152    u64 fw_ipv6_csum_support;
153    u64 fw_ipv4_csum_support;
154    /* adapter specific stats */
155    u64 replenish_task_cycles;
156    u64 replenish_no_mem;
157    u64 replenish_add_buff_failure;
158    u64 replenish_add_buff_success;
159    u64 rx_invalid_buffer;
160    u64 rx_no_buffer;
161    u64 tx_map_failed;
162    u64 tx_send_failed;
163};
164
165/*
166 * We pass struct ibmveth_buf_desc_fields to the hypervisor in registers,
167 * so we don't need to byteswap the two elements. However since we use
168 * a union (ibmveth_buf_desc) to convert from the struct to a u64 we
169 * do end up with endian specific ordering of the elements and that
170 * needs correcting.
171 */
172struct ibmveth_buf_desc_fields {
173#ifdef __BIG_ENDIAN
174	u32 flags_len;
175	u32 address;
176#else
177	u32 address;
178	u32 flags_len;
179#endif
180#define IBMVETH_BUF_VALID	0x80000000
181#define IBMVETH_BUF_TOGGLE	0x40000000
182#define IBMVETH_BUF_NO_CSUM	0x02000000
183#define IBMVETH_BUF_CSUM_GOOD	0x01000000
184#define IBMVETH_BUF_LEN_MASK	0x00FFFFFF
185};
186
187union ibmveth_buf_desc {
188    u64 desc;
189    struct ibmveth_buf_desc_fields fields;
190};
191
192struct ibmveth_rx_q_entry {
193	__be32 flags_off;
194#define IBMVETH_RXQ_TOGGLE		0x80000000
195#define IBMVETH_RXQ_TOGGLE_SHIFT	31
196#define IBMVETH_RXQ_VALID		0x40000000
197#define IBMVETH_RXQ_NO_CSUM		0x02000000
198#define IBMVETH_RXQ_CSUM_GOOD		0x01000000
199#define IBMVETH_RXQ_OFF_MASK		0x0000FFFF
200
201	__be32 length;
202	/* correlator is only used by the OS, no need to byte swap */
203	u64 correlator;
204};
205
206#endif /* _IBMVETH_H */
207