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