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); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 111 | |
| 112 | struct ibmvnic_stat { |
| 113 | char name[ETH_GSTRING_LEN]; |
| 114 | int offset; |
| 115 | }; |
| 116 | |
| 117 | #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \ |
| 118 | offsetof(struct ibmvnic_statistics, stat)) |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 119 | #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + (off)))) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 120 | |
| 121 | static const struct ibmvnic_stat ibmvnic_stats[] = { |
| 122 | {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)}, |
| 123 | {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)}, |
| 124 | {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)}, |
| 125 | {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)}, |
| 126 | {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)}, |
| 127 | {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)}, |
| 128 | {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)}, |
| 129 | {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)}, |
| 130 | {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)}, |
| 131 | {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)}, |
| 132 | {"align_errors", IBMVNIC_STAT_OFF(align_errors)}, |
| 133 | {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)}, |
| 134 | {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)}, |
| 135 | {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)}, |
| 136 | {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)}, |
| 137 | {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)}, |
| 138 | {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)}, |
| 139 | {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)}, |
| 140 | {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)}, |
| 141 | {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)}, |
| 142 | {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)}, |
| 143 | {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)}, |
| 144 | }; |
| 145 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 146 | static int send_crq_init_complete(struct ibmvnic_adapter *adapter) |
| 147 | { |
| 148 | union ibmvnic_crq crq; |
| 149 | |
| 150 | memset(&crq, 0, sizeof(crq)); |
| 151 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 152 | crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE; |
| 153 | |
| 154 | return ibmvnic_send_crq(adapter, &crq); |
| 155 | } |
| 156 | |
| 157 | static int send_version_xchg(struct ibmvnic_adapter *adapter) |
| 158 | { |
| 159 | union ibmvnic_crq crq; |
| 160 | |
| 161 | memset(&crq, 0, sizeof(crq)); |
| 162 | crq.version_exchange.first = IBMVNIC_CRQ_CMD; |
| 163 | crq.version_exchange.cmd = VERSION_EXCHANGE; |
| 164 | crq.version_exchange.version = cpu_to_be16(ibmvnic_version); |
| 165 | |
| 166 | return ibmvnic_send_crq(adapter, &crq); |
| 167 | } |
| 168 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 169 | static long h_reg_sub_crq(unsigned long unit_address, unsigned long token, |
| 170 | unsigned long length, unsigned long *number, |
| 171 | unsigned long *irq) |
| 172 | { |
| 173 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 174 | long rc; |
| 175 | |
| 176 | rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length); |
| 177 | *number = retbuf[0]; |
| 178 | *irq = retbuf[1]; |
| 179 | |
| 180 | return rc; |
| 181 | } |
| 182 | |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 183 | /** |
| 184 | * ibmvnic_wait_for_completion - Check device state and wait for completion |
| 185 | * @adapter: private device data |
| 186 | * @comp_done: completion structure to wait for |
| 187 | * @timeout: time to wait in milliseconds |
| 188 | * |
| 189 | * Wait for a completion signal or until the timeout limit is reached |
| 190 | * while checking that the device is still active. |
| 191 | */ |
| 192 | static int ibmvnic_wait_for_completion(struct ibmvnic_adapter *adapter, |
| 193 | struct completion *comp_done, |
| 194 | unsigned long timeout) |
| 195 | { |
| 196 | struct net_device *netdev; |
| 197 | unsigned long div_timeout; |
| 198 | u8 retry; |
| 199 | |
| 200 | netdev = adapter->netdev; |
| 201 | retry = 5; |
| 202 | div_timeout = msecs_to_jiffies(timeout / retry); |
| 203 | while (true) { |
| 204 | if (!adapter->crq.active) { |
| 205 | netdev_err(netdev, "Device down!\n"); |
| 206 | return -ENODEV; |
| 207 | } |
Thomas Falcon | 8f9cc1e | 2019-12-11 09:38:39 -0600 | [diff] [blame] | 208 | if (!retry--) |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 209 | break; |
| 210 | if (wait_for_completion_timeout(comp_done, div_timeout)) |
| 211 | return 0; |
| 212 | } |
| 213 | netdev_err(netdev, "Operation timed out.\n"); |
| 214 | return -ETIMEDOUT; |
| 215 | } |
| 216 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 217 | static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, |
| 218 | struct ibmvnic_long_term_buff *ltb, int size) |
| 219 | { |
| 220 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 221 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 222 | |
| 223 | ltb->size = size; |
| 224 | ltb->buff = dma_alloc_coherent(dev, ltb->size, <b->addr, |
| 225 | GFP_KERNEL); |
| 226 | |
| 227 | if (!ltb->buff) { |
| 228 | dev_err(dev, "Couldn't alloc long term buffer\n"); |
| 229 | return -ENOMEM; |
| 230 | } |
| 231 | ltb->map_id = adapter->map_id; |
| 232 | adapter->map_id++; |
Nathan Fontenot | db5d0b5 | 2017-02-10 13:45:05 -0500 | [diff] [blame] | 233 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 234 | mutex_lock(&adapter->fw_lock); |
| 235 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 236 | reinit_completion(&adapter->fw_done); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 237 | |
| 238 | rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 239 | if (rc) { |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 240 | dev_err(dev, "send_request_map failed, rc = %d\n", rc); |
| 241 | goto out; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 242 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 243 | |
| 244 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 245 | if (rc) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 246 | 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] | 247 | rc); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 248 | goto out; |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 249 | } |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 250 | |
| 251 | if (adapter->fw_done_rc) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 252 | dev_err(dev, "Couldn't map LTB, rc = %d\n", |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 253 | adapter->fw_done_rc); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 254 | rc = -1; |
| 255 | goto out; |
| 256 | } |
| 257 | rc = 0; |
| 258 | out: |
| 259 | if (rc) { |
Thomas Falcon | 4cf2ddf3 | 2018-05-16 15:49:03 -0500 | [diff] [blame] | 260 | dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 261 | ltb->buff = NULL; |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 262 | } |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 263 | mutex_unlock(&adapter->fw_lock); |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 264 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static void free_long_term_buff(struct ibmvnic_adapter *adapter, |
| 268 | struct ibmvnic_long_term_buff *ltb) |
| 269 | { |
| 270 | struct device *dev = &adapter->vdev->dev; |
| 271 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 272 | if (!ltb->buff) |
| 273 | return; |
| 274 | |
Lijun Pan | 7d3a7b9 | 2021-02-12 20:49:00 -0600 | [diff] [blame] | 275 | /* VIOS automatically unmaps the long term buffer at remote |
| 276 | * end for the following resets: |
| 277 | * FAILOVER, MOBILITY, TIMEOUT. |
| 278 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 279 | if (adapter->reset_reason != VNIC_RESET_FAILOVER && |
Lijun Pan | 7d3a7b9 | 2021-02-12 20:49:00 -0600 | [diff] [blame] | 280 | adapter->reset_reason != VNIC_RESET_MOBILITY && |
| 281 | adapter->reset_reason != VNIC_RESET_TIMEOUT) |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 282 | send_request_unmap(adapter, ltb->map_id); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 283 | |
Brian King | 59af56c | 2017-04-19 13:44:41 -0400 | [diff] [blame] | 284 | dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 285 | |
Sukadev Bhattiprolu | 552a337 | 2021-06-23 21:13:14 -0700 | [diff] [blame] | 286 | ltb->buff = NULL; |
| 287 | ltb->map_id = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 288 | } |
| 289 | |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 290 | static int reset_long_term_buff(struct ibmvnic_adapter *adapter, |
| 291 | struct ibmvnic_long_term_buff *ltb) |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 292 | { |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 293 | struct device *dev = &adapter->vdev->dev; |
| 294 | int rc; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 295 | |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 296 | memset(ltb->buff, 0, ltb->size); |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 297 | |
| 298 | mutex_lock(&adapter->fw_lock); |
| 299 | adapter->fw_done_rc = 0; |
| 300 | |
| 301 | reinit_completion(&adapter->fw_done); |
| 302 | rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id); |
| 303 | if (rc) { |
| 304 | mutex_unlock(&adapter->fw_lock); |
| 305 | return rc; |
| 306 | } |
| 307 | |
| 308 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 309 | if (rc) { |
| 310 | dev_info(dev, |
| 311 | "Reset failed, long term map request timed out or aborted\n"); |
| 312 | mutex_unlock(&adapter->fw_lock); |
| 313 | return rc; |
| 314 | } |
| 315 | |
| 316 | if (adapter->fw_done_rc) { |
| 317 | dev_info(dev, |
| 318 | "Reset failed, attempting to free and reallocate buffer\n"); |
| 319 | free_long_term_buff(adapter, ltb); |
| 320 | mutex_unlock(&adapter->fw_lock); |
| 321 | return alloc_long_term_buff(adapter, ltb, ltb->size); |
| 322 | } |
| 323 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 327 | static void deactivate_rx_pools(struct ibmvnic_adapter *adapter) |
| 328 | { |
| 329 | int i; |
| 330 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 331 | for (i = 0; i < adapter->num_active_rx_pools; i++) |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 332 | adapter->rx_pool[i].active = 0; |
| 333 | } |
| 334 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 335 | static void replenish_rx_pool(struct ibmvnic_adapter *adapter, |
| 336 | struct ibmvnic_rx_pool *pool) |
| 337 | { |
| 338 | int count = pool->size - atomic_read(&pool->available); |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 339 | u64 handle = adapter->rx_scrq[pool->index]->handle; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 340 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 341 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 342 | struct ibmvnic_sub_crq_queue *rx_scrq; |
| 343 | union sub_crq *sub_crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 344 | int buffers_added = 0; |
| 345 | unsigned long lpar_rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 346 | struct sk_buff *skb; |
| 347 | unsigned int offset; |
| 348 | dma_addr_t dma_addr; |
| 349 | unsigned char *dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 350 | int shift = 0; |
| 351 | int index; |
| 352 | int i; |
| 353 | |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 354 | if (!pool->active) |
| 355 | return; |
| 356 | |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 357 | rx_scrq = adapter->rx_scrq[pool->index]; |
| 358 | ind_bufp = &rx_scrq->ind_buf; |
Sukadev Bhattiprolu | 72368f8 | 2021-06-23 21:13:13 -0700 | [diff] [blame] | 359 | |
| 360 | /* netdev_skb_alloc() could have failed after we saved a few skbs |
| 361 | * in the indir_buf and we would not have sent them to VIOS yet. |
| 362 | * To account for them, start the loop at ind_bufp->index rather |
| 363 | * than 0. If we pushed all the skbs to VIOS, ind_bufp->index will |
| 364 | * be 0. |
| 365 | */ |
| 366 | for (i = ind_bufp->index; i < count; ++i) { |
Dwip N. Banerjee | e552aa3 | 2020-11-18 19:12:24 -0600 | [diff] [blame] | 367 | skb = netdev_alloc_skb(adapter->netdev, pool->buff_size); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 368 | if (!skb) { |
| 369 | dev_err(dev, "Couldn't replenish rx buff\n"); |
| 370 | adapter->replenish_no_mem++; |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | index = pool->free_map[pool->next_free]; |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 375 | pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP; |
| 376 | pool->next_free = (pool->next_free + 1) % pool->size; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 377 | |
| 378 | if (pool->rx_buff[index].skb) |
| 379 | dev_err(dev, "Inconsistent free_map!\n"); |
| 380 | |
| 381 | /* Copy the skb to the long term mapped DMA buffer */ |
| 382 | offset = index * pool->buff_size; |
| 383 | dst = pool->long_term_buff.buff + offset; |
| 384 | memset(dst, 0, pool->buff_size); |
| 385 | dma_addr = pool->long_term_buff.addr + offset; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 386 | |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 387 | /* add the skb to an rx_buff in the pool */ |
| 388 | pool->rx_buff[index].data = dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 389 | pool->rx_buff[index].dma = dma_addr; |
| 390 | pool->rx_buff[index].skb = skb; |
| 391 | pool->rx_buff[index].pool_index = pool->index; |
| 392 | pool->rx_buff[index].size = pool->buff_size; |
| 393 | |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 394 | /* queue the rx_buff for the next send_subcrq_indirect */ |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 395 | sub_crq = &ind_bufp->indir_arr[ind_bufp->index++]; |
| 396 | memset(sub_crq, 0, sizeof(*sub_crq)); |
| 397 | sub_crq->rx_add.first = IBMVNIC_CRQ_CMD; |
| 398 | sub_crq->rx_add.correlator = |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 399 | cpu_to_be64((u64)&pool->rx_buff[index]); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 400 | sub_crq->rx_add.ioba = cpu_to_be32(dma_addr); |
| 401 | sub_crq->rx_add.map_id = pool->long_term_buff.map_id; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 402 | |
| 403 | /* The length field of the sCRQ is defined to be 24 bits so the |
| 404 | * buffer size needs to be left shifted by a byte before it is |
| 405 | * converted to big endian to prevent the last byte from being |
| 406 | * truncated. |
| 407 | */ |
| 408 | #ifdef __LITTLE_ENDIAN__ |
| 409 | shift = 8; |
| 410 | #endif |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 411 | sub_crq->rx_add.len = cpu_to_be32(pool->buff_size << shift); |
Sukadev Bhattiprolu | 38106b2 | 2021-09-14 20:52:51 -0700 | [diff] [blame] | 412 | |
| 413 | /* if send_subcrq_indirect queue is full, flush to VIOS */ |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 414 | if (ind_bufp->index == IBMVNIC_MAX_IND_DESCS || |
| 415 | i == count - 1) { |
| 416 | lpar_rc = |
| 417 | send_subcrq_indirect(adapter, handle, |
| 418 | (u64)ind_bufp->indir_dma, |
| 419 | (u64)ind_bufp->index); |
| 420 | if (lpar_rc != H_SUCCESS) |
| 421 | goto failure; |
| 422 | buffers_added += ind_bufp->index; |
| 423 | adapter->replenish_add_buff_success += ind_bufp->index; |
| 424 | ind_bufp->index = 0; |
| 425 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 426 | } |
| 427 | atomic_add(buffers_added, &pool->available); |
| 428 | return; |
| 429 | |
| 430 | failure: |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 431 | if (lpar_rc != H_PARAMETER && lpar_rc != H_CLOSED) |
| 432 | dev_err_ratelimited(dev, "rx: replenish packet buffer failed\n"); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 433 | for (i = ind_bufp->index - 1; i >= 0; --i) { |
| 434 | struct ibmvnic_rx_buff *rx_buff; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 435 | |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 436 | pool->next_free = pool->next_free == 0 ? |
| 437 | pool->size - 1 : pool->next_free - 1; |
| 438 | sub_crq = &ind_bufp->indir_arr[i]; |
| 439 | rx_buff = (struct ibmvnic_rx_buff *) |
| 440 | be64_to_cpu(sub_crq->rx_add.correlator); |
| 441 | index = (int)(rx_buff - pool->rx_buff); |
| 442 | pool->free_map[pool->next_free] = index; |
| 443 | dev_kfree_skb_any(pool->rx_buff[index].skb); |
| 444 | pool->rx_buff[index].skb = NULL; |
| 445 | } |
Dwip N. Banerjee | c2af622 | 2020-12-09 20:53:31 -0500 | [diff] [blame] | 446 | adapter->replenish_add_buff_failure += ind_bufp->index; |
| 447 | atomic_add(buffers_added, &pool->available); |
Thomas Falcon | 4f0b681 | 2020-11-18 19:12:18 -0600 | [diff] [blame] | 448 | ind_bufp->index = 0; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 449 | if (lpar_rc == H_CLOSED || adapter->failover_pending) { |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 450 | /* Disable buffer pool replenishment and report carrier off if |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 451 | * queue is closed or pending failover. |
| 452 | * Firmware guarantees that a signal will be sent to the |
| 453 | * driver, triggering a reset. |
Thomas Falcon | f185a49 | 2017-05-26 10:30:48 -0400 | [diff] [blame] | 454 | */ |
| 455 | deactivate_rx_pools(adapter); |
| 456 | netif_carrier_off(adapter->netdev); |
| 457 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void replenish_pools(struct ibmvnic_adapter *adapter) |
| 461 | { |
| 462 | int i; |
| 463 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 464 | adapter->replenish_task_cycles++; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 465 | for (i = 0; i < adapter->num_active_rx_pools; i++) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 466 | if (adapter->rx_pool[i].active) |
| 467 | replenish_rx_pool(adapter, &adapter->rx_pool[i]); |
| 468 | } |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 469 | |
| 470 | netdev_dbg(adapter->netdev, "Replenished %d pools\n", i); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 471 | } |
| 472 | |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 473 | static void release_stats_buffers(struct ibmvnic_adapter *adapter) |
| 474 | { |
| 475 | kfree(adapter->tx_stats_buffers); |
| 476 | kfree(adapter->rx_stats_buffers); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 477 | adapter->tx_stats_buffers = NULL; |
| 478 | adapter->rx_stats_buffers = NULL; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static int init_stats_buffers(struct ibmvnic_adapter *adapter) |
| 482 | { |
| 483 | adapter->tx_stats_buffers = |
Nathan Fontenot | abcae54 | 2018-02-19 13:30:47 -0600 | [diff] [blame] | 484 | kcalloc(IBMVNIC_MAX_QUEUES, |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 485 | sizeof(struct ibmvnic_tx_queue_stats), |
| 486 | GFP_KERNEL); |
| 487 | if (!adapter->tx_stats_buffers) |
| 488 | return -ENOMEM; |
| 489 | |
| 490 | adapter->rx_stats_buffers = |
Nathan Fontenot | abcae54 | 2018-02-19 13:30:47 -0600 | [diff] [blame] | 491 | kcalloc(IBMVNIC_MAX_QUEUES, |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 492 | sizeof(struct ibmvnic_rx_queue_stats), |
| 493 | GFP_KERNEL); |
| 494 | if (!adapter->rx_stats_buffers) |
| 495 | return -ENOMEM; |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 500 | static void release_stats_token(struct ibmvnic_adapter *adapter) |
| 501 | { |
| 502 | struct device *dev = &adapter->vdev->dev; |
| 503 | |
| 504 | if (!adapter->stats_token) |
| 505 | return; |
| 506 | |
| 507 | dma_unmap_single(dev, adapter->stats_token, |
| 508 | sizeof(struct ibmvnic_statistics), |
| 509 | DMA_FROM_DEVICE); |
| 510 | adapter->stats_token = 0; |
| 511 | } |
| 512 | |
| 513 | static int init_stats_token(struct ibmvnic_adapter *adapter) |
| 514 | { |
| 515 | struct device *dev = &adapter->vdev->dev; |
| 516 | dma_addr_t stok; |
| 517 | |
| 518 | stok = dma_map_single(dev, &adapter->stats, |
| 519 | sizeof(struct ibmvnic_statistics), |
| 520 | DMA_FROM_DEVICE); |
| 521 | if (dma_mapping_error(dev, stok)) { |
| 522 | dev_err(dev, "Couldn't map stats buffer\n"); |
| 523 | return -1; |
| 524 | } |
| 525 | |
| 526 | adapter->stats_token = stok; |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 527 | netdev_dbg(adapter->netdev, "Stats token initialized (%llx)\n", stok); |
Nathan Fontenot | 7bbc27a | 2017-03-30 02:49:23 -0400 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 531 | static int reset_rx_pools(struct ibmvnic_adapter *adapter) |
| 532 | { |
| 533 | struct ibmvnic_rx_pool *rx_pool; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 534 | u64 buff_size; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 535 | int rx_scrqs; |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 536 | int i, j, rc; |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 537 | |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 538 | if (!adapter->rx_pool) |
| 539 | return -1; |
| 540 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 541 | buff_size = adapter->cur_rx_buf_sz; |
| 542 | rx_scrqs = adapter->num_active_rx_pools; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 543 | for (i = 0; i < rx_scrqs; i++) { |
| 544 | rx_pool = &adapter->rx_pool[i]; |
| 545 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 546 | netdev_dbg(adapter->netdev, "Re-setting rx_pool[%d]\n", i); |
| 547 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 548 | if (rx_pool->buff_size != buff_size) { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 549 | free_long_term_buff(adapter, &rx_pool->long_term_buff); |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 550 | rx_pool->buff_size = ALIGN(buff_size, L1_CACHE_BYTES); |
Thomas Falcon | 7c940b1 | 2019-06-07 16:03:55 -0500 | [diff] [blame] | 551 | rc = alloc_long_term_buff(adapter, |
| 552 | &rx_pool->long_term_buff, |
| 553 | rx_pool->size * |
| 554 | rx_pool->buff_size); |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 555 | } else { |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 556 | rc = reset_long_term_buff(adapter, |
| 557 | &rx_pool->long_term_buff); |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 558 | } |
| 559 | |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 560 | if (rc) |
| 561 | return rc; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 562 | |
| 563 | for (j = 0; j < rx_pool->size; j++) |
| 564 | rx_pool->free_map[j] = j; |
| 565 | |
| 566 | memset(rx_pool->rx_buff, 0, |
| 567 | rx_pool->size * sizeof(struct ibmvnic_rx_buff)); |
| 568 | |
| 569 | atomic_set(&rx_pool->available, 0); |
| 570 | rx_pool->next_alloc = 0; |
| 571 | rx_pool->next_free = 0; |
Thomas Falcon | c3e53b9 | 2017-06-14 23:50:05 -0500 | [diff] [blame] | 572 | rx_pool->active = 1; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 578 | /** |
| 579 | * release_rx_pools() - Release any rx pools attached to @adapter. |
| 580 | * @adapter: ibmvnic adapter |
| 581 | * |
| 582 | * Safe to call this multiple times - even if no pools are attached. |
| 583 | */ |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 584 | static void release_rx_pools(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 585 | { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 586 | struct ibmvnic_rx_pool *rx_pool; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 587 | int i, j; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 588 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 589 | if (!adapter->rx_pool) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 590 | return; |
| 591 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 592 | for (i = 0; i < adapter->num_active_rx_pools; i++) { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 593 | rx_pool = &adapter->rx_pool[i]; |
| 594 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 595 | netdev_dbg(adapter->netdev, "Releasing rx_pool[%d]\n", i); |
| 596 | |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 597 | kfree(rx_pool->free_map); |
| 598 | free_long_term_buff(adapter, &rx_pool->long_term_buff); |
| 599 | |
| 600 | if (!rx_pool->rx_buff) |
Nathan Fontenot | e0ebe942 | 2017-05-03 14:04:50 -0400 | [diff] [blame] | 601 | continue; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 602 | |
| 603 | for (j = 0; j < rx_pool->size; j++) { |
| 604 | if (rx_pool->rx_buff[j].skb) { |
Thomas Falcon | b7cdec3 | 2018-11-21 11:17:58 -0600 | [diff] [blame] | 605 | dev_kfree_skb_any(rx_pool->rx_buff[j].skb); |
| 606 | rx_pool->rx_buff[j].skb = NULL; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 607 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 608 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 609 | |
| 610 | kfree(rx_pool->rx_buff); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 611 | } |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 612 | |
| 613 | kfree(adapter->rx_pool); |
| 614 | adapter->rx_pool = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 615 | adapter->num_active_rx_pools = 0; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static int init_rx_pools(struct net_device *netdev) |
| 619 | { |
| 620 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 621 | struct device *dev = &adapter->vdev->dev; |
| 622 | struct ibmvnic_rx_pool *rx_pool; |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 623 | u64 num_pools; |
| 624 | u64 pool_size; /* # of buffers in one pool */ |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 625 | u64 buff_size; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 626 | int i, j; |
| 627 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 628 | num_pools = adapter->num_active_rx_scrqs; |
| 629 | pool_size = adapter->req_rx_add_entries_per_subcrq; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 630 | buff_size = adapter->cur_rx_buf_sz; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 631 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 632 | adapter->rx_pool = kcalloc(num_pools, |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 633 | sizeof(struct ibmvnic_rx_pool), |
| 634 | GFP_KERNEL); |
| 635 | if (!adapter->rx_pool) { |
| 636 | dev_err(dev, "Failed to allocate rx pools\n"); |
| 637 | return -1; |
| 638 | } |
| 639 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 640 | /* Set num_active_rx_pools early. If we fail below after partial |
| 641 | * allocation, release_rx_pools() will know how many to look for. |
| 642 | */ |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 643 | adapter->num_active_rx_pools = num_pools; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 644 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 645 | for (i = 0; i < num_pools; i++) { |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 646 | rx_pool = &adapter->rx_pool[i]; |
| 647 | |
| 648 | netdev_dbg(adapter->netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 649 | "Initializing rx_pool[%d], %lld buffs, %lld bytes each\n", |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 650 | i, pool_size, buff_size); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 651 | |
Sukadev Bhattiprolu | 0df7b9a | 2021-09-14 20:52:53 -0700 | [diff] [blame^] | 652 | rx_pool->size = pool_size; |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 653 | rx_pool->index = i; |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 654 | rx_pool->buff_size = ALIGN(buff_size, L1_CACHE_BYTES); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 655 | rx_pool->active = 1; |
| 656 | |
| 657 | rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int), |
| 658 | GFP_KERNEL); |
| 659 | if (!rx_pool->free_map) { |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 660 | dev_err(dev, "Couldn't alloc free_map %d\n", i); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 661 | release_rx_pools(adapter); |
| 662 | return -1; |
| 663 | } |
| 664 | |
| 665 | rx_pool->rx_buff = kcalloc(rx_pool->size, |
| 666 | sizeof(struct ibmvnic_rx_buff), |
| 667 | GFP_KERNEL); |
| 668 | if (!rx_pool->rx_buff) { |
| 669 | dev_err(dev, "Couldn't alloc rx buffers\n"); |
| 670 | release_rx_pools(adapter); |
| 671 | return -1; |
| 672 | } |
| 673 | |
| 674 | if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff, |
| 675 | rx_pool->size * rx_pool->buff_size)) { |
| 676 | release_rx_pools(adapter); |
| 677 | return -1; |
| 678 | } |
| 679 | |
| 680 | for (j = 0; j < rx_pool->size; ++j) |
| 681 | rx_pool->free_map[j] = j; |
| 682 | |
| 683 | atomic_set(&rx_pool->available, 0); |
| 684 | rx_pool->next_alloc = 0; |
| 685 | rx_pool->next_free = 0; |
| 686 | } |
| 687 | |
| 688 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 689 | } |
| 690 | |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 691 | static int reset_one_tx_pool(struct ibmvnic_adapter *adapter, |
| 692 | struct ibmvnic_tx_pool *tx_pool) |
Thomas Falcon | e26dc25 | 2018-03-16 20:00:25 -0500 | [diff] [blame] | 693 | { |
| 694 | int rc, i; |
| 695 | |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 696 | rc = reset_long_term_buff(adapter, &tx_pool->long_term_buff); |
Thomas Falcon | e26dc25 | 2018-03-16 20:00:25 -0500 | [diff] [blame] | 697 | if (rc) |
| 698 | return rc; |
| 699 | |
| 700 | memset(tx_pool->tx_buff, 0, |
| 701 | tx_pool->num_buffers * |
| 702 | sizeof(struct ibmvnic_tx_buff)); |
| 703 | |
| 704 | for (i = 0; i < tx_pool->num_buffers; i++) |
| 705 | tx_pool->free_map[i] = i; |
| 706 | |
| 707 | tx_pool->consumer_index = 0; |
| 708 | tx_pool->producer_index = 0; |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 713 | static int reset_tx_pools(struct ibmvnic_adapter *adapter) |
| 714 | { |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 715 | int tx_scrqs; |
Thomas Falcon | e26dc25 | 2018-03-16 20:00:25 -0500 | [diff] [blame] | 716 | int i, rc; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 717 | |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 718 | if (!adapter->tx_pool) |
| 719 | return -1; |
| 720 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 721 | tx_scrqs = adapter->num_active_tx_pools; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 722 | for (i = 0; i < tx_scrqs; i++) { |
Sukadev Bhattiprolu | 65d6470 | 2021-06-23 21:13:12 -0700 | [diff] [blame] | 723 | ibmvnic_tx_scrq_clean_buffer(adapter, adapter->tx_scrq[i]); |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 724 | rc = reset_one_tx_pool(adapter, &adapter->tso_pool[i]); |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 725 | if (rc) |
| 726 | return rc; |
Sukadev Bhattiprolu | 0ec13af | 2021-06-23 21:13:10 -0700 | [diff] [blame] | 727 | rc = reset_one_tx_pool(adapter, &adapter->tx_pool[i]); |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 728 | if (rc) |
| 729 | return rc; |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 735 | static void release_vpd_data(struct ibmvnic_adapter *adapter) |
| 736 | { |
| 737 | if (!adapter->vpd) |
| 738 | return; |
| 739 | |
| 740 | kfree(adapter->vpd->buff); |
| 741 | kfree(adapter->vpd); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 742 | |
| 743 | adapter->vpd = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 744 | } |
| 745 | |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 746 | static void release_one_tx_pool(struct ibmvnic_adapter *adapter, |
| 747 | struct ibmvnic_tx_pool *tx_pool) |
| 748 | { |
| 749 | kfree(tx_pool->tx_buff); |
| 750 | kfree(tx_pool->free_map); |
| 751 | free_long_term_buff(adapter, &tx_pool->long_term_buff); |
| 752 | } |
| 753 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 754 | /** |
| 755 | * release_tx_pools() - Release any tx pools attached to @adapter. |
| 756 | * @adapter: ibmvnic adapter |
| 757 | * |
| 758 | * Safe to call this multiple times - even if no pools are attached. |
| 759 | */ |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 760 | static void release_tx_pools(struct ibmvnic_adapter *adapter) |
| 761 | { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 762 | int i; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 763 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 764 | /* init_tx_pools() ensures that ->tx_pool and ->tso_pool are |
| 765 | * both NULL or both non-NULL. So we only need to check one. |
| 766 | */ |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 767 | if (!adapter->tx_pool) |
| 768 | return; |
| 769 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 770 | for (i = 0; i < adapter->num_active_tx_pools; i++) { |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 771 | release_one_tx_pool(adapter, &adapter->tx_pool[i]); |
| 772 | release_one_tx_pool(adapter, &adapter->tso_pool[i]); |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | kfree(adapter->tx_pool); |
| 776 | adapter->tx_pool = NULL; |
Thomas Falcon | fb79421 | 2018-03-16 20:00:26 -0500 | [diff] [blame] | 777 | kfree(adapter->tso_pool); |
| 778 | adapter->tso_pool = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 779 | adapter->num_active_tx_pools = 0; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 780 | } |
| 781 | |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 782 | static int init_one_tx_pool(struct net_device *netdev, |
| 783 | struct ibmvnic_tx_pool *tx_pool, |
| 784 | int num_entries, int buf_size) |
| 785 | { |
| 786 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 787 | int i; |
| 788 | |
| 789 | tx_pool->tx_buff = kcalloc(num_entries, |
| 790 | sizeof(struct ibmvnic_tx_buff), |
| 791 | GFP_KERNEL); |
| 792 | if (!tx_pool->tx_buff) |
| 793 | return -1; |
| 794 | |
| 795 | if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff, |
| 796 | num_entries * buf_size)) |
| 797 | return -1; |
| 798 | |
| 799 | tx_pool->free_map = kcalloc(num_entries, sizeof(int), GFP_KERNEL); |
| 800 | if (!tx_pool->free_map) |
| 801 | return -1; |
| 802 | |
| 803 | for (i = 0; i < num_entries; i++) |
| 804 | tx_pool->free_map[i] = i; |
| 805 | |
| 806 | tx_pool->consumer_index = 0; |
| 807 | tx_pool->producer_index = 0; |
| 808 | tx_pool->num_buffers = num_entries; |
| 809 | tx_pool->buf_size = buf_size; |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 814 | static int init_tx_pools(struct net_device *netdev) |
| 815 | { |
| 816 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 817 | struct device *dev = &adapter->vdev->dev; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 818 | int tx_subcrqs; |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 819 | u64 buff_size; |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 820 | int i, rc; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 821 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 822 | tx_subcrqs = adapter->num_active_tx_scrqs; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 823 | adapter->tx_pool = kcalloc(tx_subcrqs, |
| 824 | sizeof(struct ibmvnic_tx_pool), GFP_KERNEL); |
| 825 | if (!adapter->tx_pool) |
| 826 | return -1; |
| 827 | |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 828 | adapter->tso_pool = kcalloc(tx_subcrqs, |
| 829 | sizeof(struct ibmvnic_tx_pool), GFP_KERNEL); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 830 | /* To simplify release_tx_pools() ensure that ->tx_pool and |
| 831 | * ->tso_pool are either both NULL or both non-NULL. |
| 832 | */ |
Sukadev Bhattiprolu | f6ebca8 | 2021-06-23 21:13:15 -0700 | [diff] [blame] | 833 | if (!adapter->tso_pool) { |
| 834 | kfree(adapter->tx_pool); |
| 835 | adapter->tx_pool = NULL; |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 836 | return -1; |
Sukadev Bhattiprolu | f6ebca8 | 2021-06-23 21:13:15 -0700 | [diff] [blame] | 837 | } |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 838 | |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 839 | /* Set num_active_tx_pools early. If we fail below after partial |
| 840 | * allocation, release_tx_pools() will know how many to look for. |
| 841 | */ |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 842 | adapter->num_active_tx_pools = tx_subcrqs; |
| 843 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 844 | for (i = 0; i < tx_subcrqs; i++) { |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 845 | buff_size = adapter->req_mtu + VLAN_HLEN; |
| 846 | buff_size = ALIGN(buff_size, L1_CACHE_BYTES); |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 847 | |
| 848 | dev_dbg(dev, "Init tx pool %d [%llu, %llu]\n", |
| 849 | i, adapter->req_tx_entries_per_subcrq, buff_size); |
| 850 | |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 851 | rc = init_one_tx_pool(netdev, &adapter->tx_pool[i], |
| 852 | adapter->req_tx_entries_per_subcrq, |
Dwip N. Banerjee | 9a87c3f | 2020-11-18 19:12:22 -0600 | [diff] [blame] | 853 | buff_size); |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 854 | if (rc) { |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 855 | release_tx_pools(adapter); |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 856 | return rc; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Thomas Falcon | 7c940b1 | 2019-06-07 16:03:55 -0500 | [diff] [blame] | 859 | rc = init_one_tx_pool(netdev, &adapter->tso_pool[i], |
| 860 | IBMVNIC_TSO_BUFS, |
| 861 | IBMVNIC_TSO_BUF_SZ); |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 862 | if (rc) { |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 863 | release_tx_pools(adapter); |
Thomas Falcon | 3205306 | 2018-03-16 20:00:27 -0500 | [diff] [blame] | 864 | return rc; |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 865 | } |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 871 | static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter) |
| 872 | { |
| 873 | int i; |
| 874 | |
| 875 | if (adapter->napi_enabled) |
| 876 | return; |
| 877 | |
| 878 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 879 | napi_enable(&adapter->napi[i]); |
| 880 | |
| 881 | adapter->napi_enabled = true; |
| 882 | } |
| 883 | |
| 884 | static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter) |
| 885 | { |
| 886 | int i; |
| 887 | |
| 888 | if (!adapter->napi_enabled) |
| 889 | return; |
| 890 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 891 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 892 | netdev_dbg(adapter->netdev, "Disabling napi[%d]\n", i); |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 893 | napi_disable(&adapter->napi[i]); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 894 | } |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 895 | |
| 896 | adapter->napi_enabled = false; |
| 897 | } |
| 898 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 899 | static int init_napi(struct ibmvnic_adapter *adapter) |
| 900 | { |
| 901 | int i; |
| 902 | |
| 903 | adapter->napi = kcalloc(adapter->req_rx_queues, |
| 904 | sizeof(struct napi_struct), GFP_KERNEL); |
| 905 | if (!adapter->napi) |
| 906 | return -ENOMEM; |
| 907 | |
| 908 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 909 | netdev_dbg(adapter->netdev, "Adding napi[%d]\n", i); |
| 910 | netif_napi_add(adapter->netdev, &adapter->napi[i], |
| 911 | ibmvnic_poll, NAPI_POLL_WEIGHT); |
| 912 | } |
| 913 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 914 | adapter->num_active_rx_napi = adapter->req_rx_queues; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | static void release_napi(struct ibmvnic_adapter *adapter) |
| 919 | { |
| 920 | int i; |
| 921 | |
| 922 | if (!adapter->napi) |
| 923 | return; |
| 924 | |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 925 | for (i = 0; i < adapter->num_active_rx_napi; i++) { |
Wen Yang | 390de19 | 2018-12-11 12:20:46 +0800 | [diff] [blame] | 926 | netdev_dbg(adapter->netdev, "Releasing napi[%d]\n", i); |
| 927 | netif_napi_del(&adapter->napi[i]); |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | kfree(adapter->napi); |
| 931 | adapter->napi = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 932 | adapter->num_active_rx_napi = 0; |
Thomas Falcon | c3f2241 | 2018-05-23 13:37:55 -0500 | [diff] [blame] | 933 | adapter->napi_enabled = false; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 934 | } |
| 935 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 936 | static const char *adapter_state_to_string(enum vnic_state state) |
| 937 | { |
| 938 | switch (state) { |
| 939 | case VNIC_PROBING: |
| 940 | return "PROBING"; |
| 941 | case VNIC_PROBED: |
| 942 | return "PROBED"; |
| 943 | case VNIC_OPENING: |
| 944 | return "OPENING"; |
| 945 | case VNIC_OPEN: |
| 946 | return "OPEN"; |
| 947 | case VNIC_CLOSING: |
| 948 | return "CLOSING"; |
| 949 | case VNIC_CLOSED: |
| 950 | return "CLOSED"; |
| 951 | case VNIC_REMOVING: |
| 952 | return "REMOVING"; |
| 953 | case VNIC_REMOVED: |
| 954 | return "REMOVED"; |
Lijun Pan | 822ebc2 | 2021-06-11 10:35:37 -0500 | [diff] [blame] | 955 | case VNIC_DOWN: |
| 956 | return "DOWN"; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 957 | } |
Michal Suchanek | 07b5dc1 | 2021-05-20 08:50:34 +0200 | [diff] [blame] | 958 | return "UNKNOWN"; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 959 | } |
| 960 | |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 961 | static int ibmvnic_login(struct net_device *netdev) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 962 | { |
| 963 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 964 | unsigned long timeout = msecs_to_jiffies(20000); |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 965 | int retry_count = 0; |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 966 | int retries = 10; |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 967 | bool retry; |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 968 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 969 | |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 970 | do { |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 971 | retry = false; |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 972 | if (retry_count > retries) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 973 | netdev_warn(netdev, "Login attempts exceeded\n"); |
| 974 | return -1; |
| 975 | } |
| 976 | |
| 977 | adapter->init_done_rc = 0; |
| 978 | reinit_completion(&adapter->init_done); |
| 979 | rc = send_login(adapter); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 980 | if (rc) |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 981 | return rc; |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 982 | |
| 983 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 984 | timeout)) { |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 985 | netdev_warn(netdev, "Login timed out, retrying...\n"); |
| 986 | retry = true; |
| 987 | adapter->init_done_rc = 0; |
| 988 | retry_count++; |
| 989 | continue; |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 990 | } |
| 991 | |
Thomas Falcon | dff515a3 | 2020-06-15 10:29:23 -0500 | [diff] [blame] | 992 | if (adapter->init_done_rc == ABORTED) { |
| 993 | netdev_warn(netdev, "Login aborted, retrying...\n"); |
| 994 | retry = true; |
| 995 | adapter->init_done_rc = 0; |
| 996 | retry_count++; |
| 997 | /* FW or device may be busy, so |
| 998 | * wait a bit before retrying login |
| 999 | */ |
| 1000 | msleep(500); |
| 1001 | } else if (adapter->init_done_rc == PARTIALSUCCESS) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1002 | retry_count++; |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 1003 | release_sub_crqs(adapter, 1); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1004 | |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1005 | retry = true; |
| 1006 | netdev_dbg(netdev, |
| 1007 | "Received partial success, retrying...\n"); |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1008 | adapter->init_done_rc = 0; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1009 | reinit_completion(&adapter->init_done); |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 1010 | send_query_cap(adapter); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1011 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 1012 | timeout)) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1013 | netdev_warn(netdev, |
| 1014 | "Capabilities query timed out\n"); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1015 | return -1; |
| 1016 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1017 | |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1018 | rc = init_sub_crqs(adapter); |
| 1019 | if (rc) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1020 | netdev_warn(netdev, |
| 1021 | "SCRQ initialization failed\n"); |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1022 | return -1; |
| 1023 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1024 | |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1025 | rc = init_sub_crq_irqs(adapter); |
| 1026 | if (rc) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1027 | netdev_warn(netdev, |
| 1028 | "SCRQ irq initialization failed\n"); |
Thomas Falcon | 4d96f12 | 2017-08-01 15:04:36 -0500 | [diff] [blame] | 1029 | return -1; |
| 1030 | } |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 1031 | } else if (adapter->init_done_rc) { |
| 1032 | netdev_warn(netdev, "Adapter login failed\n"); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1033 | return -1; |
| 1034 | } |
Thomas Falcon | eb11041 | 2018-05-24 14:37:53 -0500 | [diff] [blame] | 1035 | } while (retry); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1036 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 1037 | __ibmvnic_set_mac(netdev, adapter->mac_addr); |
Thomas Falcon | 3d16613 | 2018-01-10 19:39:52 -0600 | [diff] [blame] | 1038 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1039 | 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] | 1040 | return 0; |
| 1041 | } |
| 1042 | |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 1043 | static void release_login_buffer(struct ibmvnic_adapter *adapter) |
| 1044 | { |
| 1045 | kfree(adapter->login_buf); |
| 1046 | adapter->login_buf = NULL; |
| 1047 | } |
| 1048 | |
| 1049 | static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter) |
| 1050 | { |
| 1051 | kfree(adapter->login_rsp_buf); |
| 1052 | adapter->login_rsp_buf = NULL; |
| 1053 | } |
| 1054 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 1055 | static void release_resources(struct ibmvnic_adapter *adapter) |
| 1056 | { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1057 | release_vpd_data(adapter); |
| 1058 | |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 1059 | release_tx_pools(adapter); |
| 1060 | release_rx_pools(adapter); |
| 1061 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1062 | release_napi(adapter); |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 1063 | release_login_buffer(adapter); |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 1064 | release_login_rsp_buffer(adapter); |
Nathan Fontenot | 1b8955e | 2017-03-30 02:49:29 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1067 | static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state) |
| 1068 | { |
| 1069 | struct net_device *netdev = adapter->netdev; |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 1070 | unsigned long timeout = msecs_to_jiffies(20000); |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1071 | union ibmvnic_crq crq; |
| 1072 | bool resend; |
| 1073 | int rc; |
| 1074 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1075 | netdev_dbg(netdev, "setting link state %d\n", link_state); |
| 1076 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1077 | memset(&crq, 0, sizeof(crq)); |
| 1078 | crq.logical_link_state.first = IBMVNIC_CRQ_CMD; |
| 1079 | crq.logical_link_state.cmd = LOGICAL_LINK_STATE; |
| 1080 | crq.logical_link_state.link_state = link_state; |
| 1081 | |
| 1082 | do { |
| 1083 | resend = false; |
| 1084 | |
| 1085 | reinit_completion(&adapter->init_done); |
| 1086 | rc = ibmvnic_send_crq(adapter, &crq); |
| 1087 | if (rc) { |
| 1088 | netdev_err(netdev, "Failed to set link state\n"); |
| 1089 | return rc; |
| 1090 | } |
| 1091 | |
| 1092 | if (!wait_for_completion_timeout(&adapter->init_done, |
| 1093 | timeout)) { |
| 1094 | netdev_err(netdev, "timeout setting link state\n"); |
| 1095 | return -1; |
| 1096 | } |
| 1097 | |
Lijun Pan | 4c5f6af | 2020-08-19 17:52:23 -0500 | [diff] [blame] | 1098 | if (adapter->init_done_rc == PARTIALSUCCESS) { |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1099 | /* Partuial success, delay and re-send */ |
| 1100 | mdelay(1000); |
| 1101 | resend = true; |
Thomas Falcon | ab5ec33 | 2018-05-23 13:37:59 -0500 | [diff] [blame] | 1102 | } else if (adapter->init_done_rc) { |
| 1103 | netdev_warn(netdev, "Unable to set link state, rc=%d\n", |
| 1104 | adapter->init_done_rc); |
| 1105 | return adapter->init_done_rc; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1106 | } |
| 1107 | } while (resend); |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1112 | static int set_real_num_queues(struct net_device *netdev) |
| 1113 | { |
| 1114 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1115 | int rc; |
| 1116 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1117 | netdev_dbg(netdev, "Setting real tx/rx queues (%llx/%llx)\n", |
| 1118 | adapter->req_tx_queues, adapter->req_rx_queues); |
| 1119 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1120 | rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues); |
| 1121 | if (rc) { |
| 1122 | netdev_err(netdev, "failed to set the number of tx queues\n"); |
| 1123 | return rc; |
| 1124 | } |
| 1125 | |
| 1126 | rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues); |
| 1127 | if (rc) |
| 1128 | netdev_err(netdev, "failed to set the number of rx queues\n"); |
| 1129 | |
| 1130 | return rc; |
| 1131 | } |
| 1132 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1133 | static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) |
| 1134 | { |
| 1135 | struct device *dev = &adapter->vdev->dev; |
| 1136 | union ibmvnic_crq crq; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1137 | int len = 0; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1138 | int rc; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1139 | |
| 1140 | if (adapter->vpd->buff) |
| 1141 | len = adapter->vpd->len; |
| 1142 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1143 | mutex_lock(&adapter->fw_lock); |
| 1144 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 1145 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1146 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1147 | crq.get_vpd_size.first = IBMVNIC_CRQ_CMD; |
| 1148 | crq.get_vpd_size.cmd = GET_VPD_SIZE; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1149 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1150 | if (rc) { |
| 1151 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1152 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1153 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1154 | |
| 1155 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 1156 | if (rc) { |
| 1157 | dev_err(dev, "Could not retrieve VPD size, rc = %d\n", rc); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1158 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1159 | return rc; |
| 1160 | } |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1161 | mutex_unlock(&adapter->fw_lock); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1162 | |
| 1163 | if (!adapter->vpd->len) |
| 1164 | return -ENODATA; |
| 1165 | |
| 1166 | if (!adapter->vpd->buff) |
| 1167 | adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL); |
| 1168 | else if (adapter->vpd->len != len) |
| 1169 | adapter->vpd->buff = |
| 1170 | krealloc(adapter->vpd->buff, |
| 1171 | adapter->vpd->len, GFP_KERNEL); |
| 1172 | |
| 1173 | if (!adapter->vpd->buff) { |
| 1174 | dev_err(dev, "Could allocate VPD buffer\n"); |
| 1175 | return -ENOMEM; |
| 1176 | } |
| 1177 | |
| 1178 | adapter->vpd->dma_addr = |
| 1179 | dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len, |
| 1180 | DMA_FROM_DEVICE); |
Desnes Augusto Nunes do Rosario | f743106 | 2017-11-17 09:09:04 -0200 | [diff] [blame] | 1181 | if (dma_mapping_error(dev, adapter->vpd->dma_addr)) { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1182 | dev_err(dev, "Could not map VPD buffer\n"); |
| 1183 | kfree(adapter->vpd->buff); |
Thomas Falcon | b0992ec | 2018-02-06 17:25:23 -0600 | [diff] [blame] | 1184 | adapter->vpd->buff = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1185 | return -ENOMEM; |
| 1186 | } |
| 1187 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1188 | mutex_lock(&adapter->fw_lock); |
| 1189 | adapter->fw_done_rc = 0; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1190 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1191 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1192 | crq.get_vpd.first = IBMVNIC_CRQ_CMD; |
| 1193 | crq.get_vpd.cmd = GET_VPD; |
| 1194 | crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr); |
| 1195 | crq.get_vpd.len = cpu_to_be32((u32)adapter->vpd->len); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1196 | rc = ibmvnic_send_crq(adapter, &crq); |
| 1197 | if (rc) { |
| 1198 | kfree(adapter->vpd->buff); |
| 1199 | adapter->vpd->buff = NULL; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1200 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1201 | return rc; |
| 1202 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1203 | |
| 1204 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
| 1205 | if (rc) { |
| 1206 | dev_err(dev, "Unable to retrieve VPD, rc = %d\n", rc); |
| 1207 | kfree(adapter->vpd->buff); |
| 1208 | adapter->vpd->buff = NULL; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1209 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 1210 | return rc; |
| 1211 | } |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1212 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 1213 | mutex_unlock(&adapter->fw_lock); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1214 | return 0; |
| 1215 | } |
| 1216 | |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1217 | static int init_resources(struct ibmvnic_adapter *adapter) |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 1218 | { |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1219 | struct net_device *netdev = adapter->netdev; |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1220 | int rc; |
John Allen | a57a5d2 | 2017-03-17 17:13:41 -0500 | [diff] [blame] | 1221 | |
Thomas Falcon | 7f3c6e6 | 2017-04-21 15:38:40 -0400 | [diff] [blame] | 1222 | rc = set_real_num_queues(netdev); |
| 1223 | if (rc) |
| 1224 | return rc; |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 1225 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1226 | adapter->vpd = kzalloc(sizeof(*adapter->vpd), GFP_KERNEL); |
| 1227 | if (!adapter->vpd) |
| 1228 | return -ENOMEM; |
| 1229 | |
John Allen | 69d08dc | 2018-01-18 16:27:58 -0600 | [diff] [blame] | 1230 | /* Vital Product Data (VPD) */ |
| 1231 | rc = ibmvnic_get_vpd(adapter); |
| 1232 | if (rc) { |
| 1233 | netdev_err(netdev, "failed to initialize Vital Product Data (VPD)\n"); |
| 1234 | return rc; |
| 1235 | } |
| 1236 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1237 | adapter->map_id = 1; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1238 | |
Nathan Fontenot | 86f669b | 2018-02-19 13:30:39 -0600 | [diff] [blame] | 1239 | rc = init_napi(adapter); |
| 1240 | if (rc) |
| 1241 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1242 | |
Lijun Pan | 69980d0 | 2020-09-27 20:13:28 -0500 | [diff] [blame] | 1243 | send_query_map(adapter); |
Nathan Fontenot | 0ffe2cb | 2017-03-30 02:49:12 -0400 | [diff] [blame] | 1244 | |
| 1245 | rc = init_rx_pools(netdev); |
| 1246 | if (rc) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1247 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1248 | |
Nathan Fontenot | c657e32 | 2017-03-30 02:49:06 -0400 | [diff] [blame] | 1249 | rc = init_tx_pools(netdev); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1250 | return rc; |
| 1251 | } |
| 1252 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1253 | static int __ibmvnic_open(struct net_device *netdev) |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1254 | { |
| 1255 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1256 | enum vnic_state prev_state = adapter->state; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1257 | int i, rc; |
| 1258 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 1259 | adapter->state = VNIC_OPENING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1260 | replenish_pools(adapter); |
John Allen | d944c3d6 | 2017-05-26 10:30:13 -0400 | [diff] [blame] | 1261 | ibmvnic_napi_enable(adapter); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1262 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1263 | /* We're ready to receive frames, enable the sub-crq interrupts and |
| 1264 | * set the logical link state to up |
| 1265 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1266 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1267 | netdev_dbg(netdev, "Enabling rx_scrq[%d] irq\n", i); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1268 | if (prev_state == VNIC_CLOSED) |
| 1269 | enable_irq(adapter->rx_scrq[i]->irq); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1270 | enable_scrq_irq(adapter, adapter->rx_scrq[i]); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1271 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1272 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1273 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1274 | netdev_dbg(netdev, "Enabling tx_scrq[%d] irq\n", i); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1275 | if (prev_state == VNIC_CLOSED) |
| 1276 | enable_irq(adapter->tx_scrq[i]->irq); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1277 | enable_scrq_irq(adapter, adapter->tx_scrq[i]); |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1278 | netdev_tx_reset_queue(netdev_get_tx_queue(netdev, i)); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1279 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1280 | |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 1281 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1282 | if (rc) { |
Lijun Pan | 0775ebc | 2021-04-14 02:46:14 -0500 | [diff] [blame] | 1283 | ibmvnic_napi_disable(adapter); |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1284 | release_resources(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1285 | return rc; |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1286 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1287 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1288 | netif_tx_start_all_queues(netdev); |
| 1289 | |
Dany Madden | 2ca220f | 2021-06-23 21:13:11 -0700 | [diff] [blame] | 1290 | if (prev_state == VNIC_CLOSED) { |
| 1291 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 1292 | napi_schedule(&adapter->napi[i]); |
| 1293 | } |
| 1294 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1295 | adapter->state = VNIC_OPEN; |
| 1296 | return rc; |
| 1297 | } |
| 1298 | |
| 1299 | static int ibmvnic_open(struct net_device *netdev) |
| 1300 | { |
| 1301 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
John Allen | 69d08dc | 2018-01-18 16:27:58 -0600 | [diff] [blame] | 1302 | int rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1303 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1304 | ASSERT_RTNL(); |
| 1305 | |
| 1306 | /* If device failover is pending or we are about to reset, just set |
| 1307 | * device state and return. Device operation will be handled by reset |
| 1308 | * routine. |
| 1309 | * |
| 1310 | * It should be safe to overwrite the adapter->state here. Since |
| 1311 | * we hold the rtnl, either the reset has not actually started or |
| 1312 | * the rtnl got dropped during the set_link_state() in do_reset(). |
| 1313 | * In the former case, no one else is changing the state (again we |
| 1314 | * have the rtnl) and in the latter case, do_reset() will detect and |
| 1315 | * honor our setting below. |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1316 | */ |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1317 | if (adapter->failover_pending || (test_bit(0, &adapter->resetting))) { |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1318 | netdev_dbg(netdev, "[S:%s FOP:%d] Resetting, deferring open\n", |
| 1319 | adapter_state_to_string(adapter->state), |
| 1320 | adapter->failover_pending); |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1321 | adapter->state = VNIC_OPEN; |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1322 | rc = 0; |
| 1323 | goto out; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1324 | } |
| 1325 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1326 | if (adapter->state != VNIC_CLOSED) { |
| 1327 | rc = ibmvnic_login(netdev); |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 1328 | if (rc) |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1329 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1330 | |
| 1331 | rc = init_resources(adapter); |
| 1332 | if (rc) { |
| 1333 | netdev_err(netdev, "failed to initialize resources\n"); |
| 1334 | release_resources(adapter); |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1335 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | rc = __ibmvnic_open(netdev); |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 1340 | |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1341 | out: |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1342 | /* If open failed and there is a pending failover or in-progress reset, |
| 1343 | * set device state and return. Device operation will be handled by |
| 1344 | * reset routine. See also comments above regarding rtnl. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1345 | */ |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1346 | if (rc && |
| 1347 | (adapter->failover_pending || (test_bit(0, &adapter->resetting)))) { |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1348 | adapter->state = VNIC_OPEN; |
| 1349 | rc = 0; |
| 1350 | } |
Nathan Fontenot | bfc32f2 | 2017-05-03 14:04:26 -0400 | [diff] [blame] | 1351 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1352 | } |
| 1353 | |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1354 | static void clean_rx_pools(struct ibmvnic_adapter *adapter) |
| 1355 | { |
| 1356 | struct ibmvnic_rx_pool *rx_pool; |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1357 | struct ibmvnic_rx_buff *rx_buff; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1358 | u64 rx_entries; |
| 1359 | int rx_scrqs; |
| 1360 | int i, j; |
| 1361 | |
| 1362 | if (!adapter->rx_pool) |
| 1363 | return; |
| 1364 | |
Thomas Falcon | 660e309 | 2018-04-20 14:25:32 -0500 | [diff] [blame] | 1365 | rx_scrqs = adapter->num_active_rx_pools; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1366 | rx_entries = adapter->req_rx_add_entries_per_subcrq; |
| 1367 | |
| 1368 | /* Free any remaining skbs in the rx buffer pools */ |
| 1369 | for (i = 0; i < rx_scrqs; i++) { |
| 1370 | rx_pool = &adapter->rx_pool[i]; |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1371 | if (!rx_pool || !rx_pool->rx_buff) |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1372 | continue; |
| 1373 | |
| 1374 | netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i); |
| 1375 | for (j = 0; j < rx_entries; j++) { |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1376 | rx_buff = &rx_pool->rx_buff[j]; |
| 1377 | if (rx_buff && rx_buff->skb) { |
| 1378 | dev_kfree_skb_any(rx_buff->skb); |
| 1379 | rx_buff->skb = NULL; |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1385 | static void clean_one_tx_pool(struct ibmvnic_adapter *adapter, |
| 1386 | struct ibmvnic_tx_pool *tx_pool) |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1387 | { |
Thomas Falcon | 637f81d | 2018-02-26 18:10:57 -0600 | [diff] [blame] | 1388 | struct ibmvnic_tx_buff *tx_buff; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1389 | u64 tx_entries; |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1390 | int i; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1391 | |
Dan Carpenter | 050e85c | 2018-03-23 14:36:15 +0300 | [diff] [blame] | 1392 | if (!tx_pool || !tx_pool->tx_buff) |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1393 | return; |
| 1394 | |
| 1395 | tx_entries = tx_pool->num_buffers; |
| 1396 | |
| 1397 | for (i = 0; i < tx_entries; i++) { |
| 1398 | tx_buff = &tx_pool->tx_buff[i]; |
| 1399 | if (tx_buff && tx_buff->skb) { |
| 1400 | dev_kfree_skb_any(tx_buff->skb); |
| 1401 | tx_buff->skb = NULL; |
| 1402 | } |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | static void clean_tx_pools(struct ibmvnic_adapter *adapter) |
| 1407 | { |
| 1408 | int tx_scrqs; |
| 1409 | int i; |
| 1410 | |
| 1411 | if (!adapter->tx_pool || !adapter->tso_pool) |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1412 | return; |
| 1413 | |
Thomas Falcon | 660e309 | 2018-04-20 14:25:32 -0500 | [diff] [blame] | 1414 | tx_scrqs = adapter->num_active_tx_pools; |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1415 | |
| 1416 | /* Free any remaining skbs in the tx buffer pools */ |
| 1417 | for (i = 0; i < tx_scrqs; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1418 | netdev_dbg(adapter->netdev, "Cleaning tx_pool[%d]\n", i); |
Thomas Falcon | e9e1e97 | 2018-03-16 20:00:30 -0500 | [diff] [blame] | 1419 | clean_one_tx_pool(adapter, &adapter->tx_pool[i]); |
| 1420 | clean_one_tx_pool(adapter, &adapter->tso_pool[i]); |
Nathan Fontenot | b41b83e | 2017-05-03 14:04:56 -0400 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1424 | static void ibmvnic_disable_irqs(struct ibmvnic_adapter *adapter) |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 1425 | { |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1426 | struct net_device *netdev = adapter->netdev; |
John Allen | ea5509f | 2017-03-17 17:13:43 -0500 | [diff] [blame] | 1427 | int i; |
| 1428 | |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1429 | if (adapter->tx_scrq) { |
| 1430 | for (i = 0; i < adapter->req_tx_queues; i++) |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1431 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | f873866 | 2018-03-07 17:51:45 -0600 | [diff] [blame] | 1432 | netdev_dbg(netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1433 | "Disabling tx_scrq[%d] irq\n", i); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1434 | disable_scrq_irq(adapter, adapter->tx_scrq[i]); |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1435 | disable_irq(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1436 | } |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1439 | if (adapter->rx_scrq) { |
| 1440 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1441 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | f873866 | 2018-03-07 17:51:45 -0600 | [diff] [blame] | 1442 | netdev_dbg(netdev, |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1443 | "Disabling rx_scrq[%d] irq\n", i); |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 1444 | disable_scrq_irq(adapter, adapter->rx_scrq[i]); |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1445 | disable_irq(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1446 | } |
Nathan Fontenot | 46293b9 | 2017-05-03 14:05:02 -0400 | [diff] [blame] | 1447 | } |
| 1448 | } |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | static void ibmvnic_cleanup(struct net_device *netdev) |
| 1452 | { |
| 1453 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1454 | |
| 1455 | /* ensure that transmissions are stopped if called by do_reset */ |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 1456 | if (test_bit(0, &adapter->resetting)) |
John Allen | 6095e59 | 2018-03-30 13:44:21 -0500 | [diff] [blame] | 1457 | netif_tx_disable(netdev); |
| 1458 | else |
| 1459 | netif_tx_stop_all_queues(netdev); |
| 1460 | |
| 1461 | ibmvnic_napi_disable(adapter); |
| 1462 | ibmvnic_disable_irqs(adapter); |
| 1463 | |
Thomas Falcon | d0869c0 | 2018-02-13 18:23:43 -0600 | [diff] [blame] | 1464 | clean_rx_pools(adapter); |
Thomas Falcon | 10f7621 | 2017-05-26 10:30:31 -0400 | [diff] [blame] | 1465 | clean_tx_pools(adapter); |
Thomas Falcon | 01d9bd7 | 2018-03-07 17:51:46 -0600 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | static int __ibmvnic_close(struct net_device *netdev) |
| 1469 | { |
| 1470 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1471 | int rc = 0; |
| 1472 | |
| 1473 | adapter->state = VNIC_CLOSING; |
| 1474 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 1475 | adapter->state = VNIC_CLOSED; |
Sukadev Bhattiprolu | d4083d3 | 2021-02-10 17:41:43 -0800 | [diff] [blame] | 1476 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1477 | } |
| 1478 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1479 | static int ibmvnic_close(struct net_device *netdev) |
| 1480 | { |
| 1481 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1482 | int rc; |
| 1483 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 1484 | netdev_dbg(netdev, "[S:%s FOP:%d FRR:%d] Closing\n", |
| 1485 | adapter_state_to_string(adapter->state), |
| 1486 | adapter->failover_pending, |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 1487 | adapter->force_reset_recovery); |
| 1488 | |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 1489 | /* If device failover is pending, just set device state and return. |
| 1490 | * Device operation will be handled by reset routine. |
| 1491 | */ |
| 1492 | if (adapter->failover_pending) { |
| 1493 | adapter->state = VNIC_CLOSED; |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1497 | rc = __ibmvnic_close(netdev); |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 1498 | ibmvnic_cleanup(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1499 | |
| 1500 | return rc; |
| 1501 | } |
| 1502 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1503 | /** |
| 1504 | * build_hdr_data - creates L2/L3/L4 header data buffer |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1505 | * @hdr_field: bitfield determining needed headers |
| 1506 | * @skb: socket buffer |
| 1507 | * @hdr_len: array of header lengths |
| 1508 | * @hdr_data: buffer to write the header to |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1509 | * |
| 1510 | * Reads hdr_field to determine which headers are needed by firmware. |
| 1511 | * Builds a buffer containing these headers. Saves individual header |
| 1512 | * lengths and total buffer length to be used to build descriptors. |
| 1513 | */ |
| 1514 | static int build_hdr_data(u8 hdr_field, struct sk_buff *skb, |
| 1515 | int *hdr_len, u8 *hdr_data) |
| 1516 | { |
| 1517 | int len = 0; |
| 1518 | u8 *hdr; |
| 1519 | |
Thomas Falcon | da75e3b | 2018-03-12 11:51:02 -0500 | [diff] [blame] | 1520 | if (skb_vlan_tagged(skb) && !skb_vlan_tag_present(skb)) |
| 1521 | hdr_len[0] = sizeof(struct vlan_ethhdr); |
| 1522 | else |
| 1523 | hdr_len[0] = sizeof(struct ethhdr); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1524 | |
| 1525 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1526 | hdr_len[1] = ip_hdr(skb)->ihl * 4; |
| 1527 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 1528 | hdr_len[2] = tcp_hdrlen(skb); |
| 1529 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
| 1530 | hdr_len[2] = sizeof(struct udphdr); |
| 1531 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 1532 | hdr_len[1] = sizeof(struct ipv6hdr); |
| 1533 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 1534 | hdr_len[2] = tcp_hdrlen(skb); |
| 1535 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP) |
| 1536 | hdr_len[2] = sizeof(struct udphdr); |
Thomas Falcon | 4eb50ce | 2017-12-18 12:52:40 -0600 | [diff] [blame] | 1537 | } else if (skb->protocol == htons(ETH_P_ARP)) { |
| 1538 | hdr_len[1] = arp_hdr_len(skb->dev); |
| 1539 | hdr_len[2] = 0; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | memset(hdr_data, 0, 120); |
| 1543 | if ((hdr_field >> 6) & 1) { |
| 1544 | hdr = skb_mac_header(skb); |
| 1545 | memcpy(hdr_data, hdr, hdr_len[0]); |
| 1546 | len += hdr_len[0]; |
| 1547 | } |
| 1548 | |
| 1549 | if ((hdr_field >> 5) & 1) { |
| 1550 | hdr = skb_network_header(skb); |
| 1551 | memcpy(hdr_data + len, hdr, hdr_len[1]); |
| 1552 | len += hdr_len[1]; |
| 1553 | } |
| 1554 | |
| 1555 | if ((hdr_field >> 4) & 1) { |
| 1556 | hdr = skb_transport_header(skb); |
| 1557 | memcpy(hdr_data + len, hdr, hdr_len[2]); |
| 1558 | len += hdr_len[2]; |
| 1559 | } |
| 1560 | return len; |
| 1561 | } |
| 1562 | |
| 1563 | /** |
| 1564 | * create_hdr_descs - create header and header extension descriptors |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1565 | * @hdr_field: bitfield determining needed headers |
| 1566 | * @hdr_data: buffer containing header data |
| 1567 | * @len: length of data buffer |
| 1568 | * @hdr_len: array of individual header lengths |
| 1569 | * @scrq_arr: descriptor array |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1570 | * |
| 1571 | * Creates header and, if needed, header extension descriptors and |
| 1572 | * places them in a descriptor array, scrq_arr |
| 1573 | */ |
| 1574 | |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1575 | static int create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len, |
| 1576 | union sub_crq *scrq_arr) |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1577 | { |
| 1578 | union sub_crq hdr_desc; |
| 1579 | int tmp_len = len; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1580 | int num_descs = 0; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1581 | u8 *data, *cur; |
| 1582 | int tmp; |
| 1583 | |
| 1584 | while (tmp_len > 0) { |
| 1585 | cur = hdr_data + len - tmp_len; |
| 1586 | |
| 1587 | memset(&hdr_desc, 0, sizeof(hdr_desc)); |
| 1588 | if (cur != hdr_data) { |
| 1589 | data = hdr_desc.hdr_ext.data; |
| 1590 | tmp = tmp_len > 29 ? 29 : tmp_len; |
| 1591 | hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD; |
| 1592 | hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC; |
| 1593 | hdr_desc.hdr_ext.len = tmp; |
| 1594 | } else { |
| 1595 | data = hdr_desc.hdr.data; |
| 1596 | tmp = tmp_len > 24 ? 24 : tmp_len; |
| 1597 | hdr_desc.hdr.first = IBMVNIC_CRQ_CMD; |
| 1598 | hdr_desc.hdr.type = IBMVNIC_HDR_DESC; |
| 1599 | hdr_desc.hdr.len = tmp; |
| 1600 | hdr_desc.hdr.l2_len = (u8)hdr_len[0]; |
| 1601 | hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]); |
| 1602 | hdr_desc.hdr.l4_len = (u8)hdr_len[2]; |
| 1603 | hdr_desc.hdr.flag = hdr_field << 1; |
| 1604 | } |
| 1605 | memcpy(data, cur, tmp); |
| 1606 | tmp_len -= tmp; |
| 1607 | *scrq_arr = hdr_desc; |
| 1608 | scrq_arr++; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1609 | num_descs++; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1610 | } |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1611 | |
| 1612 | return num_descs; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | /** |
| 1616 | * build_hdr_descs_arr - build a header descriptor array |
Lijun Pan | 73214a6 | 2021-06-11 10:43:39 -0500 | [diff] [blame] | 1617 | * @skb: tx socket buffer |
| 1618 | * @indir_arr: indirect array |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1619 | * @num_entries: number of descriptors to be sent |
| 1620 | * @hdr_field: bit field determining which headers will be sent |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1621 | * |
| 1622 | * This function will build a TX descriptor array with applicable |
| 1623 | * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect. |
| 1624 | */ |
| 1625 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1626 | static void build_hdr_descs_arr(struct sk_buff *skb, |
| 1627 | union sub_crq *indir_arr, |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1628 | int *num_entries, u8 hdr_field) |
| 1629 | { |
| 1630 | int hdr_len[3] = {0, 0, 0}; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1631 | u8 hdr_data[140] = {0}; |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1632 | int tot_len; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1633 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1634 | tot_len = build_hdr_data(hdr_field, skb, hdr_len, |
| 1635 | hdr_data); |
Thomas Falcon | 2de0968 | 2017-10-16 10:02:11 -0500 | [diff] [blame] | 1636 | *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] | 1637 | indir_arr + 1); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1638 | } |
| 1639 | |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1640 | static int ibmvnic_xmit_workarounds(struct sk_buff *skb, |
| 1641 | struct net_device *netdev) |
| 1642 | { |
| 1643 | /* For some backing devices, mishandling of small packets |
| 1644 | * can result in a loss of connection or TX stall. Device |
| 1645 | * architects recommend that no packet should be smaller |
| 1646 | * than the minimum MTU value provided to the driver, so |
| 1647 | * pad any packets to that length |
| 1648 | */ |
| 1649 | if (skb->len < netdev->min_mtu) |
| 1650 | return skb_put_padto(skb, netdev->min_mtu); |
Thomas Falcon | 7083a45 | 2018-03-12 21:05:26 -0500 | [diff] [blame] | 1651 | |
| 1652 | return 0; |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1653 | } |
| 1654 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1655 | static void ibmvnic_tx_scrq_clean_buffer(struct ibmvnic_adapter *adapter, |
| 1656 | struct ibmvnic_sub_crq_queue *tx_scrq) |
| 1657 | { |
| 1658 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 1659 | struct ibmvnic_tx_buff *tx_buff; |
| 1660 | struct ibmvnic_tx_pool *tx_pool; |
| 1661 | union sub_crq tx_scrq_entry; |
| 1662 | int queue_num; |
| 1663 | int entries; |
| 1664 | int index; |
| 1665 | int i; |
| 1666 | |
| 1667 | ind_bufp = &tx_scrq->ind_buf; |
| 1668 | entries = (u64)ind_bufp->index; |
| 1669 | queue_num = tx_scrq->pool_index; |
| 1670 | |
| 1671 | for (i = entries - 1; i >= 0; --i) { |
| 1672 | tx_scrq_entry = ind_bufp->indir_arr[i]; |
| 1673 | if (tx_scrq_entry.v1.type != IBMVNIC_TX_DESC) |
| 1674 | continue; |
| 1675 | index = be32_to_cpu(tx_scrq_entry.v1.correlator); |
| 1676 | if (index & IBMVNIC_TSO_POOL_MASK) { |
| 1677 | tx_pool = &adapter->tso_pool[queue_num]; |
| 1678 | index &= ~IBMVNIC_TSO_POOL_MASK; |
| 1679 | } else { |
| 1680 | tx_pool = &adapter->tx_pool[queue_num]; |
| 1681 | } |
| 1682 | tx_pool->free_map[tx_pool->consumer_index] = index; |
| 1683 | tx_pool->consumer_index = tx_pool->consumer_index == 0 ? |
| 1684 | tx_pool->num_buffers - 1 : |
| 1685 | tx_pool->consumer_index - 1; |
| 1686 | tx_buff = &tx_pool->tx_buff[index]; |
| 1687 | adapter->netdev->stats.tx_packets--; |
| 1688 | adapter->netdev->stats.tx_bytes -= tx_buff->skb->len; |
| 1689 | adapter->tx_stats_buffers[queue_num].packets--; |
| 1690 | adapter->tx_stats_buffers[queue_num].bytes -= |
| 1691 | tx_buff->skb->len; |
| 1692 | dev_kfree_skb_any(tx_buff->skb); |
| 1693 | tx_buff->skb = NULL; |
| 1694 | adapter->netdev->stats.tx_dropped++; |
| 1695 | } |
| 1696 | ind_bufp->index = 0; |
| 1697 | if (atomic_sub_return(entries, &tx_scrq->used) <= |
| 1698 | (adapter->req_tx_entries_per_subcrq / 2) && |
Sukadev Bhattiprolu | 65d6470 | 2021-06-23 21:13:12 -0700 | [diff] [blame] | 1699 | __netif_subqueue_stopped(adapter->netdev, queue_num) && |
| 1700 | !test_bit(0, &adapter->resetting)) { |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1701 | netif_wake_subqueue(adapter->netdev, queue_num); |
| 1702 | netdev_dbg(adapter->netdev, "Started queue %d\n", |
| 1703 | queue_num); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | static int ibmvnic_tx_scrq_flush(struct ibmvnic_adapter *adapter, |
| 1708 | struct ibmvnic_sub_crq_queue *tx_scrq) |
| 1709 | { |
| 1710 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
| 1711 | u64 dma_addr; |
| 1712 | u64 entries; |
| 1713 | u64 handle; |
| 1714 | int rc; |
| 1715 | |
| 1716 | ind_bufp = &tx_scrq->ind_buf; |
| 1717 | dma_addr = (u64)ind_bufp->indir_dma; |
| 1718 | entries = (u64)ind_bufp->index; |
| 1719 | handle = tx_scrq->handle; |
| 1720 | |
| 1721 | if (!entries) |
| 1722 | return 0; |
| 1723 | rc = send_subcrq_indirect(adapter, handle, dma_addr, entries); |
| 1724 | if (rc) |
| 1725 | ibmvnic_tx_scrq_clean_buffer(adapter, tx_scrq); |
| 1726 | else |
| 1727 | ind_bufp->index = 0; |
| 1728 | return 0; |
| 1729 | } |
| 1730 | |
YueHaibing | 94b2bb2 | 2018-09-18 14:35:47 +0800 | [diff] [blame] | 1731 | 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] | 1732 | { |
| 1733 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1734 | int queue_num = skb_get_queue_mapping(skb); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1735 | u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1736 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1737 | struct ibmvnic_ind_xmit_queue *ind_bufp; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1738 | struct ibmvnic_tx_buff *tx_buff = NULL; |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1739 | struct ibmvnic_sub_crq_queue *tx_scrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1740 | struct ibmvnic_tx_pool *tx_pool; |
| 1741 | unsigned int tx_send_failed = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1742 | netdev_tx_t ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1743 | unsigned int tx_map_failed = 0; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1744 | union sub_crq indir_arr[16]; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1745 | unsigned int tx_dropped = 0; |
| 1746 | unsigned int tx_packets = 0; |
| 1747 | unsigned int tx_bytes = 0; |
| 1748 | dma_addr_t data_dma_addr; |
| 1749 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1750 | unsigned long lpar_rc; |
| 1751 | union sub_crq tx_crq; |
| 1752 | unsigned int offset; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1753 | int num_entries = 1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1754 | unsigned char *dst; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1755 | int index = 0; |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 1756 | u8 proto = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1757 | |
| 1758 | tx_scrq = adapter->tx_scrq[queue_num]; |
| 1759 | txq = netdev_get_tx_queue(netdev, queue_num); |
| 1760 | ind_bufp = &tx_scrq->ind_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1761 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 1762 | if (test_bit(0, &adapter->resetting)) { |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1763 | if (!netif_subqueue_stopped(netdev, skb)) |
| 1764 | netif_stop_subqueue(netdev, queue_num); |
| 1765 | dev_kfree_skb_any(skb); |
| 1766 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1767 | tx_send_failed++; |
| 1768 | tx_dropped++; |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1769 | ret = NETDEV_TX_OK; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1770 | goto out; |
| 1771 | } |
| 1772 | |
Thomas Falcon | 7083a45 | 2018-03-12 21:05:26 -0500 | [diff] [blame] | 1773 | if (ibmvnic_xmit_workarounds(skb, netdev)) { |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1774 | tx_dropped++; |
| 1775 | tx_send_failed++; |
| 1776 | ret = NETDEV_TX_OK; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1777 | ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1778 | goto out; |
| 1779 | } |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1780 | if (skb_is_gso(skb)) |
| 1781 | tx_pool = &adapter->tso_pool[queue_num]; |
| 1782 | else |
| 1783 | tx_pool = &adapter->tx_pool[queue_num]; |
Thomas Falcon | 1f247a6 | 2018-03-12 11:51:04 -0500 | [diff] [blame] | 1784 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1785 | index = tx_pool->free_map[tx_pool->consumer_index]; |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1786 | |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 1787 | if (index == IBMVNIC_INVALID_MAP) { |
| 1788 | dev_kfree_skb_any(skb); |
| 1789 | tx_send_failed++; |
| 1790 | tx_dropped++; |
Sukadev Bhattiprolu | bb55362 | 2021-07-20 19:34:39 -0700 | [diff] [blame] | 1791 | ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 1792 | ret = NETDEV_TX_OK; |
| 1793 | goto out; |
| 1794 | } |
| 1795 | |
| 1796 | tx_pool->free_map[tx_pool->consumer_index] = IBMVNIC_INVALID_MAP; |
| 1797 | |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1798 | offset = index * tx_pool->buf_size; |
| 1799 | dst = tx_pool->long_term_buff.buff + offset; |
| 1800 | memset(dst, 0, tx_pool->buf_size); |
| 1801 | data_dma_addr = tx_pool->long_term_buff.addr + offset; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1802 | |
Thomas Falcon | 1548205 | 2017-10-17 12:36:54 -0500 | [diff] [blame] | 1803 | if (skb_shinfo(skb)->nr_frags) { |
| 1804 | int cur, i; |
| 1805 | |
| 1806 | /* Copy the head */ |
| 1807 | skb_copy_from_linear_data(skb, dst, skb_headlen(skb)); |
| 1808 | cur = skb_headlen(skb); |
| 1809 | |
| 1810 | /* Copy the frags */ |
| 1811 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1812 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1813 | |
Christophe JAILLET | c3105f8 | 2021-04-04 10:54:37 +0200 | [diff] [blame] | 1814 | memcpy(dst + cur, skb_frag_address(frag), |
| 1815 | skb_frag_size(frag)); |
Thomas Falcon | 1548205 | 2017-10-17 12:36:54 -0500 | [diff] [blame] | 1816 | cur += skb_frag_size(frag); |
| 1817 | } |
| 1818 | } else { |
| 1819 | skb_copy_from_linear_data(skb, dst, skb->len); |
| 1820 | } |
| 1821 | |
Lijun Pan | 42557da | 2021-02-12 20:48:40 -0600 | [diff] [blame] | 1822 | /* post changes to long_term_buff *dst before VIOS accessing it */ |
| 1823 | dma_wmb(); |
| 1824 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1825 | tx_pool->consumer_index = |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1826 | (tx_pool->consumer_index + 1) % tx_pool->num_buffers; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1827 | |
| 1828 | tx_buff = &tx_pool->tx_buff[index]; |
| 1829 | tx_buff->skb = skb; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1830 | tx_buff->index = index; |
| 1831 | tx_buff->pool_index = queue_num; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1832 | |
| 1833 | memset(&tx_crq, 0, sizeof(tx_crq)); |
| 1834 | tx_crq.v1.first = IBMVNIC_CRQ_CMD; |
| 1835 | tx_crq.v1.type = IBMVNIC_TX_DESC; |
| 1836 | tx_crq.v1.n_crq_elem = 1; |
| 1837 | tx_crq.v1.n_sge = 1; |
| 1838 | tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED; |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1839 | |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1840 | if (skb_is_gso(skb)) |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1841 | tx_crq.v1.correlator = |
| 1842 | cpu_to_be32(index | IBMVNIC_TSO_POOL_MASK); |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1843 | else |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 1844 | tx_crq.v1.correlator = cpu_to_be32(index); |
| 1845 | 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] | 1846 | tx_crq.v1.sge_len = cpu_to_be32(skb->len); |
| 1847 | tx_crq.v1.ioba = cpu_to_be64(data_dma_addr); |
| 1848 | |
Michał Mirosław | e84b479 | 2018-11-07 17:50:52 +0100 | [diff] [blame] | 1849 | if (adapter->vlan_header_insertion && skb_vlan_tag_present(skb)) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1850 | tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT; |
| 1851 | tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci); |
| 1852 | } |
| 1853 | |
| 1854 | if (skb->protocol == htons(ETH_P_IP)) { |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 1855 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4; |
| 1856 | proto = ip_hdr(skb)->protocol; |
| 1857 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
| 1858 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6; |
| 1859 | proto = ipv6_hdr(skb)->nexthdr; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1860 | } |
| 1861 | |
Thomas Falcon | a0dca10 | 2018-01-18 19:29:48 -0600 | [diff] [blame] | 1862 | if (proto == IPPROTO_TCP) |
| 1863 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP; |
| 1864 | else if (proto == IPPROTO_UDP) |
| 1865 | tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP; |
| 1866 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1867 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1868 | tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1869 | hdrs += 2; |
| 1870 | } |
Thomas Falcon | fdb0610 | 2017-10-17 12:36:55 -0500 | [diff] [blame] | 1871 | if (skb_is_gso(skb)) { |
| 1872 | tx_crq.v1.flags1 |= IBMVNIC_TX_LSO; |
| 1873 | tx_crq.v1.mss = cpu_to_be16(skb_shinfo(skb)->gso_size); |
| 1874 | hdrs += 2; |
| 1875 | } |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1876 | |
| 1877 | if ((*hdrs >> 7) & 1) |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1878 | build_hdr_descs_arr(skb, indir_arr, &num_entries, *hdrs); |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1879 | |
| 1880 | tx_crq.v1.n_crq_elem = num_entries; |
| 1881 | tx_buff->num_entries = num_entries; |
| 1882 | /* flush buffer if current entry can not fit */ |
| 1883 | if (num_entries + ind_bufp->index > IBMVNIC_MAX_IND_DESCS) { |
| 1884 | lpar_rc = ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
| 1885 | if (lpar_rc != H_SUCCESS) |
| 1886 | goto tx_flush_err; |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 1887 | } |
Thomas Falcon | 7f5b030 | 2017-04-21 15:39:16 -0400 | [diff] [blame] | 1888 | |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 1889 | indir_arr[0] = tx_crq; |
| 1890 | memcpy(&ind_bufp->indir_arr[ind_bufp->index], &indir_arr[0], |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1891 | num_entries * sizeof(struct ibmvnic_generic_scrq)); |
| 1892 | ind_bufp->index += num_entries; |
| 1893 | if (__netdev_tx_sent_queue(txq, skb->len, |
| 1894 | netdev_xmit_more() && |
| 1895 | ind_bufp->index < IBMVNIC_MAX_IND_DESCS)) { |
| 1896 | lpar_rc = ibmvnic_tx_scrq_flush(adapter, tx_scrq); |
| 1897 | if (lpar_rc != H_SUCCESS) |
| 1898 | goto tx_err; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1899 | } |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1900 | |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 1901 | if (atomic_add_return(num_entries, &tx_scrq->used) |
Brian King | 58c8c0c | 2017-04-19 13:44:47 -0400 | [diff] [blame] | 1902 | >= adapter->req_tx_entries_per_subcrq) { |
Thomas Falcon | 0aecb13 | 2018-02-26 18:10:58 -0600 | [diff] [blame] | 1903 | netdev_dbg(netdev, "Stopping queue %d\n", queue_num); |
Thomas Falcon | 142c0ac | 2017-03-05 12:18:41 -0600 | [diff] [blame] | 1904 | netif_stop_subqueue(netdev, queue_num); |
| 1905 | } |
| 1906 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1907 | tx_packets++; |
| 1908 | tx_bytes += skb->len; |
| 1909 | txq->trans_start = jiffies; |
| 1910 | ret = NETDEV_TX_OK; |
Thomas Falcon | 86b61a5 | 2018-03-16 20:00:29 -0500 | [diff] [blame] | 1911 | goto out; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1912 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 1913 | tx_flush_err: |
| 1914 | dev_kfree_skb_any(skb); |
| 1915 | tx_buff->skb = NULL; |
| 1916 | tx_pool->consumer_index = tx_pool->consumer_index == 0 ? |
| 1917 | tx_pool->num_buffers - 1 : |
| 1918 | tx_pool->consumer_index - 1; |
| 1919 | tx_dropped++; |
| 1920 | tx_err: |
| 1921 | if (lpar_rc != H_CLOSED && lpar_rc != H_PARAMETER) |
| 1922 | dev_err_ratelimited(dev, "tx: send failed\n"); |
| 1923 | |
| 1924 | if (lpar_rc == H_CLOSED || adapter->failover_pending) { |
| 1925 | /* Disable TX and report carrier off if queue is closed |
| 1926 | * or pending failover. |
| 1927 | * Firmware guarantees that a signal will be sent to the |
| 1928 | * driver, triggering a reset or some other action. |
| 1929 | */ |
| 1930 | netif_tx_stop_all_queues(netdev); |
| 1931 | netif_carrier_off(netdev); |
| 1932 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1933 | out: |
| 1934 | netdev->stats.tx_dropped += tx_dropped; |
| 1935 | netdev->stats.tx_bytes += tx_bytes; |
| 1936 | netdev->stats.tx_packets += tx_packets; |
| 1937 | adapter->tx_send_failed += tx_send_failed; |
| 1938 | adapter->tx_map_failed += tx_map_failed; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 1939 | adapter->tx_stats_buffers[queue_num].packets += tx_packets; |
| 1940 | adapter->tx_stats_buffers[queue_num].bytes += tx_bytes; |
| 1941 | adapter->tx_stats_buffers[queue_num].dropped_packets += tx_dropped; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1942 | |
| 1943 | return ret; |
| 1944 | } |
| 1945 | |
| 1946 | static void ibmvnic_set_multi(struct net_device *netdev) |
| 1947 | { |
| 1948 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 1949 | struct netdev_hw_addr *ha; |
| 1950 | union ibmvnic_crq crq; |
| 1951 | |
| 1952 | memset(&crq, 0, sizeof(crq)); |
| 1953 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 1954 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 1955 | |
| 1956 | if (netdev->flags & IFF_PROMISC) { |
| 1957 | if (!adapter->promisc_supported) |
| 1958 | return; |
| 1959 | } else { |
| 1960 | if (netdev->flags & IFF_ALLMULTI) { |
| 1961 | /* Accept all multicast */ |
| 1962 | memset(&crq, 0, sizeof(crq)); |
| 1963 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1964 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1965 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL; |
| 1966 | ibmvnic_send_crq(adapter, &crq); |
| 1967 | } else if (netdev_mc_empty(netdev)) { |
| 1968 | /* Reject all multicast */ |
| 1969 | memset(&crq, 0, sizeof(crq)); |
| 1970 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1971 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1972 | crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL; |
| 1973 | ibmvnic_send_crq(adapter, &crq); |
| 1974 | } else { |
| 1975 | /* Accept one or more multicast(s) */ |
| 1976 | netdev_for_each_mc_addr(ha, netdev) { |
| 1977 | memset(&crq, 0, sizeof(crq)); |
| 1978 | crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD; |
| 1979 | crq.multicast_ctrl.cmd = MULTICAST_CTRL; |
| 1980 | crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC; |
| 1981 | ether_addr_copy(&crq.multicast_ctrl.mac_addr[0], |
| 1982 | ha->addr); |
| 1983 | ibmvnic_send_crq(adapter, &crq); |
| 1984 | } |
| 1985 | } |
| 1986 | } |
| 1987 | } |
| 1988 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 1989 | static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1990 | { |
| 1991 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1992 | union ibmvnic_crq crq; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 1993 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1994 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 1995 | if (!is_valid_ether_addr(dev_addr)) { |
| 1996 | rc = -EADDRNOTAVAIL; |
| 1997 | goto err; |
| 1998 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 1999 | |
| 2000 | memset(&crq, 0, sizeof(crq)); |
| 2001 | crq.change_mac_addr.first = IBMVNIC_CRQ_CMD; |
| 2002 | crq.change_mac_addr.cmd = CHANGE_MAC_ADDR; |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2003 | ether_addr_copy(&crq.change_mac_addr.mac_addr[0], dev_addr); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2004 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2005 | mutex_lock(&adapter->fw_lock); |
| 2006 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2007 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2008 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 2009 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2010 | if (rc) { |
| 2011 | rc = -EIO; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2012 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2013 | goto err; |
| 2014 | } |
| 2015 | |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2016 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2017 | /* netdev->dev_addr is changed in handle_change_mac_rsp function */ |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2018 | if (rc || adapter->fw_done_rc) { |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2019 | rc = -EIO; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2020 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2021 | goto err; |
| 2022 | } |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 2023 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2024 | return 0; |
| 2025 | err: |
| 2026 | ether_addr_copy(adapter->mac_addr, netdev->dev_addr); |
| 2027 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2028 | } |
| 2029 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2030 | static int ibmvnic_set_mac(struct net_device *netdev, void *p) |
| 2031 | { |
| 2032 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2033 | struct sockaddr *addr = p; |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2034 | int rc; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2035 | |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2036 | rc = 0; |
Lijun Pan | 8fc3672 | 2020-10-27 17:04:56 -0500 | [diff] [blame] | 2037 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2038 | return -EADDRNOTAVAIL; |
| 2039 | |
Jiri Wiesner | 67eb211 | 2021-03-04 17:18:28 +0100 | [diff] [blame] | 2040 | ether_addr_copy(adapter->mac_addr, addr->sa_data); |
| 2041 | if (adapter->state != VNIC_PROBED) |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 2042 | rc = __ibmvnic_set_mac(netdev, addr->sa_data); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2043 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 2044 | return rc; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2045 | } |
| 2046 | |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2047 | static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason) |
| 2048 | { |
| 2049 | switch (reason) { |
| 2050 | case VNIC_RESET_FAILOVER: |
| 2051 | return "FAILOVER"; |
| 2052 | case VNIC_RESET_MOBILITY: |
| 2053 | return "MOBILITY"; |
| 2054 | case VNIC_RESET_FATAL: |
| 2055 | return "FATAL"; |
| 2056 | case VNIC_RESET_NON_FATAL: |
| 2057 | return "NON_FATAL"; |
| 2058 | case VNIC_RESET_TIMEOUT: |
| 2059 | return "TIMEOUT"; |
| 2060 | case VNIC_RESET_CHANGE_PARAM: |
| 2061 | return "CHANGE_PARAM"; |
Lijun Pan | 822ebc2 | 2021-06-11 10:35:37 -0500 | [diff] [blame] | 2062 | case VNIC_RESET_PASSIVE_INIT: |
| 2063 | return "PASSIVE_INIT"; |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2064 | } |
Michal Suchanek | 07b5dc1 | 2021-05-20 08:50:34 +0200 | [diff] [blame] | 2065 | return "UNKNOWN"; |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2066 | } |
| 2067 | |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 2068 | /* |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2069 | * do_reset returns zero if we are able to keep processing reset events, or |
| 2070 | * non-zero if we hit a fatal error and must halt. |
| 2071 | */ |
| 2072 | static int do_reset(struct ibmvnic_adapter *adapter, |
| 2073 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 2074 | { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2075 | u64 old_num_rx_queues, old_num_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 2076 | u64 old_num_rx_slots, old_num_tx_slots; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2077 | struct net_device *netdev = adapter->netdev; |
Lijun Pan | d3a6abc | 2021-04-14 02:46:15 -0500 | [diff] [blame] | 2078 | int rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2079 | |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2080 | netdev_dbg(adapter->netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2081 | "[S:%s FOP:%d] Reset reason: %s, reset_state: %s\n", |
| 2082 | adapter_state_to_string(adapter->state), |
| 2083 | adapter->failover_pending, |
| 2084 | reset_reason_to_string(rwi->reset_reason), |
| 2085 | adapter_state_to_string(reset_state)); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 2086 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2087 | adapter->reset_reason = rwi->reset_reason; |
| 2088 | /* requestor of VNIC_RESET_CHANGE_PARAM already has the rtnl lock */ |
| 2089 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 2090 | rtnl_lock(); |
| 2091 | |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 2092 | /* Now that we have the rtnl lock, clear any pending failover. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2093 | * This will ensure ibmvnic_open() has either completed or will |
| 2094 | * block until failover is complete. |
| 2095 | */ |
| 2096 | if (rwi->reset_reason == VNIC_RESET_FAILOVER) |
| 2097 | adapter->failover_pending = false; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2098 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2099 | /* read the state and check (again) after getting rtnl */ |
| 2100 | reset_state = adapter->state; |
| 2101 | |
| 2102 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 2103 | rc = -EBUSY; |
| 2104 | goto out; |
| 2105 | } |
| 2106 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2107 | netif_carrier_off(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2108 | |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2109 | old_num_rx_queues = adapter->req_rx_queues; |
| 2110 | old_num_tx_queues = adapter->req_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 2111 | old_num_rx_slots = adapter->req_rx_add_entries_per_subcrq; |
| 2112 | old_num_tx_slots = adapter->req_tx_entries_per_subcrq; |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2113 | |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2114 | ibmvnic_cleanup(netdev); |
| 2115 | |
Thomas Falcon | 1f94608 | 2019-06-07 16:03:53 -0500 | [diff] [blame] | 2116 | if (reset_state == VNIC_OPEN && |
| 2117 | adapter->reset_reason != VNIC_RESET_MOBILITY && |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2118 | adapter->reset_reason != VNIC_RESET_FAILOVER) { |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2119 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2120 | rc = __ibmvnic_close(netdev); |
| 2121 | if (rc) |
| 2122 | goto out; |
| 2123 | } else { |
| 2124 | adapter->state = VNIC_CLOSING; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2125 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2126 | /* Release the RTNL lock before link state change and |
| 2127 | * re-acquire after the link state change to allow |
| 2128 | * linkwatch_event to grab the RTNL lock and run during |
| 2129 | * a reset. |
| 2130 | */ |
| 2131 | rtnl_unlock(); |
| 2132 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
| 2133 | rtnl_lock(); |
| 2134 | if (rc) |
| 2135 | goto out; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2136 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2137 | if (adapter->state == VNIC_OPEN) { |
| 2138 | /* When we dropped rtnl, ibmvnic_open() got |
| 2139 | * it and noticed that we are resetting and |
| 2140 | * set the adapter state to OPEN. Update our |
| 2141 | * new "target" state, and resume the reset |
| 2142 | * from VNIC_CLOSING state. |
| 2143 | */ |
| 2144 | netdev_dbg(netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2145 | "Open changed state from %s, updating.\n", |
| 2146 | adapter_state_to_string(reset_state)); |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2147 | reset_state = VNIC_OPEN; |
| 2148 | adapter->state = VNIC_CLOSING; |
| 2149 | } |
| 2150 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2151 | if (adapter->state != VNIC_CLOSING) { |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2152 | /* If someone else changed the adapter state |
| 2153 | * when we dropped the rtnl, fail the reset |
| 2154 | */ |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2155 | rc = -1; |
| 2156 | goto out; |
| 2157 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2158 | adapter->state = VNIC_CLOSED; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2159 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2160 | } |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2161 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2162 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2163 | release_resources(adapter); |
| 2164 | release_sub_crqs(adapter, 1); |
| 2165 | release_crq_queue(adapter); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2168 | if (adapter->reset_reason != VNIC_RESET_NON_FATAL) { |
| 2169 | /* remove the closed state so when we call open it appears |
| 2170 | * we are coming from the probed state. |
| 2171 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2172 | adapter->state = VNIC_PROBED; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2173 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2174 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2175 | rc = init_crq_queue(adapter); |
| 2176 | } else if (adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2177 | rc = ibmvnic_reenable_crq_queue(adapter); |
| 2178 | release_sub_crqs(adapter, 1); |
| 2179 | } else { |
| 2180 | rc = ibmvnic_reset_crq(adapter); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2181 | if (rc == H_CLOSED || rc == H_SUCCESS) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2182 | rc = vio_enable_interrupts(adapter->vdev); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2183 | if (rc) |
| 2184 | netdev_err(adapter->netdev, |
| 2185 | "Reset failed to enable interrupts. rc=%d\n", |
| 2186 | rc); |
| 2187 | } |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | if (rc) { |
| 2191 | netdev_err(adapter->netdev, |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2192 | "Reset couldn't initialize crq. rc=%d\n", rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2193 | goto out; |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2194 | } |
| 2195 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2196 | rc = ibmvnic_reset_init(adapter, true); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2197 | if (rc) { |
| 2198 | rc = IBMVNIC_INIT_FAILED; |
| 2199 | goto out; |
| 2200 | } |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2201 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2202 | /* 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] | 2203 | * exit here. |
| 2204 | */ |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2205 | if (reset_state == VNIC_PROBED || reset_state == VNIC_DOWN) { |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2206 | rc = 0; |
| 2207 | goto out; |
| 2208 | } |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2209 | |
| 2210 | rc = ibmvnic_login(netdev); |
Lijun Pan | f78afaa | 2021-02-11 00:43:20 -0600 | [diff] [blame] | 2211 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2212 | goto out; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2213 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2214 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2215 | rc = init_resources(adapter); |
| 2216 | if (rc) |
| 2217 | goto out; |
| 2218 | } else if (adapter->req_rx_queues != old_num_rx_queues || |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2219 | adapter->req_tx_queues != old_num_tx_queues || |
| 2220 | adapter->req_rx_add_entries_per_subcrq != |
| 2221 | old_num_rx_slots || |
| 2222 | adapter->req_tx_entries_per_subcrq != |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2223 | old_num_tx_slots || |
| 2224 | !adapter->rx_pool || |
| 2225 | !adapter->tso_pool || |
| 2226 | !adapter->tx_pool) { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2227 | release_rx_pools(adapter); |
| 2228 | release_tx_pools(adapter); |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2229 | release_napi(adapter); |
| 2230 | release_vpd_data(adapter); |
| 2231 | |
| 2232 | rc = init_resources(adapter); |
Thomas Falcon | f611a5b | 2018-08-30 13:19:53 -0500 | [diff] [blame] | 2233 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2234 | goto out; |
Nathan Fontenot | d9043c1 | 2018-02-19 13:30:14 -0600 | [diff] [blame] | 2235 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2236 | } else { |
| 2237 | rc = reset_tx_pools(adapter); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2238 | if (rc) { |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2239 | netdev_dbg(adapter->netdev, "reset tx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2240 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2241 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2242 | } |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 2243 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2244 | rc = reset_rx_pools(adapter); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2245 | if (rc) { |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2246 | netdev_dbg(adapter->netdev, "reset rx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2247 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2248 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2249 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2250 | } |
Thomas Falcon | 134bbe7 | 2018-05-16 15:49:04 -0500 | [diff] [blame] | 2251 | ibmvnic_disable_irqs(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2252 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2253 | adapter->state = VNIC_CLOSED; |
| 2254 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2255 | if (reset_state == VNIC_CLOSED) { |
| 2256 | rc = 0; |
| 2257 | goto out; |
| 2258 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2259 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2260 | rc = __ibmvnic_open(netdev); |
| 2261 | if (rc) { |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2262 | rc = IBMVNIC_OPEN_FAILED; |
| 2263 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2264 | } |
| 2265 | |
Thomas Falcon | be32a24 | 2019-06-07 16:03:54 -0500 | [diff] [blame] | 2266 | /* refresh device's multicast list */ |
| 2267 | ibmvnic_set_multi(netdev); |
| 2268 | |
Lijun Pan | 98025bc | 2020-11-20 16:40:12 -0600 | [diff] [blame] | 2269 | if (adapter->reset_reason == VNIC_RESET_FAILOVER || |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2270 | adapter->reset_reason == VNIC_RESET_MOBILITY) |
| 2271 | __netdev_notify_peers(netdev); |
Nathan Fontenot | 61d3e1d | 2017-06-12 20:47:45 -0400 | [diff] [blame] | 2272 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2273 | rc = 0; |
| 2274 | |
| 2275 | out: |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2276 | /* restore the adapter state if reset failed */ |
| 2277 | if (rc) |
| 2278 | adapter->state = reset_state; |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2279 | /* requestor of VNIC_RESET_CHANGE_PARAM should still hold the rtnl lock */ |
| 2280 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 2281 | rtnl_unlock(); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2282 | |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2283 | netdev_dbg(adapter->netdev, "[S:%s FOP:%d] Reset done, rc %d\n", |
| 2284 | adapter_state_to_string(adapter->state), |
| 2285 | adapter->failover_pending, rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2286 | return rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2287 | } |
| 2288 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2289 | static int do_hard_reset(struct ibmvnic_adapter *adapter, |
| 2290 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 2291 | { |
| 2292 | struct net_device *netdev = adapter->netdev; |
| 2293 | int rc; |
| 2294 | |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2295 | netdev_dbg(adapter->netdev, "Hard resetting driver (%s)\n", |
| 2296 | reset_reason_to_string(rwi->reset_reason)); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2297 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2298 | /* read the state and check (again) after getting rtnl */ |
| 2299 | reset_state = adapter->state; |
| 2300 | |
| 2301 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 2302 | rc = -EBUSY; |
| 2303 | goto out; |
| 2304 | } |
| 2305 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2306 | netif_carrier_off(netdev); |
| 2307 | adapter->reset_reason = rwi->reset_reason; |
| 2308 | |
| 2309 | ibmvnic_cleanup(netdev); |
| 2310 | release_resources(adapter); |
| 2311 | release_sub_crqs(adapter, 0); |
| 2312 | release_crq_queue(adapter); |
| 2313 | |
| 2314 | /* remove the closed state so when we call open it appears |
| 2315 | * we are coming from the probed state. |
| 2316 | */ |
| 2317 | adapter->state = VNIC_PROBED; |
| 2318 | |
Thomas Falcon | bbd669a | 2019-04-04 18:58:26 -0500 | [diff] [blame] | 2319 | reinit_completion(&adapter->init_done); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2320 | rc = init_crq_queue(adapter); |
| 2321 | if (rc) { |
| 2322 | netdev_err(adapter->netdev, |
| 2323 | "Couldn't initialize crq. rc=%d\n", rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2324 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2325 | } |
| 2326 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2327 | rc = ibmvnic_reset_init(adapter, false); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2328 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2329 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2330 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2331 | /* 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] | 2332 | * exit here. |
| 2333 | */ |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2334 | if (reset_state == VNIC_PROBED || reset_state == VNIC_DOWN) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2335 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2336 | |
| 2337 | rc = ibmvnic_login(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2338 | if (rc) |
| 2339 | goto out; |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2340 | |
| 2341 | rc = init_resources(adapter); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2342 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2343 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2344 | |
| 2345 | ibmvnic_disable_irqs(adapter); |
| 2346 | adapter->state = VNIC_CLOSED; |
| 2347 | |
| 2348 | if (reset_state == VNIC_CLOSED) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2349 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2350 | |
| 2351 | rc = __ibmvnic_open(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2352 | if (rc) { |
| 2353 | rc = IBMVNIC_OPEN_FAILED; |
| 2354 | goto out; |
| 2355 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2356 | |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2357 | __netdev_notify_peers(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2358 | out: |
| 2359 | /* restore adapter state if reset failed */ |
| 2360 | if (rc) |
| 2361 | adapter->state = reset_state; |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2362 | netdev_dbg(adapter->netdev, "[S:%s FOP:%d] Hard reset done, rc %d\n", |
| 2363 | adapter_state_to_string(adapter->state), |
| 2364 | adapter->failover_pending, rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2365 | return rc; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2366 | } |
| 2367 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2368 | static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter) |
| 2369 | { |
| 2370 | struct ibmvnic_rwi *rwi; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2371 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2372 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2373 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2374 | |
| 2375 | if (!list_empty(&adapter->rwi_list)) { |
| 2376 | rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi, |
| 2377 | list); |
| 2378 | list_del(&rwi->list); |
| 2379 | } else { |
| 2380 | rwi = NULL; |
| 2381 | } |
| 2382 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2383 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2384 | return rwi; |
| 2385 | } |
| 2386 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2387 | /** |
| 2388 | * do_passive_init - complete probing when partner device is detected. |
| 2389 | * @adapter: ibmvnic_adapter struct |
| 2390 | * |
| 2391 | * If the ibmvnic device does not have a partner device to communicate with at boot |
| 2392 | * and that partner device comes online at a later time, this function is called |
| 2393 | * to complete the initialization process of ibmvnic device. |
| 2394 | * Caller is expected to hold rtnl_lock(). |
| 2395 | * |
| 2396 | * Returns non-zero if sub-CRQs are not initialized properly leaving the device |
| 2397 | * in the down state. |
| 2398 | * Returns 0 upon success and the device is in PROBED state. |
| 2399 | */ |
| 2400 | |
| 2401 | static int do_passive_init(struct ibmvnic_adapter *adapter) |
| 2402 | { |
| 2403 | unsigned long timeout = msecs_to_jiffies(30000); |
| 2404 | struct net_device *netdev = adapter->netdev; |
| 2405 | struct device *dev = &adapter->vdev->dev; |
| 2406 | int rc; |
| 2407 | |
| 2408 | netdev_dbg(netdev, "Partner device found, probing.\n"); |
| 2409 | |
| 2410 | adapter->state = VNIC_PROBING; |
| 2411 | reinit_completion(&adapter->init_done); |
| 2412 | adapter->init_done_rc = 0; |
| 2413 | adapter->crq.active = true; |
| 2414 | |
| 2415 | rc = send_crq_init_complete(adapter); |
| 2416 | if (rc) |
| 2417 | goto out; |
| 2418 | |
| 2419 | rc = send_version_xchg(adapter); |
| 2420 | if (rc) |
| 2421 | netdev_dbg(adapter->netdev, "send_version_xchg failed, rc=%d\n", rc); |
| 2422 | |
| 2423 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 2424 | dev_err(dev, "Initialization sequence timed out\n"); |
| 2425 | rc = -ETIMEDOUT; |
| 2426 | goto out; |
| 2427 | } |
| 2428 | |
| 2429 | rc = init_sub_crqs(adapter); |
| 2430 | if (rc) { |
| 2431 | dev_err(dev, "Initialization of sub crqs failed, rc=%d\n", rc); |
| 2432 | goto out; |
| 2433 | } |
| 2434 | |
| 2435 | rc = init_sub_crq_irqs(adapter); |
| 2436 | if (rc) { |
| 2437 | dev_err(dev, "Failed to initialize sub crq irqs\n, rc=%d", rc); |
| 2438 | goto init_failed; |
| 2439 | } |
| 2440 | |
| 2441 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 2442 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
| 2443 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
| 2444 | |
| 2445 | adapter->state = VNIC_PROBED; |
| 2446 | netdev_dbg(netdev, "Probed successfully. Waiting for signal from partner device.\n"); |
| 2447 | |
| 2448 | return 0; |
| 2449 | |
| 2450 | init_failed: |
| 2451 | release_sub_crqs(adapter, 1); |
| 2452 | out: |
| 2453 | adapter->state = VNIC_DOWN; |
| 2454 | return rc; |
| 2455 | } |
| 2456 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2457 | static void __ibmvnic_reset(struct work_struct *work) |
| 2458 | { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2459 | struct ibmvnic_adapter *adapter; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2460 | bool saved_state = false; |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2461 | struct ibmvnic_rwi *tmprwi; |
| 2462 | struct ibmvnic_rwi *rwi; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2463 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2464 | u32 reset_state; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2465 | int rc = 0; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2466 | |
| 2467 | adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2468 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2469 | if (test_and_set_bit_lock(0, &adapter->resetting)) { |
Lijun Pan | 870e04a | 2021-04-13 14:33:39 -0500 | [diff] [blame] | 2470 | queue_delayed_work(system_long_wq, |
| 2471 | &adapter->ibmvnic_delayed_reset, |
| 2472 | IBMVNIC_RESET_DELAY); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2473 | return; |
| 2474 | } |
| 2475 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2476 | rwi = get_next_rwi(adapter); |
| 2477 | while (rwi) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2478 | spin_lock_irqsave(&adapter->state_lock, flags); |
| 2479 | |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2480 | if (adapter->state == VNIC_REMOVING || |
Michal Suchanek | c8dc559 | 2019-09-09 22:44:51 +0200 | [diff] [blame] | 2481 | adapter->state == VNIC_REMOVED) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2482 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
Juliet Kim | 1c2977c | 2019-09-05 17:30:01 -0400 | [diff] [blame] | 2483 | kfree(rwi); |
| 2484 | rc = EBUSY; |
| 2485 | break; |
| 2486 | } |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2487 | |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2488 | if (!saved_state) { |
| 2489 | reset_state = adapter->state; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2490 | saved_state = true; |
| 2491 | } |
| 2492 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
| 2493 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 2494 | if (rwi->reset_reason == VNIC_RESET_PASSIVE_INIT) { |
| 2495 | rtnl_lock(); |
| 2496 | rc = do_passive_init(adapter); |
| 2497 | rtnl_unlock(); |
| 2498 | if (!rc) |
| 2499 | netif_carrier_on(adapter->netdev); |
| 2500 | } else if (adapter->force_reset_recovery) { |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 2501 | /* Since we are doing a hard reset now, clear the |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2502 | * failover_pending flag so we don't ignore any |
| 2503 | * future MOBILITY or other resets. |
| 2504 | */ |
| 2505 | adapter->failover_pending = false; |
| 2506 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2507 | /* Transport event occurred during previous reset */ |
| 2508 | if (adapter->wait_for_reset) { |
| 2509 | /* Previous was CHANGE_PARAM; caller locked */ |
| 2510 | adapter->force_reset_recovery = false; |
| 2511 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2512 | } else { |
| 2513 | rtnl_lock(); |
| 2514 | adapter->force_reset_recovery = false; |
| 2515 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2516 | rtnl_unlock(); |
| 2517 | } |
Sukadev Bhattiprolu | f15fde9 | 2020-11-25 18:04:28 -0600 | [diff] [blame] | 2518 | if (rc) { |
| 2519 | /* give backing device time to settle down */ |
| 2520 | netdev_dbg(adapter->netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2521 | "[S:%s] Hard reset failed, waiting 60 secs\n", |
| 2522 | adapter_state_to_string(adapter->state)); |
Sukadev Bhattiprolu | f15fde9 | 2020-11-25 18:04:28 -0600 | [diff] [blame] | 2523 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2524 | schedule_timeout(60 * HZ); |
| 2525 | } |
Lijun Pan | 1f45dc2 | 2020-12-23 14:49:04 -0600 | [diff] [blame] | 2526 | } else { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2527 | rc = do_reset(adapter, rwi, reset_state); |
| 2528 | } |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2529 | tmprwi = rwi; |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2530 | adapter->last_reset_time = jiffies; |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2531 | |
Dany Madden | 18f141b | 2020-11-25 18:04:25 -0600 | [diff] [blame] | 2532 | if (rc) |
| 2533 | netdev_dbg(adapter->netdev, "Reset failed, rc=%d\n", rc); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2534 | |
| 2535 | rwi = get_next_rwi(adapter); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2536 | |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2537 | /* |
| 2538 | * If there is another reset queued, free the previous rwi |
| 2539 | * and process the new reset even if previous reset failed |
| 2540 | * (the previous reset could have failed because of a fail |
| 2541 | * over for instance, so process the fail over). |
| 2542 | * |
| 2543 | * If there are no resets queued and the previous reset failed, |
| 2544 | * the adapter would be in an undefined state. So retry the |
| 2545 | * previous reset as a hard reset. |
| 2546 | */ |
| 2547 | if (rwi) |
| 2548 | kfree(tmprwi); |
| 2549 | else if (rc) |
| 2550 | rwi = tmprwi; |
| 2551 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2552 | if (rwi && (rwi->reset_reason == VNIC_RESET_FAILOVER || |
Sukadev Bhattiprolu | 4f408e1 | 2021-06-30 14:36:17 -0400 | [diff] [blame] | 2553 | rwi->reset_reason == VNIC_RESET_MOBILITY || rc)) |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2554 | adapter->force_reset_recovery = true; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2557 | if (adapter->wait_for_reset) { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2558 | adapter->reset_done_rc = rc; |
| 2559 | complete(&adapter->reset_done); |
| 2560 | } |
| 2561 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2562 | clear_bit_unlock(0, &adapter->resetting); |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2563 | |
| 2564 | netdev_dbg(adapter->netdev, |
Lijun Pan | 0666ef7 | 2021-04-12 02:41:28 -0500 | [diff] [blame] | 2565 | "[S:%s FRR:%d WFR:%d] Done processing resets\n", |
| 2566 | adapter_state_to_string(adapter->state), |
| 2567 | adapter->force_reset_recovery, |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2568 | adapter->wait_for_reset); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | static void __ibmvnic_delayed_reset(struct work_struct *work) |
| 2572 | { |
| 2573 | struct ibmvnic_adapter *adapter; |
| 2574 | |
| 2575 | adapter = container_of(work, struct ibmvnic_adapter, |
| 2576 | ibmvnic_delayed_reset.work); |
| 2577 | __ibmvnic_reset(&adapter->ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2578 | } |
| 2579 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2580 | static int ibmvnic_reset(struct ibmvnic_adapter *adapter, |
| 2581 | enum ibmvnic_reset_reason reason) |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2582 | { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2583 | struct list_head *entry, *tmp_entry; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2584 | struct ibmvnic_rwi *rwi, *tmp; |
| 2585 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2586 | unsigned long flags; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2587 | int ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2588 | |
Jakub Kicinski | b646acd5 | 2021-02-16 22:58:44 -0800 | [diff] [blame] | 2589 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
| 2590 | |
| 2591 | /* If failover is pending don't schedule any other reset. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2592 | * Instead let the failover complete. If there is already a |
| 2593 | * a failover reset scheduled, we will detect and drop the |
| 2594 | * duplicate reset when walking the ->rwi_list below. |
| 2595 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2596 | if (adapter->state == VNIC_REMOVING || |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2597 | adapter->state == VNIC_REMOVED || |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2598 | (adapter->failover_pending && reason != VNIC_RESET_FAILOVER)) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2599 | ret = EBUSY; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2600 | netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n"); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2601 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2602 | } |
| 2603 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2604 | if (adapter->state == VNIC_PROBING) { |
| 2605 | netdev_warn(netdev, "Adapter reset during probe\n"); |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2606 | adapter->init_done_rc = EAGAIN; |
| 2607 | ret = EAGAIN; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2608 | goto err; |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2609 | } |
| 2610 | |
Wang Hai | 3e98ae0 | 2021-06-10 20:54:17 +0800 | [diff] [blame] | 2611 | list_for_each_entry(tmp, &adapter->rwi_list, list) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2612 | if (tmp->reset_reason == reason) { |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2613 | netdev_dbg(netdev, "Skipping matching reset, reason=%s\n", |
| 2614 | reset_reason_to_string(reason)); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2615 | ret = EBUSY; |
| 2616 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2617 | } |
| 2618 | } |
| 2619 | |
Thomas Falcon | 1d1bbc3 | 2018-12-10 15:22:23 -0600 | [diff] [blame] | 2620 | rwi = kzalloc(sizeof(*rwi), GFP_ATOMIC); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2621 | if (!rwi) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2622 | ret = ENOMEM; |
| 2623 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2624 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2625 | /* if we just received a transport event, |
| 2626 | * flush reset queue and process this reset |
| 2627 | */ |
| 2628 | if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) { |
| 2629 | list_for_each_safe(entry, tmp_entry, &adapter->rwi_list) |
| 2630 | list_del(entry); |
| 2631 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2632 | rwi->reset_reason = reason; |
| 2633 | list_add_tail(&rwi->list, &adapter->rwi_list); |
Lijun Pan | caee7bf | 2021-04-12 02:41:27 -0500 | [diff] [blame] | 2634 | netdev_dbg(adapter->netdev, "Scheduling reset (reason %s)\n", |
| 2635 | reset_reason_to_string(reason)); |
Lijun Pan | 870e04a | 2021-04-13 14:33:39 -0500 | [diff] [blame] | 2636 | queue_work(system_long_wq, &adapter->ibmvnic_reset); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2637 | |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2638 | ret = 0; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2639 | err: |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2640 | /* ibmvnic_close() below can block, so drop the lock first */ |
| 2641 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
| 2642 | |
| 2643 | if (ret == ENOMEM) |
| 2644 | ibmvnic_close(netdev); |
| 2645 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2646 | return -ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 2649 | static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2650 | { |
| 2651 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2652 | |
Lijun Pan | 855a631 | 2020-11-20 16:40:13 -0600 | [diff] [blame] | 2653 | if (test_bit(0, &adapter->resetting)) { |
| 2654 | netdev_err(adapter->netdev, |
| 2655 | "Adapter is resetting, skip timeout reset\n"); |
| 2656 | return; |
| 2657 | } |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2658 | /* No queuing up reset until at least 5 seconds (default watchdog val) |
| 2659 | * after last reset |
| 2660 | */ |
| 2661 | if (time_before(jiffies, (adapter->last_reset_time + dev->watchdog_timeo))) { |
| 2662 | netdev_dbg(dev, "Not yet time to tx timeout.\n"); |
| 2663 | return; |
| 2664 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2665 | ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | static void remove_buff_from_pool(struct ibmvnic_adapter *adapter, |
| 2669 | struct ibmvnic_rx_buff *rx_buff) |
| 2670 | { |
| 2671 | struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index]; |
| 2672 | |
| 2673 | rx_buff->skb = NULL; |
| 2674 | |
| 2675 | pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff); |
| 2676 | pool->next_alloc = (pool->next_alloc + 1) % pool->size; |
| 2677 | |
| 2678 | atomic_dec(&pool->available); |
| 2679 | } |
| 2680 | |
| 2681 | static int ibmvnic_poll(struct napi_struct *napi, int budget) |
| 2682 | { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2683 | struct ibmvnic_sub_crq_queue *rx_scrq; |
| 2684 | struct ibmvnic_adapter *adapter; |
| 2685 | struct net_device *netdev; |
| 2686 | int frames_processed; |
| 2687 | int scrq_num; |
| 2688 | |
| 2689 | netdev = napi->dev; |
| 2690 | adapter = netdev_priv(netdev); |
| 2691 | scrq_num = (int)(napi - adapter->napi); |
| 2692 | frames_processed = 0; |
| 2693 | rx_scrq = adapter->rx_scrq[scrq_num]; |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2694 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2695 | restart_poll: |
| 2696 | while (frames_processed < budget) { |
| 2697 | struct sk_buff *skb; |
| 2698 | struct ibmvnic_rx_buff *rx_buff; |
| 2699 | union sub_crq *next; |
| 2700 | u32 length; |
| 2701 | u16 offset; |
| 2702 | u8 flags = 0; |
| 2703 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2704 | if (unlikely(test_bit(0, &adapter->resetting) && |
John Allen | 3468656 | 2018-02-06 16:21:49 -0600 | [diff] [blame] | 2705 | adapter->reset_reason != VNIC_RESET_NON_FATAL)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2706 | enable_scrq_irq(adapter, rx_scrq); |
Thomas Falcon | 21ecba6 | 2017-06-14 23:50:09 -0500 | [diff] [blame] | 2707 | napi_complete_done(napi, frames_processed); |
| 2708 | return frames_processed; |
| 2709 | } |
| 2710 | |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2711 | if (!pending_scrq(adapter, rx_scrq)) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2712 | break; |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2713 | next = ibmvnic_next_scrq(adapter, rx_scrq); |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 2714 | rx_buff = (struct ibmvnic_rx_buff *) |
| 2715 | be64_to_cpu(next->rx_comp.correlator); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2716 | /* do error checking */ |
| 2717 | if (next->rx_comp.rc) { |
John Allen | e1cea2e | 2017-08-07 15:42:30 -0500 | [diff] [blame] | 2718 | netdev_dbg(netdev, "rx buffer returned with rc %x\n", |
| 2719 | be16_to_cpu(next->rx_comp.rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2720 | /* free the entry */ |
| 2721 | next->rx_comp.first = 0; |
Thomas Falcon | 4b9b0f0 | 2018-02-13 18:23:42 -0600 | [diff] [blame] | 2722 | dev_kfree_skb_any(rx_buff->skb); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2723 | remove_buff_from_pool(adapter, rx_buff); |
Nathan Fontenot | ca05e31 | 2017-05-03 14:05:14 -0400 | [diff] [blame] | 2724 | continue; |
Thomas Falcon | abe27a8 | 2018-02-19 20:12:57 -0600 | [diff] [blame] | 2725 | } else if (!rx_buff->skb) { |
| 2726 | /* free the entry */ |
| 2727 | next->rx_comp.first = 0; |
| 2728 | remove_buff_from_pool(adapter, rx_buff); |
| 2729 | continue; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | length = be32_to_cpu(next->rx_comp.len); |
| 2733 | offset = be16_to_cpu(next->rx_comp.off_frame_data); |
| 2734 | flags = next->rx_comp.flags; |
| 2735 | skb = rx_buff->skb; |
Lijun Pan | 42557da | 2021-02-12 20:48:40 -0600 | [diff] [blame] | 2736 | /* load long_term_buff before copying to skb */ |
| 2737 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2738 | skb_copy_to_linear_data(skb, rx_buff->data + offset, |
| 2739 | length); |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 2740 | |
| 2741 | /* VLAN Header has been stripped by the system firmware and |
| 2742 | * needs to be inserted by the driver |
| 2743 | */ |
| 2744 | if (adapter->rx_vlan_header_insertion && |
| 2745 | (flags & IBMVNIC_VLAN_STRIPPED)) |
| 2746 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2747 | ntohs(next->rx_comp.vlan_tci)); |
| 2748 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2749 | /* free the entry */ |
| 2750 | next->rx_comp.first = 0; |
| 2751 | remove_buff_from_pool(adapter, rx_buff); |
| 2752 | |
| 2753 | skb_put(skb, length); |
| 2754 | skb->protocol = eth_type_trans(skb, netdev); |
Thomas Falcon | 94ca305 | 2017-05-03 14:05:20 -0400 | [diff] [blame] | 2755 | skb_record_rx_queue(skb, scrq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2756 | |
| 2757 | if (flags & IBMVNIC_IP_CHKSUM_GOOD && |
| 2758 | flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) { |
| 2759 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2760 | } |
| 2761 | |
| 2762 | length = skb->len; |
| 2763 | napi_gro_receive(napi, skb); /* send it up */ |
| 2764 | netdev->stats.rx_packets++; |
| 2765 | netdev->stats.rx_bytes += length; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2766 | adapter->rx_stats_buffers[scrq_num].packets++; |
| 2767 | adapter->rx_stats_buffers[scrq_num].bytes += length; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2768 | frames_processed++; |
| 2769 | } |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2770 | |
Dwip N. Banerjee | 41ed0a0 | 2020-11-18 19:12:25 -0600 | [diff] [blame] | 2771 | if (adapter->state != VNIC_CLOSING && |
| 2772 | ((atomic_read(&adapter->rx_pool[scrq_num].available) < |
| 2773 | adapter->req_rx_add_entries_per_subcrq / 2) || |
| 2774 | frames_processed < budget)) |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2775 | replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2776 | if (frames_processed < budget) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2777 | if (napi_complete_done(napi, frames_processed)) { |
| 2778 | enable_scrq_irq(adapter, rx_scrq); |
| 2779 | if (pending_scrq(adapter, rx_scrq)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2780 | if (napi_reschedule(napi)) { |
| 2781 | disable_scrq_irq(adapter, rx_scrq); |
| 2782 | goto restart_poll; |
| 2783 | } |
| 2784 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | return frames_processed; |
| 2788 | } |
| 2789 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2790 | static int wait_for_reset(struct ibmvnic_adapter *adapter) |
| 2791 | { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2792 | int rc, ret; |
| 2793 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2794 | adapter->fallback.mtu = adapter->req_mtu; |
| 2795 | adapter->fallback.rx_queues = adapter->req_rx_queues; |
| 2796 | adapter->fallback.tx_queues = adapter->req_tx_queues; |
| 2797 | adapter->fallback.rx_entries = adapter->req_rx_add_entries_per_subcrq; |
| 2798 | adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq; |
| 2799 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2800 | reinit_completion(&adapter->reset_done); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2801 | adapter->wait_for_reset = true; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2802 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2803 | |
| 2804 | if (rc) { |
| 2805 | ret = rc; |
| 2806 | goto out; |
| 2807 | } |
| 2808 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, 60000); |
| 2809 | if (rc) { |
| 2810 | ret = -ENODEV; |
| 2811 | goto out; |
| 2812 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2813 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2814 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2815 | if (adapter->reset_done_rc) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2816 | ret = -EIO; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2817 | adapter->desired.mtu = adapter->fallback.mtu; |
| 2818 | adapter->desired.rx_queues = adapter->fallback.rx_queues; |
| 2819 | adapter->desired.tx_queues = adapter->fallback.tx_queues; |
| 2820 | adapter->desired.rx_entries = adapter->fallback.rx_entries; |
| 2821 | adapter->desired.tx_entries = adapter->fallback.tx_entries; |
| 2822 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2823 | reinit_completion(&adapter->reset_done); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2824 | adapter->wait_for_reset = true; |
| 2825 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2826 | if (rc) { |
| 2827 | ret = rc; |
| 2828 | goto out; |
| 2829 | } |
| 2830 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, |
| 2831 | 60000); |
| 2832 | if (rc) { |
| 2833 | ret = -ENODEV; |
| 2834 | goto out; |
| 2835 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2836 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2837 | out: |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2838 | adapter->wait_for_reset = false; |
| 2839 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2840 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2841 | } |
| 2842 | |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2843 | static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu) |
| 2844 | { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2845 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2846 | |
| 2847 | adapter->desired.mtu = new_mtu + ETH_HLEN; |
| 2848 | |
| 2849 | return wait_for_reset(adapter); |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2850 | } |
| 2851 | |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 2852 | static netdev_features_t ibmvnic_features_check(struct sk_buff *skb, |
| 2853 | struct net_device *dev, |
| 2854 | netdev_features_t features) |
| 2855 | { |
| 2856 | /* Some backing hardware adapters can not |
| 2857 | * handle packets with a MSS less than 224 |
| 2858 | * or with only one segment. |
| 2859 | */ |
| 2860 | if (skb_is_gso(skb)) { |
| 2861 | if (skb_shinfo(skb)->gso_size < 224 || |
| 2862 | skb_shinfo(skb)->gso_segs == 1) |
| 2863 | features &= ~NETIF_F_GSO_MASK; |
| 2864 | } |
| 2865 | |
| 2866 | return features; |
| 2867 | } |
| 2868 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2869 | static const struct net_device_ops ibmvnic_netdev_ops = { |
| 2870 | .ndo_open = ibmvnic_open, |
| 2871 | .ndo_stop = ibmvnic_close, |
| 2872 | .ndo_start_xmit = ibmvnic_xmit, |
| 2873 | .ndo_set_rx_mode = ibmvnic_set_multi, |
| 2874 | .ndo_set_mac_address = ibmvnic_set_mac, |
| 2875 | .ndo_validate_addr = eth_validate_addr, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2876 | .ndo_tx_timeout = ibmvnic_tx_timeout, |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2877 | .ndo_change_mtu = ibmvnic_change_mtu, |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 2878 | .ndo_features_check = ibmvnic_features_check, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2879 | }; |
| 2880 | |
| 2881 | /* ethtool functions */ |
| 2882 | |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2883 | static int ibmvnic_get_link_ksettings(struct net_device *netdev, |
| 2884 | struct ethtool_link_ksettings *cmd) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2885 | { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 2886 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2887 | int rc; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2888 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 2889 | rc = send_query_phys_parms(adapter); |
| 2890 | if (rc) { |
| 2891 | adapter->speed = SPEED_UNKNOWN; |
| 2892 | adapter->duplex = DUPLEX_UNKNOWN; |
| 2893 | } |
| 2894 | cmd->base.speed = adapter->speed; |
| 2895 | cmd->base.duplex = adapter->duplex; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2896 | cmd->base.port = PORT_FIBRE; |
| 2897 | cmd->base.phy_address = 0; |
| 2898 | cmd->base.autoneg = AUTONEG_ENABLE; |
| 2899 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2900 | return 0; |
| 2901 | } |
| 2902 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2903 | static void ibmvnic_get_drvinfo(struct net_device *netdev, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2904 | struct ethtool_drvinfo *info) |
| 2905 | { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2906 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2907 | |
Lijun Pan | 8a96c80 | 2021-02-11 00:43:25 -0600 | [diff] [blame] | 2908 | strscpy(info->driver, ibmvnic_driver_name, sizeof(info->driver)); |
| 2909 | strscpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version)); |
| 2910 | strscpy(info->fw_version, adapter->fw_version, |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2911 | sizeof(info->fw_version)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | static u32 ibmvnic_get_msglevel(struct net_device *netdev) |
| 2915 | { |
| 2916 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2917 | |
| 2918 | return adapter->msg_enable; |
| 2919 | } |
| 2920 | |
| 2921 | static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data) |
| 2922 | { |
| 2923 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2924 | |
| 2925 | adapter->msg_enable = data; |
| 2926 | } |
| 2927 | |
| 2928 | static u32 ibmvnic_get_link(struct net_device *netdev) |
| 2929 | { |
| 2930 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2931 | |
| 2932 | /* Don't need to send a query because we request a logical link up at |
| 2933 | * init and then we wait for link state indications |
| 2934 | */ |
| 2935 | return adapter->logical_link_state; |
| 2936 | } |
| 2937 | |
| 2938 | static void ibmvnic_get_ringparam(struct net_device *netdev, |
| 2939 | struct ethtool_ringparam *ring) |
| 2940 | { |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 2941 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2942 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2943 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 2944 | ring->rx_max_pending = adapter->max_rx_add_entries_per_subcrq; |
| 2945 | ring->tx_max_pending = adapter->max_tx_entries_per_subcrq; |
| 2946 | } else { |
| 2947 | ring->rx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 2948 | ring->tx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 2949 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2950 | ring->rx_mini_max_pending = 0; |
| 2951 | ring->rx_jumbo_max_pending = 0; |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 2952 | ring->rx_pending = adapter->req_rx_add_entries_per_subcrq; |
| 2953 | ring->tx_pending = adapter->req_tx_entries_per_subcrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2954 | ring->rx_mini_pending = 0; |
| 2955 | ring->rx_jumbo_pending = 0; |
| 2956 | } |
| 2957 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2958 | static int ibmvnic_set_ringparam(struct net_device *netdev, |
| 2959 | struct ethtool_ringparam *ring) |
| 2960 | { |
| 2961 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2962 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2963 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2964 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2965 | adapter->desired.rx_entries = ring->rx_pending; |
| 2966 | adapter->desired.tx_entries = ring->tx_pending; |
| 2967 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2968 | ret = wait_for_reset(adapter); |
| 2969 | |
| 2970 | if (!ret && |
| 2971 | (adapter->req_rx_add_entries_per_subcrq != ring->rx_pending || |
| 2972 | adapter->req_tx_entries_per_subcrq != ring->tx_pending)) |
| 2973 | netdev_info(netdev, |
| 2974 | "Could not match full ringsize request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 2975 | ring->rx_pending, ring->tx_pending, |
| 2976 | adapter->req_rx_add_entries_per_subcrq, |
| 2977 | adapter->req_tx_entries_per_subcrq); |
| 2978 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2979 | } |
| 2980 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 2981 | static void ibmvnic_get_channels(struct net_device *netdev, |
| 2982 | struct ethtool_channels *channels) |
| 2983 | { |
| 2984 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2985 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2986 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 2987 | channels->max_rx = adapter->max_rx_queues; |
| 2988 | channels->max_tx = adapter->max_tx_queues; |
| 2989 | } else { |
| 2990 | channels->max_rx = IBMVNIC_MAX_QUEUES; |
| 2991 | channels->max_tx = IBMVNIC_MAX_QUEUES; |
| 2992 | } |
| 2993 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 2994 | channels->max_other = 0; |
| 2995 | channels->max_combined = 0; |
| 2996 | channels->rx_count = adapter->req_rx_queues; |
| 2997 | channels->tx_count = adapter->req_tx_queues; |
| 2998 | channels->other_count = 0; |
| 2999 | channels->combined_count = 0; |
| 3000 | } |
| 3001 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3002 | static int ibmvnic_set_channels(struct net_device *netdev, |
| 3003 | struct ethtool_channels *channels) |
| 3004 | { |
| 3005 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3006 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3007 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3008 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3009 | adapter->desired.rx_queues = channels->rx_count; |
| 3010 | adapter->desired.tx_queues = channels->tx_count; |
| 3011 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3012 | ret = wait_for_reset(adapter); |
| 3013 | |
| 3014 | if (!ret && |
| 3015 | (adapter->req_rx_queues != channels->rx_count || |
| 3016 | adapter->req_tx_queues != channels->tx_count)) |
| 3017 | netdev_info(netdev, |
| 3018 | "Could not match full channels request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 3019 | channels->rx_count, channels->tx_count, |
| 3020 | adapter->req_rx_queues, adapter->req_tx_queues); |
| 3021 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3022 | } |
| 3023 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3024 | static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 3025 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3026 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3027 | int i; |
| 3028 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3029 | switch (stringset) { |
| 3030 | case ETH_SS_STATS: |
| 3031 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); |
| 3032 | i++, data += ETH_GSTRING_LEN) |
| 3033 | memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN); |
| 3034 | |
| 3035 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3036 | snprintf(data, ETH_GSTRING_LEN, "tx%d_packets", i); |
| 3037 | data += ETH_GSTRING_LEN; |
| 3038 | |
| 3039 | snprintf(data, ETH_GSTRING_LEN, "tx%d_bytes", i); |
| 3040 | data += ETH_GSTRING_LEN; |
| 3041 | |
| 3042 | snprintf(data, ETH_GSTRING_LEN, |
| 3043 | "tx%d_dropped_packets", i); |
| 3044 | data += ETH_GSTRING_LEN; |
| 3045 | } |
| 3046 | |
| 3047 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3048 | snprintf(data, ETH_GSTRING_LEN, "rx%d_packets", i); |
| 3049 | data += ETH_GSTRING_LEN; |
| 3050 | |
| 3051 | snprintf(data, ETH_GSTRING_LEN, "rx%d_bytes", i); |
| 3052 | data += ETH_GSTRING_LEN; |
| 3053 | |
| 3054 | snprintf(data, ETH_GSTRING_LEN, "rx%d_interrupts", i); |
| 3055 | data += ETH_GSTRING_LEN; |
| 3056 | } |
| 3057 | break; |
| 3058 | |
| 3059 | case ETH_SS_PRIV_FLAGS: |
| 3060 | for (i = 0; i < ARRAY_SIZE(ibmvnic_priv_flags); i++) |
| 3061 | strcpy(data + i * ETH_GSTRING_LEN, |
| 3062 | ibmvnic_priv_flags[i]); |
| 3063 | break; |
| 3064 | default: |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3065 | return; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3066 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | static int ibmvnic_get_sset_count(struct net_device *dev, int sset) |
| 3070 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3071 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 3072 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3073 | switch (sset) { |
| 3074 | case ETH_SS_STATS: |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3075 | return ARRAY_SIZE(ibmvnic_stats) + |
| 3076 | adapter->req_tx_queues * NUM_TX_STATS + |
| 3077 | adapter->req_rx_queues * NUM_RX_STATS; |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3078 | case ETH_SS_PRIV_FLAGS: |
| 3079 | return ARRAY_SIZE(ibmvnic_priv_flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3080 | default: |
| 3081 | return -EOPNOTSUPP; |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | static void ibmvnic_get_ethtool_stats(struct net_device *dev, |
| 3086 | struct ethtool_stats *stats, u64 *data) |
| 3087 | { |
| 3088 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 3089 | union ibmvnic_crq crq; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3090 | int i, j; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3091 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3092 | |
| 3093 | memset(&crq, 0, sizeof(crq)); |
| 3094 | crq.request_statistics.first = IBMVNIC_CRQ_CMD; |
| 3095 | crq.request_statistics.cmd = REQUEST_STATISTICS; |
| 3096 | crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token); |
| 3097 | crq.request_statistics.len = |
| 3098 | cpu_to_be32(sizeof(struct ibmvnic_statistics)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3099 | |
| 3100 | /* Wait for data to be written */ |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 3101 | reinit_completion(&adapter->stats_done); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3102 | rc = ibmvnic_send_crq(adapter, &crq); |
| 3103 | if (rc) |
| 3104 | return; |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 3105 | rc = ibmvnic_wait_for_completion(adapter, &adapter->stats_done, 10000); |
| 3106 | if (rc) |
| 3107 | return; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3108 | |
| 3109 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++) |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 3110 | data[i] = be64_to_cpu(IBMVNIC_GET_STAT |
| 3111 | (adapter, ibmvnic_stats[i].offset)); |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3112 | |
| 3113 | for (j = 0; j < adapter->req_tx_queues; j++) { |
| 3114 | data[i] = adapter->tx_stats_buffers[j].packets; |
| 3115 | i++; |
| 3116 | data[i] = adapter->tx_stats_buffers[j].bytes; |
| 3117 | i++; |
| 3118 | data[i] = adapter->tx_stats_buffers[j].dropped_packets; |
| 3119 | i++; |
| 3120 | } |
| 3121 | |
| 3122 | for (j = 0; j < adapter->req_rx_queues; j++) { |
| 3123 | data[i] = adapter->rx_stats_buffers[j].packets; |
| 3124 | i++; |
| 3125 | data[i] = adapter->rx_stats_buffers[j].bytes; |
| 3126 | i++; |
| 3127 | data[i] = adapter->rx_stats_buffers[j].interrupts; |
| 3128 | i++; |
| 3129 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3130 | } |
| 3131 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3132 | static u32 ibmvnic_get_priv_flags(struct net_device *netdev) |
| 3133 | { |
| 3134 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3135 | |
| 3136 | return adapter->priv_flags; |
| 3137 | } |
| 3138 | |
| 3139 | static int ibmvnic_set_priv_flags(struct net_device *netdev, u32 flags) |
| 3140 | { |
| 3141 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 3142 | bool which_maxes = !!(flags & IBMVNIC_USE_SERVER_MAXES); |
| 3143 | |
| 3144 | if (which_maxes) |
| 3145 | adapter->priv_flags |= IBMVNIC_USE_SERVER_MAXES; |
| 3146 | else |
| 3147 | adapter->priv_flags &= ~IBMVNIC_USE_SERVER_MAXES; |
| 3148 | |
| 3149 | return 0; |
| 3150 | } |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 3151 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3152 | static const struct ethtool_ops ibmvnic_ethtool_ops = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3153 | .get_drvinfo = ibmvnic_get_drvinfo, |
| 3154 | .get_msglevel = ibmvnic_get_msglevel, |
| 3155 | .set_msglevel = ibmvnic_set_msglevel, |
| 3156 | .get_link = ibmvnic_get_link, |
| 3157 | .get_ringparam = ibmvnic_get_ringparam, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3158 | .set_ringparam = ibmvnic_set_ringparam, |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 3159 | .get_channels = ibmvnic_get_channels, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3160 | .set_channels = ibmvnic_set_channels, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3161 | .get_strings = ibmvnic_get_strings, |
| 3162 | .get_sset_count = ibmvnic_get_sset_count, |
| 3163 | .get_ethtool_stats = ibmvnic_get_ethtool_stats, |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 3164 | .get_link_ksettings = ibmvnic_get_link_ksettings, |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 3165 | .get_priv_flags = ibmvnic_get_priv_flags, |
| 3166 | .set_priv_flags = ibmvnic_set_priv_flags, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3167 | }; |
| 3168 | |
| 3169 | /* Routines for managing CRQs/sCRQs */ |
| 3170 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3171 | static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter, |
| 3172 | struct ibmvnic_sub_crq_queue *scrq) |
| 3173 | { |
| 3174 | int rc; |
| 3175 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3176 | if (!scrq) { |
YANG LI | 862aecb | 2020-12-30 15:23:14 +0800 | [diff] [blame] | 3177 | netdev_dbg(adapter->netdev, "Invalid scrq reset.\n"); |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3178 | return -EINVAL; |
| 3179 | } |
| 3180 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3181 | if (scrq->irq) { |
| 3182 | free_irq(scrq->irq, scrq); |
| 3183 | irq_dispose_mapping(scrq->irq); |
| 3184 | scrq->irq = 0; |
| 3185 | } |
| 3186 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3187 | if (scrq->msgs) { |
| 3188 | memset(scrq->msgs, 0, 4 * PAGE_SIZE); |
| 3189 | atomic_set(&scrq->used, 0); |
| 3190 | scrq->cur = 0; |
Jakub Kicinski | 55fd59b | 2020-12-03 15:42:13 -0800 | [diff] [blame] | 3191 | scrq->ind_buf.index = 0; |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 3192 | } else { |
| 3193 | netdev_dbg(adapter->netdev, "Invalid scrq reset\n"); |
| 3194 | return -EINVAL; |
| 3195 | } |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3196 | |
| 3197 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 3198 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 3199 | return rc; |
| 3200 | } |
| 3201 | |
| 3202 | static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter) |
| 3203 | { |
| 3204 | int i, rc; |
| 3205 | |
Lijun Pan | a0faaa2 | 2020-11-23 13:35:45 -0600 | [diff] [blame] | 3206 | if (!adapter->tx_scrq || !adapter->rx_scrq) |
| 3207 | return -EINVAL; |
| 3208 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3209 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3210 | netdev_dbg(adapter->netdev, "Re-setting tx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3211 | rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]); |
| 3212 | if (rc) |
| 3213 | return rc; |
| 3214 | } |
| 3215 | |
| 3216 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3217 | netdev_dbg(adapter->netdev, "Re-setting rx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3218 | rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]); |
| 3219 | if (rc) |
| 3220 | return rc; |
| 3221 | } |
| 3222 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 3223 | return rc; |
| 3224 | } |
| 3225 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3226 | static void release_sub_crq_queue(struct ibmvnic_adapter *adapter, |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3227 | struct ibmvnic_sub_crq_queue *scrq, |
| 3228 | bool do_h_free) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3229 | { |
| 3230 | struct device *dev = &adapter->vdev->dev; |
| 3231 | long rc; |
| 3232 | |
| 3233 | netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n"); |
| 3234 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3235 | if (do_h_free) { |
| 3236 | /* Close the sub-crqs */ |
| 3237 | do { |
| 3238 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 3239 | adapter->vdev->unit_address, |
| 3240 | scrq->crq_num); |
| 3241 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3242 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3243 | if (rc) { |
| 3244 | netdev_err(adapter->netdev, |
| 3245 | "Failed to release sub-CRQ %16lx, rc = %ld\n", |
| 3246 | scrq->crq_num, rc); |
| 3247 | } |
Thomas Falcon | ffa7385 | 2017-04-19 13:44:29 -0400 | [diff] [blame] | 3248 | } |
| 3249 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3250 | dma_free_coherent(dev, |
| 3251 | IBMVNIC_IND_ARR_SZ, |
| 3252 | scrq->ind_buf.indir_arr, |
| 3253 | scrq->ind_buf.indir_dma); |
| 3254 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3255 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3256 | DMA_BIDIRECTIONAL); |
| 3257 | free_pages((unsigned long)scrq->msgs, 2); |
| 3258 | kfree(scrq); |
| 3259 | } |
| 3260 | |
| 3261 | static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter |
| 3262 | *adapter) |
| 3263 | { |
| 3264 | struct device *dev = &adapter->vdev->dev; |
| 3265 | struct ibmvnic_sub_crq_queue *scrq; |
| 3266 | int rc; |
| 3267 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3268 | scrq = kzalloc(sizeof(*scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3269 | if (!scrq) |
| 3270 | return NULL; |
| 3271 | |
Nathan Fontenot | 7f7adc5 | 2017-04-19 13:45:16 -0400 | [diff] [blame] | 3272 | scrq->msgs = |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3273 | (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3274 | if (!scrq->msgs) { |
| 3275 | dev_warn(dev, "Couldn't allocate crq queue messages page\n"); |
| 3276 | goto zero_page_failed; |
| 3277 | } |
| 3278 | |
| 3279 | scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE, |
| 3280 | DMA_BIDIRECTIONAL); |
| 3281 | if (dma_mapping_error(dev, scrq->msg_token)) { |
| 3282 | dev_warn(dev, "Couldn't map crq queue messages page\n"); |
| 3283 | goto map_failed; |
| 3284 | } |
| 3285 | |
| 3286 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 3287 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 3288 | |
| 3289 | if (rc == H_RESOURCE) |
| 3290 | rc = ibmvnic_reset_crq(adapter); |
| 3291 | |
| 3292 | if (rc == H_CLOSED) { |
| 3293 | dev_warn(dev, "Partner adapter not ready, waiting.\n"); |
| 3294 | } else if (rc) { |
| 3295 | dev_warn(dev, "Error %d registering sub-crq\n", rc); |
| 3296 | goto reg_failed; |
| 3297 | } |
| 3298 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3299 | scrq->adapter = adapter; |
| 3300 | scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs); |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3301 | scrq->ind_buf.index = 0; |
| 3302 | |
| 3303 | scrq->ind_buf.indir_arr = |
| 3304 | dma_alloc_coherent(dev, |
| 3305 | IBMVNIC_IND_ARR_SZ, |
| 3306 | &scrq->ind_buf.indir_dma, |
| 3307 | GFP_KERNEL); |
| 3308 | |
| 3309 | if (!scrq->ind_buf.indir_arr) |
| 3310 | goto indir_failed; |
| 3311 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3312 | spin_lock_init(&scrq->lock); |
| 3313 | |
| 3314 | netdev_dbg(adapter->netdev, |
| 3315 | "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n", |
| 3316 | scrq->crq_num, scrq->hw_irq, scrq->irq); |
| 3317 | |
| 3318 | return scrq; |
| 3319 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3320 | indir_failed: |
| 3321 | do { |
| 3322 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 3323 | adapter->vdev->unit_address, |
| 3324 | scrq->crq_num); |
| 3325 | } while (rc == H_BUSY || rc == H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3326 | reg_failed: |
| 3327 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3328 | DMA_BIDIRECTIONAL); |
| 3329 | map_failed: |
| 3330 | free_pages((unsigned long)scrq->msgs, 2); |
| 3331 | zero_page_failed: |
| 3332 | kfree(scrq); |
| 3333 | |
| 3334 | return NULL; |
| 3335 | } |
| 3336 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3337 | 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] | 3338 | { |
| 3339 | int i; |
| 3340 | |
| 3341 | if (adapter->tx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3342 | for (i = 0; i < adapter->num_active_tx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3343 | if (!adapter->tx_scrq[i]) |
| 3344 | continue; |
| 3345 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3346 | netdev_dbg(adapter->netdev, "Releasing tx_scrq[%d]\n", |
| 3347 | i); |
Sukadev Bhattiprolu | 65d6470 | 2021-06-23 21:13:12 -0700 | [diff] [blame] | 3348 | ibmvnic_tx_scrq_clean_buffer(adapter, adapter->tx_scrq[i]); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3349 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3350 | free_irq(adapter->tx_scrq[i]->irq, |
| 3351 | adapter->tx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3352 | irq_dispose_mapping(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3353 | adapter->tx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3354 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3355 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3356 | release_sub_crq_queue(adapter, adapter->tx_scrq[i], |
| 3357 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3358 | } |
| 3359 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3360 | kfree(adapter->tx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3361 | adapter->tx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3362 | adapter->num_active_tx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | if (adapter->rx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3366 | for (i = 0; i < adapter->num_active_rx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3367 | if (!adapter->rx_scrq[i]) |
| 3368 | continue; |
| 3369 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3370 | netdev_dbg(adapter->netdev, "Releasing rx_scrq[%d]\n", |
| 3371 | i); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3372 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3373 | free_irq(adapter->rx_scrq[i]->irq, |
| 3374 | adapter->rx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3375 | irq_dispose_mapping(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3376 | adapter->rx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3377 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3378 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3379 | release_sub_crq_queue(adapter, adapter->rx_scrq[i], |
| 3380 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3381 | } |
| 3382 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3383 | kfree(adapter->rx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3384 | adapter->rx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3385 | adapter->num_active_rx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3386 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | static int disable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3390 | struct ibmvnic_sub_crq_queue *scrq) |
| 3391 | { |
| 3392 | struct device *dev = &adapter->vdev->dev; |
| 3393 | unsigned long rc; |
| 3394 | |
| 3395 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3396 | H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3397 | if (rc) |
| 3398 | dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n", |
| 3399 | scrq->hw_irq, rc); |
| 3400 | return rc; |
| 3401 | } |
| 3402 | |
| 3403 | static int enable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3404 | struct ibmvnic_sub_crq_queue *scrq) |
| 3405 | { |
| 3406 | struct device *dev = &adapter->vdev->dev; |
| 3407 | unsigned long rc; |
| 3408 | |
| 3409 | if (scrq->hw_irq > 0x100000000ULL) { |
| 3410 | dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq); |
| 3411 | return 1; |
| 3412 | } |
| 3413 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 3414 | if (test_bit(0, &adapter->resetting) && |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3415 | adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3416 | u64 val = (0xff000000) | scrq->hw_irq; |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3417 | |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3418 | rc = plpar_hcall_norets(H_EOI, val); |
Juliet Kim | 2df5c60 | 2019-11-20 10:50:04 -0500 | [diff] [blame] | 3419 | /* H_EOI would fail with rc = H_FUNCTION when running |
| 3420 | * in XIVE mode which is expected, but not an error. |
| 3421 | */ |
Sukadev Bhattiprolu | 154b3b2 | 2021-06-23 21:13:16 -0700 | [diff] [blame] | 3422 | if (rc && (rc != H_FUNCTION)) |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3423 | dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n", |
| 3424 | val, rc); |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3425 | } |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 3426 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3427 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3428 | H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3429 | if (rc) |
| 3430 | dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n", |
| 3431 | scrq->hw_irq, rc); |
| 3432 | return rc; |
| 3433 | } |
| 3434 | |
| 3435 | static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter, |
| 3436 | struct ibmvnic_sub_crq_queue *scrq) |
| 3437 | { |
| 3438 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3439 | struct ibmvnic_tx_pool *tx_pool; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3440 | struct ibmvnic_tx_buff *txbuff; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3441 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3442 | union sub_crq *next; |
| 3443 | int index; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 3444 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3445 | |
| 3446 | restart_loop: |
| 3447 | while (pending_scrq(adapter, scrq)) { |
| 3448 | unsigned int pool = scrq->pool_index; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3449 | int num_entries = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3450 | int total_bytes = 0; |
| 3451 | int num_packets = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3452 | |
| 3453 | next = ibmvnic_next_scrq(adapter, scrq); |
| 3454 | for (i = 0; i < next->tx_comp.num_comps; i++) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3455 | index = be32_to_cpu(next->tx_comp.correlators[i]); |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3456 | if (index & IBMVNIC_TSO_POOL_MASK) { |
| 3457 | tx_pool = &adapter->tso_pool[pool]; |
| 3458 | index &= ~IBMVNIC_TSO_POOL_MASK; |
| 3459 | } else { |
| 3460 | tx_pool = &adapter->tx_pool[pool]; |
| 3461 | } |
| 3462 | |
| 3463 | txbuff = &tx_pool->tx_buff[index]; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3464 | num_packets++; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3465 | num_entries += txbuff->num_entries; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3466 | if (txbuff->skb) { |
| 3467 | total_bytes += txbuff->skb->len; |
Lijun Pan | ca09bf7 | 2021-04-13 03:33:25 -0500 | [diff] [blame] | 3468 | if (next->tx_comp.rcs[i]) { |
| 3469 | dev_err(dev, "tx error %x\n", |
| 3470 | next->tx_comp.rcs[i]); |
| 3471 | dev_kfree_skb_irq(txbuff->skb); |
| 3472 | } else { |
| 3473 | dev_consume_skb_irq(txbuff->skb); |
| 3474 | } |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3475 | txbuff->skb = NULL; |
| 3476 | } else { |
| 3477 | netdev_warn(adapter->netdev, |
| 3478 | "TX completion received with NULL socket buffer\n"); |
| 3479 | } |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3480 | tx_pool->free_map[tx_pool->producer_index] = index; |
| 3481 | tx_pool->producer_index = |
| 3482 | (tx_pool->producer_index + 1) % |
| 3483 | tx_pool->num_buffers; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3484 | } |
| 3485 | /* remove tx_comp scrq*/ |
| 3486 | next->tx_comp.first = 0; |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3487 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3488 | txq = netdev_get_tx_queue(adapter->netdev, scrq->pool_index); |
| 3489 | netdev_tx_completed_queue(txq, num_packets, total_bytes); |
| 3490 | |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3491 | if (atomic_sub_return(num_entries, &scrq->used) <= |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3492 | (adapter->req_tx_entries_per_subcrq / 2) && |
| 3493 | __netif_subqueue_stopped(adapter->netdev, |
| 3494 | scrq->pool_index)) { |
| 3495 | netif_wake_subqueue(adapter->netdev, scrq->pool_index); |
Thomas Falcon | 0aecb13 | 2018-02-26 18:10:58 -0600 | [diff] [blame] | 3496 | netdev_dbg(adapter->netdev, "Started queue %d\n", |
| 3497 | scrq->pool_index); |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3498 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | enable_scrq_irq(adapter, scrq); |
| 3502 | |
| 3503 | if (pending_scrq(adapter, scrq)) { |
| 3504 | disable_scrq_irq(adapter, scrq); |
| 3505 | goto restart_loop; |
| 3506 | } |
| 3507 | |
| 3508 | return 0; |
| 3509 | } |
| 3510 | |
| 3511 | static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance) |
| 3512 | { |
| 3513 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3514 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3515 | |
| 3516 | disable_scrq_irq(adapter, scrq); |
| 3517 | ibmvnic_complete_tx(adapter, scrq); |
| 3518 | |
| 3519 | return IRQ_HANDLED; |
| 3520 | } |
| 3521 | |
| 3522 | static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance) |
| 3523 | { |
| 3524 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3525 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3526 | |
Nathan Fontenot | 09fb35e | 2018-01-10 10:40:09 -0600 | [diff] [blame] | 3527 | /* When booting a kdump kernel we can hit pending interrupts |
| 3528 | * prior to completing driver initialization. |
| 3529 | */ |
| 3530 | if (unlikely(adapter->state != VNIC_OPEN)) |
| 3531 | return IRQ_NONE; |
| 3532 | |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3533 | adapter->rx_stats_buffers[scrq->scrq_num].interrupts++; |
| 3534 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3535 | if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) { |
| 3536 | disable_scrq_irq(adapter, scrq); |
| 3537 | __napi_schedule(&adapter->napi[scrq->scrq_num]); |
| 3538 | } |
| 3539 | |
| 3540 | return IRQ_HANDLED; |
| 3541 | } |
| 3542 | |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3543 | static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter) |
| 3544 | { |
| 3545 | struct device *dev = &adapter->vdev->dev; |
| 3546 | struct ibmvnic_sub_crq_queue *scrq; |
| 3547 | int i = 0, j = 0; |
| 3548 | int rc = 0; |
| 3549 | |
| 3550 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3551 | netdev_dbg(adapter->netdev, "Initializing tx_scrq[%d] irq\n", |
| 3552 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3553 | scrq = adapter->tx_scrq[i]; |
| 3554 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
| 3555 | |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3556 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3557 | rc = -EINVAL; |
| 3558 | dev_err(dev, "Error mapping irq\n"); |
| 3559 | goto req_tx_irq_failed; |
| 3560 | } |
| 3561 | |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3562 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-tx%d", |
| 3563 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3564 | rc = request_irq(scrq->irq, ibmvnic_interrupt_tx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3565 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3566 | |
| 3567 | if (rc) { |
| 3568 | dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n", |
| 3569 | scrq->irq, rc); |
| 3570 | irq_dispose_mapping(scrq->irq); |
Nathan Fontenot | af9090c | 2018-02-20 11:04:18 -0600 | [diff] [blame] | 3571 | goto req_tx_irq_failed; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3576 | netdev_dbg(adapter->netdev, "Initializing rx_scrq[%d] irq\n", |
| 3577 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3578 | scrq = adapter->rx_scrq[i]; |
| 3579 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3580 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3581 | rc = -EINVAL; |
| 3582 | dev_err(dev, "Error mapping irq\n"); |
| 3583 | goto req_rx_irq_failed; |
| 3584 | } |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3585 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-rx%d", |
| 3586 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3587 | rc = request_irq(scrq->irq, ibmvnic_interrupt_rx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3588 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3589 | if (rc) { |
| 3590 | dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n", |
| 3591 | scrq->irq, rc); |
| 3592 | irq_dispose_mapping(scrq->irq); |
| 3593 | goto req_rx_irq_failed; |
| 3594 | } |
| 3595 | } |
| 3596 | return rc; |
| 3597 | |
| 3598 | req_rx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3599 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3600 | free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]); |
| 3601 | irq_dispose_mapping(adapter->rx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3602 | } |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3603 | i = adapter->req_tx_queues; |
| 3604 | req_tx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3605 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3606 | free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]); |
Thomas Falcon | 27a2145 | 2020-07-29 16:36:32 -0500 | [diff] [blame] | 3607 | irq_dispose_mapping(adapter->tx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3608 | } |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3609 | release_sub_crqs(adapter, 1); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3610 | return rc; |
| 3611 | } |
| 3612 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3613 | static int init_sub_crqs(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3614 | { |
| 3615 | struct device *dev = &adapter->vdev->dev; |
| 3616 | struct ibmvnic_sub_crq_queue **allqueues; |
| 3617 | int registered_queues = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3618 | int total_queues; |
| 3619 | int more = 0; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3620 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3621 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3622 | total_queues = adapter->req_tx_queues + adapter->req_rx_queues; |
| 3623 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3624 | allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3625 | if (!allqueues) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3626 | return -1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3627 | |
| 3628 | for (i = 0; i < total_queues; i++) { |
| 3629 | allqueues[i] = init_sub_crq_queue(adapter); |
| 3630 | if (!allqueues[i]) { |
| 3631 | dev_warn(dev, "Couldn't allocate all sub-crqs\n"); |
| 3632 | break; |
| 3633 | } |
| 3634 | registered_queues++; |
| 3635 | } |
| 3636 | |
| 3637 | /* Make sure we were able to register the minimum number of queues */ |
| 3638 | if (registered_queues < |
| 3639 | adapter->min_tx_queues + adapter->min_rx_queues) { |
| 3640 | dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n"); |
| 3641 | goto tx_failed; |
| 3642 | } |
| 3643 | |
| 3644 | /* Distribute the failed allocated queues*/ |
| 3645 | for (i = 0; i < total_queues - registered_queues + more ; i++) { |
| 3646 | netdev_dbg(adapter->netdev, "Reducing number of queues\n"); |
| 3647 | switch (i % 3) { |
| 3648 | case 0: |
| 3649 | if (adapter->req_rx_queues > adapter->min_rx_queues) |
| 3650 | adapter->req_rx_queues--; |
| 3651 | else |
| 3652 | more++; |
| 3653 | break; |
| 3654 | case 1: |
| 3655 | if (adapter->req_tx_queues > adapter->min_tx_queues) |
| 3656 | adapter->req_tx_queues--; |
| 3657 | else |
| 3658 | more++; |
| 3659 | break; |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | adapter->tx_scrq = kcalloc(adapter->req_tx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3664 | sizeof(*adapter->tx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3665 | if (!adapter->tx_scrq) |
| 3666 | goto tx_failed; |
| 3667 | |
| 3668 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3669 | adapter->tx_scrq[i] = allqueues[i]; |
| 3670 | adapter->tx_scrq[i]->pool_index = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3671 | adapter->num_active_tx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3672 | } |
| 3673 | |
| 3674 | adapter->rx_scrq = kcalloc(adapter->req_rx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3675 | sizeof(*adapter->rx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3676 | if (!adapter->rx_scrq) |
| 3677 | goto rx_failed; |
| 3678 | |
| 3679 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3680 | adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues]; |
| 3681 | adapter->rx_scrq[i]->scrq_num = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3682 | adapter->num_active_rx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3683 | } |
| 3684 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3685 | kfree(allqueues); |
| 3686 | return 0; |
| 3687 | |
| 3688 | rx_failed: |
| 3689 | kfree(adapter->tx_scrq); |
| 3690 | adapter->tx_scrq = NULL; |
| 3691 | tx_failed: |
| 3692 | for (i = 0; i < registered_queues; i++) |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3693 | release_sub_crq_queue(adapter, allqueues[i], 1); |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3694 | kfree(allqueues); |
| 3695 | return -1; |
| 3696 | } |
| 3697 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 3698 | static void send_request_cap(struct ibmvnic_adapter *adapter, int retry) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3699 | { |
| 3700 | struct device *dev = &adapter->vdev->dev; |
| 3701 | union ibmvnic_crq crq; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3702 | int max_entries; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3703 | |
| 3704 | if (!retry) { |
| 3705 | /* Sub-CRQ entries are 32 byte long */ |
| 3706 | int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4); |
| 3707 | |
| 3708 | if (adapter->min_tx_entries_per_subcrq > entries_page || |
| 3709 | adapter->min_rx_add_entries_per_subcrq > entries_page) { |
| 3710 | dev_err(dev, "Fatal, invalid entries per sub-crq\n"); |
| 3711 | return; |
| 3712 | } |
| 3713 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3714 | if (adapter->desired.mtu) |
| 3715 | adapter->req_mtu = adapter->desired.mtu; |
| 3716 | else |
| 3717 | adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3718 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3719 | if (!adapter->desired.tx_entries) |
| 3720 | adapter->desired.tx_entries = |
| 3721 | adapter->max_tx_entries_per_subcrq; |
| 3722 | if (!adapter->desired.rx_entries) |
| 3723 | adapter->desired.rx_entries = |
| 3724 | adapter->max_rx_add_entries_per_subcrq; |
| 3725 | |
| 3726 | max_entries = IBMVNIC_MAX_LTB_SIZE / |
| 3727 | (adapter->req_mtu + IBMVNIC_BUFFER_HLEN); |
| 3728 | |
| 3729 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3730 | adapter->desired.tx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3731 | adapter->desired.tx_entries = max_entries; |
| 3732 | } |
| 3733 | |
| 3734 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3735 | adapter->desired.rx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3736 | adapter->desired.rx_entries = max_entries; |
| 3737 | } |
| 3738 | |
| 3739 | if (adapter->desired.tx_entries) |
| 3740 | adapter->req_tx_entries_per_subcrq = |
| 3741 | adapter->desired.tx_entries; |
| 3742 | else |
| 3743 | adapter->req_tx_entries_per_subcrq = |
| 3744 | adapter->max_tx_entries_per_subcrq; |
| 3745 | |
| 3746 | if (adapter->desired.rx_entries) |
| 3747 | adapter->req_rx_add_entries_per_subcrq = |
| 3748 | adapter->desired.rx_entries; |
| 3749 | else |
| 3750 | adapter->req_rx_add_entries_per_subcrq = |
| 3751 | adapter->max_rx_add_entries_per_subcrq; |
| 3752 | |
| 3753 | if (adapter->desired.tx_queues) |
| 3754 | adapter->req_tx_queues = |
| 3755 | adapter->desired.tx_queues; |
| 3756 | else |
| 3757 | adapter->req_tx_queues = |
| 3758 | adapter->opt_tx_comp_sub_queues; |
| 3759 | |
| 3760 | if (adapter->desired.rx_queues) |
| 3761 | adapter->req_rx_queues = |
| 3762 | adapter->desired.rx_queues; |
| 3763 | else |
| 3764 | adapter->req_rx_queues = |
| 3765 | adapter->opt_rx_comp_queues; |
| 3766 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3767 | adapter->req_rx_add_queues = adapter->max_rx_add_queues; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3768 | } |
| 3769 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3770 | memset(&crq, 0, sizeof(crq)); |
| 3771 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 3772 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 3773 | |
| 3774 | crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3775 | crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3776 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3777 | ibmvnic_send_crq(adapter, &crq); |
| 3778 | |
| 3779 | crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3780 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3781 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3782 | ibmvnic_send_crq(adapter, &crq); |
| 3783 | |
| 3784 | crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3785 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3786 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3787 | ibmvnic_send_crq(adapter, &crq); |
| 3788 | |
| 3789 | crq.request_capability.capability = |
| 3790 | cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ); |
| 3791 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3792 | cpu_to_be64(adapter->req_tx_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3793 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3794 | ibmvnic_send_crq(adapter, &crq); |
| 3795 | |
| 3796 | crq.request_capability.capability = |
| 3797 | cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ); |
| 3798 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3799 | cpu_to_be64(adapter->req_rx_add_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3800 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3801 | ibmvnic_send_crq(adapter, &crq); |
| 3802 | |
| 3803 | crq.request_capability.capability = cpu_to_be16(REQ_MTU); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3804 | crq.request_capability.number = cpu_to_be64(adapter->req_mtu); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3805 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3806 | ibmvnic_send_crq(adapter, &crq); |
| 3807 | |
| 3808 | if (adapter->netdev->flags & IFF_PROMISC) { |
| 3809 | if (adapter->promisc_supported) { |
| 3810 | crq.request_capability.capability = |
| 3811 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3812 | crq.request_capability.number = cpu_to_be64(1); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3813 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3814 | ibmvnic_send_crq(adapter, &crq); |
| 3815 | } |
| 3816 | } else { |
| 3817 | crq.request_capability.capability = |
| 3818 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3819 | crq.request_capability.number = cpu_to_be64(0); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3820 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3821 | ibmvnic_send_crq(adapter, &crq); |
| 3822 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | static int pending_scrq(struct ibmvnic_adapter *adapter, |
| 3826 | struct ibmvnic_sub_crq_queue *scrq) |
| 3827 | { |
| 3828 | union sub_crq *entry = &scrq->msgs[scrq->cur]; |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3829 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3830 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3831 | rc = !!(entry->generic.first & IBMVNIC_CRQ_CMD_RSP); |
| 3832 | |
| 3833 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 3834 | * contents of the SCRQ descriptor |
| 3835 | */ |
| 3836 | dma_rmb(); |
| 3837 | |
| 3838 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter, |
| 3842 | struct ibmvnic_sub_crq_queue *scrq) |
| 3843 | { |
| 3844 | union sub_crq *entry; |
| 3845 | unsigned long flags; |
| 3846 | |
| 3847 | spin_lock_irqsave(&scrq->lock, flags); |
| 3848 | entry = &scrq->msgs[scrq->cur]; |
| 3849 | if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 3850 | if (++scrq->cur == scrq->size) |
| 3851 | scrq->cur = 0; |
| 3852 | } else { |
| 3853 | entry = NULL; |
| 3854 | } |
| 3855 | spin_unlock_irqrestore(&scrq->lock, flags); |
| 3856 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3857 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 3858 | * contents of the SCRQ descriptor |
Thomas Falcon | b71ec95 | 2020-12-01 09:52:10 -0600 | [diff] [blame] | 3859 | */ |
| 3860 | dma_rmb(); |
| 3861 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3862 | return entry; |
| 3863 | } |
| 3864 | |
| 3865 | static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter) |
| 3866 | { |
| 3867 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
| 3868 | union ibmvnic_crq *crq; |
| 3869 | |
| 3870 | crq = &queue->msgs[queue->cur]; |
| 3871 | if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 3872 | if (++queue->cur == queue->size) |
| 3873 | queue->cur = 0; |
| 3874 | } else { |
| 3875 | crq = NULL; |
| 3876 | } |
| 3877 | |
| 3878 | return crq; |
| 3879 | } |
| 3880 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 3881 | static void print_subcrq_error(struct device *dev, int rc, const char *func) |
| 3882 | { |
| 3883 | switch (rc) { |
| 3884 | case H_PARAMETER: |
| 3885 | dev_warn_ratelimited(dev, |
| 3886 | "%s failed: Send request is malformed or adapter failover pending. (rc=%d)\n", |
| 3887 | func, rc); |
| 3888 | break; |
| 3889 | case H_CLOSED: |
| 3890 | dev_warn_ratelimited(dev, |
| 3891 | "%s failed: Backing queue closed. Adapter is down or failover pending. (rc=%d)\n", |
| 3892 | func, rc); |
| 3893 | break; |
| 3894 | default: |
| 3895 | dev_err_ratelimited(dev, "%s failed: (rc=%d)\n", func, rc); |
| 3896 | break; |
| 3897 | } |
| 3898 | } |
| 3899 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3900 | static int send_subcrq_indirect(struct ibmvnic_adapter *adapter, |
| 3901 | u64 remote_handle, u64 ioba, u64 num_entries) |
| 3902 | { |
| 3903 | unsigned int ua = adapter->vdev->unit_address; |
| 3904 | struct device *dev = &adapter->vdev->dev; |
| 3905 | int rc; |
| 3906 | |
| 3907 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 3908 | dma_wmb(); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3909 | rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua, |
| 3910 | cpu_to_be64(remote_handle), |
| 3911 | ioba, num_entries); |
| 3912 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 3913 | if (rc) |
| 3914 | print_subcrq_error(dev, rc, __func__); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3915 | |
| 3916 | return rc; |
| 3917 | } |
| 3918 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3919 | static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter, |
| 3920 | union ibmvnic_crq *crq) |
| 3921 | { |
| 3922 | unsigned int ua = adapter->vdev->unit_address; |
| 3923 | struct device *dev = &adapter->vdev->dev; |
| 3924 | u64 *u64_crq = (u64 *)crq; |
| 3925 | int rc; |
| 3926 | |
| 3927 | netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 3928 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 3929 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3930 | |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 3931 | if (!adapter->crq.active && |
| 3932 | crq->generic.first != IBMVNIC_CRQ_INIT_CMD) { |
| 3933 | dev_warn(dev, "Invalid request detected while CRQ is inactive, possible device state change during reset\n"); |
| 3934 | return -EINVAL; |
| 3935 | } |
| 3936 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3937 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 3938 | dma_wmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3939 | |
| 3940 | rc = plpar_hcall_norets(H_SEND_CRQ, ua, |
| 3941 | cpu_to_be64(u64_crq[0]), |
| 3942 | cpu_to_be64(u64_crq[1])); |
| 3943 | |
| 3944 | if (rc) { |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 3945 | if (rc == H_CLOSED) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3946 | dev_warn(dev, "CRQ Queue closed\n"); |
Lijun Pan | fa68bfa | 2020-08-19 17:52:24 -0500 | [diff] [blame] | 3947 | /* do not reset, report the fail, wait for passive init from server */ |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 3948 | } |
| 3949 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3950 | dev_warn(dev, "Send error (rc=%d)\n", rc); |
| 3951 | } |
| 3952 | |
| 3953 | return rc; |
| 3954 | } |
| 3955 | |
| 3956 | static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter) |
| 3957 | { |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3958 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3959 | union ibmvnic_crq crq; |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3960 | int retries = 100; |
| 3961 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3962 | |
| 3963 | memset(&crq, 0, sizeof(crq)); |
| 3964 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 3965 | crq.generic.cmd = IBMVNIC_CRQ_INIT; |
| 3966 | netdev_dbg(adapter->netdev, "Sending CRQ init\n"); |
| 3967 | |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3968 | do { |
| 3969 | rc = ibmvnic_send_crq(adapter, &crq); |
| 3970 | if (rc != H_CLOSED) |
| 3971 | break; |
| 3972 | retries--; |
| 3973 | msleep(50); |
| 3974 | |
| 3975 | } while (retries > 0); |
| 3976 | |
| 3977 | if (rc) { |
| 3978 | dev_err(dev, "Failed to send init request, rc = %d\n", rc); |
| 3979 | return rc; |
| 3980 | } |
| 3981 | |
| 3982 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3983 | } |
| 3984 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3985 | struct vnic_login_client_data { |
| 3986 | u8 type; |
| 3987 | __be16 len; |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 3988 | char name[]; |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3989 | } __packed; |
| 3990 | |
| 3991 | static int vnic_client_data_len(struct ibmvnic_adapter *adapter) |
| 3992 | { |
| 3993 | int len; |
| 3994 | |
| 3995 | /* Calculate the amount of buffer space needed for the |
| 3996 | * vnic client data in the login buffer. There are four entries, |
| 3997 | * OS name, LPAR name, device name, and a null last entry. |
| 3998 | */ |
| 3999 | len = 4 * sizeof(struct vnic_login_client_data); |
| 4000 | len += 6; /* "Linux" plus NULL */ |
| 4001 | len += strlen(utsname()->nodename) + 1; |
| 4002 | len += strlen(adapter->netdev->name) + 1; |
| 4003 | |
| 4004 | return len; |
| 4005 | } |
| 4006 | |
| 4007 | static void vnic_add_client_data(struct ibmvnic_adapter *adapter, |
| 4008 | struct vnic_login_client_data *vlcd) |
| 4009 | { |
| 4010 | const char *os_name = "Linux"; |
| 4011 | int len; |
| 4012 | |
| 4013 | /* Type 1 - LPAR OS */ |
| 4014 | vlcd->type = 1; |
| 4015 | len = strlen(os_name) + 1; |
| 4016 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4017 | strscpy(vlcd->name, os_name, len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 4018 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4019 | |
| 4020 | /* Type 2 - LPAR name */ |
| 4021 | vlcd->type = 2; |
| 4022 | len = strlen(utsname()->nodename) + 1; |
| 4023 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4024 | strscpy(vlcd->name, utsname()->nodename, len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 4025 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4026 | |
| 4027 | /* Type 3 - device name */ |
| 4028 | vlcd->type = 3; |
| 4029 | len = strlen(adapter->netdev->name) + 1; |
| 4030 | vlcd->len = cpu_to_be16(len); |
Kees Cook | ef2c3dd | 2021-06-21 14:35:09 -0700 | [diff] [blame] | 4031 | strscpy(vlcd->name, adapter->netdev->name, len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4032 | } |
| 4033 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4034 | static int send_login(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4035 | { |
| 4036 | struct ibmvnic_login_rsp_buffer *login_rsp_buffer; |
| 4037 | struct ibmvnic_login_buffer *login_buffer; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4038 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4039 | struct vnic_login_client_data *vlcd; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4040 | dma_addr_t rsp_buffer_token; |
| 4041 | dma_addr_t buffer_token; |
| 4042 | size_t rsp_buffer_size; |
| 4043 | union ibmvnic_crq crq; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4044 | int client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4045 | size_t buffer_size; |
| 4046 | __be64 *tx_list_p; |
| 4047 | __be64 *rx_list_p; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4048 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4049 | int i; |
| 4050 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4051 | if (!adapter->tx_scrq || !adapter->rx_scrq) { |
| 4052 | netdev_err(adapter->netdev, |
| 4053 | "RX or TX queues are not allocated, device login failed\n"); |
| 4054 | return -1; |
| 4055 | } |
| 4056 | |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 4057 | release_login_buffer(adapter); |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 4058 | release_login_rsp_buffer(adapter); |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 4059 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4060 | client_data_len = vnic_client_data_len(adapter); |
| 4061 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4062 | buffer_size = |
| 4063 | sizeof(struct ibmvnic_login_buffer) + |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4064 | sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues) + |
| 4065 | client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4066 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4067 | login_buffer = kzalloc(buffer_size, GFP_ATOMIC); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4068 | if (!login_buffer) |
| 4069 | goto buf_alloc_failed; |
| 4070 | |
| 4071 | buffer_token = dma_map_single(dev, login_buffer, buffer_size, |
| 4072 | DMA_TO_DEVICE); |
| 4073 | if (dma_mapping_error(dev, buffer_token)) { |
| 4074 | dev_err(dev, "Couldn't map login buffer\n"); |
| 4075 | goto buf_map_failed; |
| 4076 | } |
| 4077 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4078 | rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) + |
| 4079 | sizeof(u64) * adapter->req_tx_queues + |
| 4080 | sizeof(u64) * adapter->req_rx_queues + |
| 4081 | sizeof(u64) * adapter->req_rx_queues + |
| 4082 | sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4083 | |
| 4084 | login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC); |
| 4085 | if (!login_rsp_buffer) |
| 4086 | goto buf_rsp_alloc_failed; |
| 4087 | |
| 4088 | rsp_buffer_token = dma_map_single(dev, login_rsp_buffer, |
| 4089 | rsp_buffer_size, DMA_FROM_DEVICE); |
| 4090 | if (dma_mapping_error(dev, rsp_buffer_token)) { |
| 4091 | dev_err(dev, "Couldn't map login rsp buffer\n"); |
| 4092 | goto buf_rsp_map_failed; |
| 4093 | } |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 4094 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4095 | adapter->login_buf = login_buffer; |
| 4096 | adapter->login_buf_token = buffer_token; |
| 4097 | adapter->login_buf_sz = buffer_size; |
| 4098 | adapter->login_rsp_buf = login_rsp_buffer; |
| 4099 | adapter->login_rsp_buf_token = rsp_buffer_token; |
| 4100 | adapter->login_rsp_buf_sz = rsp_buffer_size; |
| 4101 | |
| 4102 | login_buffer->len = cpu_to_be32(buffer_size); |
| 4103 | login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB); |
| 4104 | login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues); |
| 4105 | login_buffer->off_txcomp_subcrqs = |
| 4106 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer)); |
| 4107 | login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues); |
| 4108 | login_buffer->off_rxcomp_subcrqs = |
| 4109 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer) + |
| 4110 | sizeof(u64) * adapter->req_tx_queues); |
| 4111 | login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token); |
| 4112 | login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size); |
| 4113 | |
| 4114 | tx_list_p = (__be64 *)((char *)login_buffer + |
| 4115 | sizeof(struct ibmvnic_login_buffer)); |
| 4116 | rx_list_p = (__be64 *)((char *)login_buffer + |
| 4117 | sizeof(struct ibmvnic_login_buffer) + |
| 4118 | sizeof(u64) * adapter->req_tx_queues); |
| 4119 | |
| 4120 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 4121 | if (adapter->tx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4122 | tx_list_p[i] = |
| 4123 | cpu_to_be64(adapter->tx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 4128 | if (adapter->rx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4129 | rx_list_p[i] = |
| 4130 | cpu_to_be64(adapter->rx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 4134 | /* Insert vNIC login client data */ |
| 4135 | vlcd = (struct vnic_login_client_data *) |
| 4136 | ((char *)rx_list_p + (sizeof(u64) * adapter->req_rx_queues)); |
| 4137 | login_buffer->client_data_offset = |
| 4138 | cpu_to_be32((char *)vlcd - (char *)login_buffer); |
| 4139 | login_buffer->client_data_len = cpu_to_be32(client_data_len); |
| 4140 | |
| 4141 | vnic_add_client_data(adapter, vlcd); |
| 4142 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4143 | netdev_dbg(adapter->netdev, "Login Buffer:\n"); |
| 4144 | for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) { |
| 4145 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4146 | ((unsigned long *)(adapter->login_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | memset(&crq, 0, sizeof(crq)); |
| 4150 | crq.login.first = IBMVNIC_CRQ_CMD; |
| 4151 | crq.login.cmd = LOGIN; |
| 4152 | crq.login.ioba = cpu_to_be32(buffer_token); |
| 4153 | crq.login.len = cpu_to_be32(buffer_size); |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4154 | |
| 4155 | adapter->login_pending = true; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4156 | rc = ibmvnic_send_crq(adapter, &crq); |
| 4157 | if (rc) { |
| 4158 | adapter->login_pending = false; |
| 4159 | netdev_err(adapter->netdev, "Failed to send login, rc=%d\n", rc); |
| 4160 | goto buf_rsp_map_failed; |
| 4161 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4162 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4163 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4164 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4165 | buf_rsp_map_failed: |
| 4166 | kfree(login_rsp_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4167 | adapter->login_rsp_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4168 | buf_rsp_alloc_failed: |
| 4169 | dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE); |
| 4170 | buf_map_failed: |
| 4171 | kfree(login_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 4172 | adapter->login_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4173 | buf_alloc_failed: |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 4174 | return -1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4175 | } |
| 4176 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4177 | static int send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr, |
| 4178 | u32 len, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4179 | { |
| 4180 | union ibmvnic_crq crq; |
| 4181 | |
| 4182 | memset(&crq, 0, sizeof(crq)); |
| 4183 | crq.request_map.first = IBMVNIC_CRQ_CMD; |
| 4184 | crq.request_map.cmd = REQUEST_MAP; |
| 4185 | crq.request_map.map_id = map_id; |
| 4186 | crq.request_map.ioba = cpu_to_be32(addr); |
| 4187 | crq.request_map.len = cpu_to_be32(len); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4188 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4189 | } |
| 4190 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4191 | static int send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4192 | { |
| 4193 | union ibmvnic_crq crq; |
| 4194 | |
| 4195 | memset(&crq, 0, sizeof(crq)); |
| 4196 | crq.request_unmap.first = IBMVNIC_CRQ_CMD; |
| 4197 | crq.request_unmap.cmd = REQUEST_UNMAP; |
| 4198 | crq.request_unmap.map_id = map_id; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 4199 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4200 | } |
| 4201 | |
Lijun Pan | 69980d0 | 2020-09-27 20:13:28 -0500 | [diff] [blame] | 4202 | static void send_query_map(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4203 | { |
| 4204 | union ibmvnic_crq crq; |
| 4205 | |
| 4206 | memset(&crq, 0, sizeof(crq)); |
| 4207 | crq.query_map.first = IBMVNIC_CRQ_CMD; |
| 4208 | crq.query_map.cmd = QUERY_MAP; |
| 4209 | ibmvnic_send_crq(adapter, &crq); |
| 4210 | } |
| 4211 | |
| 4212 | /* Send a series of CRQs requesting various capabilities of the VNIC server */ |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 4213 | static void send_query_cap(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4214 | { |
| 4215 | union ibmvnic_crq crq; |
| 4216 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4217 | atomic_set(&adapter->running_cap_crqs, 0); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4218 | memset(&crq, 0, sizeof(crq)); |
| 4219 | crq.query_capability.first = IBMVNIC_CRQ_CMD; |
| 4220 | crq.query_capability.cmd = QUERY_CAPABILITY; |
| 4221 | |
| 4222 | crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4223 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4224 | ibmvnic_send_crq(adapter, &crq); |
| 4225 | |
| 4226 | crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4227 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4228 | ibmvnic_send_crq(adapter, &crq); |
| 4229 | |
| 4230 | crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4231 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4232 | ibmvnic_send_crq(adapter, &crq); |
| 4233 | |
| 4234 | crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4235 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4236 | ibmvnic_send_crq(adapter, &crq); |
| 4237 | |
| 4238 | crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4239 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4240 | ibmvnic_send_crq(adapter, &crq); |
| 4241 | |
| 4242 | crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4243 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4244 | ibmvnic_send_crq(adapter, &crq); |
| 4245 | |
| 4246 | crq.query_capability.capability = |
| 4247 | cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4248 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4249 | ibmvnic_send_crq(adapter, &crq); |
| 4250 | |
| 4251 | crq.query_capability.capability = |
| 4252 | cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4253 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4254 | ibmvnic_send_crq(adapter, &crq); |
| 4255 | |
| 4256 | crq.query_capability.capability = |
| 4257 | cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4258 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4259 | ibmvnic_send_crq(adapter, &crq); |
| 4260 | |
| 4261 | crq.query_capability.capability = |
| 4262 | cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4263 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4264 | ibmvnic_send_crq(adapter, &crq); |
| 4265 | |
| 4266 | crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4267 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4268 | ibmvnic_send_crq(adapter, &crq); |
| 4269 | |
| 4270 | crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4271 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4272 | ibmvnic_send_crq(adapter, &crq); |
| 4273 | |
| 4274 | crq.query_capability.capability = cpu_to_be16(MIN_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4275 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4276 | ibmvnic_send_crq(adapter, &crq); |
| 4277 | |
| 4278 | crq.query_capability.capability = cpu_to_be16(MAX_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4279 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4280 | ibmvnic_send_crq(adapter, &crq); |
| 4281 | |
| 4282 | crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4283 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4284 | ibmvnic_send_crq(adapter, &crq); |
| 4285 | |
| 4286 | crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4287 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4288 | ibmvnic_send_crq(adapter, &crq); |
| 4289 | |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4290 | crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION); |
| 4291 | atomic_inc(&adapter->running_cap_crqs); |
| 4292 | ibmvnic_send_crq(adapter, &crq); |
| 4293 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4294 | crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4295 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4296 | ibmvnic_send_crq(adapter, &crq); |
| 4297 | |
| 4298 | crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4299 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4300 | ibmvnic_send_crq(adapter, &crq); |
| 4301 | |
| 4302 | crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4303 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4304 | ibmvnic_send_crq(adapter, &crq); |
| 4305 | |
| 4306 | crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4307 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4308 | ibmvnic_send_crq(adapter, &crq); |
| 4309 | |
| 4310 | crq.query_capability.capability = |
| 4311 | cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4312 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4313 | ibmvnic_send_crq(adapter, &crq); |
| 4314 | |
| 4315 | crq.query_capability.capability = |
| 4316 | cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4317 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4318 | ibmvnic_send_crq(adapter, &crq); |
| 4319 | |
| 4320 | crq.query_capability.capability = |
| 4321 | cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4322 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4323 | ibmvnic_send_crq(adapter, &crq); |
| 4324 | |
| 4325 | crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4326 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4327 | ibmvnic_send_crq(adapter, &crq); |
| 4328 | } |
| 4329 | |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4330 | static void send_query_ip_offload(struct ibmvnic_adapter *adapter) |
| 4331 | { |
| 4332 | int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer); |
| 4333 | struct device *dev = &adapter->vdev->dev; |
| 4334 | union ibmvnic_crq crq; |
| 4335 | |
| 4336 | adapter->ip_offload_tok = |
| 4337 | dma_map_single(dev, |
| 4338 | &adapter->ip_offload_buf, |
| 4339 | buf_sz, |
| 4340 | DMA_FROM_DEVICE); |
| 4341 | |
| 4342 | if (dma_mapping_error(dev, adapter->ip_offload_tok)) { |
| 4343 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
| 4344 | dev_err(dev, "Couldn't map offload buffer\n"); |
| 4345 | return; |
| 4346 | } |
| 4347 | |
| 4348 | memset(&crq, 0, sizeof(crq)); |
| 4349 | crq.query_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4350 | crq.query_ip_offload.cmd = QUERY_IP_OFFLOAD; |
| 4351 | crq.query_ip_offload.len = cpu_to_be32(buf_sz); |
| 4352 | crq.query_ip_offload.ioba = |
| 4353 | cpu_to_be32(adapter->ip_offload_tok); |
| 4354 | |
| 4355 | ibmvnic_send_crq(adapter, &crq); |
| 4356 | } |
| 4357 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4358 | static void send_control_ip_offload(struct ibmvnic_adapter *adapter) |
| 4359 | { |
| 4360 | struct ibmvnic_control_ip_offload_buffer *ctrl_buf = &adapter->ip_offload_ctrl; |
| 4361 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
| 4362 | struct device *dev = &adapter->vdev->dev; |
| 4363 | netdev_features_t old_hw_features = 0; |
| 4364 | union ibmvnic_crq crq; |
| 4365 | |
| 4366 | adapter->ip_offload_ctrl_tok = |
| 4367 | dma_map_single(dev, |
| 4368 | ctrl_buf, |
| 4369 | sizeof(adapter->ip_offload_ctrl), |
| 4370 | DMA_TO_DEVICE); |
| 4371 | |
| 4372 | if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) { |
| 4373 | dev_err(dev, "Couldn't map ip offload control buffer\n"); |
| 4374 | return; |
| 4375 | } |
| 4376 | |
| 4377 | ctrl_buf->len = cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4378 | ctrl_buf->version = cpu_to_be32(INITIAL_VERSION_IOB); |
| 4379 | ctrl_buf->ipv4_chksum = buf->ipv4_chksum; |
| 4380 | ctrl_buf->ipv6_chksum = buf->ipv6_chksum; |
| 4381 | ctrl_buf->tcp_ipv4_chksum = buf->tcp_ipv4_chksum; |
| 4382 | ctrl_buf->udp_ipv4_chksum = buf->udp_ipv4_chksum; |
| 4383 | ctrl_buf->tcp_ipv6_chksum = buf->tcp_ipv6_chksum; |
| 4384 | ctrl_buf->udp_ipv6_chksum = buf->udp_ipv6_chksum; |
| 4385 | ctrl_buf->large_tx_ipv4 = buf->large_tx_ipv4; |
| 4386 | ctrl_buf->large_tx_ipv6 = buf->large_tx_ipv6; |
| 4387 | |
| 4388 | /* large_rx disabled for now, additional features needed */ |
| 4389 | ctrl_buf->large_rx_ipv4 = 0; |
| 4390 | ctrl_buf->large_rx_ipv6 = 0; |
| 4391 | |
| 4392 | if (adapter->state != VNIC_PROBING) { |
| 4393 | old_hw_features = adapter->netdev->hw_features; |
| 4394 | adapter->netdev->hw_features = 0; |
| 4395 | } |
| 4396 | |
| 4397 | adapter->netdev->hw_features = NETIF_F_SG | NETIF_F_GSO | NETIF_F_GRO; |
| 4398 | |
| 4399 | if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum) |
| 4400 | adapter->netdev->hw_features |= NETIF_F_IP_CSUM; |
| 4401 | |
| 4402 | if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum) |
| 4403 | adapter->netdev->hw_features |= NETIF_F_IPV6_CSUM; |
| 4404 | |
| 4405 | if ((adapter->netdev->features & |
| 4406 | (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))) |
| 4407 | adapter->netdev->hw_features |= NETIF_F_RXCSUM; |
| 4408 | |
| 4409 | if (buf->large_tx_ipv4) |
| 4410 | adapter->netdev->hw_features |= NETIF_F_TSO; |
| 4411 | if (buf->large_tx_ipv6) |
| 4412 | adapter->netdev->hw_features |= NETIF_F_TSO6; |
| 4413 | |
| 4414 | if (adapter->state == VNIC_PROBING) { |
| 4415 | adapter->netdev->features |= adapter->netdev->hw_features; |
| 4416 | } else if (old_hw_features != adapter->netdev->hw_features) { |
| 4417 | netdev_features_t tmp = 0; |
| 4418 | |
| 4419 | /* disable features no longer supported */ |
| 4420 | adapter->netdev->features &= adapter->netdev->hw_features; |
| 4421 | /* turn on features now supported if previously enabled */ |
| 4422 | tmp = (old_hw_features ^ adapter->netdev->hw_features) & |
| 4423 | adapter->netdev->hw_features; |
| 4424 | adapter->netdev->features |= |
| 4425 | tmp & adapter->netdev->wanted_features; |
| 4426 | } |
| 4427 | |
| 4428 | memset(&crq, 0, sizeof(crq)); |
| 4429 | crq.control_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4430 | crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD; |
| 4431 | crq.control_ip_offload.len = |
| 4432 | cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4433 | crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok); |
| 4434 | ibmvnic_send_crq(adapter, &crq); |
| 4435 | } |
| 4436 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4437 | static void handle_vpd_size_rsp(union ibmvnic_crq *crq, |
| 4438 | struct ibmvnic_adapter *adapter) |
| 4439 | { |
| 4440 | struct device *dev = &adapter->vdev->dev; |
| 4441 | |
| 4442 | if (crq->get_vpd_size_rsp.rc.code) { |
| 4443 | dev_err(dev, "Error retrieving VPD size, rc=%x\n", |
| 4444 | crq->get_vpd_size_rsp.rc.code); |
| 4445 | complete(&adapter->fw_done); |
| 4446 | return; |
| 4447 | } |
| 4448 | |
| 4449 | adapter->vpd->len = be64_to_cpu(crq->get_vpd_size_rsp.len); |
| 4450 | complete(&adapter->fw_done); |
| 4451 | } |
| 4452 | |
| 4453 | static void handle_vpd_rsp(union ibmvnic_crq *crq, |
| 4454 | struct ibmvnic_adapter *adapter) |
| 4455 | { |
| 4456 | struct device *dev = &adapter->vdev->dev; |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4457 | unsigned char *substr = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4458 | u8 fw_level_len = 0; |
| 4459 | |
| 4460 | memset(adapter->fw_version, 0, 32); |
| 4461 | |
| 4462 | dma_unmap_single(dev, adapter->vpd->dma_addr, adapter->vpd->len, |
| 4463 | DMA_FROM_DEVICE); |
| 4464 | |
| 4465 | if (crq->get_vpd_rsp.rc.code) { |
| 4466 | dev_err(dev, "Error retrieving VPD from device, rc=%x\n", |
| 4467 | crq->get_vpd_rsp.rc.code); |
| 4468 | goto complete; |
| 4469 | } |
| 4470 | |
| 4471 | /* get the position of the firmware version info |
| 4472 | * located after the ASCII 'RM' substring in the buffer |
| 4473 | */ |
| 4474 | substr = strnstr(adapter->vpd->buff, "RM", adapter->vpd->len); |
| 4475 | if (!substr) { |
Desnes Augusto Nunes do Rosario | a107311 | 2018-02-01 16:04:30 -0200 | [diff] [blame] | 4476 | 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] | 4477 | goto complete; |
| 4478 | } |
| 4479 | |
| 4480 | /* get length of firmware level ASCII substring */ |
| 4481 | if ((substr + 2) < (adapter->vpd->buff + adapter->vpd->len)) { |
| 4482 | fw_level_len = *(substr + 2); |
| 4483 | } else { |
| 4484 | dev_info(dev, "Length of FW substr extrapolated VDP buff\n"); |
| 4485 | goto complete; |
| 4486 | } |
| 4487 | |
| 4488 | /* copy firmware version string from vpd into adapter */ |
| 4489 | if ((substr + 3 + fw_level_len) < |
| 4490 | (adapter->vpd->buff + adapter->vpd->len)) { |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4491 | 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] | 4492 | } else { |
| 4493 | dev_info(dev, "FW substr extrapolated VPD buff\n"); |
| 4494 | } |
| 4495 | |
| 4496 | complete: |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4497 | if (adapter->fw_version[0] == '\0') |
Lijun Pan | 0b217d3 | 2021-06-11 13:33:53 -0500 | [diff] [blame] | 4498 | 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] | 4499 | complete(&adapter->fw_done); |
| 4500 | } |
| 4501 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4502 | static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter) |
| 4503 | { |
| 4504 | struct device *dev = &adapter->vdev->dev; |
| 4505 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4506 | int i; |
| 4507 | |
| 4508 | dma_unmap_single(dev, adapter->ip_offload_tok, |
| 4509 | sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE); |
| 4510 | |
| 4511 | netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n"); |
| 4512 | for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++) |
| 4513 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4514 | ((unsigned long *)(buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4515 | |
| 4516 | netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum); |
| 4517 | netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum); |
| 4518 | netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n", |
| 4519 | buf->tcp_ipv4_chksum); |
| 4520 | netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n", |
| 4521 | buf->tcp_ipv6_chksum); |
| 4522 | netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n", |
| 4523 | buf->udp_ipv4_chksum); |
| 4524 | netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n", |
| 4525 | buf->udp_ipv6_chksum); |
| 4526 | netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n", |
| 4527 | buf->large_tx_ipv4); |
| 4528 | netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n", |
| 4529 | buf->large_tx_ipv6); |
| 4530 | netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n", |
| 4531 | buf->large_rx_ipv4); |
| 4532 | netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n", |
| 4533 | buf->large_rx_ipv6); |
| 4534 | netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n", |
| 4535 | buf->max_ipv4_header_size); |
| 4536 | netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n", |
| 4537 | buf->max_ipv6_header_size); |
| 4538 | netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n", |
| 4539 | buf->max_tcp_header_size); |
| 4540 | netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n", |
| 4541 | buf->max_udp_header_size); |
| 4542 | netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n", |
| 4543 | buf->max_large_tx_size); |
| 4544 | netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n", |
| 4545 | buf->max_large_rx_size); |
| 4546 | netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n", |
| 4547 | buf->ipv6_extension_header); |
| 4548 | netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n", |
| 4549 | buf->tcp_pseudosum_req); |
| 4550 | netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n", |
| 4551 | buf->num_ipv6_ext_headers); |
| 4552 | netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n", |
| 4553 | buf->off_ipv6_ext_headers); |
| 4554 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4555 | send_control_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4556 | } |
| 4557 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4558 | static const char *ibmvnic_fw_err_cause(u16 cause) |
| 4559 | { |
| 4560 | switch (cause) { |
| 4561 | case ADAPTER_PROBLEM: |
| 4562 | return "adapter problem"; |
| 4563 | case BUS_PROBLEM: |
| 4564 | return "bus problem"; |
| 4565 | case FW_PROBLEM: |
| 4566 | return "firmware problem"; |
| 4567 | case DD_PROBLEM: |
| 4568 | return "device driver problem"; |
| 4569 | case EEH_RECOVERY: |
| 4570 | return "EEH recovery"; |
| 4571 | case FW_UPDATED: |
| 4572 | return "firmware updated"; |
| 4573 | case LOW_MEMORY: |
| 4574 | return "low Memory"; |
| 4575 | default: |
| 4576 | return "unknown"; |
| 4577 | } |
| 4578 | } |
| 4579 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4580 | static void handle_error_indication(union ibmvnic_crq *crq, |
| 4581 | struct ibmvnic_adapter *adapter) |
| 4582 | { |
| 4583 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4584 | u16 cause; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4585 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4586 | cause = be16_to_cpu(crq->error_indication.error_cause); |
| 4587 | |
| 4588 | dev_warn_ratelimited(dev, |
| 4589 | "Firmware reports %serror, cause: %s. Starting recovery...\n", |
| 4590 | crq->error_indication.flags |
| 4591 | & IBMVNIC_FATAL_ERROR ? "FATAL " : "", |
| 4592 | ibmvnic_fw_err_cause(cause)); |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4593 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4594 | if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR) |
| 4595 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 4596 | else |
| 4597 | ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4598 | } |
| 4599 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4600 | static int handle_change_mac_rsp(union ibmvnic_crq *crq, |
| 4601 | struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4602 | { |
| 4603 | struct net_device *netdev = adapter->netdev; |
| 4604 | struct device *dev = &adapter->vdev->dev; |
| 4605 | long rc; |
| 4606 | |
| 4607 | rc = crq->change_mac_addr_rsp.rc.code; |
| 4608 | if (rc) { |
| 4609 | dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4610 | goto out; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4611 | } |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4612 | /* crq->change_mac_addr.mac_addr is the requested one |
| 4613 | * crq->change_mac_addr_rsp.mac_addr is the returned valid one. |
| 4614 | */ |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 4615 | ether_addr_copy(netdev->dev_addr, |
| 4616 | &crq->change_mac_addr_rsp.mac_addr[0]); |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4617 | ether_addr_copy(adapter->mac_addr, |
| 4618 | &crq->change_mac_addr_rsp.mac_addr[0]); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4619 | out: |
| 4620 | complete(&adapter->fw_done); |
| 4621 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | static void handle_request_cap_rsp(union ibmvnic_crq *crq, |
| 4625 | struct ibmvnic_adapter *adapter) |
| 4626 | { |
| 4627 | struct device *dev = &adapter->vdev->dev; |
| 4628 | u64 *req_value; |
| 4629 | char *name; |
| 4630 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4631 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4632 | switch (be16_to_cpu(crq->request_capability_rsp.capability)) { |
| 4633 | case REQ_TX_QUEUES: |
| 4634 | req_value = &adapter->req_tx_queues; |
| 4635 | name = "tx"; |
| 4636 | break; |
| 4637 | case REQ_RX_QUEUES: |
| 4638 | req_value = &adapter->req_rx_queues; |
| 4639 | name = "rx"; |
| 4640 | break; |
| 4641 | case REQ_RX_ADD_QUEUES: |
| 4642 | req_value = &adapter->req_rx_add_queues; |
| 4643 | name = "rx_add"; |
| 4644 | break; |
| 4645 | case REQ_TX_ENTRIES_PER_SUBCRQ: |
| 4646 | req_value = &adapter->req_tx_entries_per_subcrq; |
| 4647 | name = "tx_entries_per_subcrq"; |
| 4648 | break; |
| 4649 | case REQ_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4650 | req_value = &adapter->req_rx_add_entries_per_subcrq; |
| 4651 | name = "rx_add_entries_per_subcrq"; |
| 4652 | break; |
| 4653 | case REQ_MTU: |
| 4654 | req_value = &adapter->req_mtu; |
| 4655 | name = "mtu"; |
| 4656 | break; |
| 4657 | case PROMISC_REQUESTED: |
| 4658 | req_value = &adapter->promisc; |
| 4659 | name = "promisc"; |
| 4660 | break; |
| 4661 | default: |
| 4662 | dev_err(dev, "Got invalid cap request rsp %d\n", |
| 4663 | crq->request_capability.capability); |
| 4664 | return; |
| 4665 | } |
| 4666 | |
| 4667 | switch (crq->request_capability_rsp.rc.code) { |
| 4668 | case SUCCESS: |
| 4669 | break; |
| 4670 | case PARTIALSUCCESS: |
| 4671 | dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n", |
| 4672 | *req_value, |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4673 | (long)be64_to_cpu(crq->request_capability_rsp.number), |
| 4674 | name); |
John Allen | e791380 | 2018-01-18 16:27:12 -0600 | [diff] [blame] | 4675 | |
| 4676 | if (be16_to_cpu(crq->request_capability_rsp.capability) == |
| 4677 | REQ_MTU) { |
| 4678 | pr_err("mtu of %llu is not supported. Reverting.\n", |
| 4679 | *req_value); |
| 4680 | *req_value = adapter->fallback.mtu; |
| 4681 | } else { |
| 4682 | *req_value = |
| 4683 | be64_to_cpu(crq->request_capability_rsp.number); |
| 4684 | } |
| 4685 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 4686 | send_request_cap(adapter, 1); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4687 | return; |
| 4688 | default: |
| 4689 | dev_err(dev, "Error %d in request cap rsp\n", |
| 4690 | crq->request_capability_rsp.rc.code); |
| 4691 | return; |
| 4692 | } |
| 4693 | |
| 4694 | /* Done receiving requested capabilities, query IP offload support */ |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4695 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4696 | adapter->wait_capability = false; |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4697 | send_query_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | |
| 4701 | static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, |
| 4702 | struct ibmvnic_adapter *adapter) |
| 4703 | { |
| 4704 | struct device *dev = &adapter->vdev->dev; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4705 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4706 | struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf; |
| 4707 | struct ibmvnic_login_buffer *login = adapter->login_buf; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4708 | u64 *tx_handle_array; |
| 4709 | u64 *rx_handle_array; |
| 4710 | int num_tx_pools; |
| 4711 | int num_rx_pools; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4712 | u64 *size_array; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4713 | int i; |
| 4714 | |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4715 | /* CHECK: Test/set of login_pending does not need to be atomic |
| 4716 | * because only ibmvnic_tasklet tests/clears this. |
| 4717 | */ |
| 4718 | if (!adapter->login_pending) { |
| 4719 | netdev_warn(netdev, "Ignoring unexpected login response\n"); |
| 4720 | return 0; |
| 4721 | } |
| 4722 | adapter->login_pending = false; |
| 4723 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4724 | dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4725 | DMA_TO_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4726 | dma_unmap_single(dev, adapter->login_rsp_buf_token, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4727 | adapter->login_rsp_buf_sz, DMA_FROM_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4728 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4729 | /* If the number of queues requested can't be allocated by the |
| 4730 | * server, the login response will return with code 1. We will need |
| 4731 | * to resend the login buffer with fewer queues requested. |
| 4732 | */ |
| 4733 | if (login_rsp_crq->generic.rc.code) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 4734 | adapter->init_done_rc = login_rsp_crq->generic.rc.code; |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4735 | complete(&adapter->init_done); |
| 4736 | return 0; |
| 4737 | } |
| 4738 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4739 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 4740 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4741 | netdev_dbg(adapter->netdev, "Login Response Buffer:\n"); |
| 4742 | for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) { |
| 4743 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4744 | ((unsigned long *)(adapter->login_rsp_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | /* Sanity checks */ |
| 4748 | if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs || |
| 4749 | (be32_to_cpu(login->num_rxcomp_subcrqs) * |
| 4750 | adapter->req_rx_add_queues != |
| 4751 | be32_to_cpu(login_rsp->num_rxadd_subcrqs))) { |
| 4752 | dev_err(dev, "FATAL: Inconsistent login and login rsp\n"); |
Dany Madden | 31d6b40 | 2020-11-25 18:04:24 -0600 | [diff] [blame] | 4753 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4754 | return -EIO; |
| 4755 | } |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4756 | size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4757 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size)); |
| 4758 | /* variable buffer sizes are not supported, so just read the |
| 4759 | * first entry. |
| 4760 | */ |
| 4761 | adapter->cur_rx_buf_sz = be64_to_cpu(size_array[0]); |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4762 | |
| 4763 | num_tx_pools = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 4764 | num_rx_pools = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 4765 | |
| 4766 | tx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4767 | be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs)); |
| 4768 | rx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4769 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_subcrqs)); |
| 4770 | |
| 4771 | for (i = 0; i < num_tx_pools; i++) |
| 4772 | adapter->tx_scrq[i]->handle = tx_handle_array[i]; |
| 4773 | |
| 4774 | for (i = 0; i < num_rx_pools; i++) |
| 4775 | adapter->rx_scrq[i]->handle = rx_handle_array[i]; |
| 4776 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4777 | adapter->num_active_tx_scrqs = num_tx_pools; |
| 4778 | adapter->num_active_rx_scrqs = num_rx_pools; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4779 | release_login_rsp_buffer(adapter); |
Thomas Falcon | a2c0f03 | 2018-02-21 18:18:30 -0600 | [diff] [blame] | 4780 | release_login_buffer(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4781 | complete(&adapter->init_done); |
| 4782 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4783 | return 0; |
| 4784 | } |
| 4785 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4786 | static void handle_request_unmap_rsp(union ibmvnic_crq *crq, |
| 4787 | struct ibmvnic_adapter *adapter) |
| 4788 | { |
| 4789 | struct device *dev = &adapter->vdev->dev; |
| 4790 | long rc; |
| 4791 | |
| 4792 | rc = crq->request_unmap_rsp.rc.code; |
| 4793 | if (rc) |
| 4794 | dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc); |
| 4795 | } |
| 4796 | |
| 4797 | static void handle_query_map_rsp(union ibmvnic_crq *crq, |
| 4798 | struct ibmvnic_adapter *adapter) |
| 4799 | { |
| 4800 | struct net_device *netdev = adapter->netdev; |
| 4801 | struct device *dev = &adapter->vdev->dev; |
| 4802 | long rc; |
| 4803 | |
| 4804 | rc = crq->query_map_rsp.rc.code; |
| 4805 | if (rc) { |
| 4806 | dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc); |
| 4807 | return; |
| 4808 | } |
Sukadev Bhattiprolu | 0f2bf31 | 2021-09-14 20:52:52 -0700 | [diff] [blame] | 4809 | netdev_dbg(netdev, "page_size = %d\ntot_pages = %u\nfree_pages = %u\n", |
| 4810 | crq->query_map_rsp.page_size, |
| 4811 | __be32_to_cpu(crq->query_map_rsp.tot_pages), |
| 4812 | __be32_to_cpu(crq->query_map_rsp.free_pages)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | static void handle_query_cap_rsp(union ibmvnic_crq *crq, |
| 4816 | struct ibmvnic_adapter *adapter) |
| 4817 | { |
| 4818 | struct net_device *netdev = adapter->netdev; |
| 4819 | struct device *dev = &adapter->vdev->dev; |
| 4820 | long rc; |
| 4821 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4822 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4823 | netdev_dbg(netdev, "Outstanding queries: %d\n", |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4824 | atomic_read(&adapter->running_cap_crqs)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4825 | rc = crq->query_capability.rc.code; |
| 4826 | if (rc) { |
| 4827 | dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc); |
| 4828 | goto out; |
| 4829 | } |
| 4830 | |
| 4831 | switch (be16_to_cpu(crq->query_capability.capability)) { |
| 4832 | case MIN_TX_QUEUES: |
| 4833 | adapter->min_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4834 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4835 | netdev_dbg(netdev, "min_tx_queues = %lld\n", |
| 4836 | adapter->min_tx_queues); |
| 4837 | break; |
| 4838 | case MIN_RX_QUEUES: |
| 4839 | adapter->min_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4840 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4841 | netdev_dbg(netdev, "min_rx_queues = %lld\n", |
| 4842 | adapter->min_rx_queues); |
| 4843 | break; |
| 4844 | case MIN_RX_ADD_QUEUES: |
| 4845 | adapter->min_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4846 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4847 | netdev_dbg(netdev, "min_rx_add_queues = %lld\n", |
| 4848 | adapter->min_rx_add_queues); |
| 4849 | break; |
| 4850 | case MAX_TX_QUEUES: |
| 4851 | adapter->max_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4852 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4853 | netdev_dbg(netdev, "max_tx_queues = %lld\n", |
| 4854 | adapter->max_tx_queues); |
| 4855 | break; |
| 4856 | case MAX_RX_QUEUES: |
| 4857 | adapter->max_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4858 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4859 | netdev_dbg(netdev, "max_rx_queues = %lld\n", |
| 4860 | adapter->max_rx_queues); |
| 4861 | break; |
| 4862 | case MAX_RX_ADD_QUEUES: |
| 4863 | adapter->max_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4864 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4865 | netdev_dbg(netdev, "max_rx_add_queues = %lld\n", |
| 4866 | adapter->max_rx_add_queues); |
| 4867 | break; |
| 4868 | case MIN_TX_ENTRIES_PER_SUBCRQ: |
| 4869 | adapter->min_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4870 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4871 | netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n", |
| 4872 | adapter->min_tx_entries_per_subcrq); |
| 4873 | break; |
| 4874 | case MIN_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4875 | adapter->min_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4876 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4877 | netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n", |
| 4878 | adapter->min_rx_add_entries_per_subcrq); |
| 4879 | break; |
| 4880 | case MAX_TX_ENTRIES_PER_SUBCRQ: |
| 4881 | adapter->max_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4882 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4883 | netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n", |
| 4884 | adapter->max_tx_entries_per_subcrq); |
| 4885 | break; |
| 4886 | case MAX_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4887 | adapter->max_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4888 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4889 | netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n", |
| 4890 | adapter->max_rx_add_entries_per_subcrq); |
| 4891 | break; |
| 4892 | case TCP_IP_OFFLOAD: |
| 4893 | adapter->tcp_ip_offload = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4894 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4895 | netdev_dbg(netdev, "tcp_ip_offload = %lld\n", |
| 4896 | adapter->tcp_ip_offload); |
| 4897 | break; |
| 4898 | case PROMISC_SUPPORTED: |
| 4899 | adapter->promisc_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4900 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4901 | netdev_dbg(netdev, "promisc_supported = %lld\n", |
| 4902 | adapter->promisc_supported); |
| 4903 | break; |
| 4904 | case MIN_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4905 | adapter->min_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 4906 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4907 | netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu); |
| 4908 | break; |
| 4909 | case MAX_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4910 | adapter->max_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 4911 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4912 | netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu); |
| 4913 | break; |
| 4914 | case MAX_MULTICAST_FILTERS: |
| 4915 | adapter->max_multicast_filters = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4916 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4917 | netdev_dbg(netdev, "max_multicast_filters = %lld\n", |
| 4918 | adapter->max_multicast_filters); |
| 4919 | break; |
| 4920 | case VLAN_HEADER_INSERTION: |
| 4921 | adapter->vlan_header_insertion = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4922 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4923 | if (adapter->vlan_header_insertion) |
| 4924 | netdev->features |= NETIF_F_HW_VLAN_STAG_TX; |
| 4925 | netdev_dbg(netdev, "vlan_header_insertion = %lld\n", |
| 4926 | adapter->vlan_header_insertion); |
| 4927 | break; |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4928 | case RX_VLAN_HEADER_INSERTION: |
| 4929 | adapter->rx_vlan_header_insertion = |
| 4930 | be64_to_cpu(crq->query_capability.number); |
| 4931 | netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n", |
| 4932 | adapter->rx_vlan_header_insertion); |
| 4933 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4934 | case MAX_TX_SG_ENTRIES: |
| 4935 | adapter->max_tx_sg_entries = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4936 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4937 | netdev_dbg(netdev, "max_tx_sg_entries = %lld\n", |
| 4938 | adapter->max_tx_sg_entries); |
| 4939 | break; |
| 4940 | case RX_SG_SUPPORTED: |
| 4941 | adapter->rx_sg_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4942 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4943 | netdev_dbg(netdev, "rx_sg_supported = %lld\n", |
| 4944 | adapter->rx_sg_supported); |
| 4945 | break; |
| 4946 | case OPT_TX_COMP_SUB_QUEUES: |
| 4947 | adapter->opt_tx_comp_sub_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4948 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4949 | netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n", |
| 4950 | adapter->opt_tx_comp_sub_queues); |
| 4951 | break; |
| 4952 | case OPT_RX_COMP_QUEUES: |
| 4953 | adapter->opt_rx_comp_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4954 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4955 | netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n", |
| 4956 | adapter->opt_rx_comp_queues); |
| 4957 | break; |
| 4958 | case OPT_RX_BUFADD_Q_PER_RX_COMP_Q: |
| 4959 | adapter->opt_rx_bufadd_q_per_rx_comp_q = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4960 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4961 | netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n", |
| 4962 | adapter->opt_rx_bufadd_q_per_rx_comp_q); |
| 4963 | break; |
| 4964 | case OPT_TX_ENTRIES_PER_SUBCRQ: |
| 4965 | adapter->opt_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4966 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4967 | netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n", |
| 4968 | adapter->opt_tx_entries_per_subcrq); |
| 4969 | break; |
| 4970 | case OPT_RXBA_ENTRIES_PER_SUBCRQ: |
| 4971 | adapter->opt_rxba_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4972 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4973 | netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n", |
| 4974 | adapter->opt_rxba_entries_per_subcrq); |
| 4975 | break; |
| 4976 | case TX_RX_DESC_REQ: |
| 4977 | adapter->tx_rx_desc_req = crq->query_capability.number; |
| 4978 | netdev_dbg(netdev, "tx_rx_desc_req = %llx\n", |
| 4979 | adapter->tx_rx_desc_req); |
| 4980 | break; |
| 4981 | |
| 4982 | default: |
| 4983 | netdev_err(netdev, "Got invalid cap rsp %d\n", |
| 4984 | crq->query_capability.capability); |
| 4985 | } |
| 4986 | |
| 4987 | out: |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4988 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
| 4989 | adapter->wait_capability = false; |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 4990 | send_request_cap(adapter, 0); |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4991 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4992 | } |
| 4993 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4994 | static int send_query_phys_parms(struct ibmvnic_adapter *adapter) |
| 4995 | { |
| 4996 | union ibmvnic_crq crq; |
| 4997 | int rc; |
| 4998 | |
| 4999 | memset(&crq, 0, sizeof(crq)); |
| 5000 | crq.query_phys_parms.first = IBMVNIC_CRQ_CMD; |
| 5001 | crq.query_phys_parms.cmd = QUERY_PHYS_PARMS; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5002 | |
| 5003 | mutex_lock(&adapter->fw_lock); |
| 5004 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 5005 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5006 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5007 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5008 | if (rc) { |
| 5009 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5010 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5011 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5012 | |
| 5013 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5014 | if (rc) { |
| 5015 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5016 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5017 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 5018 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5019 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5020 | return adapter->fw_done_rc ? -EIO : 0; |
| 5021 | } |
| 5022 | |
| 5023 | static int handle_query_phys_parms_rsp(union ibmvnic_crq *crq, |
| 5024 | struct ibmvnic_adapter *adapter) |
| 5025 | { |
| 5026 | struct net_device *netdev = adapter->netdev; |
| 5027 | int rc; |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5028 | __be32 rspeed = cpu_to_be32(crq->query_phys_parms_rsp.speed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5029 | |
| 5030 | rc = crq->query_phys_parms_rsp.rc.code; |
| 5031 | if (rc) { |
| 5032 | netdev_err(netdev, "Error %d in QUERY_PHYS_PARMS\n", rc); |
| 5033 | return rc; |
| 5034 | } |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5035 | switch (rspeed) { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5036 | case IBMVNIC_10MBPS: |
| 5037 | adapter->speed = SPEED_10; |
| 5038 | break; |
| 5039 | case IBMVNIC_100MBPS: |
| 5040 | adapter->speed = SPEED_100; |
| 5041 | break; |
| 5042 | case IBMVNIC_1GBPS: |
| 5043 | adapter->speed = SPEED_1000; |
| 5044 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 5045 | case IBMVNIC_10GBPS: |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5046 | adapter->speed = SPEED_10000; |
| 5047 | break; |
| 5048 | case IBMVNIC_25GBPS: |
| 5049 | adapter->speed = SPEED_25000; |
| 5050 | break; |
| 5051 | case IBMVNIC_40GBPS: |
| 5052 | adapter->speed = SPEED_40000; |
| 5053 | break; |
| 5054 | case IBMVNIC_50GBPS: |
| 5055 | adapter->speed = SPEED_50000; |
| 5056 | break; |
| 5057 | case IBMVNIC_100GBPS: |
| 5058 | adapter->speed = SPEED_100000; |
| 5059 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 5060 | case IBMVNIC_200GBPS: |
| 5061 | adapter->speed = SPEED_200000; |
| 5062 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5063 | default: |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 5064 | if (netif_carrier_ok(netdev)) |
| 5065 | netdev_warn(netdev, "Unknown speed 0x%08x\n", rspeed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5066 | adapter->speed = SPEED_UNKNOWN; |
| 5067 | } |
| 5068 | if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_FULL_DUPLEX) |
| 5069 | adapter->duplex = DUPLEX_FULL; |
| 5070 | else if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_HALF_DUPLEX) |
| 5071 | adapter->duplex = DUPLEX_HALF; |
| 5072 | else |
| 5073 | adapter->duplex = DUPLEX_UNKNOWN; |
| 5074 | |
| 5075 | return rc; |
| 5076 | } |
| 5077 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5078 | static void ibmvnic_handle_crq(union ibmvnic_crq *crq, |
| 5079 | struct ibmvnic_adapter *adapter) |
| 5080 | { |
| 5081 | struct ibmvnic_generic_crq *gen_crq = &crq->generic; |
| 5082 | struct net_device *netdev = adapter->netdev; |
| 5083 | struct device *dev = &adapter->vdev->dev; |
Murilo Fossa Vicentini | 993a82b | 2017-04-19 13:44:35 -0400 | [diff] [blame] | 5084 | u64 *u64_crq = (u64 *)crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5085 | long rc; |
| 5086 | |
| 5087 | netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 5088 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 5089 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5090 | switch (gen_crq->first) { |
| 5091 | case IBMVNIC_CRQ_INIT_RSP: |
| 5092 | switch (gen_crq->cmd) { |
| 5093 | case IBMVNIC_CRQ_INIT: |
| 5094 | dev_info(dev, "Partner initialized\n"); |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5095 | adapter->from_passive_init = true; |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 5096 | /* Discard any stale login responses from prev reset. |
| 5097 | * CHECK: should we clear even on INIT_COMPLETE? |
| 5098 | */ |
| 5099 | adapter->login_pending = false; |
| 5100 | |
Thomas Falcon | 17c8705 | 2018-05-23 13:37:58 -0500 | [diff] [blame] | 5101 | if (!completion_done(&adapter->init_done)) { |
| 5102 | complete(&adapter->init_done); |
| 5103 | adapter->init_done_rc = -EIO; |
| 5104 | } |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5105 | |
| 5106 | if (adapter->state == VNIC_DOWN) |
| 5107 | rc = ibmvnic_reset(adapter, VNIC_RESET_PASSIVE_INIT); |
| 5108 | else |
| 5109 | rc = ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
| 5110 | |
Sukadev Bhattiprolu | ef66a1e | 2021-02-02 21:08:02 -0800 | [diff] [blame] | 5111 | if (rc && rc != -EBUSY) { |
| 5112 | /* We were unable to schedule the failover |
| 5113 | * reset either because the adapter was still |
| 5114 | * probing (eg: during kexec) or we could not |
| 5115 | * allocate memory. Clear the failover_pending |
| 5116 | * flag since no one else will. We ignore |
| 5117 | * EBUSY because it means either FAILOVER reset |
| 5118 | * is already scheduled or the adapter is |
| 5119 | * being removed. |
| 5120 | */ |
| 5121 | netdev_err(netdev, |
| 5122 | "Error %ld scheduling failover reset\n", |
| 5123 | rc); |
| 5124 | adapter->failover_pending = false; |
| 5125 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5126 | break; |
| 5127 | case IBMVNIC_CRQ_INIT_COMPLETE: |
| 5128 | dev_info(dev, "Partner initialization complete\n"); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5129 | adapter->crq.active = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5130 | send_version_xchg(adapter); |
| 5131 | break; |
| 5132 | default: |
| 5133 | dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd); |
| 5134 | } |
| 5135 | return; |
| 5136 | case IBMVNIC_CRQ_XPORT_EVENT: |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5137 | netif_carrier_off(netdev); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5138 | adapter->crq.active = false; |
Thomas Falcon | 2147e3d | 2019-11-25 17:12:54 -0600 | [diff] [blame] | 5139 | /* terminate any thread waiting for a response |
| 5140 | * from the device |
| 5141 | */ |
| 5142 | if (!completion_done(&adapter->fw_done)) { |
| 5143 | adapter->fw_done_rc = -EIO; |
| 5144 | complete(&adapter->fw_done); |
| 5145 | } |
| 5146 | if (!completion_done(&adapter->stats_done)) |
| 5147 | complete(&adapter->stats_done); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5148 | if (test_bit(0, &adapter->resetting)) |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 5149 | adapter->force_reset_recovery = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5150 | if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5151 | dev_info(dev, "Migrated, re-enabling adapter\n"); |
| 5152 | ibmvnic_reset(adapter, VNIC_RESET_MOBILITY); |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 5153 | } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { |
| 5154 | dev_info(dev, "Backing device failover detected\n"); |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 5155 | adapter->failover_pending = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5156 | } else { |
| 5157 | /* The adapter lost the connection */ |
| 5158 | dev_err(dev, "Virtual Adapter failed (rc=%d)\n", |
| 5159 | gen_crq->cmd); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5160 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5161 | } |
| 5162 | return; |
| 5163 | case IBMVNIC_CRQ_CMD_RSP: |
| 5164 | break; |
| 5165 | default: |
| 5166 | dev_err(dev, "Got an invalid msg type 0x%02x\n", |
| 5167 | gen_crq->first); |
| 5168 | return; |
| 5169 | } |
| 5170 | |
| 5171 | switch (gen_crq->cmd) { |
| 5172 | case VERSION_EXCHANGE_RSP: |
| 5173 | rc = crq->version_exchange_rsp.rc.code; |
| 5174 | if (rc) { |
| 5175 | dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc); |
| 5176 | break; |
| 5177 | } |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 5178 | ibmvnic_version = |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5179 | be16_to_cpu(crq->version_exchange_rsp.version); |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 5180 | dev_info(dev, "Partner protocol version is %d\n", |
| 5181 | ibmvnic_version); |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 5182 | send_query_cap(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5183 | break; |
| 5184 | case QUERY_CAPABILITY_RSP: |
| 5185 | handle_query_cap_rsp(crq, adapter); |
| 5186 | break; |
| 5187 | case QUERY_MAP_RSP: |
| 5188 | handle_query_map_rsp(crq, adapter); |
| 5189 | break; |
| 5190 | case REQUEST_MAP_RSP: |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 5191 | adapter->fw_done_rc = crq->request_map_rsp.rc.code; |
| 5192 | complete(&adapter->fw_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5193 | break; |
| 5194 | case REQUEST_UNMAP_RSP: |
| 5195 | handle_request_unmap_rsp(crq, adapter); |
| 5196 | break; |
| 5197 | case REQUEST_CAPABILITY_RSP: |
| 5198 | handle_request_cap_rsp(crq, adapter); |
| 5199 | break; |
| 5200 | case LOGIN_RSP: |
| 5201 | netdev_dbg(netdev, "Got Login Response\n"); |
| 5202 | handle_login_rsp(crq, adapter); |
| 5203 | break; |
| 5204 | case LOGICAL_LINK_STATE_RSP: |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 5205 | netdev_dbg(netdev, |
| 5206 | "Got Logical Link State Response, state: %d rc: %d\n", |
| 5207 | crq->logical_link_state_rsp.link_state, |
| 5208 | crq->logical_link_state_rsp.rc.code); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5209 | adapter->logical_link_state = |
| 5210 | crq->logical_link_state_rsp.link_state; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 5211 | adapter->init_done_rc = crq->logical_link_state_rsp.rc.code; |
| 5212 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5213 | break; |
| 5214 | case LINK_STATE_INDICATION: |
| 5215 | netdev_dbg(netdev, "Got Logical Link State Indication\n"); |
| 5216 | adapter->phys_link_state = |
| 5217 | crq->link_state_indication.phys_link_state; |
| 5218 | adapter->logical_link_state = |
| 5219 | crq->link_state_indication.logical_link_state; |
Thomas Falcon | 0655f99 | 2019-05-09 23:13:44 -0500 | [diff] [blame] | 5220 | if (adapter->phys_link_state && adapter->logical_link_state) |
| 5221 | netif_carrier_on(netdev); |
| 5222 | else |
| 5223 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5224 | break; |
| 5225 | case CHANGE_MAC_ADDR_RSP: |
| 5226 | netdev_dbg(netdev, "Got MAC address change Response\n"); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 5227 | adapter->fw_done_rc = handle_change_mac_rsp(crq, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5228 | break; |
| 5229 | case ERROR_INDICATION: |
| 5230 | netdev_dbg(netdev, "Got Error Indication\n"); |
| 5231 | handle_error_indication(crq, adapter); |
| 5232 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5233 | case REQUEST_STATISTICS_RSP: |
| 5234 | netdev_dbg(netdev, "Got Statistics Response\n"); |
| 5235 | complete(&adapter->stats_done); |
| 5236 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5237 | case QUERY_IP_OFFLOAD_RSP: |
| 5238 | netdev_dbg(netdev, "Got Query IP offload Response\n"); |
| 5239 | handle_query_ip_offload_rsp(adapter); |
| 5240 | break; |
| 5241 | case MULTICAST_CTRL_RSP: |
| 5242 | netdev_dbg(netdev, "Got multicast control Response\n"); |
| 5243 | break; |
| 5244 | case CONTROL_IP_OFFLOAD_RSP: |
| 5245 | netdev_dbg(netdev, "Got Control IP offload Response\n"); |
| 5246 | dma_unmap_single(dev, adapter->ip_offload_ctrl_tok, |
| 5247 | sizeof(adapter->ip_offload_ctrl), |
| 5248 | DMA_TO_DEVICE); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 5249 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5250 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5251 | case COLLECT_FW_TRACE_RSP: |
| 5252 | netdev_dbg(netdev, "Got Collect firmware trace Response\n"); |
| 5253 | complete(&adapter->fw_done); |
| 5254 | break; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 5255 | case GET_VPD_SIZE_RSP: |
| 5256 | handle_vpd_size_rsp(crq, adapter); |
| 5257 | break; |
| 5258 | case GET_VPD_RSP: |
| 5259 | handle_vpd_rsp(crq, adapter); |
| 5260 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5261 | case QUERY_PHYS_PARMS_RSP: |
| 5262 | adapter->fw_done_rc = handle_query_phys_parms_rsp(crq, adapter); |
| 5263 | complete(&adapter->fw_done); |
| 5264 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5265 | default: |
| 5266 | netdev_err(netdev, "Got an invalid cmd type 0x%02x\n", |
| 5267 | gen_crq->cmd); |
| 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | static irqreturn_t ibmvnic_interrupt(int irq, void *instance) |
| 5272 | { |
| 5273 | struct ibmvnic_adapter *adapter = instance; |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5274 | |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5275 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5276 | return IRQ_HANDLED; |
| 5277 | } |
| 5278 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5279 | static void ibmvnic_tasklet(struct tasklet_struct *t) |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5280 | { |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5281 | struct ibmvnic_adapter *adapter = from_tasklet(adapter, t, tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5282 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5283 | union ibmvnic_crq *crq; |
| 5284 | unsigned long flags; |
| 5285 | bool done = false; |
| 5286 | |
| 5287 | spin_lock_irqsave(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5288 | while (!done) { |
| 5289 | /* Pull all the valid messages off the CRQ */ |
| 5290 | while ((crq = ibmvnic_next_crq(adapter)) != NULL) { |
Lijun Pan | e41aec7 | 2021-01-27 19:34:42 -0600 | [diff] [blame] | 5291 | /* This barrier makes sure ibmvnic_next_crq()'s |
| 5292 | * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded |
| 5293 | * before ibmvnic_handle_crq()'s |
| 5294 | * switch(gen_crq->first) and switch(gen_crq->cmd). |
| 5295 | */ |
| 5296 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5297 | ibmvnic_handle_crq(crq, adapter); |
| 5298 | crq->generic.first = 0; |
| 5299 | } |
Brian King | ed7ecbf | 2017-04-19 13:44:53 -0400 | [diff] [blame] | 5300 | |
| 5301 | /* remain in tasklet until all |
| 5302 | * capabilities responses are received |
| 5303 | */ |
| 5304 | if (!adapter->wait_capability) |
| 5305 | done = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5306 | } |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 5307 | /* if capabilities CRQ's were sent in this tasklet, the following |
| 5308 | * tasklet must wait until all responses are received |
| 5309 | */ |
| 5310 | if (atomic_read(&adapter->running_cap_crqs) != 0) |
| 5311 | adapter->wait_capability = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5312 | spin_unlock_irqrestore(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter) |
| 5316 | { |
| 5317 | struct vio_dev *vdev = adapter->vdev; |
| 5318 | int rc; |
| 5319 | |
| 5320 | do { |
| 5321 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); |
| 5322 | } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5323 | |
| 5324 | if (rc) |
| 5325 | dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc); |
| 5326 | |
| 5327 | return rc; |
| 5328 | } |
| 5329 | |
| 5330 | static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter) |
| 5331 | { |
| 5332 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5333 | struct device *dev = &adapter->vdev->dev; |
| 5334 | struct vio_dev *vdev = adapter->vdev; |
| 5335 | int rc; |
| 5336 | |
| 5337 | /* Close the CRQ */ |
| 5338 | do { |
| 5339 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5340 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5341 | |
| 5342 | /* Clean out the queue */ |
Lijun Pan | 0e435be | 2020-11-23 13:35:46 -0600 | [diff] [blame] | 5343 | if (!crq->msgs) |
| 5344 | return -EINVAL; |
| 5345 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5346 | memset(crq->msgs, 0, PAGE_SIZE); |
| 5347 | crq->cur = 0; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5348 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5349 | |
| 5350 | /* And re-open it again */ |
| 5351 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5352 | crq->msg_token, PAGE_SIZE); |
| 5353 | |
| 5354 | if (rc == H_CLOSED) |
| 5355 | /* Adapter is good, but other end is not ready */ |
| 5356 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5357 | else if (rc != 0) |
| 5358 | dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc); |
| 5359 | |
| 5360 | return rc; |
| 5361 | } |
| 5362 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5363 | static void release_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5364 | { |
| 5365 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5366 | struct vio_dev *vdev = adapter->vdev; |
| 5367 | long rc; |
| 5368 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5369 | if (!crq->msgs) |
| 5370 | return; |
| 5371 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5372 | netdev_dbg(adapter->netdev, "Releasing CRQ\n"); |
| 5373 | free_irq(vdev->irq, adapter); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5374 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5375 | do { |
| 5376 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5377 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5378 | |
| 5379 | dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE, |
| 5380 | DMA_BIDIRECTIONAL); |
| 5381 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5382 | crq->msgs = NULL; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5383 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5384 | } |
| 5385 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5386 | static int init_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5387 | { |
| 5388 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5389 | struct device *dev = &adapter->vdev->dev; |
| 5390 | struct vio_dev *vdev = adapter->vdev; |
| 5391 | int rc, retrc = -ENOMEM; |
| 5392 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5393 | if (crq->msgs) |
| 5394 | return 0; |
| 5395 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5396 | crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL); |
| 5397 | /* Should we allocate more than one page? */ |
| 5398 | |
| 5399 | if (!crq->msgs) |
| 5400 | return -ENOMEM; |
| 5401 | |
| 5402 | crq->size = PAGE_SIZE / sizeof(*crq->msgs); |
| 5403 | crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE, |
| 5404 | DMA_BIDIRECTIONAL); |
| 5405 | if (dma_mapping_error(dev, crq->msg_token)) |
| 5406 | goto map_failed; |
| 5407 | |
| 5408 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5409 | crq->msg_token, PAGE_SIZE); |
| 5410 | |
| 5411 | if (rc == H_RESOURCE) |
| 5412 | /* maybe kexecing and resource is busy. try a reset */ |
| 5413 | rc = ibmvnic_reset_crq(adapter); |
| 5414 | retrc = rc; |
| 5415 | |
| 5416 | if (rc == H_CLOSED) { |
| 5417 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5418 | } else if (rc) { |
| 5419 | dev_warn(dev, "Error %d opening adapter\n", rc); |
| 5420 | goto reg_crq_failed; |
| 5421 | } |
| 5422 | |
| 5423 | retrc = 0; |
| 5424 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5425 | tasklet_setup(&adapter->tasklet, (void *)ibmvnic_tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5426 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5427 | netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq); |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 5428 | snprintf(crq->name, sizeof(crq->name), "ibmvnic-%x", |
| 5429 | adapter->vdev->unit_address); |
| 5430 | rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, crq->name, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5431 | if (rc) { |
| 5432 | dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", |
| 5433 | vdev->irq, rc); |
| 5434 | goto req_irq_failed; |
| 5435 | } |
| 5436 | |
| 5437 | rc = vio_enable_interrupts(vdev); |
| 5438 | if (rc) { |
| 5439 | dev_err(dev, "Error %d enabling interrupts\n", rc); |
| 5440 | goto req_irq_failed; |
| 5441 | } |
| 5442 | |
| 5443 | crq->cur = 0; |
| 5444 | spin_lock_init(&crq->lock); |
| 5445 | |
| 5446 | return retrc; |
| 5447 | |
| 5448 | req_irq_failed: |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5449 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5450 | do { |
| 5451 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5452 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5453 | reg_crq_failed: |
| 5454 | dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 5455 | map_failed: |
| 5456 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5457 | crq->msgs = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5458 | return retrc; |
| 5459 | } |
| 5460 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5461 | static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter, bool reset) |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5462 | { |
| 5463 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 5464 | unsigned long timeout = msecs_to_jiffies(20000); |
Michal Suchanek | 6881b07 | 2021-03-02 20:47:47 +0100 | [diff] [blame] | 5465 | u64 old_num_rx_queues = adapter->req_rx_queues; |
| 5466 | u64 old_num_tx_queues = adapter->req_tx_queues; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5467 | int rc; |
| 5468 | |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5469 | adapter->from_passive_init = false; |
| 5470 | |
Michal Suchanek | 6881b07 | 2021-03-02 20:47:47 +0100 | [diff] [blame] | 5471 | if (reset) |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5472 | reinit_completion(&adapter->init_done); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5473 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5474 | adapter->init_done_rc = 0; |
Lijun Pan | fa68bfa | 2020-08-19 17:52:24 -0500 | [diff] [blame] | 5475 | rc = ibmvnic_send_crq_init(adapter); |
| 5476 | if (rc) { |
| 5477 | dev_err(dev, "Send crq init failed with error %d\n", rc); |
| 5478 | return rc; |
| 5479 | } |
| 5480 | |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5481 | if (!wait_for_completion_timeout(&adapter->init_done, timeout)) { |
| 5482 | dev_err(dev, "Initialization sequence timed out\n"); |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5483 | return -1; |
| 5484 | } |
| 5485 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5486 | if (adapter->init_done_rc) { |
| 5487 | release_crq_queue(adapter); |
| 5488 | return adapter->init_done_rc; |
| 5489 | } |
| 5490 | |
Lijun Pan | 785a2b1 | 2020-09-17 21:12:46 -0500 | [diff] [blame] | 5491 | if (adapter->from_passive_init) { |
| 5492 | adapter->state = VNIC_OPEN; |
| 5493 | adapter->from_passive_init = false; |
| 5494 | return -1; |
| 5495 | } |
| 5496 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5497 | if (reset && |
| 5498 | test_bit(0, &adapter->resetting) && !adapter->wait_for_reset && |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 5499 | adapter->reset_reason != VNIC_RESET_MOBILITY) { |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5500 | if (adapter->req_rx_queues != old_num_rx_queues || |
| 5501 | adapter->req_tx_queues != old_num_tx_queues) { |
| 5502 | release_sub_crqs(adapter, 0); |
| 5503 | rc = init_sub_crqs(adapter); |
| 5504 | } else { |
| 5505 | rc = reset_sub_crq_queues(adapter); |
| 5506 | } |
| 5507 | } else { |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 5508 | rc = init_sub_crqs(adapter); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5509 | } |
| 5510 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 5511 | if (rc) { |
| 5512 | dev_err(dev, "Initialization of sub crqs failed\n"); |
| 5513 | release_crq_queue(adapter); |
Thomas Falcon | 5df969c | 2017-06-28 19:55:54 -0500 | [diff] [blame] | 5514 | return rc; |
| 5515 | } |
| 5516 | |
| 5517 | rc = init_sub_crq_irqs(adapter); |
| 5518 | if (rc) { |
| 5519 | dev_err(dev, "Failed to initialize sub crq irqs\n"); |
| 5520 | release_crq_queue(adapter); |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | return rc; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5524 | } |
| 5525 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5526 | static struct device_attribute dev_attr_failover; |
| 5527 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5528 | static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) |
| 5529 | { |
| 5530 | struct ibmvnic_adapter *adapter; |
| 5531 | struct net_device *netdev; |
| 5532 | unsigned char *mac_addr_p; |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5533 | bool init_success; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5534 | int rc; |
| 5535 | |
| 5536 | dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n", |
| 5537 | dev->unit_address); |
| 5538 | |
| 5539 | mac_addr_p = (unsigned char *)vio_get_attribute(dev, |
| 5540 | VETH_MAC_ADDR, NULL); |
| 5541 | if (!mac_addr_p) { |
| 5542 | dev_err(&dev->dev, |
| 5543 | "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n", |
| 5544 | __FILE__, __LINE__); |
| 5545 | return 0; |
| 5546 | } |
| 5547 | |
| 5548 | netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter), |
Thomas Falcon | d45cc3a | 2017-12-18 12:52:11 -0600 | [diff] [blame] | 5549 | IBMVNIC_MAX_QUEUES); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5550 | if (!netdev) |
| 5551 | return -ENOMEM; |
| 5552 | |
| 5553 | adapter = netdev_priv(netdev); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5554 | adapter->state = VNIC_PROBING; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5555 | dev_set_drvdata(&dev->dev, netdev); |
| 5556 | adapter->vdev = dev; |
| 5557 | adapter->netdev = netdev; |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 5558 | adapter->login_pending = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5559 | |
| 5560 | ether_addr_copy(adapter->mac_addr, mac_addr_p); |
| 5561 | ether_addr_copy(netdev->dev_addr, adapter->mac_addr); |
| 5562 | netdev->irq = dev->irq; |
| 5563 | netdev->netdev_ops = &ibmvnic_netdev_ops; |
| 5564 | netdev->ethtool_ops = &ibmvnic_ethtool_ops; |
| 5565 | SET_NETDEV_DEV(netdev, &dev->dev); |
| 5566 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5567 | INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5568 | INIT_DELAYED_WORK(&adapter->ibmvnic_delayed_reset, |
| 5569 | __ibmvnic_delayed_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5570 | INIT_LIST_HEAD(&adapter->rwi_list); |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 5571 | spin_lock_init(&adapter->rwi_lock); |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5572 | spin_lock_init(&adapter->state_lock); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5573 | mutex_init(&adapter->fw_lock); |
Thomas Falcon | bbd669a | 2019-04-04 18:58:26 -0500 | [diff] [blame] | 5574 | init_completion(&adapter->init_done); |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 5575 | init_completion(&adapter->fw_done); |
| 5576 | init_completion(&adapter->reset_done); |
| 5577 | init_completion(&adapter->stats_done); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 5578 | clear_bit(0, &adapter->resetting); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 5579 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5580 | init_success = false; |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5581 | do { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 5582 | rc = init_crq_queue(adapter); |
| 5583 | if (rc) { |
| 5584 | dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n", |
| 5585 | rc); |
| 5586 | goto ibmvnic_init_fail; |
| 5587 | } |
| 5588 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5589 | rc = ibmvnic_reset_init(adapter, false); |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 5590 | } while (rc == EAGAIN); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5591 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5592 | /* We are ignoring the error from ibmvnic_reset_init() assuming that the |
| 5593 | * partner is not ready. CRQ is not active. When the partner becomes |
| 5594 | * ready, we will do the passive init reset. |
| 5595 | */ |
| 5596 | |
| 5597 | if (!rc) |
| 5598 | init_success = true; |
| 5599 | |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5600 | rc = init_stats_buffers(adapter); |
| 5601 | if (rc) |
| 5602 | goto ibmvnic_init_fail; |
| 5603 | |
| 5604 | rc = init_stats_token(adapter); |
| 5605 | if (rc) |
| 5606 | goto ibmvnic_stats_fail; |
| 5607 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5608 | rc = device_create_file(&dev->dev, &dev_attr_failover); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5609 | if (rc) |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5610 | goto ibmvnic_dev_file_err; |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5611 | |
Mick Tarsel | e876a8a | 2017-09-28 13:53:18 -0700 | [diff] [blame] | 5612 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5613 | rc = register_netdev(netdev); |
| 5614 | if (rc) { |
| 5615 | dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5616 | goto ibmvnic_register_fail; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5617 | } |
| 5618 | dev_info(&dev->dev, "ibmvnic registered\n"); |
| 5619 | |
Cristobal Forno | 53f8b1b | 2021-06-10 11:08:35 -0600 | [diff] [blame] | 5620 | if (init_success) { |
| 5621 | adapter->state = VNIC_PROBED; |
| 5622 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 5623 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
| 5624 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
| 5625 | } else { |
| 5626 | adapter->state = VNIC_DOWN; |
| 5627 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 5628 | |
| 5629 | adapter->wait_for_reset = false; |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 5630 | adapter->last_reset_time = jiffies; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5631 | return 0; |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5632 | |
| 5633 | ibmvnic_register_fail: |
| 5634 | device_remove_file(&dev->dev, &dev_attr_failover); |
| 5635 | |
Thomas Falcon | 0718421 | 2018-05-16 15:49:05 -0500 | [diff] [blame] | 5636 | ibmvnic_dev_file_err: |
| 5637 | release_stats_token(adapter); |
| 5638 | |
| 5639 | ibmvnic_stats_fail: |
| 5640 | release_stats_buffers(adapter); |
| 5641 | |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5642 | ibmvnic_init_fail: |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5643 | release_sub_crqs(adapter, 1); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5644 | release_crq_queue(adapter); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5645 | mutex_destroy(&adapter->fw_lock); |
Nathan Fontenot | 7c1885a | 2017-08-08 14:28:45 -0500 | [diff] [blame] | 5646 | free_netdev(netdev); |
| 5647 | |
| 5648 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5649 | } |
| 5650 | |
Uwe Kleine-König | 386a966 | 2021-02-25 23:18:34 +0100 | [diff] [blame] | 5651 | static void ibmvnic_remove(struct vio_dev *dev) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5652 | { |
| 5653 | struct net_device *netdev = dev_get_drvdata(&dev->dev); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5654 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5655 | unsigned long flags; |
| 5656 | |
| 5657 | spin_lock_irqsave(&adapter->state_lock, flags); |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 5658 | |
| 5659 | /* If ibmvnic_reset() is scheduling a reset, wait for it to |
| 5660 | * finish. Then, set the state to REMOVING to prevent it from |
| 5661 | * scheduling any more work and to have reset functions ignore |
| 5662 | * any resets that have already been scheduled. Drop the lock |
| 5663 | * after setting state, so __ibmvnic_reset() which is called |
| 5664 | * from the flush_work() below, can make progress. |
| 5665 | */ |
Junlin Yang | 69cdb79 | 2021-03-05 16:48:39 +0800 | [diff] [blame] | 5666 | spin_lock(&adapter->rwi_lock); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5667 | adapter->state = VNIC_REMOVING; |
Junlin Yang | 69cdb79 | 2021-03-05 16:48:39 +0800 | [diff] [blame] | 5668 | spin_unlock(&adapter->rwi_lock); |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 5669 | |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 5670 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
| 5671 | |
Thomas Falcon | 6954a9e | 2020-06-12 13:34:41 -0500 | [diff] [blame] | 5672 | flush_work(&adapter->ibmvnic_reset); |
| 5673 | flush_delayed_work(&adapter->ibmvnic_delayed_reset); |
| 5674 | |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 5675 | rtnl_lock(); |
| 5676 | unregister_netdevice(netdev); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5677 | |
| 5678 | release_resources(adapter); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5679 | release_sub_crqs(adapter, 1); |
Nathan Fontenot | 3748905 | 2017-04-19 13:45:04 -0400 | [diff] [blame] | 5680 | release_crq_queue(adapter); |
| 5681 | |
Thomas Falcon | 53cc772 | 2018-02-26 18:10:56 -0600 | [diff] [blame] | 5682 | release_stats_token(adapter); |
| 5683 | release_stats_buffers(adapter); |
| 5684 | |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5685 | adapter->state = VNIC_REMOVED; |
| 5686 | |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 5687 | rtnl_unlock(); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 5688 | mutex_destroy(&adapter->fw_lock); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5689 | device_remove_file(&dev->dev, &dev_attr_failover); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5690 | free_netdev(netdev); |
| 5691 | dev_set_drvdata(&dev->dev, NULL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5692 | } |
| 5693 | |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5694 | static ssize_t failover_store(struct device *dev, struct device_attribute *attr, |
| 5695 | const char *buf, size_t count) |
| 5696 | { |
| 5697 | struct net_device *netdev = dev_get_drvdata(dev); |
| 5698 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 5699 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 5700 | __be64 session_token; |
| 5701 | long rc; |
| 5702 | |
| 5703 | if (!sysfs_streq(buf, "1")) |
| 5704 | return -EINVAL; |
| 5705 | |
| 5706 | rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address, |
| 5707 | H_GET_SESSION_TOKEN, 0, 0, 0); |
| 5708 | if (rc) { |
| 5709 | netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n", |
| 5710 | rc); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5711 | goto last_resort; |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | session_token = (__be64)retbuf[0]; |
| 5715 | netdev_dbg(netdev, "Initiating client failover, session id %llx\n", |
| 5716 | be64_to_cpu(session_token)); |
| 5717 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 5718 | H_SESSION_ERR_DETECTED, session_token, 0, 0); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5719 | if (rc) |
| 5720 | netdev_err(netdev, |
| 5721 | "H_VIOCTL initiated failover failed, rc %ld\n", |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5722 | rc); |
Lijun Pan | 334c424 | 2021-04-13 03:31:44 -0500 | [diff] [blame] | 5723 | |
| 5724 | last_resort: |
| 5725 | netdev_dbg(netdev, "Trying to send CRQ_CMD, the last resort\n"); |
| 5726 | ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5727 | |
| 5728 | return count; |
| 5729 | } |
Joe Perches | 6cbaefb | 2017-12-19 10:15:09 -0800 | [diff] [blame] | 5730 | static DEVICE_ATTR_WO(failover); |
Thomas Falcon | 40c9db8 | 2017-06-12 12:35:04 -0500 | [diff] [blame] | 5731 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5732 | static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev) |
| 5733 | { |
| 5734 | struct net_device *netdev = dev_get_drvdata(&vdev->dev); |
| 5735 | struct ibmvnic_adapter *adapter; |
| 5736 | struct iommu_table *tbl; |
| 5737 | unsigned long ret = 0; |
| 5738 | int i; |
| 5739 | |
| 5740 | tbl = get_iommu_table_base(&vdev->dev); |
| 5741 | |
| 5742 | /* netdev inits at probe time along with the structures we need below*/ |
| 5743 | if (!netdev) |
| 5744 | return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl); |
| 5745 | |
| 5746 | adapter = netdev_priv(netdev); |
| 5747 | |
| 5748 | ret += PAGE_SIZE; /* the crq message queue */ |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5749 | ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl); |
| 5750 | |
| 5751 | for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++) |
| 5752 | ret += 4 * PAGE_SIZE; /* the scrq message queue */ |
| 5753 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 5754 | for (i = 0; i < adapter->num_active_rx_pools; i++) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5755 | ret += adapter->rx_pool[i].size * |
| 5756 | IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl); |
| 5757 | |
| 5758 | return ret; |
| 5759 | } |
| 5760 | |
| 5761 | static int ibmvnic_resume(struct device *dev) |
| 5762 | { |
| 5763 | struct net_device *netdev = dev_get_drvdata(dev); |
| 5764 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5765 | |
John Allen | cb89ba2 | 2017-06-19 11:27:53 -0500 | [diff] [blame] | 5766 | if (adapter->state != VNIC_OPEN) |
| 5767 | return 0; |
| 5768 | |
John Allen | a248878 | 2017-07-24 13:26:06 -0500 | [diff] [blame] | 5769 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5770 | |
| 5771 | return 0; |
| 5772 | } |
| 5773 | |
Arvind Yadav | 8c37bc6 | 2017-08-17 18:52:54 +0530 | [diff] [blame] | 5774 | static const struct vio_device_id ibmvnic_device_table[] = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5775 | {"network", "IBM,vnic"}, |
| 5776 | {"", "" } |
| 5777 | }; |
| 5778 | MODULE_DEVICE_TABLE(vio, ibmvnic_device_table); |
| 5779 | |
| 5780 | static const struct dev_pm_ops ibmvnic_pm_ops = { |
| 5781 | .resume = ibmvnic_resume |
| 5782 | }; |
| 5783 | |
| 5784 | static struct vio_driver ibmvnic_driver = { |
| 5785 | .id_table = ibmvnic_device_table, |
| 5786 | .probe = ibmvnic_probe, |
| 5787 | .remove = ibmvnic_remove, |
| 5788 | .get_desired_dma = ibmvnic_get_desired_dma, |
| 5789 | .name = ibmvnic_driver_name, |
| 5790 | .pm = &ibmvnic_pm_ops, |
| 5791 | }; |
| 5792 | |
| 5793 | /* module functions */ |
| 5794 | static int __init ibmvnic_module_init(void) |
| 5795 | { |
| 5796 | pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string, |
| 5797 | IBMVNIC_DRIVER_VERSION); |
| 5798 | |
| 5799 | return vio_register_driver(&ibmvnic_driver); |
| 5800 | } |
| 5801 | |
| 5802 | static void __exit ibmvnic_module_exit(void) |
| 5803 | { |
| 5804 | vio_unregister_driver(&ibmvnic_driver); |
| 5805 | } |
| 5806 | |
| 5807 | module_init(ibmvnic_module_init); |
| 5808 | module_exit(ibmvnic_module_exit); |