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