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