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