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