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