blob: 5a4fca162e00ed4da9611991d67dc08a39051693 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**************************************************************************/
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. */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -040027/* */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/**************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
Robert Jennings1096d632008-07-24 04:34:52 +100031#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/types.h>
33#include <linux/errno.h>
34#include <linux/ioport.h>
35#include <linux/dma-mapping.h>
36#include <linux/kernel.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/skbuff.h>
40#include <linux/init.h>
41#include <linux/delay.h>
42#include <linux/mm.h>
Brian Kinge7a3af52010-05-07 08:56:08 +000043#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/ethtool.h>
Brian Kingf4ff2872007-09-15 13:36:07 -070045#include <linux/in.h>
46#include <linux/ip.h>
Santiago Leonab78df72010-09-03 18:28:52 +000047#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/hvcall.h>
50#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/vio.h>
Robert Jennings1096d632008-07-24 04:34:52 +100052#include <asm/iommu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/uaccess.h>
Robert Jennings1096d632008-07-24 04:34:52 +100054#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include "ibmveth.h"
57
Anton Blanchard6af37fa2005-11-11 14:02:04 +110058#undef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define ibmveth_printk(fmt, args...) \
Olof Johanssonf98baff2006-04-12 15:22:29 -050061 printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define ibmveth_error_printk(fmt, args...) \
64 printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
65
66#ifdef DEBUG
67#define ibmveth_debug_printk_no_adapter(fmt, args...) \
68 printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
69#define ibmveth_debug_printk(fmt, args...) \
70 printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
71#define ibmveth_assert(expr) \
72 if(!(expr)) { \
73 printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
74 BUG(); \
75 }
76#else
77#define ibmveth_debug_printk_no_adapter(fmt, args...)
78#define ibmveth_debug_printk(fmt, args...)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -040079#define ibmveth_assert(expr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#endif
81
David Howells7d12e782006-10-05 14:55:46 +010082static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
Michael Ellerman493a6842007-04-17 13:12:55 +100083static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
Robert Jennings1096d632008-07-24 04:34:52 +100084static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
Santiago Leone295fe82010-09-03 18:29:08 +000085
Santiago Leon860f2422006-04-25 11:19:59 -050086static struct kobj_type ktype_veth_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Robert Jennings1096d632008-07-24 04:34:52 +100088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static const char ibmveth_driver_name[] = "ibmveth";
90static const char ibmveth_driver_string[] = "IBM i/pSeries Virtual Ethernet Driver";
91#define ibmveth_driver_version "1.03"
92
93MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>");
94MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver");
95MODULE_LICENSE("GPL");
96MODULE_VERSION(ibmveth_driver_version);
97
Santiago Leonc08cc3c2010-09-03 18:28:20 +000098static unsigned int tx_copybreak __read_mostly = 128;
99module_param(tx_copybreak, uint, 0644);
100MODULE_PARM_DESC(tx_copybreak,
101 "Maximum size of packet that is copied to a new buffer on transmit");
102
Santiago Leon8d86c612010-09-03 18:28:25 +0000103static unsigned int rx_copybreak __read_mostly = 128;
104module_param(rx_copybreak, uint, 0644);
105MODULE_PARM_DESC(rx_copybreak,
106 "Maximum size of packet that is copied to a new buffer on receive");
107
Santiago Leon0c26b672010-09-03 18:28:41 +0000108static unsigned int rx_flush __read_mostly = 0;
109module_param(rx_flush, uint, 0644);
110MODULE_PARM_DESC(rx_flush, "Flush receive buffers before use");
111
Brian Kingddbb4de2007-08-17 09:16:43 -0500112struct ibmveth_stat {
113 char name[ETH_GSTRING_LEN];
114 int offset;
115};
116
117#define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
118#define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
119
120struct ibmveth_stat ibmveth_stats[] = {
121 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
122 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
123 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) },
124 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) },
125 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
126 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500127 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
128 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
Santiago Leonab78df72010-09-03 18:28:52 +0000129 { "fw_enabled_ipv4_csum", IBMVETH_STAT_OFF(fw_ipv4_csum_support) },
130 { "fw_enabled_ipv6_csum", IBMVETH_STAT_OFF(fw_ipv6_csum_support) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500131};
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* simple methods of getting data from the current rxq entry */
Brian King79ef4a42007-08-17 09:16:56 -0500134static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
135{
136 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off;
137}
138
139static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
140{
141 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT;
142}
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
145{
Brian King79ef4a42007-08-17 09:16:56 -0500146 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
150{
Brian King79ef4a42007-08-17 09:16:56 -0500151 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
155{
Brian King79ef4a42007-08-17 09:16:56 -0500156 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
160{
161 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
162}
163
Brian Kingf4ff2872007-09-15 13:36:07 -0700164static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
165{
Brian King79ef4a42007-08-17 09:16:56 -0500166 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700167}
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* setup the initial settings for a buffer pool */
Santiago Leon860f2422006-04-25 11:19:59 -0500170static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool, u32 pool_index, u32 pool_size, u32 buff_size, u32 pool_active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 pool->size = pool_size;
173 pool->index = pool_index;
174 pool->buff_size = buff_size;
Santiago Leonc033a6d2010-09-03 18:28:09 +0000175 pool->threshold = pool_size * 7 / 8;
Santiago Leon860f2422006-04-25 11:19:59 -0500176 pool->active = pool_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
179/* allocate and setup an buffer pool - called during open */
180static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
181{
182 int i;
183
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400184 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if(!pool->free_map) {
187 return -1;
188 }
189
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400190 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if(!pool->dma_addr) {
192 kfree(pool->free_map);
193 pool->free_map = NULL;
194 return -1;
195 }
196
Julia Lawalla05abcb2010-05-13 10:06:01 +0000197 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 if(!pool->skbuff) {
200 kfree(pool->dma_addr);
201 pool->dma_addr = NULL;
202
203 kfree(pool->free_map);
204 pool->free_map = NULL;
205 return -1;
206 }
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
209
210 for(i = 0; i < pool->size; ++i) {
211 pool->free_map[i] = i;
212 }
213
214 atomic_set(&pool->available, 0);
215 pool->producer_index = 0;
216 pool->consumer_index = 0;
217
218 return 0;
219}
220
Santiago Leon0c26b672010-09-03 18:28:41 +0000221static inline void ibmveth_flush_buffer(void *addr, unsigned long length)
222{
223 unsigned long offset;
224
225 for (offset = 0; offset < length; offset += SMP_CACHE_BYTES)
226 asm("dcbfl %0,%1" :: "b" (addr), "r" (offset));
227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/* replenish the buffers for a pool. note that we don't need to
230 * skb_reserve these since they are used for incoming...
231 */
232static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
233{
234 u32 i;
235 u32 count = pool->size - atomic_read(&pool->available);
236 u32 buffers_added = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000237 struct sk_buff *skb;
238 unsigned int free_index, index;
239 u64 correlator;
240 unsigned long lpar_rc;
241 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 mb();
244
245 for(i = 0; i < count; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Santiago Leon003212c2010-09-03 18:29:03 +0000248 skb = netdev_alloc_skb(adapter->netdev, pool->buff_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 if(!skb) {
251 ibmveth_debug_printk("replenish: unable to allocate skb\n");
252 adapter->replenish_no_mem++;
253 break;
254 }
255
David Gibson047a66d2006-10-21 10:24:13 -0700256 free_index = pool->consumer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000257 pool->consumer_index++;
258 if (pool->consumer_index >= pool->size)
259 pool->consumer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 index = pool->free_map[free_index];
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
263 ibmveth_assert(pool->skbuff[index] == NULL);
264
265 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
266 pool->buff_size, DMA_FROM_DEVICE);
267
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000268 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000269 goto failure;
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
272 pool->dma_addr[index] = dma_addr;
273 pool->skbuff[index] = skb;
274
275 correlator = ((u64)pool->index << 32) | index;
276 *(u64*)skb->data = correlator;
277
Brian King79ef4a42007-08-17 09:16:56 -0500278 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400279 desc.fields.address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Santiago Leon0c26b672010-09-03 18:28:41 +0000281 if (rx_flush) {
282 unsigned int len = min(pool->buff_size,
283 adapter->netdev->mtu +
284 IBMVETH_BUFF_OH);
285 ibmveth_flush_buffer(skb->data, len);
286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400288
Robert Jennings1096d632008-07-24 04:34:52 +1000289 if (lpar_rc != H_SUCCESS)
290 goto failure;
291 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 buffers_added++;
293 adapter->replenish_add_buff_success++;
294 }
295 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 mb();
298 atomic_add(buffers_added, &(pool->available));
Robert Jennings1096d632008-07-24 04:34:52 +1000299 return;
300
301failure:
302 pool->free_map[free_index] = index;
303 pool->skbuff[index] = NULL;
304 if (pool->consumer_index == 0)
305 pool->consumer_index = pool->size - 1;
306 else
307 pool->consumer_index--;
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000308 if (!dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000309 dma_unmap_single(&adapter->vdev->dev,
310 pool->dma_addr[index], pool->buff_size,
311 DMA_FROM_DEVICE);
312 dev_kfree_skb_any(skb);
313 adapter->replenish_add_buff_failure++;
314
315 mb();
316 atomic_add(buffers_added, &(pool->available));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
Santiago Leone2adbcb2005-10-26 10:47:08 -0600319/* replenish routine */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400320static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Santiago Leonb6d35182005-10-26 10:47:01 -0600322 int i;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 adapter->replenish_task_cycles++;
325
Santiago Leonc033a6d2010-09-03 18:28:09 +0000326 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--) {
327 struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i];
328
329 if (pool->active &&
330 (atomic_read(&pool->available) < pool->threshold))
331 ibmveth_replenish_buffer_pool(adapter, pool);
332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
337/* empty and free ana buffer pool - also used to do cleanup in error paths */
338static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
339{
340 int i;
341
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400342 kfree(pool->free_map);
343 pool->free_map = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 if(pool->skbuff && pool->dma_addr) {
346 for(i = 0; i < pool->size; ++i) {
347 struct sk_buff *skb = pool->skbuff[i];
348 if(skb) {
349 dma_unmap_single(&adapter->vdev->dev,
350 pool->dma_addr[i],
351 pool->buff_size,
352 DMA_FROM_DEVICE);
353 dev_kfree_skb_any(skb);
354 pool->skbuff[i] = NULL;
355 }
356 }
357 }
358
359 if(pool->dma_addr) {
360 kfree(pool->dma_addr);
361 pool->dma_addr = NULL;
362 }
363
364 if(pool->skbuff) {
365 kfree(pool->skbuff);
366 pool->skbuff = NULL;
367 }
368}
369
370/* remove a buffer from a pool */
371static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
372{
373 unsigned int pool = correlator >> 32;
374 unsigned int index = correlator & 0xffffffffUL;
375 unsigned int free_index;
376 struct sk_buff *skb;
377
378 ibmveth_assert(pool < IbmVethNumBufferPools);
379 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
380
381 skb = adapter->rx_buff_pool[pool].skbuff[index];
382
383 ibmveth_assert(skb != NULL);
384
385 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
386
387 dma_unmap_single(&adapter->vdev->dev,
388 adapter->rx_buff_pool[pool].dma_addr[index],
389 adapter->rx_buff_pool[pool].buff_size,
390 DMA_FROM_DEVICE);
391
David Gibson047a66d2006-10-21 10:24:13 -0700392 free_index = adapter->rx_buff_pool[pool].producer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000393 adapter->rx_buff_pool[pool].producer_index++;
394 if (adapter->rx_buff_pool[pool].producer_index >=
395 adapter->rx_buff_pool[pool].size)
396 adapter->rx_buff_pool[pool].producer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 adapter->rx_buff_pool[pool].free_map[free_index] = index;
398
399 mb();
400
401 atomic_dec(&(adapter->rx_buff_pool[pool].available));
402}
403
404/* get the current buffer on the rx queue */
405static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
406{
407 u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
408 unsigned int pool = correlator >> 32;
409 unsigned int index = correlator & 0xffffffffUL;
410
411 ibmveth_assert(pool < IbmVethNumBufferPools);
412 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
413
414 return adapter->rx_buff_pool[pool].skbuff[index];
415}
416
417/* recycle the current buffer on the rx queue */
418static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
419{
420 u32 q_index = adapter->rx_queue.index;
421 u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
422 unsigned int pool = correlator >> 32;
423 unsigned int index = correlator & 0xffffffffUL;
424 union ibmveth_buf_desc desc;
425 unsigned long lpar_rc;
426
427 ibmveth_assert(pool < IbmVethNumBufferPools);
428 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
429
Santiago Leonb6d35182005-10-26 10:47:01 -0600430 if(!adapter->rx_buff_pool[pool].active) {
431 ibmveth_rxq_harvest_buffer(adapter);
432 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
433 return;
434 }
435
Brian King79ef4a42007-08-17 09:16:56 -0500436 desc.fields.flags_len = IBMVETH_BUF_VALID |
437 adapter->rx_buff_pool[pool].buff_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
439
440 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400441
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200442 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
444 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
445 }
446
447 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
448 adapter->rx_queue.index = 0;
449 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
450 }
451}
452
Michael Ellerman493a6842007-04-17 13:12:55 +1000453static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
455 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
456
457 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
458 adapter->rx_queue.index = 0;
459 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
460 }
461}
462
463static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
464{
Santiago Leonb6d35182005-10-26 10:47:01 -0600465 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700466 struct device *dev = &adapter->vdev->dev;
Santiago Leonb6d35182005-10-26 10:47:01 -0600467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if(adapter->buffer_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700469 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
470 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 DMA_BIDIRECTIONAL);
472 adapter->buffer_list_dma = DMA_ERROR_CODE;
473 }
474 free_page((unsigned long)adapter->buffer_list_addr);
475 adapter->buffer_list_addr = NULL;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 if(adapter->filter_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700479 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
480 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 DMA_BIDIRECTIONAL);
482 adapter->filter_list_dma = DMA_ERROR_CODE;
483 }
484 free_page((unsigned long)adapter->filter_list_addr);
485 adapter->filter_list_addr = NULL;
486 }
487
488 if(adapter->rx_queue.queue_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700489 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
490 dma_unmap_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 adapter->rx_queue.queue_dma,
492 adapter->rx_queue.queue_len,
493 DMA_BIDIRECTIONAL);
494 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
495 }
496 kfree(adapter->rx_queue.queue_addr);
497 adapter->rx_queue.queue_addr = NULL;
498 }
499
Santiago Leonb6d35182005-10-26 10:47:01 -0600500 for(i = 0; i<IbmVethNumBufferPools; i++)
Santiago Leon860f2422006-04-25 11:19:59 -0500501 if (adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400502 ibmveth_free_buffer_pool(adapter,
Santiago Leon860f2422006-04-25 11:19:59 -0500503 &adapter->rx_buff_pool[i]);
Robert Jennings1096d632008-07-24 04:34:52 +1000504
505 if (adapter->bounce_buffer != NULL) {
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000506 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000507 dma_unmap_single(&adapter->vdev->dev,
508 adapter->bounce_buffer_dma,
509 adapter->netdev->mtu + IBMVETH_BUFF_OH,
510 DMA_BIDIRECTIONAL);
511 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
512 }
513 kfree(adapter->bounce_buffer);
514 adapter->bounce_buffer = NULL;
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500518static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
519 union ibmveth_buf_desc rxq_desc, u64 mac_address)
520{
521 int rc, try_again = 1;
522
523 /* After a kexec the adapter will still be open, so our attempt to
524 * open it will fail. So if we get a failure we free the adapter and
525 * try again, but only once. */
526retry:
527 rc = h_register_logical_lan(adapter->vdev->unit_address,
528 adapter->buffer_list_dma, rxq_desc.desc,
529 adapter->filter_list_dma, mac_address);
530
531 if (rc != H_SUCCESS && try_again) {
532 do {
533 rc = h_free_logical_lan(adapter->vdev->unit_address);
534 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
535
536 try_again = 0;
537 goto retry;
538 }
539
540 return rc;
541}
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543static int ibmveth_open(struct net_device *netdev)
544{
Wang Chen4cf16532008-11-12 23:38:14 -0800545 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 u64 mac_address = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -0600547 int rxq_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 unsigned long lpar_rc;
549 int rc;
550 union ibmveth_buf_desc rxq_desc;
Santiago Leonb6d35182005-10-26 10:47:01 -0600551 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700552 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 ibmveth_debug_printk("open starting\n");
555
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700556 napi_enable(&adapter->napi);
557
Santiago Leonb6d35182005-10-26 10:47:01 -0600558 for(i = 0; i<IbmVethNumBufferPools; i++)
559 rxq_entries += adapter->rx_buff_pool[i].size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
562 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
565 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
566 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700567 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return -ENOMEM;
569 }
570
571 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
572 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
573
574 if(!adapter->rx_queue.queue_addr) {
575 ibmveth_error_printk("unable to allocate rx queue pages\n");
576 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700577 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return -ENOMEM;
579 }
580
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700581 dev = &adapter->vdev->dev;
582
583 adapter->buffer_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700585 adapter->filter_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700587 adapter->rx_queue.queue_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 adapter->rx_queue.queue_addr,
589 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
590
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700591 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
592 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
593 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 ibmveth_error_printk("unable to map filter or buffer list pages\n");
595 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700596 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 return -ENOMEM;
598 }
599
600 adapter->rx_queue.index = 0;
601 adapter->rx_queue.num_slots = rxq_entries;
602 adapter->rx_queue.toggle = 1;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
605 mac_address = mac_address >> 16;
606
Brian King79ef4a42007-08-17 09:16:56 -0500607 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
609
610 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
611 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
612 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
613
Santiago Leon4347ef12006-10-03 12:24:34 -0500614 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
615
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500616 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200618 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000620 ibmveth_error_printk("buffer TCE:0x%llx filter TCE:0x%llx rxq desc:0x%llx MAC:0x%llx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 adapter->buffer_list_dma,
622 adapter->filter_list_dma,
623 rxq_desc.desc,
624 mac_address);
625 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700626 napi_disable(&adapter->napi);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400627 return -ENONET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
Santiago Leon860f2422006-04-25 11:19:59 -0500630 for(i = 0; i<IbmVethNumBufferPools; i++) {
631 if(!adapter->rx_buff_pool[i].active)
632 continue;
633 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
634 ibmveth_error_printk("unable to alloc pool\n");
635 adapter->rx_buff_pool[i].active = 0;
636 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700637 napi_disable(&adapter->napi);
Santiago Leon860f2422006-04-25 11:19:59 -0500638 return -ENOMEM ;
639 }
640 }
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -0800643 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
645 do {
646 rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200647 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700650 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return rc;
652 }
653
Robert Jennings1096d632008-07-24 04:34:52 +1000654 adapter->bounce_buffer =
655 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
656 if (!adapter->bounce_buffer) {
657 ibmveth_error_printk("unable to allocate bounce buffer\n");
658 ibmveth_cleanup(adapter);
659 napi_disable(&adapter->napi);
660 return -ENOMEM;
661 }
662 adapter->bounce_buffer_dma =
663 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
664 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700665 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000666 ibmveth_error_printk("unable to map bounce buffer\n");
667 ibmveth_cleanup(adapter);
668 napi_disable(&adapter->napi);
669 return -ENOMEM;
670 }
671
Santiago Leone2adbcb2005-10-26 10:47:08 -0600672 ibmveth_debug_printk("initial replenish cycle\n");
David Howells7d12e782006-10-05 14:55:46 +0100673 ibmveth_interrupt(netdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Santiago Leone2adbcb2005-10-26 10:47:08 -0600675 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 ibmveth_debug_printk("open complete\n");
678
679 return 0;
680}
681
682static int ibmveth_close(struct net_device *netdev)
683{
Wang Chen4cf16532008-11-12 23:38:14 -0800684 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 long lpar_rc;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 ibmveth_debug_printk("close starting\n");
688
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700689 napi_disable(&adapter->napi);
690
Santiago Leon860f2422006-04-25 11:19:59 -0500691 if (!adapter->pool_config)
692 netif_stop_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Robert Jenningsee2e6112010-07-16 04:57:25 +0000694 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 do {
697 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200698 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200700 if(lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
702 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
703 lpar_rc);
704 }
705
Robert Jenningsee2e6112010-07-16 04:57:25 +0000706 free_irq(netdev->irq, netdev);
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
709
710 ibmveth_cleanup(adapter);
711
712 ibmveth_debug_printk("close complete\n");
713
714 return 0;
715}
716
717static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
718 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
719 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
720 cmd->speed = SPEED_1000;
721 cmd->duplex = DUPLEX_FULL;
722 cmd->port = PORT_FIBRE;
723 cmd->phy_address = 0;
724 cmd->transceiver = XCVR_INTERNAL;
725 cmd->autoneg = AUTONEG_ENABLE;
726 cmd->maxtxpkt = 0;
727 cmd->maxrxpkt = 1;
728 return 0;
729}
730
731static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
732 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
733 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
734}
735
736static u32 netdev_get_link(struct net_device *dev) {
737 return 1;
738}
739
Brian King5fc7e012007-08-17 09:16:31 -0500740static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data)
741{
Wang Chen4cf16532008-11-12 23:38:14 -0800742 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500743
744 if (data)
745 adapter->rx_csum = 1;
746 else {
747 /*
748 * Since the ibmveth firmware interface does not have the concept of
749 * separate tx/rx checksum offload enable, if rx checksum is disabled
750 * we also have to disable tx checksum offload. Once we disable rx
751 * checksum offload, we are no longer allowed to send tx buffers that
752 * are not properly checksummed.
753 */
754 adapter->rx_csum = 0;
755 dev->features &= ~NETIF_F_IP_CSUM;
Santiago Leonab78df72010-09-03 18:28:52 +0000756 dev->features &= ~NETIF_F_IPV6_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500757 }
758}
759
760static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data)
761{
Wang Chen4cf16532008-11-12 23:38:14 -0800762 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500763
764 if (data) {
Santiago Leonab78df72010-09-03 18:28:52 +0000765 if (adapter->fw_ipv4_csum_support)
766 dev->features |= NETIF_F_IP_CSUM;
767 if (adapter->fw_ipv6_csum_support)
768 dev->features |= NETIF_F_IPV6_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500769 adapter->rx_csum = 1;
Santiago Leonab78df72010-09-03 18:28:52 +0000770 } else {
Brian King5fc7e012007-08-17 09:16:31 -0500771 dev->features &= ~NETIF_F_IP_CSUM;
Santiago Leonab78df72010-09-03 18:28:52 +0000772 dev->features &= ~NETIF_F_IPV6_CSUM;
773 }
Brian King5fc7e012007-08-17 09:16:31 -0500774}
775
776static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
777 void (*done) (struct net_device *, u32))
778{
Wang Chen4cf16532008-11-12 23:38:14 -0800779 struct ibmveth_adapter *adapter = netdev_priv(dev);
Stephen Rothwellff5bfc32009-01-06 10:47:44 -0800780 unsigned long set_attr, clr_attr, ret_attr;
Santiago Leonab78df72010-09-03 18:28:52 +0000781 unsigned long set_attr6, clr_attr6;
782 long ret, ret6;
Brian King5fc7e012007-08-17 09:16:31 -0500783 int rc1 = 0, rc2 = 0;
784 int restart = 0;
785
786 if (netif_running(dev)) {
787 restart = 1;
788 adapter->pool_config = 1;
789 ibmveth_close(dev);
790 adapter->pool_config = 0;
791 }
792
Brian King79ef4a42007-08-17 09:16:56 -0500793 set_attr = 0;
794 clr_attr = 0;
Brian King5fc7e012007-08-17 09:16:31 -0500795
Santiago Leonab78df72010-09-03 18:28:52 +0000796 if (data) {
Brian King79ef4a42007-08-17 09:16:56 -0500797 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Santiago Leonab78df72010-09-03 18:28:52 +0000798 set_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM;
799 } else {
Brian King79ef4a42007-08-17 09:16:56 -0500800 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Santiago Leonab78df72010-09-03 18:28:52 +0000801 clr_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM;
802 }
Brian King5fc7e012007-08-17 09:16:31 -0500803
Brian King79ef4a42007-08-17 09:16:56 -0500804 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500805
Brian King79ef4a42007-08-17 09:16:56 -0500806 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
807 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
808 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
809 ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr,
810 set_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500811
812 if (ret != H_SUCCESS) {
Santiago Leonab78df72010-09-03 18:28:52 +0000813 ibmveth_error_printk("unable to change IPv4 checksum "
814 "offload settings. %d rc=%ld\n",
815 data, ret);
Brian King5fc7e012007-08-17 09:16:31 -0500816
817 ret = h_illan_attributes(adapter->vdev->unit_address,
Brian King79ef4a42007-08-17 09:16:56 -0500818 set_attr, clr_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500819 } else
Santiago Leonab78df72010-09-03 18:28:52 +0000820 adapter->fw_ipv4_csum_support = data;
821
822 ret6 = h_illan_attributes(adapter->vdev->unit_address,
823 clr_attr6, set_attr6, &ret_attr);
824
825 if (ret6 != H_SUCCESS) {
826 ibmveth_error_printk("unable to change IPv6 checksum "
827 "offload settings. %d rc=%ld\n",
828 data, ret);
829
830 ret = h_illan_attributes(adapter->vdev->unit_address,
831 set_attr6, clr_attr6,
832 &ret_attr);
833 } else
834 adapter->fw_ipv6_csum_support = data;
835
836 if (ret == H_SUCCESS || ret6 == H_SUCCESS)
Brian King5fc7e012007-08-17 09:16:31 -0500837 done(dev, data);
Santiago Leonab78df72010-09-03 18:28:52 +0000838 else
839 rc1 = -EIO;
Brian King5fc7e012007-08-17 09:16:31 -0500840 } else {
841 rc1 = -EIO;
842 ibmveth_error_printk("unable to change checksum offload settings."
Brian King79ef4a42007-08-17 09:16:56 -0500843 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500844 }
845
846 if (restart)
847 rc2 = ibmveth_open(dev);
848
849 return rc1 ? rc1 : rc2;
850}
851
852static int ibmveth_set_rx_csum(struct net_device *dev, u32 data)
853{
Wang Chen4cf16532008-11-12 23:38:14 -0800854 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500855
856 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
857 return 0;
858
859 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
860}
861
862static int ibmveth_set_tx_csum(struct net_device *dev, u32 data)
863{
Wang Chen4cf16532008-11-12 23:38:14 -0800864 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500865 int rc = 0;
866
Santiago Leonab78df72010-09-03 18:28:52 +0000867 if (data && (dev->features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
Brian King5fc7e012007-08-17 09:16:31 -0500868 return 0;
Santiago Leonab78df72010-09-03 18:28:52 +0000869 if (!data && !(dev->features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
Brian King5fc7e012007-08-17 09:16:31 -0500870 return 0;
871
872 if (data && !adapter->rx_csum)
873 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags);
874 else
875 ibmveth_set_tx_csum_flags(dev, data);
876
877 return rc;
878}
879
880static u32 ibmveth_get_rx_csum(struct net_device *dev)
881{
Wang Chen4cf16532008-11-12 23:38:14 -0800882 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500883 return adapter->rx_csum;
884}
885
Brian Kingddbb4de2007-08-17 09:16:43 -0500886static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
887{
888 int i;
889
890 if (stringset != ETH_SS_STATS)
891 return;
892
893 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN)
894 memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN);
895}
896
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700897static int ibmveth_get_sset_count(struct net_device *dev, int sset)
Brian Kingddbb4de2007-08-17 09:16:43 -0500898{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700899 switch (sset) {
900 case ETH_SS_STATS:
901 return ARRAY_SIZE(ibmveth_stats);
902 default:
903 return -EOPNOTSUPP;
904 }
Brian Kingddbb4de2007-08-17 09:16:43 -0500905}
906
907static void ibmveth_get_ethtool_stats(struct net_device *dev,
908 struct ethtool_stats *stats, u64 *data)
909{
910 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800911 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian Kingddbb4de2007-08-17 09:16:43 -0500912
913 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++)
914 data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset);
915}
916
Jeff Garzik7282d492006-09-13 14:30:00 -0400917static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 .get_drvinfo = netdev_get_drvinfo,
919 .get_settings = netdev_get_settings,
920 .get_link = netdev_get_link,
Brian King5fc7e012007-08-17 09:16:31 -0500921 .set_tx_csum = ibmveth_set_tx_csum,
922 .get_rx_csum = ibmveth_get_rx_csum,
923 .set_rx_csum = ibmveth_set_rx_csum,
Brian Kingddbb4de2007-08-17 09:16:43 -0500924 .get_strings = ibmveth_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700925 .get_sset_count = ibmveth_get_sset_count,
Brian Kingddbb4de2007-08-17 09:16:43 -0500926 .get_ethtool_stats = ibmveth_get_ethtool_stats,
Santiago Leon6e8ab302010-09-03 18:28:36 +0000927 .set_sg = ethtool_op_set_sg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928};
929
930static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
931{
932 return -EOPNOTSUPP;
933}
934
935#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
936
Santiago Leon6e8ab302010-09-03 18:28:36 +0000937static int ibmveth_send(struct ibmveth_adapter *adapter,
938 union ibmveth_buf_desc *descs)
939{
940 unsigned long correlator;
941 unsigned int retry_count;
942 unsigned long ret;
943
944 /*
945 * The retry count sets a maximum for the number of broadcast and
946 * multicast destinations within the system.
947 */
948 retry_count = 1024;
949 correlator = 0;
950 do {
951 ret = h_send_logical_lan(adapter->vdev->unit_address,
952 descs[0].desc, descs[1].desc,
953 descs[2].desc, descs[3].desc,
954 descs[4].desc, descs[5].desc,
955 correlator, &correlator);
956 } while ((ret == H_BUSY) && (retry_count--));
957
958 if (ret != H_SUCCESS && ret != H_DROPPED) {
959 ibmveth_error_printk("tx: h_send_logical_lan failed with "
960 "rc=%ld\n", ret);
961 return 1;
962 }
963
964 return 0;
965}
966
Stephen Hemminger613573252009-08-31 19:50:58 +0000967static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
968 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Wang Chen4cf16532008-11-12 23:38:14 -0800970 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon6e8ab302010-09-03 18:28:36 +0000971 unsigned int desc_flags;
972 union ibmveth_buf_desc descs[6];
973 int last, i;
974 int force_bounce = 0;
Santiago Leon60296d92005-10-26 10:47:16 -0600975
Santiago Leon6e8ab302010-09-03 18:28:36 +0000976 /*
977 * veth handles a maximum of 6 segments including the header, so
978 * we have to linearize the skb if there are more than this.
979 */
980 if (skb_shinfo(skb)->nr_frags > 5 && __skb_linearize(skb)) {
981 netdev->stats.tx_dropped++;
Brian Kingf4ff2872007-09-15 13:36:07 -0700982 goto out;
983 }
984
Santiago Leon6e8ab302010-09-03 18:28:36 +0000985 /* veth can't checksum offload UDP */
986 if (skb->ip_summed == CHECKSUM_PARTIAL &&
Santiago Leonab78df72010-09-03 18:28:52 +0000987 ((skb->protocol == htons(ETH_P_IP) &&
988 ip_hdr(skb)->protocol != IPPROTO_TCP) ||
989 (skb->protocol == htons(ETH_P_IPV6) &&
990 ipv6_hdr(skb)->nexthdr != IPPROTO_TCP)) &&
991 skb_checksum_help(skb)) {
992
Santiago Leon6e8ab302010-09-03 18:28:36 +0000993 ibmveth_error_printk("tx: failed to checksum packet\n");
994 netdev->stats.tx_dropped++;
995 goto out;
996 }
Brian Kingf4ff2872007-09-15 13:36:07 -0700997
Santiago Leon6e8ab302010-09-03 18:28:36 +0000998 desc_flags = IBMVETH_BUF_VALID;
999
1000 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1001 unsigned char *buf = skb_transport_header(skb) +
1002 skb->csum_offset;
1003
1004 desc_flags |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -07001005
1006 /* Need to zero out the checksum */
1007 buf[0] = 0;
1008 buf[1] = 0;
1009 }
1010
Santiago Leon6e8ab302010-09-03 18:28:36 +00001011retry_bounce:
1012 memset(descs, 0, sizeof(descs));
Santiago Leonc08cc3c2010-09-03 18:28:20 +00001013
Santiago Leon6e8ab302010-09-03 18:28:36 +00001014 /*
1015 * If a linear packet is below the rx threshold then
1016 * copy it into the static bounce buffer. This avoids the
1017 * cost of a TCE insert and remove.
1018 */
1019 if (force_bounce || (!skb_is_nonlinear(skb) &&
1020 (skb->len < tx_copybreak))) {
Robert Jennings1096d632008-07-24 04:34:52 +10001021 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
1022 skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Santiago Leon6e8ab302010-09-03 18:28:36 +00001024 descs[0].fields.flags_len = desc_flags | skb->len;
1025 descs[0].fields.address = adapter->bounce_buffer_dma;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001026
Santiago Leon6e8ab302010-09-03 18:28:36 +00001027 if (ibmveth_send(adapter, descs)) {
1028 adapter->tx_send_failed++;
1029 netdev->stats.tx_dropped++;
1030 } else {
1031 netdev->stats.tx_packets++;
1032 netdev->stats.tx_bytes += skb->len;
1033 }
1034
1035 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
Santiago Leon6e8ab302010-09-03 18:28:36 +00001038 /* Map the header */
1039 descs[0].fields.address = dma_map_single(&adapter->vdev->dev, skb->data,
1040 skb_headlen(skb),
1041 DMA_TO_DEVICE);
1042 if (dma_mapping_error(&adapter->vdev->dev, descs[0].fields.address))
1043 goto map_failed;
1044
1045 descs[0].fields.flags_len = desc_flags | skb_headlen(skb);
1046
1047 /* Map the frags */
1048 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1049 unsigned long dma_addr;
1050 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1051
1052 dma_addr = dma_map_page(&adapter->vdev->dev, frag->page,
1053 frag->page_offset, frag->size,
1054 DMA_TO_DEVICE);
1055
1056 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
1057 goto map_failed_frags;
1058
1059 descs[i+1].fields.flags_len = desc_flags | frag->size;
1060 descs[i+1].fields.address = dma_addr;
1061 }
1062
1063 if (ibmveth_send(adapter, descs)) {
1064 adapter->tx_send_failed++;
1065 netdev->stats.tx_dropped++;
1066 } else {
1067 netdev->stats.tx_packets++;
1068 netdev->stats.tx_bytes += skb->len;
1069 }
1070
1071 for (i = 0; i < skb_shinfo(skb)->nr_frags + 1; i++)
1072 dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address,
1073 descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK,
1074 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Santiago Leone8cb7eb2010-09-03 18:28:15 +00001076out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 dev_kfree_skb(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001078 return NETDEV_TX_OK;
Santiago Leon6e8ab302010-09-03 18:28:36 +00001079
1080map_failed_frags:
1081 last = i+1;
1082 for (i = 0; i < last; i++)
1083 dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address,
1084 descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK,
1085 DMA_TO_DEVICE);
1086
1087map_failed:
1088 if (!firmware_has_feature(FW_FEATURE_CMO))
1089 ibmveth_error_printk("tx: unable to map xmit buffer\n");
1090 adapter->tx_map_failed++;
1091 skb_linearize(skb);
1092 force_bounce = 1;
1093 goto retry_bounce;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001096static int ibmveth_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001098 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
1099 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 int frames_processed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 unsigned long lpar_rc;
1102
1103 restart_poll:
1104 do {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001105 if (!ibmveth_rxq_pending_buffer(adapter))
1106 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Anton Blanchardf89e49e2010-09-06 18:21:41 -07001108 smp_rmb();
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001109 if (!ibmveth_rxq_buffer_valid(adapter)) {
1110 wmb(); /* suggested by larson1 */
1111 adapter->rx_invalid_buffer++;
1112 ibmveth_debug_printk("recycling invalid buffer\n");
1113 ibmveth_rxq_recycle_buffer(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 } else {
Santiago Leon8d86c612010-09-03 18:28:25 +00001115 struct sk_buff *skb, *new_skb;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001116 int length = ibmveth_rxq_frame_length(adapter);
1117 int offset = ibmveth_rxq_frame_offset(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001118 int csum_good = ibmveth_rxq_csum_good(adapter);
1119
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001120 skb = ibmveth_rxq_get_buffer(adapter);
1121
Santiago Leon8d86c612010-09-03 18:28:25 +00001122 new_skb = NULL;
1123 if (length < rx_copybreak)
1124 new_skb = netdev_alloc_skb(netdev, length);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001125
Santiago Leon8d86c612010-09-03 18:28:25 +00001126 if (new_skb) {
1127 skb_copy_to_linear_data(new_skb,
1128 skb->data + offset,
1129 length);
Santiago Leon0c26b672010-09-03 18:28:41 +00001130 if (rx_flush)
1131 ibmveth_flush_buffer(skb->data,
1132 length + offset);
Santiago Leon8d86c612010-09-03 18:28:25 +00001133 skb = new_skb;
1134 ibmveth_rxq_recycle_buffer(adapter);
1135 } else {
1136 ibmveth_rxq_harvest_buffer(adapter);
1137 skb_reserve(skb, offset);
1138 }
1139
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001140 skb_put(skb, length);
1141 skb->protocol = eth_type_trans(skb, netdev);
1142
Santiago Leon8d86c612010-09-03 18:28:25 +00001143 if (csum_good)
1144 skb->ip_summed = CHECKSUM_UNNECESSARY;
1145
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001146 netif_receive_skb(skb); /* send it up */
1147
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001148 netdev->stats.rx_packets++;
1149 netdev->stats.rx_bytes += length;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001150 frames_processed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001152 } while (frames_processed < budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Santiago Leone2adbcb2005-10-26 10:47:08 -06001154 ibmveth_replenish_task(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001156 if (frames_processed < budget) {
1157 /* We think we are done - reenable interrupts,
1158 * then check once more to make sure we are done.
1159 */
1160 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1161 VIO_IRQ_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001163 ibmveth_assert(lpar_rc == H_SUCCESS);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001164
Ben Hutchings288379f2009-01-19 16:43:59 -08001165 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001166
1167 if (ibmveth_rxq_pending_buffer(adapter) &&
Ben Hutchings288379f2009-01-19 16:43:59 -08001168 napi_reschedule(napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001169 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1170 VIO_IRQ_DISABLE);
1171 goto restart_poll;
1172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
1174
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001175 return frames_processed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
David Howells7d12e782006-10-05 14:55:46 +01001178static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 struct net_device *netdev = dev_instance;
Wang Chen4cf16532008-11-12 23:38:14 -08001181 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 unsigned long lpar_rc;
1183
Ben Hutchings288379f2009-01-19 16:43:59 -08001184 if (napi_schedule_prep(&adapter->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001185 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1186 VIO_IRQ_DISABLE);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001187 ibmveth_assert(lpar_rc == H_SUCCESS);
Ben Hutchings288379f2009-01-19 16:43:59 -08001188 __napi_schedule(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190 return IRQ_HANDLED;
1191}
1192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193static void ibmveth_set_multicast_list(struct net_device *netdev)
1194{
Wang Chen4cf16532008-11-12 23:38:14 -08001195 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 unsigned long lpar_rc;
1197
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001198 if ((netdev->flags & IFF_PROMISC) ||
1199 (netdev_mc_count(netdev) > adapter->mcastFilterSize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1201 IbmVethMcastEnableRecv |
1202 IbmVethMcastDisableFiltering,
1203 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001204 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
1206 }
1207 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001208 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 /* clear the filter table & disable filtering */
1210 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1211 IbmVethMcastEnableRecv |
1212 IbmVethMcastDisableFiltering |
1213 IbmVethMcastClearFilterTable,
1214 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001215 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
1217 }
1218 /* add the addresses to the filter table */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001219 netdev_for_each_mc_addr(ha, netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 // add the multicast address to the filter table
1221 unsigned long mcast_addr = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001222 memcpy(((char *)&mcast_addr)+2, ha->addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1224 IbmVethMcastAddFilter,
1225 mcast_addr);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001226 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
1228 }
1229 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 /* re-enable filtering */
1232 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1233 IbmVethMcastEnableFiltering,
1234 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001235 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
1237 }
1238 }
1239}
1240
1241static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1242{
Wang Chen4cf16532008-11-12 23:38:14 -08001243 struct ibmveth_adapter *adapter = netdev_priv(dev);
Robert Jennings1096d632008-07-24 04:34:52 +10001244 struct vio_dev *viodev = adapter->vdev;
Santiago Leon860f2422006-04-25 11:19:59 -05001245 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
Robert Jennings0645bab2010-08-17 09:15:45 +00001246 int i, rc;
1247 int need_restart = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001248
Santiago Leon860f2422006-04-25 11:19:59 -05001249 if (new_mtu < IBMVETH_MAX_MTU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 return -EINVAL;
Santiago Leonb6d35182005-10-26 10:47:01 -06001251
Brian Kingce6eea52007-06-08 14:05:17 -05001252 for (i = 0; i < IbmVethNumBufferPools; i++)
1253 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1254 break;
1255
1256 if (i == IbmVethNumBufferPools)
1257 return -EINVAL;
1258
Santiago Leonea866e62008-07-24 04:34:23 +10001259 /* Deactivate all the buffer pools so that the next loop can activate
1260 only the buffer pools necessary to hold the new MTU */
Robert Jennings0645bab2010-08-17 09:15:45 +00001261 if (netif_running(adapter->netdev)) {
1262 need_restart = 1;
1263 adapter->pool_config = 1;
1264 ibmveth_close(adapter->netdev);
1265 adapter->pool_config = 0;
1266 }
Brian Kingce6eea52007-06-08 14:05:17 -05001267
Santiago Leonea866e62008-07-24 04:34:23 +10001268 /* Look for an active buffer pool that can hold the new MTU */
1269 for(i = 0; i<IbmVethNumBufferPools; i++) {
1270 adapter->rx_buff_pool[i].active = 1;
1271
Santiago Leon860f2422006-04-25 11:19:59 -05001272 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
Robert Jennings1096d632008-07-24 04:34:52 +10001273 dev->mtu = new_mtu;
1274 vio_cmo_set_dev_desired(viodev,
1275 ibmveth_get_desired_dma
1276 (viodev));
Robert Jennings0645bab2010-08-17 09:15:45 +00001277 if (need_restart) {
1278 return ibmveth_open(adapter->netdev);
1279 }
Santiago Leon860f2422006-04-25 11:19:59 -05001280 return 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001281 }
Santiago Leonb6d35182005-10-26 10:47:01 -06001282 }
Robert Jennings0645bab2010-08-17 09:15:45 +00001283
1284 if (need_restart && (rc = ibmveth_open(adapter->netdev)))
1285 return rc;
1286
Santiago Leon860f2422006-04-25 11:19:59 -05001287 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Santiago Leon6b422372006-10-03 12:24:28 -05001290#ifdef CONFIG_NET_POLL_CONTROLLER
1291static void ibmveth_poll_controller(struct net_device *dev)
1292{
Wang Chen4cf16532008-11-12 23:38:14 -08001293 ibmveth_replenish_task(netdev_priv(dev));
Andrew Morton5f771132006-10-10 14:33:30 -07001294 ibmveth_interrupt(dev->irq, dev);
Santiago Leon6b422372006-10-03 12:24:28 -05001295}
1296#endif
1297
Robert Jennings1096d632008-07-24 04:34:52 +10001298/**
1299 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1300 *
1301 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1302 *
1303 * Return value:
1304 * Number of bytes of IO data the driver will need to perform well.
1305 */
1306static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1307{
1308 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1309 struct ibmveth_adapter *adapter;
1310 unsigned long ret;
1311 int i;
1312 int rxqentries = 1;
1313
1314 /* netdev inits at probe time along with the structures we need below*/
1315 if (netdev == NULL)
1316 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1317
1318 adapter = netdev_priv(netdev);
1319
1320 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1321 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1322
1323 for (i = 0; i < IbmVethNumBufferPools; i++) {
1324 /* add the size of the active receive buffers */
1325 if (adapter->rx_buff_pool[i].active)
1326 ret +=
1327 adapter->rx_buff_pool[i].size *
1328 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1329 buff_size);
1330 rxqentries += adapter->rx_buff_pool[i].size;
1331 }
1332 /* add the size of the receive queue entries */
1333 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1334
1335 return ret;
1336}
1337
Alexander Beregalove186d172009-04-15 12:52:39 +00001338static const struct net_device_ops ibmveth_netdev_ops = {
1339 .ndo_open = ibmveth_open,
1340 .ndo_stop = ibmveth_close,
1341 .ndo_start_xmit = ibmveth_start_xmit,
1342 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1343 .ndo_do_ioctl = ibmveth_ioctl,
1344 .ndo_change_mtu = ibmveth_change_mtu,
1345 .ndo_validate_addr = eth_validate_addr,
1346 .ndo_set_mac_address = eth_mac_addr,
1347#ifdef CONFIG_NET_POLL_CONTROLLER
1348 .ndo_poll_controller = ibmveth_poll_controller,
1349#endif
1350};
1351
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1353{
Santiago Leonb6d35182005-10-26 10:47:01 -06001354 int rc, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 struct net_device *netdev;
Mariusz Kozlowski9dc83af2007-08-06 23:44:03 +02001356 struct ibmveth_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 unsigned char *mac_addr_p;
1359 unsigned int *mcastFilterSize_p;
1360
1361
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001362 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 dev->unit_address);
1364
Michael Ellerman493a6842007-04-17 13:12:55 +10001365 mac_addr_p = (unsigned char *) vio_get_attribute(dev,
1366 VETH_MAC_ADDR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 if(!mac_addr_p) {
1368 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1369 "attribute\n", __FILE__, __LINE__);
1370 return 0;
1371 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001372
Michael Ellerman493a6842007-04-17 13:12:55 +10001373 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev,
1374 VETH_MCAST_FILTER_SIZE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 if(!mcastFilterSize_p) {
1376 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
1377 "VETH_MCAST_FILTER_SIZE attribute\n",
1378 __FILE__, __LINE__);
1379 return 0;
1380 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001381
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1383
1384 if(!netdev)
1385 return -ENOMEM;
1386
Wang Chen4cf16532008-11-12 23:38:14 -08001387 adapter = netdev_priv(netdev);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001388 dev_set_drvdata(&dev->dev, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
1390 adapter->vdev = dev;
1391 adapter->netdev = netdev;
1392 adapter->mcastFilterSize= *mcastFilterSize_p;
Santiago Leon860f2422006-04-25 11:19:59 -05001393 adapter->pool_config = 0;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001394
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001395 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 /* Some older boxes running PHYP non-natively have an OF that
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001398 returns a 8-byte local-mac-address field (and the first
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 2 bytes have to be ignored) while newer boxes' OF return
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001400 a 6-byte field. Note that IEEE 1275 specifies that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 local-mac-address must be a 6-byte field.
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001402 The RPA doc specifies that the first byte must be 10b, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 we'll just look for it to solve this 8 vs. 6 byte field issue */
1404
1405 if ((*mac_addr_p & 0x3) != 0x02)
1406 mac_addr_p += 2;
1407
1408 adapter->mac_addr = 0;
1409 memcpy(&adapter->mac_addr, mac_addr_p, 6);
1410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 netdev->irq = dev->irq;
Alexander Beregalove186d172009-04-15 12:52:39 +00001412 netdev->netdev_ops = &ibmveth_netdev_ops;
1413 netdev->ethtool_ops = &netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 SET_NETDEV_DEV(netdev, &dev->dev);
Santiago Leon6e8ab302010-09-03 18:28:36 +00001415 netdev->features |= NETIF_F_SG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Stephen Rothwelld44b5e02009-05-11 21:44:51 +00001417 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Santiago Leon860f2422006-04-25 11:19:59 -05001419 for(i = 0; i<IbmVethNumBufferPools; i++) {
1420 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001421 int error;
1422
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001423 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1424 pool_count[i], pool_size[i],
Santiago Leon860f2422006-04-25 11:19:59 -05001425 pool_active[i]);
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001426 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1427 &dev->dev.kobj, "pool%d", i);
1428 if (!error)
1429 kobject_uevent(kobj, KOBJ_ADD);
Santiago Leon860f2422006-04-25 11:19:59 -05001430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 adapter->buffer_list_dma = DMA_ERROR_CODE;
1435 adapter->filter_list_dma = DMA_ERROR_CODE;
1436 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 ibmveth_debug_printk("registering netdev...\n");
1439
Santiago Leonbc4c6f52010-09-03 18:28:47 +00001440 ibmveth_set_csum_offload(netdev, 1, ibmveth_set_tx_csum_flags);
Brian Kingf4ff2872007-09-15 13:36:07 -07001441
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 rc = register_netdev(netdev);
1443
1444 if(rc) {
1445 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1446 free_netdev(netdev);
1447 return rc;
1448 }
1449
1450 ibmveth_debug_printk("registered\n");
1451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 return 0;
1453}
1454
1455static int __devexit ibmveth_remove(struct vio_dev *dev)
1456{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001457 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Wang Chen4cf16532008-11-12 23:38:14 -08001458 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001459 int i;
1460
1461 for(i = 0; i<IbmVethNumBufferPools; i++)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001462 kobject_put(&adapter->rx_buff_pool[i].kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 unregister_netdev(netdev);
1465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 free_netdev(netdev);
Robert Jennings1096d632008-07-24 04:34:52 +10001467 dev_set_drvdata(&dev->dev, NULL);
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 return 0;
1470}
1471
Santiago Leon860f2422006-04-25 11:19:59 -05001472static struct attribute veth_active_attr;
1473static struct attribute veth_num_attr;
1474static struct attribute veth_size_attr;
1475
1476static ssize_t veth_pool_show(struct kobject * kobj,
1477 struct attribute * attr, char * buf)
1478{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001479 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001480 struct ibmveth_buff_pool,
1481 kobj);
1482
1483 if (attr == &veth_active_attr)
1484 return sprintf(buf, "%d\n", pool->active);
1485 else if (attr == &veth_num_attr)
1486 return sprintf(buf, "%d\n", pool->size);
1487 else if (attr == &veth_size_attr)
1488 return sprintf(buf, "%d\n", pool->buff_size);
1489 return 0;
1490}
1491
1492static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr,
1493const char * buf, size_t count)
1494{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001495 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001496 struct ibmveth_buff_pool,
1497 kobj);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001498 struct net_device *netdev = dev_get_drvdata(
1499 container_of(kobj->parent, struct device, kobj));
Wang Chen4cf16532008-11-12 23:38:14 -08001500 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001501 long value = simple_strtol(buf, NULL, 10);
1502 long rc;
1503
1504 if (attr == &veth_active_attr) {
1505 if (value && !pool->active) {
Brian King4aa9c932007-06-08 14:05:16 -05001506 if (netif_running(netdev)) {
1507 if(ibmveth_alloc_buffer_pool(pool)) {
1508 ibmveth_error_printk("unable to alloc pool\n");
1509 return -ENOMEM;
1510 }
1511 pool->active = 1;
1512 adapter->pool_config = 1;
1513 ibmveth_close(netdev);
1514 adapter->pool_config = 0;
1515 if ((rc = ibmveth_open(netdev)))
1516 return rc;
1517 } else
1518 pool->active = 1;
Santiago Leon860f2422006-04-25 11:19:59 -05001519 } else if (!value && pool->active) {
1520 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1521 int i;
1522 /* Make sure there is a buffer pool with buffers that
1523 can hold a packet of the size of the MTU */
Brian King76b9cfc2007-08-03 13:55:19 +10001524 for (i = 0; i < IbmVethNumBufferPools; i++) {
Santiago Leon860f2422006-04-25 11:19:59 -05001525 if (pool == &adapter->rx_buff_pool[i])
1526 continue;
1527 if (!adapter->rx_buff_pool[i].active)
1528 continue;
Brian King76b9cfc2007-08-03 13:55:19 +10001529 if (mtu <= adapter->rx_buff_pool[i].buff_size)
1530 break;
Santiago Leon860f2422006-04-25 11:19:59 -05001531 }
Brian King76b9cfc2007-08-03 13:55:19 +10001532
1533 if (i == IbmVethNumBufferPools) {
Santiago Leon860f2422006-04-25 11:19:59 -05001534 ibmveth_error_printk("no active pool >= MTU\n");
1535 return -EPERM;
1536 }
Brian King76b9cfc2007-08-03 13:55:19 +10001537
Brian King76b9cfc2007-08-03 13:55:19 +10001538 if (netif_running(netdev)) {
1539 adapter->pool_config = 1;
1540 ibmveth_close(netdev);
Santiago Leonea866e62008-07-24 04:34:23 +10001541 pool->active = 0;
Brian King76b9cfc2007-08-03 13:55:19 +10001542 adapter->pool_config = 0;
1543 if ((rc = ibmveth_open(netdev)))
1544 return rc;
1545 }
Santiago Leonea866e62008-07-24 04:34:23 +10001546 pool->active = 0;
Santiago Leon860f2422006-04-25 11:19:59 -05001547 }
1548 } else if (attr == &veth_num_attr) {
1549 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
1550 return -EINVAL;
1551 else {
Brian King4aa9c932007-06-08 14:05:16 -05001552 if (netif_running(netdev)) {
1553 adapter->pool_config = 1;
1554 ibmveth_close(netdev);
1555 adapter->pool_config = 0;
1556 pool->size = value;
1557 if ((rc = ibmveth_open(netdev)))
1558 return rc;
1559 } else
1560 pool->size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001561 }
1562 } else if (attr == &veth_size_attr) {
1563 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
1564 return -EINVAL;
1565 else {
Brian King4aa9c932007-06-08 14:05:16 -05001566 if (netif_running(netdev)) {
1567 adapter->pool_config = 1;
1568 ibmveth_close(netdev);
1569 adapter->pool_config = 0;
1570 pool->buff_size = value;
1571 if ((rc = ibmveth_open(netdev)))
1572 return rc;
1573 } else
1574 pool->buff_size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001575 }
1576 }
1577
1578 /* kick the interrupt handler to allocate/deallocate pools */
David Howells7d12e782006-10-05 14:55:46 +01001579 ibmveth_interrupt(netdev->irq, netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001580 return count;
1581}
1582
1583
1584#define ATTR(_name, _mode) \
1585 struct attribute veth_##_name##_attr = { \
Tejun Heo7b595752007-06-14 03:45:17 +09001586 .name = __stringify(_name), .mode = _mode, \
Santiago Leon860f2422006-04-25 11:19:59 -05001587 };
1588
1589static ATTR(active, 0644);
1590static ATTR(num, 0644);
1591static ATTR(size, 0644);
1592
1593static struct attribute * veth_pool_attrs[] = {
1594 &veth_active_attr,
1595 &veth_num_attr,
1596 &veth_size_attr,
1597 NULL,
1598};
1599
Emese Revfy52cf25d2010-01-19 02:58:23 +01001600static const struct sysfs_ops veth_pool_ops = {
Santiago Leon860f2422006-04-25 11:19:59 -05001601 .show = veth_pool_show,
1602 .store = veth_pool_store,
1603};
1604
1605static struct kobj_type ktype_veth_pool = {
1606 .release = NULL,
1607 .sysfs_ops = &veth_pool_ops,
1608 .default_attrs = veth_pool_attrs,
1609};
1610
Brian Kinge7a3af52010-05-07 08:56:08 +00001611static int ibmveth_resume(struct device *dev)
1612{
1613 struct net_device *netdev = dev_get_drvdata(dev);
1614 ibmveth_interrupt(netdev->irq, netdev);
1615 return 0;
1616}
Santiago Leon860f2422006-04-25 11:19:59 -05001617
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1619 { "network", "IBM,l-lan"},
Stephen Rothwellfb120da2005-08-17 16:42:59 +10001620 { "", "" }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1623
Brian Kinge7a3af52010-05-07 08:56:08 +00001624static struct dev_pm_ops ibmveth_pm_ops = {
1625 .resume = ibmveth_resume
1626};
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628static struct vio_driver ibmveth_driver = {
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001629 .id_table = ibmveth_device_table,
1630 .probe = ibmveth_probe,
1631 .remove = ibmveth_remove,
Robert Jennings1096d632008-07-24 04:34:52 +10001632 .get_desired_dma = ibmveth_get_desired_dma,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001633 .driver = {
1634 .name = ibmveth_driver_name,
Stephen Rothwell915124d2005-10-24 15:12:22 +10001635 .owner = THIS_MODULE,
Brian Kinge7a3af52010-05-07 08:56:08 +00001636 .pm = &ibmveth_pm_ops,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638};
1639
1640static int __init ibmveth_module_init(void)
1641{
1642 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 return vio_register_driver(&ibmveth_driver);
1645}
1646
1647static void __exit ibmveth_module_exit(void)
1648{
1649 vio_unregister_driver(&ibmveth_driver);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001650}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652module_init(ibmveth_module_init);
1653module_exit(ibmveth_module_exit);