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