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 | |
| 1908 | if (adapter->state != VNIC_PROBED) { |
| 1909 | ether_addr_copy(adapter->mac_addr, addr->sa_data); |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 1910 | rc = __ibmvnic_set_mac(netdev, addr->sa_data); |
Lijun Pan | 8fc3672 | 2020-10-27 17:04:56 -0500 | [diff] [blame] | 1911 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 1912 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 1913 | return rc; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 1914 | } |
| 1915 | |
Lee Jones | 8070860 | 2021-01-15 20:09:03 +0000 | [diff] [blame] | 1916 | /* |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1917 | * do_reset returns zero if we are able to keep processing reset events, or |
| 1918 | * non-zero if we hit a fatal error and must halt. |
| 1919 | */ |
| 1920 | static int do_reset(struct ibmvnic_adapter *adapter, |
| 1921 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 1922 | { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 1923 | u64 old_num_rx_queues, old_num_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 1924 | u64 old_num_rx_slots, old_num_tx_slots; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1925 | struct net_device *netdev = adapter->netdev; |
| 1926 | int i, rc; |
| 1927 | |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 1928 | netdev_dbg(adapter->netdev, |
| 1929 | "[S:%d FOP:%d] Reset reason %d, reset_state %d\n", |
| 1930 | adapter->state, adapter->failover_pending, |
| 1931 | rwi->reset_reason, reset_state); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 1932 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 1933 | adapter->reset_reason = rwi->reset_reason; |
| 1934 | /* requestor of VNIC_RESET_CHANGE_PARAM already has the rtnl lock */ |
| 1935 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 1936 | rtnl_lock(); |
| 1937 | |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 1938 | /* Now that we have the rtnl lock, clear any pending failover. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 1939 | * This will ensure ibmvnic_open() has either completed or will |
| 1940 | * block until failover is complete. |
| 1941 | */ |
| 1942 | if (rwi->reset_reason == VNIC_RESET_FAILOVER) |
| 1943 | adapter->failover_pending = false; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 1944 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1945 | /* read the state and check (again) after getting rtnl */ |
| 1946 | reset_state = adapter->state; |
| 1947 | |
| 1948 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 1949 | rc = -EBUSY; |
| 1950 | goto out; |
| 1951 | } |
| 1952 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1953 | netif_carrier_off(netdev); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1954 | |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 1955 | old_num_rx_queues = adapter->req_rx_queues; |
| 1956 | old_num_tx_queues = adapter->req_tx_queues; |
Thomas Falcon | 5bf032e | 2018-11-21 11:17:59 -0600 | [diff] [blame] | 1957 | old_num_rx_slots = adapter->req_rx_add_entries_per_subcrq; |
| 1958 | old_num_tx_slots = adapter->req_tx_entries_per_subcrq; |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 1959 | |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 1960 | ibmvnic_cleanup(netdev); |
| 1961 | |
Thomas Falcon | 1f94608 | 2019-06-07 16:03:53 -0500 | [diff] [blame] | 1962 | if (reset_state == VNIC_OPEN && |
| 1963 | adapter->reset_reason != VNIC_RESET_MOBILITY && |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 1964 | adapter->reset_reason != VNIC_RESET_FAILOVER) { |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 1965 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 1966 | rc = __ibmvnic_close(netdev); |
| 1967 | if (rc) |
| 1968 | goto out; |
| 1969 | } else { |
| 1970 | adapter->state = VNIC_CLOSING; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 1971 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 1972 | /* Release the RTNL lock before link state change and |
| 1973 | * re-acquire after the link state change to allow |
| 1974 | * linkwatch_event to grab the RTNL lock and run during |
| 1975 | * a reset. |
| 1976 | */ |
| 1977 | rtnl_unlock(); |
| 1978 | rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); |
| 1979 | rtnl_lock(); |
| 1980 | if (rc) |
| 1981 | goto out; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 1982 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1983 | if (adapter->state == VNIC_OPEN) { |
| 1984 | /* When we dropped rtnl, ibmvnic_open() got |
| 1985 | * it and noticed that we are resetting and |
| 1986 | * set the adapter state to OPEN. Update our |
| 1987 | * new "target" state, and resume the reset |
| 1988 | * from VNIC_CLOSING state. |
| 1989 | */ |
| 1990 | netdev_dbg(netdev, |
| 1991 | "Open changed state from %d, updating.\n", |
| 1992 | reset_state); |
| 1993 | reset_state = VNIC_OPEN; |
| 1994 | adapter->state = VNIC_CLOSING; |
| 1995 | } |
| 1996 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 1997 | if (adapter->state != VNIC_CLOSING) { |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 1998 | /* If someone else changed the adapter state |
| 1999 | * when we dropped the rtnl, fail the reset |
| 2000 | */ |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2001 | rc = -1; |
| 2002 | goto out; |
| 2003 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2004 | adapter->state = VNIC_CLOSED; |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2005 | } |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2006 | } |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2007 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2008 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2009 | release_resources(adapter); |
| 2010 | release_sub_crqs(adapter, 1); |
| 2011 | release_crq_queue(adapter); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2012 | } |
| 2013 | |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2014 | if (adapter->reset_reason != VNIC_RESET_NON_FATAL) { |
| 2015 | /* remove the closed state so when we call open it appears |
| 2016 | * we are coming from the probed state. |
| 2017 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2018 | adapter->state = VNIC_PROBED; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2019 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2020 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2021 | rc = init_crq_queue(adapter); |
| 2022 | } else if (adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2023 | rc = ibmvnic_reenable_crq_queue(adapter); |
| 2024 | release_sub_crqs(adapter, 1); |
| 2025 | } else { |
| 2026 | rc = ibmvnic_reset_crq(adapter); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2027 | if (rc == H_CLOSED || rc == H_SUCCESS) { |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2028 | rc = vio_enable_interrupts(adapter->vdev); |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2029 | if (rc) |
| 2030 | netdev_err(adapter->netdev, |
| 2031 | "Reset failed to enable interrupts. rc=%d\n", |
| 2032 | rc); |
| 2033 | } |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | if (rc) { |
| 2037 | netdev_err(adapter->netdev, |
Dany Madden | 8b40eb73 | 2020-06-18 15:24:13 -0400 | [diff] [blame] | 2038 | "Reset couldn't initialize crq. rc=%d\n", rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2039 | goto out; |
Nathan Fontenot | 30f7962 | 2018-04-06 18:37:06 -0500 | [diff] [blame] | 2040 | } |
| 2041 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2042 | rc = ibmvnic_reset_init(adapter, true); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2043 | if (rc) { |
| 2044 | rc = IBMVNIC_INIT_FAILED; |
| 2045 | goto out; |
| 2046 | } |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2047 | |
| 2048 | /* If the adapter was in PROBE state prior to the reset, |
| 2049 | * exit here. |
| 2050 | */ |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2051 | if (reset_state == VNIC_PROBED) { |
| 2052 | rc = 0; |
| 2053 | goto out; |
| 2054 | } |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2055 | |
| 2056 | rc = ibmvnic_login(netdev); |
Lijun Pan | f78afaa | 2021-02-11 00:43:20 -0600 | [diff] [blame] | 2057 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2058 | goto out; |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 2059 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2060 | if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM) { |
| 2061 | rc = init_resources(adapter); |
| 2062 | if (rc) |
| 2063 | goto out; |
| 2064 | } else if (adapter->req_rx_queues != old_num_rx_queues || |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2065 | adapter->req_tx_queues != old_num_tx_queues || |
| 2066 | adapter->req_rx_add_entries_per_subcrq != |
| 2067 | old_num_rx_slots || |
| 2068 | adapter->req_tx_entries_per_subcrq != |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2069 | old_num_tx_slots || |
| 2070 | !adapter->rx_pool || |
| 2071 | !adapter->tso_pool || |
| 2072 | !adapter->tx_pool) { |
John Allen | 896d869 | 2018-01-18 16:26:31 -0600 | [diff] [blame] | 2073 | release_rx_pools(adapter); |
| 2074 | release_tx_pools(adapter); |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2075 | release_napi(adapter); |
| 2076 | release_vpd_data(adapter); |
| 2077 | |
| 2078 | rc = init_resources(adapter); |
Thomas Falcon | f611a5b | 2018-08-30 13:19:53 -0500 | [diff] [blame] | 2079 | if (rc) |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2080 | goto out; |
Nathan Fontenot | d9043c1 | 2018-02-19 13:30:14 -0600 | [diff] [blame] | 2081 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2082 | } else { |
| 2083 | rc = reset_tx_pools(adapter); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2084 | if (rc) { |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2085 | netdev_dbg(adapter->netdev, "reset tx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2086 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2087 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2088 | } |
Nathan Fontenot | 8c0543a | 2017-05-26 10:31:06 -0400 | [diff] [blame] | 2089 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2090 | rc = reset_rx_pools(adapter); |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2091 | if (rc) { |
Mingming Cao | 9f13457 | 2020-08-25 13:26:41 -0400 | [diff] [blame] | 2092 | netdev_dbg(adapter->netdev, "reset rx pools failed (%d)\n", |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2093 | rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2094 | goto out; |
Jakub Kicinski | 8ae4dff | 2020-09-04 21:07:49 -0700 | [diff] [blame] | 2095 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2096 | } |
Thomas Falcon | 134bbe7 | 2018-05-16 15:49:04 -0500 | [diff] [blame] | 2097 | ibmvnic_disable_irqs(adapter); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2098 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2099 | adapter->state = VNIC_CLOSED; |
| 2100 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2101 | if (reset_state == VNIC_CLOSED) { |
| 2102 | rc = 0; |
| 2103 | goto out; |
| 2104 | } |
John Allen | e676d81 | 2018-03-14 10:41:29 -0500 | [diff] [blame] | 2105 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2106 | rc = __ibmvnic_open(netdev); |
| 2107 | if (rc) { |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2108 | rc = IBMVNIC_OPEN_FAILED; |
| 2109 | goto out; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2110 | } |
| 2111 | |
Thomas Falcon | be32a24 | 2019-06-07 16:03:54 -0500 | [diff] [blame] | 2112 | /* refresh device's multicast list */ |
| 2113 | ibmvnic_set_multi(netdev); |
| 2114 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2115 | /* kick napi */ |
| 2116 | for (i = 0; i < adapter->req_rx_queues; i++) |
| 2117 | napi_schedule(&adapter->napi[i]); |
| 2118 | |
Lijun Pan | 98025bc | 2020-11-20 16:40:12 -0600 | [diff] [blame] | 2119 | if (adapter->reset_reason == VNIC_RESET_FAILOVER || |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2120 | adapter->reset_reason == VNIC_RESET_MOBILITY) |
| 2121 | __netdev_notify_peers(netdev); |
Nathan Fontenot | 61d3e1d | 2017-06-12 20:47:45 -0400 | [diff] [blame] | 2122 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2123 | rc = 0; |
| 2124 | |
| 2125 | out: |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2126 | /* restore the adapter state if reset failed */ |
| 2127 | if (rc) |
| 2128 | adapter->state = reset_state; |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2129 | /* requestor of VNIC_RESET_CHANGE_PARAM should still hold the rtnl lock */ |
| 2130 | if (!(adapter->reset_reason == VNIC_RESET_CHANGE_PARAM)) |
| 2131 | rtnl_unlock(); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2132 | |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2133 | netdev_dbg(adapter->netdev, "[S:%d FOP:%d] Reset done, rc %d\n", |
| 2134 | adapter->state, adapter->failover_pending, rc); |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2135 | return rc; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2136 | } |
| 2137 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2138 | static int do_hard_reset(struct ibmvnic_adapter *adapter, |
| 2139 | struct ibmvnic_rwi *rwi, u32 reset_state) |
| 2140 | { |
| 2141 | struct net_device *netdev = adapter->netdev; |
| 2142 | int rc; |
| 2143 | |
| 2144 | netdev_dbg(adapter->netdev, "Hard resetting driver (%d)\n", |
| 2145 | rwi->reset_reason); |
| 2146 | |
Sukadev Bhattiprolu | 8f1c0fd | 2021-02-23 21:02:29 -0800 | [diff] [blame] | 2147 | /* read the state and check (again) after getting rtnl */ |
| 2148 | reset_state = adapter->state; |
| 2149 | |
| 2150 | if (reset_state == VNIC_REMOVING || reset_state == VNIC_REMOVED) { |
| 2151 | rc = -EBUSY; |
| 2152 | goto out; |
| 2153 | } |
| 2154 | |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2155 | netif_carrier_off(netdev); |
| 2156 | adapter->reset_reason = rwi->reset_reason; |
| 2157 | |
| 2158 | ibmvnic_cleanup(netdev); |
| 2159 | release_resources(adapter); |
| 2160 | release_sub_crqs(adapter, 0); |
| 2161 | release_crq_queue(adapter); |
| 2162 | |
| 2163 | /* remove the closed state so when we call open it appears |
| 2164 | * we are coming from the probed state. |
| 2165 | */ |
| 2166 | adapter->state = VNIC_PROBED; |
| 2167 | |
Thomas Falcon | bbd669a | 2019-04-04 18:58:26 -0500 | [diff] [blame] | 2168 | reinit_completion(&adapter->init_done); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2169 | rc = init_crq_queue(adapter); |
| 2170 | if (rc) { |
| 2171 | netdev_err(adapter->netdev, |
| 2172 | "Couldn't initialize crq. rc=%d\n", rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2173 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2174 | } |
| 2175 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 2176 | rc = ibmvnic_reset_init(adapter, false); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2177 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2178 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2179 | |
| 2180 | /* If the adapter was in PROBE state prior to the reset, |
| 2181 | * exit here. |
| 2182 | */ |
| 2183 | if (reset_state == VNIC_PROBED) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2184 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2185 | |
| 2186 | rc = ibmvnic_login(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2187 | if (rc) |
| 2188 | goto out; |
Juliet Kim | a5681e2 | 2018-11-19 15:59:22 -0600 | [diff] [blame] | 2189 | |
| 2190 | rc = init_resources(adapter); |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2191 | if (rc) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2192 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2193 | |
| 2194 | ibmvnic_disable_irqs(adapter); |
| 2195 | adapter->state = VNIC_CLOSED; |
| 2196 | |
| 2197 | if (reset_state == VNIC_CLOSED) |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2198 | goto out; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2199 | |
| 2200 | rc = __ibmvnic_open(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2201 | if (rc) { |
| 2202 | rc = IBMVNIC_OPEN_FAILED; |
| 2203 | goto out; |
| 2204 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2205 | |
Lijun Pan | 6be4666 | 2020-12-14 15:19:29 -0600 | [diff] [blame] | 2206 | __netdev_notify_peers(netdev); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2207 | out: |
| 2208 | /* restore adapter state if reset failed */ |
| 2209 | if (rc) |
| 2210 | adapter->state = reset_state; |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2211 | netdev_dbg(adapter->netdev, "[S:%d FOP:%d] Hard reset done, rc %d\n", |
| 2212 | adapter->state, adapter->failover_pending, rc); |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2213 | return rc; |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2214 | } |
| 2215 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2216 | static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter) |
| 2217 | { |
| 2218 | struct ibmvnic_rwi *rwi; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2219 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2220 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2221 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2222 | |
| 2223 | if (!list_empty(&adapter->rwi_list)) { |
| 2224 | rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi, |
| 2225 | list); |
| 2226 | list_del(&rwi->list); |
| 2227 | } else { |
| 2228 | rwi = NULL; |
| 2229 | } |
| 2230 | |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2231 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2232 | return rwi; |
| 2233 | } |
| 2234 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2235 | static void __ibmvnic_reset(struct work_struct *work) |
| 2236 | { |
| 2237 | struct ibmvnic_rwi *rwi; |
| 2238 | struct ibmvnic_adapter *adapter; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2239 | bool saved_state = false; |
| 2240 | unsigned long flags; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2241 | u32 reset_state; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2242 | int rc = 0; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2243 | |
| 2244 | adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2245 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2246 | if (test_and_set_bit_lock(0, &adapter->resetting)) { |
| 2247 | schedule_delayed_work(&adapter->ibmvnic_delayed_reset, |
| 2248 | IBMVNIC_RESET_DELAY); |
| 2249 | return; |
| 2250 | } |
| 2251 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2252 | rwi = get_next_rwi(adapter); |
| 2253 | while (rwi) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2254 | spin_lock_irqsave(&adapter->state_lock, flags); |
| 2255 | |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2256 | if (adapter->state == VNIC_REMOVING || |
Michal Suchanek | c8dc559 | 2019-09-09 22:44:51 +0200 | [diff] [blame] | 2257 | adapter->state == VNIC_REMOVED) { |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2258 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
Juliet Kim | 1c2977c | 2019-09-05 17:30:01 -0400 | [diff] [blame] | 2259 | kfree(rwi); |
| 2260 | rc = EBUSY; |
| 2261 | break; |
| 2262 | } |
Thomas Falcon | 36f1031 | 2019-08-27 11:10:04 -0500 | [diff] [blame] | 2263 | |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2264 | if (!saved_state) { |
| 2265 | reset_state = adapter->state; |
Juliet Kim | 7d7195a | 2020-03-10 09:23:58 -0500 | [diff] [blame] | 2266 | saved_state = true; |
| 2267 | } |
| 2268 | spin_unlock_irqrestore(&adapter->state_lock, flags); |
| 2269 | |
Lijun Pan | 3f5ec37 | 2021-01-06 15:35:14 -0600 | [diff] [blame] | 2270 | if (adapter->force_reset_recovery) { |
Lijun Pan | bab08be | 2021-02-11 00:43:19 -0600 | [diff] [blame] | 2271 | /* Since we are doing a hard reset now, clear the |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2272 | * failover_pending flag so we don't ignore any |
| 2273 | * future MOBILITY or other resets. |
| 2274 | */ |
| 2275 | adapter->failover_pending = false; |
| 2276 | |
Juliet Kim | b27507b | 2019-09-20 16:11:22 -0400 | [diff] [blame] | 2277 | /* Transport event occurred during previous reset */ |
| 2278 | if (adapter->wait_for_reset) { |
| 2279 | /* Previous was CHANGE_PARAM; caller locked */ |
| 2280 | adapter->force_reset_recovery = false; |
| 2281 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2282 | } else { |
| 2283 | rtnl_lock(); |
| 2284 | adapter->force_reset_recovery = false; |
| 2285 | rc = do_hard_reset(adapter, rwi, reset_state); |
| 2286 | rtnl_unlock(); |
| 2287 | } |
Sukadev Bhattiprolu | f15fde9 | 2020-11-25 18:04:28 -0600 | [diff] [blame] | 2288 | if (rc) { |
| 2289 | /* give backing device time to settle down */ |
| 2290 | netdev_dbg(adapter->netdev, |
| 2291 | "[S:%d] Hard reset failed, waiting 60 secs\n", |
| 2292 | adapter->state); |
| 2293 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2294 | schedule_timeout(60 * HZ); |
| 2295 | } |
Lijun Pan | 1f45dc2 | 2020-12-23 14:49:04 -0600 | [diff] [blame] | 2296 | } else { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2297 | rc = do_reset(adapter, rwi, reset_state); |
| 2298 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2299 | kfree(rwi); |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2300 | adapter->last_reset_time = jiffies; |
Dany Madden | 0cb4bc6 | 2020-11-25 18:04:27 -0600 | [diff] [blame] | 2301 | |
Dany Madden | 18f141b | 2020-11-25 18:04:25 -0600 | [diff] [blame] | 2302 | if (rc) |
| 2303 | netdev_dbg(adapter->netdev, "Reset failed, rc=%d\n", rc); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2304 | |
| 2305 | rwi = get_next_rwi(adapter); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2306 | |
| 2307 | if (rwi && (rwi->reset_reason == VNIC_RESET_FAILOVER || |
| 2308 | rwi->reset_reason == VNIC_RESET_MOBILITY)) |
| 2309 | adapter->force_reset_recovery = true; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2312 | if (adapter->wait_for_reset) { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2313 | adapter->reset_done_rc = rc; |
| 2314 | complete(&adapter->reset_done); |
| 2315 | } |
| 2316 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2317 | clear_bit_unlock(0, &adapter->resetting); |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2318 | |
| 2319 | netdev_dbg(adapter->netdev, |
| 2320 | "[S:%d FRR:%d WFR:%d] Done processing resets\n", |
| 2321 | adapter->state, adapter->force_reset_recovery, |
| 2322 | adapter->wait_for_reset); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | static void __ibmvnic_delayed_reset(struct work_struct *work) |
| 2326 | { |
| 2327 | struct ibmvnic_adapter *adapter; |
| 2328 | |
| 2329 | adapter = container_of(work, struct ibmvnic_adapter, |
| 2330 | ibmvnic_delayed_reset.work); |
| 2331 | __ibmvnic_reset(&adapter->ibmvnic_reset); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2332 | } |
| 2333 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2334 | static int ibmvnic_reset(struct ibmvnic_adapter *adapter, |
| 2335 | enum ibmvnic_reset_reason reason) |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2336 | { |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2337 | struct list_head *entry, *tmp_entry; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2338 | struct ibmvnic_rwi *rwi, *tmp; |
| 2339 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 6c5c748 | 2018-12-10 15:22:22 -0600 | [diff] [blame] | 2340 | unsigned long flags; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2341 | int ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2342 | |
Jakub Kicinski | b646acd5 | 2021-02-16 22:58:44 -0800 | [diff] [blame] | 2343 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
| 2344 | |
| 2345 | /* If failover is pending don't schedule any other reset. |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2346 | * Instead let the failover complete. If there is already a |
| 2347 | * a failover reset scheduled, we will detect and drop the |
| 2348 | * duplicate reset when walking the ->rwi_list below. |
| 2349 | */ |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2350 | if (adapter->state == VNIC_REMOVING || |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2351 | adapter->state == VNIC_REMOVED || |
Sukadev Bhattiprolu | 1d85049 | 2020-10-30 10:07:11 -0700 | [diff] [blame] | 2352 | (adapter->failover_pending && reason != VNIC_RESET_FAILOVER)) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2353 | ret = EBUSY; |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 2354 | netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n"); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2355 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2356 | } |
| 2357 | |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2358 | if (adapter->state == VNIC_PROBING) { |
| 2359 | netdev_warn(netdev, "Adapter reset during probe\n"); |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2360 | adapter->init_done_rc = EAGAIN; |
| 2361 | ret = EAGAIN; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2362 | goto err; |
Nathan Fontenot | 6a2fb0e | 2017-06-15 14:48:09 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2365 | list_for_each(entry, &adapter->rwi_list) { |
| 2366 | tmp = list_entry(entry, struct ibmvnic_rwi, list); |
| 2367 | if (tmp->reset_reason == reason) { |
Sukadev Bhattiprolu | 38bd5ce | 2020-12-04 18:22:35 -0800 | [diff] [blame] | 2368 | netdev_dbg(netdev, "Skipping matching reset, reason=%d\n", |
| 2369 | reason); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2370 | ret = EBUSY; |
| 2371 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | |
Thomas Falcon | 1d1bbc3 | 2018-12-10 15:22:23 -0600 | [diff] [blame] | 2375 | rwi = kzalloc(sizeof(*rwi), GFP_ATOMIC); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2376 | if (!rwi) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2377 | ret = ENOMEM; |
| 2378 | goto err; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2379 | } |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 2380 | /* if we just received a transport event, |
| 2381 | * flush reset queue and process this reset |
| 2382 | */ |
| 2383 | if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) { |
| 2384 | list_for_each_safe(entry, tmp_entry, &adapter->rwi_list) |
| 2385 | list_del(entry); |
| 2386 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2387 | rwi->reset_reason = reason; |
| 2388 | list_add_tail(&rwi->list, &adapter->rwi_list); |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 2389 | netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2390 | schedule_work(&adapter->ibmvnic_reset); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2391 | |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2392 | ret = 0; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2393 | err: |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 2394 | /* ibmvnic_close() below can block, so drop the lock first */ |
| 2395 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
| 2396 | |
| 2397 | if (ret == ENOMEM) |
| 2398 | ibmvnic_close(netdev); |
| 2399 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2400 | return -ret; |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 2403 | static void ibmvnic_tx_timeout(struct net_device *dev, unsigned int txqueue) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2404 | { |
| 2405 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2406 | |
Lijun Pan | 855a631 | 2020-11-20 16:40:13 -0600 | [diff] [blame] | 2407 | if (test_bit(0, &adapter->resetting)) { |
| 2408 | netdev_err(adapter->netdev, |
| 2409 | "Adapter is resetting, skip timeout reset\n"); |
| 2410 | return; |
| 2411 | } |
Dany Madden | a86d5c6 | 2020-11-25 18:04:31 -0600 | [diff] [blame] | 2412 | /* No queuing up reset until at least 5 seconds (default watchdog val) |
| 2413 | * after last reset |
| 2414 | */ |
| 2415 | if (time_before(jiffies, (adapter->last_reset_time + dev->watchdog_timeo))) { |
| 2416 | netdev_dbg(dev, "Not yet time to tx timeout.\n"); |
| 2417 | return; |
| 2418 | } |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 2419 | ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | static void remove_buff_from_pool(struct ibmvnic_adapter *adapter, |
| 2423 | struct ibmvnic_rx_buff *rx_buff) |
| 2424 | { |
| 2425 | struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index]; |
| 2426 | |
| 2427 | rx_buff->skb = NULL; |
| 2428 | |
| 2429 | pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff); |
| 2430 | pool->next_alloc = (pool->next_alloc + 1) % pool->size; |
| 2431 | |
| 2432 | atomic_dec(&pool->available); |
| 2433 | } |
| 2434 | |
| 2435 | static int ibmvnic_poll(struct napi_struct *napi, int budget) |
| 2436 | { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2437 | struct ibmvnic_sub_crq_queue *rx_scrq; |
| 2438 | struct ibmvnic_adapter *adapter; |
| 2439 | struct net_device *netdev; |
| 2440 | int frames_processed; |
| 2441 | int scrq_num; |
| 2442 | |
| 2443 | netdev = napi->dev; |
| 2444 | adapter = netdev_priv(netdev); |
| 2445 | scrq_num = (int)(napi - adapter->napi); |
| 2446 | frames_processed = 0; |
| 2447 | rx_scrq = adapter->rx_scrq[scrq_num]; |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2448 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2449 | restart_poll: |
| 2450 | while (frames_processed < budget) { |
| 2451 | struct sk_buff *skb; |
| 2452 | struct ibmvnic_rx_buff *rx_buff; |
| 2453 | union sub_crq *next; |
| 2454 | u32 length; |
| 2455 | u16 offset; |
| 2456 | u8 flags = 0; |
| 2457 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 2458 | if (unlikely(test_bit(0, &adapter->resetting) && |
John Allen | 3468656 | 2018-02-06 16:21:49 -0600 | [diff] [blame] | 2459 | adapter->reset_reason != VNIC_RESET_NON_FATAL)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2460 | enable_scrq_irq(adapter, rx_scrq); |
Thomas Falcon | 21ecba6 | 2017-06-14 23:50:09 -0500 | [diff] [blame] | 2461 | napi_complete_done(napi, frames_processed); |
| 2462 | return frames_processed; |
| 2463 | } |
| 2464 | |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2465 | if (!pending_scrq(adapter, rx_scrq)) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2466 | break; |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2467 | next = ibmvnic_next_scrq(adapter, rx_scrq); |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 2468 | rx_buff = (struct ibmvnic_rx_buff *) |
| 2469 | be64_to_cpu(next->rx_comp.correlator); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2470 | /* do error checking */ |
| 2471 | if (next->rx_comp.rc) { |
John Allen | e1cea2e | 2017-08-07 15:42:30 -0500 | [diff] [blame] | 2472 | netdev_dbg(netdev, "rx buffer returned with rc %x\n", |
| 2473 | be16_to_cpu(next->rx_comp.rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2474 | /* free the entry */ |
| 2475 | next->rx_comp.first = 0; |
Thomas Falcon | 4b9b0f0 | 2018-02-13 18:23:42 -0600 | [diff] [blame] | 2476 | dev_kfree_skb_any(rx_buff->skb); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2477 | remove_buff_from_pool(adapter, rx_buff); |
Nathan Fontenot | ca05e31 | 2017-05-03 14:05:14 -0400 | [diff] [blame] | 2478 | continue; |
Thomas Falcon | abe27a8 | 2018-02-19 20:12:57 -0600 | [diff] [blame] | 2479 | } else if (!rx_buff->skb) { |
| 2480 | /* free the entry */ |
| 2481 | next->rx_comp.first = 0; |
| 2482 | remove_buff_from_pool(adapter, rx_buff); |
| 2483 | continue; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | length = be32_to_cpu(next->rx_comp.len); |
| 2487 | offset = be16_to_cpu(next->rx_comp.off_frame_data); |
| 2488 | flags = next->rx_comp.flags; |
| 2489 | skb = rx_buff->skb; |
Lijun Pan | 42557da | 2021-02-12 20:48:40 -0600 | [diff] [blame] | 2490 | /* load long_term_buff before copying to skb */ |
| 2491 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2492 | skb_copy_to_linear_data(skb, rx_buff->data + offset, |
| 2493 | length); |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 2494 | |
| 2495 | /* VLAN Header has been stripped by the system firmware and |
| 2496 | * needs to be inserted by the driver |
| 2497 | */ |
| 2498 | if (adapter->rx_vlan_header_insertion && |
| 2499 | (flags & IBMVNIC_VLAN_STRIPPED)) |
| 2500 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2501 | ntohs(next->rx_comp.vlan_tci)); |
| 2502 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2503 | /* free the entry */ |
| 2504 | next->rx_comp.first = 0; |
| 2505 | remove_buff_from_pool(adapter, rx_buff); |
| 2506 | |
| 2507 | skb_put(skb, length); |
| 2508 | skb->protocol = eth_type_trans(skb, netdev); |
Thomas Falcon | 94ca305 | 2017-05-03 14:05:20 -0400 | [diff] [blame] | 2509 | skb_record_rx_queue(skb, scrq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2510 | |
| 2511 | if (flags & IBMVNIC_IP_CHKSUM_GOOD && |
| 2512 | flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) { |
| 2513 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2514 | } |
| 2515 | |
| 2516 | length = skb->len; |
| 2517 | napi_gro_receive(napi, skb); /* send it up */ |
| 2518 | netdev->stats.rx_packets++; |
| 2519 | netdev->stats.rx_bytes += length; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2520 | adapter->rx_stats_buffers[scrq_num].packets++; |
| 2521 | adapter->rx_stats_buffers[scrq_num].bytes += length; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2522 | frames_processed++; |
| 2523 | } |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2524 | |
Dwip N. Banerjee | 41ed0a0 | 2020-11-18 19:12:25 -0600 | [diff] [blame] | 2525 | if (adapter->state != VNIC_CLOSING && |
| 2526 | ((atomic_read(&adapter->rx_pool[scrq_num].available) < |
| 2527 | adapter->req_rx_add_entries_per_subcrq / 2) || |
| 2528 | frames_processed < budget)) |
Nathan Fontenot | 152ce47 | 2017-05-26 10:30:54 -0400 | [diff] [blame] | 2529 | replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2530 | if (frames_processed < budget) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2531 | if (napi_complete_done(napi, frames_processed)) { |
| 2532 | enable_scrq_irq(adapter, rx_scrq); |
| 2533 | if (pending_scrq(adapter, rx_scrq)) { |
Dwip N. Banerjee | ec20f36 | 2020-11-18 19:12:23 -0600 | [diff] [blame] | 2534 | if (napi_reschedule(napi)) { |
| 2535 | disable_scrq_irq(adapter, rx_scrq); |
| 2536 | goto restart_poll; |
| 2537 | } |
| 2538 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | return frames_processed; |
| 2542 | } |
| 2543 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2544 | static int wait_for_reset(struct ibmvnic_adapter *adapter) |
| 2545 | { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2546 | int rc, ret; |
| 2547 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2548 | adapter->fallback.mtu = adapter->req_mtu; |
| 2549 | adapter->fallback.rx_queues = adapter->req_rx_queues; |
| 2550 | adapter->fallback.tx_queues = adapter->req_tx_queues; |
| 2551 | adapter->fallback.rx_entries = adapter->req_rx_add_entries_per_subcrq; |
| 2552 | adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq; |
| 2553 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2554 | reinit_completion(&adapter->reset_done); |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2555 | adapter->wait_for_reset = true; |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2556 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2557 | |
| 2558 | if (rc) { |
| 2559 | ret = rc; |
| 2560 | goto out; |
| 2561 | } |
| 2562 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, 60000); |
| 2563 | if (rc) { |
| 2564 | ret = -ENODEV; |
| 2565 | goto out; |
| 2566 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2567 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2568 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2569 | if (adapter->reset_done_rc) { |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2570 | ret = -EIO; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2571 | adapter->desired.mtu = adapter->fallback.mtu; |
| 2572 | adapter->desired.rx_queues = adapter->fallback.rx_queues; |
| 2573 | adapter->desired.tx_queues = adapter->fallback.tx_queues; |
| 2574 | adapter->desired.rx_entries = adapter->fallback.rx_entries; |
| 2575 | adapter->desired.tx_entries = adapter->fallback.tx_entries; |
| 2576 | |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2577 | reinit_completion(&adapter->reset_done); |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2578 | adapter->wait_for_reset = true; |
| 2579 | rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2580 | if (rc) { |
| 2581 | ret = rc; |
| 2582 | goto out; |
| 2583 | } |
| 2584 | rc = ibmvnic_wait_for_completion(adapter, &adapter->reset_done, |
| 2585 | 60000); |
| 2586 | if (rc) { |
| 2587 | ret = -ENODEV; |
| 2588 | goto out; |
| 2589 | } |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2590 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2591 | out: |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2592 | adapter->wait_for_reset = false; |
| 2593 | |
Thomas Falcon | af894d2 | 2018-04-06 18:37:04 -0500 | [diff] [blame] | 2594 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2595 | } |
| 2596 | |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2597 | static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu) |
| 2598 | { |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2599 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2600 | |
| 2601 | adapter->desired.mtu = new_mtu + ETH_HLEN; |
| 2602 | |
| 2603 | return wait_for_reset(adapter); |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2604 | } |
| 2605 | |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 2606 | static netdev_features_t ibmvnic_features_check(struct sk_buff *skb, |
| 2607 | struct net_device *dev, |
| 2608 | netdev_features_t features) |
| 2609 | { |
| 2610 | /* Some backing hardware adapters can not |
| 2611 | * handle packets with a MSS less than 224 |
| 2612 | * or with only one segment. |
| 2613 | */ |
| 2614 | if (skb_is_gso(skb)) { |
| 2615 | if (skb_shinfo(skb)->gso_size < 224 || |
| 2616 | skb_shinfo(skb)->gso_segs == 1) |
| 2617 | features &= ~NETIF_F_GSO_MASK; |
| 2618 | } |
| 2619 | |
| 2620 | return features; |
| 2621 | } |
| 2622 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2623 | static const struct net_device_ops ibmvnic_netdev_ops = { |
| 2624 | .ndo_open = ibmvnic_open, |
| 2625 | .ndo_stop = ibmvnic_close, |
| 2626 | .ndo_start_xmit = ibmvnic_xmit, |
| 2627 | .ndo_set_rx_mode = ibmvnic_set_multi, |
| 2628 | .ndo_set_mac_address = ibmvnic_set_mac, |
| 2629 | .ndo_validate_addr = eth_validate_addr, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2630 | .ndo_tx_timeout = ibmvnic_tx_timeout, |
John Allen | 3a807b7 | 2017-06-06 16:55:52 -0500 | [diff] [blame] | 2631 | .ndo_change_mtu = ibmvnic_change_mtu, |
Thomas Falcon | f10b09e | 2018-03-12 11:51:05 -0500 | [diff] [blame] | 2632 | .ndo_features_check = ibmvnic_features_check, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2633 | }; |
| 2634 | |
| 2635 | /* ethtool functions */ |
| 2636 | |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2637 | static int ibmvnic_get_link_ksettings(struct net_device *netdev, |
| 2638 | struct ethtool_link_ksettings *cmd) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2639 | { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 2640 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2641 | int rc; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2642 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 2643 | rc = send_query_phys_parms(adapter); |
| 2644 | if (rc) { |
| 2645 | adapter->speed = SPEED_UNKNOWN; |
| 2646 | adapter->duplex = DUPLEX_UNKNOWN; |
| 2647 | } |
| 2648 | cmd->base.speed = adapter->speed; |
| 2649 | cmd->base.duplex = adapter->duplex; |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2650 | cmd->base.port = PORT_FIBRE; |
| 2651 | cmd->base.phy_address = 0; |
| 2652 | cmd->base.autoneg = AUTONEG_ENABLE; |
| 2653 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2654 | return 0; |
| 2655 | } |
| 2656 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2657 | static void ibmvnic_get_drvinfo(struct net_device *netdev, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2658 | struct ethtool_drvinfo *info) |
| 2659 | { |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2660 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2661 | |
Lijun Pan | 8a96c80 | 2021-02-11 00:43:25 -0600 | [diff] [blame] | 2662 | strscpy(info->driver, ibmvnic_driver_name, sizeof(info->driver)); |
| 2663 | strscpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version)); |
| 2664 | strscpy(info->fw_version, adapter->fw_version, |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 2665 | sizeof(info->fw_version)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | static u32 ibmvnic_get_msglevel(struct net_device *netdev) |
| 2669 | { |
| 2670 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2671 | |
| 2672 | return adapter->msg_enable; |
| 2673 | } |
| 2674 | |
| 2675 | static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data) |
| 2676 | { |
| 2677 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2678 | |
| 2679 | adapter->msg_enable = data; |
| 2680 | } |
| 2681 | |
| 2682 | static u32 ibmvnic_get_link(struct net_device *netdev) |
| 2683 | { |
| 2684 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2685 | |
| 2686 | /* Don't need to send a query because we request a logical link up at |
| 2687 | * init and then we wait for link state indications |
| 2688 | */ |
| 2689 | return adapter->logical_link_state; |
| 2690 | } |
| 2691 | |
| 2692 | static void ibmvnic_get_ringparam(struct net_device *netdev, |
| 2693 | struct ethtool_ringparam *ring) |
| 2694 | { |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 2695 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2696 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2697 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 2698 | ring->rx_max_pending = adapter->max_rx_add_entries_per_subcrq; |
| 2699 | ring->tx_max_pending = adapter->max_tx_entries_per_subcrq; |
| 2700 | } else { |
| 2701 | ring->rx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 2702 | ring->tx_max_pending = IBMVNIC_MAX_QUEUE_SZ; |
| 2703 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2704 | ring->rx_mini_max_pending = 0; |
| 2705 | ring->rx_jumbo_max_pending = 0; |
John Allen | bc131b3 | 2017-08-02 16:46:30 -0500 | [diff] [blame] | 2706 | ring->rx_pending = adapter->req_rx_add_entries_per_subcrq; |
| 2707 | ring->tx_pending = adapter->req_tx_entries_per_subcrq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2708 | ring->rx_mini_pending = 0; |
| 2709 | ring->rx_jumbo_pending = 0; |
| 2710 | } |
| 2711 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2712 | static int ibmvnic_set_ringparam(struct net_device *netdev, |
| 2713 | struct ethtool_ringparam *ring) |
| 2714 | { |
| 2715 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2716 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2717 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2718 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2719 | adapter->desired.rx_entries = ring->rx_pending; |
| 2720 | adapter->desired.tx_entries = ring->tx_pending; |
| 2721 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2722 | ret = wait_for_reset(adapter); |
| 2723 | |
| 2724 | if (!ret && |
| 2725 | (adapter->req_rx_add_entries_per_subcrq != ring->rx_pending || |
| 2726 | adapter->req_tx_entries_per_subcrq != ring->tx_pending)) |
| 2727 | netdev_info(netdev, |
| 2728 | "Could not match full ringsize request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 2729 | ring->rx_pending, ring->tx_pending, |
| 2730 | adapter->req_rx_add_entries_per_subcrq, |
| 2731 | adapter->req_tx_entries_per_subcrq); |
| 2732 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2733 | } |
| 2734 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 2735 | static void ibmvnic_get_channels(struct net_device *netdev, |
| 2736 | struct ethtool_channels *channels) |
| 2737 | { |
| 2738 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2739 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2740 | if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) { |
| 2741 | channels->max_rx = adapter->max_rx_queues; |
| 2742 | channels->max_tx = adapter->max_tx_queues; |
| 2743 | } else { |
| 2744 | channels->max_rx = IBMVNIC_MAX_QUEUES; |
| 2745 | channels->max_tx = IBMVNIC_MAX_QUEUES; |
| 2746 | } |
| 2747 | |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 2748 | channels->max_other = 0; |
| 2749 | channels->max_combined = 0; |
| 2750 | channels->rx_count = adapter->req_rx_queues; |
| 2751 | channels->tx_count = adapter->req_tx_queues; |
| 2752 | channels->other_count = 0; |
| 2753 | channels->combined_count = 0; |
| 2754 | } |
| 2755 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2756 | static int ibmvnic_set_channels(struct net_device *netdev, |
| 2757 | struct ethtool_channels *channels) |
| 2758 | { |
| 2759 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2760 | int ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2761 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2762 | ret = 0; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2763 | adapter->desired.rx_queues = channels->rx_count; |
| 2764 | adapter->desired.tx_queues = channels->tx_count; |
| 2765 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2766 | ret = wait_for_reset(adapter); |
| 2767 | |
| 2768 | if (!ret && |
| 2769 | (adapter->req_rx_queues != channels->rx_count || |
| 2770 | adapter->req_tx_queues != channels->tx_count)) |
| 2771 | netdev_info(netdev, |
| 2772 | "Could not match full channels request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n", |
| 2773 | channels->rx_count, channels->tx_count, |
| 2774 | adapter->req_rx_queues, adapter->req_tx_queues); |
| 2775 | return ret; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2776 | } |
| 2777 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2778 | static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2779 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2780 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2781 | int i; |
| 2782 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2783 | switch (stringset) { |
| 2784 | case ETH_SS_STATS: |
| 2785 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); |
| 2786 | i++, data += ETH_GSTRING_LEN) |
| 2787 | memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN); |
| 2788 | |
| 2789 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 2790 | snprintf(data, ETH_GSTRING_LEN, "tx%d_packets", i); |
| 2791 | data += ETH_GSTRING_LEN; |
| 2792 | |
| 2793 | snprintf(data, ETH_GSTRING_LEN, "tx%d_bytes", i); |
| 2794 | data += ETH_GSTRING_LEN; |
| 2795 | |
| 2796 | snprintf(data, ETH_GSTRING_LEN, |
| 2797 | "tx%d_dropped_packets", i); |
| 2798 | data += ETH_GSTRING_LEN; |
| 2799 | } |
| 2800 | |
| 2801 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 2802 | snprintf(data, ETH_GSTRING_LEN, "rx%d_packets", i); |
| 2803 | data += ETH_GSTRING_LEN; |
| 2804 | |
| 2805 | snprintf(data, ETH_GSTRING_LEN, "rx%d_bytes", i); |
| 2806 | data += ETH_GSTRING_LEN; |
| 2807 | |
| 2808 | snprintf(data, ETH_GSTRING_LEN, "rx%d_interrupts", i); |
| 2809 | data += ETH_GSTRING_LEN; |
| 2810 | } |
| 2811 | break; |
| 2812 | |
| 2813 | case ETH_SS_PRIV_FLAGS: |
| 2814 | for (i = 0; i < ARRAY_SIZE(ibmvnic_priv_flags); i++) |
| 2815 | strcpy(data + i * ETH_GSTRING_LEN, |
| 2816 | ibmvnic_priv_flags[i]); |
| 2817 | break; |
| 2818 | default: |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2819 | return; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2820 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | static int ibmvnic_get_sset_count(struct net_device *dev, int sset) |
| 2824 | { |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2825 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 2826 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2827 | switch (sset) { |
| 2828 | case ETH_SS_STATS: |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2829 | return ARRAY_SIZE(ibmvnic_stats) + |
| 2830 | adapter->req_tx_queues * NUM_TX_STATS + |
| 2831 | adapter->req_rx_queues * NUM_RX_STATS; |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2832 | case ETH_SS_PRIV_FLAGS: |
| 2833 | return ARRAY_SIZE(ibmvnic_priv_flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2834 | default: |
| 2835 | return -EOPNOTSUPP; |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | static void ibmvnic_get_ethtool_stats(struct net_device *dev, |
| 2840 | struct ethtool_stats *stats, u64 *data) |
| 2841 | { |
| 2842 | struct ibmvnic_adapter *adapter = netdev_priv(dev); |
| 2843 | union ibmvnic_crq crq; |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2844 | int i, j; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 2845 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2846 | |
| 2847 | memset(&crq, 0, sizeof(crq)); |
| 2848 | crq.request_statistics.first = IBMVNIC_CRQ_CMD; |
| 2849 | crq.request_statistics.cmd = REQUEST_STATISTICS; |
| 2850 | crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token); |
| 2851 | crq.request_statistics.len = |
| 2852 | cpu_to_be32(sizeof(struct ibmvnic_statistics)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2853 | |
| 2854 | /* Wait for data to be written */ |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 2855 | reinit_completion(&adapter->stats_done); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 2856 | rc = ibmvnic_send_crq(adapter, &crq); |
| 2857 | if (rc) |
| 2858 | return; |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 2859 | rc = ibmvnic_wait_for_completion(adapter, &adapter->stats_done, 10000); |
| 2860 | if (rc) |
| 2861 | return; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2862 | |
| 2863 | for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++) |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2864 | data[i] = be64_to_cpu(IBMVNIC_GET_STAT |
| 2865 | (adapter, ibmvnic_stats[i].offset)); |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 2866 | |
| 2867 | for (j = 0; j < adapter->req_tx_queues; j++) { |
| 2868 | data[i] = adapter->tx_stats_buffers[j].packets; |
| 2869 | i++; |
| 2870 | data[i] = adapter->tx_stats_buffers[j].bytes; |
| 2871 | i++; |
| 2872 | data[i] = adapter->tx_stats_buffers[j].dropped_packets; |
| 2873 | i++; |
| 2874 | } |
| 2875 | |
| 2876 | for (j = 0; j < adapter->req_rx_queues; j++) { |
| 2877 | data[i] = adapter->rx_stats_buffers[j].packets; |
| 2878 | i++; |
| 2879 | data[i] = adapter->rx_stats_buffers[j].bytes; |
| 2880 | i++; |
| 2881 | data[i] = adapter->rx_stats_buffers[j].interrupts; |
| 2882 | i++; |
| 2883 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2884 | } |
| 2885 | |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2886 | static u32 ibmvnic_get_priv_flags(struct net_device *netdev) |
| 2887 | { |
| 2888 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2889 | |
| 2890 | return adapter->priv_flags; |
| 2891 | } |
| 2892 | |
| 2893 | static int ibmvnic_set_priv_flags(struct net_device *netdev, u32 flags) |
| 2894 | { |
| 2895 | struct ibmvnic_adapter *adapter = netdev_priv(netdev); |
| 2896 | bool which_maxes = !!(flags & IBMVNIC_USE_SERVER_MAXES); |
| 2897 | |
| 2898 | if (which_maxes) |
| 2899 | adapter->priv_flags |= IBMVNIC_USE_SERVER_MAXES; |
| 2900 | else |
| 2901 | adapter->priv_flags &= ~IBMVNIC_USE_SERVER_MAXES; |
| 2902 | |
| 2903 | return 0; |
| 2904 | } |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 2905 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2906 | static const struct ethtool_ops ibmvnic_ethtool_ops = { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2907 | .get_drvinfo = ibmvnic_get_drvinfo, |
| 2908 | .get_msglevel = ibmvnic_get_msglevel, |
| 2909 | .set_msglevel = ibmvnic_set_msglevel, |
| 2910 | .get_link = ibmvnic_get_link, |
| 2911 | .get_ringparam = ibmvnic_get_ringparam, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2912 | .set_ringparam = ibmvnic_set_ringparam, |
John Allen | c2dbeb6 | 2017-08-02 16:47:17 -0500 | [diff] [blame] | 2913 | .get_channels = ibmvnic_get_channels, |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 2914 | .set_channels = ibmvnic_set_channels, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2915 | .get_strings = ibmvnic_get_strings, |
| 2916 | .get_sset_count = ibmvnic_get_sset_count, |
| 2917 | .get_ethtool_stats = ibmvnic_get_ethtool_stats, |
Philippe Reynes | 8a43379 | 2017-01-07 22:37:29 +0100 | [diff] [blame] | 2918 | .get_link_ksettings = ibmvnic_get_link_ksettings, |
Thomas Falcon | 723ad91 | 2018-09-28 18:38:26 -0500 | [diff] [blame] | 2919 | .get_priv_flags = ibmvnic_get_priv_flags, |
| 2920 | .set_priv_flags = ibmvnic_set_priv_flags, |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2921 | }; |
| 2922 | |
| 2923 | /* Routines for managing CRQs/sCRQs */ |
| 2924 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2925 | static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter, |
| 2926 | struct ibmvnic_sub_crq_queue *scrq) |
| 2927 | { |
| 2928 | int rc; |
| 2929 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 2930 | if (!scrq) { |
YANG LI | 862aecb | 2020-12-30 15:23:14 +0800 | [diff] [blame] | 2931 | netdev_dbg(adapter->netdev, "Invalid scrq reset.\n"); |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 2932 | return -EINVAL; |
| 2933 | } |
| 2934 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2935 | if (scrq->irq) { |
| 2936 | free_irq(scrq->irq, scrq); |
| 2937 | irq_dispose_mapping(scrq->irq); |
| 2938 | scrq->irq = 0; |
| 2939 | } |
| 2940 | |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 2941 | if (scrq->msgs) { |
| 2942 | memset(scrq->msgs, 0, 4 * PAGE_SIZE); |
| 2943 | atomic_set(&scrq->used, 0); |
| 2944 | scrq->cur = 0; |
Jakub Kicinski | 55fd59b | 2020-12-03 15:42:13 -0800 | [diff] [blame] | 2945 | scrq->ind_buf.index = 0; |
Dany Madden | 9281cf2 | 2020-11-25 18:04:26 -0600 | [diff] [blame] | 2946 | } else { |
| 2947 | netdev_dbg(adapter->netdev, "Invalid scrq reset\n"); |
| 2948 | return -EINVAL; |
| 2949 | } |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2950 | |
| 2951 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 2952 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 2953 | return rc; |
| 2954 | } |
| 2955 | |
| 2956 | static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter) |
| 2957 | { |
| 2958 | int i, rc; |
| 2959 | |
Lijun Pan | a0faaa2 | 2020-11-23 13:35:45 -0600 | [diff] [blame] | 2960 | if (!adapter->tx_scrq || !adapter->rx_scrq) |
| 2961 | return -EINVAL; |
| 2962 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2963 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 2964 | netdev_dbg(adapter->netdev, "Re-setting tx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2965 | rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]); |
| 2966 | if (rc) |
| 2967 | return rc; |
| 2968 | } |
| 2969 | |
| 2970 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 2971 | netdev_dbg(adapter->netdev, "Re-setting rx_scrq[%d]\n", i); |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2972 | rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]); |
| 2973 | if (rc) |
| 2974 | return rc; |
| 2975 | } |
| 2976 | |
Nathan Fontenot | 57a4943 | 2017-05-26 10:31:12 -0400 | [diff] [blame] | 2977 | return rc; |
| 2978 | } |
| 2979 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2980 | static void release_sub_crq_queue(struct ibmvnic_adapter *adapter, |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 2981 | struct ibmvnic_sub_crq_queue *scrq, |
| 2982 | bool do_h_free) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2983 | { |
| 2984 | struct device *dev = &adapter->vdev->dev; |
| 2985 | long rc; |
| 2986 | |
| 2987 | netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n"); |
| 2988 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 2989 | if (do_h_free) { |
| 2990 | /* Close the sub-crqs */ |
| 2991 | do { |
| 2992 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 2993 | adapter->vdev->unit_address, |
| 2994 | scrq->crq_num); |
| 2995 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 2996 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 2997 | if (rc) { |
| 2998 | netdev_err(adapter->netdev, |
| 2999 | "Failed to release sub-CRQ %16lx, rc = %ld\n", |
| 3000 | scrq->crq_num, rc); |
| 3001 | } |
Thomas Falcon | ffa7385 | 2017-04-19 13:44:29 -0400 | [diff] [blame] | 3002 | } |
| 3003 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3004 | dma_free_coherent(dev, |
| 3005 | IBMVNIC_IND_ARR_SZ, |
| 3006 | scrq->ind_buf.indir_arr, |
| 3007 | scrq->ind_buf.indir_dma); |
| 3008 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3009 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3010 | DMA_BIDIRECTIONAL); |
| 3011 | free_pages((unsigned long)scrq->msgs, 2); |
| 3012 | kfree(scrq); |
| 3013 | } |
| 3014 | |
| 3015 | static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter |
| 3016 | *adapter) |
| 3017 | { |
| 3018 | struct device *dev = &adapter->vdev->dev; |
| 3019 | struct ibmvnic_sub_crq_queue *scrq; |
| 3020 | int rc; |
| 3021 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3022 | scrq = kzalloc(sizeof(*scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3023 | if (!scrq) |
| 3024 | return NULL; |
| 3025 | |
Nathan Fontenot | 7f7adc5 | 2017-04-19 13:45:16 -0400 | [diff] [blame] | 3026 | scrq->msgs = |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3027 | (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3028 | if (!scrq->msgs) { |
| 3029 | dev_warn(dev, "Couldn't allocate crq queue messages page\n"); |
| 3030 | goto zero_page_failed; |
| 3031 | } |
| 3032 | |
| 3033 | scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE, |
| 3034 | DMA_BIDIRECTIONAL); |
| 3035 | if (dma_mapping_error(dev, scrq->msg_token)) { |
| 3036 | dev_warn(dev, "Couldn't map crq queue messages page\n"); |
| 3037 | goto map_failed; |
| 3038 | } |
| 3039 | |
| 3040 | rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, |
| 3041 | 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq); |
| 3042 | |
| 3043 | if (rc == H_RESOURCE) |
| 3044 | rc = ibmvnic_reset_crq(adapter); |
| 3045 | |
| 3046 | if (rc == H_CLOSED) { |
| 3047 | dev_warn(dev, "Partner adapter not ready, waiting.\n"); |
| 3048 | } else if (rc) { |
| 3049 | dev_warn(dev, "Error %d registering sub-crq\n", rc); |
| 3050 | goto reg_failed; |
| 3051 | } |
| 3052 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3053 | scrq->adapter = adapter; |
| 3054 | scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs); |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3055 | scrq->ind_buf.index = 0; |
| 3056 | |
| 3057 | scrq->ind_buf.indir_arr = |
| 3058 | dma_alloc_coherent(dev, |
| 3059 | IBMVNIC_IND_ARR_SZ, |
| 3060 | &scrq->ind_buf.indir_dma, |
| 3061 | GFP_KERNEL); |
| 3062 | |
| 3063 | if (!scrq->ind_buf.indir_arr) |
| 3064 | goto indir_failed; |
| 3065 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3066 | spin_lock_init(&scrq->lock); |
| 3067 | |
| 3068 | netdev_dbg(adapter->netdev, |
| 3069 | "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n", |
| 3070 | scrq->crq_num, scrq->hw_irq, scrq->irq); |
| 3071 | |
| 3072 | return scrq; |
| 3073 | |
Thomas Falcon | f019fb6 | 2020-11-18 19:12:17 -0600 | [diff] [blame] | 3074 | indir_failed: |
| 3075 | do { |
| 3076 | rc = plpar_hcall_norets(H_FREE_SUB_CRQ, |
| 3077 | adapter->vdev->unit_address, |
| 3078 | scrq->crq_num); |
| 3079 | } while (rc == H_BUSY || rc == H_IS_LONG_BUSY(rc)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3080 | reg_failed: |
| 3081 | dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE, |
| 3082 | DMA_BIDIRECTIONAL); |
| 3083 | map_failed: |
| 3084 | free_pages((unsigned long)scrq->msgs, 2); |
| 3085 | zero_page_failed: |
| 3086 | kfree(scrq); |
| 3087 | |
| 3088 | return NULL; |
| 3089 | } |
| 3090 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3091 | 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] | 3092 | { |
| 3093 | int i; |
| 3094 | |
| 3095 | if (adapter->tx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3096 | for (i = 0; i < adapter->num_active_tx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3097 | if (!adapter->tx_scrq[i]) |
| 3098 | continue; |
| 3099 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3100 | netdev_dbg(adapter->netdev, "Releasing tx_scrq[%d]\n", |
| 3101 | i); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3102 | if (adapter->tx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3103 | free_irq(adapter->tx_scrq[i]->irq, |
| 3104 | adapter->tx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3105 | irq_dispose_mapping(adapter->tx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3106 | adapter->tx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3107 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3108 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3109 | release_sub_crq_queue(adapter, adapter->tx_scrq[i], |
| 3110 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3111 | } |
| 3112 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3113 | kfree(adapter->tx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3114 | adapter->tx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3115 | adapter->num_active_tx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | if (adapter->rx_scrq) { |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3119 | for (i = 0; i < adapter->num_active_rx_scrqs; i++) { |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3120 | if (!adapter->rx_scrq[i]) |
| 3121 | continue; |
| 3122 | |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3123 | netdev_dbg(adapter->netdev, "Releasing rx_scrq[%d]\n", |
| 3124 | i); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3125 | if (adapter->rx_scrq[i]->irq) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3126 | free_irq(adapter->rx_scrq[i]->irq, |
| 3127 | adapter->rx_scrq[i]); |
Thomas Falcon | 88eb98a | 2016-07-06 15:35:16 -0500 | [diff] [blame] | 3128 | irq_dispose_mapping(adapter->rx_scrq[i]->irq); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3129 | adapter->rx_scrq[i]->irq = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3130 | } |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3131 | |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3132 | release_sub_crq_queue(adapter, adapter->rx_scrq[i], |
| 3133 | do_h_free); |
Nathan Fontenot | b510888 | 2017-03-30 02:49:18 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
Nathan Fontenot | 9501df3 | 2017-03-15 23:38:07 -0400 | [diff] [blame] | 3136 | kfree(adapter->rx_scrq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3137 | adapter->rx_scrq = NULL; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3138 | adapter->num_active_rx_scrqs = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3139 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | static int disable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3143 | struct ibmvnic_sub_crq_queue *scrq) |
| 3144 | { |
| 3145 | struct device *dev = &adapter->vdev->dev; |
| 3146 | unsigned long rc; |
| 3147 | |
| 3148 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3149 | H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3150 | if (rc) |
| 3151 | dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n", |
| 3152 | scrq->hw_irq, rc); |
| 3153 | return rc; |
| 3154 | } |
| 3155 | |
| 3156 | static int enable_scrq_irq(struct ibmvnic_adapter *adapter, |
| 3157 | struct ibmvnic_sub_crq_queue *scrq) |
| 3158 | { |
| 3159 | struct device *dev = &adapter->vdev->dev; |
| 3160 | unsigned long rc; |
| 3161 | |
| 3162 | if (scrq->hw_irq > 0x100000000ULL) { |
| 3163 | dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq); |
| 3164 | return 1; |
| 3165 | } |
| 3166 | |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 3167 | if (test_bit(0, &adapter->resetting) && |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3168 | adapter->reset_reason == VNIC_RESET_MOBILITY) { |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3169 | u64 val = (0xff000000) | scrq->hw_irq; |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3170 | |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3171 | rc = plpar_hcall_norets(H_EOI, val); |
Juliet Kim | 2df5c60 | 2019-11-20 10:50:04 -0500 | [diff] [blame] | 3172 | /* H_EOI would fail with rc = H_FUNCTION when running |
| 3173 | * in XIVE mode which is expected, but not an error. |
| 3174 | */ |
Lijun Pan | 91dc5d2 | 2021-02-11 00:43:22 -0600 | [diff] [blame] | 3175 | if (rc && rc != H_FUNCTION) |
Juliet Kim | 284f87d | 2019-11-20 10:50:03 -0500 | [diff] [blame] | 3176 | dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n", |
| 3177 | val, rc); |
Nathan Fontenot | 73f9d36 | 2018-05-22 11:21:10 -0500 | [diff] [blame] | 3178 | } |
Thomas Falcon | f23e064 | 2018-04-15 18:53:36 -0500 | [diff] [blame] | 3179 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3180 | rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address, |
| 3181 | H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0); |
| 3182 | if (rc) |
| 3183 | dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n", |
| 3184 | scrq->hw_irq, rc); |
| 3185 | return rc; |
| 3186 | } |
| 3187 | |
| 3188 | static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter, |
| 3189 | struct ibmvnic_sub_crq_queue *scrq) |
| 3190 | { |
| 3191 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3192 | struct ibmvnic_tx_pool *tx_pool; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3193 | struct ibmvnic_tx_buff *txbuff; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3194 | struct netdev_queue *txq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3195 | union sub_crq *next; |
| 3196 | int index; |
Thomas Falcon | c62aa37 | 2020-11-18 19:12:20 -0600 | [diff] [blame] | 3197 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3198 | |
| 3199 | restart_loop: |
| 3200 | while (pending_scrq(adapter, scrq)) { |
| 3201 | unsigned int pool = scrq->pool_index; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3202 | int num_entries = 0; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3203 | int total_bytes = 0; |
| 3204 | int num_packets = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3205 | |
| 3206 | next = ibmvnic_next_scrq(adapter, scrq); |
| 3207 | for (i = 0; i < next->tx_comp.num_comps; i++) { |
Thomas Falcon | ba246c1 | 2020-12-01 09:52:11 -0600 | [diff] [blame] | 3208 | if (next->tx_comp.rcs[i]) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3209 | dev_err(dev, "tx error %x\n", |
| 3210 | next->tx_comp.rcs[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3211 | index = be32_to_cpu(next->tx_comp.correlators[i]); |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3212 | if (index & IBMVNIC_TSO_POOL_MASK) { |
| 3213 | tx_pool = &adapter->tso_pool[pool]; |
| 3214 | index &= ~IBMVNIC_TSO_POOL_MASK; |
| 3215 | } else { |
| 3216 | tx_pool = &adapter->tx_pool[pool]; |
| 3217 | } |
| 3218 | |
| 3219 | txbuff = &tx_pool->tx_buff[index]; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3220 | num_packets++; |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3221 | num_entries += txbuff->num_entries; |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3222 | if (txbuff->skb) { |
| 3223 | total_bytes += txbuff->skb->len; |
| 3224 | dev_consume_skb_irq(txbuff->skb); |
| 3225 | txbuff->skb = NULL; |
| 3226 | } else { |
| 3227 | netdev_warn(adapter->netdev, |
| 3228 | "TX completion received with NULL socket buffer\n"); |
| 3229 | } |
Thomas Falcon | 06b3e35 | 2018-03-16 20:00:28 -0500 | [diff] [blame] | 3230 | tx_pool->free_map[tx_pool->producer_index] = index; |
| 3231 | tx_pool->producer_index = |
| 3232 | (tx_pool->producer_index + 1) % |
| 3233 | tx_pool->num_buffers; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3234 | } |
| 3235 | /* remove tx_comp scrq*/ |
| 3236 | next->tx_comp.first = 0; |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3237 | |
Thomas Falcon | 0d97338 | 2020-11-18 19:12:19 -0600 | [diff] [blame] | 3238 | txq = netdev_get_tx_queue(adapter->netdev, scrq->pool_index); |
| 3239 | netdev_tx_completed_queue(txq, num_packets, total_bytes); |
| 3240 | |
Thomas Falcon | ffc385b | 2018-02-18 10:08:41 -0600 | [diff] [blame] | 3241 | if (atomic_sub_return(num_entries, &scrq->used) <= |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3242 | (adapter->req_tx_entries_per_subcrq / 2) && |
| 3243 | __netif_subqueue_stopped(adapter->netdev, |
| 3244 | scrq->pool_index)) { |
| 3245 | netif_wake_subqueue(adapter->netdev, scrq->pool_index); |
Thomas Falcon | 0aecb13 | 2018-02-26 18:10:58 -0600 | [diff] [blame] | 3246 | netdev_dbg(adapter->netdev, "Started queue %d\n", |
| 3247 | scrq->pool_index); |
Nathan Fontenot | 7c3e7de | 2017-05-03 14:05:25 -0400 | [diff] [blame] | 3248 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | enable_scrq_irq(adapter, scrq); |
| 3252 | |
| 3253 | if (pending_scrq(adapter, scrq)) { |
| 3254 | disable_scrq_irq(adapter, scrq); |
| 3255 | goto restart_loop; |
| 3256 | } |
| 3257 | |
| 3258 | return 0; |
| 3259 | } |
| 3260 | |
| 3261 | static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance) |
| 3262 | { |
| 3263 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3264 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3265 | |
| 3266 | disable_scrq_irq(adapter, scrq); |
| 3267 | ibmvnic_complete_tx(adapter, scrq); |
| 3268 | |
| 3269 | return IRQ_HANDLED; |
| 3270 | } |
| 3271 | |
| 3272 | static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance) |
| 3273 | { |
| 3274 | struct ibmvnic_sub_crq_queue *scrq = instance; |
| 3275 | struct ibmvnic_adapter *adapter = scrq->adapter; |
| 3276 | |
Nathan Fontenot | 09fb35e | 2018-01-10 10:40:09 -0600 | [diff] [blame] | 3277 | /* When booting a kdump kernel we can hit pending interrupts |
| 3278 | * prior to completing driver initialization. |
| 3279 | */ |
| 3280 | if (unlikely(adapter->state != VNIC_OPEN)) |
| 3281 | return IRQ_NONE; |
| 3282 | |
John Allen | 3d52b59 | 2017-08-02 16:44:14 -0500 | [diff] [blame] | 3283 | adapter->rx_stats_buffers[scrq->scrq_num].interrupts++; |
| 3284 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3285 | if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) { |
| 3286 | disable_scrq_irq(adapter, scrq); |
| 3287 | __napi_schedule(&adapter->napi[scrq->scrq_num]); |
| 3288 | } |
| 3289 | |
| 3290 | return IRQ_HANDLED; |
| 3291 | } |
| 3292 | |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3293 | static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter) |
| 3294 | { |
| 3295 | struct device *dev = &adapter->vdev->dev; |
| 3296 | struct ibmvnic_sub_crq_queue *scrq; |
| 3297 | int i = 0, j = 0; |
| 3298 | int rc = 0; |
| 3299 | |
| 3300 | for (i = 0; i < adapter->req_tx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3301 | netdev_dbg(adapter->netdev, "Initializing tx_scrq[%d] irq\n", |
| 3302 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3303 | scrq = adapter->tx_scrq[i]; |
| 3304 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
| 3305 | |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3306 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3307 | rc = -EINVAL; |
| 3308 | dev_err(dev, "Error mapping irq\n"); |
| 3309 | goto req_tx_irq_failed; |
| 3310 | } |
| 3311 | |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3312 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-tx%d", |
| 3313 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3314 | rc = request_irq(scrq->irq, ibmvnic_interrupt_tx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3315 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3316 | |
| 3317 | if (rc) { |
| 3318 | dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n", |
| 3319 | scrq->irq, rc); |
| 3320 | irq_dispose_mapping(scrq->irq); |
Nathan Fontenot | af9090c | 2018-02-20 11:04:18 -0600 | [diff] [blame] | 3321 | goto req_tx_irq_failed; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | for (i = 0; i < adapter->req_rx_queues; i++) { |
Nathan Fontenot | d1cf33d | 2017-08-08 15:24:05 -0500 | [diff] [blame] | 3326 | netdev_dbg(adapter->netdev, "Initializing rx_scrq[%d] irq\n", |
| 3327 | i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3328 | scrq = adapter->rx_scrq[i]; |
| 3329 | scrq->irq = irq_create_mapping(NULL, scrq->hw_irq); |
Michael Ellerman | 99c1790 | 2016-09-10 19:59:05 +1000 | [diff] [blame] | 3330 | if (!scrq->irq) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3331 | rc = -EINVAL; |
| 3332 | dev_err(dev, "Error mapping irq\n"); |
| 3333 | goto req_rx_irq_failed; |
| 3334 | } |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3335 | snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-rx%d", |
| 3336 | adapter->vdev->unit_address, i); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3337 | rc = request_irq(scrq->irq, ibmvnic_interrupt_rx, |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 3338 | 0, scrq->name, scrq); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3339 | if (rc) { |
| 3340 | dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n", |
| 3341 | scrq->irq, rc); |
| 3342 | irq_dispose_mapping(scrq->irq); |
| 3343 | goto req_rx_irq_failed; |
| 3344 | } |
| 3345 | } |
| 3346 | return rc; |
| 3347 | |
| 3348 | req_rx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3349 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3350 | free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]); |
| 3351 | irq_dispose_mapping(adapter->rx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3352 | } |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3353 | i = adapter->req_tx_queues; |
| 3354 | req_tx_irq_failed: |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3355 | for (j = 0; j < i; j++) { |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3356 | free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]); |
Thomas Falcon | 27a2145 | 2020-07-29 16:36:32 -0500 | [diff] [blame] | 3357 | irq_dispose_mapping(adapter->tx_scrq[j]->irq); |
Thomas Falcon | 8bf371e | 2016-10-27 12:28:52 -0500 | [diff] [blame] | 3358 | } |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3359 | release_sub_crqs(adapter, 1); |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3360 | return rc; |
| 3361 | } |
| 3362 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3363 | static int init_sub_crqs(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3364 | { |
| 3365 | struct device *dev = &adapter->vdev->dev; |
| 3366 | struct ibmvnic_sub_crq_queue **allqueues; |
| 3367 | int registered_queues = 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3368 | int total_queues; |
| 3369 | int more = 0; |
Thomas Falcon | ea22d51 | 2016-07-06 15:35:17 -0500 | [diff] [blame] | 3370 | int i; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3371 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3372 | total_queues = adapter->req_tx_queues + adapter->req_rx_queues; |
| 3373 | |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3374 | allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3375 | if (!allqueues) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3376 | return -1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3377 | |
| 3378 | for (i = 0; i < total_queues; i++) { |
| 3379 | allqueues[i] = init_sub_crq_queue(adapter); |
| 3380 | if (!allqueues[i]) { |
| 3381 | dev_warn(dev, "Couldn't allocate all sub-crqs\n"); |
| 3382 | break; |
| 3383 | } |
| 3384 | registered_queues++; |
| 3385 | } |
| 3386 | |
| 3387 | /* Make sure we were able to register the minimum number of queues */ |
| 3388 | if (registered_queues < |
| 3389 | adapter->min_tx_queues + adapter->min_rx_queues) { |
| 3390 | dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n"); |
| 3391 | goto tx_failed; |
| 3392 | } |
| 3393 | |
| 3394 | /* Distribute the failed allocated queues*/ |
| 3395 | for (i = 0; i < total_queues - registered_queues + more ; i++) { |
| 3396 | netdev_dbg(adapter->netdev, "Reducing number of queues\n"); |
| 3397 | switch (i % 3) { |
| 3398 | case 0: |
| 3399 | if (adapter->req_rx_queues > adapter->min_rx_queues) |
| 3400 | adapter->req_rx_queues--; |
| 3401 | else |
| 3402 | more++; |
| 3403 | break; |
| 3404 | case 1: |
| 3405 | if (adapter->req_tx_queues > adapter->min_tx_queues) |
| 3406 | adapter->req_tx_queues--; |
| 3407 | else |
| 3408 | more++; |
| 3409 | break; |
| 3410 | } |
| 3411 | } |
| 3412 | |
| 3413 | adapter->tx_scrq = kcalloc(adapter->req_tx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3414 | sizeof(*adapter->tx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3415 | if (!adapter->tx_scrq) |
| 3416 | goto tx_failed; |
| 3417 | |
| 3418 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3419 | adapter->tx_scrq[i] = allqueues[i]; |
| 3420 | adapter->tx_scrq[i]->pool_index = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3421 | adapter->num_active_tx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | adapter->rx_scrq = kcalloc(adapter->req_rx_queues, |
Nathan Fontenot | 1bb3c73 | 2017-04-25 15:01:10 -0400 | [diff] [blame] | 3425 | sizeof(*adapter->rx_scrq), GFP_KERNEL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3426 | if (!adapter->rx_scrq) |
| 3427 | goto rx_failed; |
| 3428 | |
| 3429 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3430 | adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues]; |
| 3431 | adapter->rx_scrq[i]->scrq_num = i; |
Nathan Fontenot | 82e3be3 | 2018-02-21 21:33:56 -0600 | [diff] [blame] | 3432 | adapter->num_active_rx_scrqs++; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3433 | } |
| 3434 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3435 | kfree(allqueues); |
| 3436 | return 0; |
| 3437 | |
| 3438 | rx_failed: |
| 3439 | kfree(adapter->tx_scrq); |
| 3440 | adapter->tx_scrq = NULL; |
| 3441 | tx_failed: |
| 3442 | for (i = 0; i < registered_queues; i++) |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 3443 | release_sub_crq_queue(adapter, allqueues[i], 1); |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3444 | kfree(allqueues); |
| 3445 | return -1; |
| 3446 | } |
| 3447 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 3448 | static void send_request_cap(struct ibmvnic_adapter *adapter, int retry) |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3449 | { |
| 3450 | struct device *dev = &adapter->vdev->dev; |
| 3451 | union ibmvnic_crq crq; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3452 | int max_entries; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3453 | |
| 3454 | if (!retry) { |
| 3455 | /* Sub-CRQ entries are 32 byte long */ |
| 3456 | int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4); |
| 3457 | |
| 3458 | if (adapter->min_tx_entries_per_subcrq > entries_page || |
| 3459 | adapter->min_rx_add_entries_per_subcrq > entries_page) { |
| 3460 | dev_err(dev, "Fatal, invalid entries per sub-crq\n"); |
| 3461 | return; |
| 3462 | } |
| 3463 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3464 | if (adapter->desired.mtu) |
| 3465 | adapter->req_mtu = adapter->desired.mtu; |
| 3466 | else |
| 3467 | adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3468 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 3469 | if (!adapter->desired.tx_entries) |
| 3470 | adapter->desired.tx_entries = |
| 3471 | adapter->max_tx_entries_per_subcrq; |
| 3472 | if (!adapter->desired.rx_entries) |
| 3473 | adapter->desired.rx_entries = |
| 3474 | adapter->max_rx_add_entries_per_subcrq; |
| 3475 | |
| 3476 | max_entries = IBMVNIC_MAX_LTB_SIZE / |
| 3477 | (adapter->req_mtu + IBMVNIC_BUFFER_HLEN); |
| 3478 | |
| 3479 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3480 | adapter->desired.tx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3481 | adapter->desired.tx_entries = max_entries; |
| 3482 | } |
| 3483 | |
| 3484 | if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) * |
| 3485 | adapter->desired.rx_entries > IBMVNIC_MAX_LTB_SIZE) { |
| 3486 | adapter->desired.rx_entries = max_entries; |
| 3487 | } |
| 3488 | |
| 3489 | if (adapter->desired.tx_entries) |
| 3490 | adapter->req_tx_entries_per_subcrq = |
| 3491 | adapter->desired.tx_entries; |
| 3492 | else |
| 3493 | adapter->req_tx_entries_per_subcrq = |
| 3494 | adapter->max_tx_entries_per_subcrq; |
| 3495 | |
| 3496 | if (adapter->desired.rx_entries) |
| 3497 | adapter->req_rx_add_entries_per_subcrq = |
| 3498 | adapter->desired.rx_entries; |
| 3499 | else |
| 3500 | adapter->req_rx_add_entries_per_subcrq = |
| 3501 | adapter->max_rx_add_entries_per_subcrq; |
| 3502 | |
| 3503 | if (adapter->desired.tx_queues) |
| 3504 | adapter->req_tx_queues = |
| 3505 | adapter->desired.tx_queues; |
| 3506 | else |
| 3507 | adapter->req_tx_queues = |
| 3508 | adapter->opt_tx_comp_sub_queues; |
| 3509 | |
| 3510 | if (adapter->desired.rx_queues) |
| 3511 | adapter->req_rx_queues = |
| 3512 | adapter->desired.rx_queues; |
| 3513 | else |
| 3514 | adapter->req_rx_queues = |
| 3515 | adapter->opt_rx_comp_queues; |
| 3516 | |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3517 | adapter->req_rx_add_queues = adapter->max_rx_add_queues; |
Nathan Fontenot | d346b9b | 2017-04-25 15:01:04 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3520 | memset(&crq, 0, sizeof(crq)); |
| 3521 | crq.request_capability.first = IBMVNIC_CRQ_CMD; |
| 3522 | crq.request_capability.cmd = REQUEST_CAPABILITY; |
| 3523 | |
| 3524 | crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3525 | crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3526 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3527 | ibmvnic_send_crq(adapter, &crq); |
| 3528 | |
| 3529 | crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3530 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3531 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3532 | ibmvnic_send_crq(adapter, &crq); |
| 3533 | |
| 3534 | crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3535 | crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3536 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3537 | ibmvnic_send_crq(adapter, &crq); |
| 3538 | |
| 3539 | crq.request_capability.capability = |
| 3540 | cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ); |
| 3541 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3542 | cpu_to_be64(adapter->req_tx_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3543 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3544 | ibmvnic_send_crq(adapter, &crq); |
| 3545 | |
| 3546 | crq.request_capability.capability = |
| 3547 | cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ); |
| 3548 | crq.request_capability.number = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3549 | cpu_to_be64(adapter->req_rx_add_entries_per_subcrq); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3550 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3551 | ibmvnic_send_crq(adapter, &crq); |
| 3552 | |
| 3553 | crq.request_capability.capability = cpu_to_be16(REQ_MTU); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3554 | crq.request_capability.number = cpu_to_be64(adapter->req_mtu); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3555 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3556 | ibmvnic_send_crq(adapter, &crq); |
| 3557 | |
| 3558 | if (adapter->netdev->flags & IFF_PROMISC) { |
| 3559 | if (adapter->promisc_supported) { |
| 3560 | crq.request_capability.capability = |
| 3561 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3562 | crq.request_capability.number = cpu_to_be64(1); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3563 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3564 | ibmvnic_send_crq(adapter, &crq); |
| 3565 | } |
| 3566 | } else { |
| 3567 | crq.request_capability.capability = |
| 3568 | cpu_to_be16(PROMISC_REQUESTED); |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 3569 | crq.request_capability.number = cpu_to_be64(0); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3570 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3571 | ibmvnic_send_crq(adapter, &crq); |
| 3572 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | static int pending_scrq(struct ibmvnic_adapter *adapter, |
| 3576 | struct ibmvnic_sub_crq_queue *scrq) |
| 3577 | { |
| 3578 | union sub_crq *entry = &scrq->msgs[scrq->cur]; |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3579 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3580 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3581 | rc = !!(entry->generic.first & IBMVNIC_CRQ_CMD_RSP); |
| 3582 | |
| 3583 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 3584 | * contents of the SCRQ descriptor |
| 3585 | */ |
| 3586 | dma_rmb(); |
| 3587 | |
| 3588 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter, |
| 3592 | struct ibmvnic_sub_crq_queue *scrq) |
| 3593 | { |
| 3594 | union sub_crq *entry; |
| 3595 | unsigned long flags; |
| 3596 | |
| 3597 | spin_lock_irqsave(&scrq->lock, flags); |
| 3598 | entry = &scrq->msgs[scrq->cur]; |
| 3599 | if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 3600 | if (++scrq->cur == scrq->size) |
| 3601 | scrq->cur = 0; |
| 3602 | } else { |
| 3603 | entry = NULL; |
| 3604 | } |
| 3605 | spin_unlock_irqrestore(&scrq->lock, flags); |
| 3606 | |
Lijun Pan | 665ab1e | 2021-01-29 19:19:04 -0600 | [diff] [blame] | 3607 | /* Ensure that the SCRQ valid flag is loaded prior to loading the |
| 3608 | * contents of the SCRQ descriptor |
Thomas Falcon | b71ec95 | 2020-12-01 09:52:10 -0600 | [diff] [blame] | 3609 | */ |
| 3610 | dma_rmb(); |
| 3611 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3612 | return entry; |
| 3613 | } |
| 3614 | |
| 3615 | static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter) |
| 3616 | { |
| 3617 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
| 3618 | union ibmvnic_crq *crq; |
| 3619 | |
| 3620 | crq = &queue->msgs[queue->cur]; |
| 3621 | if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) { |
| 3622 | if (++queue->cur == queue->size) |
| 3623 | queue->cur = 0; |
| 3624 | } else { |
| 3625 | crq = NULL; |
| 3626 | } |
| 3627 | |
| 3628 | return crq; |
| 3629 | } |
| 3630 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 3631 | static void print_subcrq_error(struct device *dev, int rc, const char *func) |
| 3632 | { |
| 3633 | switch (rc) { |
| 3634 | case H_PARAMETER: |
| 3635 | dev_warn_ratelimited(dev, |
| 3636 | "%s failed: Send request is malformed or adapter failover pending. (rc=%d)\n", |
| 3637 | func, rc); |
| 3638 | break; |
| 3639 | case H_CLOSED: |
| 3640 | dev_warn_ratelimited(dev, |
| 3641 | "%s failed: Backing queue closed. Adapter is down or failover pending. (rc=%d)\n", |
| 3642 | func, rc); |
| 3643 | break; |
| 3644 | default: |
| 3645 | dev_err_ratelimited(dev, "%s failed: (rc=%d)\n", func, rc); |
| 3646 | break; |
| 3647 | } |
| 3648 | } |
| 3649 | |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3650 | static int send_subcrq_indirect(struct ibmvnic_adapter *adapter, |
| 3651 | u64 remote_handle, u64 ioba, u64 num_entries) |
| 3652 | { |
| 3653 | unsigned int ua = adapter->vdev->unit_address; |
| 3654 | struct device *dev = &adapter->vdev->dev; |
| 3655 | int rc; |
| 3656 | |
| 3657 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 3658 | dma_wmb(); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3659 | rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua, |
| 3660 | cpu_to_be64(remote_handle), |
| 3661 | ioba, num_entries); |
| 3662 | |
Thomas Falcon | 2d14d37 | 2018-07-13 12:03:32 -0500 | [diff] [blame] | 3663 | if (rc) |
| 3664 | print_subcrq_error(dev, rc, __func__); |
Thomas Falcon | ad7775d | 2016-04-01 17:20:34 -0500 | [diff] [blame] | 3665 | |
| 3666 | return rc; |
| 3667 | } |
| 3668 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3669 | static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter, |
| 3670 | union ibmvnic_crq *crq) |
| 3671 | { |
| 3672 | unsigned int ua = adapter->vdev->unit_address; |
| 3673 | struct device *dev = &adapter->vdev->dev; |
| 3674 | u64 *u64_crq = (u64 *)crq; |
| 3675 | int rc; |
| 3676 | |
| 3677 | netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 3678 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 3679 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3680 | |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 3681 | if (!adapter->crq.active && |
| 3682 | crq->generic.first != IBMVNIC_CRQ_INIT_CMD) { |
| 3683 | dev_warn(dev, "Invalid request detected while CRQ is inactive, possible device state change during reset\n"); |
| 3684 | return -EINVAL; |
| 3685 | } |
| 3686 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3687 | /* Make sure the hypervisor sees the complete request */ |
Lijun Pan | 1a42156 | 2021-02-12 20:36:46 -0600 | [diff] [blame] | 3688 | dma_wmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3689 | |
| 3690 | rc = plpar_hcall_norets(H_SEND_CRQ, ua, |
| 3691 | cpu_to_be64(u64_crq[0]), |
| 3692 | cpu_to_be64(u64_crq[1])); |
| 3693 | |
| 3694 | if (rc) { |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 3695 | if (rc == H_CLOSED) { |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3696 | dev_warn(dev, "CRQ Queue closed\n"); |
Lijun Pan | fa68bfa | 2020-08-19 17:52:24 -0500 | [diff] [blame] | 3697 | /* do not reset, report the fail, wait for passive init from server */ |
Nathan Fontenot | ec95dff | 2018-02-07 13:00:24 -0600 | [diff] [blame] | 3698 | } |
| 3699 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3700 | dev_warn(dev, "Send error (rc=%d)\n", rc); |
| 3701 | } |
| 3702 | |
| 3703 | return rc; |
| 3704 | } |
| 3705 | |
| 3706 | static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter) |
| 3707 | { |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3708 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3709 | union ibmvnic_crq crq; |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3710 | int retries = 100; |
| 3711 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3712 | |
| 3713 | memset(&crq, 0, sizeof(crq)); |
| 3714 | crq.generic.first = IBMVNIC_CRQ_INIT_CMD; |
| 3715 | crq.generic.cmd = IBMVNIC_CRQ_INIT; |
| 3716 | netdev_dbg(adapter->netdev, "Sending CRQ init\n"); |
| 3717 | |
Thomas Falcon | 36a782f | 2020-08-31 11:59:57 -0500 | [diff] [blame] | 3718 | do { |
| 3719 | rc = ibmvnic_send_crq(adapter, &crq); |
| 3720 | if (rc != H_CLOSED) |
| 3721 | break; |
| 3722 | retries--; |
| 3723 | msleep(50); |
| 3724 | |
| 3725 | } while (retries > 0); |
| 3726 | |
| 3727 | if (rc) { |
| 3728 | dev_err(dev, "Failed to send init request, rc = %d\n", rc); |
| 3729 | return rc; |
| 3730 | } |
| 3731 | |
| 3732 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3733 | } |
| 3734 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3735 | static int send_version_xchg(struct ibmvnic_adapter *adapter) |
| 3736 | { |
| 3737 | union ibmvnic_crq crq; |
| 3738 | |
| 3739 | memset(&crq, 0, sizeof(crq)); |
| 3740 | crq.version_exchange.first = IBMVNIC_CRQ_CMD; |
| 3741 | crq.version_exchange.cmd = VERSION_EXCHANGE; |
| 3742 | crq.version_exchange.version = cpu_to_be16(ibmvnic_version); |
| 3743 | |
| 3744 | return ibmvnic_send_crq(adapter, &crq); |
| 3745 | } |
| 3746 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3747 | struct vnic_login_client_data { |
| 3748 | u8 type; |
| 3749 | __be16 len; |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 3750 | char name[]; |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3751 | } __packed; |
| 3752 | |
| 3753 | static int vnic_client_data_len(struct ibmvnic_adapter *adapter) |
| 3754 | { |
| 3755 | int len; |
| 3756 | |
| 3757 | /* Calculate the amount of buffer space needed for the |
| 3758 | * vnic client data in the login buffer. There are four entries, |
| 3759 | * OS name, LPAR name, device name, and a null last entry. |
| 3760 | */ |
| 3761 | len = 4 * sizeof(struct vnic_login_client_data); |
| 3762 | len += 6; /* "Linux" plus NULL */ |
| 3763 | len += strlen(utsname()->nodename) + 1; |
| 3764 | len += strlen(adapter->netdev->name) + 1; |
| 3765 | |
| 3766 | return len; |
| 3767 | } |
| 3768 | |
| 3769 | static void vnic_add_client_data(struct ibmvnic_adapter *adapter, |
| 3770 | struct vnic_login_client_data *vlcd) |
| 3771 | { |
| 3772 | const char *os_name = "Linux"; |
| 3773 | int len; |
| 3774 | |
| 3775 | /* Type 1 - LPAR OS */ |
| 3776 | vlcd->type = 1; |
| 3777 | len = strlen(os_name) + 1; |
| 3778 | vlcd->len = cpu_to_be16(len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 3779 | strncpy(vlcd->name, os_name, len); |
| 3780 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3781 | |
| 3782 | /* Type 2 - LPAR name */ |
| 3783 | vlcd->type = 2; |
| 3784 | len = strlen(utsname()->nodename) + 1; |
| 3785 | vlcd->len = cpu_to_be16(len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 3786 | strncpy(vlcd->name, utsname()->nodename, len); |
| 3787 | vlcd = (struct vnic_login_client_data *)(vlcd->name + len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3788 | |
| 3789 | /* Type 3 - device name */ |
| 3790 | vlcd->type = 3; |
| 3791 | len = strlen(adapter->netdev->name) + 1; |
| 3792 | vlcd->len = cpu_to_be16(len); |
Kees Cook | 08ea556 | 2018-04-10 15:26:43 -0700 | [diff] [blame] | 3793 | strncpy(vlcd->name, adapter->netdev->name, len); |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3794 | } |
| 3795 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 3796 | static int send_login(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3797 | { |
| 3798 | struct ibmvnic_login_rsp_buffer *login_rsp_buffer; |
| 3799 | struct ibmvnic_login_buffer *login_buffer; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3800 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3801 | struct vnic_login_client_data *vlcd; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3802 | dma_addr_t rsp_buffer_token; |
| 3803 | dma_addr_t buffer_token; |
| 3804 | size_t rsp_buffer_size; |
| 3805 | union ibmvnic_crq crq; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3806 | int client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3807 | size_t buffer_size; |
| 3808 | __be64 *tx_list_p; |
| 3809 | __be64 *rx_list_p; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3810 | int rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3811 | int i; |
| 3812 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 3813 | if (!adapter->tx_scrq || !adapter->rx_scrq) { |
| 3814 | netdev_err(adapter->netdev, |
| 3815 | "RX or TX queues are not allocated, device login failed\n"); |
| 3816 | return -1; |
| 3817 | } |
| 3818 | |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 3819 | release_login_buffer(adapter); |
Thomas Falcon | 34f0f4e | 2018-02-13 18:23:40 -0600 | [diff] [blame] | 3820 | release_login_rsp_buffer(adapter); |
Lijun Pan | a0c8be5 | 2020-12-19 15:39:19 -0600 | [diff] [blame] | 3821 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3822 | client_data_len = vnic_client_data_len(adapter); |
| 3823 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3824 | buffer_size = |
| 3825 | sizeof(struct ibmvnic_login_buffer) + |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3826 | sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues) + |
| 3827 | client_data_len; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3828 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3829 | login_buffer = kzalloc(buffer_size, GFP_ATOMIC); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3830 | if (!login_buffer) |
| 3831 | goto buf_alloc_failed; |
| 3832 | |
| 3833 | buffer_token = dma_map_single(dev, login_buffer, buffer_size, |
| 3834 | DMA_TO_DEVICE); |
| 3835 | if (dma_mapping_error(dev, buffer_token)) { |
| 3836 | dev_err(dev, "Couldn't map login buffer\n"); |
| 3837 | goto buf_map_failed; |
| 3838 | } |
| 3839 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 3840 | rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) + |
| 3841 | sizeof(u64) * adapter->req_tx_queues + |
| 3842 | sizeof(u64) * adapter->req_rx_queues + |
| 3843 | sizeof(u64) * adapter->req_rx_queues + |
| 3844 | sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3845 | |
| 3846 | login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC); |
| 3847 | if (!login_rsp_buffer) |
| 3848 | goto buf_rsp_alloc_failed; |
| 3849 | |
| 3850 | rsp_buffer_token = dma_map_single(dev, login_rsp_buffer, |
| 3851 | rsp_buffer_size, DMA_FROM_DEVICE); |
| 3852 | if (dma_mapping_error(dev, rsp_buffer_token)) { |
| 3853 | dev_err(dev, "Couldn't map login rsp buffer\n"); |
| 3854 | goto buf_rsp_map_failed; |
| 3855 | } |
Nathan Fontenot | 661a262 | 2017-04-19 13:44:58 -0400 | [diff] [blame] | 3856 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3857 | adapter->login_buf = login_buffer; |
| 3858 | adapter->login_buf_token = buffer_token; |
| 3859 | adapter->login_buf_sz = buffer_size; |
| 3860 | adapter->login_rsp_buf = login_rsp_buffer; |
| 3861 | adapter->login_rsp_buf_token = rsp_buffer_token; |
| 3862 | adapter->login_rsp_buf_sz = rsp_buffer_size; |
| 3863 | |
| 3864 | login_buffer->len = cpu_to_be32(buffer_size); |
| 3865 | login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB); |
| 3866 | login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues); |
| 3867 | login_buffer->off_txcomp_subcrqs = |
| 3868 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer)); |
| 3869 | login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues); |
| 3870 | login_buffer->off_rxcomp_subcrqs = |
| 3871 | cpu_to_be32(sizeof(struct ibmvnic_login_buffer) + |
| 3872 | sizeof(u64) * adapter->req_tx_queues); |
| 3873 | login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token); |
| 3874 | login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size); |
| 3875 | |
| 3876 | tx_list_p = (__be64 *)((char *)login_buffer + |
| 3877 | sizeof(struct ibmvnic_login_buffer)); |
| 3878 | rx_list_p = (__be64 *)((char *)login_buffer + |
| 3879 | sizeof(struct ibmvnic_login_buffer) + |
| 3880 | sizeof(u64) * adapter->req_tx_queues); |
| 3881 | |
| 3882 | for (i = 0; i < adapter->req_tx_queues; i++) { |
| 3883 | if (adapter->tx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 3884 | tx_list_p[i] = |
| 3885 | cpu_to_be64(adapter->tx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | for (i = 0; i < adapter->req_rx_queues; i++) { |
| 3890 | if (adapter->rx_scrq[i]) { |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 3891 | rx_list_p[i] = |
| 3892 | cpu_to_be64(adapter->rx_scrq[i]->crq_num); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | |
Nathan Fontenot | 37798d0 | 2017-11-08 11:23:56 -0600 | [diff] [blame] | 3896 | /* Insert vNIC login client data */ |
| 3897 | vlcd = (struct vnic_login_client_data *) |
| 3898 | ((char *)rx_list_p + (sizeof(u64) * adapter->req_rx_queues)); |
| 3899 | login_buffer->client_data_offset = |
| 3900 | cpu_to_be32((char *)vlcd - (char *)login_buffer); |
| 3901 | login_buffer->client_data_len = cpu_to_be32(client_data_len); |
| 3902 | |
| 3903 | vnic_add_client_data(adapter, vlcd); |
| 3904 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3905 | netdev_dbg(adapter->netdev, "Login Buffer:\n"); |
| 3906 | for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) { |
| 3907 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 3908 | ((unsigned long *)(adapter->login_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | memset(&crq, 0, sizeof(crq)); |
| 3912 | crq.login.first = IBMVNIC_CRQ_CMD; |
| 3913 | crq.login.cmd = LOGIN; |
| 3914 | crq.login.ioba = cpu_to_be32(buffer_token); |
| 3915 | crq.login.len = cpu_to_be32(buffer_size); |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 3916 | |
| 3917 | adapter->login_pending = true; |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3918 | rc = ibmvnic_send_crq(adapter, &crq); |
| 3919 | if (rc) { |
| 3920 | adapter->login_pending = false; |
| 3921 | netdev_err(adapter->netdev, "Failed to send login, rc=%d\n", rc); |
| 3922 | goto buf_rsp_map_failed; |
| 3923 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3924 | |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 3925 | return 0; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3926 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3927 | buf_rsp_map_failed: |
| 3928 | kfree(login_rsp_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3929 | adapter->login_rsp_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3930 | buf_rsp_alloc_failed: |
| 3931 | dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE); |
| 3932 | buf_map_failed: |
| 3933 | kfree(login_buffer); |
Dany Madden | c98d9cc | 2020-11-25 18:04:30 -0600 | [diff] [blame] | 3934 | adapter->login_buf = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3935 | buf_alloc_failed: |
Thomas Falcon | 20a8ab7 | 2018-02-26 18:10:59 -0600 | [diff] [blame] | 3936 | return -1; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3937 | } |
| 3938 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3939 | static int send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr, |
| 3940 | u32 len, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3941 | { |
| 3942 | union ibmvnic_crq crq; |
| 3943 | |
| 3944 | memset(&crq, 0, sizeof(crq)); |
| 3945 | crq.request_map.first = IBMVNIC_CRQ_CMD; |
| 3946 | crq.request_map.cmd = REQUEST_MAP; |
| 3947 | crq.request_map.map_id = map_id; |
| 3948 | crq.request_map.ioba = cpu_to_be32(addr); |
| 3949 | crq.request_map.len = cpu_to_be32(len); |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3950 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3951 | } |
| 3952 | |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3953 | static int send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3954 | { |
| 3955 | union ibmvnic_crq crq; |
| 3956 | |
| 3957 | memset(&crq, 0, sizeof(crq)); |
| 3958 | crq.request_unmap.first = IBMVNIC_CRQ_CMD; |
| 3959 | crq.request_unmap.cmd = REQUEST_UNMAP; |
| 3960 | crq.request_unmap.map_id = map_id; |
Thomas Falcon | 9c4eaab | 2018-05-23 13:37:57 -0500 | [diff] [blame] | 3961 | return ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3962 | } |
| 3963 | |
Lijun Pan | 69980d0 | 2020-09-27 20:13:28 -0500 | [diff] [blame] | 3964 | static void send_query_map(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3965 | { |
| 3966 | union ibmvnic_crq crq; |
| 3967 | |
| 3968 | memset(&crq, 0, sizeof(crq)); |
| 3969 | crq.query_map.first = IBMVNIC_CRQ_CMD; |
| 3970 | crq.query_map.cmd = QUERY_MAP; |
| 3971 | ibmvnic_send_crq(adapter, &crq); |
| 3972 | } |
| 3973 | |
| 3974 | /* Send a series of CRQs requesting various capabilities of the VNIC server */ |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 3975 | static void send_query_cap(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3976 | { |
| 3977 | union ibmvnic_crq crq; |
| 3978 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3979 | atomic_set(&adapter->running_cap_crqs, 0); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3980 | memset(&crq, 0, sizeof(crq)); |
| 3981 | crq.query_capability.first = IBMVNIC_CRQ_CMD; |
| 3982 | crq.query_capability.cmd = QUERY_CAPABILITY; |
| 3983 | |
| 3984 | crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3985 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3986 | ibmvnic_send_crq(adapter, &crq); |
| 3987 | |
| 3988 | crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3989 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3990 | ibmvnic_send_crq(adapter, &crq); |
| 3991 | |
| 3992 | crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3993 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3994 | ibmvnic_send_crq(adapter, &crq); |
| 3995 | |
| 3996 | crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 3997 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 3998 | ibmvnic_send_crq(adapter, &crq); |
| 3999 | |
| 4000 | crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4001 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4002 | ibmvnic_send_crq(adapter, &crq); |
| 4003 | |
| 4004 | crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4005 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4006 | ibmvnic_send_crq(adapter, &crq); |
| 4007 | |
| 4008 | crq.query_capability.capability = |
| 4009 | cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4010 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4011 | ibmvnic_send_crq(adapter, &crq); |
| 4012 | |
| 4013 | crq.query_capability.capability = |
| 4014 | cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4015 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4016 | ibmvnic_send_crq(adapter, &crq); |
| 4017 | |
| 4018 | crq.query_capability.capability = |
| 4019 | cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4020 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4021 | ibmvnic_send_crq(adapter, &crq); |
| 4022 | |
| 4023 | crq.query_capability.capability = |
| 4024 | cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4025 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4026 | ibmvnic_send_crq(adapter, &crq); |
| 4027 | |
| 4028 | crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4029 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4030 | ibmvnic_send_crq(adapter, &crq); |
| 4031 | |
| 4032 | crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4033 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4034 | ibmvnic_send_crq(adapter, &crq); |
| 4035 | |
| 4036 | crq.query_capability.capability = cpu_to_be16(MIN_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4037 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4038 | ibmvnic_send_crq(adapter, &crq); |
| 4039 | |
| 4040 | crq.query_capability.capability = cpu_to_be16(MAX_MTU); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4041 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4042 | ibmvnic_send_crq(adapter, &crq); |
| 4043 | |
| 4044 | crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4045 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4046 | ibmvnic_send_crq(adapter, &crq); |
| 4047 | |
| 4048 | crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4049 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4050 | ibmvnic_send_crq(adapter, &crq); |
| 4051 | |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4052 | crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION); |
| 4053 | atomic_inc(&adapter->running_cap_crqs); |
| 4054 | ibmvnic_send_crq(adapter, &crq); |
| 4055 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4056 | crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4057 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4058 | ibmvnic_send_crq(adapter, &crq); |
| 4059 | |
| 4060 | crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4061 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4062 | ibmvnic_send_crq(adapter, &crq); |
| 4063 | |
| 4064 | crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4065 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4066 | ibmvnic_send_crq(adapter, &crq); |
| 4067 | |
| 4068 | crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4069 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4070 | ibmvnic_send_crq(adapter, &crq); |
| 4071 | |
| 4072 | crq.query_capability.capability = |
| 4073 | cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4074 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4075 | ibmvnic_send_crq(adapter, &crq); |
| 4076 | |
| 4077 | crq.query_capability.capability = |
| 4078 | cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4079 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4080 | ibmvnic_send_crq(adapter, &crq); |
| 4081 | |
| 4082 | crq.query_capability.capability = |
| 4083 | cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4084 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4085 | ibmvnic_send_crq(adapter, &crq); |
| 4086 | |
| 4087 | crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ); |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4088 | atomic_inc(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4089 | ibmvnic_send_crq(adapter, &crq); |
| 4090 | } |
| 4091 | |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4092 | static void send_query_ip_offload(struct ibmvnic_adapter *adapter) |
| 4093 | { |
| 4094 | int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer); |
| 4095 | struct device *dev = &adapter->vdev->dev; |
| 4096 | union ibmvnic_crq crq; |
| 4097 | |
| 4098 | adapter->ip_offload_tok = |
| 4099 | dma_map_single(dev, |
| 4100 | &adapter->ip_offload_buf, |
| 4101 | buf_sz, |
| 4102 | DMA_FROM_DEVICE); |
| 4103 | |
| 4104 | if (dma_mapping_error(dev, adapter->ip_offload_tok)) { |
| 4105 | if (!firmware_has_feature(FW_FEATURE_CMO)) |
| 4106 | dev_err(dev, "Couldn't map offload buffer\n"); |
| 4107 | return; |
| 4108 | } |
| 4109 | |
| 4110 | memset(&crq, 0, sizeof(crq)); |
| 4111 | crq.query_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4112 | crq.query_ip_offload.cmd = QUERY_IP_OFFLOAD; |
| 4113 | crq.query_ip_offload.len = cpu_to_be32(buf_sz); |
| 4114 | crq.query_ip_offload.ioba = |
| 4115 | cpu_to_be32(adapter->ip_offload_tok); |
| 4116 | |
| 4117 | ibmvnic_send_crq(adapter, &crq); |
| 4118 | } |
| 4119 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4120 | static void send_control_ip_offload(struct ibmvnic_adapter *adapter) |
| 4121 | { |
| 4122 | struct ibmvnic_control_ip_offload_buffer *ctrl_buf = &adapter->ip_offload_ctrl; |
| 4123 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
| 4124 | struct device *dev = &adapter->vdev->dev; |
| 4125 | netdev_features_t old_hw_features = 0; |
| 4126 | union ibmvnic_crq crq; |
| 4127 | |
| 4128 | adapter->ip_offload_ctrl_tok = |
| 4129 | dma_map_single(dev, |
| 4130 | ctrl_buf, |
| 4131 | sizeof(adapter->ip_offload_ctrl), |
| 4132 | DMA_TO_DEVICE); |
| 4133 | |
| 4134 | if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) { |
| 4135 | dev_err(dev, "Couldn't map ip offload control buffer\n"); |
| 4136 | return; |
| 4137 | } |
| 4138 | |
| 4139 | ctrl_buf->len = cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4140 | ctrl_buf->version = cpu_to_be32(INITIAL_VERSION_IOB); |
| 4141 | ctrl_buf->ipv4_chksum = buf->ipv4_chksum; |
| 4142 | ctrl_buf->ipv6_chksum = buf->ipv6_chksum; |
| 4143 | ctrl_buf->tcp_ipv4_chksum = buf->tcp_ipv4_chksum; |
| 4144 | ctrl_buf->udp_ipv4_chksum = buf->udp_ipv4_chksum; |
| 4145 | ctrl_buf->tcp_ipv6_chksum = buf->tcp_ipv6_chksum; |
| 4146 | ctrl_buf->udp_ipv6_chksum = buf->udp_ipv6_chksum; |
| 4147 | ctrl_buf->large_tx_ipv4 = buf->large_tx_ipv4; |
| 4148 | ctrl_buf->large_tx_ipv6 = buf->large_tx_ipv6; |
| 4149 | |
| 4150 | /* large_rx disabled for now, additional features needed */ |
| 4151 | ctrl_buf->large_rx_ipv4 = 0; |
| 4152 | ctrl_buf->large_rx_ipv6 = 0; |
| 4153 | |
| 4154 | if (adapter->state != VNIC_PROBING) { |
| 4155 | old_hw_features = adapter->netdev->hw_features; |
| 4156 | adapter->netdev->hw_features = 0; |
| 4157 | } |
| 4158 | |
| 4159 | adapter->netdev->hw_features = NETIF_F_SG | NETIF_F_GSO | NETIF_F_GRO; |
| 4160 | |
| 4161 | if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum) |
| 4162 | adapter->netdev->hw_features |= NETIF_F_IP_CSUM; |
| 4163 | |
| 4164 | if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum) |
| 4165 | adapter->netdev->hw_features |= NETIF_F_IPV6_CSUM; |
| 4166 | |
| 4167 | if ((adapter->netdev->features & |
| 4168 | (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM))) |
| 4169 | adapter->netdev->hw_features |= NETIF_F_RXCSUM; |
| 4170 | |
| 4171 | if (buf->large_tx_ipv4) |
| 4172 | adapter->netdev->hw_features |= NETIF_F_TSO; |
| 4173 | if (buf->large_tx_ipv6) |
| 4174 | adapter->netdev->hw_features |= NETIF_F_TSO6; |
| 4175 | |
| 4176 | if (adapter->state == VNIC_PROBING) { |
| 4177 | adapter->netdev->features |= adapter->netdev->hw_features; |
| 4178 | } else if (old_hw_features != adapter->netdev->hw_features) { |
| 4179 | netdev_features_t tmp = 0; |
| 4180 | |
| 4181 | /* disable features no longer supported */ |
| 4182 | adapter->netdev->features &= adapter->netdev->hw_features; |
| 4183 | /* turn on features now supported if previously enabled */ |
| 4184 | tmp = (old_hw_features ^ adapter->netdev->hw_features) & |
| 4185 | adapter->netdev->hw_features; |
| 4186 | adapter->netdev->features |= |
| 4187 | tmp & adapter->netdev->wanted_features; |
| 4188 | } |
| 4189 | |
| 4190 | memset(&crq, 0, sizeof(crq)); |
| 4191 | crq.control_ip_offload.first = IBMVNIC_CRQ_CMD; |
| 4192 | crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD; |
| 4193 | crq.control_ip_offload.len = |
| 4194 | cpu_to_be32(sizeof(adapter->ip_offload_ctrl)); |
| 4195 | crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok); |
| 4196 | ibmvnic_send_crq(adapter, &crq); |
| 4197 | } |
| 4198 | |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4199 | static void handle_vpd_size_rsp(union ibmvnic_crq *crq, |
| 4200 | struct ibmvnic_adapter *adapter) |
| 4201 | { |
| 4202 | struct device *dev = &adapter->vdev->dev; |
| 4203 | |
| 4204 | if (crq->get_vpd_size_rsp.rc.code) { |
| 4205 | dev_err(dev, "Error retrieving VPD size, rc=%x\n", |
| 4206 | crq->get_vpd_size_rsp.rc.code); |
| 4207 | complete(&adapter->fw_done); |
| 4208 | return; |
| 4209 | } |
| 4210 | |
| 4211 | adapter->vpd->len = be64_to_cpu(crq->get_vpd_size_rsp.len); |
| 4212 | complete(&adapter->fw_done); |
| 4213 | } |
| 4214 | |
| 4215 | static void handle_vpd_rsp(union ibmvnic_crq *crq, |
| 4216 | struct ibmvnic_adapter *adapter) |
| 4217 | { |
| 4218 | struct device *dev = &adapter->vdev->dev; |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4219 | unsigned char *substr = NULL; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 4220 | u8 fw_level_len = 0; |
| 4221 | |
| 4222 | memset(adapter->fw_version, 0, 32); |
| 4223 | |
| 4224 | dma_unmap_single(dev, adapter->vpd->dma_addr, adapter->vpd->len, |
| 4225 | DMA_FROM_DEVICE); |
| 4226 | |
| 4227 | if (crq->get_vpd_rsp.rc.code) { |
| 4228 | dev_err(dev, "Error retrieving VPD from device, rc=%x\n", |
| 4229 | crq->get_vpd_rsp.rc.code); |
| 4230 | goto complete; |
| 4231 | } |
| 4232 | |
| 4233 | /* get the position of the firmware version info |
| 4234 | * located after the ASCII 'RM' substring in the buffer |
| 4235 | */ |
| 4236 | substr = strnstr(adapter->vpd->buff, "RM", adapter->vpd->len); |
| 4237 | if (!substr) { |
Desnes Augusto Nunes do Rosario | a107311 | 2018-02-01 16:04:30 -0200 | [diff] [blame] | 4238 | 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] | 4239 | goto complete; |
| 4240 | } |
| 4241 | |
| 4242 | /* get length of firmware level ASCII substring */ |
| 4243 | if ((substr + 2) < (adapter->vpd->buff + adapter->vpd->len)) { |
| 4244 | fw_level_len = *(substr + 2); |
| 4245 | } else { |
| 4246 | dev_info(dev, "Length of FW substr extrapolated VDP buff\n"); |
| 4247 | goto complete; |
| 4248 | } |
| 4249 | |
| 4250 | /* copy firmware version string from vpd into adapter */ |
| 4251 | if ((substr + 3 + fw_level_len) < |
| 4252 | (adapter->vpd->buff + adapter->vpd->len)) { |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4253 | 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] | 4254 | } else { |
| 4255 | dev_info(dev, "FW substr extrapolated VPD buff\n"); |
| 4256 | } |
| 4257 | |
| 4258 | complete: |
Desnes Augusto Nunes do Rosario | 21a2545 | 2018-02-05 14:33:55 -0200 | [diff] [blame] | 4259 | if (adapter->fw_version[0] == '\0') |
| 4260 | 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] | 4261 | complete(&adapter->fw_done); |
| 4262 | } |
| 4263 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4264 | static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter) |
| 4265 | { |
| 4266 | struct device *dev = &adapter->vdev->dev; |
| 4267 | struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4268 | int i; |
| 4269 | |
| 4270 | dma_unmap_single(dev, adapter->ip_offload_tok, |
| 4271 | sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE); |
| 4272 | |
| 4273 | netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n"); |
| 4274 | for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++) |
| 4275 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4276 | ((unsigned long *)(buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4277 | |
| 4278 | netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum); |
| 4279 | netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum); |
| 4280 | netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n", |
| 4281 | buf->tcp_ipv4_chksum); |
| 4282 | netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n", |
| 4283 | buf->tcp_ipv6_chksum); |
| 4284 | netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n", |
| 4285 | buf->udp_ipv4_chksum); |
| 4286 | netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n", |
| 4287 | buf->udp_ipv6_chksum); |
| 4288 | netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n", |
| 4289 | buf->large_tx_ipv4); |
| 4290 | netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n", |
| 4291 | buf->large_tx_ipv6); |
| 4292 | netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n", |
| 4293 | buf->large_rx_ipv4); |
| 4294 | netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n", |
| 4295 | buf->large_rx_ipv6); |
| 4296 | netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n", |
| 4297 | buf->max_ipv4_header_size); |
| 4298 | netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n", |
| 4299 | buf->max_ipv6_header_size); |
| 4300 | netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n", |
| 4301 | buf->max_tcp_header_size); |
| 4302 | netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n", |
| 4303 | buf->max_udp_header_size); |
| 4304 | netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n", |
| 4305 | buf->max_large_tx_size); |
| 4306 | netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n", |
| 4307 | buf->max_large_rx_size); |
| 4308 | netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n", |
| 4309 | buf->ipv6_extension_header); |
| 4310 | netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n", |
| 4311 | buf->tcp_pseudosum_req); |
| 4312 | netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n", |
| 4313 | buf->num_ipv6_ext_headers); |
| 4314 | netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n", |
| 4315 | buf->off_ipv6_ext_headers); |
| 4316 | |
Lijun Pan | 46899bd | 2020-09-27 20:13:30 -0500 | [diff] [blame] | 4317 | send_control_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4318 | } |
| 4319 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4320 | static const char *ibmvnic_fw_err_cause(u16 cause) |
| 4321 | { |
| 4322 | switch (cause) { |
| 4323 | case ADAPTER_PROBLEM: |
| 4324 | return "adapter problem"; |
| 4325 | case BUS_PROBLEM: |
| 4326 | return "bus problem"; |
| 4327 | case FW_PROBLEM: |
| 4328 | return "firmware problem"; |
| 4329 | case DD_PROBLEM: |
| 4330 | return "device driver problem"; |
| 4331 | case EEH_RECOVERY: |
| 4332 | return "EEH recovery"; |
| 4333 | case FW_UPDATED: |
| 4334 | return "firmware updated"; |
| 4335 | case LOW_MEMORY: |
| 4336 | return "low Memory"; |
| 4337 | default: |
| 4338 | return "unknown"; |
| 4339 | } |
| 4340 | } |
| 4341 | |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4342 | static void handle_error_indication(union ibmvnic_crq *crq, |
| 4343 | struct ibmvnic_adapter *adapter) |
| 4344 | { |
| 4345 | struct device *dev = &adapter->vdev->dev; |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4346 | u16 cause; |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4347 | |
Thomas Falcon | c9008d3 | 2018-08-06 21:39:59 -0500 | [diff] [blame] | 4348 | cause = be16_to_cpu(crq->error_indication.error_cause); |
| 4349 | |
| 4350 | dev_warn_ratelimited(dev, |
| 4351 | "Firmware reports %serror, cause: %s. Starting recovery...\n", |
| 4352 | crq->error_indication.flags |
| 4353 | & IBMVNIC_FATAL_ERROR ? "FATAL " : "", |
| 4354 | ibmvnic_fw_err_cause(cause)); |
Nathan Fontenot | 2f9de9b | 2017-04-21 15:38:52 -0400 | [diff] [blame] | 4355 | |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4356 | if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR) |
| 4357 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
John Allen | 8cb31cf | 2017-05-26 10:30:37 -0400 | [diff] [blame] | 4358 | else |
| 4359 | ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4360 | } |
| 4361 | |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4362 | static int handle_change_mac_rsp(union ibmvnic_crq *crq, |
| 4363 | struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4364 | { |
| 4365 | struct net_device *netdev = adapter->netdev; |
| 4366 | struct device *dev = &adapter->vdev->dev; |
| 4367 | long rc; |
| 4368 | |
| 4369 | rc = crq->change_mac_addr_rsp.rc.code; |
| 4370 | if (rc) { |
| 4371 | dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4372 | goto out; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4373 | } |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4374 | /* crq->change_mac_addr.mac_addr is the requested one |
| 4375 | * crq->change_mac_addr_rsp.mac_addr is the returned valid one. |
| 4376 | */ |
Thomas Falcon | 62740e9 | 2019-05-09 23:13:43 -0500 | [diff] [blame] | 4377 | ether_addr_copy(netdev->dev_addr, |
| 4378 | &crq->change_mac_addr_rsp.mac_addr[0]); |
Lijun Pan | d9b0e59 | 2020-10-20 17:39:19 -0500 | [diff] [blame] | 4379 | ether_addr_copy(adapter->mac_addr, |
| 4380 | &crq->change_mac_addr_rsp.mac_addr[0]); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4381 | out: |
| 4382 | complete(&adapter->fw_done); |
| 4383 | return rc; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | static void handle_request_cap_rsp(union ibmvnic_crq *crq, |
| 4387 | struct ibmvnic_adapter *adapter) |
| 4388 | { |
| 4389 | struct device *dev = &adapter->vdev->dev; |
| 4390 | u64 *req_value; |
| 4391 | char *name; |
| 4392 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4393 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4394 | switch (be16_to_cpu(crq->request_capability_rsp.capability)) { |
| 4395 | case REQ_TX_QUEUES: |
| 4396 | req_value = &adapter->req_tx_queues; |
| 4397 | name = "tx"; |
| 4398 | break; |
| 4399 | case REQ_RX_QUEUES: |
| 4400 | req_value = &adapter->req_rx_queues; |
| 4401 | name = "rx"; |
| 4402 | break; |
| 4403 | case REQ_RX_ADD_QUEUES: |
| 4404 | req_value = &adapter->req_rx_add_queues; |
| 4405 | name = "rx_add"; |
| 4406 | break; |
| 4407 | case REQ_TX_ENTRIES_PER_SUBCRQ: |
| 4408 | req_value = &adapter->req_tx_entries_per_subcrq; |
| 4409 | name = "tx_entries_per_subcrq"; |
| 4410 | break; |
| 4411 | case REQ_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4412 | req_value = &adapter->req_rx_add_entries_per_subcrq; |
| 4413 | name = "rx_add_entries_per_subcrq"; |
| 4414 | break; |
| 4415 | case REQ_MTU: |
| 4416 | req_value = &adapter->req_mtu; |
| 4417 | name = "mtu"; |
| 4418 | break; |
| 4419 | case PROMISC_REQUESTED: |
| 4420 | req_value = &adapter->promisc; |
| 4421 | name = "promisc"; |
| 4422 | break; |
| 4423 | default: |
| 4424 | dev_err(dev, "Got invalid cap request rsp %d\n", |
| 4425 | crq->request_capability.capability); |
| 4426 | return; |
| 4427 | } |
| 4428 | |
| 4429 | switch (crq->request_capability_rsp.rc.code) { |
| 4430 | case SUCCESS: |
| 4431 | break; |
| 4432 | case PARTIALSUCCESS: |
| 4433 | dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n", |
| 4434 | *req_value, |
Lijun Pan | 914789a | 2021-02-11 00:43:21 -0600 | [diff] [blame] | 4435 | (long)be64_to_cpu(crq->request_capability_rsp.number), |
| 4436 | name); |
John Allen | e791380 | 2018-01-18 16:27:12 -0600 | [diff] [blame] | 4437 | |
| 4438 | if (be16_to_cpu(crq->request_capability_rsp.capability) == |
| 4439 | REQ_MTU) { |
| 4440 | pr_err("mtu of %llu is not supported. Reverting.\n", |
| 4441 | *req_value); |
| 4442 | *req_value = adapter->fallback.mtu; |
| 4443 | } else { |
| 4444 | *req_value = |
| 4445 | be64_to_cpu(crq->request_capability_rsp.number); |
| 4446 | } |
| 4447 | |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 4448 | send_request_cap(adapter, 1); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4449 | return; |
| 4450 | default: |
| 4451 | dev_err(dev, "Error %d in request cap rsp\n", |
| 4452 | crq->request_capability_rsp.rc.code); |
| 4453 | return; |
| 4454 | } |
| 4455 | |
| 4456 | /* Done receiving requested capabilities, query IP offload support */ |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4457 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4458 | adapter->wait_capability = false; |
Lijun Pan | 16e811f | 2020-09-27 20:13:29 -0500 | [diff] [blame] | 4459 | send_query_ip_offload(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, |
| 4464 | struct ibmvnic_adapter *adapter) |
| 4465 | { |
| 4466 | struct device *dev = &adapter->vdev->dev; |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4467 | struct net_device *netdev = adapter->netdev; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4468 | struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf; |
| 4469 | struct ibmvnic_login_buffer *login = adapter->login_buf; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4470 | u64 *tx_handle_array; |
| 4471 | u64 *rx_handle_array; |
| 4472 | int num_tx_pools; |
| 4473 | int num_rx_pools; |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4474 | u64 *size_array; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4475 | int i; |
| 4476 | |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4477 | /* CHECK: Test/set of login_pending does not need to be atomic |
| 4478 | * because only ibmvnic_tasklet tests/clears this. |
| 4479 | */ |
| 4480 | if (!adapter->login_pending) { |
| 4481 | netdev_warn(netdev, "Ignoring unexpected login response\n"); |
| 4482 | return 0; |
| 4483 | } |
| 4484 | adapter->login_pending = false; |
| 4485 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4486 | dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4487 | DMA_TO_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4488 | dma_unmap_single(dev, adapter->login_rsp_buf_token, |
Thomas Falcon | 37e40fa | 2018-04-06 18:37:02 -0500 | [diff] [blame] | 4489 | adapter->login_rsp_buf_sz, DMA_FROM_DEVICE); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4490 | |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4491 | /* If the number of queues requested can't be allocated by the |
| 4492 | * server, the login response will return with code 1. We will need |
| 4493 | * to resend the login buffer with fewer queues requested. |
| 4494 | */ |
| 4495 | if (login_rsp_crq->generic.rc.code) { |
Nathan Fontenot | 64d92aa | 2018-04-11 10:09:32 -0500 | [diff] [blame] | 4496 | adapter->init_done_rc = login_rsp_crq->generic.rc.code; |
John Allen | 498cd8e | 2016-04-06 11:49:55 -0500 | [diff] [blame] | 4497 | complete(&adapter->init_done); |
| 4498 | return 0; |
| 4499 | } |
| 4500 | |
John Allen | c26eba0 | 2017-10-26 16:23:25 -0500 | [diff] [blame] | 4501 | netdev->mtu = adapter->req_mtu - ETH_HLEN; |
| 4502 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4503 | netdev_dbg(adapter->netdev, "Login Response Buffer:\n"); |
| 4504 | for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) { |
| 4505 | netdev_dbg(adapter->netdev, "%016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4506 | ((unsigned long *)(adapter->login_rsp_buf))[i]); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | /* Sanity checks */ |
| 4510 | if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs || |
| 4511 | (be32_to_cpu(login->num_rxcomp_subcrqs) * |
| 4512 | adapter->req_rx_add_queues != |
| 4513 | be32_to_cpu(login_rsp->num_rxadd_subcrqs))) { |
| 4514 | dev_err(dev, "FATAL: Inconsistent login and login rsp\n"); |
Dany Madden | 31d6b40 | 2020-11-25 18:04:24 -0600 | [diff] [blame] | 4515 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4516 | return -EIO; |
| 4517 | } |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4518 | size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4519 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size)); |
| 4520 | /* variable buffer sizes are not supported, so just read the |
| 4521 | * first entry. |
| 4522 | */ |
| 4523 | adapter->cur_rx_buf_sz = be64_to_cpu(size_array[0]); |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4524 | |
| 4525 | num_tx_pools = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs); |
| 4526 | num_rx_pools = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs); |
| 4527 | |
| 4528 | tx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4529 | be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs)); |
| 4530 | rx_handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) + |
| 4531 | be32_to_cpu(adapter->login_rsp_buf->off_rxadd_subcrqs)); |
| 4532 | |
| 4533 | for (i = 0; i < num_tx_pools; i++) |
| 4534 | adapter->tx_scrq[i]->handle = tx_handle_array[i]; |
| 4535 | |
| 4536 | for (i = 0; i < num_rx_pools; i++) |
| 4537 | adapter->rx_scrq[i]->handle = rx_handle_array[i]; |
| 4538 | |
Thomas Falcon | 507ebe6 | 2020-08-21 13:39:01 -0500 | [diff] [blame] | 4539 | adapter->num_active_tx_scrqs = num_tx_pools; |
| 4540 | adapter->num_active_rx_scrqs = num_rx_pools; |
Cristobal Forno | f3ae59c | 2020-08-19 13:16:23 -0500 | [diff] [blame] | 4541 | release_login_rsp_buffer(adapter); |
Thomas Falcon | a2c0f03 | 2018-02-21 18:18:30 -0600 | [diff] [blame] | 4542 | release_login_buffer(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4543 | complete(&adapter->init_done); |
| 4544 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4545 | return 0; |
| 4546 | } |
| 4547 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4548 | static void handle_request_unmap_rsp(union ibmvnic_crq *crq, |
| 4549 | struct ibmvnic_adapter *adapter) |
| 4550 | { |
| 4551 | struct device *dev = &adapter->vdev->dev; |
| 4552 | long rc; |
| 4553 | |
| 4554 | rc = crq->request_unmap_rsp.rc.code; |
| 4555 | if (rc) |
| 4556 | dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc); |
| 4557 | } |
| 4558 | |
| 4559 | static void handle_query_map_rsp(union ibmvnic_crq *crq, |
| 4560 | struct ibmvnic_adapter *adapter) |
| 4561 | { |
| 4562 | struct net_device *netdev = adapter->netdev; |
| 4563 | struct device *dev = &adapter->vdev->dev; |
| 4564 | long rc; |
| 4565 | |
| 4566 | rc = crq->query_map_rsp.rc.code; |
| 4567 | if (rc) { |
| 4568 | dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc); |
| 4569 | return; |
| 4570 | } |
| 4571 | netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n", |
| 4572 | crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages, |
| 4573 | crq->query_map_rsp.free_pages); |
| 4574 | } |
| 4575 | |
| 4576 | static void handle_query_cap_rsp(union ibmvnic_crq *crq, |
| 4577 | struct ibmvnic_adapter *adapter) |
| 4578 | { |
| 4579 | struct net_device *netdev = adapter->netdev; |
| 4580 | struct device *dev = &adapter->vdev->dev; |
| 4581 | long rc; |
| 4582 | |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4583 | atomic_dec(&adapter->running_cap_crqs); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4584 | netdev_dbg(netdev, "Outstanding queries: %d\n", |
Thomas Falcon | 901e040 | 2017-02-15 12:17:59 -0600 | [diff] [blame] | 4585 | atomic_read(&adapter->running_cap_crqs)); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4586 | rc = crq->query_capability.rc.code; |
| 4587 | if (rc) { |
| 4588 | dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc); |
| 4589 | goto out; |
| 4590 | } |
| 4591 | |
| 4592 | switch (be16_to_cpu(crq->query_capability.capability)) { |
| 4593 | case MIN_TX_QUEUES: |
| 4594 | adapter->min_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4595 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4596 | netdev_dbg(netdev, "min_tx_queues = %lld\n", |
| 4597 | adapter->min_tx_queues); |
| 4598 | break; |
| 4599 | case MIN_RX_QUEUES: |
| 4600 | adapter->min_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4601 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4602 | netdev_dbg(netdev, "min_rx_queues = %lld\n", |
| 4603 | adapter->min_rx_queues); |
| 4604 | break; |
| 4605 | case MIN_RX_ADD_QUEUES: |
| 4606 | adapter->min_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4607 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4608 | netdev_dbg(netdev, "min_rx_add_queues = %lld\n", |
| 4609 | adapter->min_rx_add_queues); |
| 4610 | break; |
| 4611 | case MAX_TX_QUEUES: |
| 4612 | adapter->max_tx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4613 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4614 | netdev_dbg(netdev, "max_tx_queues = %lld\n", |
| 4615 | adapter->max_tx_queues); |
| 4616 | break; |
| 4617 | case MAX_RX_QUEUES: |
| 4618 | adapter->max_rx_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4619 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4620 | netdev_dbg(netdev, "max_rx_queues = %lld\n", |
| 4621 | adapter->max_rx_queues); |
| 4622 | break; |
| 4623 | case MAX_RX_ADD_QUEUES: |
| 4624 | adapter->max_rx_add_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4625 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4626 | netdev_dbg(netdev, "max_rx_add_queues = %lld\n", |
| 4627 | adapter->max_rx_add_queues); |
| 4628 | break; |
| 4629 | case MIN_TX_ENTRIES_PER_SUBCRQ: |
| 4630 | adapter->min_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4631 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4632 | netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n", |
| 4633 | adapter->min_tx_entries_per_subcrq); |
| 4634 | break; |
| 4635 | case MIN_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4636 | adapter->min_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4637 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4638 | netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n", |
| 4639 | adapter->min_rx_add_entries_per_subcrq); |
| 4640 | break; |
| 4641 | case MAX_TX_ENTRIES_PER_SUBCRQ: |
| 4642 | adapter->max_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4643 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4644 | netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n", |
| 4645 | adapter->max_tx_entries_per_subcrq); |
| 4646 | break; |
| 4647 | case MAX_RX_ADD_ENTRIES_PER_SUBCRQ: |
| 4648 | adapter->max_rx_add_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4649 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4650 | netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n", |
| 4651 | adapter->max_rx_add_entries_per_subcrq); |
| 4652 | break; |
| 4653 | case TCP_IP_OFFLOAD: |
| 4654 | adapter->tcp_ip_offload = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4655 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4656 | netdev_dbg(netdev, "tcp_ip_offload = %lld\n", |
| 4657 | adapter->tcp_ip_offload); |
| 4658 | break; |
| 4659 | case PROMISC_SUPPORTED: |
| 4660 | adapter->promisc_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4661 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4662 | netdev_dbg(netdev, "promisc_supported = %lld\n", |
| 4663 | adapter->promisc_supported); |
| 4664 | break; |
| 4665 | case MIN_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4666 | adapter->min_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 4667 | netdev->min_mtu = adapter->min_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4668 | netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu); |
| 4669 | break; |
| 4670 | case MAX_MTU: |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4671 | adapter->max_mtu = be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | f39f0d1 | 2017-02-14 10:22:59 -0600 | [diff] [blame] | 4672 | netdev->max_mtu = adapter->max_mtu - ETH_HLEN; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4673 | netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu); |
| 4674 | break; |
| 4675 | case MAX_MULTICAST_FILTERS: |
| 4676 | adapter->max_multicast_filters = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4677 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4678 | netdev_dbg(netdev, "max_multicast_filters = %lld\n", |
| 4679 | adapter->max_multicast_filters); |
| 4680 | break; |
| 4681 | case VLAN_HEADER_INSERTION: |
| 4682 | adapter->vlan_header_insertion = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4683 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4684 | if (adapter->vlan_header_insertion) |
| 4685 | netdev->features |= NETIF_F_HW_VLAN_STAG_TX; |
| 4686 | netdev_dbg(netdev, "vlan_header_insertion = %lld\n", |
| 4687 | adapter->vlan_header_insertion); |
| 4688 | break; |
Murilo Fossa Vicentini | 6052d5e | 2017-04-21 15:38:46 -0400 | [diff] [blame] | 4689 | case RX_VLAN_HEADER_INSERTION: |
| 4690 | adapter->rx_vlan_header_insertion = |
| 4691 | be64_to_cpu(crq->query_capability.number); |
| 4692 | netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n", |
| 4693 | adapter->rx_vlan_header_insertion); |
| 4694 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4695 | case MAX_TX_SG_ENTRIES: |
| 4696 | adapter->max_tx_sg_entries = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4697 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4698 | netdev_dbg(netdev, "max_tx_sg_entries = %lld\n", |
| 4699 | adapter->max_tx_sg_entries); |
| 4700 | break; |
| 4701 | case RX_SG_SUPPORTED: |
| 4702 | adapter->rx_sg_supported = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4703 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4704 | netdev_dbg(netdev, "rx_sg_supported = %lld\n", |
| 4705 | adapter->rx_sg_supported); |
| 4706 | break; |
| 4707 | case OPT_TX_COMP_SUB_QUEUES: |
| 4708 | adapter->opt_tx_comp_sub_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4709 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4710 | netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n", |
| 4711 | adapter->opt_tx_comp_sub_queues); |
| 4712 | break; |
| 4713 | case OPT_RX_COMP_QUEUES: |
| 4714 | adapter->opt_rx_comp_queues = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4715 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4716 | netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n", |
| 4717 | adapter->opt_rx_comp_queues); |
| 4718 | break; |
| 4719 | case OPT_RX_BUFADD_Q_PER_RX_COMP_Q: |
| 4720 | adapter->opt_rx_bufadd_q_per_rx_comp_q = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4721 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4722 | netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n", |
| 4723 | adapter->opt_rx_bufadd_q_per_rx_comp_q); |
| 4724 | break; |
| 4725 | case OPT_TX_ENTRIES_PER_SUBCRQ: |
| 4726 | adapter->opt_tx_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4727 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4728 | netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n", |
| 4729 | adapter->opt_tx_entries_per_subcrq); |
| 4730 | break; |
| 4731 | case OPT_RXBA_ENTRIES_PER_SUBCRQ: |
| 4732 | adapter->opt_rxba_entries_per_subcrq = |
Thomas Falcon | de89e85 | 2016-03-01 10:20:09 -0600 | [diff] [blame] | 4733 | be64_to_cpu(crq->query_capability.number); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4734 | netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n", |
| 4735 | adapter->opt_rxba_entries_per_subcrq); |
| 4736 | break; |
| 4737 | case TX_RX_DESC_REQ: |
| 4738 | adapter->tx_rx_desc_req = crq->query_capability.number; |
| 4739 | netdev_dbg(netdev, "tx_rx_desc_req = %llx\n", |
| 4740 | adapter->tx_rx_desc_req); |
| 4741 | break; |
| 4742 | |
| 4743 | default: |
| 4744 | netdev_err(netdev, "Got invalid cap rsp %d\n", |
| 4745 | crq->query_capability.capability); |
| 4746 | } |
| 4747 | |
| 4748 | out: |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4749 | if (atomic_read(&adapter->running_cap_crqs) == 0) { |
| 4750 | adapter->wait_capability = false; |
Lijun Pan | 09081b9 | 2020-09-27 20:13:27 -0500 | [diff] [blame] | 4751 | send_request_cap(adapter, 0); |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 4752 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4753 | } |
| 4754 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4755 | static int send_query_phys_parms(struct ibmvnic_adapter *adapter) |
| 4756 | { |
| 4757 | union ibmvnic_crq crq; |
| 4758 | int rc; |
| 4759 | |
| 4760 | memset(&crq, 0, sizeof(crq)); |
| 4761 | crq.query_phys_parms.first = IBMVNIC_CRQ_CMD; |
| 4762 | crq.query_phys_parms.cmd = QUERY_PHYS_PARMS; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4763 | |
| 4764 | mutex_lock(&adapter->fw_lock); |
| 4765 | adapter->fw_done_rc = 0; |
Thomas Falcon | 070eca9 | 2019-11-25 17:12:53 -0600 | [diff] [blame] | 4766 | reinit_completion(&adapter->fw_done); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4767 | |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4768 | rc = ibmvnic_send_crq(adapter, &crq); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4769 | if (rc) { |
| 4770 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4771 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4772 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 4773 | |
| 4774 | rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4775 | if (rc) { |
| 4776 | mutex_unlock(&adapter->fw_lock); |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 4777 | return rc; |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4778 | } |
Thomas Falcon | 476d96c | 2019-11-25 17:12:55 -0600 | [diff] [blame] | 4779 | |
Thomas Falcon | ff25dcb | 2019-11-25 17:12:56 -0600 | [diff] [blame] | 4780 | mutex_unlock(&adapter->fw_lock); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4781 | return adapter->fw_done_rc ? -EIO : 0; |
| 4782 | } |
| 4783 | |
| 4784 | static int handle_query_phys_parms_rsp(union ibmvnic_crq *crq, |
| 4785 | struct ibmvnic_adapter *adapter) |
| 4786 | { |
| 4787 | struct net_device *netdev = adapter->netdev; |
| 4788 | int rc; |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 4789 | __be32 rspeed = cpu_to_be32(crq->query_phys_parms_rsp.speed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4790 | |
| 4791 | rc = crq->query_phys_parms_rsp.rc.code; |
| 4792 | if (rc) { |
| 4793 | netdev_err(netdev, "Error %d in QUERY_PHYS_PARMS\n", rc); |
| 4794 | return rc; |
| 4795 | } |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 4796 | switch (rspeed) { |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4797 | case IBMVNIC_10MBPS: |
| 4798 | adapter->speed = SPEED_10; |
| 4799 | break; |
| 4800 | case IBMVNIC_100MBPS: |
| 4801 | adapter->speed = SPEED_100; |
| 4802 | break; |
| 4803 | case IBMVNIC_1GBPS: |
| 4804 | adapter->speed = SPEED_1000; |
| 4805 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 4806 | case IBMVNIC_10GBPS: |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4807 | adapter->speed = SPEED_10000; |
| 4808 | break; |
| 4809 | case IBMVNIC_25GBPS: |
| 4810 | adapter->speed = SPEED_25000; |
| 4811 | break; |
| 4812 | case IBMVNIC_40GBPS: |
| 4813 | adapter->speed = SPEED_40000; |
| 4814 | break; |
| 4815 | case IBMVNIC_50GBPS: |
| 4816 | adapter->speed = SPEED_50000; |
| 4817 | break; |
| 4818 | case IBMVNIC_100GBPS: |
| 4819 | adapter->speed = SPEED_100000; |
| 4820 | break; |
Lijun Pan | b9cd795 | 2020-09-27 19:06:25 -0500 | [diff] [blame] | 4821 | case IBMVNIC_200GBPS: |
| 4822 | adapter->speed = SPEED_200000; |
| 4823 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4824 | default: |
Murilo Fossa Vicentini | dd0f9d8 | 2019-09-16 11:50:37 -0300 | [diff] [blame] | 4825 | if (netif_carrier_ok(netdev)) |
| 4826 | netdev_warn(netdev, "Unknown speed 0x%08x\n", rspeed); |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 4827 | adapter->speed = SPEED_UNKNOWN; |
| 4828 | } |
| 4829 | if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_FULL_DUPLEX) |
| 4830 | adapter->duplex = DUPLEX_FULL; |
| 4831 | else if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_HALF_DUPLEX) |
| 4832 | adapter->duplex = DUPLEX_HALF; |
| 4833 | else |
| 4834 | adapter->duplex = DUPLEX_UNKNOWN; |
| 4835 | |
| 4836 | return rc; |
| 4837 | } |
| 4838 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4839 | static void ibmvnic_handle_crq(union ibmvnic_crq *crq, |
| 4840 | struct ibmvnic_adapter *adapter) |
| 4841 | { |
| 4842 | struct ibmvnic_generic_crq *gen_crq = &crq->generic; |
| 4843 | struct net_device *netdev = adapter->netdev; |
| 4844 | struct device *dev = &adapter->vdev->dev; |
Murilo Fossa Vicentini | 993a82b | 2017-04-19 13:44:35 -0400 | [diff] [blame] | 4845 | u64 *u64_crq = (u64 *)crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4846 | long rc; |
| 4847 | |
| 4848 | netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n", |
Lijun Pan | 429aa36 | 2021-02-11 00:43:18 -0600 | [diff] [blame] | 4849 | (unsigned long)cpu_to_be64(u64_crq[0]), |
| 4850 | (unsigned long)cpu_to_be64(u64_crq[1])); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4851 | switch (gen_crq->first) { |
| 4852 | case IBMVNIC_CRQ_INIT_RSP: |
| 4853 | switch (gen_crq->cmd) { |
| 4854 | case IBMVNIC_CRQ_INIT: |
| 4855 | dev_info(dev, "Partner initialized\n"); |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 4856 | adapter->from_passive_init = true; |
Sukadev Bhattiprolu | 76cdc5c | 2020-11-25 18:04:29 -0600 | [diff] [blame] | 4857 | /* Discard any stale login responses from prev reset. |
| 4858 | * CHECK: should we clear even on INIT_COMPLETE? |
| 4859 | */ |
| 4860 | adapter->login_pending = false; |
| 4861 | |
Thomas Falcon | 17c8705 | 2018-05-23 13:37:58 -0500 | [diff] [blame] | 4862 | if (!completion_done(&adapter->init_done)) { |
| 4863 | complete(&adapter->init_done); |
| 4864 | adapter->init_done_rc = -EIO; |
| 4865 | } |
Sukadev Bhattiprolu | ef66a1e | 2021-02-02 21:08:02 -0800 | [diff] [blame] | 4866 | rc = ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); |
| 4867 | if (rc && rc != -EBUSY) { |
| 4868 | /* We were unable to schedule the failover |
| 4869 | * reset either because the adapter was still |
| 4870 | * probing (eg: during kexec) or we could not |
| 4871 | * allocate memory. Clear the failover_pending |
| 4872 | * flag since no one else will. We ignore |
| 4873 | * EBUSY because it means either FAILOVER reset |
| 4874 | * is already scheduled or the adapter is |
| 4875 | * being removed. |
| 4876 | */ |
| 4877 | netdev_err(netdev, |
| 4878 | "Error %ld scheduling failover reset\n", |
| 4879 | rc); |
| 4880 | adapter->failover_pending = false; |
| 4881 | } |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4882 | break; |
| 4883 | case IBMVNIC_CRQ_INIT_COMPLETE: |
| 4884 | dev_info(dev, "Partner initialization complete\n"); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 4885 | adapter->crq.active = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4886 | send_version_xchg(adapter); |
| 4887 | break; |
| 4888 | default: |
| 4889 | dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd); |
| 4890 | } |
| 4891 | return; |
| 4892 | case IBMVNIC_CRQ_XPORT_EVENT: |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4893 | netif_carrier_off(netdev); |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 4894 | adapter->crq.active = false; |
Thomas Falcon | 2147e3d | 2019-11-25 17:12:54 -0600 | [diff] [blame] | 4895 | /* terminate any thread waiting for a response |
| 4896 | * from the device |
| 4897 | */ |
| 4898 | if (!completion_done(&adapter->fw_done)) { |
| 4899 | adapter->fw_done_rc = -EIO; |
| 4900 | complete(&adapter->fw_done); |
| 4901 | } |
| 4902 | if (!completion_done(&adapter->stats_done)) |
| 4903 | complete(&adapter->stats_done); |
Juliet Kim | 7ed5b31 | 2019-09-20 16:11:23 -0400 | [diff] [blame] | 4904 | if (test_bit(0, &adapter->resetting)) |
Thomas Falcon | 2770a79 | 2018-05-23 13:38:02 -0500 | [diff] [blame] | 4905 | adapter->force_reset_recovery = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4906 | if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4907 | dev_info(dev, "Migrated, re-enabling adapter\n"); |
| 4908 | ibmvnic_reset(adapter, VNIC_RESET_MOBILITY); |
Thomas Falcon | dfad09a | 2016-08-18 11:37:51 -0500 | [diff] [blame] | 4909 | } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { |
| 4910 | dev_info(dev, "Backing device failover detected\n"); |
Thomas Falcon | 5a18e1e | 2018-04-06 18:37:05 -0500 | [diff] [blame] | 4911 | adapter->failover_pending = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4912 | } else { |
| 4913 | /* The adapter lost the connection */ |
| 4914 | dev_err(dev, "Virtual Adapter failed (rc=%d)\n", |
| 4915 | gen_crq->cmd); |
Nathan Fontenot | ed651a1 | 2017-05-03 14:04:38 -0400 | [diff] [blame] | 4916 | ibmvnic_reset(adapter, VNIC_RESET_FATAL); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4917 | } |
| 4918 | return; |
| 4919 | case IBMVNIC_CRQ_CMD_RSP: |
| 4920 | break; |
| 4921 | default: |
| 4922 | dev_err(dev, "Got an invalid msg type 0x%02x\n", |
| 4923 | gen_crq->first); |
| 4924 | return; |
| 4925 | } |
| 4926 | |
| 4927 | switch (gen_crq->cmd) { |
| 4928 | case VERSION_EXCHANGE_RSP: |
| 4929 | rc = crq->version_exchange_rsp.rc.code; |
| 4930 | if (rc) { |
| 4931 | dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc); |
| 4932 | break; |
| 4933 | } |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 4934 | ibmvnic_version = |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4935 | be16_to_cpu(crq->version_exchange_rsp.version); |
Thomas Falcon | 7846889 | 2020-05-28 11:19:17 -0500 | [diff] [blame] | 4936 | dev_info(dev, "Partner protocol version is %d\n", |
| 4937 | ibmvnic_version); |
Lijun Pan | 491099a | 2020-09-27 20:13:26 -0500 | [diff] [blame] | 4938 | send_query_cap(adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4939 | break; |
| 4940 | case QUERY_CAPABILITY_RSP: |
| 4941 | handle_query_cap_rsp(crq, adapter); |
| 4942 | break; |
| 4943 | case QUERY_MAP_RSP: |
| 4944 | handle_query_map_rsp(crq, adapter); |
| 4945 | break; |
| 4946 | case REQUEST_MAP_RSP: |
Thomas Falcon | f3be0cb | 2017-06-21 14:53:01 -0500 | [diff] [blame] | 4947 | adapter->fw_done_rc = crq->request_map_rsp.rc.code; |
| 4948 | complete(&adapter->fw_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4949 | break; |
| 4950 | case REQUEST_UNMAP_RSP: |
| 4951 | handle_request_unmap_rsp(crq, adapter); |
| 4952 | break; |
| 4953 | case REQUEST_CAPABILITY_RSP: |
| 4954 | handle_request_cap_rsp(crq, adapter); |
| 4955 | break; |
| 4956 | case LOGIN_RSP: |
| 4957 | netdev_dbg(netdev, "Got Login Response\n"); |
| 4958 | handle_login_rsp(crq, adapter); |
| 4959 | break; |
| 4960 | case LOGICAL_LINK_STATE_RSP: |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 4961 | netdev_dbg(netdev, |
| 4962 | "Got Logical Link State Response, state: %d rc: %d\n", |
| 4963 | crq->logical_link_state_rsp.link_state, |
| 4964 | crq->logical_link_state_rsp.rc.code); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4965 | adapter->logical_link_state = |
| 4966 | crq->logical_link_state_rsp.link_state; |
Nathan Fontenot | 53da09e | 2017-04-21 15:39:04 -0400 | [diff] [blame] | 4967 | adapter->init_done_rc = crq->logical_link_state_rsp.rc.code; |
| 4968 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4969 | break; |
| 4970 | case LINK_STATE_INDICATION: |
| 4971 | netdev_dbg(netdev, "Got Logical Link State Indication\n"); |
| 4972 | adapter->phys_link_state = |
| 4973 | crq->link_state_indication.phys_link_state; |
| 4974 | adapter->logical_link_state = |
| 4975 | crq->link_state_indication.logical_link_state; |
Thomas Falcon | 0655f99 | 2019-05-09 23:13:44 -0500 | [diff] [blame] | 4976 | if (adapter->phys_link_state && adapter->logical_link_state) |
| 4977 | netif_carrier_on(netdev); |
| 4978 | else |
| 4979 | netif_carrier_off(netdev); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4980 | break; |
| 4981 | case CHANGE_MAC_ADDR_RSP: |
| 4982 | netdev_dbg(netdev, "Got MAC address change Response\n"); |
Thomas Falcon | f813614 | 2018-01-29 13:45:05 -0600 | [diff] [blame] | 4983 | adapter->fw_done_rc = handle_change_mac_rsp(crq, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4984 | break; |
| 4985 | case ERROR_INDICATION: |
| 4986 | netdev_dbg(netdev, "Got Error Indication\n"); |
| 4987 | handle_error_indication(crq, adapter); |
| 4988 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4989 | case REQUEST_STATISTICS_RSP: |
| 4990 | netdev_dbg(netdev, "Got Statistics Response\n"); |
| 4991 | complete(&adapter->stats_done); |
| 4992 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 4993 | case QUERY_IP_OFFLOAD_RSP: |
| 4994 | netdev_dbg(netdev, "Got Query IP offload Response\n"); |
| 4995 | handle_query_ip_offload_rsp(adapter); |
| 4996 | break; |
| 4997 | case MULTICAST_CTRL_RSP: |
| 4998 | netdev_dbg(netdev, "Got multicast control Response\n"); |
| 4999 | break; |
| 5000 | case CONTROL_IP_OFFLOAD_RSP: |
| 5001 | netdev_dbg(netdev, "Got Control IP offload Response\n"); |
| 5002 | dma_unmap_single(dev, adapter->ip_offload_ctrl_tok, |
| 5003 | sizeof(adapter->ip_offload_ctrl), |
| 5004 | DMA_TO_DEVICE); |
John Allen | bd0b672 | 2017-03-17 17:13:40 -0500 | [diff] [blame] | 5005 | complete(&adapter->init_done); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5006 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5007 | case COLLECT_FW_TRACE_RSP: |
| 5008 | netdev_dbg(netdev, "Got Collect firmware trace Response\n"); |
| 5009 | complete(&adapter->fw_done); |
| 5010 | break; |
Desnes Augusto Nunes do Rosario | 4e6759b | 2017-11-13 15:59:19 -0200 | [diff] [blame] | 5011 | case GET_VPD_SIZE_RSP: |
| 5012 | handle_vpd_size_rsp(crq, adapter); |
| 5013 | break; |
| 5014 | case GET_VPD_RSP: |
| 5015 | handle_vpd_rsp(crq, adapter); |
| 5016 | break; |
Murilo Fossa Vicentini | f8d6ae0 | 2019-03-19 10:28:51 -0300 | [diff] [blame] | 5017 | case QUERY_PHYS_PARMS_RSP: |
| 5018 | adapter->fw_done_rc = handle_query_phys_parms_rsp(crq, adapter); |
| 5019 | complete(&adapter->fw_done); |
| 5020 | break; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5021 | default: |
| 5022 | netdev_err(netdev, "Got an invalid cmd type 0x%02x\n", |
| 5023 | gen_crq->cmd); |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | static irqreturn_t ibmvnic_interrupt(int irq, void *instance) |
| 5028 | { |
| 5029 | struct ibmvnic_adapter *adapter = instance; |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5030 | |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5031 | tasklet_schedule(&adapter->tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5032 | return IRQ_HANDLED; |
| 5033 | } |
| 5034 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5035 | static void ibmvnic_tasklet(struct tasklet_struct *t) |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5036 | { |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5037 | struct ibmvnic_adapter *adapter = from_tasklet(adapter, t, tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5038 | struct ibmvnic_crq_queue *queue = &adapter->crq; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5039 | union ibmvnic_crq *crq; |
| 5040 | unsigned long flags; |
| 5041 | bool done = false; |
| 5042 | |
| 5043 | spin_lock_irqsave(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5044 | while (!done) { |
| 5045 | /* Pull all the valid messages off the CRQ */ |
| 5046 | while ((crq = ibmvnic_next_crq(adapter)) != NULL) { |
Lijun Pan | e41aec7 | 2021-01-27 19:34:42 -0600 | [diff] [blame] | 5047 | /* This barrier makes sure ibmvnic_next_crq()'s |
| 5048 | * crq->generic.first & IBMVNIC_CRQ_CMD_RSP is loaded |
| 5049 | * before ibmvnic_handle_crq()'s |
| 5050 | * switch(gen_crq->first) and switch(gen_crq->cmd). |
| 5051 | */ |
| 5052 | dma_rmb(); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5053 | ibmvnic_handle_crq(crq, adapter); |
| 5054 | crq->generic.first = 0; |
| 5055 | } |
Brian King | ed7ecbf | 2017-04-19 13:44:53 -0400 | [diff] [blame] | 5056 | |
| 5057 | /* remain in tasklet until all |
| 5058 | * capabilities responses are received |
| 5059 | */ |
| 5060 | if (!adapter->wait_capability) |
| 5061 | done = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5062 | } |
Thomas Falcon | 249168a | 2017-02-15 12:18:00 -0600 | [diff] [blame] | 5063 | /* if capabilities CRQ's were sent in this tasklet, the following |
| 5064 | * tasklet must wait until all responses are received |
| 5065 | */ |
| 5066 | if (atomic_read(&adapter->running_cap_crqs) != 0) |
| 5067 | adapter->wait_capability = true; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5068 | spin_unlock_irqrestore(&queue->lock, flags); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter) |
| 5072 | { |
| 5073 | struct vio_dev *vdev = adapter->vdev; |
| 5074 | int rc; |
| 5075 | |
| 5076 | do { |
| 5077 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); |
| 5078 | } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5079 | |
| 5080 | if (rc) |
| 5081 | dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc); |
| 5082 | |
| 5083 | return rc; |
| 5084 | } |
| 5085 | |
| 5086 | static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter) |
| 5087 | { |
| 5088 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5089 | struct device *dev = &adapter->vdev->dev; |
| 5090 | struct vio_dev *vdev = adapter->vdev; |
| 5091 | int rc; |
| 5092 | |
| 5093 | /* Close the CRQ */ |
| 5094 | do { |
| 5095 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5096 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5097 | |
| 5098 | /* Clean out the queue */ |
Lijun Pan | 0e435be | 2020-11-23 13:35:46 -0600 | [diff] [blame] | 5099 | if (!crq->msgs) |
| 5100 | return -EINVAL; |
| 5101 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5102 | memset(crq->msgs, 0, PAGE_SIZE); |
| 5103 | crq->cur = 0; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5104 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5105 | |
| 5106 | /* And re-open it again */ |
| 5107 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5108 | crq->msg_token, PAGE_SIZE); |
| 5109 | |
| 5110 | if (rc == H_CLOSED) |
| 5111 | /* Adapter is good, but other end is not ready */ |
| 5112 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5113 | else if (rc != 0) |
| 5114 | dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc); |
| 5115 | |
| 5116 | return rc; |
| 5117 | } |
| 5118 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5119 | static void release_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5120 | { |
| 5121 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5122 | struct vio_dev *vdev = adapter->vdev; |
| 5123 | long rc; |
| 5124 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5125 | if (!crq->msgs) |
| 5126 | return; |
| 5127 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5128 | netdev_dbg(adapter->netdev, "Releasing CRQ\n"); |
| 5129 | free_irq(vdev->irq, adapter); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5130 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5131 | do { |
| 5132 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5133 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5134 | |
| 5135 | dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE, |
| 5136 | DMA_BIDIRECTIONAL); |
| 5137 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5138 | crq->msgs = NULL; |
Thomas Falcon | 5153698 | 2018-05-23 13:37:56 -0500 | [diff] [blame] | 5139 | crq->active = false; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5140 | } |
| 5141 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5142 | static int init_crq_queue(struct ibmvnic_adapter *adapter) |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5143 | { |
| 5144 | struct ibmvnic_crq_queue *crq = &adapter->crq; |
| 5145 | struct device *dev = &adapter->vdev->dev; |
| 5146 | struct vio_dev *vdev = adapter->vdev; |
| 5147 | int rc, retrc = -ENOMEM; |
| 5148 | |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5149 | if (crq->msgs) |
| 5150 | return 0; |
| 5151 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5152 | crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL); |
| 5153 | /* Should we allocate more than one page? */ |
| 5154 | |
| 5155 | if (!crq->msgs) |
| 5156 | return -ENOMEM; |
| 5157 | |
| 5158 | crq->size = PAGE_SIZE / sizeof(*crq->msgs); |
| 5159 | crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE, |
| 5160 | DMA_BIDIRECTIONAL); |
| 5161 | if (dma_mapping_error(dev, crq->msg_token)) |
| 5162 | goto map_failed; |
| 5163 | |
| 5164 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, |
| 5165 | crq->msg_token, PAGE_SIZE); |
| 5166 | |
| 5167 | if (rc == H_RESOURCE) |
| 5168 | /* maybe kexecing and resource is busy. try a reset */ |
| 5169 | rc = ibmvnic_reset_crq(adapter); |
| 5170 | retrc = rc; |
| 5171 | |
| 5172 | if (rc == H_CLOSED) { |
| 5173 | dev_warn(dev, "Partner adapter not ready\n"); |
| 5174 | } else if (rc) { |
| 5175 | dev_warn(dev, "Error %d opening adapter\n", rc); |
| 5176 | goto reg_crq_failed; |
| 5177 | } |
| 5178 | |
| 5179 | retrc = 0; |
| 5180 | |
Allen Pais | aa7c3fe | 2020-09-14 12:59:29 +0530 | [diff] [blame] | 5181 | tasklet_setup(&adapter->tasklet, (void *)ibmvnic_tasklet); |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5182 | |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5183 | netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq); |
Murilo Fossa Vicentini | e56e251 | 2019-04-25 11:02:33 -0300 | [diff] [blame] | 5184 | snprintf(crq->name, sizeof(crq->name), "ibmvnic-%x", |
| 5185 | adapter->vdev->unit_address); |
| 5186 | rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, crq->name, adapter); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5187 | if (rc) { |
| 5188 | dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", |
| 5189 | vdev->irq, rc); |
| 5190 | goto req_irq_failed; |
| 5191 | } |
| 5192 | |
| 5193 | rc = vio_enable_interrupts(vdev); |
| 5194 | if (rc) { |
| 5195 | dev_err(dev, "Error %d enabling interrupts\n", rc); |
| 5196 | goto req_irq_failed; |
| 5197 | } |
| 5198 | |
| 5199 | crq->cur = 0; |
| 5200 | spin_lock_init(&crq->lock); |
| 5201 | |
| 5202 | return retrc; |
| 5203 | |
| 5204 | req_irq_failed: |
Thomas Falcon | 6c267b3 | 2017-02-15 12:17:58 -0600 | [diff] [blame] | 5205 | tasklet_kill(&adapter->tasklet); |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5206 | do { |
| 5207 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); |
| 5208 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); |
| 5209 | reg_crq_failed: |
| 5210 | dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 5211 | map_failed: |
| 5212 | free_page((unsigned long)crq->msgs); |
Nathan Fontenot | f992887 | 2017-03-30 02:48:54 -0400 | [diff] [blame] | 5213 | crq->msgs = NULL; |
Thomas Falcon | 032c5e8 | 2015-12-21 11:26:06 -0600 | [diff] [blame] | 5214 | return retrc; |
| 5215 | } |
| 5216 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5217 | static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter, bool reset) |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5218 | { |
| 5219 | struct device *dev = &adapter->vdev->dev; |
Dany Madden | 98c41f0 | 2020-11-25 18:04:32 -0600 | [diff] [blame] | 5220 | unsigned long timeout = msecs_to_jiffies(20000); |
Nathan Fontenot | d7c0ef3 | 2018-02-19 13:30:31 -0600 | [diff] [blame] | 5221 | u64 old_num_rx_queues, old_num_tx_queues; |
John Allen | f6ef640 | 2017-03-17 17:13:42 -0500 | [diff] [blame] | 5222 | int rc; |
| 5223 | |
John Allen | 017892c1 | 2017-05-26 10:30:19 -0400 | [diff] [blame] | 5224 | adapter->from_passive_init = false; |
| 5225 | |
Lijun Pan | 635e442 | 2020-08-19 17:52:26 -0500 | [diff] [blame] | 5226 | if (reset) { |
| 5227 | old_num_rx_queues = adapter->req_rx_queues; |
| 5228 | old_num_tx_queues = adapter->req_tx_queues; |
| 5229 | reinit_completion(&adapter->init_done); |
| 5230 | } |
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 | */ |
| 5413 | spin_lock_irqsave(&adapter->rwi_lock, flags); |
Nathan Fontenot | 90c8014 | 2017-05-03 14:04:32 -0400 | [diff] [blame] | 5414 | adapter->state = VNIC_REMOVING; |
Sukadev Bhattiprolu | 4a41c42 | 2021-02-12 20:42:50 -0800 | [diff] [blame] | 5415 | spin_unlock_irqrestore(&adapter->rwi_lock, flags); |
| 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); |