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