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