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