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