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