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