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