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