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