[PATCH] ibmveth fix buffer pool management
[linux-2.6] / drivers / net / ibmveth.c
1 /**************************************************************************/
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.   */
27 /*                                                                        */ 
28 /**************************************************************************/
29 /*
30   TODO:
31   - remove frag processing code - no longer needed
32   - add support for sysfs
33   - possibly remove procfs support
34 */
35
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/version.h>
39 #include <linux/types.h>
40 #include <linux/errno.h>
41 #include <linux/ioport.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/kernel.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/skbuff.h>
47 #include <linux/init.h>
48 #include <linux/delay.h>
49 #include <linux/mm.h>
50 #include <linux/ethtool.h>
51 #include <linux/proc_fs.h>
52 #include <asm/semaphore.h>
53 #include <asm/hvcall.h>
54 #include <asm/atomic.h>
55 #include <asm/iommu.h>
56 #include <asm/vio.h>
57 #include <asm/uaccess.h>
58 #include <linux/seq_file.h>
59
60 #include "ibmveth.h"
61
62 #define DEBUG 1
63
64 #define ibmveth_printk(fmt, args...) \
65   printk(KERN_INFO "%s: " fmt, __FILE__, ## args)
66
67 #define ibmveth_error_printk(fmt, args...) \
68   printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
69
70 #ifdef DEBUG
71 #define ibmveth_debug_printk_no_adapter(fmt, args...) \
72   printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
73 #define ibmveth_debug_printk(fmt, args...) \
74   printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
75 #define ibmveth_assert(expr) \
76   if(!(expr)) {                                   \
77     printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
78     BUG(); \
79   }
80 #else
81 #define ibmveth_debug_printk_no_adapter(fmt, args...)
82 #define ibmveth_debug_printk(fmt, args...)
83 #define ibmveth_assert(expr) 
84 #endif
85
86 static int ibmveth_open(struct net_device *dev);
87 static int ibmveth_close(struct net_device *dev);
88 static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
89 static int ibmveth_poll(struct net_device *dev, int *budget);
90 static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *dev);
91 static struct net_device_stats *ibmveth_get_stats(struct net_device *dev);
92 static void ibmveth_set_multicast_list(struct net_device *dev);
93 static int ibmveth_change_mtu(struct net_device *dev, int new_mtu);
94 static void ibmveth_proc_register_driver(void);
95 static void ibmveth_proc_unregister_driver(void);
96 static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
97 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
98 static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
99 static inline void ibmveth_schedule_replenishing(struct ibmveth_adapter*);
100 static inline void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
101
102 #ifdef CONFIG_PROC_FS
103 #define IBMVETH_PROC_DIR "net/ibmveth"
104 static struct proc_dir_entry *ibmveth_proc_dir;
105 #endif
106
107 static const char ibmveth_driver_name[] = "ibmveth";
108 static const char ibmveth_driver_string[] = "IBM i/pSeries Virtual Ethernet Driver";
109 #define ibmveth_driver_version "1.03"
110
111 MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>");
112 MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver");
113 MODULE_LICENSE("GPL");
114 MODULE_VERSION(ibmveth_driver_version);
115
116 /* simple methods of getting data from the current rxq entry */
117 static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter)
118 {
119         return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].toggle == adapter->rx_queue.toggle);
120 }
121
122 static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter)
123 {
124         return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].valid);
125 }
126
127 static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
128 {
129         return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].offset);
130 }
131
132 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
133 {
134         return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
135 }
136
137 /* setup the initial settings for a buffer pool */
138 static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool, u32 pool_index, u32 pool_size, u32 buff_size)
139 {
140         pool->size = pool_size;
141         pool->index = pool_index;
142         pool->buff_size = buff_size;
143         pool->threshold = pool_size / 2;
144 }
145
146 /* allocate and setup an buffer pool - called during open */
147 static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
148 {
149         int i;
150
151         pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL); 
152
153         if(!pool->free_map) {
154                 return -1;
155         }
156
157         pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL); 
158         if(!pool->dma_addr) {
159                 kfree(pool->free_map);
160                 pool->free_map = NULL;
161                 return -1;
162         }
163
164         pool->skbuff = kmalloc(sizeof(void*) * pool->size, GFP_KERNEL);
165
166         if(!pool->skbuff) {
167                 kfree(pool->dma_addr);
168                 pool->dma_addr = NULL;
169
170                 kfree(pool->free_map);
171                 pool->free_map = NULL;
172                 return -1;
173         }
174
175         memset(pool->skbuff, 0, sizeof(void*) * pool->size);
176         memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size);
177
178         for(i = 0; i < pool->size; ++i) {
179                 pool->free_map[i] = i;
180         }
181
182         atomic_set(&pool->available, 0);
183         pool->producer_index = 0;
184         pool->consumer_index = 0;
185         pool->active = 0;
186
187         return 0;
188 }
189
190 /* replenish the buffers for a pool.  note that we don't need to
191  * skb_reserve these since they are used for incoming...
192  */
193 static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
194 {
195         u32 i;
196         u32 count = pool->size - atomic_read(&pool->available);
197         u32 buffers_added = 0;
198
199         mb();
200
201         for(i = 0; i < count; ++i) {
202                 struct sk_buff *skb;
203                 unsigned int free_index, index;
204                 u64 correlator;
205                 union ibmveth_buf_desc desc;
206                 unsigned long lpar_rc;
207                 dma_addr_t dma_addr;
208
209                 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
210
211                 if(!skb) {
212                         ibmveth_debug_printk("replenish: unable to allocate skb\n");
213                         adapter->replenish_no_mem++;
214                         break;
215                 }
216
217                 free_index = pool->consumer_index++ % pool->size;
218                 index = pool->free_map[free_index];
219         
220                 ibmveth_assert(index != IBM_VETH_INVALID_MAP);
221                 ibmveth_assert(pool->skbuff[index] == NULL);
222
223                 dma_addr = dma_map_single(&adapter->vdev->dev, skb->data,
224                                 pool->buff_size, DMA_FROM_DEVICE);
225
226                 pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
227                 pool->dma_addr[index] = dma_addr;
228                 pool->skbuff[index] = skb;
229
230                 correlator = ((u64)pool->index << 32) | index;
231                 *(u64*)skb->data = correlator;
232
233                 desc.desc = 0;
234                 desc.fields.valid = 1;
235                 desc.fields.length = pool->buff_size;
236                 desc.fields.address = dma_addr; 
237
238                 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
239                     
240                 if(lpar_rc != H_Success) {
241                         pool->free_map[free_index] = IBM_VETH_INVALID_MAP;
242                         pool->skbuff[index] = NULL;
243                         pool->consumer_index--;
244                         dma_unmap_single(&adapter->vdev->dev,
245                                         pool->dma_addr[index], pool->buff_size,
246                                         DMA_FROM_DEVICE);
247                         dev_kfree_skb_any(skb);
248                         adapter->replenish_add_buff_failure++;
249                         break;
250                 } else {
251                         buffers_added++;
252                         adapter->replenish_add_buff_success++;
253                 }
254         }
255     
256         mb();
257         atomic_add(buffers_added, &(pool->available));
258 }
259
260 /* check if replenishing is needed.  */
261 static inline int ibmveth_is_replenishing_needed(struct ibmveth_adapter *adapter)
262 {
263         int i;
264
265         for(i = 0; i < IbmVethNumBufferPools; i++)
266                 if(adapter->rx_buff_pool[i].active &&
267                   (atomic_read(&adapter->rx_buff_pool[i].available) <
268                    adapter->rx_buff_pool[i].threshold))
269                         return 1;
270         return 0;
271 }
272
273 /* kick the replenish tasklet if we need replenishing and it isn't already running */
274 static inline void ibmveth_schedule_replenishing(struct ibmveth_adapter *adapter)
275 {
276         if(ibmveth_is_replenishing_needed(adapter) &&
277            (atomic_dec_if_positive(&adapter->not_replenishing) == 0)) {
278                 schedule_work(&adapter->replenish_task);
279         }
280 }
281
282 /* replenish tasklet routine */
283 static void ibmveth_replenish_task(struct ibmveth_adapter *adapter) 
284 {
285         int i;
286
287         adapter->replenish_task_cycles++;
288
289         for(i = 0; i < IbmVethNumBufferPools; i++)
290                 if(adapter->rx_buff_pool[i].active)
291                         ibmveth_replenish_buffer_pool(adapter, 
292                                                      &adapter->rx_buff_pool[i]);
293
294         adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
295
296         atomic_inc(&adapter->not_replenishing);
297
298         ibmveth_schedule_replenishing(adapter);
299 }
300
301 /* empty and free ana buffer pool - also used to do cleanup in error paths */
302 static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool)
303 {
304         int i;
305
306         if(pool->free_map) {
307                 kfree(pool->free_map);
308                 pool->free_map  = NULL;
309         }
310
311         if(pool->skbuff && pool->dma_addr) {
312                 for(i = 0; i < pool->size; ++i) {
313                         struct sk_buff *skb = pool->skbuff[i];
314                         if(skb) {
315                                 dma_unmap_single(&adapter->vdev->dev,
316                                                  pool->dma_addr[i],
317                                                  pool->buff_size,
318                                                  DMA_FROM_DEVICE);
319                                 dev_kfree_skb_any(skb);
320                                 pool->skbuff[i] = NULL;
321                         }
322                 }
323         }
324
325         if(pool->dma_addr) {
326                 kfree(pool->dma_addr);
327                 pool->dma_addr = NULL;
328         }
329
330         if(pool->skbuff) {
331                 kfree(pool->skbuff);
332                 pool->skbuff = NULL;
333         }
334         pool->active = 0;
335 }
336
337 /* remove a buffer from a pool */
338 static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator)
339 {
340         unsigned int pool  = correlator >> 32;
341         unsigned int index = correlator & 0xffffffffUL;
342         unsigned int free_index;
343         struct sk_buff *skb;
344
345         ibmveth_assert(pool < IbmVethNumBufferPools);
346         ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
347
348         skb = adapter->rx_buff_pool[pool].skbuff[index];
349
350         ibmveth_assert(skb != NULL);
351
352         adapter->rx_buff_pool[pool].skbuff[index] = NULL;
353
354         dma_unmap_single(&adapter->vdev->dev,
355                          adapter->rx_buff_pool[pool].dma_addr[index],
356                          adapter->rx_buff_pool[pool].buff_size,
357                          DMA_FROM_DEVICE);
358
359         free_index = adapter->rx_buff_pool[pool].producer_index++ % adapter->rx_buff_pool[pool].size;
360         adapter->rx_buff_pool[pool].free_map[free_index] = index;
361
362         mb();
363
364         atomic_dec(&(adapter->rx_buff_pool[pool].available));
365 }
366
367 /* get the current buffer on the rx queue */
368 static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter)
369 {
370         u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator;
371         unsigned int pool = correlator >> 32;
372         unsigned int index = correlator & 0xffffffffUL;
373
374         ibmveth_assert(pool < IbmVethNumBufferPools);
375         ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
376
377         return adapter->rx_buff_pool[pool].skbuff[index];
378 }
379
380 /* recycle the current buffer on the rx queue */
381 static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
382 {
383         u32 q_index = adapter->rx_queue.index;
384         u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator;
385         unsigned int pool = correlator >> 32;
386         unsigned int index = correlator & 0xffffffffUL;
387         union ibmveth_buf_desc desc;
388         unsigned long lpar_rc;
389
390         ibmveth_assert(pool < IbmVethNumBufferPools);
391         ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
392
393         if(!adapter->rx_buff_pool[pool].active) {
394                 ibmveth_rxq_harvest_buffer(adapter);
395                 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
396                 return;
397         }
398
399         desc.desc = 0;
400         desc.fields.valid = 1;
401         desc.fields.length = adapter->rx_buff_pool[pool].buff_size;
402         desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index];
403
404         lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
405                     
406         if(lpar_rc != H_Success) {
407                 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
408                 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
409         }
410
411         if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
412                 adapter->rx_queue.index = 0;
413                 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
414         }
415 }
416
417 static inline void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
418 {
419         ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
420
421         if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) {
422                 adapter->rx_queue.index = 0;
423                 adapter->rx_queue.toggle = !adapter->rx_queue.toggle;
424         }
425 }
426
427 static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
428 {
429         int i;
430
431         if(adapter->buffer_list_addr != NULL) {
432                 if(!dma_mapping_error(adapter->buffer_list_dma)) {
433                         dma_unmap_single(&adapter->vdev->dev,
434                                         adapter->buffer_list_dma, 4096,
435                                         DMA_BIDIRECTIONAL);
436                         adapter->buffer_list_dma = DMA_ERROR_CODE;
437                 }
438                 free_page((unsigned long)adapter->buffer_list_addr);
439                 adapter->buffer_list_addr = NULL;
440         } 
441
442         if(adapter->filter_list_addr != NULL) {
443                 if(!dma_mapping_error(adapter->filter_list_dma)) {
444                         dma_unmap_single(&adapter->vdev->dev,
445                                         adapter->filter_list_dma, 4096,
446                                         DMA_BIDIRECTIONAL);
447                         adapter->filter_list_dma = DMA_ERROR_CODE;
448                 }
449                 free_page((unsigned long)adapter->filter_list_addr);
450                 adapter->filter_list_addr = NULL;
451         }
452
453         if(adapter->rx_queue.queue_addr != NULL) {
454                 if(!dma_mapping_error(adapter->rx_queue.queue_dma)) {
455                         dma_unmap_single(&adapter->vdev->dev,
456                                         adapter->rx_queue.queue_dma,
457                                         adapter->rx_queue.queue_len,
458                                         DMA_BIDIRECTIONAL);
459                         adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
460                 }
461                 kfree(adapter->rx_queue.queue_addr);
462                 adapter->rx_queue.queue_addr = NULL;
463         }
464
465         for(i = 0; i<IbmVethNumBufferPools; i++)
466                 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[i]);
467 }
468
469 static int ibmveth_open(struct net_device *netdev)
470 {
471         struct ibmveth_adapter *adapter = netdev->priv;
472         u64 mac_address = 0;
473         int rxq_entries = 1;
474         unsigned long lpar_rc;
475         int rc;
476         union ibmveth_buf_desc rxq_desc;
477         int i;
478
479         ibmveth_debug_printk("open starting\n");
480
481         for(i = 0; i<IbmVethNumBufferPools; i++)
482                 rxq_entries += adapter->rx_buff_pool[i].size;
483     
484         adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
485         adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
486  
487         if(!adapter->buffer_list_addr || !adapter->filter_list_addr) {
488                 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
489                 ibmveth_cleanup(adapter);
490                 return -ENOMEM;
491         }
492
493         adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries;
494         adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL);
495
496         if(!adapter->rx_queue.queue_addr) {
497                 ibmveth_error_printk("unable to allocate rx queue pages\n");
498                 ibmveth_cleanup(adapter);
499                 return -ENOMEM;
500         }
501
502         adapter->buffer_list_dma = dma_map_single(&adapter->vdev->dev,
503                         adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL);
504         adapter->filter_list_dma = dma_map_single(&adapter->vdev->dev,
505                         adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL);
506         adapter->rx_queue.queue_dma = dma_map_single(&adapter->vdev->dev,
507                         adapter->rx_queue.queue_addr,
508                         adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL);
509
510         if((dma_mapping_error(adapter->buffer_list_dma) ) ||
511            (dma_mapping_error(adapter->filter_list_dma)) ||
512            (dma_mapping_error(adapter->rx_queue.queue_dma))) {
513                 ibmveth_error_printk("unable to map filter or buffer list pages\n");
514                 ibmveth_cleanup(adapter);
515                 return -ENOMEM;
516         }
517
518         adapter->rx_queue.index = 0;
519         adapter->rx_queue.num_slots = rxq_entries;
520         adapter->rx_queue.toggle = 1;
521
522         /* call change_mtu to init the buffer pools based in initial mtu */
523         ibmveth_change_mtu(netdev, netdev->mtu);
524
525         memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
526         mac_address = mac_address >> 16;
527
528         rxq_desc.desc = 0;
529         rxq_desc.fields.valid = 1;
530         rxq_desc.fields.length = adapter->rx_queue.queue_len;
531         rxq_desc.fields.address = adapter->rx_queue.queue_dma;
532
533         ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr);
534         ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr);
535         ibmveth_debug_printk("receive q   @ 0x%p\n", adapter->rx_queue.queue_addr);
536
537     
538         lpar_rc = h_register_logical_lan(adapter->vdev->unit_address,
539                                          adapter->buffer_list_dma,
540                                          rxq_desc.desc,
541                                          adapter->filter_list_dma,
542                                          mac_address);
543
544         if(lpar_rc != H_Success) {
545                 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
546                 ibmveth_error_printk("buffer TCE:0x%x filter TCE:0x%x rxq desc:0x%lx MAC:0x%lx\n",
547                                      adapter->buffer_list_dma,
548                                      adapter->filter_list_dma,
549                                      rxq_desc.desc,
550                                      mac_address);
551                 ibmveth_cleanup(adapter);
552                 return -ENONET; 
553         }
554
555         ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq);
556         if((rc = request_irq(netdev->irq, &ibmveth_interrupt, 0, netdev->name, netdev)) != 0) {
557                 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
558                 do {
559                         rc = h_free_logical_lan(adapter->vdev->unit_address);
560                 } while (H_isLongBusy(rc) || (rc == H_Busy));
561
562                 ibmveth_cleanup(adapter);
563                 return rc;
564         }
565
566         netif_start_queue(netdev);
567
568         ibmveth_debug_printk("scheduling initial replenish cycle\n");
569         ibmveth_schedule_replenishing(adapter);
570
571         ibmveth_debug_printk("open complete\n");
572
573         return 0;
574 }
575
576 static int ibmveth_close(struct net_device *netdev)
577 {
578         struct ibmveth_adapter *adapter = netdev->priv;
579         long lpar_rc;
580     
581         ibmveth_debug_printk("close starting\n");
582
583         netif_stop_queue(netdev);
584
585         free_irq(netdev->irq, netdev);
586
587         cancel_delayed_work(&adapter->replenish_task);
588         flush_scheduled_work();
589
590         do {
591                 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
592         } while (H_isLongBusy(lpar_rc) || (lpar_rc == H_Busy));
593
594         if(lpar_rc != H_Success)
595         {
596                 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
597                                      lpar_rc);
598         }
599
600         adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
601
602         ibmveth_cleanup(adapter);
603
604         ibmveth_debug_printk("close complete\n");
605
606         return 0;
607 }
608
609 static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
610         cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE);
611         cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE);
612         cmd->speed = SPEED_1000;
613         cmd->duplex = DUPLEX_FULL;
614         cmd->port = PORT_FIBRE;
615         cmd->phy_address = 0;
616         cmd->transceiver = XCVR_INTERNAL;
617         cmd->autoneg = AUTONEG_ENABLE;
618         cmd->maxtxpkt = 0;
619         cmd->maxrxpkt = 1;
620         return 0;
621 }
622
623 static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) {
624         strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1);
625         strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1);
626 }
627
628 static u32 netdev_get_link(struct net_device *dev) {
629         return 1;
630 }
631
632 static struct ethtool_ops netdev_ethtool_ops = {
633         .get_drvinfo            = netdev_get_drvinfo,
634         .get_settings           = netdev_get_settings,
635         .get_link               = netdev_get_link,
636         .get_sg                 = ethtool_op_get_sg,
637         .get_tx_csum            = ethtool_op_get_tx_csum,
638 };
639
640 static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
641 {
642         return -EOPNOTSUPP;
643 }
644
645 #define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
646
647 static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
648 {
649         struct ibmveth_adapter *adapter = netdev->priv;
650         union ibmveth_buf_desc desc[IbmVethMaxSendFrags];
651         unsigned long lpar_rc;
652         int nfrags = 0, curfrag;
653         unsigned long correlator;
654         unsigned int retry_count;
655
656         if ((skb_shinfo(skb)->nr_frags + 1) > IbmVethMaxSendFrags) {
657                 adapter->stats.tx_dropped++;
658                 dev_kfree_skb(skb);
659                 return 0;
660         }
661
662         memset(&desc, 0, sizeof(desc));
663
664         /* nfrags = number of frags after the initial fragment */
665         nfrags = skb_shinfo(skb)->nr_frags;
666
667         if(nfrags)
668                 adapter->tx_multidesc_send++;
669
670         /* map the initial fragment */
671         desc[0].fields.length  = nfrags ? skb->len - skb->data_len : skb->len;
672         desc[0].fields.address = dma_map_single(&adapter->vdev->dev, skb->data,
673                                         desc[0].fields.length, DMA_TO_DEVICE);
674         desc[0].fields.valid   = 1;
675
676         if(dma_mapping_error(desc[0].fields.address)) {
677                 ibmveth_error_printk("tx: unable to map initial fragment\n");
678                 adapter->tx_map_failed++;
679                 adapter->stats.tx_dropped++;
680                 dev_kfree_skb(skb);
681                 return 0;
682         }
683
684         curfrag = nfrags;
685
686         /* map fragments past the initial portion if there are any */
687         while(curfrag--) {
688                 skb_frag_t *frag = &skb_shinfo(skb)->frags[curfrag];
689                 desc[curfrag+1].fields.address
690                         = dma_map_single(&adapter->vdev->dev,
691                                 page_address(frag->page) + frag->page_offset,
692                                 frag->size, DMA_TO_DEVICE);
693                 desc[curfrag+1].fields.length = frag->size;
694                 desc[curfrag+1].fields.valid  = 1;
695
696                 if(dma_mapping_error(desc[curfrag+1].fields.address)) {
697                         ibmveth_error_printk("tx: unable to map fragment %d\n", curfrag);
698                         adapter->tx_map_failed++;
699                         adapter->stats.tx_dropped++;
700                         /* Free all the mappings we just created */
701                         while(curfrag < nfrags) {
702                                 dma_unmap_single(&adapter->vdev->dev,
703                                                  desc[curfrag+1].fields.address,
704                                                  desc[curfrag+1].fields.length,
705                                                  DMA_TO_DEVICE);
706                                 curfrag++;
707                         }
708                         dev_kfree_skb(skb);
709                         return 0;
710                 }
711         }
712
713         /* send the frame. Arbitrarily set retrycount to 1024 */
714         correlator = 0;
715         retry_count = 1024;
716         do {
717                 lpar_rc = h_send_logical_lan(adapter->vdev->unit_address,
718                                              desc[0].desc,
719                                              desc[1].desc,
720                                              desc[2].desc,
721                                              desc[3].desc,
722                                              desc[4].desc,
723                                              desc[5].desc,
724                                              correlator);
725         } while ((lpar_rc == H_Busy) && (retry_count--));
726     
727         if(lpar_rc != H_Success && lpar_rc != H_Dropped) {
728                 int i;
729                 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
730                 for(i = 0; i < 6; i++) {
731                         ibmveth_error_printk("tx: desc[%i] valid=%d, len=%d, address=0x%d\n", i,
732                                              desc[i].fields.valid, desc[i].fields.length, desc[i].fields.address);
733                 }
734                 adapter->tx_send_failed++;
735                 adapter->stats.tx_dropped++;
736         } else {
737                 adapter->stats.tx_packets++;
738                 adapter->stats.tx_bytes += skb->len;
739                 netdev->trans_start = jiffies;
740         }
741
742         do {
743                 dma_unmap_single(&adapter->vdev->dev,
744                                 desc[nfrags].fields.address,
745                                 desc[nfrags].fields.length, DMA_TO_DEVICE);
746         } while(--nfrags >= 0);
747
748         dev_kfree_skb(skb);
749         return 0;
750 }
751
752 static int ibmveth_poll(struct net_device *netdev, int *budget)
753 {
754         struct ibmveth_adapter *adapter = netdev->priv;
755         int max_frames_to_process = netdev->quota;
756         int frames_processed = 0;
757         int more_work = 1;
758         unsigned long lpar_rc;
759
760  restart_poll:
761         do {
762                 struct net_device *netdev = adapter->netdev;
763
764                 if(ibmveth_rxq_pending_buffer(adapter)) {
765                         struct sk_buff *skb;
766
767                         rmb();
768
769                         if(!ibmveth_rxq_buffer_valid(adapter)) {
770                                 wmb(); /* suggested by larson1 */
771                                 adapter->rx_invalid_buffer++;
772                                 ibmveth_debug_printk("recycling invalid buffer\n");
773                                 ibmveth_rxq_recycle_buffer(adapter);
774                         } else {
775                                 int length = ibmveth_rxq_frame_length(adapter);
776                                 int offset = ibmveth_rxq_frame_offset(adapter);
777                                 skb = ibmveth_rxq_get_buffer(adapter);
778
779                                 ibmveth_rxq_harvest_buffer(adapter);
780
781                                 skb_reserve(skb, offset);
782                                 skb_put(skb, length);
783                                 skb->dev = netdev;
784                                 skb->protocol = eth_type_trans(skb, netdev);
785
786                                 netif_receive_skb(skb); /* send it up */
787
788                                 adapter->stats.rx_packets++;
789                                 adapter->stats.rx_bytes += length;
790                                 frames_processed++;
791                                 netdev->last_rx = jiffies;
792                         }
793                 } else {
794                         more_work = 0;
795                 }
796         } while(more_work && (frames_processed < max_frames_to_process));
797
798         ibmveth_schedule_replenishing(adapter);
799
800         if(more_work) {
801                 /* more work to do - return that we are not done yet */
802                 netdev->quota -= frames_processed;
803                 *budget -= frames_processed;
804                 return 1; 
805         }
806
807         /* we think we are done - reenable interrupts, then check once more to make sure we are done */
808         lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_ENABLE);
809
810         ibmveth_assert(lpar_rc == H_Success);
811
812         netif_rx_complete(netdev);
813
814         if(ibmveth_rxq_pending_buffer(adapter) && netif_rx_reschedule(netdev, frames_processed))
815         {
816                 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
817                 ibmveth_assert(lpar_rc == H_Success);
818                 more_work = 1;
819                 goto restart_poll;
820         }
821
822         netdev->quota -= frames_processed;
823         *budget -= frames_processed;
824
825         /* we really are done */
826         return 0;
827 }
828
829 static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
830 {   
831         struct net_device *netdev = dev_instance;
832         struct ibmveth_adapter *adapter = netdev->priv;
833         unsigned long lpar_rc;
834
835         if(netif_rx_schedule_prep(netdev)) {
836                 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
837                 ibmveth_assert(lpar_rc == H_Success);
838                 __netif_rx_schedule(netdev);
839         }
840         return IRQ_HANDLED;
841 }
842
843 static struct net_device_stats *ibmveth_get_stats(struct net_device *dev)
844 {
845         struct ibmveth_adapter *adapter = dev->priv;
846         return &adapter->stats;
847 }
848
849 static void ibmveth_set_multicast_list(struct net_device *netdev)
850 {
851         struct ibmveth_adapter *adapter = netdev->priv;
852         unsigned long lpar_rc;
853
854         if((netdev->flags & IFF_PROMISC) || (netdev->mc_count > adapter->mcastFilterSize)) {
855                 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
856                                            IbmVethMcastEnableRecv |
857                                            IbmVethMcastDisableFiltering,
858                                            0);
859                 if(lpar_rc != H_Success) {
860                         ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
861                 }
862         } else {
863                 struct dev_mc_list *mclist = netdev->mc_list;
864                 int i;
865                 /* clear the filter table & disable filtering */
866                 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
867                                            IbmVethMcastEnableRecv |
868                                            IbmVethMcastDisableFiltering |
869                                            IbmVethMcastClearFilterTable,
870                                            0);
871                 if(lpar_rc != H_Success) {
872                         ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
873                 }
874                 /* add the addresses to the filter table */
875                 for(i = 0; i < netdev->mc_count; ++i, mclist = mclist->next) {
876                         // add the multicast address to the filter table
877                         unsigned long mcast_addr = 0;
878                         memcpy(((char *)&mcast_addr)+2, mclist->dmi_addr, 6);
879                         lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
880                                                    IbmVethMcastAddFilter,
881                                                    mcast_addr);
882                         if(lpar_rc != H_Success) {
883                                 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
884                         }
885                 }
886         
887                 /* re-enable filtering */
888                 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
889                                            IbmVethMcastEnableFiltering,
890                                            0);
891                 if(lpar_rc != H_Success) {
892                         ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
893                 }
894         }
895 }
896
897 static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
898 {
899         struct ibmveth_adapter *adapter = dev->priv;
900         int i;
901         int prev_smaller = 1;
902
903         if ((new_mtu < 68) || 
904             (new_mtu > (pool_size[IbmVethNumBufferPools-1]) - IBMVETH_BUFF_OH))
905                 return -EINVAL;
906
907         for(i = 0; i<IbmVethNumBufferPools; i++) {
908                 int activate = 0;
909                 if (new_mtu > (pool_size[i]  - IBMVETH_BUFF_OH)) { 
910                         activate = 1;
911                         prev_smaller= 1;
912                 } else {
913                         if (prev_smaller)
914                                 activate = 1;
915                         prev_smaller= 0;
916                 }
917
918                 if (activate && !adapter->rx_buff_pool[i].active) {
919                         struct ibmveth_buff_pool *pool = 
920                                                 &adapter->rx_buff_pool[i];
921                         if(ibmveth_alloc_buffer_pool(pool)) {
922                                 ibmveth_error_printk("unable to alloc pool\n");
923                                 return -ENOMEM;
924                         }
925                         adapter->rx_buff_pool[i].active = 1;
926                 } else if (!activate && adapter->rx_buff_pool[i].active) {
927                         adapter->rx_buff_pool[i].active = 0;
928                         h_free_logical_lan_buffer(adapter->vdev->unit_address,
929                                           (u64)pool_size[i]);
930                 }
931
932         }
933
934
935         ibmveth_schedule_replenishing(adapter);
936         dev->mtu = new_mtu;
937         return 0;       
938 }
939
940 static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
941 {
942         int rc, i;
943         struct net_device *netdev;
944         struct ibmveth_adapter *adapter = NULL;
945
946         unsigned char *mac_addr_p;
947         unsigned int *mcastFilterSize_p;
948
949
950         ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n", 
951                                         dev->unit_address);
952
953         mac_addr_p = (unsigned char *) vio_get_attribute(dev, VETH_MAC_ADDR, 0);
954         if(!mac_addr_p) {
955                 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
956                                 "attribute\n", __FILE__, __LINE__);
957                 return 0;
958         }
959         
960         mcastFilterSize_p= (unsigned int *) vio_get_attribute(dev, VETH_MCAST_FILTER_SIZE, 0);
961         if(!mcastFilterSize_p) {
962                 printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find "
963                                 "VETH_MCAST_FILTER_SIZE attribute\n",
964                                 __FILE__, __LINE__);
965                 return 0;
966         }
967         
968         netdev = alloc_etherdev(sizeof(struct ibmveth_adapter));
969
970         if(!netdev)
971                 return -ENOMEM;
972
973         SET_MODULE_OWNER(netdev);
974
975         adapter = netdev->priv;
976         memset(adapter, 0, sizeof(adapter));
977         dev->dev.driver_data = netdev;
978
979         adapter->vdev = dev;
980         adapter->netdev = netdev;
981         adapter->mcastFilterSize= *mcastFilterSize_p;
982         
983         /*      Some older boxes running PHYP non-natively have an OF that
984                 returns a 8-byte local-mac-address field (and the first 
985                 2 bytes have to be ignored) while newer boxes' OF return
986                 a 6-byte field. Note that IEEE 1275 specifies that 
987                 local-mac-address must be a 6-byte field.
988                 The RPA doc specifies that the first byte must be 10b, so 
989                 we'll just look for it to solve this 8 vs. 6 byte field issue */
990
991         if ((*mac_addr_p & 0x3) != 0x02)
992                 mac_addr_p += 2;
993
994         adapter->mac_addr = 0;
995         memcpy(&adapter->mac_addr, mac_addr_p, 6);
996
997         adapter->liobn = dev->iommu_table->it_index;
998         
999         netdev->irq = dev->irq;
1000         netdev->open               = ibmveth_open;
1001         netdev->poll               = ibmveth_poll;
1002         netdev->weight             = 16;
1003         netdev->stop               = ibmveth_close;
1004         netdev->hard_start_xmit    = ibmveth_start_xmit;
1005         netdev->get_stats          = ibmveth_get_stats;
1006         netdev->set_multicast_list = ibmveth_set_multicast_list;
1007         netdev->do_ioctl           = ibmveth_ioctl;
1008         netdev->ethtool_ops           = &netdev_ethtool_ops;
1009         netdev->change_mtu         = ibmveth_change_mtu;
1010         SET_NETDEV_DEV(netdev, &dev->dev);
1011
1012         memcpy(&netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
1013
1014         for(i = 0; i<IbmVethNumBufferPools; i++)
1015                 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, 
1016                                          pool_count[i], pool_size[i]);
1017
1018         ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
1019
1020         INIT_WORK(&adapter->replenish_task, (void*)ibmveth_replenish_task, (void*)adapter);
1021
1022         adapter->buffer_list_dma = DMA_ERROR_CODE;
1023         adapter->filter_list_dma = DMA_ERROR_CODE;
1024         adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
1025
1026         atomic_set(&adapter->not_replenishing, 1);
1027
1028         ibmveth_debug_printk("registering netdev...\n");
1029
1030         rc = register_netdev(netdev);
1031
1032         if(rc) {
1033                 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc);
1034                 free_netdev(netdev);
1035                 return rc;
1036         }
1037
1038         ibmveth_debug_printk("registered\n");
1039
1040         ibmveth_proc_register_adapter(adapter);
1041
1042         return 0;
1043 }
1044
1045 static int __devexit ibmveth_remove(struct vio_dev *dev)
1046 {
1047         struct net_device *netdev = dev->dev.driver_data;
1048         struct ibmveth_adapter *adapter = netdev->priv;
1049
1050         unregister_netdev(netdev);
1051
1052         ibmveth_proc_unregister_adapter(adapter);
1053
1054         free_netdev(netdev);
1055         return 0;
1056 }
1057
1058 #ifdef CONFIG_PROC_FS
1059 static void ibmveth_proc_register_driver(void)
1060 {
1061         ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, NULL);
1062         if (ibmveth_proc_dir) {
1063                 SET_MODULE_OWNER(ibmveth_proc_dir);
1064         }
1065 }
1066
1067 static void ibmveth_proc_unregister_driver(void)
1068 {
1069         remove_proc_entry(IBMVETH_PROC_DIR, NULL);
1070 }
1071
1072 static void *ibmveth_seq_start(struct seq_file *seq, loff_t *pos) 
1073 {
1074         if (*pos == 0) {
1075                 return (void *)1;
1076         } else {
1077                 return NULL;
1078         }
1079 }
1080
1081 static void *ibmveth_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1082 {
1083         ++*pos;
1084         return NULL;
1085 }
1086
1087 static void ibmveth_seq_stop(struct seq_file *seq, void *v) 
1088 {
1089 }
1090
1091 static int ibmveth_seq_show(struct seq_file *seq, void *v) 
1092 {
1093         struct ibmveth_adapter *adapter = seq->private;
1094         char *current_mac = ((char*) &adapter->netdev->dev_addr);
1095         char *firmware_mac = ((char*) &adapter->mac_addr) ;
1096
1097         seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version);
1098         
1099         seq_printf(seq, "Unit Address:    0x%x\n", adapter->vdev->unit_address);
1100         seq_printf(seq, "LIOBN:           0x%lx\n", adapter->liobn);
1101         seq_printf(seq, "Current MAC:     %02X:%02X:%02X:%02X:%02X:%02X\n",
1102                    current_mac[0], current_mac[1], current_mac[2],
1103                    current_mac[3], current_mac[4], current_mac[5]);
1104         seq_printf(seq, "Firmware MAC:    %02X:%02X:%02X:%02X:%02X:%02X\n",
1105                    firmware_mac[0], firmware_mac[1], firmware_mac[2],
1106                    firmware_mac[3], firmware_mac[4], firmware_mac[5]);
1107         
1108         seq_printf(seq, "\nAdapter Statistics:\n");
1109         seq_printf(seq, "  TX:  skbuffs linearized:          %ld\n", adapter->tx_linearized);
1110         seq_printf(seq, "       multi-descriptor sends:      %ld\n", adapter->tx_multidesc_send);
1111         seq_printf(seq, "       skb_linearize failures:      %ld\n", adapter->tx_linearize_failed);
1112         seq_printf(seq, "       vio_map_single failres:      %ld\n", adapter->tx_map_failed);
1113         seq_printf(seq, "       send failures:               %ld\n", adapter->tx_send_failed);
1114         seq_printf(seq, "  RX:  replenish task cycles:       %ld\n", adapter->replenish_task_cycles);
1115         seq_printf(seq, "       alloc_skb_failures:          %ld\n", adapter->replenish_no_mem);
1116         seq_printf(seq, "       add buffer failures:         %ld\n", adapter->replenish_add_buff_failure);
1117         seq_printf(seq, "       invalid buffers:             %ld\n", adapter->rx_invalid_buffer);
1118         seq_printf(seq, "       no buffers:                  %ld\n", adapter->rx_no_buffer);
1119         
1120         return 0;
1121 }
1122 static struct seq_operations ibmveth_seq_ops = {
1123         .start = ibmveth_seq_start,
1124         .next  = ibmveth_seq_next,
1125         .stop  = ibmveth_seq_stop,
1126         .show  = ibmveth_seq_show,
1127 };
1128
1129 static int ibmveth_proc_open(struct inode *inode, struct file *file)
1130 {
1131         struct seq_file *seq;
1132         struct proc_dir_entry *proc;
1133         int rc;
1134
1135         rc = seq_open(file, &ibmveth_seq_ops);
1136         if (!rc) {
1137                 /* recover the pointer buried in proc_dir_entry data */
1138                 seq = file->private_data;
1139                 proc = PDE(inode);
1140                 seq->private = proc->data;
1141         }
1142         return rc;
1143 }
1144
1145 static struct file_operations ibmveth_proc_fops = {
1146         .owner   = THIS_MODULE,
1147         .open    = ibmveth_proc_open,
1148         .read    = seq_read,
1149         .llseek  = seq_lseek,
1150         .release = seq_release,
1151 };
1152
1153 static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter)
1154 {
1155         struct proc_dir_entry *entry;
1156         if (ibmveth_proc_dir) {
1157                 entry = create_proc_entry(adapter->netdev->name, S_IFREG, ibmveth_proc_dir);
1158                 if (!entry) {
1159                         ibmveth_error_printk("Cannot create adapter proc entry");
1160                 } else {
1161                         entry->data = (void *) adapter;
1162                         entry->proc_fops = &ibmveth_proc_fops;
1163                         SET_MODULE_OWNER(entry);
1164                 }
1165         }
1166         return;
1167 }
1168
1169 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter)
1170 {
1171         if (ibmveth_proc_dir) {
1172                 remove_proc_entry(adapter->netdev->name, ibmveth_proc_dir);
1173         }
1174 }
1175
1176 #else /* CONFIG_PROC_FS */
1177 static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter) 
1178 {
1179 }
1180
1181 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter) 
1182 {
1183 }
1184 static void ibmveth_proc_register_driver(void)
1185 {
1186 }
1187
1188 static void ibmveth_proc_unregister_driver(void)
1189 {
1190 }
1191 #endif /* CONFIG_PROC_FS */
1192
1193 static struct vio_device_id ibmveth_device_table[] __devinitdata= {
1194         { "network", "IBM,l-lan"},
1195         { "", "" }
1196 };
1197
1198 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
1199
1200 static struct vio_driver ibmveth_driver = {
1201         .name        = (char *)ibmveth_driver_name,
1202         .id_table    = ibmveth_device_table,
1203         .probe       = ibmveth_probe,
1204         .remove      = ibmveth_remove
1205 };
1206
1207 static int __init ibmveth_module_init(void)
1208 {
1209         ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version);
1210
1211         ibmveth_proc_register_driver();
1212
1213         return vio_register_driver(&ibmveth_driver);
1214 }
1215
1216 static void __exit ibmveth_module_exit(void)
1217 {
1218         vio_unregister_driver(&ibmveth_driver);
1219         ibmveth_proc_unregister_driver();
1220 }       
1221
1222 module_init(ibmveth_module_init);
1223 module_exit(ibmveth_module_exit);