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