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