blob: 3515ef318eb01b393bd2356ee273bf8e98b40a0a [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
Brian Kingddbb4de2007-08-17 09:16:43 -0500120struct ibmveth_stat {
121 char name[ETH_GSTRING_LEN];
122 int offset;
123};
124
125#define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
126#define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
127
128struct ibmveth_stat ibmveth_stats[] = {
129 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
130 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
131 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) },
132 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) },
133 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
134 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500135 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
136 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
137};
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* simple methods of getting data from the current rxq entry */
Brian King79ef4a42007-08-17 09:16:56 -0500140static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
141{
142 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off;
143}
144
145static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
146{
147 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT;
148}
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
151{
Brian King79ef4a42007-08-17 09:16:56 -0500152 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
155static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
156{
Brian King79ef4a42007-08-17 09:16:56 -0500157 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
161{
Brian King79ef4a42007-08-17 09:16:56 -0500162 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
166{
167 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
168}
169
Brian Kingf4ff2872007-09-15 13:36:07 -0700170static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
171{
Brian King79ef4a42007-08-17 09:16:56 -0500172 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700173}
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/* setup the initial settings for a buffer pool */
Santiago Leon860f2422006-04-25 11:19:59 -0500176static 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 -0700177{
178 pool->size = pool_size;
179 pool->index = pool_index;
180 pool->buff_size = buff_size;
Santiago Leonc033a6d2010-09-03 18:28:09 +0000181 pool->threshold = pool_size * 7 / 8;
Santiago Leon860f2422006-04-25 11:19:59 -0500182 pool->active = pool_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
185/* allocate and setup an buffer pool - called during open */
186static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
187{
188 int i;
189
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400190 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 if(!pool->free_map) {
193 return -1;
194 }
195
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400196 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if(!pool->dma_addr) {
198 kfree(pool->free_map);
199 pool->free_map = NULL;
200 return -1;
201 }
202
Julia Lawalla05abcb2010-05-13 10:06:01 +0000203 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 if(!pool->skbuff) {
206 kfree(pool->dma_addr);
207 pool->dma_addr = NULL;
208
209 kfree(pool->free_map);
210 pool->free_map = NULL;
211 return -1;
212 }
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
215
216 for(i = 0; i < pool->size; ++i) {
217 pool->free_map[i] = i;
218 }
219
220 atomic_set(&pool->available, 0);
221 pool->producer_index = 0;
222 pool->consumer_index = 0;
223
224 return 0;
225}
226
227/* replenish the buffers for a pool. note that we don't need to
228 * skb_reserve these since they are used for incoming...
229 */
230static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
231{
232 u32 i;
233 u32 count = pool->size - atomic_read(&pool->available);
234 u32 buffers_added = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000235 struct sk_buff *skb;
236 unsigned int free_index, index;
237 u64 correlator;
238 unsigned long lpar_rc;
239 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 mb();
242
243 for(i = 0; i < count; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
247
248 if(!skb) {
249 ibmveth_debug_printk("replenish: unable to allocate skb\n");
250 adapter->replenish_no_mem++;
251 break;
252 }
253
David Gibson047a66d2006-10-21 10:24:13 -0700254 free_index = pool->consumer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000255 pool->consumer_index++;
256 if (pool->consumer_index >= pool->size)
257 pool->consumer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 index = pool->free_map[free_index];
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
261 ibmveth_assert(pool->skbuff[index] == NULL);
262
263 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
264 pool->buff_size, DMA_FROM_DEVICE);
265
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000266 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000267 goto failure;
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
270 pool->dma_addr[index] = dma_addr;
271 pool->skbuff[index] = skb;
272
273 correlator = ((u64)pool->index << 32) | index;
274 *(u64*)skb->data = correlator;
275
Brian King79ef4a42007-08-17 09:16:56 -0500276 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400277 desc.fields.address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400280
Robert Jennings1096d632008-07-24 04:34:52 +1000281 if (lpar_rc != H_SUCCESS)
282 goto failure;
283 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 buffers_added++;
285 adapter->replenish_add_buff_success++;
286 }
287 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 mb();
290 atomic_add(buffers_added, &(pool->available));
Robert Jennings1096d632008-07-24 04:34:52 +1000291 return;
292
293failure:
294 pool->free_map[free_index] = index;
295 pool->skbuff[index] = NULL;
296 if (pool->consumer_index == 0)
297 pool->consumer_index = pool->size - 1;
298 else
299 pool->consumer_index--;
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000300 if (!dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000301 dma_unmap_single(&adapter->vdev->dev,
302 pool->dma_addr[index], pool->buff_size,
303 DMA_FROM_DEVICE);
304 dev_kfree_skb_any(skb);
305 adapter->replenish_add_buff_failure++;
306
307 mb();
308 atomic_add(buffers_added, &(pool->available));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Santiago Leone2adbcb2005-10-26 10:47:08 -0600311/* replenish routine */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400312static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Santiago Leonb6d35182005-10-26 10:47:01 -0600314 int i;
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 adapter->replenish_task_cycles++;
317
Santiago Leonc033a6d2010-09-03 18:28:09 +0000318 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--) {
319 struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i];
320
321 if (pool->active &&
322 (atomic_read(&pool->available) < pool->threshold))
323 ibmveth_replenish_buffer_pool(adapter, pool);
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
329/* empty and free ana buffer pool - also used to do cleanup in error paths */
330static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
331{
332 int i;
333
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400334 kfree(pool->free_map);
335 pool->free_map = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if(pool->skbuff && pool->dma_addr) {
338 for(i = 0; i < pool->size; ++i) {
339 struct sk_buff *skb = pool->skbuff[i];
340 if(skb) {
341 dma_unmap_single(&adapter->vdev->dev,
342 pool->dma_addr[i],
343 pool->buff_size,
344 DMA_FROM_DEVICE);
345 dev_kfree_skb_any(skb);
346 pool->skbuff[i] = NULL;
347 }
348 }
349 }
350
351 if(pool->dma_addr) {
352 kfree(pool->dma_addr);
353 pool->dma_addr = NULL;
354 }
355
356 if(pool->skbuff) {
357 kfree(pool->skbuff);
358 pool->skbuff = NULL;
359 }
360}
361
362/* remove a buffer from a pool */
363static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
364{
365 unsigned int pool = correlator >> 32;
366 unsigned int index = correlator & 0xffffffffUL;
367 unsigned int free_index;
368 struct sk_buff *skb;
369
370 ibmveth_assert(pool < IbmVethNumBufferPools);
371 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
372
373 skb = adapter->rx_buff_pool[pool].skbuff[index];
374
375 ibmveth_assert(skb != NULL);
376
377 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
378
379 dma_unmap_single(&adapter->vdev->dev,
380 adapter->rx_buff_pool[pool].dma_addr[index],
381 adapter->rx_buff_pool[pool].buff_size,
382 DMA_FROM_DEVICE);
383
David Gibson047a66d2006-10-21 10:24:13 -0700384 free_index = adapter->rx_buff_pool[pool].producer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000385 adapter->rx_buff_pool[pool].producer_index++;
386 if (adapter->rx_buff_pool[pool].producer_index >=
387 adapter->rx_buff_pool[pool].size)
388 adapter->rx_buff_pool[pool].producer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 adapter->rx_buff_pool[pool].free_map[free_index] = index;
390
391 mb();
392
393 atomic_dec(&(adapter->rx_buff_pool[pool].available));
394}
395
396/* get the current buffer on the rx queue */
397static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
398{
399 u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
400 unsigned int pool = correlator >> 32;
401 unsigned int index = correlator & 0xffffffffUL;
402
403 ibmveth_assert(pool < IbmVethNumBufferPools);
404 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
405
406 return adapter->rx_buff_pool[pool].skbuff[index];
407}
408
409/* recycle the current buffer on the rx queue */
410static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
411{
412 u32 q_index = adapter->rx_queue.index;
413 u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
414 unsigned int pool = correlator >> 32;
415 unsigned int index = correlator & 0xffffffffUL;
416 union ibmveth_buf_desc desc;
417 unsigned long lpar_rc;
418
419 ibmveth_assert(pool < IbmVethNumBufferPools);
420 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
421
Santiago Leonb6d35182005-10-26 10:47:01 -0600422 if(!adapter->rx_buff_pool[pool].active) {
423 ibmveth_rxq_harvest_buffer(adapter);
424 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
425 return;
426 }
427
Brian King79ef4a42007-08-17 09:16:56 -0500428 desc.fields.flags_len = IBMVETH_BUF_VALID |
429 adapter->rx_buff_pool[pool].buff_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
431
432 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400433
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200434 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
436 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
437 }
438
439 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
440 adapter->rx_queue.index = 0;
441 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
442 }
443}
444
Michael Ellerman493a6842007-04-17 13:12:55 +1000445static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
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
455static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
456{
Santiago Leonb6d35182005-10-26 10:47:01 -0600457 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700458 struct device *dev = &adapter->vdev->dev;
Santiago Leonb6d35182005-10-26 10:47:01 -0600459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if(adapter->buffer_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700461 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
462 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 DMA_BIDIRECTIONAL);
464 adapter->buffer_list_dma = DMA_ERROR_CODE;
465 }
466 free_page((unsigned long)adapter->buffer_list_addr);
467 adapter->buffer_list_addr = NULL;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 if(adapter->filter_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700471 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
472 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 DMA_BIDIRECTIONAL);
474 adapter->filter_list_dma = DMA_ERROR_CODE;
475 }
476 free_page((unsigned long)adapter->filter_list_addr);
477 adapter->filter_list_addr = NULL;
478 }
479
480 if(adapter->rx_queue.queue_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700481 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
482 dma_unmap_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 adapter->rx_queue.queue_dma,
484 adapter->rx_queue.queue_len,
485 DMA_BIDIRECTIONAL);
486 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
487 }
488 kfree(adapter->rx_queue.queue_addr);
489 adapter->rx_queue.queue_addr = NULL;
490 }
491
Santiago Leonb6d35182005-10-26 10:47:01 -0600492 for(i = 0; i<IbmVethNumBufferPools; i++)
Santiago Leon860f2422006-04-25 11:19:59 -0500493 if (adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400494 ibmveth_free_buffer_pool(adapter,
Santiago Leon860f2422006-04-25 11:19:59 -0500495 &adapter->rx_buff_pool[i]);
Robert Jennings1096d632008-07-24 04:34:52 +1000496
497 if (adapter->bounce_buffer != NULL) {
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000498 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000499 dma_unmap_single(&adapter->vdev->dev,
500 adapter->bounce_buffer_dma,
501 adapter->netdev->mtu + IBMVETH_BUFF_OH,
502 DMA_BIDIRECTIONAL);
503 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
504 }
505 kfree(adapter->bounce_buffer);
506 adapter->bounce_buffer = NULL;
507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500510static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
511 union ibmveth_buf_desc rxq_desc, u64 mac_address)
512{
513 int rc, try_again = 1;
514
515 /* After a kexec the adapter will still be open, so our attempt to
516 * open it will fail. So if we get a failure we free the adapter and
517 * try again, but only once. */
518retry:
519 rc = h_register_logical_lan(adapter->vdev->unit_address,
520 adapter->buffer_list_dma, rxq_desc.desc,
521 adapter->filter_list_dma, mac_address);
522
523 if (rc != H_SUCCESS && try_again) {
524 do {
525 rc = h_free_logical_lan(adapter->vdev->unit_address);
526 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
527
528 try_again = 0;
529 goto retry;
530 }
531
532 return rc;
533}
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535static int ibmveth_open(struct net_device *netdev)
536{
Wang Chen4cf16532008-11-12 23:38:14 -0800537 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 u64 mac_address = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -0600539 int rxq_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 unsigned long lpar_rc;
541 int rc;
542 union ibmveth_buf_desc rxq_desc;
Santiago Leonb6d35182005-10-26 10:47:01 -0600543 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700544 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 ibmveth_debug_printk("open starting\n");
547
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700548 napi_enable(&adapter->napi);
549
Santiago Leonb6d35182005-10-26 10:47:01 -0600550 for(i = 0; i<IbmVethNumBufferPools; i++)
551 rxq_entries += adapter->rx_buff_pool[i].size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
554 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
557 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
558 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700559 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return -ENOMEM;
561 }
562
563 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
564 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
565
566 if(!adapter->rx_queue.queue_addr) {
567 ibmveth_error_printk("unable to allocate rx queue 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
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700573 dev = &adapter->vdev->dev;
574
575 adapter->buffer_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700577 adapter->filter_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700579 adapter->rx_queue.queue_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 adapter->rx_queue.queue_addr,
581 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
582
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700583 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
584 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
585 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 ibmveth_error_printk("unable to map filter or buffer list pages\n");
587 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700588 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 return -ENOMEM;
590 }
591
592 adapter->rx_queue.index = 0;
593 adapter->rx_queue.num_slots = rxq_entries;
594 adapter->rx_queue.toggle = 1;
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
597 mac_address = mac_address >> 16;
598
Brian King79ef4a42007-08-17 09:16:56 -0500599 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
601
602 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
603 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
604 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
605
Santiago Leon4347ef12006-10-03 12:24:34 -0500606 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
607
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500608 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200610 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000612 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 -0700613 adapter->buffer_list_dma,
614 adapter->filter_list_dma,
615 rxq_desc.desc,
616 mac_address);
617 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700618 napi_disable(&adapter->napi);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400619 return -ENONET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
Santiago Leon860f2422006-04-25 11:19:59 -0500622 for(i = 0; i<IbmVethNumBufferPools; i++) {
623 if(!adapter->rx_buff_pool[i].active)
624 continue;
625 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
626 ibmveth_error_printk("unable to alloc pool\n");
627 adapter->rx_buff_pool[i].active = 0;
628 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700629 napi_disable(&adapter->napi);
Santiago Leon860f2422006-04-25 11:19:59 -0500630 return -ENOMEM ;
631 }
632 }
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -0800635 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
637 do {
638 rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200639 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700642 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return rc;
644 }
645
Robert Jennings1096d632008-07-24 04:34:52 +1000646 adapter->bounce_buffer =
647 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
648 if (!adapter->bounce_buffer) {
649 ibmveth_error_printk("unable to allocate bounce buffer\n");
650 ibmveth_cleanup(adapter);
651 napi_disable(&adapter->napi);
652 return -ENOMEM;
653 }
654 adapter->bounce_buffer_dma =
655 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
656 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700657 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000658 ibmveth_error_printk("unable to map bounce buffer\n");
659 ibmveth_cleanup(adapter);
660 napi_disable(&adapter->napi);
661 return -ENOMEM;
662 }
663
Santiago Leone2adbcb2005-10-26 10:47:08 -0600664 ibmveth_debug_printk("initial replenish cycle\n");
David Howells7d12e782006-10-05 14:55:46 +0100665 ibmveth_interrupt(netdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Santiago Leone2adbcb2005-10-26 10:47:08 -0600667 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 ibmveth_debug_printk("open complete\n");
670
671 return 0;
672}
673
674static int ibmveth_close(struct net_device *netdev)
675{
Wang Chen4cf16532008-11-12 23:38:14 -0800676 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 long lpar_rc;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 ibmveth_debug_printk("close starting\n");
680
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700681 napi_disable(&adapter->napi);
682
Santiago Leon860f2422006-04-25 11:19:59 -0500683 if (!adapter->pool_config)
684 netif_stop_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Robert Jenningsee2e6112010-07-16 04:57:25 +0000686 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 do {
689 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200690 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200692 if(lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 {
694 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
695 lpar_rc);
696 }
697
Robert Jenningsee2e6112010-07-16 04:57:25 +0000698 free_irq(netdev->irq, netdev);
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
701
702 ibmveth_cleanup(adapter);
703
704 ibmveth_debug_printk("close complete\n");
705
706 return 0;
707}
708
709static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
710 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
711 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
712 cmd->speed = SPEED_1000;
713 cmd->duplex = DUPLEX_FULL;
714 cmd->port = PORT_FIBRE;
715 cmd->phy_address = 0;
716 cmd->transceiver = XCVR_INTERNAL;
717 cmd->autoneg = AUTONEG_ENABLE;
718 cmd->maxtxpkt = 0;
719 cmd->maxrxpkt = 1;
720 return 0;
721}
722
723static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
724 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
725 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
726}
727
728static u32 netdev_get_link(struct net_device *dev) {
729 return 1;
730}
731
Brian King5fc7e012007-08-17 09:16:31 -0500732static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data)
733{
Wang Chen4cf16532008-11-12 23:38:14 -0800734 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500735
736 if (data)
737 adapter->rx_csum = 1;
738 else {
739 /*
740 * Since the ibmveth firmware interface does not have the concept of
741 * separate tx/rx checksum offload enable, if rx checksum is disabled
742 * we also have to disable tx checksum offload. Once we disable rx
743 * checksum offload, we are no longer allowed to send tx buffers that
744 * are not properly checksummed.
745 */
746 adapter->rx_csum = 0;
747 dev->features &= ~NETIF_F_IP_CSUM;
748 }
749}
750
751static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data)
752{
Wang Chen4cf16532008-11-12 23:38:14 -0800753 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500754
755 if (data) {
756 dev->features |= NETIF_F_IP_CSUM;
757 adapter->rx_csum = 1;
758 } else
759 dev->features &= ~NETIF_F_IP_CSUM;
760}
761
762static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
763 void (*done) (struct net_device *, u32))
764{
Wang Chen4cf16532008-11-12 23:38:14 -0800765 struct ibmveth_adapter *adapter = netdev_priv(dev);
Stephen Rothwellff5bfc32009-01-06 10:47:44 -0800766 unsigned long set_attr, clr_attr, ret_attr;
Brian King5fc7e012007-08-17 09:16:31 -0500767 long ret;
768 int rc1 = 0, rc2 = 0;
769 int restart = 0;
770
771 if (netif_running(dev)) {
772 restart = 1;
773 adapter->pool_config = 1;
774 ibmveth_close(dev);
775 adapter->pool_config = 0;
776 }
777
Brian King79ef4a42007-08-17 09:16:56 -0500778 set_attr = 0;
779 clr_attr = 0;
Brian King5fc7e012007-08-17 09:16:31 -0500780
781 if (data)
Brian King79ef4a42007-08-17 09:16:56 -0500782 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500783 else
Brian King79ef4a42007-08-17 09:16:56 -0500784 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500785
Brian King79ef4a42007-08-17 09:16:56 -0500786 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500787
Brian King79ef4a42007-08-17 09:16:56 -0500788 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
789 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
790 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
791 ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr,
792 set_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500793
794 if (ret != H_SUCCESS) {
795 rc1 = -EIO;
796 ibmveth_error_printk("unable to change checksum offload settings."
797 " %d rc=%ld\n", data, ret);
798
799 ret = h_illan_attributes(adapter->vdev->unit_address,
Brian King79ef4a42007-08-17 09:16:56 -0500800 set_attr, clr_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500801 } else
802 done(dev, data);
803 } else {
804 rc1 = -EIO;
805 ibmveth_error_printk("unable to change checksum offload settings."
Brian King79ef4a42007-08-17 09:16:56 -0500806 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500807 }
808
809 if (restart)
810 rc2 = ibmveth_open(dev);
811
812 return rc1 ? rc1 : rc2;
813}
814
815static int ibmveth_set_rx_csum(struct net_device *dev, u32 data)
816{
Wang Chen4cf16532008-11-12 23:38:14 -0800817 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500818
819 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
820 return 0;
821
822 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
823}
824
825static int ibmveth_set_tx_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 int rc = 0;
829
830 if (data && (dev->features & NETIF_F_IP_CSUM))
831 return 0;
832 if (!data && !(dev->features & NETIF_F_IP_CSUM))
833 return 0;
834
835 if (data && !adapter->rx_csum)
836 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags);
837 else
838 ibmveth_set_tx_csum_flags(dev, data);
839
840 return rc;
841}
842
843static u32 ibmveth_get_rx_csum(struct net_device *dev)
844{
Wang Chen4cf16532008-11-12 23:38:14 -0800845 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500846 return adapter->rx_csum;
847}
848
Brian Kingddbb4de2007-08-17 09:16:43 -0500849static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
850{
851 int i;
852
853 if (stringset != ETH_SS_STATS)
854 return;
855
856 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN)
857 memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN);
858}
859
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700860static int ibmveth_get_sset_count(struct net_device *dev, int sset)
Brian Kingddbb4de2007-08-17 09:16:43 -0500861{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700862 switch (sset) {
863 case ETH_SS_STATS:
864 return ARRAY_SIZE(ibmveth_stats);
865 default:
866 return -EOPNOTSUPP;
867 }
Brian Kingddbb4de2007-08-17 09:16:43 -0500868}
869
870static void ibmveth_get_ethtool_stats(struct net_device *dev,
871 struct ethtool_stats *stats, u64 *data)
872{
873 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800874 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian Kingddbb4de2007-08-17 09:16:43 -0500875
876 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++)
877 data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset);
878}
879
Jeff Garzik7282d492006-09-13 14:30:00 -0400880static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 .get_drvinfo = netdev_get_drvinfo,
882 .get_settings = netdev_get_settings,
883 .get_link = netdev_get_link,
Brian King5fc7e012007-08-17 09:16:31 -0500884 .set_tx_csum = ibmveth_set_tx_csum,
885 .get_rx_csum = ibmveth_get_rx_csum,
886 .set_rx_csum = ibmveth_set_rx_csum,
Brian Kingddbb4de2007-08-17 09:16:43 -0500887 .get_strings = ibmveth_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700888 .get_sset_count = ibmveth_get_sset_count,
Brian Kingddbb4de2007-08-17 09:16:43 -0500889 .get_ethtool_stats = ibmveth_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890};
891
892static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
893{
894 return -EOPNOTSUPP;
895}
896
897#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
898
Stephen Hemminger613573252009-08-31 19:50:58 +0000899static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
900 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Wang Chen4cf16532008-11-12 23:38:14 -0800902 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Brian King3449a2a2007-08-17 09:16:49 -0500903 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 unsigned long lpar_rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 unsigned long correlator;
Santiago Leon60296d92005-10-26 10:47:16 -0600906 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 unsigned int retry_count;
Santiago Leon60296d92005-10-26 10:47:16 -0600908 unsigned int tx_dropped = 0;
909 unsigned int tx_bytes = 0;
910 unsigned int tx_packets = 0;
911 unsigned int tx_send_failed = 0;
912 unsigned int tx_map_failed = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000913 int used_bounce = 0;
914 unsigned long data_dma_addr;
Santiago Leon60296d92005-10-26 10:47:16 -0600915
Brian King79ef4a42007-08-17 09:16:56 -0500916 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Brian Kingf4ff2872007-09-15 13:36:07 -0700918 if (skb->ip_summed == CHECKSUM_PARTIAL &&
919 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) {
920 ibmveth_error_printk("tx: failed to checksum packet\n");
921 tx_dropped++;
922 goto out;
923 }
924
925 if (skb->ip_summed == CHECKSUM_PARTIAL) {
926 unsigned char *buf = skb_transport_header(skb) + skb->csum_offset;
927
Brian King79ef4a42007-08-17 09:16:56 -0500928 desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700929
930 /* Need to zero out the checksum */
931 buf[0] = 0;
932 buf[1] = 0;
933 }
934
Santiago Leon45e15bb2008-08-20 13:09:19 -0600935 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
936 skb->len, DMA_TO_DEVICE);
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000937 if (dma_mapping_error(&adapter->vdev->dev, data_dma_addr)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000938 if (!firmware_has_feature(FW_FEATURE_CMO))
939 ibmveth_error_printk("tx: unable to map xmit buffer\n");
940 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
941 skb->len);
942 desc.fields.address = adapter->bounce_buffer_dma;
Santiago Leon60296d92005-10-26 10:47:16 -0600943 tx_map_failed++;
Robert Jennings1096d632008-07-24 04:34:52 +1000944 used_bounce = 1;
Santiago Leon45e15bb2008-08-20 13:09:19 -0600945 wmb();
Robert Jennings1096d632008-07-24 04:34:52 +1000946 } else
947 desc.fields.address = data_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 /* send the frame. Arbitrarily set retrycount to 1024 */
950 correlator = 0;
951 retry_count = 1024;
952 do {
953 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address,
Brian King3449a2a2007-08-17 09:16:49 -0500954 desc.desc, 0, 0, 0, 0, 0,
955 correlator, &correlator);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200956 } while ((lpar_rc == H_BUSY) && (retry_count--));
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400957
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200958 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
Brian King3449a2a2007-08-17 09:16:49 -0500960 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n",
Brian King79ef4a42007-08-17 09:16:56 -0500961 (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0,
962 skb->len, desc.fields.address);
Santiago Leon60296d92005-10-26 10:47:16 -0600963 tx_send_failed++;
964 tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 } else {
Santiago Leon60296d92005-10-26 10:47:16 -0600966 tx_packets++;
967 tx_bytes += skb->len;
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700968 netdev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 }
970
Robert Jennings1096d632008-07-24 04:34:52 +1000971 if (!used_bounce)
972 dma_unmap_single(&adapter->vdev->dev, data_dma_addr,
973 skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Santiago Leon60296d92005-10-26 10:47:16 -0600975out: spin_lock_irqsave(&adapter->stats_lock, flags);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700976 netdev->stats.tx_dropped += tx_dropped;
977 netdev->stats.tx_bytes += tx_bytes;
978 netdev->stats.tx_packets += tx_packets;
Santiago Leon60296d92005-10-26 10:47:16 -0600979 adapter->tx_send_failed += tx_send_failed;
980 adapter->tx_map_failed += tx_map_failed;
981 spin_unlock_irqrestore(&adapter->stats_lock, flags);
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 dev_kfree_skb(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000984 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700987static int ibmveth_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700989 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
990 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 int frames_processed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 unsigned long lpar_rc;
993
994 restart_poll:
995 do {
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700996 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700998 if (!ibmveth_rxq_pending_buffer(adapter))
999 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001001 rmb();
1002 if (!ibmveth_rxq_buffer_valid(adapter)) {
1003 wmb(); /* suggested by larson1 */
1004 adapter->rx_invalid_buffer++;
1005 ibmveth_debug_printk("recycling invalid buffer\n");
1006 ibmveth_rxq_recycle_buffer(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 } else {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001008 int length = ibmveth_rxq_frame_length(adapter);
1009 int offset = ibmveth_rxq_frame_offset(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001010 int csum_good = ibmveth_rxq_csum_good(adapter);
1011
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001012 skb = ibmveth_rxq_get_buffer(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001013 if (csum_good)
1014 skb->ip_summed = CHECKSUM_UNNECESSARY;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001015
1016 ibmveth_rxq_harvest_buffer(adapter);
1017
1018 skb_reserve(skb, offset);
1019 skb_put(skb, length);
1020 skb->protocol = eth_type_trans(skb, netdev);
1021
1022 netif_receive_skb(skb); /* send it up */
1023
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001024 netdev->stats.rx_packets++;
1025 netdev->stats.rx_bytes += length;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001026 frames_processed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001028 } while (frames_processed < budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Santiago Leone2adbcb2005-10-26 10:47:08 -06001030 ibmveth_replenish_task(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001032 if (frames_processed < budget) {
1033 /* We think we are done - reenable interrupts,
1034 * then check once more to make sure we are done.
1035 */
1036 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1037 VIO_IRQ_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001039 ibmveth_assert(lpar_rc == H_SUCCESS);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001040
Ben Hutchings288379f2009-01-19 16:43:59 -08001041 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001042
1043 if (ibmveth_rxq_pending_buffer(adapter) &&
Ben Hutchings288379f2009-01-19 16:43:59 -08001044 napi_reschedule(napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001045 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1046 VIO_IRQ_DISABLE);
1047 goto restart_poll;
1048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001051 return frames_processed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
David Howells7d12e782006-10-05 14:55:46 +01001054static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001055{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct net_device *netdev = dev_instance;
Wang Chen4cf16532008-11-12 23:38:14 -08001057 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 unsigned long lpar_rc;
1059
Ben Hutchings288379f2009-01-19 16:43:59 -08001060 if (napi_schedule_prep(&adapter->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001061 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1062 VIO_IRQ_DISABLE);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001063 ibmveth_assert(lpar_rc == H_SUCCESS);
Ben Hutchings288379f2009-01-19 16:43:59 -08001064 __napi_schedule(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 return IRQ_HANDLED;
1067}
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069static void ibmveth_set_multicast_list(struct net_device *netdev)
1070{
Wang Chen4cf16532008-11-12 23:38:14 -08001071 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 unsigned long lpar_rc;
1073
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001074 if ((netdev->flags & IFF_PROMISC) ||
1075 (netdev_mc_count(netdev) > adapter->mcastFilterSize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1077 IbmVethMcastEnableRecv |
1078 IbmVethMcastDisableFiltering,
1079 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001080 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
1082 }
1083 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001084 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 /* clear the filter table & disable filtering */
1086 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1087 IbmVethMcastEnableRecv |
1088 IbmVethMcastDisableFiltering |
1089 IbmVethMcastClearFilterTable,
1090 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001091 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
1093 }
1094 /* add the addresses to the filter table */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001095 netdev_for_each_mc_addr(ha, netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 // add the multicast address to the filter table
1097 unsigned long mcast_addr = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001098 memcpy(((char *)&mcast_addr)+2, ha->addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1100 IbmVethMcastAddFilter,
1101 mcast_addr);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001102 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
1104 }
1105 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /* re-enable filtering */
1108 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1109 IbmVethMcastEnableFiltering,
1110 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001111 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
1113 }
1114 }
1115}
1116
1117static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1118{
Wang Chen4cf16532008-11-12 23:38:14 -08001119 struct ibmveth_adapter *adapter = netdev_priv(dev);
Robert Jennings1096d632008-07-24 04:34:52 +10001120 struct vio_dev *viodev = adapter->vdev;
Santiago Leon860f2422006-04-25 11:19:59 -05001121 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
Robert Jennings0645bab2010-08-17 09:15:45 +00001122 int i, rc;
1123 int need_restart = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001124
Santiago Leon860f2422006-04-25 11:19:59 -05001125 if (new_mtu < IBMVETH_MAX_MTU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 return -EINVAL;
Santiago Leonb6d35182005-10-26 10:47:01 -06001127
Brian Kingce6eea52007-06-08 14:05:17 -05001128 for (i = 0; i < IbmVethNumBufferPools; i++)
1129 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1130 break;
1131
1132 if (i == IbmVethNumBufferPools)
1133 return -EINVAL;
1134
Santiago Leonea866e62008-07-24 04:34:23 +10001135 /* Deactivate all the buffer pools so that the next loop can activate
1136 only the buffer pools necessary to hold the new MTU */
Robert Jennings0645bab2010-08-17 09:15:45 +00001137 if (netif_running(adapter->netdev)) {
1138 need_restart = 1;
1139 adapter->pool_config = 1;
1140 ibmveth_close(adapter->netdev);
1141 adapter->pool_config = 0;
1142 }
Brian Kingce6eea52007-06-08 14:05:17 -05001143
Santiago Leonea866e62008-07-24 04:34:23 +10001144 /* Look for an active buffer pool that can hold the new MTU */
1145 for(i = 0; i<IbmVethNumBufferPools; i++) {
1146 adapter->rx_buff_pool[i].active = 1;
1147
Santiago Leon860f2422006-04-25 11:19:59 -05001148 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
Robert Jennings1096d632008-07-24 04:34:52 +10001149 dev->mtu = new_mtu;
1150 vio_cmo_set_dev_desired(viodev,
1151 ibmveth_get_desired_dma
1152 (viodev));
Robert Jennings0645bab2010-08-17 09:15:45 +00001153 if (need_restart) {
1154 return ibmveth_open(adapter->netdev);
1155 }
Santiago Leon860f2422006-04-25 11:19:59 -05001156 return 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001157 }
Santiago Leonb6d35182005-10-26 10:47:01 -06001158 }
Robert Jennings0645bab2010-08-17 09:15:45 +00001159
1160 if (need_restart && (rc = ibmveth_open(adapter->netdev)))
1161 return rc;
1162
Santiago Leon860f2422006-04-25 11:19:59 -05001163 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Santiago Leon6b422372006-10-03 12:24:28 -05001166#ifdef CONFIG_NET_POLL_CONTROLLER
1167static void ibmveth_poll_controller(struct net_device *dev)
1168{
Wang Chen4cf16532008-11-12 23:38:14 -08001169 ibmveth_replenish_task(netdev_priv(dev));
Andrew Morton5f771132006-10-10 14:33:30 -07001170 ibmveth_interrupt(dev->irq, dev);
Santiago Leon6b422372006-10-03 12:24:28 -05001171}
1172#endif
1173
Robert Jennings1096d632008-07-24 04:34:52 +10001174/**
1175 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1176 *
1177 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1178 *
1179 * Return value:
1180 * Number of bytes of IO data the driver will need to perform well.
1181 */
1182static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1183{
1184 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1185 struct ibmveth_adapter *adapter;
1186 unsigned long ret;
1187 int i;
1188 int rxqentries = 1;
1189
1190 /* netdev inits at probe time along with the structures we need below*/
1191 if (netdev == NULL)
1192 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1193
1194 adapter = netdev_priv(netdev);
1195
1196 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1197 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1198
1199 for (i = 0; i < IbmVethNumBufferPools; i++) {
1200 /* add the size of the active receive buffers */
1201 if (adapter->rx_buff_pool[i].active)
1202 ret +=
1203 adapter->rx_buff_pool[i].size *
1204 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1205 buff_size);
1206 rxqentries += adapter->rx_buff_pool[i].size;
1207 }
1208 /* add the size of the receive queue entries */
1209 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1210
1211 return ret;
1212}
1213
Alexander Beregalove186d172009-04-15 12:52:39 +00001214static const struct net_device_ops ibmveth_netdev_ops = {
1215 .ndo_open = ibmveth_open,
1216 .ndo_stop = ibmveth_close,
1217 .ndo_start_xmit = ibmveth_start_xmit,
1218 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1219 .ndo_do_ioctl = ibmveth_ioctl,
1220 .ndo_change_mtu = ibmveth_change_mtu,
1221 .ndo_validate_addr = eth_validate_addr,
1222 .ndo_set_mac_address = eth_mac_addr,
1223#ifdef CONFIG_NET_POLL_CONTROLLER
1224 .ndo_poll_controller = ibmveth_poll_controller,
1225#endif
1226};
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1229{
Santiago Leonb6d35182005-10-26 10:47:01 -06001230 int rc, i;
Brian Kingf4ff2872007-09-15 13:36:07 -07001231 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 struct net_device *netdev;
Mariusz Kozlowski9dc83af2007-08-06 23:44:03 +02001233 struct ibmveth_adapter *adapter;
Stephen Rothwellff5bfc32009-01-06 10:47:44 -08001234 unsigned long set_attr, ret_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 unsigned char *mac_addr_p;
1237 unsigned int *mcastFilterSize_p;
1238
1239
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001240 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 dev->unit_address);
1242
Michael Ellerman493a6842007-04-17 13:12:55 +10001243 mac_addr_p = (unsigned char *) vio_get_attribute(dev,
1244 VETH_MAC_ADDR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if(!mac_addr_p) {
1246 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1247 "attribute\n", __FILE__, __LINE__);
1248 return 0;
1249 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001250
Michael Ellerman493a6842007-04-17 13:12:55 +10001251 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev,
1252 VETH_MCAST_FILTER_SIZE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 if(!mcastFilterSize_p) {
1254 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
1255 "VETH_MCAST_FILTER_SIZE attribute\n",
1256 __FILE__, __LINE__);
1257 return 0;
1258 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1261
1262 if(!netdev)
1263 return -ENOMEM;
1264
Wang Chen4cf16532008-11-12 23:38:14 -08001265 adapter = netdev_priv(netdev);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001266 dev_set_drvdata(&dev->dev, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 adapter->vdev = dev;
1269 adapter->netdev = netdev;
1270 adapter->mcastFilterSize= *mcastFilterSize_p;
Santiago Leon860f2422006-04-25 11:19:59 -05001271 adapter->pool_config = 0;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001272
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001273 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 /* Some older boxes running PHYP non-natively have an OF that
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001276 returns a 8-byte local-mac-address field (and the first
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 2 bytes have to be ignored) while newer boxes' OF return
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001278 a 6-byte field. Note that IEEE 1275 specifies that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 local-mac-address must be a 6-byte field.
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001280 The RPA doc specifies that the first byte must be 10b, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 we'll just look for it to solve this 8 vs. 6 byte field issue */
1282
1283 if ((*mac_addr_p & 0x3) != 0x02)
1284 mac_addr_p += 2;
1285
1286 adapter->mac_addr = 0;
1287 memcpy(&adapter->mac_addr, mac_addr_p, 6);
1288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 netdev->irq = dev->irq;
Alexander Beregalove186d172009-04-15 12:52:39 +00001290 netdev->netdev_ops = &ibmveth_netdev_ops;
1291 netdev->ethtool_ops = &netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 SET_NETDEV_DEV(netdev, &dev->dev);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001293 netdev->features |= NETIF_F_LLTX;
Santiago Leon60296d92005-10-26 10:47:16 -06001294 spin_lock_init(&adapter->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Stephen Rothwelld44b5e02009-05-11 21:44:51 +00001296 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Santiago Leon860f2422006-04-25 11:19:59 -05001298 for(i = 0; i<IbmVethNumBufferPools; i++) {
1299 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001300 int error;
1301
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001302 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1303 pool_count[i], pool_size[i],
Santiago Leon860f2422006-04-25 11:19:59 -05001304 pool_active[i]);
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001305 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1306 &dev->dev.kobj, "pool%d", i);
1307 if (!error)
1308 kobject_uevent(kobj, KOBJ_ADD);
Santiago Leon860f2422006-04-25 11:19:59 -05001309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 adapter->buffer_list_dma = DMA_ERROR_CODE;
1314 adapter->filter_list_dma = DMA_ERROR_CODE;
1315 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 ibmveth_debug_printk("registering netdev...\n");
1318
Brian King79ef4a42007-08-17 09:16:56 -05001319 ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001320
Brian King79ef4a42007-08-17 09:16:56 -05001321 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
1322 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
1323 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
1324 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian Kingf4ff2872007-09-15 13:36:07 -07001325
Brian King79ef4a42007-08-17 09:16:56 -05001326 ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001327
Brian King5fc7e012007-08-17 09:16:31 -05001328 if (ret == H_SUCCESS) {
1329 adapter->rx_csum = 1;
Brian Kingf4ff2872007-09-15 13:36:07 -07001330 netdev->features |= NETIF_F_IP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -05001331 } else
Brian King79ef4a42007-08-17 09:16:56 -05001332 ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001333 }
1334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 rc = register_netdev(netdev);
1336
1337 if(rc) {
1338 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1339 free_netdev(netdev);
1340 return rc;
1341 }
1342
1343 ibmveth_debug_printk("registered\n");
1344
1345 ibmveth_proc_register_adapter(adapter);
1346
1347 return 0;
1348}
1349
1350static int __devexit ibmveth_remove(struct vio_dev *dev)
1351{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001352 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Wang Chen4cf16532008-11-12 23:38:14 -08001353 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001354 int i;
1355
1356 for(i = 0; i<IbmVethNumBufferPools; i++)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001357 kobject_put(&adapter->rx_buff_pool[i].kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
1359 unregister_netdev(netdev);
1360
1361 ibmveth_proc_unregister_adapter(adapter);
1362
1363 free_netdev(netdev);
Robert Jennings1096d632008-07-24 04:34:52 +10001364 dev_set_drvdata(&dev->dev, NULL);
1365
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 return 0;
1367}
1368
1369#ifdef CONFIG_PROC_FS
1370static void ibmveth_proc_register_driver(void)
1371{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001372 ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (ibmveth_proc_dir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
1375}
1376
1377static void ibmveth_proc_unregister_driver(void)
1378{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001379 remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001382static int ibmveth_show(struct seq_file *seq, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 struct ibmveth_adapter *adapter = seq->private;
Jiri Pirko3a6d54c2009-05-11 23:37:15 +00001385 char *current_mac = (char *) adapter->netdev->dev_addr;
1386 char *firmware_mac = (char *) &adapter->mac_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388 seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address);
Johannes Berge1749612008-10-27 15:59:26 -07001391 seq_printf(seq, "Current MAC: %pM\n", current_mac);
1392 seq_printf(seq, "Firmware MAC: %pM\n", firmware_mac);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 seq_printf(seq, "\nAdapter Statistics:\n");
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001395 seq_printf(seq, " TX: vio_map_single failres: %lld\n", adapter->tx_map_failed);
1396 seq_printf(seq, " send failures: %lld\n", adapter->tx_send_failed);
1397 seq_printf(seq, " RX: replenish task cycles: %lld\n", adapter->replenish_task_cycles);
1398 seq_printf(seq, " alloc_skb_failures: %lld\n", adapter->replenish_no_mem);
1399 seq_printf(seq, " add buffer failures: %lld\n", adapter->replenish_add_buff_failure);
1400 seq_printf(seq, " invalid buffers: %lld\n", adapter->rx_invalid_buffer);
1401 seq_printf(seq, " no buffers: %lld\n", adapter->rx_no_buffer);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return 0;
1404}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
1406static int ibmveth_proc_open(struct inode *inode, struct file *file)
1407{
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001408 return single_open(file, ibmveth_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409}
1410
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001411static const struct file_operations ibmveth_proc_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .owner = THIS_MODULE,
1413 .open = ibmveth_proc_open,
1414 .read = seq_read,
1415 .llseek = seq_lseek,
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001416 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417};
1418
1419static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1420{
1421 struct proc_dir_entry *entry;
1422 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001423 char u_addr[10];
1424 sprintf(u_addr, "%x", adapter->vdev->unit_address);
Denis V. Luneva95609c2008-04-29 01:02:29 -07001425 entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir,
1426 &ibmveth_proc_fops, adapter);
1427 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 ibmveth_error_printk("Cannot create adapter proc entry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
1432static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1433{
1434 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001435 char u_addr[10];
1436 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1437 remove_proc_entry(u_addr, ibmveth_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439}
1440
1441#else /* CONFIG_PROC_FS */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001442static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
1444}
1445
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001446static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448}
1449static void ibmveth_proc_register_driver(void)
1450{
1451}
1452
1453static void ibmveth_proc_unregister_driver(void)
1454{
1455}
1456#endif /* CONFIG_PROC_FS */
1457
Santiago Leon860f2422006-04-25 11:19:59 -05001458static struct attribute veth_active_attr;
1459static struct attribute veth_num_attr;
1460static struct attribute veth_size_attr;
1461
1462static ssize_t veth_pool_show(struct kobject * kobj,
1463 struct attribute * attr, char * buf)
1464{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001465 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001466 struct ibmveth_buff_pool,
1467 kobj);
1468
1469 if (attr == &veth_active_attr)
1470 return sprintf(buf, "%d\n", pool->active);
1471 else if (attr == &veth_num_attr)
1472 return sprintf(buf, "%d\n", pool->size);
1473 else if (attr == &veth_size_attr)
1474 return sprintf(buf, "%d\n", pool->buff_size);
1475 return 0;
1476}
1477
1478static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr,
1479const char * buf, size_t count)
1480{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001481 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001482 struct ibmveth_buff_pool,
1483 kobj);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001484 struct net_device *netdev = dev_get_drvdata(
1485 container_of(kobj->parent, struct device, kobj));
Wang Chen4cf16532008-11-12 23:38:14 -08001486 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001487 long value = simple_strtol(buf, NULL, 10);
1488 long rc;
1489
1490 if (attr == &veth_active_attr) {
1491 if (value && !pool->active) {
Brian King4aa9c932007-06-08 14:05:16 -05001492 if (netif_running(netdev)) {
1493 if(ibmveth_alloc_buffer_pool(pool)) {
1494 ibmveth_error_printk("unable to alloc pool\n");
1495 return -ENOMEM;
1496 }
1497 pool->active = 1;
1498 adapter->pool_config = 1;
1499 ibmveth_close(netdev);
1500 adapter->pool_config = 0;
1501 if ((rc = ibmveth_open(netdev)))
1502 return rc;
1503 } else
1504 pool->active = 1;
Santiago Leon860f2422006-04-25 11:19:59 -05001505 } else if (!value && pool->active) {
1506 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1507 int i;
1508 /* Make sure there is a buffer pool with buffers that
1509 can hold a packet of the size of the MTU */
Brian King76b9cfc2007-08-03 13:55:19 +10001510 for (i = 0; i < IbmVethNumBufferPools; i++) {
Santiago Leon860f2422006-04-25 11:19:59 -05001511 if (pool == &adapter->rx_buff_pool[i])
1512 continue;
1513 if (!adapter->rx_buff_pool[i].active)
1514 continue;
Brian King76b9cfc2007-08-03 13:55:19 +10001515 if (mtu <= adapter->rx_buff_pool[i].buff_size)
1516 break;
Santiago Leon860f2422006-04-25 11:19:59 -05001517 }
Brian King76b9cfc2007-08-03 13:55:19 +10001518
1519 if (i == IbmVethNumBufferPools) {
Santiago Leon860f2422006-04-25 11:19:59 -05001520 ibmveth_error_printk("no active pool >= MTU\n");
1521 return -EPERM;
1522 }
Brian King76b9cfc2007-08-03 13:55:19 +10001523
Brian King76b9cfc2007-08-03 13:55:19 +10001524 if (netif_running(netdev)) {
1525 adapter->pool_config = 1;
1526 ibmveth_close(netdev);
Santiago Leonea866e62008-07-24 04:34:23 +10001527 pool->active = 0;
Brian King76b9cfc2007-08-03 13:55:19 +10001528 adapter->pool_config = 0;
1529 if ((rc = ibmveth_open(netdev)))
1530 return rc;
1531 }
Santiago Leonea866e62008-07-24 04:34:23 +10001532 pool->active = 0;
Santiago Leon860f2422006-04-25 11:19:59 -05001533 }
1534 } else if (attr == &veth_num_attr) {
1535 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
1536 return -EINVAL;
1537 else {
Brian King4aa9c932007-06-08 14:05:16 -05001538 if (netif_running(netdev)) {
1539 adapter->pool_config = 1;
1540 ibmveth_close(netdev);
1541 adapter->pool_config = 0;
1542 pool->size = value;
1543 if ((rc = ibmveth_open(netdev)))
1544 return rc;
1545 } else
1546 pool->size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001547 }
1548 } else if (attr == &veth_size_attr) {
1549 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
1550 return -EINVAL;
1551 else {
Brian King4aa9c932007-06-08 14:05:16 -05001552 if (netif_running(netdev)) {
1553 adapter->pool_config = 1;
1554 ibmveth_close(netdev);
1555 adapter->pool_config = 0;
1556 pool->buff_size = value;
1557 if ((rc = ibmveth_open(netdev)))
1558 return rc;
1559 } else
1560 pool->buff_size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001561 }
1562 }
1563
1564 /* kick the interrupt handler to allocate/deallocate pools */
David Howells7d12e782006-10-05 14:55:46 +01001565 ibmveth_interrupt(netdev->irq, netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001566 return count;
1567}
1568
1569
1570#define ATTR(_name, _mode) \
1571 struct attribute veth_##_name##_attr = { \
Tejun Heo7b595752007-06-14 03:45:17 +09001572 .name = __stringify(_name), .mode = _mode, \
Santiago Leon860f2422006-04-25 11:19:59 -05001573 };
1574
1575static ATTR(active, 0644);
1576static ATTR(num, 0644);
1577static ATTR(size, 0644);
1578
1579static struct attribute * veth_pool_attrs[] = {
1580 &veth_active_attr,
1581 &veth_num_attr,
1582 &veth_size_attr,
1583 NULL,
1584};
1585
Emese Revfy52cf25d2010-01-19 02:58:23 +01001586static const struct sysfs_ops veth_pool_ops = {
Santiago Leon860f2422006-04-25 11:19:59 -05001587 .show = veth_pool_show,
1588 .store = veth_pool_store,
1589};
1590
1591static struct kobj_type ktype_veth_pool = {
1592 .release = NULL,
1593 .sysfs_ops = &veth_pool_ops,
1594 .default_attrs = veth_pool_attrs,
1595};
1596
Brian Kinge7a3af52010-05-07 08:56:08 +00001597static int ibmveth_resume(struct device *dev)
1598{
1599 struct net_device *netdev = dev_get_drvdata(dev);
1600 ibmveth_interrupt(netdev->irq, netdev);
1601 return 0;
1602}
Santiago Leon860f2422006-04-25 11:19:59 -05001603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1605 { "network", "IBM,l-lan"},
Stephen Rothwellfb120da2005-08-17 16:42:59 +10001606 { "", "" }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1609
Brian Kinge7a3af52010-05-07 08:56:08 +00001610static struct dev_pm_ops ibmveth_pm_ops = {
1611 .resume = ibmveth_resume
1612};
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614static struct vio_driver ibmveth_driver = {
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001615 .id_table = ibmveth_device_table,
1616 .probe = ibmveth_probe,
1617 .remove = ibmveth_remove,
Robert Jennings1096d632008-07-24 04:34:52 +10001618 .get_desired_dma = ibmveth_get_desired_dma,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001619 .driver = {
1620 .name = ibmveth_driver_name,
Stephen Rothwell915124d2005-10-24 15:12:22 +10001621 .owner = THIS_MODULE,
Brian Kinge7a3af52010-05-07 08:56:08 +00001622 .pm = &ibmveth_pm_ops,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624};
1625
1626static int __init ibmveth_module_init(void)
1627{
1628 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1629
1630 ibmveth_proc_register_driver();
1631
1632 return vio_register_driver(&ibmveth_driver);
1633}
1634
1635static void __exit ibmveth_module_exit(void)
1636{
1637 vio_unregister_driver(&ibmveth_driver);
1638 ibmveth_proc_unregister_driver();
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001639}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641module_init(ibmveth_module_init);
1642module_exit(ibmveth_module_exit);