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