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