blob: c236c8af33673482eb5a0a6b814df7bd84274b71 [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>
Brian Kinge7a3af52010-05-07 08:56:08 +000048#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/ethtool.h>
50#include <linux/proc_fs.h>
Brian Kingf4ff2872007-09-15 13:36:07 -070051#include <linux/in.h>
52#include <linux/ip.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090053#include <linux/slab.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020054#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/hvcall.h>
56#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <asm/vio.h>
Robert Jennings1096d632008-07-24 04:34:52 +100058#include <asm/iommu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <asm/uaccess.h>
Robert Jennings1096d632008-07-24 04:34:52 +100060#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/seq_file.h>
62
63#include "ibmveth.h"
64
Anton Blanchard6af37fa2005-11-11 14:02:04 +110065#undef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#define ibmveth_printk(fmt, args...) \
Olof Johanssonf98baff2006-04-12 15:22:29 -050068 printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#define ibmveth_error_printk(fmt, args...) \
71 printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
72
73#ifdef DEBUG
74#define ibmveth_debug_printk_no_adapter(fmt, args...) \
75 printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
76#define ibmveth_debug_printk(fmt, args...) \
77 printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
78#define ibmveth_assert(expr) \
79 if(!(expr)) { \
80 printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
81 BUG(); \
82 }
83#else
84#define ibmveth_debug_printk_no_adapter(fmt, args...)
85#define ibmveth_debug_printk(fmt, args...)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -040086#define ibmveth_assert(expr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif
88
89static int ibmveth_open(struct net_device *dev);
90static int ibmveth_close(struct net_device *dev);
91static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
Stephen Hemmingerbea33482007-10-03 16:41:36 -070092static int ibmveth_poll(struct napi_struct *napi, int budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void ibmveth_set_multicast_list(struct net_device *dev);
95static int ibmveth_change_mtu(struct net_device *dev, int new_mtu);
96static void ibmveth_proc_register_driver(void);
97static void ibmveth_proc_unregister_driver(void);
98static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
99static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
David Howells7d12e782006-10-05 14:55:46 +0100100static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
Michael Ellerman493a6842007-04-17 13:12:55 +1000101static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
Robert Jennings1096d632008-07-24 04:34:52 +1000102static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
Santiago Leon860f2422006-04-25 11:19:59 -0500103static struct kobj_type ktype_veth_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Robert Jennings1096d632008-07-24 04:34:52 +1000105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_PROC_FS
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200107#define IBMVETH_PROC_DIR "ibmveth"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static struct proc_dir_entry *ibmveth_proc_dir;
109#endif
110
111static const char ibmveth_driver_name[] = "ibmveth";
112static const char ibmveth_driver_string[] = "IBM i/pSeries Virtual Ethernet Driver";
113#define ibmveth_driver_version "1.03"
114
115MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>");
116MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver");
117MODULE_LICENSE("GPL");
118MODULE_VERSION(ibmveth_driver_version);
119
Santiago Leonc08cc3c2010-09-03 18:28:20 +0000120static unsigned int tx_copybreak __read_mostly = 128;
121module_param(tx_copybreak, uint, 0644);
122MODULE_PARM_DESC(tx_copybreak,
123 "Maximum size of packet that is copied to a new buffer on transmit");
124
Santiago Leon8d86c612010-09-03 18:28:25 +0000125static unsigned int rx_copybreak __read_mostly = 128;
126module_param(rx_copybreak, uint, 0644);
127MODULE_PARM_DESC(rx_copybreak,
128 "Maximum size of packet that is copied to a new buffer on receive");
129
Brian Kingddbb4de2007-08-17 09:16:43 -0500130struct ibmveth_stat {
131 char name[ETH_GSTRING_LEN];
132 int offset;
133};
134
135#define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
136#define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
137
138struct ibmveth_stat ibmveth_stats[] = {
139 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
140 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
141 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) },
142 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) },
143 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
144 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500145 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
146 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
147};
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/* simple methods of getting data from the current rxq entry */
Brian King79ef4a42007-08-17 09:16:56 -0500150static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
151{
152 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off;
153}
154
155static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
156{
157 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT;
158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
161{
Brian King79ef4a42007-08-17 09:16:56 -0500162 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
166{
Brian King79ef4a42007-08-17 09:16:56 -0500167 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
171{
Brian King79ef4a42007-08-17 09:16:56 -0500172 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
175static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
176{
177 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
178}
179
Brian Kingf4ff2872007-09-15 13:36:07 -0700180static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
181{
Brian King79ef4a42007-08-17 09:16:56 -0500182 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700183}
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* setup the initial settings for a buffer pool */
Santiago Leon860f2422006-04-25 11:19:59 -0500186static 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 -0700187{
188 pool->size = pool_size;
189 pool->index = pool_index;
190 pool->buff_size = buff_size;
Santiago Leonc033a6d2010-09-03 18:28:09 +0000191 pool->threshold = pool_size * 7 / 8;
Santiago Leon860f2422006-04-25 11:19:59 -0500192 pool->active = pool_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195/* allocate and setup an buffer pool - called during open */
196static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
197{
198 int i;
199
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400200 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if(!pool->free_map) {
203 return -1;
204 }
205
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400206 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if(!pool->dma_addr) {
208 kfree(pool->free_map);
209 pool->free_map = NULL;
210 return -1;
211 }
212
Julia Lawalla05abcb2010-05-13 10:06:01 +0000213 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 if(!pool->skbuff) {
216 kfree(pool->dma_addr);
217 pool->dma_addr = NULL;
218
219 kfree(pool->free_map);
220 pool->free_map = NULL;
221 return -1;
222 }
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
225
226 for(i = 0; i < pool->size; ++i) {
227 pool->free_map[i] = i;
228 }
229
230 atomic_set(&pool->available, 0);
231 pool->producer_index = 0;
232 pool->consumer_index = 0;
233
234 return 0;
235}
236
237/* replenish the buffers for a pool. note that we don't need to
238 * skb_reserve these since they are used for incoming...
239 */
240static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
241{
242 u32 i;
243 u32 count = pool->size - atomic_read(&pool->available);
244 u32 buffers_added = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000245 struct sk_buff *skb;
246 unsigned int free_index, index;
247 u64 correlator;
248 unsigned long lpar_rc;
249 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 mb();
252
253 for(i = 0; i < count; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
257
258 if(!skb) {
259 ibmveth_debug_printk("replenish: unable to allocate skb\n");
260 adapter->replenish_no_mem++;
261 break;
262 }
263
David Gibson047a66d2006-10-21 10:24:13 -0700264 free_index = pool->consumer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000265 pool->consumer_index++;
266 if (pool->consumer_index >= pool->size)
267 pool->consumer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 index = pool->free_map[free_index];
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
271 ibmveth_assert(pool->skbuff[index] == NULL);
272
273 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
274 pool->buff_size, DMA_FROM_DEVICE);
275
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000276 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000277 goto failure;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
280 pool->dma_addr[index] = dma_addr;
281 pool->skbuff[index] = skb;
282
283 correlator = ((u64)pool->index << 32) | index;
284 *(u64*)skb->data = correlator;
285
Brian King79ef4a42007-08-17 09:16:56 -0500286 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400287 desc.fields.address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400290
Robert Jennings1096d632008-07-24 04:34:52 +1000291 if (lpar_rc != H_SUCCESS)
292 goto failure;
293 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 buffers_added++;
295 adapter->replenish_add_buff_success++;
296 }
297 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 mb();
300 atomic_add(buffers_added, &(pool->available));
Robert Jennings1096d632008-07-24 04:34:52 +1000301 return;
302
303failure:
304 pool->free_map[free_index] = index;
305 pool->skbuff[index] = NULL;
306 if (pool->consumer_index == 0)
307 pool->consumer_index = pool->size - 1;
308 else
309 pool->consumer_index--;
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000310 if (!dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000311 dma_unmap_single(&adapter->vdev->dev,
312 pool->dma_addr[index], pool->buff_size,
313 DMA_FROM_DEVICE);
314 dev_kfree_skb_any(skb);
315 adapter->replenish_add_buff_failure++;
316
317 mb();
318 atomic_add(buffers_added, &(pool->available));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
Santiago Leone2adbcb2005-10-26 10:47:08 -0600321/* replenish routine */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400322static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Santiago Leonb6d35182005-10-26 10:47:01 -0600324 int i;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 adapter->replenish_task_cycles++;
327
Santiago Leonc033a6d2010-09-03 18:28:09 +0000328 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--) {
329 struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i];
330
331 if (pool->active &&
332 (atomic_read(&pool->available) < pool->threshold))
333 ibmveth_replenish_buffer_pool(adapter, pool);
334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
339/* empty and free ana buffer pool - also used to do cleanup in error paths */
340static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
341{
342 int i;
343
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400344 kfree(pool->free_map);
345 pool->free_map = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if(pool->skbuff && pool->dma_addr) {
348 for(i = 0; i < pool->size; ++i) {
349 struct sk_buff *skb = pool->skbuff[i];
350 if(skb) {
351 dma_unmap_single(&adapter->vdev->dev,
352 pool->dma_addr[i],
353 pool->buff_size,
354 DMA_FROM_DEVICE);
355 dev_kfree_skb_any(skb);
356 pool->skbuff[i] = NULL;
357 }
358 }
359 }
360
361 if(pool->dma_addr) {
362 kfree(pool->dma_addr);
363 pool->dma_addr = NULL;
364 }
365
366 if(pool->skbuff) {
367 kfree(pool->skbuff);
368 pool->skbuff = NULL;
369 }
370}
371
372/* remove a buffer from a pool */
373static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
374{
375 unsigned int pool = correlator >> 32;
376 unsigned int index = correlator & 0xffffffffUL;
377 unsigned int free_index;
378 struct sk_buff *skb;
379
380 ibmveth_assert(pool < IbmVethNumBufferPools);
381 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
382
383 skb = adapter->rx_buff_pool[pool].skbuff[index];
384
385 ibmveth_assert(skb != NULL);
386
387 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
388
389 dma_unmap_single(&adapter->vdev->dev,
390 adapter->rx_buff_pool[pool].dma_addr[index],
391 adapter->rx_buff_pool[pool].buff_size,
392 DMA_FROM_DEVICE);
393
David Gibson047a66d2006-10-21 10:24:13 -0700394 free_index = adapter->rx_buff_pool[pool].producer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000395 adapter->rx_buff_pool[pool].producer_index++;
396 if (adapter->rx_buff_pool[pool].producer_index >=
397 adapter->rx_buff_pool[pool].size)
398 adapter->rx_buff_pool[pool].producer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 adapter->rx_buff_pool[pool].free_map[free_index] = index;
400
401 mb();
402
403 atomic_dec(&(adapter->rx_buff_pool[pool].available));
404}
405
406/* get the current buffer on the rx queue */
407static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
408{
409 u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
410 unsigned int pool = correlator >> 32;
411 unsigned int index = correlator & 0xffffffffUL;
412
413 ibmveth_assert(pool < IbmVethNumBufferPools);
414 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
415
416 return adapter->rx_buff_pool[pool].skbuff[index];
417}
418
419/* recycle the current buffer on the rx queue */
420static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
421{
422 u32 q_index = adapter->rx_queue.index;
423 u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
424 unsigned int pool = correlator >> 32;
425 unsigned int index = correlator & 0xffffffffUL;
426 union ibmveth_buf_desc desc;
427 unsigned long lpar_rc;
428
429 ibmveth_assert(pool < IbmVethNumBufferPools);
430 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
431
Santiago Leonb6d35182005-10-26 10:47:01 -0600432 if(!adapter->rx_buff_pool[pool].active) {
433 ibmveth_rxq_harvest_buffer(adapter);
434 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
435 return;
436 }
437
Brian King79ef4a42007-08-17 09:16:56 -0500438 desc.fields.flags_len = IBMVETH_BUF_VALID |
439 adapter->rx_buff_pool[pool].buff_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
441
442 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400443
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200444 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
446 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
447 }
448
449 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
450 adapter->rx_queue.index = 0;
451 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
452 }
453}
454
Michael Ellerman493a6842007-04-17 13:12:55 +1000455static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
457 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
458
459 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
460 adapter->rx_queue.index = 0;
461 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
462 }
463}
464
465static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
466{
Santiago Leonb6d35182005-10-26 10:47:01 -0600467 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700468 struct device *dev = &adapter->vdev->dev;
Santiago Leonb6d35182005-10-26 10:47:01 -0600469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if(adapter->buffer_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700471 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
472 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 DMA_BIDIRECTIONAL);
474 adapter->buffer_list_dma = DMA_ERROR_CODE;
475 }
476 free_page((unsigned long)adapter->buffer_list_addr);
477 adapter->buffer_list_addr = NULL;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 if(adapter->filter_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700481 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
482 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 DMA_BIDIRECTIONAL);
484 adapter->filter_list_dma = DMA_ERROR_CODE;
485 }
486 free_page((unsigned long)adapter->filter_list_addr);
487 adapter->filter_list_addr = NULL;
488 }
489
490 if(adapter->rx_queue.queue_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700491 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
492 dma_unmap_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 adapter->rx_queue.queue_dma,
494 adapter->rx_queue.queue_len,
495 DMA_BIDIRECTIONAL);
496 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
497 }
498 kfree(adapter->rx_queue.queue_addr);
499 adapter->rx_queue.queue_addr = NULL;
500 }
501
Santiago Leonb6d35182005-10-26 10:47:01 -0600502 for(i = 0; i<IbmVethNumBufferPools; i++)
Santiago Leon860f2422006-04-25 11:19:59 -0500503 if (adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400504 ibmveth_free_buffer_pool(adapter,
Santiago Leon860f2422006-04-25 11:19:59 -0500505 &adapter->rx_buff_pool[i]);
Robert Jennings1096d632008-07-24 04:34:52 +1000506
507 if (adapter->bounce_buffer != NULL) {
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000508 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000509 dma_unmap_single(&adapter->vdev->dev,
510 adapter->bounce_buffer_dma,
511 adapter->netdev->mtu + IBMVETH_BUFF_OH,
512 DMA_BIDIRECTIONAL);
513 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
514 }
515 kfree(adapter->bounce_buffer);
516 adapter->bounce_buffer = NULL;
517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500520static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
521 union ibmveth_buf_desc rxq_desc, u64 mac_address)
522{
523 int rc, try_again = 1;
524
525 /* After a kexec the adapter will still be open, so our attempt to
526 * open it will fail. So if we get a failure we free the adapter and
527 * try again, but only once. */
528retry:
529 rc = h_register_logical_lan(adapter->vdev->unit_address,
530 adapter->buffer_list_dma, rxq_desc.desc,
531 adapter->filter_list_dma, mac_address);
532
533 if (rc != H_SUCCESS && try_again) {
534 do {
535 rc = h_free_logical_lan(adapter->vdev->unit_address);
536 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
537
538 try_again = 0;
539 goto retry;
540 }
541
542 return rc;
543}
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545static int ibmveth_open(struct net_device *netdev)
546{
Wang Chen4cf16532008-11-12 23:38:14 -0800547 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 u64 mac_address = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -0600549 int rxq_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 unsigned long lpar_rc;
551 int rc;
552 union ibmveth_buf_desc rxq_desc;
Santiago Leonb6d35182005-10-26 10:47:01 -0600553 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700554 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 ibmveth_debug_printk("open starting\n");
557
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700558 napi_enable(&adapter->napi);
559
Santiago Leonb6d35182005-10-26 10:47:01 -0600560 for(i = 0; i<IbmVethNumBufferPools; i++)
561 rxq_entries += adapter->rx_buff_pool[i].size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
564 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
567 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
568 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700569 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 return -ENOMEM;
571 }
572
573 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
574 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
575
576 if(!adapter->rx_queue.queue_addr) {
577 ibmveth_error_printk("unable to allocate rx queue pages\n");
578 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700579 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return -ENOMEM;
581 }
582
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700583 dev = &adapter->vdev->dev;
584
585 adapter->buffer_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700587 adapter->filter_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700589 adapter->rx_queue.queue_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 adapter->rx_queue.queue_addr,
591 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
592
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700593 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
594 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
595 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 ibmveth_error_printk("unable to map filter or buffer list pages\n");
597 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700598 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return -ENOMEM;
600 }
601
602 adapter->rx_queue.index = 0;
603 adapter->rx_queue.num_slots = rxq_entries;
604 adapter->rx_queue.toggle = 1;
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
607 mac_address = mac_address >> 16;
608
Brian King79ef4a42007-08-17 09:16:56 -0500609 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
611
612 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
613 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
614 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
615
Santiago Leon4347ef12006-10-03 12:24:34 -0500616 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
617
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500618 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200620 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000622 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 -0700623 adapter->buffer_list_dma,
624 adapter->filter_list_dma,
625 rxq_desc.desc,
626 mac_address);
627 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700628 napi_disable(&adapter->napi);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400629 return -ENONET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
Santiago Leon860f2422006-04-25 11:19:59 -0500632 for(i = 0; i<IbmVethNumBufferPools; i++) {
633 if(!adapter->rx_buff_pool[i].active)
634 continue;
635 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
636 ibmveth_error_printk("unable to alloc pool\n");
637 adapter->rx_buff_pool[i].active = 0;
638 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700639 napi_disable(&adapter->napi);
Santiago Leon860f2422006-04-25 11:19:59 -0500640 return -ENOMEM ;
641 }
642 }
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -0800645 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
647 do {
648 rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200649 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700652 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return rc;
654 }
655
Robert Jennings1096d632008-07-24 04:34:52 +1000656 adapter->bounce_buffer =
657 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
658 if (!adapter->bounce_buffer) {
659 ibmveth_error_printk("unable to allocate bounce buffer\n");
660 ibmveth_cleanup(adapter);
661 napi_disable(&adapter->napi);
662 return -ENOMEM;
663 }
664 adapter->bounce_buffer_dma =
665 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
666 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700667 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000668 ibmveth_error_printk("unable to map bounce buffer\n");
669 ibmveth_cleanup(adapter);
670 napi_disable(&adapter->napi);
671 return -ENOMEM;
672 }
673
Santiago Leone2adbcb2005-10-26 10:47:08 -0600674 ibmveth_debug_printk("initial replenish cycle\n");
David Howells7d12e782006-10-05 14:55:46 +0100675 ibmveth_interrupt(netdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Santiago Leone2adbcb2005-10-26 10:47:08 -0600677 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 ibmveth_debug_printk("open complete\n");
680
681 return 0;
682}
683
684static int ibmveth_close(struct net_device *netdev)
685{
Wang Chen4cf16532008-11-12 23:38:14 -0800686 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 long lpar_rc;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 ibmveth_debug_printk("close starting\n");
690
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700691 napi_disable(&adapter->napi);
692
Santiago Leon860f2422006-04-25 11:19:59 -0500693 if (!adapter->pool_config)
694 netif_stop_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Robert Jenningsee2e6112010-07-16 04:57:25 +0000696 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 do {
699 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200700 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200702 if(lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 {
704 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
705 lpar_rc);
706 }
707
Robert Jenningsee2e6112010-07-16 04:57:25 +0000708 free_irq(netdev->irq, netdev);
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
711
712 ibmveth_cleanup(adapter);
713
714 ibmveth_debug_printk("close complete\n");
715
716 return 0;
717}
718
719static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
720 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
721 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
722 cmd->speed = SPEED_1000;
723 cmd->duplex = DUPLEX_FULL;
724 cmd->port = PORT_FIBRE;
725 cmd->phy_address = 0;
726 cmd->transceiver = XCVR_INTERNAL;
727 cmd->autoneg = AUTONEG_ENABLE;
728 cmd->maxtxpkt = 0;
729 cmd->maxrxpkt = 1;
730 return 0;
731}
732
733static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
734 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
735 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
736}
737
738static u32 netdev_get_link(struct net_device *dev) {
739 return 1;
740}
741
Brian King5fc7e012007-08-17 09:16:31 -0500742static void ibmveth_set_rx_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 adapter->rx_csum = 1;
748 else {
749 /*
750 * Since the ibmveth firmware interface does not have the concept of
751 * separate tx/rx checksum offload enable, if rx checksum is disabled
752 * we also have to disable tx checksum offload. Once we disable rx
753 * checksum offload, we are no longer allowed to send tx buffers that
754 * are not properly checksummed.
755 */
756 adapter->rx_csum = 0;
757 dev->features &= ~NETIF_F_IP_CSUM;
758 }
759}
760
761static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data)
762{
Wang Chen4cf16532008-11-12 23:38:14 -0800763 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500764
765 if (data) {
766 dev->features |= NETIF_F_IP_CSUM;
767 adapter->rx_csum = 1;
768 } else
769 dev->features &= ~NETIF_F_IP_CSUM;
770}
771
772static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
773 void (*done) (struct net_device *, u32))
774{
Wang Chen4cf16532008-11-12 23:38:14 -0800775 struct ibmveth_adapter *adapter = netdev_priv(dev);
Stephen Rothwellff5bfc32009-01-06 10:47:44 -0800776 unsigned long set_attr, clr_attr, ret_attr;
Brian King5fc7e012007-08-17 09:16:31 -0500777 long ret;
778 int rc1 = 0, rc2 = 0;
779 int restart = 0;
780
781 if (netif_running(dev)) {
782 restart = 1;
783 adapter->pool_config = 1;
784 ibmveth_close(dev);
785 adapter->pool_config = 0;
786 }
787
Brian King79ef4a42007-08-17 09:16:56 -0500788 set_attr = 0;
789 clr_attr = 0;
Brian King5fc7e012007-08-17 09:16:31 -0500790
791 if (data)
Brian King79ef4a42007-08-17 09:16:56 -0500792 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500793 else
Brian King79ef4a42007-08-17 09:16:56 -0500794 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500795
Brian King79ef4a42007-08-17 09:16:56 -0500796 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500797
Brian King79ef4a42007-08-17 09:16:56 -0500798 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
799 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
800 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
801 ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr,
802 set_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500803
804 if (ret != H_SUCCESS) {
805 rc1 = -EIO;
806 ibmveth_error_printk("unable to change checksum offload settings."
807 " %d rc=%ld\n", data, ret);
808
809 ret = h_illan_attributes(adapter->vdev->unit_address,
Brian King79ef4a42007-08-17 09:16:56 -0500810 set_attr, clr_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500811 } else
812 done(dev, data);
813 } else {
814 rc1 = -EIO;
815 ibmveth_error_printk("unable to change checksum offload settings."
Brian King79ef4a42007-08-17 09:16:56 -0500816 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500817 }
818
819 if (restart)
820 rc2 = ibmveth_open(dev);
821
822 return rc1 ? rc1 : rc2;
823}
824
825static int ibmveth_set_rx_csum(struct net_device *dev, u32 data)
826{
Wang Chen4cf16532008-11-12 23:38:14 -0800827 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500828
829 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
830 return 0;
831
832 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
833}
834
835static int ibmveth_set_tx_csum(struct net_device *dev, u32 data)
836{
Wang Chen4cf16532008-11-12 23:38:14 -0800837 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500838 int rc = 0;
839
840 if (data && (dev->features & NETIF_F_IP_CSUM))
841 return 0;
842 if (!data && !(dev->features & NETIF_F_IP_CSUM))
843 return 0;
844
845 if (data && !adapter->rx_csum)
846 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags);
847 else
848 ibmveth_set_tx_csum_flags(dev, data);
849
850 return rc;
851}
852
853static u32 ibmveth_get_rx_csum(struct net_device *dev)
854{
Wang Chen4cf16532008-11-12 23:38:14 -0800855 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500856 return adapter->rx_csum;
857}
858
Brian Kingddbb4de2007-08-17 09:16:43 -0500859static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
860{
861 int i;
862
863 if (stringset != ETH_SS_STATS)
864 return;
865
866 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN)
867 memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN);
868}
869
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700870static int ibmveth_get_sset_count(struct net_device *dev, int sset)
Brian Kingddbb4de2007-08-17 09:16:43 -0500871{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700872 switch (sset) {
873 case ETH_SS_STATS:
874 return ARRAY_SIZE(ibmveth_stats);
875 default:
876 return -EOPNOTSUPP;
877 }
Brian Kingddbb4de2007-08-17 09:16:43 -0500878}
879
880static void ibmveth_get_ethtool_stats(struct net_device *dev,
881 struct ethtool_stats *stats, u64 *data)
882{
883 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800884 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian Kingddbb4de2007-08-17 09:16:43 -0500885
886 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++)
887 data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset);
888}
889
Jeff Garzik7282d492006-09-13 14:30:00 -0400890static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 .get_drvinfo = netdev_get_drvinfo,
892 .get_settings = netdev_get_settings,
893 .get_link = netdev_get_link,
Brian King5fc7e012007-08-17 09:16:31 -0500894 .set_tx_csum = ibmveth_set_tx_csum,
895 .get_rx_csum = ibmveth_get_rx_csum,
896 .set_rx_csum = ibmveth_set_rx_csum,
Brian Kingddbb4de2007-08-17 09:16:43 -0500897 .get_strings = ibmveth_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700898 .get_sset_count = ibmveth_get_sset_count,
Brian Kingddbb4de2007-08-17 09:16:43 -0500899 .get_ethtool_stats = ibmveth_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900};
901
902static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
903{
904 return -EOPNOTSUPP;
905}
906
907#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
908
Stephen Hemminger613573252009-08-31 19:50:58 +0000909static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
910 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Wang Chen4cf16532008-11-12 23:38:14 -0800912 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Brian King3449a2a2007-08-17 09:16:49 -0500913 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 unsigned long lpar_rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 unsigned long correlator;
916 unsigned int retry_count;
Santiago Leon60296d92005-10-26 10:47:16 -0600917 unsigned int tx_dropped = 0;
918 unsigned int tx_bytes = 0;
919 unsigned int tx_packets = 0;
920 unsigned int tx_send_failed = 0;
921 unsigned int tx_map_failed = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000922 int used_bounce = 0;
923 unsigned long data_dma_addr;
Santiago Leon60296d92005-10-26 10:47:16 -0600924
Brian King79ef4a42007-08-17 09:16:56 -0500925 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Brian Kingf4ff2872007-09-15 13:36:07 -0700927 if (skb->ip_summed == CHECKSUM_PARTIAL &&
928 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) {
929 ibmveth_error_printk("tx: failed to checksum packet\n");
930 tx_dropped++;
931 goto out;
932 }
933
934 if (skb->ip_summed == CHECKSUM_PARTIAL) {
935 unsigned char *buf = skb_transport_header(skb) + skb->csum_offset;
936
Brian King79ef4a42007-08-17 09:16:56 -0500937 desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700938
939 /* Need to zero out the checksum */
940 buf[0] = 0;
941 buf[1] = 0;
942 }
943
Santiago Leonc08cc3c2010-09-03 18:28:20 +0000944 if (skb->len < tx_copybreak) {
945 used_bounce = 1;
946 } else {
947 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
948 skb->len, DMA_TO_DEVICE);
949 if (dma_mapping_error(&adapter->vdev->dev, data_dma_addr)) {
950 if (!firmware_has_feature(FW_FEATURE_CMO))
951 ibmveth_error_printk("tx: unable to map "
952 "xmit buffer\n");
953 tx_map_failed++;
954 used_bounce = 1;
955 }
956 }
957
958 if (used_bounce) {
Robert Jennings1096d632008-07-24 04:34:52 +1000959 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
960 skb->len);
961 desc.fields.address = adapter->bounce_buffer_dma;
Robert Jennings1096d632008-07-24 04:34:52 +1000962 } else
963 desc.fields.address = data_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 /* send the frame. Arbitrarily set retrycount to 1024 */
966 correlator = 0;
967 retry_count = 1024;
968 do {
969 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address,
Brian King3449a2a2007-08-17 09:16:49 -0500970 desc.desc, 0, 0, 0, 0, 0,
971 correlator, &correlator);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200972 } while ((lpar_rc == H_BUSY) && (retry_count--));
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400973
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200974 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
Brian King3449a2a2007-08-17 09:16:49 -0500976 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n",
Brian King79ef4a42007-08-17 09:16:56 -0500977 (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0,
978 skb->len, desc.fields.address);
Santiago Leon60296d92005-10-26 10:47:16 -0600979 tx_send_failed++;
980 tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 } else {
Santiago Leon60296d92005-10-26 10:47:16 -0600982 tx_packets++;
983 tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 }
985
Robert Jennings1096d632008-07-24 04:34:52 +1000986 if (!used_bounce)
987 dma_unmap_single(&adapter->vdev->dev, data_dma_addr,
988 skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Santiago Leone8cb7eb2010-09-03 18:28:15 +0000990out:
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700991 netdev->stats.tx_dropped += tx_dropped;
992 netdev->stats.tx_bytes += tx_bytes;
993 netdev->stats.tx_packets += tx_packets;
Santiago Leon60296d92005-10-26 10:47:16 -0600994 adapter->tx_send_failed += tx_send_failed;
995 adapter->tx_map_failed += tx_map_failed;
Santiago Leon60296d92005-10-26 10:47:16 -0600996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 dev_kfree_skb(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000998 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001001static int ibmveth_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001003 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
1004 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 int frames_processed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 unsigned long lpar_rc;
1007
1008 restart_poll:
1009 do {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001010 if (!ibmveth_rxq_pending_buffer(adapter))
1011 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001013 rmb();
1014 if (!ibmveth_rxq_buffer_valid(adapter)) {
1015 wmb(); /* suggested by larson1 */
1016 adapter->rx_invalid_buffer++;
1017 ibmveth_debug_printk("recycling invalid buffer\n");
1018 ibmveth_rxq_recycle_buffer(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 } else {
Santiago Leon8d86c612010-09-03 18:28:25 +00001020 struct sk_buff *skb, *new_skb;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001021 int length = ibmveth_rxq_frame_length(adapter);
1022 int offset = ibmveth_rxq_frame_offset(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001023 int csum_good = ibmveth_rxq_csum_good(adapter);
1024
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001025 skb = ibmveth_rxq_get_buffer(adapter);
1026
Santiago Leon8d86c612010-09-03 18:28:25 +00001027 new_skb = NULL;
1028 if (length < rx_copybreak)
1029 new_skb = netdev_alloc_skb(netdev, length);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001030
Santiago Leon8d86c612010-09-03 18:28:25 +00001031 if (new_skb) {
1032 skb_copy_to_linear_data(new_skb,
1033 skb->data + offset,
1034 length);
1035 skb = new_skb;
1036 ibmveth_rxq_recycle_buffer(adapter);
1037 } else {
1038 ibmveth_rxq_harvest_buffer(adapter);
1039 skb_reserve(skb, offset);
1040 }
1041
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001042 skb_put(skb, length);
1043 skb->protocol = eth_type_trans(skb, netdev);
1044
Santiago Leon8d86c612010-09-03 18:28:25 +00001045 if (csum_good)
1046 skb->ip_summed = CHECKSUM_UNNECESSARY;
1047
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001048 netif_receive_skb(skb); /* send it up */
1049
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001050 netdev->stats.rx_packets++;
1051 netdev->stats.rx_bytes += length;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001052 frames_processed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001054 } while (frames_processed < budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Santiago Leone2adbcb2005-10-26 10:47:08 -06001056 ibmveth_replenish_task(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001058 if (frames_processed < budget) {
1059 /* We think we are done - reenable interrupts,
1060 * then check once more to make sure we are done.
1061 */
1062 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1063 VIO_IRQ_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001065 ibmveth_assert(lpar_rc == H_SUCCESS);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001066
Ben Hutchings288379f2009-01-19 16:43:59 -08001067 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001068
1069 if (ibmveth_rxq_pending_buffer(adapter) &&
Ben Hutchings288379f2009-01-19 16:43:59 -08001070 napi_reschedule(napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001071 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1072 VIO_IRQ_DISABLE);
1073 goto restart_poll;
1074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001077 return frames_processed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
David Howells7d12e782006-10-05 14:55:46 +01001080static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001081{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 struct net_device *netdev = dev_instance;
Wang Chen4cf16532008-11-12 23:38:14 -08001083 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 unsigned long lpar_rc;
1085
Ben Hutchings288379f2009-01-19 16:43:59 -08001086 if (napi_schedule_prep(&adapter->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001087 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1088 VIO_IRQ_DISABLE);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001089 ibmveth_assert(lpar_rc == H_SUCCESS);
Ben Hutchings288379f2009-01-19 16:43:59 -08001090 __napi_schedule(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092 return IRQ_HANDLED;
1093}
1094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095static void ibmveth_set_multicast_list(struct net_device *netdev)
1096{
Wang Chen4cf16532008-11-12 23:38:14 -08001097 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 unsigned long lpar_rc;
1099
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001100 if ((netdev->flags & IFF_PROMISC) ||
1101 (netdev_mc_count(netdev) > adapter->mcastFilterSize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1103 IbmVethMcastEnableRecv |
1104 IbmVethMcastDisableFiltering,
1105 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001106 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
1108 }
1109 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001110 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 /* clear the filter table & disable filtering */
1112 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1113 IbmVethMcastEnableRecv |
1114 IbmVethMcastDisableFiltering |
1115 IbmVethMcastClearFilterTable,
1116 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001117 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
1119 }
1120 /* add the addresses to the filter table */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001121 netdev_for_each_mc_addr(ha, netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 // add the multicast address to the filter table
1123 unsigned long mcast_addr = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001124 memcpy(((char *)&mcast_addr)+2, ha->addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1126 IbmVethMcastAddFilter,
1127 mcast_addr);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001128 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
1130 }
1131 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 /* re-enable filtering */
1134 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1135 IbmVethMcastEnableFiltering,
1136 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001137 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
1139 }
1140 }
1141}
1142
1143static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1144{
Wang Chen4cf16532008-11-12 23:38:14 -08001145 struct ibmveth_adapter *adapter = netdev_priv(dev);
Robert Jennings1096d632008-07-24 04:34:52 +10001146 struct vio_dev *viodev = adapter->vdev;
Santiago Leon860f2422006-04-25 11:19:59 -05001147 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
Robert Jennings0645bab2010-08-17 09:15:45 +00001148 int i, rc;
1149 int need_restart = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001150
Santiago Leon860f2422006-04-25 11:19:59 -05001151 if (new_mtu < IBMVETH_MAX_MTU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 return -EINVAL;
Santiago Leonb6d35182005-10-26 10:47:01 -06001153
Brian Kingce6eea52007-06-08 14:05:17 -05001154 for (i = 0; i < IbmVethNumBufferPools; i++)
1155 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1156 break;
1157
1158 if (i == IbmVethNumBufferPools)
1159 return -EINVAL;
1160
Santiago Leonea866e62008-07-24 04:34:23 +10001161 /* Deactivate all the buffer pools so that the next loop can activate
1162 only the buffer pools necessary to hold the new MTU */
Robert Jennings0645bab2010-08-17 09:15:45 +00001163 if (netif_running(adapter->netdev)) {
1164 need_restart = 1;
1165 adapter->pool_config = 1;
1166 ibmveth_close(adapter->netdev);
1167 adapter->pool_config = 0;
1168 }
Brian Kingce6eea52007-06-08 14:05:17 -05001169
Santiago Leonea866e62008-07-24 04:34:23 +10001170 /* Look for an active buffer pool that can hold the new MTU */
1171 for(i = 0; i<IbmVethNumBufferPools; i++) {
1172 adapter->rx_buff_pool[i].active = 1;
1173
Santiago Leon860f2422006-04-25 11:19:59 -05001174 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
Robert Jennings1096d632008-07-24 04:34:52 +10001175 dev->mtu = new_mtu;
1176 vio_cmo_set_dev_desired(viodev,
1177 ibmveth_get_desired_dma
1178 (viodev));
Robert Jennings0645bab2010-08-17 09:15:45 +00001179 if (need_restart) {
1180 return ibmveth_open(adapter->netdev);
1181 }
Santiago Leon860f2422006-04-25 11:19:59 -05001182 return 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001183 }
Santiago Leonb6d35182005-10-26 10:47:01 -06001184 }
Robert Jennings0645bab2010-08-17 09:15:45 +00001185
1186 if (need_restart && (rc = ibmveth_open(adapter->netdev)))
1187 return rc;
1188
Santiago Leon860f2422006-04-25 11:19:59 -05001189 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
Santiago Leon6b422372006-10-03 12:24:28 -05001192#ifdef CONFIG_NET_POLL_CONTROLLER
1193static void ibmveth_poll_controller(struct net_device *dev)
1194{
Wang Chen4cf16532008-11-12 23:38:14 -08001195 ibmveth_replenish_task(netdev_priv(dev));
Andrew Morton5f771132006-10-10 14:33:30 -07001196 ibmveth_interrupt(dev->irq, dev);
Santiago Leon6b422372006-10-03 12:24:28 -05001197}
1198#endif
1199
Robert Jennings1096d632008-07-24 04:34:52 +10001200/**
1201 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1202 *
1203 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1204 *
1205 * Return value:
1206 * Number of bytes of IO data the driver will need to perform well.
1207 */
1208static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1209{
1210 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1211 struct ibmveth_adapter *adapter;
1212 unsigned long ret;
1213 int i;
1214 int rxqentries = 1;
1215
1216 /* netdev inits at probe time along with the structures we need below*/
1217 if (netdev == NULL)
1218 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1219
1220 adapter = netdev_priv(netdev);
1221
1222 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1223 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1224
1225 for (i = 0; i < IbmVethNumBufferPools; i++) {
1226 /* add the size of the active receive buffers */
1227 if (adapter->rx_buff_pool[i].active)
1228 ret +=
1229 adapter->rx_buff_pool[i].size *
1230 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1231 buff_size);
1232 rxqentries += adapter->rx_buff_pool[i].size;
1233 }
1234 /* add the size of the receive queue entries */
1235 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1236
1237 return ret;
1238}
1239
Alexander Beregalove186d172009-04-15 12:52:39 +00001240static const struct net_device_ops ibmveth_netdev_ops = {
1241 .ndo_open = ibmveth_open,
1242 .ndo_stop = ibmveth_close,
1243 .ndo_start_xmit = ibmveth_start_xmit,
1244 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1245 .ndo_do_ioctl = ibmveth_ioctl,
1246 .ndo_change_mtu = ibmveth_change_mtu,
1247 .ndo_validate_addr = eth_validate_addr,
1248 .ndo_set_mac_address = eth_mac_addr,
1249#ifdef CONFIG_NET_POLL_CONTROLLER
1250 .ndo_poll_controller = ibmveth_poll_controller,
1251#endif
1252};
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1255{
Santiago Leonb6d35182005-10-26 10:47:01 -06001256 int rc, i;
Brian Kingf4ff2872007-09-15 13:36:07 -07001257 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 struct net_device *netdev;
Mariusz Kozlowski9dc83af2007-08-06 23:44:03 +02001259 struct ibmveth_adapter *adapter;
Stephen Rothwellff5bfc32009-01-06 10:47:44 -08001260 unsigned long set_attr, ret_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 unsigned char *mac_addr_p;
1263 unsigned int *mcastFilterSize_p;
1264
1265
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001266 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 dev->unit_address);
1268
Michael Ellerman493a6842007-04-17 13:12:55 +10001269 mac_addr_p = (unsigned char *) vio_get_attribute(dev,
1270 VETH_MAC_ADDR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if(!mac_addr_p) {
1272 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1273 "attribute\n", __FILE__, __LINE__);
1274 return 0;
1275 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001276
Michael Ellerman493a6842007-04-17 13:12:55 +10001277 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev,
1278 VETH_MCAST_FILTER_SIZE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if(!mcastFilterSize_p) {
1280 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
1281 "VETH_MCAST_FILTER_SIZE attribute\n",
1282 __FILE__, __LINE__);
1283 return 0;
1284 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001285
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1287
1288 if(!netdev)
1289 return -ENOMEM;
1290
Wang Chen4cf16532008-11-12 23:38:14 -08001291 adapter = netdev_priv(netdev);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001292 dev_set_drvdata(&dev->dev, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 adapter->vdev = dev;
1295 adapter->netdev = netdev;
1296 adapter->mcastFilterSize= *mcastFilterSize_p;
Santiago Leon860f2422006-04-25 11:19:59 -05001297 adapter->pool_config = 0;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001298
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001299 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 /* Some older boxes running PHYP non-natively have an OF that
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001302 returns a 8-byte local-mac-address field (and the first
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 2 bytes have to be ignored) while newer boxes' OF return
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001304 a 6-byte field. Note that IEEE 1275 specifies that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 local-mac-address must be a 6-byte field.
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001306 The RPA doc specifies that the first byte must be 10b, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 we'll just look for it to solve this 8 vs. 6 byte field issue */
1308
1309 if ((*mac_addr_p & 0x3) != 0x02)
1310 mac_addr_p += 2;
1311
1312 adapter->mac_addr = 0;
1313 memcpy(&adapter->mac_addr, mac_addr_p, 6);
1314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 netdev->irq = dev->irq;
Alexander Beregalove186d172009-04-15 12:52:39 +00001316 netdev->netdev_ops = &ibmveth_netdev_ops;
1317 netdev->ethtool_ops = &netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 SET_NETDEV_DEV(netdev, &dev->dev);
1319
Stephen Rothwelld44b5e02009-05-11 21:44:51 +00001320 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Santiago Leon860f2422006-04-25 11:19:59 -05001322 for(i = 0; i<IbmVethNumBufferPools; i++) {
1323 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001324 int error;
1325
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001326 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1327 pool_count[i], pool_size[i],
Santiago Leon860f2422006-04-25 11:19:59 -05001328 pool_active[i]);
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001329 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1330 &dev->dev.kobj, "pool%d", i);
1331 if (!error)
1332 kobject_uevent(kobj, KOBJ_ADD);
Santiago Leon860f2422006-04-25 11:19:59 -05001333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 adapter->buffer_list_dma = DMA_ERROR_CODE;
1338 adapter->filter_list_dma = DMA_ERROR_CODE;
1339 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 ibmveth_debug_printk("registering netdev...\n");
1342
Brian King79ef4a42007-08-17 09:16:56 -05001343 ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001344
Brian King79ef4a42007-08-17 09:16:56 -05001345 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
1346 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
1347 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
1348 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian Kingf4ff2872007-09-15 13:36:07 -07001349
Brian King79ef4a42007-08-17 09:16:56 -05001350 ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001351
Brian King5fc7e012007-08-17 09:16:31 -05001352 if (ret == H_SUCCESS) {
1353 adapter->rx_csum = 1;
Brian Kingf4ff2872007-09-15 13:36:07 -07001354 netdev->features |= NETIF_F_IP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -05001355 } else
Brian King79ef4a42007-08-17 09:16:56 -05001356 ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001357 }
1358
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 rc = register_netdev(netdev);
1360
1361 if(rc) {
1362 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1363 free_netdev(netdev);
1364 return rc;
1365 }
1366
1367 ibmveth_debug_printk("registered\n");
1368
1369 ibmveth_proc_register_adapter(adapter);
1370
1371 return 0;
1372}
1373
1374static int __devexit ibmveth_remove(struct vio_dev *dev)
1375{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001376 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Wang Chen4cf16532008-11-12 23:38:14 -08001377 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001378 int i;
1379
1380 for(i = 0; i<IbmVethNumBufferPools; i++)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001381 kobject_put(&adapter->rx_buff_pool[i].kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 unregister_netdev(netdev);
1384
1385 ibmveth_proc_unregister_adapter(adapter);
1386
1387 free_netdev(netdev);
Robert Jennings1096d632008-07-24 04:34:52 +10001388 dev_set_drvdata(&dev->dev, NULL);
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 return 0;
1391}
1392
1393#ifdef CONFIG_PROC_FS
1394static void ibmveth_proc_register_driver(void)
1395{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001396 ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (ibmveth_proc_dir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
1399}
1400
1401static void ibmveth_proc_unregister_driver(void)
1402{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001403 remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001406static int ibmveth_show(struct seq_file *seq, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
1408 struct ibmveth_adapter *adapter = seq->private;
Jiri Pirko3a6d54c2009-05-11 23:37:15 +00001409 char *current_mac = (char *) adapter->netdev->dev_addr;
1410 char *firmware_mac = (char *) &adapter->mac_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address);
Johannes Berge1749612008-10-27 15:59:26 -07001415 seq_printf(seq, "Current MAC: %pM\n", current_mac);
1416 seq_printf(seq, "Firmware MAC: %pM\n", firmware_mac);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 seq_printf(seq, "\nAdapter Statistics:\n");
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001419 seq_printf(seq, " TX: vio_map_single failres: %lld\n", adapter->tx_map_failed);
1420 seq_printf(seq, " send failures: %lld\n", adapter->tx_send_failed);
1421 seq_printf(seq, " RX: replenish task cycles: %lld\n", adapter->replenish_task_cycles);
1422 seq_printf(seq, " alloc_skb_failures: %lld\n", adapter->replenish_no_mem);
1423 seq_printf(seq, " add buffer failures: %lld\n", adapter->replenish_add_buff_failure);
1424 seq_printf(seq, " invalid buffers: %lld\n", adapter->rx_invalid_buffer);
1425 seq_printf(seq, " no buffers: %lld\n", adapter->rx_no_buffer);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 return 0;
1428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430static int ibmveth_proc_open(struct inode *inode, struct file *file)
1431{
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001432 return single_open(file, ibmveth_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433}
1434
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001435static const struct file_operations ibmveth_proc_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 .owner = THIS_MODULE,
1437 .open = ibmveth_proc_open,
1438 .read = seq_read,
1439 .llseek = seq_lseek,
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001440 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441};
1442
1443static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1444{
1445 struct proc_dir_entry *entry;
1446 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001447 char u_addr[10];
1448 sprintf(u_addr, "%x", adapter->vdev->unit_address);
Denis V. Luneva95609c2008-04-29 01:02:29 -07001449 entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir,
1450 &ibmveth_proc_fops, adapter);
1451 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 ibmveth_error_printk("Cannot create adapter proc entry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
1456static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1457{
1458 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001459 char u_addr[10];
1460 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1461 remove_proc_entry(u_addr, ibmveth_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
1463}
1464
1465#else /* CONFIG_PROC_FS */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001466static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
1468}
1469
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001470static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
1472}
1473static void ibmveth_proc_register_driver(void)
1474{
1475}
1476
1477static void ibmveth_proc_unregister_driver(void)
1478{
1479}
1480#endif /* CONFIG_PROC_FS */
1481
Santiago Leon860f2422006-04-25 11:19:59 -05001482static struct attribute veth_active_attr;
1483static struct attribute veth_num_attr;
1484static struct attribute veth_size_attr;
1485
1486static ssize_t veth_pool_show(struct kobject * kobj,
1487 struct attribute * attr, char * buf)
1488{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001489 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001490 struct ibmveth_buff_pool,
1491 kobj);
1492
1493 if (attr == &veth_active_attr)
1494 return sprintf(buf, "%d\n", pool->active);
1495 else if (attr == &veth_num_attr)
1496 return sprintf(buf, "%d\n", pool->size);
1497 else if (attr == &veth_size_attr)
1498 return sprintf(buf, "%d\n", pool->buff_size);
1499 return 0;
1500}
1501
1502static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr,
1503const char * buf, size_t count)
1504{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001505 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001506 struct ibmveth_buff_pool,
1507 kobj);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001508 struct net_device *netdev = dev_get_drvdata(
1509 container_of(kobj->parent, struct device, kobj));
Wang Chen4cf16532008-11-12 23:38:14 -08001510 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001511 long value = simple_strtol(buf, NULL, 10);
1512 long rc;
1513
1514 if (attr == &veth_active_attr) {
1515 if (value && !pool->active) {
Brian King4aa9c932007-06-08 14:05:16 -05001516 if (netif_running(netdev)) {
1517 if(ibmveth_alloc_buffer_pool(pool)) {
1518 ibmveth_error_printk("unable to alloc pool\n");
1519 return -ENOMEM;
1520 }
1521 pool->active = 1;
1522 adapter->pool_config = 1;
1523 ibmveth_close(netdev);
1524 adapter->pool_config = 0;
1525 if ((rc = ibmveth_open(netdev)))
1526 return rc;
1527 } else
1528 pool->active = 1;
Santiago Leon860f2422006-04-25 11:19:59 -05001529 } else if (!value && pool->active) {
1530 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1531 int i;
1532 /* Make sure there is a buffer pool with buffers that
1533 can hold a packet of the size of the MTU */
Brian King76b9cfc2007-08-03 13:55:19 +10001534 for (i = 0; i < IbmVethNumBufferPools; i++) {
Santiago Leon860f2422006-04-25 11:19:59 -05001535 if (pool == &adapter->rx_buff_pool[i])
1536 continue;
1537 if (!adapter->rx_buff_pool[i].active)
1538 continue;
Brian King76b9cfc2007-08-03 13:55:19 +10001539 if (mtu <= adapter->rx_buff_pool[i].buff_size)
1540 break;
Santiago Leon860f2422006-04-25 11:19:59 -05001541 }
Brian King76b9cfc2007-08-03 13:55:19 +10001542
1543 if (i == IbmVethNumBufferPools) {
Santiago Leon860f2422006-04-25 11:19:59 -05001544 ibmveth_error_printk("no active pool >= MTU\n");
1545 return -EPERM;
1546 }
Brian King76b9cfc2007-08-03 13:55:19 +10001547
Brian King76b9cfc2007-08-03 13:55:19 +10001548 if (netif_running(netdev)) {
1549 adapter->pool_config = 1;
1550 ibmveth_close(netdev);
Santiago Leonea866e62008-07-24 04:34:23 +10001551 pool->active = 0;
Brian King76b9cfc2007-08-03 13:55:19 +10001552 adapter->pool_config = 0;
1553 if ((rc = ibmveth_open(netdev)))
1554 return rc;
1555 }
Santiago Leonea866e62008-07-24 04:34:23 +10001556 pool->active = 0;
Santiago Leon860f2422006-04-25 11:19:59 -05001557 }
1558 } else if (attr == &veth_num_attr) {
1559 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
1560 return -EINVAL;
1561 else {
Brian King4aa9c932007-06-08 14:05:16 -05001562 if (netif_running(netdev)) {
1563 adapter->pool_config = 1;
1564 ibmveth_close(netdev);
1565 adapter->pool_config = 0;
1566 pool->size = value;
1567 if ((rc = ibmveth_open(netdev)))
1568 return rc;
1569 } else
1570 pool->size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001571 }
1572 } else if (attr == &veth_size_attr) {
1573 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
1574 return -EINVAL;
1575 else {
Brian King4aa9c932007-06-08 14:05:16 -05001576 if (netif_running(netdev)) {
1577 adapter->pool_config = 1;
1578 ibmveth_close(netdev);
1579 adapter->pool_config = 0;
1580 pool->buff_size = value;
1581 if ((rc = ibmveth_open(netdev)))
1582 return rc;
1583 } else
1584 pool->buff_size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001585 }
1586 }
1587
1588 /* kick the interrupt handler to allocate/deallocate pools */
David Howells7d12e782006-10-05 14:55:46 +01001589 ibmveth_interrupt(netdev->irq, netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001590 return count;
1591}
1592
1593
1594#define ATTR(_name, _mode) \
1595 struct attribute veth_##_name##_attr = { \
Tejun Heo7b595752007-06-14 03:45:17 +09001596 .name = __stringify(_name), .mode = _mode, \
Santiago Leon860f2422006-04-25 11:19:59 -05001597 };
1598
1599static ATTR(active, 0644);
1600static ATTR(num, 0644);
1601static ATTR(size, 0644);
1602
1603static struct attribute * veth_pool_attrs[] = {
1604 &veth_active_attr,
1605 &veth_num_attr,
1606 &veth_size_attr,
1607 NULL,
1608};
1609
Emese Revfy52cf25d2010-01-19 02:58:23 +01001610static const struct sysfs_ops veth_pool_ops = {
Santiago Leon860f2422006-04-25 11:19:59 -05001611 .show = veth_pool_show,
1612 .store = veth_pool_store,
1613};
1614
1615static struct kobj_type ktype_veth_pool = {
1616 .release = NULL,
1617 .sysfs_ops = &veth_pool_ops,
1618 .default_attrs = veth_pool_attrs,
1619};
1620
Brian Kinge7a3af52010-05-07 08:56:08 +00001621static int ibmveth_resume(struct device *dev)
1622{
1623 struct net_device *netdev = dev_get_drvdata(dev);
1624 ibmveth_interrupt(netdev->irq, netdev);
1625 return 0;
1626}
Santiago Leon860f2422006-04-25 11:19:59 -05001627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1629 { "network", "IBM,l-lan"},
Stephen Rothwellfb120da2005-08-17 16:42:59 +10001630 { "", "" }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1633
Brian Kinge7a3af52010-05-07 08:56:08 +00001634static struct dev_pm_ops ibmveth_pm_ops = {
1635 .resume = ibmveth_resume
1636};
1637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638static struct vio_driver ibmveth_driver = {
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001639 .id_table = ibmveth_device_table,
1640 .probe = ibmveth_probe,
1641 .remove = ibmveth_remove,
Robert Jennings1096d632008-07-24 04:34:52 +10001642 .get_desired_dma = ibmveth_get_desired_dma,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001643 .driver = {
1644 .name = ibmveth_driver_name,
Stephen Rothwell915124d2005-10-24 15:12:22 +10001645 .owner = THIS_MODULE,
Brian Kinge7a3af52010-05-07 08:56:08 +00001646 .pm = &ibmveth_pm_ops,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648};
1649
1650static int __init ibmveth_module_init(void)
1651{
1652 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1653
1654 ibmveth_proc_register_driver();
1655
1656 return vio_register_driver(&ibmveth_driver);
1657}
1658
1659static void __exit ibmveth_module_exit(void)
1660{
1661 vio_unregister_driver(&ibmveth_driver);
1662 ibmveth_proc_unregister_driver();
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001663}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665module_init(ibmveth_module_init);
1666module_exit(ibmveth_module_exit);