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