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); |
Lijun Pan | 673ead2 | 2021-06-14 00:20:45 -0500 | [diff] [blame] | 98 | static int send_request_map(struct ibmvnic_adapter *, dma_addr_t, u32, u8); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 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); |
Sukadev Bhattiprolu | f8ac0bf | 2021-09-14 20:52:57 -0700 | [diff] [blame] | 111 | static void free_long_term_buff(struct ibmvnic_adapter *adapter, |
| 112 | struct ibmvnic_long_term_buff *ltb); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 113 | |
| 114 | struct ibmvnic_stat { |
| 115 | char name[ETH_GSTRING_LEN]; |
| 116 | int offset; |
| 117 | }; |
| 118 | |
| 119 | #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \ |
| 120 | offsetof(struct ibmvnic_statistics, stat)) |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 121 | #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + (off)))) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 122 | |
| 123 | static const struct ibmvnic_stat ibmvnic_stats[] = { |
| 124 | {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)}, |
| 125 | {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)}, |
| 126 | {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)}, |
| 127 | {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)}, |
| 128 | {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)}, |
| 129 | {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)}, |
| 130 | {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)}, |
| 131 | {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)}, |
| 132 | {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)}, |
| 133 | {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)}, |
| 134 | {"align_errors", IBMVNIC_STAT_OFF(align_errors)}, |
| 135 | {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)}, |
| 136 | {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)}, |
| 137 | {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)}, |
| 138 | {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)}, |
| 139 | {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)}, |
| 140 | {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)}, |
| 141 | {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)}, |
| 142 | {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)}, |
| 143 | {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)}, |
| 144 | {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)}, |
| 145 | {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)}, |
| 146 | }; |
| 147 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 148 | static int send_crq_init_complete(struct ibmvnic_adapter *adapter) |
| 149 | { |
| 150 | union ibmvnic_crq crq; |
| 151 | |
| 152 | memset(&crq, 0, sizeof(crq)); |
| 153 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 154 | crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE; |
| 155 | |
| 156 | return ibmvnic_send_crq(adapter, &crq); |
| 157 | } |
| 158 | |
| 159 | static int send_version_xchg(struct ibmvnic_adapter *adapter) |
| 160 | { |
| 161 | union ibmvnic_crq crq; |
| 162 | |
| 163 | memset(&crq, 0, sizeof(crq)); |
| 164 | crq.version_exchange.first = IBMVNIC_CRQ_CMD; |
| 165 | crq.version_exchange.cmd = VERSION_EXCHANGE; |
| 166 | crq.version_exchange.version = cpu_to_be16(ibmvnic_version); |
| 167 | |
| 168 | return ibmvnic_send_crq(adapter, &crq); |
| 169 | } |
| 170 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 171 | static long h_reg_sub_crq(unsigned long unit_address, unsigned long token, |
| 172 | unsigned long length, unsigned long *number, |
| 173 | unsigned long *irq) |
| 174 | { |
| 175 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 176 | long rc; |
| 177 | |
| 178 | rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length); |
| 179 | *number = retbuf[0]; |
| 180 | *irq = retbuf[1]; |
| 181 | |
| 182 | return rc; |
| 183 | } |
| 184 | |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 185 | /** |
| 186 | * ibmvnic_wait_for_completion - Check device state and wait for completion |
| 187 | * @adapter: private device data |
| 188 | * @comp_done: completion structure to wait for |
| 189 | * @timeout: time to wait in milliseconds |
| 190 | * |
| 191 | * Wait for a completion signal or until the timeout limit is reached |
| 192 | * while checking that the device is still active. |
| 193 | */ |
| 194 | static int ibmvnic_wait_for_completion(struct ibmvnic_adapter *adapter, |
| 195 | struct completion *comp_done, |
| 196 | unsigned long timeout) |
| 197 | { |
| 198 | struct net_device *netdev; |
| 199 | unsigned long div_timeout; |
| 200 | u8 retry; |
| 201 | |
| 202 | netdev = adapter->netdev; |
| 203 | retry = 5; |
| 204 | div_timeout = msecs_to_jiffies(timeout / retry); |
| 205 | while (true) { |
| 206 | if (!adapter->crq.active) { |
| 207 | netdev_err(netdev, "Device down!\n"); |
| 208 | return -ENODEV; |
| 209 | } |
Thomas Falcon | 8f9cc1e | 2019-12-11 09:38:39 -0600 | [diff] [blame] | 210 | if (!retry--) |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 211 | break; |
| 212 | if (wait_for_completion_timeout(comp_done, div_timeout)) |
| 213 | return 0; |
| 214 | } |
| 215 | netdev_err(netdev, "Operation timed out.\n"); |
| 216 | return -ETIMEDOUT; |
| 217 | } |
| 218 | |
Sukadev Bhattiprolu | f8ac0bf | 2021-09-14 20:52:57 -0700 | [diff] [blame] | 219 | /** |
| 220 | * reuse_ltb() - Check if a long term buffer can be reused |
| 221 | * @ltb: The long term buffer to be checked |
| 222 | * @size: The size of the long term buffer. |
| 223 | * |
| 224 | * An LTB can be reused unless its size has changed. |
| 225 | * |
| 226 | * Return: Return true if the LTB can be reused, false otherwise. |
| 227 | */ |
| 228 | static bool reuse_ltb(struct ibmvnic_long_term_buff *ltb, int size) |
| 229 | { |
| 230 | return (ltb->buff && ltb->size == size); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * alloc_long_term_buff() - Allocate a long term buffer (LTB) |
| 235 | * |
| 236 | * @adapter: ibmvnic adapter associated to the LTB |
| 237 | * @ltb: container object for the LTB |
| 238 | * @size: size of the LTB |
| 239 | * |
| 240 | * Allocate an LTB of the specified size and notify VIOS. |
| 241 | * |
| 242 | * If the given @ltb already has the correct size, reuse it. Otherwise if |
| 243 | * its non-NULL, free it. Then allocate a new one of the correct size. |
| 244 | * Notify the VIOS either way since we may now be working with a new VIOS. |
| 245 | * |
| 246 | * Allocating larger chunks of memory during resets, specially LPM or under |
| 247 | * low memory situations can cause resets to fail/timeout and for LPAR to |
| 248 | * lose connectivity. So hold onto the LTB even if we fail to communicate |
| 249 | * with the VIOS and reuse it on next open. Free LTB when adapter is closed. |
| 250 | * |
| 251 | * Return: 0 if we were able to allocate the LTB and notify the VIOS and |
| 252 | * a negative value otherwise. |
| 253 | */ |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 254 | static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, |
| 255 | struct ibmvnic_long_term_buff *ltb, int size) |
| 256 | { |
| 257 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 258 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 259 | |
Sukadev Bhattiprolu | f8ac0bf | 2021-09-14 20:52:57 -0700 | [diff] [blame] | 260 | if (!reuse_ltb(ltb, size)) { |
| 261 | dev_dbg(dev, |
| 262 | "LTB size changed from 0x%llx to 0x%x, reallocating\n", |
| 263 | ltb->size, size); |
| 264 | free_long_term_buff(adapter, ltb); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 265 | } |
Sukadev Bhattiprolu | f8ac0bf | 2021-09-14 20:52:57 -0700 | [diff] [blame] | 266 | |
| 267 | if (ltb->buff) { |
| 268 | dev_dbg(dev, "Reusing LTB [map %d, size 0x%llx]\n", |
| 269 | ltb->map_id, ltb->size); |
| 270 | } else { |
| 271 | ltb->buff = dma_alloc_coherent(dev, size, <b->addr, |
| 272 | GFP_KERNEL); |
| 273 | if (!ltb->buff) { |
| 274 | dev_err(dev, "Couldn't alloc long term buffer\n"); |
| 275 | return -ENOMEM; |
| 276 | } |
| 277 | ltb->size = size; |
| 278 | |
| 279 | ltb->map_id = find_first_zero_bit(adapter->map_ids, |
| 280 | MAX_MAP_ID); |
| 281 | bitmap_set(adapter->map_ids, ltb->map_id, 1); |
| 282 | |
| 283 | dev_dbg(dev, |
| 284 | "Allocated new LTB [map %d, size 0x%llx]\n", |
| 285 | ltb->map_id, ltb->size); |
| 286 | } |
| 287 | |
| 288 | /* Ensure ltb is zeroed - specially when reusing it. */ |
| 289 | memset(ltb->buff, 0, ltb->size); |
Nathan Fontenot | db5d0b5 | 2017-02-10 13:45:05 -0500 | [diff] [blame] | 290 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 291 | mutex_lock(&adapter->fw_lock); |
| 292 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 293 | reinit_completion(&adapter->fw_done); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 294 | |
| 295 | rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 296 | if (rc) { |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 297 | dev_err(dev, "send_request_map failed, rc = %d\n", rc); |
| 298 | goto out; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 299 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 300 | |
| 301 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 302 | if (rc) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 303 | dev_err(dev, "LTB map request aborted or timed out, rc = %d\n", |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 304 | rc); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 305 | goto out; |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 306 | } |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 307 | |
| 308 | if (adapter->fw_done_rc) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 309 | dev_err(dev, "Couldn't map LTB, rc = %d\n", |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 310 | adapter->fw_done_rc); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 311 | rc = -EIO; |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 312 | goto out; |
| 313 | } |
| 314 | rc = 0; |
| 315 | out: |
Sukadev Bhattiprolu | f8ac0bf | 2021-09-14 20:52:57 -0700 | [diff] [blame] | 316 | /* don't free LTB on communication error - see function header */ |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 317 | mutex_unlock(&adapter->fw_lock); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 318 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static void free_long_term_buff(struct ibmvnic_adapter *adapter, |
| 322 | struct ibmvnic_long_term_buff *ltb) |
| 323 | { |
| 324 | struct device *dev = &adapter->vdev->dev; |
| 325 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 326 | if (!ltb->buff) |
| 327 | return; |
| 328 | |
Lijun Pan | 7d3a7b9 | 2021-02-12 20:49:00 -0600 | [diff] [blame] | 329 | /* VIOS automatically unmaps the long term buffer at remote |
| 330 | * end for the following resets: |
| 331 | * FAILOVER, MOBILITY, TIMEOUT. |
| 332 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 333 | if (adapter->reset_reason != VNIC_RESET_FAILOVER && |
Lijun Pan | 7d3a7b9 | 2021-02-12 20:49:00 -0600 | [diff] [blame] | 334 | adapter->reset_reason != VNIC_RESET_MOBILITY && |
| 335 | adapter->reset_reason != VNIC_RESET_TIMEOUT) |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 336 | send_request_unmap(adapter, ltb->map_id); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 337 | |
Brian King | 59af56c | 2017-04-19 13:44:41 -0400 | [diff] [blame] | 338 | dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 339 | |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 340 | ltb->buff = NULL; |
Sukadev Bhattiprolu | 129854f0 | 2021-09-14 20:52:56 -0700 | [diff] [blame] | 341 | /* mark this map_id free */ |
| 342 | bitmap_clear(adapter->map_ids, ltb->map_id, 1); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 343 | ltb->map_id = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 346 | static void deactivate_rx_pools(struct ibmvnic_adapter *adapter) |
| 347 | { |
| 348 | int i; |
| 349 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 350 | for (i = 0; i < adapter->num_active_rx_pools; i++) |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 351 | adapter->rx_pool[i].active = 0; |
| 352 | } |
| 353 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 354 | static void replenish_rx_pool(struct ibmvnic_adapter *adapter, |
| 355 | struct ibmvnic_rx_pool *pool) |
| 356 | { |
| 357 | int count = pool->size - atomic_read(&pool->available); |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 358 | u64 handle = adapter->rx_scrq[pool->index]->handle; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 359 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 360 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 361 | struct ibmvnic_sub_crq_queue *rx_scrq; |
| 362 | union sub_crq *sub_crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 363 | int buffers_added = 0; |
| 364 | unsigned long lpar_rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 365 | struct sk_buff *skb; |
| 366 | unsigned int offset; |
| 367 | dma_addr_t dma_addr; |
| 368 | unsigned char *dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 369 | int shift = 0; |
| 370 | int index; |
| 371 | int i; |
| 372 | |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 373 | if (!pool->active) |
| 374 | return; |
| 375 | |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 376 | rx_scrq = adapter->rx_scrq[pool->index]; |
| 377 | ind_bufp = &rx_scrq->ind_buf; |
Sukadev Bhattiprolu | 72368f8 | 2021-06-23 21:13:13 -0700 | [diff] [blame] | 378 | |
| 379 | /* netdev_skb_alloc() could have failed after we saved a few skbs |
| 380 | * in the indir_buf and we would not have sent them to VIOS yet. |
| 381 | * To account for them, start the loop at ind_bufp->index rather |
| 382 | * than 0. If we pushed all the skbs to VIOS, ind_bufp->index will |
| 383 | * be 0. |
| 384 | */ |
| 385 | for (i = ind_bufp->index; i < count; ++i) { |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 386 | index = pool->free_map[pool->next_free]; |
| 387 | |
| 388 | /* We maybe reusing the skb from earlier resets. Allocate |
| 389 | * only if necessary. But since the LTB may have changed |
| 390 | * during reset (see init_rx_pools()), update LTB below |
| 391 | * even if reusing skb. |
| 392 | */ |
| 393 | skb = pool->rx_buff[index].skb; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 394 | if (!skb) { |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 395 | skb = netdev_alloc_skb(adapter->netdev, |
| 396 | pool->buff_size); |
| 397 | if (!skb) { |
| 398 | dev_err(dev, "Couldn't replenish rx buff\n"); |
| 399 | adapter->replenish_no_mem++; |
| 400 | break; |
| 401 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 402 | } |
| 403 | |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 404 | pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP; |
| 405 | pool->next_free = (pool->next_free + 1) % pool->size; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 406 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 407 | /* Copy the skb to the long term mapped DMA buffer */ |
| 408 | offset = index * pool->buff_size; |
| 409 | dst = pool->long_term_buff.buff + offset; |
| 410 | memset(dst, 0, pool->buff_size); |
| 411 | dma_addr = pool->long_term_buff.addr + offset; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 412 | |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 413 | /* add the skb to an rx_buff in the pool */ |
| 414 | pool->rx_buff[index].data = dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 415 | pool->rx_buff[index].dma = dma_addr; |
| 416 | pool->rx_buff[index].skb = skb; |
| 417 | pool->rx_buff[index].pool_index = pool->index; |
| 418 | pool->rx_buff[index].size = pool->buff_size; |
| 419 | |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 420 | /* queue the rx_buff for the next send_subcrq_indirect */ |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 421 | sub_crq = &ind_bufp->indir_arr[ind_bufp->index++]; |
| 422 | memset(sub_crq, 0, sizeof(*sub_crq)); |
| 423 | sub_crq->rx_add.first = IBMVNIC_CRQ_CMD; |
| 424 | sub_crq->rx_add.correlator = |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 425 | cpu_to_be64((u64)&pool->rx_buff[index]); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 426 | sub_crq->rx_add.ioba = cpu_to_be32(dma_addr); |
| 427 | sub_crq->rx_add.map_id = pool->long_term_buff.map_id; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 428 | |
| 429 | /* The length field of the sCRQ is defined to be 24 bits so the |
| 430 | * buffer size needs to be left shifted by a byte before it is |
| 431 | * converted to big endian to prevent the last byte from being |
| 432 | * truncated. |
| 433 | */ |
| 434 | #ifdef __LITTLE_ENDIAN__ |
| 435 | shift = 8; |
| 436 | #endif |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 437 | sub_crq->rx_add.len = cpu_to_be32(pool->buff_size << shift); |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 438 | |
| 439 | /* if send_subcrq_indirect queue is full, flush to VIOS */ |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 440 | if (ind_bufp->index == IBMVNIC_MAX_IND_DESCS || |
| 441 | i == count - 1) { |
| 442 | lpar_rc = |
| 443 | send_subcrq_indirect(adapter, handle, |
| 444 | (u64)ind_bufp->indir_dma, |
| 445 | (u64)ind_bufp->index); |
| 446 | if (lpar_rc != H_SUCCESS) |
| 447 | goto failure; |
| 448 | buffers_added += ind_bufp->index; |
| 449 | adapter->replenish_add_buff_success += ind_bufp->index; |
| 450 | ind_bufp->index = 0; |
| 451 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 452 | } |
| 453 | atomic_add(buffers_added, &pool->available); |
| 454 | return; |
| 455 | |
| 456 | failure: |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 457 | if (lpar_rc != H_PARAMETER && lpar_rc != H_CLOSED) |
| 458 | dev_err_ratelimited(dev, "rx: replenish packet buffer failed\n"); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 459 | for (i = ind_bufp->index - 1; i >= 0; --i) { |
| 460 | struct ibmvnic_rx_buff *rx_buff; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 461 | |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 462 | pool->next_free = pool->next_free == 0 ? |
| 463 | pool->size - 1 : pool->next_free - 1; |
| 464 | sub_crq = &ind_bufp->indir_arr[i]; |
| 465 | rx_buff = (struct ibmvnic_rx_buff *) |
| 466 | be64_to_cpu(sub_crq->rx_add.correlator); |
| 467 | index = (int)(rx_buff - pool->rx_buff); |
| 468 | pool->free_map[pool->next_free] = index; |
| 469 | dev_kfree_skb_any(pool->rx_buff[index].skb); |
| 470 | pool->rx_buff[index].skb = NULL; |
| 471 | } |
Dwip N. Banerjee | c2af622 | 2020-12-09 20:53:31 -0500 | [diff] [blame] | 472 | adapter->replenish_add_buff_failure += ind_bufp->index; |
| 473 | atomic_add(buffers_added, &pool->available); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 474 | ind_bufp->index = 0; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 475 | if (lpar_rc == H_CLOSED || adapter->failover_pending) { |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 476 | /* Disable buffer pool replenishment and report carrier off if |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 477 | * queue is closed or pending failover. |
| 478 | * Firmware guarantees that a signal will be sent to the |
| 479 | * driver, triggering a reset. |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 480 | */ |
| 481 | deactivate_rx_pools(adapter); |
| 482 | netif_carrier_off(adapter->netdev); |
| 483 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void replenish_pools(struct ibmvnic_adapter *adapter) |
| 487 | { |
| 488 | int i; |
| 489 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 490 | adapter->replenish_task_cycles++; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 491 | for (i = 0; i < adapter->num_active_rx_pools; i++) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 492 | if (adapter->rx_pool[i].active) |
| 493 | replenish_rx_pool(adapter, &adapter->rx_pool[i]); |
| 494 | } |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 495 | |
| 496 | netdev_dbg(adapter->netdev, "Replenished %d pools\n", i); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 497 | } |
| 498 | |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 499 | static void release_stats_buffers(struct ibmvnic_adapter *adapter) |
| 500 | { |
| 501 | kfree(adapter->tx_stats_buffers); |
| 502 | kfree(adapter->rx_stats_buffers); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 503 | adapter->tx_stats_buffers = NULL; |
| 504 | adapter->rx_stats_buffers = NULL; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static int init_stats_buffers(struct ibmvnic_adapter *adapter) |
| 508 | { |
| 509 | adapter->tx_stats_buffers = |
Nathan Fontenot | abcae54 | 2018-02-19 13:30:47 -0600 | [diff] [blame] | 510 | kcalloc(IBMVNIC_MAX_QUEUES, |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 511 | sizeof(struct ibmvnic_tx_queue_stats), |
| 512 | GFP_KERNEL); |
| 513 | if (!adapter->tx_stats_buffers) |
| 514 | return -ENOMEM; |
| 515 | |
| 516 | adapter->rx_stats_buffers = |
Nathan Fontenot | abcae54 | 2018-02-19 13:30:47 -0600 | [diff] [blame] | 517 | kcalloc(IBMVNIC_MAX_QUEUES, |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 518 | sizeof(struct ibmvnic_rx_queue_stats), |
| 519 | GFP_KERNEL); |
| 520 | if (!adapter->rx_stats_buffers) |
| 521 | return -ENOMEM; |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 526 | static void release_stats_token(struct ibmvnic_adapter *adapter) |
| 527 | { |
| 528 | struct device *dev = &adapter->vdev->dev; |
| 529 | |
| 530 | if (!adapter->stats_token) |
| 531 | return; |
| 532 | |
| 533 | dma_unmap_single(dev, adapter->stats_token, |
| 534 | sizeof(struct ibmvnic_statistics), |
| 535 | DMA_FROM_DEVICE); |
| 536 | adapter->stats_token = 0; |
| 537 | } |
| 538 | |
| 539 | static int init_stats_token(struct ibmvnic_adapter *adapter) |
| 540 | { |
| 541 | struct device *dev = &adapter->vdev->dev; |
| 542 | dma_addr_t stok; |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 543 | int rc; |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 544 | |
| 545 | stok = dma_map_single(dev, &adapter->stats, |
| 546 | sizeof(struct ibmvnic_statistics), |
| 547 | DMA_FROM_DEVICE); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 548 | rc = dma_mapping_error(dev, stok); |
| 549 | if (rc) { |
| 550 | dev_err(dev, "Couldn't map stats buffer, rc = %d\n", rc); |
| 551 | return rc; |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | adapter->stats_token = stok; |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 555 | netdev_dbg(adapter->netdev, "Stats token initialized (%llx)\n", stok); |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 559 | /** |
| 560 | * release_rx_pools() - Release any rx pools attached to @adapter. |
| 561 | * @adapter: ibmvnic adapter |
| 562 | * |
| 563 | * Safe to call this multiple times - even if no pools are attached. |
| 564 | */ |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 565 | static void release_rx_pools(struct ibmvnic_adapter *adapter) |
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 | struct ibmvnic_rx_pool *rx_pool; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 568 | int i, j; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 569 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 570 | if (!adapter->rx_pool) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 571 | return; |
| 572 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 573 | for (i = 0; i < adapter->num_active_rx_pools; i++) { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 574 | rx_pool = &adapter->rx_pool[i]; |
| 575 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 576 | netdev_dbg(adapter->netdev, "Releasing rx_pool[%d]\n", i); |
| 577 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 578 | kfree(rx_pool->free_map); |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 579 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 580 | free_long_term_buff(adapter, &rx_pool->long_term_buff); |
| 581 | |
| 582 | if (!rx_pool->rx_buff) |
Nathan Fontenot | e0ebe942 | 2017-05-03 14:04:50 -0400 | [diff] [blame] | 583 | continue; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 584 | |
| 585 | for (j = 0; j < rx_pool->size; j++) { |
| 586 | if (rx_pool->rx_buff[j].skb) { |
Thomas Falcon | b7cdec3 | 2018-11-21 11:17:58 -0600 | [diff] [blame] | 587 | dev_kfree_skb_any(rx_pool->rx_buff[j].skb); |
| 588 | rx_pool->rx_buff[j].skb = NULL; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 589 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 590 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 591 | |
| 592 | kfree(rx_pool->rx_buff); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 593 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 594 | |
| 595 | kfree(adapter->rx_pool); |
| 596 | adapter->rx_pool = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 597 | adapter->num_active_rx_pools = 0; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 598 | adapter->prev_rx_pool_size = 0; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 601 | /** |
| 602 | * reuse_rx_pools() - Check if the existing rx pools can be reused. |
| 603 | * @adapter: ibmvnic adapter |
| 604 | * |
| 605 | * Check if the existing rx pools in the adapter can be reused. The |
| 606 | * pools can be reused if the pool parameters (number of pools, |
| 607 | * number of buffers in the pool and size of each buffer) have not |
| 608 | * changed. |
| 609 | * |
| 610 | * NOTE: This assumes that all pools have the same number of buffers |
| 611 | * which is the case currently. If that changes, we must fix this. |
| 612 | * |
| 613 | * Return: true if the rx pools can be reused, false otherwise. |
| 614 | */ |
| 615 | static bool reuse_rx_pools(struct ibmvnic_adapter *adapter) |
| 616 | { |
| 617 | u64 old_num_pools, new_num_pools; |
| 618 | u64 old_pool_size, new_pool_size; |
| 619 | u64 old_buff_size, new_buff_size; |
| 620 | |
| 621 | if (!adapter->rx_pool) |
| 622 | return false; |
| 623 | |
| 624 | old_num_pools = adapter->num_active_rx_pools; |
| 625 | new_num_pools = adapter->req_rx_queues; |
| 626 | |
| 627 | old_pool_size = adapter->prev_rx_pool_size; |
| 628 | new_pool_size = adapter->req_rx_add_entries_per_subcrq; |
| 629 | |
| 630 | old_buff_size = adapter->prev_rx_buf_sz; |
| 631 | new_buff_size = adapter->cur_rx_buf_sz; |
| 632 | |
Sukadev Bhattiprolu | 0584f49 | 2021-11-30 21:48:35 -0800 | [diff] [blame] | 633 | if (old_buff_size != new_buff_size || |
| 634 | old_num_pools != new_num_pools || |
| 635 | old_pool_size != new_pool_size) |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 636 | return false; |
| 637 | |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * init_rx_pools(): Initialize the set of receiver pools in the adapter. |
| 643 | * @netdev: net device associated with the vnic interface |
| 644 | * |
| 645 | * Initialize the set of receiver pools in the ibmvnic adapter associated |
| 646 | * with the net_device @netdev. If possible, reuse the existing rx pools. |
| 647 | * Otherwise free any existing pools and allocate a new set of pools |
| 648 | * before initializing them. |
| 649 | * |
| 650 | * Return: 0 on success and negative value on error. |
| 651 | */ |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 652 | static int init_rx_pools(struct net_device *netdev) |
| 653 | { |
| 654 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 655 | struct device *dev = &adapter->vdev->dev; |
| 656 | struct ibmvnic_rx_pool *rx_pool; |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 657 | u64 num_pools; |
| 658 | u64 pool_size; /* # of buffers in one pool */ |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 659 | u64 buff_size; |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 660 | int i, j, rc; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 661 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 662 | pool_size = adapter->req_rx_add_entries_per_subcrq; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 663 | num_pools = adapter->req_rx_queues; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 664 | buff_size = adapter->cur_rx_buf_sz; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 665 | |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 666 | if (reuse_rx_pools(adapter)) { |
| 667 | dev_dbg(dev, "Reusing rx pools\n"); |
| 668 | goto update_ltb; |
| 669 | } |
| 670 | |
| 671 | /* Allocate/populate the pools. */ |
| 672 | release_rx_pools(adapter); |
| 673 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 674 | adapter->rx_pool = kcalloc(num_pools, |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 675 | sizeof(struct ibmvnic_rx_pool), |
| 676 | GFP_KERNEL); |
| 677 | if (!adapter->rx_pool) { |
| 678 | dev_err(dev, "Failed to allocate rx pools\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 679 | return -ENOMEM; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 680 | } |
| 681 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 682 | /* Set num_active_rx_pools early. If we fail below after partial |
| 683 | * allocation, release_rx_pools() will know how many to look for. |
| 684 | */ |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 685 | adapter->num_active_rx_pools = num_pools; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 686 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 687 | for (i = 0; i < num_pools; i++) { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 688 | rx_pool = &adapter->rx_pool[i]; |
| 689 | |
| 690 | netdev_dbg(adapter->netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 691 | "Initializing rx_pool[%d], %lld buffs, %lld bytes each\n", |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 692 | i, pool_size, buff_size); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 693 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame] | 694 | rx_pool->size = pool_size; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 695 | rx_pool->index = i; |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 696 | rx_pool->buff_size = ALIGN(buff_size, L1_CACHE_BYTES); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 697 | |
| 698 | rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int), |
| 699 | GFP_KERNEL); |
| 700 | if (!rx_pool->free_map) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 701 | dev_err(dev, "Couldn't alloc free_map %d\n", i); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 702 | rc = -ENOMEM; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 703 | goto out_release; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | rx_pool->rx_buff = kcalloc(rx_pool->size, |
| 707 | sizeof(struct ibmvnic_rx_buff), |
| 708 | GFP_KERNEL); |
| 709 | if (!rx_pool->rx_buff) { |
| 710 | dev_err(dev, "Couldn't alloc rx buffers\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 711 | rc = -ENOMEM; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 712 | goto out_release; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 713 | } |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | adapter->prev_rx_pool_size = pool_size; |
| 717 | adapter->prev_rx_buf_sz = adapter->cur_rx_buf_sz; |
| 718 | |
| 719 | update_ltb: |
| 720 | for (i = 0; i < num_pools; i++) { |
| 721 | rx_pool = &adapter->rx_pool[i]; |
| 722 | dev_dbg(dev, "Updating LTB for rx pool %d [%d, %d]\n", |
| 723 | i, rx_pool->size, rx_pool->buff_size); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 724 | |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 725 | rc = alloc_long_term_buff(adapter, &rx_pool->long_term_buff, |
| 726 | rx_pool->size * rx_pool->buff_size); |
| 727 | if (rc) |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 728 | goto out; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 729 | |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 730 | for (j = 0; j < rx_pool->size; ++j) { |
| 731 | struct ibmvnic_rx_buff *rx_buff; |
| 732 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 733 | rx_pool->free_map[j] = j; |
| 734 | |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 735 | /* NOTE: Don't clear rx_buff->skb here - will leak |
| 736 | * memory! replenish_rx_pool() will reuse skbs or |
| 737 | * allocate as necessary. |
| 738 | */ |
| 739 | rx_buff = &rx_pool->rx_buff[j]; |
| 740 | rx_buff->dma = 0; |
| 741 | rx_buff->data = 0; |
| 742 | rx_buff->size = 0; |
| 743 | rx_buff->pool_index = 0; |
| 744 | } |
| 745 | |
| 746 | /* Mark pool "empty" so replenish_rx_pools() will |
| 747 | * update the LTB info for each buffer |
| 748 | */ |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 749 | atomic_set(&rx_pool->available, 0); |
| 750 | rx_pool->next_alloc = 0; |
| 751 | rx_pool->next_free = 0; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 752 | /* replenish_rx_pool() may have called deactivate_rx_pools() |
| 753 | * on failover. Ensure pool is active now. |
| 754 | */ |
| 755 | rx_pool->active = 1; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 756 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 757 | return 0; |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 758 | out_release: |
| 759 | release_rx_pools(adapter); |
| 760 | out: |
| 761 | /* We failed to allocate one or more LTBs or map them on the VIOS. |
| 762 | * Hold onto the pools and any LTBs that we did allocate/map. |
| 763 | */ |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 764 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 765 | } |
| 766 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 767 | static void release_vpd_data(struct ibmvnic_adapter *adapter) |
| 768 | { |
| 769 | if (!adapter->vpd) |
| 770 | return; |
| 771 | |
| 772 | kfree(adapter->vpd->buff); |
| 773 | kfree(adapter->vpd); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 774 | |
| 775 | adapter->vpd = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 776 | } |
| 777 | |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 778 | static void release_one_tx_pool(struct ibmvnic_adapter *adapter, |
| 779 | struct ibmvnic_tx_pool *tx_pool) |
| 780 | { |
| 781 | kfree(tx_pool->tx_buff); |
| 782 | kfree(tx_pool->free_map); |
| 783 | free_long_term_buff(adapter, &tx_pool->long_term_buff); |
| 784 | } |
| 785 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 786 | /** |
| 787 | * release_tx_pools() - Release any tx pools attached to @adapter. |
| 788 | * @adapter: ibmvnic adapter |
| 789 | * |
| 790 | * Safe to call this multiple times - even if no pools are attached. |
| 791 | */ |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 792 | static void release_tx_pools(struct ibmvnic_adapter *adapter) |
| 793 | { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 794 | int i; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 795 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 796 | /* init_tx_pools() ensures that ->tx_pool and ->tso_pool are |
| 797 | * both NULL or both non-NULL. So we only need to check one. |
| 798 | */ |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 799 | if (!adapter->tx_pool) |
| 800 | return; |
| 801 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 802 | for (i = 0; i < adapter->num_active_tx_pools; i++) { |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 803 | release_one_tx_pool(adapter, &adapter->tx_pool[i]); |
| 804 | release_one_tx_pool(adapter, &adapter->tso_pool[i]); |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | kfree(adapter->tx_pool); |
| 808 | adapter->tx_pool = NULL; |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 809 | kfree(adapter->tso_pool); |
| 810 | adapter->tso_pool = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 811 | adapter->num_active_tx_pools = 0; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 812 | adapter->prev_tx_pool_size = 0; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 813 | } |
| 814 | |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 815 | static int init_one_tx_pool(struct net_device *netdev, |
| 816 | struct ibmvnic_tx_pool *tx_pool, |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 817 | int pool_size, int buf_size) |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 818 | { |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 819 | int i; |
| 820 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 821 | tx_pool->tx_buff = kcalloc(pool_size, |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 822 | sizeof(struct ibmvnic_tx_buff), |
| 823 | GFP_KERNEL); |
| 824 | if (!tx_pool->tx_buff) |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 825 | return -ENOMEM; |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 826 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 827 | tx_pool->free_map = kcalloc(pool_size, sizeof(int), GFP_KERNEL); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 828 | if (!tx_pool->free_map) { |
| 829 | kfree(tx_pool->tx_buff); |
| 830 | tx_pool->tx_buff = NULL; |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 831 | return -ENOMEM; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 832 | } |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 833 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 834 | for (i = 0; i < pool_size; i++) |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 835 | tx_pool->free_map[i] = i; |
| 836 | |
| 837 | tx_pool->consumer_index = 0; |
| 838 | tx_pool->producer_index = 0; |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 839 | tx_pool->num_buffers = pool_size; |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 840 | tx_pool->buf_size = buf_size; |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 845 | /** |
| 846 | * reuse_tx_pools() - Check if the existing tx pools can be reused. |
| 847 | * @adapter: ibmvnic adapter |
| 848 | * |
| 849 | * Check if the existing tx pools in the adapter can be reused. The |
| 850 | * pools can be reused if the pool parameters (number of pools, |
| 851 | * number of buffers in the pool and mtu) have not changed. |
| 852 | * |
| 853 | * NOTE: This assumes that all pools have the same number of buffers |
| 854 | * which is the case currently. If that changes, we must fix this. |
| 855 | * |
| 856 | * Return: true if the tx pools can be reused, false otherwise. |
| 857 | */ |
| 858 | static bool reuse_tx_pools(struct ibmvnic_adapter *adapter) |
| 859 | { |
| 860 | u64 old_num_pools, new_num_pools; |
| 861 | u64 old_pool_size, new_pool_size; |
| 862 | u64 old_mtu, new_mtu; |
| 863 | |
| 864 | if (!adapter->tx_pool) |
| 865 | return false; |
| 866 | |
| 867 | old_num_pools = adapter->num_active_tx_pools; |
| 868 | new_num_pools = adapter->num_active_tx_scrqs; |
| 869 | old_pool_size = adapter->prev_tx_pool_size; |
| 870 | new_pool_size = adapter->req_tx_entries_per_subcrq; |
| 871 | old_mtu = adapter->prev_mtu; |
| 872 | new_mtu = adapter->req_mtu; |
| 873 | |
Sukadev Bhattiprolu | 5b08560 | 2021-11-30 21:48:36 -0800 | [diff] [blame] | 874 | if (old_mtu != new_mtu || |
| 875 | old_num_pools != new_num_pools || |
| 876 | old_pool_size != new_pool_size) |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 877 | return false; |
| 878 | |
| 879 | return true; |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * init_tx_pools(): Initialize the set of transmit pools in the adapter. |
| 884 | * @netdev: net device associated with the vnic interface |
| 885 | * |
| 886 | * Initialize the set of transmit pools in the ibmvnic adapter associated |
| 887 | * with the net_device @netdev. If possible, reuse the existing tx pools. |
| 888 | * Otherwise free any existing pools and allocate a new set of pools |
| 889 | * before initializing them. |
| 890 | * |
| 891 | * Return: 0 on success and negative value on error. |
| 892 | */ |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 893 | static int init_tx_pools(struct net_device *netdev) |
| 894 | { |
| 895 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 896 | struct device *dev = &adapter->vdev->dev; |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 897 | int num_pools; |
| 898 | u64 pool_size; /* # of buffers in pool */ |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 899 | u64 buff_size; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 900 | int i, j, rc; |
| 901 | |
| 902 | num_pools = adapter->req_tx_queues; |
| 903 | |
| 904 | /* We must notify the VIOS about the LTB on all resets - but we only |
| 905 | * need to alloc/populate pools if either the number of buffers or |
| 906 | * size of each buffer in the pool has changed. |
| 907 | */ |
| 908 | if (reuse_tx_pools(adapter)) { |
| 909 | netdev_dbg(netdev, "Reusing tx pools\n"); |
| 910 | goto update_ltb; |
| 911 | } |
| 912 | |
| 913 | /* Allocate/populate the pools. */ |
| 914 | release_tx_pools(adapter); |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 915 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 916 | pool_size = adapter->req_tx_entries_per_subcrq; |
| 917 | num_pools = adapter->num_active_tx_scrqs; |
| 918 | |
| 919 | adapter->tx_pool = kcalloc(num_pools, |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 920 | sizeof(struct ibmvnic_tx_pool), GFP_KERNEL); |
| 921 | if (!adapter->tx_pool) |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 922 | return -ENOMEM; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 923 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 924 | adapter->tso_pool = kcalloc(num_pools, |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 925 | sizeof(struct ibmvnic_tx_pool), GFP_KERNEL); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 926 | /* To simplify release_tx_pools() ensure that ->tx_pool and |
| 927 | * ->tso_pool are either both NULL or both non-NULL. |
| 928 | */ |
Sukadev Bhattiprolu | f6ebca8 | 2021-06-23 21:13:15 -0700 | [diff] [blame] | 929 | if (!adapter->tso_pool) { |
| 930 | kfree(adapter->tx_pool); |
| 931 | adapter->tx_pool = NULL; |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 932 | return -ENOMEM; |
Sukadev Bhattiprolu | f6ebca8 | 2021-06-23 21:13:15 -0700 | [diff] [blame] | 933 | } |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 934 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 935 | /* Set num_active_tx_pools early. If we fail below after partial |
| 936 | * allocation, release_tx_pools() will know how many to look for. |
| 937 | */ |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 938 | adapter->num_active_tx_pools = num_pools; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 939 | |
Sukadev Bhattiprolu | 0d1af4f | 2021-09-14 20:52:55 -0700 | [diff] [blame] | 940 | buff_size = adapter->req_mtu + VLAN_HLEN; |
| 941 | buff_size = ALIGN(buff_size, L1_CACHE_BYTES); |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 942 | |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 943 | for (i = 0; i < num_pools; i++) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 944 | dev_dbg(dev, "Init tx pool %d [%llu, %llu]\n", |
| 945 | i, adapter->req_tx_entries_per_subcrq, buff_size); |
| 946 | |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 947 | rc = init_one_tx_pool(netdev, &adapter->tx_pool[i], |
Sukadev Bhattiprolu | 8243c7e | 2021-09-14 20:52:54 -0700 | [diff] [blame] | 948 | pool_size, buff_size); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 949 | if (rc) |
| 950 | goto out_release; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 951 | |
Thomas Falcon | 7c940b1 | 2019-06-07 16:03:55 -0500 | [diff] [blame] | 952 | rc = init_one_tx_pool(netdev, &adapter->tso_pool[i], |
| 953 | IBMVNIC_TSO_BUFS, |
| 954 | IBMVNIC_TSO_BUF_SZ); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 955 | if (rc) |
| 956 | goto out_release; |
| 957 | } |
| 958 | |
| 959 | adapter->prev_tx_pool_size = pool_size; |
| 960 | adapter->prev_mtu = adapter->req_mtu; |
| 961 | |
| 962 | update_ltb: |
| 963 | /* NOTE: All tx_pools have the same number of buffers (which is |
| 964 | * same as pool_size). All tso_pools have IBMVNIC_TSO_BUFS |
| 965 | * buffers (see calls init_one_tx_pool() for these). |
| 966 | * For consistency, we use tx_pool->num_buffers and |
| 967 | * tso_pool->num_buffers below. |
| 968 | */ |
| 969 | rc = -1; |
| 970 | for (i = 0; i < num_pools; i++) { |
| 971 | struct ibmvnic_tx_pool *tso_pool; |
| 972 | struct ibmvnic_tx_pool *tx_pool; |
| 973 | u32 ltb_size; |
| 974 | |
| 975 | tx_pool = &adapter->tx_pool[i]; |
| 976 | ltb_size = tx_pool->num_buffers * tx_pool->buf_size; |
| 977 | if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff, |
| 978 | ltb_size)) |
| 979 | goto out; |
| 980 | |
| 981 | dev_dbg(dev, "Updated LTB for tx pool %d [%p, %d, %d]\n", |
| 982 | i, tx_pool->long_term_buff.buff, |
| 983 | tx_pool->num_buffers, tx_pool->buf_size); |
| 984 | |
| 985 | tx_pool->consumer_index = 0; |
| 986 | tx_pool->producer_index = 0; |
| 987 | |
| 988 | for (j = 0; j < tx_pool->num_buffers; j++) |
| 989 | tx_pool->free_map[j] = j; |
| 990 | |
| 991 | tso_pool = &adapter->tso_pool[i]; |
| 992 | ltb_size = tso_pool->num_buffers * tso_pool->buf_size; |
| 993 | if (alloc_long_term_buff(adapter, &tso_pool->long_term_buff, |
| 994 | ltb_size)) |
| 995 | goto out; |
| 996 | |
| 997 | dev_dbg(dev, "Updated LTB for tso pool %d [%p, %d, %d]\n", |
| 998 | i, tso_pool->long_term_buff.buff, |
| 999 | tso_pool->num_buffers, tso_pool->buf_size); |
| 1000 | |
| 1001 | tso_pool->consumer_index = 0; |
| 1002 | tso_pool->producer_index = 0; |
| 1003 | |
| 1004 | for (j = 0; j < tso_pool->num_buffers; j++) |
| 1005 | tso_pool->free_map[j] = j; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | return 0; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 1009 | out_release: |
| 1010 | release_tx_pools(adapter); |
| 1011 | out: |
| 1012 | /* We failed to allocate one or more LTBs or map them on the VIOS. |
| 1013 | * Hold onto the pools and any LTBs that we did allocate/map. |
| 1014 | */ |
| 1015 | return rc; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 1018 | static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter) |
| 1019 | { |
| 1020 | int i; |
| 1021 | |
| 1022 | if (adapter->napi_enabled) |
| 1023 | return; |
| 1024 | |
| 1025 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 1026 | napi_enable(&adapter->napi[i]); |
| 1027 | |
| 1028 | adapter->napi_enabled = true; |
| 1029 | } |
| 1030 | |
| 1031 | static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter) |
| 1032 | { |
| 1033 | int i; |
| 1034 | |
| 1035 | if (!adapter->napi_enabled) |
| 1036 | return; |
| 1037 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1038 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 1039 | netdev_dbg(adapter->netdev, "Disabling napi[%d]\n", i); |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 1040 | napi_disable(&adapter->napi[i]); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1041 | } |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 1042 | |
| 1043 | adapter->napi_enabled = false; |
| 1044 | } |
| 1045 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1046 | static int init_napi(struct ibmvnic_adapter *adapter) |
| 1047 | { |
| 1048 | int i; |
| 1049 | |
| 1050 | adapter->napi = kcalloc(adapter->req_rx_queues, |
| 1051 | sizeof(struct napi_struct), GFP_KERNEL); |
| 1052 | if (!adapter->napi) |
| 1053 | return -ENOMEM; |
| 1054 | |
| 1055 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 1056 | netdev_dbg(adapter->netdev, "Adding napi[%d]\n", i); |
| 1057 | netif_napi_add(adapter->netdev, &adapter->napi[i], |
| 1058 | ibmvnic_poll, NAPI_POLL_WEIGHT); |
| 1059 | } |
| 1060 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 1061 | adapter->num_active_rx_napi = adapter->req_rx_queues; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | static void release_napi(struct ibmvnic_adapter *adapter) |
| 1066 | { |
| 1067 | int i; |
| 1068 | |
| 1069 | if (!adapter->napi) |
| 1070 | return; |
| 1071 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 1072 | for (i = 0; i < adapter->num_active_rx_napi; i++) { |
Wen Yang | 390de19 | 2018-12-11 12:20:46 +0800 | [diff] [blame] | 1073 | netdev_dbg(adapter->netdev, "Releasing napi[%d]\n", i); |
| 1074 | netif_napi_del(&adapter->napi[i]); |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | kfree(adapter->napi); |
| 1078 | adapter->napi = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 1079 | adapter->num_active_rx_napi = 0; |
Thomas Falcon | c3f2241 | 2018-05-23 13:37:55 -0500 | [diff] [blame] | 1080 | adapter->napi_enabled = false; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1081 | } |
| 1082 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1083 | static const char *adapter_state_to_string(enum vnic_state state) |
| 1084 | { |
| 1085 | switch (state) { |
| 1086 | case VNIC_PROBING: |
| 1087 | return "PROBING"; |
| 1088 | case VNIC_PROBED: |
| 1089 | return "PROBED"; |
| 1090 | case VNIC_OPENING: |
| 1091 | return "OPENING"; |
| 1092 | case VNIC_OPEN: |
| 1093 | return "OPEN"; |
| 1094 | case VNIC_CLOSING: |
| 1095 | return "CLOSING"; |
| 1096 | case VNIC_CLOSED: |
| 1097 | return "CLOSED"; |
| 1098 | case VNIC_REMOVING: |
| 1099 | return "REMOVING"; |
| 1100 | case VNIC_REMOVED: |
| 1101 | return "REMOVED"; |
Lijun Pan | 822ebc2 | 2021-06-11 10:35:37 -0500 | [diff] [blame] | 1102 | case VNIC_DOWN: |
| 1103 | return "DOWN"; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1104 | } |
Michal Suchanek | 07b5dc1 | 2021-05-20 08:50:34 +0200 | [diff] [blame] | 1105 | return "UNKNOWN"; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1106 | } |
| 1107 | |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 1108 | static int ibmvnic_login(struct net_device *netdev) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1109 | { |
| 1110 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 1111 | unsigned long timeout = msecs_to_jiffies(20000); |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1112 | int retry_count = 0; |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 1113 | int retries = 10; |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1114 | bool retry; |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1115 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1116 | |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1117 | do { |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1118 | retry = false; |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 1119 | if (retry_count > retries) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1120 | netdev_warn(netdev, "Login attempts exceeded\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1121 | return -EACCES; |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | adapter->init_done_rc = 0; |
| 1125 | reinit_completion(&adapter->init_done); |
| 1126 | rc = send_login(adapter); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 1127 | if (rc) |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1128 | return rc; |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1129 | |
| 1130 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 1131 | timeout)) { |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 1132 | netdev_warn(netdev, "Login timed out, retrying...\n"); |
| 1133 | retry = true; |
| 1134 | adapter->init_done_rc = 0; |
| 1135 | retry_count++; |
| 1136 | continue; |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1137 | } |
| 1138 | |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 1139 | if (adapter->init_done_rc == ABORTED) { |
| 1140 | netdev_warn(netdev, "Login aborted, retrying...\n"); |
| 1141 | retry = true; |
| 1142 | adapter->init_done_rc = 0; |
| 1143 | retry_count++; |
| 1144 | /* FW or device may be busy, so |
| 1145 | * wait a bit before retrying login |
| 1146 | */ |
| 1147 | msleep(500); |
| 1148 | } else if (adapter->init_done_rc == PARTIALSUCCESS) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1149 | retry_count++; |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 1150 | release_sub_crqs(adapter, 1); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1151 | |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1152 | retry = true; |
| 1153 | netdev_dbg(netdev, |
| 1154 | "Received partial success, retrying...\n"); |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1155 | adapter->init_done_rc = 0; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1156 | reinit_completion(&adapter->init_done); |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 1157 | send_query_cap(adapter); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1158 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 1159 | timeout)) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1160 | netdev_warn(netdev, |
| 1161 | "Capabilities query timed out\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1162 | return -ETIMEDOUT; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1163 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1164 | |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1165 | rc = init_sub_crqs(adapter); |
| 1166 | if (rc) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1167 | netdev_warn(netdev, |
| 1168 | "SCRQ initialization failed\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1169 | return rc; |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1170 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1171 | |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1172 | rc = init_sub_crq_irqs(adapter); |
| 1173 | if (rc) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1174 | netdev_warn(netdev, |
| 1175 | "SCRQ irq initialization failed\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1176 | return rc; |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1177 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1178 | } else if (adapter->init_done_rc) { |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1179 | netdev_warn(netdev, "Adapter login failed, init_done_rc = %d\n", |
| 1180 | adapter->init_done_rc); |
| 1181 | return -EIO; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1182 | } |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1183 | } while (retry); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1184 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 1185 | __ibmvnic_set_mac(netdev, adapter->mac_addr); |
Thomas Falcon | 3d16613 | 2018-01-10 19:39:52 -0600 | [diff] [blame] | 1186 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1187 | 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] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 1191 | static void release_login_buffer(struct ibmvnic_adapter *adapter) |
| 1192 | { |
| 1193 | kfree(adapter->login_buf); |
| 1194 | adapter->login_buf = NULL; |
| 1195 | } |
| 1196 | |
| 1197 | static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter) |
| 1198 | { |
| 1199 | kfree(adapter->login_rsp_buf); |
| 1200 | adapter->login_rsp_buf = NULL; |
| 1201 | } |
| 1202 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 1203 | static void release_resources(struct ibmvnic_adapter *adapter) |
| 1204 | { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1205 | release_vpd_data(adapter); |
| 1206 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1207 | release_napi(adapter); |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 1208 | release_login_buffer(adapter); |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 1209 | release_login_rsp_buffer(adapter); |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1212 | static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state) |
| 1213 | { |
| 1214 | struct net_device *netdev = adapter->netdev; |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 1215 | unsigned long timeout = msecs_to_jiffies(20000); |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1216 | union ibmvnic_crq crq; |
| 1217 | bool resend; |
| 1218 | int rc; |
| 1219 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1220 | netdev_dbg(netdev, "setting link state %d\n", link_state); |
| 1221 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1222 | memset(&crq, 0, sizeof(crq)); |
| 1223 | crq.logical_link_state.first = IBMVNIC_CRQ_CMD; |
| 1224 | crq.logical_link_state.cmd = LOGICAL_LINK_STATE; |
| 1225 | crq.logical_link_state.link_state = link_state; |
| 1226 | |
| 1227 | do { |
| 1228 | resend = false; |
| 1229 | |
| 1230 | reinit_completion(&adapter->init_done); |
| 1231 | rc = ibmvnic_send_crq(adapter, &crq); |
| 1232 | if (rc) { |
| 1233 | netdev_err(netdev, "Failed to set link state\n"); |
| 1234 | return rc; |
| 1235 | } |
| 1236 | |
| 1237 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 1238 | timeout)) { |
| 1239 | netdev_err(netdev, "timeout setting link state\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 1240 | return -ETIMEDOUT; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1241 | } |
| 1242 | |
Lijun Pan | 4c5f6af | 2020-08-19 17:52:23 -0500 | [diff] [blame] | 1243 | if (adapter->init_done_rc == PARTIALSUCCESS) { |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1244 | /* Partuial success, delay and re-send */ |
| 1245 | mdelay(1000); |
| 1246 | resend = true; |
Thomas Falcon | ab5ec33 | 2018-05-23 13:37:59 -0500 | [diff] [blame] | 1247 | } else if (adapter->init_done_rc) { |
| 1248 | netdev_warn(netdev, "Unable to set link state, rc=%d\n", |
| 1249 | adapter->init_done_rc); |
| 1250 | return adapter->init_done_rc; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1251 | } |
| 1252 | } while (resend); |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1257 | static int set_real_num_queues(struct net_device *netdev) |
| 1258 | { |
| 1259 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1260 | int rc; |
| 1261 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1262 | netdev_dbg(netdev, "Setting real tx/rx queues (%llx/%llx)\n", |
| 1263 | adapter->req_tx_queues, adapter->req_rx_queues); |
| 1264 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1265 | rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues); |
| 1266 | if (rc) { |
| 1267 | netdev_err(netdev, "failed to set the number of tx queues\n"); |
| 1268 | return rc; |
| 1269 | } |
| 1270 | |
| 1271 | rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues); |
| 1272 | if (rc) |
| 1273 | netdev_err(netdev, "failed to set the number of rx queues\n"); |
| 1274 | |
| 1275 | return rc; |
| 1276 | } |
| 1277 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1278 | static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) |
| 1279 | { |
| 1280 | struct device *dev = &adapter->vdev->dev; |
| 1281 | union ibmvnic_crq crq; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1282 | int len = 0; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1283 | int rc; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1284 | |
| 1285 | if (adapter->vpd->buff) |
| 1286 | len = adapter->vpd->len; |
| 1287 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1288 | mutex_lock(&adapter->fw_lock); |
| 1289 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 1290 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1291 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1292 | crq.get_vpd_size.first = IBMVNIC_CRQ_CMD; |
| 1293 | crq.get_vpd_size.cmd = GET_VPD_SIZE; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1294 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1295 | if (rc) { |
| 1296 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1297 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1298 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1299 | |
| 1300 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 1301 | if (rc) { |
| 1302 | dev_err(dev, "Could not retrieve VPD size, rc = %d\n", rc); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1303 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1304 | return rc; |
| 1305 | } |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1306 | mutex_unlock(&adapter->fw_lock); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1307 | |
| 1308 | if (!adapter->vpd->len) |
| 1309 | return -ENODATA; |
| 1310 | |
| 1311 | if (!adapter->vpd->buff) |
| 1312 | adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL); |
| 1313 | else if (adapter->vpd->len != len) |
| 1314 | adapter->vpd->buff = |
| 1315 | krealloc(adapter->vpd->buff, |
| 1316 | adapter->vpd->len, GFP_KERNEL); |
| 1317 | |
| 1318 | if (!adapter->vpd->buff) { |
| 1319 | dev_err(dev, "Could allocate VPD buffer\n"); |
| 1320 | return -ENOMEM; |
| 1321 | } |
| 1322 | |
| 1323 | adapter->vpd->dma_addr = |
| 1324 | dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len, |
| 1325 | DMA_FROM_DEVICE); |
Desnes Augusto Nunes do Rosario | f743106 | 2017-11-17 09:09:04 -0200 | [diff] [blame] | 1326 | if (dma_mapping_error(dev, adapter->vpd->dma_addr)) { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1327 | dev_err(dev, "Could not map VPD buffer\n"); |
| 1328 | kfree(adapter->vpd->buff); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 1329 | adapter->vpd->buff = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1330 | return -ENOMEM; |
| 1331 | } |
| 1332 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1333 | mutex_lock(&adapter->fw_lock); |
| 1334 | adapter->fw_done_rc = 0; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1335 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1336 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1337 | crq.get_vpd.first = IBMVNIC_CRQ_CMD; |
| 1338 | crq.get_vpd.cmd = GET_VPD; |
| 1339 | crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr); |
| 1340 | crq.get_vpd.len = cpu_to_be32((u32)adapter->vpd->len); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1341 | rc = ibmvnic_send_crq(adapter, &crq); |
| 1342 | if (rc) { |
| 1343 | kfree(adapter->vpd->buff); |
| 1344 | adapter->vpd->buff = NULL; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1345 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1346 | return rc; |
| 1347 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1348 | |
| 1349 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 1350 | if (rc) { |
| 1351 | dev_err(dev, "Unable to retrieve VPD, rc = %d\n", rc); |
| 1352 | kfree(adapter->vpd->buff); |
| 1353 | adapter->vpd->buff = NULL; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1354 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1355 | return rc; |
| 1356 | } |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1357 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1358 | mutex_unlock(&adapter->fw_lock); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1359 | return 0; |
| 1360 | } |
| 1361 | |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1362 | static int init_resources(struct ibmvnic_adapter *adapter) |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 1363 | { |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1364 | struct net_device *netdev = adapter->netdev; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1365 | int rc; |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 1366 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1367 | rc = set_real_num_queues(netdev); |
| 1368 | if (rc) |
| 1369 | return rc; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1370 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1371 | adapter->vpd = kzalloc(sizeof(*adapter->vpd), GFP_KERNEL); |
| 1372 | if (!adapter->vpd) |
| 1373 | return -ENOMEM; |
| 1374 | |
John Allen | 69d08dc | 2018-01-18 16:27:58 -0600 | [diff] [blame] | 1375 | /* Vital Product Data (VPD) */ |
| 1376 | rc = ibmvnic_get_vpd(adapter); |
| 1377 | if (rc) { |
| 1378 | netdev_err(netdev, "failed to initialize Vital Product Data (VPD)\n"); |
| 1379 | return rc; |
| 1380 | } |
| 1381 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1382 | rc = init_napi(adapter); |
| 1383 | if (rc) |
| 1384 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1385 | |
Lijun Pan | 69980d0 | 2020-09-27 20:13:28 -0500 | [diff] [blame] | 1386 | send_query_map(adapter); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 1387 | |
| 1388 | rc = init_rx_pools(netdev); |
| 1389 | if (rc) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1390 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1391 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 1392 | rc = init_tx_pools(netdev); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1393 | return rc; |
| 1394 | } |
| 1395 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1396 | static int __ibmvnic_open(struct net_device *netdev) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1397 | { |
| 1398 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1399 | enum vnic_state prev_state = adapter->state; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1400 | int i, rc; |
| 1401 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 1402 | adapter->state = VNIC_OPENING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1403 | replenish_pools(adapter); |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 1404 | ibmvnic_napi_enable(adapter); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1405 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1406 | /* We're ready to receive frames, enable the sub-crq interrupts and |
| 1407 | * set the logical link state to up |
| 1408 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1409 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1410 | netdev_dbg(netdev, "Enabling rx_scrq[%d] irq\n", i); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1411 | if (prev_state == VNIC_CLOSED) |
| 1412 | enable_irq(adapter->rx_scrq[i]->irq); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1413 | enable_scrq_irq(adapter, adapter->rx_scrq[i]); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1414 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1415 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1416 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1417 | netdev_dbg(netdev, "Enabling tx_scrq[%d] irq\n", i); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1418 | if (prev_state == VNIC_CLOSED) |
| 1419 | enable_irq(adapter->tx_scrq[i]->irq); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1420 | enable_scrq_irq(adapter, adapter->tx_scrq[i]); |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1421 | netdev_tx_reset_queue(netdev_get_tx_queue(netdev, i)); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1422 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1423 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1424 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1425 | if (rc) { |
Lijun Pan | 0775ebc | 2021-04-14 02:46:14 -0500 | [diff] [blame] | 1426 | ibmvnic_napi_disable(adapter); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1427 | release_resources(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1428 | return rc; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1429 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1430 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1431 | netif_tx_start_all_queues(netdev); |
| 1432 | |
Dany Madden | 2ca220f | 2021-06-23 21:13:11 -0700 | [diff] [blame] | 1433 | if (prev_state == VNIC_CLOSED) { |
| 1434 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 1435 | napi_schedule(&adapter->napi[i]); |
| 1436 | } |
| 1437 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1438 | adapter->state = VNIC_OPEN; |
| 1439 | return rc; |
| 1440 | } |
| 1441 | |
| 1442 | static int ibmvnic_open(struct net_device *netdev) |
| 1443 | { |
| 1444 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
John Allen | 69d08dc | 2018-01-18 16:27:58 -0600 | [diff] [blame] | 1445 | int rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1446 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1447 | ASSERT_RTNL(); |
| 1448 | |
| 1449 | /* If device failover is pending or we are about to reset, just set |
| 1450 | * device state and return. Device operation will be handled by reset |
| 1451 | * routine. |
| 1452 | * |
| 1453 | * It should be safe to overwrite the adapter->state here. Since |
| 1454 | * we hold the rtnl, either the reset has not actually started or |
| 1455 | * the rtnl got dropped during the set_link_state() in do_reset(). |
| 1456 | * In the former case, no one else is changing the state (again we |
| 1457 | * have the rtnl) and in the latter case, do_reset() will detect and |
| 1458 | * honor our setting below. |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1459 | */ |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1460 | if (adapter->failover_pending || (test_bit(0, &adapter->resetting))) { |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1461 | netdev_dbg(netdev, "[S:%s FOP:%d] Resetting, deferring open\n", |
| 1462 | adapter_state_to_string(adapter->state), |
| 1463 | adapter->failover_pending); |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1464 | adapter->state = VNIC_OPEN; |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1465 | rc = 0; |
| 1466 | goto out; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1469 | if (adapter->state != VNIC_CLOSED) { |
| 1470 | rc = ibmvnic_login(netdev); |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 1471 | if (rc) |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1472 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1473 | |
| 1474 | rc = init_resources(adapter); |
| 1475 | if (rc) { |
| 1476 | netdev_err(netdev, "failed to initialize resources\n"); |
| 1477 | release_resources(adapter); |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 1478 | release_rx_pools(adapter); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 1479 | release_tx_pools(adapter); |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1480 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | rc = __ibmvnic_open(netdev); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1485 | |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1486 | out: |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1487 | /* If open failed and there is a pending failover or in-progress reset, |
| 1488 | * set device state and return. Device operation will be handled by |
| 1489 | * reset routine. See also comments above regarding rtnl. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1490 | */ |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1491 | if (rc && |
| 1492 | (adapter->failover_pending || (test_bit(0, &adapter->resetting)))) { |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1493 | adapter->state = VNIC_OPEN; |
| 1494 | rc = 0; |
| 1495 | } |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1496 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1497 | } |
| 1498 | |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1499 | static void clean_rx_pools(struct ibmvnic_adapter *adapter) |
| 1500 | { |
| 1501 | struct ibmvnic_rx_pool *rx_pool; |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1502 | struct ibmvnic_rx_buff *rx_buff; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1503 | u64 rx_entries; |
| 1504 | int rx_scrqs; |
| 1505 | int i, j; |
| 1506 | |
| 1507 | if (!adapter->rx_pool) |
| 1508 | return; |
| 1509 | |
Thomas Falcon | 660e309 | 2018-04-20 14:25:32 -0500 | [diff] [blame] | 1510 | rx_scrqs = adapter->num_active_rx_pools; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1511 | rx_entries = adapter->req_rx_add_entries_per_subcrq; |
| 1512 | |
| 1513 | /* Free any remaining skbs in the rx buffer pools */ |
| 1514 | for (i = 0; i < rx_scrqs; i++) { |
| 1515 | rx_pool = &adapter->rx_pool[i]; |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1516 | if (!rx_pool || !rx_pool->rx_buff) |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1517 | continue; |
| 1518 | |
| 1519 | netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i); |
| 1520 | for (j = 0; j < rx_entries; j++) { |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1521 | rx_buff = &rx_pool->rx_buff[j]; |
| 1522 | if (rx_buff && rx_buff->skb) { |
| 1523 | dev_kfree_skb_any(rx_buff->skb); |
| 1524 | rx_buff->skb = NULL; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1530 | static void clean_one_tx_pool(struct ibmvnic_adapter *adapter, |
| 1531 | struct ibmvnic_tx_pool *tx_pool) |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1532 | { |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1533 | struct ibmvnic_tx_buff *tx_buff; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1534 | u64 tx_entries; |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1535 | int i; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1536 | |
Dan Carpenter | 050e85c | 2018-03-23 14:36:15 +0300 | [diff] [blame] | 1537 | if (!tx_pool || !tx_pool->tx_buff) |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1538 | return; |
| 1539 | |
| 1540 | tx_entries = tx_pool->num_buffers; |
| 1541 | |
| 1542 | for (i = 0; i < tx_entries; i++) { |
| 1543 | tx_buff = &tx_pool->tx_buff[i]; |
| 1544 | if (tx_buff && tx_buff->skb) { |
| 1545 | dev_kfree_skb_any(tx_buff->skb); |
| 1546 | tx_buff->skb = NULL; |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | static void clean_tx_pools(struct ibmvnic_adapter *adapter) |
| 1552 | { |
| 1553 | int tx_scrqs; |
| 1554 | int i; |
| 1555 | |
| 1556 | if (!adapter->tx_pool || !adapter->tso_pool) |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1557 | return; |
| 1558 | |
Thomas Falcon | 660e309 | 2018-04-20 14:25:32 -0500 | [diff] [blame] | 1559 | tx_scrqs = adapter->num_active_tx_pools; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1560 | |
| 1561 | /* Free any remaining skbs in the tx buffer pools */ |
| 1562 | for (i = 0; i < tx_scrqs; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1563 | netdev_dbg(adapter->netdev, "Cleaning tx_pool[%d]\n", i); |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1564 | clean_one_tx_pool(adapter, &adapter->tx_pool[i]); |
| 1565 | clean_one_tx_pool(adapter, &adapter->tso_pool[i]); |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1569 | static void ibmvnic_disable_irqs(struct ibmvnic_adapter *adapter) |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 1570 | { |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1571 | struct net_device *netdev = adapter->netdev; |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 1572 | int i; |
| 1573 | |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1574 | if (adapter->tx_scrq) { |
| 1575 | for (i = 0; i < adapter->req_tx_queues; i++) |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1576 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | f873866 | 2018-03-07 17:51:45 -0600 | [diff] [blame] | 1577 | netdev_dbg(netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1578 | "Disabling tx_scrq[%d] irq\n", i); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1579 | disable_scrq_irq(adapter, adapter->tx_scrq[i]); |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1580 | disable_irq(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1581 | } |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1582 | } |
| 1583 | |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1584 | if (adapter->rx_scrq) { |
| 1585 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1586 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | f873866 | 2018-03-07 17:51:45 -0600 | [diff] [blame] | 1587 | netdev_dbg(netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1588 | "Disabling rx_scrq[%d] irq\n", i); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1589 | disable_scrq_irq(adapter, adapter->rx_scrq[i]); |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1590 | disable_irq(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1591 | } |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1592 | } |
| 1593 | } |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | static void ibmvnic_cleanup(struct net_device *netdev) |
| 1597 | { |
| 1598 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1599 | |
| 1600 | /* ensure that transmissions are stopped if called by do_reset */ |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 1601 | if (test_bit(0, &adapter->resetting)) |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1602 | netif_tx_disable(netdev); |
| 1603 | else |
| 1604 | netif_tx_stop_all_queues(netdev); |
| 1605 | |
| 1606 | ibmvnic_napi_disable(adapter); |
| 1607 | ibmvnic_disable_irqs(adapter); |
Thomas Falcon | 01d9bd7 | 2018-03-07 17:51:46 -0600 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | static int __ibmvnic_close(struct net_device *netdev) |
| 1611 | { |
| 1612 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1613 | int rc = 0; |
| 1614 | |
| 1615 | adapter->state = VNIC_CLOSING; |
| 1616 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 1617 | adapter->state = VNIC_CLOSED; |
Sukadev Bhattiprolu | d4083d3 | 2021-02-10 17:41:43 -0800 | [diff] [blame] | 1618 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1619 | } |
| 1620 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1621 | static int ibmvnic_close(struct net_device *netdev) |
| 1622 | { |
| 1623 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1624 | int rc; |
| 1625 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1626 | netdev_dbg(netdev, "[S:%s FOP:%d FRR:%d] Closing\n", |
| 1627 | adapter_state_to_string(adapter->state), |
| 1628 | adapter->failover_pending, |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 1629 | adapter->force_reset_recovery); |
| 1630 | |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1631 | /* If device failover is pending, just set device state and return. |
| 1632 | * Device operation will be handled by reset routine. |
| 1633 | */ |
| 1634 | if (adapter->failover_pending) { |
| 1635 | adapter->state = VNIC_CLOSED; |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1639 | rc = __ibmvnic_close(netdev); |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 1640 | ibmvnic_cleanup(netdev); |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 1641 | clean_rx_pools(adapter); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 1642 | clean_tx_pools(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1643 | |
| 1644 | return rc; |
| 1645 | } |
| 1646 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1647 | /** |
| 1648 | * build_hdr_data - creates L2/L3/L4 header data buffer |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1649 | * @hdr_field: bitfield determining needed headers |
| 1650 | * @skb: socket buffer |
| 1651 | * @hdr_len: array of header lengths |
| 1652 | * @hdr_data: buffer to write the header to |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1653 | * |
| 1654 | * Reads hdr_field to determine which headers are needed by firmware. |
| 1655 | * Builds a buffer containing these headers. Saves individual header |
| 1656 | * lengths and total buffer length to be used to build descriptors. |
| 1657 | */ |
| 1658 | static int build_hdr_data(u8 hdr_field, struct sk_buff *skb, |
| 1659 | int *hdr_len, u8 *hdr_data) |
| 1660 | { |
| 1661 | int len = 0; |
| 1662 | u8 *hdr; |
| 1663 | |
Thomas Falcon | da75e3b | 2018-03-12 11:51:02 -0500 | [diff] [blame] | 1664 | if (skb_vlan_tagged(skb) && !skb_vlan_tag_present(skb)) |
| 1665 | hdr_len[0] = sizeof(struct vlan_ethhdr); |
| 1666 | else |
| 1667 | hdr_len[0] = sizeof(struct ethhdr); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1668 | |
| 1669 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1670 | hdr_len[1] = ip_hdr(skb)->ihl * 4; |
| 1671 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 1672 | hdr_len[2] = tcp_hdrlen(skb); |
| 1673 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 1674 | hdr_len[2] = sizeof(struct udphdr); |
| 1675 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 1676 | hdr_len[1] = sizeof(struct ipv6hdr); |
| 1677 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 1678 | hdr_len[2] = tcp_hdrlen(skb); |
| 1679 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) |
| 1680 | hdr_len[2] = sizeof(struct udphdr); |
Thomas Falcon | 4eb50ce | 2017-12-18 12:52:40 -0600 | [diff] [blame] | 1681 | } else if (skb->protocol == htons(ETH_P_ARP)) { |
| 1682 | hdr_len[1] = arp_hdr_len(skb->dev); |
| 1683 | hdr_len[2] = 0; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | memset(hdr_data, 0, 120); |
| 1687 | if ((hdr_field >> 6) & 1) { |
| 1688 | hdr = skb_mac_header(skb); |
| 1689 | memcpy(hdr_data, hdr, hdr_len[0]); |
| 1690 | len += hdr_len[0]; |
| 1691 | } |
| 1692 | |
| 1693 | if ((hdr_field >> 5) & 1) { |
| 1694 | hdr = skb_network_header(skb); |
| 1695 | memcpy(hdr_data + len, hdr, hdr_len[1]); |
| 1696 | len += hdr_len[1]; |
| 1697 | } |
| 1698 | |
| 1699 | if ((hdr_field >> 4) & 1) { |
| 1700 | hdr = skb_transport_header(skb); |
| 1701 | memcpy(hdr_data + len, hdr, hdr_len[2]); |
| 1702 | len += hdr_len[2]; |
| 1703 | } |
| 1704 | return len; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * create_hdr_descs - create header and header extension descriptors |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1709 | * @hdr_field: bitfield determining needed headers |
| 1710 | * @hdr_data: buffer containing header data |
| 1711 | * @len: length of data buffer |
| 1712 | * @hdr_len: array of individual header lengths |
| 1713 | * @scrq_arr: descriptor array |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1714 | * |
| 1715 | * Creates header and, if needed, header extension descriptors and |
| 1716 | * places them in a descriptor array, scrq_arr |
| 1717 | */ |
| 1718 | |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1719 | static int create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len, |
| 1720 | union sub_crq *scrq_arr) |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1721 | { |
| 1722 | union sub_crq hdr_desc; |
| 1723 | int tmp_len = len; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1724 | int num_descs = 0; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1725 | u8 *data, *cur; |
| 1726 | int tmp; |
| 1727 | |
| 1728 | while (tmp_len > 0) { |
| 1729 | cur = hdr_data + len - tmp_len; |
| 1730 | |
| 1731 | memset(&hdr_desc, 0, sizeof(hdr_desc)); |
| 1732 | if (cur != hdr_data) { |
| 1733 | data = hdr_desc.hdr_ext.data; |
| 1734 | tmp = tmp_len > 29 ? 29 : tmp_len; |
| 1735 | hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD; |
| 1736 | hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC; |
| 1737 | hdr_desc.hdr_ext.len = tmp; |
| 1738 | } else { |
| 1739 | data = hdr_desc.hdr.data; |
| 1740 | tmp = tmp_len > 24 ? 24 : tmp_len; |
| 1741 | hdr_desc.hdr.first = IBMVNIC_CRQ_CMD; |
| 1742 | hdr_desc.hdr.type = IBMVNIC_HDR_DESC; |
| 1743 | hdr_desc.hdr.len = tmp; |
| 1744 | hdr_desc.hdr.l2_len = (u8)hdr_len[0]; |
| 1745 | hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]); |
| 1746 | hdr_desc.hdr.l4_len = (u8)hdr_len[2]; |
| 1747 | hdr_desc.hdr.flag = hdr_field << 1; |
| 1748 | } |
| 1749 | memcpy(data, cur, tmp); |
| 1750 | tmp_len -= tmp; |
| 1751 | *scrq_arr = hdr_desc; |
| 1752 | scrq_arr++; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1753 | num_descs++; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1754 | } |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1755 | |
| 1756 | return num_descs; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | /** |
| 1760 | * build_hdr_descs_arr - build a header descriptor array |
Lijun Pan | 73214a6 | 2021-06-11 10:43:39 -0500 | [diff] [blame] | 1761 | * @skb: tx socket buffer |
| 1762 | * @indir_arr: indirect array |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1763 | * @num_entries: number of descriptors to be sent |
| 1764 | * @hdr_field: bit field determining which headers will be sent |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1765 | * |
| 1766 | * This function will build a TX descriptor array with applicable |
| 1767 | * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect. |
| 1768 | */ |
| 1769 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1770 | static void build_hdr_descs_arr(struct sk_buff *skb, |
| 1771 | union sub_crq *indir_arr, |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1772 | int *num_entries, u8 hdr_field) |
| 1773 | { |
| 1774 | int hdr_len[3] = {0, 0, 0}; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1775 | u8 hdr_data[140] = {0}; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1776 | int tot_len; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1777 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1778 | tot_len = build_hdr_data(hdr_field, skb, hdr_len, |
| 1779 | hdr_data); |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1780 | *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] | 1781 | indir_arr + 1); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1782 | } |
| 1783 | |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1784 | static int ibmvnic_xmit_workarounds(struct sk_buff *skb, |
| 1785 | struct net_device *netdev) |
| 1786 | { |
| 1787 | /* For some backing devices, mishandling of small packets |
| 1788 | * can result in a loss of connection or TX stall. Device |
| 1789 | * architects recommend that no packet should be smaller |
| 1790 | * than the minimum MTU value provided to the driver, so |
| 1791 | * pad any packets to that length |
| 1792 | */ |
| 1793 | if (skb->len < netdev->min_mtu) |
| 1794 | return skb_put_padto(skb, netdev->min_mtu); |
Thomas Falcon | 7083a45 | 2018-03-12 21:05:26 -0500 | [diff] [blame] | 1795 | |
| 1796 | return 0; |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1797 | } |
| 1798 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1799 | static void ibmvnic_tx_scrq_clean_buffer(struct ibmvnic_adapter *adapter, |
| 1800 | struct ibmvnic_sub_crq_queue *tx_scrq) |
| 1801 | { |
| 1802 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 1803 | struct ibmvnic_tx_buff *tx_buff; |
| 1804 | struct ibmvnic_tx_pool *tx_pool; |
| 1805 | union sub_crq tx_scrq_entry; |
| 1806 | int queue_num; |
| 1807 | int entries; |
| 1808 | int index; |
| 1809 | int i; |
| 1810 | |
| 1811 | ind_bufp = &tx_scrq->ind_buf; |
| 1812 | entries = (u64)ind_bufp->index; |
| 1813 | queue_num = tx_scrq->pool_index; |
| 1814 | |
| 1815 | for (i = entries - 1; i >= 0; --i) { |
| 1816 | tx_scrq_entry = ind_bufp->indir_arr[i]; |
| 1817 | if (tx_scrq_entry.v1.type != IBMVNIC_TX_DESC) |
| 1818 | continue; |
| 1819 | index = be32_to_cpu(tx_scrq_entry.v1.correlator); |
| 1820 | if (index & IBMVNIC_TSO_POOL_MASK) { |
| 1821 | tx_pool = &adapter->tso_pool[queue_num]; |
| 1822 | index &= ~IBMVNIC_TSO_POOL_MASK; |
| 1823 | } else { |
| 1824 | tx_pool = &adapter->tx_pool[queue_num]; |
| 1825 | } |
| 1826 | tx_pool->free_map[tx_pool->consumer_index] = index; |
| 1827 | tx_pool->consumer_index = tx_pool->consumer_index == 0 ? |
| 1828 | tx_pool->num_buffers - 1 : |
| 1829 | tx_pool->consumer_index - 1; |
| 1830 | tx_buff = &tx_pool->tx_buff[index]; |
| 1831 | adapter->netdev->stats.tx_packets--; |
| 1832 | adapter->netdev->stats.tx_bytes -= tx_buff->skb->len; |
| 1833 | adapter->tx_stats_buffers[queue_num].packets--; |
| 1834 | adapter->tx_stats_buffers[queue_num].bytes -= |
| 1835 | tx_buff->skb->len; |
| 1836 | dev_kfree_skb_any(tx_buff->skb); |
| 1837 | tx_buff->skb = NULL; |
| 1838 | adapter->netdev->stats.tx_dropped++; |
| 1839 | } |
| 1840 | ind_bufp->index = 0; |
| 1841 | if (atomic_sub_return(entries, &tx_scrq->used) <= |
| 1842 | (adapter->req_tx_entries_per_subcrq / 2) && |
Sukadev Bhattiprolu | 65d6470 | 2021-06-23 21:13:12 -0700 | [diff] [blame] | 1843 | __netif_subqueue_stopped(adapter->netdev, queue_num) && |
| 1844 | !test_bit(0, &adapter->resetting)) { |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1845 | netif_wake_subqueue(adapter->netdev, queue_num); |
| 1846 | netdev_dbg(adapter->netdev, "Started queue %d\n", |
| 1847 | queue_num); |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | static int ibmvnic_tx_scrq_flush(struct ibmvnic_adapter *adapter, |
| 1852 | struct ibmvnic_sub_crq_queue *tx_scrq) |
| 1853 | { |
| 1854 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 1855 | u64 dma_addr; |
| 1856 | u64 entries; |
| 1857 | u64 handle; |
| 1858 | int rc; |
| 1859 | |
| 1860 | ind_bufp = &tx_scrq->ind_buf; |
| 1861 | dma_addr = (u64)ind_bufp->indir_dma; |
| 1862 | entries = (u64)ind_bufp->index; |
| 1863 | handle = tx_scrq->handle; |
| 1864 | |
| 1865 | if (!entries) |
| 1866 | return 0; |
| 1867 | rc = send_subcrq_indirect(adapter, handle, dma_addr, entries); |
| 1868 | if (rc) |
| 1869 | ibmvnic_tx_scrq_clean_buffer(adapter, tx_scrq); |
| 1870 | else |
| 1871 | ind_bufp->index = 0; |
| 1872 | return 0; |
| 1873 | } |
| 1874 | |
YueHaibing | 94b2bb2 | 2018-09-18 14:35:47 +0800 | [diff] [blame] | 1875 | 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] | 1876 | { |
| 1877 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1878 | int queue_num = skb_get_queue_mapping(skb); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1879 | u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1880 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1881 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1882 | struct ibmvnic_tx_buff *tx_buff = NULL; |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1883 | struct ibmvnic_sub_crq_queue *tx_scrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1884 | struct ibmvnic_tx_pool *tx_pool; |
| 1885 | unsigned int tx_send_failed = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1886 | netdev_tx_t ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1887 | unsigned int tx_map_failed = 0; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1888 | union sub_crq indir_arr[16]; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1889 | unsigned int tx_dropped = 0; |
| 1890 | unsigned int tx_packets = 0; |
| 1891 | unsigned int tx_bytes = 0; |
| 1892 | dma_addr_t data_dma_addr; |
| 1893 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1894 | unsigned long lpar_rc; |
| 1895 | union sub_crq tx_crq; |
| 1896 | unsigned int offset; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1897 | int num_entries = 1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1898 | unsigned char *dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1899 | int index = 0; |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 1900 | u8 proto = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1901 | |
| 1902 | tx_scrq = adapter->tx_scrq[queue_num]; |
| 1903 | txq = netdev_get_tx_queue(netdev, queue_num); |
| 1904 | ind_bufp = &tx_scrq->ind_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1905 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 1906 | if (test_bit(0, &adapter->resetting)) { |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1907 | dev_kfree_skb_any(skb); |
| 1908 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1909 | tx_send_failed++; |
| 1910 | tx_dropped++; |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1911 | ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1912 | goto out; |
| 1913 | } |
| 1914 | |
Thomas Falcon | 7083a45 | 2018-03-12 21:05:26 -0500 | [diff] [blame] | 1915 | if (ibmvnic_xmit_workarounds(skb, netdev)) { |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1916 | tx_dropped++; |
| 1917 | tx_send_failed++; |
| 1918 | ret = NETDEV_TX_OK; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1919 | ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1920 | goto out; |
| 1921 | } |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1922 | if (skb_is_gso(skb)) |
| 1923 | tx_pool = &adapter->tso_pool[queue_num]; |
| 1924 | else |
| 1925 | tx_pool = &adapter->tx_pool[queue_num]; |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1926 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1927 | index = tx_pool->free_map[tx_pool->consumer_index]; |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1928 | |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 1929 | if (index == IBMVNIC_INVALID_MAP) { |
| 1930 | dev_kfree_skb_any(skb); |
| 1931 | tx_send_failed++; |
| 1932 | tx_dropped++; |
Sukadev Bhattiprolu | bb55362 | 2021-07-20 19:34:39 -0700 | [diff] [blame] | 1933 | ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 1934 | ret = NETDEV_TX_OK; |
| 1935 | goto out; |
| 1936 | } |
| 1937 | |
| 1938 | tx_pool->free_map[tx_pool->consumer_index] = IBMVNIC_INVALID_MAP; |
| 1939 | |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1940 | offset = index * tx_pool->buf_size; |
| 1941 | dst = tx_pool->long_term_buff.buff + offset; |
| 1942 | memset(dst, 0, tx_pool->buf_size); |
| 1943 | data_dma_addr = tx_pool->long_term_buff.addr + offset; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1944 | |
Thomas Falcon | 1548205 | 2017-10-17 12:36:54 -0500 | [diff] [blame] | 1945 | if (skb_shinfo(skb)->nr_frags) { |
| 1946 | int cur, i; |
| 1947 | |
| 1948 | /* Copy the head */ |
| 1949 | skb_copy_from_linear_data(skb, dst, skb_headlen(skb)); |
| 1950 | cur = skb_headlen(skb); |
| 1951 | |
| 1952 | /* Copy the frags */ |
| 1953 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1954 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1955 | |
Christophe JAILLET | c3105f8 | 2021-04-04 10:54:37 +0200 | [diff] [blame] | 1956 | memcpy(dst + cur, skb_frag_address(frag), |
| 1957 | skb_frag_size(frag)); |
Thomas Falcon | 1548205 | 2017-10-17 12:36:54 -0500 | [diff] [blame] | 1958 | cur += skb_frag_size(frag); |
| 1959 | } |
| 1960 | } else { |
| 1961 | skb_copy_from_linear_data(skb, dst, skb->len); |
| 1962 | } |
| 1963 | |
Lijun Pan | 42557da | 2021-02-12 20:48:40 -0600 | [diff] [blame] | 1964 | /* post changes to long_term_buff *dst before VIOS accessing it */ |
| 1965 | dma_wmb(); |
| 1966 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1967 | tx_pool->consumer_index = |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1968 | (tx_pool->consumer_index + 1) % tx_pool->num_buffers; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1969 | |
| 1970 | tx_buff = &tx_pool->tx_buff[index]; |
| 1971 | tx_buff->skb = skb; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1972 | tx_buff->index = index; |
| 1973 | tx_buff->pool_index = queue_num; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1974 | |
| 1975 | memset(&tx_crq, 0, sizeof(tx_crq)); |
| 1976 | tx_crq.v1.first = IBMVNIC_CRQ_CMD; |
| 1977 | tx_crq.v1.type = IBMVNIC_TX_DESC; |
| 1978 | tx_crq.v1.n_crq_elem = 1; |
| 1979 | tx_crq.v1.n_sge = 1; |
| 1980 | tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED; |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1981 | |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1982 | if (skb_is_gso(skb)) |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1983 | tx_crq.v1.correlator = |
| 1984 | cpu_to_be32(index | IBMVNIC_TSO_POOL_MASK); |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1985 | else |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1986 | tx_crq.v1.correlator = cpu_to_be32(index); |
| 1987 | 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] | 1988 | tx_crq.v1.sge_len = cpu_to_be32(skb->len); |
| 1989 | tx_crq.v1.ioba = cpu_to_be64(data_dma_addr); |
| 1990 | |
Michał Mirosław | e84b479 | 2018-11-07 17:50:52 +0100 | [diff] [blame] | 1991 | if (adapter->vlan_header_insertion && skb_vlan_tag_present(skb)) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1992 | tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT; |
| 1993 | tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci); |
| 1994 | } |
| 1995 | |
| 1996 | if (skb->protocol == htons(ETH_P_IP)) { |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 1997 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4; |
| 1998 | proto = ip_hdr(skb)->protocol; |
| 1999 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 2000 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6; |
| 2001 | proto = ipv6_hdr(skb)->nexthdr; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2002 | } |
| 2003 | |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 2004 | if (proto == IPPROTO_TCP) |
| 2005 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP; |
| 2006 | else if (proto == IPPROTO_UDP) |
| 2007 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP; |
| 2008 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 2009 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2010 | tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 2011 | hdrs += 2; |
| 2012 | } |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 2013 | if (skb_is_gso(skb)) { |
| 2014 | tx_crq.v1.flags1 |= IBMVNIC_TX_LSO; |
| 2015 | tx_crq.v1.mss = cpu_to_be16(skb_shinfo(skb)->gso_size); |
| 2016 | hdrs += 2; |
| 2017 | } |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 2018 | |
| 2019 | if ((*hdrs >> 7) & 1) |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 2020 | build_hdr_descs_arr(skb, indir_arr, &num_entries, *hdrs); |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 2021 | |
| 2022 | tx_crq.v1.n_crq_elem = num_entries; |
| 2023 | tx_buff->num_entries = num_entries; |
| 2024 | /* flush buffer if current entry can not fit */ |
| 2025 | if (num_entries + ind_bufp->index > IBMVNIC_MAX_IND_DESCS) { |
| 2026 | lpar_rc = ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
| 2027 | if (lpar_rc != H_SUCCESS) |
| 2028 | goto tx_flush_err; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 2029 | } |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 2030 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 2031 | indir_arr[0] = tx_crq; |
| 2032 | memcpy(&ind_bufp->indir_arr[ind_bufp->index], &indir_arr[0], |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 2033 | num_entries * sizeof(struct ibmvnic_generic_scrq)); |
| 2034 | ind_bufp->index += num_entries; |
| 2035 | if (__netdev_tx_sent_queue(txq, skb->len, |
| 2036 | netdev_xmit_more() && |
| 2037 | ind_bufp->index < IBMVNIC_MAX_IND_DESCS)) { |
| 2038 | lpar_rc = ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
| 2039 | if (lpar_rc != H_SUCCESS) |
| 2040 | goto tx_err; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2041 | } |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 2042 | |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 2043 | if (atomic_add_return(num_entries, &tx_scrq->used) |
Brian King | 58c8c0c | 2017-04-19 13:44:47 -0400 | [diff] [blame] | 2044 | >= adapter->req_tx_entries_per_subcrq) { |
Thomas Falcon | 0aecb13 | 2018-02-26 18:10:58 -0600 | [diff] [blame] | 2045 | netdev_dbg(netdev, "Stopping queue %d\n", queue_num); |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 2046 | netif_stop_subqueue(netdev, queue_num); |
| 2047 | } |
| 2048 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2049 | tx_packets++; |
| 2050 | tx_bytes += skb->len; |
Eric Dumazet | 5337824 | 2021-11-16 19:29:22 -0800 | [diff] [blame] | 2051 | txq_trans_cond_update(txq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2052 | ret = NETDEV_TX_OK; |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 2053 | goto out; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2054 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 2055 | tx_flush_err: |
| 2056 | dev_kfree_skb_any(skb); |
| 2057 | tx_buff->skb = NULL; |
| 2058 | tx_pool->consumer_index = tx_pool->consumer_index == 0 ? |
| 2059 | tx_pool->num_buffers - 1 : |
| 2060 | tx_pool->consumer_index - 1; |
| 2061 | tx_dropped++; |
| 2062 | tx_err: |
| 2063 | if (lpar_rc != H_CLOSED && lpar_rc != H_PARAMETER) |
| 2064 | dev_err_ratelimited(dev, "tx: send failed\n"); |
| 2065 | |
| 2066 | if (lpar_rc == H_CLOSED || adapter->failover_pending) { |
| 2067 | /* Disable TX and report carrier off if queue is closed |
| 2068 | * or pending failover. |
| 2069 | * Firmware guarantees that a signal will be sent to the |
| 2070 | * driver, triggering a reset or some other action. |
| 2071 | */ |
| 2072 | netif_tx_stop_all_queues(netdev); |
| 2073 | netif_carrier_off(netdev); |
| 2074 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2075 | out: |
| 2076 | netdev->stats.tx_dropped += tx_dropped; |
| 2077 | netdev->stats.tx_bytes += tx_bytes; |
| 2078 | netdev->stats.tx_packets += tx_packets; |
| 2079 | adapter->tx_send_failed += tx_send_failed; |
| 2080 | adapter->tx_map_failed += tx_map_failed; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2081 | adapter->tx_stats_buffers[queue_num].packets += tx_packets; |
| 2082 | adapter->tx_stats_buffers[queue_num].bytes += tx_bytes; |
| 2083 | adapter->tx_stats_buffers[queue_num].dropped_packets += tx_dropped; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2084 | |
| 2085 | return ret; |
| 2086 | } |
| 2087 | |
| 2088 | static void ibmvnic_set_multi(struct net_device *netdev) |
| 2089 | { |
| 2090 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2091 | struct netdev_hw_addr *ha; |
| 2092 | union ibmvnic_crq crq; |
| 2093 | |
| 2094 | memset(&crq, 0, sizeof(crq)); |
| 2095 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 2096 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 2097 | |
| 2098 | if (netdev->flags & IFF_PROMISC) { |
| 2099 | if (!adapter->promisc_supported) |
| 2100 | return; |
| 2101 | } else { |
| 2102 | if (netdev->flags & IFF_ALLMULTI) { |
| 2103 | /* Accept all multicast */ |
| 2104 | memset(&crq, 0, sizeof(crq)); |
| 2105 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 2106 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 2107 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL; |
| 2108 | ibmvnic_send_crq(adapter, &crq); |
| 2109 | } else if (netdev_mc_empty(netdev)) { |
| 2110 | /* Reject all multicast */ |
| 2111 | memset(&crq, 0, sizeof(crq)); |
| 2112 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 2113 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 2114 | crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL; |
| 2115 | ibmvnic_send_crq(adapter, &crq); |
| 2116 | } else { |
| 2117 | /* Accept one or more multicast(s) */ |
| 2118 | netdev_for_each_mc_addr(ha, netdev) { |
| 2119 | memset(&crq, 0, sizeof(crq)); |
| 2120 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 2121 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 2122 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC; |
| 2123 | ether_addr_copy(&crq.multicast_ctrl.mac_addr[0], |
| 2124 | ha->addr); |
| 2125 | ibmvnic_send_crq(adapter, &crq); |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | } |
| 2130 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2131 | static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2132 | { |
| 2133 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2134 | union ibmvnic_crq crq; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 2135 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2136 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2137 | if (!is_valid_ether_addr(dev_addr)) { |
| 2138 | rc = -EADDRNOTAVAIL; |
| 2139 | goto err; |
| 2140 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2141 | |
| 2142 | memset(&crq, 0, sizeof(crq)); |
| 2143 | crq.change_mac_addr.first = IBMVNIC_CRQ_CMD; |
| 2144 | crq.change_mac_addr.cmd = CHANGE_MAC_ADDR; |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2145 | ether_addr_copy(&crq.change_mac_addr.mac_addr[0], dev_addr); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2146 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2147 | mutex_lock(&adapter->fw_lock); |
| 2148 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2149 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2150 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 2151 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2152 | if (rc) { |
| 2153 | rc = -EIO; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2154 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2155 | goto err; |
| 2156 | } |
| 2157 | |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2158 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2159 | /* netdev->dev_addr is changed in handle_change_mac_rsp function */ |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2160 | if (rc || adapter->fw_done_rc) { |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2161 | rc = -EIO; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2162 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2163 | goto err; |
| 2164 | } |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2165 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2166 | return 0; |
| 2167 | err: |
| 2168 | ether_addr_copy(adapter->mac_addr, netdev->dev_addr); |
| 2169 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2170 | } |
| 2171 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2172 | static int ibmvnic_set_mac(struct net_device *netdev, void *p) |
| 2173 | { |
| 2174 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2175 | struct sockaddr *addr = p; |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2176 | int rc; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2177 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2178 | rc = 0; |
Lijun Pan | 8fc3672 | 2020-10-27 17:04:56 -0500 | [diff] [blame] | 2179 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2180 | return -EADDRNOTAVAIL; |
| 2181 | |
Jiri Wiesner | 67eb211 | 2021-03-04 17:18:28 +0100 | [diff] [blame] | 2182 | ether_addr_copy(adapter->mac_addr, addr->sa_data); |
| 2183 | if (adapter->state != VNIC_PROBED) |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2184 | rc = __ibmvnic_set_mac(netdev, addr->sa_data); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2185 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2186 | return rc; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2187 | } |
| 2188 | |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2189 | static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason) |
| 2190 | { |
| 2191 | switch (reason) { |
| 2192 | case VNIC_RESET_FAILOVER: |
| 2193 | return "FAILOVER"; |
| 2194 | case VNIC_RESET_MOBILITY: |
| 2195 | return "MOBILITY"; |
| 2196 | case VNIC_RESET_FATAL: |
| 2197 | return "FATAL"; |
| 2198 | case VNIC_RESET_NON_FATAL: |
| 2199 | return "NON_FATAL"; |
| 2200 | case VNIC_RESET_TIMEOUT: |
| 2201 | return "TIMEOUT"; |
| 2202 | case VNIC_RESET_CHANGE_PARAM: |
| 2203 | return "CHANGE_PARAM"; |
Lijun Pan | 822ebc2 | 2021-06-11 10:35:37 -0500 | [diff] [blame] | 2204 | case VNIC_RESET_PASSIVE_INIT: |
| 2205 | return "PASSIVE_INIT"; |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2206 | } |
Michal Suchanek | 07b5dc1 | 2021-05-20 08:50:34 +0200 | [diff] [blame] | 2207 | return "UNKNOWN"; |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2208 | } |
| 2209 | |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 2210 | /* |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2211 | * do_reset returns zero if we are able to keep processing reset events, or |
| 2212 | * non-zero if we hit a fatal error and must halt. |
| 2213 | */ |
| 2214 | static int do_reset(struct ibmvnic_adapter *adapter, |
| 2215 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 2216 | { |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 2217 | struct net_device *netdev = adapter->netdev; |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2218 | u64 old_num_rx_queues, old_num_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 2219 | u64 old_num_rx_slots, old_num_tx_slots; |
Lijun Pan | d3a6abc | 2021-04-14 02:46:15 -0500 | [diff] [blame] | 2220 | int rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2221 | |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2222 | netdev_dbg(adapter->netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2223 | "[S:%s FOP:%d] Reset reason: %s, reset_state: %s\n", |
| 2224 | adapter_state_to_string(adapter->state), |
| 2225 | adapter->failover_pending, |
| 2226 | reset_reason_to_string(rwi->reset_reason), |
| 2227 | adapter_state_to_string(reset_state)); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 2228 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2229 | adapter->reset_reason = rwi->reset_reason; |
| 2230 | /* requestor of VNIC_RESET_CHANGE_PARAM already has the rtnl lock */ |
| 2231 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 2232 | rtnl_lock(); |
| 2233 | |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 2234 | /* Now that we have the rtnl lock, clear any pending failover. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2235 | * This will ensure ibmvnic_open() has either completed or will |
| 2236 | * block until failover is complete. |
| 2237 | */ |
| 2238 | if (rwi->reset_reason == VNIC_RESET_FAILOVER) |
| 2239 | adapter->failover_pending = false; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2240 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2241 | /* read the state and check (again) after getting rtnl */ |
| 2242 | reset_state = adapter->state; |
| 2243 | |
| 2244 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 2245 | rc = -EBUSY; |
| 2246 | goto out; |
| 2247 | } |
| 2248 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2249 | netif_carrier_off(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2250 | |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2251 | old_num_rx_queues = adapter->req_rx_queues; |
| 2252 | old_num_tx_queues = adapter->req_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 2253 | old_num_rx_slots = adapter->req_rx_add_entries_per_subcrq; |
| 2254 | old_num_tx_slots = adapter->req_tx_entries_per_subcrq; |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2255 | |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2256 | ibmvnic_cleanup(netdev); |
| 2257 | |
Thomas Falcon | 1f94608 | 2019-06-07 16:03:53 -0500 | [diff] [blame] | 2258 | if (reset_state == VNIC_OPEN && |
| 2259 | adapter->reset_reason != VNIC_RESET_MOBILITY && |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2260 | adapter->reset_reason != VNIC_RESET_FAILOVER) { |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2261 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2262 | rc = __ibmvnic_close(netdev); |
| 2263 | if (rc) |
| 2264 | goto out; |
| 2265 | } else { |
| 2266 | adapter->state = VNIC_CLOSING; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2267 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2268 | /* Release the RTNL lock before link state change and |
| 2269 | * re-acquire after the link state change to allow |
| 2270 | * linkwatch_event to grab the RTNL lock and run during |
| 2271 | * a reset. |
| 2272 | */ |
| 2273 | rtnl_unlock(); |
| 2274 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
| 2275 | rtnl_lock(); |
| 2276 | if (rc) |
| 2277 | goto out; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2278 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2279 | if (adapter->state == VNIC_OPEN) { |
| 2280 | /* When we dropped rtnl, ibmvnic_open() got |
| 2281 | * it and noticed that we are resetting and |
| 2282 | * set the adapter state to OPEN. Update our |
| 2283 | * new "target" state, and resume the reset |
| 2284 | * from VNIC_CLOSING state. |
| 2285 | */ |
| 2286 | netdev_dbg(netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2287 | "Open changed state from %s, updating.\n", |
| 2288 | adapter_state_to_string(reset_state)); |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2289 | reset_state = VNIC_OPEN; |
| 2290 | adapter->state = VNIC_CLOSING; |
| 2291 | } |
| 2292 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2293 | if (adapter->state != VNIC_CLOSING) { |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2294 | /* If someone else changed the adapter state |
| 2295 | * when we dropped the rtnl, fail the reset |
| 2296 | */ |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 2297 | rc = -EAGAIN; |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2298 | goto out; |
| 2299 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2300 | adapter->state = VNIC_CLOSED; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2301 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2302 | } |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2303 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2304 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2305 | release_resources(adapter); |
| 2306 | release_sub_crqs(adapter, 1); |
| 2307 | release_crq_queue(adapter); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2308 | } |
| 2309 | |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2310 | if (adapter->reset_reason != VNIC_RESET_NON_FATAL) { |
| 2311 | /* remove the closed state so when we call open it appears |
| 2312 | * we are coming from the probed state. |
| 2313 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2314 | adapter->state = VNIC_PROBED; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2315 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2316 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2317 | rc = init_crq_queue(adapter); |
| 2318 | } else if (adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2319 | rc = ibmvnic_reenable_crq_queue(adapter); |
| 2320 | release_sub_crqs(adapter, 1); |
| 2321 | } else { |
| 2322 | rc = ibmvnic_reset_crq(adapter); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2323 | if (rc == H_CLOSED || rc == H_SUCCESS) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2324 | rc = vio_enable_interrupts(adapter->vdev); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2325 | if (rc) |
| 2326 | netdev_err(adapter->netdev, |
| 2327 | "Reset failed to enable interrupts. rc=%d\n", |
| 2328 | rc); |
| 2329 | } |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | if (rc) { |
| 2333 | netdev_err(adapter->netdev, |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2334 | "Reset couldn't initialize crq. rc=%d\n", rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2335 | goto out; |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2336 | } |
| 2337 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2338 | rc = ibmvnic_reset_init(adapter, true); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 2339 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2340 | goto out; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2341 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2342 | /* If the adapter was in PROBE or DOWN state prior to the reset, |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2343 | * exit here. |
| 2344 | */ |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2345 | if (reset_state == VNIC_PROBED || reset_state == VNIC_DOWN) { |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2346 | rc = 0; |
| 2347 | goto out; |
| 2348 | } |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2349 | |
| 2350 | rc = ibmvnic_login(netdev); |
Lijun Pan | f78afaa | 2021-02-11 00:43:20 -0600 | [diff] [blame] | 2351 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2352 | goto out; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2353 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2354 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2355 | rc = init_resources(adapter); |
| 2356 | if (rc) |
| 2357 | goto out; |
| 2358 | } else if (adapter->req_rx_queues != old_num_rx_queues || |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2359 | adapter->req_tx_queues != old_num_tx_queues || |
| 2360 | adapter->req_rx_add_entries_per_subcrq != |
| 2361 | old_num_rx_slots || |
| 2362 | adapter->req_tx_entries_per_subcrq != |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2363 | old_num_tx_slots || |
| 2364 | !adapter->rx_pool || |
| 2365 | !adapter->tso_pool || |
| 2366 | !adapter->tx_pool) { |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2367 | release_napi(adapter); |
| 2368 | release_vpd_data(adapter); |
| 2369 | |
| 2370 | rc = init_resources(adapter); |
Thomas Falcon | f611a5b | 2018-08-30 13:19:53 -0500 | [diff] [blame] | 2371 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2372 | goto out; |
Nathan Fontenot | d9043c1 | 2018-02-19 13:30:14 -0600 | [diff] [blame] | 2373 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2374 | } else { |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 2375 | rc = init_tx_pools(netdev); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2376 | if (rc) { |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 2377 | netdev_dbg(netdev, |
| 2378 | "init tx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2379 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2380 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2381 | } |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 2382 | |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 2383 | rc = init_rx_pools(netdev); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2384 | if (rc) { |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 2385 | netdev_dbg(netdev, |
| 2386 | "init rx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2387 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2388 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2389 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2390 | } |
Thomas Falcon | 134bbe7 | 2018-05-16 15:49:04 -0500 | [diff] [blame] | 2391 | ibmvnic_disable_irqs(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2392 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2393 | adapter->state = VNIC_CLOSED; |
| 2394 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2395 | if (reset_state == VNIC_CLOSED) { |
| 2396 | rc = 0; |
| 2397 | goto out; |
| 2398 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2399 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2400 | rc = __ibmvnic_open(netdev); |
| 2401 | if (rc) { |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2402 | rc = IBMVNIC_OPEN_FAILED; |
| 2403 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2404 | } |
| 2405 | |
Thomas Falcon | be32a24 | 2019-06-07 16:03:54 -0500 | [diff] [blame] | 2406 | /* refresh device's multicast list */ |
| 2407 | ibmvnic_set_multi(netdev); |
| 2408 | |
Lijun Pan | 98025bc | 2020-11-20 16:40:12 -0600 | [diff] [blame] | 2409 | if (adapter->reset_reason == VNIC_RESET_FAILOVER || |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2410 | adapter->reset_reason == VNIC_RESET_MOBILITY) |
| 2411 | __netdev_notify_peers(netdev); |
Nathan Fontenot | 61d3e1d | 2017-06-12 20:47:45 -0400 | [diff] [blame] | 2412 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2413 | rc = 0; |
| 2414 | |
| 2415 | out: |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2416 | /* restore the adapter state if reset failed */ |
| 2417 | if (rc) |
| 2418 | adapter->state = reset_state; |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2419 | /* requestor of VNIC_RESET_CHANGE_PARAM should still hold the rtnl lock */ |
| 2420 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 2421 | rtnl_unlock(); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2422 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2423 | netdev_dbg(adapter->netdev, "[S:%s FOP:%d] Reset done, rc %d\n", |
| 2424 | adapter_state_to_string(adapter->state), |
| 2425 | adapter->failover_pending, rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2426 | return rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2427 | } |
| 2428 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2429 | static int do_hard_reset(struct ibmvnic_adapter *adapter, |
| 2430 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 2431 | { |
| 2432 | struct net_device *netdev = adapter->netdev; |
| 2433 | int rc; |
| 2434 | |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2435 | netdev_dbg(adapter->netdev, "Hard resetting driver (%s)\n", |
| 2436 | reset_reason_to_string(rwi->reset_reason)); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2437 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2438 | /* read the state and check (again) after getting rtnl */ |
| 2439 | reset_state = adapter->state; |
| 2440 | |
| 2441 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 2442 | rc = -EBUSY; |
| 2443 | goto out; |
| 2444 | } |
| 2445 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2446 | netif_carrier_off(netdev); |
| 2447 | adapter->reset_reason = rwi->reset_reason; |
| 2448 | |
| 2449 | ibmvnic_cleanup(netdev); |
| 2450 | release_resources(adapter); |
| 2451 | release_sub_crqs(adapter, 0); |
| 2452 | release_crq_queue(adapter); |
| 2453 | |
| 2454 | /* remove the closed state so when we call open it appears |
| 2455 | * we are coming from the probed state. |
| 2456 | */ |
| 2457 | adapter->state = VNIC_PROBED; |
| 2458 | |
Thomas Falcon | bbd669a | 2019-04-04 18:58:26 -0500 | [diff] [blame] | 2459 | reinit_completion(&adapter->init_done); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2460 | rc = init_crq_queue(adapter); |
| 2461 | if (rc) { |
| 2462 | netdev_err(adapter->netdev, |
| 2463 | "Couldn't initialize crq. rc=%d\n", rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2464 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2465 | } |
| 2466 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2467 | rc = ibmvnic_reset_init(adapter, false); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2468 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2469 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2470 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2471 | /* If the adapter was in PROBE or DOWN state prior to the reset, |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2472 | * exit here. |
| 2473 | */ |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2474 | if (reset_state == VNIC_PROBED || reset_state == VNIC_DOWN) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2475 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2476 | |
| 2477 | rc = ibmvnic_login(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2478 | if (rc) |
| 2479 | goto out; |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2480 | |
| 2481 | rc = init_resources(adapter); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2482 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2483 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2484 | |
| 2485 | ibmvnic_disable_irqs(adapter); |
| 2486 | adapter->state = VNIC_CLOSED; |
| 2487 | |
| 2488 | if (reset_state == VNIC_CLOSED) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2489 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2490 | |
| 2491 | rc = __ibmvnic_open(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2492 | if (rc) { |
| 2493 | rc = IBMVNIC_OPEN_FAILED; |
| 2494 | goto out; |
| 2495 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2496 | |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2497 | __netdev_notify_peers(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2498 | out: |
| 2499 | /* restore adapter state if reset failed */ |
| 2500 | if (rc) |
| 2501 | adapter->state = reset_state; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2502 | netdev_dbg(adapter->netdev, "[S:%s FOP:%d] Hard reset done, rc %d\n", |
| 2503 | adapter_state_to_string(adapter->state), |
| 2504 | adapter->failover_pending, rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2505 | return rc; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2506 | } |
| 2507 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2508 | static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter) |
| 2509 | { |
| 2510 | struct ibmvnic_rwi *rwi; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2511 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2512 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2513 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2514 | |
| 2515 | if (!list_empty(&adapter->rwi_list)) { |
| 2516 | rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi, |
| 2517 | list); |
| 2518 | list_del(&rwi->list); |
| 2519 | } else { |
| 2520 | rwi = NULL; |
| 2521 | } |
| 2522 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2523 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2524 | return rwi; |
| 2525 | } |
| 2526 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2527 | /** |
| 2528 | * do_passive_init - complete probing when partner device is detected. |
| 2529 | * @adapter: ibmvnic_adapter struct |
| 2530 | * |
| 2531 | * If the ibmvnic device does not have a partner device to communicate with at boot |
| 2532 | * and that partner device comes online at a later time, this function is called |
| 2533 | * to complete the initialization process of ibmvnic device. |
| 2534 | * Caller is expected to hold rtnl_lock(). |
| 2535 | * |
| 2536 | * Returns non-zero if sub-CRQs are not initialized properly leaving the device |
| 2537 | * in the down state. |
| 2538 | * Returns 0 upon success and the device is in PROBED state. |
| 2539 | */ |
| 2540 | |
| 2541 | static int do_passive_init(struct ibmvnic_adapter *adapter) |
| 2542 | { |
| 2543 | unsigned long timeout = msecs_to_jiffies(30000); |
| 2544 | struct net_device *netdev = adapter->netdev; |
| 2545 | struct device *dev = &adapter->vdev->dev; |
| 2546 | int rc; |
| 2547 | |
| 2548 | netdev_dbg(netdev, "Partner device found, probing.\n"); |
| 2549 | |
| 2550 | adapter->state = VNIC_PROBING; |
| 2551 | reinit_completion(&adapter->init_done); |
| 2552 | adapter->init_done_rc = 0; |
| 2553 | adapter->crq.active = true; |
| 2554 | |
| 2555 | rc = send_crq_init_complete(adapter); |
| 2556 | if (rc) |
| 2557 | goto out; |
| 2558 | |
| 2559 | rc = send_version_xchg(adapter); |
| 2560 | if (rc) |
| 2561 | netdev_dbg(adapter->netdev, "send_version_xchg failed, rc=%d\n", rc); |
| 2562 | |
| 2563 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 2564 | dev_err(dev, "Initialization sequence timed out\n"); |
| 2565 | rc = -ETIMEDOUT; |
| 2566 | goto out; |
| 2567 | } |
| 2568 | |
| 2569 | rc = init_sub_crqs(adapter); |
| 2570 | if (rc) { |
| 2571 | dev_err(dev, "Initialization of sub crqs failed, rc=%d\n", rc); |
| 2572 | goto out; |
| 2573 | } |
| 2574 | |
| 2575 | rc = init_sub_crq_irqs(adapter); |
| 2576 | if (rc) { |
| 2577 | dev_err(dev, "Failed to initialize sub crq irqs\n, rc=%d", rc); |
| 2578 | goto init_failed; |
| 2579 | } |
| 2580 | |
| 2581 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 2582 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
| 2583 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
| 2584 | |
| 2585 | adapter->state = VNIC_PROBED; |
| 2586 | netdev_dbg(netdev, "Probed successfully. Waiting for signal from partner device.\n"); |
| 2587 | |
| 2588 | return 0; |
| 2589 | |
| 2590 | init_failed: |
| 2591 | release_sub_crqs(adapter, 1); |
| 2592 | out: |
| 2593 | adapter->state = VNIC_DOWN; |
| 2594 | return rc; |
| 2595 | } |
| 2596 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2597 | static void __ibmvnic_reset(struct work_struct *work) |
| 2598 | { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2599 | struct ibmvnic_adapter *adapter; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2600 | bool saved_state = false; |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2601 | struct ibmvnic_rwi *tmprwi; |
| 2602 | struct ibmvnic_rwi *rwi; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2603 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2604 | u32 reset_state; |
Sukadev Bhattiprolu | db9f0e8 | 2022-01-21 18:59:18 -0800 | [diff] [blame] | 2605 | int num_fails = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2606 | int rc = 0; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2607 | |
| 2608 | adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2609 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2610 | if (test_and_set_bit_lock(0, &adapter->resetting)) { |
Lijun Pan | 870e04a | 2021-04-13 14:33:39 -0500 | [diff] [blame] | 2611 | queue_delayed_work(system_long_wq, |
| 2612 | &adapter->ibmvnic_delayed_reset, |
| 2613 | IBMVNIC_RESET_DELAY); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2614 | return; |
| 2615 | } |
| 2616 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2617 | rwi = get_next_rwi(adapter); |
| 2618 | while (rwi) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2619 | spin_lock_irqsave(&adapter->state_lock, flags); |
| 2620 | |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2621 | if (adapter->state == VNIC_REMOVING || |
Michal Suchanek | c8dc559 | 2019-09-09 22:44:51 +0200 | [diff] [blame] | 2622 | adapter->state == VNIC_REMOVED) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2623 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
Juliet Kim | 1c2977c | 2019-09-05 17:30:01 -0400 | [diff] [blame] | 2624 | kfree(rwi); |
| 2625 | rc = EBUSY; |
| 2626 | break; |
| 2627 | } |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2628 | |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2629 | if (!saved_state) { |
| 2630 | reset_state = adapter->state; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2631 | saved_state = true; |
| 2632 | } |
| 2633 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
| 2634 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2635 | if (rwi->reset_reason == VNIC_RESET_PASSIVE_INIT) { |
| 2636 | rtnl_lock(); |
| 2637 | rc = do_passive_init(adapter); |
| 2638 | rtnl_unlock(); |
| 2639 | if (!rc) |
| 2640 | netif_carrier_on(adapter->netdev); |
| 2641 | } else if (adapter->force_reset_recovery) { |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 2642 | /* Since we are doing a hard reset now, clear the |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2643 | * failover_pending flag so we don't ignore any |
| 2644 | * future MOBILITY or other resets. |
| 2645 | */ |
| 2646 | adapter->failover_pending = false; |
| 2647 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2648 | /* Transport event occurred during previous reset */ |
| 2649 | if (adapter->wait_for_reset) { |
| 2650 | /* Previous was CHANGE_PARAM; caller locked */ |
| 2651 | adapter->force_reset_recovery = false; |
| 2652 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2653 | } else { |
| 2654 | rtnl_lock(); |
| 2655 | adapter->force_reset_recovery = false; |
| 2656 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2657 | rtnl_unlock(); |
| 2658 | } |
Sukadev Bhattiprolu | db9f0e8 | 2022-01-21 18:59:18 -0800 | [diff] [blame] | 2659 | if (rc) |
| 2660 | num_fails++; |
| 2661 | else |
| 2662 | num_fails = 0; |
| 2663 | |
| 2664 | /* If auto-priority-failover is enabled we can get |
| 2665 | * back to back failovers during resets, resulting |
| 2666 | * in at least two failed resets (from high-priority |
| 2667 | * backing device to low-priority one and then back) |
| 2668 | * If resets continue to fail beyond that, give the |
| 2669 | * adapter some time to settle down before retrying. |
| 2670 | */ |
| 2671 | if (num_fails >= 3) { |
Sukadev Bhattiprolu | f15fde9 | 2020-11-25 18:04:28 -0600 | [diff] [blame] | 2672 | netdev_dbg(adapter->netdev, |
Sukadev Bhattiprolu | db9f0e8 | 2022-01-21 18:59:18 -0800 | [diff] [blame] | 2673 | "[S:%s] Hard reset failed %d times, waiting 60 secs\n", |
| 2674 | adapter_state_to_string(adapter->state), |
| 2675 | num_fails); |
Sukadev Bhattiprolu | f15fde9 | 2020-11-25 18:04:28 -0600 | [diff] [blame] | 2676 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2677 | schedule_timeout(60 * HZ); |
| 2678 | } |
Lijun Pan | 1f45dc2 | 2020-12-23 14:49:04 -0600 | [diff] [blame] | 2679 | } else { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2680 | rc = do_reset(adapter, rwi, reset_state); |
| 2681 | } |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2682 | tmprwi = rwi; |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2683 | adapter->last_reset_time = jiffies; |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2684 | |
Dany Madden | 18f141b | 2020-11-25 18:04:25 -0600 | [diff] [blame] | 2685 | if (rc) |
| 2686 | netdev_dbg(adapter->netdev, "Reset failed, rc=%d\n", rc); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2687 | |
| 2688 | rwi = get_next_rwi(adapter); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2689 | |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2690 | /* |
| 2691 | * If there is another reset queued, free the previous rwi |
| 2692 | * and process the new reset even if previous reset failed |
| 2693 | * (the previous reset could have failed because of a fail |
| 2694 | * over for instance, so process the fail over). |
| 2695 | * |
| 2696 | * If there are no resets queued and the previous reset failed, |
| 2697 | * the adapter would be in an undefined state. So retry the |
| 2698 | * previous reset as a hard reset. |
| 2699 | */ |
| 2700 | if (rwi) |
| 2701 | kfree(tmprwi); |
| 2702 | else if (rc) |
| 2703 | rwi = tmprwi; |
| 2704 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2705 | if (rwi && (rwi->reset_reason == VNIC_RESET_FAILOVER || |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2706 | rwi->reset_reason == VNIC_RESET_MOBILITY || rc)) |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2707 | adapter->force_reset_recovery = true; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2708 | } |
| 2709 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2710 | if (adapter->wait_for_reset) { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2711 | adapter->reset_done_rc = rc; |
| 2712 | complete(&adapter->reset_done); |
| 2713 | } |
| 2714 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2715 | clear_bit_unlock(0, &adapter->resetting); |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2716 | |
| 2717 | netdev_dbg(adapter->netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2718 | "[S:%s FRR:%d WFR:%d] Done processing resets\n", |
| 2719 | adapter_state_to_string(adapter->state), |
| 2720 | adapter->force_reset_recovery, |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2721 | adapter->wait_for_reset); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | static void __ibmvnic_delayed_reset(struct work_struct *work) |
| 2725 | { |
| 2726 | struct ibmvnic_adapter *adapter; |
| 2727 | |
| 2728 | adapter = container_of(work, struct ibmvnic_adapter, |
| 2729 | ibmvnic_delayed_reset.work); |
| 2730 | __ibmvnic_reset(&adapter->ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2731 | } |
| 2732 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2733 | static int ibmvnic_reset(struct ibmvnic_adapter *adapter, |
| 2734 | enum ibmvnic_reset_reason reason) |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2735 | { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2736 | struct list_head *entry, *tmp_entry; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2737 | struct ibmvnic_rwi *rwi, *tmp; |
| 2738 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2739 | unsigned long flags; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2740 | int ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2741 | |
Jakub Kicinski | b646acd5 | 2021-02-16 22:58:44 -0800 | [diff] [blame] | 2742 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
| 2743 | |
| 2744 | /* If failover is pending don't schedule any other reset. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2745 | * Instead let the failover complete. If there is already a |
| 2746 | * a failover reset scheduled, we will detect and drop the |
| 2747 | * duplicate reset when walking the ->rwi_list below. |
| 2748 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2749 | if (adapter->state == VNIC_REMOVING || |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2750 | adapter->state == VNIC_REMOVED || |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2751 | (adapter->failover_pending && reason != VNIC_RESET_FAILOVER)) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2752 | ret = EBUSY; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2753 | netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n"); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2754 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2755 | } |
| 2756 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2757 | if (adapter->state == VNIC_PROBING) { |
| 2758 | netdev_warn(netdev, "Adapter reset during probe\n"); |
Sukadev Bhattiprolu | 6b278c0 | 2021-10-29 15:03:16 -0700 | [diff] [blame] | 2759 | adapter->init_done_rc = -EAGAIN; |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2760 | ret = EAGAIN; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2761 | goto err; |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2762 | } |
| 2763 | |
Wang Hai | 3e98ae0 | 2021-06-10 20:54:17 +0800 | [diff] [blame] | 2764 | list_for_each_entry(tmp, &adapter->rwi_list, list) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2765 | if (tmp->reset_reason == reason) { |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2766 | netdev_dbg(netdev, "Skipping matching reset, reason=%s\n", |
| 2767 | reset_reason_to_string(reason)); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2768 | ret = EBUSY; |
| 2769 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | |
Thomas Falcon | 1d1bbc3 | 2018-12-10 15:22:23 -0600 | [diff] [blame] | 2773 | rwi = kzalloc(sizeof(*rwi), GFP_ATOMIC); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2774 | if (!rwi) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2775 | ret = ENOMEM; |
| 2776 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2777 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2778 | /* if we just received a transport event, |
| 2779 | * flush reset queue and process this reset |
| 2780 | */ |
| 2781 | if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) { |
| 2782 | list_for_each_safe(entry, tmp_entry, &adapter->rwi_list) |
| 2783 | list_del(entry); |
| 2784 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2785 | rwi->reset_reason = reason; |
| 2786 | list_add_tail(&rwi->list, &adapter->rwi_list); |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2787 | netdev_dbg(adapter->netdev, "Scheduling reset (reason %s)\n", |
| 2788 | reset_reason_to_string(reason)); |
Lijun Pan | 870e04a | 2021-04-13 14:33:39 -0500 | [diff] [blame] | 2789 | queue_work(system_long_wq, &adapter->ibmvnic_reset); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2790 | |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2791 | ret = 0; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2792 | err: |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2793 | /* ibmvnic_close() below can block, so drop the lock first */ |
| 2794 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
| 2795 | |
| 2796 | if (ret == ENOMEM) |
| 2797 | ibmvnic_close(netdev); |
| 2798 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2799 | return -ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 2802 | static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2803 | { |
| 2804 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2805 | |
Lijun Pan | 855a631 | 2020-11-20 16:40:13 -0600 | [diff] [blame] | 2806 | if (test_bit(0, &adapter->resetting)) { |
| 2807 | netdev_err(adapter->netdev, |
| 2808 | "Adapter is resetting, skip timeout reset\n"); |
| 2809 | return; |
| 2810 | } |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2811 | /* No queuing up reset until at least 5 seconds (default watchdog val) |
| 2812 | * after last reset |
| 2813 | */ |
| 2814 | if (time_before(jiffies, (adapter->last_reset_time + dev->watchdog_timeo))) { |
| 2815 | netdev_dbg(dev, "Not yet time to tx timeout.\n"); |
| 2816 | return; |
| 2817 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2818 | ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | static void remove_buff_from_pool(struct ibmvnic_adapter *adapter, |
| 2822 | struct ibmvnic_rx_buff *rx_buff) |
| 2823 | { |
| 2824 | struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index]; |
| 2825 | |
| 2826 | rx_buff->skb = NULL; |
| 2827 | |
| 2828 | pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff); |
| 2829 | pool->next_alloc = (pool->next_alloc + 1) % pool->size; |
| 2830 | |
| 2831 | atomic_dec(&pool->available); |
| 2832 | } |
| 2833 | |
| 2834 | static int ibmvnic_poll(struct napi_struct *napi, int budget) |
| 2835 | { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2836 | struct ibmvnic_sub_crq_queue *rx_scrq; |
| 2837 | struct ibmvnic_adapter *adapter; |
| 2838 | struct net_device *netdev; |
| 2839 | int frames_processed; |
| 2840 | int scrq_num; |
| 2841 | |
| 2842 | netdev = napi->dev; |
| 2843 | adapter = netdev_priv(netdev); |
| 2844 | scrq_num = (int)(napi - adapter->napi); |
| 2845 | frames_processed = 0; |
| 2846 | rx_scrq = adapter->rx_scrq[scrq_num]; |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2847 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2848 | restart_poll: |
| 2849 | while (frames_processed < budget) { |
| 2850 | struct sk_buff *skb; |
| 2851 | struct ibmvnic_rx_buff *rx_buff; |
| 2852 | union sub_crq *next; |
| 2853 | u32 length; |
| 2854 | u16 offset; |
| 2855 | u8 flags = 0; |
| 2856 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2857 | if (unlikely(test_bit(0, &adapter->resetting) && |
John Allen | 3468656 | 2018-02-06 16:21:49 -0600 | [diff] [blame] | 2858 | adapter->reset_reason != VNIC_RESET_NON_FATAL)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2859 | enable_scrq_irq(adapter, rx_scrq); |
Thomas Falcon | 21ecba6 | 2017-06-14 23:50:09 -0500 | [diff] [blame] | 2860 | napi_complete_done(napi, frames_processed); |
| 2861 | return frames_processed; |
| 2862 | } |
| 2863 | |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2864 | if (!pending_scrq(adapter, rx_scrq)) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2865 | break; |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2866 | next = ibmvnic_next_scrq(adapter, rx_scrq); |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 2867 | rx_buff = (struct ibmvnic_rx_buff *) |
| 2868 | be64_to_cpu(next->rx_comp.correlator); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2869 | /* do error checking */ |
| 2870 | if (next->rx_comp.rc) { |
John Allen | e1cea2e | 2017-08-07 15:42:30 -0500 | [diff] [blame] | 2871 | netdev_dbg(netdev, "rx buffer returned with rc %x\n", |
| 2872 | be16_to_cpu(next->rx_comp.rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2873 | /* free the entry */ |
| 2874 | next->rx_comp.first = 0; |
Thomas Falcon | 4b9b0f0 | 2018-02-13 18:23:42 -0600 | [diff] [blame] | 2875 | dev_kfree_skb_any(rx_buff->skb); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2876 | remove_buff_from_pool(adapter, rx_buff); |
Nathan Fontenot | ca05e31 | 2017-05-03 14:05:14 -0400 | [diff] [blame] | 2877 | continue; |
Thomas Falcon | abe27a8 | 2018-02-19 20:12:57 -0600 | [diff] [blame] | 2878 | } else if (!rx_buff->skb) { |
| 2879 | /* free the entry */ |
| 2880 | next->rx_comp.first = 0; |
| 2881 | remove_buff_from_pool(adapter, rx_buff); |
| 2882 | continue; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | length = be32_to_cpu(next->rx_comp.len); |
| 2886 | offset = be16_to_cpu(next->rx_comp.off_frame_data); |
| 2887 | flags = next->rx_comp.flags; |
| 2888 | skb = rx_buff->skb; |
Lijun Pan | 42557da | 2021-02-12 20:48:40 -0600 | [diff] [blame] | 2889 | /* load long_term_buff before copying to skb */ |
| 2890 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2891 | skb_copy_to_linear_data(skb, rx_buff->data + offset, |
| 2892 | length); |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 2893 | |
| 2894 | /* VLAN Header has been stripped by the system firmware and |
| 2895 | * needs to be inserted by the driver |
| 2896 | */ |
| 2897 | if (adapter->rx_vlan_header_insertion && |
| 2898 | (flags & IBMVNIC_VLAN_STRIPPED)) |
| 2899 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2900 | ntohs(next->rx_comp.vlan_tci)); |
| 2901 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2902 | /* free the entry */ |
| 2903 | next->rx_comp.first = 0; |
| 2904 | remove_buff_from_pool(adapter, rx_buff); |
| 2905 | |
| 2906 | skb_put(skb, length); |
| 2907 | skb->protocol = eth_type_trans(skb, netdev); |
Thomas Falcon | 94ca305 | 2017-05-03 14:05:20 -0400 | [diff] [blame] | 2908 | skb_record_rx_queue(skb, scrq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2909 | |
| 2910 | if (flags & IBMVNIC_IP_CHKSUM_GOOD && |
| 2911 | flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) { |
| 2912 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2913 | } |
| 2914 | |
| 2915 | length = skb->len; |
| 2916 | napi_gro_receive(napi, skb); /* send it up */ |
| 2917 | netdev->stats.rx_packets++; |
| 2918 | netdev->stats.rx_bytes += length; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2919 | adapter->rx_stats_buffers[scrq_num].packets++; |
| 2920 | adapter->rx_stats_buffers[scrq_num].bytes += length; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2921 | frames_processed++; |
| 2922 | } |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2923 | |
Dwip N. Banerjee | 41ed0a0 | 2020-11-18 19:12:25 -0600 | [diff] [blame] | 2924 | if (adapter->state != VNIC_CLOSING && |
| 2925 | ((atomic_read(&adapter->rx_pool[scrq_num].available) < |
| 2926 | adapter->req_rx_add_entries_per_subcrq / 2) || |
| 2927 | frames_processed < budget)) |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2928 | replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2929 | if (frames_processed < budget) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2930 | if (napi_complete_done(napi, frames_processed)) { |
| 2931 | enable_scrq_irq(adapter, rx_scrq); |
| 2932 | if (pending_scrq(adapter, rx_scrq)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2933 | if (napi_reschedule(napi)) { |
| 2934 | disable_scrq_irq(adapter, rx_scrq); |
| 2935 | goto restart_poll; |
| 2936 | } |
| 2937 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | return frames_processed; |
| 2941 | } |
| 2942 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2943 | static int wait_for_reset(struct ibmvnic_adapter *adapter) |
| 2944 | { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2945 | int rc, ret; |
| 2946 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2947 | adapter->fallback.mtu = adapter->req_mtu; |
| 2948 | adapter->fallback.rx_queues = adapter->req_rx_queues; |
| 2949 | adapter->fallback.tx_queues = adapter->req_tx_queues; |
| 2950 | adapter->fallback.rx_entries = adapter->req_rx_add_entries_per_subcrq; |
| 2951 | adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq; |
| 2952 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2953 | reinit_completion(&adapter->reset_done); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2954 | adapter->wait_for_reset = true; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2955 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2956 | |
| 2957 | if (rc) { |
| 2958 | ret = rc; |
| 2959 | goto out; |
| 2960 | } |
| 2961 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, 60000); |
| 2962 | if (rc) { |
| 2963 | ret = -ENODEV; |
| 2964 | goto out; |
| 2965 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2966 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2967 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2968 | if (adapter->reset_done_rc) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2969 | ret = -EIO; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2970 | adapter->desired.mtu = adapter->fallback.mtu; |
| 2971 | adapter->desired.rx_queues = adapter->fallback.rx_queues; |
| 2972 | adapter->desired.tx_queues = adapter->fallback.tx_queues; |
| 2973 | adapter->desired.rx_entries = adapter->fallback.rx_entries; |
| 2974 | adapter->desired.tx_entries = adapter->fallback.tx_entries; |
| 2975 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2976 | reinit_completion(&adapter->reset_done); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2977 | adapter->wait_for_reset = true; |
| 2978 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2979 | if (rc) { |
| 2980 | ret = rc; |
| 2981 | goto out; |
| 2982 | } |
| 2983 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, |
| 2984 | 60000); |
| 2985 | if (rc) { |
| 2986 | ret = -ENODEV; |
| 2987 | goto out; |
| 2988 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2989 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2990 | out: |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2991 | adapter->wait_for_reset = false; |
| 2992 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2993 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2994 | } |
| 2995 | |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2996 | static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu) |
| 2997 | { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2998 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2999 | |
| 3000 | adapter->desired.mtu = new_mtu + ETH_HLEN; |
| 3001 | |
| 3002 | return wait_for_reset(adapter); |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 3003 | } |
| 3004 | |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 3005 | static netdev_features_t ibmvnic_features_check(struct sk_buff *skb, |
| 3006 | struct net_device *dev, |
| 3007 | netdev_features_t features) |
| 3008 | { |
| 3009 | /* Some backing hardware adapters can not |
| 3010 | * handle packets with a MSS less than 224 |
| 3011 | * or with only one segment. |
| 3012 | */ |
| 3013 | if (skb_is_gso(skb)) { |
| 3014 | if (skb_shinfo(skb)->gso_size < 224 || |
| 3015 | skb_shinfo(skb)->gso_segs == 1) |
| 3016 | features &= ~NETIF_F_GSO_MASK; |
| 3017 | } |
| 3018 | |
| 3019 | return features; |
| 3020 | } |
| 3021 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3022 | static const struct net_device_ops ibmvnic_netdev_ops = { |
| 3023 | .ndo_open = ibmvnic_open, |
| 3024 | .ndo_stop = ibmvnic_close, |
| 3025 | .ndo_start_xmit = ibmvnic_xmit, |
| 3026 | .ndo_set_rx_mode = ibmvnic_set_multi, |
| 3027 | .ndo_set_mac_address = ibmvnic_set_mac, |
| 3028 | .ndo_validate_addr = eth_validate_addr, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3029 | .ndo_tx_timeout = ibmvnic_tx_timeout, |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 3030 | .ndo_change_mtu = ibmvnic_change_mtu, |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 3031 | .ndo_features_check = ibmvnic_features_check, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3032 | }; |
| 3033 | |
| 3034 | /* ethtool functions */ |
| 3035 | |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 3036 | static int ibmvnic_get_link_ksettings(struct net_device *netdev, |
| 3037 | struct ethtool_link_ksettings *cmd) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3038 | { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 3039 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3040 | int rc; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 3041 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 3042 | rc = send_query_phys_parms(adapter); |
| 3043 | if (rc) { |
| 3044 | adapter->speed = SPEED_UNKNOWN; |
| 3045 | adapter->duplex = DUPLEX_UNKNOWN; |
| 3046 | } |
| 3047 | cmd->base.speed = adapter->speed; |
| 3048 | cmd->base.duplex = adapter->duplex; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 3049 | cmd->base.port = PORT_FIBRE; |
| 3050 | cmd->base.phy_address = 0; |
| 3051 | cmd->base.autoneg = AUTONEG_ENABLE; |
| 3052 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3053 | return 0; |
| 3054 | } |
| 3055 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 3056 | static void ibmvnic_get_drvinfo(struct net_device *netdev, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3057 | struct ethtool_drvinfo *info) |
| 3058 | { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 3059 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3060 | |
Lijun Pan | 8a96c80 | 2021-02-11 00:43:25 -0600 | [diff] [blame] | 3061 | strscpy(info->driver, ibmvnic_driver_name, sizeof(info->driver)); |
| 3062 | strscpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version)); |
| 3063 | strscpy(info->fw_version, adapter->fw_version, |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 3064 | sizeof(info->fw_version)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | static u32 ibmvnic_get_msglevel(struct net_device *netdev) |
| 3068 | { |
| 3069 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3070 | |
| 3071 | return adapter->msg_enable; |
| 3072 | } |
| 3073 | |
| 3074 | static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data) |
| 3075 | { |
| 3076 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3077 | |
| 3078 | adapter->msg_enable = data; |
| 3079 | } |
| 3080 | |
| 3081 | static u32 ibmvnic_get_link(struct net_device *netdev) |
| 3082 | { |
| 3083 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3084 | |
| 3085 | /* Don't need to send a query because we request a logical link up at |
| 3086 | * init and then we wait for link state indications |
| 3087 | */ |
| 3088 | return adapter->logical_link_state; |
| 3089 | } |
| 3090 | |
| 3091 | static void ibmvnic_get_ringparam(struct net_device *netdev, |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 3092 | struct ethtool_ringparam *ring, |
| 3093 | struct kernel_ethtool_ringparam *kernel_ring, |
| 3094 | struct netlink_ext_ack *extack) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3095 | { |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 3096 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3097 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3098 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 3099 | ring->rx_max_pending = adapter->max_rx_add_entries_per_subcrq; |
| 3100 | ring->tx_max_pending = adapter->max_tx_entries_per_subcrq; |
| 3101 | } else { |
| 3102 | ring->rx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 3103 | ring->tx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 3104 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3105 | ring->rx_mini_max_pending = 0; |
| 3106 | ring->rx_jumbo_max_pending = 0; |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 3107 | ring->rx_pending = adapter->req_rx_add_entries_per_subcrq; |
| 3108 | ring->tx_pending = adapter->req_tx_entries_per_subcrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3109 | ring->rx_mini_pending = 0; |
| 3110 | ring->rx_jumbo_pending = 0; |
| 3111 | } |
| 3112 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3113 | static int ibmvnic_set_ringparam(struct net_device *netdev, |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 3114 | struct ethtool_ringparam *ring, |
| 3115 | struct kernel_ethtool_ringparam *kernel_ring, |
| 3116 | struct netlink_ext_ack *extack) |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3117 | { |
| 3118 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3119 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3120 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3121 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3122 | adapter->desired.rx_entries = ring->rx_pending; |
| 3123 | adapter->desired.tx_entries = ring->tx_pending; |
| 3124 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3125 | ret = wait_for_reset(adapter); |
| 3126 | |
| 3127 | if (!ret && |
| 3128 | (adapter->req_rx_add_entries_per_subcrq != ring->rx_pending || |
| 3129 | adapter->req_tx_entries_per_subcrq != ring->tx_pending)) |
| 3130 | netdev_info(netdev, |
| 3131 | "Could not match full ringsize request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 3132 | ring->rx_pending, ring->tx_pending, |
| 3133 | adapter->req_rx_add_entries_per_subcrq, |
| 3134 | adapter->req_tx_entries_per_subcrq); |
| 3135 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3136 | } |
| 3137 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 3138 | static void ibmvnic_get_channels(struct net_device *netdev, |
| 3139 | struct ethtool_channels *channels) |
| 3140 | { |
| 3141 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3142 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3143 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 3144 | channels->max_rx = adapter->max_rx_queues; |
| 3145 | channels->max_tx = adapter->max_tx_queues; |
| 3146 | } else { |
| 3147 | channels->max_rx = IBMVNIC_MAX_QUEUES; |
| 3148 | channels->max_tx = IBMVNIC_MAX_QUEUES; |
| 3149 | } |
| 3150 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 3151 | channels->max_other = 0; |
| 3152 | channels->max_combined = 0; |
| 3153 | channels->rx_count = adapter->req_rx_queues; |
| 3154 | channels->tx_count = adapter->req_tx_queues; |
| 3155 | channels->other_count = 0; |
| 3156 | channels->combined_count = 0; |
| 3157 | } |
| 3158 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3159 | static int ibmvnic_set_channels(struct net_device *netdev, |
| 3160 | struct ethtool_channels *channels) |
| 3161 | { |
| 3162 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3163 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3164 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3165 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3166 | adapter->desired.rx_queues = channels->rx_count; |
| 3167 | adapter->desired.tx_queues = channels->tx_count; |
| 3168 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3169 | ret = wait_for_reset(adapter); |
| 3170 | |
| 3171 | if (!ret && |
| 3172 | (adapter->req_rx_queues != channels->rx_count || |
| 3173 | adapter->req_tx_queues != channels->tx_count)) |
| 3174 | netdev_info(netdev, |
| 3175 | "Could not match full channels request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 3176 | channels->rx_count, channels->tx_count, |
| 3177 | adapter->req_rx_queues, adapter->req_tx_queues); |
| 3178 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3179 | } |
| 3180 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3181 | static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 3182 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3183 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3184 | int i; |
| 3185 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3186 | switch (stringset) { |
| 3187 | case ETH_SS_STATS: |
| 3188 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); |
| 3189 | i++, data += ETH_GSTRING_LEN) |
| 3190 | memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN); |
| 3191 | |
| 3192 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3193 | snprintf(data, ETH_GSTRING_LEN, "tx%d_packets", i); |
| 3194 | data += ETH_GSTRING_LEN; |
| 3195 | |
| 3196 | snprintf(data, ETH_GSTRING_LEN, "tx%d_bytes", i); |
| 3197 | data += ETH_GSTRING_LEN; |
| 3198 | |
| 3199 | snprintf(data, ETH_GSTRING_LEN, |
| 3200 | "tx%d_dropped_packets", i); |
| 3201 | data += ETH_GSTRING_LEN; |
| 3202 | } |
| 3203 | |
| 3204 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3205 | snprintf(data, ETH_GSTRING_LEN, "rx%d_packets", i); |
| 3206 | data += ETH_GSTRING_LEN; |
| 3207 | |
| 3208 | snprintf(data, ETH_GSTRING_LEN, "rx%d_bytes", i); |
| 3209 | data += ETH_GSTRING_LEN; |
| 3210 | |
| 3211 | snprintf(data, ETH_GSTRING_LEN, "rx%d_interrupts", i); |
| 3212 | data += ETH_GSTRING_LEN; |
| 3213 | } |
| 3214 | break; |
| 3215 | |
| 3216 | case ETH_SS_PRIV_FLAGS: |
| 3217 | for (i = 0; i < ARRAY_SIZE(ibmvnic_priv_flags); i++) |
| 3218 | strcpy(data + i * ETH_GSTRING_LEN, |
| 3219 | ibmvnic_priv_flags[i]); |
| 3220 | break; |
| 3221 | default: |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3222 | return; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3223 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | static int ibmvnic_get_sset_count(struct net_device *dev, int sset) |
| 3227 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3228 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 3229 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3230 | switch (sset) { |
| 3231 | case ETH_SS_STATS: |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3232 | return ARRAY_SIZE(ibmvnic_stats) + |
| 3233 | adapter->req_tx_queues * NUM_TX_STATS + |
| 3234 | adapter->req_rx_queues * NUM_RX_STATS; |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3235 | case ETH_SS_PRIV_FLAGS: |
| 3236 | return ARRAY_SIZE(ibmvnic_priv_flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3237 | default: |
| 3238 | return -EOPNOTSUPP; |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | static void ibmvnic_get_ethtool_stats(struct net_device *dev, |
| 3243 | struct ethtool_stats *stats, u64 *data) |
| 3244 | { |
| 3245 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 3246 | union ibmvnic_crq crq; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3247 | int i, j; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3248 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3249 | |
| 3250 | memset(&crq, 0, sizeof(crq)); |
| 3251 | crq.request_statistics.first = IBMVNIC_CRQ_CMD; |
| 3252 | crq.request_statistics.cmd = REQUEST_STATISTICS; |
| 3253 | crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token); |
| 3254 | crq.request_statistics.len = |
| 3255 | cpu_to_be32(sizeof(struct ibmvnic_statistics)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3256 | |
| 3257 | /* Wait for data to be written */ |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 3258 | reinit_completion(&adapter->stats_done); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3259 | rc = ibmvnic_send_crq(adapter, &crq); |
| 3260 | if (rc) |
| 3261 | return; |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 3262 | rc = ibmvnic_wait_for_completion(adapter, &adapter->stats_done, 10000); |
| 3263 | if (rc) |
| 3264 | return; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3265 | |
| 3266 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++) |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 3267 | data[i] = be64_to_cpu(IBMVNIC_GET_STAT |
| 3268 | (adapter, ibmvnic_stats[i].offset)); |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3269 | |
| 3270 | for (j = 0; j < adapter->req_tx_queues; j++) { |
| 3271 | data[i] = adapter->tx_stats_buffers[j].packets; |
| 3272 | i++; |
| 3273 | data[i] = adapter->tx_stats_buffers[j].bytes; |
| 3274 | i++; |
| 3275 | data[i] = adapter->tx_stats_buffers[j].dropped_packets; |
| 3276 | i++; |
| 3277 | } |
| 3278 | |
| 3279 | for (j = 0; j < adapter->req_rx_queues; j++) { |
| 3280 | data[i] = adapter->rx_stats_buffers[j].packets; |
| 3281 | i++; |
| 3282 | data[i] = adapter->rx_stats_buffers[j].bytes; |
| 3283 | i++; |
| 3284 | data[i] = adapter->rx_stats_buffers[j].interrupts; |
| 3285 | i++; |
| 3286 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3287 | } |
| 3288 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3289 | static u32 ibmvnic_get_priv_flags(struct net_device *netdev) |
| 3290 | { |
| 3291 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3292 | |
| 3293 | return adapter->priv_flags; |
| 3294 | } |
| 3295 | |
| 3296 | static int ibmvnic_set_priv_flags(struct net_device *netdev, u32 flags) |
| 3297 | { |
| 3298 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3299 | bool which_maxes = !!(flags & IBMVNIC_USE_SERVER_MAXES); |
| 3300 | |
| 3301 | if (which_maxes) |
| 3302 | adapter->priv_flags |= IBMVNIC_USE_SERVER_MAXES; |
| 3303 | else |
| 3304 | adapter->priv_flags &= ~IBMVNIC_USE_SERVER_MAXES; |
| 3305 | |
| 3306 | return 0; |
| 3307 | } |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 3308 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3309 | static const struct ethtool_ops ibmvnic_ethtool_ops = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3310 | .get_drvinfo = ibmvnic_get_drvinfo, |
| 3311 | .get_msglevel = ibmvnic_get_msglevel, |
| 3312 | .set_msglevel = ibmvnic_set_msglevel, |
| 3313 | .get_link = ibmvnic_get_link, |
| 3314 | .get_ringparam = ibmvnic_get_ringparam, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3315 | .set_ringparam = ibmvnic_set_ringparam, |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 3316 | .get_channels = ibmvnic_get_channels, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3317 | .set_channels = ibmvnic_set_channels, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3318 | .get_strings = ibmvnic_get_strings, |
| 3319 | .get_sset_count = ibmvnic_get_sset_count, |
| 3320 | .get_ethtool_stats = ibmvnic_get_ethtool_stats, |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 3321 | .get_link_ksettings = ibmvnic_get_link_ksettings, |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3322 | .get_priv_flags = ibmvnic_get_priv_flags, |
| 3323 | .set_priv_flags = ibmvnic_set_priv_flags, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3324 | }; |
| 3325 | |
| 3326 | /* Routines for managing CRQs/sCRQs */ |
| 3327 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3328 | static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter, |
| 3329 | struct ibmvnic_sub_crq_queue *scrq) |
| 3330 | { |
| 3331 | int rc; |
| 3332 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3333 | if (!scrq) { |
YANG LI | 862aecb | 2020-12-30 15:23:14 +0800 | [diff] [blame] | 3334 | netdev_dbg(adapter->netdev, "Invalid scrq reset.\n"); |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3335 | return -EINVAL; |
| 3336 | } |
| 3337 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3338 | if (scrq->irq) { |
| 3339 | free_irq(scrq->irq, scrq); |
| 3340 | irq_dispose_mapping(scrq->irq); |
| 3341 | scrq->irq = 0; |
| 3342 | } |
| 3343 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3344 | if (scrq->msgs) { |
| 3345 | memset(scrq->msgs, 0, 4 * PAGE_SIZE); |
| 3346 | atomic_set(&scrq->used, 0); |
| 3347 | scrq->cur = 0; |
Jakub Kicinski | 55fd59b | 2020-12-03 15:42:13 -0800 | [diff] [blame] | 3348 | scrq->ind_buf.index = 0; |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3349 | } else { |
| 3350 | netdev_dbg(adapter->netdev, "Invalid scrq reset\n"); |
| 3351 | return -EINVAL; |
| 3352 | } |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3353 | |
| 3354 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 3355 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 3356 | return rc; |
| 3357 | } |
| 3358 | |
| 3359 | static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter) |
| 3360 | { |
| 3361 | int i, rc; |
| 3362 | |
Lijun Pan | a0faaa2 | 2020-11-23 13:35:45 -0600 | [diff] [blame] | 3363 | if (!adapter->tx_scrq || !adapter->rx_scrq) |
| 3364 | return -EINVAL; |
| 3365 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3366 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3367 | netdev_dbg(adapter->netdev, "Re-setting tx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3368 | rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]); |
| 3369 | if (rc) |
| 3370 | return rc; |
| 3371 | } |
| 3372 | |
| 3373 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3374 | netdev_dbg(adapter->netdev, "Re-setting rx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3375 | rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]); |
| 3376 | if (rc) |
| 3377 | return rc; |
| 3378 | } |
| 3379 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3380 | return rc; |
| 3381 | } |
| 3382 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3383 | static void release_sub_crq_queue(struct ibmvnic_adapter *adapter, |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3384 | struct ibmvnic_sub_crq_queue *scrq, |
| 3385 | bool do_h_free) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3386 | { |
| 3387 | struct device *dev = &adapter->vdev->dev; |
| 3388 | long rc; |
| 3389 | |
| 3390 | netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n"); |
| 3391 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3392 | if (do_h_free) { |
| 3393 | /* Close the sub-crqs */ |
| 3394 | do { |
| 3395 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 3396 | adapter->vdev->unit_address, |
| 3397 | scrq->crq_num); |
| 3398 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3399 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3400 | if (rc) { |
| 3401 | netdev_err(adapter->netdev, |
| 3402 | "Failed to release sub-CRQ %16lx, rc = %ld\n", |
| 3403 | scrq->crq_num, rc); |
| 3404 | } |
Thomas Falcon | ffa7385 | 2017-04-19 13:44:29 -0400 | [diff] [blame] | 3405 | } |
| 3406 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3407 | dma_free_coherent(dev, |
| 3408 | IBMVNIC_IND_ARR_SZ, |
| 3409 | scrq->ind_buf.indir_arr, |
| 3410 | scrq->ind_buf.indir_dma); |
| 3411 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3412 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3413 | DMA_BIDIRECTIONAL); |
| 3414 | free_pages((unsigned long)scrq->msgs, 2); |
| 3415 | kfree(scrq); |
| 3416 | } |
| 3417 | |
| 3418 | static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter |
| 3419 | *adapter) |
| 3420 | { |
| 3421 | struct device *dev = &adapter->vdev->dev; |
| 3422 | struct ibmvnic_sub_crq_queue *scrq; |
| 3423 | int rc; |
| 3424 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3425 | scrq = kzalloc(sizeof(*scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3426 | if (!scrq) |
| 3427 | return NULL; |
| 3428 | |
Nathan Fontenot | 7f7adc5 | 2017-04-19 13:45:16 -0400 | [diff] [blame] | 3429 | scrq->msgs = |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3430 | (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3431 | if (!scrq->msgs) { |
| 3432 | dev_warn(dev, "Couldn't allocate crq queue messages page\n"); |
| 3433 | goto zero_page_failed; |
| 3434 | } |
| 3435 | |
| 3436 | scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE, |
| 3437 | DMA_BIDIRECTIONAL); |
| 3438 | if (dma_mapping_error(dev, scrq->msg_token)) { |
| 3439 | dev_warn(dev, "Couldn't map crq queue messages page\n"); |
| 3440 | goto map_failed; |
| 3441 | } |
| 3442 | |
| 3443 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 3444 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 3445 | |
| 3446 | if (rc == H_RESOURCE) |
| 3447 | rc = ibmvnic_reset_crq(adapter); |
| 3448 | |
| 3449 | if (rc == H_CLOSED) { |
| 3450 | dev_warn(dev, "Partner adapter not ready, waiting.\n"); |
| 3451 | } else if (rc) { |
| 3452 | dev_warn(dev, "Error %d registering sub-crq\n", rc); |
| 3453 | goto reg_failed; |
| 3454 | } |
| 3455 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3456 | scrq->adapter = adapter; |
| 3457 | scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs); |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3458 | scrq->ind_buf.index = 0; |
| 3459 | |
| 3460 | scrq->ind_buf.indir_arr = |
| 3461 | dma_alloc_coherent(dev, |
| 3462 | IBMVNIC_IND_ARR_SZ, |
| 3463 | &scrq->ind_buf.indir_dma, |
| 3464 | GFP_KERNEL); |
| 3465 | |
| 3466 | if (!scrq->ind_buf.indir_arr) |
| 3467 | goto indir_failed; |
| 3468 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3469 | spin_lock_init(&scrq->lock); |
| 3470 | |
| 3471 | netdev_dbg(adapter->netdev, |
| 3472 | "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n", |
| 3473 | scrq->crq_num, scrq->hw_irq, scrq->irq); |
| 3474 | |
| 3475 | return scrq; |
| 3476 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3477 | indir_failed: |
| 3478 | do { |
| 3479 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 3480 | adapter->vdev->unit_address, |
| 3481 | scrq->crq_num); |
| 3482 | } while (rc == H_BUSY || rc == H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3483 | reg_failed: |
| 3484 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3485 | DMA_BIDIRECTIONAL); |
| 3486 | map_failed: |
| 3487 | free_pages((unsigned long)scrq->msgs, 2); |
| 3488 | zero_page_failed: |
| 3489 | kfree(scrq); |
| 3490 | |
| 3491 | return NULL; |
| 3492 | } |
| 3493 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3494 | 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] | 3495 | { |
| 3496 | int i; |
| 3497 | |
| 3498 | if (adapter->tx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3499 | for (i = 0; i < adapter->num_active_tx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3500 | if (!adapter->tx_scrq[i]) |
| 3501 | continue; |
| 3502 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3503 | netdev_dbg(adapter->netdev, "Releasing tx_scrq[%d]\n", |
| 3504 | i); |
Sukadev Bhattiprolu | 65d6470 | 2021-06-23 21:13:12 -0700 | [diff] [blame] | 3505 | ibmvnic_tx_scrq_clean_buffer(adapter, adapter->tx_scrq[i]); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3506 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3507 | free_irq(adapter->tx_scrq[i]->irq, |
| 3508 | adapter->tx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3509 | irq_dispose_mapping(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3510 | adapter->tx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3511 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3512 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3513 | release_sub_crq_queue(adapter, adapter->tx_scrq[i], |
| 3514 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3515 | } |
| 3516 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3517 | kfree(adapter->tx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3518 | adapter->tx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3519 | adapter->num_active_tx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | if (adapter->rx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3523 | for (i = 0; i < adapter->num_active_rx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3524 | if (!adapter->rx_scrq[i]) |
| 3525 | continue; |
| 3526 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3527 | netdev_dbg(adapter->netdev, "Releasing rx_scrq[%d]\n", |
| 3528 | i); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3529 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3530 | free_irq(adapter->rx_scrq[i]->irq, |
| 3531 | adapter->rx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3532 | irq_dispose_mapping(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3533 | adapter->rx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3534 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3535 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3536 | release_sub_crq_queue(adapter, adapter->rx_scrq[i], |
| 3537 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3538 | } |
| 3539 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3540 | kfree(adapter->rx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3541 | adapter->rx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3542 | adapter->num_active_rx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3543 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | static int disable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3547 | struct ibmvnic_sub_crq_queue *scrq) |
| 3548 | { |
| 3549 | struct device *dev = &adapter->vdev->dev; |
| 3550 | unsigned long rc; |
| 3551 | |
| 3552 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3553 | H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3554 | if (rc) |
| 3555 | dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n", |
| 3556 | scrq->hw_irq, rc); |
| 3557 | return rc; |
| 3558 | } |
| 3559 | |
| 3560 | static int enable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3561 | struct ibmvnic_sub_crq_queue *scrq) |
| 3562 | { |
| 3563 | struct device *dev = &adapter->vdev->dev; |
| 3564 | unsigned long rc; |
| 3565 | |
| 3566 | if (scrq->hw_irq > 0x100000000ULL) { |
| 3567 | dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq); |
| 3568 | return 1; |
| 3569 | } |
| 3570 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 3571 | if (test_bit(0, &adapter->resetting) && |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3572 | adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3573 | u64 val = (0xff000000) | scrq->hw_irq; |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3574 | |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3575 | rc = plpar_hcall_norets(H_EOI, val); |
Juliet Kim | 2df5c60 | 2019-11-20 10:50:04 -0500 | [diff] [blame] | 3576 | /* H_EOI would fail with rc = H_FUNCTION when running |
| 3577 | * in XIVE mode which is expected, but not an error. |
| 3578 | */ |
Sukadev Bhattiprolu | 154b3b2 | 2021-06-23 21:13:16 -0700 | [diff] [blame] | 3579 | if (rc && (rc != H_FUNCTION)) |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3580 | dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n", |
| 3581 | val, rc); |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3582 | } |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 3583 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3584 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3585 | H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3586 | if (rc) |
| 3587 | dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n", |
| 3588 | scrq->hw_irq, rc); |
| 3589 | return rc; |
| 3590 | } |
| 3591 | |
| 3592 | static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter, |
| 3593 | struct ibmvnic_sub_crq_queue *scrq) |
| 3594 | { |
| 3595 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3596 | struct ibmvnic_tx_pool *tx_pool; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3597 | struct ibmvnic_tx_buff *txbuff; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3598 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3599 | union sub_crq *next; |
| 3600 | int index; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 3601 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3602 | |
| 3603 | restart_loop: |
| 3604 | while (pending_scrq(adapter, scrq)) { |
| 3605 | unsigned int pool = scrq->pool_index; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3606 | int num_entries = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3607 | int total_bytes = 0; |
| 3608 | int num_packets = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3609 | |
| 3610 | next = ibmvnic_next_scrq(adapter, scrq); |
| 3611 | for (i = 0; i < next->tx_comp.num_comps; i++) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3612 | index = be32_to_cpu(next->tx_comp.correlators[i]); |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3613 | if (index & IBMVNIC_TSO_POOL_MASK) { |
| 3614 | tx_pool = &adapter->tso_pool[pool]; |
| 3615 | index &= ~IBMVNIC_TSO_POOL_MASK; |
| 3616 | } else { |
| 3617 | tx_pool = &adapter->tx_pool[pool]; |
| 3618 | } |
| 3619 | |
| 3620 | txbuff = &tx_pool->tx_buff[index]; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3621 | num_packets++; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3622 | num_entries += txbuff->num_entries; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3623 | if (txbuff->skb) { |
| 3624 | total_bytes += txbuff->skb->len; |
Lijun Pan | ca09bf7 | 2021-04-13 03:33:25 -0500 | [diff] [blame] | 3625 | if (next->tx_comp.rcs[i]) { |
| 3626 | dev_err(dev, "tx error %x\n", |
| 3627 | next->tx_comp.rcs[i]); |
| 3628 | dev_kfree_skb_irq(txbuff->skb); |
| 3629 | } else { |
| 3630 | dev_consume_skb_irq(txbuff->skb); |
| 3631 | } |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3632 | txbuff->skb = NULL; |
| 3633 | } else { |
| 3634 | netdev_warn(adapter->netdev, |
| 3635 | "TX completion received with NULL socket buffer\n"); |
| 3636 | } |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3637 | tx_pool->free_map[tx_pool->producer_index] = index; |
| 3638 | tx_pool->producer_index = |
| 3639 | (tx_pool->producer_index + 1) % |
| 3640 | tx_pool->num_buffers; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3641 | } |
| 3642 | /* remove tx_comp scrq*/ |
| 3643 | next->tx_comp.first = 0; |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3644 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3645 | txq = netdev_get_tx_queue(adapter->netdev, scrq->pool_index); |
| 3646 | netdev_tx_completed_queue(txq, num_packets, total_bytes); |
| 3647 | |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3648 | if (atomic_sub_return(num_entries, &scrq->used) <= |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3649 | (adapter->req_tx_entries_per_subcrq / 2) && |
| 3650 | __netif_subqueue_stopped(adapter->netdev, |
| 3651 | scrq->pool_index)) { |
| 3652 | netif_wake_subqueue(adapter->netdev, scrq->pool_index); |
Thomas Falcon | 0aecb13 | 2018-02-26 18:10:58 -0600 | [diff] [blame] | 3653 | netdev_dbg(adapter->netdev, "Started queue %d\n", |
| 3654 | scrq->pool_index); |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3655 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | enable_scrq_irq(adapter, scrq); |
| 3659 | |
| 3660 | if (pending_scrq(adapter, scrq)) { |
| 3661 | disable_scrq_irq(adapter, scrq); |
| 3662 | goto restart_loop; |
| 3663 | } |
| 3664 | |
| 3665 | return 0; |
| 3666 | } |
| 3667 | |
| 3668 | static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance) |
| 3669 | { |
| 3670 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3671 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3672 | |
| 3673 | disable_scrq_irq(adapter, scrq); |
| 3674 | ibmvnic_complete_tx(adapter, scrq); |
| 3675 | |
| 3676 | return IRQ_HANDLED; |
| 3677 | } |
| 3678 | |
| 3679 | static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance) |
| 3680 | { |
| 3681 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3682 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3683 | |
Nathan Fontenot | 09fb35e | 2018-01-10 10:40:09 -0600 | [diff] [blame] | 3684 | /* When booting a kdump kernel we can hit pending interrupts |
| 3685 | * prior to completing driver initialization. |
| 3686 | */ |
| 3687 | if (unlikely(adapter->state != VNIC_OPEN)) |
| 3688 | return IRQ_NONE; |
| 3689 | |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3690 | adapter->rx_stats_buffers[scrq->scrq_num].interrupts++; |
| 3691 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3692 | if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) { |
| 3693 | disable_scrq_irq(adapter, scrq); |
| 3694 | __napi_schedule(&adapter->napi[scrq->scrq_num]); |
| 3695 | } |
| 3696 | |
| 3697 | return IRQ_HANDLED; |
| 3698 | } |
| 3699 | |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3700 | static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter) |
| 3701 | { |
| 3702 | struct device *dev = &adapter->vdev->dev; |
| 3703 | struct ibmvnic_sub_crq_queue *scrq; |
| 3704 | int i = 0, j = 0; |
| 3705 | int rc = 0; |
| 3706 | |
| 3707 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3708 | netdev_dbg(adapter->netdev, "Initializing tx_scrq[%d] irq\n", |
| 3709 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3710 | scrq = adapter->tx_scrq[i]; |
| 3711 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
| 3712 | |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3713 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3714 | rc = -EINVAL; |
| 3715 | dev_err(dev, "Error mapping irq\n"); |
| 3716 | goto req_tx_irq_failed; |
| 3717 | } |
| 3718 | |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3719 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-tx%d", |
| 3720 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3721 | rc = request_irq(scrq->irq, ibmvnic_interrupt_tx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3722 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3723 | |
| 3724 | if (rc) { |
| 3725 | dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n", |
| 3726 | scrq->irq, rc); |
| 3727 | irq_dispose_mapping(scrq->irq); |
Nathan Fontenot | af9090c | 2018-02-20 11:04:18 -0600 | [diff] [blame] | 3728 | goto req_tx_irq_failed; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3733 | netdev_dbg(adapter->netdev, "Initializing rx_scrq[%d] irq\n", |
| 3734 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3735 | scrq = adapter->rx_scrq[i]; |
| 3736 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3737 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3738 | rc = -EINVAL; |
| 3739 | dev_err(dev, "Error mapping irq\n"); |
| 3740 | goto req_rx_irq_failed; |
| 3741 | } |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3742 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-rx%d", |
| 3743 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3744 | rc = request_irq(scrq->irq, ibmvnic_interrupt_rx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3745 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3746 | if (rc) { |
| 3747 | dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n", |
| 3748 | scrq->irq, rc); |
| 3749 | irq_dispose_mapping(scrq->irq); |
| 3750 | goto req_rx_irq_failed; |
| 3751 | } |
| 3752 | } |
| 3753 | return rc; |
| 3754 | |
| 3755 | req_rx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3756 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3757 | free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]); |
| 3758 | irq_dispose_mapping(adapter->rx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3759 | } |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3760 | i = adapter->req_tx_queues; |
| 3761 | req_tx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3762 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3763 | free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]); |
Thomas Falcon | 27a2145 | 2020-07-29 16:36:32 -0500 | [diff] [blame] | 3764 | irq_dispose_mapping(adapter->tx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3765 | } |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3766 | release_sub_crqs(adapter, 1); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3767 | return rc; |
| 3768 | } |
| 3769 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3770 | static int init_sub_crqs(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3771 | { |
| 3772 | struct device *dev = &adapter->vdev->dev; |
| 3773 | struct ibmvnic_sub_crq_queue **allqueues; |
| 3774 | int registered_queues = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3775 | int total_queues; |
| 3776 | int more = 0; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3777 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3778 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3779 | total_queues = adapter->req_tx_queues + adapter->req_rx_queues; |
| 3780 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3781 | allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3782 | if (!allqueues) |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 3783 | return -ENOMEM; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3784 | |
| 3785 | for (i = 0; i < total_queues; i++) { |
| 3786 | allqueues[i] = init_sub_crq_queue(adapter); |
| 3787 | if (!allqueues[i]) { |
| 3788 | dev_warn(dev, "Couldn't allocate all sub-crqs\n"); |
| 3789 | break; |
| 3790 | } |
| 3791 | registered_queues++; |
| 3792 | } |
| 3793 | |
| 3794 | /* Make sure we were able to register the minimum number of queues */ |
| 3795 | if (registered_queues < |
| 3796 | adapter->min_tx_queues + adapter->min_rx_queues) { |
| 3797 | dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n"); |
| 3798 | goto tx_failed; |
| 3799 | } |
| 3800 | |
| 3801 | /* Distribute the failed allocated queues*/ |
| 3802 | for (i = 0; i < total_queues - registered_queues + more ; i++) { |
| 3803 | netdev_dbg(adapter->netdev, "Reducing number of queues\n"); |
| 3804 | switch (i % 3) { |
| 3805 | case 0: |
| 3806 | if (adapter->req_rx_queues > adapter->min_rx_queues) |
| 3807 | adapter->req_rx_queues--; |
| 3808 | else |
| 3809 | more++; |
| 3810 | break; |
| 3811 | case 1: |
| 3812 | if (adapter->req_tx_queues > adapter->min_tx_queues) |
| 3813 | adapter->req_tx_queues--; |
| 3814 | else |
| 3815 | more++; |
| 3816 | break; |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | adapter->tx_scrq = kcalloc(adapter->req_tx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3821 | sizeof(*adapter->tx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3822 | if (!adapter->tx_scrq) |
| 3823 | goto tx_failed; |
| 3824 | |
| 3825 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3826 | adapter->tx_scrq[i] = allqueues[i]; |
| 3827 | adapter->tx_scrq[i]->pool_index = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3828 | adapter->num_active_tx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | adapter->rx_scrq = kcalloc(adapter->req_rx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3832 | sizeof(*adapter->rx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3833 | if (!adapter->rx_scrq) |
| 3834 | goto rx_failed; |
| 3835 | |
| 3836 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3837 | adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues]; |
| 3838 | adapter->rx_scrq[i]->scrq_num = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3839 | adapter->num_active_rx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3840 | } |
| 3841 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3842 | kfree(allqueues); |
| 3843 | return 0; |
| 3844 | |
| 3845 | rx_failed: |
| 3846 | kfree(adapter->tx_scrq); |
| 3847 | adapter->tx_scrq = NULL; |
| 3848 | tx_failed: |
| 3849 | for (i = 0; i < registered_queues; i++) |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3850 | release_sub_crq_queue(adapter, allqueues[i], 1); |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3851 | kfree(allqueues); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 3852 | return -ENOMEM; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3853 | } |
| 3854 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 3855 | static void send_request_cap(struct ibmvnic_adapter *adapter, int retry) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3856 | { |
| 3857 | struct device *dev = &adapter->vdev->dev; |
| 3858 | union ibmvnic_crq crq; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3859 | int max_entries; |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3860 | int cap_reqs; |
| 3861 | |
| 3862 | /* We send out 6 or 7 REQUEST_CAPABILITY CRQs below (depending on |
| 3863 | * the PROMISC flag). Initialize this count upfront. When the tasklet |
| 3864 | * receives a response to all of these, it will send the next protocol |
| 3865 | * message (QUERY_IP_OFFLOAD). |
| 3866 | */ |
| 3867 | if (!(adapter->netdev->flags & IFF_PROMISC) || |
| 3868 | adapter->promisc_supported) |
| 3869 | cap_reqs = 7; |
| 3870 | else |
| 3871 | cap_reqs = 6; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3872 | |
| 3873 | if (!retry) { |
| 3874 | /* Sub-CRQ entries are 32 byte long */ |
| 3875 | int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4); |
| 3876 | |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3877 | atomic_set(&adapter->running_cap_crqs, cap_reqs); |
| 3878 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3879 | if (adapter->min_tx_entries_per_subcrq > entries_page || |
| 3880 | adapter->min_rx_add_entries_per_subcrq > entries_page) { |
| 3881 | dev_err(dev, "Fatal, invalid entries per sub-crq\n"); |
| 3882 | return; |
| 3883 | } |
| 3884 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3885 | if (adapter->desired.mtu) |
| 3886 | adapter->req_mtu = adapter->desired.mtu; |
| 3887 | else |
| 3888 | adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3889 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3890 | if (!adapter->desired.tx_entries) |
| 3891 | adapter->desired.tx_entries = |
| 3892 | adapter->max_tx_entries_per_subcrq; |
| 3893 | if (!adapter->desired.rx_entries) |
| 3894 | adapter->desired.rx_entries = |
| 3895 | adapter->max_rx_add_entries_per_subcrq; |
| 3896 | |
| 3897 | max_entries = IBMVNIC_MAX_LTB_SIZE / |
| 3898 | (adapter->req_mtu + IBMVNIC_BUFFER_HLEN); |
| 3899 | |
| 3900 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3901 | adapter->desired.tx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3902 | adapter->desired.tx_entries = max_entries; |
| 3903 | } |
| 3904 | |
| 3905 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3906 | adapter->desired.rx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3907 | adapter->desired.rx_entries = max_entries; |
| 3908 | } |
| 3909 | |
| 3910 | if (adapter->desired.tx_entries) |
| 3911 | adapter->req_tx_entries_per_subcrq = |
| 3912 | adapter->desired.tx_entries; |
| 3913 | else |
| 3914 | adapter->req_tx_entries_per_subcrq = |
| 3915 | adapter->max_tx_entries_per_subcrq; |
| 3916 | |
| 3917 | if (adapter->desired.rx_entries) |
| 3918 | adapter->req_rx_add_entries_per_subcrq = |
| 3919 | adapter->desired.rx_entries; |
| 3920 | else |
| 3921 | adapter->req_rx_add_entries_per_subcrq = |
| 3922 | adapter->max_rx_add_entries_per_subcrq; |
| 3923 | |
| 3924 | if (adapter->desired.tx_queues) |
| 3925 | adapter->req_tx_queues = |
| 3926 | adapter->desired.tx_queues; |
| 3927 | else |
| 3928 | adapter->req_tx_queues = |
| 3929 | adapter->opt_tx_comp_sub_queues; |
| 3930 | |
| 3931 | if (adapter->desired.rx_queues) |
| 3932 | adapter->req_rx_queues = |
| 3933 | adapter->desired.rx_queues; |
| 3934 | else |
| 3935 | adapter->req_rx_queues = |
| 3936 | adapter->opt_rx_comp_queues; |
| 3937 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3938 | adapter->req_rx_add_queues = adapter->max_rx_add_queues; |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3939 | } else { |
| 3940 | atomic_add(cap_reqs, &adapter->running_cap_crqs); |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3941 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3942 | memset(&crq, 0, sizeof(crq)); |
| 3943 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 3944 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 3945 | |
| 3946 | crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3947 | crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3948 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3949 | ibmvnic_send_crq(adapter, &crq); |
| 3950 | |
| 3951 | crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3952 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3953 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3954 | ibmvnic_send_crq(adapter, &crq); |
| 3955 | |
| 3956 | crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3957 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3958 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3959 | ibmvnic_send_crq(adapter, &crq); |
| 3960 | |
| 3961 | crq.request_capability.capability = |
| 3962 | cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ); |
| 3963 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3964 | cpu_to_be64(adapter->req_tx_entries_per_subcrq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3965 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3966 | ibmvnic_send_crq(adapter, &crq); |
| 3967 | |
| 3968 | crq.request_capability.capability = |
| 3969 | cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ); |
| 3970 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3971 | cpu_to_be64(adapter->req_rx_add_entries_per_subcrq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3972 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3973 | ibmvnic_send_crq(adapter, &crq); |
| 3974 | |
| 3975 | crq.request_capability.capability = cpu_to_be16(REQ_MTU); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3976 | crq.request_capability.number = cpu_to_be64(adapter->req_mtu); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3977 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3978 | ibmvnic_send_crq(adapter, &crq); |
| 3979 | |
| 3980 | if (adapter->netdev->flags & IFF_PROMISC) { |
| 3981 | if (adapter->promisc_supported) { |
| 3982 | crq.request_capability.capability = |
| 3983 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3984 | crq.request_capability.number = cpu_to_be64(1); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3985 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3986 | ibmvnic_send_crq(adapter, &crq); |
| 3987 | } |
| 3988 | } else { |
| 3989 | crq.request_capability.capability = |
| 3990 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3991 | crq.request_capability.number = cpu_to_be64(0); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3992 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3993 | ibmvnic_send_crq(adapter, &crq); |
| 3994 | } |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 3995 | |
| 3996 | /* Keep at end to catch any discrepancy between expected and actual |
| 3997 | * CRQs sent. |
| 3998 | */ |
| 3999 | WARN_ON(cap_reqs != 0); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | static int pending_scrq(struct ibmvnic_adapter *adapter, |
| 4003 | struct ibmvnic_sub_crq_queue *scrq) |
| 4004 | { |
| 4005 | union sub_crq *entry = &scrq->msgs[scrq->cur]; |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 4006 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4007 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 4008 | rc = !!(entry->generic.first & IBMVNIC_CRQ_CMD_RSP); |
| 4009 | |
| 4010 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 4011 | * contents of the SCRQ descriptor |
| 4012 | */ |
| 4013 | dma_rmb(); |
| 4014 | |
| 4015 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter, |
| 4019 | struct ibmvnic_sub_crq_queue *scrq) |
| 4020 | { |
| 4021 | union sub_crq *entry; |
| 4022 | unsigned long flags; |
| 4023 | |
| 4024 | spin_lock_irqsave(&scrq->lock, flags); |
| 4025 | entry = &scrq->msgs[scrq->cur]; |
| 4026 | if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 4027 | if (++scrq->cur == scrq->size) |
| 4028 | scrq->cur = 0; |
| 4029 | } else { |
| 4030 | entry = NULL; |
| 4031 | } |
| 4032 | spin_unlock_irqrestore(&scrq->lock, flags); |
| 4033 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 4034 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 4035 | * contents of the SCRQ descriptor |
Thomas Falcon | b71ec95 | 2020-12-01 09:52:10 -0600 | [diff] [blame] | 4036 | */ |
| 4037 | dma_rmb(); |
| 4038 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4039 | return entry; |
| 4040 | } |
| 4041 | |
| 4042 | static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter) |
| 4043 | { |
| 4044 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
| 4045 | union ibmvnic_crq *crq; |
| 4046 | |
| 4047 | crq = &queue->msgs[queue->cur]; |
| 4048 | if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 4049 | if (++queue->cur == queue->size) |
| 4050 | queue->cur = 0; |
| 4051 | } else { |
| 4052 | crq = NULL; |
| 4053 | } |
| 4054 | |
| 4055 | return crq; |
| 4056 | } |
| 4057 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 4058 | static void print_subcrq_error(struct device *dev, int rc, const char *func) |
| 4059 | { |
| 4060 | switch (rc) { |
| 4061 | case H_PARAMETER: |
| 4062 | dev_warn_ratelimited(dev, |
| 4063 | "%s failed: Send request is malformed or adapter failover pending. (rc=%d)\n", |
| 4064 | func, rc); |
| 4065 | break; |
| 4066 | case H_CLOSED: |
| 4067 | dev_warn_ratelimited(dev, |
| 4068 | "%s failed: Backing queue closed. Adapter is down or failover pending. (rc=%d)\n", |
| 4069 | func, rc); |
| 4070 | break; |
| 4071 | default: |
| 4072 | dev_err_ratelimited(dev, "%s failed: (rc=%d)\n", func, rc); |
| 4073 | break; |
| 4074 | } |
| 4075 | } |
| 4076 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 4077 | static int send_subcrq_indirect(struct ibmvnic_adapter *adapter, |
| 4078 | u64 remote_handle, u64 ioba, u64 num_entries) |
| 4079 | { |
| 4080 | unsigned int ua = adapter->vdev->unit_address; |
| 4081 | struct device *dev = &adapter->vdev->dev; |
| 4082 | int rc; |
| 4083 | |
| 4084 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 4085 | dma_wmb(); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 4086 | rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua, |
| 4087 | cpu_to_be64(remote_handle), |
| 4088 | ioba, num_entries); |
| 4089 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 4090 | if (rc) |
| 4091 | print_subcrq_error(dev, rc, __func__); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 4092 | |
| 4093 | return rc; |
| 4094 | } |
| 4095 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4096 | static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter, |
| 4097 | union ibmvnic_crq *crq) |
| 4098 | { |
| 4099 | unsigned int ua = adapter->vdev->unit_address; |
| 4100 | struct device *dev = &adapter->vdev->dev; |
| 4101 | u64 *u64_crq = (u64 *)crq; |
| 4102 | int rc; |
| 4103 | |
| 4104 | netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4105 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 4106 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4107 | |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 4108 | if (!adapter->crq.active && |
| 4109 | crq->generic.first != IBMVNIC_CRQ_INIT_CMD) { |
| 4110 | dev_warn(dev, "Invalid request detected while CRQ is inactive, possible device state change during reset\n"); |
| 4111 | return -EINVAL; |
| 4112 | } |
| 4113 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4114 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 4115 | dma_wmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4116 | |
| 4117 | rc = plpar_hcall_norets(H_SEND_CRQ, ua, |
| 4118 | cpu_to_be64(u64_crq[0]), |
| 4119 | cpu_to_be64(u64_crq[1])); |
| 4120 | |
| 4121 | if (rc) { |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 4122 | if (rc == H_CLOSED) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4123 | dev_warn(dev, "CRQ Queue closed\n"); |
Lijun Pan | fa68bfa | 2020-08-19 17:52:24 -0500 | [diff] [blame] | 4124 | /* do not reset, report the fail, wait for passive init from server */ |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 4125 | } |
| 4126 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4127 | dev_warn(dev, "Send error (rc=%d)\n", rc); |
| 4128 | } |
| 4129 | |
| 4130 | return rc; |
| 4131 | } |
| 4132 | |
| 4133 | static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter) |
| 4134 | { |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 4135 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4136 | union ibmvnic_crq crq; |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 4137 | int retries = 100; |
| 4138 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4139 | |
| 4140 | memset(&crq, 0, sizeof(crq)); |
| 4141 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 4142 | crq.generic.cmd = IBMVNIC_CRQ_INIT; |
| 4143 | netdev_dbg(adapter->netdev, "Sending CRQ init\n"); |
| 4144 | |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 4145 | do { |
| 4146 | rc = ibmvnic_send_crq(adapter, &crq); |
| 4147 | if (rc != H_CLOSED) |
| 4148 | break; |
| 4149 | retries--; |
| 4150 | msleep(50); |
| 4151 | |
| 4152 | } while (retries > 0); |
| 4153 | |
| 4154 | if (rc) { |
| 4155 | dev_err(dev, "Failed to send init request, rc = %d\n", rc); |
| 4156 | return rc; |
| 4157 | } |
| 4158 | |
| 4159 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4160 | } |
| 4161 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4162 | struct vnic_login_client_data { |
| 4163 | u8 type; |
| 4164 | __be16 len; |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 4165 | char name[]; |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4166 | } __packed; |
| 4167 | |
| 4168 | static int vnic_client_data_len(struct ibmvnic_adapter *adapter) |
| 4169 | { |
| 4170 | int len; |
| 4171 | |
| 4172 | /* Calculate the amount of buffer space needed for the |
| 4173 | * vnic client data in the login buffer. There are four entries, |
| 4174 | * OS name, LPAR name, device name, and a null last entry. |
| 4175 | */ |
| 4176 | len = 4 * sizeof(struct vnic_login_client_data); |
| 4177 | len += 6; /* "Linux" plus NULL */ |
| 4178 | len += strlen(utsname()->nodename) + 1; |
| 4179 | len += strlen(adapter->netdev->name) + 1; |
| 4180 | |
| 4181 | return len; |
| 4182 | } |
| 4183 | |
| 4184 | static void vnic_add_client_data(struct ibmvnic_adapter *adapter, |
| 4185 | struct vnic_login_client_data *vlcd) |
| 4186 | { |
| 4187 | const char *os_name = "Linux"; |
| 4188 | int len; |
| 4189 | |
| 4190 | /* Type 1 - LPAR OS */ |
| 4191 | vlcd->type = 1; |
| 4192 | len = strlen(os_name) + 1; |
| 4193 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4194 | strscpy(vlcd->name, os_name, len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 4195 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4196 | |
| 4197 | /* Type 2 - LPAR name */ |
| 4198 | vlcd->type = 2; |
| 4199 | len = strlen(utsname()->nodename) + 1; |
| 4200 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4201 | strscpy(vlcd->name, utsname()->nodename, len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 4202 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4203 | |
| 4204 | /* Type 3 - device name */ |
| 4205 | vlcd->type = 3; |
| 4206 | len = strlen(adapter->netdev->name) + 1; |
| 4207 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4208 | strscpy(vlcd->name, adapter->netdev->name, len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4209 | } |
| 4210 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4211 | static int send_login(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4212 | { |
| 4213 | struct ibmvnic_login_rsp_buffer *login_rsp_buffer; |
| 4214 | struct ibmvnic_login_buffer *login_buffer; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4215 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4216 | struct vnic_login_client_data *vlcd; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4217 | dma_addr_t rsp_buffer_token; |
| 4218 | dma_addr_t buffer_token; |
| 4219 | size_t rsp_buffer_size; |
| 4220 | union ibmvnic_crq crq; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4221 | int client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4222 | size_t buffer_size; |
| 4223 | __be64 *tx_list_p; |
| 4224 | __be64 *rx_list_p; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4225 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4226 | int i; |
| 4227 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4228 | if (!adapter->tx_scrq || !adapter->rx_scrq) { |
| 4229 | netdev_err(adapter->netdev, |
| 4230 | "RX or TX queues are not allocated, device login failed\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 4231 | return -ENOMEM; |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4232 | } |
| 4233 | |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 4234 | release_login_buffer(adapter); |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 4235 | release_login_rsp_buffer(adapter); |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 4236 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4237 | client_data_len = vnic_client_data_len(adapter); |
| 4238 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4239 | buffer_size = |
| 4240 | sizeof(struct ibmvnic_login_buffer) + |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4241 | sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues) + |
| 4242 | client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4243 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4244 | login_buffer = kzalloc(buffer_size, GFP_ATOMIC); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4245 | if (!login_buffer) |
| 4246 | goto buf_alloc_failed; |
| 4247 | |
| 4248 | buffer_token = dma_map_single(dev, login_buffer, buffer_size, |
| 4249 | DMA_TO_DEVICE); |
| 4250 | if (dma_mapping_error(dev, buffer_token)) { |
| 4251 | dev_err(dev, "Couldn't map login buffer\n"); |
| 4252 | goto buf_map_failed; |
| 4253 | } |
| 4254 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4255 | rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) + |
| 4256 | sizeof(u64) * adapter->req_tx_queues + |
| 4257 | sizeof(u64) * adapter->req_rx_queues + |
| 4258 | sizeof(u64) * adapter->req_rx_queues + |
| 4259 | sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4260 | |
| 4261 | login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC); |
| 4262 | if (!login_rsp_buffer) |
| 4263 | goto buf_rsp_alloc_failed; |
| 4264 | |
| 4265 | rsp_buffer_token = dma_map_single(dev, login_rsp_buffer, |
| 4266 | rsp_buffer_size, DMA_FROM_DEVICE); |
| 4267 | if (dma_mapping_error(dev, rsp_buffer_token)) { |
| 4268 | dev_err(dev, "Couldn't map login rsp buffer\n"); |
| 4269 | goto buf_rsp_map_failed; |
| 4270 | } |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 4271 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4272 | adapter->login_buf = login_buffer; |
| 4273 | adapter->login_buf_token = buffer_token; |
| 4274 | adapter->login_buf_sz = buffer_size; |
| 4275 | adapter->login_rsp_buf = login_rsp_buffer; |
| 4276 | adapter->login_rsp_buf_token = rsp_buffer_token; |
| 4277 | adapter->login_rsp_buf_sz = rsp_buffer_size; |
| 4278 | |
| 4279 | login_buffer->len = cpu_to_be32(buffer_size); |
| 4280 | login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB); |
| 4281 | login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues); |
| 4282 | login_buffer->off_txcomp_subcrqs = |
| 4283 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer)); |
| 4284 | login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues); |
| 4285 | login_buffer->off_rxcomp_subcrqs = |
| 4286 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer) + |
| 4287 | sizeof(u64) * adapter->req_tx_queues); |
| 4288 | login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token); |
| 4289 | login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size); |
| 4290 | |
| 4291 | tx_list_p = (__be64 *)((char *)login_buffer + |
| 4292 | sizeof(struct ibmvnic_login_buffer)); |
| 4293 | rx_list_p = (__be64 *)((char *)login_buffer + |
| 4294 | sizeof(struct ibmvnic_login_buffer) + |
| 4295 | sizeof(u64) * adapter->req_tx_queues); |
| 4296 | |
| 4297 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 4298 | if (adapter->tx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4299 | tx_list_p[i] = |
| 4300 | cpu_to_be64(adapter->tx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 4305 | if (adapter->rx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4306 | rx_list_p[i] = |
| 4307 | cpu_to_be64(adapter->rx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4311 | /* Insert vNIC login client data */ |
| 4312 | vlcd = (struct vnic_login_client_data *) |
| 4313 | ((char *)rx_list_p + (sizeof(u64) * adapter->req_rx_queues)); |
| 4314 | login_buffer->client_data_offset = |
| 4315 | cpu_to_be32((char *)vlcd - (char *)login_buffer); |
| 4316 | login_buffer->client_data_len = cpu_to_be32(client_data_len); |
| 4317 | |
| 4318 | vnic_add_client_data(adapter, vlcd); |
| 4319 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4320 | netdev_dbg(adapter->netdev, "Login Buffer:\n"); |
| 4321 | for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) { |
| 4322 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4323 | ((unsigned long *)(adapter->login_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | memset(&crq, 0, sizeof(crq)); |
| 4327 | crq.login.first = IBMVNIC_CRQ_CMD; |
| 4328 | crq.login.cmd = LOGIN; |
| 4329 | crq.login.ioba = cpu_to_be32(buffer_token); |
| 4330 | crq.login.len = cpu_to_be32(buffer_size); |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4331 | |
| 4332 | adapter->login_pending = true; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4333 | rc = ibmvnic_send_crq(adapter, &crq); |
| 4334 | if (rc) { |
| 4335 | adapter->login_pending = false; |
| 4336 | netdev_err(adapter->netdev, "Failed to send login, rc=%d\n", rc); |
| 4337 | goto buf_rsp_map_failed; |
| 4338 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4339 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4340 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4341 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4342 | buf_rsp_map_failed: |
| 4343 | kfree(login_rsp_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4344 | adapter->login_rsp_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4345 | buf_rsp_alloc_failed: |
| 4346 | dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE); |
| 4347 | buf_map_failed: |
| 4348 | kfree(login_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4349 | adapter->login_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4350 | buf_alloc_failed: |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 4351 | return -ENOMEM; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4352 | } |
| 4353 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4354 | static int send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr, |
| 4355 | u32 len, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4356 | { |
| 4357 | union ibmvnic_crq crq; |
| 4358 | |
| 4359 | memset(&crq, 0, sizeof(crq)); |
| 4360 | crq.request_map.first = IBMVNIC_CRQ_CMD; |
| 4361 | crq.request_map.cmd = REQUEST_MAP; |
| 4362 | crq.request_map.map_id = map_id; |
| 4363 | crq.request_map.ioba = cpu_to_be32(addr); |
| 4364 | crq.request_map.len = cpu_to_be32(len); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4365 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4366 | } |
| 4367 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4368 | static int send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4369 | { |
| 4370 | union ibmvnic_crq crq; |
| 4371 | |
| 4372 | memset(&crq, 0, sizeof(crq)); |
| 4373 | crq.request_unmap.first = IBMVNIC_CRQ_CMD; |
| 4374 | crq.request_unmap.cmd = REQUEST_UNMAP; |
| 4375 | crq.request_unmap.map_id = map_id; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4376 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4377 | } |
| 4378 | |
Lijun Pan | 69980d0 | 2020-09-27 20:13:28 -0500 | [diff] [blame] | 4379 | static void send_query_map(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4380 | { |
| 4381 | union ibmvnic_crq crq; |
| 4382 | |
| 4383 | memset(&crq, 0, sizeof(crq)); |
| 4384 | crq.query_map.first = IBMVNIC_CRQ_CMD; |
| 4385 | crq.query_map.cmd = QUERY_MAP; |
| 4386 | ibmvnic_send_crq(adapter, &crq); |
| 4387 | } |
| 4388 | |
| 4389 | /* Send a series of CRQs requesting various capabilities of the VNIC server */ |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 4390 | static void send_query_cap(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4391 | { |
| 4392 | union ibmvnic_crq crq; |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4393 | int cap_reqs; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4394 | |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4395 | /* We send out 25 QUERY_CAPABILITY CRQs below. Initialize this count |
| 4396 | * upfront. When the tasklet receives a response to all of these, it |
| 4397 | * can send out the next protocol messaage (REQUEST_CAPABILITY). |
| 4398 | */ |
| 4399 | cap_reqs = 25; |
| 4400 | |
| 4401 | atomic_set(&adapter->running_cap_crqs, cap_reqs); |
| 4402 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4403 | memset(&crq, 0, sizeof(crq)); |
| 4404 | crq.query_capability.first = IBMVNIC_CRQ_CMD; |
| 4405 | crq.query_capability.cmd = QUERY_CAPABILITY; |
| 4406 | |
| 4407 | crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4408 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4409 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4410 | |
| 4411 | crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4412 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4413 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4414 | |
| 4415 | crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4416 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4417 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4418 | |
| 4419 | crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4420 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4421 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4422 | |
| 4423 | crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4424 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4425 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4426 | |
| 4427 | crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4428 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4429 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4430 | |
| 4431 | crq.query_capability.capability = |
| 4432 | cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4433 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4434 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4435 | |
| 4436 | crq.query_capability.capability = |
| 4437 | cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4438 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4439 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4440 | |
| 4441 | crq.query_capability.capability = |
| 4442 | cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4443 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4444 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4445 | |
| 4446 | crq.query_capability.capability = |
| 4447 | cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4448 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4449 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4450 | |
| 4451 | crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4452 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4453 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4454 | |
| 4455 | crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4456 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4457 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4458 | |
| 4459 | crq.query_capability.capability = cpu_to_be16(MIN_MTU); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4460 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4461 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4462 | |
| 4463 | crq.query_capability.capability = cpu_to_be16(MAX_MTU); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4464 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4465 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4466 | |
| 4467 | crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4468 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4469 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4470 | |
| 4471 | crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4472 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4473 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4474 | |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4475 | crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION); |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4476 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4477 | cap_reqs--; |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4478 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4479 | crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4480 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4481 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4482 | |
| 4483 | crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4484 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4485 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4486 | |
| 4487 | crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4488 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4489 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4490 | |
| 4491 | crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4492 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4493 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4494 | |
| 4495 | crq.query_capability.capability = |
| 4496 | cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4497 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4498 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4499 | |
| 4500 | crq.query_capability.capability = |
| 4501 | cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4502 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4503 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4504 | |
| 4505 | crq.query_capability.capability = |
| 4506 | cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4507 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4508 | cap_reqs--; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4509 | |
| 4510 | crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4511 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4512 | ibmvnic_send_crq(adapter, &crq); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4513 | cap_reqs--; |
| 4514 | |
| 4515 | /* Keep at end to catch any discrepancy between expected and actual |
| 4516 | * CRQs sent. |
| 4517 | */ |
| 4518 | WARN_ON(cap_reqs != 0); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4519 | } |
| 4520 | |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4521 | static void send_query_ip_offload(struct ibmvnic_adapter *adapter) |
| 4522 | { |
| 4523 | int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer); |
| 4524 | struct device *dev = &adapter->vdev->dev; |
| 4525 | union ibmvnic_crq crq; |
| 4526 | |
| 4527 | adapter->ip_offload_tok = |
| 4528 | dma_map_single(dev, |
| 4529 | &adapter->ip_offload_buf, |
| 4530 | buf_sz, |
| 4531 | DMA_FROM_DEVICE); |
| 4532 | |
| 4533 | if (dma_mapping_error(dev, adapter->ip_offload_tok)) { |
| 4534 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
| 4535 | dev_err(dev, "Couldn't map offload buffer\n"); |
| 4536 | return; |
| 4537 | } |
| 4538 | |
| 4539 | memset(&crq, 0, sizeof(crq)); |
| 4540 | crq.query_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4541 | crq.query_ip_offload.cmd = QUERY_IP_OFFLOAD; |
| 4542 | crq.query_ip_offload.len = cpu_to_be32(buf_sz); |
| 4543 | crq.query_ip_offload.ioba = |
| 4544 | cpu_to_be32(adapter->ip_offload_tok); |
| 4545 | |
| 4546 | ibmvnic_send_crq(adapter, &crq); |
| 4547 | } |
| 4548 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4549 | static void send_control_ip_offload(struct ibmvnic_adapter *adapter) |
| 4550 | { |
| 4551 | struct ibmvnic_control_ip_offload_buffer *ctrl_buf = &adapter->ip_offload_ctrl; |
| 4552 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
| 4553 | struct device *dev = &adapter->vdev->dev; |
| 4554 | netdev_features_t old_hw_features = 0; |
| 4555 | union ibmvnic_crq crq; |
| 4556 | |
| 4557 | adapter->ip_offload_ctrl_tok = |
| 4558 | dma_map_single(dev, |
| 4559 | ctrl_buf, |
| 4560 | sizeof(adapter->ip_offload_ctrl), |
| 4561 | DMA_TO_DEVICE); |
| 4562 | |
| 4563 | if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) { |
| 4564 | dev_err(dev, "Couldn't map ip offload control buffer\n"); |
| 4565 | return; |
| 4566 | } |
| 4567 | |
| 4568 | ctrl_buf->len = cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4569 | ctrl_buf->version = cpu_to_be32(INITIAL_VERSION_IOB); |
| 4570 | ctrl_buf->ipv4_chksum = buf->ipv4_chksum; |
| 4571 | ctrl_buf->ipv6_chksum = buf->ipv6_chksum; |
| 4572 | ctrl_buf->tcp_ipv4_chksum = buf->tcp_ipv4_chksum; |
| 4573 | ctrl_buf->udp_ipv4_chksum = buf->udp_ipv4_chksum; |
| 4574 | ctrl_buf->tcp_ipv6_chksum = buf->tcp_ipv6_chksum; |
| 4575 | ctrl_buf->udp_ipv6_chksum = buf->udp_ipv6_chksum; |
| 4576 | ctrl_buf->large_tx_ipv4 = buf->large_tx_ipv4; |
| 4577 | ctrl_buf->large_tx_ipv6 = buf->large_tx_ipv6; |
| 4578 | |
| 4579 | /* large_rx disabled for now, additional features needed */ |
| 4580 | ctrl_buf->large_rx_ipv4 = 0; |
| 4581 | ctrl_buf->large_rx_ipv6 = 0; |
| 4582 | |
| 4583 | if (adapter->state != VNIC_PROBING) { |
| 4584 | old_hw_features = adapter->netdev->hw_features; |
| 4585 | adapter->netdev->hw_features = 0; |
| 4586 | } |
| 4587 | |
| 4588 | adapter->netdev->hw_features = NETIF_F_SG | NETIF_F_GSO | NETIF_F_GRO; |
| 4589 | |
| 4590 | if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum) |
| 4591 | adapter->netdev->hw_features |= NETIF_F_IP_CSUM; |
| 4592 | |
| 4593 | if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum) |
| 4594 | adapter->netdev->hw_features |= NETIF_F_IPV6_CSUM; |
| 4595 | |
| 4596 | if ((adapter->netdev->features & |
| 4597 | (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))) |
| 4598 | adapter->netdev->hw_features |= NETIF_F_RXCSUM; |
| 4599 | |
| 4600 | if (buf->large_tx_ipv4) |
| 4601 | adapter->netdev->hw_features |= NETIF_F_TSO; |
| 4602 | if (buf->large_tx_ipv6) |
| 4603 | adapter->netdev->hw_features |= NETIF_F_TSO6; |
| 4604 | |
| 4605 | if (adapter->state == VNIC_PROBING) { |
| 4606 | adapter->netdev->features |= adapter->netdev->hw_features; |
| 4607 | } else if (old_hw_features != adapter->netdev->hw_features) { |
| 4608 | netdev_features_t tmp = 0; |
| 4609 | |
| 4610 | /* disable features no longer supported */ |
| 4611 | adapter->netdev->features &= adapter->netdev->hw_features; |
| 4612 | /* turn on features now supported if previously enabled */ |
| 4613 | tmp = (old_hw_features ^ adapter->netdev->hw_features) & |
| 4614 | adapter->netdev->hw_features; |
| 4615 | adapter->netdev->features |= |
| 4616 | tmp & adapter->netdev->wanted_features; |
| 4617 | } |
| 4618 | |
| 4619 | memset(&crq, 0, sizeof(crq)); |
| 4620 | crq.control_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4621 | crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD; |
| 4622 | crq.control_ip_offload.len = |
| 4623 | cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4624 | crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok); |
| 4625 | ibmvnic_send_crq(adapter, &crq); |
| 4626 | } |
| 4627 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4628 | static void handle_vpd_size_rsp(union ibmvnic_crq *crq, |
| 4629 | struct ibmvnic_adapter *adapter) |
| 4630 | { |
| 4631 | struct device *dev = &adapter->vdev->dev; |
| 4632 | |
| 4633 | if (crq->get_vpd_size_rsp.rc.code) { |
| 4634 | dev_err(dev, "Error retrieving VPD size, rc=%x\n", |
| 4635 | crq->get_vpd_size_rsp.rc.code); |
| 4636 | complete(&adapter->fw_done); |
| 4637 | return; |
| 4638 | } |
| 4639 | |
| 4640 | adapter->vpd->len = be64_to_cpu(crq->get_vpd_size_rsp.len); |
| 4641 | complete(&adapter->fw_done); |
| 4642 | } |
| 4643 | |
| 4644 | static void handle_vpd_rsp(union ibmvnic_crq *crq, |
| 4645 | struct ibmvnic_adapter *adapter) |
| 4646 | { |
| 4647 | struct device *dev = &adapter->vdev->dev; |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4648 | unsigned char *substr = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4649 | u8 fw_level_len = 0; |
| 4650 | |
| 4651 | memset(adapter->fw_version, 0, 32); |
| 4652 | |
| 4653 | dma_unmap_single(dev, adapter->vpd->dma_addr, adapter->vpd->len, |
| 4654 | DMA_FROM_DEVICE); |
| 4655 | |
| 4656 | if (crq->get_vpd_rsp.rc.code) { |
| 4657 | dev_err(dev, "Error retrieving VPD from device, rc=%x\n", |
| 4658 | crq->get_vpd_rsp.rc.code); |
| 4659 | goto complete; |
| 4660 | } |
| 4661 | |
| 4662 | /* get the position of the firmware version info |
| 4663 | * located after the ASCII 'RM' substring in the buffer |
| 4664 | */ |
| 4665 | substr = strnstr(adapter->vpd->buff, "RM", adapter->vpd->len); |
| 4666 | if (!substr) { |
Desnes Augusto Nunes do Rosario | a107311 | 2018-02-01 16:04:30 -0200 | [diff] [blame] | 4667 | 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] | 4668 | goto complete; |
| 4669 | } |
| 4670 | |
| 4671 | /* get length of firmware level ASCII substring */ |
| 4672 | if ((substr + 2) < (adapter->vpd->buff + adapter->vpd->len)) { |
| 4673 | fw_level_len = *(substr + 2); |
| 4674 | } else { |
| 4675 | dev_info(dev, "Length of FW substr extrapolated VDP buff\n"); |
| 4676 | goto complete; |
| 4677 | } |
| 4678 | |
| 4679 | /* copy firmware version string from vpd into adapter */ |
| 4680 | if ((substr + 3 + fw_level_len) < |
| 4681 | (adapter->vpd->buff + adapter->vpd->len)) { |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4682 | 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] | 4683 | } else { |
| 4684 | dev_info(dev, "FW substr extrapolated VPD buff\n"); |
| 4685 | } |
| 4686 | |
| 4687 | complete: |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4688 | if (adapter->fw_version[0] == '\0') |
Lijun Pan | 0b217d3 | 2021-06-11 13:33:53 -0500 | [diff] [blame] | 4689 | strscpy((char *)adapter->fw_version, "N/A", sizeof(adapter->fw_version)); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4690 | complete(&adapter->fw_done); |
| 4691 | } |
| 4692 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4693 | static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter) |
| 4694 | { |
| 4695 | struct device *dev = &adapter->vdev->dev; |
| 4696 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4697 | int i; |
| 4698 | |
| 4699 | dma_unmap_single(dev, adapter->ip_offload_tok, |
| 4700 | sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE); |
| 4701 | |
| 4702 | netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n"); |
| 4703 | for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++) |
| 4704 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4705 | ((unsigned long *)(buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4706 | |
| 4707 | netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum); |
| 4708 | netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum); |
| 4709 | netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n", |
| 4710 | buf->tcp_ipv4_chksum); |
| 4711 | netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n", |
| 4712 | buf->tcp_ipv6_chksum); |
| 4713 | netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n", |
| 4714 | buf->udp_ipv4_chksum); |
| 4715 | netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n", |
| 4716 | buf->udp_ipv6_chksum); |
| 4717 | netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n", |
| 4718 | buf->large_tx_ipv4); |
| 4719 | netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n", |
| 4720 | buf->large_tx_ipv6); |
| 4721 | netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n", |
| 4722 | buf->large_rx_ipv4); |
| 4723 | netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n", |
| 4724 | buf->large_rx_ipv6); |
| 4725 | netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n", |
| 4726 | buf->max_ipv4_header_size); |
| 4727 | netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n", |
| 4728 | buf->max_ipv6_header_size); |
| 4729 | netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n", |
| 4730 | buf->max_tcp_header_size); |
| 4731 | netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n", |
| 4732 | buf->max_udp_header_size); |
| 4733 | netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n", |
| 4734 | buf->max_large_tx_size); |
| 4735 | netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n", |
| 4736 | buf->max_large_rx_size); |
| 4737 | netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n", |
| 4738 | buf->ipv6_extension_header); |
| 4739 | netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n", |
| 4740 | buf->tcp_pseudosum_req); |
| 4741 | netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n", |
| 4742 | buf->num_ipv6_ext_headers); |
| 4743 | netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n", |
| 4744 | buf->off_ipv6_ext_headers); |
| 4745 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4746 | send_control_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4747 | } |
| 4748 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4749 | static const char *ibmvnic_fw_err_cause(u16 cause) |
| 4750 | { |
| 4751 | switch (cause) { |
| 4752 | case ADAPTER_PROBLEM: |
| 4753 | return "adapter problem"; |
| 4754 | case BUS_PROBLEM: |
| 4755 | return "bus problem"; |
| 4756 | case FW_PROBLEM: |
| 4757 | return "firmware problem"; |
| 4758 | case DD_PROBLEM: |
| 4759 | return "device driver problem"; |
| 4760 | case EEH_RECOVERY: |
| 4761 | return "EEH recovery"; |
| 4762 | case FW_UPDATED: |
| 4763 | return "firmware updated"; |
| 4764 | case LOW_MEMORY: |
| 4765 | return "low Memory"; |
| 4766 | default: |
| 4767 | return "unknown"; |
| 4768 | } |
| 4769 | } |
| 4770 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4771 | static void handle_error_indication(union ibmvnic_crq *crq, |
| 4772 | struct ibmvnic_adapter *adapter) |
| 4773 | { |
| 4774 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4775 | u16 cause; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4776 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4777 | cause = be16_to_cpu(crq->error_indication.error_cause); |
| 4778 | |
| 4779 | dev_warn_ratelimited(dev, |
| 4780 | "Firmware reports %serror, cause: %s. Starting recovery...\n", |
| 4781 | crq->error_indication.flags |
| 4782 | & IBMVNIC_FATAL_ERROR ? "FATAL " : "", |
| 4783 | ibmvnic_fw_err_cause(cause)); |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4784 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4785 | if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR) |
| 4786 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 4787 | else |
| 4788 | ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4789 | } |
| 4790 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4791 | static int handle_change_mac_rsp(union ibmvnic_crq *crq, |
| 4792 | struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4793 | { |
| 4794 | struct net_device *netdev = adapter->netdev; |
| 4795 | struct device *dev = &adapter->vdev->dev; |
| 4796 | long rc; |
| 4797 | |
| 4798 | rc = crq->change_mac_addr_rsp.rc.code; |
| 4799 | if (rc) { |
| 4800 | dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4801 | goto out; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4802 | } |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4803 | /* crq->change_mac_addr.mac_addr is the requested one |
| 4804 | * crq->change_mac_addr_rsp.mac_addr is the returned valid one. |
| 4805 | */ |
Jakub Kicinski | f3956eb | 2021-10-01 14:32:23 -0700 | [diff] [blame] | 4806 | eth_hw_addr_set(netdev, &crq->change_mac_addr_rsp.mac_addr[0]); |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4807 | ether_addr_copy(adapter->mac_addr, |
| 4808 | &crq->change_mac_addr_rsp.mac_addr[0]); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4809 | out: |
| 4810 | complete(&adapter->fw_done); |
| 4811 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | static void handle_request_cap_rsp(union ibmvnic_crq *crq, |
| 4815 | struct ibmvnic_adapter *adapter) |
| 4816 | { |
| 4817 | struct device *dev = &adapter->vdev->dev; |
| 4818 | u64 *req_value; |
| 4819 | char *name; |
| 4820 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4821 | atomic_dec(&adapter->running_cap_crqs); |
Sukadev Bhattiprolu | 151b6a5c | 2022-01-21 18:59:19 -0800 | [diff] [blame^] | 4822 | netdev_dbg(adapter->netdev, "Outstanding request-caps: %d\n", |
| 4823 | atomic_read(&adapter->running_cap_crqs)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4824 | switch (be16_to_cpu(crq->request_capability_rsp.capability)) { |
| 4825 | case REQ_TX_QUEUES: |
| 4826 | req_value = &adapter->req_tx_queues; |
| 4827 | name = "tx"; |
| 4828 | break; |
| 4829 | case REQ_RX_QUEUES: |
| 4830 | req_value = &adapter->req_rx_queues; |
| 4831 | name = "rx"; |
| 4832 | break; |
| 4833 | case REQ_RX_ADD_QUEUES: |
| 4834 | req_value = &adapter->req_rx_add_queues; |
| 4835 | name = "rx_add"; |
| 4836 | break; |
| 4837 | case REQ_TX_ENTRIES_PER_SUBCRQ: |
| 4838 | req_value = &adapter->req_tx_entries_per_subcrq; |
| 4839 | name = "tx_entries_per_subcrq"; |
| 4840 | break; |
| 4841 | case REQ_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4842 | req_value = &adapter->req_rx_add_entries_per_subcrq; |
| 4843 | name = "rx_add_entries_per_subcrq"; |
| 4844 | break; |
| 4845 | case REQ_MTU: |
| 4846 | req_value = &adapter->req_mtu; |
| 4847 | name = "mtu"; |
| 4848 | break; |
| 4849 | case PROMISC_REQUESTED: |
| 4850 | req_value = &adapter->promisc; |
| 4851 | name = "promisc"; |
| 4852 | break; |
| 4853 | default: |
| 4854 | dev_err(dev, "Got invalid cap request rsp %d\n", |
| 4855 | crq->request_capability.capability); |
| 4856 | return; |
| 4857 | } |
| 4858 | |
| 4859 | switch (crq->request_capability_rsp.rc.code) { |
| 4860 | case SUCCESS: |
| 4861 | break; |
| 4862 | case PARTIALSUCCESS: |
| 4863 | dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n", |
| 4864 | *req_value, |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4865 | (long)be64_to_cpu(crq->request_capability_rsp.number), |
| 4866 | name); |
John Allen | e791380 | 2018-01-18 16:27:12 -0600 | [diff] [blame] | 4867 | |
| 4868 | if (be16_to_cpu(crq->request_capability_rsp.capability) == |
| 4869 | REQ_MTU) { |
| 4870 | pr_err("mtu of %llu is not supported. Reverting.\n", |
| 4871 | *req_value); |
| 4872 | *req_value = adapter->fallback.mtu; |
| 4873 | } else { |
| 4874 | *req_value = |
| 4875 | be64_to_cpu(crq->request_capability_rsp.number); |
| 4876 | } |
| 4877 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 4878 | send_request_cap(adapter, 1); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4879 | return; |
| 4880 | default: |
| 4881 | dev_err(dev, "Error %d in request cap rsp\n", |
| 4882 | crq->request_capability_rsp.rc.code); |
| 4883 | return; |
| 4884 | } |
| 4885 | |
| 4886 | /* Done receiving requested capabilities, query IP offload support */ |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4887 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4888 | adapter->wait_capability = false; |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4889 | send_query_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, |
| 4894 | struct ibmvnic_adapter *adapter) |
| 4895 | { |
| 4896 | struct device *dev = &adapter->vdev->dev; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4897 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4898 | struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf; |
| 4899 | struct ibmvnic_login_buffer *login = adapter->login_buf; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4900 | u64 *tx_handle_array; |
| 4901 | u64 *rx_handle_array; |
| 4902 | int num_tx_pools; |
| 4903 | int num_rx_pools; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4904 | u64 *size_array; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4905 | int i; |
| 4906 | |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4907 | /* CHECK: Test/set of login_pending does not need to be atomic |
| 4908 | * because only ibmvnic_tasklet tests/clears this. |
| 4909 | */ |
| 4910 | if (!adapter->login_pending) { |
| 4911 | netdev_warn(netdev, "Ignoring unexpected login response\n"); |
| 4912 | return 0; |
| 4913 | } |
| 4914 | adapter->login_pending = false; |
| 4915 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4916 | dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4917 | DMA_TO_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4918 | dma_unmap_single(dev, adapter->login_rsp_buf_token, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4919 | adapter->login_rsp_buf_sz, DMA_FROM_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4920 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4921 | /* If the number of queues requested can't be allocated by the |
| 4922 | * server, the login response will return with code 1. We will need |
| 4923 | * to resend the login buffer with fewer queues requested. |
| 4924 | */ |
| 4925 | if (login_rsp_crq->generic.rc.code) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 4926 | adapter->init_done_rc = login_rsp_crq->generic.rc.code; |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4927 | complete(&adapter->init_done); |
| 4928 | return 0; |
| 4929 | } |
| 4930 | |
Sukadev Bhattiprolu | d437f5a | 2021-09-07 22:07:03 -0700 | [diff] [blame] | 4931 | if (adapter->failover_pending) { |
| 4932 | adapter->init_done_rc = -EAGAIN; |
| 4933 | netdev_dbg(netdev, "Failover pending, ignoring login response\n"); |
| 4934 | complete(&adapter->init_done); |
| 4935 | /* login response buffer will be released on reset */ |
| 4936 | return 0; |
| 4937 | } |
| 4938 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4939 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 4940 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4941 | netdev_dbg(adapter->netdev, "Login Response Buffer:\n"); |
| 4942 | for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) { |
| 4943 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4944 | ((unsigned long *)(adapter->login_rsp_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | /* Sanity checks */ |
| 4948 | if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs || |
| 4949 | (be32_to_cpu(login->num_rxcomp_subcrqs) * |
| 4950 | adapter->req_rx_add_queues != |
| 4951 | be32_to_cpu(login_rsp->num_rxadd_subcrqs))) { |
| 4952 | dev_err(dev, "FATAL: Inconsistent login and login rsp\n"); |
Dany Madden | 31d6b40 | 2020-11-25 18:04:24 -0600 | [diff] [blame] | 4953 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4954 | return -EIO; |
| 4955 | } |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4956 | size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4957 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size)); |
| 4958 | /* variable buffer sizes are not supported, so just read the |
| 4959 | * first entry. |
| 4960 | */ |
| 4961 | adapter->cur_rx_buf_sz = be64_to_cpu(size_array[0]); |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4962 | |
| 4963 | num_tx_pools = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 4964 | num_rx_pools = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 4965 | |
| 4966 | tx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4967 | be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs)); |
| 4968 | rx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4969 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_subcrqs)); |
| 4970 | |
| 4971 | for (i = 0; i < num_tx_pools; i++) |
| 4972 | adapter->tx_scrq[i]->handle = tx_handle_array[i]; |
| 4973 | |
| 4974 | for (i = 0; i < num_rx_pools; i++) |
| 4975 | adapter->rx_scrq[i]->handle = rx_handle_array[i]; |
| 4976 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4977 | adapter->num_active_tx_scrqs = num_tx_pools; |
| 4978 | adapter->num_active_rx_scrqs = num_rx_pools; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4979 | release_login_rsp_buffer(adapter); |
Thomas Falcon | a2c0f03 | 2018-02-21 18:18:30 -0600 | [diff] [blame] | 4980 | release_login_buffer(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4981 | complete(&adapter->init_done); |
| 4982 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4983 | return 0; |
| 4984 | } |
| 4985 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4986 | static void handle_request_unmap_rsp(union ibmvnic_crq *crq, |
| 4987 | struct ibmvnic_adapter *adapter) |
| 4988 | { |
| 4989 | struct device *dev = &adapter->vdev->dev; |
| 4990 | long rc; |
| 4991 | |
| 4992 | rc = crq->request_unmap_rsp.rc.code; |
| 4993 | if (rc) |
| 4994 | dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc); |
| 4995 | } |
| 4996 | |
| 4997 | static void handle_query_map_rsp(union ibmvnic_crq *crq, |
| 4998 | struct ibmvnic_adapter *adapter) |
| 4999 | { |
| 5000 | struct net_device *netdev = adapter->netdev; |
| 5001 | struct device *dev = &adapter->vdev->dev; |
| 5002 | long rc; |
| 5003 | |
| 5004 | rc = crq->query_map_rsp.rc.code; |
| 5005 | if (rc) { |
| 5006 | dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc); |
| 5007 | return; |
| 5008 | } |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 5009 | netdev_dbg(netdev, "page_size = %d\ntot_pages = %u\nfree_pages = %u\n", |
| 5010 | crq->query_map_rsp.page_size, |
| 5011 | __be32_to_cpu(crq->query_map_rsp.tot_pages), |
| 5012 | __be32_to_cpu(crq->query_map_rsp.free_pages)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | static void handle_query_cap_rsp(union ibmvnic_crq *crq, |
| 5016 | struct ibmvnic_adapter *adapter) |
| 5017 | { |
| 5018 | struct net_device *netdev = adapter->netdev; |
| 5019 | struct device *dev = &adapter->vdev->dev; |
| 5020 | long rc; |
| 5021 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 5022 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5023 | netdev_dbg(netdev, "Outstanding queries: %d\n", |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 5024 | atomic_read(&adapter->running_cap_crqs)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5025 | rc = crq->query_capability.rc.code; |
| 5026 | if (rc) { |
| 5027 | dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc); |
| 5028 | goto out; |
| 5029 | } |
| 5030 | |
| 5031 | switch (be16_to_cpu(crq->query_capability.capability)) { |
| 5032 | case MIN_TX_QUEUES: |
| 5033 | adapter->min_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5034 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5035 | netdev_dbg(netdev, "min_tx_queues = %lld\n", |
| 5036 | adapter->min_tx_queues); |
| 5037 | break; |
| 5038 | case MIN_RX_QUEUES: |
| 5039 | adapter->min_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5040 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5041 | netdev_dbg(netdev, "min_rx_queues = %lld\n", |
| 5042 | adapter->min_rx_queues); |
| 5043 | break; |
| 5044 | case MIN_RX_ADD_QUEUES: |
| 5045 | adapter->min_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5046 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5047 | netdev_dbg(netdev, "min_rx_add_queues = %lld\n", |
| 5048 | adapter->min_rx_add_queues); |
| 5049 | break; |
| 5050 | case MAX_TX_QUEUES: |
| 5051 | adapter->max_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5052 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5053 | netdev_dbg(netdev, "max_tx_queues = %lld\n", |
| 5054 | adapter->max_tx_queues); |
| 5055 | break; |
| 5056 | case MAX_RX_QUEUES: |
| 5057 | adapter->max_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5058 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5059 | netdev_dbg(netdev, "max_rx_queues = %lld\n", |
| 5060 | adapter->max_rx_queues); |
| 5061 | break; |
| 5062 | case MAX_RX_ADD_QUEUES: |
| 5063 | adapter->max_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5064 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5065 | netdev_dbg(netdev, "max_rx_add_queues = %lld\n", |
| 5066 | adapter->max_rx_add_queues); |
| 5067 | break; |
| 5068 | case MIN_TX_ENTRIES_PER_SUBCRQ: |
| 5069 | adapter->min_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5070 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5071 | netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n", |
| 5072 | adapter->min_tx_entries_per_subcrq); |
| 5073 | break; |
| 5074 | case MIN_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 5075 | adapter->min_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5076 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5077 | netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n", |
| 5078 | adapter->min_rx_add_entries_per_subcrq); |
| 5079 | break; |
| 5080 | case MAX_TX_ENTRIES_PER_SUBCRQ: |
| 5081 | adapter->max_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5082 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5083 | netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n", |
| 5084 | adapter->max_tx_entries_per_subcrq); |
| 5085 | break; |
| 5086 | case MAX_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 5087 | adapter->max_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5088 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5089 | netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n", |
| 5090 | adapter->max_rx_add_entries_per_subcrq); |
| 5091 | break; |
| 5092 | case TCP_IP_OFFLOAD: |
| 5093 | adapter->tcp_ip_offload = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5094 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5095 | netdev_dbg(netdev, "tcp_ip_offload = %lld\n", |
| 5096 | adapter->tcp_ip_offload); |
| 5097 | break; |
| 5098 | case PROMISC_SUPPORTED: |
| 5099 | adapter->promisc_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5100 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5101 | netdev_dbg(netdev, "promisc_supported = %lld\n", |
| 5102 | adapter->promisc_supported); |
| 5103 | break; |
| 5104 | case MIN_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5105 | adapter->min_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 5106 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5107 | netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu); |
| 5108 | break; |
| 5109 | case MAX_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5110 | adapter->max_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 5111 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5112 | netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu); |
| 5113 | break; |
| 5114 | case MAX_MULTICAST_FILTERS: |
| 5115 | adapter->max_multicast_filters = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5116 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5117 | netdev_dbg(netdev, "max_multicast_filters = %lld\n", |
| 5118 | adapter->max_multicast_filters); |
| 5119 | break; |
| 5120 | case VLAN_HEADER_INSERTION: |
| 5121 | adapter->vlan_header_insertion = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5122 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5123 | if (adapter->vlan_header_insertion) |
| 5124 | netdev->features |= NETIF_F_HW_VLAN_STAG_TX; |
| 5125 | netdev_dbg(netdev, "vlan_header_insertion = %lld\n", |
| 5126 | adapter->vlan_header_insertion); |
| 5127 | break; |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 5128 | case RX_VLAN_HEADER_INSERTION: |
| 5129 | adapter->rx_vlan_header_insertion = |
| 5130 | be64_to_cpu(crq->query_capability.number); |
| 5131 | netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n", |
| 5132 | adapter->rx_vlan_header_insertion); |
| 5133 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5134 | case MAX_TX_SG_ENTRIES: |
| 5135 | adapter->max_tx_sg_entries = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5136 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5137 | netdev_dbg(netdev, "max_tx_sg_entries = %lld\n", |
| 5138 | adapter->max_tx_sg_entries); |
| 5139 | break; |
| 5140 | case RX_SG_SUPPORTED: |
| 5141 | adapter->rx_sg_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5142 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5143 | netdev_dbg(netdev, "rx_sg_supported = %lld\n", |
| 5144 | adapter->rx_sg_supported); |
| 5145 | break; |
| 5146 | case OPT_TX_COMP_SUB_QUEUES: |
| 5147 | adapter->opt_tx_comp_sub_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5148 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5149 | netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n", |
| 5150 | adapter->opt_tx_comp_sub_queues); |
| 5151 | break; |
| 5152 | case OPT_RX_COMP_QUEUES: |
| 5153 | adapter->opt_rx_comp_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5154 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5155 | netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n", |
| 5156 | adapter->opt_rx_comp_queues); |
| 5157 | break; |
| 5158 | case OPT_RX_BUFADD_Q_PER_RX_COMP_Q: |
| 5159 | adapter->opt_rx_bufadd_q_per_rx_comp_q = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5160 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5161 | netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n", |
| 5162 | adapter->opt_rx_bufadd_q_per_rx_comp_q); |
| 5163 | break; |
| 5164 | case OPT_TX_ENTRIES_PER_SUBCRQ: |
| 5165 | adapter->opt_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5166 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5167 | netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n", |
| 5168 | adapter->opt_tx_entries_per_subcrq); |
| 5169 | break; |
| 5170 | case OPT_RXBA_ENTRIES_PER_SUBCRQ: |
| 5171 | adapter->opt_rxba_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 5172 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5173 | netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n", |
| 5174 | adapter->opt_rxba_entries_per_subcrq); |
| 5175 | break; |
| 5176 | case TX_RX_DESC_REQ: |
| 5177 | adapter->tx_rx_desc_req = crq->query_capability.number; |
| 5178 | netdev_dbg(netdev, "tx_rx_desc_req = %llx\n", |
| 5179 | adapter->tx_rx_desc_req); |
| 5180 | break; |
| 5181 | |
| 5182 | default: |
| 5183 | netdev_err(netdev, "Got invalid cap rsp %d\n", |
| 5184 | crq->query_capability.capability); |
| 5185 | } |
| 5186 | |
| 5187 | out: |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 5188 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
| 5189 | adapter->wait_capability = false; |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 5190 | send_request_cap(adapter, 0); |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 5191 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5192 | } |
| 5193 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5194 | static int send_query_phys_parms(struct ibmvnic_adapter *adapter) |
| 5195 | { |
| 5196 | union ibmvnic_crq crq; |
| 5197 | int rc; |
| 5198 | |
| 5199 | memset(&crq, 0, sizeof(crq)); |
| 5200 | crq.query_phys_parms.first = IBMVNIC_CRQ_CMD; |
| 5201 | crq.query_phys_parms.cmd = QUERY_PHYS_PARMS; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5202 | |
| 5203 | mutex_lock(&adapter->fw_lock); |
| 5204 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 5205 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5206 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5207 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5208 | if (rc) { |
| 5209 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5210 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5211 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5212 | |
| 5213 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5214 | if (rc) { |
| 5215 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5216 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5217 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5218 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5219 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5220 | return adapter->fw_done_rc ? -EIO : 0; |
| 5221 | } |
| 5222 | |
| 5223 | static int handle_query_phys_parms_rsp(union ibmvnic_crq *crq, |
| 5224 | struct ibmvnic_adapter *adapter) |
| 5225 | { |
| 5226 | struct net_device *netdev = adapter->netdev; |
| 5227 | int rc; |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5228 | __be32 rspeed = cpu_to_be32(crq->query_phys_parms_rsp.speed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5229 | |
| 5230 | rc = crq->query_phys_parms_rsp.rc.code; |
| 5231 | if (rc) { |
| 5232 | netdev_err(netdev, "Error %d in QUERY_PHYS_PARMS\n", rc); |
| 5233 | return rc; |
| 5234 | } |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5235 | switch (rspeed) { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5236 | case IBMVNIC_10MBPS: |
| 5237 | adapter->speed = SPEED_10; |
| 5238 | break; |
| 5239 | case IBMVNIC_100MBPS: |
| 5240 | adapter->speed = SPEED_100; |
| 5241 | break; |
| 5242 | case IBMVNIC_1GBPS: |
| 5243 | adapter->speed = SPEED_1000; |
| 5244 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 5245 | case IBMVNIC_10GBPS: |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5246 | adapter->speed = SPEED_10000; |
| 5247 | break; |
| 5248 | case IBMVNIC_25GBPS: |
| 5249 | adapter->speed = SPEED_25000; |
| 5250 | break; |
| 5251 | case IBMVNIC_40GBPS: |
| 5252 | adapter->speed = SPEED_40000; |
| 5253 | break; |
| 5254 | case IBMVNIC_50GBPS: |
| 5255 | adapter->speed = SPEED_50000; |
| 5256 | break; |
| 5257 | case IBMVNIC_100GBPS: |
| 5258 | adapter->speed = SPEED_100000; |
| 5259 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 5260 | case IBMVNIC_200GBPS: |
| 5261 | adapter->speed = SPEED_200000; |
| 5262 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5263 | default: |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5264 | if (netif_carrier_ok(netdev)) |
| 5265 | netdev_warn(netdev, "Unknown speed 0x%08x\n", rspeed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5266 | adapter->speed = SPEED_UNKNOWN; |
| 5267 | } |
| 5268 | if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_FULL_DUPLEX) |
| 5269 | adapter->duplex = DUPLEX_FULL; |
| 5270 | else if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_HALF_DUPLEX) |
| 5271 | adapter->duplex = DUPLEX_HALF; |
| 5272 | else |
| 5273 | adapter->duplex = DUPLEX_UNKNOWN; |
| 5274 | |
| 5275 | return rc; |
| 5276 | } |
| 5277 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5278 | static void ibmvnic_handle_crq(union ibmvnic_crq *crq, |
| 5279 | struct ibmvnic_adapter *adapter) |
| 5280 | { |
| 5281 | struct ibmvnic_generic_crq *gen_crq = &crq->generic; |
| 5282 | struct net_device *netdev = adapter->netdev; |
| 5283 | struct device *dev = &adapter->vdev->dev; |
Murilo Fossa Vicentini | 993a82b | 2017-04-19 13:44:35 -0400 | [diff] [blame] | 5284 | u64 *u64_crq = (u64 *)crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5285 | long rc; |
| 5286 | |
| 5287 | netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 5288 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 5289 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5290 | switch (gen_crq->first) { |
| 5291 | case IBMVNIC_CRQ_INIT_RSP: |
| 5292 | switch (gen_crq->cmd) { |
| 5293 | case IBMVNIC_CRQ_INIT: |
| 5294 | dev_info(dev, "Partner initialized\n"); |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5295 | adapter->from_passive_init = true; |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 5296 | /* Discard any stale login responses from prev reset. |
| 5297 | * CHECK: should we clear even on INIT_COMPLETE? |
| 5298 | */ |
| 5299 | adapter->login_pending = false; |
| 5300 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5301 | if (adapter->state == VNIC_DOWN) |
| 5302 | rc = ibmvnic_reset(adapter, VNIC_RESET_PASSIVE_INIT); |
| 5303 | else |
| 5304 | rc = ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
| 5305 | |
Sukadev Bhattiprolu | ef66a1e | 2021-02-02 21:08:02 -0800 | [diff] [blame] | 5306 | if (rc && rc != -EBUSY) { |
| 5307 | /* We were unable to schedule the failover |
| 5308 | * reset either because the adapter was still |
| 5309 | * probing (eg: during kexec) or we could not |
| 5310 | * allocate memory. Clear the failover_pending |
| 5311 | * flag since no one else will. We ignore |
| 5312 | * EBUSY because it means either FAILOVER reset |
| 5313 | * is already scheduled or the adapter is |
| 5314 | * being removed. |
| 5315 | */ |
| 5316 | netdev_err(netdev, |
| 5317 | "Error %ld scheduling failover reset\n", |
| 5318 | rc); |
| 5319 | adapter->failover_pending = false; |
| 5320 | } |
Sukadev Bhattiprolu | 6b278c0 | 2021-10-29 15:03:16 -0700 | [diff] [blame] | 5321 | |
| 5322 | if (!completion_done(&adapter->init_done)) { |
| 5323 | complete(&adapter->init_done); |
| 5324 | if (!adapter->init_done_rc) |
| 5325 | adapter->init_done_rc = -EAGAIN; |
| 5326 | } |
| 5327 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5328 | break; |
| 5329 | case IBMVNIC_CRQ_INIT_COMPLETE: |
| 5330 | dev_info(dev, "Partner initialization complete\n"); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5331 | adapter->crq.active = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5332 | send_version_xchg(adapter); |
| 5333 | break; |
| 5334 | default: |
| 5335 | dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd); |
| 5336 | } |
| 5337 | return; |
| 5338 | case IBMVNIC_CRQ_XPORT_EVENT: |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5339 | netif_carrier_off(netdev); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5340 | adapter->crq.active = false; |
Thomas Falcon | 2147e3d | 2019-11-25 17:12:54 -0600 | [diff] [blame] | 5341 | /* terminate any thread waiting for a response |
| 5342 | * from the device |
| 5343 | */ |
| 5344 | if (!completion_done(&adapter->fw_done)) { |
| 5345 | adapter->fw_done_rc = -EIO; |
| 5346 | complete(&adapter->fw_done); |
| 5347 | } |
| 5348 | if (!completion_done(&adapter->stats_done)) |
| 5349 | complete(&adapter->stats_done); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5350 | if (test_bit(0, &adapter->resetting)) |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 5351 | adapter->force_reset_recovery = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5352 | if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5353 | dev_info(dev, "Migrated, re-enabling adapter\n"); |
| 5354 | ibmvnic_reset(adapter, VNIC_RESET_MOBILITY); |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 5355 | } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { |
| 5356 | dev_info(dev, "Backing device failover detected\n"); |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 5357 | adapter->failover_pending = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5358 | } else { |
| 5359 | /* The adapter lost the connection */ |
| 5360 | dev_err(dev, "Virtual Adapter failed (rc=%d)\n", |
| 5361 | gen_crq->cmd); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5362 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5363 | } |
| 5364 | return; |
| 5365 | case IBMVNIC_CRQ_CMD_RSP: |
| 5366 | break; |
| 5367 | default: |
| 5368 | dev_err(dev, "Got an invalid msg type 0x%02x\n", |
| 5369 | gen_crq->first); |
| 5370 | return; |
| 5371 | } |
| 5372 | |
| 5373 | switch (gen_crq->cmd) { |
| 5374 | case VERSION_EXCHANGE_RSP: |
| 5375 | rc = crq->version_exchange_rsp.rc.code; |
| 5376 | if (rc) { |
| 5377 | dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc); |
| 5378 | break; |
| 5379 | } |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 5380 | ibmvnic_version = |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5381 | be16_to_cpu(crq->version_exchange_rsp.version); |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 5382 | dev_info(dev, "Partner protocol version is %d\n", |
| 5383 | ibmvnic_version); |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 5384 | send_query_cap(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5385 | break; |
| 5386 | case QUERY_CAPABILITY_RSP: |
| 5387 | handle_query_cap_rsp(crq, adapter); |
| 5388 | break; |
| 5389 | case QUERY_MAP_RSP: |
| 5390 | handle_query_map_rsp(crq, adapter); |
| 5391 | break; |
| 5392 | case REQUEST_MAP_RSP: |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 5393 | adapter->fw_done_rc = crq->request_map_rsp.rc.code; |
| 5394 | complete(&adapter->fw_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5395 | break; |
| 5396 | case REQUEST_UNMAP_RSP: |
| 5397 | handle_request_unmap_rsp(crq, adapter); |
| 5398 | break; |
| 5399 | case REQUEST_CAPABILITY_RSP: |
| 5400 | handle_request_cap_rsp(crq, adapter); |
| 5401 | break; |
| 5402 | case LOGIN_RSP: |
| 5403 | netdev_dbg(netdev, "Got Login Response\n"); |
| 5404 | handle_login_rsp(crq, adapter); |
| 5405 | break; |
| 5406 | case LOGICAL_LINK_STATE_RSP: |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 5407 | netdev_dbg(netdev, |
| 5408 | "Got Logical Link State Response, state: %d rc: %d\n", |
| 5409 | crq->logical_link_state_rsp.link_state, |
| 5410 | crq->logical_link_state_rsp.rc.code); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5411 | adapter->logical_link_state = |
| 5412 | crq->logical_link_state_rsp.link_state; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 5413 | adapter->init_done_rc = crq->logical_link_state_rsp.rc.code; |
| 5414 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5415 | break; |
| 5416 | case LINK_STATE_INDICATION: |
| 5417 | netdev_dbg(netdev, "Got Logical Link State Indication\n"); |
| 5418 | adapter->phys_link_state = |
| 5419 | crq->link_state_indication.phys_link_state; |
| 5420 | adapter->logical_link_state = |
| 5421 | crq->link_state_indication.logical_link_state; |
Thomas Falcon | 0655f99 | 2019-05-09 23:13:44 -0500 | [diff] [blame] | 5422 | if (adapter->phys_link_state && adapter->logical_link_state) |
| 5423 | netif_carrier_on(netdev); |
| 5424 | else |
| 5425 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5426 | break; |
| 5427 | case CHANGE_MAC_ADDR_RSP: |
| 5428 | netdev_dbg(netdev, "Got MAC address change Response\n"); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 5429 | adapter->fw_done_rc = handle_change_mac_rsp(crq, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5430 | break; |
| 5431 | case ERROR_INDICATION: |
| 5432 | netdev_dbg(netdev, "Got Error Indication\n"); |
| 5433 | handle_error_indication(crq, adapter); |
| 5434 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5435 | case REQUEST_STATISTICS_RSP: |
| 5436 | netdev_dbg(netdev, "Got Statistics Response\n"); |
| 5437 | complete(&adapter->stats_done); |
| 5438 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5439 | case QUERY_IP_OFFLOAD_RSP: |
| 5440 | netdev_dbg(netdev, "Got Query IP offload Response\n"); |
| 5441 | handle_query_ip_offload_rsp(adapter); |
| 5442 | break; |
| 5443 | case MULTICAST_CTRL_RSP: |
| 5444 | netdev_dbg(netdev, "Got multicast control Response\n"); |
| 5445 | break; |
| 5446 | case CONTROL_IP_OFFLOAD_RSP: |
| 5447 | netdev_dbg(netdev, "Got Control IP offload Response\n"); |
| 5448 | dma_unmap_single(dev, adapter->ip_offload_ctrl_tok, |
| 5449 | sizeof(adapter->ip_offload_ctrl), |
| 5450 | DMA_TO_DEVICE); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 5451 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5452 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5453 | case COLLECT_FW_TRACE_RSP: |
| 5454 | netdev_dbg(netdev, "Got Collect firmware trace Response\n"); |
| 5455 | complete(&adapter->fw_done); |
| 5456 | break; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 5457 | case GET_VPD_SIZE_RSP: |
| 5458 | handle_vpd_size_rsp(crq, adapter); |
| 5459 | break; |
| 5460 | case GET_VPD_RSP: |
| 5461 | handle_vpd_rsp(crq, adapter); |
| 5462 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5463 | case QUERY_PHYS_PARMS_RSP: |
| 5464 | adapter->fw_done_rc = handle_query_phys_parms_rsp(crq, adapter); |
| 5465 | complete(&adapter->fw_done); |
| 5466 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5467 | default: |
| 5468 | netdev_err(netdev, "Got an invalid cmd type 0x%02x\n", |
| 5469 | gen_crq->cmd); |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | static irqreturn_t ibmvnic_interrupt(int irq, void *instance) |
| 5474 | { |
| 5475 | struct ibmvnic_adapter *adapter = instance; |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5476 | |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5477 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5478 | return IRQ_HANDLED; |
| 5479 | } |
| 5480 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5481 | static void ibmvnic_tasklet(struct tasklet_struct *t) |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5482 | { |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5483 | struct ibmvnic_adapter *adapter = from_tasklet(adapter, t, tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5484 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5485 | union ibmvnic_crq *crq; |
| 5486 | unsigned long flags; |
| 5487 | bool done = false; |
| 5488 | |
| 5489 | spin_lock_irqsave(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5490 | while (!done) { |
| 5491 | /* Pull all the valid messages off the CRQ */ |
| 5492 | while ((crq = ibmvnic_next_crq(adapter)) != NULL) { |
Lijun Pan | e41aec7 | 2021-01-27 19:34:42 -0600 | [diff] [blame] | 5493 | /* This barrier makes sure ibmvnic_next_crq()'s |
| 5494 | * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded |
| 5495 | * before ibmvnic_handle_crq()'s |
| 5496 | * switch(gen_crq->first) and switch(gen_crq->cmd). |
| 5497 | */ |
| 5498 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5499 | ibmvnic_handle_crq(crq, adapter); |
| 5500 | crq->generic.first = 0; |
| 5501 | } |
Brian King | ed7ecbf | 2017-04-19 13:44:53 -0400 | [diff] [blame] | 5502 | |
| 5503 | /* remain in tasklet until all |
| 5504 | * capabilities responses are received |
| 5505 | */ |
| 5506 | if (!adapter->wait_capability) |
| 5507 | done = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5508 | } |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 5509 | /* if capabilities CRQ's were sent in this tasklet, the following |
| 5510 | * tasklet must wait until all responses are received |
| 5511 | */ |
| 5512 | if (atomic_read(&adapter->running_cap_crqs) != 0) |
| 5513 | adapter->wait_capability = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5514 | spin_unlock_irqrestore(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter) |
| 5518 | { |
| 5519 | struct vio_dev *vdev = adapter->vdev; |
| 5520 | int rc; |
| 5521 | |
| 5522 | do { |
| 5523 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); |
| 5524 | } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5525 | |
| 5526 | if (rc) |
| 5527 | dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc); |
| 5528 | |
| 5529 | return rc; |
| 5530 | } |
| 5531 | |
| 5532 | static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter) |
| 5533 | { |
| 5534 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5535 | struct device *dev = &adapter->vdev->dev; |
| 5536 | struct vio_dev *vdev = adapter->vdev; |
| 5537 | int rc; |
| 5538 | |
| 5539 | /* Close the CRQ */ |
| 5540 | do { |
| 5541 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5542 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5543 | |
| 5544 | /* Clean out the queue */ |
Lijun Pan | 0e435be | 2020-11-23 13:35:46 -0600 | [diff] [blame] | 5545 | if (!crq->msgs) |
| 5546 | return -EINVAL; |
| 5547 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5548 | memset(crq->msgs, 0, PAGE_SIZE); |
| 5549 | crq->cur = 0; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5550 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5551 | |
| 5552 | /* And re-open it again */ |
| 5553 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5554 | crq->msg_token, PAGE_SIZE); |
| 5555 | |
| 5556 | if (rc == H_CLOSED) |
| 5557 | /* Adapter is good, but other end is not ready */ |
| 5558 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5559 | else if (rc != 0) |
| 5560 | dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc); |
| 5561 | |
| 5562 | return rc; |
| 5563 | } |
| 5564 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5565 | static void release_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5566 | { |
| 5567 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5568 | struct vio_dev *vdev = adapter->vdev; |
| 5569 | long rc; |
| 5570 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5571 | if (!crq->msgs) |
| 5572 | return; |
| 5573 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5574 | netdev_dbg(adapter->netdev, "Releasing CRQ\n"); |
| 5575 | free_irq(vdev->irq, adapter); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5576 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5577 | do { |
| 5578 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5579 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5580 | |
| 5581 | dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE, |
| 5582 | DMA_BIDIRECTIONAL); |
| 5583 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5584 | crq->msgs = NULL; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5585 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5586 | } |
| 5587 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5588 | static int init_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5589 | { |
| 5590 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5591 | struct device *dev = &adapter->vdev->dev; |
| 5592 | struct vio_dev *vdev = adapter->vdev; |
| 5593 | int rc, retrc = -ENOMEM; |
| 5594 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5595 | if (crq->msgs) |
| 5596 | return 0; |
| 5597 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5598 | crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL); |
| 5599 | /* Should we allocate more than one page? */ |
| 5600 | |
| 5601 | if (!crq->msgs) |
| 5602 | return -ENOMEM; |
| 5603 | |
| 5604 | crq->size = PAGE_SIZE / sizeof(*crq->msgs); |
| 5605 | crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE, |
| 5606 | DMA_BIDIRECTIONAL); |
| 5607 | if (dma_mapping_error(dev, crq->msg_token)) |
| 5608 | goto map_failed; |
| 5609 | |
| 5610 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5611 | crq->msg_token, PAGE_SIZE); |
| 5612 | |
| 5613 | if (rc == H_RESOURCE) |
| 5614 | /* maybe kexecing and resource is busy. try a reset */ |
| 5615 | rc = ibmvnic_reset_crq(adapter); |
| 5616 | retrc = rc; |
| 5617 | |
| 5618 | if (rc == H_CLOSED) { |
| 5619 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5620 | } else if (rc) { |
| 5621 | dev_warn(dev, "Error %d opening adapter\n", rc); |
| 5622 | goto reg_crq_failed; |
| 5623 | } |
| 5624 | |
| 5625 | retrc = 0; |
| 5626 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5627 | tasklet_setup(&adapter->tasklet, (void *)ibmvnic_tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5628 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5629 | netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq); |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 5630 | snprintf(crq->name, sizeof(crq->name), "ibmvnic-%x", |
| 5631 | adapter->vdev->unit_address); |
| 5632 | rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, crq->name, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5633 | if (rc) { |
| 5634 | dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", |
| 5635 | vdev->irq, rc); |
| 5636 | goto req_irq_failed; |
| 5637 | } |
| 5638 | |
| 5639 | rc = vio_enable_interrupts(vdev); |
| 5640 | if (rc) { |
| 5641 | dev_err(dev, "Error %d enabling interrupts\n", rc); |
| 5642 | goto req_irq_failed; |
| 5643 | } |
| 5644 | |
| 5645 | crq->cur = 0; |
| 5646 | spin_lock_init(&crq->lock); |
| 5647 | |
Sukadev Bhattiprolu | 6e20d00 | 2021-10-29 15:03:15 -0700 | [diff] [blame] | 5648 | /* process any CRQs that were queued before we enabled interrupts */ |
| 5649 | tasklet_schedule(&adapter->tasklet); |
| 5650 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5651 | return retrc; |
| 5652 | |
| 5653 | req_irq_failed: |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5654 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5655 | do { |
| 5656 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5657 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5658 | reg_crq_failed: |
| 5659 | dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 5660 | map_failed: |
| 5661 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5662 | crq->msgs = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5663 | return retrc; |
| 5664 | } |
| 5665 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5666 | static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter, bool reset) |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5667 | { |
| 5668 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 5669 | unsigned long timeout = msecs_to_jiffies(20000); |
Michal Suchanek | 6881b07 | 2021-03-02 20:47:47 +0100 | [diff] [blame] | 5670 | u64 old_num_rx_queues = adapter->req_rx_queues; |
| 5671 | u64 old_num_tx_queues = adapter->req_tx_queues; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5672 | int rc; |
| 5673 | |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5674 | adapter->from_passive_init = false; |
| 5675 | |
Michal Suchanek | 6881b07 | 2021-03-02 20:47:47 +0100 | [diff] [blame] | 5676 | if (reset) |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5677 | reinit_completion(&adapter->init_done); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5678 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5679 | adapter->init_done_rc = 0; |
Lijun Pan | fa68bfa | 2020-08-19 17:52:24 -0500 | [diff] [blame] | 5680 | rc = ibmvnic_send_crq_init(adapter); |
| 5681 | if (rc) { |
| 5682 | dev_err(dev, "Send crq init failed with error %d\n", rc); |
| 5683 | return rc; |
| 5684 | } |
| 5685 | |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5686 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 5687 | dev_err(dev, "Initialization sequence timed out\n"); |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 5688 | return -ETIMEDOUT; |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5689 | } |
| 5690 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5691 | if (adapter->init_done_rc) { |
| 5692 | release_crq_queue(adapter); |
| 5693 | return adapter->init_done_rc; |
| 5694 | } |
| 5695 | |
Lijun Pan | 785a2b1 | 2020-09-17 21:12:46 -0500 | [diff] [blame] | 5696 | if (adapter->from_passive_init) { |
| 5697 | adapter->state = VNIC_OPEN; |
| 5698 | adapter->from_passive_init = false; |
Dany Madden | b6ee566 | 2021-12-14 00:17:47 -0500 | [diff] [blame] | 5699 | return -EINVAL; |
Lijun Pan | 785a2b1 | 2020-09-17 21:12:46 -0500 | [diff] [blame] | 5700 | } |
| 5701 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5702 | if (reset && |
| 5703 | test_bit(0, &adapter->resetting) && !adapter->wait_for_reset && |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 5704 | adapter->reset_reason != VNIC_RESET_MOBILITY) { |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5705 | if (adapter->req_rx_queues != old_num_rx_queues || |
| 5706 | adapter->req_tx_queues != old_num_tx_queues) { |
| 5707 | release_sub_crqs(adapter, 0); |
| 5708 | rc = init_sub_crqs(adapter); |
| 5709 | } else { |
| 5710 | rc = reset_sub_crq_queues(adapter); |
| 5711 | } |
| 5712 | } else { |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 5713 | rc = init_sub_crqs(adapter); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5714 | } |
| 5715 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 5716 | if (rc) { |
| 5717 | dev_err(dev, "Initialization of sub crqs failed\n"); |
| 5718 | release_crq_queue(adapter); |
Thomas Falcon | 5df969c | 2017-06-28 19:55:54 -0500 | [diff] [blame] | 5719 | return rc; |
| 5720 | } |
| 5721 | |
| 5722 | rc = init_sub_crq_irqs(adapter); |
| 5723 | if (rc) { |
| 5724 | dev_err(dev, "Failed to initialize sub crq irqs\n"); |
| 5725 | release_crq_queue(adapter); |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | return rc; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5729 | } |
| 5730 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5731 | static struct device_attribute dev_attr_failover; |
| 5732 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5733 | static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) |
| 5734 | { |
| 5735 | struct ibmvnic_adapter *adapter; |
| 5736 | struct net_device *netdev; |
| 5737 | unsigned char *mac_addr_p; |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5738 | bool init_success; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5739 | int rc; |
| 5740 | |
| 5741 | dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n", |
| 5742 | dev->unit_address); |
| 5743 | |
| 5744 | mac_addr_p = (unsigned char *)vio_get_attribute(dev, |
| 5745 | VETH_MAC_ADDR, NULL); |
| 5746 | if (!mac_addr_p) { |
| 5747 | dev_err(&dev->dev, |
| 5748 | "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n", |
| 5749 | __FILE__, __LINE__); |
| 5750 | return 0; |
| 5751 | } |
| 5752 | |
| 5753 | netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter), |
Thomas Falcon | d45cc3a | 2017-12-18 12:52:11 -0600 | [diff] [blame] | 5754 | IBMVNIC_MAX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5755 | if (!netdev) |
| 5756 | return -ENOMEM; |
| 5757 | |
| 5758 | adapter = netdev_priv(netdev); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5759 | adapter->state = VNIC_PROBING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5760 | dev_set_drvdata(&dev->dev, netdev); |
| 5761 | adapter->vdev = dev; |
| 5762 | adapter->netdev = netdev; |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 5763 | adapter->login_pending = false; |
Sukadev Bhattiprolu | 129854f0 | 2021-09-14 20:52:56 -0700 | [diff] [blame] | 5764 | memset(&adapter->map_ids, 0, sizeof(adapter->map_ids)); |
| 5765 | /* map_ids start at 1, so ensure map_id 0 is always "in-use" */ |
| 5766 | bitmap_set(adapter->map_ids, 0, 1); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5767 | |
| 5768 | ether_addr_copy(adapter->mac_addr, mac_addr_p); |
Jakub Kicinski | f3956eb | 2021-10-01 14:32:23 -0700 | [diff] [blame] | 5769 | eth_hw_addr_set(netdev, adapter->mac_addr); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5770 | netdev->irq = dev->irq; |
| 5771 | netdev->netdev_ops = &ibmvnic_netdev_ops; |
| 5772 | netdev->ethtool_ops = &ibmvnic_ethtool_ops; |
| 5773 | SET_NETDEV_DEV(netdev, &dev->dev); |
| 5774 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5775 | INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5776 | INIT_DELAYED_WORK(&adapter->ibmvnic_delayed_reset, |
| 5777 | __ibmvnic_delayed_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5778 | INIT_LIST_HEAD(&adapter->rwi_list); |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 5779 | spin_lock_init(&adapter->rwi_lock); |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5780 | spin_lock_init(&adapter->state_lock); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5781 | mutex_init(&adapter->fw_lock); |
Thomas Falcon | bbd669a | 2019-04-04 18:58:26 -0500 | [diff] [blame] | 5782 | init_completion(&adapter->init_done); |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 5783 | init_completion(&adapter->fw_done); |
| 5784 | init_completion(&adapter->reset_done); |
| 5785 | init_completion(&adapter->stats_done); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5786 | clear_bit(0, &adapter->resetting); |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 5787 | adapter->prev_rx_buf_sz = 0; |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 5788 | adapter->prev_mtu = 0; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5789 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5790 | init_success = false; |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5791 | do { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 5792 | rc = init_crq_queue(adapter); |
| 5793 | if (rc) { |
| 5794 | dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n", |
| 5795 | rc); |
| 5796 | goto ibmvnic_init_fail; |
| 5797 | } |
| 5798 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5799 | rc = ibmvnic_reset_init(adapter, false); |
Sukadev Bhattiprolu | 6b278c0 | 2021-10-29 15:03:16 -0700 | [diff] [blame] | 5800 | } while (rc == -EAGAIN); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5801 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5802 | /* We are ignoring the error from ibmvnic_reset_init() assuming that the |
| 5803 | * partner is not ready. CRQ is not active. When the partner becomes |
| 5804 | * ready, we will do the passive init reset. |
| 5805 | */ |
| 5806 | |
| 5807 | if (!rc) |
| 5808 | init_success = true; |
| 5809 | |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5810 | rc = init_stats_buffers(adapter); |
| 5811 | if (rc) |
| 5812 | goto ibmvnic_init_fail; |
| 5813 | |
| 5814 | rc = init_stats_token(adapter); |
| 5815 | if (rc) |
| 5816 | goto ibmvnic_stats_fail; |
| 5817 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5818 | rc = device_create_file(&dev->dev, &dev_attr_failover); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5819 | if (rc) |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5820 | goto ibmvnic_dev_file_err; |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5821 | |
Mick Tarsel | e876a8a | 2017-09-28 13:53:18 -0700 | [diff] [blame] | 5822 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5823 | rc = register_netdev(netdev); |
| 5824 | if (rc) { |
| 5825 | dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5826 | goto ibmvnic_register_fail; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5827 | } |
| 5828 | dev_info(&dev->dev, "ibmvnic registered\n"); |
| 5829 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5830 | if (init_success) { |
| 5831 | adapter->state = VNIC_PROBED; |
| 5832 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 5833 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
| 5834 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
| 5835 | } else { |
| 5836 | adapter->state = VNIC_DOWN; |
| 5837 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 5838 | |
| 5839 | adapter->wait_for_reset = false; |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 5840 | adapter->last_reset_time = jiffies; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5841 | return 0; |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5842 | |
| 5843 | ibmvnic_register_fail: |
| 5844 | device_remove_file(&dev->dev, &dev_attr_failover); |
| 5845 | |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5846 | ibmvnic_dev_file_err: |
| 5847 | release_stats_token(adapter); |
| 5848 | |
| 5849 | ibmvnic_stats_fail: |
| 5850 | release_stats_buffers(adapter); |
| 5851 | |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5852 | ibmvnic_init_fail: |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5853 | release_sub_crqs(adapter, 1); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5854 | release_crq_queue(adapter); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5855 | mutex_destroy(&adapter->fw_lock); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5856 | free_netdev(netdev); |
| 5857 | |
| 5858 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5859 | } |
| 5860 | |
Uwe Kleine-König | 386a966 | 2021-02-25 23:18:34 +0100 | [diff] [blame] | 5861 | static void ibmvnic_remove(struct vio_dev *dev) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5862 | { |
| 5863 | struct net_device *netdev = dev_get_drvdata(&dev->dev); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5864 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5865 | unsigned long flags; |
| 5866 | |
| 5867 | spin_lock_irqsave(&adapter->state_lock, flags); |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 5868 | |
| 5869 | /* If ibmvnic_reset() is scheduling a reset, wait for it to |
| 5870 | * finish. Then, set the state to REMOVING to prevent it from |
| 5871 | * scheduling any more work and to have reset functions ignore |
| 5872 | * any resets that have already been scheduled. Drop the lock |
| 5873 | * after setting state, so __ibmvnic_reset() which is called |
| 5874 | * from the flush_work() below, can make progress. |
| 5875 | */ |
Junlin Yang | 69cdb79 | 2021-03-05 16:48:39 +0800 | [diff] [blame] | 5876 | spin_lock(&adapter->rwi_lock); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5877 | adapter->state = VNIC_REMOVING; |
Junlin Yang | 69cdb79 | 2021-03-05 16:48:39 +0800 | [diff] [blame] | 5878 | spin_unlock(&adapter->rwi_lock); |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 5879 | |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5880 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
| 5881 | |
Thomas Falcon | 6954a9e | 2020-06-12 13:34:41 -0500 | [diff] [blame] | 5882 | flush_work(&adapter->ibmvnic_reset); |
| 5883 | flush_delayed_work(&adapter->ibmvnic_delayed_reset); |
| 5884 | |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 5885 | rtnl_lock(); |
| 5886 | unregister_netdevice(netdev); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5887 | |
| 5888 | release_resources(adapter); |
Sukadev Bhattiprolu | 489de95 | 2021-09-14 20:52:58 -0700 | [diff] [blame] | 5889 | release_rx_pools(adapter); |
Sukadev Bhattiprolu | bbd8093 | 2021-09-14 20:52:59 -0700 | [diff] [blame] | 5890 | release_tx_pools(adapter); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5891 | release_sub_crqs(adapter, 1); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5892 | release_crq_queue(adapter); |
| 5893 | |
Thomas Falcon | 53cc772 | 2018-02-26 18:10:56 -0600 | [diff] [blame] | 5894 | release_stats_token(adapter); |
| 5895 | release_stats_buffers(adapter); |
| 5896 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5897 | adapter->state = VNIC_REMOVED; |
| 5898 | |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 5899 | rtnl_unlock(); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5900 | mutex_destroy(&adapter->fw_lock); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5901 | device_remove_file(&dev->dev, &dev_attr_failover); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5902 | free_netdev(netdev); |
| 5903 | dev_set_drvdata(&dev->dev, NULL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5904 | } |
| 5905 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5906 | static ssize_t failover_store(struct device *dev, struct device_attribute *attr, |
| 5907 | const char *buf, size_t count) |
| 5908 | { |
| 5909 | struct net_device *netdev = dev_get_drvdata(dev); |
| 5910 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 5911 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 5912 | __be64 session_token; |
| 5913 | long rc; |
| 5914 | |
| 5915 | if (!sysfs_streq(buf, "1")) |
| 5916 | return -EINVAL; |
| 5917 | |
| 5918 | rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address, |
| 5919 | H_GET_SESSION_TOKEN, 0, 0, 0); |
| 5920 | if (rc) { |
| 5921 | netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n", |
| 5922 | rc); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5923 | goto last_resort; |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | session_token = (__be64)retbuf[0]; |
| 5927 | netdev_dbg(netdev, "Initiating client failover, session id %llx\n", |
| 5928 | be64_to_cpu(session_token)); |
| 5929 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 5930 | H_SESSION_ERR_DETECTED, session_token, 0, 0); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5931 | if (rc) |
| 5932 | netdev_err(netdev, |
| 5933 | "H_VIOCTL initiated failover failed, rc %ld\n", |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5934 | rc); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5935 | |
| 5936 | last_resort: |
| 5937 | netdev_dbg(netdev, "Trying to send CRQ_CMD, the last resort\n"); |
| 5938 | ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5939 | |
| 5940 | return count; |
| 5941 | } |
Joe Perches | 6cbaefb | 2017-12-19 10:15:09 -0800 | [diff] [blame] | 5942 | static DEVICE_ATTR_WO(failover); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5943 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5944 | static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev) |
| 5945 | { |
| 5946 | struct net_device *netdev = dev_get_drvdata(&vdev->dev); |
| 5947 | struct ibmvnic_adapter *adapter; |
| 5948 | struct iommu_table *tbl; |
| 5949 | unsigned long ret = 0; |
| 5950 | int i; |
| 5951 | |
| 5952 | tbl = get_iommu_table_base(&vdev->dev); |
| 5953 | |
| 5954 | /* netdev inits at probe time along with the structures we need below*/ |
| 5955 | if (!netdev) |
| 5956 | return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl); |
| 5957 | |
| 5958 | adapter = netdev_priv(netdev); |
| 5959 | |
| 5960 | ret += PAGE_SIZE; /* the crq message queue */ |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5961 | ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl); |
| 5962 | |
| 5963 | for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++) |
| 5964 | ret += 4 * PAGE_SIZE; /* the scrq message queue */ |
| 5965 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 5966 | for (i = 0; i < adapter->num_active_rx_pools; i++) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5967 | ret += adapter->rx_pool[i].size * |
| 5968 | IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl); |
| 5969 | |
| 5970 | return ret; |
| 5971 | } |
| 5972 | |
| 5973 | static int ibmvnic_resume(struct device *dev) |
| 5974 | { |
| 5975 | struct net_device *netdev = dev_get_drvdata(dev); |
| 5976 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5977 | |
John Allen | cb89ba2 | 2017-06-19 11:27:53 -0500 | [diff] [blame] | 5978 | if (adapter->state != VNIC_OPEN) |
| 5979 | return 0; |
| 5980 | |
John Allen | a248878 | 2017-07-24 13:26:06 -0500 | [diff] [blame] | 5981 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5982 | |
| 5983 | return 0; |
| 5984 | } |
| 5985 | |
Arvind Yadav | 8c37bc6 | 2017-08-17 18:52:54 +0530 | [diff] [blame] | 5986 | static const struct vio_device_id ibmvnic_device_table[] = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5987 | {"network", "IBM,vnic"}, |
| 5988 | {"", "" } |
| 5989 | }; |
| 5990 | MODULE_DEVICE_TABLE(vio, ibmvnic_device_table); |
| 5991 | |
| 5992 | static const struct dev_pm_ops ibmvnic_pm_ops = { |
| 5993 | .resume = ibmvnic_resume |
| 5994 | }; |
| 5995 | |
| 5996 | static struct vio_driver ibmvnic_driver = { |
| 5997 | .id_table = ibmvnic_device_table, |
| 5998 | .probe = ibmvnic_probe, |
| 5999 | .remove = ibmvnic_remove, |
| 6000 | .get_desired_dma = ibmvnic_get_desired_dma, |
| 6001 | .name = ibmvnic_driver_name, |
| 6002 | .pm = &ibmvnic_pm_ops, |
| 6003 | }; |
| 6004 | |
| 6005 | /* module functions */ |
| 6006 | static int __init ibmvnic_module_init(void) |
| 6007 | { |
| 6008 | pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string, |
| 6009 | IBMVNIC_DRIVER_VERSION); |
| 6010 | |
| 6011 | return vio_register_driver(&ibmvnic_driver); |
| 6012 | } |
| 6013 | |
| 6014 | static void __exit ibmvnic_module_exit(void) |
| 6015 | { |
| 6016 | vio_unregister_driver(&ibmvnic_driver); |
| 6017 | } |
| 6018 | |
| 6019 | module_init(ibmvnic_module_init); |
| 6020 | module_exit(ibmvnic_module_exit); |