1 /**************************************************************************/
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) */
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. */
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. */
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 */
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. */
28 /**************************************************************************/
31 - add support for sysfs
32 - possibly remove procfs support
35 #include <linux/module.h>
36 #include <linux/types.h>
37 #include <linux/errno.h>
38 #include <linux/ioport.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/kernel.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/init.h>
45 #include <linux/delay.h>
47 #include <linux/ethtool.h>
48 #include <linux/proc_fs.h>
51 #include <net/net_namespace.h>
52 #include <asm/hvcall.h>
53 #include <asm/atomic.h>
55 #include <asm/uaccess.h>
56 #include <linux/seq_file.h>
62 #define ibmveth_printk(fmt, args...) \
63 printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args)
65 #define ibmveth_error_printk(fmt, args...) \
66 printk(KERN_ERR "(%s:%3.3d ua:%x) ERROR: " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
69 #define ibmveth_debug_printk_no_adapter(fmt, args...) \
70 printk(KERN_DEBUG "(%s:%3.3d): " fmt, __FILE__, __LINE__ , ## args)
71 #define ibmveth_debug_printk(fmt, args...) \
72 printk(KERN_DEBUG "(%s:%3.3d ua:%x): " fmt, __FILE__, __LINE__ , adapter->vdev->unit_address, ## args)
73 #define ibmveth_assert(expr) \
75 printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \
79 #define ibmveth_debug_printk_no_adapter(fmt, args...)
80 #define ibmveth_debug_printk(fmt, args...)
81 #define ibmveth_assert(expr)
84 static int ibmveth_open(struct net_device
*dev
);
85 static int ibmveth_close(struct net_device
*dev
);
86 static int ibmveth_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
87 static int ibmveth_poll(struct napi_struct
*napi
, int budget
);
88 static int ibmveth_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
89 static void ibmveth_set_multicast_list(struct net_device
*dev
);
90 static int ibmveth_change_mtu(struct net_device
*dev
, int new_mtu
);
91 static void ibmveth_proc_register_driver(void);
92 static void ibmveth_proc_unregister_driver(void);
93 static void ibmveth_proc_register_adapter(struct ibmveth_adapter
*adapter
);
94 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter
*adapter
);
95 static irqreturn_t
ibmveth_interrupt(int irq
, void *dev_instance
);
96 static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter
*adapter
);
97 static struct kobj_type ktype_veth_pool
;
100 #define IBMVETH_PROC_DIR "ibmveth"
101 static struct proc_dir_entry
*ibmveth_proc_dir
;
104 static const char ibmveth_driver_name
[] = "ibmveth";
105 static const char ibmveth_driver_string
[] = "IBM i/pSeries Virtual Ethernet Driver";
106 #define ibmveth_driver_version "1.03"
108 MODULE_AUTHOR("Santiago Leon <santil@us.ibm.com>");
109 MODULE_DESCRIPTION("IBM i/pSeries Virtual Ethernet Driver");
110 MODULE_LICENSE("GPL");
111 MODULE_VERSION(ibmveth_driver_version
);
113 struct ibmveth_stat
{
114 char name
[ETH_GSTRING_LEN
];
118 #define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat)
119 #define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off))
121 struct ibmveth_stat ibmveth_stats
[] = {
122 { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles
) },
123 { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem
) },
124 { "replenish_add_buff_failure", IBMVETH_STAT_OFF(replenish_add_buff_failure
) },
125 { "replenish_add_buff_success", IBMVETH_STAT_OFF(replenish_add_buff_success
) },
126 { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer
) },
127 { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer
) },
128 { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed
) },
129 { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed
) },
132 /* simple methods of getting data from the current rxq entry */
133 static inline u32
ibmveth_rxq_flags(struct ibmveth_adapter
*adapter
)
135 return adapter
->rx_queue
.queue_addr
[adapter
->rx_queue
.index
].flags_off
;
138 static inline int ibmveth_rxq_toggle(struct ibmveth_adapter
*adapter
)
140 return (ibmveth_rxq_flags(adapter
) & IBMVETH_RXQ_TOGGLE
) >> IBMVETH_RXQ_TOGGLE_SHIFT
;
143 static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter
*adapter
)
145 return (ibmveth_rxq_toggle(adapter
) == adapter
->rx_queue
.toggle
);
148 static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter
*adapter
)
150 return (ibmveth_rxq_flags(adapter
) & IBMVETH_RXQ_VALID
);
153 static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter
*adapter
)
155 return (ibmveth_rxq_flags(adapter
) & IBMVETH_RXQ_OFF_MASK
);
158 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter
*adapter
)
160 return (adapter
->rx_queue
.queue_addr
[adapter
->rx_queue
.index
].length
);
163 static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter
*adapter
)
165 return (ibmveth_rxq_flags(adapter
) & IBMVETH_RXQ_CSUM_GOOD
);
168 /* setup the initial settings for a buffer pool */
169 static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool
*pool
, u32 pool_index
, u32 pool_size
, u32 buff_size
, u32 pool_active
)
171 pool
->size
= pool_size
;
172 pool
->index
= pool_index
;
173 pool
->buff_size
= buff_size
;
174 pool
->threshold
= pool_size
/ 2;
175 pool
->active
= pool_active
;
178 /* allocate and setup an buffer pool - called during open */
179 static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool
*pool
)
183 pool
->free_map
= kmalloc(sizeof(u16
) * pool
->size
, GFP_KERNEL
);
185 if(!pool
->free_map
) {
189 pool
->dma_addr
= kmalloc(sizeof(dma_addr_t
) * pool
->size
, GFP_KERNEL
);
190 if(!pool
->dma_addr
) {
191 kfree(pool
->free_map
);
192 pool
->free_map
= NULL
;
196 pool
->skbuff
= kmalloc(sizeof(void*) * pool
->size
, GFP_KERNEL
);
199 kfree(pool
->dma_addr
);
200 pool
->dma_addr
= NULL
;
202 kfree(pool
->free_map
);
203 pool
->free_map
= NULL
;
207 memset(pool
->skbuff
, 0, sizeof(void*) * pool
->size
);
208 memset(pool
->dma_addr
, 0, sizeof(dma_addr_t
) * pool
->size
);
210 for(i
= 0; i
< pool
->size
; ++i
) {
211 pool
->free_map
[i
] = i
;
214 atomic_set(&pool
->available
, 0);
215 pool
->producer_index
= 0;
216 pool
->consumer_index
= 0;
221 /* replenish the buffers for a pool. note that we don't need to
222 * skb_reserve these since they are used for incoming...
224 static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter
*adapter
, struct ibmveth_buff_pool
*pool
)
227 u32 count
= pool
->size
- atomic_read(&pool
->available
);
228 u32 buffers_added
= 0;
232 for(i
= 0; i
< count
; ++i
) {
234 unsigned int free_index
, index
;
236 union ibmveth_buf_desc desc
;
237 unsigned long lpar_rc
;
240 skb
= alloc_skb(pool
->buff_size
, GFP_ATOMIC
);
243 ibmveth_debug_printk("replenish: unable to allocate skb\n");
244 adapter
->replenish_no_mem
++;
248 free_index
= pool
->consumer_index
;
249 pool
->consumer_index
= (pool
->consumer_index
+ 1) % pool
->size
;
250 index
= pool
->free_map
[free_index
];
252 ibmveth_assert(index
!= IBM_VETH_INVALID_MAP
);
253 ibmveth_assert(pool
->skbuff
[index
] == NULL
);
255 dma_addr
= dma_map_single(&adapter
->vdev
->dev
, skb
->data
,
256 pool
->buff_size
, DMA_FROM_DEVICE
);
258 pool
->free_map
[free_index
] = IBM_VETH_INVALID_MAP
;
259 pool
->dma_addr
[index
] = dma_addr
;
260 pool
->skbuff
[index
] = skb
;
262 correlator
= ((u64
)pool
->index
<< 32) | index
;
263 *(u64
*)skb
->data
= correlator
;
265 desc
.fields
.flags_len
= IBMVETH_BUF_VALID
| pool
->buff_size
;
266 desc
.fields
.address
= dma_addr
;
268 lpar_rc
= h_add_logical_lan_buffer(adapter
->vdev
->unit_address
, desc
.desc
);
270 if(lpar_rc
!= H_SUCCESS
) {
271 pool
->free_map
[free_index
] = index
;
272 pool
->skbuff
[index
] = NULL
;
273 if (pool
->consumer_index
== 0)
274 pool
->consumer_index
= pool
->size
- 1;
276 pool
->consumer_index
--;
277 dma_unmap_single(&adapter
->vdev
->dev
,
278 pool
->dma_addr
[index
], pool
->buff_size
,
280 dev_kfree_skb_any(skb
);
281 adapter
->replenish_add_buff_failure
++;
285 adapter
->replenish_add_buff_success
++;
290 atomic_add(buffers_added
, &(pool
->available
));
293 /* replenish routine */
294 static void ibmveth_replenish_task(struct ibmveth_adapter
*adapter
)
298 adapter
->replenish_task_cycles
++;
300 for(i
= 0; i
< IbmVethNumBufferPools
; i
++)
301 if(adapter
->rx_buff_pool
[i
].active
)
302 ibmveth_replenish_buffer_pool(adapter
,
303 &adapter
->rx_buff_pool
[i
]);
305 adapter
->rx_no_buffer
= *(u64
*)(((char*)adapter
->buffer_list_addr
) + 4096 - 8);
308 /* empty and free ana buffer pool - also used to do cleanup in error paths */
309 static void ibmveth_free_buffer_pool(struct ibmveth_adapter
*adapter
, struct ibmveth_buff_pool
*pool
)
313 kfree(pool
->free_map
);
314 pool
->free_map
= NULL
;
316 if(pool
->skbuff
&& pool
->dma_addr
) {
317 for(i
= 0; i
< pool
->size
; ++i
) {
318 struct sk_buff
*skb
= pool
->skbuff
[i
];
320 dma_unmap_single(&adapter
->vdev
->dev
,
324 dev_kfree_skb_any(skb
);
325 pool
->skbuff
[i
] = NULL
;
331 kfree(pool
->dma_addr
);
332 pool
->dma_addr
= NULL
;
341 /* remove a buffer from a pool */
342 static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter
*adapter
, u64 correlator
)
344 unsigned int pool
= correlator
>> 32;
345 unsigned int index
= correlator
& 0xffffffffUL
;
346 unsigned int free_index
;
349 ibmveth_assert(pool
< IbmVethNumBufferPools
);
350 ibmveth_assert(index
< adapter
->rx_buff_pool
[pool
].size
);
352 skb
= adapter
->rx_buff_pool
[pool
].skbuff
[index
];
354 ibmveth_assert(skb
!= NULL
);
356 adapter
->rx_buff_pool
[pool
].skbuff
[index
] = NULL
;
358 dma_unmap_single(&adapter
->vdev
->dev
,
359 adapter
->rx_buff_pool
[pool
].dma_addr
[index
],
360 adapter
->rx_buff_pool
[pool
].buff_size
,
363 free_index
= adapter
->rx_buff_pool
[pool
].producer_index
;
364 adapter
->rx_buff_pool
[pool
].producer_index
365 = (adapter
->rx_buff_pool
[pool
].producer_index
+ 1)
366 % adapter
->rx_buff_pool
[pool
].size
;
367 adapter
->rx_buff_pool
[pool
].free_map
[free_index
] = index
;
371 atomic_dec(&(adapter
->rx_buff_pool
[pool
].available
));
374 /* get the current buffer on the rx queue */
375 static inline struct sk_buff
*ibmveth_rxq_get_buffer(struct ibmveth_adapter
*adapter
)
377 u64 correlator
= adapter
->rx_queue
.queue_addr
[adapter
->rx_queue
.index
].correlator
;
378 unsigned int pool
= correlator
>> 32;
379 unsigned int index
= correlator
& 0xffffffffUL
;
381 ibmveth_assert(pool
< IbmVethNumBufferPools
);
382 ibmveth_assert(index
< adapter
->rx_buff_pool
[pool
].size
);
384 return adapter
->rx_buff_pool
[pool
].skbuff
[index
];
387 /* recycle the current buffer on the rx queue */
388 static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter
*adapter
)
390 u32 q_index
= adapter
->rx_queue
.index
;
391 u64 correlator
= adapter
->rx_queue
.queue_addr
[q_index
].correlator
;
392 unsigned int pool
= correlator
>> 32;
393 unsigned int index
= correlator
& 0xffffffffUL
;
394 union ibmveth_buf_desc desc
;
395 unsigned long lpar_rc
;
397 ibmveth_assert(pool
< IbmVethNumBufferPools
);
398 ibmveth_assert(index
< adapter
->rx_buff_pool
[pool
].size
);
400 if(!adapter
->rx_buff_pool
[pool
].active
) {
401 ibmveth_rxq_harvest_buffer(adapter
);
402 ibmveth_free_buffer_pool(adapter
, &adapter
->rx_buff_pool
[pool
]);
406 desc
.fields
.flags_len
= IBMVETH_BUF_VALID
|
407 adapter
->rx_buff_pool
[pool
].buff_size
;
408 desc
.fields
.address
= adapter
->rx_buff_pool
[pool
].dma_addr
[index
];
410 lpar_rc
= h_add_logical_lan_buffer(adapter
->vdev
->unit_address
, desc
.desc
);
412 if(lpar_rc
!= H_SUCCESS
) {
413 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc
);
414 ibmveth_remove_buffer_from_pool(adapter
, adapter
->rx_queue
.queue_addr
[adapter
->rx_queue
.index
].correlator
);
417 if(++adapter
->rx_queue
.index
== adapter
->rx_queue
.num_slots
) {
418 adapter
->rx_queue
.index
= 0;
419 adapter
->rx_queue
.toggle
= !adapter
->rx_queue
.toggle
;
423 static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter
*adapter
)
425 ibmveth_remove_buffer_from_pool(adapter
, adapter
->rx_queue
.queue_addr
[adapter
->rx_queue
.index
].correlator
);
427 if(++adapter
->rx_queue
.index
== adapter
->rx_queue
.num_slots
) {
428 adapter
->rx_queue
.index
= 0;
429 adapter
->rx_queue
.toggle
= !adapter
->rx_queue
.toggle
;
433 static void ibmveth_cleanup(struct ibmveth_adapter
*adapter
)
437 if(adapter
->buffer_list_addr
!= NULL
) {
438 if(!dma_mapping_error(adapter
->buffer_list_dma
)) {
439 dma_unmap_single(&adapter
->vdev
->dev
,
440 adapter
->buffer_list_dma
, 4096,
442 adapter
->buffer_list_dma
= DMA_ERROR_CODE
;
444 free_page((unsigned long)adapter
->buffer_list_addr
);
445 adapter
->buffer_list_addr
= NULL
;
448 if(adapter
->filter_list_addr
!= NULL
) {
449 if(!dma_mapping_error(adapter
->filter_list_dma
)) {
450 dma_unmap_single(&adapter
->vdev
->dev
,
451 adapter
->filter_list_dma
, 4096,
453 adapter
->filter_list_dma
= DMA_ERROR_CODE
;
455 free_page((unsigned long)adapter
->filter_list_addr
);
456 adapter
->filter_list_addr
= NULL
;
459 if(adapter
->rx_queue
.queue_addr
!= NULL
) {
460 if(!dma_mapping_error(adapter
->rx_queue
.queue_dma
)) {
461 dma_unmap_single(&adapter
->vdev
->dev
,
462 adapter
->rx_queue
.queue_dma
,
463 adapter
->rx_queue
.queue_len
,
465 adapter
->rx_queue
.queue_dma
= DMA_ERROR_CODE
;
467 kfree(adapter
->rx_queue
.queue_addr
);
468 adapter
->rx_queue
.queue_addr
= NULL
;
471 for(i
= 0; i
<IbmVethNumBufferPools
; i
++)
472 if (adapter
->rx_buff_pool
[i
].active
)
473 ibmveth_free_buffer_pool(adapter
,
474 &adapter
->rx_buff_pool
[i
]);
477 static int ibmveth_register_logical_lan(struct ibmveth_adapter
*adapter
,
478 union ibmveth_buf_desc rxq_desc
, u64 mac_address
)
480 int rc
, try_again
= 1;
482 /* After a kexec the adapter will still be open, so our attempt to
483 * open it will fail. So if we get a failure we free the adapter and
484 * try again, but only once. */
486 rc
= h_register_logical_lan(adapter
->vdev
->unit_address
,
487 adapter
->buffer_list_dma
, rxq_desc
.desc
,
488 adapter
->filter_list_dma
, mac_address
);
490 if (rc
!= H_SUCCESS
&& try_again
) {
492 rc
= h_free_logical_lan(adapter
->vdev
->unit_address
);
493 } while (H_IS_LONG_BUSY(rc
) || (rc
== H_BUSY
));
502 static int ibmveth_open(struct net_device
*netdev
)
504 struct ibmveth_adapter
*adapter
= netdev
->priv
;
507 unsigned long lpar_rc
;
509 union ibmveth_buf_desc rxq_desc
;
512 ibmveth_debug_printk("open starting\n");
514 napi_enable(&adapter
->napi
);
516 for(i
= 0; i
<IbmVethNumBufferPools
; i
++)
517 rxq_entries
+= adapter
->rx_buff_pool
[i
].size
;
519 adapter
->buffer_list_addr
= (void*) get_zeroed_page(GFP_KERNEL
);
520 adapter
->filter_list_addr
= (void*) get_zeroed_page(GFP_KERNEL
);
522 if(!adapter
->buffer_list_addr
|| !adapter
->filter_list_addr
) {
523 ibmveth_error_printk("unable to allocate filter or buffer list pages\n");
524 ibmveth_cleanup(adapter
);
525 napi_disable(&adapter
->napi
);
529 adapter
->rx_queue
.queue_len
= sizeof(struct ibmveth_rx_q_entry
) * rxq_entries
;
530 adapter
->rx_queue
.queue_addr
= kmalloc(adapter
->rx_queue
.queue_len
, GFP_KERNEL
);
532 if(!adapter
->rx_queue
.queue_addr
) {
533 ibmveth_error_printk("unable to allocate rx queue pages\n");
534 ibmveth_cleanup(adapter
);
535 napi_disable(&adapter
->napi
);
539 adapter
->buffer_list_dma
= dma_map_single(&adapter
->vdev
->dev
,
540 adapter
->buffer_list_addr
, 4096, DMA_BIDIRECTIONAL
);
541 adapter
->filter_list_dma
= dma_map_single(&adapter
->vdev
->dev
,
542 adapter
->filter_list_addr
, 4096, DMA_BIDIRECTIONAL
);
543 adapter
->rx_queue
.queue_dma
= dma_map_single(&adapter
->vdev
->dev
,
544 adapter
->rx_queue
.queue_addr
,
545 adapter
->rx_queue
.queue_len
, DMA_BIDIRECTIONAL
);
547 if((dma_mapping_error(adapter
->buffer_list_dma
) ) ||
548 (dma_mapping_error(adapter
->filter_list_dma
)) ||
549 (dma_mapping_error(adapter
->rx_queue
.queue_dma
))) {
550 ibmveth_error_printk("unable to map filter or buffer list pages\n");
551 ibmveth_cleanup(adapter
);
552 napi_disable(&adapter
->napi
);
556 adapter
->rx_queue
.index
= 0;
557 adapter
->rx_queue
.num_slots
= rxq_entries
;
558 adapter
->rx_queue
.toggle
= 1;
560 memcpy(&mac_address
, netdev
->dev_addr
, netdev
->addr_len
);
561 mac_address
= mac_address
>> 16;
563 rxq_desc
.fields
.flags_len
= IBMVETH_BUF_VALID
| adapter
->rx_queue
.queue_len
;
564 rxq_desc
.fields
.address
= adapter
->rx_queue
.queue_dma
;
566 ibmveth_debug_printk("buffer list @ 0x%p\n", adapter
->buffer_list_addr
);
567 ibmveth_debug_printk("filter list @ 0x%p\n", adapter
->filter_list_addr
);
568 ibmveth_debug_printk("receive q @ 0x%p\n", adapter
->rx_queue
.queue_addr
);
570 h_vio_signal(adapter
->vdev
->unit_address
, VIO_IRQ_DISABLE
);
572 lpar_rc
= ibmveth_register_logical_lan(adapter
, rxq_desc
, mac_address
);
574 if(lpar_rc
!= H_SUCCESS
) {
575 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc
);
576 ibmveth_error_printk("buffer TCE:0x%lx filter TCE:0x%lx rxq desc:0x%lx MAC:0x%lx\n",
577 adapter
->buffer_list_dma
,
578 adapter
->filter_list_dma
,
581 ibmveth_cleanup(adapter
);
582 napi_disable(&adapter
->napi
);
586 for(i
= 0; i
<IbmVethNumBufferPools
; i
++) {
587 if(!adapter
->rx_buff_pool
[i
].active
)
589 if (ibmveth_alloc_buffer_pool(&adapter
->rx_buff_pool
[i
])) {
590 ibmveth_error_printk("unable to alloc pool\n");
591 adapter
->rx_buff_pool
[i
].active
= 0;
592 ibmveth_cleanup(adapter
);
593 napi_disable(&adapter
->napi
);
598 ibmveth_debug_printk("registering irq 0x%x\n", netdev
->irq
);
599 if((rc
= request_irq(netdev
->irq
, &ibmveth_interrupt
, 0, netdev
->name
, netdev
)) != 0) {
600 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev
->irq
, rc
);
602 rc
= h_free_logical_lan(adapter
->vdev
->unit_address
);
603 } while (H_IS_LONG_BUSY(rc
) || (rc
== H_BUSY
));
605 ibmveth_cleanup(adapter
);
606 napi_disable(&adapter
->napi
);
610 ibmveth_debug_printk("initial replenish cycle\n");
611 ibmveth_interrupt(netdev
->irq
, netdev
);
613 netif_start_queue(netdev
);
615 ibmveth_debug_printk("open complete\n");
620 static int ibmveth_close(struct net_device
*netdev
)
622 struct ibmveth_adapter
*adapter
= netdev
->priv
;
625 ibmveth_debug_printk("close starting\n");
627 napi_disable(&adapter
->napi
);
629 if (!adapter
->pool_config
)
630 netif_stop_queue(netdev
);
632 free_irq(netdev
->irq
, netdev
);
635 lpar_rc
= h_free_logical_lan(adapter
->vdev
->unit_address
);
636 } while (H_IS_LONG_BUSY(lpar_rc
) || (lpar_rc
== H_BUSY
));
638 if(lpar_rc
!= H_SUCCESS
)
640 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
644 adapter
->rx_no_buffer
= *(u64
*)(((char*)adapter
->buffer_list_addr
) + 4096 - 8);
646 ibmveth_cleanup(adapter
);
648 ibmveth_debug_printk("close complete\n");
653 static int netdev_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
) {
654 cmd
->supported
= (SUPPORTED_1000baseT_Full
| SUPPORTED_Autoneg
| SUPPORTED_FIBRE
);
655 cmd
->advertising
= (ADVERTISED_1000baseT_Full
| ADVERTISED_Autoneg
| ADVERTISED_FIBRE
);
656 cmd
->speed
= SPEED_1000
;
657 cmd
->duplex
= DUPLEX_FULL
;
658 cmd
->port
= PORT_FIBRE
;
659 cmd
->phy_address
= 0;
660 cmd
->transceiver
= XCVR_INTERNAL
;
661 cmd
->autoneg
= AUTONEG_ENABLE
;
667 static void netdev_get_drvinfo (struct net_device
*dev
, struct ethtool_drvinfo
*info
) {
668 strncpy(info
->driver
, ibmveth_driver_name
, sizeof(info
->driver
) - 1);
669 strncpy(info
->version
, ibmveth_driver_version
, sizeof(info
->version
) - 1);
672 static u32
netdev_get_link(struct net_device
*dev
) {
676 static void ibmveth_set_rx_csum_flags(struct net_device
*dev
, u32 data
)
678 struct ibmveth_adapter
*adapter
= dev
->priv
;
681 adapter
->rx_csum
= 1;
684 * Since the ibmveth firmware interface does not have the concept of
685 * separate tx/rx checksum offload enable, if rx checksum is disabled
686 * we also have to disable tx checksum offload. Once we disable rx
687 * checksum offload, we are no longer allowed to send tx buffers that
688 * are not properly checksummed.
690 adapter
->rx_csum
= 0;
691 dev
->features
&= ~NETIF_F_IP_CSUM
;
695 static void ibmveth_set_tx_csum_flags(struct net_device
*dev
, u32 data
)
697 struct ibmveth_adapter
*adapter
= dev
->priv
;
700 dev
->features
|= NETIF_F_IP_CSUM
;
701 adapter
->rx_csum
= 1;
703 dev
->features
&= ~NETIF_F_IP_CSUM
;
706 static int ibmveth_set_csum_offload(struct net_device
*dev
, u32 data
,
707 void (*done
) (struct net_device
*, u32
))
709 struct ibmveth_adapter
*adapter
= dev
->priv
;
710 u64 set_attr
, clr_attr
, ret_attr
;
712 int rc1
= 0, rc2
= 0;
715 if (netif_running(dev
)) {
717 adapter
->pool_config
= 1;
719 adapter
->pool_config
= 0;
726 set_attr
= IBMVETH_ILLAN_IPV4_TCP_CSUM
;
728 clr_attr
= IBMVETH_ILLAN_IPV4_TCP_CSUM
;
730 ret
= h_illan_attributes(adapter
->vdev
->unit_address
, 0, 0, &ret_attr
);
732 if (ret
== H_SUCCESS
&& !(ret_attr
& IBMVETH_ILLAN_ACTIVE_TRUNK
) &&
733 !(ret_attr
& IBMVETH_ILLAN_TRUNK_PRI_MASK
) &&
734 (ret_attr
& IBMVETH_ILLAN_PADDED_PKT_CSUM
)) {
735 ret
= h_illan_attributes(adapter
->vdev
->unit_address
, clr_attr
,
736 set_attr
, &ret_attr
);
738 if (ret
!= H_SUCCESS
) {
740 ibmveth_error_printk("unable to change checksum offload settings."
741 " %d rc=%ld\n", data
, ret
);
743 ret
= h_illan_attributes(adapter
->vdev
->unit_address
,
744 set_attr
, clr_attr
, &ret_attr
);
749 ibmveth_error_printk("unable to change checksum offload settings."
750 " %d rc=%ld ret_attr=%lx\n", data
, ret
, ret_attr
);
754 rc2
= ibmveth_open(dev
);
756 return rc1
? rc1
: rc2
;
759 static int ibmveth_set_rx_csum(struct net_device
*dev
, u32 data
)
761 struct ibmveth_adapter
*adapter
= dev
->priv
;
763 if ((data
&& adapter
->rx_csum
) || (!data
&& !adapter
->rx_csum
))
766 return ibmveth_set_csum_offload(dev
, data
, ibmveth_set_rx_csum_flags
);
769 static int ibmveth_set_tx_csum(struct net_device
*dev
, u32 data
)
771 struct ibmveth_adapter
*adapter
= dev
->priv
;
774 if (data
&& (dev
->features
& NETIF_F_IP_CSUM
))
776 if (!data
&& !(dev
->features
& NETIF_F_IP_CSUM
))
779 if (data
&& !adapter
->rx_csum
)
780 rc
= ibmveth_set_csum_offload(dev
, data
, ibmveth_set_tx_csum_flags
);
782 ibmveth_set_tx_csum_flags(dev
, data
);
787 static u32
ibmveth_get_rx_csum(struct net_device
*dev
)
789 struct ibmveth_adapter
*adapter
= dev
->priv
;
790 return adapter
->rx_csum
;
793 static void ibmveth_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
797 if (stringset
!= ETH_SS_STATS
)
800 for (i
= 0; i
< ARRAY_SIZE(ibmveth_stats
); i
++, data
+= ETH_GSTRING_LEN
)
801 memcpy(data
, ibmveth_stats
[i
].name
, ETH_GSTRING_LEN
);
804 static int ibmveth_get_sset_count(struct net_device
*dev
, int sset
)
808 return ARRAY_SIZE(ibmveth_stats
);
814 static void ibmveth_get_ethtool_stats(struct net_device
*dev
,
815 struct ethtool_stats
*stats
, u64
*data
)
818 struct ibmveth_adapter
*adapter
= dev
->priv
;
820 for (i
= 0; i
< ARRAY_SIZE(ibmveth_stats
); i
++)
821 data
[i
] = IBMVETH_GET_STAT(adapter
, ibmveth_stats
[i
].offset
);
824 static const struct ethtool_ops netdev_ethtool_ops
= {
825 .get_drvinfo
= netdev_get_drvinfo
,
826 .get_settings
= netdev_get_settings
,
827 .get_link
= netdev_get_link
,
828 .set_tx_csum
= ibmveth_set_tx_csum
,
829 .get_rx_csum
= ibmveth_get_rx_csum
,
830 .set_rx_csum
= ibmveth_set_rx_csum
,
831 .get_strings
= ibmveth_get_strings
,
832 .get_sset_count
= ibmveth_get_sset_count
,
833 .get_ethtool_stats
= ibmveth_get_ethtool_stats
,
836 static int ibmveth_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
841 #define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1))
843 static int ibmveth_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
845 struct ibmveth_adapter
*adapter
= netdev
->priv
;
846 union ibmveth_buf_desc desc
;
847 unsigned long lpar_rc
;
848 unsigned long correlator
;
850 unsigned int retry_count
;
851 unsigned int tx_dropped
= 0;
852 unsigned int tx_bytes
= 0;
853 unsigned int tx_packets
= 0;
854 unsigned int tx_send_failed
= 0;
855 unsigned int tx_map_failed
= 0;
857 desc
.fields
.flags_len
= IBMVETH_BUF_VALID
| skb
->len
;
858 desc
.fields
.address
= dma_map_single(&adapter
->vdev
->dev
, skb
->data
,
859 skb
->len
, DMA_TO_DEVICE
);
861 if (skb
->ip_summed
== CHECKSUM_PARTIAL
&&
862 ip_hdr(skb
)->protocol
!= IPPROTO_TCP
&& skb_checksum_help(skb
)) {
863 ibmveth_error_printk("tx: failed to checksum packet\n");
868 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
869 unsigned char *buf
= skb_transport_header(skb
) + skb
->csum_offset
;
871 desc
.fields
.flags_len
|= (IBMVETH_BUF_NO_CSUM
| IBMVETH_BUF_CSUM_GOOD
);
873 /* Need to zero out the checksum */
878 if (dma_mapping_error(desc
.fields
.address
)) {
879 ibmveth_error_printk("tx: unable to map xmit buffer\n");
885 /* send the frame. Arbitrarily set retrycount to 1024 */
889 lpar_rc
= h_send_logical_lan(adapter
->vdev
->unit_address
,
890 desc
.desc
, 0, 0, 0, 0, 0,
891 correlator
, &correlator
);
892 } while ((lpar_rc
== H_BUSY
) && (retry_count
--));
894 if(lpar_rc
!= H_SUCCESS
&& lpar_rc
!= H_DROPPED
) {
895 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc
);
896 ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n",
897 (desc
.fields
.flags_len
& IBMVETH_BUF_VALID
) ? 1 : 0,
898 skb
->len
, desc
.fields
.address
);
903 tx_bytes
+= skb
->len
;
904 netdev
->trans_start
= jiffies
;
907 dma_unmap_single(&adapter
->vdev
->dev
, desc
.fields
.address
,
908 skb
->len
, DMA_TO_DEVICE
);
910 out
: spin_lock_irqsave(&adapter
->stats_lock
, flags
);
911 netdev
->stats
.tx_dropped
+= tx_dropped
;
912 netdev
->stats
.tx_bytes
+= tx_bytes
;
913 netdev
->stats
.tx_packets
+= tx_packets
;
914 adapter
->tx_send_failed
+= tx_send_failed
;
915 adapter
->tx_map_failed
+= tx_map_failed
;
916 spin_unlock_irqrestore(&adapter
->stats_lock
, flags
);
922 static int ibmveth_poll(struct napi_struct
*napi
, int budget
)
924 struct ibmveth_adapter
*adapter
= container_of(napi
, struct ibmveth_adapter
, napi
);
925 struct net_device
*netdev
= adapter
->netdev
;
926 int frames_processed
= 0;
927 unsigned long lpar_rc
;
933 if (!ibmveth_rxq_pending_buffer(adapter
))
937 if (!ibmveth_rxq_buffer_valid(adapter
)) {
938 wmb(); /* suggested by larson1 */
939 adapter
->rx_invalid_buffer
++;
940 ibmveth_debug_printk("recycling invalid buffer\n");
941 ibmveth_rxq_recycle_buffer(adapter
);
943 int length
= ibmveth_rxq_frame_length(adapter
);
944 int offset
= ibmveth_rxq_frame_offset(adapter
);
945 int csum_good
= ibmveth_rxq_csum_good(adapter
);
947 skb
= ibmveth_rxq_get_buffer(adapter
);
949 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
951 ibmveth_rxq_harvest_buffer(adapter
);
953 skb_reserve(skb
, offset
);
954 skb_put(skb
, length
);
955 skb
->protocol
= eth_type_trans(skb
, netdev
);
957 netif_receive_skb(skb
); /* send it up */
959 netdev
->stats
.rx_packets
++;
960 netdev
->stats
.rx_bytes
+= length
;
962 netdev
->last_rx
= jiffies
;
964 } while (frames_processed
< budget
);
966 ibmveth_replenish_task(adapter
);
968 if (frames_processed
< budget
) {
969 /* We think we are done - reenable interrupts,
970 * then check once more to make sure we are done.
972 lpar_rc
= h_vio_signal(adapter
->vdev
->unit_address
,
975 ibmveth_assert(lpar_rc
== H_SUCCESS
);
977 netif_rx_complete(netdev
, napi
);
979 if (ibmveth_rxq_pending_buffer(adapter
) &&
980 netif_rx_reschedule(netdev
, napi
)) {
981 lpar_rc
= h_vio_signal(adapter
->vdev
->unit_address
,
987 return frames_processed
;
990 static irqreturn_t
ibmveth_interrupt(int irq
, void *dev_instance
)
992 struct net_device
*netdev
= dev_instance
;
993 struct ibmveth_adapter
*adapter
= netdev
->priv
;
994 unsigned long lpar_rc
;
996 if (netif_rx_schedule_prep(netdev
, &adapter
->napi
)) {
997 lpar_rc
= h_vio_signal(adapter
->vdev
->unit_address
,
999 ibmveth_assert(lpar_rc
== H_SUCCESS
);
1000 __netif_rx_schedule(netdev
, &adapter
->napi
);
1005 static void ibmveth_set_multicast_list(struct net_device
*netdev
)
1007 struct ibmveth_adapter
*adapter
= netdev
->priv
;
1008 unsigned long lpar_rc
;
1010 if((netdev
->flags
& IFF_PROMISC
) || (netdev
->mc_count
> adapter
->mcastFilterSize
)) {
1011 lpar_rc
= h_multicast_ctrl(adapter
->vdev
->unit_address
,
1012 IbmVethMcastEnableRecv
|
1013 IbmVethMcastDisableFiltering
,
1015 if(lpar_rc
!= H_SUCCESS
) {
1016 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc
);
1019 struct dev_mc_list
*mclist
= netdev
->mc_list
;
1021 /* clear the filter table & disable filtering */
1022 lpar_rc
= h_multicast_ctrl(adapter
->vdev
->unit_address
,
1023 IbmVethMcastEnableRecv
|
1024 IbmVethMcastDisableFiltering
|
1025 IbmVethMcastClearFilterTable
,
1027 if(lpar_rc
!= H_SUCCESS
) {
1028 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc
);
1030 /* add the addresses to the filter table */
1031 for(i
= 0; i
< netdev
->mc_count
; ++i
, mclist
= mclist
->next
) {
1032 // add the multicast address to the filter table
1033 unsigned long mcast_addr
= 0;
1034 memcpy(((char *)&mcast_addr
)+2, mclist
->dmi_addr
, 6);
1035 lpar_rc
= h_multicast_ctrl(adapter
->vdev
->unit_address
,
1036 IbmVethMcastAddFilter
,
1038 if(lpar_rc
!= H_SUCCESS
) {
1039 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc
);
1043 /* re-enable filtering */
1044 lpar_rc
= h_multicast_ctrl(adapter
->vdev
->unit_address
,
1045 IbmVethMcastEnableFiltering
,
1047 if(lpar_rc
!= H_SUCCESS
) {
1048 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc
);
1053 static int ibmveth_change_mtu(struct net_device
*dev
, int new_mtu
)
1055 struct ibmveth_adapter
*adapter
= dev
->priv
;
1056 int new_mtu_oh
= new_mtu
+ IBMVETH_BUFF_OH
;
1060 if (new_mtu
< IBMVETH_MAX_MTU
)
1063 for (i
= 0; i
< IbmVethNumBufferPools
; i
++)
1064 if (new_mtu_oh
< adapter
->rx_buff_pool
[i
].buff_size
)
1067 if (i
== IbmVethNumBufferPools
)
1070 /* Look for an active buffer pool that can hold the new MTU */
1071 for(i
= 0; i
<IbmVethNumBufferPools
; i
++) {
1072 if (!adapter
->rx_buff_pool
[i
].active
) {
1073 adapter
->rx_buff_pool
[i
].active
= 1;
1077 if (new_mtu_oh
< adapter
->rx_buff_pool
[i
].buff_size
) {
1078 if (reinit
&& netif_running(adapter
->netdev
)) {
1079 adapter
->pool_config
= 1;
1080 ibmveth_close(adapter
->netdev
);
1081 adapter
->pool_config
= 0;
1083 if ((rc
= ibmveth_open(adapter
->netdev
)))
1093 #ifdef CONFIG_NET_POLL_CONTROLLER
1094 static void ibmveth_poll_controller(struct net_device
*dev
)
1096 ibmveth_replenish_task(dev
->priv
);
1097 ibmveth_interrupt(dev
->irq
, dev
);
1101 static int __devinit
ibmveth_probe(struct vio_dev
*dev
, const struct vio_device_id
*id
)
1105 struct net_device
*netdev
;
1106 struct ibmveth_adapter
*adapter
;
1107 u64 set_attr
, ret_attr
;
1109 unsigned char *mac_addr_p
;
1110 unsigned int *mcastFilterSize_p
;
1113 ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n",
1116 mac_addr_p
= (unsigned char *) vio_get_attribute(dev
,
1117 VETH_MAC_ADDR
, NULL
);
1119 printk(KERN_ERR
"(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR "
1120 "attribute\n", __FILE__
, __LINE__
);
1124 mcastFilterSize_p
= (unsigned int *) vio_get_attribute(dev
,
1125 VETH_MCAST_FILTER_SIZE
, NULL
);
1126 if(!mcastFilterSize_p
) {
1127 printk(KERN_ERR
"(%s:%3.3d) ERROR: Can't find "
1128 "VETH_MCAST_FILTER_SIZE attribute\n",
1129 __FILE__
, __LINE__
);
1133 netdev
= alloc_etherdev(sizeof(struct ibmveth_adapter
));
1138 adapter
= netdev
->priv
;
1139 dev
->dev
.driver_data
= netdev
;
1141 adapter
->vdev
= dev
;
1142 adapter
->netdev
= netdev
;
1143 adapter
->mcastFilterSize
= *mcastFilterSize_p
;
1144 adapter
->pool_config
= 0;
1146 netif_napi_add(netdev
, &adapter
->napi
, ibmveth_poll
, 16);
1148 /* Some older boxes running PHYP non-natively have an OF that
1149 returns a 8-byte local-mac-address field (and the first
1150 2 bytes have to be ignored) while newer boxes' OF return
1151 a 6-byte field. Note that IEEE 1275 specifies that
1152 local-mac-address must be a 6-byte field.
1153 The RPA doc specifies that the first byte must be 10b, so
1154 we'll just look for it to solve this 8 vs. 6 byte field issue */
1156 if ((*mac_addr_p
& 0x3) != 0x02)
1159 adapter
->mac_addr
= 0;
1160 memcpy(&adapter
->mac_addr
, mac_addr_p
, 6);
1162 netdev
->irq
= dev
->irq
;
1163 netdev
->open
= ibmveth_open
;
1164 netdev
->stop
= ibmveth_close
;
1165 netdev
->hard_start_xmit
= ibmveth_start_xmit
;
1166 netdev
->set_multicast_list
= ibmveth_set_multicast_list
;
1167 netdev
->do_ioctl
= ibmveth_ioctl
;
1168 netdev
->ethtool_ops
= &netdev_ethtool_ops
;
1169 netdev
->change_mtu
= ibmveth_change_mtu
;
1170 SET_NETDEV_DEV(netdev
, &dev
->dev
);
1171 #ifdef CONFIG_NET_POLL_CONTROLLER
1172 netdev
->poll_controller
= ibmveth_poll_controller
;
1174 netdev
->features
|= NETIF_F_LLTX
;
1175 spin_lock_init(&adapter
->stats_lock
);
1177 memcpy(&netdev
->dev_addr
, &adapter
->mac_addr
, netdev
->addr_len
);
1179 for(i
= 0; i
<IbmVethNumBufferPools
; i
++) {
1180 struct kobject
*kobj
= &adapter
->rx_buff_pool
[i
].kobj
;
1183 ibmveth_init_buffer_pool(&adapter
->rx_buff_pool
[i
], i
,
1184 pool_count
[i
], pool_size
[i
],
1186 error
= kobject_init_and_add(kobj
, &ktype_veth_pool
,
1187 &dev
->dev
.kobj
, "pool%d", i
);
1189 kobject_uevent(kobj
, KOBJ_ADD
);
1192 ibmveth_debug_printk("adapter @ 0x%p\n", adapter
);
1194 adapter
->buffer_list_dma
= DMA_ERROR_CODE
;
1195 adapter
->filter_list_dma
= DMA_ERROR_CODE
;
1196 adapter
->rx_queue
.queue_dma
= DMA_ERROR_CODE
;
1198 ibmveth_debug_printk("registering netdev...\n");
1200 ret
= h_illan_attributes(dev
->unit_address
, 0, 0, &ret_attr
);
1202 if (ret
== H_SUCCESS
&& !(ret_attr
& IBMVETH_ILLAN_ACTIVE_TRUNK
) &&
1203 !(ret_attr
& IBMVETH_ILLAN_TRUNK_PRI_MASK
) &&
1204 (ret_attr
& IBMVETH_ILLAN_PADDED_PKT_CSUM
)) {
1205 set_attr
= IBMVETH_ILLAN_IPV4_TCP_CSUM
;
1207 ret
= h_illan_attributes(dev
->unit_address
, 0, set_attr
, &ret_attr
);
1209 if (ret
== H_SUCCESS
) {
1210 adapter
->rx_csum
= 1;
1211 netdev
->features
|= NETIF_F_IP_CSUM
;
1213 ret
= h_illan_attributes(dev
->unit_address
, set_attr
, 0, &ret_attr
);
1216 rc
= register_netdev(netdev
);
1219 ibmveth_debug_printk("failed to register netdev rc=%d\n", rc
);
1220 free_netdev(netdev
);
1224 ibmveth_debug_printk("registered\n");
1226 ibmveth_proc_register_adapter(adapter
);
1231 static int __devexit
ibmveth_remove(struct vio_dev
*dev
)
1233 struct net_device
*netdev
= dev
->dev
.driver_data
;
1234 struct ibmveth_adapter
*adapter
= netdev
->priv
;
1237 for(i
= 0; i
<IbmVethNumBufferPools
; i
++)
1238 kobject_put(&adapter
->rx_buff_pool
[i
].kobj
);
1240 unregister_netdev(netdev
);
1242 ibmveth_proc_unregister_adapter(adapter
);
1244 free_netdev(netdev
);
1248 #ifdef CONFIG_PROC_FS
1249 static void ibmveth_proc_register_driver(void)
1251 ibmveth_proc_dir
= proc_mkdir(IBMVETH_PROC_DIR
, init_net
.proc_net
);
1252 if (ibmveth_proc_dir
) {
1256 static void ibmveth_proc_unregister_driver(void)
1258 remove_proc_entry(IBMVETH_PROC_DIR
, init_net
.proc_net
);
1261 static int ibmveth_show(struct seq_file
*seq
, void *v
)
1263 struct ibmveth_adapter
*adapter
= seq
->private;
1264 char *current_mac
= ((char*) &adapter
->netdev
->dev_addr
);
1265 char *firmware_mac
= ((char*) &adapter
->mac_addr
) ;
1266 DECLARE_MAC_BUF(mac
);
1268 seq_printf(seq
, "%s %s\n\n", ibmveth_driver_string
, ibmveth_driver_version
);
1270 seq_printf(seq
, "Unit Address: 0x%x\n", adapter
->vdev
->unit_address
);
1271 seq_printf(seq
, "Current MAC: %s\n", print_mac(mac
, current_mac
));
1272 seq_printf(seq
, "Firmware MAC: %s\n", print_mac(mac
, firmware_mac
));
1274 seq_printf(seq
, "\nAdapter Statistics:\n");
1275 seq_printf(seq
, " TX: vio_map_single failres: %ld\n", adapter
->tx_map_failed
);
1276 seq_printf(seq
, " send failures: %ld\n", adapter
->tx_send_failed
);
1277 seq_printf(seq
, " RX: replenish task cycles: %ld\n", adapter
->replenish_task_cycles
);
1278 seq_printf(seq
, " alloc_skb_failures: %ld\n", adapter
->replenish_no_mem
);
1279 seq_printf(seq
, " add buffer failures: %ld\n", adapter
->replenish_add_buff_failure
);
1280 seq_printf(seq
, " invalid buffers: %ld\n", adapter
->rx_invalid_buffer
);
1281 seq_printf(seq
, " no buffers: %ld\n", adapter
->rx_no_buffer
);
1286 static int ibmveth_proc_open(struct inode
*inode
, struct file
*file
)
1288 return single_open(file
, ibmveth_show
, PDE(inode
)->data
);
1291 static const struct file_operations ibmveth_proc_fops
= {
1292 .owner
= THIS_MODULE
,
1293 .open
= ibmveth_proc_open
,
1295 .llseek
= seq_lseek
,
1296 .release
= single_release
,
1299 static void ibmveth_proc_register_adapter(struct ibmveth_adapter
*adapter
)
1301 struct proc_dir_entry
*entry
;
1302 if (ibmveth_proc_dir
) {
1304 sprintf(u_addr
, "%x", adapter
->vdev
->unit_address
);
1305 entry
= proc_create_data(u_addr
, S_IFREG
, ibmveth_proc_dir
,
1306 &ibmveth_proc_fops
, adapter
);
1308 ibmveth_error_printk("Cannot create adapter proc entry");
1313 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter
*adapter
)
1315 if (ibmveth_proc_dir
) {
1317 sprintf(u_addr
, "%x", adapter
->vdev
->unit_address
);
1318 remove_proc_entry(u_addr
, ibmveth_proc_dir
);
1322 #else /* CONFIG_PROC_FS */
1323 static void ibmveth_proc_register_adapter(struct ibmveth_adapter
*adapter
)
1327 static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter
*adapter
)
1330 static void ibmveth_proc_register_driver(void)
1334 static void ibmveth_proc_unregister_driver(void)
1337 #endif /* CONFIG_PROC_FS */
1339 static struct attribute veth_active_attr
;
1340 static struct attribute veth_num_attr
;
1341 static struct attribute veth_size_attr
;
1343 static ssize_t
veth_pool_show(struct kobject
* kobj
,
1344 struct attribute
* attr
, char * buf
)
1346 struct ibmveth_buff_pool
*pool
= container_of(kobj
,
1347 struct ibmveth_buff_pool
,
1350 if (attr
== &veth_active_attr
)
1351 return sprintf(buf
, "%d\n", pool
->active
);
1352 else if (attr
== &veth_num_attr
)
1353 return sprintf(buf
, "%d\n", pool
->size
);
1354 else if (attr
== &veth_size_attr
)
1355 return sprintf(buf
, "%d\n", pool
->buff_size
);
1359 static ssize_t
veth_pool_store(struct kobject
* kobj
, struct attribute
* attr
,
1360 const char * buf
, size_t count
)
1362 struct ibmveth_buff_pool
*pool
= container_of(kobj
,
1363 struct ibmveth_buff_pool
,
1365 struct net_device
*netdev
=
1366 container_of(kobj
->parent
, struct device
, kobj
)->driver_data
;
1367 struct ibmveth_adapter
*adapter
= netdev
->priv
;
1368 long value
= simple_strtol(buf
, NULL
, 10);
1371 if (attr
== &veth_active_attr
) {
1372 if (value
&& !pool
->active
) {
1373 if (netif_running(netdev
)) {
1374 if(ibmveth_alloc_buffer_pool(pool
)) {
1375 ibmveth_error_printk("unable to alloc pool\n");
1379 adapter
->pool_config
= 1;
1380 ibmveth_close(netdev
);
1381 adapter
->pool_config
= 0;
1382 if ((rc
= ibmveth_open(netdev
)))
1386 } else if (!value
&& pool
->active
) {
1387 int mtu
= netdev
->mtu
+ IBMVETH_BUFF_OH
;
1389 /* Make sure there is a buffer pool with buffers that
1390 can hold a packet of the size of the MTU */
1391 for (i
= 0; i
< IbmVethNumBufferPools
; i
++) {
1392 if (pool
== &adapter
->rx_buff_pool
[i
])
1394 if (!adapter
->rx_buff_pool
[i
].active
)
1396 if (mtu
<= adapter
->rx_buff_pool
[i
].buff_size
)
1400 if (i
== IbmVethNumBufferPools
) {
1401 ibmveth_error_printk("no active pool >= MTU\n");
1406 if (netif_running(netdev
)) {
1407 adapter
->pool_config
= 1;
1408 ibmveth_close(netdev
);
1409 adapter
->pool_config
= 0;
1410 if ((rc
= ibmveth_open(netdev
)))
1414 } else if (attr
== &veth_num_attr
) {
1415 if (value
<= 0 || value
> IBMVETH_MAX_POOL_COUNT
)
1418 if (netif_running(netdev
)) {
1419 adapter
->pool_config
= 1;
1420 ibmveth_close(netdev
);
1421 adapter
->pool_config
= 0;
1423 if ((rc
= ibmveth_open(netdev
)))
1428 } else if (attr
== &veth_size_attr
) {
1429 if (value
<= IBMVETH_BUFF_OH
|| value
> IBMVETH_MAX_BUF_SIZE
)
1432 if (netif_running(netdev
)) {
1433 adapter
->pool_config
= 1;
1434 ibmveth_close(netdev
);
1435 adapter
->pool_config
= 0;
1436 pool
->buff_size
= value
;
1437 if ((rc
= ibmveth_open(netdev
)))
1440 pool
->buff_size
= value
;
1444 /* kick the interrupt handler to allocate/deallocate pools */
1445 ibmveth_interrupt(netdev
->irq
, netdev
);
1450 #define ATTR(_name, _mode) \
1451 struct attribute veth_##_name##_attr = { \
1452 .name = __stringify(_name), .mode = _mode, \
1455 static ATTR(active
, 0644);
1456 static ATTR(num
, 0644);
1457 static ATTR(size
, 0644);
1459 static struct attribute
* veth_pool_attrs
[] = {
1466 static struct sysfs_ops veth_pool_ops
= {
1467 .show
= veth_pool_show
,
1468 .store
= veth_pool_store
,
1471 static struct kobj_type ktype_veth_pool
= {
1473 .sysfs_ops
= &veth_pool_ops
,
1474 .default_attrs
= veth_pool_attrs
,
1478 static struct vio_device_id ibmveth_device_table
[] __devinitdata
= {
1479 { "network", "IBM,l-lan"},
1482 MODULE_DEVICE_TABLE(vio
, ibmveth_device_table
);
1484 static struct vio_driver ibmveth_driver
= {
1485 .id_table
= ibmveth_device_table
,
1486 .probe
= ibmveth_probe
,
1487 .remove
= ibmveth_remove
,
1489 .name
= ibmveth_driver_name
,
1490 .owner
= THIS_MODULE
,
1494 static int __init
ibmveth_module_init(void)
1496 ibmveth_printk("%s: %s %s\n", ibmveth_driver_name
, ibmveth_driver_string
, ibmveth_driver_version
);
1498 ibmveth_proc_register_driver();
1500 return vio_register_driver(&ibmveth_driver
);
1503 static void __exit
ibmveth_module_exit(void)
1505 vio_unregister_driver(&ibmveth_driver
);
1506 ibmveth_proc_unregister_driver();
1509 module_init(ibmveth_module_init
);
1510 module_exit(ibmveth_module_exit
);