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