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: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | - add support for sysfs |
| 32 | - possibly remove procfs support |
| 33 | */ |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 46 | #include <linux/mm.h> |
| 47 | #include <linux/ethtool.h> |
| 48 | #include <linux/proc_fs.h> |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 49 | #include <linux/in.h> |
| 50 | #include <linux/ip.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 51 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/hvcall.h> |
| 53 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/vio.h> |
| 55 | #include <asm/uaccess.h> |
| 56 | #include <linux/seq_file.h> |
| 57 | |
| 58 | #include "ibmveth.h" |
| 59 | |
Anton Blanchard | 6af37fa | 2005-11-11 14:02:04 +1100 | [diff] [blame] | 60 | #undef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define ibmveth_printk(fmt, args...) \ |
Olof Johansson | f98baff | 2006-04-12 15:22:29 -0500 | [diff] [blame] | 63 | printk(KERN_DEBUG "%s: " fmt, __FILE__, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 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) |
| 67 | |
| 68 | #ifdef DEBUG |
| 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) \ |
| 74 | if(!(expr)) { \ |
| 75 | printk(KERN_DEBUG "assertion failed (%s:%3.3d ua:%x): %s\n", __FILE__, __LINE__, adapter->vdev->unit_address, #expr); \ |
| 76 | BUG(); \ |
| 77 | } |
| 78 | #else |
| 79 | #define ibmveth_debug_printk_no_adapter(fmt, args...) |
| 80 | #define ibmveth_debug_printk(fmt, args...) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 81 | #define ibmveth_assert(expr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #endif |
| 83 | |
| 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); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 87 | static int ibmveth_poll(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 95 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 96 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 97 | static struct kobj_type ktype_veth_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | #ifdef CONFIG_PROC_FS |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 100 | #define IBMVETH_PROC_DIR "ibmveth" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static struct proc_dir_entry *ibmveth_proc_dir; |
| 102 | #endif |
| 103 | |
| 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" |
| 107 | |
| 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); |
| 112 | |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 113 | struct ibmveth_stat { |
| 114 | char name[ETH_GSTRING_LEN]; |
| 115 | int offset; |
| 116 | }; |
| 117 | |
| 118 | #define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat) |
| 119 | #define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off)) |
| 120 | |
| 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) }, |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 128 | { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) }, |
| 129 | { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) }, |
| 130 | }; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* simple methods of getting data from the current rxq entry */ |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 133 | static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter) |
| 134 | { |
| 135 | return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off; |
| 136 | } |
| 137 | |
| 138 | static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter) |
| 139 | { |
| 140 | return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> IBMVETH_RXQ_TOGGLE_SHIFT; |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter) |
| 144 | { |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 145 | return (ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter) |
| 149 | { |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 150 | return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter) |
| 154 | { |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 155 | return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) |
| 159 | { |
| 160 | return (adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); |
| 161 | } |
| 162 | |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 163 | static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter) |
| 164 | { |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 165 | return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* setup the initial settings for a buffer pool */ |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 169 | 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] | 170 | { |
| 171 | pool->size = pool_size; |
| 172 | pool->index = pool_index; |
| 173 | pool->buff_size = buff_size; |
| 174 | pool->threshold = pool_size / 2; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 175 | pool->active = pool_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* allocate and setup an buffer pool - called during open */ |
| 179 | static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool) |
| 180 | { |
| 181 | int i; |
| 182 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 183 | pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | if(!pool->free_map) { |
| 186 | return -1; |
| 187 | } |
| 188 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 189 | pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | if(!pool->dma_addr) { |
| 191 | kfree(pool->free_map); |
| 192 | pool->free_map = NULL; |
| 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | pool->skbuff = kmalloc(sizeof(void*) * pool->size, GFP_KERNEL); |
| 197 | |
| 198 | if(!pool->skbuff) { |
| 199 | kfree(pool->dma_addr); |
| 200 | pool->dma_addr = NULL; |
| 201 | |
| 202 | kfree(pool->free_map); |
| 203 | pool->free_map = NULL; |
| 204 | return -1; |
| 205 | } |
| 206 | |
| 207 | memset(pool->skbuff, 0, sizeof(void*) * pool->size); |
| 208 | memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size); |
| 209 | |
| 210 | for(i = 0; i < pool->size; ++i) { |
| 211 | pool->free_map[i] = i; |
| 212 | } |
| 213 | |
| 214 | atomic_set(&pool->available, 0); |
| 215 | pool->producer_index = 0; |
| 216 | pool->consumer_index = 0; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* replenish the buffers for a pool. note that we don't need to |
| 222 | * skb_reserve these since they are used for incoming... |
| 223 | */ |
| 224 | static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struct ibmveth_buff_pool *pool) |
| 225 | { |
| 226 | u32 i; |
| 227 | u32 count = pool->size - atomic_read(&pool->available); |
| 228 | u32 buffers_added = 0; |
| 229 | |
| 230 | mb(); |
| 231 | |
| 232 | for(i = 0; i < count; ++i) { |
| 233 | struct sk_buff *skb; |
| 234 | unsigned int free_index, index; |
| 235 | u64 correlator; |
| 236 | union ibmveth_buf_desc desc; |
| 237 | unsigned long lpar_rc; |
| 238 | dma_addr_t dma_addr; |
| 239 | |
| 240 | skb = alloc_skb(pool->buff_size, GFP_ATOMIC); |
| 241 | |
| 242 | if(!skb) { |
| 243 | ibmveth_debug_printk("replenish: unable to allocate skb\n"); |
| 244 | adapter->replenish_no_mem++; |
| 245 | break; |
| 246 | } |
| 247 | |
David Gibson | 047a66d | 2006-10-21 10:24:13 -0700 | [diff] [blame] | 248 | free_index = pool->consumer_index; |
| 249 | pool->consumer_index = (pool->consumer_index + 1) % pool->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | index = pool->free_map[free_index]; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | ibmveth_assert(index != IBM_VETH_INVALID_MAP); |
| 253 | ibmveth_assert(pool->skbuff[index] == NULL); |
| 254 | |
| 255 | dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, |
| 256 | pool->buff_size, DMA_FROM_DEVICE); |
| 257 | |
| 258 | pool->free_map[free_index] = IBM_VETH_INVALID_MAP; |
| 259 | pool->dma_addr[index] = dma_addr; |
| 260 | pool->skbuff[index] = skb; |
| 261 | |
| 262 | correlator = ((u64)pool->index << 32) | index; |
| 263 | *(u64*)skb->data = correlator; |
| 264 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 265 | desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 266 | desc.fields.address = dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | 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] | 269 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 270 | if(lpar_rc != H_SUCCESS) { |
Santiago Leon | 82702d3 | 2005-10-26 10:47:23 -0600 | [diff] [blame] | 271 | pool->free_map[free_index] = index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | pool->skbuff[index] = NULL; |
Santiago Leon | 751ae21 | 2006-10-03 12:24:45 -0500 | [diff] [blame] | 273 | if (pool->consumer_index == 0) |
| 274 | pool->consumer_index = pool->size - 1; |
| 275 | else |
| 276 | pool->consumer_index--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | dma_unmap_single(&adapter->vdev->dev, |
| 278 | pool->dma_addr[index], pool->buff_size, |
| 279 | DMA_FROM_DEVICE); |
| 280 | dev_kfree_skb_any(skb); |
| 281 | adapter->replenish_add_buff_failure++; |
| 282 | break; |
| 283 | } else { |
| 284 | buffers_added++; |
| 285 | adapter->replenish_add_buff_success++; |
| 286 | } |
| 287 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | mb(); |
| 290 | atomic_add(buffers_added, &(pool->available)); |
| 291 | } |
| 292 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 293 | /* replenish routine */ |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 294 | static void ibmveth_replenish_task(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 296 | int i; |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | adapter->replenish_task_cycles++; |
| 299 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 300 | for(i = 0; i < IbmVethNumBufferPools; i++) |
| 301 | if(adapter->rx_buff_pool[i].active) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 302 | ibmveth_replenish_buffer_pool(adapter, |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 303 | &adapter->rx_buff_pool[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 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) |
| 310 | { |
| 311 | int i; |
| 312 | |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 313 | kfree(pool->free_map); |
| 314 | pool->free_map = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | if(pool->skbuff && pool->dma_addr) { |
| 317 | for(i = 0; i < pool->size; ++i) { |
| 318 | struct sk_buff *skb = pool->skbuff[i]; |
| 319 | if(skb) { |
| 320 | dma_unmap_single(&adapter->vdev->dev, |
| 321 | pool->dma_addr[i], |
| 322 | pool->buff_size, |
| 323 | DMA_FROM_DEVICE); |
| 324 | dev_kfree_skb_any(skb); |
| 325 | pool->skbuff[i] = NULL; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | if(pool->dma_addr) { |
| 331 | kfree(pool->dma_addr); |
| 332 | pool->dma_addr = NULL; |
| 333 | } |
| 334 | |
| 335 | if(pool->skbuff) { |
| 336 | kfree(pool->skbuff); |
| 337 | pool->skbuff = NULL; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* remove a buffer from a pool */ |
| 342 | static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, u64 correlator) |
| 343 | { |
| 344 | unsigned int pool = correlator >> 32; |
| 345 | unsigned int index = correlator & 0xffffffffUL; |
| 346 | unsigned int free_index; |
| 347 | struct sk_buff *skb; |
| 348 | |
| 349 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 350 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 351 | |
| 352 | skb = adapter->rx_buff_pool[pool].skbuff[index]; |
| 353 | |
| 354 | ibmveth_assert(skb != NULL); |
| 355 | |
| 356 | adapter->rx_buff_pool[pool].skbuff[index] = NULL; |
| 357 | |
| 358 | dma_unmap_single(&adapter->vdev->dev, |
| 359 | adapter->rx_buff_pool[pool].dma_addr[index], |
| 360 | adapter->rx_buff_pool[pool].buff_size, |
| 361 | DMA_FROM_DEVICE); |
| 362 | |
David Gibson | 047a66d | 2006-10-21 10:24:13 -0700 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | adapter->rx_buff_pool[pool].free_map[free_index] = index; |
| 368 | |
| 369 | mb(); |
| 370 | |
| 371 | atomic_dec(&(adapter->rx_buff_pool[pool].available)); |
| 372 | } |
| 373 | |
| 374 | /* get the current buffer on the rx queue */ |
| 375 | static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter) |
| 376 | { |
| 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; |
| 380 | |
| 381 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 382 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 383 | |
| 384 | return adapter->rx_buff_pool[pool].skbuff[index]; |
| 385 | } |
| 386 | |
| 387 | /* recycle the current buffer on the rx queue */ |
| 388 | static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter) |
| 389 | { |
| 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; |
| 396 | |
| 397 | ibmveth_assert(pool < IbmVethNumBufferPools); |
| 398 | ibmveth_assert(index < adapter->rx_buff_pool[pool].size); |
| 399 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 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]); |
| 403 | return; |
| 404 | } |
| 405 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 406 | desc.fields.flags_len = IBMVETH_BUF_VALID | |
| 407 | adapter->rx_buff_pool[pool].buff_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index]; |
| 409 | |
| 410 | 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] | 411 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 412 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 415 | } |
| 416 | |
| 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; |
| 420 | } |
| 421 | } |
| 422 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 423 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); |
| 426 | |
| 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; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | static void ibmveth_cleanup(struct ibmveth_adapter *adapter) |
| 434 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 435 | int i; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
| 441 | DMA_BIDIRECTIONAL); |
| 442 | adapter->buffer_list_dma = DMA_ERROR_CODE; |
| 443 | } |
| 444 | free_page((unsigned long)adapter->buffer_list_addr); |
| 445 | adapter->buffer_list_addr = NULL; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 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, |
| 452 | DMA_BIDIRECTIONAL); |
| 453 | adapter->filter_list_dma = DMA_ERROR_CODE; |
| 454 | } |
| 455 | free_page((unsigned long)adapter->filter_list_addr); |
| 456 | adapter->filter_list_addr = NULL; |
| 457 | } |
| 458 | |
| 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, |
| 464 | DMA_BIDIRECTIONAL); |
| 465 | adapter->rx_queue.queue_dma = DMA_ERROR_CODE; |
| 466 | } |
| 467 | kfree(adapter->rx_queue.queue_addr); |
| 468 | adapter->rx_queue.queue_addr = NULL; |
| 469 | } |
| 470 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 471 | for(i = 0; i<IbmVethNumBufferPools; i++) |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 472 | if (adapter->rx_buff_pool[i].active) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 473 | ibmveth_free_buffer_pool(adapter, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 474 | &adapter->rx_buff_pool[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Michael Ellerman | bbedefc | 2006-10-03 12:24:23 -0500 | [diff] [blame] | 477 | static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, |
| 478 | union ibmveth_buf_desc rxq_desc, u64 mac_address) |
| 479 | { |
| 480 | int rc, try_again = 1; |
| 481 | |
| 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. */ |
| 485 | retry: |
| 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); |
| 489 | |
| 490 | if (rc != H_SUCCESS && try_again) { |
| 491 | do { |
| 492 | rc = h_free_logical_lan(adapter->vdev->unit_address); |
| 493 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); |
| 494 | |
| 495 | try_again = 0; |
| 496 | goto retry; |
| 497 | } |
| 498 | |
| 499 | return rc; |
| 500 | } |
| 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | static int ibmveth_open(struct net_device *netdev) |
| 503 | { |
| 504 | struct ibmveth_adapter *adapter = netdev->priv; |
| 505 | u64 mac_address = 0; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 506 | int rxq_entries = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | unsigned long lpar_rc; |
| 508 | int rc; |
| 509 | union ibmveth_buf_desc rxq_desc; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 510 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | ibmveth_debug_printk("open starting\n"); |
| 513 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 514 | napi_enable(&adapter->napi); |
| 515 | |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 516 | for(i = 0; i<IbmVethNumBufferPools; i++) |
| 517 | rxq_entries += adapter->rx_buff_pool[i].size; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL); |
| 520 | adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 525 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | return -ENOMEM; |
| 527 | } |
| 528 | |
| 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); |
| 531 | |
| 532 | if(!adapter->rx_queue.queue_addr) { |
| 533 | ibmveth_error_printk("unable to allocate rx queue pages\n"); |
| 534 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 535 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return -ENOMEM; |
| 537 | } |
| 538 | |
| 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); |
| 546 | |
| 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); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 552 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | return -ENOMEM; |
| 554 | } |
| 555 | |
| 556 | adapter->rx_queue.index = 0; |
| 557 | adapter->rx_queue.num_slots = rxq_entries; |
| 558 | adapter->rx_queue.toggle = 1; |
| 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); |
| 561 | mac_address = mac_address >> 16; |
| 562 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 563 | rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | adapter->rx_queue.queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | rxq_desc.fields.address = adapter->rx_queue.queue_dma; |
| 565 | |
| 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); |
| 569 | |
Santiago Leon | 4347ef1 | 2006-10-03 12:24:34 -0500 | [diff] [blame] | 570 | h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); |
| 571 | |
Michael Ellerman | bbedefc | 2006-10-03 12:24:23 -0500 | [diff] [blame] | 572 | lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 574 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | 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] | 576 | 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] | 577 | adapter->buffer_list_dma, |
| 578 | adapter->filter_list_dma, |
| 579 | rxq_desc.desc, |
| 580 | mac_address); |
| 581 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 582 | napi_disable(&adapter->napi); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 583 | return -ENONET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 586 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
| 587 | if(!adapter->rx_buff_pool[i].active) |
| 588 | continue; |
| 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); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 593 | napi_disable(&adapter->napi); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 594 | return -ENOMEM ; |
| 595 | } |
| 596 | } |
| 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 601 | do { |
| 602 | rc = h_free_logical_lan(adapter->vdev->unit_address); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 603 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | ibmveth_cleanup(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 606 | napi_disable(&adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | return rc; |
| 608 | } |
| 609 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 610 | ibmveth_debug_printk("initial replenish cycle\n"); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 611 | ibmveth_interrupt(netdev->irq, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 613 | netif_start_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | ibmveth_debug_printk("open complete\n"); |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int ibmveth_close(struct net_device *netdev) |
| 621 | { |
| 622 | struct ibmveth_adapter *adapter = netdev->priv; |
| 623 | long lpar_rc; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | ibmveth_debug_printk("close starting\n"); |
| 626 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 627 | napi_disable(&adapter->napi); |
| 628 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 629 | if (!adapter->pool_config) |
| 630 | netif_stop_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
| 632 | free_irq(netdev->irq, netdev); |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | do { |
| 635 | lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 636 | } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 638 | if(lpar_rc != H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
| 640 | ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n", |
| 641 | lpar_rc); |
| 642 | } |
| 643 | |
| 644 | adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); |
| 645 | |
| 646 | ibmveth_cleanup(adapter); |
| 647 | |
| 648 | ibmveth_debug_printk("close complete\n"); |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 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; |
| 662 | cmd->maxtxpkt = 0; |
| 663 | cmd->maxrxpkt = 1; |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 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); |
| 670 | } |
| 671 | |
| 672 | static u32 netdev_get_link(struct net_device *dev) { |
| 673 | return 1; |
| 674 | } |
| 675 | |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 676 | static void ibmveth_set_rx_csum_flags(struct net_device *dev, u32 data) |
| 677 | { |
| 678 | struct ibmveth_adapter *adapter = dev->priv; |
| 679 | |
| 680 | if (data) |
| 681 | adapter->rx_csum = 1; |
| 682 | else { |
| 683 | /* |
| 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. |
| 689 | */ |
| 690 | adapter->rx_csum = 0; |
| 691 | dev->features &= ~NETIF_F_IP_CSUM; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | static void ibmveth_set_tx_csum_flags(struct net_device *dev, u32 data) |
| 696 | { |
| 697 | struct ibmveth_adapter *adapter = dev->priv; |
| 698 | |
| 699 | if (data) { |
| 700 | dev->features |= NETIF_F_IP_CSUM; |
| 701 | adapter->rx_csum = 1; |
| 702 | } else |
| 703 | dev->features &= ~NETIF_F_IP_CSUM; |
| 704 | } |
| 705 | |
| 706 | static int ibmveth_set_csum_offload(struct net_device *dev, u32 data, |
| 707 | void (*done) (struct net_device *, u32)) |
| 708 | { |
| 709 | struct ibmveth_adapter *adapter = dev->priv; |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 710 | u64 set_attr, clr_attr, ret_attr; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 711 | long ret; |
| 712 | int rc1 = 0, rc2 = 0; |
| 713 | int restart = 0; |
| 714 | |
| 715 | if (netif_running(dev)) { |
| 716 | restart = 1; |
| 717 | adapter->pool_config = 1; |
| 718 | ibmveth_close(dev); |
| 719 | adapter->pool_config = 0; |
| 720 | } |
| 721 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 722 | set_attr = 0; |
| 723 | clr_attr = 0; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 724 | |
| 725 | if (data) |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 726 | set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 727 | else |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 728 | clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 729 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 730 | ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr); |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 731 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 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); |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 737 | |
| 738 | if (ret != H_SUCCESS) { |
| 739 | rc1 = -EIO; |
| 740 | ibmveth_error_printk("unable to change checksum offload settings." |
| 741 | " %d rc=%ld\n", data, ret); |
| 742 | |
| 743 | ret = h_illan_attributes(adapter->vdev->unit_address, |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 744 | set_attr, clr_attr, &ret_attr); |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 745 | } else |
| 746 | done(dev, data); |
| 747 | } else { |
| 748 | rc1 = -EIO; |
| 749 | ibmveth_error_printk("unable to change checksum offload settings." |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 750 | " %d rc=%ld ret_attr=%lx\n", data, ret, ret_attr); |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | if (restart) |
| 754 | rc2 = ibmveth_open(dev); |
| 755 | |
| 756 | return rc1 ? rc1 : rc2; |
| 757 | } |
| 758 | |
| 759 | static int ibmveth_set_rx_csum(struct net_device *dev, u32 data) |
| 760 | { |
| 761 | struct ibmveth_adapter *adapter = dev->priv; |
| 762 | |
| 763 | if ((data && adapter->rx_csum) || (!data && !adapter->rx_csum)) |
| 764 | return 0; |
| 765 | |
| 766 | return ibmveth_set_csum_offload(dev, data, ibmveth_set_rx_csum_flags); |
| 767 | } |
| 768 | |
| 769 | static int ibmveth_set_tx_csum(struct net_device *dev, u32 data) |
| 770 | { |
| 771 | struct ibmveth_adapter *adapter = dev->priv; |
| 772 | int rc = 0; |
| 773 | |
| 774 | if (data && (dev->features & NETIF_F_IP_CSUM)) |
| 775 | return 0; |
| 776 | if (!data && !(dev->features & NETIF_F_IP_CSUM)) |
| 777 | return 0; |
| 778 | |
| 779 | if (data && !adapter->rx_csum) |
| 780 | rc = ibmveth_set_csum_offload(dev, data, ibmveth_set_tx_csum_flags); |
| 781 | else |
| 782 | ibmveth_set_tx_csum_flags(dev, data); |
| 783 | |
| 784 | return rc; |
| 785 | } |
| 786 | |
| 787 | static u32 ibmveth_get_rx_csum(struct net_device *dev) |
| 788 | { |
| 789 | struct ibmveth_adapter *adapter = dev->priv; |
| 790 | return adapter->rx_csum; |
| 791 | } |
| 792 | |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 793 | static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 794 | { |
| 795 | int i; |
| 796 | |
| 797 | if (stringset != ETH_SS_STATS) |
| 798 | return; |
| 799 | |
| 800 | for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN) |
| 801 | memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN); |
| 802 | } |
| 803 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 804 | static int ibmveth_get_sset_count(struct net_device *dev, int sset) |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 805 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 806 | switch (sset) { |
| 807 | case ETH_SS_STATS: |
| 808 | return ARRAY_SIZE(ibmveth_stats); |
| 809 | default: |
| 810 | return -EOPNOTSUPP; |
| 811 | } |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static void ibmveth_get_ethtool_stats(struct net_device *dev, |
| 815 | struct ethtool_stats *stats, u64 *data) |
| 816 | { |
| 817 | int i; |
| 818 | struct ibmveth_adapter *adapter = dev->priv; |
| 819 | |
| 820 | for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++) |
| 821 | data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset); |
| 822 | } |
| 823 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 824 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | .get_drvinfo = netdev_get_drvinfo, |
| 826 | .get_settings = netdev_get_settings, |
| 827 | .get_link = netdev_get_link, |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 828 | .set_tx_csum = ibmveth_set_tx_csum, |
| 829 | .get_rx_csum = ibmveth_get_rx_csum, |
| 830 | .set_rx_csum = ibmveth_set_rx_csum, |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 831 | .get_strings = ibmveth_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 832 | .get_sset_count = ibmveth_get_sset_count, |
Brian King | ddbb4de | 2007-08-17 09:16:43 -0500 | [diff] [blame] | 833 | .get_ethtool_stats = ibmveth_get_ethtool_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | }; |
| 835 | |
| 836 | static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 837 | { |
| 838 | return -EOPNOTSUPP; |
| 839 | } |
| 840 | |
| 841 | #define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1)) |
| 842 | |
| 843 | static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 844 | { |
| 845 | struct ibmveth_adapter *adapter = netdev->priv; |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 846 | union ibmveth_buf_desc desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | unsigned long lpar_rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | unsigned long correlator; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 849 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | unsigned int retry_count; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 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; |
| 856 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 857 | desc.fields.flags_len = IBMVETH_BUF_VALID | skb->len; |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 858 | desc.fields.address = dma_map_single(&adapter->vdev->dev, skb->data, |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 859 | skb->len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 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"); |
| 864 | tx_dropped++; |
| 865 | goto out; |
| 866 | } |
| 867 | |
| 868 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 869 | unsigned char *buf = skb_transport_header(skb) + skb->csum_offset; |
| 870 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 871 | desc.fields.flags_len |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 872 | |
| 873 | /* Need to zero out the checksum */ |
| 874 | buf[0] = 0; |
| 875 | buf[1] = 0; |
| 876 | } |
| 877 | |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 878 | if (dma_mapping_error(desc.fields.address)) { |
| 879 | ibmveth_error_printk("tx: unable to map xmit buffer\n"); |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 880 | tx_map_failed++; |
| 881 | tx_dropped++; |
| 882 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | /* send the frame. Arbitrarily set retrycount to 1024 */ |
| 886 | correlator = 0; |
| 887 | retry_count = 1024; |
| 888 | do { |
| 889 | lpar_rc = h_send_logical_lan(adapter->vdev->unit_address, |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 890 | desc.desc, 0, 0, 0, 0, 0, |
| 891 | correlator, &correlator); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 892 | } while ((lpar_rc == H_BUSY) && (retry_count--)); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 893 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 894 | if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc); |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 896 | ibmveth_error_printk("tx: valid=%d, len=%d, address=0x%08x\n", |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 897 | (desc.fields.flags_len & IBMVETH_BUF_VALID) ? 1 : 0, |
| 898 | skb->len, desc.fields.address); |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 899 | tx_send_failed++; |
| 900 | tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } else { |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 902 | tx_packets++; |
| 903 | tx_bytes += skb->len; |
Santiago Leon | 0abe791 | 2005-10-26 10:46:53 -0600 | [diff] [blame] | 904 | netdev->trans_start = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 907 | dma_unmap_single(&adapter->vdev->dev, desc.fields.address, |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 908 | skb->len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 910 | out: spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 911 | netdev->stats.tx_dropped += tx_dropped; |
| 912 | netdev->stats.tx_bytes += tx_bytes; |
| 913 | netdev->stats.tx_packets += tx_packets; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 914 | adapter->tx_send_failed += tx_send_failed; |
| 915 | adapter->tx_map_failed += tx_map_failed; |
| 916 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | dev_kfree_skb(skb); |
| 919 | return 0; |
| 920 | } |
| 921 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 922 | static int ibmveth_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 924 | struct ibmveth_adapter *adapter = container_of(napi, struct ibmveth_adapter, napi); |
| 925 | struct net_device *netdev = adapter->netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | int frames_processed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | unsigned long lpar_rc; |
| 928 | |
| 929 | restart_poll: |
| 930 | do { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 931 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 933 | if (!ibmveth_rxq_pending_buffer(adapter)) |
| 934 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 936 | rmb(); |
| 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } else { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 943 | int length = ibmveth_rxq_frame_length(adapter); |
| 944 | int offset = ibmveth_rxq_frame_offset(adapter); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 945 | int csum_good = ibmveth_rxq_csum_good(adapter); |
| 946 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 947 | skb = ibmveth_rxq_get_buffer(adapter); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 948 | if (csum_good) |
| 949 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 950 | |
| 951 | ibmveth_rxq_harvest_buffer(adapter); |
| 952 | |
| 953 | skb_reserve(skb, offset); |
| 954 | skb_put(skb, length); |
| 955 | skb->protocol = eth_type_trans(skb, netdev); |
| 956 | |
| 957 | netif_receive_skb(skb); /* send it up */ |
| 958 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 959 | netdev->stats.rx_packets++; |
| 960 | netdev->stats.rx_bytes += length; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 961 | frames_processed++; |
| 962 | netdev->last_rx = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 964 | } while (frames_processed < budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Santiago Leon | e2adbcb | 2005-10-26 10:47:08 -0600 | [diff] [blame] | 966 | ibmveth_replenish_task(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 968 | if (frames_processed < budget) { |
| 969 | /* We think we are done - reenable interrupts, |
| 970 | * then check once more to make sure we are done. |
| 971 | */ |
| 972 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 973 | VIO_IRQ_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 975 | ibmveth_assert(lpar_rc == H_SUCCESS); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 976 | |
| 977 | netif_rx_complete(netdev, napi); |
| 978 | |
| 979 | if (ibmveth_rxq_pending_buffer(adapter) && |
| 980 | netif_rx_reschedule(netdev, napi)) { |
| 981 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 982 | VIO_IRQ_DISABLE); |
| 983 | goto restart_poll; |
| 984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 987 | return frames_processed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 990 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance) |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 991 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | struct net_device *netdev = dev_instance; |
| 993 | struct ibmveth_adapter *adapter = netdev->priv; |
| 994 | unsigned long lpar_rc; |
| 995 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 996 | if (netif_rx_schedule_prep(netdev, &adapter->napi)) { |
| 997 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, |
| 998 | VIO_IRQ_DISABLE); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 999 | ibmveth_assert(lpar_rc == H_SUCCESS); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1000 | __netif_rx_schedule(netdev, &adapter->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | return IRQ_HANDLED; |
| 1003 | } |
| 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | static void ibmveth_set_multicast_list(struct net_device *netdev) |
| 1006 | { |
| 1007 | struct ibmveth_adapter *adapter = netdev->priv; |
| 1008 | unsigned long lpar_rc; |
| 1009 | |
| 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, |
| 1014 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1015 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc); |
| 1017 | } |
| 1018 | } else { |
| 1019 | struct dev_mc_list *mclist = netdev->mc_list; |
| 1020 | int i; |
| 1021 | /* clear the filter table & disable filtering */ |
| 1022 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1023 | IbmVethMcastEnableRecv | |
| 1024 | IbmVethMcastDisableFiltering | |
| 1025 | IbmVethMcastClearFilterTable, |
| 1026 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1027 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc); |
| 1029 | } |
| 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, |
| 1037 | mcast_addr); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1038 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc); |
| 1040 | } |
| 1041 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | /* re-enable filtering */ |
| 1044 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, |
| 1045 | IbmVethMcastEnableFiltering, |
| 1046 | 0); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 1047 | if(lpar_rc != H_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) |
| 1054 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1055 | struct ibmveth_adapter *adapter = dev->priv; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1056 | int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH; |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1057 | int reinit = 0; |
| 1058 | int i, rc; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1059 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1060 | if (new_mtu < IBMVETH_MAX_MTU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | return -EINVAL; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1062 | |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1063 | for (i = 0; i < IbmVethNumBufferPools; i++) |
| 1064 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) |
| 1065 | break; |
| 1066 | |
| 1067 | if (i == IbmVethNumBufferPools) |
| 1068 | return -EINVAL; |
| 1069 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1070 | /* Look for an active buffer pool that can hold the new MTU */ |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1071 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1072 | if (!adapter->rx_buff_pool[i].active) { |
| 1073 | adapter->rx_buff_pool[i].active = 1; |
| 1074 | reinit = 1; |
| 1075 | } |
| 1076 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1077 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { |
Brian King | ce6eea5 | 2007-06-08 14:05:17 -0500 | [diff] [blame] | 1078 | if (reinit && netif_running(adapter->netdev)) { |
| 1079 | adapter->pool_config = 1; |
| 1080 | ibmveth_close(adapter->netdev); |
| 1081 | adapter->pool_config = 0; |
| 1082 | dev->mtu = new_mtu; |
| 1083 | if ((rc = ibmveth_open(adapter->netdev))) |
| 1084 | return rc; |
| 1085 | } else |
| 1086 | dev->mtu = new_mtu; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1087 | return 0; |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1088 | } |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1089 | } |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1090 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1093 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1094 | static void ibmveth_poll_controller(struct net_device *dev) |
| 1095 | { |
| 1096 | ibmveth_replenish_task(dev->priv); |
Andrew Morton | 5f77113 | 2006-10-10 14:33:30 -0700 | [diff] [blame] | 1097 | ibmveth_interrupt(dev->irq, dev); |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1098 | } |
| 1099 | #endif |
| 1100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) |
| 1102 | { |
Santiago Leon | b6d3518 | 2005-10-26 10:47:01 -0600 | [diff] [blame] | 1103 | int rc, i; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1104 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | struct net_device *netdev; |
Mariusz Kozlowski | 9dc83af | 2007-08-06 23:44:03 +0200 | [diff] [blame] | 1106 | struct ibmveth_adapter *adapter; |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 1107 | u64 set_attr, ret_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | unsigned char *mac_addr_p; |
| 1110 | unsigned int *mcastFilterSize_p; |
| 1111 | |
| 1112 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1113 | 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] | 1114 | dev->unit_address); |
| 1115 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 1116 | mac_addr_p = (unsigned char *) vio_get_attribute(dev, |
| 1117 | VETH_MAC_ADDR, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | if(!mac_addr_p) { |
| 1119 | printk(KERN_ERR "(%s:%3.3d) ERROR: Can't find VETH_MAC_ADDR " |
| 1120 | "attribute\n", __FILE__, __LINE__); |
| 1121 | return 0; |
| 1122 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1123 | |
Michael Ellerman | 493a684 | 2007-04-17 13:12:55 +1000 | [diff] [blame] | 1124 | mcastFilterSize_p = (unsigned int *) vio_get_attribute(dev, |
| 1125 | VETH_MCAST_FILTER_SIZE, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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__); |
| 1130 | return 0; |
| 1131 | } |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | netdev = alloc_etherdev(sizeof(struct ibmveth_adapter)); |
| 1134 | |
| 1135 | if(!netdev) |
| 1136 | return -ENOMEM; |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | adapter = netdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | dev->dev.driver_data = netdev; |
| 1140 | |
| 1141 | adapter->vdev = dev; |
| 1142 | adapter->netdev = netdev; |
| 1143 | adapter->mcastFilterSize= *mcastFilterSize_p; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1144 | adapter->pool_config = 0; |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1145 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1146 | netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); |
| 1147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | /* Some older boxes running PHYP non-natively have an OF that |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1149 | returns a 8-byte local-mac-address field (and the first |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | 2 bytes have to be ignored) while newer boxes' OF return |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1151 | a 6-byte field. Note that IEEE 1275 specifies that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | local-mac-address must be a 6-byte field. |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1153 | The RPA doc specifies that the first byte must be 10b, so |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | we'll just look for it to solve this 8 vs. 6 byte field issue */ |
| 1155 | |
| 1156 | if ((*mac_addr_p & 0x3) != 0x02) |
| 1157 | mac_addr_p += 2; |
| 1158 | |
| 1159 | adapter->mac_addr = 0; |
| 1160 | memcpy(&adapter->mac_addr, mac_addr_p, 6); |
| 1161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | netdev->irq = dev->irq; |
| 1163 | netdev->open = ibmveth_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | netdev->stop = ibmveth_close; |
| 1165 | netdev->hard_start_xmit = ibmveth_start_xmit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Santiago Leon | 6b42237 | 2006-10-03 12:24:28 -0500 | [diff] [blame] | 1171 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1172 | netdev->poll_controller = ibmveth_poll_controller; |
| 1173 | #endif |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1174 | netdev->features |= NETIF_F_LLTX; |
Santiago Leon | 60296d9 | 2005-10-26 10:47:16 -0600 | [diff] [blame] | 1175 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
| 1177 | memcpy(&netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); |
| 1178 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1179 | for(i = 0; i<IbmVethNumBufferPools; i++) { |
| 1180 | struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; |
Greg Kroah-Hartman | 8dde2a9 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 1181 | int error; |
| 1182 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1183 | ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, |
| 1184 | pool_count[i], pool_size[i], |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1185 | pool_active[i]); |
Greg Kroah-Hartman | 8dde2a9 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 1186 | error = kobject_init_and_add(kobj, &ktype_veth_pool, |
| 1187 | &dev->dev.kobj, "pool%d", i); |
| 1188 | if (!error) |
| 1189 | kobject_uevent(kobj, KOBJ_ADD); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | ibmveth_debug_printk("adapter @ 0x%p\n", adapter); |
| 1193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | ibmveth_debug_printk("registering netdev...\n"); |
| 1199 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 1200 | ret = h_illan_attributes(dev->unit_address, 0, 0, &ret_attr); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1201 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 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; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1206 | |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 1207 | ret = h_illan_attributes(dev->unit_address, 0, set_attr, &ret_attr); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1208 | |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 1209 | if (ret == H_SUCCESS) { |
| 1210 | adapter->rx_csum = 1; |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1211 | netdev->features |= NETIF_F_IP_CSUM; |
Brian King | 5fc7e01 | 2007-08-17 09:16:31 -0500 | [diff] [blame] | 1212 | } else |
Brian King | 79ef4a4 | 2007-08-17 09:16:56 -0500 | [diff] [blame] | 1213 | ret = h_illan_attributes(dev->unit_address, set_attr, 0, &ret_attr); |
Brian King | f4ff287 | 2007-09-15 13:36:07 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | rc = register_netdev(netdev); |
| 1217 | |
| 1218 | if(rc) { |
| 1219 | ibmveth_debug_printk("failed to register netdev rc=%d\n", rc); |
| 1220 | free_netdev(netdev); |
| 1221 | return rc; |
| 1222 | } |
| 1223 | |
| 1224 | ibmveth_debug_printk("registered\n"); |
| 1225 | |
| 1226 | ibmveth_proc_register_adapter(adapter); |
| 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | static int __devexit ibmveth_remove(struct vio_dev *dev) |
| 1232 | { |
| 1233 | struct net_device *netdev = dev->dev.driver_data; |
| 1234 | struct ibmveth_adapter *adapter = netdev->priv; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1235 | int i; |
| 1236 | |
| 1237 | for(i = 0; i<IbmVethNumBufferPools; i++) |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 1238 | kobject_put(&adapter->rx_buff_pool[i].kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | unregister_netdev(netdev); |
| 1241 | |
| 1242 | ibmveth_proc_unregister_adapter(adapter); |
| 1243 | |
| 1244 | free_netdev(netdev); |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | #ifdef CONFIG_PROC_FS |
| 1249 | static void ibmveth_proc_register_driver(void) |
| 1250 | { |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1251 | ibmveth_proc_dir = proc_mkdir(IBMVETH_PROC_DIR, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | if (ibmveth_proc_dir) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | static void ibmveth_proc_unregister_driver(void) |
| 1257 | { |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1258 | remove_proc_entry(IBMVETH_PROC_DIR, init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Pavel Emelyanov | 1119d57 | 2008-02-18 13:55:10 +0300 | [diff] [blame] | 1261 | static int ibmveth_show(struct seq_file *seq, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | { |
| 1263 | struct ibmveth_adapter *adapter = seq->private; |
| 1264 | char *current_mac = ((char*) &adapter->netdev->dev_addr); |
| 1265 | char *firmware_mac = ((char*) &adapter->mac_addr) ; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1266 | DECLARE_MAC_BUF(mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
| 1268 | 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] | 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | seq_printf(seq, "Unit Address: 0x%x\n", adapter->vdev->unit_address); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 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)); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | seq_printf(seq, "\nAdapter Statistics:\n"); |
Brian King | 3449a2a | 2007-08-17 09:16:49 -0500 | [diff] [blame] | 1275 | seq_printf(seq, " TX: vio_map_single failres: %ld\n", adapter->tx_map_failed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | return 0; |
| 1284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | static int ibmveth_proc_open(struct inode *inode, struct file *file) |
| 1287 | { |
Pavel Emelyanov | 1119d57 | 2008-02-18 13:55:10 +0300 | [diff] [blame] | 1288 | return single_open(file, ibmveth_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1291 | static const struct file_operations ibmveth_proc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | .owner = THIS_MODULE, |
| 1293 | .open = ibmveth_proc_open, |
| 1294 | .read = seq_read, |
| 1295 | .llseek = seq_lseek, |
Pavel Emelyanov | 1119d57 | 2008-02-18 13:55:10 +0300 | [diff] [blame] | 1296 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | }; |
| 1298 | |
| 1299 | static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter) |
| 1300 | { |
| 1301 | struct proc_dir_entry *entry; |
| 1302 | if (ibmveth_proc_dir) { |
Santiago Leon | 03a85d0 | 2006-10-03 12:24:39 -0500 | [diff] [blame] | 1303 | char u_addr[10]; |
| 1304 | sprintf(u_addr, "%x", adapter->vdev->unit_address); |
Denis V. Lunev | a95609c | 2008-04-29 01:02:29 -0700 | [diff] [blame] | 1305 | entry = proc_create_data(u_addr, S_IFREG, ibmveth_proc_dir, |
| 1306 | &ibmveth_proc_fops, adapter); |
| 1307 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | ibmveth_error_printk("Cannot create adapter proc entry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter) |
| 1314 | { |
| 1315 | if (ibmveth_proc_dir) { |
Santiago Leon | 03a85d0 | 2006-10-03 12:24:39 -0500 | [diff] [blame] | 1316 | char u_addr[10]; |
| 1317 | sprintf(u_addr, "%x", adapter->vdev->unit_address); |
| 1318 | remove_proc_entry(u_addr, ibmveth_proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | #else /* CONFIG_PROC_FS */ |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1323 | static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
| 1325 | } |
| 1326 | |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1327 | static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | { |
| 1329 | } |
| 1330 | static void ibmveth_proc_register_driver(void) |
| 1331 | { |
| 1332 | } |
| 1333 | |
| 1334 | static void ibmveth_proc_unregister_driver(void) |
| 1335 | { |
| 1336 | } |
| 1337 | #endif /* CONFIG_PROC_FS */ |
| 1338 | |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1339 | static struct attribute veth_active_attr; |
| 1340 | static struct attribute veth_num_attr; |
| 1341 | static struct attribute veth_size_attr; |
| 1342 | |
| 1343 | static ssize_t veth_pool_show(struct kobject * kobj, |
| 1344 | struct attribute * attr, char * buf) |
| 1345 | { |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1346 | struct ibmveth_buff_pool *pool = container_of(kobj, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1347 | struct ibmveth_buff_pool, |
| 1348 | kobj); |
| 1349 | |
| 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); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | static ssize_t veth_pool_store(struct kobject * kobj, struct attribute * attr, |
| 1360 | const char * buf, size_t count) |
| 1361 | { |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1362 | struct ibmveth_buff_pool *pool = container_of(kobj, |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1363 | struct ibmveth_buff_pool, |
| 1364 | kobj); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1365 | struct net_device *netdev = |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 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); |
| 1369 | long rc; |
| 1370 | |
| 1371 | if (attr == &veth_active_attr) { |
| 1372 | if (value && !pool->active) { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 1373 | if (netif_running(netdev)) { |
| 1374 | if(ibmveth_alloc_buffer_pool(pool)) { |
| 1375 | ibmveth_error_printk("unable to alloc pool\n"); |
| 1376 | return -ENOMEM; |
| 1377 | } |
| 1378 | pool->active = 1; |
| 1379 | adapter->pool_config = 1; |
| 1380 | ibmveth_close(netdev); |
| 1381 | adapter->pool_config = 0; |
| 1382 | if ((rc = ibmveth_open(netdev))) |
| 1383 | return rc; |
| 1384 | } else |
| 1385 | pool->active = 1; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1386 | } else if (!value && pool->active) { |
| 1387 | int mtu = netdev->mtu + IBMVETH_BUFF_OH; |
| 1388 | int i; |
| 1389 | /* Make sure there is a buffer pool with buffers that |
| 1390 | can hold a packet of the size of the MTU */ |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1391 | for (i = 0; i < IbmVethNumBufferPools; i++) { |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1392 | if (pool == &adapter->rx_buff_pool[i]) |
| 1393 | continue; |
| 1394 | if (!adapter->rx_buff_pool[i].active) |
| 1395 | continue; |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1396 | if (mtu <= adapter->rx_buff_pool[i].buff_size) |
| 1397 | break; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1398 | } |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1399 | |
| 1400 | if (i == IbmVethNumBufferPools) { |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1401 | ibmveth_error_printk("no active pool >= MTU\n"); |
| 1402 | return -EPERM; |
| 1403 | } |
Brian King | 76b9cfc | 2007-08-03 13:55:19 +1000 | [diff] [blame] | 1404 | |
| 1405 | pool->active = 0; |
| 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))) |
| 1411 | return rc; |
| 1412 | } |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1413 | } |
| 1414 | } else if (attr == &veth_num_attr) { |
| 1415 | if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) |
| 1416 | return -EINVAL; |
| 1417 | else { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 1418 | if (netif_running(netdev)) { |
| 1419 | adapter->pool_config = 1; |
| 1420 | ibmveth_close(netdev); |
| 1421 | adapter->pool_config = 0; |
| 1422 | pool->size = value; |
| 1423 | if ((rc = ibmveth_open(netdev))) |
| 1424 | return rc; |
| 1425 | } else |
| 1426 | pool->size = value; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1427 | } |
| 1428 | } else if (attr == &veth_size_attr) { |
| 1429 | if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) |
| 1430 | return -EINVAL; |
| 1431 | else { |
Brian King | 4aa9c93 | 2007-06-08 14:05:16 -0500 | [diff] [blame] | 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))) |
| 1438 | return rc; |
| 1439 | } else |
| 1440 | pool->buff_size = value; |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | /* kick the interrupt handler to allocate/deallocate pools */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1445 | ibmveth_interrupt(netdev->irq, netdev); |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1446 | return count; |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | #define ATTR(_name, _mode) \ |
| 1451 | struct attribute veth_##_name##_attr = { \ |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 1452 | .name = __stringify(_name), .mode = _mode, \ |
Santiago Leon | 860f242 | 2006-04-25 11:19:59 -0500 | [diff] [blame] | 1453 | }; |
| 1454 | |
| 1455 | static ATTR(active, 0644); |
| 1456 | static ATTR(num, 0644); |
| 1457 | static ATTR(size, 0644); |
| 1458 | |
| 1459 | static struct attribute * veth_pool_attrs[] = { |
| 1460 | &veth_active_attr, |
| 1461 | &veth_num_attr, |
| 1462 | &veth_size_attr, |
| 1463 | NULL, |
| 1464 | }; |
| 1465 | |
| 1466 | static struct sysfs_ops veth_pool_ops = { |
| 1467 | .show = veth_pool_show, |
| 1468 | .store = veth_pool_store, |
| 1469 | }; |
| 1470 | |
| 1471 | static struct kobj_type ktype_veth_pool = { |
| 1472 | .release = NULL, |
| 1473 | .sysfs_ops = &veth_pool_ops, |
| 1474 | .default_attrs = veth_pool_attrs, |
| 1475 | }; |
| 1476 | |
| 1477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | static struct vio_device_id ibmveth_device_table[] __devinitdata= { |
| 1479 | { "network", "IBM,l-lan"}, |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 1480 | { "", "" } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | MODULE_DEVICE_TABLE(vio, ibmveth_device_table); |
| 1483 | |
| 1484 | static struct vio_driver ibmveth_driver = { |
Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 1485 | .id_table = ibmveth_device_table, |
| 1486 | .probe = ibmveth_probe, |
| 1487 | .remove = ibmveth_remove, |
| 1488 | .driver = { |
| 1489 | .name = ibmveth_driver_name, |
Stephen Rothwell | 915124d | 2005-10-24 15:12:22 +1000 | [diff] [blame] | 1490 | .owner = THIS_MODULE, |
Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 1491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | }; |
| 1493 | |
| 1494 | static int __init ibmveth_module_init(void) |
| 1495 | { |
| 1496 | ibmveth_printk("%s: %s %s\n", ibmveth_driver_name, ibmveth_driver_string, ibmveth_driver_version); |
| 1497 | |
| 1498 | ibmveth_proc_register_driver(); |
| 1499 | |
| 1500 | return vio_register_driver(&ibmveth_driver); |
| 1501 | } |
| 1502 | |
| 1503 | static void __exit ibmveth_module_exit(void) |
| 1504 | { |
| 1505 | vio_unregister_driver(&ibmveth_driver); |
| 1506 | ibmveth_proc_unregister_driver(); |
Jeff Garzik | d7fbeba | 2006-05-24 01:31:14 -0400 | [diff] [blame] | 1507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | |
| 1509 | module_init(ibmveth_module_init); |
| 1510 | module_exit(ibmveth_module_exit); |