aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ibmveth.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/net/ibmveth.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/net/ibmveth.c')
-rw-r--r--drivers/net/ibmveth.c1056
1 files changed, 519 insertions, 537 deletions
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 4734c939ad03..b388d782c7c4 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1,122 +1,84 @@
1/**************************************************************************/
2/* */
3/* IBM eServer i/pSeries Virtual Ethernet Device Driver */
4/* Copyright (C) 2003 IBM Corp. */
5/* Originally written by Dave Larson (larson1@us.ibm.com) */
6/* Maintained by Santiago Leon (santil@us.ibm.com) */
7/* */
8/* This program is free software; you can redistribute it and/or modify */
9/* it under the terms of the GNU General Public License as published by */
10/* the Free Software Foundation; either version 2 of the License, or */
11/* (at your option) any later version. */
12/* */
13/* This program is distributed in the hope that it will be useful, */
14/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16/* GNU General Public License for more details. */
17/* */
18/* You should have received a copy of the GNU General Public License */
19/* along with this program; if not, write to the Free Software */
20/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */
21/* USA */
22/* */
23/* This module contains the implementation of a virtual ethernet device */
24/* for use with IBM i/pSeries LPAR Linux. It utilizes the logical LAN */
25/* option of the RS/6000 Platform Architechture to interface with virtual */
26/* ethernet NICs that are presented to the partition by the hypervisor. */
27/* */
28/**************************************************************************/
29/* 1/*
30 TODO: 2 * IBM Power Virtual Ethernet Device Driver
31 - add support for sysfs 3 *
32 - possibly remove procfs support 4 * This program is free software; you can redistribute it and/or modify
33*/ 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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) IBM Corporation, 2003, 2010
19 *
20 * Authors: Dave Larson <larson1@us.ibm.com>
21 * Santiago Leon <santil@linux.vnet.ibm.com>
22 * Brian King <brking@linux.vnet.ibm.com>
23 * Robert Jennings <rcj@linux.vnet.ibm.com>
24 * Anton Blanchard <anton@au.ibm.com>
25 */
34 26
35#include <linux/module.h> 27#include <linux/module.h>
36#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
37#include <linux/types.h> 29#include <linux/types.h>
38#include <linux/errno.h> 30#include <linux/errno.h>
39#include <linux/ioport.h>
40#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
41#include <linux/kernel.h> 32#include <linux/kernel.h>
42#include <linux/netdevice.h> 33#include <linux/netdevice.h>
43#include <linux/etherdevice.h> 34#include <linux/etherdevice.h>
44#include <linux/skbuff.h> 35#include <linux/skbuff.h>
45#include <linux/init.h> 36#include <linux/init.h>
46#include <linux/delay.h>
47#include <linux/mm.h> 37#include <linux/mm.h>
48#include <linux/pm.h> 38#include <linux/pm.h>
49#include <linux/ethtool.h> 39#include <linux/ethtool.h>
50#include <linux/proc_fs.h>
51#include <linux/in.h> 40#include <linux/in.h>
52#include <linux/ip.h> 41#include <linux/ip.h>
42#include <linux/ipv6.h>
53#include <linux/slab.h> 43#include <linux/slab.h>
54#include <net/net_namespace.h>
55#include <asm/hvcall.h> 44#include <asm/hvcall.h>
56#include <asm/atomic.h> 45#include <asm/atomic.h>
57#include <asm/vio.h> 46#include <asm/vio.h>
58#include <asm/iommu.h> 47#include <asm/iommu.h>
59#include <asm/uaccess.h>
60#include <asm/firmware.h> 48#include <asm/firmware.h>
61#include <linux/seq_file.h>
62 49
63#include "ibmveth.h" 50#include "ibmveth.h"
64 51
65#undef DEBUG
66
67#define ibmveth_printk(fmt, args...) \
68 printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args)
69
70#define ibmveth_error_printk(fmt, args...) \
71 printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
72
73#ifdef DEBUG
74#define ibmveth_debug_printk_no_adapter(fmt, args...) \
75 printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
76#define ibmveth_debug_printk(fmt, args...) \
77 printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
78#define ibmveth_assert(expr) \
79 if(!(expr)) { \
80 printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
81 BUG(); \
82 }
83#else
84#define ibmveth_debug_printk_no_adapter(fmt, args...)
85#define ibmveth_debug_printk(fmt, args...)
86#define ibmveth_assert(expr)
87#endif
88
89static int ibmveth_open(struct net_device *dev);
90static int ibmveth_close(struct net_device *dev);
91static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
92static int ibmveth_poll(struct napi_struct *napi, int budget);
93static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *dev);
94static void ibmveth_set_multicast_list(struct net_device *dev);
95static int ibmveth_change_mtu(struct net_device *dev, int new_mtu);
96static void ibmveth_proc_register_driver(void);
97static void ibmveth_proc_unregister_driver(void);
98static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
99static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
100static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); 52static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
101static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter); 53static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
102static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev); 54static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
103static struct kobj_type ktype_veth_pool;
104 55
56static struct kobj_type ktype_veth_pool;
105 57
106#ifdef CONFIG_PROC_FS
107#define IBMVETH_PROC_DIR "ibmveth"
108static struct proc_dir_entry *ibmveth_proc_dir;
109#endif
110 58
111static const char ibmveth_driver_name[] = "ibmveth"; 59static const char ibmveth_driver_name[] = "ibmveth";
112static const char ibmveth_driver_string[] = "IBM i/pSeries Virtual Ethernet Driver"; 60static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver";
113#define ibmveth_driver_version "1.03" 61#define ibmveth_driver_version "1.04"
114 62
115MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>"); 63MODULE_AUTHOR("Santiago Leon <santil@linux.vnet.ibm.com>");
116MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver"); 64MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver");
117MODULE_LICENSE("GPL"); 65MODULE_LICENSE("GPL");
118MODULE_VERSION(ibmveth_driver_version); 66MODULE_VERSION(ibmveth_driver_version);
119 67
68static unsigned int tx_copybreak __read_mostly = 128;
69module_param(tx_copybreak, uint, 0644);
70MODULE_PARM_DESC(tx_copybreak,
71 "Maximum size of packet that is copied to a new buffer on transmit");
72
73static unsigned int rx_copybreak __read_mostly = 128;
74module_param(rx_copybreak, uint, 0644);
75MODULE_PARM_DESC(rx_copybreak,
76 "Maximum size of packet that is copied to a new buffer on receive");
77
78static unsigned int rx_flush __read_mostly = 0;
79module_param(rx_flush, uint, 0644);
80MODULE_PARM_DESC(rx_flush, "Flush receive buffers before use");
81
120struct ibmveth_stat { 82struct ibmveth_stat {
121 char name[ETH_GSTRING_LEN]; 83 char name[ETH_GSTRING_LEN];
122 int offset; 84 int offset;
@@ -128,12 +90,16 @@ struct ibmveth_stat {
128struct ibmveth_stat ibmveth_stats[] = { 90struct ibmveth_stat ibmveth_stats[] = {
129 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) }, 91 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
130 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) }, 92 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
131 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) }, 93 { "replenish_add_buff_failure",
132 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) }, 94 IBMVETH_STAT_OFF(replenish_add_buff_failure) },
95 { "replenish_add_buff_success",
96 IBMVETH_STAT_OFF(replenish_add_buff_success) },
133 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) }, 97 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
134 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) }, 98 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
135 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) }, 99 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
136 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) }, 100 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
101 { "fw_enabled_ipv4_csum", IBMVETH_STAT_OFF(fw_ipv4_csum_support) },
102 { "fw_enabled_ipv6_csum", IBMVETH_STAT_OFF(fw_ipv6_csum_support) },
137}; 103};
138 104
139/* simple methods of getting data from the current rxq entry */ 105/* simple methods of getting data from the current rxq entry */
@@ -144,41 +110,44 @@ static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
144 110
145static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter) 111static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
146{ 112{
147 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT; 113 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >>
114 IBMVETH_RXQ_TOGGLE_SHIFT;
148} 115}
149 116
150static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter) 117static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
151{ 118{
152 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle); 119 return ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle;
153} 120}
154 121
155static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter) 122static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
156{ 123{
157 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID); 124 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID;
158} 125}
159 126
160static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter) 127static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
161{ 128{
162 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK); 129 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK;
163} 130}
164 131
165static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) 132static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
166{ 133{
167 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); 134 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].length;
168} 135}
169 136
170static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter) 137static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
171{ 138{
172 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD); 139 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD;
173} 140}
174 141
175/* setup the initial settings for a buffer pool */ 142/* setup the initial settings for a buffer pool */
176static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool, u32 pool_index, u32 pool_size, u32 buff_size, u32 pool_active) 143static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool,
144 u32 pool_index, u32 pool_size,
145 u32 buff_size, u32 pool_active)
177{ 146{
178 pool->size = pool_size; 147 pool->size = pool_size;
179 pool->index = pool_index; 148 pool->index = pool_index;
180 pool->buff_size = buff_size; 149 pool->buff_size = buff_size;
181 pool->threshold = pool_size / 2; 150 pool->threshold = pool_size * 7 / 8;
182 pool->active = pool_active; 151 pool->active = pool_active;
183} 152}
184 153
@@ -189,12 +158,11 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
189 158
190 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL); 159 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
191 160
192 if(!pool->free_map) { 161 if (!pool->free_map)
193 return -1; 162 return -1;
194 }
195 163
196 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL); 164 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
197 if(!pool->dma_addr) { 165 if (!pool->dma_addr) {
198 kfree(pool->free_map); 166 kfree(pool->free_map);
199 pool->free_map = NULL; 167 pool->free_map = NULL;
200 return -1; 168 return -1;
@@ -202,7 +170,7 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
202 170
203 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL); 171 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
204 172
205 if(!pool->skbuff) { 173 if (!pool->skbuff) {
206 kfree(pool->dma_addr); 174 kfree(pool->dma_addr);
207 pool->dma_addr = NULL; 175 pool->dma_addr = NULL;
208 176
@@ -213,9 +181,8 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
213 181
214 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size); 182 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
215 183
216 for(i = 0; i < pool->size; ++i) { 184 for (i = 0; i < pool->size; ++i)
217 pool->free_map[i] = i; 185 pool->free_map[i] = i;
218 }
219 186
220 atomic_set(&pool->available, 0); 187 atomic_set(&pool->available, 0);
221 pool->producer_index = 0; 188 pool->producer_index = 0;
@@ -224,10 +191,19 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
224 return 0; 191 return 0;
225} 192}
226 193
194static inline void ibmveth_flush_buffer(void *addr, unsigned long length)
195{
196 unsigned long offset;
197
198 for (offset = 0; offset < length; offset += SMP_CACHE_BYTES)
199 asm("dcbfl %0,%1" :: "b" (addr), "r" (offset));
200}
201
227/* replenish the buffers for a pool. note that we don't need to 202/* replenish the buffers for a pool. note that we don't need to
228 * skb_reserve these since they are used for incoming... 203 * skb_reserve these since they are used for incoming...
229 */ 204 */
230static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool) 205static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter,
206 struct ibmveth_buff_pool *pool)
231{ 207{
232 u32 i; 208 u32 i;
233 u32 count = pool->size - atomic_read(&pool->available); 209 u32 count = pool->size - atomic_read(&pool->available);
@@ -240,23 +216,26 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
240 216
241 mb(); 217 mb();
242 218
243 for(i = 0; i < count; ++i) { 219 for (i = 0; i < count; ++i) {
244 union ibmveth_buf_desc desc; 220 union ibmveth_buf_desc desc;
245 221
246 skb = alloc_skb(pool->buff_size, GFP_ATOMIC); 222 skb = netdev_alloc_skb(adapter->netdev, pool->buff_size);
247 223
248 if(!skb) { 224 if (!skb) {
249 ibmveth_debug_printk("replenish: unable to allocate skb\n"); 225 netdev_dbg(adapter->netdev,
226 "replenish: unable to allocate skb\n");
250 adapter->replenish_no_mem++; 227 adapter->replenish_no_mem++;
251 break; 228 break;
252 } 229 }
253 230
254 free_index = pool->consumer_index; 231 free_index = pool->consumer_index;
255 pool->consumer_index = (pool->consumer_index + 1) % pool->size; 232 pool->consumer_index++;
233 if (pool->consumer_index >= pool->size)
234 pool->consumer_index = 0;
256 index = pool->free_map[free_index]; 235 index = pool->free_map[free_index];
257 236
258 ibmveth_assert(index != IBM_VETH_INVALID_MAP); 237 BUG_ON(index == IBM_VETH_INVALID_MAP);
259 ibmveth_assert(pool->skbuff[index] == NULL); 238 BUG_ON(pool->skbuff[index] != NULL);
260 239
261 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, 240 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
262 pool->buff_size, DMA_FROM_DEVICE); 241 pool->buff_size, DMA_FROM_DEVICE);
@@ -269,16 +248,23 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
269 pool->skbuff[index] = skb; 248 pool->skbuff[index] = skb;
270 249
271 correlator = ((u64)pool->index << 32) | index; 250 correlator = ((u64)pool->index << 32) | index;
272 *(u64*)skb->data = correlator; 251 *(u64 *)skb->data = correlator;
273 252
274 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size; 253 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
275 desc.fields.address = dma_addr; 254 desc.fields.address = dma_addr;
276 255
277 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 256 if (rx_flush) {
257 unsigned int len = min(pool->buff_size,
258 adapter->netdev->mtu +
259 IBMVETH_BUFF_OH);
260 ibmveth_flush_buffer(skb->data, len);
261 }
262 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address,
263 desc.desc);
278 264
279 if (lpar_rc != H_SUCCESS) 265 if (lpar_rc != H_SUCCESS) {
280 goto failure; 266 goto failure;
281 else { 267 } else {
282 buffers_added++; 268 buffers_added++;
283 adapter->replenish_add_buff_success++; 269 adapter->replenish_add_buff_success++;
284 } 270 }
@@ -313,26 +299,31 @@ static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
313 299
314 adapter->replenish_task_cycles++; 300 adapter->replenish_task_cycles++;
315 301
316 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--) 302 for (i = (IBMVETH_NUM_BUFF_POOLS - 1); i >= 0; i--) {
317 if(adapter->rx_buff_pool[i].active) 303 struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i];
318 ibmveth_replenish_buffer_pool(adapter, 304
319 &adapter->rx_buff_pool[i]); 305 if (pool->active &&
306 (atomic_read(&pool->available) < pool->threshold))
307 ibmveth_replenish_buffer_pool(adapter, pool);
308 }
320 309
321 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); 310 adapter->rx_no_buffer = *(u64 *)(((char*)adapter->buffer_list_addr) +
311 4096 - 8);
322} 312}
323 313
324/* empty and free ana buffer pool - also used to do cleanup in error paths */ 314/* empty and free ana buffer pool - also used to do cleanup in error paths */
325static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool) 315static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter,
316 struct ibmveth_buff_pool *pool)
326{ 317{
327 int i; 318 int i;
328 319
329 kfree(pool->free_map); 320 kfree(pool->free_map);
330 pool->free_map = NULL; 321 pool->free_map = NULL;
331 322
332 if(pool->skbuff && pool->dma_addr) { 323 if (pool->skbuff && pool->dma_addr) {
333 for(i = 0; i < pool->size; ++i) { 324 for (i = 0; i < pool->size; ++i) {
334 struct sk_buff *skb = pool->skbuff[i]; 325 struct sk_buff *skb = pool->skbuff[i];
335 if(skb) { 326 if (skb) {
336 dma_unmap_single(&adapter->vdev->dev, 327 dma_unmap_single(&adapter->vdev->dev,
337 pool->dma_addr[i], 328 pool->dma_addr[i],
338 pool->buff_size, 329 pool->buff_size,
@@ -343,31 +334,32 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibm
343 } 334 }
344 } 335 }
345 336
346 if(pool->dma_addr) { 337 if (pool->dma_addr) {
347 kfree(pool->dma_addr); 338 kfree(pool->dma_addr);
348 pool->dma_addr = NULL; 339 pool->dma_addr = NULL;
349 } 340 }
350 341
351 if(pool->skbuff) { 342 if (pool->skbuff) {
352 kfree(pool->skbuff); 343 kfree(pool->skbuff);
353 pool->skbuff = NULL; 344 pool->skbuff = NULL;
354 } 345 }
355} 346}
356 347
357/* remove a buffer from a pool */ 348/* remove a buffer from a pool */
358static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator) 349static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter,
350 u64 correlator)
359{ 351{
360 unsigned int pool = correlator >> 32; 352 unsigned int pool = correlator >> 32;
361 unsigned int index = correlator & 0xffffffffUL; 353 unsigned int index = correlator & 0xffffffffUL;
362 unsigned int free_index; 354 unsigned int free_index;
363 struct sk_buff *skb; 355 struct sk_buff *skb;
364 356
365 ibmveth_assert(pool < IbmVethNumBufferPools); 357 BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS);
366 ibmveth_assert(index < adapter->rx_buff_pool[pool].size); 358 BUG_ON(index >= adapter->rx_buff_pool[pool].size);
367 359
368 skb = adapter->rx_buff_pool[pool].skbuff[index]; 360 skb = adapter->rx_buff_pool[pool].skbuff[index];
369 361
370 ibmveth_assert(skb != NULL); 362 BUG_ON(skb == NULL);
371 363
372 adapter->rx_buff_pool[pool].skbuff[index] = NULL; 364 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
373 365
@@ -377,9 +369,10 @@ static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64
377 DMA_FROM_DEVICE); 369 DMA_FROM_DEVICE);
378 370
379 free_index = adapter->rx_buff_pool[pool].producer_index; 371 free_index = adapter->rx_buff_pool[pool].producer_index;
380 adapter->rx_buff_pool[pool].producer_index 372 adapter->rx_buff_pool[pool].producer_index++;
381 = (adapter->rx_buff_pool[pool].producer_index + 1) 373 if (adapter->rx_buff_pool[pool].producer_index >=
382 % adapter->rx_buff_pool[pool].size; 374 adapter->rx_buff_pool[pool].size)
375 adapter->rx_buff_pool[pool].producer_index = 0;
383 adapter->rx_buff_pool[pool].free_map[free_index] = index; 376 adapter->rx_buff_pool[pool].free_map[free_index] = index;
384 377
385 mb(); 378 mb();
@@ -394,8 +387,8 @@ static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *ada
394 unsigned int pool = correlator >> 32; 387 unsigned int pool = correlator >> 32;
395 unsigned int index = correlator & 0xffffffffUL; 388 unsigned int index = correlator & 0xffffffffUL;
396 389
397 ibmveth_assert(pool < IbmVethNumBufferPools); 390 BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS);
398 ibmveth_assert(index < adapter->rx_buff_pool[pool].size); 391 BUG_ON(index >= adapter->rx_buff_pool[pool].size);
399 392
400 return adapter->rx_buff_pool[pool].skbuff[index]; 393 return adapter->rx_buff_pool[pool].skbuff[index];
401} 394}
@@ -410,10 +403,10 @@ static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
410 union ibmveth_buf_desc desc; 403 union ibmveth_buf_desc desc;
411 unsigned long lpar_rc; 404 unsigned long lpar_rc;
412 405
413 ibmveth_assert(pool < IbmVethNumBufferPools); 406 BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS);
414 ibmveth_assert(index < adapter->rx_buff_pool[pool].size); 407 BUG_ON(index >= adapter->rx_buff_pool[pool].size);
415 408
416 if(!adapter->rx_buff_pool[pool].active) { 409 if (!adapter->rx_buff_pool[pool].active) {
417 ibmveth_rxq_harvest_buffer(adapter); 410 ibmveth_rxq_harvest_buffer(adapter);
418 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]); 411 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
419 return; 412 return;
@@ -425,12 +418,13 @@ static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
425 418
426 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 419 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
427 420
428 if(lpar_rc != H_SUCCESS) { 421 if (lpar_rc != H_SUCCESS) {
429 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc); 422 netdev_dbg(adapter->netdev, "h_add_logical_lan_buffer failed "
423 "during recycle rc=%ld", lpar_rc);
430 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); 424 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
431 } 425 }
432 426
433 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) { 427 if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
434 adapter->rx_queue.index = 0; 428 adapter->rx_queue.index = 0;
435 adapter->rx_queue.toggle = !adapter->rx_queue.toggle; 429 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
436 } 430 }
@@ -440,7 +434,7 @@ static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
440{ 434{
441 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); 435 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
442 436
443 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) { 437 if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
444 adapter->rx_queue.index = 0; 438 adapter->rx_queue.index = 0;
445 adapter->rx_queue.toggle = !adapter->rx_queue.toggle; 439 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
446 } 440 }
@@ -451,7 +445,7 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
451 int i; 445 int i;
452 struct device *dev = &adapter->vdev->dev; 446 struct device *dev = &adapter->vdev->dev;
453 447
454 if(adapter->buffer_list_addr != NULL) { 448 if (adapter->buffer_list_addr != NULL) {
455 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) { 449 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
456 dma_unmap_single(dev, adapter->buffer_list_dma, 4096, 450 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
457 DMA_BIDIRECTIONAL); 451 DMA_BIDIRECTIONAL);
@@ -461,7 +455,7 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
461 adapter->buffer_list_addr = NULL; 455 adapter->buffer_list_addr = NULL;
462 } 456 }
463 457
464 if(adapter->filter_list_addr != NULL) { 458 if (adapter->filter_list_addr != NULL) {
465 if (!dma_mapping_error(dev, adapter->filter_list_dma)) { 459 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
466 dma_unmap_single(dev, adapter->filter_list_dma, 4096, 460 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
467 DMA_BIDIRECTIONAL); 461 DMA_BIDIRECTIONAL);
@@ -471,7 +465,7 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
471 adapter->filter_list_addr = NULL; 465 adapter->filter_list_addr = NULL;
472 } 466 }
473 467
474 if(adapter->rx_queue.queue_addr != NULL) { 468 if (adapter->rx_queue.queue_addr != NULL) {
475 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) { 469 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
476 dma_unmap_single(dev, 470 dma_unmap_single(dev,
477 adapter->rx_queue.queue_dma, 471 adapter->rx_queue.queue_dma,
@@ -483,7 +477,7 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
483 adapter->rx_queue.queue_addr = NULL; 477 adapter->rx_queue.queue_addr = NULL;
484 } 478 }
485 479
486 for(i = 0; i<IbmVethNumBufferPools; i++) 480 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
487 if (adapter->rx_buff_pool[i].active) 481 if (adapter->rx_buff_pool[i].active)
488 ibmveth_free_buffer_pool(adapter, 482 ibmveth_free_buffer_pool(adapter,
489 &adapter->rx_buff_pool[i]); 483 &adapter->rx_buff_pool[i]);
@@ -506,9 +500,11 @@ static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
506{ 500{
507 int rc, try_again = 1; 501 int rc, try_again = 1;
508 502
509 /* After a kexec the adapter will still be open, so our attempt to 503 /*
510 * open it will fail. So if we get a failure we free the adapter and 504 * After a kexec the adapter will still be open, so our attempt to
511 * try again, but only once. */ 505 * open it will fail. So if we get a failure we free the adapter and
506 * try again, but only once.
507 */
512retry: 508retry:
513 rc = h_register_logical_lan(adapter->vdev->unit_address, 509 rc = h_register_logical_lan(adapter->vdev->unit_address,
514 adapter->buffer_list_dma, rxq_desc.desc, 510 adapter->buffer_list_dma, rxq_desc.desc,
@@ -537,31 +533,32 @@ static int ibmveth_open(struct net_device *netdev)
537 int i; 533 int i;
538 struct device *dev; 534 struct device *dev;
539 535
540 ibmveth_debug_printk("open starting\n"); 536 netdev_dbg(netdev, "open starting\n");
541 537
542 napi_enable(&adapter->napi); 538 napi_enable(&adapter->napi);
543 539
544 for(i = 0; i<IbmVethNumBufferPools; i++) 540 for(i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
545 rxq_entries += adapter->rx_buff_pool[i].size; 541 rxq_entries += adapter->rx_buff_pool[i].size;
546 542
547 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL); 543 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
548 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL); 544 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
549 545
550 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) { 546 if (!adapter->buffer_list_addr || !adapter->filter_list_addr) {
551 ibmveth_error_printk("unable to allocate filter or buffer list pages\n"); 547 netdev_err(netdev, "unable to allocate filter or buffer list "
552 ibmveth_cleanup(adapter); 548 "pages\n");
553 napi_disable(&adapter->napi); 549 rc = -ENOMEM;
554 return -ENOMEM; 550 goto err_out;
555 } 551 }
556 552
557 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries; 553 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) *
558 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL); 554 rxq_entries;
555 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len,
556 GFP_KERNEL);
559 557
560 if(!adapter->rx_queue.queue_addr) { 558 if (!adapter->rx_queue.queue_addr) {
561 ibmveth_error_printk("unable to allocate rx queue pages\n"); 559 netdev_err(netdev, "unable to allocate rx queue pages\n");
562 ibmveth_cleanup(adapter); 560 rc = -ENOMEM;
563 napi_disable(&adapter->napi); 561 goto err_out;
564 return -ENOMEM;
565 } 562 }
566 563
567 dev = &adapter->vdev->dev; 564 dev = &adapter->vdev->dev;
@@ -577,10 +574,10 @@ static int ibmveth_open(struct net_device *netdev)
577 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) || 574 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
578 (dma_mapping_error(dev, adapter->filter_list_dma)) || 575 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
579 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) { 576 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
580 ibmveth_error_printk("unable to map filter or buffer list pages\n"); 577 netdev_err(netdev, "unable to map filter or buffer list "
581 ibmveth_cleanup(adapter); 578 "pages\n");
582 napi_disable(&adapter->napi); 579 rc = -ENOMEM;
583 return -ENOMEM; 580 goto err_out;
584 } 581 }
585 582
586 adapter->rx_queue.index = 0; 583 adapter->rx_queue.index = 0;
@@ -590,79 +587,86 @@ static int ibmveth_open(struct net_device *netdev)
590 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); 587 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
591 mac_address = mac_address >> 16; 588 mac_address = mac_address >> 16;
592 589
593 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len; 590 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
591 adapter->rx_queue.queue_len;
594 rxq_desc.fields.address = adapter->rx_queue.queue_dma; 592 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
595 593
596 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr); 594 netdev_dbg(netdev, "buffer list @ 0x%p\n", adapter->buffer_list_addr);
597 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr); 595 netdev_dbg(netdev, "filter list @ 0x%p\n", adapter->filter_list_addr);
598 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr); 596 netdev_dbg(netdev, "receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
599 597
600 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); 598 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
601 599
602 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address); 600 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
603 601
604 if(lpar_rc != H_SUCCESS) { 602 if (lpar_rc != H_SUCCESS) {
605 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc); 603 netdev_err(netdev, "h_register_logical_lan failed with %ld\n",
606 ibmveth_error_printk("buffer TCE:0x%llx filter TCE:0x%llx rxq desc:0x%llx MAC:0x%llx\n", 604 lpar_rc);
605 netdev_err(netdev, "buffer TCE:0x%llx filter TCE:0x%llx rxq "
606 "desc:0x%llx MAC:0x%llx\n",
607 adapter->buffer_list_dma, 607 adapter->buffer_list_dma,
608 adapter->filter_list_dma, 608 adapter->filter_list_dma,
609 rxq_desc.desc, 609 rxq_desc.desc,
610 mac_address); 610 mac_address);
611 ibmveth_cleanup(adapter); 611 rc = -ENONET;
612 napi_disable(&adapter->napi); 612 goto err_out;
613 return -ENONET;
614 } 613 }
615 614
616 for(i = 0; i<IbmVethNumBufferPools; i++) { 615 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
617 if(!adapter->rx_buff_pool[i].active) 616 if (!adapter->rx_buff_pool[i].active)
618 continue; 617 continue;
619 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) { 618 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
620 ibmveth_error_printk("unable to alloc pool\n"); 619 netdev_err(netdev, "unable to alloc pool\n");
621 adapter->rx_buff_pool[i].active = 0; 620 adapter->rx_buff_pool[i].active = 0;
622 ibmveth_cleanup(adapter); 621 rc = -ENOMEM;
623 napi_disable(&adapter->napi); 622 goto err_out;
624 return -ENOMEM ;
625 } 623 }
626 } 624 }
627 625
628 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq); 626 netdev_dbg(netdev, "registering irq 0x%x\n", netdev->irq);
629 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) { 627 rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name,
630 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc); 628 netdev);
629 if (rc != 0) {
630 netdev_err(netdev, "unable to request irq 0x%x, rc %d\n",
631 netdev->irq, rc);
631 do { 632 do {
632 rc = h_free_logical_lan(adapter->vdev->unit_address); 633 rc = h_free_logical_lan(adapter->vdev->unit_address);
633 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); 634 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
634 635
635 ibmveth_cleanup(adapter); 636 goto err_out;
636 napi_disable(&adapter->napi);
637 return rc;
638 } 637 }
639 638
640 adapter->bounce_buffer = 639 adapter->bounce_buffer =
641 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL); 640 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
642 if (!adapter->bounce_buffer) { 641 if (!adapter->bounce_buffer) {
643 ibmveth_error_printk("unable to allocate bounce buffer\n"); 642 netdev_err(netdev, "unable to allocate bounce buffer\n");
644 ibmveth_cleanup(adapter); 643 rc = -ENOMEM;
645 napi_disable(&adapter->napi); 644 goto err_out_free_irq;
646 return -ENOMEM;
647 } 645 }
648 adapter->bounce_buffer_dma = 646 adapter->bounce_buffer_dma =
649 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer, 647 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
650 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL); 648 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
651 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) { 649 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
652 ibmveth_error_printk("unable to map bounce buffer\n"); 650 netdev_err(netdev, "unable to map bounce buffer\n");
653 ibmveth_cleanup(adapter); 651 rc = -ENOMEM;
654 napi_disable(&adapter->napi); 652 goto err_out_free_irq;
655 return -ENOMEM;
656 } 653 }
657 654
658 ibmveth_debug_printk("initial replenish cycle\n"); 655 netdev_dbg(netdev, "initial replenish cycle\n");
659 ibmveth_interrupt(netdev->irq, netdev); 656 ibmveth_interrupt(netdev->irq, netdev);
660 657
661 netif_start_queue(netdev); 658 netif_start_queue(netdev);
662 659
663 ibmveth_debug_printk("open complete\n"); 660 netdev_dbg(netdev, "open complete\n");
664 661
665 return 0; 662 return 0;
663
664err_out_free_irq:
665 free_irq(netdev->irq, netdev);
666err_out:
667 ibmveth_cleanup(adapter);
668 napi_disable(&adapter->napi);
669 return rc;
666} 670}
667 671
668static int ibmveth_close(struct net_device *netdev) 672static int ibmveth_close(struct net_device *netdev)
@@ -670,7 +674,7 @@ static int ibmveth_close(struct net_device *netdev)
670 struct ibmveth_adapter *adapter = netdev_priv(netdev); 674 struct ibmveth_adapter *adapter = netdev_priv(netdev);
671 long lpar_rc; 675 long lpar_rc;
672 676
673 ibmveth_debug_printk("close starting\n"); 677 netdev_dbg(netdev, "close starting\n");
674 678
675 napi_disable(&adapter->napi); 679 napi_disable(&adapter->napi);
676 680
@@ -683,27 +687,30 @@ static int ibmveth_close(struct net_device *netdev)
683 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); 687 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
684 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); 688 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
685 689
686 if(lpar_rc != H_SUCCESS) 690 if (lpar_rc != H_SUCCESS) {
687 { 691 netdev_err(netdev, "h_free_logical_lan failed with %lx, "
688 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n", 692 "continuing with close\n", lpar_rc);
689 lpar_rc);
690 } 693 }
691 694
692 free_irq(netdev->irq, netdev); 695 free_irq(netdev->irq, netdev);
693 696
694 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); 697 adapter->rx_no_buffer = *(u64 *)(((char *)adapter->buffer_list_addr) +
698 4096 - 8);
695 699
696 ibmveth_cleanup(adapter); 700 ibmveth_cleanup(adapter);
697 701
698 ibmveth_debug_printk("close complete\n"); 702 netdev_dbg(netdev, "close complete\n");
699 703
700 return 0; 704 return 0;
701} 705}
702 706
703static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { 707static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
704 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE); 708{
705 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE); 709 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
706 cmd->speed = SPEED_1000; 710 SUPPORTED_FIBRE);
711 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
712 ADVERTISED_FIBRE);
713 ethtool_cmd_speed_set(cmd, SPEED_1000);
707 cmd->duplex = DUPLEX_FULL; 714 cmd->duplex = DUPLEX_FULL;
708 cmd->port = PORT_FIBRE; 715 cmd->port = PORT_FIBRE;
709 cmd->phy_address = 0; 716 cmd->phy_address = 0;
@@ -714,51 +721,37 @@ static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
714 return 0; 721 return 0;
715} 722}
716 723
717static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) { 724static void netdev_get_drvinfo(struct net_device *dev,
718 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1); 725 struct ethtool_drvinfo *info)
719 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
720}
721
722static u32 netdev_get_link(struct net_device *dev) {
723 return 1;
724}
725
726static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data)
727{ 726{
728 struct ibmveth_adapter *adapter = netdev_priv(dev); 727 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
729 728 strncpy(info->version, ibmveth_driver_version,
730 if (data) 729 sizeof(info->version) - 1);
731 adapter->rx_csum = 1;
732 else {
733 /*
734 * Since the ibmveth firmware interface does not have the concept of
735 * separate tx/rx checksum offload enable, if rx checksum is disabled
736 * we also have to disable tx checksum offload. Once we disable rx
737 * checksum offload, we are no longer allowed to send tx buffers that
738 * are not properly checksummed.
739 */
740 adapter->rx_csum = 0;
741 dev->features &= ~NETIF_F_IP_CSUM;
742 }
743} 730}
744 731
745static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data) 732static u32 ibmveth_fix_features(struct net_device *dev, u32 features)
746{ 733{
747 struct ibmveth_adapter *adapter = netdev_priv(dev); 734 /*
748 735 * Since the ibmveth firmware interface does not have the
749 if (data) { 736 * concept of separate tx/rx checksum offload enable, if rx
750 dev->features |= NETIF_F_IP_CSUM; 737 * checksum is disabled we also have to disable tx checksum
751 adapter->rx_csum = 1; 738 * offload. Once we disable rx checksum offload, we are no
752 } else 739 * longer allowed to send tx buffers that are not properly
753 dev->features &= ~NETIF_F_IP_CSUM; 740 * checksummed.
741 */
742
743 if (!(features & NETIF_F_RXCSUM))
744 features &= ~NETIF_F_ALL_CSUM;
745
746 return features;
754} 747}
755 748
756static int ibmveth_set_csum_offload(struct net_device *dev, u32 data, 749static int ibmveth_set_csum_offload(struct net_device *dev, u32 data)
757 void (*done) (struct net_device *, u32))
758{ 750{
759 struct ibmveth_adapter *adapter = netdev_priv(dev); 751 struct ibmveth_adapter *adapter = netdev_priv(dev);
760 unsigned long set_attr, clr_attr, ret_attr; 752 unsigned long set_attr, clr_attr, ret_attr;
761 long ret; 753 unsigned long set_attr6, clr_attr6;
754 long ret, ret6;
762 int rc1 = 0, rc2 = 0; 755 int rc1 = 0, rc2 = 0;
763 int restart = 0; 756 int restart = 0;
764 757
@@ -772,10 +765,13 @@ static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
772 set_attr = 0; 765 set_attr = 0;
773 clr_attr = 0; 766 clr_attr = 0;
774 767
775 if (data) 768 if (data) {
776 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; 769 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
777 else 770 set_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM;
771 } else {
778 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; 772 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
773 clr_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM;
774 }
779 775
780 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr); 776 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
781 777
@@ -786,18 +782,39 @@ static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
786 set_attr, &ret_attr); 782 set_attr, &ret_attr);
787 783
788 if (ret != H_SUCCESS) { 784 if (ret != H_SUCCESS) {
789 rc1 = -EIO; 785 netdev_err(dev, "unable to change IPv4 checksum "
790 ibmveth_error_printk("unable to change checksum offload settings." 786 "offload settings. %d rc=%ld\n",
791 " %d rc=%ld\n", data, ret); 787 data, ret);
792 788
793 ret = h_illan_attributes(adapter->vdev->unit_address, 789 ret = h_illan_attributes(adapter->vdev->unit_address,
794 set_attr, clr_attr, &ret_attr); 790 set_attr, clr_attr, &ret_attr);
791 } else {
792 adapter->fw_ipv4_csum_support = data;
793 }
794
795 ret6 = h_illan_attributes(adapter->vdev->unit_address,
796 clr_attr6, set_attr6, &ret_attr);
797
798 if (ret6 != H_SUCCESS) {
799 netdev_err(dev, "unable to change IPv6 checksum "
800 "offload settings. %d rc=%ld\n",
801 data, ret);
802
803 ret = h_illan_attributes(adapter->vdev->unit_address,
804 set_attr6, clr_attr6,
805 &ret_attr);
795 } else 806 } else
796 done(dev, data); 807 adapter->fw_ipv6_csum_support = data;
808
809 if (ret != H_SUCCESS || ret6 != H_SUCCESS)
810 adapter->rx_csum = data;
811 else
812 rc1 = -EIO;
797 } else { 813 } else {
798 rc1 = -EIO; 814 rc1 = -EIO;
799 ibmveth_error_printk("unable to change checksum offload settings." 815 netdev_err(dev, "unable to change checksum offload settings."
800 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr); 816 " %d rc=%ld ret_attr=%lx\n", data, ret,
817 ret_attr);
801 } 818 }
802 819
803 if (restart) 820 if (restart)
@@ -806,40 +823,22 @@ static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
806 return rc1 ? rc1 : rc2; 823 return rc1 ? rc1 : rc2;
807} 824}
808 825
809static int ibmveth_set_rx_csum(struct net_device *dev, u32 data) 826static int ibmveth_set_features(struct net_device *dev, u32 features)
810{
811 struct ibmveth_adapter *adapter = netdev_priv(dev);
812
813 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
814 return 0;
815
816 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
817}
818
819static int ibmveth_set_tx_csum(struct net_device *dev, u32 data)
820{ 827{
821 struct ibmveth_adapter *adapter = netdev_priv(dev); 828 struct ibmveth_adapter *adapter = netdev_priv(dev);
822 int rc = 0; 829 int rx_csum = !!(features & NETIF_F_RXCSUM);
830 int rc;
823 831
824 if (data && (dev->features & NETIF_F_IP_CSUM)) 832 if (rx_csum == adapter->rx_csum)
825 return 0;
826 if (!data && !(dev->features & NETIF_F_IP_CSUM))
827 return 0; 833 return 0;
828 834
829 if (data && !adapter->rx_csum) 835 rc = ibmveth_set_csum_offload(dev, rx_csum);
830 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags); 836 if (rc && !adapter->rx_csum)
831 else 837 dev->features = features & ~(NETIF_F_ALL_CSUM | NETIF_F_RXCSUM);
832 ibmveth_set_tx_csum_flags(dev, data);
833 838
834 return rc; 839 return rc;
835} 840}
836 841
837static u32 ibmveth_get_rx_csum(struct net_device *dev)
838{
839 struct ibmveth_adapter *adapter = netdev_priv(dev);
840 return adapter->rx_csum;
841}
842
843static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data) 842static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
844{ 843{
845 int i; 844 int i;
@@ -874,10 +873,7 @@ static void ibmveth_get_ethtool_stats(struct net_device *dev,
874static const struct ethtool_ops netdev_ethtool_ops = { 873static const struct ethtool_ops netdev_ethtool_ops = {
875 .get_drvinfo = netdev_get_drvinfo, 874 .get_drvinfo = netdev_get_drvinfo,
876 .get_settings = netdev_get_settings, 875 .get_settings = netdev_get_settings,
877 .get_link = netdev_get_link, 876 .get_link = ethtool_op_get_link,
878 .set_tx_csum = ibmveth_set_tx_csum,
879 .get_rx_csum = ibmveth_get_rx_csum,
880 .set_rx_csum = ibmveth_set_rx_csum,
881 .get_strings = ibmveth_get_strings, 877 .get_strings = ibmveth_get_strings,
882 .get_sset_count = ibmveth_get_sset_count, 878 .get_sset_count = ibmveth_get_sset_count,
883 .get_ethtool_stats = ibmveth_get_ethtool_stats, 879 .get_ethtool_stats = ibmveth_get_ethtool_stats,
@@ -890,129 +886,216 @@ static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
890 886
891#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1)) 887#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
892 888
893static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, 889static int ibmveth_send(struct ibmveth_adapter *adapter,
894 struct net_device *netdev) 890 union ibmveth_buf_desc *descs)
895{ 891{
896 struct ibmveth_adapter *adapter = netdev_priv(netdev);
897 union ibmveth_buf_desc desc;
898 unsigned long lpar_rc;
899 unsigned long correlator; 892 unsigned long correlator;
900 unsigned long flags;
901 unsigned int retry_count; 893 unsigned int retry_count;
902 unsigned int tx_dropped = 0; 894 unsigned long ret;
903 unsigned int tx_bytes = 0; 895
904 unsigned int tx_packets = 0; 896 /*
905 unsigned int tx_send_failed = 0; 897 * The retry count sets a maximum for the number of broadcast and
906 unsigned int tx_map_failed = 0; 898 * multicast destinations within the system.
907 int used_bounce = 0; 899 */
908 unsigned long data_dma_addr; 900 retry_count = 1024;
901 correlator = 0;
902 do {
903 ret = h_send_logical_lan(adapter->vdev->unit_address,
904 descs[0].desc, descs[1].desc,
905 descs[2].desc, descs[3].desc,
906 descs[4].desc, descs[5].desc,
907 correlator, &correlator);
908 } while ((ret == H_BUSY) && (retry_count--));
909
910 if (ret != H_SUCCESS && ret != H_DROPPED) {
911 netdev_err(adapter->netdev, "tx: h_send_logical_lan failed "
912 "with rc=%ld\n", ret);
913 return 1;
914 }
915
916 return 0;
917}
909 918
910 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len; 919static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
920 struct net_device *netdev)
921{
922 struct ibmveth_adapter *adapter = netdev_priv(netdev);
923 unsigned int desc_flags;
924 union ibmveth_buf_desc descs[6];
925 int last, i;
926 int force_bounce = 0;
927
928 /*
929 * veth handles a maximum of 6 segments including the header, so
930 * we have to linearize the skb if there are more than this.
931 */
932 if (skb_shinfo(skb)->nr_frags > 5 && __skb_linearize(skb)) {
933 netdev->stats.tx_dropped++;
934 goto out;
935 }
911 936
937 /* veth can't checksum offload UDP */
912 if (skb->ip_summed == CHECKSUM_PARTIAL && 938 if (skb->ip_summed == CHECKSUM_PARTIAL &&
913 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) { 939 ((skb->protocol == htons(ETH_P_IP) &&
914 ibmveth_error_printk("tx: failed to checksum packet\n"); 940 ip_hdr(skb)->protocol != IPPROTO_TCP) ||
915 tx_dropped++; 941 (skb->protocol == htons(ETH_P_IPV6) &&
942 ipv6_hdr(skb)->nexthdr != IPPROTO_TCP)) &&
943 skb_checksum_help(skb)) {
944
945 netdev_err(netdev, "tx: failed to checksum packet\n");
946 netdev->stats.tx_dropped++;
916 goto out; 947 goto out;
917 } 948 }
918 949
950 desc_flags = IBMVETH_BUF_VALID;
951
919 if (skb->ip_summed == CHECKSUM_PARTIAL) { 952 if (skb->ip_summed == CHECKSUM_PARTIAL) {
920 unsigned char *buf = skb_transport_header(skb) + skb->csum_offset; 953 unsigned char *buf = skb_transport_header(skb) +
954 skb->csum_offset;
921 955
922 desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD); 956 desc_flags |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
923 957
924 /* Need to zero out the checksum */ 958 /* Need to zero out the checksum */
925 buf[0] = 0; 959 buf[0] = 0;
926 buf[1] = 0; 960 buf[1] = 0;
927 } 961 }
928 962
929 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, 963retry_bounce:
930 skb->len, DMA_TO_DEVICE); 964 memset(descs, 0, sizeof(descs));
931 if (dma_mapping_error(&adapter->vdev->dev, data_dma_addr)) { 965
932 if (!firmware_has_feature(FW_FEATURE_CMO)) 966 /*
933 ibmveth_error_printk("tx: unable to map xmit buffer\n"); 967 * If a linear packet is below the rx threshold then
968 * copy it into the static bounce buffer. This avoids the
969 * cost of a TCE insert and remove.
970 */
971 if (force_bounce || (!skb_is_nonlinear(skb) &&
972 (skb->len < tx_copybreak))) {
934 skb_copy_from_linear_data(skb, adapter->bounce_buffer, 973 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
935 skb->len); 974 skb->len);
936 desc.fields.address = adapter->bounce_buffer_dma; 975
937 tx_map_failed++; 976 descs[0].fields.flags_len = desc_flags | skb->len;
938 used_bounce = 1; 977 descs[0].fields.address = adapter->bounce_buffer_dma;
939 wmb(); 978
940 } else 979 if (ibmveth_send(adapter, descs)) {
941 desc.fields.address = data_dma_addr; 980 adapter->tx_send_failed++;
942 981 netdev->stats.tx_dropped++;
943 /* send the frame. Arbitrarily set retrycount to 1024 */ 982 } else {
944 correlator = 0; 983 netdev->stats.tx_packets++;
945 retry_count = 1024; 984 netdev->stats.tx_bytes += skb->len;
946 do { 985 }
947 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address, 986
948 desc.desc, 0, 0, 0, 0, 0, 987 goto out;
949 correlator, &correlator); 988 }
950 } while ((lpar_rc == H_BUSY) && (retry_count--)); 989
951 990 /* Map the header */
952 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) { 991 descs[0].fields.address = dma_map_single(&adapter->vdev->dev, skb->data,
953 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc); 992 skb_headlen(skb),
954 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n", 993 DMA_TO_DEVICE);
955 (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0, 994 if (dma_mapping_error(&adapter->vdev->dev, descs[0].fields.address))
956 skb->len, desc.fields.address); 995 goto map_failed;
957 tx_send_failed++; 996
958 tx_dropped++; 997 descs[0].fields.flags_len = desc_flags | skb_headlen(skb);
959 } else { 998
960 tx_packets++; 999 /* Map the frags */
961 tx_bytes += skb->len; 1000 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
962 netdev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */ 1001 unsigned long dma_addr;
1002 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1003
1004 dma_addr = dma_map_page(&adapter->vdev->dev, frag->page,
1005 frag->page_offset, frag->size,
1006 DMA_TO_DEVICE);
1007
1008 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
1009 goto map_failed_frags;
1010
1011 descs[i+1].fields.flags_len = desc_flags | frag->size;
1012 descs[i+1].fields.address = dma_addr;
963 } 1013 }
964 1014
965 if (!used_bounce) 1015 if (ibmveth_send(adapter, descs)) {
966 dma_unmap_single(&adapter->vdev->dev, data_dma_addr, 1016 adapter->tx_send_failed++;
967 skb->len, DMA_TO_DEVICE); 1017 netdev->stats.tx_dropped++;
1018 } else {
1019 netdev->stats.tx_packets++;
1020 netdev->stats.tx_bytes += skb->len;
1021 }
968 1022
969out: spin_lock_irqsave(&adapter->stats_lock, flags); 1023 for (i = 0; i < skb_shinfo(skb)->nr_frags + 1; i++)
970 netdev->stats.tx_dropped += tx_dropped; 1024 dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address,
971 netdev->stats.tx_bytes += tx_bytes; 1025 descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK,
972 netdev->stats.tx_packets += tx_packets; 1026 DMA_TO_DEVICE);
973 adapter->tx_send_failed += tx_send_failed;
974 adapter->tx_map_failed += tx_map_failed;
975 spin_unlock_irqrestore(&adapter->stats_lock, flags);
976 1027
1028out:
977 dev_kfree_skb(skb); 1029 dev_kfree_skb(skb);
978 return NETDEV_TX_OK; 1030 return NETDEV_TX_OK;
1031
1032map_failed_frags:
1033 last = i+1;
1034 for (i = 0; i < last; i++)
1035 dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address,
1036 descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK,
1037 DMA_TO_DEVICE);
1038
1039map_failed:
1040 if (!firmware_has_feature(FW_FEATURE_CMO))
1041 netdev_err(netdev, "tx: unable to map xmit buffer\n");
1042 adapter->tx_map_failed++;
1043 skb_linearize(skb);
1044 force_bounce = 1;
1045 goto retry_bounce;
979} 1046}
980 1047
981static int ibmveth_poll(struct napi_struct *napi, int budget) 1048static int ibmveth_poll(struct napi_struct *napi, int budget)
982{ 1049{
983 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi); 1050 struct ibmveth_adapter *adapter =
1051 container_of(napi, struct ibmveth_adapter, napi);
984 struct net_device *netdev = adapter->netdev; 1052 struct net_device *netdev = adapter->netdev;
985 int frames_processed = 0; 1053 int frames_processed = 0;
986 unsigned long lpar_rc; 1054 unsigned long lpar_rc;
987 1055
988 restart_poll: 1056restart_poll:
989 do { 1057 do {
990 struct sk_buff *skb;
991
992 if (!ibmveth_rxq_pending_buffer(adapter)) 1058 if (!ibmveth_rxq_pending_buffer(adapter))
993 break; 1059 break;
994 1060
995 rmb(); 1061 smp_rmb();
996 if (!ibmveth_rxq_buffer_valid(adapter)) { 1062 if (!ibmveth_rxq_buffer_valid(adapter)) {
997 wmb(); /* suggested by larson1 */ 1063 wmb(); /* suggested by larson1 */
998 adapter->rx_invalid_buffer++; 1064 adapter->rx_invalid_buffer++;
999 ibmveth_debug_printk("recycling invalid buffer\n"); 1065 netdev_dbg(netdev, "recycling invalid buffer\n");
1000 ibmveth_rxq_recycle_buffer(adapter); 1066 ibmveth_rxq_recycle_buffer(adapter);
1001 } else { 1067 } else {
1068 struct sk_buff *skb, *new_skb;
1002 int length = ibmveth_rxq_frame_length(adapter); 1069 int length = ibmveth_rxq_frame_length(adapter);
1003 int offset = ibmveth_rxq_frame_offset(adapter); 1070 int offset = ibmveth_rxq_frame_offset(adapter);
1004 int csum_good = ibmveth_rxq_csum_good(adapter); 1071 int csum_good = ibmveth_rxq_csum_good(adapter);
1005 1072
1006 skb = ibmveth_rxq_get_buffer(adapter); 1073 skb = ibmveth_rxq_get_buffer(adapter);
1007 if (csum_good)
1008 skb->ip_summed = CHECKSUM_UNNECESSARY;
1009 1074
1010 ibmveth_rxq_harvest_buffer(adapter); 1075 new_skb = NULL;
1076 if (length < rx_copybreak)
1077 new_skb = netdev_alloc_skb(netdev, length);
1078
1079 if (new_skb) {
1080 skb_copy_to_linear_data(new_skb,
1081 skb->data + offset,
1082 length);
1083 if (rx_flush)
1084 ibmveth_flush_buffer(skb->data,
1085 length + offset);
1086 skb = new_skb;
1087 ibmveth_rxq_recycle_buffer(adapter);
1088 } else {
1089 ibmveth_rxq_harvest_buffer(adapter);
1090 skb_reserve(skb, offset);
1091 }
1011 1092
1012 skb_reserve(skb, offset);
1013 skb_put(skb, length); 1093 skb_put(skb, length);
1014 skb->protocol = eth_type_trans(skb, netdev); 1094 skb->protocol = eth_type_trans(skb, netdev);
1015 1095
1096 if (csum_good)
1097 skb->ip_summed = CHECKSUM_UNNECESSARY;
1098
1016 netif_receive_skb(skb); /* send it up */ 1099 netif_receive_skb(skb); /* send it up */
1017 1100
1018 netdev->stats.rx_packets++; 1101 netdev->stats.rx_packets++;
@@ -1030,7 +1113,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
1030 lpar_rc = h_vio_signal(adapter->vdev->unit_address, 1113 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1031 VIO_IRQ_ENABLE); 1114 VIO_IRQ_ENABLE);
1032 1115
1033 ibmveth_assert(lpar_rc == H_SUCCESS); 1116 BUG_ON(lpar_rc != H_SUCCESS);
1034 1117
1035 napi_complete(napi); 1118 napi_complete(napi);
1036 1119
@@ -1054,7 +1137,7 @@ static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
1054 if (napi_schedule_prep(&adapter->napi)) { 1137 if (napi_schedule_prep(&adapter->napi)) {
1055 lpar_rc = h_vio_signal(adapter->vdev->unit_address, 1138 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1056 VIO_IRQ_DISABLE); 1139 VIO_IRQ_DISABLE);
1057 ibmveth_assert(lpar_rc == H_SUCCESS); 1140 BUG_ON(lpar_rc != H_SUCCESS);
1058 __napi_schedule(&adapter->napi); 1141 __napi_schedule(&adapter->napi);
1059 } 1142 }
1060 return IRQ_HANDLED; 1143 return IRQ_HANDLED;
@@ -1071,8 +1154,9 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1071 IbmVethMcastEnableRecv | 1154 IbmVethMcastEnableRecv |
1072 IbmVethMcastDisableFiltering, 1155 IbmVethMcastDisableFiltering,
1073 0); 1156 0);
1074 if(lpar_rc != H_SUCCESS) { 1157 if (lpar_rc != H_SUCCESS) {
1075 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc); 1158 netdev_err(netdev, "h_multicast_ctrl rc=%ld when "
1159 "entering promisc mode\n", lpar_rc);
1076 } 1160 }
1077 } else { 1161 } else {
1078 struct netdev_hw_addr *ha; 1162 struct netdev_hw_addr *ha;
@@ -1082,19 +1166,23 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1082 IbmVethMcastDisableFiltering | 1166 IbmVethMcastDisableFiltering |
1083 IbmVethMcastClearFilterTable, 1167 IbmVethMcastClearFilterTable,
1084 0); 1168 0);
1085 if(lpar_rc != H_SUCCESS) { 1169 if (lpar_rc != H_SUCCESS) {
1086 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc); 1170 netdev_err(netdev, "h_multicast_ctrl rc=%ld when "
1171 "attempting to clear filter table\n",
1172 lpar_rc);
1087 } 1173 }
1088 /* add the addresses to the filter table */ 1174 /* add the addresses to the filter table */
1089 netdev_for_each_mc_addr(ha, netdev) { 1175 netdev_for_each_mc_addr(ha, netdev) {
1090 // add the multicast address to the filter table 1176 /* add the multicast address to the filter table */
1091 unsigned long mcast_addr = 0; 1177 unsigned long mcast_addr = 0;
1092 memcpy(((char *)&mcast_addr)+2, ha->addr, 6); 1178 memcpy(((char *)&mcast_addr)+2, ha->addr, 6);
1093 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 1179 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1094 IbmVethMcastAddFilter, 1180 IbmVethMcastAddFilter,
1095 mcast_addr); 1181 mcast_addr);
1096 if(lpar_rc != H_SUCCESS) { 1182 if (lpar_rc != H_SUCCESS) {
1097 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc); 1183 netdev_err(netdev, "h_multicast_ctrl rc=%ld "
1184 "when adding an entry to the filter "
1185 "table\n", lpar_rc);
1098 } 1186 }
1099 } 1187 }
1100 1188
@@ -1102,8 +1190,9 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1102 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 1190 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1103 IbmVethMcastEnableFiltering, 1191 IbmVethMcastEnableFiltering,
1104 0); 1192 0);
1105 if(lpar_rc != H_SUCCESS) { 1193 if (lpar_rc != H_SUCCESS) {
1106 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc); 1194 netdev_err(netdev, "h_multicast_ctrl rc=%ld when "
1195 "enabling filtering\n", lpar_rc);
1107 } 1196 }
1108 } 1197 }
1109} 1198}
@@ -1116,14 +1205,14 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1116 int i, rc; 1205 int i, rc;
1117 int need_restart = 0; 1206 int need_restart = 0;
1118 1207
1119 if (new_mtu < IBMVETH_MAX_MTU) 1208 if (new_mtu < IBMVETH_MIN_MTU)
1120 return -EINVAL; 1209 return -EINVAL;
1121 1210
1122 for (i = 0; i < IbmVethNumBufferPools; i++) 1211 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
1123 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) 1212 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1124 break; 1213 break;
1125 1214
1126 if (i == IbmVethNumBufferPools) 1215 if (i == IBMVETH_NUM_BUFF_POOLS)
1127 return -EINVAL; 1216 return -EINVAL;
1128 1217
1129 /* Deactivate all the buffer pools so that the next loop can activate 1218 /* Deactivate all the buffer pools so that the next loop can activate
@@ -1136,7 +1225,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1136 } 1225 }
1137 1226
1138 /* Look for an active buffer pool that can hold the new MTU */ 1227 /* Look for an active buffer pool that can hold the new MTU */
1139 for(i = 0; i<IbmVethNumBufferPools; i++) { 1228 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1140 adapter->rx_buff_pool[i].active = 1; 1229 adapter->rx_buff_pool[i].active = 1;
1141 1230
1142 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { 1231 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
@@ -1190,7 +1279,7 @@ static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1190 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE; 1279 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1191 ret += IOMMU_PAGE_ALIGN(netdev->mtu); 1280 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1192 1281
1193 for (i = 0; i < IbmVethNumBufferPools; i++) { 1282 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1194 /* add the size of the active receive buffers */ 1283 /* add the size of the active receive buffers */
1195 if (adapter->rx_buff_pool[i].active) 1284 if (adapter->rx_buff_pool[i].active)
1196 ret += 1285 ret +=
@@ -1212,6 +1301,8 @@ static const struct net_device_ops ibmveth_netdev_ops = {
1212 .ndo_set_multicast_list = ibmveth_set_multicast_list, 1301 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1213 .ndo_do_ioctl = ibmveth_ioctl, 1302 .ndo_do_ioctl = ibmveth_ioctl,
1214 .ndo_change_mtu = ibmveth_change_mtu, 1303 .ndo_change_mtu = ibmveth_change_mtu,
1304 .ndo_fix_features = ibmveth_fix_features,
1305 .ndo_set_features = ibmveth_set_features,
1215 .ndo_validate_addr = eth_validate_addr, 1306 .ndo_validate_addr = eth_validate_addr,
1216 .ndo_set_mac_address = eth_mac_addr, 1307 .ndo_set_mac_address = eth_mac_addr,
1217#ifdef CONFIG_NET_POLL_CONTROLLER 1308#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -1219,41 +1310,36 @@ static const struct net_device_ops ibmveth_netdev_ops = {
1219#endif 1310#endif
1220}; 1311};
1221 1312
1222static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) 1313static int __devinit ibmveth_probe(struct vio_dev *dev,
1314 const struct vio_device_id *id)
1223{ 1315{
1224 int rc, i; 1316 int rc, i;
1225 long ret;
1226 struct net_device *netdev; 1317 struct net_device *netdev;
1227 struct ibmveth_adapter *adapter; 1318 struct ibmveth_adapter *adapter;
1228 unsigned long set_attr, ret_attr;
1229
1230 unsigned char *mac_addr_p; 1319 unsigned char *mac_addr_p;
1231 unsigned int *mcastFilterSize_p; 1320 unsigned int *mcastFilterSize_p;
1232 1321
1322 dev_dbg(&dev->dev, "entering ibmveth_probe for UA 0x%x\n",
1323 dev->unit_address);
1233 1324
1234 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n", 1325 mac_addr_p = (unsigned char *)vio_get_attribute(dev, VETH_MAC_ADDR,
1235 dev->unit_address); 1326 NULL);
1236 1327 if (!mac_addr_p) {
1237 mac_addr_p = (unsigned char *) vio_get_attribute(dev, 1328 dev_err(&dev->dev, "Can't find VETH_MAC_ADDR attribute\n");
1238 VETH_MAC_ADDR, NULL); 1329 return -EINVAL;
1239 if(!mac_addr_p) {
1240 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1241 "attribute\n", __FILE__, __LINE__);
1242 return 0;
1243 } 1330 }
1244 1331
1245 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev, 1332 mcastFilterSize_p = (unsigned int *)vio_get_attribute(dev,
1246 VETH_MCAST_FILTER_SIZE, NULL); 1333 VETH_MCAST_FILTER_SIZE, NULL);
1247 if(!mcastFilterSize_p) { 1334 if (!mcastFilterSize_p) {
1248 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find " 1335 dev_err(&dev->dev, "Can't find VETH_MCAST_FILTER_SIZE "
1249 "VETH_MCAST_FILTER_SIZE attribute\n", 1336 "attribute\n");
1250 __FILE__, __LINE__); 1337 return -EINVAL;
1251 return 0;
1252 } 1338 }
1253 1339
1254 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter)); 1340 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1255 1341
1256 if(!netdev) 1342 if (!netdev)
1257 return -ENOMEM; 1343 return -ENOMEM;
1258 1344
1259 adapter = netdev_priv(netdev); 1345 adapter = netdev_priv(netdev);
@@ -1261,19 +1347,19 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_
1261 1347
1262 adapter->vdev = dev; 1348 adapter->vdev = dev;
1263 adapter->netdev = netdev; 1349 adapter->netdev = netdev;
1264 adapter->mcastFilterSize= *mcastFilterSize_p; 1350 adapter->mcastFilterSize = *mcastFilterSize_p;
1265 adapter->pool_config = 0; 1351 adapter->pool_config = 0;
1266 1352
1267 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); 1353 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1268 1354
1269 /* Some older boxes running PHYP non-natively have an OF that 1355 /*
1270 returns a 8-byte local-mac-address field (and the first 1356 * Some older boxes running PHYP non-natively have an OF that returns
1271 2 bytes have to be ignored) while newer boxes' OF return 1357 * a 8-byte local-mac-address field (and the first 2 bytes have to be
1272 a 6-byte field. Note that IEEE 1275 specifies that 1358 * ignored) while newer boxes' OF return a 6-byte field. Note that
1273 local-mac-address must be a 6-byte field. 1359 * IEEE 1275 specifies that local-mac-address must be a 6-byte field.
1274 The RPA doc specifies that the first byte must be 10b, so 1360 * The RPA doc specifies that the first byte must be 10b, so we'll
1275 we'll just look for it to solve this 8 vs. 6 byte field issue */ 1361 * just look for it to solve this 8 vs. 6 byte field issue
1276 1362 */
1277 if ((*mac_addr_p & 0x3) != 0x02) 1363 if ((*mac_addr_p & 0x3) != 0x02)
1278 mac_addr_p += 2; 1364 mac_addr_p += 2;
1279 1365
@@ -1284,12 +1370,13 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_
1284 netdev->netdev_ops = &ibmveth_netdev_ops; 1370 netdev->netdev_ops = &ibmveth_netdev_ops;
1285 netdev->ethtool_ops = &netdev_ethtool_ops; 1371 netdev->ethtool_ops = &netdev_ethtool_ops;
1286 SET_NETDEV_DEV(netdev, &dev->dev); 1372 SET_NETDEV_DEV(netdev, &dev->dev);
1287 netdev->features |= NETIF_F_LLTX; 1373 netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
1288 spin_lock_init(&adapter->stats_lock); 1374 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1375 netdev->features |= netdev->hw_features;
1289 1376
1290 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); 1377 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
1291 1378
1292 for(i = 0; i<IbmVethNumBufferPools; i++) { 1379 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1293 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; 1380 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
1294 int error; 1381 int error;
1295 1382
@@ -1302,41 +1389,25 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_
1302 kobject_uevent(kobj, KOBJ_ADD); 1389 kobject_uevent(kobj, KOBJ_ADD);
1303 } 1390 }
1304 1391
1305 ibmveth_debug_printk("adapter @ 0x%p\n", adapter); 1392 netdev_dbg(netdev, "adapter @ 0x%p\n", adapter);
1306 1393
1307 adapter->buffer_list_dma = DMA_ERROR_CODE; 1394 adapter->buffer_list_dma = DMA_ERROR_CODE;
1308 adapter->filter_list_dma = DMA_ERROR_CODE; 1395 adapter->filter_list_dma = DMA_ERROR_CODE;
1309 adapter->rx_queue.queue_dma = DMA_ERROR_CODE; 1396 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1310 1397
1311 ibmveth_debug_printk("registering netdev...\n"); 1398 netdev_dbg(netdev, "registering netdev...\n");
1312
1313 ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr);
1314
1315 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
1316 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
1317 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
1318 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
1319
1320 ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr);
1321 1399
1322 if (ret == H_SUCCESS) { 1400 ibmveth_set_features(netdev, netdev->features);
1323 adapter->rx_csum = 1;
1324 netdev->features |= NETIF_F_IP_CSUM;
1325 } else
1326 ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr);
1327 }
1328 1401
1329 rc = register_netdev(netdev); 1402 rc = register_netdev(netdev);
1330 1403
1331 if(rc) { 1404 if (rc) {
1332 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc); 1405 netdev_dbg(netdev, "failed to register netdev rc=%d\n", rc);
1333 free_netdev(netdev); 1406 free_netdev(netdev);
1334 return rc; 1407 return rc;
1335 } 1408 }
1336 1409
1337 ibmveth_debug_printk("registered\n"); 1410 netdev_dbg(netdev, "registered\n");
1338
1339 ibmveth_proc_register_adapter(adapter);
1340 1411
1341 return 0; 1412 return 0;
1342} 1413}
@@ -1347,114 +1418,23 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)
1347 struct ibmveth_adapter *adapter = netdev_priv(netdev); 1418 struct ibmveth_adapter *adapter = netdev_priv(netdev);
1348 int i; 1419 int i;
1349 1420
1350 for(i = 0; i<IbmVethNumBufferPools; i++) 1421 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
1351 kobject_put(&adapter->rx_buff_pool[i].kobj); 1422 kobject_put(&adapter->rx_buff_pool[i].kobj);
1352 1423
1353 unregister_netdev(netdev); 1424 unregister_netdev(netdev);
1354 1425
1355 ibmveth_proc_unregister_adapter(adapter);
1356
1357 free_netdev(netdev); 1426 free_netdev(netdev);
1358 dev_set_drvdata(&dev->dev, NULL); 1427 dev_set_drvdata(&dev->dev, NULL);
1359 1428
1360 return 0; 1429 return 0;
1361} 1430}
1362 1431
1363#ifdef CONFIG_PROC_FS
1364static void ibmveth_proc_register_driver(void)
1365{
1366 ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
1367 if (ibmveth_proc_dir) {
1368 }
1369}
1370
1371static void ibmveth_proc_unregister_driver(void)
1372{
1373 remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
1374}
1375
1376static int ibmveth_show(struct seq_file *seq, void *v)
1377{
1378 struct ibmveth_adapter *adapter = seq->private;
1379 char *current_mac = (char *) adapter->netdev->dev_addr;
1380 char *firmware_mac = (char *) &adapter->mac_addr;
1381
1382 seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
1383
1384 seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address);
1385 seq_printf(seq, "Current MAC: %pM\n", current_mac);
1386 seq_printf(seq, "Firmware MAC: %pM\n", firmware_mac);
1387
1388 seq_printf(seq, "\nAdapter Statistics:\n");
1389 seq_printf(seq, " TX: vio_map_single failres: %lld\n", adapter->tx_map_failed);
1390 seq_printf(seq, " send failures: %lld\n", adapter->tx_send_failed);
1391 seq_printf(seq, " RX: replenish task cycles: %lld\n", adapter->replenish_task_cycles);
1392 seq_printf(seq, " alloc_skb_failures: %lld\n", adapter->replenish_no_mem);
1393 seq_printf(seq, " add buffer failures: %lld\n", adapter->replenish_add_buff_failure);
1394 seq_printf(seq, " invalid buffers: %lld\n", adapter->rx_invalid_buffer);
1395 seq_printf(seq, " no buffers: %lld\n", adapter->rx_no_buffer);
1396
1397 return 0;
1398}
1399
1400static int ibmveth_proc_open(struct inode *inode, struct file *file)
1401{
1402 return single_open(file, ibmveth_show, PDE(inode)->data);
1403}
1404
1405static const struct file_operations ibmveth_proc_fops = {
1406 .owner = THIS_MODULE,
1407 .open = ibmveth_proc_open,
1408 .read = seq_read,
1409 .llseek = seq_lseek,
1410 .release = single_release,
1411};
1412
1413static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1414{
1415 struct proc_dir_entry *entry;
1416 if (ibmveth_proc_dir) {
1417 char u_addr[10];
1418 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1419 entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir,
1420 &ibmveth_proc_fops, adapter);
1421 if (!entry)
1422 ibmveth_error_printk("Cannot create adapter proc entry");
1423 }
1424}
1425
1426static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1427{
1428 if (ibmveth_proc_dir) {
1429 char u_addr[10];
1430 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1431 remove_proc_entry(u_addr, ibmveth_proc_dir);
1432 }
1433}
1434
1435#else /* CONFIG_PROC_FS */
1436static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1437{
1438}
1439
1440static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1441{
1442}
1443static void ibmveth_proc_register_driver(void)
1444{
1445}
1446
1447static void ibmveth_proc_unregister_driver(void)
1448{
1449}
1450#endif /* CONFIG_PROC_FS */
1451
1452static struct attribute veth_active_attr; 1432static struct attribute veth_active_attr;
1453static struct attribute veth_num_attr; 1433static struct attribute veth_num_attr;
1454static struct attribute veth_size_attr; 1434static struct attribute veth_size_attr;
1455 1435
1456static ssize_t veth_pool_show(struct kobject * kobj, 1436static ssize_t veth_pool_show(struct kobject *kobj,
1457 struct attribute * attr, char * buf) 1437 struct attribute *attr, char *buf)
1458{ 1438{
1459 struct ibmveth_buff_pool *pool = container_of(kobj, 1439 struct ibmveth_buff_pool *pool = container_of(kobj,
1460 struct ibmveth_buff_pool, 1440 struct ibmveth_buff_pool,
@@ -1469,8 +1449,8 @@ static ssize_t veth_pool_show(struct kobject * kobj,
1469 return 0; 1449 return 0;
1470} 1450}
1471 1451
1472static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr, 1452static ssize_t veth_pool_store(struct kobject *kobj, struct attribute *attr,
1473const char * buf, size_t count) 1453 const char *buf, size_t count)
1474{ 1454{
1475 struct ibmveth_buff_pool *pool = container_of(kobj, 1455 struct ibmveth_buff_pool *pool = container_of(kobj,
1476 struct ibmveth_buff_pool, 1456 struct ibmveth_buff_pool,
@@ -1484,8 +1464,9 @@ const char * buf, size_t count)
1484 if (attr == &veth_active_attr) { 1464 if (attr == &veth_active_attr) {
1485 if (value && !pool->active) { 1465 if (value && !pool->active) {
1486 if (netif_running(netdev)) { 1466 if (netif_running(netdev)) {
1487 if(ibmveth_alloc_buffer_pool(pool)) { 1467 if (ibmveth_alloc_buffer_pool(pool)) {
1488 ibmveth_error_printk("unable to alloc pool\n"); 1468 netdev_err(netdev,
1469 "unable to alloc pool\n");
1489 return -ENOMEM; 1470 return -ENOMEM;
1490 } 1471 }
1491 pool->active = 1; 1472 pool->active = 1;
@@ -1494,14 +1475,15 @@ const char * buf, size_t count)
1494 adapter->pool_config = 0; 1475 adapter->pool_config = 0;
1495 if ((rc = ibmveth_open(netdev))) 1476 if ((rc = ibmveth_open(netdev)))
1496 return rc; 1477 return rc;
1497 } else 1478 } else {
1498 pool->active = 1; 1479 pool->active = 1;
1480 }
1499 } else if (!value && pool->active) { 1481 } else if (!value && pool->active) {
1500 int mtu = netdev->mtu + IBMVETH_BUFF_OH; 1482 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1501 int i; 1483 int i;
1502 /* Make sure there is a buffer pool with buffers that 1484 /* Make sure there is a buffer pool with buffers that
1503 can hold a packet of the size of the MTU */ 1485 can hold a packet of the size of the MTU */
1504 for (i = 0; i < IbmVethNumBufferPools; i++) { 1486 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1505 if (pool == &adapter->rx_buff_pool[i]) 1487 if (pool == &adapter->rx_buff_pool[i])
1506 continue; 1488 continue;
1507 if (!adapter->rx_buff_pool[i].active) 1489 if (!adapter->rx_buff_pool[i].active)
@@ -1510,8 +1492,8 @@ const char * buf, size_t count)
1510 break; 1492 break;
1511 } 1493 }
1512 1494
1513 if (i == IbmVethNumBufferPools) { 1495 if (i == IBMVETH_NUM_BUFF_POOLS) {
1514 ibmveth_error_printk("no active pool >= MTU\n"); 1496 netdev_err(netdev, "no active pool >= MTU\n");
1515 return -EPERM; 1497 return -EPERM;
1516 } 1498 }
1517 1499
@@ -1526,9 +1508,9 @@ const char * buf, size_t count)
1526 pool->active = 0; 1508 pool->active = 0;
1527 } 1509 }
1528 } else if (attr == &veth_num_attr) { 1510 } else if (attr == &veth_num_attr) {
1529 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) 1511 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) {
1530 return -EINVAL; 1512 return -EINVAL;
1531 else { 1513 } else {
1532 if (netif_running(netdev)) { 1514 if (netif_running(netdev)) {
1533 adapter->pool_config = 1; 1515 adapter->pool_config = 1;
1534 ibmveth_close(netdev); 1516 ibmveth_close(netdev);
@@ -1536,13 +1518,14 @@ const char * buf, size_t count)
1536 pool->size = value; 1518 pool->size = value;
1537 if ((rc = ibmveth_open(netdev))) 1519 if ((rc = ibmveth_open(netdev)))
1538 return rc; 1520 return rc;
1539 } else 1521 } else {
1540 pool->size = value; 1522 pool->size = value;
1523 }
1541 } 1524 }
1542 } else if (attr == &veth_size_attr) { 1525 } else if (attr == &veth_size_attr) {
1543 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) 1526 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) {
1544 return -EINVAL; 1527 return -EINVAL;
1545 else { 1528 } else {
1546 if (netif_running(netdev)) { 1529 if (netif_running(netdev)) {
1547 adapter->pool_config = 1; 1530 adapter->pool_config = 1;
1548 ibmveth_close(netdev); 1531 ibmveth_close(netdev);
@@ -1550,8 +1533,9 @@ const char * buf, size_t count)
1550 pool->buff_size = value; 1533 pool->buff_size = value;
1551 if ((rc = ibmveth_open(netdev))) 1534 if ((rc = ibmveth_open(netdev)))
1552 return rc; 1535 return rc;
1553 } else 1536 } else {
1554 pool->buff_size = value; 1537 pool->buff_size = value;
1538 }
1555 } 1539 }
1556 } 1540 }
1557 1541
@@ -1561,16 +1545,16 @@ const char * buf, size_t count)
1561} 1545}
1562 1546
1563 1547
1564#define ATTR(_name, _mode) \ 1548#define ATTR(_name, _mode) \
1565 struct attribute veth_##_name##_attr = { \ 1549 struct attribute veth_##_name##_attr = { \
1566 .name = __stringify(_name), .mode = _mode, \ 1550 .name = __stringify(_name), .mode = _mode, \
1567 }; 1551 };
1568 1552
1569static ATTR(active, 0644); 1553static ATTR(active, 0644);
1570static ATTR(num, 0644); 1554static ATTR(num, 0644);
1571static ATTR(size, 0644); 1555static ATTR(size, 0644);
1572 1556
1573static struct attribute * veth_pool_attrs[] = { 1557static struct attribute *veth_pool_attrs[] = {
1574 &veth_active_attr, 1558 &veth_active_attr,
1575 &veth_num_attr, 1559 &veth_num_attr,
1576 &veth_size_attr, 1560 &veth_size_attr,
@@ -1595,7 +1579,7 @@ static int ibmveth_resume(struct device *dev)
1595 return 0; 1579 return 0;
1596} 1580}
1597 1581
1598static struct vio_device_id ibmveth_device_table[] __devinitdata= { 1582static struct vio_device_id ibmveth_device_table[] __devinitdata = {
1599 { "network", "IBM,l-lan"}, 1583 { "network", "IBM,l-lan"},
1600 { "", "" } 1584 { "", "" }
1601}; 1585};
@@ -1619,9 +1603,8 @@ static struct vio_driver ibmveth_driver = {
1619 1603
1620static int __init ibmveth_module_init(void) 1604static int __init ibmveth_module_init(void)
1621{ 1605{
1622 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version); 1606 printk(KERN_DEBUG "%s: %s %s\n", ibmveth_driver_name,
1623 1607 ibmveth_driver_string, ibmveth_driver_version);
1624 ibmveth_proc_register_driver();
1625 1608
1626 return vio_register_driver(&ibmveth_driver); 1609 return vio_register_driver(&ibmveth_driver);
1627} 1610}
@@ -1629,7 +1612,6 @@ static int __init ibmveth_module_init(void)
1629static void __exit ibmveth_module_exit(void) 1612static void __exit ibmveth_module_exit(void)
1630{ 1613{
1631 vio_unregister_driver(&ibmveth_driver); 1614 vio_unregister_driver(&ibmveth_driver);
1632 ibmveth_proc_unregister_driver();
1633} 1615}
1634 1616
1635module_init(ibmveth_module_init); 1617module_init(ibmveth_module_init);