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