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