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