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