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