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