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