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