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