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