blob: 41b9c0efcbddfcccfca9a6a1680879102e244208 [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/**************************************************************************/
29/*
30 TODO:
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 - add support for sysfs
32 - possibly remove procfs support
33*/
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/module.h>
Robert Jennings1096d632008-07-24 04:34:52 +100036#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/types.h>
38#include <linux/errno.h>
39#include <linux/ioport.h>
40#include <linux/dma-mapping.h>
41#include <linux/kernel.h>
42#include <linux/netdevice.h>
43#include <linux/etherdevice.h>
44#include <linux/skbuff.h>
45#include <linux/init.h>
46#include <linux/delay.h>
47#include <linux/mm.h>
48#include <linux/ethtool.h>
49#include <linux/proc_fs.h>
Brian Kingf4ff2872007-09-15 13:36:07 -070050#include <linux/in.h>
51#include <linux/ip.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020052#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/hvcall.h>
54#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/vio.h>
Robert Jennings1096d632008-07-24 04:34:52 +100056#include <asm/iommu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <asm/uaccess.h>
Robert Jennings1096d632008-07-24 04:34:52 +100058#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <linux/seq_file.h>
60
61#include "ibmveth.h"
62
Anton Blanchard6af37fa2005-11-11 14:02:04 +110063#undef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#define ibmveth_printk(fmt, args...) \
Olof Johanssonf98baff2006-04-12 15:22:29 -050066 printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#define ibmveth_error_printk(fmt, args...) \
69 printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
70
71#ifdef DEBUG
72#define ibmveth_debug_printk_no_adapter(fmt, args...) \
73 printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
74#define ibmveth_debug_printk(fmt, args...) \
75 printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
76#define ibmveth_assert(expr) \
77 if(!(expr)) { \
78 printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
79 BUG(); \
80 }
81#else
82#define ibmveth_debug_printk_no_adapter(fmt, args...)
83#define ibmveth_debug_printk(fmt, args...)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -040084#define ibmveth_assert(expr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#endif
86
87static int ibmveth_open(struct net_device *dev);
88static int ibmveth_close(struct net_device *dev);
89static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070090static int ibmveth_poll(struct napi_struct *napi, int budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static void ibmveth_set_multicast_list(struct net_device *dev);
93static int ibmveth_change_mtu(struct net_device *dev, int new_mtu);
94static void ibmveth_proc_register_driver(void);
95static void ibmveth_proc_unregister_driver(void);
96static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
97static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
David Howells7d12e782006-10-05 14:55:46 +010098static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
Michael Ellerman493a6842007-04-17 13:12:55 +100099static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
Robert Jennings1096d632008-07-24 04:34:52 +1000100static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
Santiago Leon860f2422006-04-25 11:19:59 -0500101static struct kobj_type ktype_veth_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Robert Jennings1096d632008-07-24 04:34:52 +1000103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#ifdef CONFIG_PROC_FS
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200105#define IBMVETH_PROC_DIR "ibmveth"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static struct proc_dir_entry *ibmveth_proc_dir;
107#endif
108
109static const char ibmveth_driver_name[] = "ibmveth";
110static const char ibmveth_driver_string[] = "IBM i/pSeries Virtual Ethernet Driver";
111#define ibmveth_driver_version "1.03"
112
113MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>");
114MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver");
115MODULE_LICENSE("GPL");
116MODULE_VERSION(ibmveth_driver_version);
117
Brian Kingddbb4de2007-08-17 09:16:43 -0500118struct ibmveth_stat {
119 char name[ETH_GSTRING_LEN];
120 int offset;
121};
122
123#define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
124#define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
125
126struct ibmveth_stat ibmveth_stats[] = {
127 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
128 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
129 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) },
130 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) },
131 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
132 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500133 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
134 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
135};
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/* simple methods of getting data from the current rxq entry */
Brian King79ef4a42007-08-17 09:16:56 -0500138static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
139{
140 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off;
141}
142
143static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
144{
145 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT;
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
149{
Brian King79ef4a42007-08-17 09:16:56 -0500150 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
154{
Brian King79ef4a42007-08-17 09:16:56 -0500155 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
159{
Brian King79ef4a42007-08-17 09:16:56 -0500160 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
163static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
164{
165 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
166}
167
Brian Kingf4ff2872007-09-15 13:36:07 -0700168static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
169{
Brian King79ef4a42007-08-17 09:16:56 -0500170 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* setup the initial settings for a buffer pool */
Santiago Leon860f2422006-04-25 11:19:59 -0500174static 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 -0700175{
176 pool->size = pool_size;
177 pool->index = pool_index;
178 pool->buff_size = buff_size;
179 pool->threshold = pool_size / 2;
Santiago Leon860f2422006-04-25 11:19:59 -0500180 pool->active = pool_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183/* allocate and setup an buffer pool - called during open */
184static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
185{
186 int i;
187
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400188 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 if(!pool->free_map) {
191 return -1;
192 }
193
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400194 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if(!pool->dma_addr) {
196 kfree(pool->free_map);
197 pool->free_map = NULL;
198 return -1;
199 }
200
201 pool->skbuff = kmalloc(sizeof(void*) * pool->size, GFP_KERNEL);
202
203 if(!pool->skbuff) {
204 kfree(pool->dma_addr);
205 pool->dma_addr = NULL;
206
207 kfree(pool->free_map);
208 pool->free_map = NULL;
209 return -1;
210 }
211
212 memset(pool->skbuff, 0, sizeof(void*) * pool->size);
213 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
214
215 for(i = 0; i < pool->size; ++i) {
216 pool->free_map[i] = i;
217 }
218
219 atomic_set(&pool->available, 0);
220 pool->producer_index = 0;
221 pool->consumer_index = 0;
222
223 return 0;
224}
225
226/* replenish the buffers for a pool. note that we don't need to
227 * skb_reserve these since they are used for incoming...
228 */
229static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
230{
231 u32 i;
232 u32 count = pool->size - atomic_read(&pool->available);
233 u32 buffers_added = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000234 struct sk_buff *skb;
235 unsigned int free_index, index;
236 u64 correlator;
237 unsigned long lpar_rc;
238 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 mb();
241
242 for(i = 0; i < count; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
246
247 if(!skb) {
248 ibmveth_debug_printk("replenish: unable to allocate skb\n");
249 adapter->replenish_no_mem++;
250 break;
251 }
252
David Gibson047a66d2006-10-21 10:24:13 -0700253 free_index = pool->consumer_index;
254 pool->consumer_index = (pool->consumer_index + 1) % pool->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 index = pool->free_map[free_index];
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
258 ibmveth_assert(pool->skbuff[index] == NULL);
259
260 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
261 pool->buff_size, DMA_FROM_DEVICE);
262
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000263 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000264 goto failure;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
267 pool->dma_addr[index] = dma_addr;
268 pool->skbuff[index] = skb;
269
270 correlator = ((u64)pool->index << 32) | index;
271 *(u64*)skb->data = correlator;
272
Brian King79ef4a42007-08-17 09:16:56 -0500273 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400274 desc.fields.address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400277
Robert Jennings1096d632008-07-24 04:34:52 +1000278 if (lpar_rc != H_SUCCESS)
279 goto failure;
280 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 buffers_added++;
282 adapter->replenish_add_buff_success++;
283 }
284 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 mb();
287 atomic_add(buffers_added, &(pool->available));
Robert Jennings1096d632008-07-24 04:34:52 +1000288 return;
289
290failure:
291 pool->free_map[free_index] = index;
292 pool->skbuff[index] = NULL;
293 if (pool->consumer_index == 0)
294 pool->consumer_index = pool->size - 1;
295 else
296 pool->consumer_index--;
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000297 if (!dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000298 dma_unmap_single(&adapter->vdev->dev,
299 pool->dma_addr[index], pool->buff_size,
300 DMA_FROM_DEVICE);
301 dev_kfree_skb_any(skb);
302 adapter->replenish_add_buff_failure++;
303
304 mb();
305 atomic_add(buffers_added, &(pool->available));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Santiago Leone2adbcb2005-10-26 10:47:08 -0600308/* replenish routine */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400309static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Santiago Leonb6d35182005-10-26 10:47:01 -0600311 int i;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 adapter->replenish_task_cycles++;
314
Robert Jennings1096d632008-07-24 04:34:52 +1000315 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--)
Santiago Leonb6d35182005-10-26 10:47:01 -0600316 if(adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400317 ibmveth_replenish_buffer_pool(adapter,
Santiago Leonb6d35182005-10-26 10:47:01 -0600318 &adapter->rx_buff_pool[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323/* empty and free ana buffer pool - also used to do cleanup in error paths */
324static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
325{
326 int i;
327
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400328 kfree(pool->free_map);
329 pool->free_map = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 if(pool->skbuff && pool->dma_addr) {
332 for(i = 0; i < pool->size; ++i) {
333 struct sk_buff *skb = pool->skbuff[i];
334 if(skb) {
335 dma_unmap_single(&adapter->vdev->dev,
336 pool->dma_addr[i],
337 pool->buff_size,
338 DMA_FROM_DEVICE);
339 dev_kfree_skb_any(skb);
340 pool->skbuff[i] = NULL;
341 }
342 }
343 }
344
345 if(pool->dma_addr) {
346 kfree(pool->dma_addr);
347 pool->dma_addr = NULL;
348 }
349
350 if(pool->skbuff) {
351 kfree(pool->skbuff);
352 pool->skbuff = NULL;
353 }
354}
355
356/* remove a buffer from a pool */
357static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
358{
359 unsigned int pool = correlator >> 32;
360 unsigned int index = correlator & 0xffffffffUL;
361 unsigned int free_index;
362 struct sk_buff *skb;
363
364 ibmveth_assert(pool < IbmVethNumBufferPools);
365 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
366
367 skb = adapter->rx_buff_pool[pool].skbuff[index];
368
369 ibmveth_assert(skb != NULL);
370
371 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
372
373 dma_unmap_single(&adapter->vdev->dev,
374 adapter->rx_buff_pool[pool].dma_addr[index],
375 adapter->rx_buff_pool[pool].buff_size,
376 DMA_FROM_DEVICE);
377
David Gibson047a66d2006-10-21 10:24:13 -0700378 free_index = adapter->rx_buff_pool[pool].producer_index;
379 adapter->rx_buff_pool[pool].producer_index
380 = (adapter->rx_buff_pool[pool].producer_index + 1)
381 % adapter->rx_buff_pool[pool].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 adapter->rx_buff_pool[pool].free_map[free_index] = index;
383
384 mb();
385
386 atomic_dec(&(adapter->rx_buff_pool[pool].available));
387}
388
389/* get the current buffer on the rx queue */
390static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
391{
392 u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
393 unsigned int pool = correlator >> 32;
394 unsigned int index = correlator & 0xffffffffUL;
395
396 ibmveth_assert(pool < IbmVethNumBufferPools);
397 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
398
399 return adapter->rx_buff_pool[pool].skbuff[index];
400}
401
402/* recycle the current buffer on the rx queue */
403static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
404{
405 u32 q_index = adapter->rx_queue.index;
406 u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
407 unsigned int pool = correlator >> 32;
408 unsigned int index = correlator & 0xffffffffUL;
409 union ibmveth_buf_desc desc;
410 unsigned long lpar_rc;
411
412 ibmveth_assert(pool < IbmVethNumBufferPools);
413 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
414
Santiago Leonb6d35182005-10-26 10:47:01 -0600415 if(!adapter->rx_buff_pool[pool].active) {
416 ibmveth_rxq_harvest_buffer(adapter);
417 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
418 return;
419 }
420
Brian King79ef4a42007-08-17 09:16:56 -0500421 desc.fields.flags_len = IBMVETH_BUF_VALID |
422 adapter->rx_buff_pool[pool].buff_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
424
425 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400426
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200427 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
429 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
430 }
431
432 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
433 adapter->rx_queue.index = 0;
434 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
435 }
436}
437
Michael Ellerman493a6842007-04-17 13:12:55 +1000438static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
441
442 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
443 adapter->rx_queue.index = 0;
444 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
445 }
446}
447
448static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
449{
Santiago Leonb6d35182005-10-26 10:47:01 -0600450 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700451 struct device *dev = &adapter->vdev->dev;
Santiago Leonb6d35182005-10-26 10:47:01 -0600452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if(adapter->buffer_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700454 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
455 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 DMA_BIDIRECTIONAL);
457 adapter->buffer_list_dma = DMA_ERROR_CODE;
458 }
459 free_page((unsigned long)adapter->buffer_list_addr);
460 adapter->buffer_list_addr = NULL;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if(adapter->filter_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700464 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
465 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 DMA_BIDIRECTIONAL);
467 adapter->filter_list_dma = DMA_ERROR_CODE;
468 }
469 free_page((unsigned long)adapter->filter_list_addr);
470 adapter->filter_list_addr = NULL;
471 }
472
473 if(adapter->rx_queue.queue_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700474 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
475 dma_unmap_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 adapter->rx_queue.queue_dma,
477 adapter->rx_queue.queue_len,
478 DMA_BIDIRECTIONAL);
479 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
480 }
481 kfree(adapter->rx_queue.queue_addr);
482 adapter->rx_queue.queue_addr = NULL;
483 }
484
Santiago Leonb6d35182005-10-26 10:47:01 -0600485 for(i = 0; i<IbmVethNumBufferPools; i++)
Santiago Leon860f2422006-04-25 11:19:59 -0500486 if (adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400487 ibmveth_free_buffer_pool(adapter,
Santiago Leon860f2422006-04-25 11:19:59 -0500488 &adapter->rx_buff_pool[i]);
Robert Jennings1096d632008-07-24 04:34:52 +1000489
490 if (adapter->bounce_buffer != NULL) {
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000491 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000492 dma_unmap_single(&adapter->vdev->dev,
493 adapter->bounce_buffer_dma,
494 adapter->netdev->mtu + IBMVETH_BUFF_OH,
495 DMA_BIDIRECTIONAL);
496 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
497 }
498 kfree(adapter->bounce_buffer);
499 adapter->bounce_buffer = NULL;
500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500503static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
504 union ibmveth_buf_desc rxq_desc, u64 mac_address)
505{
506 int rc, try_again = 1;
507
508 /* After a kexec the adapter will still be open, so our attempt to
509 * open it will fail. So if we get a failure we free the adapter and
510 * try again, but only once. */
511retry:
512 rc = h_register_logical_lan(adapter->vdev->unit_address,
513 adapter->buffer_list_dma, rxq_desc.desc,
514 adapter->filter_list_dma, mac_address);
515
516 if (rc != H_SUCCESS && try_again) {
517 do {
518 rc = h_free_logical_lan(adapter->vdev->unit_address);
519 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
520
521 try_again = 0;
522 goto retry;
523 }
524
525 return rc;
526}
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528static int ibmveth_open(struct net_device *netdev)
529{
Wang Chen4cf16532008-11-12 23:38:14 -0800530 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 u64 mac_address = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -0600532 int rxq_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned long lpar_rc;
534 int rc;
535 union ibmveth_buf_desc rxq_desc;
Santiago Leonb6d35182005-10-26 10:47:01 -0600536 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700537 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 ibmveth_debug_printk("open starting\n");
540
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700541 napi_enable(&adapter->napi);
542
Santiago Leonb6d35182005-10-26 10:47:01 -0600543 for(i = 0; i<IbmVethNumBufferPools; i++)
544 rxq_entries += adapter->rx_buff_pool[i].size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
547 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
550 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
551 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700552 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return -ENOMEM;
554 }
555
556 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
557 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
558
559 if(!adapter->rx_queue.queue_addr) {
560 ibmveth_error_printk("unable to allocate rx queue pages\n");
561 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700562 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 return -ENOMEM;
564 }
565
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700566 dev = &adapter->vdev->dev;
567
568 adapter->buffer_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700570 adapter->filter_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700572 adapter->rx_queue.queue_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 adapter->rx_queue.queue_addr,
574 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
575
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700576 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
577 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
578 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 ibmveth_error_printk("unable to map filter or buffer list pages\n");
580 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700581 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 return -ENOMEM;
583 }
584
585 adapter->rx_queue.index = 0;
586 adapter->rx_queue.num_slots = rxq_entries;
587 adapter->rx_queue.toggle = 1;
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
590 mac_address = mac_address >> 16;
591
Brian King79ef4a42007-08-17 09:16:56 -0500592 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
594
595 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
596 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
597 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
598
Santiago Leon4347ef12006-10-03 12:24:34 -0500599 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
600
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500601 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200603 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000605 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 -0700606 adapter->buffer_list_dma,
607 adapter->filter_list_dma,
608 rxq_desc.desc,
609 mac_address);
610 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700611 napi_disable(&adapter->napi);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400612 return -ENONET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
Santiago Leon860f2422006-04-25 11:19:59 -0500615 for(i = 0; i<IbmVethNumBufferPools; i++) {
616 if(!adapter->rx_buff_pool[i].active)
617 continue;
618 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
619 ibmveth_error_printk("unable to alloc pool\n");
620 adapter->rx_buff_pool[i].active = 0;
621 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700622 napi_disable(&adapter->napi);
Santiago Leon860f2422006-04-25 11:19:59 -0500623 return -ENOMEM ;
624 }
625 }
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -0800628 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
630 do {
631 rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200632 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700635 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return rc;
637 }
638
Robert Jennings1096d632008-07-24 04:34:52 +1000639 adapter->bounce_buffer =
640 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
641 if (!adapter->bounce_buffer) {
642 ibmveth_error_printk("unable to allocate bounce buffer\n");
643 ibmveth_cleanup(adapter);
644 napi_disable(&adapter->napi);
645 return -ENOMEM;
646 }
647 adapter->bounce_buffer_dma =
648 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
649 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700650 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000651 ibmveth_error_printk("unable to map bounce buffer\n");
652 ibmveth_cleanup(adapter);
653 napi_disable(&adapter->napi);
654 return -ENOMEM;
655 }
656
Santiago Leone2adbcb2005-10-26 10:47:08 -0600657 ibmveth_debug_printk("initial replenish cycle\n");
David Howells7d12e782006-10-05 14:55:46 +0100658 ibmveth_interrupt(netdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Santiago Leone2adbcb2005-10-26 10:47:08 -0600660 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 ibmveth_debug_printk("open complete\n");
663
664 return 0;
665}
666
667static int ibmveth_close(struct net_device *netdev)
668{
Wang Chen4cf16532008-11-12 23:38:14 -0800669 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 long lpar_rc;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 ibmveth_debug_printk("close starting\n");
673
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700674 napi_disable(&adapter->napi);
675
Santiago Leon860f2422006-04-25 11:19:59 -0500676 if (!adapter->pool_config)
677 netif_stop_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 free_irq(netdev->irq, netdev);
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 do {
682 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200683 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200685 if(lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
687 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
688 lpar_rc);
689 }
690
691 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
692
693 ibmveth_cleanup(adapter);
694
695 ibmveth_debug_printk("close complete\n");
696
697 return 0;
698}
699
700static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
701 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
702 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
703 cmd->speed = SPEED_1000;
704 cmd->duplex = DUPLEX_FULL;
705 cmd->port = PORT_FIBRE;
706 cmd->phy_address = 0;
707 cmd->transceiver = XCVR_INTERNAL;
708 cmd->autoneg = AUTONEG_ENABLE;
709 cmd->maxtxpkt = 0;
710 cmd->maxrxpkt = 1;
711 return 0;
712}
713
714static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
715 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
716 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
717}
718
719static u32 netdev_get_link(struct net_device *dev) {
720 return 1;
721}
722
Brian King5fc7e012007-08-17 09:16:31 -0500723static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data)
724{
Wang Chen4cf16532008-11-12 23:38:14 -0800725 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500726
727 if (data)
728 adapter->rx_csum = 1;
729 else {
730 /*
731 * Since the ibmveth firmware interface does not have the concept of
732 * separate tx/rx checksum offload enable, if rx checksum is disabled
733 * we also have to disable tx checksum offload. Once we disable rx
734 * checksum offload, we are no longer allowed to send tx buffers that
735 * are not properly checksummed.
736 */
737 adapter->rx_csum = 0;
738 dev->features &= ~NETIF_F_IP_CSUM;
739 }
740}
741
742static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data)
743{
Wang Chen4cf16532008-11-12 23:38:14 -0800744 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500745
746 if (data) {
747 dev->features |= NETIF_F_IP_CSUM;
748 adapter->rx_csum = 1;
749 } else
750 dev->features &= ~NETIF_F_IP_CSUM;
751}
752
753static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
754 void (*done) (struct net_device *, u32))
755{
Wang Chen4cf16532008-11-12 23:38:14 -0800756 struct ibmveth_adapter *adapter = netdev_priv(dev);
Stephen Rothwellff5bfc32009-01-06 10:47:44 -0800757 unsigned long set_attr, clr_attr, ret_attr;
Brian King5fc7e012007-08-17 09:16:31 -0500758 long ret;
759 int rc1 = 0, rc2 = 0;
760 int restart = 0;
761
762 if (netif_running(dev)) {
763 restart = 1;
764 adapter->pool_config = 1;
765 ibmveth_close(dev);
766 adapter->pool_config = 0;
767 }
768
Brian King79ef4a42007-08-17 09:16:56 -0500769 set_attr = 0;
770 clr_attr = 0;
Brian King5fc7e012007-08-17 09:16:31 -0500771
772 if (data)
Brian King79ef4a42007-08-17 09:16:56 -0500773 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500774 else
Brian King79ef4a42007-08-17 09:16:56 -0500775 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500776
Brian King79ef4a42007-08-17 09:16:56 -0500777 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500778
Brian King79ef4a42007-08-17 09:16:56 -0500779 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
780 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
781 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
782 ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr,
783 set_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500784
785 if (ret != H_SUCCESS) {
786 rc1 = -EIO;
787 ibmveth_error_printk("unable to change checksum offload settings."
788 " %d rc=%ld\n", data, ret);
789
790 ret = h_illan_attributes(adapter->vdev->unit_address,
Brian King79ef4a42007-08-17 09:16:56 -0500791 set_attr, clr_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500792 } else
793 done(dev, data);
794 } else {
795 rc1 = -EIO;
796 ibmveth_error_printk("unable to change checksum offload settings."
Brian King79ef4a42007-08-17 09:16:56 -0500797 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500798 }
799
800 if (restart)
801 rc2 = ibmveth_open(dev);
802
803 return rc1 ? rc1 : rc2;
804}
805
806static int ibmveth_set_rx_csum(struct net_device *dev, u32 data)
807{
Wang Chen4cf16532008-11-12 23:38:14 -0800808 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500809
810 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
811 return 0;
812
813 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
814}
815
816static int ibmveth_set_tx_csum(struct net_device *dev, u32 data)
817{
Wang Chen4cf16532008-11-12 23:38:14 -0800818 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500819 int rc = 0;
820
821 if (data && (dev->features & NETIF_F_IP_CSUM))
822 return 0;
823 if (!data && !(dev->features & NETIF_F_IP_CSUM))
824 return 0;
825
826 if (data && !adapter->rx_csum)
827 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags);
828 else
829 ibmveth_set_tx_csum_flags(dev, data);
830
831 return rc;
832}
833
834static u32 ibmveth_get_rx_csum(struct net_device *dev)
835{
Wang Chen4cf16532008-11-12 23:38:14 -0800836 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500837 return adapter->rx_csum;
838}
839
Brian Kingddbb4de2007-08-17 09:16:43 -0500840static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
841{
842 int i;
843
844 if (stringset != ETH_SS_STATS)
845 return;
846
847 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN)
848 memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN);
849}
850
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700851static int ibmveth_get_sset_count(struct net_device *dev, int sset)
Brian Kingddbb4de2007-08-17 09:16:43 -0500852{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700853 switch (sset) {
854 case ETH_SS_STATS:
855 return ARRAY_SIZE(ibmveth_stats);
856 default:
857 return -EOPNOTSUPP;
858 }
Brian Kingddbb4de2007-08-17 09:16:43 -0500859}
860
861static void ibmveth_get_ethtool_stats(struct net_device *dev,
862 struct ethtool_stats *stats, u64 *data)
863{
864 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800865 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian Kingddbb4de2007-08-17 09:16:43 -0500866
867 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++)
868 data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset);
869}
870
Jeff Garzik7282d492006-09-13 14:30:00 -0400871static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 .get_drvinfo = netdev_get_drvinfo,
873 .get_settings = netdev_get_settings,
874 .get_link = netdev_get_link,
Brian King5fc7e012007-08-17 09:16:31 -0500875 .set_tx_csum = ibmveth_set_tx_csum,
876 .get_rx_csum = ibmveth_get_rx_csum,
877 .set_rx_csum = ibmveth_set_rx_csum,
Brian Kingddbb4de2007-08-17 09:16:43 -0500878 .get_strings = ibmveth_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700879 .get_sset_count = ibmveth_get_sset_count,
Brian Kingddbb4de2007-08-17 09:16:43 -0500880 .get_ethtool_stats = ibmveth_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881};
882
883static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
884{
885 return -EOPNOTSUPP;
886}
887
888#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
889
Stephen Hemminger613573252009-08-31 19:50:58 +0000890static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
891 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
Wang Chen4cf16532008-11-12 23:38:14 -0800893 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Brian King3449a2a2007-08-17 09:16:49 -0500894 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 unsigned long lpar_rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 unsigned long correlator;
Santiago Leon60296d92005-10-26 10:47:16 -0600897 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 unsigned int retry_count;
Santiago Leon60296d92005-10-26 10:47:16 -0600899 unsigned int tx_dropped = 0;
900 unsigned int tx_bytes = 0;
901 unsigned int tx_packets = 0;
902 unsigned int tx_send_failed = 0;
903 unsigned int tx_map_failed = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000904 int used_bounce = 0;
905 unsigned long data_dma_addr;
Santiago Leon60296d92005-10-26 10:47:16 -0600906
Brian King79ef4a42007-08-17 09:16:56 -0500907 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Brian Kingf4ff2872007-09-15 13:36:07 -0700909 if (skb->ip_summed == CHECKSUM_PARTIAL &&
910 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) {
911 ibmveth_error_printk("tx: failed to checksum packet\n");
912 tx_dropped++;
913 goto out;
914 }
915
916 if (skb->ip_summed == CHECKSUM_PARTIAL) {
917 unsigned char *buf = skb_transport_header(skb) + skb->csum_offset;
918
Brian King79ef4a42007-08-17 09:16:56 -0500919 desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700920
921 /* Need to zero out the checksum */
922 buf[0] = 0;
923 buf[1] = 0;
924 }
925
Santiago Leon45e15bb2008-08-20 13:09:19 -0600926 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
927 skb->len, DMA_TO_DEVICE);
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000928 if (dma_mapping_error(&adapter->vdev->dev, data_dma_addr)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000929 if (!firmware_has_feature(FW_FEATURE_CMO))
930 ibmveth_error_printk("tx: unable to map xmit buffer\n");
931 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
932 skb->len);
933 desc.fields.address = adapter->bounce_buffer_dma;
Santiago Leon60296d92005-10-26 10:47:16 -0600934 tx_map_failed++;
Robert Jennings1096d632008-07-24 04:34:52 +1000935 used_bounce = 1;
Santiago Leon45e15bb2008-08-20 13:09:19 -0600936 wmb();
Robert Jennings1096d632008-07-24 04:34:52 +1000937 } else
938 desc.fields.address = data_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /* send the frame. Arbitrarily set retrycount to 1024 */
941 correlator = 0;
942 retry_count = 1024;
943 do {
944 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address,
Brian King3449a2a2007-08-17 09:16:49 -0500945 desc.desc, 0, 0, 0, 0, 0,
946 correlator, &correlator);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200947 } while ((lpar_rc == H_BUSY) && (retry_count--));
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400948
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200949 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
Brian King3449a2a2007-08-17 09:16:49 -0500951 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n",
Brian King79ef4a42007-08-17 09:16:56 -0500952 (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0,
953 skb->len, desc.fields.address);
Santiago Leon60296d92005-10-26 10:47:16 -0600954 tx_send_failed++;
955 tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 } else {
Santiago Leon60296d92005-10-26 10:47:16 -0600957 tx_packets++;
958 tx_bytes += skb->len;
Santiago Leon0abe7912005-10-26 10:46:53 -0600959 netdev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 }
961
Robert Jennings1096d632008-07-24 04:34:52 +1000962 if (!used_bounce)
963 dma_unmap_single(&adapter->vdev->dev, data_dma_addr,
964 skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Santiago Leon60296d92005-10-26 10:47:16 -0600966out: spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700967 netdev->stats.tx_dropped += tx_dropped;
968 netdev->stats.tx_bytes += tx_bytes;
969 netdev->stats.tx_packets += tx_packets;
Santiago Leon60296d92005-10-26 10:47:16 -0600970 adapter->tx_send_failed += tx_send_failed;
971 adapter->tx_map_failed += tx_map_failed;
972 spin_unlock_irqrestore(&adapter->stats_lock, flags);
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 dev_kfree_skb(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000975 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700978static int ibmveth_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700980 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
981 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 int frames_processed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 unsigned long lpar_rc;
984
985 restart_poll:
986 do {
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700987 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700989 if (!ibmveth_rxq_pending_buffer(adapter))
990 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700992 rmb();
993 if (!ibmveth_rxq_buffer_valid(adapter)) {
994 wmb(); /* suggested by larson1 */
995 adapter->rx_invalid_buffer++;
996 ibmveth_debug_printk("recycling invalid buffer\n");
997 ibmveth_rxq_recycle_buffer(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 } else {
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700999 int length = ibmveth_rxq_frame_length(adapter);
1000 int offset = ibmveth_rxq_frame_offset(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001001 int csum_good = ibmveth_rxq_csum_good(adapter);
1002
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001003 skb = ibmveth_rxq_get_buffer(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001004 if (csum_good)
1005 skb->ip_summed = CHECKSUM_UNNECESSARY;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001006
1007 ibmveth_rxq_harvest_buffer(adapter);
1008
1009 skb_reserve(skb, offset);
1010 skb_put(skb, length);
1011 skb->protocol = eth_type_trans(skb, netdev);
1012
1013 netif_receive_skb(skb); /* send it up */
1014
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001015 netdev->stats.rx_packets++;
1016 netdev->stats.rx_bytes += length;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001017 frames_processed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001019 } while (frames_processed < budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Santiago Leone2adbcb2005-10-26 10:47:08 -06001021 ibmveth_replenish_task(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001023 if (frames_processed < budget) {
1024 /* We think we are done - reenable interrupts,
1025 * then check once more to make sure we are done.
1026 */
1027 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1028 VIO_IRQ_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001030 ibmveth_assert(lpar_rc == H_SUCCESS);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001031
Ben Hutchings288379f2009-01-19 16:43:59 -08001032 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001033
1034 if (ibmveth_rxq_pending_buffer(adapter) &&
Ben Hutchings288379f2009-01-19 16:43:59 -08001035 napi_reschedule(napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001036 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1037 VIO_IRQ_DISABLE);
1038 goto restart_poll;
1039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
1041
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001042 return frames_processed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
David Howells7d12e782006-10-05 14:55:46 +01001045static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 struct net_device *netdev = dev_instance;
Wang Chen4cf16532008-11-12 23:38:14 -08001048 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 unsigned long lpar_rc;
1050
Ben Hutchings288379f2009-01-19 16:43:59 -08001051 if (napi_schedule_prep(&adapter->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001052 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1053 VIO_IRQ_DISABLE);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001054 ibmveth_assert(lpar_rc == H_SUCCESS);
Ben Hutchings288379f2009-01-19 16:43:59 -08001055 __napi_schedule(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057 return IRQ_HANDLED;
1058}
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060static void ibmveth_set_multicast_list(struct net_device *netdev)
1061{
Wang Chen4cf16532008-11-12 23:38:14 -08001062 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 unsigned long lpar_rc;
1064
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001065 if ((netdev->flags & IFF_PROMISC) ||
1066 (netdev_mc_count(netdev) > adapter->mcastFilterSize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1068 IbmVethMcastEnableRecv |
1069 IbmVethMcastDisableFiltering,
1070 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001071 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
1073 }
1074 } else {
1075 struct dev_mc_list *mclist = netdev->mc_list;
1076 int i;
1077 /* clear the filter table & disable filtering */
1078 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1079 IbmVethMcastEnableRecv |
1080 IbmVethMcastDisableFiltering |
1081 IbmVethMcastClearFilterTable,
1082 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001083 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
1085 }
1086 /* add the addresses to the filter table */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001087 for(i = 0; i < netdev_mc_count(netdev); ++i, mclist = mclist->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 // add the multicast address to the filter table
1089 unsigned long mcast_addr = 0;
1090 memcpy(((char *)&mcast_addr)+2, mclist->dmi_addr, 6);
1091 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1092 IbmVethMcastAddFilter,
1093 mcast_addr);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001094 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
1096 }
1097 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /* re-enable filtering */
1100 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1101 IbmVethMcastEnableFiltering,
1102 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001103 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
1105 }
1106 }
1107}
1108
1109static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1110{
Wang Chen4cf16532008-11-12 23:38:14 -08001111 struct ibmveth_adapter *adapter = netdev_priv(dev);
Robert Jennings1096d632008-07-24 04:34:52 +10001112 struct vio_dev *viodev = adapter->vdev;
Santiago Leon860f2422006-04-25 11:19:59 -05001113 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
Robert Jennings1096d632008-07-24 04:34:52 +10001114 int i;
Santiago Leonb6d35182005-10-26 10:47:01 -06001115
Santiago Leon860f2422006-04-25 11:19:59 -05001116 if (new_mtu < IBMVETH_MAX_MTU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 return -EINVAL;
Santiago Leonb6d35182005-10-26 10:47:01 -06001118
Brian Kingce6eea52007-06-08 14:05:17 -05001119 for (i = 0; i < IbmVethNumBufferPools; i++)
1120 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1121 break;
1122
1123 if (i == IbmVethNumBufferPools)
1124 return -EINVAL;
1125
Santiago Leonea866e62008-07-24 04:34:23 +10001126 /* Deactivate all the buffer pools so that the next loop can activate
1127 only the buffer pools necessary to hold the new MTU */
1128 for (i = 0; i < IbmVethNumBufferPools; i++)
1129 if (adapter->rx_buff_pool[i].active) {
1130 ibmveth_free_buffer_pool(adapter,
1131 &adapter->rx_buff_pool[i]);
1132 adapter->rx_buff_pool[i].active = 0;
Brian Kingce6eea52007-06-08 14:05:17 -05001133 }
1134
Santiago Leonea866e62008-07-24 04:34:23 +10001135 /* Look for an active buffer pool that can hold the new MTU */
1136 for(i = 0; i<IbmVethNumBufferPools; i++) {
1137 adapter->rx_buff_pool[i].active = 1;
1138
Santiago Leon860f2422006-04-25 11:19:59 -05001139 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
Santiago Leonea866e62008-07-24 04:34:23 +10001140 if (netif_running(adapter->netdev)) {
Brian Kingce6eea52007-06-08 14:05:17 -05001141 adapter->pool_config = 1;
1142 ibmveth_close(adapter->netdev);
1143 adapter->pool_config = 0;
1144 dev->mtu = new_mtu;
Robert Jennings1096d632008-07-24 04:34:52 +10001145 vio_cmo_set_dev_desired(viodev,
1146 ibmveth_get_desired_dma
1147 (viodev));
1148 return ibmveth_open(adapter->netdev);
1149 }
1150 dev->mtu = new_mtu;
1151 vio_cmo_set_dev_desired(viodev,
1152 ibmveth_get_desired_dma
1153 (viodev));
Santiago Leon860f2422006-04-25 11:19:59 -05001154 return 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001155 }
Santiago Leonb6d35182005-10-26 10:47:01 -06001156 }
Santiago Leon860f2422006-04-25 11:19:59 -05001157 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
Santiago Leon6b422372006-10-03 12:24:28 -05001160#ifdef CONFIG_NET_POLL_CONTROLLER
1161static void ibmveth_poll_controller(struct net_device *dev)
1162{
Wang Chen4cf16532008-11-12 23:38:14 -08001163 ibmveth_replenish_task(netdev_priv(dev));
Andrew Morton5f771132006-10-10 14:33:30 -07001164 ibmveth_interrupt(dev->irq, dev);
Santiago Leon6b422372006-10-03 12:24:28 -05001165}
1166#endif
1167
Robert Jennings1096d632008-07-24 04:34:52 +10001168/**
1169 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1170 *
1171 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1172 *
1173 * Return value:
1174 * Number of bytes of IO data the driver will need to perform well.
1175 */
1176static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1177{
1178 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1179 struct ibmveth_adapter *adapter;
1180 unsigned long ret;
1181 int i;
1182 int rxqentries = 1;
1183
1184 /* netdev inits at probe time along with the structures we need below*/
1185 if (netdev == NULL)
1186 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1187
1188 adapter = netdev_priv(netdev);
1189
1190 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1191 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1192
1193 for (i = 0; i < IbmVethNumBufferPools; i++) {
1194 /* add the size of the active receive buffers */
1195 if (adapter->rx_buff_pool[i].active)
1196 ret +=
1197 adapter->rx_buff_pool[i].size *
1198 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1199 buff_size);
1200 rxqentries += adapter->rx_buff_pool[i].size;
1201 }
1202 /* add the size of the receive queue entries */
1203 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1204
1205 return ret;
1206}
1207
Alexander Beregalove186d172009-04-15 12:52:39 +00001208static const struct net_device_ops ibmveth_netdev_ops = {
1209 .ndo_open = ibmveth_open,
1210 .ndo_stop = ibmveth_close,
1211 .ndo_start_xmit = ibmveth_start_xmit,
1212 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1213 .ndo_do_ioctl = ibmveth_ioctl,
1214 .ndo_change_mtu = ibmveth_change_mtu,
1215 .ndo_validate_addr = eth_validate_addr,
1216 .ndo_set_mac_address = eth_mac_addr,
1217#ifdef CONFIG_NET_POLL_CONTROLLER
1218 .ndo_poll_controller = ibmveth_poll_controller,
1219#endif
1220};
1221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1223{
Santiago Leonb6d35182005-10-26 10:47:01 -06001224 int rc, i;
Brian Kingf4ff2872007-09-15 13:36:07 -07001225 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 struct net_device *netdev;
Mariusz Kozlowski9dc83af2007-08-06 23:44:03 +02001227 struct ibmveth_adapter *adapter;
Stephen Rothwellff5bfc32009-01-06 10:47:44 -08001228 unsigned long set_attr, ret_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 unsigned char *mac_addr_p;
1231 unsigned int *mcastFilterSize_p;
1232
1233
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001234 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 dev->unit_address);
1236
Michael Ellerman493a6842007-04-17 13:12:55 +10001237 mac_addr_p = (unsigned char *) vio_get_attribute(dev,
1238 VETH_MAC_ADDR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 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 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001244
Michael Ellerman493a6842007-04-17 13:12:55 +10001245 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev,
1246 VETH_MCAST_FILTER_SIZE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 if(!mcastFilterSize_p) {
1248 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
1249 "VETH_MCAST_FILTER_SIZE attribute\n",
1250 __FILE__, __LINE__);
1251 return 0;
1252 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1255
1256 if(!netdev)
1257 return -ENOMEM;
1258
Wang Chen4cf16532008-11-12 23:38:14 -08001259 adapter = netdev_priv(netdev);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001260 dev_set_drvdata(&dev->dev, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 adapter->vdev = dev;
1263 adapter->netdev = netdev;
1264 adapter->mcastFilterSize= *mcastFilterSize_p;
Santiago Leon860f2422006-04-25 11:19:59 -05001265 adapter->pool_config = 0;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001266
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001267 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 /* Some older boxes running PHYP non-natively have an OF that
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001270 returns a 8-byte local-mac-address field (and the first
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 2 bytes have to be ignored) while newer boxes' OF return
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001272 a 6-byte field. Note that IEEE 1275 specifies that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 local-mac-address must be a 6-byte field.
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001274 The RPA doc specifies that the first byte must be 10b, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 we'll just look for it to solve this 8 vs. 6 byte field issue */
1276
1277 if ((*mac_addr_p & 0x3) != 0x02)
1278 mac_addr_p += 2;
1279
1280 adapter->mac_addr = 0;
1281 memcpy(&adapter->mac_addr, mac_addr_p, 6);
1282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 netdev->irq = dev->irq;
Alexander Beregalove186d172009-04-15 12:52:39 +00001284 netdev->netdev_ops = &ibmveth_netdev_ops;
1285 netdev->ethtool_ops = &netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 SET_NETDEV_DEV(netdev, &dev->dev);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001287 netdev->features |= NETIF_F_LLTX;
Santiago Leon60296d92005-10-26 10:47:16 -06001288 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Stephen Rothwelld44b5e02009-05-11 21:44:51 +00001290 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Santiago Leon860f2422006-04-25 11:19:59 -05001292 for(i = 0; i<IbmVethNumBufferPools; i++) {
1293 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001294 int error;
1295
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001296 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1297 pool_count[i], pool_size[i],
Santiago Leon860f2422006-04-25 11:19:59 -05001298 pool_active[i]);
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001299 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1300 &dev->dev.kobj, "pool%d", i);
1301 if (!error)
1302 kobject_uevent(kobj, KOBJ_ADD);
Santiago Leon860f2422006-04-25 11:19:59 -05001303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 adapter->buffer_list_dma = DMA_ERROR_CODE;
1308 adapter->filter_list_dma = DMA_ERROR_CODE;
1309 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 ibmveth_debug_printk("registering netdev...\n");
1312
Brian King79ef4a42007-08-17 09:16:56 -05001313 ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001314
Brian King79ef4a42007-08-17 09:16:56 -05001315 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;
Brian Kingf4ff2872007-09-15 13:36:07 -07001319
Brian King79ef4a42007-08-17 09:16:56 -05001320 ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001321
Brian King5fc7e012007-08-17 09:16:31 -05001322 if (ret == H_SUCCESS) {
1323 adapter->rx_csum = 1;
Brian Kingf4ff2872007-09-15 13:36:07 -07001324 netdev->features |= NETIF_F_IP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -05001325 } else
Brian King79ef4a42007-08-17 09:16:56 -05001326 ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001327 }
1328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 rc = register_netdev(netdev);
1330
1331 if(rc) {
1332 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1333 free_netdev(netdev);
1334 return rc;
1335 }
1336
1337 ibmveth_debug_printk("registered\n");
1338
1339 ibmveth_proc_register_adapter(adapter);
1340
1341 return 0;
1342}
1343
1344static int __devexit ibmveth_remove(struct vio_dev *dev)
1345{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001346 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Wang Chen4cf16532008-11-12 23:38:14 -08001347 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001348 int i;
1349
1350 for(i = 0; i<IbmVethNumBufferPools; i++)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001351 kobject_put(&adapter->rx_buff_pool[i].kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 unregister_netdev(netdev);
1354
1355 ibmveth_proc_unregister_adapter(adapter);
1356
1357 free_netdev(netdev);
Robert Jennings1096d632008-07-24 04:34:52 +10001358 dev_set_drvdata(&dev->dev, NULL);
1359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return 0;
1361}
1362
1363#ifdef CONFIG_PROC_FS
1364static void ibmveth_proc_register_driver(void)
1365{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001366 ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 if (ibmveth_proc_dir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369}
1370
1371static void ibmveth_proc_unregister_driver(void)
1372{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001373 remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374}
1375
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001376static int ibmveth_show(struct seq_file *seq, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
1378 struct ibmveth_adapter *adapter = seq->private;
Jiri Pirko3a6d54c2009-05-11 23:37:15 +00001379 char *current_mac = (char *) adapter->netdev->dev_addr;
1380 char *firmware_mac = (char *) &adapter->mac_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001383
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address);
Johannes Berge1749612008-10-27 15:59:26 -07001385 seq_printf(seq, "Current MAC: %pM\n", current_mac);
1386 seq_printf(seq, "Firmware MAC: %pM\n", firmware_mac);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001387
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 seq_printf(seq, "\nAdapter Statistics:\n");
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001389 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);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 return 0;
1398}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400static int ibmveth_proc_open(struct inode *inode, struct file *file)
1401{
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001402 return single_open(file, ibmveth_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001405static const struct file_operations ibmveth_proc_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .owner = THIS_MODULE,
1407 .open = ibmveth_proc_open,
1408 .read = seq_read,
1409 .llseek = seq_lseek,
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001410 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411};
1412
1413static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1414{
1415 struct proc_dir_entry *entry;
1416 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001417 char u_addr[10];
1418 sprintf(u_addr, "%x", adapter->vdev->unit_address);
Denis V. Luneva95609c2008-04-29 01:02:29 -07001419 entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir,
1420 &ibmveth_proc_fops, adapter);
1421 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 ibmveth_error_printk("Cannot create adapter proc entry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424 return;
1425}
1426
1427static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1428{
1429 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001430 char u_addr[10];
1431 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1432 remove_proc_entry(u_addr, ibmveth_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434}
1435
1436#else /* CONFIG_PROC_FS */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001437static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
1439}
1440
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001441static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
1443}
1444static void ibmveth_proc_register_driver(void)
1445{
1446}
1447
1448static void ibmveth_proc_unregister_driver(void)
1449{
1450}
1451#endif /* CONFIG_PROC_FS */
1452
Santiago Leon860f2422006-04-25 11:19:59 -05001453static struct attribute veth_active_attr;
1454static struct attribute veth_num_attr;
1455static struct attribute veth_size_attr;
1456
1457static ssize_t veth_pool_show(struct kobject * kobj,
1458 struct attribute * attr, char * buf)
1459{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001460 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001461 struct ibmveth_buff_pool,
1462 kobj);
1463
1464 if (attr == &veth_active_attr)
1465 return sprintf(buf, "%d\n", pool->active);
1466 else if (attr == &veth_num_attr)
1467 return sprintf(buf, "%d\n", pool->size);
1468 else if (attr == &veth_size_attr)
1469 return sprintf(buf, "%d\n", pool->buff_size);
1470 return 0;
1471}
1472
1473static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr,
1474const char * buf, size_t count)
1475{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001476 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001477 struct ibmveth_buff_pool,
1478 kobj);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001479 struct net_device *netdev = dev_get_drvdata(
1480 container_of(kobj->parent, struct device, kobj));
Wang Chen4cf16532008-11-12 23:38:14 -08001481 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001482 long value = simple_strtol(buf, NULL, 10);
1483 long rc;
1484
1485 if (attr == &veth_active_attr) {
1486 if (value && !pool->active) {
Brian King4aa9c932007-06-08 14:05:16 -05001487 if (netif_running(netdev)) {
1488 if(ibmveth_alloc_buffer_pool(pool)) {
1489 ibmveth_error_printk("unable to alloc pool\n");
1490 return -ENOMEM;
1491 }
1492 pool->active = 1;
1493 adapter->pool_config = 1;
1494 ibmveth_close(netdev);
1495 adapter->pool_config = 0;
1496 if ((rc = ibmveth_open(netdev)))
1497 return rc;
1498 } else
1499 pool->active = 1;
Santiago Leon860f2422006-04-25 11:19:59 -05001500 } else if (!value && pool->active) {
1501 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1502 int i;
1503 /* Make sure there is a buffer pool with buffers that
1504 can hold a packet of the size of the MTU */
Brian King76b9cfc2007-08-03 13:55:19 +10001505 for (i = 0; i < IbmVethNumBufferPools; i++) {
Santiago Leon860f2422006-04-25 11:19:59 -05001506 if (pool == &adapter->rx_buff_pool[i])
1507 continue;
1508 if (!adapter->rx_buff_pool[i].active)
1509 continue;
Brian King76b9cfc2007-08-03 13:55:19 +10001510 if (mtu <= adapter->rx_buff_pool[i].buff_size)
1511 break;
Santiago Leon860f2422006-04-25 11:19:59 -05001512 }
Brian King76b9cfc2007-08-03 13:55:19 +10001513
1514 if (i == IbmVethNumBufferPools) {
Santiago Leon860f2422006-04-25 11:19:59 -05001515 ibmveth_error_printk("no active pool >= MTU\n");
1516 return -EPERM;
1517 }
Brian King76b9cfc2007-08-03 13:55:19 +10001518
Brian King76b9cfc2007-08-03 13:55:19 +10001519 if (netif_running(netdev)) {
1520 adapter->pool_config = 1;
1521 ibmveth_close(netdev);
Santiago Leonea866e62008-07-24 04:34:23 +10001522 pool->active = 0;
Brian King76b9cfc2007-08-03 13:55:19 +10001523 adapter->pool_config = 0;
1524 if ((rc = ibmveth_open(netdev)))
1525 return rc;
1526 }
Santiago Leonea866e62008-07-24 04:34:23 +10001527 pool->active = 0;
Santiago Leon860f2422006-04-25 11:19:59 -05001528 }
1529 } else if (attr == &veth_num_attr) {
1530 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
1531 return -EINVAL;
1532 else {
Brian King4aa9c932007-06-08 14:05:16 -05001533 if (netif_running(netdev)) {
1534 adapter->pool_config = 1;
1535 ibmveth_close(netdev);
1536 adapter->pool_config = 0;
1537 pool->size = value;
1538 if ((rc = ibmveth_open(netdev)))
1539 return rc;
1540 } else
1541 pool->size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001542 }
1543 } else if (attr == &veth_size_attr) {
1544 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
1545 return -EINVAL;
1546 else {
Brian King4aa9c932007-06-08 14:05:16 -05001547 if (netif_running(netdev)) {
1548 adapter->pool_config = 1;
1549 ibmveth_close(netdev);
1550 adapter->pool_config = 0;
1551 pool->buff_size = value;
1552 if ((rc = ibmveth_open(netdev)))
1553 return rc;
1554 } else
1555 pool->buff_size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001556 }
1557 }
1558
1559 /* kick the interrupt handler to allocate/deallocate pools */
David Howells7d12e782006-10-05 14:55:46 +01001560 ibmveth_interrupt(netdev->irq, netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001561 return count;
1562}
1563
1564
1565#define ATTR(_name, _mode) \
1566 struct attribute veth_##_name##_attr = { \
Tejun Heo7b595752007-06-14 03:45:17 +09001567 .name = __stringify(_name), .mode = _mode, \
Santiago Leon860f2422006-04-25 11:19:59 -05001568 };
1569
1570static ATTR(active, 0644);
1571static ATTR(num, 0644);
1572static ATTR(size, 0644);
1573
1574static struct attribute * veth_pool_attrs[] = {
1575 &veth_active_attr,
1576 &veth_num_attr,
1577 &veth_size_attr,
1578 NULL,
1579};
1580
1581static struct sysfs_ops veth_pool_ops = {
1582 .show = veth_pool_show,
1583 .store = veth_pool_store,
1584};
1585
1586static struct kobj_type ktype_veth_pool = {
1587 .release = NULL,
1588 .sysfs_ops = &veth_pool_ops,
1589 .default_attrs = veth_pool_attrs,
1590};
1591
1592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1594 { "network", "IBM,l-lan"},
Stephen Rothwellfb120da2005-08-17 16:42:59 +10001595 { "", "" }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1598
1599static struct vio_driver ibmveth_driver = {
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001600 .id_table = ibmveth_device_table,
1601 .probe = ibmveth_probe,
1602 .remove = ibmveth_remove,
Robert Jennings1096d632008-07-24 04:34:52 +10001603 .get_desired_dma = ibmveth_get_desired_dma,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001604 .driver = {
1605 .name = ibmveth_driver_name,
Stephen Rothwell915124d2005-10-24 15:12:22 +10001606 .owner = THIS_MODULE,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608};
1609
1610static int __init ibmveth_module_init(void)
1611{
1612 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1613
1614 ibmveth_proc_register_driver();
1615
1616 return vio_register_driver(&ibmveth_driver);
1617}
1618
1619static void __exit ibmveth_module_exit(void)
1620{
1621 vio_unregister_driver(&ibmveth_driver);
1622 ibmveth_proc_unregister_driver();
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001623}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625module_init(ibmveth_module_init);
1626module_exit(ibmveth_module_exit);