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