blob: fc6e2cf879c0a32a48496096bab8acd5a966184b [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
Brian Kingddbb4de2007-08-17 09:16:43 -0500125struct ibmveth_stat {
126 char name[ETH_GSTRING_LEN];
127 int offset;
128};
129
130#define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
131#define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
132
133struct ibmveth_stat ibmveth_stats[] = {
134 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) },
135 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) },
136 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure) },
137 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success) },
138 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) },
139 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) },
Brian Kingddbb4de2007-08-17 09:16:43 -0500140 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) },
141 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) },
142};
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/* simple methods of getting data from the current rxq entry */
Brian King79ef4a42007-08-17 09:16:56 -0500145static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter)
146{
147 return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off;
148}
149
150static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter)
151{
152 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT;
153}
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
156{
Brian King79ef4a42007-08-17 09:16:56 -0500157 return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
161{
Brian King79ef4a42007-08-17 09:16:56 -0500162 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
166{
Brian King79ef4a42007-08-17 09:16:56 -0500167 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
171{
172 return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
173}
174
Brian Kingf4ff2872007-09-15 13:36:07 -0700175static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter)
176{
Brian King79ef4a42007-08-17 09:16:56 -0500177 return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700178}
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* setup the initial settings for a buffer pool */
Santiago Leon860f2422006-04-25 11:19:59 -0500181static 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 -0700182{
183 pool->size = pool_size;
184 pool->index = pool_index;
185 pool->buff_size = buff_size;
Santiago Leonc033a6d2010-09-03 18:28:09 +0000186 pool->threshold = pool_size * 7 / 8;
Santiago Leon860f2422006-04-25 11:19:59 -0500187 pool->active = pool_active;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
190/* allocate and setup an buffer pool - called during open */
191static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
192{
193 int i;
194
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400195 pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 if(!pool->free_map) {
198 return -1;
199 }
200
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400201 pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if(!pool->dma_addr) {
203 kfree(pool->free_map);
204 pool->free_map = NULL;
205 return -1;
206 }
207
Julia Lawalla05abcb2010-05-13 10:06:01 +0000208 pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 if(!pool->skbuff) {
211 kfree(pool->dma_addr);
212 pool->dma_addr = NULL;
213
214 kfree(pool->free_map);
215 pool->free_map = NULL;
216 return -1;
217 }
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
220
221 for(i = 0; i < pool->size; ++i) {
222 pool->free_map[i] = i;
223 }
224
225 atomic_set(&pool->available, 0);
226 pool->producer_index = 0;
227 pool->consumer_index = 0;
228
229 return 0;
230}
231
232/* replenish the buffers for a pool. note that we don't need to
233 * skb_reserve these since they are used for incoming...
234 */
235static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
236{
237 u32 i;
238 u32 count = pool->size - atomic_read(&pool->available);
239 u32 buffers_added = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000240 struct sk_buff *skb;
241 unsigned int free_index, index;
242 u64 correlator;
243 unsigned long lpar_rc;
244 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 mb();
247
248 for(i = 0; i < count; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
252
253 if(!skb) {
254 ibmveth_debug_printk("replenish: unable to allocate skb\n");
255 adapter->replenish_no_mem++;
256 break;
257 }
258
David Gibson047a66d2006-10-21 10:24:13 -0700259 free_index = pool->consumer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000260 pool->consumer_index++;
261 if (pool->consumer_index >= pool->size)
262 pool->consumer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 index = pool->free_map[free_index];
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
266 ibmveth_assert(pool->skbuff[index] == NULL);
267
268 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
269 pool->buff_size, DMA_FROM_DEVICE);
270
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000271 if (dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000272 goto failure;
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
275 pool->dma_addr[index] = dma_addr;
276 pool->skbuff[index] = skb;
277
278 correlator = ((u64)pool->index << 32) | index;
279 *(u64*)skb->data = correlator;
280
Brian King79ef4a42007-08-17 09:16:56 -0500281 desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400282 desc.fields.address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400285
Robert Jennings1096d632008-07-24 04:34:52 +1000286 if (lpar_rc != H_SUCCESS)
287 goto failure;
288 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 buffers_added++;
290 adapter->replenish_add_buff_success++;
291 }
292 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 mb();
295 atomic_add(buffers_added, &(pool->available));
Robert Jennings1096d632008-07-24 04:34:52 +1000296 return;
297
298failure:
299 pool->free_map[free_index] = index;
300 pool->skbuff[index] = NULL;
301 if (pool->consumer_index == 0)
302 pool->consumer_index = pool->size - 1;
303 else
304 pool->consumer_index--;
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000305 if (!dma_mapping_error(&adapter->vdev->dev, dma_addr))
Robert Jennings1096d632008-07-24 04:34:52 +1000306 dma_unmap_single(&adapter->vdev->dev,
307 pool->dma_addr[index], pool->buff_size,
308 DMA_FROM_DEVICE);
309 dev_kfree_skb_any(skb);
310 adapter->replenish_add_buff_failure++;
311
312 mb();
313 atomic_add(buffers_added, &(pool->available));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Santiago Leone2adbcb2005-10-26 10:47:08 -0600316/* replenish routine */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400317static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Santiago Leonb6d35182005-10-26 10:47:01 -0600319 int i;
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 adapter->replenish_task_cycles++;
322
Santiago Leonc033a6d2010-09-03 18:28:09 +0000323 for (i = (IbmVethNumBufferPools - 1); i >= 0; i--) {
324 struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i];
325
326 if (pool->active &&
327 (atomic_read(&pool->available) < pool->threshold))
328 ibmveth_replenish_buffer_pool(adapter, pool);
329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
334/* empty and free ana buffer pool - also used to do cleanup in error paths */
335static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
336{
337 int i;
338
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400339 kfree(pool->free_map);
340 pool->free_map = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if(pool->skbuff && pool->dma_addr) {
343 for(i = 0; i < pool->size; ++i) {
344 struct sk_buff *skb = pool->skbuff[i];
345 if(skb) {
346 dma_unmap_single(&adapter->vdev->dev,
347 pool->dma_addr[i],
348 pool->buff_size,
349 DMA_FROM_DEVICE);
350 dev_kfree_skb_any(skb);
351 pool->skbuff[i] = NULL;
352 }
353 }
354 }
355
356 if(pool->dma_addr) {
357 kfree(pool->dma_addr);
358 pool->dma_addr = NULL;
359 }
360
361 if(pool->skbuff) {
362 kfree(pool->skbuff);
363 pool->skbuff = NULL;
364 }
365}
366
367/* remove a buffer from a pool */
368static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
369{
370 unsigned int pool = correlator >> 32;
371 unsigned int index = correlator & 0xffffffffUL;
372 unsigned int free_index;
373 struct sk_buff *skb;
374
375 ibmveth_assert(pool < IbmVethNumBufferPools);
376 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
377
378 skb = adapter->rx_buff_pool[pool].skbuff[index];
379
380 ibmveth_assert(skb != NULL);
381
382 adapter->rx_buff_pool[pool].skbuff[index] = NULL;
383
384 dma_unmap_single(&adapter->vdev->dev,
385 adapter->rx_buff_pool[pool].dma_addr[index],
386 adapter->rx_buff_pool[pool].buff_size,
387 DMA_FROM_DEVICE);
388
David Gibson047a66d2006-10-21 10:24:13 -0700389 free_index = adapter->rx_buff_pool[pool].producer_index;
Santiago Leona613f582010-09-03 18:28:04 +0000390 adapter->rx_buff_pool[pool].producer_index++;
391 if (adapter->rx_buff_pool[pool].producer_index >=
392 adapter->rx_buff_pool[pool].size)
393 adapter->rx_buff_pool[pool].producer_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 adapter->rx_buff_pool[pool].free_map[free_index] = index;
395
396 mb();
397
398 atomic_dec(&(adapter->rx_buff_pool[pool].available));
399}
400
401/* get the current buffer on the rx queue */
402static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
403{
404 u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
405 unsigned int pool = correlator >> 32;
406 unsigned int index = correlator & 0xffffffffUL;
407
408 ibmveth_assert(pool < IbmVethNumBufferPools);
409 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
410
411 return adapter->rx_buff_pool[pool].skbuff[index];
412}
413
414/* recycle the current buffer on the rx queue */
415static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
416{
417 u32 q_index = adapter->rx_queue.index;
418 u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
419 unsigned int pool = correlator >> 32;
420 unsigned int index = correlator & 0xffffffffUL;
421 union ibmveth_buf_desc desc;
422 unsigned long lpar_rc;
423
424 ibmveth_assert(pool < IbmVethNumBufferPools);
425 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
426
Santiago Leonb6d35182005-10-26 10:47:01 -0600427 if(!adapter->rx_buff_pool[pool].active) {
428 ibmveth_rxq_harvest_buffer(adapter);
429 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
430 return;
431 }
432
Brian King79ef4a42007-08-17 09:16:56 -0500433 desc.fields.flags_len = IBMVETH_BUF_VALID |
434 adapter->rx_buff_pool[pool].buff_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
436
437 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400438
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200439 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
441 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
442 }
443
444 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
445 adapter->rx_queue.index = 0;
446 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
447 }
448}
449
Michael Ellerman493a6842007-04-17 13:12:55 +1000450static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
453
454 if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
455 adapter->rx_queue.index = 0;
456 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
457 }
458}
459
460static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
461{
Santiago Leonb6d35182005-10-26 10:47:01 -0600462 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700463 struct device *dev = &adapter->vdev->dev;
Santiago Leonb6d35182005-10-26 10:47:01 -0600464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if(adapter->buffer_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700466 if (!dma_mapping_error(dev, adapter->buffer_list_dma)) {
467 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 DMA_BIDIRECTIONAL);
469 adapter->buffer_list_dma = DMA_ERROR_CODE;
470 }
471 free_page((unsigned long)adapter->buffer_list_addr);
472 adapter->buffer_list_addr = NULL;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 if(adapter->filter_list_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700476 if (!dma_mapping_error(dev, adapter->filter_list_dma)) {
477 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 DMA_BIDIRECTIONAL);
479 adapter->filter_list_dma = DMA_ERROR_CODE;
480 }
481 free_page((unsigned long)adapter->filter_list_addr);
482 adapter->filter_list_addr = NULL;
483 }
484
485 if(adapter->rx_queue.queue_addr != NULL) {
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700486 if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) {
487 dma_unmap_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 adapter->rx_queue.queue_dma,
489 adapter->rx_queue.queue_len,
490 DMA_BIDIRECTIONAL);
491 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
492 }
493 kfree(adapter->rx_queue.queue_addr);
494 adapter->rx_queue.queue_addr = NULL;
495 }
496
Santiago Leonb6d35182005-10-26 10:47:01 -0600497 for(i = 0; i<IbmVethNumBufferPools; i++)
Santiago Leon860f2422006-04-25 11:19:59 -0500498 if (adapter->rx_buff_pool[i].active)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400499 ibmveth_free_buffer_pool(adapter,
Santiago Leon860f2422006-04-25 11:19:59 -0500500 &adapter->rx_buff_pool[i]);
Robert Jennings1096d632008-07-24 04:34:52 +1000501
502 if (adapter->bounce_buffer != NULL) {
Stephen Rothwellc713e7c2008-07-28 02:14:24 +1000503 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000504 dma_unmap_single(&adapter->vdev->dev,
505 adapter->bounce_buffer_dma,
506 adapter->netdev->mtu + IBMVETH_BUFF_OH,
507 DMA_BIDIRECTIONAL);
508 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
509 }
510 kfree(adapter->bounce_buffer);
511 adapter->bounce_buffer = NULL;
512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500515static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
516 union ibmveth_buf_desc rxq_desc, u64 mac_address)
517{
518 int rc, try_again = 1;
519
520 /* After a kexec the adapter will still be open, so our attempt to
521 * open it will fail. So if we get a failure we free the adapter and
522 * try again, but only once. */
523retry:
524 rc = h_register_logical_lan(adapter->vdev->unit_address,
525 adapter->buffer_list_dma, rxq_desc.desc,
526 adapter->filter_list_dma, mac_address);
527
528 if (rc != H_SUCCESS && try_again) {
529 do {
530 rc = h_free_logical_lan(adapter->vdev->unit_address);
531 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
532
533 try_again = 0;
534 goto retry;
535 }
536
537 return rc;
538}
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540static int ibmveth_open(struct net_device *netdev)
541{
Wang Chen4cf16532008-11-12 23:38:14 -0800542 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 u64 mac_address = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -0600544 int rxq_entries = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 unsigned long lpar_rc;
546 int rc;
547 union ibmveth_buf_desc rxq_desc;
Santiago Leonb6d35182005-10-26 10:47:01 -0600548 int i;
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700549 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 ibmveth_debug_printk("open starting\n");
552
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700553 napi_enable(&adapter->napi);
554
Santiago Leonb6d35182005-10-26 10:47:01 -0600555 for(i = 0; i<IbmVethNumBufferPools; i++)
556 rxq_entries += adapter->rx_buff_pool[i].size;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
559 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
562 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
563 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700564 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return -ENOMEM;
566 }
567
568 adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
569 adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
570
571 if(!adapter->rx_queue.queue_addr) {
572 ibmveth_error_printk("unable to allocate rx queue pages\n");
573 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700574 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return -ENOMEM;
576 }
577
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700578 dev = &adapter->vdev->dev;
579
580 adapter->buffer_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700582 adapter->filter_list_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700584 adapter->rx_queue.queue_dma = dma_map_single(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 adapter->rx_queue.queue_addr,
586 adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
587
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700588 if ((dma_mapping_error(dev, adapter->buffer_list_dma)) ||
589 (dma_mapping_error(dev, adapter->filter_list_dma)) ||
590 (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 ibmveth_error_printk("unable to map filter or buffer list pages\n");
592 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700593 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 return -ENOMEM;
595 }
596
597 adapter->rx_queue.index = 0;
598 adapter->rx_queue.num_slots = rxq_entries;
599 adapter->rx_queue.toggle = 1;
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
602 mac_address = mac_address >> 16;
603
Brian King79ef4a42007-08-17 09:16:56 -0500604 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 rxq_desc.fields.address = adapter->rx_queue.queue_dma;
606
607 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
608 ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
609 ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr);
610
Santiago Leon4347ef12006-10-03 12:24:34 -0500611 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
612
Michael Ellermanbbedefc2006-10-03 12:24:23 -0500613 lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200615 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000617 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 -0700618 adapter->buffer_list_dma,
619 adapter->filter_list_dma,
620 rxq_desc.desc,
621 mac_address);
622 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700623 napi_disable(&adapter->napi);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400624 return -ENONET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
Santiago Leon860f2422006-04-25 11:19:59 -0500627 for(i = 0; i<IbmVethNumBufferPools; i++) {
628 if(!adapter->rx_buff_pool[i].active)
629 continue;
630 if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) {
631 ibmveth_error_printk("unable to alloc pool\n");
632 adapter->rx_buff_pool[i].active = 0;
633 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700634 napi_disable(&adapter->napi);
Santiago Leon860f2422006-04-25 11:19:59 -0500635 return -ENOMEM ;
636 }
637 }
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
Joe Perchesa0607fd2009-11-18 23:29:17 -0800640 if((rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
642 do {
643 rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200644 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 ibmveth_cleanup(adapter);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700647 napi_disable(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return rc;
649 }
650
Robert Jennings1096d632008-07-24 04:34:52 +1000651 adapter->bounce_buffer =
652 kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL);
653 if (!adapter->bounce_buffer) {
654 ibmveth_error_printk("unable to allocate bounce buffer\n");
655 ibmveth_cleanup(adapter);
656 napi_disable(&adapter->napi);
657 return -ENOMEM;
658 }
659 adapter->bounce_buffer_dma =
660 dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer,
661 netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700662 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
Robert Jennings1096d632008-07-24 04:34:52 +1000663 ibmveth_error_printk("unable to map bounce buffer\n");
664 ibmveth_cleanup(adapter);
665 napi_disable(&adapter->napi);
666 return -ENOMEM;
667 }
668
Santiago Leone2adbcb2005-10-26 10:47:08 -0600669 ibmveth_debug_printk("initial replenish cycle\n");
David Howells7d12e782006-10-05 14:55:46 +0100670 ibmveth_interrupt(netdev->irq, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Santiago Leone2adbcb2005-10-26 10:47:08 -0600672 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 ibmveth_debug_printk("open complete\n");
675
676 return 0;
677}
678
679static int ibmveth_close(struct net_device *netdev)
680{
Wang Chen4cf16532008-11-12 23:38:14 -0800681 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 long lpar_rc;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 ibmveth_debug_printk("close starting\n");
685
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700686 napi_disable(&adapter->napi);
687
Santiago Leon860f2422006-04-25 11:19:59 -0500688 if (!adapter->pool_config)
689 netif_stop_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Robert Jenningsee2e6112010-07-16 04:57:25 +0000691 h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 do {
694 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200695 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200697 if(lpar_rc != H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 {
699 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
700 lpar_rc);
701 }
702
Robert Jenningsee2e6112010-07-16 04:57:25 +0000703 free_irq(netdev->irq, netdev);
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
706
707 ibmveth_cleanup(adapter);
708
709 ibmveth_debug_printk("close complete\n");
710
711 return 0;
712}
713
714static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
715 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
716 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
717 cmd->speed = SPEED_1000;
718 cmd->duplex = DUPLEX_FULL;
719 cmd->port = PORT_FIBRE;
720 cmd->phy_address = 0;
721 cmd->transceiver = XCVR_INTERNAL;
722 cmd->autoneg = AUTONEG_ENABLE;
723 cmd->maxtxpkt = 0;
724 cmd->maxrxpkt = 1;
725 return 0;
726}
727
728static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
729 strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
730 strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
731}
732
733static u32 netdev_get_link(struct net_device *dev) {
734 return 1;
735}
736
Brian King5fc7e012007-08-17 09:16:31 -0500737static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data)
738{
Wang Chen4cf16532008-11-12 23:38:14 -0800739 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500740
741 if (data)
742 adapter->rx_csum = 1;
743 else {
744 /*
745 * Since the ibmveth firmware interface does not have the concept of
746 * separate tx/rx checksum offload enable, if rx checksum is disabled
747 * we also have to disable tx checksum offload. Once we disable rx
748 * checksum offload, we are no longer allowed to send tx buffers that
749 * are not properly checksummed.
750 */
751 adapter->rx_csum = 0;
752 dev->features &= ~NETIF_F_IP_CSUM;
753 }
754}
755
756static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data)
757{
Wang Chen4cf16532008-11-12 23:38:14 -0800758 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500759
760 if (data) {
761 dev->features |= NETIF_F_IP_CSUM;
762 adapter->rx_csum = 1;
763 } else
764 dev->features &= ~NETIF_F_IP_CSUM;
765}
766
767static int ibmveth_set_csum_offload(struct net_device *dev, u32 data,
768 void (*done) (struct net_device *, u32))
769{
Wang Chen4cf16532008-11-12 23:38:14 -0800770 struct ibmveth_adapter *adapter = netdev_priv(dev);
Stephen Rothwellff5bfc32009-01-06 10:47:44 -0800771 unsigned long set_attr, clr_attr, ret_attr;
Brian King5fc7e012007-08-17 09:16:31 -0500772 long ret;
773 int rc1 = 0, rc2 = 0;
774 int restart = 0;
775
776 if (netif_running(dev)) {
777 restart = 1;
778 adapter->pool_config = 1;
779 ibmveth_close(dev);
780 adapter->pool_config = 0;
781 }
782
Brian King79ef4a42007-08-17 09:16:56 -0500783 set_attr = 0;
784 clr_attr = 0;
Brian King5fc7e012007-08-17 09:16:31 -0500785
786 if (data)
Brian King79ef4a42007-08-17 09:16:56 -0500787 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500788 else
Brian King79ef4a42007-08-17 09:16:56 -0500789 clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -0500790
Brian King79ef4a42007-08-17 09:16:56 -0500791 ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500792
Brian King79ef4a42007-08-17 09:16:56 -0500793 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
794 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
795 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
796 ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr,
797 set_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500798
799 if (ret != H_SUCCESS) {
800 rc1 = -EIO;
801 ibmveth_error_printk("unable to change checksum offload settings."
802 " %d rc=%ld\n", data, ret);
803
804 ret = h_illan_attributes(adapter->vdev->unit_address,
Brian King79ef4a42007-08-17 09:16:56 -0500805 set_attr, clr_attr, &ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500806 } else
807 done(dev, data);
808 } else {
809 rc1 = -EIO;
810 ibmveth_error_printk("unable to change checksum offload settings."
Brian King79ef4a42007-08-17 09:16:56 -0500811 " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr);
Brian King5fc7e012007-08-17 09:16:31 -0500812 }
813
814 if (restart)
815 rc2 = ibmveth_open(dev);
816
817 return rc1 ? rc1 : rc2;
818}
819
820static int ibmveth_set_rx_csum(struct net_device *dev, u32 data)
821{
Wang Chen4cf16532008-11-12 23:38:14 -0800822 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500823
824 if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum))
825 return 0;
826
827 return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags);
828}
829
830static int ibmveth_set_tx_csum(struct net_device *dev, u32 data)
831{
Wang Chen4cf16532008-11-12 23:38:14 -0800832 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500833 int rc = 0;
834
835 if (data && (dev->features & NETIF_F_IP_CSUM))
836 return 0;
837 if (!data && !(dev->features & NETIF_F_IP_CSUM))
838 return 0;
839
840 if (data && !adapter->rx_csum)
841 rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags);
842 else
843 ibmveth_set_tx_csum_flags(dev, data);
844
845 return rc;
846}
847
848static u32 ibmveth_get_rx_csum(struct net_device *dev)
849{
Wang Chen4cf16532008-11-12 23:38:14 -0800850 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian King5fc7e012007-08-17 09:16:31 -0500851 return adapter->rx_csum;
852}
853
Brian Kingddbb4de2007-08-17 09:16:43 -0500854static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data)
855{
856 int i;
857
858 if (stringset != ETH_SS_STATS)
859 return;
860
861 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN)
862 memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN);
863}
864
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700865static int ibmveth_get_sset_count(struct net_device *dev, int sset)
Brian Kingddbb4de2007-08-17 09:16:43 -0500866{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700867 switch (sset) {
868 case ETH_SS_STATS:
869 return ARRAY_SIZE(ibmveth_stats);
870 default:
871 return -EOPNOTSUPP;
872 }
Brian Kingddbb4de2007-08-17 09:16:43 -0500873}
874
875static void ibmveth_get_ethtool_stats(struct net_device *dev,
876 struct ethtool_stats *stats, u64 *data)
877{
878 int i;
Wang Chen4cf16532008-11-12 23:38:14 -0800879 struct ibmveth_adapter *adapter = netdev_priv(dev);
Brian Kingddbb4de2007-08-17 09:16:43 -0500880
881 for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++)
882 data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset);
883}
884
Jeff Garzik7282d492006-09-13 14:30:00 -0400885static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 .get_drvinfo = netdev_get_drvinfo,
887 .get_settings = netdev_get_settings,
888 .get_link = netdev_get_link,
Brian King5fc7e012007-08-17 09:16:31 -0500889 .set_tx_csum = ibmveth_set_tx_csum,
890 .get_rx_csum = ibmveth_get_rx_csum,
891 .set_rx_csum = ibmveth_set_rx_csum,
Brian Kingddbb4de2007-08-17 09:16:43 -0500892 .get_strings = ibmveth_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700893 .get_sset_count = ibmveth_get_sset_count,
Brian Kingddbb4de2007-08-17 09:16:43 -0500894 .get_ethtool_stats = ibmveth_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895};
896
897static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
898{
899 return -EOPNOTSUPP;
900}
901
902#define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
903
Stephen Hemminger613573252009-08-31 19:50:58 +0000904static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
905 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
Wang Chen4cf16532008-11-12 23:38:14 -0800907 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Brian King3449a2a2007-08-17 09:16:49 -0500908 union ibmveth_buf_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 unsigned long lpar_rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 unsigned long correlator;
911 unsigned int retry_count;
Santiago Leon60296d92005-10-26 10:47:16 -0600912 unsigned int tx_dropped = 0;
913 unsigned int tx_bytes = 0;
914 unsigned int tx_packets = 0;
915 unsigned int tx_send_failed = 0;
916 unsigned int tx_map_failed = 0;
Robert Jennings1096d632008-07-24 04:34:52 +1000917 int used_bounce = 0;
918 unsigned long data_dma_addr;
Santiago Leon60296d92005-10-26 10:47:16 -0600919
Brian King79ef4a42007-08-17 09:16:56 -0500920 desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Brian Kingf4ff2872007-09-15 13:36:07 -0700922 if (skb->ip_summed == CHECKSUM_PARTIAL &&
923 ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) {
924 ibmveth_error_printk("tx: failed to checksum packet\n");
925 tx_dropped++;
926 goto out;
927 }
928
929 if (skb->ip_summed == CHECKSUM_PARTIAL) {
930 unsigned char *buf = skb_transport_header(skb) + skb->csum_offset;
931
Brian King79ef4a42007-08-17 09:16:56 -0500932 desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD);
Brian Kingf4ff2872007-09-15 13:36:07 -0700933
934 /* Need to zero out the checksum */
935 buf[0] = 0;
936 buf[1] = 0;
937 }
938
Santiago Leonc08cc3c2010-09-03 18:28:20 +0000939 if (skb->len < tx_copybreak) {
940 used_bounce = 1;
941 } else {
942 data_dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
943 skb->len, DMA_TO_DEVICE);
944 if (dma_mapping_error(&adapter->vdev->dev, data_dma_addr)) {
945 if (!firmware_has_feature(FW_FEATURE_CMO))
946 ibmveth_error_printk("tx: unable to map "
947 "xmit buffer\n");
948 tx_map_failed++;
949 used_bounce = 1;
950 }
951 }
952
953 if (used_bounce) {
Robert Jennings1096d632008-07-24 04:34:52 +1000954 skb_copy_from_linear_data(skb, adapter->bounce_buffer,
955 skb->len);
956 desc.fields.address = adapter->bounce_buffer_dma;
Robert Jennings1096d632008-07-24 04:34:52 +1000957 } else
958 desc.fields.address = data_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 /* send the frame. Arbitrarily set retrycount to 1024 */
961 correlator = 0;
962 retry_count = 1024;
963 do {
964 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address,
Brian King3449a2a2007-08-17 09:16:49 -0500965 desc.desc, 0, 0, 0, 0, 0,
966 correlator, &correlator);
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200967 } while ((lpar_rc == H_BUSY) && (retry_count--));
Jeff Garzikd7fbeba2006-05-24 01:31:14 -0400968
Segher Boessenkool706c8c92006-03-30 14:49:40 +0200969 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
Brian King3449a2a2007-08-17 09:16:49 -0500971 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n",
Brian King79ef4a42007-08-17 09:16:56 -0500972 (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0,
973 skb->len, desc.fields.address);
Santiago Leon60296d92005-10-26 10:47:16 -0600974 tx_send_failed++;
975 tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 } else {
Santiago Leon60296d92005-10-26 10:47:16 -0600977 tx_packets++;
978 tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
980
Robert Jennings1096d632008-07-24 04:34:52 +1000981 if (!used_bounce)
982 dma_unmap_single(&adapter->vdev->dev, data_dma_addr,
983 skb->len, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Santiago Leone8cb7eb2010-09-03 18:28:15 +0000985out:
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700986 netdev->stats.tx_dropped += tx_dropped;
987 netdev->stats.tx_bytes += tx_bytes;
988 netdev->stats.tx_packets += tx_packets;
Santiago Leon60296d92005-10-26 10:47:16 -0600989 adapter->tx_send_failed += tx_send_failed;
990 adapter->tx_map_failed += tx_map_failed;
Santiago Leon60296d92005-10-26 10:47:16 -0600991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 dev_kfree_skb(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000993 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700996static int ibmveth_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700998 struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi);
999 struct net_device *netdev = adapter->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 int frames_processed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 unsigned long lpar_rc;
1002
1003 restart_poll:
1004 do {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001005 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001007 if (!ibmveth_rxq_pending_buffer(adapter))
1008 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001010 rmb();
1011 if (!ibmveth_rxq_buffer_valid(adapter)) {
1012 wmb(); /* suggested by larson1 */
1013 adapter->rx_invalid_buffer++;
1014 ibmveth_debug_printk("recycling invalid buffer\n");
1015 ibmveth_rxq_recycle_buffer(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 } else {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001017 int length = ibmveth_rxq_frame_length(adapter);
1018 int offset = ibmveth_rxq_frame_offset(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001019 int csum_good = ibmveth_rxq_csum_good(adapter);
1020
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001021 skb = ibmveth_rxq_get_buffer(adapter);
Brian Kingf4ff2872007-09-15 13:36:07 -07001022 if (csum_good)
1023 skb->ip_summed = CHECKSUM_UNNECESSARY;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001024
1025 ibmveth_rxq_harvest_buffer(adapter);
1026
1027 skb_reserve(skb, offset);
1028 skb_put(skb, length);
1029 skb->protocol = eth_type_trans(skb, netdev);
1030
1031 netif_receive_skb(skb); /* send it up */
1032
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001033 netdev->stats.rx_packets++;
1034 netdev->stats.rx_bytes += length;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001035 frames_processed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001037 } while (frames_processed < budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Santiago Leone2adbcb2005-10-26 10:47:08 -06001039 ibmveth_replenish_task(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001041 if (frames_processed < budget) {
1042 /* We think we are done - reenable interrupts,
1043 * then check once more to make sure we are done.
1044 */
1045 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1046 VIO_IRQ_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001048 ibmveth_assert(lpar_rc == H_SUCCESS);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001049
Ben Hutchings288379f2009-01-19 16:43:59 -08001050 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001051
1052 if (ibmveth_rxq_pending_buffer(adapter) &&
Ben Hutchings288379f2009-01-19 16:43:59 -08001053 napi_reschedule(napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001054 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1055 VIO_IRQ_DISABLE);
1056 goto restart_poll;
1057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
1059
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001060 return frames_processed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
David Howells7d12e782006-10-05 14:55:46 +01001063static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance)
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 struct net_device *netdev = dev_instance;
Wang Chen4cf16532008-11-12 23:38:14 -08001066 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 unsigned long lpar_rc;
1068
Ben Hutchings288379f2009-01-19 16:43:59 -08001069 if (napi_schedule_prep(&adapter->napi)) {
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001070 lpar_rc = h_vio_signal(adapter->vdev->unit_address,
1071 VIO_IRQ_DISABLE);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001072 ibmveth_assert(lpar_rc == H_SUCCESS);
Ben Hutchings288379f2009-01-19 16:43:59 -08001073 __napi_schedule(&adapter->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
1075 return IRQ_HANDLED;
1076}
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078static void ibmveth_set_multicast_list(struct net_device *netdev)
1079{
Wang Chen4cf16532008-11-12 23:38:14 -08001080 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 unsigned long lpar_rc;
1082
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001083 if ((netdev->flags & IFF_PROMISC) ||
1084 (netdev_mc_count(netdev) > adapter->mcastFilterSize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1086 IbmVethMcastEnableRecv |
1087 IbmVethMcastDisableFiltering,
1088 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001089 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
1091 }
1092 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001093 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /* clear the filter table & disable filtering */
1095 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1096 IbmVethMcastEnableRecv |
1097 IbmVethMcastDisableFiltering |
1098 IbmVethMcastClearFilterTable,
1099 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001100 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
1102 }
1103 /* add the addresses to the filter table */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001104 netdev_for_each_mc_addr(ha, netdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 // add the multicast address to the filter table
1106 unsigned long mcast_addr = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001107 memcpy(((char *)&mcast_addr)+2, ha->addr, 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1109 IbmVethMcastAddFilter,
1110 mcast_addr);
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 adding an entry to the filter table\n", lpar_rc);
1113 }
1114 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 /* re-enable filtering */
1117 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1118 IbmVethMcastEnableFiltering,
1119 0);
Segher Boessenkool706c8c92006-03-30 14:49:40 +02001120 if(lpar_rc != H_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
1122 }
1123 }
1124}
1125
1126static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1127{
Wang Chen4cf16532008-11-12 23:38:14 -08001128 struct ibmveth_adapter *adapter = netdev_priv(dev);
Robert Jennings1096d632008-07-24 04:34:52 +10001129 struct vio_dev *viodev = adapter->vdev;
Santiago Leon860f2422006-04-25 11:19:59 -05001130 int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH;
Robert Jennings0645bab2010-08-17 09:15:45 +00001131 int i, rc;
1132 int need_restart = 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001133
Santiago Leon860f2422006-04-25 11:19:59 -05001134 if (new_mtu < IBMVETH_MAX_MTU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 return -EINVAL;
Santiago Leonb6d35182005-10-26 10:47:01 -06001136
Brian Kingce6eea52007-06-08 14:05:17 -05001137 for (i = 0; i < IbmVethNumBufferPools; i++)
1138 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size)
1139 break;
1140
1141 if (i == IbmVethNumBufferPools)
1142 return -EINVAL;
1143
Santiago Leonea866e62008-07-24 04:34:23 +10001144 /* Deactivate all the buffer pools so that the next loop can activate
1145 only the buffer pools necessary to hold the new MTU */
Robert Jennings0645bab2010-08-17 09:15:45 +00001146 if (netif_running(adapter->netdev)) {
1147 need_restart = 1;
1148 adapter->pool_config = 1;
1149 ibmveth_close(adapter->netdev);
1150 adapter->pool_config = 0;
1151 }
Brian Kingce6eea52007-06-08 14:05:17 -05001152
Santiago Leonea866e62008-07-24 04:34:23 +10001153 /* Look for an active buffer pool that can hold the new MTU */
1154 for(i = 0; i<IbmVethNumBufferPools; i++) {
1155 adapter->rx_buff_pool[i].active = 1;
1156
Santiago Leon860f2422006-04-25 11:19:59 -05001157 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) {
Robert Jennings1096d632008-07-24 04:34:52 +10001158 dev->mtu = new_mtu;
1159 vio_cmo_set_dev_desired(viodev,
1160 ibmveth_get_desired_dma
1161 (viodev));
Robert Jennings0645bab2010-08-17 09:15:45 +00001162 if (need_restart) {
1163 return ibmveth_open(adapter->netdev);
1164 }
Santiago Leon860f2422006-04-25 11:19:59 -05001165 return 0;
Santiago Leonb6d35182005-10-26 10:47:01 -06001166 }
Santiago Leonb6d35182005-10-26 10:47:01 -06001167 }
Robert Jennings0645bab2010-08-17 09:15:45 +00001168
1169 if (need_restart && (rc = ibmveth_open(adapter->netdev)))
1170 return rc;
1171
Santiago Leon860f2422006-04-25 11:19:59 -05001172 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Santiago Leon6b422372006-10-03 12:24:28 -05001175#ifdef CONFIG_NET_POLL_CONTROLLER
1176static void ibmveth_poll_controller(struct net_device *dev)
1177{
Wang Chen4cf16532008-11-12 23:38:14 -08001178 ibmveth_replenish_task(netdev_priv(dev));
Andrew Morton5f771132006-10-10 14:33:30 -07001179 ibmveth_interrupt(dev->irq, dev);
Santiago Leon6b422372006-10-03 12:24:28 -05001180}
1181#endif
1182
Robert Jennings1096d632008-07-24 04:34:52 +10001183/**
1184 * ibmveth_get_desired_dma - Calculate IO memory desired by the driver
1185 *
1186 * @vdev: struct vio_dev for the device whose desired IO mem is to be returned
1187 *
1188 * Return value:
1189 * Number of bytes of IO data the driver will need to perform well.
1190 */
1191static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev)
1192{
1193 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
1194 struct ibmveth_adapter *adapter;
1195 unsigned long ret;
1196 int i;
1197 int rxqentries = 1;
1198
1199 /* netdev inits at probe time along with the structures we need below*/
1200 if (netdev == NULL)
1201 return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT);
1202
1203 adapter = netdev_priv(netdev);
1204
1205 ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE;
1206 ret += IOMMU_PAGE_ALIGN(netdev->mtu);
1207
1208 for (i = 0; i < IbmVethNumBufferPools; i++) {
1209 /* add the size of the active receive buffers */
1210 if (adapter->rx_buff_pool[i].active)
1211 ret +=
1212 adapter->rx_buff_pool[i].size *
1213 IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i].
1214 buff_size);
1215 rxqentries += adapter->rx_buff_pool[i].size;
1216 }
1217 /* add the size of the receive queue entries */
1218 ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry));
1219
1220 return ret;
1221}
1222
Alexander Beregalove186d172009-04-15 12:52:39 +00001223static const struct net_device_ops ibmveth_netdev_ops = {
1224 .ndo_open = ibmveth_open,
1225 .ndo_stop = ibmveth_close,
1226 .ndo_start_xmit = ibmveth_start_xmit,
1227 .ndo_set_multicast_list = ibmveth_set_multicast_list,
1228 .ndo_do_ioctl = ibmveth_ioctl,
1229 .ndo_change_mtu = ibmveth_change_mtu,
1230 .ndo_validate_addr = eth_validate_addr,
1231 .ndo_set_mac_address = eth_mac_addr,
1232#ifdef CONFIG_NET_POLL_CONTROLLER
1233 .ndo_poll_controller = ibmveth_poll_controller,
1234#endif
1235};
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1238{
Santiago Leonb6d35182005-10-26 10:47:01 -06001239 int rc, i;
Brian Kingf4ff2872007-09-15 13:36:07 -07001240 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 struct net_device *netdev;
Mariusz Kozlowski9dc83af2007-08-06 23:44:03 +02001242 struct ibmveth_adapter *adapter;
Stephen Rothwellff5bfc32009-01-06 10:47:44 -08001243 unsigned long set_attr, ret_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 unsigned char *mac_addr_p;
1246 unsigned int *mcastFilterSize_p;
1247
1248
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001249 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 dev->unit_address);
1251
Michael Ellerman493a6842007-04-17 13:12:55 +10001252 mac_addr_p = (unsigned char *) vio_get_attribute(dev,
1253 VETH_MAC_ADDR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 if(!mac_addr_p) {
1255 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1256 "attribute\n", __FILE__, __LINE__);
1257 return 0;
1258 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001259
Michael Ellerman493a6842007-04-17 13:12:55 +10001260 mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev,
1261 VETH_MCAST_FILTER_SIZE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 if(!mcastFilterSize_p) {
1263 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
1264 "VETH_MCAST_FILTER_SIZE attribute\n",
1265 __FILE__, __LINE__);
1266 return 0;
1267 }
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
1270
1271 if(!netdev)
1272 return -ENOMEM;
1273
Wang Chen4cf16532008-11-12 23:38:14 -08001274 adapter = netdev_priv(netdev);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001275 dev_set_drvdata(&dev->dev, netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 adapter->vdev = dev;
1278 adapter->netdev = netdev;
1279 adapter->mcastFilterSize= *mcastFilterSize_p;
Santiago Leon860f2422006-04-25 11:19:59 -05001280 adapter->pool_config = 0;
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001281
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001282 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 /* Some older boxes running PHYP non-natively have an OF that
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001285 returns a 8-byte local-mac-address field (and the first
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 2 bytes have to be ignored) while newer boxes' OF return
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001287 a 6-byte field. Note that IEEE 1275 specifies that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 local-mac-address must be a 6-byte field.
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001289 The RPA doc specifies that the first byte must be 10b, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 we'll just look for it to solve this 8 vs. 6 byte field issue */
1291
1292 if ((*mac_addr_p & 0x3) != 0x02)
1293 mac_addr_p += 2;
1294
1295 adapter->mac_addr = 0;
1296 memcpy(&adapter->mac_addr, mac_addr_p, 6);
1297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 netdev->irq = dev->irq;
Alexander Beregalove186d172009-04-15 12:52:39 +00001299 netdev->netdev_ops = &ibmveth_netdev_ops;
1300 netdev->ethtool_ops = &netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 SET_NETDEV_DEV(netdev, &dev->dev);
1302
Stephen Rothwelld44b5e02009-05-11 21:44:51 +00001303 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Santiago Leon860f2422006-04-25 11:19:59 -05001305 for(i = 0; i<IbmVethNumBufferPools; i++) {
1306 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001307 int error;
1308
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001309 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1310 pool_count[i], pool_size[i],
Santiago Leon860f2422006-04-25 11:19:59 -05001311 pool_active[i]);
Greg Kroah-Hartman8dde2a92007-12-17 15:54:39 -04001312 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1313 &dev->dev.kobj, "pool%d", i);
1314 if (!error)
1315 kobject_uevent(kobj, KOBJ_ADD);
Santiago Leon860f2422006-04-25 11:19:59 -05001316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 adapter->buffer_list_dma = DMA_ERROR_CODE;
1321 adapter->filter_list_dma = DMA_ERROR_CODE;
1322 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 ibmveth_debug_printk("registering netdev...\n");
1325
Brian King79ef4a42007-08-17 09:16:56 -05001326 ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001327
Brian King79ef4a42007-08-17 09:16:56 -05001328 if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) &&
1329 !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) &&
1330 (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) {
1331 set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM;
Brian Kingf4ff2872007-09-15 13:36:07 -07001332
Brian King79ef4a42007-08-17 09:16:56 -05001333 ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001334
Brian King5fc7e012007-08-17 09:16:31 -05001335 if (ret == H_SUCCESS) {
1336 adapter->rx_csum = 1;
Brian Kingf4ff2872007-09-15 13:36:07 -07001337 netdev->features |= NETIF_F_IP_CSUM;
Brian King5fc7e012007-08-17 09:16:31 -05001338 } else
Brian King79ef4a42007-08-17 09:16:56 -05001339 ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr);
Brian Kingf4ff2872007-09-15 13:36:07 -07001340 }
1341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 rc = register_netdev(netdev);
1343
1344 if(rc) {
1345 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1346 free_netdev(netdev);
1347 return rc;
1348 }
1349
1350 ibmveth_debug_printk("registered\n");
1351
1352 ibmveth_proc_register_adapter(adapter);
1353
1354 return 0;
1355}
1356
1357static int __devexit ibmveth_remove(struct vio_dev *dev)
1358{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001359 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Wang Chen4cf16532008-11-12 23:38:14 -08001360 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001361 int i;
1362
1363 for(i = 0; i<IbmVethNumBufferPools; i++)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001364 kobject_put(&adapter->rx_buff_pool[i].kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
1366 unregister_netdev(netdev);
1367
1368 ibmveth_proc_unregister_adapter(adapter);
1369
1370 free_netdev(netdev);
Robert Jennings1096d632008-07-24 04:34:52 +10001371 dev_set_drvdata(&dev->dev, NULL);
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 return 0;
1374}
1375
1376#ifdef CONFIG_PROC_FS
1377static void ibmveth_proc_register_driver(void)
1378{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001379 ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (ibmveth_proc_dir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382}
1383
1384static void ibmveth_proc_unregister_driver(void)
1385{
Eric W. Biederman457c4cb2007-09-12 12:01:34 +02001386 remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001389static int ibmveth_show(struct seq_file *seq, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391 struct ibmveth_adapter *adapter = seq->private;
Jiri Pirko3a6d54c2009-05-11 23:37:15 +00001392 char *current_mac = (char *) adapter->netdev->dev_addr;
1393 char *firmware_mac = (char *) &adapter->mac_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address);
Johannes Berge1749612008-10-27 15:59:26 -07001398 seq_printf(seq, "Current MAC: %pM\n", current_mac);
1399 seq_printf(seq, "Firmware MAC: %pM\n", firmware_mac);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 seq_printf(seq, "\nAdapter Statistics:\n");
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001402 seq_printf(seq, " TX: vio_map_single failres: %lld\n", adapter->tx_map_failed);
1403 seq_printf(seq, " send failures: %lld\n", adapter->tx_send_failed);
1404 seq_printf(seq, " RX: replenish task cycles: %lld\n", adapter->replenish_task_cycles);
1405 seq_printf(seq, " alloc_skb_failures: %lld\n", adapter->replenish_no_mem);
1406 seq_printf(seq, " add buffer failures: %lld\n", adapter->replenish_add_buff_failure);
1407 seq_printf(seq, " invalid buffers: %lld\n", adapter->rx_invalid_buffer);
1408 seq_printf(seq, " no buffers: %lld\n", adapter->rx_no_buffer);
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 return 0;
1411}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413static int ibmveth_proc_open(struct inode *inode, struct file *file)
1414{
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001415 return single_open(file, ibmveth_show, PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Arjan van de Vend54b1fd2007-02-12 00:55:34 -08001418static const struct file_operations ibmveth_proc_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 .owner = THIS_MODULE,
1420 .open = ibmveth_proc_open,
1421 .read = seq_read,
1422 .llseek = seq_lseek,
Pavel Emelyanov1119d572008-02-18 13:55:10 +03001423 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424};
1425
1426static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1427{
1428 struct proc_dir_entry *entry;
1429 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001430 char u_addr[10];
1431 sprintf(u_addr, "%x", adapter->vdev->unit_address);
Denis V. Luneva95609c2008-04-29 01:02:29 -07001432 entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir,
1433 &ibmveth_proc_fops, adapter);
1434 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 ibmveth_error_printk("Cannot create adapter proc entry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
1439static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1440{
1441 if (ibmveth_proc_dir) {
Santiago Leon03a85d02006-10-03 12:24:39 -05001442 char u_addr[10];
1443 sprintf(u_addr, "%x", adapter->vdev->unit_address);
1444 remove_proc_entry(u_addr, ibmveth_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
1446}
1447
1448#else /* CONFIG_PROC_FS */
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001449static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450{
1451}
1452
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001453static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455}
1456static void ibmveth_proc_register_driver(void)
1457{
1458}
1459
1460static void ibmveth_proc_unregister_driver(void)
1461{
1462}
1463#endif /* CONFIG_PROC_FS */
1464
Santiago Leon860f2422006-04-25 11:19:59 -05001465static struct attribute veth_active_attr;
1466static struct attribute veth_num_attr;
1467static struct attribute veth_size_attr;
1468
1469static ssize_t veth_pool_show(struct kobject * kobj,
1470 struct attribute * attr, char * buf)
1471{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001472 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001473 struct ibmveth_buff_pool,
1474 kobj);
1475
1476 if (attr == &veth_active_attr)
1477 return sprintf(buf, "%d\n", pool->active);
1478 else if (attr == &veth_num_attr)
1479 return sprintf(buf, "%d\n", pool->size);
1480 else if (attr == &veth_size_attr)
1481 return sprintf(buf, "%d\n", pool->buff_size);
1482 return 0;
1483}
1484
1485static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr,
1486const char * buf, size_t count)
1487{
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001488 struct ibmveth_buff_pool *pool = container_of(kobj,
Santiago Leon860f2422006-04-25 11:19:59 -05001489 struct ibmveth_buff_pool,
1490 kobj);
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07001491 struct net_device *netdev = dev_get_drvdata(
1492 container_of(kobj->parent, struct device, kobj));
Wang Chen4cf16532008-11-12 23:38:14 -08001493 struct ibmveth_adapter *adapter = netdev_priv(netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001494 long value = simple_strtol(buf, NULL, 10);
1495 long rc;
1496
1497 if (attr == &veth_active_attr) {
1498 if (value && !pool->active) {
Brian King4aa9c932007-06-08 14:05:16 -05001499 if (netif_running(netdev)) {
1500 if(ibmveth_alloc_buffer_pool(pool)) {
1501 ibmveth_error_printk("unable to alloc pool\n");
1502 return -ENOMEM;
1503 }
1504 pool->active = 1;
1505 adapter->pool_config = 1;
1506 ibmveth_close(netdev);
1507 adapter->pool_config = 0;
1508 if ((rc = ibmveth_open(netdev)))
1509 return rc;
1510 } else
1511 pool->active = 1;
Santiago Leon860f2422006-04-25 11:19:59 -05001512 } else if (!value && pool->active) {
1513 int mtu = netdev->mtu + IBMVETH_BUFF_OH;
1514 int i;
1515 /* Make sure there is a buffer pool with buffers that
1516 can hold a packet of the size of the MTU */
Brian King76b9cfc2007-08-03 13:55:19 +10001517 for (i = 0; i < IbmVethNumBufferPools; i++) {
Santiago Leon860f2422006-04-25 11:19:59 -05001518 if (pool == &adapter->rx_buff_pool[i])
1519 continue;
1520 if (!adapter->rx_buff_pool[i].active)
1521 continue;
Brian King76b9cfc2007-08-03 13:55:19 +10001522 if (mtu <= adapter->rx_buff_pool[i].buff_size)
1523 break;
Santiago Leon860f2422006-04-25 11:19:59 -05001524 }
Brian King76b9cfc2007-08-03 13:55:19 +10001525
1526 if (i == IbmVethNumBufferPools) {
Santiago Leon860f2422006-04-25 11:19:59 -05001527 ibmveth_error_printk("no active pool >= MTU\n");
1528 return -EPERM;
1529 }
Brian King76b9cfc2007-08-03 13:55:19 +10001530
Brian King76b9cfc2007-08-03 13:55:19 +10001531 if (netif_running(netdev)) {
1532 adapter->pool_config = 1;
1533 ibmveth_close(netdev);
Santiago Leonea866e62008-07-24 04:34:23 +10001534 pool->active = 0;
Brian King76b9cfc2007-08-03 13:55:19 +10001535 adapter->pool_config = 0;
1536 if ((rc = ibmveth_open(netdev)))
1537 return rc;
1538 }
Santiago Leonea866e62008-07-24 04:34:23 +10001539 pool->active = 0;
Santiago Leon860f2422006-04-25 11:19:59 -05001540 }
1541 } else if (attr == &veth_num_attr) {
1542 if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT)
1543 return -EINVAL;
1544 else {
Brian King4aa9c932007-06-08 14:05:16 -05001545 if (netif_running(netdev)) {
1546 adapter->pool_config = 1;
1547 ibmveth_close(netdev);
1548 adapter->pool_config = 0;
1549 pool->size = value;
1550 if ((rc = ibmveth_open(netdev)))
1551 return rc;
1552 } else
1553 pool->size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001554 }
1555 } else if (attr == &veth_size_attr) {
1556 if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE)
1557 return -EINVAL;
1558 else {
Brian King4aa9c932007-06-08 14:05:16 -05001559 if (netif_running(netdev)) {
1560 adapter->pool_config = 1;
1561 ibmveth_close(netdev);
1562 adapter->pool_config = 0;
1563 pool->buff_size = value;
1564 if ((rc = ibmveth_open(netdev)))
1565 return rc;
1566 } else
1567 pool->buff_size = value;
Santiago Leon860f2422006-04-25 11:19:59 -05001568 }
1569 }
1570
1571 /* kick the interrupt handler to allocate/deallocate pools */
David Howells7d12e782006-10-05 14:55:46 +01001572 ibmveth_interrupt(netdev->irq, netdev);
Santiago Leon860f2422006-04-25 11:19:59 -05001573 return count;
1574}
1575
1576
1577#define ATTR(_name, _mode) \
1578 struct attribute veth_##_name##_attr = { \
Tejun Heo7b595752007-06-14 03:45:17 +09001579 .name = __stringify(_name), .mode = _mode, \
Santiago Leon860f2422006-04-25 11:19:59 -05001580 };
1581
1582static ATTR(active, 0644);
1583static ATTR(num, 0644);
1584static ATTR(size, 0644);
1585
1586static struct attribute * veth_pool_attrs[] = {
1587 &veth_active_attr,
1588 &veth_num_attr,
1589 &veth_size_attr,
1590 NULL,
1591};
1592
Emese Revfy52cf25d2010-01-19 02:58:23 +01001593static const struct sysfs_ops veth_pool_ops = {
Santiago Leon860f2422006-04-25 11:19:59 -05001594 .show = veth_pool_show,
1595 .store = veth_pool_store,
1596};
1597
1598static struct kobj_type ktype_veth_pool = {
1599 .release = NULL,
1600 .sysfs_ops = &veth_pool_ops,
1601 .default_attrs = veth_pool_attrs,
1602};
1603
Brian Kinge7a3af52010-05-07 08:56:08 +00001604static int ibmveth_resume(struct device *dev)
1605{
1606 struct net_device *netdev = dev_get_drvdata(dev);
1607 ibmveth_interrupt(netdev->irq, netdev);
1608 return 0;
1609}
Santiago Leon860f2422006-04-25 11:19:59 -05001610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1612 { "network", "IBM,l-lan"},
Stephen Rothwellfb120da2005-08-17 16:42:59 +10001613 { "", "" }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1616
Brian Kinge7a3af52010-05-07 08:56:08 +00001617static struct dev_pm_ops ibmveth_pm_ops = {
1618 .resume = ibmveth_resume
1619};
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621static struct vio_driver ibmveth_driver = {
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001622 .id_table = ibmveth_device_table,
1623 .probe = ibmveth_probe,
1624 .remove = ibmveth_remove,
Robert Jennings1096d632008-07-24 04:34:52 +10001625 .get_desired_dma = ibmveth_get_desired_dma,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001626 .driver = {
1627 .name = ibmveth_driver_name,
Stephen Rothwell915124d2005-10-24 15:12:22 +10001628 .owner = THIS_MODULE,
Brian Kinge7a3af52010-05-07 08:56:08 +00001629 .pm = &ibmveth_pm_ops,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +10001630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631};
1632
1633static int __init ibmveth_module_init(void)
1634{
1635 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1636
1637 ibmveth_proc_register_driver();
1638
1639 return vio_register_driver(&ibmveth_driver);
1640}
1641
1642static void __exit ibmveth_module_exit(void)
1643{
1644 vio_unregister_driver(&ibmveth_driver);
1645 ibmveth_proc_unregister_driver();
Jeff Garzikd7fbeba2006-05-24 01:31:14 -04001646}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648module_init(ibmveth_module_init);
1649module_exit(ibmveth_module_exit);