Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1 | /**************************************************************************/ |
| 2 | /* */ |
| 3 | /* IBM System i and System p Virtual NIC Device Driver */ |
| 4 | /* Copyright (C) 2014 IBM Corp. */ |
| 5 | /* Santiago Leon (santi_leon@yahoo.com) */ |
| 6 | /* Thomas Falcon (tlfalcon@linux.vnet.ibm.com) */ |
| 7 | /* John Allen (jallen@linux.vnet.ibm.com) */ |
| 8 | /* */ |
| 9 | /* This program is free software; you can redistribute it and/or modify */ |
| 10 | /* it under the terms of the GNU General Public License as published by */ |
| 11 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 12 | /* (at your option) any later version. */ |
| 13 | /* */ |
| 14 | /* This program is distributed in the hope that it will be useful, */ |
| 15 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 16 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 17 | /* GNU General Public License for more details. */ |
| 18 | /* */ |
| 19 | /* You should have received a copy of the GNU General Public License */ |
| 20 | /* along with this program. */ |
| 21 | /* */ |
| 22 | /* This module contains the implementation of a virtual ethernet device */ |
| 23 | /* for use with IBM i/p Series LPAR Linux. It utilizes the logical LAN */ |
| 24 | /* option of the RS/6000 Platform Architecture to interface with virtual */ |
| 25 | /* ethernet NICs that are presented to the partition by the hypervisor. */ |
| 26 | /* */ |
| 27 | /* Messages are passed between the VNIC driver and the VNIC server using */ |
| 28 | /* Command/Response Queues (CRQs) and sub CRQs (sCRQs). CRQs are used to */ |
| 29 | /* issue and receive commands that initiate communication with the server */ |
| 30 | /* on driver initialization. Sub CRQs (sCRQs) are similar to CRQs, but */ |
| 31 | /* are used by the driver to notify the server that a packet is */ |
| 32 | /* ready for transmission or that a buffer has been added to receive a */ |
| 33 | /* packet. Subsequently, sCRQs are used by the server to notify the */ |
| 34 | /* driver that a packet transmission has been completed or that a packet */ |
| 35 | /* has been received and placed in a waiting buffer. */ |
| 36 | /* */ |
| 37 | /* In lieu of a more conventional "on-the-fly" DMA mapping strategy in */ |
| 38 | /* which skbs are DMA mapped and immediately unmapped when the transmit */ |
| 39 | /* or receive has been completed, the VNIC driver is required to use */ |
| 40 | /* "long term mapping". This entails that large, continuous DMA mapped */ |
| 41 | /* buffers are allocated on driver initialization and these buffers are */ |
| 42 | /* then continuously reused to pass skbs to and from the VNIC server. */ |
| 43 | /* */ |
| 44 | /**************************************************************************/ |
| 45 | |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/moduleparam.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/errno.h> |
| 50 | #include <linux/completion.h> |
| 51 | #include <linux/ioport.h> |
| 52 | #include <linux/dma-mapping.h> |
| 53 | #include <linux/kernel.h> |
| 54 | #include <linux/netdevice.h> |
| 55 | #include <linux/etherdevice.h> |
| 56 | #include <linux/skbuff.h> |
| 57 | #include <linux/init.h> |
| 58 | #include <linux/delay.h> |
| 59 | #include <linux/mm.h> |
| 60 | #include <linux/ethtool.h> |
| 61 | #include <linux/proc_fs.h> |
| 62 | #include <linux/in.h> |
| 63 | #include <linux/ip.h> |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 64 | #include <linux/ipv6.h> |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 65 | #include <linux/irq.h> |
| 66 | #include <linux/kthread.h> |
| 67 | #include <linux/seq_file.h> |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 68 | #include <linux/interrupt.h> |
| 69 | #include <net/net_namespace.h> |
| 70 | #include <asm/hvcall.h> |
| 71 | #include <linux/atomic.h> |
| 72 | #include <asm/vio.h> |
| 73 | #include <asm/iommu.h> |
| 74 | #include <linux/uaccess.h> |
| 75 | #include <asm/firmware.h> |
Thomas Falcon | 65dc689 | 2016-07-06 15:35:18 -0500 | [diff] [blame] | 76 | #include <linux/workqueue.h> |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 77 | #include <linux/if_vlan.h> |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 78 | |
| 79 | #include "ibmvnic.h" |
| 80 | |
| 81 | static const char ibmvnic_driver_name[] = "ibmvnic"; |
| 82 | static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver"; |
| 83 | |
Thomas Falcon | 78b07ac | 2017-06-01 15:32:34 -0500 | [diff] [blame] | 84 | MODULE_AUTHOR("Santiago Leon"); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 85 | MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver"); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_VERSION(IBMVNIC_DRIVER_VERSION); |
| 88 | |
| 89 | static int ibmvnic_version = IBMVNIC_INITIAL_VERSION; |
| 90 | static int ibmvnic_remove(struct vio_dev *); |
| 91 | static void release_sub_crqs(struct ibmvnic_adapter *); |
| 92 | static int ibmvnic_reset_crq(struct ibmvnic_adapter *); |
| 93 | static int ibmvnic_send_crq_init(struct ibmvnic_adapter *); |
| 94 | static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *); |
| 95 | static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *); |
| 96 | static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle, |
| 97 | union sub_crq *sub_crq); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 98 | static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 99 | static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance); |
| 100 | static int enable_scrq_irq(struct ibmvnic_adapter *, |
| 101 | struct ibmvnic_sub_crq_queue *); |
| 102 | static int disable_scrq_irq(struct ibmvnic_adapter *, |
| 103 | struct ibmvnic_sub_crq_queue *); |
| 104 | static int pending_scrq(struct ibmvnic_adapter *, |
| 105 | struct ibmvnic_sub_crq_queue *); |
| 106 | static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *, |
| 107 | struct ibmvnic_sub_crq_queue *); |
| 108 | static int ibmvnic_poll(struct napi_struct *napi, int data); |
| 109 | static void send_map_query(struct ibmvnic_adapter *adapter); |
| 110 | static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8); |
| 111 | static void send_request_unmap(struct ibmvnic_adapter *, u8); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 112 | static void send_login(struct ibmvnic_adapter *adapter); |
| 113 | static void send_cap_queries(struct ibmvnic_adapter *adapter); |
| 114 | static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter); |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 115 | static int ibmvnic_init(struct ibmvnic_adapter *); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 116 | static void release_crq_queue(struct ibmvnic_adapter *); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 117 | |
| 118 | struct ibmvnic_stat { |
| 119 | char name[ETH_GSTRING_LEN]; |
| 120 | int offset; |
| 121 | }; |
| 122 | |
| 123 | #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \ |
| 124 | offsetof(struct ibmvnic_statistics, stat)) |
| 125 | #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off))) |
| 126 | |
| 127 | static const struct ibmvnic_stat ibmvnic_stats[] = { |
| 128 | {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)}, |
| 129 | {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)}, |
| 130 | {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)}, |
| 131 | {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)}, |
| 132 | {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)}, |
| 133 | {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)}, |
| 134 | {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)}, |
| 135 | {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)}, |
| 136 | {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)}, |
| 137 | {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)}, |
| 138 | {"align_errors", IBMVNIC_STAT_OFF(align_errors)}, |
| 139 | {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)}, |
| 140 | {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)}, |
| 141 | {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)}, |
| 142 | {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)}, |
| 143 | {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)}, |
| 144 | {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)}, |
| 145 | {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)}, |
| 146 | {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)}, |
| 147 | {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)}, |
| 148 | {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)}, |
| 149 | {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)}, |
| 150 | }; |
| 151 | |
| 152 | static long h_reg_sub_crq(unsigned long unit_address, unsigned long token, |
| 153 | unsigned long length, unsigned long *number, |
| 154 | unsigned long *irq) |
| 155 | { |
| 156 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 157 | long rc; |
| 158 | |
| 159 | rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length); |
| 160 | *number = retbuf[0]; |
| 161 | *irq = retbuf[1]; |
| 162 | |
| 163 | return rc; |
| 164 | } |
| 165 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 166 | static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, |
| 167 | struct ibmvnic_long_term_buff *ltb, int size) |
| 168 | { |
| 169 | struct device *dev = &adapter->vdev->dev; |
| 170 | |
| 171 | ltb->size = size; |
| 172 | ltb->buff = dma_alloc_coherent(dev, ltb->size, <b->addr, |
| 173 | GFP_KERNEL); |
| 174 | |
| 175 | if (!ltb->buff) { |
| 176 | dev_err(dev, "Couldn't alloc long term buffer\n"); |
| 177 | return -ENOMEM; |
| 178 | } |
| 179 | ltb->map_id = adapter->map_id; |
| 180 | adapter->map_id++; |
Nathan Fontenot | db5d0b5 | 2017-02-10 13:45:05 -0500 | [diff] [blame] | 181 | |
| 182 | init_completion(&adapter->fw_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 183 | send_request_map(adapter, ltb->addr, |
| 184 | ltb->size, ltb->map_id); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 185 | wait_for_completion(&adapter->fw_done); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static void free_long_term_buff(struct ibmvnic_adapter *adapter, |
| 190 | struct ibmvnic_long_term_buff *ltb) |
| 191 | { |
| 192 | struct device *dev = &adapter->vdev->dev; |
| 193 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 194 | if (!ltb->buff) |
| 195 | return; |
| 196 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 197 | if (adapter->reset_reason != VNIC_RESET_FAILOVER && |
| 198 | adapter->reset_reason != VNIC_RESET_MOBILITY) |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 199 | send_request_unmap(adapter, ltb->map_id); |
Brian King | 59af56c | 2017-04-19 13:44:41 -0400 | [diff] [blame] | 200 | dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 201 | } |
| 202 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 203 | static void replenish_rx_pool(struct ibmvnic_adapter *adapter, |
| 204 | struct ibmvnic_rx_pool *pool) |
| 205 | { |
| 206 | int count = pool->size - atomic_read(&pool->available); |
| 207 | struct device *dev = &adapter->vdev->dev; |
| 208 | int buffers_added = 0; |
| 209 | unsigned long lpar_rc; |
| 210 | union sub_crq sub_crq; |
| 211 | struct sk_buff *skb; |
| 212 | unsigned int offset; |
| 213 | dma_addr_t dma_addr; |
| 214 | unsigned char *dst; |
| 215 | u64 *handle_array; |
| 216 | int shift = 0; |
| 217 | int index; |
| 218 | int i; |
| 219 | |
| 220 | handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 221 | be32_to_cpu(adapter->login_rsp_buf-> |
| 222 | off_rxadd_subcrqs)); |
| 223 | |
| 224 | for (i = 0; i < count; ++i) { |
| 225 | skb = alloc_skb(pool->buff_size, GFP_ATOMIC); |
| 226 | if (!skb) { |
| 227 | dev_err(dev, "Couldn't replenish rx buff\n"); |
| 228 | adapter->replenish_no_mem++; |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | index = pool->free_map[pool->next_free]; |
| 233 | |
| 234 | if (pool->rx_buff[index].skb) |
| 235 | dev_err(dev, "Inconsistent free_map!\n"); |
| 236 | |
| 237 | /* Copy the skb to the long term mapped DMA buffer */ |
| 238 | offset = index * pool->buff_size; |
| 239 | dst = pool->long_term_buff.buff + offset; |
| 240 | memset(dst, 0, pool->buff_size); |
| 241 | dma_addr = pool->long_term_buff.addr + offset; |
| 242 | pool->rx_buff[index].data = dst; |
| 243 | |
| 244 | pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP; |
| 245 | pool->rx_buff[index].dma = dma_addr; |
| 246 | pool->rx_buff[index].skb = skb; |
| 247 | pool->rx_buff[index].pool_index = pool->index; |
| 248 | pool->rx_buff[index].size = pool->buff_size; |
| 249 | |
| 250 | memset(&sub_crq, 0, sizeof(sub_crq)); |
| 251 | sub_crq.rx_add.first = IBMVNIC_CRQ_CMD; |
| 252 | sub_crq.rx_add.correlator = |
| 253 | cpu_to_be64((u64)&pool->rx_buff[index]); |
| 254 | sub_crq.rx_add.ioba = cpu_to_be32(dma_addr); |
| 255 | sub_crq.rx_add.map_id = pool->long_term_buff.map_id; |
| 256 | |
| 257 | /* The length field of the sCRQ is defined to be 24 bits so the |
| 258 | * buffer size needs to be left shifted by a byte before it is |
| 259 | * converted to big endian to prevent the last byte from being |
| 260 | * truncated. |
| 261 | */ |
| 262 | #ifdef __LITTLE_ENDIAN__ |
| 263 | shift = 8; |
| 264 | #endif |
| 265 | sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift); |
| 266 | |
| 267 | lpar_rc = send_subcrq(adapter, handle_array[pool->index], |
| 268 | &sub_crq); |
| 269 | if (lpar_rc != H_SUCCESS) |
| 270 | goto failure; |
| 271 | |
| 272 | buffers_added++; |
| 273 | adapter->replenish_add_buff_success++; |
| 274 | pool->next_free = (pool->next_free + 1) % pool->size; |
| 275 | } |
| 276 | atomic_add(buffers_added, &pool->available); |
| 277 | return; |
| 278 | |
| 279 | failure: |
| 280 | dev_info(dev, "replenish pools failure\n"); |
| 281 | pool->free_map[pool->next_free] = index; |
| 282 | pool->rx_buff[index].skb = NULL; |
| 283 | if (!dma_mapping_error(dev, dma_addr)) |
| 284 | dma_unmap_single(dev, dma_addr, pool->buff_size, |
| 285 | DMA_FROM_DEVICE); |
| 286 | |
| 287 | dev_kfree_skb_any(skb); |
| 288 | adapter->replenish_add_buff_failure++; |
| 289 | atomic_add(buffers_added, &pool->available); |
| 290 | } |
| 291 | |
| 292 | static void replenish_pools(struct ibmvnic_adapter *adapter) |
| 293 | { |
| 294 | int i; |
| 295 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 296 | adapter->replenish_task_cycles++; |
| 297 | for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 298 | i++) { |
| 299 | if (adapter->rx_pool[i].active) |
| 300 | replenish_rx_pool(adapter, &adapter->rx_pool[i]); |
| 301 | } |
| 302 | } |
| 303 | |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 304 | static void release_stats_token(struct ibmvnic_adapter *adapter) |
| 305 | { |
| 306 | struct device *dev = &adapter->vdev->dev; |
| 307 | |
| 308 | if (!adapter->stats_token) |
| 309 | return; |
| 310 | |
| 311 | dma_unmap_single(dev, adapter->stats_token, |
| 312 | sizeof(struct ibmvnic_statistics), |
| 313 | DMA_FROM_DEVICE); |
| 314 | adapter->stats_token = 0; |
| 315 | } |
| 316 | |
| 317 | static int init_stats_token(struct ibmvnic_adapter *adapter) |
| 318 | { |
| 319 | struct device *dev = &adapter->vdev->dev; |
| 320 | dma_addr_t stok; |
| 321 | |
| 322 | stok = dma_map_single(dev, &adapter->stats, |
| 323 | sizeof(struct ibmvnic_statistics), |
| 324 | DMA_FROM_DEVICE); |
| 325 | if (dma_mapping_error(dev, stok)) { |
| 326 | dev_err(dev, "Couldn't map stats buffer\n"); |
| 327 | return -1; |
| 328 | } |
| 329 | |
| 330 | adapter->stats_token = stok; |
| 331 | return 0; |
| 332 | } |
| 333 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 334 | static void release_rx_pools(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 335 | { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 336 | struct ibmvnic_rx_pool *rx_pool; |
| 337 | int rx_scrqs; |
| 338 | int i, j; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 339 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 340 | if (!adapter->rx_pool) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 341 | return; |
| 342 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 343 | rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 344 | for (i = 0; i < rx_scrqs; i++) { |
| 345 | rx_pool = &adapter->rx_pool[i]; |
| 346 | |
| 347 | kfree(rx_pool->free_map); |
| 348 | free_long_term_buff(adapter, &rx_pool->long_term_buff); |
| 349 | |
| 350 | if (!rx_pool->rx_buff) |
Nathan Fontenot | e0ebe942 | 2017-05-03 14:04:50 -0400 | [diff] [blame] | 351 | continue; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 352 | |
| 353 | for (j = 0; j < rx_pool->size; j++) { |
| 354 | if (rx_pool->rx_buff[j].skb) { |
| 355 | dev_kfree_skb_any(rx_pool->rx_buff[i].skb); |
| 356 | rx_pool->rx_buff[i].skb = NULL; |
| 357 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 358 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 359 | |
| 360 | kfree(rx_pool->rx_buff); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 361 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 362 | |
| 363 | kfree(adapter->rx_pool); |
| 364 | adapter->rx_pool = NULL; |
| 365 | } |
| 366 | |
| 367 | static int init_rx_pools(struct net_device *netdev) |
| 368 | { |
| 369 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 370 | struct device *dev = &adapter->vdev->dev; |
| 371 | struct ibmvnic_rx_pool *rx_pool; |
| 372 | int rxadd_subcrqs; |
| 373 | u64 *size_array; |
| 374 | int i, j; |
| 375 | |
| 376 | rxadd_subcrqs = |
| 377 | be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 378 | size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 379 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size)); |
| 380 | |
| 381 | adapter->rx_pool = kcalloc(rxadd_subcrqs, |
| 382 | sizeof(struct ibmvnic_rx_pool), |
| 383 | GFP_KERNEL); |
| 384 | if (!adapter->rx_pool) { |
| 385 | dev_err(dev, "Failed to allocate rx pools\n"); |
| 386 | return -1; |
| 387 | } |
| 388 | |
| 389 | for (i = 0; i < rxadd_subcrqs; i++) { |
| 390 | rx_pool = &adapter->rx_pool[i]; |
| 391 | |
| 392 | netdev_dbg(adapter->netdev, |
| 393 | "Initializing rx_pool %d, %lld buffs, %lld bytes each\n", |
| 394 | i, adapter->req_rx_add_entries_per_subcrq, |
| 395 | be64_to_cpu(size_array[i])); |
| 396 | |
| 397 | rx_pool->size = adapter->req_rx_add_entries_per_subcrq; |
| 398 | rx_pool->index = i; |
| 399 | rx_pool->buff_size = be64_to_cpu(size_array[i]); |
| 400 | rx_pool->active = 1; |
| 401 | |
| 402 | rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int), |
| 403 | GFP_KERNEL); |
| 404 | if (!rx_pool->free_map) { |
| 405 | release_rx_pools(adapter); |
| 406 | return -1; |
| 407 | } |
| 408 | |
| 409 | rx_pool->rx_buff = kcalloc(rx_pool->size, |
| 410 | sizeof(struct ibmvnic_rx_buff), |
| 411 | GFP_KERNEL); |
| 412 | if (!rx_pool->rx_buff) { |
| 413 | dev_err(dev, "Couldn't alloc rx buffers\n"); |
| 414 | release_rx_pools(adapter); |
| 415 | return -1; |
| 416 | } |
| 417 | |
| 418 | if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff, |
| 419 | rx_pool->size * rx_pool->buff_size)) { |
| 420 | release_rx_pools(adapter); |
| 421 | return -1; |
| 422 | } |
| 423 | |
| 424 | for (j = 0; j < rx_pool->size; ++j) |
| 425 | rx_pool->free_map[j] = j; |
| 426 | |
| 427 | atomic_set(&rx_pool->available, 0); |
| 428 | rx_pool->next_alloc = 0; |
| 429 | rx_pool->next_free = 0; |
| 430 | } |
| 431 | |
| 432 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 433 | } |
| 434 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 435 | static void release_tx_pools(struct ibmvnic_adapter *adapter) |
| 436 | { |
| 437 | struct ibmvnic_tx_pool *tx_pool; |
| 438 | int i, tx_scrqs; |
| 439 | |
| 440 | if (!adapter->tx_pool) |
| 441 | return; |
| 442 | |
| 443 | tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 444 | for (i = 0; i < tx_scrqs; i++) { |
| 445 | tx_pool = &adapter->tx_pool[i]; |
| 446 | kfree(tx_pool->tx_buff); |
| 447 | free_long_term_buff(adapter, &tx_pool->long_term_buff); |
| 448 | kfree(tx_pool->free_map); |
| 449 | } |
| 450 | |
| 451 | kfree(adapter->tx_pool); |
| 452 | adapter->tx_pool = NULL; |
| 453 | } |
| 454 | |
| 455 | static int init_tx_pools(struct net_device *netdev) |
| 456 | { |
| 457 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 458 | struct device *dev = &adapter->vdev->dev; |
| 459 | struct ibmvnic_tx_pool *tx_pool; |
| 460 | int tx_subcrqs; |
| 461 | int i, j; |
| 462 | |
| 463 | tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 464 | adapter->tx_pool = kcalloc(tx_subcrqs, |
| 465 | sizeof(struct ibmvnic_tx_pool), GFP_KERNEL); |
| 466 | if (!adapter->tx_pool) |
| 467 | return -1; |
| 468 | |
| 469 | for (i = 0; i < tx_subcrqs; i++) { |
| 470 | tx_pool = &adapter->tx_pool[i]; |
| 471 | tx_pool->tx_buff = kcalloc(adapter->req_tx_entries_per_subcrq, |
| 472 | sizeof(struct ibmvnic_tx_buff), |
| 473 | GFP_KERNEL); |
| 474 | if (!tx_pool->tx_buff) { |
| 475 | dev_err(dev, "tx pool buffer allocation failed\n"); |
| 476 | release_tx_pools(adapter); |
| 477 | return -1; |
| 478 | } |
| 479 | |
| 480 | if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff, |
| 481 | adapter->req_tx_entries_per_subcrq * |
| 482 | adapter->req_mtu)) { |
| 483 | release_tx_pools(adapter); |
| 484 | return -1; |
| 485 | } |
| 486 | |
| 487 | tx_pool->free_map = kcalloc(adapter->req_tx_entries_per_subcrq, |
| 488 | sizeof(int), GFP_KERNEL); |
| 489 | if (!tx_pool->free_map) { |
| 490 | release_tx_pools(adapter); |
| 491 | return -1; |
| 492 | } |
| 493 | |
| 494 | for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++) |
| 495 | tx_pool->free_map[j] = j; |
| 496 | |
| 497 | tx_pool->consumer_index = 0; |
| 498 | tx_pool->producer_index = 0; |
| 499 | } |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 504 | static void release_error_buffers(struct ibmvnic_adapter *adapter) |
| 505 | { |
| 506 | struct device *dev = &adapter->vdev->dev; |
| 507 | struct ibmvnic_error_buff *error_buff, *tmp; |
| 508 | unsigned long flags; |
| 509 | |
| 510 | spin_lock_irqsave(&adapter->error_list_lock, flags); |
| 511 | list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) { |
| 512 | list_del(&error_buff->list); |
| 513 | dma_unmap_single(dev, error_buff->dma, error_buff->len, |
| 514 | DMA_FROM_DEVICE); |
| 515 | kfree(error_buff->buff); |
| 516 | kfree(error_buff); |
| 517 | } |
| 518 | spin_unlock_irqrestore(&adapter->error_list_lock, flags); |
| 519 | } |
| 520 | |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 521 | static int ibmvnic_login(struct net_device *netdev) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 522 | { |
| 523 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 524 | unsigned long timeout = msecs_to_jiffies(30000); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 525 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 526 | |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 527 | do { |
| 528 | if (adapter->renegotiate) { |
| 529 | adapter->renegotiate = false; |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 530 | release_sub_crqs(adapter); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 531 | |
| 532 | reinit_completion(&adapter->init_done); |
| 533 | send_cap_queries(adapter); |
| 534 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 535 | timeout)) { |
| 536 | dev_err(dev, "Capabilities query timeout\n"); |
| 537 | return -1; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | reinit_completion(&adapter->init_done); |
| 542 | send_login(adapter); |
| 543 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 544 | timeout)) { |
| 545 | dev_err(dev, "Login timeout\n"); |
| 546 | return -1; |
| 547 | } |
| 548 | } while (adapter->renegotiate); |
| 549 | |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 550 | return 0; |
| 551 | } |
| 552 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 553 | static void release_resources(struct ibmvnic_adapter *adapter) |
| 554 | { |
Nathan Fontenot | c7bac00 | 2017-05-03 14:04:44 -0400 | [diff] [blame] | 555 | int i; |
| 556 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 557 | release_tx_pools(adapter); |
| 558 | release_rx_pools(adapter); |
| 559 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 560 | release_stats_token(adapter); |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 561 | release_error_buffers(adapter); |
Nathan Fontenot | c7bac00 | 2017-05-03 14:04:44 -0400 | [diff] [blame] | 562 | |
| 563 | if (adapter->napi) { |
| 564 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 565 | if (&adapter->napi[i]) |
| 566 | netif_napi_del(&adapter->napi[i]); |
| 567 | } |
| 568 | } |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 571 | static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state) |
| 572 | { |
| 573 | struct net_device *netdev = adapter->netdev; |
| 574 | unsigned long timeout = msecs_to_jiffies(30000); |
| 575 | union ibmvnic_crq crq; |
| 576 | bool resend; |
| 577 | int rc; |
| 578 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 579 | netdev_err(netdev, "setting link state %d\n", link_state); |
| 580 | memset(&crq, 0, sizeof(crq)); |
| 581 | crq.logical_link_state.first = IBMVNIC_CRQ_CMD; |
| 582 | crq.logical_link_state.cmd = LOGICAL_LINK_STATE; |
| 583 | crq.logical_link_state.link_state = link_state; |
| 584 | |
| 585 | do { |
| 586 | resend = false; |
| 587 | |
| 588 | reinit_completion(&adapter->init_done); |
| 589 | rc = ibmvnic_send_crq(adapter, &crq); |
| 590 | if (rc) { |
| 591 | netdev_err(netdev, "Failed to set link state\n"); |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 596 | timeout)) { |
| 597 | netdev_err(netdev, "timeout setting link state\n"); |
| 598 | return -1; |
| 599 | } |
| 600 | |
| 601 | if (adapter->init_done_rc == 1) { |
| 602 | /* Partuial success, delay and re-send */ |
| 603 | mdelay(1000); |
| 604 | resend = true; |
| 605 | } |
| 606 | } while (resend); |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 611 | static int set_real_num_queues(struct net_device *netdev) |
| 612 | { |
| 613 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 614 | int rc; |
| 615 | |
| 616 | rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues); |
| 617 | if (rc) { |
| 618 | netdev_err(netdev, "failed to set the number of tx queues\n"); |
| 619 | return rc; |
| 620 | } |
| 621 | |
| 622 | rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues); |
| 623 | if (rc) |
| 624 | netdev_err(netdev, "failed to set the number of rx queues\n"); |
| 625 | |
| 626 | return rc; |
| 627 | } |
| 628 | |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 629 | static int init_resources(struct ibmvnic_adapter *adapter) |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 630 | { |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 631 | struct net_device *netdev = adapter->netdev; |
| 632 | int i, rc; |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 633 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 634 | rc = set_real_num_queues(netdev); |
| 635 | if (rc) |
| 636 | return rc; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 637 | |
| 638 | rc = init_sub_crq_irqs(adapter); |
| 639 | if (rc) { |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 640 | netdev_err(netdev, "failed to initialize sub crq irqs\n"); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 641 | return -1; |
| 642 | } |
| 643 | |
Nathan Fontenot | 5d5e84e | 2017-04-21 15:38:58 -0400 | [diff] [blame] | 644 | rc = init_stats_token(adapter); |
| 645 | if (rc) |
| 646 | return rc; |
| 647 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 648 | adapter->map_id = 1; |
| 649 | adapter->napi = kcalloc(adapter->req_rx_queues, |
| 650 | sizeof(struct napi_struct), GFP_KERNEL); |
| 651 | if (!adapter->napi) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 652 | return -ENOMEM; |
| 653 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 654 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 655 | netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll, |
| 656 | NAPI_POLL_WEIGHT); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 657 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 658 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 659 | send_map_query(adapter); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 660 | |
| 661 | rc = init_rx_pools(netdev); |
| 662 | if (rc) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 663 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 664 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 665 | rc = init_tx_pools(netdev); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 666 | return rc; |
| 667 | } |
| 668 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 669 | static int __ibmvnic_open(struct net_device *netdev) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 670 | { |
| 671 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 672 | enum vnic_state prev_state = adapter->state; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 673 | int i, rc; |
| 674 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 675 | adapter->state = VNIC_OPENING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 676 | replenish_pools(adapter); |
| 677 | |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 678 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 679 | napi_enable(&adapter->napi[i]); |
| 680 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 681 | /* We're ready to receive frames, enable the sub-crq interrupts and |
| 682 | * set the logical link state to up |
| 683 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 684 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 685 | if (prev_state == VNIC_CLOSED) |
| 686 | enable_irq(adapter->rx_scrq[i]->irq); |
| 687 | else |
| 688 | enable_scrq_irq(adapter, adapter->rx_scrq[i]); |
| 689 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 690 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 691 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 692 | if (prev_state == VNIC_CLOSED) |
| 693 | enable_irq(adapter->tx_scrq[i]->irq); |
| 694 | else |
| 695 | enable_scrq_irq(adapter, adapter->tx_scrq[i]); |
| 696 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 697 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 698 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 699 | if (rc) { |
| 700 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 701 | napi_disable(&adapter->napi[i]); |
| 702 | release_resources(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 703 | return rc; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 704 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 705 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 706 | netif_tx_start_all_queues(netdev); |
| 707 | |
| 708 | if (prev_state == VNIC_CLOSED) { |
| 709 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 710 | napi_schedule(&adapter->napi[i]); |
| 711 | } |
| 712 | |
| 713 | adapter->state = VNIC_OPEN; |
| 714 | return rc; |
| 715 | } |
| 716 | |
| 717 | static int ibmvnic_open(struct net_device *netdev) |
| 718 | { |
| 719 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 720 | int rc; |
| 721 | |
| 722 | mutex_lock(&adapter->reset_lock); |
| 723 | |
| 724 | if (adapter->state != VNIC_CLOSED) { |
| 725 | rc = ibmvnic_login(netdev); |
| 726 | if (rc) { |
| 727 | mutex_unlock(&adapter->reset_lock); |
| 728 | return rc; |
| 729 | } |
| 730 | |
| 731 | rc = init_resources(adapter); |
| 732 | if (rc) { |
| 733 | netdev_err(netdev, "failed to initialize resources\n"); |
| 734 | release_resources(adapter); |
| 735 | mutex_unlock(&adapter->reset_lock); |
| 736 | return rc; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | rc = __ibmvnic_open(netdev); |
| 741 | mutex_unlock(&adapter->reset_lock); |
| 742 | |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 743 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 744 | } |
| 745 | |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 746 | static void clean_tx_pools(struct ibmvnic_adapter *adapter) |
| 747 | { |
| 748 | struct ibmvnic_tx_pool *tx_pool; |
| 749 | u64 tx_entries; |
| 750 | int tx_scrqs; |
| 751 | int i, j; |
| 752 | |
| 753 | if (!adapter->tx_pool) |
| 754 | return; |
| 755 | |
| 756 | tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 757 | tx_entries = adapter->req_tx_entries_per_subcrq; |
| 758 | |
| 759 | /* Free any remaining skbs in the tx buffer pools */ |
| 760 | for (i = 0; i < tx_scrqs; i++) { |
| 761 | tx_pool = &adapter->tx_pool[i]; |
| 762 | if (!tx_pool) |
| 763 | continue; |
| 764 | |
| 765 | for (j = 0; j < tx_entries; j++) { |
| 766 | if (tx_pool->tx_buff[j].skb) { |
| 767 | dev_kfree_skb_any(tx_pool->tx_buff[j].skb); |
| 768 | tx_pool->tx_buff[j].skb = NULL; |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 774 | static int __ibmvnic_close(struct net_device *netdev) |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 775 | { |
| 776 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 777 | int rc = 0; |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 778 | int i; |
| 779 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 780 | adapter->state = VNIC_CLOSING; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 781 | netif_tx_stop_all_queues(netdev); |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 782 | |
Nathan Fontenot | 3ca1993 | 2017-04-21 15:39:10 -0400 | [diff] [blame] | 783 | if (adapter->napi) { |
| 784 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 785 | napi_disable(&adapter->napi[i]); |
| 786 | } |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 787 | |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 788 | clean_tx_pools(adapter); |
| 789 | |
| 790 | if (adapter->tx_scrq) { |
| 791 | for (i = 0; i < adapter->req_tx_queues; i++) |
| 792 | if (adapter->tx_scrq[i]->irq) |
| 793 | disable_irq(adapter->tx_scrq[i]->irq); |
| 794 | } |
| 795 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 796 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 797 | if (rc) |
| 798 | return rc; |
| 799 | |
| 800 | if (adapter->rx_scrq) { |
| 801 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 802 | int retries = 10; |
| 803 | |
| 804 | while (pending_scrq(adapter, adapter->rx_scrq[i])) { |
| 805 | retries--; |
| 806 | mdelay(100); |
| 807 | |
| 808 | if (retries == 0) |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | if (adapter->rx_scrq[i]->irq) |
| 813 | disable_irq(adapter->rx_scrq[i]->irq); |
| 814 | } |
| 815 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 816 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 817 | adapter->state = VNIC_CLOSED; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 818 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 819 | } |
| 820 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 821 | static int ibmvnic_close(struct net_device *netdev) |
| 822 | { |
| 823 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 824 | int rc; |
| 825 | |
| 826 | mutex_lock(&adapter->reset_lock); |
| 827 | rc = __ibmvnic_close(netdev); |
| 828 | mutex_unlock(&adapter->reset_lock); |
| 829 | |
| 830 | return rc; |
| 831 | } |
| 832 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 833 | /** |
| 834 | * build_hdr_data - creates L2/L3/L4 header data buffer |
| 835 | * @hdr_field - bitfield determining needed headers |
| 836 | * @skb - socket buffer |
| 837 | * @hdr_len - array of header lengths |
| 838 | * @tot_len - total length of data |
| 839 | * |
| 840 | * Reads hdr_field to determine which headers are needed by firmware. |
| 841 | * Builds a buffer containing these headers. Saves individual header |
| 842 | * lengths and total buffer length to be used to build descriptors. |
| 843 | */ |
| 844 | static int build_hdr_data(u8 hdr_field, struct sk_buff *skb, |
| 845 | int *hdr_len, u8 *hdr_data) |
| 846 | { |
| 847 | int len = 0; |
| 848 | u8 *hdr; |
| 849 | |
| 850 | hdr_len[0] = sizeof(struct ethhdr); |
| 851 | |
| 852 | if (skb->protocol == htons(ETH_P_IP)) { |
| 853 | hdr_len[1] = ip_hdr(skb)->ihl * 4; |
| 854 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 855 | hdr_len[2] = tcp_hdrlen(skb); |
| 856 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 857 | hdr_len[2] = sizeof(struct udphdr); |
| 858 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 859 | hdr_len[1] = sizeof(struct ipv6hdr); |
| 860 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 861 | hdr_len[2] = tcp_hdrlen(skb); |
| 862 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) |
| 863 | hdr_len[2] = sizeof(struct udphdr); |
| 864 | } |
| 865 | |
| 866 | memset(hdr_data, 0, 120); |
| 867 | if ((hdr_field >> 6) & 1) { |
| 868 | hdr = skb_mac_header(skb); |
| 869 | memcpy(hdr_data, hdr, hdr_len[0]); |
| 870 | len += hdr_len[0]; |
| 871 | } |
| 872 | |
| 873 | if ((hdr_field >> 5) & 1) { |
| 874 | hdr = skb_network_header(skb); |
| 875 | memcpy(hdr_data + len, hdr, hdr_len[1]); |
| 876 | len += hdr_len[1]; |
| 877 | } |
| 878 | |
| 879 | if ((hdr_field >> 4) & 1) { |
| 880 | hdr = skb_transport_header(skb); |
| 881 | memcpy(hdr_data + len, hdr, hdr_len[2]); |
| 882 | len += hdr_len[2]; |
| 883 | } |
| 884 | return len; |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * create_hdr_descs - create header and header extension descriptors |
| 889 | * @hdr_field - bitfield determining needed headers |
| 890 | * @data - buffer containing header data |
| 891 | * @len - length of data buffer |
| 892 | * @hdr_len - array of individual header lengths |
| 893 | * @scrq_arr - descriptor array |
| 894 | * |
| 895 | * Creates header and, if needed, header extension descriptors and |
| 896 | * places them in a descriptor array, scrq_arr |
| 897 | */ |
| 898 | |
| 899 | static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len, |
| 900 | union sub_crq *scrq_arr) |
| 901 | { |
| 902 | union sub_crq hdr_desc; |
| 903 | int tmp_len = len; |
| 904 | u8 *data, *cur; |
| 905 | int tmp; |
| 906 | |
| 907 | while (tmp_len > 0) { |
| 908 | cur = hdr_data + len - tmp_len; |
| 909 | |
| 910 | memset(&hdr_desc, 0, sizeof(hdr_desc)); |
| 911 | if (cur != hdr_data) { |
| 912 | data = hdr_desc.hdr_ext.data; |
| 913 | tmp = tmp_len > 29 ? 29 : tmp_len; |
| 914 | hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD; |
| 915 | hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC; |
| 916 | hdr_desc.hdr_ext.len = tmp; |
| 917 | } else { |
| 918 | data = hdr_desc.hdr.data; |
| 919 | tmp = tmp_len > 24 ? 24 : tmp_len; |
| 920 | hdr_desc.hdr.first = IBMVNIC_CRQ_CMD; |
| 921 | hdr_desc.hdr.type = IBMVNIC_HDR_DESC; |
| 922 | hdr_desc.hdr.len = tmp; |
| 923 | hdr_desc.hdr.l2_len = (u8)hdr_len[0]; |
| 924 | hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]); |
| 925 | hdr_desc.hdr.l4_len = (u8)hdr_len[2]; |
| 926 | hdr_desc.hdr.flag = hdr_field << 1; |
| 927 | } |
| 928 | memcpy(data, cur, tmp); |
| 929 | tmp_len -= tmp; |
| 930 | *scrq_arr = hdr_desc; |
| 931 | scrq_arr++; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * build_hdr_descs_arr - build a header descriptor array |
| 937 | * @skb - socket buffer |
| 938 | * @num_entries - number of descriptors to be sent |
| 939 | * @subcrq - first TX descriptor |
| 940 | * @hdr_field - bit field determining which headers will be sent |
| 941 | * |
| 942 | * This function will build a TX descriptor array with applicable |
| 943 | * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect. |
| 944 | */ |
| 945 | |
| 946 | static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff, |
| 947 | int *num_entries, u8 hdr_field) |
| 948 | { |
| 949 | int hdr_len[3] = {0, 0, 0}; |
| 950 | int tot_len, len; |
| 951 | u8 *hdr_data = txbuff->hdr_data; |
| 952 | |
| 953 | tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len, |
| 954 | txbuff->hdr_data); |
| 955 | len = tot_len; |
| 956 | len -= 24; |
| 957 | if (len > 0) |
| 958 | num_entries += len % 29 ? len / 29 + 1 : len / 29; |
| 959 | create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len, |
| 960 | txbuff->indir_arr + 1); |
| 961 | } |
| 962 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 963 | static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 964 | { |
| 965 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 966 | int queue_num = skb_get_queue_mapping(skb); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 967 | u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 968 | struct device *dev = &adapter->vdev->dev; |
| 969 | struct ibmvnic_tx_buff *tx_buff = NULL; |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 970 | struct ibmvnic_sub_crq_queue *tx_scrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 971 | struct ibmvnic_tx_pool *tx_pool; |
| 972 | unsigned int tx_send_failed = 0; |
| 973 | unsigned int tx_map_failed = 0; |
| 974 | unsigned int tx_dropped = 0; |
| 975 | unsigned int tx_packets = 0; |
| 976 | unsigned int tx_bytes = 0; |
| 977 | dma_addr_t data_dma_addr; |
| 978 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 979 | unsigned long lpar_rc; |
| 980 | union sub_crq tx_crq; |
| 981 | unsigned int offset; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 982 | int num_entries = 1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 983 | unsigned char *dst; |
| 984 | u64 *handle_array; |
| 985 | int index = 0; |
| 986 | int ret = 0; |
| 987 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 988 | if (adapter->resetting) { |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 989 | if (!netif_subqueue_stopped(netdev, skb)) |
| 990 | netif_stop_subqueue(netdev, queue_num); |
| 991 | dev_kfree_skb_any(skb); |
| 992 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 993 | tx_send_failed++; |
| 994 | tx_dropped++; |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 995 | ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 996 | goto out; |
| 997 | } |
| 998 | |
Nathan Fontenot | 161b8a8 | 2017-05-03 14:05:08 -0400 | [diff] [blame] | 999 | tx_pool = &adapter->tx_pool[queue_num]; |
| 1000 | tx_scrq = adapter->tx_scrq[queue_num]; |
| 1001 | txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb)); |
| 1002 | handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 1003 | be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs)); |
| 1004 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1005 | index = tx_pool->free_map[tx_pool->consumer_index]; |
| 1006 | offset = index * adapter->req_mtu; |
| 1007 | dst = tx_pool->long_term_buff.buff + offset; |
| 1008 | memset(dst, 0, adapter->req_mtu); |
| 1009 | skb_copy_from_linear_data(skb, dst, skb->len); |
| 1010 | data_dma_addr = tx_pool->long_term_buff.addr + offset; |
| 1011 | |
| 1012 | tx_pool->consumer_index = |
| 1013 | (tx_pool->consumer_index + 1) % |
Thomas Falcon | 068d9f9 | 2017-03-05 12:18:42 -0600 | [diff] [blame] | 1014 | adapter->req_tx_entries_per_subcrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1015 | |
| 1016 | tx_buff = &tx_pool->tx_buff[index]; |
| 1017 | tx_buff->skb = skb; |
| 1018 | tx_buff->data_dma[0] = data_dma_addr; |
| 1019 | tx_buff->data_len[0] = skb->len; |
| 1020 | tx_buff->index = index; |
| 1021 | tx_buff->pool_index = queue_num; |
| 1022 | tx_buff->last_frag = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1023 | |
| 1024 | memset(&tx_crq, 0, sizeof(tx_crq)); |
| 1025 | tx_crq.v1.first = IBMVNIC_CRQ_CMD; |
| 1026 | tx_crq.v1.type = IBMVNIC_TX_DESC; |
| 1027 | tx_crq.v1.n_crq_elem = 1; |
| 1028 | tx_crq.v1.n_sge = 1; |
| 1029 | tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED; |
| 1030 | tx_crq.v1.correlator = cpu_to_be32(index); |
| 1031 | tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id); |
| 1032 | tx_crq.v1.sge_len = cpu_to_be32(skb->len); |
| 1033 | tx_crq.v1.ioba = cpu_to_be64(data_dma_addr); |
| 1034 | |
| 1035 | if (adapter->vlan_header_insertion) { |
| 1036 | tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT; |
| 1037 | tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci); |
| 1038 | } |
| 1039 | |
| 1040 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1041 | if (ip_hdr(skb)->version == 4) |
| 1042 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4; |
| 1043 | else if (ip_hdr(skb)->version == 6) |
| 1044 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6; |
| 1045 | |
| 1046 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 1047 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP; |
| 1048 | else if (ip_hdr(skb)->protocol != IPPROTO_TCP) |
| 1049 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP; |
| 1050 | } |
| 1051 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1052 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1053 | tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1054 | hdrs += 2; |
| 1055 | } |
| 1056 | /* determine if l2/3/4 headers are sent to firmware */ |
| 1057 | if ((*hdrs >> 7) & 1 && |
| 1058 | (skb->protocol == htons(ETH_P_IP) || |
| 1059 | skb->protocol == htons(ETH_P_IPV6))) { |
| 1060 | build_hdr_descs_arr(tx_buff, &num_entries, *hdrs); |
| 1061 | tx_crq.v1.n_crq_elem = num_entries; |
| 1062 | tx_buff->indir_arr[0] = tx_crq; |
| 1063 | tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr, |
| 1064 | sizeof(tx_buff->indir_arr), |
| 1065 | DMA_TO_DEVICE); |
| 1066 | if (dma_mapping_error(dev, tx_buff->indir_dma)) { |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1067 | dev_kfree_skb_any(skb); |
| 1068 | tx_buff->skb = NULL; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1069 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
| 1070 | dev_err(dev, "tx: unable to map descriptor array\n"); |
| 1071 | tx_map_failed++; |
| 1072 | tx_dropped++; |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1073 | ret = NETDEV_TX_OK; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1074 | goto out; |
| 1075 | } |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 1076 | lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num], |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1077 | (u64)tx_buff->indir_dma, |
| 1078 | (u64)num_entries); |
| 1079 | } else { |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 1080 | lpar_rc = send_subcrq(adapter, handle_array[queue_num], |
| 1081 | &tx_crq); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1082 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1083 | if (lpar_rc != H_SUCCESS) { |
| 1084 | dev_err(dev, "tx failed with code %ld\n", lpar_rc); |
| 1085 | |
| 1086 | if (tx_pool->consumer_index == 0) |
| 1087 | tx_pool->consumer_index = |
Thomas Falcon | 068d9f9 | 2017-03-05 12:18:42 -0600 | [diff] [blame] | 1088 | adapter->req_tx_entries_per_subcrq - 1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1089 | else |
| 1090 | tx_pool->consumer_index--; |
| 1091 | |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1092 | dev_kfree_skb_any(skb); |
| 1093 | tx_buff->skb = NULL; |
| 1094 | |
| 1095 | if (lpar_rc == H_CLOSED) |
| 1096 | netif_stop_subqueue(netdev, queue_num); |
| 1097 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1098 | tx_send_failed++; |
| 1099 | tx_dropped++; |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1100 | ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1101 | goto out; |
| 1102 | } |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1103 | |
Brian King | 58c8c0c | 2017-04-19 13:44:47 -0400 | [diff] [blame] | 1104 | if (atomic_inc_return(&tx_scrq->used) |
| 1105 | >= adapter->req_tx_entries_per_subcrq) { |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1106 | netdev_info(netdev, "Stopping queue %d\n", queue_num); |
| 1107 | netif_stop_subqueue(netdev, queue_num); |
| 1108 | } |
| 1109 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1110 | tx_packets++; |
| 1111 | tx_bytes += skb->len; |
| 1112 | txq->trans_start = jiffies; |
| 1113 | ret = NETDEV_TX_OK; |
| 1114 | |
| 1115 | out: |
| 1116 | netdev->stats.tx_dropped += tx_dropped; |
| 1117 | netdev->stats.tx_bytes += tx_bytes; |
| 1118 | netdev->stats.tx_packets += tx_packets; |
| 1119 | adapter->tx_send_failed += tx_send_failed; |
| 1120 | adapter->tx_map_failed += tx_map_failed; |
| 1121 | |
| 1122 | return ret; |
| 1123 | } |
| 1124 | |
| 1125 | static void ibmvnic_set_multi(struct net_device *netdev) |
| 1126 | { |
| 1127 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1128 | struct netdev_hw_addr *ha; |
| 1129 | union ibmvnic_crq crq; |
| 1130 | |
| 1131 | memset(&crq, 0, sizeof(crq)); |
| 1132 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 1133 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 1134 | |
| 1135 | if (netdev->flags & IFF_PROMISC) { |
| 1136 | if (!adapter->promisc_supported) |
| 1137 | return; |
| 1138 | } else { |
| 1139 | if (netdev->flags & IFF_ALLMULTI) { |
| 1140 | /* Accept all multicast */ |
| 1141 | memset(&crq, 0, sizeof(crq)); |
| 1142 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1143 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1144 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL; |
| 1145 | ibmvnic_send_crq(adapter, &crq); |
| 1146 | } else if (netdev_mc_empty(netdev)) { |
| 1147 | /* Reject all multicast */ |
| 1148 | memset(&crq, 0, sizeof(crq)); |
| 1149 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1150 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1151 | crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL; |
| 1152 | ibmvnic_send_crq(adapter, &crq); |
| 1153 | } else { |
| 1154 | /* Accept one or more multicast(s) */ |
| 1155 | netdev_for_each_mc_addr(ha, netdev) { |
| 1156 | memset(&crq, 0, sizeof(crq)); |
| 1157 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1158 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1159 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC; |
| 1160 | ether_addr_copy(&crq.multicast_ctrl.mac_addr[0], |
| 1161 | ha->addr); |
| 1162 | ibmvnic_send_crq(adapter, &crq); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | static int ibmvnic_set_mac(struct net_device *netdev, void *p) |
| 1169 | { |
| 1170 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1171 | struct sockaddr *addr = p; |
| 1172 | union ibmvnic_crq crq; |
| 1173 | |
| 1174 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1175 | return -EADDRNOTAVAIL; |
| 1176 | |
| 1177 | memset(&crq, 0, sizeof(crq)); |
| 1178 | crq.change_mac_addr.first = IBMVNIC_CRQ_CMD; |
| 1179 | crq.change_mac_addr.cmd = CHANGE_MAC_ADDR; |
| 1180 | ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data); |
| 1181 | ibmvnic_send_crq(adapter, &crq); |
| 1182 | /* netdev->dev_addr is changed in handle_change_mac_rsp function */ |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1186 | /** |
| 1187 | * do_reset returns zero if we are able to keep processing reset events, or |
| 1188 | * non-zero if we hit a fatal error and must halt. |
| 1189 | */ |
| 1190 | static int do_reset(struct ibmvnic_adapter *adapter, |
| 1191 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 1192 | { |
| 1193 | struct net_device *netdev = adapter->netdev; |
| 1194 | int i, rc; |
| 1195 | |
| 1196 | netif_carrier_off(netdev); |
| 1197 | adapter->reset_reason = rwi->reset_reason; |
| 1198 | |
| 1199 | if (rwi->reset_reason == VNIC_RESET_MOBILITY) { |
| 1200 | rc = ibmvnic_reenable_crq_queue(adapter); |
| 1201 | if (rc) |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | rc = __ibmvnic_close(netdev); |
| 1206 | if (rc) |
| 1207 | return rc; |
| 1208 | |
| 1209 | /* remove the closed state so when we call open it appears |
| 1210 | * we are coming from the probed state. |
| 1211 | */ |
| 1212 | adapter->state = VNIC_PROBED; |
| 1213 | |
| 1214 | release_resources(adapter); |
| 1215 | release_sub_crqs(adapter); |
| 1216 | release_crq_queue(adapter); |
| 1217 | |
| 1218 | rc = ibmvnic_init(adapter); |
| 1219 | if (rc) |
| 1220 | return 0; |
| 1221 | |
| 1222 | /* If the adapter was in PROBE state prior to the reset, exit here. */ |
| 1223 | if (reset_state == VNIC_PROBED) |
| 1224 | return 0; |
| 1225 | |
| 1226 | rc = ibmvnic_login(netdev); |
| 1227 | if (rc) { |
| 1228 | adapter->state = VNIC_PROBED; |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | rtnl_lock(); |
| 1233 | rc = init_resources(adapter); |
| 1234 | rtnl_unlock(); |
| 1235 | if (rc) |
| 1236 | return rc; |
| 1237 | |
| 1238 | if (reset_state == VNIC_CLOSED) |
| 1239 | return 0; |
| 1240 | |
| 1241 | rc = __ibmvnic_open(netdev); |
| 1242 | if (rc) { |
| 1243 | if (list_empty(&adapter->rwi_list)) |
| 1244 | adapter->state = VNIC_CLOSED; |
| 1245 | else |
| 1246 | adapter->state = reset_state; |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | netif_carrier_on(netdev); |
| 1252 | |
| 1253 | /* kick napi */ |
| 1254 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 1255 | napi_schedule(&adapter->napi[i]); |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter) |
| 1261 | { |
| 1262 | struct ibmvnic_rwi *rwi; |
| 1263 | |
| 1264 | mutex_lock(&adapter->rwi_lock); |
| 1265 | |
| 1266 | if (!list_empty(&adapter->rwi_list)) { |
| 1267 | rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi, |
| 1268 | list); |
| 1269 | list_del(&rwi->list); |
| 1270 | } else { |
| 1271 | rwi = NULL; |
| 1272 | } |
| 1273 | |
| 1274 | mutex_unlock(&adapter->rwi_lock); |
| 1275 | return rwi; |
| 1276 | } |
| 1277 | |
| 1278 | static void free_all_rwi(struct ibmvnic_adapter *adapter) |
| 1279 | { |
| 1280 | struct ibmvnic_rwi *rwi; |
| 1281 | |
| 1282 | rwi = get_next_rwi(adapter); |
| 1283 | while (rwi) { |
| 1284 | kfree(rwi); |
| 1285 | rwi = get_next_rwi(adapter); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | static void __ibmvnic_reset(struct work_struct *work) |
| 1290 | { |
| 1291 | struct ibmvnic_rwi *rwi; |
| 1292 | struct ibmvnic_adapter *adapter; |
| 1293 | struct net_device *netdev; |
| 1294 | u32 reset_state; |
| 1295 | int rc; |
| 1296 | |
| 1297 | adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset); |
| 1298 | netdev = adapter->netdev; |
| 1299 | |
| 1300 | mutex_lock(&adapter->reset_lock); |
| 1301 | adapter->resetting = true; |
| 1302 | reset_state = adapter->state; |
| 1303 | |
| 1304 | rwi = get_next_rwi(adapter); |
| 1305 | while (rwi) { |
| 1306 | rc = do_reset(adapter, rwi, reset_state); |
| 1307 | kfree(rwi); |
| 1308 | if (rc) |
| 1309 | break; |
| 1310 | |
| 1311 | rwi = get_next_rwi(adapter); |
| 1312 | } |
| 1313 | |
| 1314 | if (rc) { |
| 1315 | free_all_rwi(adapter); |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | adapter->resetting = false; |
| 1320 | mutex_unlock(&adapter->reset_lock); |
| 1321 | } |
| 1322 | |
| 1323 | static void ibmvnic_reset(struct ibmvnic_adapter *adapter, |
| 1324 | enum ibmvnic_reset_reason reason) |
| 1325 | { |
| 1326 | struct ibmvnic_rwi *rwi, *tmp; |
| 1327 | struct net_device *netdev = adapter->netdev; |
| 1328 | struct list_head *entry; |
| 1329 | |
| 1330 | if (adapter->state == VNIC_REMOVING || |
| 1331 | adapter->state == VNIC_REMOVED) { |
| 1332 | netdev_dbg(netdev, "Adapter removing, skipping reset\n"); |
| 1333 | return; |
| 1334 | } |
| 1335 | |
| 1336 | mutex_lock(&adapter->rwi_lock); |
| 1337 | |
| 1338 | list_for_each(entry, &adapter->rwi_list) { |
| 1339 | tmp = list_entry(entry, struct ibmvnic_rwi, list); |
| 1340 | if (tmp->reset_reason == reason) { |
| 1341 | netdev_err(netdev, "Matching reset found, skipping\n"); |
| 1342 | mutex_unlock(&adapter->rwi_lock); |
| 1343 | return; |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | rwi = kzalloc(sizeof(*rwi), GFP_KERNEL); |
| 1348 | if (!rwi) { |
| 1349 | mutex_unlock(&adapter->rwi_lock); |
| 1350 | ibmvnic_close(netdev); |
| 1351 | return; |
| 1352 | } |
| 1353 | |
| 1354 | rwi->reset_reason = reason; |
| 1355 | list_add_tail(&rwi->list, &adapter->rwi_list); |
| 1356 | mutex_unlock(&adapter->rwi_lock); |
| 1357 | schedule_work(&adapter->ibmvnic_reset); |
| 1358 | } |
| 1359 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1360 | static void ibmvnic_tx_timeout(struct net_device *dev) |
| 1361 | { |
| 1362 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1363 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1364 | ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | static void remove_buff_from_pool(struct ibmvnic_adapter *adapter, |
| 1368 | struct ibmvnic_rx_buff *rx_buff) |
| 1369 | { |
| 1370 | struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index]; |
| 1371 | |
| 1372 | rx_buff->skb = NULL; |
| 1373 | |
| 1374 | pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff); |
| 1375 | pool->next_alloc = (pool->next_alloc + 1) % pool->size; |
| 1376 | |
| 1377 | atomic_dec(&pool->available); |
| 1378 | } |
| 1379 | |
| 1380 | static int ibmvnic_poll(struct napi_struct *napi, int budget) |
| 1381 | { |
| 1382 | struct net_device *netdev = napi->dev; |
| 1383 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1384 | int scrq_num = (int)(napi - adapter->napi); |
| 1385 | int frames_processed = 0; |
| 1386 | restart_poll: |
| 1387 | while (frames_processed < budget) { |
| 1388 | struct sk_buff *skb; |
| 1389 | struct ibmvnic_rx_buff *rx_buff; |
| 1390 | union sub_crq *next; |
| 1391 | u32 length; |
| 1392 | u16 offset; |
| 1393 | u8 flags = 0; |
| 1394 | |
| 1395 | if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num])) |
| 1396 | break; |
| 1397 | next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]); |
| 1398 | rx_buff = |
| 1399 | (struct ibmvnic_rx_buff *)be64_to_cpu(next-> |
| 1400 | rx_comp.correlator); |
| 1401 | /* do error checking */ |
| 1402 | if (next->rx_comp.rc) { |
| 1403 | netdev_err(netdev, "rx error %x\n", next->rx_comp.rc); |
| 1404 | /* free the entry */ |
| 1405 | next->rx_comp.first = 0; |
| 1406 | remove_buff_from_pool(adapter, rx_buff); |
Nathan Fontenot | ca05e31 | 2017-05-03 14:05:14 -0400 | [diff] [blame] | 1407 | continue; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | length = be32_to_cpu(next->rx_comp.len); |
| 1411 | offset = be16_to_cpu(next->rx_comp.off_frame_data); |
| 1412 | flags = next->rx_comp.flags; |
| 1413 | skb = rx_buff->skb; |
| 1414 | skb_copy_to_linear_data(skb, rx_buff->data + offset, |
| 1415 | length); |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 1416 | |
| 1417 | /* VLAN Header has been stripped by the system firmware and |
| 1418 | * needs to be inserted by the driver |
| 1419 | */ |
| 1420 | if (adapter->rx_vlan_header_insertion && |
| 1421 | (flags & IBMVNIC_VLAN_STRIPPED)) |
| 1422 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 1423 | ntohs(next->rx_comp.vlan_tci)); |
| 1424 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1425 | /* free the entry */ |
| 1426 | next->rx_comp.first = 0; |
| 1427 | remove_buff_from_pool(adapter, rx_buff); |
| 1428 | |
| 1429 | skb_put(skb, length); |
| 1430 | skb->protocol = eth_type_trans(skb, netdev); |
Thomas Falcon | 94ca305 | 2017-05-03 14:05:20 -0400 | [diff] [blame] | 1431 | skb_record_rx_queue(skb, scrq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1432 | |
| 1433 | if (flags & IBMVNIC_IP_CHKSUM_GOOD && |
| 1434 | flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) { |
| 1435 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1436 | } |
| 1437 | |
| 1438 | length = skb->len; |
| 1439 | napi_gro_receive(napi, skb); /* send it up */ |
| 1440 | netdev->stats.rx_packets++; |
| 1441 | netdev->stats.rx_bytes += length; |
| 1442 | frames_processed++; |
| 1443 | } |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 1444 | replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1445 | |
| 1446 | if (frames_processed < budget) { |
| 1447 | enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]); |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 1448 | napi_complete_done(napi, frames_processed); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1449 | if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) && |
| 1450 | napi_reschedule(napi)) { |
| 1451 | disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]); |
| 1452 | goto restart_poll; |
| 1453 | } |
| 1454 | } |
| 1455 | return frames_processed; |
| 1456 | } |
| 1457 | |
| 1458 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1459 | static void ibmvnic_netpoll_controller(struct net_device *dev) |
| 1460 | { |
| 1461 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 1462 | int i; |
| 1463 | |
| 1464 | replenish_pools(netdev_priv(dev)); |
| 1465 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 1466 | ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq, |
| 1467 | adapter->rx_scrq[i]); |
| 1468 | } |
| 1469 | #endif |
| 1470 | |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame^] | 1471 | static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu) |
| 1472 | { |
| 1473 | return -EOPNOTSUPP; |
| 1474 | } |
| 1475 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1476 | static const struct net_device_ops ibmvnic_netdev_ops = { |
| 1477 | .ndo_open = ibmvnic_open, |
| 1478 | .ndo_stop = ibmvnic_close, |
| 1479 | .ndo_start_xmit = ibmvnic_xmit, |
| 1480 | .ndo_set_rx_mode = ibmvnic_set_multi, |
| 1481 | .ndo_set_mac_address = ibmvnic_set_mac, |
| 1482 | .ndo_validate_addr = eth_validate_addr, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1483 | .ndo_tx_timeout = ibmvnic_tx_timeout, |
| 1484 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1485 | .ndo_poll_controller = ibmvnic_netpoll_controller, |
| 1486 | #endif |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame^] | 1487 | .ndo_change_mtu = ibmvnic_change_mtu, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1488 | }; |
| 1489 | |
| 1490 | /* ethtool functions */ |
| 1491 | |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 1492 | static int ibmvnic_get_link_ksettings(struct net_device *netdev, |
| 1493 | struct ethtool_link_ksettings *cmd) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1494 | { |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 1495 | u32 supported, advertising; |
| 1496 | |
| 1497 | supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1498 | SUPPORTED_FIBRE); |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 1499 | advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1500 | ADVERTISED_FIBRE); |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 1501 | cmd->base.speed = SPEED_1000; |
| 1502 | cmd->base.duplex = DUPLEX_FULL; |
| 1503 | cmd->base.port = PORT_FIBRE; |
| 1504 | cmd->base.phy_address = 0; |
| 1505 | cmd->base.autoneg = AUTONEG_ENABLE; |
| 1506 | |
| 1507 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 1508 | supported); |
| 1509 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 1510 | advertising); |
| 1511 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | static void ibmvnic_get_drvinfo(struct net_device *dev, |
| 1516 | struct ethtool_drvinfo *info) |
| 1517 | { |
| 1518 | strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver)); |
| 1519 | strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version)); |
| 1520 | } |
| 1521 | |
| 1522 | static u32 ibmvnic_get_msglevel(struct net_device *netdev) |
| 1523 | { |
| 1524 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1525 | |
| 1526 | return adapter->msg_enable; |
| 1527 | } |
| 1528 | |
| 1529 | static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data) |
| 1530 | { |
| 1531 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1532 | |
| 1533 | adapter->msg_enable = data; |
| 1534 | } |
| 1535 | |
| 1536 | static u32 ibmvnic_get_link(struct net_device *netdev) |
| 1537 | { |
| 1538 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1539 | |
| 1540 | /* Don't need to send a query because we request a logical link up at |
| 1541 | * init and then we wait for link state indications |
| 1542 | */ |
| 1543 | return adapter->logical_link_state; |
| 1544 | } |
| 1545 | |
| 1546 | static void ibmvnic_get_ringparam(struct net_device *netdev, |
| 1547 | struct ethtool_ringparam *ring) |
| 1548 | { |
| 1549 | ring->rx_max_pending = 0; |
| 1550 | ring->tx_max_pending = 0; |
| 1551 | ring->rx_mini_max_pending = 0; |
| 1552 | ring->rx_jumbo_max_pending = 0; |
| 1553 | ring->rx_pending = 0; |
| 1554 | ring->tx_pending = 0; |
| 1555 | ring->rx_mini_pending = 0; |
| 1556 | ring->rx_jumbo_pending = 0; |
| 1557 | } |
| 1558 | |
| 1559 | static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1560 | { |
| 1561 | int i; |
| 1562 | |
| 1563 | if (stringset != ETH_SS_STATS) |
| 1564 | return; |
| 1565 | |
| 1566 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN) |
| 1567 | memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN); |
| 1568 | } |
| 1569 | |
| 1570 | static int ibmvnic_get_sset_count(struct net_device *dev, int sset) |
| 1571 | { |
| 1572 | switch (sset) { |
| 1573 | case ETH_SS_STATS: |
| 1574 | return ARRAY_SIZE(ibmvnic_stats); |
| 1575 | default: |
| 1576 | return -EOPNOTSUPP; |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | static void ibmvnic_get_ethtool_stats(struct net_device *dev, |
| 1581 | struct ethtool_stats *stats, u64 *data) |
| 1582 | { |
| 1583 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 1584 | union ibmvnic_crq crq; |
| 1585 | int i; |
| 1586 | |
| 1587 | memset(&crq, 0, sizeof(crq)); |
| 1588 | crq.request_statistics.first = IBMVNIC_CRQ_CMD; |
| 1589 | crq.request_statistics.cmd = REQUEST_STATISTICS; |
| 1590 | crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token); |
| 1591 | crq.request_statistics.len = |
| 1592 | cpu_to_be32(sizeof(struct ibmvnic_statistics)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1593 | |
| 1594 | /* Wait for data to be written */ |
| 1595 | init_completion(&adapter->stats_done); |
Nathan Fontenot | db5d0b5 | 2017-02-10 13:45:05 -0500 | [diff] [blame] | 1596 | ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1597 | wait_for_completion(&adapter->stats_done); |
| 1598 | |
| 1599 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++) |
| 1600 | data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset); |
| 1601 | } |
| 1602 | |
| 1603 | static const struct ethtool_ops ibmvnic_ethtool_ops = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1604 | .get_drvinfo = ibmvnic_get_drvinfo, |
| 1605 | .get_msglevel = ibmvnic_get_msglevel, |
| 1606 | .set_msglevel = ibmvnic_set_msglevel, |
| 1607 | .get_link = ibmvnic_get_link, |
| 1608 | .get_ringparam = ibmvnic_get_ringparam, |
| 1609 | .get_strings = ibmvnic_get_strings, |
| 1610 | .get_sset_count = ibmvnic_get_sset_count, |
| 1611 | .get_ethtool_stats = ibmvnic_get_ethtool_stats, |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 1612 | .get_link_ksettings = ibmvnic_get_link_ksettings, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1613 | }; |
| 1614 | |
| 1615 | /* Routines for managing CRQs/sCRQs */ |
| 1616 | |
| 1617 | static void release_sub_crq_queue(struct ibmvnic_adapter *adapter, |
| 1618 | struct ibmvnic_sub_crq_queue *scrq) |
| 1619 | { |
| 1620 | struct device *dev = &adapter->vdev->dev; |
| 1621 | long rc; |
| 1622 | |
| 1623 | netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n"); |
| 1624 | |
| 1625 | /* Close the sub-crqs */ |
| 1626 | do { |
| 1627 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 1628 | adapter->vdev->unit_address, |
| 1629 | scrq->crq_num); |
| 1630 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 1631 | |
Thomas Falcon | ffa7385 | 2017-04-19 13:44:29 -0400 | [diff] [blame] | 1632 | if (rc) { |
| 1633 | netdev_err(adapter->netdev, |
| 1634 | "Failed to release sub-CRQ %16lx, rc = %ld\n", |
| 1635 | scrq->crq_num, rc); |
| 1636 | } |
| 1637 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1638 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 1639 | DMA_BIDIRECTIONAL); |
| 1640 | free_pages((unsigned long)scrq->msgs, 2); |
| 1641 | kfree(scrq); |
| 1642 | } |
| 1643 | |
| 1644 | static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter |
| 1645 | *adapter) |
| 1646 | { |
| 1647 | struct device *dev = &adapter->vdev->dev; |
| 1648 | struct ibmvnic_sub_crq_queue *scrq; |
| 1649 | int rc; |
| 1650 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 1651 | scrq = kzalloc(sizeof(*scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1652 | if (!scrq) |
| 1653 | return NULL; |
| 1654 | |
Nathan Fontenot | 7f7adc5 | 2017-04-19 13:45:16 -0400 | [diff] [blame] | 1655 | scrq->msgs = |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 1656 | (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1657 | if (!scrq->msgs) { |
| 1658 | dev_warn(dev, "Couldn't allocate crq queue messages page\n"); |
| 1659 | goto zero_page_failed; |
| 1660 | } |
| 1661 | |
| 1662 | scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE, |
| 1663 | DMA_BIDIRECTIONAL); |
| 1664 | if (dma_mapping_error(dev, scrq->msg_token)) { |
| 1665 | dev_warn(dev, "Couldn't map crq queue messages page\n"); |
| 1666 | goto map_failed; |
| 1667 | } |
| 1668 | |
| 1669 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 1670 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 1671 | |
| 1672 | if (rc == H_RESOURCE) |
| 1673 | rc = ibmvnic_reset_crq(adapter); |
| 1674 | |
| 1675 | if (rc == H_CLOSED) { |
| 1676 | dev_warn(dev, "Partner adapter not ready, waiting.\n"); |
| 1677 | } else if (rc) { |
| 1678 | dev_warn(dev, "Error %d registering sub-crq\n", rc); |
| 1679 | goto reg_failed; |
| 1680 | } |
| 1681 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1682 | scrq->adapter = adapter; |
| 1683 | scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1684 | spin_lock_init(&scrq->lock); |
| 1685 | |
| 1686 | netdev_dbg(adapter->netdev, |
| 1687 | "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n", |
| 1688 | scrq->crq_num, scrq->hw_irq, scrq->irq); |
| 1689 | |
| 1690 | return scrq; |
| 1691 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1692 | reg_failed: |
| 1693 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 1694 | DMA_BIDIRECTIONAL); |
| 1695 | map_failed: |
| 1696 | free_pages((unsigned long)scrq->msgs, 2); |
| 1697 | zero_page_failed: |
| 1698 | kfree(scrq); |
| 1699 | |
| 1700 | return NULL; |
| 1701 | } |
| 1702 | |
| 1703 | static void release_sub_crqs(struct ibmvnic_adapter *adapter) |
| 1704 | { |
| 1705 | int i; |
| 1706 | |
| 1707 | if (adapter->tx_scrq) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1708 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 1709 | if (!adapter->tx_scrq[i]) |
| 1710 | continue; |
| 1711 | |
| 1712 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1713 | free_irq(adapter->tx_scrq[i]->irq, |
| 1714 | adapter->tx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 1715 | irq_dispose_mapping(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1716 | adapter->tx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1717 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1718 | |
| 1719 | release_sub_crq_queue(adapter, adapter->tx_scrq[i]); |
| 1720 | } |
| 1721 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 1722 | kfree(adapter->tx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1723 | adapter->tx_scrq = NULL; |
| 1724 | } |
| 1725 | |
| 1726 | if (adapter->rx_scrq) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1727 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 1728 | if (!adapter->rx_scrq[i]) |
| 1729 | continue; |
| 1730 | |
| 1731 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1732 | free_irq(adapter->rx_scrq[i]->irq, |
| 1733 | adapter->rx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 1734 | irq_dispose_mapping(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1735 | adapter->rx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1736 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1737 | |
| 1738 | release_sub_crq_queue(adapter, adapter->rx_scrq[i]); |
| 1739 | } |
| 1740 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 1741 | kfree(adapter->rx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1742 | adapter->rx_scrq = NULL; |
| 1743 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | static int disable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 1747 | struct ibmvnic_sub_crq_queue *scrq) |
| 1748 | { |
| 1749 | struct device *dev = &adapter->vdev->dev; |
| 1750 | unsigned long rc; |
| 1751 | |
| 1752 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 1753 | H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 1754 | if (rc) |
| 1755 | dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n", |
| 1756 | scrq->hw_irq, rc); |
| 1757 | return rc; |
| 1758 | } |
| 1759 | |
| 1760 | static int enable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 1761 | struct ibmvnic_sub_crq_queue *scrq) |
| 1762 | { |
| 1763 | struct device *dev = &adapter->vdev->dev; |
| 1764 | unsigned long rc; |
| 1765 | |
| 1766 | if (scrq->hw_irq > 0x100000000ULL) { |
| 1767 | dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq); |
| 1768 | return 1; |
| 1769 | } |
| 1770 | |
| 1771 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 1772 | H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 1773 | if (rc) |
| 1774 | dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n", |
| 1775 | scrq->hw_irq, rc); |
| 1776 | return rc; |
| 1777 | } |
| 1778 | |
| 1779 | static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter, |
| 1780 | struct ibmvnic_sub_crq_queue *scrq) |
| 1781 | { |
| 1782 | struct device *dev = &adapter->vdev->dev; |
| 1783 | struct ibmvnic_tx_buff *txbuff; |
| 1784 | union sub_crq *next; |
| 1785 | int index; |
| 1786 | int i, j; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1787 | u8 first; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1788 | |
| 1789 | restart_loop: |
| 1790 | while (pending_scrq(adapter, scrq)) { |
| 1791 | unsigned int pool = scrq->pool_index; |
| 1792 | |
| 1793 | next = ibmvnic_next_scrq(adapter, scrq); |
| 1794 | for (i = 0; i < next->tx_comp.num_comps; i++) { |
| 1795 | if (next->tx_comp.rcs[i]) { |
| 1796 | dev_err(dev, "tx error %x\n", |
| 1797 | next->tx_comp.rcs[i]); |
| 1798 | continue; |
| 1799 | } |
| 1800 | index = be32_to_cpu(next->tx_comp.correlators[i]); |
| 1801 | txbuff = &adapter->tx_pool[pool].tx_buff[index]; |
| 1802 | |
| 1803 | for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) { |
| 1804 | if (!txbuff->data_dma[j]) |
| 1805 | continue; |
| 1806 | |
| 1807 | txbuff->data_dma[j] = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1808 | } |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1809 | /* if sub_crq was sent indirectly */ |
| 1810 | first = txbuff->indir_arr[0].generic.first; |
| 1811 | if (first == IBMVNIC_CRQ_CMD) { |
| 1812 | dma_unmap_single(dev, txbuff->indir_dma, |
| 1813 | sizeof(txbuff->indir_arr), |
| 1814 | DMA_TO_DEVICE); |
| 1815 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1816 | |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1817 | if (txbuff->last_frag) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1818 | dev_kfree_skb_any(txbuff->skb); |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 1819 | txbuff->skb = NULL; |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1820 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1821 | |
| 1822 | adapter->tx_pool[pool].free_map[adapter->tx_pool[pool]. |
| 1823 | producer_index] = index; |
| 1824 | adapter->tx_pool[pool].producer_index = |
| 1825 | (adapter->tx_pool[pool].producer_index + 1) % |
Thomas Falcon | 068d9f9 | 2017-03-05 12:18:42 -0600 | [diff] [blame] | 1826 | adapter->req_tx_entries_per_subcrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1827 | } |
| 1828 | /* remove tx_comp scrq*/ |
| 1829 | next->tx_comp.first = 0; |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 1830 | |
| 1831 | if (atomic_sub_return(next->tx_comp.num_comps, &scrq->used) <= |
| 1832 | (adapter->req_tx_entries_per_subcrq / 2) && |
| 1833 | __netif_subqueue_stopped(adapter->netdev, |
| 1834 | scrq->pool_index)) { |
| 1835 | netif_wake_subqueue(adapter->netdev, scrq->pool_index); |
| 1836 | netdev_info(adapter->netdev, "Started queue %d\n", |
| 1837 | scrq->pool_index); |
| 1838 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | enable_scrq_irq(adapter, scrq); |
| 1842 | |
| 1843 | if (pending_scrq(adapter, scrq)) { |
| 1844 | disable_scrq_irq(adapter, scrq); |
| 1845 | goto restart_loop; |
| 1846 | } |
| 1847 | |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
| 1851 | static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance) |
| 1852 | { |
| 1853 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 1854 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 1855 | |
| 1856 | disable_scrq_irq(adapter, scrq); |
| 1857 | ibmvnic_complete_tx(adapter, scrq); |
| 1858 | |
| 1859 | return IRQ_HANDLED; |
| 1860 | } |
| 1861 | |
| 1862 | static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance) |
| 1863 | { |
| 1864 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 1865 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 1866 | |
| 1867 | if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) { |
| 1868 | disable_scrq_irq(adapter, scrq); |
| 1869 | __napi_schedule(&adapter->napi[scrq->scrq_num]); |
| 1870 | } |
| 1871 | |
| 1872 | return IRQ_HANDLED; |
| 1873 | } |
| 1874 | |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1875 | static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter) |
| 1876 | { |
| 1877 | struct device *dev = &adapter->vdev->dev; |
| 1878 | struct ibmvnic_sub_crq_queue *scrq; |
| 1879 | int i = 0, j = 0; |
| 1880 | int rc = 0; |
| 1881 | |
| 1882 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 1883 | scrq = adapter->tx_scrq[i]; |
| 1884 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
| 1885 | |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 1886 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1887 | rc = -EINVAL; |
| 1888 | dev_err(dev, "Error mapping irq\n"); |
| 1889 | goto req_tx_irq_failed; |
| 1890 | } |
| 1891 | |
| 1892 | rc = request_irq(scrq->irq, ibmvnic_interrupt_tx, |
| 1893 | 0, "ibmvnic_tx", scrq); |
| 1894 | |
| 1895 | if (rc) { |
| 1896 | dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n", |
| 1897 | scrq->irq, rc); |
| 1898 | irq_dispose_mapping(scrq->irq); |
| 1899 | goto req_rx_irq_failed; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 1904 | scrq = adapter->rx_scrq[i]; |
| 1905 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 1906 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1907 | rc = -EINVAL; |
| 1908 | dev_err(dev, "Error mapping irq\n"); |
| 1909 | goto req_rx_irq_failed; |
| 1910 | } |
| 1911 | rc = request_irq(scrq->irq, ibmvnic_interrupt_rx, |
| 1912 | 0, "ibmvnic_rx", scrq); |
| 1913 | if (rc) { |
| 1914 | dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n", |
| 1915 | scrq->irq, rc); |
| 1916 | irq_dispose_mapping(scrq->irq); |
| 1917 | goto req_rx_irq_failed; |
| 1918 | } |
| 1919 | } |
| 1920 | return rc; |
| 1921 | |
| 1922 | req_rx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 1923 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1924 | free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]); |
| 1925 | irq_dispose_mapping(adapter->rx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 1926 | } |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1927 | i = adapter->req_tx_queues; |
| 1928 | req_tx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 1929 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1930 | free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]); |
| 1931 | irq_dispose_mapping(adapter->rx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 1932 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 1933 | release_sub_crqs(adapter); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1934 | return rc; |
| 1935 | } |
| 1936 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 1937 | static int init_sub_crqs(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1938 | { |
| 1939 | struct device *dev = &adapter->vdev->dev; |
| 1940 | struct ibmvnic_sub_crq_queue **allqueues; |
| 1941 | int registered_queues = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1942 | int total_queues; |
| 1943 | int more = 0; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 1944 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1945 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1946 | total_queues = adapter->req_tx_queues + adapter->req_rx_queues; |
| 1947 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 1948 | allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1949 | if (!allqueues) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 1950 | return -1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1951 | |
| 1952 | for (i = 0; i < total_queues; i++) { |
| 1953 | allqueues[i] = init_sub_crq_queue(adapter); |
| 1954 | if (!allqueues[i]) { |
| 1955 | dev_warn(dev, "Couldn't allocate all sub-crqs\n"); |
| 1956 | break; |
| 1957 | } |
| 1958 | registered_queues++; |
| 1959 | } |
| 1960 | |
| 1961 | /* Make sure we were able to register the minimum number of queues */ |
| 1962 | if (registered_queues < |
| 1963 | adapter->min_tx_queues + adapter->min_rx_queues) { |
| 1964 | dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n"); |
| 1965 | goto tx_failed; |
| 1966 | } |
| 1967 | |
| 1968 | /* Distribute the failed allocated queues*/ |
| 1969 | for (i = 0; i < total_queues - registered_queues + more ; i++) { |
| 1970 | netdev_dbg(adapter->netdev, "Reducing number of queues\n"); |
| 1971 | switch (i % 3) { |
| 1972 | case 0: |
| 1973 | if (adapter->req_rx_queues > adapter->min_rx_queues) |
| 1974 | adapter->req_rx_queues--; |
| 1975 | else |
| 1976 | more++; |
| 1977 | break; |
| 1978 | case 1: |
| 1979 | if (adapter->req_tx_queues > adapter->min_tx_queues) |
| 1980 | adapter->req_tx_queues--; |
| 1981 | else |
| 1982 | more++; |
| 1983 | break; |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | adapter->tx_scrq = kcalloc(adapter->req_tx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 1988 | sizeof(*adapter->tx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1989 | if (!adapter->tx_scrq) |
| 1990 | goto tx_failed; |
| 1991 | |
| 1992 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 1993 | adapter->tx_scrq[i] = allqueues[i]; |
| 1994 | adapter->tx_scrq[i]->pool_index = i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | adapter->rx_scrq = kcalloc(adapter->req_rx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 1998 | sizeof(*adapter->rx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1999 | if (!adapter->rx_scrq) |
| 2000 | goto rx_failed; |
| 2001 | |
| 2002 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 2003 | adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues]; |
| 2004 | adapter->rx_scrq[i]->scrq_num = i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2005 | } |
| 2006 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 2007 | kfree(allqueues); |
| 2008 | return 0; |
| 2009 | |
| 2010 | rx_failed: |
| 2011 | kfree(adapter->tx_scrq); |
| 2012 | adapter->tx_scrq = NULL; |
| 2013 | tx_failed: |
| 2014 | for (i = 0; i < registered_queues; i++) |
| 2015 | release_sub_crq_queue(adapter, allqueues[i]); |
| 2016 | kfree(allqueues); |
| 2017 | return -1; |
| 2018 | } |
| 2019 | |
| 2020 | static void ibmvnic_send_req_caps(struct ibmvnic_adapter *adapter, int retry) |
| 2021 | { |
| 2022 | struct device *dev = &adapter->vdev->dev; |
| 2023 | union ibmvnic_crq crq; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 2024 | |
| 2025 | if (!retry) { |
| 2026 | /* Sub-CRQ entries are 32 byte long */ |
| 2027 | int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4); |
| 2028 | |
| 2029 | if (adapter->min_tx_entries_per_subcrq > entries_page || |
| 2030 | adapter->min_rx_add_entries_per_subcrq > entries_page) { |
| 2031 | dev_err(dev, "Fatal, invalid entries per sub-crq\n"); |
| 2032 | return; |
| 2033 | } |
| 2034 | |
| 2035 | /* Get the minimum between the queried max and the entries |
| 2036 | * that fit in our PAGE_SIZE |
| 2037 | */ |
| 2038 | adapter->req_tx_entries_per_subcrq = |
| 2039 | adapter->max_tx_entries_per_subcrq > entries_page ? |
| 2040 | entries_page : adapter->max_tx_entries_per_subcrq; |
| 2041 | adapter->req_rx_add_entries_per_subcrq = |
| 2042 | adapter->max_rx_add_entries_per_subcrq > entries_page ? |
| 2043 | entries_page : adapter->max_rx_add_entries_per_subcrq; |
| 2044 | |
| 2045 | adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues; |
| 2046 | adapter->req_rx_queues = adapter->opt_rx_comp_queues; |
| 2047 | adapter->req_rx_add_queues = adapter->max_rx_add_queues; |
| 2048 | |
| 2049 | adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN; |
| 2050 | } |
| 2051 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2052 | memset(&crq, 0, sizeof(crq)); |
| 2053 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 2054 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 2055 | |
| 2056 | crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2057 | crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2058 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2059 | ibmvnic_send_crq(adapter, &crq); |
| 2060 | |
| 2061 | crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2062 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2063 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2064 | ibmvnic_send_crq(adapter, &crq); |
| 2065 | |
| 2066 | crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2067 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2068 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2069 | ibmvnic_send_crq(adapter, &crq); |
| 2070 | |
| 2071 | crq.request_capability.capability = |
| 2072 | cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ); |
| 2073 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2074 | cpu_to_be64(adapter->req_tx_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2075 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2076 | ibmvnic_send_crq(adapter, &crq); |
| 2077 | |
| 2078 | crq.request_capability.capability = |
| 2079 | cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ); |
| 2080 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2081 | cpu_to_be64(adapter->req_rx_add_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2082 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2083 | ibmvnic_send_crq(adapter, &crq); |
| 2084 | |
| 2085 | crq.request_capability.capability = cpu_to_be16(REQ_MTU); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2086 | crq.request_capability.number = cpu_to_be64(adapter->req_mtu); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2087 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2088 | ibmvnic_send_crq(adapter, &crq); |
| 2089 | |
| 2090 | if (adapter->netdev->flags & IFF_PROMISC) { |
| 2091 | if (adapter->promisc_supported) { |
| 2092 | crq.request_capability.capability = |
| 2093 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2094 | crq.request_capability.number = cpu_to_be64(1); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2095 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2096 | ibmvnic_send_crq(adapter, &crq); |
| 2097 | } |
| 2098 | } else { |
| 2099 | crq.request_capability.capability = |
| 2100 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2101 | crq.request_capability.number = cpu_to_be64(0); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2102 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2103 | ibmvnic_send_crq(adapter, &crq); |
| 2104 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | static int pending_scrq(struct ibmvnic_adapter *adapter, |
| 2108 | struct ibmvnic_sub_crq_queue *scrq) |
| 2109 | { |
| 2110 | union sub_crq *entry = &scrq->msgs[scrq->cur]; |
| 2111 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 2112 | if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP || |
| 2113 | adapter->state == VNIC_CLOSING) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2114 | return 1; |
| 2115 | else |
| 2116 | return 0; |
| 2117 | } |
| 2118 | |
| 2119 | static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter, |
| 2120 | struct ibmvnic_sub_crq_queue *scrq) |
| 2121 | { |
| 2122 | union sub_crq *entry; |
| 2123 | unsigned long flags; |
| 2124 | |
| 2125 | spin_lock_irqsave(&scrq->lock, flags); |
| 2126 | entry = &scrq->msgs[scrq->cur]; |
| 2127 | if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 2128 | if (++scrq->cur == scrq->size) |
| 2129 | scrq->cur = 0; |
| 2130 | } else { |
| 2131 | entry = NULL; |
| 2132 | } |
| 2133 | spin_unlock_irqrestore(&scrq->lock, flags); |
| 2134 | |
| 2135 | return entry; |
| 2136 | } |
| 2137 | |
| 2138 | static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter) |
| 2139 | { |
| 2140 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
| 2141 | union ibmvnic_crq *crq; |
| 2142 | |
| 2143 | crq = &queue->msgs[queue->cur]; |
| 2144 | if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 2145 | if (++queue->cur == queue->size) |
| 2146 | queue->cur = 0; |
| 2147 | } else { |
| 2148 | crq = NULL; |
| 2149 | } |
| 2150 | |
| 2151 | return crq; |
| 2152 | } |
| 2153 | |
| 2154 | static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle, |
| 2155 | union sub_crq *sub_crq) |
| 2156 | { |
| 2157 | unsigned int ua = adapter->vdev->unit_address; |
| 2158 | struct device *dev = &adapter->vdev->dev; |
| 2159 | u64 *u64_crq = (u64 *)sub_crq; |
| 2160 | int rc; |
| 2161 | |
| 2162 | netdev_dbg(adapter->netdev, |
| 2163 | "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n", |
| 2164 | (unsigned long int)cpu_to_be64(remote_handle), |
| 2165 | (unsigned long int)cpu_to_be64(u64_crq[0]), |
| 2166 | (unsigned long int)cpu_to_be64(u64_crq[1]), |
| 2167 | (unsigned long int)cpu_to_be64(u64_crq[2]), |
| 2168 | (unsigned long int)cpu_to_be64(u64_crq[3])); |
| 2169 | |
| 2170 | /* Make sure the hypervisor sees the complete request */ |
| 2171 | mb(); |
| 2172 | |
| 2173 | rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua, |
| 2174 | cpu_to_be64(remote_handle), |
| 2175 | cpu_to_be64(u64_crq[0]), |
| 2176 | cpu_to_be64(u64_crq[1]), |
| 2177 | cpu_to_be64(u64_crq[2]), |
| 2178 | cpu_to_be64(u64_crq[3])); |
| 2179 | |
| 2180 | if (rc) { |
| 2181 | if (rc == H_CLOSED) |
| 2182 | dev_warn(dev, "CRQ Queue closed\n"); |
| 2183 | dev_err(dev, "Send error (rc=%d)\n", rc); |
| 2184 | } |
| 2185 | |
| 2186 | return rc; |
| 2187 | } |
| 2188 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 2189 | static int send_subcrq_indirect(struct ibmvnic_adapter *adapter, |
| 2190 | u64 remote_handle, u64 ioba, u64 num_entries) |
| 2191 | { |
| 2192 | unsigned int ua = adapter->vdev->unit_address; |
| 2193 | struct device *dev = &adapter->vdev->dev; |
| 2194 | int rc; |
| 2195 | |
| 2196 | /* Make sure the hypervisor sees the complete request */ |
| 2197 | mb(); |
| 2198 | rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua, |
| 2199 | cpu_to_be64(remote_handle), |
| 2200 | ioba, num_entries); |
| 2201 | |
| 2202 | if (rc) { |
| 2203 | if (rc == H_CLOSED) |
| 2204 | dev_warn(dev, "CRQ Queue closed\n"); |
| 2205 | dev_err(dev, "Send (indirect) error (rc=%d)\n", rc); |
| 2206 | } |
| 2207 | |
| 2208 | return rc; |
| 2209 | } |
| 2210 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2211 | static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter, |
| 2212 | union ibmvnic_crq *crq) |
| 2213 | { |
| 2214 | unsigned int ua = adapter->vdev->unit_address; |
| 2215 | struct device *dev = &adapter->vdev->dev; |
| 2216 | u64 *u64_crq = (u64 *)crq; |
| 2217 | int rc; |
| 2218 | |
| 2219 | netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n", |
| 2220 | (unsigned long int)cpu_to_be64(u64_crq[0]), |
| 2221 | (unsigned long int)cpu_to_be64(u64_crq[1])); |
| 2222 | |
| 2223 | /* Make sure the hypervisor sees the complete request */ |
| 2224 | mb(); |
| 2225 | |
| 2226 | rc = plpar_hcall_norets(H_SEND_CRQ, ua, |
| 2227 | cpu_to_be64(u64_crq[0]), |
| 2228 | cpu_to_be64(u64_crq[1])); |
| 2229 | |
| 2230 | if (rc) { |
| 2231 | if (rc == H_CLOSED) |
| 2232 | dev_warn(dev, "CRQ Queue closed\n"); |
| 2233 | dev_warn(dev, "Send error (rc=%d)\n", rc); |
| 2234 | } |
| 2235 | |
| 2236 | return rc; |
| 2237 | } |
| 2238 | |
| 2239 | static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter) |
| 2240 | { |
| 2241 | union ibmvnic_crq crq; |
| 2242 | |
| 2243 | memset(&crq, 0, sizeof(crq)); |
| 2244 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 2245 | crq.generic.cmd = IBMVNIC_CRQ_INIT; |
| 2246 | netdev_dbg(adapter->netdev, "Sending CRQ init\n"); |
| 2247 | |
| 2248 | return ibmvnic_send_crq(adapter, &crq); |
| 2249 | } |
| 2250 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2251 | static int send_version_xchg(struct ibmvnic_adapter *adapter) |
| 2252 | { |
| 2253 | union ibmvnic_crq crq; |
| 2254 | |
| 2255 | memset(&crq, 0, sizeof(crq)); |
| 2256 | crq.version_exchange.first = IBMVNIC_CRQ_CMD; |
| 2257 | crq.version_exchange.cmd = VERSION_EXCHANGE; |
| 2258 | crq.version_exchange.version = cpu_to_be16(ibmvnic_version); |
| 2259 | |
| 2260 | return ibmvnic_send_crq(adapter, &crq); |
| 2261 | } |
| 2262 | |
| 2263 | static void send_login(struct ibmvnic_adapter *adapter) |
| 2264 | { |
| 2265 | struct ibmvnic_login_rsp_buffer *login_rsp_buffer; |
| 2266 | struct ibmvnic_login_buffer *login_buffer; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2267 | struct device *dev = &adapter->vdev->dev; |
| 2268 | dma_addr_t rsp_buffer_token; |
| 2269 | dma_addr_t buffer_token; |
| 2270 | size_t rsp_buffer_size; |
| 2271 | union ibmvnic_crq crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2272 | size_t buffer_size; |
| 2273 | __be64 *tx_list_p; |
| 2274 | __be64 *rx_list_p; |
| 2275 | int i; |
| 2276 | |
| 2277 | buffer_size = |
| 2278 | sizeof(struct ibmvnic_login_buffer) + |
| 2279 | sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues); |
| 2280 | |
| 2281 | login_buffer = kmalloc(buffer_size, GFP_ATOMIC); |
| 2282 | if (!login_buffer) |
| 2283 | goto buf_alloc_failed; |
| 2284 | |
| 2285 | buffer_token = dma_map_single(dev, login_buffer, buffer_size, |
| 2286 | DMA_TO_DEVICE); |
| 2287 | if (dma_mapping_error(dev, buffer_token)) { |
| 2288 | dev_err(dev, "Couldn't map login buffer\n"); |
| 2289 | goto buf_map_failed; |
| 2290 | } |
| 2291 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 2292 | rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) + |
| 2293 | sizeof(u64) * adapter->req_tx_queues + |
| 2294 | sizeof(u64) * adapter->req_rx_queues + |
| 2295 | sizeof(u64) * adapter->req_rx_queues + |
| 2296 | sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2297 | |
| 2298 | login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC); |
| 2299 | if (!login_rsp_buffer) |
| 2300 | goto buf_rsp_alloc_failed; |
| 2301 | |
| 2302 | rsp_buffer_token = dma_map_single(dev, login_rsp_buffer, |
| 2303 | rsp_buffer_size, DMA_FROM_DEVICE); |
| 2304 | if (dma_mapping_error(dev, rsp_buffer_token)) { |
| 2305 | dev_err(dev, "Couldn't map login rsp buffer\n"); |
| 2306 | goto buf_rsp_map_failed; |
| 2307 | } |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 2308 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2309 | adapter->login_buf = login_buffer; |
| 2310 | adapter->login_buf_token = buffer_token; |
| 2311 | adapter->login_buf_sz = buffer_size; |
| 2312 | adapter->login_rsp_buf = login_rsp_buffer; |
| 2313 | adapter->login_rsp_buf_token = rsp_buffer_token; |
| 2314 | adapter->login_rsp_buf_sz = rsp_buffer_size; |
| 2315 | |
| 2316 | login_buffer->len = cpu_to_be32(buffer_size); |
| 2317 | login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB); |
| 2318 | login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues); |
| 2319 | login_buffer->off_txcomp_subcrqs = |
| 2320 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer)); |
| 2321 | login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues); |
| 2322 | login_buffer->off_rxcomp_subcrqs = |
| 2323 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer) + |
| 2324 | sizeof(u64) * adapter->req_tx_queues); |
| 2325 | login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token); |
| 2326 | login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size); |
| 2327 | |
| 2328 | tx_list_p = (__be64 *)((char *)login_buffer + |
| 2329 | sizeof(struct ibmvnic_login_buffer)); |
| 2330 | rx_list_p = (__be64 *)((char *)login_buffer + |
| 2331 | sizeof(struct ibmvnic_login_buffer) + |
| 2332 | sizeof(u64) * adapter->req_tx_queues); |
| 2333 | |
| 2334 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 2335 | if (adapter->tx_scrq[i]) { |
| 2336 | tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]-> |
| 2337 | crq_num); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 2342 | if (adapter->rx_scrq[i]) { |
| 2343 | rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]-> |
| 2344 | crq_num); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | netdev_dbg(adapter->netdev, "Login Buffer:\n"); |
| 2349 | for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) { |
| 2350 | netdev_dbg(adapter->netdev, "%016lx\n", |
| 2351 | ((unsigned long int *)(adapter->login_buf))[i]); |
| 2352 | } |
| 2353 | |
| 2354 | memset(&crq, 0, sizeof(crq)); |
| 2355 | crq.login.first = IBMVNIC_CRQ_CMD; |
| 2356 | crq.login.cmd = LOGIN; |
| 2357 | crq.login.ioba = cpu_to_be32(buffer_token); |
| 2358 | crq.login.len = cpu_to_be32(buffer_size); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2359 | ibmvnic_send_crq(adapter, &crq); |
| 2360 | |
| 2361 | return; |
| 2362 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2363 | buf_rsp_map_failed: |
| 2364 | kfree(login_rsp_buffer); |
| 2365 | buf_rsp_alloc_failed: |
| 2366 | dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE); |
| 2367 | buf_map_failed: |
| 2368 | kfree(login_buffer); |
| 2369 | buf_alloc_failed: |
| 2370 | return; |
| 2371 | } |
| 2372 | |
| 2373 | static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr, |
| 2374 | u32 len, u8 map_id) |
| 2375 | { |
| 2376 | union ibmvnic_crq crq; |
| 2377 | |
| 2378 | memset(&crq, 0, sizeof(crq)); |
| 2379 | crq.request_map.first = IBMVNIC_CRQ_CMD; |
| 2380 | crq.request_map.cmd = REQUEST_MAP; |
| 2381 | crq.request_map.map_id = map_id; |
| 2382 | crq.request_map.ioba = cpu_to_be32(addr); |
| 2383 | crq.request_map.len = cpu_to_be32(len); |
| 2384 | ibmvnic_send_crq(adapter, &crq); |
| 2385 | } |
| 2386 | |
| 2387 | static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id) |
| 2388 | { |
| 2389 | union ibmvnic_crq crq; |
| 2390 | |
| 2391 | memset(&crq, 0, sizeof(crq)); |
| 2392 | crq.request_unmap.first = IBMVNIC_CRQ_CMD; |
| 2393 | crq.request_unmap.cmd = REQUEST_UNMAP; |
| 2394 | crq.request_unmap.map_id = map_id; |
| 2395 | ibmvnic_send_crq(adapter, &crq); |
| 2396 | } |
| 2397 | |
| 2398 | static void send_map_query(struct ibmvnic_adapter *adapter) |
| 2399 | { |
| 2400 | union ibmvnic_crq crq; |
| 2401 | |
| 2402 | memset(&crq, 0, sizeof(crq)); |
| 2403 | crq.query_map.first = IBMVNIC_CRQ_CMD; |
| 2404 | crq.query_map.cmd = QUERY_MAP; |
| 2405 | ibmvnic_send_crq(adapter, &crq); |
| 2406 | } |
| 2407 | |
| 2408 | /* Send a series of CRQs requesting various capabilities of the VNIC server */ |
| 2409 | static void send_cap_queries(struct ibmvnic_adapter *adapter) |
| 2410 | { |
| 2411 | union ibmvnic_crq crq; |
| 2412 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2413 | atomic_set(&adapter->running_cap_crqs, 0); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2414 | memset(&crq, 0, sizeof(crq)); |
| 2415 | crq.query_capability.first = IBMVNIC_CRQ_CMD; |
| 2416 | crq.query_capability.cmd = QUERY_CAPABILITY; |
| 2417 | |
| 2418 | crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2419 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2420 | ibmvnic_send_crq(adapter, &crq); |
| 2421 | |
| 2422 | crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2423 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2424 | ibmvnic_send_crq(adapter, &crq); |
| 2425 | |
| 2426 | crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2427 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2428 | ibmvnic_send_crq(adapter, &crq); |
| 2429 | |
| 2430 | crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2431 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2432 | ibmvnic_send_crq(adapter, &crq); |
| 2433 | |
| 2434 | crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2435 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2436 | ibmvnic_send_crq(adapter, &crq); |
| 2437 | |
| 2438 | crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2439 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2440 | ibmvnic_send_crq(adapter, &crq); |
| 2441 | |
| 2442 | crq.query_capability.capability = |
| 2443 | cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2444 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2445 | ibmvnic_send_crq(adapter, &crq); |
| 2446 | |
| 2447 | crq.query_capability.capability = |
| 2448 | cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2449 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2450 | ibmvnic_send_crq(adapter, &crq); |
| 2451 | |
| 2452 | crq.query_capability.capability = |
| 2453 | cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2454 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2455 | ibmvnic_send_crq(adapter, &crq); |
| 2456 | |
| 2457 | crq.query_capability.capability = |
| 2458 | cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2459 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2460 | ibmvnic_send_crq(adapter, &crq); |
| 2461 | |
| 2462 | crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2463 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2464 | ibmvnic_send_crq(adapter, &crq); |
| 2465 | |
| 2466 | crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2467 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2468 | ibmvnic_send_crq(adapter, &crq); |
| 2469 | |
| 2470 | crq.query_capability.capability = cpu_to_be16(MIN_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2471 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2472 | ibmvnic_send_crq(adapter, &crq); |
| 2473 | |
| 2474 | crq.query_capability.capability = cpu_to_be16(MAX_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2475 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2476 | ibmvnic_send_crq(adapter, &crq); |
| 2477 | |
| 2478 | crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2479 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2480 | ibmvnic_send_crq(adapter, &crq); |
| 2481 | |
| 2482 | crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2483 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2484 | ibmvnic_send_crq(adapter, &crq); |
| 2485 | |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 2486 | crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION); |
| 2487 | atomic_inc(&adapter->running_cap_crqs); |
| 2488 | ibmvnic_send_crq(adapter, &crq); |
| 2489 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2490 | crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2491 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2492 | ibmvnic_send_crq(adapter, &crq); |
| 2493 | |
| 2494 | crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2495 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2496 | ibmvnic_send_crq(adapter, &crq); |
| 2497 | |
| 2498 | crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2499 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2500 | ibmvnic_send_crq(adapter, &crq); |
| 2501 | |
| 2502 | crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2503 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2504 | ibmvnic_send_crq(adapter, &crq); |
| 2505 | |
| 2506 | crq.query_capability.capability = |
| 2507 | cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2508 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2509 | ibmvnic_send_crq(adapter, &crq); |
| 2510 | |
| 2511 | crq.query_capability.capability = |
| 2512 | cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2513 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2514 | ibmvnic_send_crq(adapter, &crq); |
| 2515 | |
| 2516 | crq.query_capability.capability = |
| 2517 | cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2518 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2519 | ibmvnic_send_crq(adapter, &crq); |
| 2520 | |
| 2521 | crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2522 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2523 | ibmvnic_send_crq(adapter, &crq); |
| 2524 | } |
| 2525 | |
| 2526 | static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter) |
| 2527 | { |
| 2528 | struct device *dev = &adapter->vdev->dev; |
| 2529 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
| 2530 | union ibmvnic_crq crq; |
| 2531 | int i; |
| 2532 | |
| 2533 | dma_unmap_single(dev, adapter->ip_offload_tok, |
| 2534 | sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE); |
| 2535 | |
| 2536 | netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n"); |
| 2537 | for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++) |
| 2538 | netdev_dbg(adapter->netdev, "%016lx\n", |
| 2539 | ((unsigned long int *)(buf))[i]); |
| 2540 | |
| 2541 | netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum); |
| 2542 | netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum); |
| 2543 | netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n", |
| 2544 | buf->tcp_ipv4_chksum); |
| 2545 | netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n", |
| 2546 | buf->tcp_ipv6_chksum); |
| 2547 | netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n", |
| 2548 | buf->udp_ipv4_chksum); |
| 2549 | netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n", |
| 2550 | buf->udp_ipv6_chksum); |
| 2551 | netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n", |
| 2552 | buf->large_tx_ipv4); |
| 2553 | netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n", |
| 2554 | buf->large_tx_ipv6); |
| 2555 | netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n", |
| 2556 | buf->large_rx_ipv4); |
| 2557 | netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n", |
| 2558 | buf->large_rx_ipv6); |
| 2559 | netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n", |
| 2560 | buf->max_ipv4_header_size); |
| 2561 | netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n", |
| 2562 | buf->max_ipv6_header_size); |
| 2563 | netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n", |
| 2564 | buf->max_tcp_header_size); |
| 2565 | netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n", |
| 2566 | buf->max_udp_header_size); |
| 2567 | netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n", |
| 2568 | buf->max_large_tx_size); |
| 2569 | netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n", |
| 2570 | buf->max_large_rx_size); |
| 2571 | netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n", |
| 2572 | buf->ipv6_extension_header); |
| 2573 | netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n", |
| 2574 | buf->tcp_pseudosum_req); |
| 2575 | netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n", |
| 2576 | buf->num_ipv6_ext_headers); |
| 2577 | netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n", |
| 2578 | buf->off_ipv6_ext_headers); |
| 2579 | |
| 2580 | adapter->ip_offload_ctrl_tok = |
| 2581 | dma_map_single(dev, &adapter->ip_offload_ctrl, |
| 2582 | sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE); |
| 2583 | |
| 2584 | if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) { |
| 2585 | dev_err(dev, "Couldn't map ip offload control buffer\n"); |
| 2586 | return; |
| 2587 | } |
| 2588 | |
| 2589 | adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB); |
| 2590 | adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum; |
| 2591 | adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum; |
| 2592 | adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum; |
| 2593 | adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum; |
| 2594 | |
| 2595 | /* large_tx/rx disabled for now, additional features needed */ |
| 2596 | adapter->ip_offload_ctrl.large_tx_ipv4 = 0; |
| 2597 | adapter->ip_offload_ctrl.large_tx_ipv6 = 0; |
| 2598 | adapter->ip_offload_ctrl.large_rx_ipv4 = 0; |
| 2599 | adapter->ip_offload_ctrl.large_rx_ipv6 = 0; |
| 2600 | |
| 2601 | adapter->netdev->features = NETIF_F_GSO; |
| 2602 | |
| 2603 | if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum) |
| 2604 | adapter->netdev->features |= NETIF_F_IP_CSUM; |
| 2605 | |
| 2606 | if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum) |
| 2607 | adapter->netdev->features |= NETIF_F_IPV6_CSUM; |
| 2608 | |
Thomas Falcon | 9be02cd | 2016-04-01 17:20:35 -0500 | [diff] [blame] | 2609 | if ((adapter->netdev->features & |
| 2610 | (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))) |
| 2611 | adapter->netdev->features |= NETIF_F_RXCSUM; |
| 2612 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2613 | memset(&crq, 0, sizeof(crq)); |
| 2614 | crq.control_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 2615 | crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD; |
| 2616 | crq.control_ip_offload.len = |
| 2617 | cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 2618 | crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok); |
| 2619 | ibmvnic_send_crq(adapter, &crq); |
| 2620 | } |
| 2621 | |
| 2622 | static void handle_error_info_rsp(union ibmvnic_crq *crq, |
| 2623 | struct ibmvnic_adapter *adapter) |
| 2624 | { |
| 2625 | struct device *dev = &adapter->vdev->dev; |
Wei Yongjun | 9618318 | 2016-06-27 20:48:53 +0800 | [diff] [blame] | 2626 | struct ibmvnic_error_buff *error_buff, *tmp; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2627 | unsigned long flags; |
| 2628 | bool found = false; |
| 2629 | int i; |
| 2630 | |
| 2631 | if (!crq->request_error_rsp.rc.code) { |
| 2632 | dev_info(dev, "Request Error Rsp returned with rc=%x\n", |
| 2633 | crq->request_error_rsp.rc.code); |
| 2634 | return; |
| 2635 | } |
| 2636 | |
| 2637 | spin_lock_irqsave(&adapter->error_list_lock, flags); |
Wei Yongjun | 9618318 | 2016-06-27 20:48:53 +0800 | [diff] [blame] | 2638 | list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2639 | if (error_buff->error_id == crq->request_error_rsp.error_id) { |
| 2640 | found = true; |
| 2641 | list_del(&error_buff->list); |
| 2642 | break; |
| 2643 | } |
| 2644 | spin_unlock_irqrestore(&adapter->error_list_lock, flags); |
| 2645 | |
| 2646 | if (!found) { |
| 2647 | dev_err(dev, "Couldn't find error id %x\n", |
Thomas Falcon | 75224c9 | 2017-02-15 10:33:33 -0600 | [diff] [blame] | 2648 | be32_to_cpu(crq->request_error_rsp.error_id)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2649 | return; |
| 2650 | } |
| 2651 | |
| 2652 | dev_err(dev, "Detailed info for error id %x:", |
Thomas Falcon | 75224c9 | 2017-02-15 10:33:33 -0600 | [diff] [blame] | 2653 | be32_to_cpu(crq->request_error_rsp.error_id)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2654 | |
| 2655 | for (i = 0; i < error_buff->len; i++) { |
| 2656 | pr_cont("%02x", (int)error_buff->buff[i]); |
| 2657 | if (i % 8 == 7) |
| 2658 | pr_cont(" "); |
| 2659 | } |
| 2660 | pr_cont("\n"); |
| 2661 | |
| 2662 | dma_unmap_single(dev, error_buff->dma, error_buff->len, |
| 2663 | DMA_FROM_DEVICE); |
| 2664 | kfree(error_buff->buff); |
| 2665 | kfree(error_buff); |
| 2666 | } |
| 2667 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2668 | static void request_error_information(struct ibmvnic_adapter *adapter, |
| 2669 | union ibmvnic_crq *err_crq) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2670 | { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2671 | struct device *dev = &adapter->vdev->dev; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2672 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2673 | struct ibmvnic_error_buff *error_buff; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2674 | unsigned long timeout = msecs_to_jiffies(30000); |
| 2675 | union ibmvnic_crq crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2676 | unsigned long flags; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2677 | int rc, detail_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2678 | |
| 2679 | error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC); |
| 2680 | if (!error_buff) |
| 2681 | return; |
| 2682 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2683 | detail_len = be32_to_cpu(err_crq->error_indication.detail_error_sz); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2684 | error_buff->buff = kmalloc(detail_len, GFP_ATOMIC); |
| 2685 | if (!error_buff->buff) { |
| 2686 | kfree(error_buff); |
| 2687 | return; |
| 2688 | } |
| 2689 | |
| 2690 | error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len, |
| 2691 | DMA_FROM_DEVICE); |
| 2692 | if (dma_mapping_error(dev, error_buff->dma)) { |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2693 | netdev_err(netdev, "Couldn't map error buffer\n"); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2694 | kfree(error_buff->buff); |
| 2695 | kfree(error_buff); |
| 2696 | return; |
| 2697 | } |
| 2698 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2699 | error_buff->len = detail_len; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2700 | error_buff->error_id = err_crq->error_indication.error_id; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2701 | |
| 2702 | spin_lock_irqsave(&adapter->error_list_lock, flags); |
| 2703 | list_add_tail(&error_buff->list, &adapter->errors); |
| 2704 | spin_unlock_irqrestore(&adapter->error_list_lock, flags); |
| 2705 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 2706 | memset(&crq, 0, sizeof(crq)); |
| 2707 | crq.request_error_info.first = IBMVNIC_CRQ_CMD; |
| 2708 | crq.request_error_info.cmd = REQUEST_ERROR_INFO; |
| 2709 | crq.request_error_info.ioba = cpu_to_be32(error_buff->dma); |
| 2710 | crq.request_error_info.len = cpu_to_be32(detail_len); |
| 2711 | crq.request_error_info.error_id = err_crq->error_indication.error_id; |
| 2712 | |
| 2713 | rc = ibmvnic_send_crq(adapter, &crq); |
| 2714 | if (rc) { |
| 2715 | netdev_err(netdev, "failed to request error information\n"); |
| 2716 | goto err_info_fail; |
| 2717 | } |
| 2718 | |
| 2719 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 2720 | netdev_err(netdev, "timeout waiting for error information\n"); |
| 2721 | goto err_info_fail; |
| 2722 | } |
| 2723 | |
| 2724 | return; |
| 2725 | |
| 2726 | err_info_fail: |
| 2727 | spin_lock_irqsave(&adapter->error_list_lock, flags); |
| 2728 | list_del(&error_buff->list); |
| 2729 | spin_unlock_irqrestore(&adapter->error_list_lock, flags); |
| 2730 | |
| 2731 | kfree(error_buff->buff); |
| 2732 | kfree(error_buff); |
| 2733 | } |
| 2734 | |
| 2735 | static void handle_error_indication(union ibmvnic_crq *crq, |
| 2736 | struct ibmvnic_adapter *adapter) |
| 2737 | { |
| 2738 | struct device *dev = &adapter->vdev->dev; |
| 2739 | |
| 2740 | dev_err(dev, "Firmware reports %serror id %x, cause %d\n", |
| 2741 | crq->error_indication.flags |
| 2742 | & IBMVNIC_FATAL_ERROR ? "FATAL " : "", |
| 2743 | be32_to_cpu(crq->error_indication.error_id), |
| 2744 | be16_to_cpu(crq->error_indication.error_cause)); |
| 2745 | |
| 2746 | if (be32_to_cpu(crq->error_indication.error_id)) |
| 2747 | request_error_information(adapter, crq); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2748 | |
| 2749 | if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR) |
| 2750 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | static void handle_change_mac_rsp(union ibmvnic_crq *crq, |
| 2754 | struct ibmvnic_adapter *adapter) |
| 2755 | { |
| 2756 | struct net_device *netdev = adapter->netdev; |
| 2757 | struct device *dev = &adapter->vdev->dev; |
| 2758 | long rc; |
| 2759 | |
| 2760 | rc = crq->change_mac_addr_rsp.rc.code; |
| 2761 | if (rc) { |
| 2762 | dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc); |
| 2763 | return; |
| 2764 | } |
| 2765 | memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0], |
| 2766 | ETH_ALEN); |
| 2767 | } |
| 2768 | |
| 2769 | static void handle_request_cap_rsp(union ibmvnic_crq *crq, |
| 2770 | struct ibmvnic_adapter *adapter) |
| 2771 | { |
| 2772 | struct device *dev = &adapter->vdev->dev; |
| 2773 | u64 *req_value; |
| 2774 | char *name; |
| 2775 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2776 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2777 | switch (be16_to_cpu(crq->request_capability_rsp.capability)) { |
| 2778 | case REQ_TX_QUEUES: |
| 2779 | req_value = &adapter->req_tx_queues; |
| 2780 | name = "tx"; |
| 2781 | break; |
| 2782 | case REQ_RX_QUEUES: |
| 2783 | req_value = &adapter->req_rx_queues; |
| 2784 | name = "rx"; |
| 2785 | break; |
| 2786 | case REQ_RX_ADD_QUEUES: |
| 2787 | req_value = &adapter->req_rx_add_queues; |
| 2788 | name = "rx_add"; |
| 2789 | break; |
| 2790 | case REQ_TX_ENTRIES_PER_SUBCRQ: |
| 2791 | req_value = &adapter->req_tx_entries_per_subcrq; |
| 2792 | name = "tx_entries_per_subcrq"; |
| 2793 | break; |
| 2794 | case REQ_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 2795 | req_value = &adapter->req_rx_add_entries_per_subcrq; |
| 2796 | name = "rx_add_entries_per_subcrq"; |
| 2797 | break; |
| 2798 | case REQ_MTU: |
| 2799 | req_value = &adapter->req_mtu; |
| 2800 | name = "mtu"; |
| 2801 | break; |
| 2802 | case PROMISC_REQUESTED: |
| 2803 | req_value = &adapter->promisc; |
| 2804 | name = "promisc"; |
| 2805 | break; |
| 2806 | default: |
| 2807 | dev_err(dev, "Got invalid cap request rsp %d\n", |
| 2808 | crq->request_capability.capability); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
| 2812 | switch (crq->request_capability_rsp.rc.code) { |
| 2813 | case SUCCESS: |
| 2814 | break; |
| 2815 | case PARTIALSUCCESS: |
| 2816 | dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n", |
| 2817 | *req_value, |
Thomas Falcon | 28f4d16 | 2017-02-15 10:32:11 -0600 | [diff] [blame] | 2818 | (long int)be64_to_cpu(crq->request_capability_rsp. |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2819 | number), name); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 2820 | release_sub_crqs(adapter); |
Thomas Falcon | 28f4d16 | 2017-02-15 10:32:11 -0600 | [diff] [blame] | 2821 | *req_value = be64_to_cpu(crq->request_capability_rsp.number); |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 2822 | ibmvnic_send_req_caps(adapter, 1); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2823 | return; |
| 2824 | default: |
| 2825 | dev_err(dev, "Error %d in request cap rsp\n", |
| 2826 | crq->request_capability_rsp.rc.code); |
| 2827 | return; |
| 2828 | } |
| 2829 | |
| 2830 | /* Done receiving requested capabilities, query IP offload support */ |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2831 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2832 | union ibmvnic_crq newcrq; |
| 2833 | int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer); |
| 2834 | struct ibmvnic_query_ip_offload_buffer *ip_offload_buf = |
| 2835 | &adapter->ip_offload_buf; |
| 2836 | |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 2837 | adapter->wait_capability = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2838 | adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf, |
| 2839 | buf_sz, |
| 2840 | DMA_FROM_DEVICE); |
| 2841 | |
| 2842 | if (dma_mapping_error(dev, adapter->ip_offload_tok)) { |
| 2843 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
| 2844 | dev_err(dev, "Couldn't map offload buffer\n"); |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | memset(&newcrq, 0, sizeof(newcrq)); |
| 2849 | newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 2850 | newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD; |
| 2851 | newcrq.query_ip_offload.len = cpu_to_be32(buf_sz); |
| 2852 | newcrq.query_ip_offload.ioba = |
| 2853 | cpu_to_be32(adapter->ip_offload_tok); |
| 2854 | |
| 2855 | ibmvnic_send_crq(adapter, &newcrq); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, |
| 2860 | struct ibmvnic_adapter *adapter) |
| 2861 | { |
| 2862 | struct device *dev = &adapter->vdev->dev; |
| 2863 | struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf; |
| 2864 | struct ibmvnic_login_buffer *login = adapter->login_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2865 | int i; |
| 2866 | |
| 2867 | dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, |
| 2868 | DMA_BIDIRECTIONAL); |
| 2869 | dma_unmap_single(dev, adapter->login_rsp_buf_token, |
| 2870 | adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL); |
| 2871 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 2872 | /* If the number of queues requested can't be allocated by the |
| 2873 | * server, the login response will return with code 1. We will need |
| 2874 | * to resend the login buffer with fewer queues requested. |
| 2875 | */ |
| 2876 | if (login_rsp_crq->generic.rc.code) { |
| 2877 | adapter->renegotiate = true; |
| 2878 | complete(&adapter->init_done); |
| 2879 | return 0; |
| 2880 | } |
| 2881 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2882 | netdev_dbg(adapter->netdev, "Login Response Buffer:\n"); |
| 2883 | for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) { |
| 2884 | netdev_dbg(adapter->netdev, "%016lx\n", |
| 2885 | ((unsigned long int *)(adapter->login_rsp_buf))[i]); |
| 2886 | } |
| 2887 | |
| 2888 | /* Sanity checks */ |
| 2889 | if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs || |
| 2890 | (be32_to_cpu(login->num_rxcomp_subcrqs) * |
| 2891 | adapter->req_rx_add_queues != |
| 2892 | be32_to_cpu(login_rsp->num_rxadd_subcrqs))) { |
| 2893 | dev_err(dev, "FATAL: Inconsistent login and login rsp\n"); |
| 2894 | ibmvnic_remove(adapter->vdev); |
| 2895 | return -EIO; |
| 2896 | } |
| 2897 | complete(&adapter->init_done); |
| 2898 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2899 | return 0; |
| 2900 | } |
| 2901 | |
| 2902 | static void handle_request_map_rsp(union ibmvnic_crq *crq, |
| 2903 | struct ibmvnic_adapter *adapter) |
| 2904 | { |
| 2905 | struct device *dev = &adapter->vdev->dev; |
| 2906 | u8 map_id = crq->request_map_rsp.map_id; |
| 2907 | int tx_subcrqs; |
| 2908 | int rx_subcrqs; |
| 2909 | long rc; |
| 2910 | int i; |
| 2911 | |
| 2912 | tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 2913 | rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 2914 | |
| 2915 | rc = crq->request_map_rsp.rc.code; |
| 2916 | if (rc) { |
| 2917 | dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc); |
| 2918 | adapter->map_id--; |
| 2919 | /* need to find and zero tx/rx_pool map_id */ |
| 2920 | for (i = 0; i < tx_subcrqs; i++) { |
| 2921 | if (adapter->tx_pool[i].long_term_buff.map_id == map_id) |
| 2922 | adapter->tx_pool[i].long_term_buff.map_id = 0; |
| 2923 | } |
| 2924 | for (i = 0; i < rx_subcrqs; i++) { |
| 2925 | if (adapter->rx_pool[i].long_term_buff.map_id == map_id) |
| 2926 | adapter->rx_pool[i].long_term_buff.map_id = 0; |
| 2927 | } |
| 2928 | } |
| 2929 | complete(&adapter->fw_done); |
| 2930 | } |
| 2931 | |
| 2932 | static void handle_request_unmap_rsp(union ibmvnic_crq *crq, |
| 2933 | struct ibmvnic_adapter *adapter) |
| 2934 | { |
| 2935 | struct device *dev = &adapter->vdev->dev; |
| 2936 | long rc; |
| 2937 | |
| 2938 | rc = crq->request_unmap_rsp.rc.code; |
| 2939 | if (rc) |
| 2940 | dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc); |
| 2941 | } |
| 2942 | |
| 2943 | static void handle_query_map_rsp(union ibmvnic_crq *crq, |
| 2944 | struct ibmvnic_adapter *adapter) |
| 2945 | { |
| 2946 | struct net_device *netdev = adapter->netdev; |
| 2947 | struct device *dev = &adapter->vdev->dev; |
| 2948 | long rc; |
| 2949 | |
| 2950 | rc = crq->query_map_rsp.rc.code; |
| 2951 | if (rc) { |
| 2952 | dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc); |
| 2953 | return; |
| 2954 | } |
| 2955 | netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n", |
| 2956 | crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages, |
| 2957 | crq->query_map_rsp.free_pages); |
| 2958 | } |
| 2959 | |
| 2960 | static void handle_query_cap_rsp(union ibmvnic_crq *crq, |
| 2961 | struct ibmvnic_adapter *adapter) |
| 2962 | { |
| 2963 | struct net_device *netdev = adapter->netdev; |
| 2964 | struct device *dev = &adapter->vdev->dev; |
| 2965 | long rc; |
| 2966 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2967 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2968 | netdev_dbg(netdev, "Outstanding queries: %d\n", |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 2969 | atomic_read(&adapter->running_cap_crqs)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2970 | rc = crq->query_capability.rc.code; |
| 2971 | if (rc) { |
| 2972 | dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc); |
| 2973 | goto out; |
| 2974 | } |
| 2975 | |
| 2976 | switch (be16_to_cpu(crq->query_capability.capability)) { |
| 2977 | case MIN_TX_QUEUES: |
| 2978 | adapter->min_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2979 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2980 | netdev_dbg(netdev, "min_tx_queues = %lld\n", |
| 2981 | adapter->min_tx_queues); |
| 2982 | break; |
| 2983 | case MIN_RX_QUEUES: |
| 2984 | adapter->min_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2985 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2986 | netdev_dbg(netdev, "min_rx_queues = %lld\n", |
| 2987 | adapter->min_rx_queues); |
| 2988 | break; |
| 2989 | case MIN_RX_ADD_QUEUES: |
| 2990 | adapter->min_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2991 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2992 | netdev_dbg(netdev, "min_rx_add_queues = %lld\n", |
| 2993 | adapter->min_rx_add_queues); |
| 2994 | break; |
| 2995 | case MAX_TX_QUEUES: |
| 2996 | adapter->max_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 2997 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2998 | netdev_dbg(netdev, "max_tx_queues = %lld\n", |
| 2999 | adapter->max_tx_queues); |
| 3000 | break; |
| 3001 | case MAX_RX_QUEUES: |
| 3002 | adapter->max_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3003 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3004 | netdev_dbg(netdev, "max_rx_queues = %lld\n", |
| 3005 | adapter->max_rx_queues); |
| 3006 | break; |
| 3007 | case MAX_RX_ADD_QUEUES: |
| 3008 | adapter->max_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3009 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3010 | netdev_dbg(netdev, "max_rx_add_queues = %lld\n", |
| 3011 | adapter->max_rx_add_queues); |
| 3012 | break; |
| 3013 | case MIN_TX_ENTRIES_PER_SUBCRQ: |
| 3014 | adapter->min_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3015 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3016 | netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n", |
| 3017 | adapter->min_tx_entries_per_subcrq); |
| 3018 | break; |
| 3019 | case MIN_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 3020 | adapter->min_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3021 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3022 | netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n", |
| 3023 | adapter->min_rx_add_entries_per_subcrq); |
| 3024 | break; |
| 3025 | case MAX_TX_ENTRIES_PER_SUBCRQ: |
| 3026 | adapter->max_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3027 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3028 | netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n", |
| 3029 | adapter->max_tx_entries_per_subcrq); |
| 3030 | break; |
| 3031 | case MAX_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 3032 | adapter->max_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3033 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3034 | netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n", |
| 3035 | adapter->max_rx_add_entries_per_subcrq); |
| 3036 | break; |
| 3037 | case TCP_IP_OFFLOAD: |
| 3038 | adapter->tcp_ip_offload = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3039 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3040 | netdev_dbg(netdev, "tcp_ip_offload = %lld\n", |
| 3041 | adapter->tcp_ip_offload); |
| 3042 | break; |
| 3043 | case PROMISC_SUPPORTED: |
| 3044 | adapter->promisc_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3045 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3046 | netdev_dbg(netdev, "promisc_supported = %lld\n", |
| 3047 | adapter->promisc_supported); |
| 3048 | break; |
| 3049 | case MIN_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3050 | adapter->min_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 3051 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3052 | netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu); |
| 3053 | break; |
| 3054 | case MAX_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3055 | adapter->max_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 3056 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3057 | netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu); |
| 3058 | break; |
| 3059 | case MAX_MULTICAST_FILTERS: |
| 3060 | adapter->max_multicast_filters = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3061 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3062 | netdev_dbg(netdev, "max_multicast_filters = %lld\n", |
| 3063 | adapter->max_multicast_filters); |
| 3064 | break; |
| 3065 | case VLAN_HEADER_INSERTION: |
| 3066 | adapter->vlan_header_insertion = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3067 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3068 | if (adapter->vlan_header_insertion) |
| 3069 | netdev->features |= NETIF_F_HW_VLAN_STAG_TX; |
| 3070 | netdev_dbg(netdev, "vlan_header_insertion = %lld\n", |
| 3071 | adapter->vlan_header_insertion); |
| 3072 | break; |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 3073 | case RX_VLAN_HEADER_INSERTION: |
| 3074 | adapter->rx_vlan_header_insertion = |
| 3075 | be64_to_cpu(crq->query_capability.number); |
| 3076 | netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n", |
| 3077 | adapter->rx_vlan_header_insertion); |
| 3078 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3079 | case MAX_TX_SG_ENTRIES: |
| 3080 | adapter->max_tx_sg_entries = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3081 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3082 | netdev_dbg(netdev, "max_tx_sg_entries = %lld\n", |
| 3083 | adapter->max_tx_sg_entries); |
| 3084 | break; |
| 3085 | case RX_SG_SUPPORTED: |
| 3086 | adapter->rx_sg_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3087 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3088 | netdev_dbg(netdev, "rx_sg_supported = %lld\n", |
| 3089 | adapter->rx_sg_supported); |
| 3090 | break; |
| 3091 | case OPT_TX_COMP_SUB_QUEUES: |
| 3092 | adapter->opt_tx_comp_sub_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3093 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3094 | netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n", |
| 3095 | adapter->opt_tx_comp_sub_queues); |
| 3096 | break; |
| 3097 | case OPT_RX_COMP_QUEUES: |
| 3098 | adapter->opt_rx_comp_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3099 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3100 | netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n", |
| 3101 | adapter->opt_rx_comp_queues); |
| 3102 | break; |
| 3103 | case OPT_RX_BUFADD_Q_PER_RX_COMP_Q: |
| 3104 | adapter->opt_rx_bufadd_q_per_rx_comp_q = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3105 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3106 | netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n", |
| 3107 | adapter->opt_rx_bufadd_q_per_rx_comp_q); |
| 3108 | break; |
| 3109 | case OPT_TX_ENTRIES_PER_SUBCRQ: |
| 3110 | adapter->opt_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3111 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3112 | netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n", |
| 3113 | adapter->opt_tx_entries_per_subcrq); |
| 3114 | break; |
| 3115 | case OPT_RXBA_ENTRIES_PER_SUBCRQ: |
| 3116 | adapter->opt_rxba_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3117 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3118 | netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n", |
| 3119 | adapter->opt_rxba_entries_per_subcrq); |
| 3120 | break; |
| 3121 | case TX_RX_DESC_REQ: |
| 3122 | adapter->tx_rx_desc_req = crq->query_capability.number; |
| 3123 | netdev_dbg(netdev, "tx_rx_desc_req = %llx\n", |
| 3124 | adapter->tx_rx_desc_req); |
| 3125 | break; |
| 3126 | |
| 3127 | default: |
| 3128 | netdev_err(netdev, "Got invalid cap rsp %d\n", |
| 3129 | crq->query_capability.capability); |
| 3130 | } |
| 3131 | |
| 3132 | out: |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 3133 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
| 3134 | adapter->wait_capability = false; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3135 | ibmvnic_send_req_caps(adapter, 0); |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 3136 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3137 | } |
| 3138 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3139 | static void ibmvnic_handle_crq(union ibmvnic_crq *crq, |
| 3140 | struct ibmvnic_adapter *adapter) |
| 3141 | { |
| 3142 | struct ibmvnic_generic_crq *gen_crq = &crq->generic; |
| 3143 | struct net_device *netdev = adapter->netdev; |
| 3144 | struct device *dev = &adapter->vdev->dev; |
Murilo Fossa Vicentini | 993a82b | 2017-04-19 13:44:35 -0400 | [diff] [blame] | 3145 | u64 *u64_crq = (u64 *)crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3146 | long rc; |
| 3147 | |
| 3148 | netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n", |
Murilo Fossa Vicentini | 993a82b | 2017-04-19 13:44:35 -0400 | [diff] [blame] | 3149 | (unsigned long int)cpu_to_be64(u64_crq[0]), |
| 3150 | (unsigned long int)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3151 | switch (gen_crq->first) { |
| 3152 | case IBMVNIC_CRQ_INIT_RSP: |
| 3153 | switch (gen_crq->cmd) { |
| 3154 | case IBMVNIC_CRQ_INIT: |
| 3155 | dev_info(dev, "Partner initialized\n"); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3156 | break; |
| 3157 | case IBMVNIC_CRQ_INIT_COMPLETE: |
| 3158 | dev_info(dev, "Partner initialization complete\n"); |
| 3159 | send_version_xchg(adapter); |
| 3160 | break; |
| 3161 | default: |
| 3162 | dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd); |
| 3163 | } |
| 3164 | return; |
| 3165 | case IBMVNIC_CRQ_XPORT_EVENT: |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3166 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3167 | if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3168 | dev_info(dev, "Migrated, re-enabling adapter\n"); |
| 3169 | ibmvnic_reset(adapter, VNIC_RESET_MOBILITY); |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 3170 | } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { |
| 3171 | dev_info(dev, "Backing device failover detected\n"); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3172 | ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3173 | } else { |
| 3174 | /* The adapter lost the connection */ |
| 3175 | dev_err(dev, "Virtual Adapter failed (rc=%d)\n", |
| 3176 | gen_crq->cmd); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3177 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3178 | } |
| 3179 | return; |
| 3180 | case IBMVNIC_CRQ_CMD_RSP: |
| 3181 | break; |
| 3182 | default: |
| 3183 | dev_err(dev, "Got an invalid msg type 0x%02x\n", |
| 3184 | gen_crq->first); |
| 3185 | return; |
| 3186 | } |
| 3187 | |
| 3188 | switch (gen_crq->cmd) { |
| 3189 | case VERSION_EXCHANGE_RSP: |
| 3190 | rc = crq->version_exchange_rsp.rc.code; |
| 3191 | if (rc) { |
| 3192 | dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc); |
| 3193 | break; |
| 3194 | } |
| 3195 | dev_info(dev, "Partner protocol version is %d\n", |
| 3196 | crq->version_exchange_rsp.version); |
| 3197 | if (be16_to_cpu(crq->version_exchange_rsp.version) < |
| 3198 | ibmvnic_version) |
| 3199 | ibmvnic_version = |
| 3200 | be16_to_cpu(crq->version_exchange_rsp.version); |
| 3201 | send_cap_queries(adapter); |
| 3202 | break; |
| 3203 | case QUERY_CAPABILITY_RSP: |
| 3204 | handle_query_cap_rsp(crq, adapter); |
| 3205 | break; |
| 3206 | case QUERY_MAP_RSP: |
| 3207 | handle_query_map_rsp(crq, adapter); |
| 3208 | break; |
| 3209 | case REQUEST_MAP_RSP: |
| 3210 | handle_request_map_rsp(crq, adapter); |
| 3211 | break; |
| 3212 | case REQUEST_UNMAP_RSP: |
| 3213 | handle_request_unmap_rsp(crq, adapter); |
| 3214 | break; |
| 3215 | case REQUEST_CAPABILITY_RSP: |
| 3216 | handle_request_cap_rsp(crq, adapter); |
| 3217 | break; |
| 3218 | case LOGIN_RSP: |
| 3219 | netdev_dbg(netdev, "Got Login Response\n"); |
| 3220 | handle_login_rsp(crq, adapter); |
| 3221 | break; |
| 3222 | case LOGICAL_LINK_STATE_RSP: |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 3223 | netdev_dbg(netdev, |
| 3224 | "Got Logical Link State Response, state: %d rc: %d\n", |
| 3225 | crq->logical_link_state_rsp.link_state, |
| 3226 | crq->logical_link_state_rsp.rc.code); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3227 | adapter->logical_link_state = |
| 3228 | crq->logical_link_state_rsp.link_state; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 3229 | adapter->init_done_rc = crq->logical_link_state_rsp.rc.code; |
| 3230 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3231 | break; |
| 3232 | case LINK_STATE_INDICATION: |
| 3233 | netdev_dbg(netdev, "Got Logical Link State Indication\n"); |
| 3234 | adapter->phys_link_state = |
| 3235 | crq->link_state_indication.phys_link_state; |
| 3236 | adapter->logical_link_state = |
| 3237 | crq->link_state_indication.logical_link_state; |
| 3238 | break; |
| 3239 | case CHANGE_MAC_ADDR_RSP: |
| 3240 | netdev_dbg(netdev, "Got MAC address change Response\n"); |
| 3241 | handle_change_mac_rsp(crq, adapter); |
| 3242 | break; |
| 3243 | case ERROR_INDICATION: |
| 3244 | netdev_dbg(netdev, "Got Error Indication\n"); |
| 3245 | handle_error_indication(crq, adapter); |
| 3246 | break; |
| 3247 | case REQUEST_ERROR_RSP: |
| 3248 | netdev_dbg(netdev, "Got Error Detail Response\n"); |
| 3249 | handle_error_info_rsp(crq, adapter); |
| 3250 | break; |
| 3251 | case REQUEST_STATISTICS_RSP: |
| 3252 | netdev_dbg(netdev, "Got Statistics Response\n"); |
| 3253 | complete(&adapter->stats_done); |
| 3254 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3255 | case QUERY_IP_OFFLOAD_RSP: |
| 3256 | netdev_dbg(netdev, "Got Query IP offload Response\n"); |
| 3257 | handle_query_ip_offload_rsp(adapter); |
| 3258 | break; |
| 3259 | case MULTICAST_CTRL_RSP: |
| 3260 | netdev_dbg(netdev, "Got multicast control Response\n"); |
| 3261 | break; |
| 3262 | case CONTROL_IP_OFFLOAD_RSP: |
| 3263 | netdev_dbg(netdev, "Got Control IP offload Response\n"); |
| 3264 | dma_unmap_single(dev, adapter->ip_offload_ctrl_tok, |
| 3265 | sizeof(adapter->ip_offload_ctrl), |
| 3266 | DMA_TO_DEVICE); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 3267 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3268 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3269 | case COLLECT_FW_TRACE_RSP: |
| 3270 | netdev_dbg(netdev, "Got Collect firmware trace Response\n"); |
| 3271 | complete(&adapter->fw_done); |
| 3272 | break; |
| 3273 | default: |
| 3274 | netdev_err(netdev, "Got an invalid cmd type 0x%02x\n", |
| 3275 | gen_crq->cmd); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | static irqreturn_t ibmvnic_interrupt(int irq, void *instance) |
| 3280 | { |
| 3281 | struct ibmvnic_adapter *adapter = instance; |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3282 | |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3283 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3284 | return IRQ_HANDLED; |
| 3285 | } |
| 3286 | |
| 3287 | static void ibmvnic_tasklet(void *data) |
| 3288 | { |
| 3289 | struct ibmvnic_adapter *adapter = data; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3290 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3291 | union ibmvnic_crq *crq; |
| 3292 | unsigned long flags; |
| 3293 | bool done = false; |
| 3294 | |
| 3295 | spin_lock_irqsave(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3296 | while (!done) { |
| 3297 | /* Pull all the valid messages off the CRQ */ |
| 3298 | while ((crq = ibmvnic_next_crq(adapter)) != NULL) { |
| 3299 | ibmvnic_handle_crq(crq, adapter); |
| 3300 | crq->generic.first = 0; |
| 3301 | } |
Brian King | ed7ecbf | 2017-04-19 13:44:53 -0400 | [diff] [blame] | 3302 | |
| 3303 | /* remain in tasklet until all |
| 3304 | * capabilities responses are received |
| 3305 | */ |
| 3306 | if (!adapter->wait_capability) |
| 3307 | done = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3308 | } |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 3309 | /* if capabilities CRQ's were sent in this tasklet, the following |
| 3310 | * tasklet must wait until all responses are received |
| 3311 | */ |
| 3312 | if (atomic_read(&adapter->running_cap_crqs) != 0) |
| 3313 | adapter->wait_capability = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3314 | spin_unlock_irqrestore(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter) |
| 3318 | { |
| 3319 | struct vio_dev *vdev = adapter->vdev; |
| 3320 | int rc; |
| 3321 | |
| 3322 | do { |
| 3323 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); |
| 3324 | } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 3325 | |
| 3326 | if (rc) |
| 3327 | dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc); |
| 3328 | |
| 3329 | return rc; |
| 3330 | } |
| 3331 | |
| 3332 | static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter) |
| 3333 | { |
| 3334 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 3335 | struct device *dev = &adapter->vdev->dev; |
| 3336 | struct vio_dev *vdev = adapter->vdev; |
| 3337 | int rc; |
| 3338 | |
| 3339 | /* Close the CRQ */ |
| 3340 | do { |
| 3341 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 3342 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 3343 | |
| 3344 | /* Clean out the queue */ |
| 3345 | memset(crq->msgs, 0, PAGE_SIZE); |
| 3346 | crq->cur = 0; |
| 3347 | |
| 3348 | /* And re-open it again */ |
| 3349 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 3350 | crq->msg_token, PAGE_SIZE); |
| 3351 | |
| 3352 | if (rc == H_CLOSED) |
| 3353 | /* Adapter is good, but other end is not ready */ |
| 3354 | dev_warn(dev, "Partner adapter not ready\n"); |
| 3355 | else if (rc != 0) |
| 3356 | dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc); |
| 3357 | |
| 3358 | return rc; |
| 3359 | } |
| 3360 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3361 | static void release_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3362 | { |
| 3363 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 3364 | struct vio_dev *vdev = adapter->vdev; |
| 3365 | long rc; |
| 3366 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3367 | if (!crq->msgs) |
| 3368 | return; |
| 3369 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3370 | netdev_dbg(adapter->netdev, "Releasing CRQ\n"); |
| 3371 | free_irq(vdev->irq, adapter); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3372 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3373 | do { |
| 3374 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 3375 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 3376 | |
| 3377 | dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE, |
| 3378 | DMA_BIDIRECTIONAL); |
| 3379 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3380 | crq->msgs = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3381 | } |
| 3382 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3383 | static int init_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3384 | { |
| 3385 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 3386 | struct device *dev = &adapter->vdev->dev; |
| 3387 | struct vio_dev *vdev = adapter->vdev; |
| 3388 | int rc, retrc = -ENOMEM; |
| 3389 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3390 | if (crq->msgs) |
| 3391 | return 0; |
| 3392 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3393 | crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL); |
| 3394 | /* Should we allocate more than one page? */ |
| 3395 | |
| 3396 | if (!crq->msgs) |
| 3397 | return -ENOMEM; |
| 3398 | |
| 3399 | crq->size = PAGE_SIZE / sizeof(*crq->msgs); |
| 3400 | crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE, |
| 3401 | DMA_BIDIRECTIONAL); |
| 3402 | if (dma_mapping_error(dev, crq->msg_token)) |
| 3403 | goto map_failed; |
| 3404 | |
| 3405 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 3406 | crq->msg_token, PAGE_SIZE); |
| 3407 | |
| 3408 | if (rc == H_RESOURCE) |
| 3409 | /* maybe kexecing and resource is busy. try a reset */ |
| 3410 | rc = ibmvnic_reset_crq(adapter); |
| 3411 | retrc = rc; |
| 3412 | |
| 3413 | if (rc == H_CLOSED) { |
| 3414 | dev_warn(dev, "Partner adapter not ready\n"); |
| 3415 | } else if (rc) { |
| 3416 | dev_warn(dev, "Error %d opening adapter\n", rc); |
| 3417 | goto reg_crq_failed; |
| 3418 | } |
| 3419 | |
| 3420 | retrc = 0; |
| 3421 | |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3422 | tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet, |
| 3423 | (unsigned long)adapter); |
| 3424 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3425 | netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq); |
| 3426 | rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME, |
| 3427 | adapter); |
| 3428 | if (rc) { |
| 3429 | dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", |
| 3430 | vdev->irq, rc); |
| 3431 | goto req_irq_failed; |
| 3432 | } |
| 3433 | |
| 3434 | rc = vio_enable_interrupts(vdev); |
| 3435 | if (rc) { |
| 3436 | dev_err(dev, "Error %d enabling interrupts\n", rc); |
| 3437 | goto req_irq_failed; |
| 3438 | } |
| 3439 | |
| 3440 | crq->cur = 0; |
| 3441 | spin_lock_init(&crq->lock); |
| 3442 | |
| 3443 | return retrc; |
| 3444 | |
| 3445 | req_irq_failed: |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 3446 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3447 | do { |
| 3448 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 3449 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 3450 | reg_crq_failed: |
| 3451 | dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 3452 | map_failed: |
| 3453 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3454 | crq->msgs = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3455 | return retrc; |
| 3456 | } |
| 3457 | |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3458 | static int ibmvnic_init(struct ibmvnic_adapter *adapter) |
| 3459 | { |
| 3460 | struct device *dev = &adapter->vdev->dev; |
| 3461 | unsigned long timeout = msecs_to_jiffies(30000); |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3462 | int rc; |
| 3463 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3464 | rc = init_crq_queue(adapter); |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3465 | if (rc) { |
| 3466 | dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc); |
| 3467 | return rc; |
| 3468 | } |
| 3469 | |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3470 | init_completion(&adapter->init_done); |
| 3471 | ibmvnic_send_crq_init(adapter); |
| 3472 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 3473 | dev_err(dev, "Initialization sequence timed out\n"); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 3474 | release_crq_queue(adapter); |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3475 | return -1; |
| 3476 | } |
| 3477 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3478 | rc = init_sub_crqs(adapter); |
| 3479 | if (rc) { |
| 3480 | dev_err(dev, "Initialization of sub crqs failed\n"); |
| 3481 | release_crq_queue(adapter); |
| 3482 | } |
| 3483 | |
| 3484 | return rc; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3485 | } |
| 3486 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3487 | static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) |
| 3488 | { |
| 3489 | struct ibmvnic_adapter *adapter; |
| 3490 | struct net_device *netdev; |
| 3491 | unsigned char *mac_addr_p; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3492 | int rc; |
| 3493 | |
| 3494 | dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n", |
| 3495 | dev->unit_address); |
| 3496 | |
| 3497 | mac_addr_p = (unsigned char *)vio_get_attribute(dev, |
| 3498 | VETH_MAC_ADDR, NULL); |
| 3499 | if (!mac_addr_p) { |
| 3500 | dev_err(&dev->dev, |
| 3501 | "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n", |
| 3502 | __FILE__, __LINE__); |
| 3503 | return 0; |
| 3504 | } |
| 3505 | |
| 3506 | netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter), |
| 3507 | IBMVNIC_MAX_TX_QUEUES); |
| 3508 | if (!netdev) |
| 3509 | return -ENOMEM; |
| 3510 | |
| 3511 | adapter = netdev_priv(netdev); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 3512 | adapter->state = VNIC_PROBING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3513 | dev_set_drvdata(&dev->dev, netdev); |
| 3514 | adapter->vdev = dev; |
| 3515 | adapter->netdev = netdev; |
| 3516 | |
| 3517 | ether_addr_copy(adapter->mac_addr, mac_addr_p); |
| 3518 | ether_addr_copy(netdev->dev_addr, adapter->mac_addr); |
| 3519 | netdev->irq = dev->irq; |
| 3520 | netdev->netdev_ops = &ibmvnic_netdev_ops; |
| 3521 | netdev->ethtool_ops = &ibmvnic_ethtool_ops; |
| 3522 | SET_NETDEV_DEV(netdev, &dev->dev); |
| 3523 | |
| 3524 | spin_lock_init(&adapter->stats_lock); |
| 3525 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3526 | INIT_LIST_HEAD(&adapter->errors); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3527 | spin_lock_init(&adapter->error_list_lock); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3528 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3529 | INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset); |
| 3530 | INIT_LIST_HEAD(&adapter->rwi_list); |
| 3531 | mutex_init(&adapter->reset_lock); |
| 3532 | mutex_init(&adapter->rwi_lock); |
| 3533 | adapter->resetting = false; |
| 3534 | |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3535 | rc = ibmvnic_init(adapter); |
| 3536 | if (rc) { |
| 3537 | free_netdev(netdev); |
| 3538 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3539 | } |
| 3540 | |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 3541 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3542 | |
| 3543 | rc = register_netdev(netdev); |
| 3544 | if (rc) { |
| 3545 | dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc); |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 3546 | free_netdev(netdev); |
| 3547 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3548 | } |
| 3549 | dev_info(&dev->dev, "ibmvnic registered\n"); |
| 3550 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 3551 | adapter->state = VNIC_PROBED; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3552 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | static int ibmvnic_remove(struct vio_dev *dev) |
| 3556 | { |
| 3557 | struct net_device *netdev = dev_get_drvdata(&dev->dev); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 3558 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3559 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 3560 | adapter->state = VNIC_REMOVING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3561 | unregister_netdev(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3562 | mutex_lock(&adapter->reset_lock); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 3563 | |
| 3564 | release_resources(adapter); |
| 3565 | release_sub_crqs(adapter); |
| 3566 | release_crq_queue(adapter); |
| 3567 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 3568 | adapter->state = VNIC_REMOVED; |
| 3569 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 3570 | mutex_unlock(&adapter->reset_lock); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3571 | free_netdev(netdev); |
| 3572 | dev_set_drvdata(&dev->dev, NULL); |
| 3573 | |
| 3574 | return 0; |
| 3575 | } |
| 3576 | |
| 3577 | static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev) |
| 3578 | { |
| 3579 | struct net_device *netdev = dev_get_drvdata(&vdev->dev); |
| 3580 | struct ibmvnic_adapter *adapter; |
| 3581 | struct iommu_table *tbl; |
| 3582 | unsigned long ret = 0; |
| 3583 | int i; |
| 3584 | |
| 3585 | tbl = get_iommu_table_base(&vdev->dev); |
| 3586 | |
| 3587 | /* netdev inits at probe time along with the structures we need below*/ |
| 3588 | if (!netdev) |
| 3589 | return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl); |
| 3590 | |
| 3591 | adapter = netdev_priv(netdev); |
| 3592 | |
| 3593 | ret += PAGE_SIZE; /* the crq message queue */ |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3594 | ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl); |
| 3595 | |
| 3596 | for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++) |
| 3597 | ret += 4 * PAGE_SIZE; /* the scrq message queue */ |
| 3598 | |
| 3599 | for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 3600 | i++) |
| 3601 | ret += adapter->rx_pool[i].size * |
| 3602 | IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl); |
| 3603 | |
| 3604 | return ret; |
| 3605 | } |
| 3606 | |
| 3607 | static int ibmvnic_resume(struct device *dev) |
| 3608 | { |
| 3609 | struct net_device *netdev = dev_get_drvdata(dev); |
| 3610 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3611 | int i; |
| 3612 | |
| 3613 | /* kick the interrupt handlers just in case we lost an interrupt */ |
| 3614 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 3615 | ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq, |
| 3616 | adapter->rx_scrq[i]); |
| 3617 | |
| 3618 | return 0; |
| 3619 | } |
| 3620 | |
| 3621 | static struct vio_device_id ibmvnic_device_table[] = { |
| 3622 | {"network", "IBM,vnic"}, |
| 3623 | {"", "" } |
| 3624 | }; |
| 3625 | MODULE_DEVICE_TABLE(vio, ibmvnic_device_table); |
| 3626 | |
| 3627 | static const struct dev_pm_ops ibmvnic_pm_ops = { |
| 3628 | .resume = ibmvnic_resume |
| 3629 | }; |
| 3630 | |
| 3631 | static struct vio_driver ibmvnic_driver = { |
| 3632 | .id_table = ibmvnic_device_table, |
| 3633 | .probe = ibmvnic_probe, |
| 3634 | .remove = ibmvnic_remove, |
| 3635 | .get_desired_dma = ibmvnic_get_desired_dma, |
| 3636 | .name = ibmvnic_driver_name, |
| 3637 | .pm = &ibmvnic_pm_ops, |
| 3638 | }; |
| 3639 | |
| 3640 | /* module functions */ |
| 3641 | static int __init ibmvnic_module_init(void) |
| 3642 | { |
| 3643 | pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string, |
| 3644 | IBMVNIC_DRIVER_VERSION); |
| 3645 | |
| 3646 | return vio_register_driver(&ibmvnic_driver); |
| 3647 | } |
| 3648 | |
| 3649 | static void __exit ibmvnic_module_exit(void) |
| 3650 | { |
| 3651 | vio_unregister_driver(&ibmvnic_driver); |
| 3652 | } |
| 3653 | |
| 3654 | module_init(ibmvnic_module_init); |
| 3655 | module_exit(ibmvnic_module_exit); |