Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. */ |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 27 | /* */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | /**************************************************************************/ |
| 29 | /* |
| 30 | TODO: |
| 31 | - remove frag processing code - no longer needed |
| 32 | - add support for sysfs |
| 33 | - possibly remove procfs support |
| 34 | */ |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/types.h> |
| 38 | #include <linux/errno.h> |
| 39 | #include <linux/ioport.h> |
| 40 | #include <linux/dma-mapping.h> |
| 41 | #include <linux/kernel.h> |
| 42 | #include <linux/netdevice.h> |
| 43 | #include <linux/etherdevice.h> |
| 44 | #include <linux/skbuff.h> |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/delay.h> |
| 47 | #include <linux/mm.h> |
| 48 | #include <linux/ethtool.h> |
| 49 | #include <linux/proc_fs.h> |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 50 | #include <linux/in.h> |
| 51 | #include <linux/ip.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 52 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/semaphore.h> |
| 54 | #include <asm/hvcall.h> |
| 55 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/vio.h> |
| 57 | #include <asm/uaccess.h> |
| 58 | #include <linux/seq_file.h> |
| 59 | |
| 60 | #include "ibmveth.h" |
| 61 | |
Anton Blanchard | 6af37fa | 2005-11-11 14:02:04 +1100 | [diff] [blame] | 62 | #undef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define ibmveth_printk(fmt, args...) \ |
Olof Johansson | f98baff | 2006-04-12 15:22:29 -0500 | [diff] [blame] | 65 | printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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...) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 83 | #define ibmveth_assert(expr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 89 | static int ibmveth_poll(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 98 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 99 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 100 | static struct kobj_type ktype_veth_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 103 | #define IBMVETH_PROC_DIR "ibmveth" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 137 | static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter) |
| 138 | { |
| 139 | return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].csum_good); |
| 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* setup the initial settings for a buffer pool */ |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 143 | static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool, u32 pool_index, u32 pool_size, u32 buff_size, u32 pool_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | pool->size = pool_size; |
| 146 | pool->index = pool_index; |
| 147 | pool->buff_size = buff_size; |
| 148 | pool->threshold = pool_size / 2; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 149 | pool->active = pool_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* allocate and setup an buffer pool - called during open */ |
| 153 | static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool) |
| 154 | { |
| 155 | int i; |
| 156 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 157 | pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | if(!pool->free_map) { |
| 160 | return -1; |
| 161 | } |
| 162 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 163 | pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if(!pool->dma_addr) { |
| 165 | kfree(pool->free_map); |
| 166 | pool->free_map = NULL; |
| 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | pool->skbuff = kmalloc(sizeof(void*) * pool->size, GFP_KERNEL); |
| 171 | |
| 172 | if(!pool->skbuff) { |
| 173 | kfree(pool->dma_addr); |
| 174 | pool->dma_addr = NULL; |
| 175 | |
| 176 | kfree(pool->free_map); |
| 177 | pool->free_map = NULL; |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | memset(pool->skbuff, 0, sizeof(void*) * pool->size); |
| 182 | memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size); |
| 183 | |
| 184 | for(i = 0; i < pool->size; ++i) { |
| 185 | pool->free_map[i] = i; |
| 186 | } |
| 187 | |
| 188 | atomic_set(&pool->available, 0); |
| 189 | pool->producer_index = 0; |
| 190 | pool->consumer_index = 0; |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* replenish the buffers for a pool. note that we don't need to |
| 196 | * skb_reserve these since they are used for incoming... |
| 197 | */ |
| 198 | static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool) |
| 199 | { |
| 200 | u32 i; |
| 201 | u32 count = pool->size - atomic_read(&pool->available); |
| 202 | u32 buffers_added = 0; |
| 203 | |
| 204 | mb(); |
| 205 | |
| 206 | for(i = 0; i < count; ++i) { |
| 207 | struct sk_buff *skb; |
| 208 | unsigned int free_index, index; |
| 209 | u64 correlator; |
| 210 | union ibmveth_buf_desc desc; |
| 211 | unsigned long lpar_rc; |
| 212 | dma_addr_t dma_addr; |
| 213 | |
| 214 | skb = alloc_skb(pool->buff_size, GFP_ATOMIC); |
| 215 | |
| 216 | if(!skb) { |
| 217 | ibmveth_debug_printk("replenish: unable to allocate skb\n"); |
| 218 | adapter->replenish_no_mem++; |
| 219 | break; |
| 220 | } |
| 221 | |
David Gibson | 047a66d | 2006-10-21 10:24:13 -0700 | [diff] [blame] | 222 | free_index = pool->consumer_index; |
| 223 | pool->consumer_index = (pool->consumer_index + 1) % pool->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | index = pool->free_map[free_index]; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | ibmveth_assert(index != IBM_VETH_INVALID_MAP); |
| 227 | ibmveth_assert(pool->skbuff[index] == NULL); |
| 228 | |
| 229 | dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, |
| 230 | pool->buff_size, DMA_FROM_DEVICE); |
| 231 | |
| 232 | pool->free_map[free_index] = IBM_VETH_INVALID_MAP; |
| 233 | pool->dma_addr[index] = dma_addr; |
| 234 | pool->skbuff[index] = skb; |
| 235 | |
| 236 | correlator = ((u64)pool->index << 32) | index; |
| 237 | *(u64*)skb->data = correlator; |
| 238 | |
| 239 | desc.desc = 0; |
| 240 | desc.fields.valid = 1; |
| 241 | desc.fields.length = pool->buff_size; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 242 | desc.fields.address = dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 245 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 246 | if(lpar_rc != H_SUCCESS) { |
Santiago Leon | 82702d3 | 2005-10-26 10:47:23 -0600 | [diff] [blame] | 247 | pool->free_map[free_index] = index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | pool->skbuff[index] = NULL; |
Santiago Leon | 751ae21 | 2006-10-03 12:24:45 -0500 | [diff] [blame] | 249 | if (pool->consumer_index == 0) |
| 250 | pool->consumer_index = pool->size - 1; |
| 251 | else |
| 252 | pool->consumer_index--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | dma_unmap_single(&adapter->vdev->dev, |
| 254 | pool->dma_addr[index], pool->buff_size, |
| 255 | DMA_FROM_DEVICE); |
| 256 | dev_kfree_skb_any(skb); |
| 257 | adapter->replenish_add_buff_failure++; |
| 258 | break; |
| 259 | } else { |
| 260 | buffers_added++; |
| 261 | adapter->replenish_add_buff_success++; |
| 262 | } |
| 263 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | mb(); |
| 266 | atomic_add(buffers_added, &(pool->available)); |
| 267 | } |
| 268 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 269 | /* replenish routine */ |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 270 | static void ibmveth_replenish_task(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 272 | int i; |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | adapter->replenish_task_cycles++; |
| 275 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 276 | for(i = 0; i < IbmVethNumBufferPools; i++) |
| 277 | if(adapter->rx_buff_pool[i].active) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 278 | ibmveth_replenish_buffer_pool(adapter, |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 279 | &adapter->rx_buff_pool[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* empty and free ana buffer pool - also used to do cleanup in error paths */ |
| 285 | static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool) |
| 286 | { |
| 287 | int i; |
| 288 | |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 289 | kfree(pool->free_map); |
| 290 | pool->free_map = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | if(pool->skbuff && pool->dma_addr) { |
| 293 | for(i = 0; i < pool->size; ++i) { |
| 294 | struct sk_buff *skb = pool->skbuff[i]; |
| 295 | if(skb) { |
| 296 | dma_unmap_single(&adapter->vdev->dev, |
| 297 | pool->dma_addr[i], |
| 298 | pool->buff_size, |
| 299 | DMA_FROM_DEVICE); |
| 300 | dev_kfree_skb_any(skb); |
| 301 | pool->skbuff[i] = NULL; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if(pool->dma_addr) { |
| 307 | kfree(pool->dma_addr); |
| 308 | pool->dma_addr = NULL; |
| 309 | } |
| 310 | |
| 311 | if(pool->skbuff) { |
| 312 | kfree(pool->skbuff); |
| 313 | pool->skbuff = NULL; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /* remove a buffer from a pool */ |
| 318 | static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator) |
| 319 | { |
| 320 | unsigned int pool = correlator >> 32; |
| 321 | unsigned int index = correlator & 0xffffffffUL; |
| 322 | unsigned int free_index; |
| 323 | struct sk_buff *skb; |
| 324 | |
| 325 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 326 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 327 | |
| 328 | skb = adapter->rx_buff_pool[pool].skbuff[index]; |
| 329 | |
| 330 | ibmveth_assert(skb != NULL); |
| 331 | |
| 332 | adapter->rx_buff_pool[pool].skbuff[index] = NULL; |
| 333 | |
| 334 | dma_unmap_single(&adapter->vdev->dev, |
| 335 | adapter->rx_buff_pool[pool].dma_addr[index], |
| 336 | adapter->rx_buff_pool[pool].buff_size, |
| 337 | DMA_FROM_DEVICE); |
| 338 | |
David Gibson | 047a66d | 2006-10-21 10:24:13 -0700 | [diff] [blame] | 339 | free_index = adapter->rx_buff_pool[pool].producer_index; |
| 340 | adapter->rx_buff_pool[pool].producer_index |
| 341 | = (adapter->rx_buff_pool[pool].producer_index + 1) |
| 342 | % adapter->rx_buff_pool[pool].size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | adapter->rx_buff_pool[pool].free_map[free_index] = index; |
| 344 | |
| 345 | mb(); |
| 346 | |
| 347 | atomic_dec(&(adapter->rx_buff_pool[pool].available)); |
| 348 | } |
| 349 | |
| 350 | /* get the current buffer on the rx queue */ |
| 351 | static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter) |
| 352 | { |
| 353 | u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator; |
| 354 | unsigned int pool = correlator >> 32; |
| 355 | unsigned int index = correlator & 0xffffffffUL; |
| 356 | |
| 357 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 358 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 359 | |
| 360 | return adapter->rx_buff_pool[pool].skbuff[index]; |
| 361 | } |
| 362 | |
| 363 | /* recycle the current buffer on the rx queue */ |
| 364 | static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter) |
| 365 | { |
| 366 | u32 q_index = adapter->rx_queue.index; |
| 367 | u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator; |
| 368 | unsigned int pool = correlator >> 32; |
| 369 | unsigned int index = correlator & 0xffffffffUL; |
| 370 | union ibmveth_buf_desc desc; |
| 371 | unsigned long lpar_rc; |
| 372 | |
| 373 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 374 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 375 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 376 | if(!adapter->rx_buff_pool[pool].active) { |
| 377 | ibmveth_rxq_harvest_buffer(adapter); |
| 378 | ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]); |
| 379 | return; |
| 380 | } |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | desc.desc = 0; |
| 383 | desc.fields.valid = 1; |
| 384 | desc.fields.length = adapter->rx_buff_pool[pool].buff_size; |
| 385 | desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index]; |
| 386 | |
| 387 | lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 388 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 389 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc); |
| 391 | ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); |
| 392 | } |
| 393 | |
| 394 | if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) { |
| 395 | adapter->rx_queue.index = 0; |
| 396 | adapter->rx_queue.toggle = !adapter->rx_queue.toggle; |
| 397 | } |
| 398 | } |
| 399 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 400 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); |
| 403 | |
| 404 | if(++adapter->rx_queue.index == adapter->rx_queue.num_slots) { |
| 405 | adapter->rx_queue.index = 0; |
| 406 | adapter->rx_queue.toggle = !adapter->rx_queue.toggle; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | static void ibmveth_cleanup(struct ibmveth_adapter *adapter) |
| 411 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 412 | int i; |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if(adapter->buffer_list_addr != NULL) { |
| 415 | if(!dma_mapping_error(adapter->buffer_list_dma)) { |
| 416 | dma_unmap_single(&adapter->vdev->dev, |
| 417 | adapter->buffer_list_dma, 4096, |
| 418 | DMA_BIDIRECTIONAL); |
| 419 | adapter->buffer_list_dma = DMA_ERROR_CODE; |
| 420 | } |
| 421 | free_page((unsigned long)adapter->buffer_list_addr); |
| 422 | adapter->buffer_list_addr = NULL; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | if(adapter->filter_list_addr != NULL) { |
| 426 | if(!dma_mapping_error(adapter->filter_list_dma)) { |
| 427 | dma_unmap_single(&adapter->vdev->dev, |
| 428 | adapter->filter_list_dma, 4096, |
| 429 | DMA_BIDIRECTIONAL); |
| 430 | adapter->filter_list_dma = DMA_ERROR_CODE; |
| 431 | } |
| 432 | free_page((unsigned long)adapter->filter_list_addr); |
| 433 | adapter->filter_list_addr = NULL; |
| 434 | } |
| 435 | |
| 436 | if(adapter->rx_queue.queue_addr != NULL) { |
| 437 | if(!dma_mapping_error(adapter->rx_queue.queue_dma)) { |
| 438 | dma_unmap_single(&adapter->vdev->dev, |
| 439 | adapter->rx_queue.queue_dma, |
| 440 | adapter->rx_queue.queue_len, |
| 441 | DMA_BIDIRECTIONAL); |
| 442 | adapter->rx_queue.queue_dma = DMA_ERROR_CODE; |
| 443 | } |
| 444 | kfree(adapter->rx_queue.queue_addr); |
| 445 | adapter->rx_queue.queue_addr = NULL; |
| 446 | } |
| 447 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 448 | for(i = 0; i<IbmVethNumBufferPools; i++) |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 449 | if (adapter->rx_buff_pool[i].active) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 450 | ibmveth_free_buffer_pool(adapter, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 451 | &adapter->rx_buff_pool[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Michael Ellerman | bbedefc | 2006-10-03 12:24:23 -0500 | [diff] [blame] | 454 | static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, |
| 455 | union ibmveth_buf_desc rxq_desc, u64 mac_address) |
| 456 | { |
| 457 | int rc, try_again = 1; |
| 458 | |
| 459 | /* After a kexec the adapter will still be open, so our attempt to |
| 460 | * open it will fail. So if we get a failure we free the adapter and |
| 461 | * try again, but only once. */ |
| 462 | retry: |
| 463 | rc = h_register_logical_lan(adapter->vdev->unit_address, |
| 464 | adapter->buffer_list_dma, rxq_desc.desc, |
| 465 | adapter->filter_list_dma, mac_address); |
| 466 | |
| 467 | if (rc != H_SUCCESS && try_again) { |
| 468 | do { |
| 469 | rc = h_free_logical_lan(adapter->vdev->unit_address); |
| 470 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); |
| 471 | |
| 472 | try_again = 0; |
| 473 | goto retry; |
| 474 | } |
| 475 | |
| 476 | return rc; |
| 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | static int ibmveth_open(struct net_device *netdev) |
| 480 | { |
| 481 | struct ibmveth_adapter *adapter = netdev->priv; |
| 482 | u64 mac_address = 0; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 483 | int rxq_entries = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | unsigned long lpar_rc; |
| 485 | int rc; |
| 486 | union ibmveth_buf_desc rxq_desc; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 487 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | ibmveth_debug_printk("open starting\n"); |
| 490 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 491 | napi_enable(&adapter->napi); |
| 492 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 493 | for(i = 0; i<IbmVethNumBufferPools; i++) |
| 494 | rxq_entries += adapter->rx_buff_pool[i].size; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL); |
| 497 | adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | if(!adapter->buffer_list_addr || !adapter->filter_list_addr) { |
| 500 | ibmveth_error_printk("unable to allocate filter or buffer list pages\n"); |
| 501 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 502 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | return -ENOMEM; |
| 504 | } |
| 505 | |
| 506 | adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * rxq_entries; |
| 507 | adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, GFP_KERNEL); |
| 508 | |
| 509 | if(!adapter->rx_queue.queue_addr) { |
| 510 | ibmveth_error_printk("unable to allocate rx queue pages\n"); |
| 511 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 512 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | return -ENOMEM; |
| 514 | } |
| 515 | |
| 516 | adapter->buffer_list_dma = dma_map_single(&adapter->vdev->dev, |
| 517 | adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL); |
| 518 | adapter->filter_list_dma = dma_map_single(&adapter->vdev->dev, |
| 519 | adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL); |
| 520 | adapter->rx_queue.queue_dma = dma_map_single(&adapter->vdev->dev, |
| 521 | adapter->rx_queue.queue_addr, |
| 522 | adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL); |
| 523 | |
| 524 | if((dma_mapping_error(adapter->buffer_list_dma) ) || |
| 525 | (dma_mapping_error(adapter->filter_list_dma)) || |
| 526 | (dma_mapping_error(adapter->rx_queue.queue_dma))) { |
| 527 | ibmveth_error_printk("unable to map filter or buffer list pages\n"); |
| 528 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 529 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return -ENOMEM; |
| 531 | } |
| 532 | |
| 533 | adapter->rx_queue.index = 0; |
| 534 | adapter->rx_queue.num_slots = rxq_entries; |
| 535 | adapter->rx_queue.toggle = 1; |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); |
| 538 | mac_address = mac_address >> 16; |
| 539 | |
| 540 | rxq_desc.desc = 0; |
| 541 | rxq_desc.fields.valid = 1; |
| 542 | rxq_desc.fields.length = adapter->rx_queue.queue_len; |
| 543 | rxq_desc.fields.address = adapter->rx_queue.queue_dma; |
| 544 | |
| 545 | ibmveth_debug_printk("buffer list @ 0x%p\n", adapter->buffer_list_addr); |
| 546 | ibmveth_debug_printk("filter list @ 0x%p\n", adapter->filter_list_addr); |
| 547 | ibmveth_debug_printk("receive q @ 0x%p\n", adapter->rx_queue.queue_addr); |
| 548 | |
Santiago Leon | 4347ef1 | 2006-10-03 12:24:34 -0500 | [diff] [blame] | 549 | h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); |
| 550 | |
Michael Ellerman | bbedefc | 2006-10-03 12:24:23 -0500 | [diff] [blame] | 551 | lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 553 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc); |
Stephen Rothwell | 8168f90 | 2005-10-25 16:56:43 +1000 | [diff] [blame] | 555 | ibmveth_error_printk("buffer TCE:0x%lx filter TCE:0x%lx rxq desc:0x%lx MAC:0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | adapter->buffer_list_dma, |
| 557 | adapter->filter_list_dma, |
| 558 | rxq_desc.desc, |
| 559 | mac_address); |
| 560 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 561 | napi_disable(&adapter->napi); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 562 | return -ENONET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 565 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
| 566 | if(!adapter->rx_buff_pool[i].active) |
| 567 | continue; |
| 568 | if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) { |
| 569 | ibmveth_error_printk("unable to alloc pool\n"); |
| 570 | adapter->rx_buff_pool[i].active = 0; |
| 571 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 572 | napi_disable(&adapter->napi); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 573 | return -ENOMEM ; |
| 574 | } |
| 575 | } |
| 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | ibmveth_debug_printk("registering irq 0x%x\n", netdev->irq); |
| 578 | if((rc = request_irq(netdev->irq, &ibmveth_interrupt, 0, netdev->name, netdev)) != 0) { |
| 579 | ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc); |
| 580 | do { |
| 581 | rc = h_free_logical_lan(adapter->vdev->unit_address); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 582 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 585 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return rc; |
| 587 | } |
| 588 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 589 | ibmveth_debug_printk("initial replenish cycle\n"); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 590 | ibmveth_interrupt(netdev->irq, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 592 | netif_start_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | ibmveth_debug_printk("open complete\n"); |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static int ibmveth_close(struct net_device *netdev) |
| 600 | { |
| 601 | struct ibmveth_adapter *adapter = netdev->priv; |
| 602 | long lpar_rc; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | ibmveth_debug_printk("close starting\n"); |
| 605 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 606 | napi_disable(&adapter->napi); |
| 607 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 608 | if (!adapter->pool_config) |
| 609 | netif_stop_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | free_irq(netdev->irq, netdev); |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | do { |
| 614 | lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 615 | } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 617 | if(lpar_rc != H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
| 619 | ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n", |
| 620 | lpar_rc); |
| 621 | } |
| 622 | |
| 623 | adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); |
| 624 | |
| 625 | ibmveth_cleanup(adapter); |
| 626 | |
| 627 | ibmveth_debug_printk("close complete\n"); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { |
| 633 | cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE); |
| 634 | cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ADVERTISED_FIBRE); |
| 635 | cmd->speed = SPEED_1000; |
| 636 | cmd->duplex = DUPLEX_FULL; |
| 637 | cmd->port = PORT_FIBRE; |
| 638 | cmd->phy_address = 0; |
| 639 | cmd->transceiver = XCVR_INTERNAL; |
| 640 | cmd->autoneg = AUTONEG_ENABLE; |
| 641 | cmd->maxtxpkt = 0; |
| 642 | cmd->maxrxpkt = 1; |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info) { |
| 647 | strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1); |
| 648 | strncpy(info->version, ibmveth_driver_version, sizeof(info->version) - 1); |
| 649 | } |
| 650 | |
| 651 | static u32 netdev_get_link(struct net_device *dev) { |
| 652 | return 1; |
| 653 | } |
| 654 | |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame^] | 655 | static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data) |
| 656 | { |
| 657 | struct ibmveth_adapter *adapter = dev->priv; |
| 658 | |
| 659 | if (data) |
| 660 | adapter->rx_csum = 1; |
| 661 | else { |
| 662 | /* |
| 663 | * Since the ibmveth firmware interface does not have the concept of |
| 664 | * separate tx/rx checksum offload enable, if rx checksum is disabled |
| 665 | * we also have to disable tx checksum offload. Once we disable rx |
| 666 | * checksum offload, we are no longer allowed to send tx buffers that |
| 667 | * are not properly checksummed. |
| 668 | */ |
| 669 | adapter->rx_csum = 0; |
| 670 | dev->features &= ~NETIF_F_IP_CSUM; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data) |
| 675 | { |
| 676 | struct ibmveth_adapter *adapter = dev->priv; |
| 677 | |
| 678 | if (data) { |
| 679 | dev->features |= NETIF_F_IP_CSUM; |
| 680 | adapter->rx_csum = 1; |
| 681 | } else |
| 682 | dev->features &= ~NETIF_F_IP_CSUM; |
| 683 | } |
| 684 | |
| 685 | static int ibmveth_set_csum_offload(struct net_device *dev, u32 data, |
| 686 | void (*done) (struct net_device *, u32)) |
| 687 | { |
| 688 | struct ibmveth_adapter *adapter = dev->priv; |
| 689 | union ibmveth_illan_attributes set_attr, clr_attr, ret_attr; |
| 690 | long ret; |
| 691 | int rc1 = 0, rc2 = 0; |
| 692 | int restart = 0; |
| 693 | |
| 694 | if (netif_running(dev)) { |
| 695 | restart = 1; |
| 696 | adapter->pool_config = 1; |
| 697 | ibmveth_close(dev); |
| 698 | adapter->pool_config = 0; |
| 699 | } |
| 700 | |
| 701 | set_attr.desc = 0; |
| 702 | clr_attr.desc = 0; |
| 703 | |
| 704 | if (data) |
| 705 | set_attr.fields.tcp_csum_offload_ipv4 = 1; |
| 706 | else |
| 707 | clr_attr.fields.tcp_csum_offload_ipv4 = 1; |
| 708 | |
| 709 | ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr.desc); |
| 710 | |
| 711 | if (ret == H_SUCCESS && !ret_attr.fields.active_trunk && |
| 712 | !ret_attr.fields.trunk_priority && |
| 713 | ret_attr.fields.csum_offload_padded_pkt_support) { |
| 714 | ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr.desc, |
| 715 | set_attr.desc, &ret_attr.desc); |
| 716 | |
| 717 | if (ret != H_SUCCESS) { |
| 718 | rc1 = -EIO; |
| 719 | ibmveth_error_printk("unable to change checksum offload settings." |
| 720 | " %d rc=%ld\n", data, ret); |
| 721 | |
| 722 | ret = h_illan_attributes(adapter->vdev->unit_address, |
| 723 | set_attr.desc, clr_attr.desc, &ret_attr.desc); |
| 724 | } else |
| 725 | done(dev, data); |
| 726 | } else { |
| 727 | rc1 = -EIO; |
| 728 | ibmveth_error_printk("unable to change checksum offload settings." |
| 729 | " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr.desc); |
| 730 | } |
| 731 | |
| 732 | if (restart) |
| 733 | rc2 = ibmveth_open(dev); |
| 734 | |
| 735 | return rc1 ? rc1 : rc2; |
| 736 | } |
| 737 | |
| 738 | static int ibmveth_set_rx_csum(struct net_device *dev, u32 data) |
| 739 | { |
| 740 | struct ibmveth_adapter *adapter = dev->priv; |
| 741 | |
| 742 | if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum)) |
| 743 | return 0; |
| 744 | |
| 745 | return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags); |
| 746 | } |
| 747 | |
| 748 | static int ibmveth_set_tx_csum(struct net_device *dev, u32 data) |
| 749 | { |
| 750 | struct ibmveth_adapter *adapter = dev->priv; |
| 751 | int rc = 0; |
| 752 | |
| 753 | if (data && (dev->features & NETIF_F_IP_CSUM)) |
| 754 | return 0; |
| 755 | if (!data && !(dev->features & NETIF_F_IP_CSUM)) |
| 756 | return 0; |
| 757 | |
| 758 | if (data && !adapter->rx_csum) |
| 759 | rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags); |
| 760 | else |
| 761 | ibmveth_set_tx_csum_flags(dev, data); |
| 762 | |
| 763 | return rc; |
| 764 | } |
| 765 | |
| 766 | static u32 ibmveth_get_rx_csum(struct net_device *dev) |
| 767 | { |
| 768 | struct ibmveth_adapter *adapter = dev->priv; |
| 769 | return adapter->rx_csum; |
| 770 | } |
| 771 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 772 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | .get_drvinfo = netdev_get_drvinfo, |
| 774 | .get_settings = netdev_get_settings, |
| 775 | .get_link = netdev_get_link, |
| 776 | .get_sg = ethtool_op_get_sg, |
| 777 | .get_tx_csum = ethtool_op_get_tx_csum, |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame^] | 778 | .set_tx_csum = ibmveth_set_tx_csum, |
| 779 | .get_rx_csum = ibmveth_get_rx_csum, |
| 780 | .set_rx_csum = ibmveth_set_rx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 784 | { |
| 785 | return -EOPNOTSUPP; |
| 786 | } |
| 787 | |
| 788 | #define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1)) |
| 789 | |
| 790 | static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 791 | { |
| 792 | struct ibmveth_adapter *adapter = netdev->priv; |
| 793 | union ibmveth_buf_desc desc[IbmVethMaxSendFrags]; |
| 794 | unsigned long lpar_rc; |
| 795 | int nfrags = 0, curfrag; |
| 796 | unsigned long correlator; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 797 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | unsigned int retry_count; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 799 | unsigned int tx_dropped = 0; |
| 800 | unsigned int tx_bytes = 0; |
| 801 | unsigned int tx_packets = 0; |
| 802 | unsigned int tx_send_failed = 0; |
| 803 | unsigned int tx_map_failed = 0; |
| 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | if ((skb_shinfo(skb)->nr_frags + 1) > IbmVethMaxSendFrags) { |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 807 | tx_dropped++; |
| 808 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | memset(&desc, 0, sizeof(desc)); |
| 812 | |
| 813 | /* nfrags = number of frags after the initial fragment */ |
| 814 | nfrags = skb_shinfo(skb)->nr_frags; |
| 815 | |
| 816 | if(nfrags) |
| 817 | adapter->tx_multidesc_send++; |
| 818 | |
| 819 | /* map the initial fragment */ |
| 820 | desc[0].fields.length = nfrags ? skb->len - skb->data_len : skb->len; |
| 821 | desc[0].fields.address = dma_map_single(&adapter->vdev->dev, skb->data, |
| 822 | desc[0].fields.length, DMA_TO_DEVICE); |
| 823 | desc[0].fields.valid = 1; |
| 824 | |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 825 | if (skb->ip_summed == CHECKSUM_PARTIAL && |
| 826 | ip_hdr(skb)->protocol != IPPROTO_TCP && skb_checksum_help(skb)) { |
| 827 | ibmveth_error_printk("tx: failed to checksum packet\n"); |
| 828 | tx_dropped++; |
| 829 | goto out; |
| 830 | } |
| 831 | |
| 832 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 833 | unsigned char *buf = skb_transport_header(skb) + skb->csum_offset; |
| 834 | |
| 835 | desc[0].fields.no_csum = 1; |
| 836 | desc[0].fields.csum_good = 1; |
| 837 | |
| 838 | /* Need to zero out the checksum */ |
| 839 | buf[0] = 0; |
| 840 | buf[1] = 0; |
| 841 | } |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | if(dma_mapping_error(desc[0].fields.address)) { |
| 844 | ibmveth_error_printk("tx: unable to map initial fragment\n"); |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 845 | tx_map_failed++; |
| 846 | tx_dropped++; |
| 847 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | curfrag = nfrags; |
| 851 | |
| 852 | /* map fragments past the initial portion if there are any */ |
| 853 | while(curfrag--) { |
| 854 | skb_frag_t *frag = &skb_shinfo(skb)->frags[curfrag]; |
| 855 | desc[curfrag+1].fields.address |
| 856 | = dma_map_single(&adapter->vdev->dev, |
| 857 | page_address(frag->page) + frag->page_offset, |
| 858 | frag->size, DMA_TO_DEVICE); |
| 859 | desc[curfrag+1].fields.length = frag->size; |
| 860 | desc[curfrag+1].fields.valid = 1; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 861 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 862 | desc[curfrag+1].fields.no_csum = 1; |
| 863 | desc[curfrag+1].fields.csum_good = 1; |
| 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | if(dma_mapping_error(desc[curfrag+1].fields.address)) { |
| 867 | ibmveth_error_printk("tx: unable to map fragment %d\n", curfrag); |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 868 | tx_map_failed++; |
| 869 | tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | /* Free all the mappings we just created */ |
| 871 | while(curfrag < nfrags) { |
| 872 | dma_unmap_single(&adapter->vdev->dev, |
| 873 | desc[curfrag+1].fields.address, |
| 874 | desc[curfrag+1].fields.length, |
| 875 | DMA_TO_DEVICE); |
| 876 | curfrag++; |
| 877 | } |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 878 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
| 882 | /* send the frame. Arbitrarily set retrycount to 1024 */ |
| 883 | correlator = 0; |
| 884 | retry_count = 1024; |
| 885 | do { |
| 886 | lpar_rc = h_send_logical_lan(adapter->vdev->unit_address, |
| 887 | desc[0].desc, |
| 888 | desc[1].desc, |
| 889 | desc[2].desc, |
| 890 | desc[3].desc, |
| 891 | desc[4].desc, |
| 892 | desc[5].desc, |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 893 | correlator, |
| 894 | &correlator); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 895 | } while ((lpar_rc == H_BUSY) && (retry_count--)); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 896 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 897 | if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | int i; |
| 899 | ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc); |
| 900 | for(i = 0; i < 6; i++) { |
| 901 | ibmveth_error_printk("tx: desc[%i] valid=%d, len=%d, address=0x%d\n", i, |
| 902 | desc[i].fields.valid, desc[i].fields.length, desc[i].fields.address); |
| 903 | } |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 904 | tx_send_failed++; |
| 905 | tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } else { |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 907 | tx_packets++; |
| 908 | tx_bytes += skb->len; |
Santiago Leon | 0abe791 | 2005-10-26 10:46:53 -0600 | [diff] [blame] | 909 | netdev->trans_start = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | do { |
| 913 | dma_unmap_single(&adapter->vdev->dev, |
| 914 | desc[nfrags].fields.address, |
| 915 | desc[nfrags].fields.length, DMA_TO_DEVICE); |
| 916 | } while(--nfrags >= 0); |
| 917 | |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 918 | out: spin_lock_irqsave(&adapter->stats_lock, flags); |
| 919 | adapter->stats.tx_dropped += tx_dropped; |
| 920 | adapter->stats.tx_bytes += tx_bytes; |
| 921 | adapter->stats.tx_packets += tx_packets; |
| 922 | adapter->tx_send_failed += tx_send_failed; |
| 923 | adapter->tx_map_failed += tx_map_failed; |
| 924 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | dev_kfree_skb(skb); |
| 927 | return 0; |
| 928 | } |
| 929 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 930 | static int ibmveth_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 932 | struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi); |
| 933 | struct net_device *netdev = adapter->netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | int frames_processed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | unsigned long lpar_rc; |
| 936 | |
| 937 | restart_poll: |
| 938 | do { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 939 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 941 | if (!ibmveth_rxq_pending_buffer(adapter)) |
| 942 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 944 | rmb(); |
| 945 | if (!ibmveth_rxq_buffer_valid(adapter)) { |
| 946 | wmb(); /* suggested by larson1 */ |
| 947 | adapter->rx_invalid_buffer++; |
| 948 | ibmveth_debug_printk("recycling invalid buffer\n"); |
| 949 | ibmveth_rxq_recycle_buffer(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } else { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 951 | int length = ibmveth_rxq_frame_length(adapter); |
| 952 | int offset = ibmveth_rxq_frame_offset(adapter); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 953 | int csum_good = ibmveth_rxq_csum_good(adapter); |
| 954 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 955 | skb = ibmveth_rxq_get_buffer(adapter); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 956 | if (csum_good) |
| 957 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 958 | |
| 959 | ibmveth_rxq_harvest_buffer(adapter); |
| 960 | |
| 961 | skb_reserve(skb, offset); |
| 962 | skb_put(skb, length); |
| 963 | skb->protocol = eth_type_trans(skb, netdev); |
| 964 | |
| 965 | netif_receive_skb(skb); /* send it up */ |
| 966 | |
| 967 | adapter->stats.rx_packets++; |
| 968 | adapter->stats.rx_bytes += length; |
| 969 | frames_processed++; |
| 970 | netdev->last_rx = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 972 | } while (frames_processed < budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 974 | ibmveth_replenish_task(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 976 | if (frames_processed < budget) { |
| 977 | /* We think we are done - reenable interrupts, |
| 978 | * then check once more to make sure we are done. |
| 979 | */ |
| 980 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 981 | VIO_IRQ_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 983 | ibmveth_assert(lpar_rc == H_SUCCESS); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 984 | |
| 985 | netif_rx_complete(netdev, napi); |
| 986 | |
| 987 | if (ibmveth_rxq_pending_buffer(adapter) && |
| 988 | netif_rx_reschedule(netdev, napi)) { |
| 989 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 990 | VIO_IRQ_DISABLE); |
| 991 | goto restart_poll; |
| 992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 995 | return frames_processed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 998 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 999 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | struct net_device *netdev = dev_instance; |
| 1001 | struct ibmveth_adapter *adapter = netdev->priv; |
| 1002 | unsigned long lpar_rc; |
| 1003 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1004 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { |
| 1005 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 1006 | VIO_IRQ_DISABLE); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1007 | ibmveth_assert(lpar_rc == H_SUCCESS); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1008 | __netif_rx_schedule(netdev, &adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
| 1010 | return IRQ_HANDLED; |
| 1011 | } |
| 1012 | |
| 1013 | static struct net_device_stats *ibmveth_get_stats(struct net_device *dev) |
| 1014 | { |
| 1015 | struct ibmveth_adapter *adapter = dev->priv; |
| 1016 | return &adapter->stats; |
| 1017 | } |
| 1018 | |
| 1019 | static void ibmveth_set_multicast_list(struct net_device *netdev) |
| 1020 | { |
| 1021 | struct ibmveth_adapter *adapter = netdev->priv; |
| 1022 | unsigned long lpar_rc; |
| 1023 | |
| 1024 | if((netdev->flags & IFF_PROMISC) || (netdev->mc_count > adapter->mcastFilterSize)) { |
| 1025 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1026 | IbmVethMcastEnableRecv | |
| 1027 | IbmVethMcastDisableFiltering, |
| 1028 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1029 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc); |
| 1031 | } |
| 1032 | } else { |
| 1033 | struct dev_mc_list *mclist = netdev->mc_list; |
| 1034 | int i; |
| 1035 | /* clear the filter table & disable filtering */ |
| 1036 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1037 | IbmVethMcastEnableRecv | |
| 1038 | IbmVethMcastDisableFiltering | |
| 1039 | IbmVethMcastClearFilterTable, |
| 1040 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1041 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc); |
| 1043 | } |
| 1044 | /* add the addresses to the filter table */ |
| 1045 | for(i = 0; i < netdev->mc_count; ++i, mclist = mclist->next) { |
| 1046 | // add the multicast address to the filter table |
| 1047 | unsigned long mcast_addr = 0; |
| 1048 | memcpy(((char *)&mcast_addr)+2, mclist->dmi_addr, 6); |
| 1049 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1050 | IbmVethMcastAddFilter, |
| 1051 | mcast_addr); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1052 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc); |
| 1054 | } |
| 1055 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | /* re-enable filtering */ |
| 1058 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1059 | IbmVethMcastEnableFiltering, |
| 1060 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1061 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc); |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) |
| 1068 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1069 | struct ibmveth_adapter *adapter = dev->priv; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1070 | int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH; |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1071 | int reinit = 0; |
| 1072 | int i, rc; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1073 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1074 | if (new_mtu < IBMVETH_MAX_MTU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | return -EINVAL; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1076 | |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1077 | for (i = 0; i < IbmVethNumBufferPools; i++) |
| 1078 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) |
| 1079 | break; |
| 1080 | |
| 1081 | if (i == IbmVethNumBufferPools) |
| 1082 | return -EINVAL; |
| 1083 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1084 | /* Look for an active buffer pool that can hold the new MTU */ |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1085 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1086 | if (!adapter->rx_buff_pool[i].active) { |
| 1087 | adapter->rx_buff_pool[i].active = 1; |
| 1088 | reinit = 1; |
| 1089 | } |
| 1090 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1091 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1092 | if (reinit && netif_running(adapter->netdev)) { |
| 1093 | adapter->pool_config = 1; |
| 1094 | ibmveth_close(adapter->netdev); |
| 1095 | adapter->pool_config = 0; |
| 1096 | dev->mtu = new_mtu; |
| 1097 | if ((rc = ibmveth_open(adapter->netdev))) |
| 1098 | return rc; |
| 1099 | } else |
| 1100 | dev->mtu = new_mtu; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1101 | return 0; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1102 | } |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1103 | } |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1104 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1107 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1108 | static void ibmveth_poll_controller(struct net_device *dev) |
| 1109 | { |
| 1110 | ibmveth_replenish_task(dev->priv); |
Andrew Morton | 5f77113 | 2006-10-10 14:33:30 -0700 | [diff] [blame] | 1111 | ibmveth_interrupt(dev->irq, dev); |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1112 | } |
| 1113 | #endif |
| 1114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) |
| 1116 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1117 | int rc, i; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1118 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | struct net_device *netdev; |
Mariusz Kozlowski | 9dc83af | 2007-08-06 23:44:03 +0200 | [diff] [blame] | 1120 | struct ibmveth_adapter *adapter; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1121 | union ibmveth_illan_attributes set_attr, ret_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
| 1123 | unsigned char *mac_addr_p; |
| 1124 | unsigned int *mcastFilterSize_p; |
| 1125 | |
| 1126 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1127 | ibmveth_debug_printk_no_adapter("entering ibmveth_probe for UA 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | dev->unit_address); |
| 1129 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 1130 | mac_addr_p = (unsigned char *) vio_get_attribute(dev, |
| 1131 | VETH_MAC_ADDR, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | if(!mac_addr_p) { |
| 1133 | printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR " |
| 1134 | "attribute\n", __FILE__, __LINE__); |
| 1135 | return 0; |
| 1136 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1137 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 1138 | mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev, |
| 1139 | VETH_MCAST_FILTER_SIZE, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | if(!mcastFilterSize_p) { |
| 1141 | printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find " |
| 1142 | "VETH_MCAST_FILTER_SIZE attribute\n", |
| 1143 | __FILE__, __LINE__); |
| 1144 | return 0; |
| 1145 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | netdev = alloc_etherdev(sizeof(struct ibmveth_adapter)); |
| 1148 | |
| 1149 | if(!netdev) |
| 1150 | return -ENOMEM; |
| 1151 | |
| 1152 | SET_MODULE_OWNER(netdev); |
| 1153 | |
| 1154 | adapter = netdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | dev->dev.driver_data = netdev; |
| 1156 | |
| 1157 | adapter->vdev = dev; |
| 1158 | adapter->netdev = netdev; |
| 1159 | adapter->mcastFilterSize= *mcastFilterSize_p; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1160 | adapter->pool_config = 0; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1161 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1162 | netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); |
| 1163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | /* Some older boxes running PHYP non-natively have an OF that |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1165 | returns a 8-byte local-mac-address field (and the first |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | 2 bytes have to be ignored) while newer boxes' OF return |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1167 | a 6-byte field. Note that IEEE 1275 specifies that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | local-mac-address must be a 6-byte field. |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1169 | The RPA doc specifies that the first byte must be 10b, so |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | we'll just look for it to solve this 8 vs. 6 byte field issue */ |
| 1171 | |
| 1172 | if ((*mac_addr_p & 0x3) != 0x02) |
| 1173 | mac_addr_p += 2; |
| 1174 | |
| 1175 | adapter->mac_addr = 0; |
| 1176 | memcpy(&adapter->mac_addr, mac_addr_p, 6); |
| 1177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | netdev->irq = dev->irq; |
| 1179 | netdev->open = ibmveth_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | netdev->stop = ibmveth_close; |
| 1181 | netdev->hard_start_xmit = ibmveth_start_xmit; |
| 1182 | netdev->get_stats = ibmveth_get_stats; |
| 1183 | netdev->set_multicast_list = ibmveth_set_multicast_list; |
| 1184 | netdev->do_ioctl = ibmveth_ioctl; |
| 1185 | netdev->ethtool_ops = &netdev_ethtool_ops; |
| 1186 | netdev->change_mtu = ibmveth_change_mtu; |
| 1187 | SET_NETDEV_DEV(netdev, &dev->dev); |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1188 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1189 | netdev->poll_controller = ibmveth_poll_controller; |
| 1190 | #endif |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1191 | netdev->features |= NETIF_F_LLTX; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 1192 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | memcpy(&netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); |
| 1195 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1196 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
| 1197 | struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1198 | ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, |
| 1199 | pool_count[i], pool_size[i], |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1200 | pool_active[i]); |
| 1201 | kobj->parent = &dev->dev.kobj; |
| 1202 | sprintf(kobj->name, "pool%d", i); |
| 1203 | kobj->ktype = &ktype_veth_pool; |
| 1204 | kobject_register(kobj); |
| 1205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
| 1207 | ibmveth_debug_printk("adapter @ 0x%p\n", adapter); |
| 1208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | adapter->buffer_list_dma = DMA_ERROR_CODE; |
| 1210 | adapter->filter_list_dma = DMA_ERROR_CODE; |
| 1211 | adapter->rx_queue.queue_dma = DMA_ERROR_CODE; |
| 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | ibmveth_debug_printk("registering netdev...\n"); |
| 1214 | |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1215 | ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr.desc); |
| 1216 | |
| 1217 | if (ret == H_SUCCESS && !ret_attr.fields.active_trunk && |
| 1218 | !ret_attr.fields.trunk_priority && |
| 1219 | ret_attr.fields.csum_offload_padded_pkt_support) { |
| 1220 | set_attr.desc = 0; |
| 1221 | set_attr.fields.tcp_csum_offload_ipv4 = 1; |
| 1222 | |
| 1223 | ret = h_illan_attributes(dev->unit_address, 0, set_attr.desc, |
| 1224 | &ret_attr.desc); |
| 1225 | |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame^] | 1226 | if (ret == H_SUCCESS) { |
| 1227 | adapter->rx_csum = 1; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1228 | netdev->features |= NETIF_F_IP_CSUM; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame^] | 1229 | } else |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1230 | ret = h_illan_attributes(dev->unit_address, set_attr.desc, |
| 1231 | 0, &ret_attr.desc); |
| 1232 | } |
| 1233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | rc = register_netdev(netdev); |
| 1235 | |
| 1236 | if(rc) { |
| 1237 | ibmveth_debug_printk("failed to register netdev rc=%d\n", rc); |
| 1238 | free_netdev(netdev); |
| 1239 | return rc; |
| 1240 | } |
| 1241 | |
| 1242 | ibmveth_debug_printk("registered\n"); |
| 1243 | |
| 1244 | ibmveth_proc_register_adapter(adapter); |
| 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static int __devexit ibmveth_remove(struct vio_dev *dev) |
| 1250 | { |
| 1251 | struct net_device *netdev = dev->dev.driver_data; |
| 1252 | struct ibmveth_adapter *adapter = netdev->priv; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1253 | int i; |
| 1254 | |
| 1255 | for(i = 0; i<IbmVethNumBufferPools; i++) |
| 1256 | kobject_unregister(&adapter->rx_buff_pool[i].kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
| 1258 | unregister_netdev(netdev); |
| 1259 | |
| 1260 | ibmveth_proc_unregister_adapter(adapter); |
| 1261 | |
| 1262 | free_netdev(netdev); |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | #ifdef CONFIG_PROC_FS |
| 1267 | static void ibmveth_proc_register_driver(void) |
| 1268 | { |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1269 | ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | if (ibmveth_proc_dir) { |
| 1271 | SET_MODULE_OWNER(ibmveth_proc_dir); |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | static void ibmveth_proc_unregister_driver(void) |
| 1276 | { |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1277 | remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1280 | static void *ibmveth_seq_start(struct seq_file *seq, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | { |
| 1282 | if (*pos == 0) { |
| 1283 | return (void *)1; |
| 1284 | } else { |
| 1285 | return NULL; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | static void *ibmveth_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1290 | { |
| 1291 | ++*pos; |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1295 | static void ibmveth_seq_stop(struct seq_file *seq, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
| 1297 | } |
| 1298 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1299 | static int ibmveth_seq_show(struct seq_file *seq, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | { |
| 1301 | struct ibmveth_adapter *adapter = seq->private; |
| 1302 | char *current_mac = ((char*) &adapter->netdev->dev_addr); |
| 1303 | char *firmware_mac = ((char*) &adapter->mac_addr) ; |
| 1304 | |
| 1305 | seq_printf(seq, "%s %s\n\n", ibmveth_driver_string, ibmveth_driver_version); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | seq_printf(seq, "Current MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 1309 | current_mac[0], current_mac[1], current_mac[2], |
| 1310 | current_mac[3], current_mac[4], current_mac[5]); |
| 1311 | seq_printf(seq, "Firmware MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 1312 | firmware_mac[0], firmware_mac[1], firmware_mac[2], |
| 1313 | firmware_mac[3], firmware_mac[4], firmware_mac[5]); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | seq_printf(seq, "\nAdapter Statistics:\n"); |
| 1316 | seq_printf(seq, " TX: skbuffs linearized: %ld\n", adapter->tx_linearized); |
| 1317 | seq_printf(seq, " multi-descriptor sends: %ld\n", adapter->tx_multidesc_send); |
| 1318 | seq_printf(seq, " skb_linearize failures: %ld\n", adapter->tx_linearize_failed); |
| 1319 | seq_printf(seq, " vio_map_single failres: %ld\n", adapter->tx_map_failed); |
| 1320 | seq_printf(seq, " send failures: %ld\n", adapter->tx_send_failed); |
| 1321 | seq_printf(seq, " RX: replenish task cycles: %ld\n", adapter->replenish_task_cycles); |
| 1322 | seq_printf(seq, " alloc_skb_failures: %ld\n", adapter->replenish_no_mem); |
| 1323 | seq_printf(seq, " add buffer failures: %ld\n", adapter->replenish_add_buff_failure); |
| 1324 | seq_printf(seq, " invalid buffers: %ld\n", adapter->rx_invalid_buffer); |
| 1325 | seq_printf(seq, " no buffers: %ld\n", adapter->rx_no_buffer); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | return 0; |
| 1328 | } |
| 1329 | static struct seq_operations ibmveth_seq_ops = { |
| 1330 | .start = ibmveth_seq_start, |
| 1331 | .next = ibmveth_seq_next, |
| 1332 | .stop = ibmveth_seq_stop, |
| 1333 | .show = ibmveth_seq_show, |
| 1334 | }; |
| 1335 | |
| 1336 | static int ibmveth_proc_open(struct inode *inode, struct file *file) |
| 1337 | { |
| 1338 | struct seq_file *seq; |
| 1339 | struct proc_dir_entry *proc; |
| 1340 | int rc; |
| 1341 | |
| 1342 | rc = seq_open(file, &ibmveth_seq_ops); |
| 1343 | if (!rc) { |
| 1344 | /* recover the pointer buried in proc_dir_entry data */ |
| 1345 | seq = file->private_data; |
| 1346 | proc = PDE(inode); |
| 1347 | seq->private = proc->data; |
| 1348 | } |
| 1349 | return rc; |
| 1350 | } |
| 1351 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1352 | static const struct file_operations ibmveth_proc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | .owner = THIS_MODULE, |
| 1354 | .open = ibmveth_proc_open, |
| 1355 | .read = seq_read, |
| 1356 | .llseek = seq_lseek, |
| 1357 | .release = seq_release, |
| 1358 | }; |
| 1359 | |
| 1360 | static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter) |
| 1361 | { |
| 1362 | struct proc_dir_entry *entry; |
| 1363 | if (ibmveth_proc_dir) { |
Santiago Leon | 03a85d0 | 2006-10-03 12:24:39 -0500 | [diff] [blame] | 1364 | char u_addr[10]; |
| 1365 | sprintf(u_addr, "%x", adapter->vdev->unit_address); |
| 1366 | entry = create_proc_entry(u_addr, S_IFREG, ibmveth_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | if (!entry) { |
| 1368 | ibmveth_error_printk("Cannot create adapter proc entry"); |
| 1369 | } else { |
| 1370 | entry->data = (void *) adapter; |
| 1371 | entry->proc_fops = &ibmveth_proc_fops; |
| 1372 | SET_MODULE_OWNER(entry); |
| 1373 | } |
| 1374 | } |
| 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter) |
| 1379 | { |
| 1380 | if (ibmveth_proc_dir) { |
Santiago Leon | 03a85d0 | 2006-10-03 12:24:39 -0500 | [diff] [blame] | 1381 | char u_addr[10]; |
| 1382 | sprintf(u_addr, "%x", adapter->vdev->unit_address); |
| 1383 | remove_proc_entry(u_addr, ibmveth_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | #else /* CONFIG_PROC_FS */ |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1388 | static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | { |
| 1390 | } |
| 1391 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1392 | static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
| 1394 | } |
| 1395 | static void ibmveth_proc_register_driver(void) |
| 1396 | { |
| 1397 | } |
| 1398 | |
| 1399 | static void ibmveth_proc_unregister_driver(void) |
| 1400 | { |
| 1401 | } |
| 1402 | #endif /* CONFIG_PROC_FS */ |
| 1403 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1404 | static struct attribute veth_active_attr; |
| 1405 | static struct attribute veth_num_attr; |
| 1406 | static struct attribute veth_size_attr; |
| 1407 | |
| 1408 | static ssize_t veth_pool_show(struct kobject * kobj, |
| 1409 | struct attribute * attr, char * buf) |
| 1410 | { |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1411 | struct ibmveth_buff_pool *pool = container_of(kobj, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1412 | struct ibmveth_buff_pool, |
| 1413 | kobj); |
| 1414 | |
| 1415 | if (attr == &veth_active_attr) |
| 1416 | return sprintf(buf, "%d\n", pool->active); |
| 1417 | else if (attr == &veth_num_attr) |
| 1418 | return sprintf(buf, "%d\n", pool->size); |
| 1419 | else if (attr == &veth_size_attr) |
| 1420 | return sprintf(buf, "%d\n", pool->buff_size); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr, |
| 1425 | const char * buf, size_t count) |
| 1426 | { |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1427 | struct ibmveth_buff_pool *pool = container_of(kobj, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1428 | struct ibmveth_buff_pool, |
| 1429 | kobj); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1430 | struct net_device *netdev = |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1431 | container_of(kobj->parent, struct device, kobj)->driver_data; |
| 1432 | struct ibmveth_adapter *adapter = netdev->priv; |
| 1433 | long value = simple_strtol(buf, NULL, 10); |
| 1434 | long rc; |
| 1435 | |
| 1436 | if (attr == &veth_active_attr) { |
| 1437 | if (value && !pool->active) { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 1438 | if (netif_running(netdev)) { |
| 1439 | if(ibmveth_alloc_buffer_pool(pool)) { |
| 1440 | ibmveth_error_printk("unable to alloc pool\n"); |
| 1441 | return -ENOMEM; |
| 1442 | } |
| 1443 | pool->active = 1; |
| 1444 | adapter->pool_config = 1; |
| 1445 | ibmveth_close(netdev); |
| 1446 | adapter->pool_config = 0; |
| 1447 | if ((rc = ibmveth_open(netdev))) |
| 1448 | return rc; |
| 1449 | } else |
| 1450 | pool->active = 1; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1451 | } else if (!value && pool->active) { |
| 1452 | int mtu = netdev->mtu + IBMVETH_BUFF_OH; |
| 1453 | int i; |
| 1454 | /* Make sure there is a buffer pool with buffers that |
| 1455 | can hold a packet of the size of the MTU */ |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1456 | for (i = 0; i < IbmVethNumBufferPools; i++) { |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1457 | if (pool == &adapter->rx_buff_pool[i]) |
| 1458 | continue; |
| 1459 | if (!adapter->rx_buff_pool[i].active) |
| 1460 | continue; |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1461 | if (mtu <= adapter->rx_buff_pool[i].buff_size) |
| 1462 | break; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1463 | } |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1464 | |
| 1465 | if (i == IbmVethNumBufferPools) { |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1466 | ibmveth_error_printk("no active pool >= MTU\n"); |
| 1467 | return -EPERM; |
| 1468 | } |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1469 | |
| 1470 | pool->active = 0; |
| 1471 | if (netif_running(netdev)) { |
| 1472 | adapter->pool_config = 1; |
| 1473 | ibmveth_close(netdev); |
| 1474 | adapter->pool_config = 0; |
| 1475 | if ((rc = ibmveth_open(netdev))) |
| 1476 | return rc; |
| 1477 | } |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1478 | } |
| 1479 | } else if (attr == &veth_num_attr) { |
| 1480 | if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) |
| 1481 | return -EINVAL; |
| 1482 | else { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 1483 | if (netif_running(netdev)) { |
| 1484 | adapter->pool_config = 1; |
| 1485 | ibmveth_close(netdev); |
| 1486 | adapter->pool_config = 0; |
| 1487 | pool->size = value; |
| 1488 | if ((rc = ibmveth_open(netdev))) |
| 1489 | return rc; |
| 1490 | } else |
| 1491 | pool->size = value; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1492 | } |
| 1493 | } else if (attr == &veth_size_attr) { |
| 1494 | if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) |
| 1495 | return -EINVAL; |
| 1496 | else { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 1497 | if (netif_running(netdev)) { |
| 1498 | adapter->pool_config = 1; |
| 1499 | ibmveth_close(netdev); |
| 1500 | adapter->pool_config = 0; |
| 1501 | pool->buff_size = value; |
| 1502 | if ((rc = ibmveth_open(netdev))) |
| 1503 | return rc; |
| 1504 | } else |
| 1505 | pool->buff_size = value; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | /* kick the interrupt handler to allocate/deallocate pools */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1510 | ibmveth_interrupt(netdev->irq, netdev); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1511 | return count; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | #define ATTR(_name, _mode) \ |
| 1516 | struct attribute veth_##_name##_attr = { \ |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 1517 | .name = __stringify(_name), .mode = _mode, \ |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1518 | }; |
| 1519 | |
| 1520 | static ATTR(active, 0644); |
| 1521 | static ATTR(num, 0644); |
| 1522 | static ATTR(size, 0644); |
| 1523 | |
| 1524 | static struct attribute * veth_pool_attrs[] = { |
| 1525 | &veth_active_attr, |
| 1526 | &veth_num_attr, |
| 1527 | &veth_size_attr, |
| 1528 | NULL, |
| 1529 | }; |
| 1530 | |
| 1531 | static struct sysfs_ops veth_pool_ops = { |
| 1532 | .show = veth_pool_show, |
| 1533 | .store = veth_pool_store, |
| 1534 | }; |
| 1535 | |
| 1536 | static struct kobj_type ktype_veth_pool = { |
| 1537 | .release = NULL, |
| 1538 | .sysfs_ops = &veth_pool_ops, |
| 1539 | .default_attrs = veth_pool_attrs, |
| 1540 | }; |
| 1541 | |
| 1542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | static struct vio_device_id ibmveth_device_table[] __devinitdata= { |
| 1544 | { "network", "IBM,l-lan"}, |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 1545 | { "", "" } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | MODULE_DEVICE_TABLE(vio, ibmveth_device_table); |
| 1548 | |
| 1549 | static struct vio_driver ibmveth_driver = { |
Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 1550 | .id_table = ibmveth_device_table, |
| 1551 | .probe = ibmveth_probe, |
| 1552 | .remove = ibmveth_remove, |
| 1553 | .driver = { |
| 1554 | .name = ibmveth_driver_name, |
Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 1555 | .owner = THIS_MODULE, |
Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 1556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | }; |
| 1558 | |
| 1559 | static int __init ibmveth_module_init(void) |
| 1560 | { |
| 1561 | ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version); |
| 1562 | |
| 1563 | ibmveth_proc_register_driver(); |
| 1564 | |
| 1565 | return vio_register_driver(&ibmveth_driver); |
| 1566 | } |
| 1567 | |
| 1568 | static void __exit ibmveth_module_exit(void) |
| 1569 | { |
| 1570 | vio_unregister_driver(&ibmveth_driver); |
| 1571 | ibmveth_proc_unregister_driver(); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
| 1574 | module_init(ibmveth_module_init); |
| 1575 | module_exit(ibmveth_module_exit); |