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