blob: dc1b881163305c7c96a14824dae95c80afc3109e [file] [log] [blame]
Thomas Gleixnerd5bb9942019-05-23 11:14:51 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Thomas Falcon032c5e82015-12-21 11:26:06 -06002/**************************************************************************/
3/* */
4/* IBM System i and System p Virtual NIC Device Driver */
5/* Copyright (C) 2014 IBM Corp. */
6/* Santiago Leon (santi_leon@yahoo.com) */
7/* Thomas Falcon (tlfalcon@linux.vnet.ibm.com) */
8/* John Allen (jallen@linux.vnet.ibm.com) */
9/* */
Thomas Falcon032c5e82015-12-21 11:26:06 -060010/* */
11/* This module contains the implementation of a virtual ethernet device */
12/* for use with IBM i/p Series LPAR Linux. It utilizes the logical LAN */
13/* option of the RS/6000 Platform Architecture to interface with virtual */
14/* ethernet NICs that are presented to the partition by the hypervisor. */
15/* */
16/* Messages are passed between the VNIC driver and the VNIC server using */
17/* Command/Response Queues (CRQs) and sub CRQs (sCRQs). CRQs are used to */
18/* issue and receive commands that initiate communication with the server */
19/* on driver initialization. Sub CRQs (sCRQs) are similar to CRQs, but */
20/* are used by the driver to notify the server that a packet is */
21/* ready for transmission or that a buffer has been added to receive a */
22/* packet. Subsequently, sCRQs are used by the server to notify the */
23/* driver that a packet transmission has been completed or that a packet */
24/* has been received and placed in a waiting buffer. */
25/* */
26/* In lieu of a more conventional "on-the-fly" DMA mapping strategy in */
27/* which skbs are DMA mapped and immediately unmapped when the transmit */
28/* or receive has been completed, the VNIC driver is required to use */
29/* "long term mapping". This entails that large, continuous DMA mapped */
30/* buffers are allocated on driver initialization and these buffers are */
31/* then continuously reused to pass skbs to and from the VNIC server. */
32/* */
33/**************************************************************************/
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/types.h>
38#include <linux/errno.h>
39#include <linux/completion.h>
40#include <linux/ioport.h>
41#include <linux/dma-mapping.h>
42#include <linux/kernel.h>
43#include <linux/netdevice.h>
44#include <linux/etherdevice.h>
45#include <linux/skbuff.h>
46#include <linux/init.h>
47#include <linux/delay.h>
48#include <linux/mm.h>
49#include <linux/ethtool.h>
50#include <linux/proc_fs.h>
Thomas Falcon4eb50ce2017-12-18 12:52:40 -060051#include <linux/if_arp.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060052#include <linux/in.h>
53#include <linux/ip.h>
Thomas Falconad7775d2016-04-01 17:20:34 -050054#include <linux/ipv6.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060055#include <linux/irq.h>
56#include <linux/kthread.h>
57#include <linux/seq_file.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060058#include <linux/interrupt.h>
59#include <net/net_namespace.h>
60#include <asm/hvcall.h>
61#include <linux/atomic.h>
62#include <asm/vio.h>
63#include <asm/iommu.h>
64#include <linux/uaccess.h>
65#include <asm/firmware.h>
Thomas Falcon65dc6892016-07-06 15:35:18 -050066#include <linux/workqueue.h>
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -040067#include <linux/if_vlan.h>
Nathan Fontenot37798d02017-11-08 11:23:56 -060068#include <linux/utsname.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060069
70#include "ibmvnic.h"
71
72static const char ibmvnic_driver_name[] = "ibmvnic";
73static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
74
Thomas Falcon78b07ac2017-06-01 15:32:34 -050075MODULE_AUTHOR("Santiago Leon");
Thomas Falcon032c5e82015-12-21 11:26:06 -060076MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
77MODULE_LICENSE("GPL");
78MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
79
80static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
81static int ibmvnic_remove(struct vio_dev *);
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -060082static void release_sub_crqs(struct ibmvnic_adapter *, bool);
Thomas Falcon032c5e82015-12-21 11:26:06 -060083static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
84static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
85static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
86static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
87static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
88 union sub_crq *sub_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -050089static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
Thomas Falcon032c5e82015-12-21 11:26:06 -060090static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
91static int enable_scrq_irq(struct ibmvnic_adapter *,
92 struct ibmvnic_sub_crq_queue *);
93static int disable_scrq_irq(struct ibmvnic_adapter *,
94 struct ibmvnic_sub_crq_queue *);
95static int pending_scrq(struct ibmvnic_adapter *,
96 struct ibmvnic_sub_crq_queue *);
97static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
98 struct ibmvnic_sub_crq_queue *);
99static int ibmvnic_poll(struct napi_struct *napi, int data);
100static void send_map_query(struct ibmvnic_adapter *adapter);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500101static int send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
102static int send_request_unmap(struct ibmvnic_adapter *, u8);
Thomas Falcon20a8ab72018-02-26 18:10:59 -0600103static int send_login(struct ibmvnic_adapter *adapter);
John Allenbd0b6722017-03-17 17:13:40 -0500104static void send_cap_queries(struct ibmvnic_adapter *adapter);
Thomas Falcon4d96f122017-08-01 15:04:36 -0500105static int init_sub_crqs(struct ibmvnic_adapter *);
John Allenbd0b6722017-03-17 17:13:40 -0500106static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
John Allenea5509f2017-03-17 17:13:43 -0500107static int ibmvnic_init(struct ibmvnic_adapter *);
Thomas Falcon8a348452018-05-23 13:38:00 -0500108static int ibmvnic_reset_init(struct ibmvnic_adapter *);
Nathan Fontenotf9928872017-03-30 02:48:54 -0400109static void release_crq_queue(struct ibmvnic_adapter *);
Thomas Falcon62740e92019-05-09 23:13:43 -0500110static int __ibmvnic_set_mac(struct net_device *, u8 *);
Nathan Fontenot30f79622018-04-06 18:37:06 -0500111static int init_crq_queue(struct ibmvnic_adapter *adapter);
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -0300112static int send_query_phys_parms(struct ibmvnic_adapter *adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600113
114struct ibmvnic_stat {
115 char name[ETH_GSTRING_LEN];
116 int offset;
117};
118
119#define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
120 offsetof(struct ibmvnic_statistics, stat))
121#define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
122
123static const struct ibmvnic_stat ibmvnic_stats[] = {
124 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
125 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
126 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
127 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
128 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
129 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
130 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
131 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
132 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
133 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
134 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
135 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
136 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
137 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
138 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
139 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
140 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
141 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
142 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
143 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
144 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
145 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
146};
147
148static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
149 unsigned long length, unsigned long *number,
150 unsigned long *irq)
151{
152 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
153 long rc;
154
155 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
156 *number = retbuf[0];
157 *irq = retbuf[1];
158
159 return rc;
160}
161
Thomas Falcon032c5e82015-12-21 11:26:06 -0600162static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
163 struct ibmvnic_long_term_buff *ltb, int size)
164{
165 struct device *dev = &adapter->vdev->dev;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500166 int rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600167
168 ltb->size = size;
169 ltb->buff = dma_alloc_coherent(dev, ltb->size, &ltb->addr,
170 GFP_KERNEL);
171
172 if (!ltb->buff) {
173 dev_err(dev, "Couldn't alloc long term buffer\n");
174 return -ENOMEM;
175 }
176 ltb->map_id = adapter->map_id;
177 adapter->map_id++;
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -0500178
Thomas Falcon070eca92019-11-25 17:12:53 -0600179 reinit_completion(&adapter->fw_done);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500180 rc = send_request_map(adapter, ltb->addr,
181 ltb->size, ltb->map_id);
182 if (rc) {
183 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
184 return rc;
185 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600186 wait_for_completion(&adapter->fw_done);
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500187
188 if (adapter->fw_done_rc) {
189 dev_err(dev, "Couldn't map long term buffer,rc = %d\n",
190 adapter->fw_done_rc);
Thomas Falcon4cf2ddf32018-05-16 15:49:03 -0500191 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500192 return -1;
193 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600194 return 0;
195}
196
197static void free_long_term_buff(struct ibmvnic_adapter *adapter,
198 struct ibmvnic_long_term_buff *ltb)
199{
200 struct device *dev = &adapter->vdev->dev;
201
Nathan Fontenotc657e322017-03-30 02:49:06 -0400202 if (!ltb->buff)
203 return;
204
Nathan Fontenoted651a12017-05-03 14:04:38 -0400205 if (adapter->reset_reason != VNIC_RESET_FAILOVER &&
206 adapter->reset_reason != VNIC_RESET_MOBILITY)
Thomas Falcondfad09a2016-08-18 11:37:51 -0500207 send_request_unmap(adapter, ltb->map_id);
Brian King59af56c2017-04-19 13:44:41 -0400208 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600209}
210
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500211static int reset_long_term_buff(struct ibmvnic_adapter *adapter,
212 struct ibmvnic_long_term_buff *ltb)
213{
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500214 int rc;
215
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500216 memset(ltb->buff, 0, ltb->size);
217
Thomas Falcon070eca92019-11-25 17:12:53 -0600218 reinit_completion(&adapter->fw_done);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500219 rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id);
220 if (rc)
221 return rc;
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500222 wait_for_completion(&adapter->fw_done);
223
224 if (adapter->fw_done_rc) {
225 dev_info(&adapter->vdev->dev,
226 "Reset failed, attempting to free and reallocate buffer\n");
227 free_long_term_buff(adapter, ltb);
228 return alloc_long_term_buff(adapter, ltb, ltb->size);
229 }
230 return 0;
231}
232
Thomas Falconf185a492017-05-26 10:30:48 -0400233static void deactivate_rx_pools(struct ibmvnic_adapter *adapter)
234{
235 int i;
236
237 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
238 i++)
239 adapter->rx_pool[i].active = 0;
240}
241
Thomas Falcon032c5e82015-12-21 11:26:06 -0600242static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
243 struct ibmvnic_rx_pool *pool)
244{
245 int count = pool->size - atomic_read(&pool->available);
246 struct device *dev = &adapter->vdev->dev;
247 int buffers_added = 0;
248 unsigned long lpar_rc;
249 union sub_crq sub_crq;
250 struct sk_buff *skb;
251 unsigned int offset;
252 dma_addr_t dma_addr;
253 unsigned char *dst;
254 u64 *handle_array;
255 int shift = 0;
256 int index;
257 int i;
258
Thomas Falconf185a492017-05-26 10:30:48 -0400259 if (!pool->active)
260 return;
261
Thomas Falcon032c5e82015-12-21 11:26:06 -0600262 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
263 be32_to_cpu(adapter->login_rsp_buf->
264 off_rxadd_subcrqs));
265
266 for (i = 0; i < count; ++i) {
267 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
268 if (!skb) {
269 dev_err(dev, "Couldn't replenish rx buff\n");
270 adapter->replenish_no_mem++;
271 break;
272 }
273
274 index = pool->free_map[pool->next_free];
275
276 if (pool->rx_buff[index].skb)
277 dev_err(dev, "Inconsistent free_map!\n");
278
279 /* Copy the skb to the long term mapped DMA buffer */
280 offset = index * pool->buff_size;
281 dst = pool->long_term_buff.buff + offset;
282 memset(dst, 0, pool->buff_size);
283 dma_addr = pool->long_term_buff.addr + offset;
284 pool->rx_buff[index].data = dst;
285
286 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
287 pool->rx_buff[index].dma = dma_addr;
288 pool->rx_buff[index].skb = skb;
289 pool->rx_buff[index].pool_index = pool->index;
290 pool->rx_buff[index].size = pool->buff_size;
291
292 memset(&sub_crq, 0, sizeof(sub_crq));
293 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
294 sub_crq.rx_add.correlator =
295 cpu_to_be64((u64)&pool->rx_buff[index]);
296 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
297 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
298
299 /* The length field of the sCRQ is defined to be 24 bits so the
300 * buffer size needs to be left shifted by a byte before it is
301 * converted to big endian to prevent the last byte from being
302 * truncated.
303 */
304#ifdef __LITTLE_ENDIAN__
305 shift = 8;
306#endif
307 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
308
309 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
310 &sub_crq);
311 if (lpar_rc != H_SUCCESS)
312 goto failure;
313
314 buffers_added++;
315 adapter->replenish_add_buff_success++;
316 pool->next_free = (pool->next_free + 1) % pool->size;
317 }
318 atomic_add(buffers_added, &pool->available);
319 return;
320
321failure:
Thomas Falcon2d14d372018-07-13 12:03:32 -0500322 if (lpar_rc != H_PARAMETER && lpar_rc != H_CLOSED)
323 dev_err_ratelimited(dev, "rx: replenish packet buffer failed\n");
Thomas Falcon032c5e82015-12-21 11:26:06 -0600324 pool->free_map[pool->next_free] = index;
325 pool->rx_buff[index].skb = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600326
327 dev_kfree_skb_any(skb);
328 adapter->replenish_add_buff_failure++;
329 atomic_add(buffers_added, &pool->available);
Thomas Falconf185a492017-05-26 10:30:48 -0400330
Thomas Falcon5a18e1e2018-04-06 18:37:05 -0500331 if (lpar_rc == H_CLOSED || adapter->failover_pending) {
Thomas Falconf185a492017-05-26 10:30:48 -0400332 /* Disable buffer pool replenishment and report carrier off if
Thomas Falcon5a18e1e2018-04-06 18:37:05 -0500333 * queue is closed or pending failover.
334 * Firmware guarantees that a signal will be sent to the
335 * driver, triggering a reset.
Thomas Falconf185a492017-05-26 10:30:48 -0400336 */
337 deactivate_rx_pools(adapter);
338 netif_carrier_off(adapter->netdev);
339 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600340}
341
342static void replenish_pools(struct ibmvnic_adapter *adapter)
343{
344 int i;
345
Thomas Falcon032c5e82015-12-21 11:26:06 -0600346 adapter->replenish_task_cycles++;
347 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
348 i++) {
349 if (adapter->rx_pool[i].active)
350 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
351 }
352}
353
John Allen3d52b592017-08-02 16:44:14 -0500354static void release_stats_buffers(struct ibmvnic_adapter *adapter)
355{
356 kfree(adapter->tx_stats_buffers);
357 kfree(adapter->rx_stats_buffers);
Thomas Falconb0992ec2018-02-06 17:25:23 -0600358 adapter->tx_stats_buffers = NULL;
359 adapter->rx_stats_buffers = NULL;
John Allen3d52b592017-08-02 16:44:14 -0500360}
361
362static int init_stats_buffers(struct ibmvnic_adapter *adapter)
363{
364 adapter->tx_stats_buffers =
Nathan Fontenotabcae542018-02-19 13:30:47 -0600365 kcalloc(IBMVNIC_MAX_QUEUES,
John Allen3d52b592017-08-02 16:44:14 -0500366 sizeof(struct ibmvnic_tx_queue_stats),
367 GFP_KERNEL);
368 if (!adapter->tx_stats_buffers)
369 return -ENOMEM;
370
371 adapter->rx_stats_buffers =
Nathan Fontenotabcae542018-02-19 13:30:47 -0600372 kcalloc(IBMVNIC_MAX_QUEUES,
John Allen3d52b592017-08-02 16:44:14 -0500373 sizeof(struct ibmvnic_rx_queue_stats),
374 GFP_KERNEL);
375 if (!adapter->rx_stats_buffers)
376 return -ENOMEM;
377
378 return 0;
379}
380
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -0400381static void release_stats_token(struct ibmvnic_adapter *adapter)
382{
383 struct device *dev = &adapter->vdev->dev;
384
385 if (!adapter->stats_token)
386 return;
387
388 dma_unmap_single(dev, adapter->stats_token,
389 sizeof(struct ibmvnic_statistics),
390 DMA_FROM_DEVICE);
391 adapter->stats_token = 0;
392}
393
394static int init_stats_token(struct ibmvnic_adapter *adapter)
395{
396 struct device *dev = &adapter->vdev->dev;
397 dma_addr_t stok;
398
399 stok = dma_map_single(dev, &adapter->stats,
400 sizeof(struct ibmvnic_statistics),
401 DMA_FROM_DEVICE);
402 if (dma_mapping_error(dev, stok)) {
403 dev_err(dev, "Couldn't map stats buffer\n");
404 return -1;
405 }
406
407 adapter->stats_token = stok;
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500408 netdev_dbg(adapter->netdev, "Stats token initialized (%llx)\n", stok);
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -0400409 return 0;
410}
411
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400412static int reset_rx_pools(struct ibmvnic_adapter *adapter)
413{
414 struct ibmvnic_rx_pool *rx_pool;
415 int rx_scrqs;
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500416 int i, j, rc;
John Allen896d8692018-01-18 16:26:31 -0600417 u64 *size_array;
418
419 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
420 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400421
422 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
423 for (i = 0; i < rx_scrqs; i++) {
424 rx_pool = &adapter->rx_pool[i];
425
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500426 netdev_dbg(adapter->netdev, "Re-setting rx_pool[%d]\n", i);
427
John Allen896d8692018-01-18 16:26:31 -0600428 if (rx_pool->buff_size != be64_to_cpu(size_array[i])) {
429 free_long_term_buff(adapter, &rx_pool->long_term_buff);
430 rx_pool->buff_size = be64_to_cpu(size_array[i]);
Thomas Falcon7c940b12019-06-07 16:03:55 -0500431 rc = alloc_long_term_buff(adapter,
432 &rx_pool->long_term_buff,
433 rx_pool->size *
434 rx_pool->buff_size);
John Allen896d8692018-01-18 16:26:31 -0600435 } else {
436 rc = reset_long_term_buff(adapter,
437 &rx_pool->long_term_buff);
438 }
439
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500440 if (rc)
441 return rc;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400442
443 for (j = 0; j < rx_pool->size; j++)
444 rx_pool->free_map[j] = j;
445
446 memset(rx_pool->rx_buff, 0,
447 rx_pool->size * sizeof(struct ibmvnic_rx_buff));
448
449 atomic_set(&rx_pool->available, 0);
450 rx_pool->next_alloc = 0;
451 rx_pool->next_free = 0;
Thomas Falconc3e53b92017-06-14 23:50:05 -0500452 rx_pool->active = 1;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400453 }
454
455 return 0;
456}
457
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400458static void release_rx_pools(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600459{
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400460 struct ibmvnic_rx_pool *rx_pool;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400461 int i, j;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600462
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400463 if (!adapter->rx_pool)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600464 return;
465
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600466 for (i = 0; i < adapter->num_active_rx_pools; i++) {
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400467 rx_pool = &adapter->rx_pool[i];
468
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500469 netdev_dbg(adapter->netdev, "Releasing rx_pool[%d]\n", i);
470
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400471 kfree(rx_pool->free_map);
472 free_long_term_buff(adapter, &rx_pool->long_term_buff);
473
474 if (!rx_pool->rx_buff)
Nathan Fontenote0ebe9422017-05-03 14:04:50 -0400475 continue;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400476
477 for (j = 0; j < rx_pool->size; j++) {
478 if (rx_pool->rx_buff[j].skb) {
Thomas Falconb7cdec32018-11-21 11:17:58 -0600479 dev_kfree_skb_any(rx_pool->rx_buff[j].skb);
480 rx_pool->rx_buff[j].skb = NULL;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400481 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600482 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400483
484 kfree(rx_pool->rx_buff);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600485 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400486
487 kfree(adapter->rx_pool);
488 adapter->rx_pool = NULL;
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600489 adapter->num_active_rx_pools = 0;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400490}
491
492static int init_rx_pools(struct net_device *netdev)
493{
494 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
495 struct device *dev = &adapter->vdev->dev;
496 struct ibmvnic_rx_pool *rx_pool;
497 int rxadd_subcrqs;
498 u64 *size_array;
499 int i, j;
500
501 rxadd_subcrqs =
502 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
503 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
504 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
505
506 adapter->rx_pool = kcalloc(rxadd_subcrqs,
507 sizeof(struct ibmvnic_rx_pool),
508 GFP_KERNEL);
509 if (!adapter->rx_pool) {
510 dev_err(dev, "Failed to allocate rx pools\n");
511 return -1;
512 }
513
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600514 adapter->num_active_rx_pools = rxadd_subcrqs;
515
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400516 for (i = 0; i < rxadd_subcrqs; i++) {
517 rx_pool = &adapter->rx_pool[i];
518
519 netdev_dbg(adapter->netdev,
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500520 "Initializing rx_pool[%d], %lld buffs, %lld bytes each\n",
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400521 i, adapter->req_rx_add_entries_per_subcrq,
522 be64_to_cpu(size_array[i]));
523
524 rx_pool->size = adapter->req_rx_add_entries_per_subcrq;
525 rx_pool->index = i;
526 rx_pool->buff_size = be64_to_cpu(size_array[i]);
527 rx_pool->active = 1;
528
529 rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int),
530 GFP_KERNEL);
531 if (!rx_pool->free_map) {
532 release_rx_pools(adapter);
533 return -1;
534 }
535
536 rx_pool->rx_buff = kcalloc(rx_pool->size,
537 sizeof(struct ibmvnic_rx_buff),
538 GFP_KERNEL);
539 if (!rx_pool->rx_buff) {
540 dev_err(dev, "Couldn't alloc rx buffers\n");
541 release_rx_pools(adapter);
542 return -1;
543 }
544
545 if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
546 rx_pool->size * rx_pool->buff_size)) {
547 release_rx_pools(adapter);
548 return -1;
549 }
550
551 for (j = 0; j < rx_pool->size; ++j)
552 rx_pool->free_map[j] = j;
553
554 atomic_set(&rx_pool->available, 0);
555 rx_pool->next_alloc = 0;
556 rx_pool->next_free = 0;
557 }
558
559 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600560}
561
Thomas Falcone26dc252018-03-16 20:00:25 -0500562static int reset_one_tx_pool(struct ibmvnic_adapter *adapter,
563 struct ibmvnic_tx_pool *tx_pool)
564{
565 int rc, i;
566
567 rc = reset_long_term_buff(adapter, &tx_pool->long_term_buff);
568 if (rc)
569 return rc;
570
571 memset(tx_pool->tx_buff, 0,
572 tx_pool->num_buffers *
573 sizeof(struct ibmvnic_tx_buff));
574
575 for (i = 0; i < tx_pool->num_buffers; i++)
576 tx_pool->free_map[i] = i;
577
578 tx_pool->consumer_index = 0;
579 tx_pool->producer_index = 0;
580
581 return 0;
582}
583
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400584static int reset_tx_pools(struct ibmvnic_adapter *adapter)
585{
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400586 int tx_scrqs;
Thomas Falcone26dc252018-03-16 20:00:25 -0500587 int i, rc;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400588
589 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
590 for (i = 0; i < tx_scrqs; i++) {
Thomas Falcone26dc252018-03-16 20:00:25 -0500591 rc = reset_one_tx_pool(adapter, &adapter->tso_pool[i]);
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500592 if (rc)
593 return rc;
Thomas Falcone26dc252018-03-16 20:00:25 -0500594 rc = reset_one_tx_pool(adapter, &adapter->tx_pool[i]);
Thomas Falconfdb06102017-10-17 12:36:55 -0500595 if (rc)
596 return rc;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400597 }
598
599 return 0;
600}
601
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200602static void release_vpd_data(struct ibmvnic_adapter *adapter)
603{
604 if (!adapter->vpd)
605 return;
606
607 kfree(adapter->vpd->buff);
608 kfree(adapter->vpd);
Thomas Falconb0992ec2018-02-06 17:25:23 -0600609
610 adapter->vpd = NULL;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200611}
612
Thomas Falconfb794212018-03-16 20:00:26 -0500613static void release_one_tx_pool(struct ibmvnic_adapter *adapter,
614 struct ibmvnic_tx_pool *tx_pool)
615{
616 kfree(tx_pool->tx_buff);
617 kfree(tx_pool->free_map);
618 free_long_term_buff(adapter, &tx_pool->long_term_buff);
619}
620
Nathan Fontenotc657e322017-03-30 02:49:06 -0400621static void release_tx_pools(struct ibmvnic_adapter *adapter)
622{
John Allen896d8692018-01-18 16:26:31 -0600623 int i;
Nathan Fontenotc657e322017-03-30 02:49:06 -0400624
625 if (!adapter->tx_pool)
626 return;
627
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600628 for (i = 0; i < adapter->num_active_tx_pools; i++) {
Thomas Falconfb794212018-03-16 20:00:26 -0500629 release_one_tx_pool(adapter, &adapter->tx_pool[i]);
630 release_one_tx_pool(adapter, &adapter->tso_pool[i]);
Nathan Fontenotc657e322017-03-30 02:49:06 -0400631 }
632
633 kfree(adapter->tx_pool);
634 adapter->tx_pool = NULL;
Thomas Falconfb794212018-03-16 20:00:26 -0500635 kfree(adapter->tso_pool);
636 adapter->tso_pool = NULL;
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600637 adapter->num_active_tx_pools = 0;
Nathan Fontenotc657e322017-03-30 02:49:06 -0400638}
639
Thomas Falcon32053062018-03-16 20:00:27 -0500640static int init_one_tx_pool(struct net_device *netdev,
641 struct ibmvnic_tx_pool *tx_pool,
642 int num_entries, int buf_size)
643{
644 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
645 int i;
646
647 tx_pool->tx_buff = kcalloc(num_entries,
648 sizeof(struct ibmvnic_tx_buff),
649 GFP_KERNEL);
650 if (!tx_pool->tx_buff)
651 return -1;
652
653 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
654 num_entries * buf_size))
655 return -1;
656
657 tx_pool->free_map = kcalloc(num_entries, sizeof(int), GFP_KERNEL);
658 if (!tx_pool->free_map)
659 return -1;
660
661 for (i = 0; i < num_entries; i++)
662 tx_pool->free_map[i] = i;
663
664 tx_pool->consumer_index = 0;
665 tx_pool->producer_index = 0;
666 tx_pool->num_buffers = num_entries;
667 tx_pool->buf_size = buf_size;
668
669 return 0;
670}
671
Nathan Fontenotc657e322017-03-30 02:49:06 -0400672static int init_tx_pools(struct net_device *netdev)
673{
674 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenotc657e322017-03-30 02:49:06 -0400675 int tx_subcrqs;
Thomas Falcon32053062018-03-16 20:00:27 -0500676 int i, rc;
Nathan Fontenotc657e322017-03-30 02:49:06 -0400677
678 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
679 adapter->tx_pool = kcalloc(tx_subcrqs,
680 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
681 if (!adapter->tx_pool)
682 return -1;
683
Thomas Falcon32053062018-03-16 20:00:27 -0500684 adapter->tso_pool = kcalloc(tx_subcrqs,
685 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
686 if (!adapter->tso_pool)
687 return -1;
688
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600689 adapter->num_active_tx_pools = tx_subcrqs;
690
Nathan Fontenotc657e322017-03-30 02:49:06 -0400691 for (i = 0; i < tx_subcrqs; i++) {
Thomas Falcon32053062018-03-16 20:00:27 -0500692 rc = init_one_tx_pool(netdev, &adapter->tx_pool[i],
693 adapter->req_tx_entries_per_subcrq,
694 adapter->req_mtu + VLAN_HLEN);
695 if (rc) {
Nathan Fontenotc657e322017-03-30 02:49:06 -0400696 release_tx_pools(adapter);
Thomas Falcon32053062018-03-16 20:00:27 -0500697 return rc;
Nathan Fontenotc657e322017-03-30 02:49:06 -0400698 }
699
Thomas Falcon7c940b12019-06-07 16:03:55 -0500700 rc = init_one_tx_pool(netdev, &adapter->tso_pool[i],
701 IBMVNIC_TSO_BUFS,
702 IBMVNIC_TSO_BUF_SZ);
Thomas Falcon32053062018-03-16 20:00:27 -0500703 if (rc) {
Nathan Fontenotc657e322017-03-30 02:49:06 -0400704 release_tx_pools(adapter);
Thomas Falcon32053062018-03-16 20:00:27 -0500705 return rc;
Nathan Fontenotc657e322017-03-30 02:49:06 -0400706 }
Nathan Fontenotc657e322017-03-30 02:49:06 -0400707 }
708
709 return 0;
710}
711
John Allend944c3d62017-05-26 10:30:13 -0400712static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter)
713{
714 int i;
715
716 if (adapter->napi_enabled)
717 return;
718
719 for (i = 0; i < adapter->req_rx_queues; i++)
720 napi_enable(&adapter->napi[i]);
721
722 adapter->napi_enabled = true;
723}
724
725static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter)
726{
727 int i;
728
729 if (!adapter->napi_enabled)
730 return;
731
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500732 for (i = 0; i < adapter->req_rx_queues; i++) {
733 netdev_dbg(adapter->netdev, "Disabling napi[%d]\n", i);
John Allend944c3d62017-05-26 10:30:13 -0400734 napi_disable(&adapter->napi[i]);
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500735 }
John Allend944c3d62017-05-26 10:30:13 -0400736
737 adapter->napi_enabled = false;
738}
739
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600740static int init_napi(struct ibmvnic_adapter *adapter)
741{
742 int i;
743
744 adapter->napi = kcalloc(adapter->req_rx_queues,
745 sizeof(struct napi_struct), GFP_KERNEL);
746 if (!adapter->napi)
747 return -ENOMEM;
748
749 for (i = 0; i < adapter->req_rx_queues; i++) {
750 netdev_dbg(adapter->netdev, "Adding napi[%d]\n", i);
751 netif_napi_add(adapter->netdev, &adapter->napi[i],
752 ibmvnic_poll, NAPI_POLL_WEIGHT);
753 }
754
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600755 adapter->num_active_rx_napi = adapter->req_rx_queues;
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600756 return 0;
757}
758
759static void release_napi(struct ibmvnic_adapter *adapter)
760{
761 int i;
762
763 if (!adapter->napi)
764 return;
765
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600766 for (i = 0; i < adapter->num_active_rx_napi; i++) {
Wen Yang390de192018-12-11 12:20:46 +0800767 netdev_dbg(adapter->netdev, "Releasing napi[%d]\n", i);
768 netif_napi_del(&adapter->napi[i]);
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600769 }
770
771 kfree(adapter->napi);
772 adapter->napi = NULL;
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600773 adapter->num_active_rx_napi = 0;
Thomas Falconc3f22412018-05-23 13:37:55 -0500774 adapter->napi_enabled = false;
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600775}
776
John Allena57a5d22017-03-17 17:13:41 -0500777static int ibmvnic_login(struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600778{
779 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allenbd0b6722017-03-17 17:13:40 -0500780 unsigned long timeout = msecs_to_jiffies(30000);
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500781 int retry_count = 0;
Thomas Falconeb110412018-05-24 14:37:53 -0500782 bool retry;
Thomas Falcon4d96f122017-08-01 15:04:36 -0500783 int rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600784
John Allenbd0b6722017-03-17 17:13:40 -0500785 do {
Thomas Falconeb110412018-05-24 14:37:53 -0500786 retry = false;
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500787 if (retry_count > IBMVNIC_MAX_QUEUES) {
788 netdev_warn(netdev, "Login attempts exceeded\n");
789 return -1;
790 }
791
792 adapter->init_done_rc = 0;
793 reinit_completion(&adapter->init_done);
794 rc = send_login(adapter);
795 if (rc) {
796 netdev_warn(netdev, "Unable to login\n");
797 return rc;
798 }
799
800 if (!wait_for_completion_timeout(&adapter->init_done,
801 timeout)) {
802 netdev_warn(netdev, "Login timed out\n");
803 return -1;
804 }
805
806 if (adapter->init_done_rc == PARTIALSUCCESS) {
807 retry_count++;
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -0600808 release_sub_crqs(adapter, 1);
John Allenbd0b6722017-03-17 17:13:40 -0500809
Thomas Falconeb110412018-05-24 14:37:53 -0500810 retry = true;
811 netdev_dbg(netdev,
812 "Received partial success, retrying...\n");
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500813 adapter->init_done_rc = 0;
John Allenbd0b6722017-03-17 17:13:40 -0500814 reinit_completion(&adapter->init_done);
815 send_cap_queries(adapter);
816 if (!wait_for_completion_timeout(&adapter->init_done,
817 timeout)) {
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500818 netdev_warn(netdev,
819 "Capabilities query timed out\n");
John Allenbd0b6722017-03-17 17:13:40 -0500820 return -1;
821 }
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500822
Thomas Falcon4d96f122017-08-01 15:04:36 -0500823 rc = init_sub_crqs(adapter);
824 if (rc) {
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500825 netdev_warn(netdev,
826 "SCRQ initialization failed\n");
Thomas Falcon4d96f122017-08-01 15:04:36 -0500827 return -1;
828 }
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500829
Thomas Falcon4d96f122017-08-01 15:04:36 -0500830 rc = init_sub_crq_irqs(adapter);
831 if (rc) {
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500832 netdev_warn(netdev,
833 "SCRQ irq initialization failed\n");
Thomas Falcon4d96f122017-08-01 15:04:36 -0500834 return -1;
835 }
Nathan Fontenot64d92aa2018-04-11 10:09:32 -0500836 } else if (adapter->init_done_rc) {
837 netdev_warn(netdev, "Adapter login failed\n");
John Allenbd0b6722017-03-17 17:13:40 -0500838 return -1;
839 }
Thomas Falconeb110412018-05-24 14:37:53 -0500840 } while (retry);
John Allenbd0b6722017-03-17 17:13:40 -0500841
Thomas Falcon62740e92019-05-09 23:13:43 -0500842 __ibmvnic_set_mac(netdev, adapter->mac_addr);
Thomas Falcon3d166132018-01-10 19:39:52 -0600843
John Allena57a5d22017-03-17 17:13:41 -0500844 return 0;
845}
846
Thomas Falcon34f0f4e2018-02-13 18:23:40 -0600847static void release_login_buffer(struct ibmvnic_adapter *adapter)
848{
849 kfree(adapter->login_buf);
850 adapter->login_buf = NULL;
851}
852
853static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
854{
855 kfree(adapter->login_rsp_buf);
856 adapter->login_rsp_buf = NULL;
857}
858
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400859static void release_resources(struct ibmvnic_adapter *adapter)
860{
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200861 release_vpd_data(adapter);
862
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400863 release_tx_pools(adapter);
864 release_rx_pools(adapter);
865
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600866 release_napi(adapter);
Thomas Falcon34f0f4e2018-02-13 18:23:40 -0600867 release_login_rsp_buffer(adapter);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400868}
869
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400870static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
871{
872 struct net_device *netdev = adapter->netdev;
873 unsigned long timeout = msecs_to_jiffies(30000);
874 union ibmvnic_crq crq;
875 bool resend;
876 int rc;
877
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500878 netdev_dbg(netdev, "setting link state %d\n", link_state);
879
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400880 memset(&crq, 0, sizeof(crq));
881 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
882 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
883 crq.logical_link_state.link_state = link_state;
884
885 do {
886 resend = false;
887
888 reinit_completion(&adapter->init_done);
889 rc = ibmvnic_send_crq(adapter, &crq);
890 if (rc) {
891 netdev_err(netdev, "Failed to set link state\n");
892 return rc;
893 }
894
895 if (!wait_for_completion_timeout(&adapter->init_done,
896 timeout)) {
897 netdev_err(netdev, "timeout setting link state\n");
898 return -1;
899 }
900
901 if (adapter->init_done_rc == 1) {
902 /* Partuial success, delay and re-send */
903 mdelay(1000);
904 resend = true;
Thomas Falconab5ec332018-05-23 13:37:59 -0500905 } else if (adapter->init_done_rc) {
906 netdev_warn(netdev, "Unable to set link state, rc=%d\n",
907 adapter->init_done_rc);
908 return adapter->init_done_rc;
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400909 }
910 } while (resend);
911
912 return 0;
913}
914
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400915static int set_real_num_queues(struct net_device *netdev)
916{
917 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
918 int rc;
919
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -0500920 netdev_dbg(netdev, "Setting real tx/rx queues (%llx/%llx)\n",
921 adapter->req_tx_queues, adapter->req_rx_queues);
922
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400923 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
924 if (rc) {
925 netdev_err(netdev, "failed to set the number of tx queues\n");
926 return rc;
927 }
928
929 rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues);
930 if (rc)
931 netdev_err(netdev, "failed to set the number of rx queues\n");
932
933 return rc;
934}
935
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200936static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
937{
938 struct device *dev = &adapter->vdev->dev;
939 union ibmvnic_crq crq;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200940 int len = 0;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500941 int rc;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200942
943 if (adapter->vpd->buff)
944 len = adapter->vpd->len;
945
Thomas Falcon070eca92019-11-25 17:12:53 -0600946 reinit_completion(&adapter->fw_done);
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200947 crq.get_vpd_size.first = IBMVNIC_CRQ_CMD;
948 crq.get_vpd_size.cmd = GET_VPD_SIZE;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500949 rc = ibmvnic_send_crq(adapter, &crq);
950 if (rc)
951 return rc;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200952 wait_for_completion(&adapter->fw_done);
953
954 if (!adapter->vpd->len)
955 return -ENODATA;
956
957 if (!adapter->vpd->buff)
958 adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
959 else if (adapter->vpd->len != len)
960 adapter->vpd->buff =
961 krealloc(adapter->vpd->buff,
962 adapter->vpd->len, GFP_KERNEL);
963
964 if (!adapter->vpd->buff) {
965 dev_err(dev, "Could allocate VPD buffer\n");
966 return -ENOMEM;
967 }
968
969 adapter->vpd->dma_addr =
970 dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len,
971 DMA_FROM_DEVICE);
Desnes Augusto Nunes do Rosariof7431062017-11-17 09:09:04 -0200972 if (dma_mapping_error(dev, adapter->vpd->dma_addr)) {
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200973 dev_err(dev, "Could not map VPD buffer\n");
974 kfree(adapter->vpd->buff);
Thomas Falconb0992ec2018-02-06 17:25:23 -0600975 adapter->vpd->buff = NULL;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200976 return -ENOMEM;
977 }
978
979 reinit_completion(&adapter->fw_done);
980 crq.get_vpd.first = IBMVNIC_CRQ_CMD;
981 crq.get_vpd.cmd = GET_VPD;
982 crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr);
983 crq.get_vpd.len = cpu_to_be32((u32)adapter->vpd->len);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -0500984 rc = ibmvnic_send_crq(adapter, &crq);
985 if (rc) {
986 kfree(adapter->vpd->buff);
987 adapter->vpd->buff = NULL;
988 return rc;
989 }
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200990 wait_for_completion(&adapter->fw_done);
991
992 return 0;
993}
994
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400995static int init_resources(struct ibmvnic_adapter *adapter)
John Allena57a5d22017-03-17 17:13:41 -0500996{
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400997 struct net_device *netdev = adapter->netdev;
Nathan Fontenot86f669b2018-02-19 13:30:39 -0600998 int rc;
John Allena57a5d22017-03-17 17:13:41 -0500999
Thomas Falcon7f3c6e62017-04-21 15:38:40 -04001000 rc = set_real_num_queues(netdev);
1001 if (rc)
1002 return rc;
John Allenbd0b6722017-03-17 17:13:40 -05001003
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02001004 adapter->vpd = kzalloc(sizeof(*adapter->vpd), GFP_KERNEL);
1005 if (!adapter->vpd)
1006 return -ENOMEM;
1007
John Allen69d08dc2018-01-18 16:27:58 -06001008 /* Vital Product Data (VPD) */
1009 rc = ibmvnic_get_vpd(adapter);
1010 if (rc) {
1011 netdev_err(netdev, "failed to initialize Vital Product Data (VPD)\n");
1012 return rc;
1013 }
1014
Thomas Falcon032c5e82015-12-21 11:26:06 -06001015 adapter->map_id = 1;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001016
Nathan Fontenot86f669b2018-02-19 13:30:39 -06001017 rc = init_napi(adapter);
1018 if (rc)
1019 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001020
Thomas Falcon032c5e82015-12-21 11:26:06 -06001021 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -04001022
1023 rc = init_rx_pools(netdev);
1024 if (rc)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001025 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001026
Nathan Fontenotc657e322017-03-30 02:49:06 -04001027 rc = init_tx_pools(netdev);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001028 return rc;
1029}
1030
Nathan Fontenoted651a12017-05-03 14:04:38 -04001031static int __ibmvnic_open(struct net_device *netdev)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001032{
1033 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001034 enum vnic_state prev_state = adapter->state;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001035 int i, rc;
1036
Nathan Fontenot90c80142017-05-03 14:04:32 -04001037 adapter->state = VNIC_OPENING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001038 replenish_pools(adapter);
John Allend944c3d62017-05-26 10:30:13 -04001039 ibmvnic_napi_enable(adapter);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001040
Thomas Falcon032c5e82015-12-21 11:26:06 -06001041 /* We're ready to receive frames, enable the sub-crq interrupts and
1042 * set the logical link state to up
1043 */
Nathan Fontenoted651a12017-05-03 14:04:38 -04001044 for (i = 0; i < adapter->req_rx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001045 netdev_dbg(netdev, "Enabling rx_scrq[%d] irq\n", i);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001046 if (prev_state == VNIC_CLOSED)
1047 enable_irq(adapter->rx_scrq[i]->irq);
Thomas Falconf23e0642018-04-15 18:53:36 -05001048 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001049 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001050
Nathan Fontenoted651a12017-05-03 14:04:38 -04001051 for (i = 0; i < adapter->req_tx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001052 netdev_dbg(netdev, "Enabling tx_scrq[%d] irq\n", i);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001053 if (prev_state == VNIC_CLOSED)
1054 enable_irq(adapter->tx_scrq[i]->irq);
Thomas Falconf23e0642018-04-15 18:53:36 -05001055 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001056 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001057
Nathan Fontenot53da09e2017-04-21 15:39:04 -04001058 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001059 if (rc) {
1060 for (i = 0; i < adapter->req_rx_queues; i++)
1061 napi_disable(&adapter->napi[i]);
1062 release_resources(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001063 return rc;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001064 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001065
Nathan Fontenoted651a12017-05-03 14:04:38 -04001066 netif_tx_start_all_queues(netdev);
1067
1068 if (prev_state == VNIC_CLOSED) {
1069 for (i = 0; i < adapter->req_rx_queues; i++)
1070 napi_schedule(&adapter->napi[i]);
1071 }
1072
1073 adapter->state = VNIC_OPEN;
1074 return rc;
1075}
1076
1077static int ibmvnic_open(struct net_device *netdev)
1078{
1079 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allen69d08dc2018-01-18 16:27:58 -06001080 int rc;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001081
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05001082 /* If device failover is pending, just set device state and return.
1083 * Device operation will be handled by reset routine.
1084 */
1085 if (adapter->failover_pending) {
1086 adapter->state = VNIC_OPEN;
1087 return 0;
1088 }
1089
Nathan Fontenoted651a12017-05-03 14:04:38 -04001090 if (adapter->state != VNIC_CLOSED) {
1091 rc = ibmvnic_login(netdev);
Juliet Kima5681e22018-11-19 15:59:22 -06001092 if (rc)
Nathan Fontenoted651a12017-05-03 14:04:38 -04001093 return rc;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001094
1095 rc = init_resources(adapter);
1096 if (rc) {
1097 netdev_err(netdev, "failed to initialize resources\n");
1098 release_resources(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001099 return rc;
1100 }
1101 }
1102
1103 rc = __ibmvnic_open(netdev);
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02001104
Nathan Fontenotbfc32f22017-05-03 14:04:26 -04001105 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001106}
1107
Thomas Falcond0869c02018-02-13 18:23:43 -06001108static void clean_rx_pools(struct ibmvnic_adapter *adapter)
1109{
1110 struct ibmvnic_rx_pool *rx_pool;
Thomas Falcon637f81d2018-02-26 18:10:57 -06001111 struct ibmvnic_rx_buff *rx_buff;
Thomas Falcond0869c02018-02-13 18:23:43 -06001112 u64 rx_entries;
1113 int rx_scrqs;
1114 int i, j;
1115
1116 if (!adapter->rx_pool)
1117 return;
1118
Thomas Falcon660e3092018-04-20 14:25:32 -05001119 rx_scrqs = adapter->num_active_rx_pools;
Thomas Falcond0869c02018-02-13 18:23:43 -06001120 rx_entries = adapter->req_rx_add_entries_per_subcrq;
1121
1122 /* Free any remaining skbs in the rx buffer pools */
1123 for (i = 0; i < rx_scrqs; i++) {
1124 rx_pool = &adapter->rx_pool[i];
Thomas Falcon637f81d2018-02-26 18:10:57 -06001125 if (!rx_pool || !rx_pool->rx_buff)
Thomas Falcond0869c02018-02-13 18:23:43 -06001126 continue;
1127
1128 netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i);
1129 for (j = 0; j < rx_entries; j++) {
Thomas Falcon637f81d2018-02-26 18:10:57 -06001130 rx_buff = &rx_pool->rx_buff[j];
1131 if (rx_buff && rx_buff->skb) {
1132 dev_kfree_skb_any(rx_buff->skb);
1133 rx_buff->skb = NULL;
Thomas Falcond0869c02018-02-13 18:23:43 -06001134 }
1135 }
1136 }
1137}
1138
Thomas Falcone9e1e972018-03-16 20:00:30 -05001139static void clean_one_tx_pool(struct ibmvnic_adapter *adapter,
1140 struct ibmvnic_tx_pool *tx_pool)
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001141{
Thomas Falcon637f81d2018-02-26 18:10:57 -06001142 struct ibmvnic_tx_buff *tx_buff;
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001143 u64 tx_entries;
Thomas Falcone9e1e972018-03-16 20:00:30 -05001144 int i;
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001145
Dan Carpenter050e85c2018-03-23 14:36:15 +03001146 if (!tx_pool || !tx_pool->tx_buff)
Thomas Falcone9e1e972018-03-16 20:00:30 -05001147 return;
1148
1149 tx_entries = tx_pool->num_buffers;
1150
1151 for (i = 0; i < tx_entries; i++) {
1152 tx_buff = &tx_pool->tx_buff[i];
1153 if (tx_buff && tx_buff->skb) {
1154 dev_kfree_skb_any(tx_buff->skb);
1155 tx_buff->skb = NULL;
1156 }
1157 }
1158}
1159
1160static void clean_tx_pools(struct ibmvnic_adapter *adapter)
1161{
1162 int tx_scrqs;
1163 int i;
1164
1165 if (!adapter->tx_pool || !adapter->tso_pool)
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001166 return;
1167
Thomas Falcon660e3092018-04-20 14:25:32 -05001168 tx_scrqs = adapter->num_active_tx_pools;
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001169
1170 /* Free any remaining skbs in the tx buffer pools */
1171 for (i = 0; i < tx_scrqs; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001172 netdev_dbg(adapter->netdev, "Cleaning tx_pool[%d]\n", i);
Thomas Falcone9e1e972018-03-16 20:00:30 -05001173 clean_one_tx_pool(adapter, &adapter->tx_pool[i]);
1174 clean_one_tx_pool(adapter, &adapter->tso_pool[i]);
Nathan Fontenotb41b83e2017-05-03 14:04:56 -04001175 }
1176}
1177
John Allen6095e592018-03-30 13:44:21 -05001178static void ibmvnic_disable_irqs(struct ibmvnic_adapter *adapter)
John Allenea5509f2017-03-17 17:13:43 -05001179{
John Allen6095e592018-03-30 13:44:21 -05001180 struct net_device *netdev = adapter->netdev;
John Allenea5509f2017-03-17 17:13:43 -05001181 int i;
1182
Nathan Fontenot46293b92017-05-03 14:05:02 -04001183 if (adapter->tx_scrq) {
1184 for (i = 0; i < adapter->req_tx_queues; i++)
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001185 if (adapter->tx_scrq[i]->irq) {
Thomas Falconf8738662018-03-07 17:51:45 -06001186 netdev_dbg(netdev,
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001187 "Disabling tx_scrq[%d] irq\n", i);
Thomas Falconf23e0642018-04-15 18:53:36 -05001188 disable_scrq_irq(adapter, adapter->tx_scrq[i]);
Nathan Fontenot46293b92017-05-03 14:05:02 -04001189 disable_irq(adapter->tx_scrq[i]->irq);
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001190 }
Nathan Fontenot46293b92017-05-03 14:05:02 -04001191 }
1192
Nathan Fontenot46293b92017-05-03 14:05:02 -04001193 if (adapter->rx_scrq) {
1194 for (i = 0; i < adapter->req_rx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001195 if (adapter->rx_scrq[i]->irq) {
Thomas Falconf8738662018-03-07 17:51:45 -06001196 netdev_dbg(netdev,
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001197 "Disabling rx_scrq[%d] irq\n", i);
Thomas Falconf23e0642018-04-15 18:53:36 -05001198 disable_scrq_irq(adapter, adapter->rx_scrq[i]);
Nathan Fontenot46293b92017-05-03 14:05:02 -04001199 disable_irq(adapter->rx_scrq[i]->irq);
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001200 }
Nathan Fontenot46293b92017-05-03 14:05:02 -04001201 }
1202 }
John Allen6095e592018-03-30 13:44:21 -05001203}
1204
1205static void ibmvnic_cleanup(struct net_device *netdev)
1206{
1207 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1208
1209 /* ensure that transmissions are stopped if called by do_reset */
Juliet Kim7ed5b312019-09-20 16:11:23 -04001210 if (test_bit(0, &adapter->resetting))
John Allen6095e592018-03-30 13:44:21 -05001211 netif_tx_disable(netdev);
1212 else
1213 netif_tx_stop_all_queues(netdev);
1214
1215 ibmvnic_napi_disable(adapter);
1216 ibmvnic_disable_irqs(adapter);
1217
Thomas Falcond0869c02018-02-13 18:23:43 -06001218 clean_rx_pools(adapter);
Thomas Falcon10f76212017-05-26 10:30:31 -04001219 clean_tx_pools(adapter);
Thomas Falcon01d9bd72018-03-07 17:51:46 -06001220}
1221
1222static int __ibmvnic_close(struct net_device *netdev)
1223{
1224 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1225 int rc = 0;
1226
1227 adapter->state = VNIC_CLOSING;
1228 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
1229 if (rc)
1230 return rc;
Nathan Fontenot90c80142017-05-03 14:04:32 -04001231 adapter->state = VNIC_CLOSED;
Thomas Falcon01d9bd72018-03-07 17:51:46 -06001232 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001233}
1234
Nathan Fontenoted651a12017-05-03 14:04:38 -04001235static int ibmvnic_close(struct net_device *netdev)
1236{
1237 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1238 int rc;
1239
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05001240 /* If device failover is pending, just set device state and return.
1241 * Device operation will be handled by reset routine.
1242 */
1243 if (adapter->failover_pending) {
1244 adapter->state = VNIC_CLOSED;
1245 return 0;
1246 }
1247
Nathan Fontenoted651a12017-05-03 14:04:38 -04001248 rc = __ibmvnic_close(netdev);
Nathan Fontenot30f79622018-04-06 18:37:06 -05001249 ibmvnic_cleanup(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001250
1251 return rc;
1252}
1253
Thomas Falconad7775d2016-04-01 17:20:34 -05001254/**
1255 * build_hdr_data - creates L2/L3/L4 header data buffer
1256 * @hdr_field - bitfield determining needed headers
1257 * @skb - socket buffer
1258 * @hdr_len - array of header lengths
1259 * @tot_len - total length of data
1260 *
1261 * Reads hdr_field to determine which headers are needed by firmware.
1262 * Builds a buffer containing these headers. Saves individual header
1263 * lengths and total buffer length to be used to build descriptors.
1264 */
1265static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
1266 int *hdr_len, u8 *hdr_data)
1267{
1268 int len = 0;
1269 u8 *hdr;
1270
Thomas Falconda75e3b2018-03-12 11:51:02 -05001271 if (skb_vlan_tagged(skb) && !skb_vlan_tag_present(skb))
1272 hdr_len[0] = sizeof(struct vlan_ethhdr);
1273 else
1274 hdr_len[0] = sizeof(struct ethhdr);
Thomas Falconad7775d2016-04-01 17:20:34 -05001275
1276 if (skb->protocol == htons(ETH_P_IP)) {
1277 hdr_len[1] = ip_hdr(skb)->ihl * 4;
1278 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1279 hdr_len[2] = tcp_hdrlen(skb);
1280 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1281 hdr_len[2] = sizeof(struct udphdr);
1282 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1283 hdr_len[1] = sizeof(struct ipv6hdr);
1284 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
1285 hdr_len[2] = tcp_hdrlen(skb);
1286 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
1287 hdr_len[2] = sizeof(struct udphdr);
Thomas Falcon4eb50ce2017-12-18 12:52:40 -06001288 } else if (skb->protocol == htons(ETH_P_ARP)) {
1289 hdr_len[1] = arp_hdr_len(skb->dev);
1290 hdr_len[2] = 0;
Thomas Falconad7775d2016-04-01 17:20:34 -05001291 }
1292
1293 memset(hdr_data, 0, 120);
1294 if ((hdr_field >> 6) & 1) {
1295 hdr = skb_mac_header(skb);
1296 memcpy(hdr_data, hdr, hdr_len[0]);
1297 len += hdr_len[0];
1298 }
1299
1300 if ((hdr_field >> 5) & 1) {
1301 hdr = skb_network_header(skb);
1302 memcpy(hdr_data + len, hdr, hdr_len[1]);
1303 len += hdr_len[1];
1304 }
1305
1306 if ((hdr_field >> 4) & 1) {
1307 hdr = skb_transport_header(skb);
1308 memcpy(hdr_data + len, hdr, hdr_len[2]);
1309 len += hdr_len[2];
1310 }
1311 return len;
1312}
1313
1314/**
1315 * create_hdr_descs - create header and header extension descriptors
1316 * @hdr_field - bitfield determining needed headers
1317 * @data - buffer containing header data
1318 * @len - length of data buffer
1319 * @hdr_len - array of individual header lengths
1320 * @scrq_arr - descriptor array
1321 *
1322 * Creates header and, if needed, header extension descriptors and
1323 * places them in a descriptor array, scrq_arr
1324 */
1325
Thomas Falcon2de09682017-10-16 10:02:11 -05001326static int create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
1327 union sub_crq *scrq_arr)
Thomas Falconad7775d2016-04-01 17:20:34 -05001328{
1329 union sub_crq hdr_desc;
1330 int tmp_len = len;
Thomas Falcon2de09682017-10-16 10:02:11 -05001331 int num_descs = 0;
Thomas Falconad7775d2016-04-01 17:20:34 -05001332 u8 *data, *cur;
1333 int tmp;
1334
1335 while (tmp_len > 0) {
1336 cur = hdr_data + len - tmp_len;
1337
1338 memset(&hdr_desc, 0, sizeof(hdr_desc));
1339 if (cur != hdr_data) {
1340 data = hdr_desc.hdr_ext.data;
1341 tmp = tmp_len > 29 ? 29 : tmp_len;
1342 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
1343 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
1344 hdr_desc.hdr_ext.len = tmp;
1345 } else {
1346 data = hdr_desc.hdr.data;
1347 tmp = tmp_len > 24 ? 24 : tmp_len;
1348 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
1349 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
1350 hdr_desc.hdr.len = tmp;
1351 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
1352 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
1353 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
1354 hdr_desc.hdr.flag = hdr_field << 1;
1355 }
1356 memcpy(data, cur, tmp);
1357 tmp_len -= tmp;
1358 *scrq_arr = hdr_desc;
1359 scrq_arr++;
Thomas Falcon2de09682017-10-16 10:02:11 -05001360 num_descs++;
Thomas Falconad7775d2016-04-01 17:20:34 -05001361 }
Thomas Falcon2de09682017-10-16 10:02:11 -05001362
1363 return num_descs;
Thomas Falconad7775d2016-04-01 17:20:34 -05001364}
1365
1366/**
1367 * build_hdr_descs_arr - build a header descriptor array
1368 * @skb - socket buffer
1369 * @num_entries - number of descriptors to be sent
1370 * @subcrq - first TX descriptor
1371 * @hdr_field - bit field determining which headers will be sent
1372 *
1373 * This function will build a TX descriptor array with applicable
1374 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
1375 */
1376
1377static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
1378 int *num_entries, u8 hdr_field)
1379{
1380 int hdr_len[3] = {0, 0, 0};
Thomas Falcon2de09682017-10-16 10:02:11 -05001381 int tot_len;
Thomas Falconad7775d2016-04-01 17:20:34 -05001382 u8 *hdr_data = txbuff->hdr_data;
1383
1384 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
1385 txbuff->hdr_data);
Thomas Falcon2de09682017-10-16 10:02:11 -05001386 *num_entries += create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
Thomas Falconad7775d2016-04-01 17:20:34 -05001387 txbuff->indir_arr + 1);
1388}
1389
Thomas Falcon1f247a62018-03-12 11:51:04 -05001390static int ibmvnic_xmit_workarounds(struct sk_buff *skb,
1391 struct net_device *netdev)
1392{
1393 /* For some backing devices, mishandling of small packets
1394 * can result in a loss of connection or TX stall. Device
1395 * architects recommend that no packet should be smaller
1396 * than the minimum MTU value provided to the driver, so
1397 * pad any packets to that length
1398 */
1399 if (skb->len < netdev->min_mtu)
1400 return skb_put_padto(skb, netdev->min_mtu);
Thomas Falcon7083a452018-03-12 21:05:26 -05001401
1402 return 0;
Thomas Falcon1f247a62018-03-12 11:51:04 -05001403}
1404
YueHaibing94b2bb22018-09-18 14:35:47 +08001405static netdev_tx_t ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001406{
1407 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1408 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -05001409 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001410 struct device *dev = &adapter->vdev->dev;
1411 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001412 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001413 struct ibmvnic_tx_pool *tx_pool;
1414 unsigned int tx_send_failed = 0;
1415 unsigned int tx_map_failed = 0;
1416 unsigned int tx_dropped = 0;
1417 unsigned int tx_packets = 0;
1418 unsigned int tx_bytes = 0;
1419 dma_addr_t data_dma_addr;
1420 struct netdev_queue *txq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001421 unsigned long lpar_rc;
1422 union sub_crq tx_crq;
1423 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -05001424 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001425 unsigned char *dst;
1426 u64 *handle_array;
1427 int index = 0;
Thomas Falcona0dca102018-01-18 19:29:48 -06001428 u8 proto = 0;
YueHaibing94b2bb22018-09-18 14:35:47 +08001429 netdev_tx_t ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001430
Juliet Kim7ed5b312019-09-20 16:11:23 -04001431 if (test_bit(0, &adapter->resetting)) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001432 if (!netif_subqueue_stopped(netdev, skb))
1433 netif_stop_subqueue(netdev, queue_num);
1434 dev_kfree_skb_any(skb);
1435
Thomas Falcon032c5e82015-12-21 11:26:06 -06001436 tx_send_failed++;
1437 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001438 ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001439 goto out;
1440 }
1441
Thomas Falcon7083a452018-03-12 21:05:26 -05001442 if (ibmvnic_xmit_workarounds(skb, netdev)) {
Thomas Falcon1f247a62018-03-12 11:51:04 -05001443 tx_dropped++;
1444 tx_send_failed++;
1445 ret = NETDEV_TX_OK;
1446 goto out;
1447 }
Thomas Falcon06b3e352018-03-16 20:00:28 -05001448 if (skb_is_gso(skb))
1449 tx_pool = &adapter->tso_pool[queue_num];
1450 else
1451 tx_pool = &adapter->tx_pool[queue_num];
Thomas Falcon1f247a62018-03-12 11:51:04 -05001452
Nathan Fontenot161b8a82017-05-03 14:05:08 -04001453 tx_scrq = adapter->tx_scrq[queue_num];
1454 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
1455 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
1456 be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs));
1457
Thomas Falcon032c5e82015-12-21 11:26:06 -06001458 index = tx_pool->free_map[tx_pool->consumer_index];
Thomas Falconfdb06102017-10-17 12:36:55 -05001459
Thomas Falcon86b61a52018-03-16 20:00:29 -05001460 if (index == IBMVNIC_INVALID_MAP) {
1461 dev_kfree_skb_any(skb);
1462 tx_send_failed++;
1463 tx_dropped++;
1464 ret = NETDEV_TX_OK;
1465 goto out;
1466 }
1467
1468 tx_pool->free_map[tx_pool->consumer_index] = IBMVNIC_INVALID_MAP;
1469
Thomas Falcon06b3e352018-03-16 20:00:28 -05001470 offset = index * tx_pool->buf_size;
1471 dst = tx_pool->long_term_buff.buff + offset;
1472 memset(dst, 0, tx_pool->buf_size);
1473 data_dma_addr = tx_pool->long_term_buff.addr + offset;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001474
Thomas Falcon15482052017-10-17 12:36:54 -05001475 if (skb_shinfo(skb)->nr_frags) {
1476 int cur, i;
1477
1478 /* Copy the head */
1479 skb_copy_from_linear_data(skb, dst, skb_headlen(skb));
1480 cur = skb_headlen(skb);
1481
1482 /* Copy the frags */
1483 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1484 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1485
1486 memcpy(dst + cur,
1487 page_address(skb_frag_page(frag)) +
Jonathan Lemonb54c9d52019-07-30 07:40:33 -07001488 skb_frag_off(frag), skb_frag_size(frag));
Thomas Falcon15482052017-10-17 12:36:54 -05001489 cur += skb_frag_size(frag);
1490 }
1491 } else {
1492 skb_copy_from_linear_data(skb, dst, skb->len);
1493 }
1494
Thomas Falcon032c5e82015-12-21 11:26:06 -06001495 tx_pool->consumer_index =
Thomas Falcon06b3e352018-03-16 20:00:28 -05001496 (tx_pool->consumer_index + 1) % tx_pool->num_buffers;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001497
1498 tx_buff = &tx_pool->tx_buff[index];
1499 tx_buff->skb = skb;
1500 tx_buff->data_dma[0] = data_dma_addr;
1501 tx_buff->data_len[0] = skb->len;
1502 tx_buff->index = index;
1503 tx_buff->pool_index = queue_num;
1504 tx_buff->last_frag = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001505
1506 memset(&tx_crq, 0, sizeof(tx_crq));
1507 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
1508 tx_crq.v1.type = IBMVNIC_TX_DESC;
1509 tx_crq.v1.n_crq_elem = 1;
1510 tx_crq.v1.n_sge = 1;
1511 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
Thomas Falcon06b3e352018-03-16 20:00:28 -05001512
Thomas Falconfdb06102017-10-17 12:36:55 -05001513 if (skb_is_gso(skb))
Thomas Falcon06b3e352018-03-16 20:00:28 -05001514 tx_crq.v1.correlator =
1515 cpu_to_be32(index | IBMVNIC_TSO_POOL_MASK);
Thomas Falconfdb06102017-10-17 12:36:55 -05001516 else
Thomas Falcon06b3e352018-03-16 20:00:28 -05001517 tx_crq.v1.correlator = cpu_to_be32(index);
1518 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001519 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
1520 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
1521
Michał Mirosławe84b4792018-11-07 17:50:52 +01001522 if (adapter->vlan_header_insertion && skb_vlan_tag_present(skb)) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001523 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
1524 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
1525 }
1526
1527 if (skb->protocol == htons(ETH_P_IP)) {
Thomas Falcona0dca102018-01-18 19:29:48 -06001528 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
1529 proto = ip_hdr(skb)->protocol;
1530 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1531 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
1532 proto = ipv6_hdr(skb)->nexthdr;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001533 }
1534
Thomas Falcona0dca102018-01-18 19:29:48 -06001535 if (proto == IPPROTO_TCP)
1536 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
1537 else if (proto == IPPROTO_UDP)
1538 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
1539
Thomas Falconad7775d2016-04-01 17:20:34 -05001540 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001541 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -05001542 hdrs += 2;
1543 }
Thomas Falconfdb06102017-10-17 12:36:55 -05001544 if (skb_is_gso(skb)) {
1545 tx_crq.v1.flags1 |= IBMVNIC_TX_LSO;
1546 tx_crq.v1.mss = cpu_to_be16(skb_shinfo(skb)->gso_size);
1547 hdrs += 2;
1548 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001549 /* determine if l2/3/4 headers are sent to firmware */
John Allen2fa56a42018-02-09 13:19:46 -06001550 if ((*hdrs >> 7) & 1) {
Thomas Falconad7775d2016-04-01 17:20:34 -05001551 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
1552 tx_crq.v1.n_crq_elem = num_entries;
Thomas Falconecba6162018-02-26 18:10:55 -06001553 tx_buff->num_entries = num_entries;
Thomas Falconad7775d2016-04-01 17:20:34 -05001554 tx_buff->indir_arr[0] = tx_crq;
1555 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
1556 sizeof(tx_buff->indir_arr),
1557 DMA_TO_DEVICE);
1558 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001559 dev_kfree_skb_any(skb);
1560 tx_buff->skb = NULL;
Thomas Falconad7775d2016-04-01 17:20:34 -05001561 if (!firmware_has_feature(FW_FEATURE_CMO))
1562 dev_err(dev, "tx: unable to map descriptor array\n");
1563 tx_map_failed++;
1564 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001565 ret = NETDEV_TX_OK;
Thomas Falcon86b61a52018-03-16 20:00:29 -05001566 goto tx_err_out;
Thomas Falconad7775d2016-04-01 17:20:34 -05001567 }
John Allen498cd8e2016-04-06 11:49:55 -05001568 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -05001569 (u64)tx_buff->indir_dma,
1570 (u64)num_entries);
Thomas Falcon80f0fe02019-08-14 14:57:05 -05001571 dma_unmap_single(dev, tx_buff->indir_dma,
1572 sizeof(tx_buff->indir_arr), DMA_TO_DEVICE);
Thomas Falconad7775d2016-04-01 17:20:34 -05001573 } else {
Thomas Falconecba6162018-02-26 18:10:55 -06001574 tx_buff->num_entries = num_entries;
John Allen498cd8e2016-04-06 11:49:55 -05001575 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
1576 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -05001577 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001578 if (lpar_rc != H_SUCCESS) {
Thomas Falcon2d14d372018-07-13 12:03:32 -05001579 if (lpar_rc != H_CLOSED && lpar_rc != H_PARAMETER)
1580 dev_err_ratelimited(dev, "tx: send failed\n");
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001581 dev_kfree_skb_any(skb);
1582 tx_buff->skb = NULL;
1583
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05001584 if (lpar_rc == H_CLOSED || adapter->failover_pending) {
1585 /* Disable TX and report carrier off if queue is closed
1586 * or pending failover.
Thomas Falconb8c80b82017-05-26 10:30:42 -04001587 * Firmware guarantees that a signal will be sent to the
1588 * driver, triggering a reset or some other action.
1589 */
1590 netif_tx_stop_all_queues(netdev);
1591 netif_carrier_off(netdev);
1592 }
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001593
Thomas Falcon032c5e82015-12-21 11:26:06 -06001594 tx_send_failed++;
1595 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001596 ret = NETDEV_TX_OK;
Thomas Falcon86b61a52018-03-16 20:00:29 -05001597 goto tx_err_out;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001598 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001599
Thomas Falconffc385b2018-02-18 10:08:41 -06001600 if (atomic_add_return(num_entries, &tx_scrq->used)
Brian King58c8c0c2017-04-19 13:44:47 -04001601 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon0aecb132018-02-26 18:10:58 -06001602 netdev_dbg(netdev, "Stopping queue %d\n", queue_num);
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001603 netif_stop_subqueue(netdev, queue_num);
1604 }
1605
Thomas Falcon032c5e82015-12-21 11:26:06 -06001606 tx_packets++;
1607 tx_bytes += skb->len;
1608 txq->trans_start = jiffies;
1609 ret = NETDEV_TX_OK;
Thomas Falcon86b61a52018-03-16 20:00:29 -05001610 goto out;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001611
Thomas Falcon86b61a52018-03-16 20:00:29 -05001612tx_err_out:
1613 /* roll back consumer index and map array*/
1614 if (tx_pool->consumer_index == 0)
1615 tx_pool->consumer_index =
1616 tx_pool->num_buffers - 1;
1617 else
1618 tx_pool->consumer_index--;
1619 tx_pool->free_map[tx_pool->consumer_index] = index;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001620out:
1621 netdev->stats.tx_dropped += tx_dropped;
1622 netdev->stats.tx_bytes += tx_bytes;
1623 netdev->stats.tx_packets += tx_packets;
1624 adapter->tx_send_failed += tx_send_failed;
1625 adapter->tx_map_failed += tx_map_failed;
John Allen3d52b592017-08-02 16:44:14 -05001626 adapter->tx_stats_buffers[queue_num].packets += tx_packets;
1627 adapter->tx_stats_buffers[queue_num].bytes += tx_bytes;
1628 adapter->tx_stats_buffers[queue_num].dropped_packets += tx_dropped;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001629
1630 return ret;
1631}
1632
1633static void ibmvnic_set_multi(struct net_device *netdev)
1634{
1635 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1636 struct netdev_hw_addr *ha;
1637 union ibmvnic_crq crq;
1638
1639 memset(&crq, 0, sizeof(crq));
1640 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1641 crq.request_capability.cmd = REQUEST_CAPABILITY;
1642
1643 if (netdev->flags & IFF_PROMISC) {
1644 if (!adapter->promisc_supported)
1645 return;
1646 } else {
1647 if (netdev->flags & IFF_ALLMULTI) {
1648 /* Accept all multicast */
1649 memset(&crq, 0, sizeof(crq));
1650 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1651 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1652 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1653 ibmvnic_send_crq(adapter, &crq);
1654 } else if (netdev_mc_empty(netdev)) {
1655 /* Reject all multicast */
1656 memset(&crq, 0, sizeof(crq));
1657 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1658 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1659 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1660 ibmvnic_send_crq(adapter, &crq);
1661 } else {
1662 /* Accept one or more multicast(s) */
1663 netdev_for_each_mc_addr(ha, netdev) {
1664 memset(&crq, 0, sizeof(crq));
1665 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1666 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1667 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1668 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1669 ha->addr);
1670 ibmvnic_send_crq(adapter, &crq);
1671 }
1672 }
1673 }
1674}
1675
Thomas Falcon62740e92019-05-09 23:13:43 -05001676static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001677{
1678 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001679 union ibmvnic_crq crq;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05001680 int rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001681
Thomas Falcon62740e92019-05-09 23:13:43 -05001682 if (!is_valid_ether_addr(dev_addr)) {
1683 rc = -EADDRNOTAVAIL;
1684 goto err;
1685 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001686
1687 memset(&crq, 0, sizeof(crq));
1688 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1689 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
Thomas Falcon62740e92019-05-09 23:13:43 -05001690 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], dev_addr);
Thomas Falconf8136142018-01-29 13:45:05 -06001691
Thomas Falcon070eca92019-11-25 17:12:53 -06001692 reinit_completion(&adapter->fw_done);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05001693 rc = ibmvnic_send_crq(adapter, &crq);
Thomas Falcon62740e92019-05-09 23:13:43 -05001694 if (rc) {
1695 rc = -EIO;
1696 goto err;
1697 }
1698
Thomas Falconf8136142018-01-29 13:45:05 -06001699 wait_for_completion(&adapter->fw_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001700 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
Thomas Falcon62740e92019-05-09 23:13:43 -05001701 if (adapter->fw_done_rc) {
1702 rc = -EIO;
1703 goto err;
1704 }
1705
1706 return 0;
1707err:
1708 ether_addr_copy(adapter->mac_addr, netdev->dev_addr);
1709 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001710}
1711
John Allenc26eba02017-10-26 16:23:25 -05001712static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1713{
1714 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1715 struct sockaddr *addr = p;
Thomas Falconf8136142018-01-29 13:45:05 -06001716 int rc;
John Allenc26eba02017-10-26 16:23:25 -05001717
Thomas Falcon62740e92019-05-09 23:13:43 -05001718 rc = 0;
1719 ether_addr_copy(adapter->mac_addr, addr->sa_data);
1720 if (adapter->state != VNIC_PROBED)
1721 rc = __ibmvnic_set_mac(netdev, addr->sa_data);
John Allenc26eba02017-10-26 16:23:25 -05001722
Thomas Falconf8136142018-01-29 13:45:05 -06001723 return rc;
John Allenc26eba02017-10-26 16:23:25 -05001724}
1725
Nathan Fontenoted651a12017-05-03 14:04:38 -04001726/**
Juliet Kimb27507b2019-09-20 16:11:22 -04001727 * do_change_param_reset returns zero if we are able to keep processing reset
1728 * events, or non-zero if we hit a fatal error and must halt.
1729 */
1730static int do_change_param_reset(struct ibmvnic_adapter *adapter,
1731 struct ibmvnic_rwi *rwi,
1732 u32 reset_state)
1733{
1734 struct net_device *netdev = adapter->netdev;
1735 int i, rc;
1736
1737 netdev_dbg(adapter->netdev, "Change param resetting driver (%d)\n",
1738 rwi->reset_reason);
1739
1740 netif_carrier_off(netdev);
1741 adapter->reset_reason = rwi->reset_reason;
1742
1743 ibmvnic_cleanup(netdev);
1744
1745 if (reset_state == VNIC_OPEN) {
1746 rc = __ibmvnic_close(netdev);
1747 if (rc)
1748 return rc;
1749 }
1750
1751 release_resources(adapter);
1752 release_sub_crqs(adapter, 1);
1753 release_crq_queue(adapter);
1754
1755 adapter->state = VNIC_PROBED;
1756
1757 rc = init_crq_queue(adapter);
1758
1759 if (rc) {
1760 netdev_err(adapter->netdev,
1761 "Couldn't initialize crq. rc=%d\n", rc);
1762 return rc;
1763 }
1764
1765 rc = ibmvnic_reset_init(adapter);
1766 if (rc)
1767 return IBMVNIC_INIT_FAILED;
1768
1769 /* If the adapter was in PROBE state prior to the reset,
1770 * exit here.
1771 */
1772 if (reset_state == VNIC_PROBED)
1773 return 0;
1774
1775 rc = ibmvnic_login(netdev);
1776 if (rc) {
1777 adapter->state = reset_state;
1778 return rc;
1779 }
1780
1781 rc = init_resources(adapter);
1782 if (rc)
1783 return rc;
1784
1785 ibmvnic_disable_irqs(adapter);
1786
1787 adapter->state = VNIC_CLOSED;
1788
1789 if (reset_state == VNIC_CLOSED)
1790 return 0;
1791
1792 rc = __ibmvnic_open(netdev);
1793 if (rc)
1794 return IBMVNIC_OPEN_FAILED;
1795
1796 /* refresh device's multicast list */
1797 ibmvnic_set_multi(netdev);
1798
1799 /* kick napi */
1800 for (i = 0; i < adapter->req_rx_queues; i++)
1801 napi_schedule(&adapter->napi[i]);
1802
1803 return 0;
1804}
1805
1806/**
Nathan Fontenoted651a12017-05-03 14:04:38 -04001807 * do_reset returns zero if we are able to keep processing reset events, or
1808 * non-zero if we hit a fatal error and must halt.
1809 */
1810static int do_reset(struct ibmvnic_adapter *adapter,
1811 struct ibmvnic_rwi *rwi, u32 reset_state)
1812{
John Allen896d8692018-01-18 16:26:31 -06001813 u64 old_num_rx_queues, old_num_tx_queues;
Thomas Falcon5bf032e2018-11-21 11:17:59 -06001814 u64 old_num_rx_slots, old_num_tx_slots;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001815 struct net_device *netdev = adapter->netdev;
1816 int i, rc;
1817
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05001818 netdev_dbg(adapter->netdev, "Re-setting driver (%d)\n",
1819 rwi->reset_reason);
1820
Juliet Kimb27507b2019-09-20 16:11:22 -04001821 rtnl_lock();
1822
Nathan Fontenoted651a12017-05-03 14:04:38 -04001823 netif_carrier_off(netdev);
1824 adapter->reset_reason = rwi->reset_reason;
1825
John Allen896d8692018-01-18 16:26:31 -06001826 old_num_rx_queues = adapter->req_rx_queues;
1827 old_num_tx_queues = adapter->req_tx_queues;
Thomas Falcon5bf032e2018-11-21 11:17:59 -06001828 old_num_rx_slots = adapter->req_rx_add_entries_per_subcrq;
1829 old_num_tx_slots = adapter->req_tx_entries_per_subcrq;
John Allen896d8692018-01-18 16:26:31 -06001830
Nathan Fontenot30f79622018-04-06 18:37:06 -05001831 ibmvnic_cleanup(netdev);
1832
Thomas Falcon1f946082019-06-07 16:03:53 -05001833 if (reset_state == VNIC_OPEN &&
1834 adapter->reset_reason != VNIC_RESET_MOBILITY &&
Nathan Fontenot30f79622018-04-06 18:37:06 -05001835 adapter->reset_reason != VNIC_RESET_FAILOVER) {
Juliet Kimb27507b2019-09-20 16:11:22 -04001836 adapter->state = VNIC_CLOSING;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001837
Juliet Kimb27507b2019-09-20 16:11:22 -04001838 /* Release the RTNL lock before link state change and
1839 * re-acquire after the link state change to allow
1840 * linkwatch_event to grab the RTNL lock and run during
1841 * a reset.
1842 */
1843 rtnl_unlock();
1844 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
1845 rtnl_lock();
1846 if (rc)
1847 goto out;
1848
1849 if (adapter->state != VNIC_CLOSING) {
1850 rc = -1;
1851 goto out;
1852 }
1853
1854 adapter->state = VNIC_CLOSED;
John Allenc26eba02017-10-26 16:23:25 -05001855 }
1856
John Allen8cb31cf2017-05-26 10:30:37 -04001857 if (adapter->reset_reason != VNIC_RESET_NON_FATAL) {
1858 /* remove the closed state so when we call open it appears
1859 * we are coming from the probed state.
1860 */
Nathan Fontenoted651a12017-05-03 14:04:38 -04001861 adapter->state = VNIC_PROBED;
John Allen8cb31cf2017-05-26 10:30:37 -04001862
Juliet Kimb27507b2019-09-20 16:11:22 -04001863 if (adapter->reset_reason == VNIC_RESET_MOBILITY) {
Nathan Fontenot30f79622018-04-06 18:37:06 -05001864 rc = ibmvnic_reenable_crq_queue(adapter);
1865 release_sub_crqs(adapter, 1);
1866 } else {
1867 rc = ibmvnic_reset_crq(adapter);
1868 if (!rc)
1869 rc = vio_enable_interrupts(adapter->vdev);
1870 }
1871
1872 if (rc) {
1873 netdev_err(adapter->netdev,
1874 "Couldn't initialize crq. rc=%d\n", rc);
Juliet Kimb27507b2019-09-20 16:11:22 -04001875 goto out;
Nathan Fontenot30f79622018-04-06 18:37:06 -05001876 }
1877
Thomas Falcon8a348452018-05-23 13:38:00 -05001878 rc = ibmvnic_reset_init(adapter);
Juliet Kimb27507b2019-09-20 16:11:22 -04001879 if (rc) {
1880 rc = IBMVNIC_INIT_FAILED;
1881 goto out;
1882 }
John Allen8cb31cf2017-05-26 10:30:37 -04001883
1884 /* If the adapter was in PROBE state prior to the reset,
1885 * exit here.
1886 */
Juliet Kimb27507b2019-09-20 16:11:22 -04001887 if (reset_state == VNIC_PROBED) {
1888 rc = 0;
1889 goto out;
1890 }
John Allen8cb31cf2017-05-26 10:30:37 -04001891
1892 rc = ibmvnic_login(netdev);
1893 if (rc) {
John Allen3578a7e2018-07-16 10:29:30 -05001894 adapter->state = reset_state;
Juliet Kimb27507b2019-09-20 16:11:22 -04001895 goto out;
John Allen8cb31cf2017-05-26 10:30:37 -04001896 }
1897
Juliet Kimb27507b2019-09-20 16:11:22 -04001898 if (adapter->req_rx_queues != old_num_rx_queues ||
1899 adapter->req_tx_queues != old_num_tx_queues ||
1900 adapter->req_rx_add_entries_per_subcrq !=
1901 old_num_rx_slots ||
1902 adapter->req_tx_entries_per_subcrq !=
1903 old_num_tx_slots) {
John Allen896d8692018-01-18 16:26:31 -06001904 release_rx_pools(adapter);
1905 release_tx_pools(adapter);
Juliet Kima5681e22018-11-19 15:59:22 -06001906 release_napi(adapter);
1907 release_vpd_data(adapter);
1908
1909 rc = init_resources(adapter);
Thomas Falconf611a5b2018-08-30 13:19:53 -05001910 if (rc)
Juliet Kimb27507b2019-09-20 16:11:22 -04001911 goto out;
Nathan Fontenotd9043c12018-02-19 13:30:14 -06001912
John Allenc26eba02017-10-26 16:23:25 -05001913 } else {
1914 rc = reset_tx_pools(adapter);
1915 if (rc)
Juliet Kimb27507b2019-09-20 16:11:22 -04001916 goto out;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -04001917
John Allenc26eba02017-10-26 16:23:25 -05001918 rc = reset_rx_pools(adapter);
1919 if (rc)
Juliet Kimb27507b2019-09-20 16:11:22 -04001920 goto out;
John Allenc26eba02017-10-26 16:23:25 -05001921 }
Thomas Falcon134bbe72018-05-16 15:49:04 -05001922 ibmvnic_disable_irqs(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001923 }
John Allene676d812018-03-14 10:41:29 -05001924 adapter->state = VNIC_CLOSED;
1925
Juliet Kimb27507b2019-09-20 16:11:22 -04001926 if (reset_state == VNIC_CLOSED) {
1927 rc = 0;
1928 goto out;
1929 }
John Allene676d812018-03-14 10:41:29 -05001930
Nathan Fontenoted651a12017-05-03 14:04:38 -04001931 rc = __ibmvnic_open(netdev);
1932 if (rc) {
Juliet Kimb27507b2019-09-20 16:11:22 -04001933 rc = IBMVNIC_OPEN_FAILED;
1934 goto out;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001935 }
1936
Thomas Falconbe32a242019-06-07 16:03:54 -05001937 /* refresh device's multicast list */
1938 ibmvnic_set_multi(netdev);
1939
Nathan Fontenoted651a12017-05-03 14:04:38 -04001940 /* kick napi */
1941 for (i = 0; i < adapter->req_rx_queues; i++)
1942 napi_schedule(&adapter->napi[i]);
1943
Juliet Kimb27507b2019-09-20 16:11:22 -04001944 if (adapter->reset_reason != VNIC_RESET_FAILOVER)
Thomas Falcon986103e2018-11-30 10:59:08 -06001945 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, netdev);
Nathan Fontenot61d3e1d2017-06-12 20:47:45 -04001946
Juliet Kimb27507b2019-09-20 16:11:22 -04001947 rc = 0;
1948
1949out:
1950 rtnl_unlock();
1951
1952 return rc;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001953}
1954
Thomas Falcon2770a792018-05-23 13:38:02 -05001955static int do_hard_reset(struct ibmvnic_adapter *adapter,
1956 struct ibmvnic_rwi *rwi, u32 reset_state)
1957{
1958 struct net_device *netdev = adapter->netdev;
1959 int rc;
1960
1961 netdev_dbg(adapter->netdev, "Hard resetting driver (%d)\n",
1962 rwi->reset_reason);
1963
1964 netif_carrier_off(netdev);
1965 adapter->reset_reason = rwi->reset_reason;
1966
1967 ibmvnic_cleanup(netdev);
1968 release_resources(adapter);
1969 release_sub_crqs(adapter, 0);
1970 release_crq_queue(adapter);
1971
1972 /* remove the closed state so when we call open it appears
1973 * we are coming from the probed state.
1974 */
1975 adapter->state = VNIC_PROBED;
1976
Thomas Falconbbd669a2019-04-04 18:58:26 -05001977 reinit_completion(&adapter->init_done);
Thomas Falcon2770a792018-05-23 13:38:02 -05001978 rc = init_crq_queue(adapter);
1979 if (rc) {
1980 netdev_err(adapter->netdev,
1981 "Couldn't initialize crq. rc=%d\n", rc);
1982 return rc;
1983 }
1984
1985 rc = ibmvnic_init(adapter);
1986 if (rc)
1987 return rc;
1988
1989 /* If the adapter was in PROBE state prior to the reset,
1990 * exit here.
1991 */
1992 if (reset_state == VNIC_PROBED)
1993 return 0;
1994
1995 rc = ibmvnic_login(netdev);
1996 if (rc) {
1997 adapter->state = VNIC_PROBED;
1998 return 0;
1999 }
Juliet Kima5681e22018-11-19 15:59:22 -06002000
2001 rc = init_resources(adapter);
Thomas Falcon2770a792018-05-23 13:38:02 -05002002 if (rc)
2003 return rc;
2004
2005 ibmvnic_disable_irqs(adapter);
2006 adapter->state = VNIC_CLOSED;
2007
2008 if (reset_state == VNIC_CLOSED)
2009 return 0;
2010
2011 rc = __ibmvnic_open(netdev);
Juliet Kimb27507b2019-09-20 16:11:22 -04002012 if (rc)
2013 return IBMVNIC_OPEN_FAILED;
Thomas Falcon2770a792018-05-23 13:38:02 -05002014
Thomas Falcon2770a792018-05-23 13:38:02 -05002015 return 0;
2016}
2017
Nathan Fontenoted651a12017-05-03 14:04:38 -04002018static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter)
2019{
2020 struct ibmvnic_rwi *rwi;
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002021 unsigned long flags;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002022
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002023 spin_lock_irqsave(&adapter->rwi_lock, flags);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002024
2025 if (!list_empty(&adapter->rwi_list)) {
2026 rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi,
2027 list);
2028 list_del(&rwi->list);
2029 } else {
2030 rwi = NULL;
2031 }
2032
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002033 spin_unlock_irqrestore(&adapter->rwi_lock, flags);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002034 return rwi;
2035}
2036
2037static void free_all_rwi(struct ibmvnic_adapter *adapter)
2038{
2039 struct ibmvnic_rwi *rwi;
2040
2041 rwi = get_next_rwi(adapter);
2042 while (rwi) {
2043 kfree(rwi);
2044 rwi = get_next_rwi(adapter);
2045 }
2046}
2047
2048static void __ibmvnic_reset(struct work_struct *work)
2049{
2050 struct ibmvnic_rwi *rwi;
2051 struct ibmvnic_adapter *adapter;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002052 u32 reset_state;
John Allenc26eba02017-10-26 16:23:25 -05002053 int rc = 0;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002054
2055 adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002056
Juliet Kim7ed5b312019-09-20 16:11:23 -04002057 if (test_and_set_bit_lock(0, &adapter->resetting)) {
2058 schedule_delayed_work(&adapter->ibmvnic_delayed_reset,
2059 IBMVNIC_RESET_DELAY);
2060 return;
2061 }
2062
Nathan Fontenoted651a12017-05-03 14:04:38 -04002063 reset_state = adapter->state;
2064
2065 rwi = get_next_rwi(adapter);
2066 while (rwi) {
Thomas Falcon36f10312019-08-27 11:10:04 -05002067 if (adapter->state == VNIC_REMOVING ||
Michal Suchanekc8dc5592019-09-09 22:44:51 +02002068 adapter->state == VNIC_REMOVED) {
Juliet Kim1c2977c2019-09-05 17:30:01 -04002069 kfree(rwi);
2070 rc = EBUSY;
2071 break;
2072 }
Thomas Falcon36f10312019-08-27 11:10:04 -05002073
Juliet Kimb27507b2019-09-20 16:11:22 -04002074 if (rwi->reset_reason == VNIC_RESET_CHANGE_PARAM) {
2075 /* CHANGE_PARAM requestor holds rtnl_lock */
2076 rc = do_change_param_reset(adapter, rwi, reset_state);
2077 } else if (adapter->force_reset_recovery) {
2078 /* Transport event occurred during previous reset */
2079 if (adapter->wait_for_reset) {
2080 /* Previous was CHANGE_PARAM; caller locked */
2081 adapter->force_reset_recovery = false;
2082 rc = do_hard_reset(adapter, rwi, reset_state);
2083 } else {
2084 rtnl_lock();
2085 adapter->force_reset_recovery = false;
2086 rc = do_hard_reset(adapter, rwi, reset_state);
2087 rtnl_unlock();
2088 }
Thomas Falcon2770a792018-05-23 13:38:02 -05002089 } else {
2090 rc = do_reset(adapter, rwi, reset_state);
2091 }
Nathan Fontenoted651a12017-05-03 14:04:38 -04002092 kfree(rwi);
Juliet Kimb27507b2019-09-20 16:11:22 -04002093 if (rc == IBMVNIC_OPEN_FAILED) {
2094 if (list_empty(&adapter->rwi_list))
2095 adapter->state = VNIC_CLOSED;
2096 else
2097 adapter->state = reset_state;
2098 rc = 0;
2099 } else if (rc && rc != IBMVNIC_INIT_FAILED &&
Thomas Falcon2770a792018-05-23 13:38:02 -05002100 !adapter->force_reset_recovery)
Nathan Fontenoted651a12017-05-03 14:04:38 -04002101 break;
2102
2103 rwi = get_next_rwi(adapter);
Juliet Kim7ed5b312019-09-20 16:11:23 -04002104
2105 if (rwi && (rwi->reset_reason == VNIC_RESET_FAILOVER ||
2106 rwi->reset_reason == VNIC_RESET_MOBILITY))
2107 adapter->force_reset_recovery = true;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002108 }
2109
John Allenc26eba02017-10-26 16:23:25 -05002110 if (adapter->wait_for_reset) {
John Allenc26eba02017-10-26 16:23:25 -05002111 adapter->reset_done_rc = rc;
2112 complete(&adapter->reset_done);
2113 }
2114
Nathan Fontenoted651a12017-05-03 14:04:38 -04002115 if (rc) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002116 netdev_dbg(adapter->netdev, "Reset failed\n");
Nathan Fontenoted651a12017-05-03 14:04:38 -04002117 free_all_rwi(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002118 }
Juliet Kim1c2977c2019-09-05 17:30:01 -04002119
Juliet Kim7ed5b312019-09-20 16:11:23 -04002120 clear_bit_unlock(0, &adapter->resetting);
2121}
2122
2123static void __ibmvnic_delayed_reset(struct work_struct *work)
2124{
2125 struct ibmvnic_adapter *adapter;
2126
2127 adapter = container_of(work, struct ibmvnic_adapter,
2128 ibmvnic_delayed_reset.work);
2129 __ibmvnic_reset(&adapter->ibmvnic_reset);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002130}
2131
Thomas Falconaf894d22018-04-06 18:37:04 -05002132static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
2133 enum ibmvnic_reset_reason reason)
Nathan Fontenoted651a12017-05-03 14:04:38 -04002134{
Thomas Falcon2770a792018-05-23 13:38:02 -05002135 struct list_head *entry, *tmp_entry;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002136 struct ibmvnic_rwi *rwi, *tmp;
2137 struct net_device *netdev = adapter->netdev;
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002138 unsigned long flags;
Thomas Falconaf894d22018-04-06 18:37:04 -05002139 int ret;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002140
2141 if (adapter->state == VNIC_REMOVING ||
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05002142 adapter->state == VNIC_REMOVED ||
2143 adapter->failover_pending) {
Thomas Falconaf894d22018-04-06 18:37:04 -05002144 ret = EBUSY;
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05002145 netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n");
Thomas Falconaf894d22018-04-06 18:37:04 -05002146 goto err;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002147 }
2148
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04002149 if (adapter->state == VNIC_PROBING) {
2150 netdev_warn(netdev, "Adapter reset during probe\n");
Thomas Falconaf894d22018-04-06 18:37:04 -05002151 ret = adapter->init_done_rc = EAGAIN;
2152 goto err;
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04002153 }
2154
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002155 spin_lock_irqsave(&adapter->rwi_lock, flags);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002156
2157 list_for_each(entry, &adapter->rwi_list) {
2158 tmp = list_entry(entry, struct ibmvnic_rwi, list);
2159 if (tmp->reset_reason == reason) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002160 netdev_dbg(netdev, "Skipping matching reset\n");
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002161 spin_unlock_irqrestore(&adapter->rwi_lock, flags);
Thomas Falconaf894d22018-04-06 18:37:04 -05002162 ret = EBUSY;
2163 goto err;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002164 }
2165 }
2166
Thomas Falcon1d1bbc32018-12-10 15:22:23 -06002167 rwi = kzalloc(sizeof(*rwi), GFP_ATOMIC);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002168 if (!rwi) {
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002169 spin_unlock_irqrestore(&adapter->rwi_lock, flags);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002170 ibmvnic_close(netdev);
Thomas Falconaf894d22018-04-06 18:37:04 -05002171 ret = ENOMEM;
2172 goto err;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002173 }
Thomas Falcon2770a792018-05-23 13:38:02 -05002174 /* if we just received a transport event,
2175 * flush reset queue and process this reset
2176 */
2177 if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) {
2178 list_for_each_safe(entry, tmp_entry, &adapter->rwi_list)
2179 list_del(entry);
2180 }
Nathan Fontenoted651a12017-05-03 14:04:38 -04002181 rwi->reset_reason = reason;
2182 list_add_tail(&rwi->list, &adapter->rwi_list);
Thomas Falcon6c5c7482018-12-10 15:22:22 -06002183 spin_unlock_irqrestore(&adapter->rwi_lock, flags);
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002184 netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002185 schedule_work(&adapter->ibmvnic_reset);
Thomas Falconaf894d22018-04-06 18:37:04 -05002186
2187 return 0;
2188err:
Thomas Falconaf894d22018-04-06 18:37:04 -05002189 return -ret;
Nathan Fontenoted651a12017-05-03 14:04:38 -04002190}
2191
Thomas Falcon032c5e82015-12-21 11:26:06 -06002192static void ibmvnic_tx_timeout(struct net_device *dev)
2193{
2194 struct ibmvnic_adapter *adapter = netdev_priv(dev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002195
Nathan Fontenoted651a12017-05-03 14:04:38 -04002196 ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002197}
2198
2199static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
2200 struct ibmvnic_rx_buff *rx_buff)
2201{
2202 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
2203
2204 rx_buff->skb = NULL;
2205
2206 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
2207 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
2208
2209 atomic_dec(&pool->available);
2210}
2211
2212static int ibmvnic_poll(struct napi_struct *napi, int budget)
2213{
2214 struct net_device *netdev = napi->dev;
2215 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2216 int scrq_num = (int)(napi - adapter->napi);
2217 int frames_processed = 0;
Nathan Fontenot152ce472017-05-26 10:30:54 -04002218
Thomas Falcon032c5e82015-12-21 11:26:06 -06002219restart_poll:
2220 while (frames_processed < budget) {
2221 struct sk_buff *skb;
2222 struct ibmvnic_rx_buff *rx_buff;
2223 union sub_crq *next;
2224 u32 length;
2225 u16 offset;
2226 u8 flags = 0;
2227
Juliet Kim7ed5b312019-09-20 16:11:23 -04002228 if (unlikely(test_bit(0, &adapter->resetting) &&
John Allen34686562018-02-06 16:21:49 -06002229 adapter->reset_reason != VNIC_RESET_NON_FATAL)) {
Thomas Falcon21ecba62017-06-14 23:50:09 -05002230 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
2231 napi_complete_done(napi, frames_processed);
2232 return frames_processed;
2233 }
2234
Thomas Falcon032c5e82015-12-21 11:26:06 -06002235 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
2236 break;
2237 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
2238 rx_buff =
2239 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
2240 rx_comp.correlator);
2241 /* do error checking */
2242 if (next->rx_comp.rc) {
John Allene1cea2e2017-08-07 15:42:30 -05002243 netdev_dbg(netdev, "rx buffer returned with rc %x\n",
2244 be16_to_cpu(next->rx_comp.rc));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002245 /* free the entry */
2246 next->rx_comp.first = 0;
Thomas Falcon4b9b0f02018-02-13 18:23:42 -06002247 dev_kfree_skb_any(rx_buff->skb);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002248 remove_buff_from_pool(adapter, rx_buff);
Nathan Fontenotca05e312017-05-03 14:05:14 -04002249 continue;
Thomas Falconabe27a82018-02-19 20:12:57 -06002250 } else if (!rx_buff->skb) {
2251 /* free the entry */
2252 next->rx_comp.first = 0;
2253 remove_buff_from_pool(adapter, rx_buff);
2254 continue;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002255 }
2256
2257 length = be32_to_cpu(next->rx_comp.len);
2258 offset = be16_to_cpu(next->rx_comp.off_frame_data);
2259 flags = next->rx_comp.flags;
2260 skb = rx_buff->skb;
2261 skb_copy_to_linear_data(skb, rx_buff->data + offset,
2262 length);
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04002263
2264 /* VLAN Header has been stripped by the system firmware and
2265 * needs to be inserted by the driver
2266 */
2267 if (adapter->rx_vlan_header_insertion &&
2268 (flags & IBMVNIC_VLAN_STRIPPED))
2269 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2270 ntohs(next->rx_comp.vlan_tci));
2271
Thomas Falcon032c5e82015-12-21 11:26:06 -06002272 /* free the entry */
2273 next->rx_comp.first = 0;
2274 remove_buff_from_pool(adapter, rx_buff);
2275
2276 skb_put(skb, length);
2277 skb->protocol = eth_type_trans(skb, netdev);
Thomas Falcon94ca3052017-05-03 14:05:20 -04002278 skb_record_rx_queue(skb, scrq_num);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002279
2280 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
2281 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
2282 skb->ip_summed = CHECKSUM_UNNECESSARY;
2283 }
2284
2285 length = skb->len;
2286 napi_gro_receive(napi, skb); /* send it up */
2287 netdev->stats.rx_packets++;
2288 netdev->stats.rx_bytes += length;
John Allen3d52b592017-08-02 16:44:14 -05002289 adapter->rx_stats_buffers[scrq_num].packets++;
2290 adapter->rx_stats_buffers[scrq_num].bytes += length;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002291 frames_processed++;
2292 }
Nathan Fontenot152ce472017-05-26 10:30:54 -04002293
2294 if (adapter->state != VNIC_CLOSING)
2295 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002296
2297 if (frames_processed < budget) {
2298 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08002299 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002300 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
2301 napi_reschedule(napi)) {
2302 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
2303 goto restart_poll;
2304 }
2305 }
2306 return frames_processed;
2307}
2308
John Allenc26eba02017-10-26 16:23:25 -05002309static int wait_for_reset(struct ibmvnic_adapter *adapter)
2310{
Thomas Falconaf894d22018-04-06 18:37:04 -05002311 int rc, ret;
2312
John Allenc26eba02017-10-26 16:23:25 -05002313 adapter->fallback.mtu = adapter->req_mtu;
2314 adapter->fallback.rx_queues = adapter->req_rx_queues;
2315 adapter->fallback.tx_queues = adapter->req_tx_queues;
2316 adapter->fallback.rx_entries = adapter->req_rx_add_entries_per_subcrq;
2317 adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq;
2318
Thomas Falcon070eca92019-11-25 17:12:53 -06002319 reinit_completion(&adapter->reset_done);
John Allenc26eba02017-10-26 16:23:25 -05002320 adapter->wait_for_reset = true;
Thomas Falconaf894d22018-04-06 18:37:04 -05002321 rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM);
2322 if (rc)
2323 return rc;
John Allenc26eba02017-10-26 16:23:25 -05002324 wait_for_completion(&adapter->reset_done);
2325
Thomas Falconaf894d22018-04-06 18:37:04 -05002326 ret = 0;
John Allenc26eba02017-10-26 16:23:25 -05002327 if (adapter->reset_done_rc) {
Thomas Falconaf894d22018-04-06 18:37:04 -05002328 ret = -EIO;
John Allenc26eba02017-10-26 16:23:25 -05002329 adapter->desired.mtu = adapter->fallback.mtu;
2330 adapter->desired.rx_queues = adapter->fallback.rx_queues;
2331 adapter->desired.tx_queues = adapter->fallback.tx_queues;
2332 adapter->desired.rx_entries = adapter->fallback.rx_entries;
2333 adapter->desired.tx_entries = adapter->fallback.tx_entries;
2334
Thomas Falcon070eca92019-11-25 17:12:53 -06002335 reinit_completion(&adapter->reset_done);
Thomas Falconaf894d22018-04-06 18:37:04 -05002336 adapter->wait_for_reset = true;
2337 rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM);
2338 if (rc)
2339 return ret;
John Allenc26eba02017-10-26 16:23:25 -05002340 wait_for_completion(&adapter->reset_done);
2341 }
2342 adapter->wait_for_reset = false;
2343
Thomas Falconaf894d22018-04-06 18:37:04 -05002344 return ret;
John Allenc26eba02017-10-26 16:23:25 -05002345}
2346
John Allen3a807b72017-06-06 16:55:52 -05002347static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu)
2348{
John Allenc26eba02017-10-26 16:23:25 -05002349 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2350
2351 adapter->desired.mtu = new_mtu + ETH_HLEN;
2352
2353 return wait_for_reset(adapter);
John Allen3a807b72017-06-06 16:55:52 -05002354}
2355
Thomas Falconf10b09e2018-03-12 11:51:05 -05002356static netdev_features_t ibmvnic_features_check(struct sk_buff *skb,
2357 struct net_device *dev,
2358 netdev_features_t features)
2359{
2360 /* Some backing hardware adapters can not
2361 * handle packets with a MSS less than 224
2362 * or with only one segment.
2363 */
2364 if (skb_is_gso(skb)) {
2365 if (skb_shinfo(skb)->gso_size < 224 ||
2366 skb_shinfo(skb)->gso_segs == 1)
2367 features &= ~NETIF_F_GSO_MASK;
2368 }
2369
2370 return features;
2371}
2372
Thomas Falcon032c5e82015-12-21 11:26:06 -06002373static const struct net_device_ops ibmvnic_netdev_ops = {
2374 .ndo_open = ibmvnic_open,
2375 .ndo_stop = ibmvnic_close,
2376 .ndo_start_xmit = ibmvnic_xmit,
2377 .ndo_set_rx_mode = ibmvnic_set_multi,
2378 .ndo_set_mac_address = ibmvnic_set_mac,
2379 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06002380 .ndo_tx_timeout = ibmvnic_tx_timeout,
John Allen3a807b72017-06-06 16:55:52 -05002381 .ndo_change_mtu = ibmvnic_change_mtu,
Thomas Falconf10b09e2018-03-12 11:51:05 -05002382 .ndo_features_check = ibmvnic_features_check,
Thomas Falcon032c5e82015-12-21 11:26:06 -06002383};
2384
2385/* ethtool functions */
2386
Philippe Reynes8a433792017-01-07 22:37:29 +01002387static int ibmvnic_get_link_ksettings(struct net_device *netdev,
2388 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002389{
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03002390 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2391 int rc;
Philippe Reynes8a433792017-01-07 22:37:29 +01002392
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03002393 rc = send_query_phys_parms(adapter);
2394 if (rc) {
2395 adapter->speed = SPEED_UNKNOWN;
2396 adapter->duplex = DUPLEX_UNKNOWN;
2397 }
2398 cmd->base.speed = adapter->speed;
2399 cmd->base.duplex = adapter->duplex;
Philippe Reynes8a433792017-01-07 22:37:29 +01002400 cmd->base.port = PORT_FIBRE;
2401 cmd->base.phy_address = 0;
2402 cmd->base.autoneg = AUTONEG_ENABLE;
2403
Thomas Falcon032c5e82015-12-21 11:26:06 -06002404 return 0;
2405}
2406
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02002407static void ibmvnic_get_drvinfo(struct net_device *netdev,
Thomas Falcon032c5e82015-12-21 11:26:06 -06002408 struct ethtool_drvinfo *info)
2409{
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02002410 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2411
Thomas Falcon032c5e82015-12-21 11:26:06 -06002412 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
2413 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02002414 strlcpy(info->fw_version, adapter->fw_version,
2415 sizeof(info->fw_version));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002416}
2417
2418static u32 ibmvnic_get_msglevel(struct net_device *netdev)
2419{
2420 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2421
2422 return adapter->msg_enable;
2423}
2424
2425static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
2426{
2427 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2428
2429 adapter->msg_enable = data;
2430}
2431
2432static u32 ibmvnic_get_link(struct net_device *netdev)
2433{
2434 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2435
2436 /* Don't need to send a query because we request a logical link up at
2437 * init and then we wait for link state indications
2438 */
2439 return adapter->logical_link_state;
2440}
2441
2442static void ibmvnic_get_ringparam(struct net_device *netdev,
2443 struct ethtool_ringparam *ring)
2444{
John Allenbc131b32017-08-02 16:46:30 -05002445 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2446
Thomas Falcon723ad912018-09-28 18:38:26 -05002447 if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) {
2448 ring->rx_max_pending = adapter->max_rx_add_entries_per_subcrq;
2449 ring->tx_max_pending = adapter->max_tx_entries_per_subcrq;
2450 } else {
2451 ring->rx_max_pending = IBMVNIC_MAX_QUEUE_SZ;
2452 ring->tx_max_pending = IBMVNIC_MAX_QUEUE_SZ;
2453 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002454 ring->rx_mini_max_pending = 0;
2455 ring->rx_jumbo_max_pending = 0;
John Allenbc131b32017-08-02 16:46:30 -05002456 ring->rx_pending = adapter->req_rx_add_entries_per_subcrq;
2457 ring->tx_pending = adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002458 ring->rx_mini_pending = 0;
2459 ring->rx_jumbo_pending = 0;
2460}
2461
John Allenc26eba02017-10-26 16:23:25 -05002462static int ibmvnic_set_ringparam(struct net_device *netdev,
2463 struct ethtool_ringparam *ring)
2464{
2465 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon723ad912018-09-28 18:38:26 -05002466 int ret;
John Allenc26eba02017-10-26 16:23:25 -05002467
Thomas Falcon723ad912018-09-28 18:38:26 -05002468 ret = 0;
John Allenc26eba02017-10-26 16:23:25 -05002469 adapter->desired.rx_entries = ring->rx_pending;
2470 adapter->desired.tx_entries = ring->tx_pending;
2471
Thomas Falcon723ad912018-09-28 18:38:26 -05002472 ret = wait_for_reset(adapter);
2473
2474 if (!ret &&
2475 (adapter->req_rx_add_entries_per_subcrq != ring->rx_pending ||
2476 adapter->req_tx_entries_per_subcrq != ring->tx_pending))
2477 netdev_info(netdev,
2478 "Could not match full ringsize request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n",
2479 ring->rx_pending, ring->tx_pending,
2480 adapter->req_rx_add_entries_per_subcrq,
2481 adapter->req_tx_entries_per_subcrq);
2482 return ret;
John Allenc26eba02017-10-26 16:23:25 -05002483}
2484
John Allenc2dbeb62017-08-02 16:47:17 -05002485static void ibmvnic_get_channels(struct net_device *netdev,
2486 struct ethtool_channels *channels)
2487{
2488 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2489
Thomas Falcon723ad912018-09-28 18:38:26 -05002490 if (adapter->priv_flags & IBMVNIC_USE_SERVER_MAXES) {
2491 channels->max_rx = adapter->max_rx_queues;
2492 channels->max_tx = adapter->max_tx_queues;
2493 } else {
2494 channels->max_rx = IBMVNIC_MAX_QUEUES;
2495 channels->max_tx = IBMVNIC_MAX_QUEUES;
2496 }
2497
John Allenc2dbeb62017-08-02 16:47:17 -05002498 channels->max_other = 0;
2499 channels->max_combined = 0;
2500 channels->rx_count = adapter->req_rx_queues;
2501 channels->tx_count = adapter->req_tx_queues;
2502 channels->other_count = 0;
2503 channels->combined_count = 0;
2504}
2505
John Allenc26eba02017-10-26 16:23:25 -05002506static int ibmvnic_set_channels(struct net_device *netdev,
2507 struct ethtool_channels *channels)
2508{
2509 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon723ad912018-09-28 18:38:26 -05002510 int ret;
John Allenc26eba02017-10-26 16:23:25 -05002511
Thomas Falcon723ad912018-09-28 18:38:26 -05002512 ret = 0;
John Allenc26eba02017-10-26 16:23:25 -05002513 adapter->desired.rx_queues = channels->rx_count;
2514 adapter->desired.tx_queues = channels->tx_count;
2515
Thomas Falcon723ad912018-09-28 18:38:26 -05002516 ret = wait_for_reset(adapter);
2517
2518 if (!ret &&
2519 (adapter->req_rx_queues != channels->rx_count ||
2520 adapter->req_tx_queues != channels->tx_count))
2521 netdev_info(netdev,
2522 "Could not match full channels request. Requested: RX %d, TX %d; Allowed: RX %llu, TX %llu\n",
2523 channels->rx_count, channels->tx_count,
2524 adapter->req_rx_queues, adapter->req_tx_queues);
2525 return ret;
2526
John Allenc26eba02017-10-26 16:23:25 -05002527}
2528
Thomas Falcon032c5e82015-12-21 11:26:06 -06002529static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
2530{
John Allen3d52b592017-08-02 16:44:14 -05002531 struct ibmvnic_adapter *adapter = netdev_priv(dev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002532 int i;
2533
Thomas Falcon723ad912018-09-28 18:38:26 -05002534 switch (stringset) {
2535 case ETH_SS_STATS:
2536 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats);
2537 i++, data += ETH_GSTRING_LEN)
2538 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
2539
2540 for (i = 0; i < adapter->req_tx_queues; i++) {
2541 snprintf(data, ETH_GSTRING_LEN, "tx%d_packets", i);
2542 data += ETH_GSTRING_LEN;
2543
2544 snprintf(data, ETH_GSTRING_LEN, "tx%d_bytes", i);
2545 data += ETH_GSTRING_LEN;
2546
2547 snprintf(data, ETH_GSTRING_LEN,
2548 "tx%d_dropped_packets", i);
2549 data += ETH_GSTRING_LEN;
2550 }
2551
2552 for (i = 0; i < adapter->req_rx_queues; i++) {
2553 snprintf(data, ETH_GSTRING_LEN, "rx%d_packets", i);
2554 data += ETH_GSTRING_LEN;
2555
2556 snprintf(data, ETH_GSTRING_LEN, "rx%d_bytes", i);
2557 data += ETH_GSTRING_LEN;
2558
2559 snprintf(data, ETH_GSTRING_LEN, "rx%d_interrupts", i);
2560 data += ETH_GSTRING_LEN;
2561 }
2562 break;
2563
2564 case ETH_SS_PRIV_FLAGS:
2565 for (i = 0; i < ARRAY_SIZE(ibmvnic_priv_flags); i++)
2566 strcpy(data + i * ETH_GSTRING_LEN,
2567 ibmvnic_priv_flags[i]);
2568 break;
2569 default:
Thomas Falcon032c5e82015-12-21 11:26:06 -06002570 return;
John Allen3d52b592017-08-02 16:44:14 -05002571 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002572}
2573
2574static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
2575{
John Allen3d52b592017-08-02 16:44:14 -05002576 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2577
Thomas Falcon032c5e82015-12-21 11:26:06 -06002578 switch (sset) {
2579 case ETH_SS_STATS:
John Allen3d52b592017-08-02 16:44:14 -05002580 return ARRAY_SIZE(ibmvnic_stats) +
2581 adapter->req_tx_queues * NUM_TX_STATS +
2582 adapter->req_rx_queues * NUM_RX_STATS;
Thomas Falcon723ad912018-09-28 18:38:26 -05002583 case ETH_SS_PRIV_FLAGS:
2584 return ARRAY_SIZE(ibmvnic_priv_flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002585 default:
2586 return -EOPNOTSUPP;
2587 }
2588}
2589
2590static void ibmvnic_get_ethtool_stats(struct net_device *dev,
2591 struct ethtool_stats *stats, u64 *data)
2592{
2593 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2594 union ibmvnic_crq crq;
John Allen3d52b592017-08-02 16:44:14 -05002595 int i, j;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05002596 int rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002597
2598 memset(&crq, 0, sizeof(crq));
2599 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
2600 crq.request_statistics.cmd = REQUEST_STATISTICS;
2601 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
2602 crq.request_statistics.len =
2603 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002604
2605 /* Wait for data to be written */
Thomas Falcon070eca92019-11-25 17:12:53 -06002606 reinit_completion(&adapter->stats_done);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05002607 rc = ibmvnic_send_crq(adapter, &crq);
2608 if (rc)
2609 return;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002610 wait_for_completion(&adapter->stats_done);
2611
2612 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
John Allen52da5c12017-08-02 16:45:28 -05002613 data[i] = be64_to_cpu(IBMVNIC_GET_STAT(adapter,
2614 ibmvnic_stats[i].offset));
John Allen3d52b592017-08-02 16:44:14 -05002615
2616 for (j = 0; j < adapter->req_tx_queues; j++) {
2617 data[i] = adapter->tx_stats_buffers[j].packets;
2618 i++;
2619 data[i] = adapter->tx_stats_buffers[j].bytes;
2620 i++;
2621 data[i] = adapter->tx_stats_buffers[j].dropped_packets;
2622 i++;
2623 }
2624
2625 for (j = 0; j < adapter->req_rx_queues; j++) {
2626 data[i] = adapter->rx_stats_buffers[j].packets;
2627 i++;
2628 data[i] = adapter->rx_stats_buffers[j].bytes;
2629 i++;
2630 data[i] = adapter->rx_stats_buffers[j].interrupts;
2631 i++;
2632 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002633}
2634
Thomas Falcon723ad912018-09-28 18:38:26 -05002635static u32 ibmvnic_get_priv_flags(struct net_device *netdev)
2636{
2637 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2638
2639 return adapter->priv_flags;
2640}
2641
2642static int ibmvnic_set_priv_flags(struct net_device *netdev, u32 flags)
2643{
2644 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2645 bool which_maxes = !!(flags & IBMVNIC_USE_SERVER_MAXES);
2646
2647 if (which_maxes)
2648 adapter->priv_flags |= IBMVNIC_USE_SERVER_MAXES;
2649 else
2650 adapter->priv_flags &= ~IBMVNIC_USE_SERVER_MAXES;
2651
2652 return 0;
2653}
Thomas Falcon032c5e82015-12-21 11:26:06 -06002654static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002655 .get_drvinfo = ibmvnic_get_drvinfo,
2656 .get_msglevel = ibmvnic_get_msglevel,
2657 .set_msglevel = ibmvnic_set_msglevel,
2658 .get_link = ibmvnic_get_link,
2659 .get_ringparam = ibmvnic_get_ringparam,
John Allenc26eba02017-10-26 16:23:25 -05002660 .set_ringparam = ibmvnic_set_ringparam,
John Allenc2dbeb62017-08-02 16:47:17 -05002661 .get_channels = ibmvnic_get_channels,
John Allenc26eba02017-10-26 16:23:25 -05002662 .set_channels = ibmvnic_set_channels,
Thomas Falcon032c5e82015-12-21 11:26:06 -06002663 .get_strings = ibmvnic_get_strings,
2664 .get_sset_count = ibmvnic_get_sset_count,
2665 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01002666 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon723ad912018-09-28 18:38:26 -05002667 .get_priv_flags = ibmvnic_get_priv_flags,
2668 .set_priv_flags = ibmvnic_set_priv_flags,
Thomas Falcon032c5e82015-12-21 11:26:06 -06002669};
2670
2671/* Routines for managing CRQs/sCRQs */
2672
Nathan Fontenot57a49432017-05-26 10:31:12 -04002673static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter,
2674 struct ibmvnic_sub_crq_queue *scrq)
2675{
2676 int rc;
2677
2678 if (scrq->irq) {
2679 free_irq(scrq->irq, scrq);
2680 irq_dispose_mapping(scrq->irq);
2681 scrq->irq = 0;
2682 }
2683
Thomas Falconc8b2ad02017-06-14 23:50:07 -05002684 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
Thomas Falcon41f71462018-04-06 18:37:03 -05002685 atomic_set(&scrq->used, 0);
Nathan Fontenot57a49432017-05-26 10:31:12 -04002686 scrq->cur = 0;
2687
2688 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
2689 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
2690 return rc;
2691}
2692
2693static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter)
2694{
2695 int i, rc;
2696
2697 for (i = 0; i < adapter->req_tx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002698 netdev_dbg(adapter->netdev, "Re-setting tx_scrq[%d]\n", i);
Nathan Fontenot57a49432017-05-26 10:31:12 -04002699 rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]);
2700 if (rc)
2701 return rc;
2702 }
2703
2704 for (i = 0; i < adapter->req_rx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002705 netdev_dbg(adapter->netdev, "Re-setting rx_scrq[%d]\n", i);
Nathan Fontenot57a49432017-05-26 10:31:12 -04002706 rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]);
2707 if (rc)
2708 return rc;
2709 }
2710
Nathan Fontenot57a49432017-05-26 10:31:12 -04002711 return rc;
2712}
2713
Thomas Falcon032c5e82015-12-21 11:26:06 -06002714static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002715 struct ibmvnic_sub_crq_queue *scrq,
2716 bool do_h_free)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002717{
2718 struct device *dev = &adapter->vdev->dev;
2719 long rc;
2720
2721 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
2722
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002723 if (do_h_free) {
2724 /* Close the sub-crqs */
2725 do {
2726 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
2727 adapter->vdev->unit_address,
2728 scrq->crq_num);
2729 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002730
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002731 if (rc) {
2732 netdev_err(adapter->netdev,
2733 "Failed to release sub-CRQ %16lx, rc = %ld\n",
2734 scrq->crq_num, rc);
2735 }
Thomas Falconffa73852017-04-19 13:44:29 -04002736 }
2737
Thomas Falcon032c5e82015-12-21 11:26:06 -06002738 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
2739 DMA_BIDIRECTIONAL);
2740 free_pages((unsigned long)scrq->msgs, 2);
2741 kfree(scrq);
2742}
2743
2744static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
2745 *adapter)
2746{
2747 struct device *dev = &adapter->vdev->dev;
2748 struct ibmvnic_sub_crq_queue *scrq;
2749 int rc;
2750
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002751 scrq = kzalloc(sizeof(*scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002752 if (!scrq)
2753 return NULL;
2754
Nathan Fontenot7f7adc52017-04-19 13:45:16 -04002755 scrq->msgs =
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002756 (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002757 if (!scrq->msgs) {
2758 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
2759 goto zero_page_failed;
2760 }
2761
2762 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
2763 DMA_BIDIRECTIONAL);
2764 if (dma_mapping_error(dev, scrq->msg_token)) {
2765 dev_warn(dev, "Couldn't map crq queue messages page\n");
2766 goto map_failed;
2767 }
2768
2769 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
2770 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
2771
2772 if (rc == H_RESOURCE)
2773 rc = ibmvnic_reset_crq(adapter);
2774
2775 if (rc == H_CLOSED) {
2776 dev_warn(dev, "Partner adapter not ready, waiting.\n");
2777 } else if (rc) {
2778 dev_warn(dev, "Error %d registering sub-crq\n", rc);
2779 goto reg_failed;
2780 }
2781
Thomas Falcon032c5e82015-12-21 11:26:06 -06002782 scrq->adapter = adapter;
2783 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002784 spin_lock_init(&scrq->lock);
2785
2786 netdev_dbg(adapter->netdev,
2787 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
2788 scrq->crq_num, scrq->hw_irq, scrq->irq);
2789
2790 return scrq;
2791
Thomas Falcon032c5e82015-12-21 11:26:06 -06002792reg_failed:
2793 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
2794 DMA_BIDIRECTIONAL);
2795map_failed:
2796 free_pages((unsigned long)scrq->msgs, 2);
2797zero_page_failed:
2798 kfree(scrq);
2799
2800 return NULL;
2801}
2802
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002803static void release_sub_crqs(struct ibmvnic_adapter *adapter, bool do_h_free)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002804{
2805 int i;
2806
2807 if (adapter->tx_scrq) {
Nathan Fontenot82e3be32018-02-21 21:33:56 -06002808 for (i = 0; i < adapter->num_active_tx_scrqs; i++) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04002809 if (!adapter->tx_scrq[i])
2810 continue;
2811
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002812 netdev_dbg(adapter->netdev, "Releasing tx_scrq[%d]\n",
2813 i);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002814 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002815 free_irq(adapter->tx_scrq[i]->irq,
2816 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05002817 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002818 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002819 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04002820
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002821 release_sub_crq_queue(adapter, adapter->tx_scrq[i],
2822 do_h_free);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002823 }
2824
Nathan Fontenot9501df32017-03-15 23:38:07 -04002825 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002826 adapter->tx_scrq = NULL;
Nathan Fontenot82e3be32018-02-21 21:33:56 -06002827 adapter->num_active_tx_scrqs = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002828 }
2829
2830 if (adapter->rx_scrq) {
Nathan Fontenot82e3be32018-02-21 21:33:56 -06002831 for (i = 0; i < adapter->num_active_rx_scrqs; i++) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04002832 if (!adapter->rx_scrq[i])
2833 continue;
2834
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05002835 netdev_dbg(adapter->netdev, "Releasing rx_scrq[%d]\n",
2836 i);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002837 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002838 free_irq(adapter->rx_scrq[i]->irq,
2839 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05002840 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002841 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002842 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04002843
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06002844 release_sub_crq_queue(adapter, adapter->rx_scrq[i],
2845 do_h_free);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002846 }
2847
Nathan Fontenot9501df32017-03-15 23:38:07 -04002848 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002849 adapter->rx_scrq = NULL;
Nathan Fontenot82e3be32018-02-21 21:33:56 -06002850 adapter->num_active_rx_scrqs = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002851 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002852}
2853
2854static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
2855 struct ibmvnic_sub_crq_queue *scrq)
2856{
2857 struct device *dev = &adapter->vdev->dev;
2858 unsigned long rc;
2859
2860 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
2861 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
2862 if (rc)
2863 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
2864 scrq->hw_irq, rc);
2865 return rc;
2866}
2867
2868static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
2869 struct ibmvnic_sub_crq_queue *scrq)
2870{
2871 struct device *dev = &adapter->vdev->dev;
2872 unsigned long rc;
2873
2874 if (scrq->hw_irq > 0x100000000ULL) {
2875 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
2876 return 1;
2877 }
2878
Juliet Kim7ed5b312019-09-20 16:11:23 -04002879 if (test_bit(0, &adapter->resetting) &&
Nathan Fontenot73f9d362018-05-22 11:21:10 -05002880 adapter->reset_reason == VNIC_RESET_MOBILITY) {
Juliet Kim284f87d2019-11-20 10:50:03 -05002881 u64 val = (0xff000000) | scrq->hw_irq;
Nathan Fontenot73f9d362018-05-22 11:21:10 -05002882
Juliet Kim284f87d2019-11-20 10:50:03 -05002883 rc = plpar_hcall_norets(H_EOI, val);
Juliet Kim2df5c602019-11-20 10:50:04 -05002884 /* H_EOI would fail with rc = H_FUNCTION when running
2885 * in XIVE mode which is expected, but not an error.
2886 */
2887 if (rc && (rc != H_FUNCTION))
Juliet Kim284f87d2019-11-20 10:50:03 -05002888 dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",
2889 val, rc);
Nathan Fontenot73f9d362018-05-22 11:21:10 -05002890 }
Thomas Falconf23e0642018-04-15 18:53:36 -05002891
Thomas Falcon032c5e82015-12-21 11:26:06 -06002892 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
2893 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
2894 if (rc)
2895 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
2896 scrq->hw_irq, rc);
2897 return rc;
2898}
2899
2900static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
2901 struct ibmvnic_sub_crq_queue *scrq)
2902{
2903 struct device *dev = &adapter->vdev->dev;
Thomas Falcon06b3e352018-03-16 20:00:28 -05002904 struct ibmvnic_tx_pool *tx_pool;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002905 struct ibmvnic_tx_buff *txbuff;
2906 union sub_crq *next;
2907 int index;
2908 int i, j;
2909
2910restart_loop:
2911 while (pending_scrq(adapter, scrq)) {
2912 unsigned int pool = scrq->pool_index;
Thomas Falconffc385b2018-02-18 10:08:41 -06002913 int num_entries = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002914
2915 next = ibmvnic_next_scrq(adapter, scrq);
2916 for (i = 0; i < next->tx_comp.num_comps; i++) {
2917 if (next->tx_comp.rcs[i]) {
2918 dev_err(dev, "tx error %x\n",
2919 next->tx_comp.rcs[i]);
2920 continue;
2921 }
2922 index = be32_to_cpu(next->tx_comp.correlators[i]);
Thomas Falcon06b3e352018-03-16 20:00:28 -05002923 if (index & IBMVNIC_TSO_POOL_MASK) {
2924 tx_pool = &adapter->tso_pool[pool];
2925 index &= ~IBMVNIC_TSO_POOL_MASK;
2926 } else {
2927 tx_pool = &adapter->tx_pool[pool];
2928 }
2929
2930 txbuff = &tx_pool->tx_buff[index];
Thomas Falcon032c5e82015-12-21 11:26:06 -06002931
2932 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
2933 if (!txbuff->data_dma[j])
2934 continue;
2935
2936 txbuff->data_dma[j] = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002937 }
2938
Thomas Falcon142c0ac2017-03-05 12:18:41 -06002939 if (txbuff->last_frag) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002940 dev_kfree_skb_any(txbuff->skb);
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04002941 txbuff->skb = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06002942 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002943
Thomas Falconffc385b2018-02-18 10:08:41 -06002944 num_entries += txbuff->num_entries;
2945
Thomas Falcon06b3e352018-03-16 20:00:28 -05002946 tx_pool->free_map[tx_pool->producer_index] = index;
2947 tx_pool->producer_index =
2948 (tx_pool->producer_index + 1) %
2949 tx_pool->num_buffers;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002950 }
2951 /* remove tx_comp scrq*/
2952 next->tx_comp.first = 0;
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04002953
Thomas Falconffc385b2018-02-18 10:08:41 -06002954 if (atomic_sub_return(num_entries, &scrq->used) <=
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04002955 (adapter->req_tx_entries_per_subcrq / 2) &&
2956 __netif_subqueue_stopped(adapter->netdev,
2957 scrq->pool_index)) {
2958 netif_wake_subqueue(adapter->netdev, scrq->pool_index);
Thomas Falcon0aecb132018-02-26 18:10:58 -06002959 netdev_dbg(adapter->netdev, "Started queue %d\n",
2960 scrq->pool_index);
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04002961 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002962 }
2963
2964 enable_scrq_irq(adapter, scrq);
2965
2966 if (pending_scrq(adapter, scrq)) {
2967 disable_scrq_irq(adapter, scrq);
2968 goto restart_loop;
2969 }
2970
2971 return 0;
2972}
2973
2974static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
2975{
2976 struct ibmvnic_sub_crq_queue *scrq = instance;
2977 struct ibmvnic_adapter *adapter = scrq->adapter;
2978
2979 disable_scrq_irq(adapter, scrq);
2980 ibmvnic_complete_tx(adapter, scrq);
2981
2982 return IRQ_HANDLED;
2983}
2984
2985static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
2986{
2987 struct ibmvnic_sub_crq_queue *scrq = instance;
2988 struct ibmvnic_adapter *adapter = scrq->adapter;
2989
Nathan Fontenot09fb35e2018-01-10 10:40:09 -06002990 /* When booting a kdump kernel we can hit pending interrupts
2991 * prior to completing driver initialization.
2992 */
2993 if (unlikely(adapter->state != VNIC_OPEN))
2994 return IRQ_NONE;
2995
John Allen3d52b592017-08-02 16:44:14 -05002996 adapter->rx_stats_buffers[scrq->scrq_num].interrupts++;
2997
Thomas Falcon032c5e82015-12-21 11:26:06 -06002998 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
2999 disable_scrq_irq(adapter, scrq);
3000 __napi_schedule(&adapter->napi[scrq->scrq_num]);
3001 }
3002
3003 return IRQ_HANDLED;
3004}
3005
Thomas Falconea22d512016-07-06 15:35:17 -05003006static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
3007{
3008 struct device *dev = &adapter->vdev->dev;
3009 struct ibmvnic_sub_crq_queue *scrq;
3010 int i = 0, j = 0;
3011 int rc = 0;
3012
3013 for (i = 0; i < adapter->req_tx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05003014 netdev_dbg(adapter->netdev, "Initializing tx_scrq[%d] irq\n",
3015 i);
Thomas Falconea22d512016-07-06 15:35:17 -05003016 scrq = adapter->tx_scrq[i];
3017 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
3018
Michael Ellerman99c17902016-09-10 19:59:05 +10003019 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05003020 rc = -EINVAL;
3021 dev_err(dev, "Error mapping irq\n");
3022 goto req_tx_irq_failed;
3023 }
3024
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -03003025 snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-tx%d",
3026 adapter->vdev->unit_address, i);
Thomas Falconea22d512016-07-06 15:35:17 -05003027 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -03003028 0, scrq->name, scrq);
Thomas Falconea22d512016-07-06 15:35:17 -05003029
3030 if (rc) {
3031 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
3032 scrq->irq, rc);
3033 irq_dispose_mapping(scrq->irq);
Nathan Fontenotaf9090c2018-02-20 11:04:18 -06003034 goto req_tx_irq_failed;
Thomas Falconea22d512016-07-06 15:35:17 -05003035 }
3036 }
3037
3038 for (i = 0; i < adapter->req_rx_queues; i++) {
Nathan Fontenotd1cf33d2017-08-08 15:24:05 -05003039 netdev_dbg(adapter->netdev, "Initializing rx_scrq[%d] irq\n",
3040 i);
Thomas Falconea22d512016-07-06 15:35:17 -05003041 scrq = adapter->rx_scrq[i];
3042 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10003043 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05003044 rc = -EINVAL;
3045 dev_err(dev, "Error mapping irq\n");
3046 goto req_rx_irq_failed;
3047 }
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -03003048 snprintf(scrq->name, sizeof(scrq->name), "ibmvnic-%x-rx%d",
3049 adapter->vdev->unit_address, i);
Thomas Falconea22d512016-07-06 15:35:17 -05003050 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -03003051 0, scrq->name, scrq);
Thomas Falconea22d512016-07-06 15:35:17 -05003052 if (rc) {
3053 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
3054 scrq->irq, rc);
3055 irq_dispose_mapping(scrq->irq);
3056 goto req_rx_irq_failed;
3057 }
3058 }
3059 return rc;
3060
3061req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05003062 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05003063 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
3064 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05003065 }
Thomas Falconea22d512016-07-06 15:35:17 -05003066 i = adapter->req_tx_queues;
3067req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05003068 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05003069 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
3070 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05003071 }
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06003072 release_sub_crqs(adapter, 1);
Thomas Falconea22d512016-07-06 15:35:17 -05003073 return rc;
3074}
3075
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003076static int init_sub_crqs(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003077{
3078 struct device *dev = &adapter->vdev->dev;
3079 struct ibmvnic_sub_crq_queue **allqueues;
3080 int registered_queues = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003081 int total_queues;
3082 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05003083 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003084
Thomas Falcon032c5e82015-12-21 11:26:06 -06003085 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
3086
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04003087 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003088 if (!allqueues)
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003089 return -1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003090
3091 for (i = 0; i < total_queues; i++) {
3092 allqueues[i] = init_sub_crq_queue(adapter);
3093 if (!allqueues[i]) {
3094 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
3095 break;
3096 }
3097 registered_queues++;
3098 }
3099
3100 /* Make sure we were able to register the minimum number of queues */
3101 if (registered_queues <
3102 adapter->min_tx_queues + adapter->min_rx_queues) {
3103 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
3104 goto tx_failed;
3105 }
3106
3107 /* Distribute the failed allocated queues*/
3108 for (i = 0; i < total_queues - registered_queues + more ; i++) {
3109 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
3110 switch (i % 3) {
3111 case 0:
3112 if (adapter->req_rx_queues > adapter->min_rx_queues)
3113 adapter->req_rx_queues--;
3114 else
3115 more++;
3116 break;
3117 case 1:
3118 if (adapter->req_tx_queues > adapter->min_tx_queues)
3119 adapter->req_tx_queues--;
3120 else
3121 more++;
3122 break;
3123 }
3124 }
3125
3126 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04003127 sizeof(*adapter->tx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003128 if (!adapter->tx_scrq)
3129 goto tx_failed;
3130
3131 for (i = 0; i < adapter->req_tx_queues; i++) {
3132 adapter->tx_scrq[i] = allqueues[i];
3133 adapter->tx_scrq[i]->pool_index = i;
Nathan Fontenot82e3be32018-02-21 21:33:56 -06003134 adapter->num_active_tx_scrqs++;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003135 }
3136
3137 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04003138 sizeof(*adapter->rx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003139 if (!adapter->rx_scrq)
3140 goto rx_failed;
3141
3142 for (i = 0; i < adapter->req_rx_queues; i++) {
3143 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
3144 adapter->rx_scrq[i]->scrq_num = i;
Nathan Fontenot82e3be32018-02-21 21:33:56 -06003145 adapter->num_active_rx_scrqs++;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003146 }
3147
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003148 kfree(allqueues);
3149 return 0;
3150
3151rx_failed:
3152 kfree(adapter->tx_scrq);
3153 adapter->tx_scrq = NULL;
3154tx_failed:
3155 for (i = 0; i < registered_queues; i++)
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06003156 release_sub_crq_queue(adapter, allqueues[i], 1);
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003157 kfree(allqueues);
3158 return -1;
3159}
3160
3161static void ibmvnic_send_req_caps(struct ibmvnic_adapter *adapter, int retry)
3162{
3163 struct device *dev = &adapter->vdev->dev;
3164 union ibmvnic_crq crq;
John Allenc26eba02017-10-26 16:23:25 -05003165 int max_entries;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003166
3167 if (!retry) {
3168 /* Sub-CRQ entries are 32 byte long */
3169 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
3170
3171 if (adapter->min_tx_entries_per_subcrq > entries_page ||
3172 adapter->min_rx_add_entries_per_subcrq > entries_page) {
3173 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
3174 return;
3175 }
3176
John Allenc26eba02017-10-26 16:23:25 -05003177 if (adapter->desired.mtu)
3178 adapter->req_mtu = adapter->desired.mtu;
3179 else
3180 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003181
John Allenc26eba02017-10-26 16:23:25 -05003182 if (!adapter->desired.tx_entries)
3183 adapter->desired.tx_entries =
3184 adapter->max_tx_entries_per_subcrq;
3185 if (!adapter->desired.rx_entries)
3186 adapter->desired.rx_entries =
3187 adapter->max_rx_add_entries_per_subcrq;
3188
3189 max_entries = IBMVNIC_MAX_LTB_SIZE /
3190 (adapter->req_mtu + IBMVNIC_BUFFER_HLEN);
3191
3192 if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) *
3193 adapter->desired.tx_entries > IBMVNIC_MAX_LTB_SIZE) {
3194 adapter->desired.tx_entries = max_entries;
3195 }
3196
3197 if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) *
3198 adapter->desired.rx_entries > IBMVNIC_MAX_LTB_SIZE) {
3199 adapter->desired.rx_entries = max_entries;
3200 }
3201
3202 if (adapter->desired.tx_entries)
3203 adapter->req_tx_entries_per_subcrq =
3204 adapter->desired.tx_entries;
3205 else
3206 adapter->req_tx_entries_per_subcrq =
3207 adapter->max_tx_entries_per_subcrq;
3208
3209 if (adapter->desired.rx_entries)
3210 adapter->req_rx_add_entries_per_subcrq =
3211 adapter->desired.rx_entries;
3212 else
3213 adapter->req_rx_add_entries_per_subcrq =
3214 adapter->max_rx_add_entries_per_subcrq;
3215
3216 if (adapter->desired.tx_queues)
3217 adapter->req_tx_queues =
3218 adapter->desired.tx_queues;
3219 else
3220 adapter->req_tx_queues =
3221 adapter->opt_tx_comp_sub_queues;
3222
3223 if (adapter->desired.rx_queues)
3224 adapter->req_rx_queues =
3225 adapter->desired.rx_queues;
3226 else
3227 adapter->req_rx_queues =
3228 adapter->opt_rx_comp_queues;
3229
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003230 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003231 }
3232
Thomas Falcon032c5e82015-12-21 11:26:06 -06003233 memset(&crq, 0, sizeof(crq));
3234 crq.request_capability.first = IBMVNIC_CRQ_CMD;
3235 crq.request_capability.cmd = REQUEST_CAPABILITY;
3236
3237 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06003238 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06003239 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003240 ibmvnic_send_crq(adapter, &crq);
3241
3242 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06003243 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06003244 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003245 ibmvnic_send_crq(adapter, &crq);
3246
3247 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06003248 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06003249 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003250 ibmvnic_send_crq(adapter, &crq);
3251
3252 crq.request_capability.capability =
3253 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
3254 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06003255 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06003256 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003257 ibmvnic_send_crq(adapter, &crq);
3258
3259 crq.request_capability.capability =
3260 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
3261 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06003262 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06003263 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003264 ibmvnic_send_crq(adapter, &crq);
3265
3266 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06003267 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06003268 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003269 ibmvnic_send_crq(adapter, &crq);
3270
3271 if (adapter->netdev->flags & IFF_PROMISC) {
3272 if (adapter->promisc_supported) {
3273 crq.request_capability.capability =
3274 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06003275 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06003276 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003277 ibmvnic_send_crq(adapter, &crq);
3278 }
3279 } else {
3280 crq.request_capability.capability =
3281 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06003282 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06003283 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003284 ibmvnic_send_crq(adapter, &crq);
3285 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06003286}
3287
3288static int pending_scrq(struct ibmvnic_adapter *adapter,
3289 struct ibmvnic_sub_crq_queue *scrq)
3290{
3291 union sub_crq *entry = &scrq->msgs[scrq->cur];
3292
Thomas Falcon1cf9cc72017-06-14 23:50:08 -05003293 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003294 return 1;
3295 else
3296 return 0;
3297}
3298
3299static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
3300 struct ibmvnic_sub_crq_queue *scrq)
3301{
3302 union sub_crq *entry;
3303 unsigned long flags;
3304
3305 spin_lock_irqsave(&scrq->lock, flags);
3306 entry = &scrq->msgs[scrq->cur];
3307 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
3308 if (++scrq->cur == scrq->size)
3309 scrq->cur = 0;
3310 } else {
3311 entry = NULL;
3312 }
3313 spin_unlock_irqrestore(&scrq->lock, flags);
3314
3315 return entry;
3316}
3317
3318static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
3319{
3320 struct ibmvnic_crq_queue *queue = &adapter->crq;
3321 union ibmvnic_crq *crq;
3322
3323 crq = &queue->msgs[queue->cur];
3324 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
3325 if (++queue->cur == queue->size)
3326 queue->cur = 0;
3327 } else {
3328 crq = NULL;
3329 }
3330
3331 return crq;
3332}
3333
Thomas Falcon2d14d372018-07-13 12:03:32 -05003334static void print_subcrq_error(struct device *dev, int rc, const char *func)
3335{
3336 switch (rc) {
3337 case H_PARAMETER:
3338 dev_warn_ratelimited(dev,
3339 "%s failed: Send request is malformed or adapter failover pending. (rc=%d)\n",
3340 func, rc);
3341 break;
3342 case H_CLOSED:
3343 dev_warn_ratelimited(dev,
3344 "%s failed: Backing queue closed. Adapter is down or failover pending. (rc=%d)\n",
3345 func, rc);
3346 break;
3347 default:
3348 dev_err_ratelimited(dev, "%s failed: (rc=%d)\n", func, rc);
3349 break;
3350 }
3351}
3352
Thomas Falcon032c5e82015-12-21 11:26:06 -06003353static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
3354 union sub_crq *sub_crq)
3355{
3356 unsigned int ua = adapter->vdev->unit_address;
3357 struct device *dev = &adapter->vdev->dev;
3358 u64 *u64_crq = (u64 *)sub_crq;
3359 int rc;
3360
3361 netdev_dbg(adapter->netdev,
3362 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
3363 (unsigned long int)cpu_to_be64(remote_handle),
3364 (unsigned long int)cpu_to_be64(u64_crq[0]),
3365 (unsigned long int)cpu_to_be64(u64_crq[1]),
3366 (unsigned long int)cpu_to_be64(u64_crq[2]),
3367 (unsigned long int)cpu_to_be64(u64_crq[3]));
3368
3369 /* Make sure the hypervisor sees the complete request */
3370 mb();
3371
3372 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
3373 cpu_to_be64(remote_handle),
3374 cpu_to_be64(u64_crq[0]),
3375 cpu_to_be64(u64_crq[1]),
3376 cpu_to_be64(u64_crq[2]),
3377 cpu_to_be64(u64_crq[3]));
3378
Thomas Falcon2d14d372018-07-13 12:03:32 -05003379 if (rc)
3380 print_subcrq_error(dev, rc, __func__);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003381
3382 return rc;
3383}
3384
Thomas Falconad7775d2016-04-01 17:20:34 -05003385static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
3386 u64 remote_handle, u64 ioba, u64 num_entries)
3387{
3388 unsigned int ua = adapter->vdev->unit_address;
3389 struct device *dev = &adapter->vdev->dev;
3390 int rc;
3391
3392 /* Make sure the hypervisor sees the complete request */
3393 mb();
3394 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
3395 cpu_to_be64(remote_handle),
3396 ioba, num_entries);
3397
Thomas Falcon2d14d372018-07-13 12:03:32 -05003398 if (rc)
3399 print_subcrq_error(dev, rc, __func__);
Thomas Falconad7775d2016-04-01 17:20:34 -05003400
3401 return rc;
3402}
3403
Thomas Falcon032c5e82015-12-21 11:26:06 -06003404static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
3405 union ibmvnic_crq *crq)
3406{
3407 unsigned int ua = adapter->vdev->unit_address;
3408 struct device *dev = &adapter->vdev->dev;
3409 u64 *u64_crq = (u64 *)crq;
3410 int rc;
3411
3412 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
3413 (unsigned long int)cpu_to_be64(u64_crq[0]),
3414 (unsigned long int)cpu_to_be64(u64_crq[1]));
3415
Thomas Falcon51536982018-05-23 13:37:56 -05003416 if (!adapter->crq.active &&
3417 crq->generic.first != IBMVNIC_CRQ_INIT_CMD) {
3418 dev_warn(dev, "Invalid request detected while CRQ is inactive, possible device state change during reset\n");
3419 return -EINVAL;
3420 }
3421
Thomas Falcon032c5e82015-12-21 11:26:06 -06003422 /* Make sure the hypervisor sees the complete request */
3423 mb();
3424
3425 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
3426 cpu_to_be64(u64_crq[0]),
3427 cpu_to_be64(u64_crq[1]));
3428
3429 if (rc) {
Nathan Fontenotec95dff2018-02-07 13:00:24 -06003430 if (rc == H_CLOSED) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06003431 dev_warn(dev, "CRQ Queue closed\n");
Juliet Kim7ed5b312019-09-20 16:11:23 -04003432 if (test_bit(0, &adapter->resetting))
Nathan Fontenotec95dff2018-02-07 13:00:24 -06003433 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
3434 }
3435
Thomas Falcon032c5e82015-12-21 11:26:06 -06003436 dev_warn(dev, "Send error (rc=%d)\n", rc);
3437 }
3438
3439 return rc;
3440}
3441
3442static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
3443{
3444 union ibmvnic_crq crq;
3445
3446 memset(&crq, 0, sizeof(crq));
3447 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
3448 crq.generic.cmd = IBMVNIC_CRQ_INIT;
3449 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
3450
3451 return ibmvnic_send_crq(adapter, &crq);
3452}
3453
Thomas Falcon032c5e82015-12-21 11:26:06 -06003454static int send_version_xchg(struct ibmvnic_adapter *adapter)
3455{
3456 union ibmvnic_crq crq;
3457
3458 memset(&crq, 0, sizeof(crq));
3459 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
3460 crq.version_exchange.cmd = VERSION_EXCHANGE;
3461 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
3462
3463 return ibmvnic_send_crq(adapter, &crq);
3464}
3465
Nathan Fontenot37798d02017-11-08 11:23:56 -06003466struct vnic_login_client_data {
3467 u8 type;
3468 __be16 len;
Kees Cook08ea5562018-04-10 15:26:43 -07003469 char name[];
Nathan Fontenot37798d02017-11-08 11:23:56 -06003470} __packed;
3471
3472static int vnic_client_data_len(struct ibmvnic_adapter *adapter)
3473{
3474 int len;
3475
3476 /* Calculate the amount of buffer space needed for the
3477 * vnic client data in the login buffer. There are four entries,
3478 * OS name, LPAR name, device name, and a null last entry.
3479 */
3480 len = 4 * sizeof(struct vnic_login_client_data);
3481 len += 6; /* "Linux" plus NULL */
3482 len += strlen(utsname()->nodename) + 1;
3483 len += strlen(adapter->netdev->name) + 1;
3484
3485 return len;
3486}
3487
3488static void vnic_add_client_data(struct ibmvnic_adapter *adapter,
3489 struct vnic_login_client_data *vlcd)
3490{
3491 const char *os_name = "Linux";
3492 int len;
3493
3494 /* Type 1 - LPAR OS */
3495 vlcd->type = 1;
3496 len = strlen(os_name) + 1;
3497 vlcd->len = cpu_to_be16(len);
Kees Cook08ea5562018-04-10 15:26:43 -07003498 strncpy(vlcd->name, os_name, len);
3499 vlcd = (struct vnic_login_client_data *)(vlcd->name + len);
Nathan Fontenot37798d02017-11-08 11:23:56 -06003500
3501 /* Type 2 - LPAR name */
3502 vlcd->type = 2;
3503 len = strlen(utsname()->nodename) + 1;
3504 vlcd->len = cpu_to_be16(len);
Kees Cook08ea5562018-04-10 15:26:43 -07003505 strncpy(vlcd->name, utsname()->nodename, len);
3506 vlcd = (struct vnic_login_client_data *)(vlcd->name + len);
Nathan Fontenot37798d02017-11-08 11:23:56 -06003507
3508 /* Type 3 - device name */
3509 vlcd->type = 3;
3510 len = strlen(adapter->netdev->name) + 1;
3511 vlcd->len = cpu_to_be16(len);
Kees Cook08ea5562018-04-10 15:26:43 -07003512 strncpy(vlcd->name, adapter->netdev->name, len);
Nathan Fontenot37798d02017-11-08 11:23:56 -06003513}
3514
Thomas Falcon20a8ab72018-02-26 18:10:59 -06003515static int send_login(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003516{
3517 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
3518 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003519 struct device *dev = &adapter->vdev->dev;
3520 dma_addr_t rsp_buffer_token;
3521 dma_addr_t buffer_token;
3522 size_t rsp_buffer_size;
3523 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003524 size_t buffer_size;
3525 __be64 *tx_list_p;
3526 __be64 *rx_list_p;
Nathan Fontenot37798d02017-11-08 11:23:56 -06003527 int client_data_len;
3528 struct vnic_login_client_data *vlcd;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003529 int i;
3530
Thomas Falcon20a8ab72018-02-26 18:10:59 -06003531 if (!adapter->tx_scrq || !adapter->rx_scrq) {
3532 netdev_err(adapter->netdev,
3533 "RX or TX queues are not allocated, device login failed\n");
3534 return -1;
3535 }
3536
Thomas Falcon34f0f4e2018-02-13 18:23:40 -06003537 release_login_rsp_buffer(adapter);
Nathan Fontenot37798d02017-11-08 11:23:56 -06003538 client_data_len = vnic_client_data_len(adapter);
3539
Thomas Falcon032c5e82015-12-21 11:26:06 -06003540 buffer_size =
3541 sizeof(struct ibmvnic_login_buffer) +
Nathan Fontenot37798d02017-11-08 11:23:56 -06003542 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues) +
3543 client_data_len;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003544
Nathan Fontenot37798d02017-11-08 11:23:56 -06003545 login_buffer = kzalloc(buffer_size, GFP_ATOMIC);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003546 if (!login_buffer)
3547 goto buf_alloc_failed;
3548
3549 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
3550 DMA_TO_DEVICE);
3551 if (dma_mapping_error(dev, buffer_token)) {
3552 dev_err(dev, "Couldn't map login buffer\n");
3553 goto buf_map_failed;
3554 }
3555
John Allen498cd8e2016-04-06 11:49:55 -05003556 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
3557 sizeof(u64) * adapter->req_tx_queues +
3558 sizeof(u64) * adapter->req_rx_queues +
3559 sizeof(u64) * adapter->req_rx_queues +
3560 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003561
3562 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
3563 if (!login_rsp_buffer)
3564 goto buf_rsp_alloc_failed;
3565
3566 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
3567 rsp_buffer_size, DMA_FROM_DEVICE);
3568 if (dma_mapping_error(dev, rsp_buffer_token)) {
3569 dev_err(dev, "Couldn't map login rsp buffer\n");
3570 goto buf_rsp_map_failed;
3571 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04003572
Thomas Falcon032c5e82015-12-21 11:26:06 -06003573 adapter->login_buf = login_buffer;
3574 adapter->login_buf_token = buffer_token;
3575 adapter->login_buf_sz = buffer_size;
3576 adapter->login_rsp_buf = login_rsp_buffer;
3577 adapter->login_rsp_buf_token = rsp_buffer_token;
3578 adapter->login_rsp_buf_sz = rsp_buffer_size;
3579
3580 login_buffer->len = cpu_to_be32(buffer_size);
3581 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
3582 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
3583 login_buffer->off_txcomp_subcrqs =
3584 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
3585 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
3586 login_buffer->off_rxcomp_subcrqs =
3587 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
3588 sizeof(u64) * adapter->req_tx_queues);
3589 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
3590 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
3591
3592 tx_list_p = (__be64 *)((char *)login_buffer +
3593 sizeof(struct ibmvnic_login_buffer));
3594 rx_list_p = (__be64 *)((char *)login_buffer +
3595 sizeof(struct ibmvnic_login_buffer) +
3596 sizeof(u64) * adapter->req_tx_queues);
3597
3598 for (i = 0; i < adapter->req_tx_queues; i++) {
3599 if (adapter->tx_scrq[i]) {
3600 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
3601 crq_num);
3602 }
3603 }
3604
3605 for (i = 0; i < adapter->req_rx_queues; i++) {
3606 if (adapter->rx_scrq[i]) {
3607 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
3608 crq_num);
3609 }
3610 }
3611
Nathan Fontenot37798d02017-11-08 11:23:56 -06003612 /* Insert vNIC login client data */
3613 vlcd = (struct vnic_login_client_data *)
3614 ((char *)rx_list_p + (sizeof(u64) * adapter->req_rx_queues));
3615 login_buffer->client_data_offset =
3616 cpu_to_be32((char *)vlcd - (char *)login_buffer);
3617 login_buffer->client_data_len = cpu_to_be32(client_data_len);
3618
3619 vnic_add_client_data(adapter, vlcd);
3620
Thomas Falcon032c5e82015-12-21 11:26:06 -06003621 netdev_dbg(adapter->netdev, "Login Buffer:\n");
3622 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
3623 netdev_dbg(adapter->netdev, "%016lx\n",
3624 ((unsigned long int *)(adapter->login_buf))[i]);
3625 }
3626
3627 memset(&crq, 0, sizeof(crq));
3628 crq.login.first = IBMVNIC_CRQ_CMD;
3629 crq.login.cmd = LOGIN;
3630 crq.login.ioba = cpu_to_be32(buffer_token);
3631 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003632 ibmvnic_send_crq(adapter, &crq);
3633
Thomas Falcon20a8ab72018-02-26 18:10:59 -06003634 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003635
Thomas Falcon032c5e82015-12-21 11:26:06 -06003636buf_rsp_map_failed:
3637 kfree(login_rsp_buffer);
3638buf_rsp_alloc_failed:
3639 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
3640buf_map_failed:
3641 kfree(login_buffer);
3642buf_alloc_failed:
Thomas Falcon20a8ab72018-02-26 18:10:59 -06003643 return -1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003644}
3645
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05003646static int send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
3647 u32 len, u8 map_id)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003648{
3649 union ibmvnic_crq crq;
3650
3651 memset(&crq, 0, sizeof(crq));
3652 crq.request_map.first = IBMVNIC_CRQ_CMD;
3653 crq.request_map.cmd = REQUEST_MAP;
3654 crq.request_map.map_id = map_id;
3655 crq.request_map.ioba = cpu_to_be32(addr);
3656 crq.request_map.len = cpu_to_be32(len);
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05003657 return ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003658}
3659
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05003660static int send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003661{
3662 union ibmvnic_crq crq;
3663
3664 memset(&crq, 0, sizeof(crq));
3665 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
3666 crq.request_unmap.cmd = REQUEST_UNMAP;
3667 crq.request_unmap.map_id = map_id;
Thomas Falcon9c4eaab2018-05-23 13:37:57 -05003668 return ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003669}
3670
3671static void send_map_query(struct ibmvnic_adapter *adapter)
3672{
3673 union ibmvnic_crq crq;
3674
3675 memset(&crq, 0, sizeof(crq));
3676 crq.query_map.first = IBMVNIC_CRQ_CMD;
3677 crq.query_map.cmd = QUERY_MAP;
3678 ibmvnic_send_crq(adapter, &crq);
3679}
3680
3681/* Send a series of CRQs requesting various capabilities of the VNIC server */
3682static void send_cap_queries(struct ibmvnic_adapter *adapter)
3683{
3684 union ibmvnic_crq crq;
3685
Thomas Falcon901e0402017-02-15 12:17:59 -06003686 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003687 memset(&crq, 0, sizeof(crq));
3688 crq.query_capability.first = IBMVNIC_CRQ_CMD;
3689 crq.query_capability.cmd = QUERY_CAPABILITY;
3690
3691 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003692 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003693 ibmvnic_send_crq(adapter, &crq);
3694
3695 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003696 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003697 ibmvnic_send_crq(adapter, &crq);
3698
3699 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003700 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003701 ibmvnic_send_crq(adapter, &crq);
3702
3703 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003704 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003705 ibmvnic_send_crq(adapter, &crq);
3706
3707 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003708 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003709 ibmvnic_send_crq(adapter, &crq);
3710
3711 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003712 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003713 ibmvnic_send_crq(adapter, &crq);
3714
3715 crq.query_capability.capability =
3716 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003717 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003718 ibmvnic_send_crq(adapter, &crq);
3719
3720 crq.query_capability.capability =
3721 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003722 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003723 ibmvnic_send_crq(adapter, &crq);
3724
3725 crq.query_capability.capability =
3726 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003727 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003728 ibmvnic_send_crq(adapter, &crq);
3729
3730 crq.query_capability.capability =
3731 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003732 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003733 ibmvnic_send_crq(adapter, &crq);
3734
3735 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
Thomas Falcon901e0402017-02-15 12:17:59 -06003736 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003737 ibmvnic_send_crq(adapter, &crq);
3738
3739 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06003740 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003741 ibmvnic_send_crq(adapter, &crq);
3742
3743 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06003744 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003745 ibmvnic_send_crq(adapter, &crq);
3746
3747 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06003748 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003749 ibmvnic_send_crq(adapter, &crq);
3750
3751 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
Thomas Falcon901e0402017-02-15 12:17:59 -06003752 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003753 ibmvnic_send_crq(adapter, &crq);
3754
3755 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06003756 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003757 ibmvnic_send_crq(adapter, &crq);
3758
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04003759 crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION);
3760 atomic_inc(&adapter->running_cap_crqs);
3761 ibmvnic_send_crq(adapter, &crq);
3762
Thomas Falcon032c5e82015-12-21 11:26:06 -06003763 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003764 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003765 ibmvnic_send_crq(adapter, &crq);
3766
3767 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06003768 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003769 ibmvnic_send_crq(adapter, &crq);
3770
3771 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003772 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003773 ibmvnic_send_crq(adapter, &crq);
3774
3775 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06003776 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003777 ibmvnic_send_crq(adapter, &crq);
3778
3779 crq.query_capability.capability =
3780 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06003781 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003782 ibmvnic_send_crq(adapter, &crq);
3783
3784 crq.query_capability.capability =
3785 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003786 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003787 ibmvnic_send_crq(adapter, &crq);
3788
3789 crq.query_capability.capability =
3790 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003791 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003792 ibmvnic_send_crq(adapter, &crq);
3793
3794 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06003795 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003796 ibmvnic_send_crq(adapter, &crq);
3797}
3798
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02003799static void handle_vpd_size_rsp(union ibmvnic_crq *crq,
3800 struct ibmvnic_adapter *adapter)
3801{
3802 struct device *dev = &adapter->vdev->dev;
3803
3804 if (crq->get_vpd_size_rsp.rc.code) {
3805 dev_err(dev, "Error retrieving VPD size, rc=%x\n",
3806 crq->get_vpd_size_rsp.rc.code);
3807 complete(&adapter->fw_done);
3808 return;
3809 }
3810
3811 adapter->vpd->len = be64_to_cpu(crq->get_vpd_size_rsp.len);
3812 complete(&adapter->fw_done);
3813}
3814
3815static void handle_vpd_rsp(union ibmvnic_crq *crq,
3816 struct ibmvnic_adapter *adapter)
3817{
3818 struct device *dev = &adapter->vdev->dev;
Desnes Augusto Nunes do Rosario21a25452018-02-05 14:33:55 -02003819 unsigned char *substr = NULL;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02003820 u8 fw_level_len = 0;
3821
3822 memset(adapter->fw_version, 0, 32);
3823
3824 dma_unmap_single(dev, adapter->vpd->dma_addr, adapter->vpd->len,
3825 DMA_FROM_DEVICE);
3826
3827 if (crq->get_vpd_rsp.rc.code) {
3828 dev_err(dev, "Error retrieving VPD from device, rc=%x\n",
3829 crq->get_vpd_rsp.rc.code);
3830 goto complete;
3831 }
3832
3833 /* get the position of the firmware version info
3834 * located after the ASCII 'RM' substring in the buffer
3835 */
3836 substr = strnstr(adapter->vpd->buff, "RM", adapter->vpd->len);
3837 if (!substr) {
Desnes Augusto Nunes do Rosarioa1073112018-02-01 16:04:30 -02003838 dev_info(dev, "Warning - No FW level has been provided in the VPD buffer by the VIOS Server\n");
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02003839 goto complete;
3840 }
3841
3842 /* get length of firmware level ASCII substring */
3843 if ((substr + 2) < (adapter->vpd->buff + adapter->vpd->len)) {
3844 fw_level_len = *(substr + 2);
3845 } else {
3846 dev_info(dev, "Length of FW substr extrapolated VDP buff\n");
3847 goto complete;
3848 }
3849
3850 /* copy firmware version string from vpd into adapter */
3851 if ((substr + 3 + fw_level_len) <
3852 (adapter->vpd->buff + adapter->vpd->len)) {
Desnes Augusto Nunes do Rosario21a25452018-02-05 14:33:55 -02003853 strncpy((char *)adapter->fw_version, substr + 3, fw_level_len);
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02003854 } else {
3855 dev_info(dev, "FW substr extrapolated VPD buff\n");
3856 }
3857
3858complete:
Desnes Augusto Nunes do Rosario21a25452018-02-05 14:33:55 -02003859 if (adapter->fw_version[0] == '\0')
3860 strncpy((char *)adapter->fw_version, "N/A", 3 * sizeof(char));
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02003861 complete(&adapter->fw_done);
3862}
3863
Thomas Falcon032c5e82015-12-21 11:26:06 -06003864static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
3865{
3866 struct device *dev = &adapter->vdev->dev;
3867 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
Thomas Falcondde746a2019-04-10 11:07:00 -05003868 netdev_features_t old_hw_features = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003869 union ibmvnic_crq crq;
3870 int i;
3871
3872 dma_unmap_single(dev, adapter->ip_offload_tok,
3873 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
3874
3875 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
3876 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
3877 netdev_dbg(adapter->netdev, "%016lx\n",
3878 ((unsigned long int *)(buf))[i]);
3879
3880 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
3881 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
3882 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
3883 buf->tcp_ipv4_chksum);
3884 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
3885 buf->tcp_ipv6_chksum);
3886 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
3887 buf->udp_ipv4_chksum);
3888 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
3889 buf->udp_ipv6_chksum);
3890 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
3891 buf->large_tx_ipv4);
3892 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
3893 buf->large_tx_ipv6);
3894 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
3895 buf->large_rx_ipv4);
3896 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
3897 buf->large_rx_ipv6);
3898 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
3899 buf->max_ipv4_header_size);
3900 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
3901 buf->max_ipv6_header_size);
3902 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
3903 buf->max_tcp_header_size);
3904 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
3905 buf->max_udp_header_size);
3906 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
3907 buf->max_large_tx_size);
3908 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
3909 buf->max_large_rx_size);
3910 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
3911 buf->ipv6_extension_header);
3912 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
3913 buf->tcp_pseudosum_req);
3914 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
3915 buf->num_ipv6_ext_headers);
3916 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
3917 buf->off_ipv6_ext_headers);
3918
3919 adapter->ip_offload_ctrl_tok =
3920 dma_map_single(dev, &adapter->ip_offload_ctrl,
3921 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
3922
3923 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
3924 dev_err(dev, "Couldn't map ip offload control buffer\n");
3925 return;
3926 }
3927
Thomas Falconf6897942018-01-18 19:05:01 -06003928 adapter->ip_offload_ctrl.len =
3929 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
Thomas Falcon032c5e82015-12-21 11:26:06 -06003930 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
Thomas Falconf6897942018-01-18 19:05:01 -06003931 adapter->ip_offload_ctrl.ipv4_chksum = buf->ipv4_chksum;
3932 adapter->ip_offload_ctrl.ipv6_chksum = buf->ipv6_chksum;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003933 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
3934 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
3935 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
3936 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
Thomas Falconfdb06102017-10-17 12:36:55 -05003937 adapter->ip_offload_ctrl.large_tx_ipv4 = buf->large_tx_ipv4;
3938 adapter->ip_offload_ctrl.large_tx_ipv6 = buf->large_tx_ipv6;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003939
Thomas Falconfdb06102017-10-17 12:36:55 -05003940 /* large_rx disabled for now, additional features needed */
Thomas Falcon032c5e82015-12-21 11:26:06 -06003941 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
3942 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
3943
Thomas Falcondde746a2019-04-10 11:07:00 -05003944 if (adapter->state != VNIC_PROBING) {
3945 old_hw_features = adapter->netdev->hw_features;
3946 adapter->netdev->hw_features = 0;
3947 }
3948
Thomas Falconb66b7bd2019-04-10 11:06:59 -05003949 adapter->netdev->hw_features = NETIF_F_SG | NETIF_F_GSO | NETIF_F_GRO;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003950
3951 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
Thomas Falcondde746a2019-04-10 11:07:00 -05003952 adapter->netdev->hw_features |= NETIF_F_IP_CSUM;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003953
3954 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
Thomas Falcondde746a2019-04-10 11:07:00 -05003955 adapter->netdev->hw_features |= NETIF_F_IPV6_CSUM;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003956
Thomas Falcon9be02cd2016-04-01 17:20:35 -05003957 if ((adapter->netdev->features &
3958 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
Thomas Falcondde746a2019-04-10 11:07:00 -05003959 adapter->netdev->hw_features |= NETIF_F_RXCSUM;
Thomas Falcon9be02cd2016-04-01 17:20:35 -05003960
Thomas Falconfdb06102017-10-17 12:36:55 -05003961 if (buf->large_tx_ipv4)
Thomas Falcondde746a2019-04-10 11:07:00 -05003962 adapter->netdev->hw_features |= NETIF_F_TSO;
Thomas Falconfdb06102017-10-17 12:36:55 -05003963 if (buf->large_tx_ipv6)
Thomas Falcondde746a2019-04-10 11:07:00 -05003964 adapter->netdev->hw_features |= NETIF_F_TSO6;
Thomas Falconfdb06102017-10-17 12:36:55 -05003965
Thomas Falcondde746a2019-04-10 11:07:00 -05003966 if (adapter->state == VNIC_PROBING) {
3967 adapter->netdev->features |= adapter->netdev->hw_features;
3968 } else if (old_hw_features != adapter->netdev->hw_features) {
3969 netdev_features_t tmp = 0;
3970
3971 /* disable features no longer supported */
3972 adapter->netdev->features &= adapter->netdev->hw_features;
3973 /* turn on features now supported if previously enabled */
3974 tmp = (old_hw_features ^ adapter->netdev->hw_features) &
3975 adapter->netdev->hw_features;
3976 adapter->netdev->features |=
3977 tmp & adapter->netdev->wanted_features;
3978 }
Thomas Falconaa0bf852017-10-17 12:36:56 -05003979
Thomas Falcon032c5e82015-12-21 11:26:06 -06003980 memset(&crq, 0, sizeof(crq));
3981 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
3982 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
3983 crq.control_ip_offload.len =
3984 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
3985 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
3986 ibmvnic_send_crq(adapter, &crq);
3987}
3988
Thomas Falconc9008d32018-08-06 21:39:59 -05003989static const char *ibmvnic_fw_err_cause(u16 cause)
3990{
3991 switch (cause) {
3992 case ADAPTER_PROBLEM:
3993 return "adapter problem";
3994 case BUS_PROBLEM:
3995 return "bus problem";
3996 case FW_PROBLEM:
3997 return "firmware problem";
3998 case DD_PROBLEM:
3999 return "device driver problem";
4000 case EEH_RECOVERY:
4001 return "EEH recovery";
4002 case FW_UPDATED:
4003 return "firmware updated";
4004 case LOW_MEMORY:
4005 return "low Memory";
4006 default:
4007 return "unknown";
4008 }
4009}
4010
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04004011static void handle_error_indication(union ibmvnic_crq *crq,
4012 struct ibmvnic_adapter *adapter)
4013{
4014 struct device *dev = &adapter->vdev->dev;
Thomas Falconc9008d32018-08-06 21:39:59 -05004015 u16 cause;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04004016
Thomas Falconc9008d32018-08-06 21:39:59 -05004017 cause = be16_to_cpu(crq->error_indication.error_cause);
4018
4019 dev_warn_ratelimited(dev,
4020 "Firmware reports %serror, cause: %s. Starting recovery...\n",
4021 crq->error_indication.flags
4022 & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
4023 ibmvnic_fw_err_cause(cause));
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04004024
Nathan Fontenoted651a12017-05-03 14:04:38 -04004025 if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR)
4026 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
John Allen8cb31cf2017-05-26 10:30:37 -04004027 else
4028 ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004029}
4030
Thomas Falconf8136142018-01-29 13:45:05 -06004031static int handle_change_mac_rsp(union ibmvnic_crq *crq,
4032 struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06004033{
4034 struct net_device *netdev = adapter->netdev;
4035 struct device *dev = &adapter->vdev->dev;
4036 long rc;
4037
4038 rc = crq->change_mac_addr_rsp.rc.code;
4039 if (rc) {
4040 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
Thomas Falconf8136142018-01-29 13:45:05 -06004041 goto out;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004042 }
Thomas Falcon62740e92019-05-09 23:13:43 -05004043 ether_addr_copy(netdev->dev_addr,
4044 &crq->change_mac_addr_rsp.mac_addr[0]);
Thomas Falconf8136142018-01-29 13:45:05 -06004045out:
4046 complete(&adapter->fw_done);
4047 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004048}
4049
4050static void handle_request_cap_rsp(union ibmvnic_crq *crq,
4051 struct ibmvnic_adapter *adapter)
4052{
4053 struct device *dev = &adapter->vdev->dev;
4054 u64 *req_value;
4055 char *name;
4056
Thomas Falcon901e0402017-02-15 12:17:59 -06004057 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004058 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
4059 case REQ_TX_QUEUES:
4060 req_value = &adapter->req_tx_queues;
4061 name = "tx";
4062 break;
4063 case REQ_RX_QUEUES:
4064 req_value = &adapter->req_rx_queues;
4065 name = "rx";
4066 break;
4067 case REQ_RX_ADD_QUEUES:
4068 req_value = &adapter->req_rx_add_queues;
4069 name = "rx_add";
4070 break;
4071 case REQ_TX_ENTRIES_PER_SUBCRQ:
4072 req_value = &adapter->req_tx_entries_per_subcrq;
4073 name = "tx_entries_per_subcrq";
4074 break;
4075 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
4076 req_value = &adapter->req_rx_add_entries_per_subcrq;
4077 name = "rx_add_entries_per_subcrq";
4078 break;
4079 case REQ_MTU:
4080 req_value = &adapter->req_mtu;
4081 name = "mtu";
4082 break;
4083 case PROMISC_REQUESTED:
4084 req_value = &adapter->promisc;
4085 name = "promisc";
4086 break;
4087 default:
4088 dev_err(dev, "Got invalid cap request rsp %d\n",
4089 crq->request_capability.capability);
4090 return;
4091 }
4092
4093 switch (crq->request_capability_rsp.rc.code) {
4094 case SUCCESS:
4095 break;
4096 case PARTIALSUCCESS:
4097 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
4098 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06004099 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06004100 number), name);
John Allene7913802018-01-18 16:27:12 -06004101
4102 if (be16_to_cpu(crq->request_capability_rsp.capability) ==
4103 REQ_MTU) {
4104 pr_err("mtu of %llu is not supported. Reverting.\n",
4105 *req_value);
4106 *req_value = adapter->fallback.mtu;
4107 } else {
4108 *req_value =
4109 be64_to_cpu(crq->request_capability_rsp.number);
4110 }
4111
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04004112 ibmvnic_send_req_caps(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004113 return;
4114 default:
4115 dev_err(dev, "Error %d in request cap rsp\n",
4116 crq->request_capability_rsp.rc.code);
4117 return;
4118 }
4119
4120 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06004121 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06004122 union ibmvnic_crq newcrq;
4123 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
4124 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
4125 &adapter->ip_offload_buf;
4126
Thomas Falcon249168a2017-02-15 12:18:00 -06004127 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004128 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
4129 buf_sz,
4130 DMA_FROM_DEVICE);
4131
4132 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
4133 if (!firmware_has_feature(FW_FEATURE_CMO))
4134 dev_err(dev, "Couldn't map offload buffer\n");
4135 return;
4136 }
4137
4138 memset(&newcrq, 0, sizeof(newcrq));
4139 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
4140 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
4141 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
4142 newcrq.query_ip_offload.ioba =
4143 cpu_to_be32(adapter->ip_offload_tok);
4144
4145 ibmvnic_send_crq(adapter, &newcrq);
4146 }
4147}
4148
4149static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
4150 struct ibmvnic_adapter *adapter)
4151{
4152 struct device *dev = &adapter->vdev->dev;
John Allenc26eba02017-10-26 16:23:25 -05004153 struct net_device *netdev = adapter->netdev;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004154 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
4155 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004156 int i;
4157
4158 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
Thomas Falcon37e40fa2018-04-06 18:37:02 -05004159 DMA_TO_DEVICE);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004160 dma_unmap_single(dev, adapter->login_rsp_buf_token,
Thomas Falcon37e40fa2018-04-06 18:37:02 -05004161 adapter->login_rsp_buf_sz, DMA_FROM_DEVICE);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004162
John Allen498cd8e2016-04-06 11:49:55 -05004163 /* If the number of queues requested can't be allocated by the
4164 * server, the login response will return with code 1. We will need
4165 * to resend the login buffer with fewer queues requested.
4166 */
4167 if (login_rsp_crq->generic.rc.code) {
Nathan Fontenot64d92aa2018-04-11 10:09:32 -05004168 adapter->init_done_rc = login_rsp_crq->generic.rc.code;
John Allen498cd8e2016-04-06 11:49:55 -05004169 complete(&adapter->init_done);
4170 return 0;
4171 }
4172
John Allenc26eba02017-10-26 16:23:25 -05004173 netdev->mtu = adapter->req_mtu - ETH_HLEN;
4174
Thomas Falcon032c5e82015-12-21 11:26:06 -06004175 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
4176 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
4177 netdev_dbg(adapter->netdev, "%016lx\n",
4178 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
4179 }
4180
4181 /* Sanity checks */
4182 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
4183 (be32_to_cpu(login->num_rxcomp_subcrqs) *
4184 adapter->req_rx_add_queues !=
4185 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
4186 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
4187 ibmvnic_remove(adapter->vdev);
4188 return -EIO;
4189 }
Thomas Falcona2c0f032018-02-21 18:18:30 -06004190 release_login_buffer(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004191 complete(&adapter->init_done);
4192
Thomas Falcon032c5e82015-12-21 11:26:06 -06004193 return 0;
4194}
4195
Thomas Falcon032c5e82015-12-21 11:26:06 -06004196static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
4197 struct ibmvnic_adapter *adapter)
4198{
4199 struct device *dev = &adapter->vdev->dev;
4200 long rc;
4201
4202 rc = crq->request_unmap_rsp.rc.code;
4203 if (rc)
4204 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
4205}
4206
4207static void handle_query_map_rsp(union ibmvnic_crq *crq,
4208 struct ibmvnic_adapter *adapter)
4209{
4210 struct net_device *netdev = adapter->netdev;
4211 struct device *dev = &adapter->vdev->dev;
4212 long rc;
4213
4214 rc = crq->query_map_rsp.rc.code;
4215 if (rc) {
4216 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
4217 return;
4218 }
4219 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
4220 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
4221 crq->query_map_rsp.free_pages);
4222}
4223
4224static void handle_query_cap_rsp(union ibmvnic_crq *crq,
4225 struct ibmvnic_adapter *adapter)
4226{
4227 struct net_device *netdev = adapter->netdev;
4228 struct device *dev = &adapter->vdev->dev;
4229 long rc;
4230
Thomas Falcon901e0402017-02-15 12:17:59 -06004231 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004232 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06004233 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06004234 rc = crq->query_capability.rc.code;
4235 if (rc) {
4236 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
4237 goto out;
4238 }
4239
4240 switch (be16_to_cpu(crq->query_capability.capability)) {
4241 case MIN_TX_QUEUES:
4242 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004243 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004244 netdev_dbg(netdev, "min_tx_queues = %lld\n",
4245 adapter->min_tx_queues);
4246 break;
4247 case MIN_RX_QUEUES:
4248 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004249 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004250 netdev_dbg(netdev, "min_rx_queues = %lld\n",
4251 adapter->min_rx_queues);
4252 break;
4253 case MIN_RX_ADD_QUEUES:
4254 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004255 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004256 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
4257 adapter->min_rx_add_queues);
4258 break;
4259 case MAX_TX_QUEUES:
4260 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004261 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004262 netdev_dbg(netdev, "max_tx_queues = %lld\n",
4263 adapter->max_tx_queues);
4264 break;
4265 case MAX_RX_QUEUES:
4266 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004267 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004268 netdev_dbg(netdev, "max_rx_queues = %lld\n",
4269 adapter->max_rx_queues);
4270 break;
4271 case MAX_RX_ADD_QUEUES:
4272 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004273 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004274 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
4275 adapter->max_rx_add_queues);
4276 break;
4277 case MIN_TX_ENTRIES_PER_SUBCRQ:
4278 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004279 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004280 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
4281 adapter->min_tx_entries_per_subcrq);
4282 break;
4283 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
4284 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004285 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004286 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
4287 adapter->min_rx_add_entries_per_subcrq);
4288 break;
4289 case MAX_TX_ENTRIES_PER_SUBCRQ:
4290 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004291 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004292 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
4293 adapter->max_tx_entries_per_subcrq);
4294 break;
4295 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
4296 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004297 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004298 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
4299 adapter->max_rx_add_entries_per_subcrq);
4300 break;
4301 case TCP_IP_OFFLOAD:
4302 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06004303 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004304 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
4305 adapter->tcp_ip_offload);
4306 break;
4307 case PROMISC_SUPPORTED:
4308 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06004309 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004310 netdev_dbg(netdev, "promisc_supported = %lld\n",
4311 adapter->promisc_supported);
4312 break;
4313 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06004314 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06004315 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004316 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
4317 break;
4318 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06004319 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06004320 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004321 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
4322 break;
4323 case MAX_MULTICAST_FILTERS:
4324 adapter->max_multicast_filters =
Thomas Falconde89e852016-03-01 10:20:09 -06004325 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004326 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
4327 adapter->max_multicast_filters);
4328 break;
4329 case VLAN_HEADER_INSERTION:
4330 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06004331 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004332 if (adapter->vlan_header_insertion)
4333 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
4334 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
4335 adapter->vlan_header_insertion);
4336 break;
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04004337 case RX_VLAN_HEADER_INSERTION:
4338 adapter->rx_vlan_header_insertion =
4339 be64_to_cpu(crq->query_capability.number);
4340 netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n",
4341 adapter->rx_vlan_header_insertion);
4342 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004343 case MAX_TX_SG_ENTRIES:
4344 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06004345 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004346 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
4347 adapter->max_tx_sg_entries);
4348 break;
4349 case RX_SG_SUPPORTED:
4350 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06004351 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004352 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
4353 adapter->rx_sg_supported);
4354 break;
4355 case OPT_TX_COMP_SUB_QUEUES:
4356 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004357 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004358 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
4359 adapter->opt_tx_comp_sub_queues);
4360 break;
4361 case OPT_RX_COMP_QUEUES:
4362 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06004363 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004364 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
4365 adapter->opt_rx_comp_queues);
4366 break;
4367 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
4368 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06004369 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004370 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
4371 adapter->opt_rx_bufadd_q_per_rx_comp_q);
4372 break;
4373 case OPT_TX_ENTRIES_PER_SUBCRQ:
4374 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004375 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004376 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
4377 adapter->opt_tx_entries_per_subcrq);
4378 break;
4379 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
4380 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06004381 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004382 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
4383 adapter->opt_rxba_entries_per_subcrq);
4384 break;
4385 case TX_RX_DESC_REQ:
4386 adapter->tx_rx_desc_req = crq->query_capability.number;
4387 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
4388 adapter->tx_rx_desc_req);
4389 break;
4390
4391 default:
4392 netdev_err(netdev, "Got invalid cap rsp %d\n",
4393 crq->query_capability.capability);
4394 }
4395
4396out:
Thomas Falcon249168a2017-02-15 12:18:00 -06004397 if (atomic_read(&adapter->running_cap_crqs) == 0) {
4398 adapter->wait_capability = false;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04004399 ibmvnic_send_req_caps(adapter, 0);
Thomas Falcon249168a2017-02-15 12:18:00 -06004400 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06004401}
4402
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004403static int send_query_phys_parms(struct ibmvnic_adapter *adapter)
4404{
4405 union ibmvnic_crq crq;
4406 int rc;
4407
4408 memset(&crq, 0, sizeof(crq));
4409 crq.query_phys_parms.first = IBMVNIC_CRQ_CMD;
4410 crq.query_phys_parms.cmd = QUERY_PHYS_PARMS;
Thomas Falcon070eca92019-11-25 17:12:53 -06004411 reinit_completion(&adapter->fw_done);
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004412 rc = ibmvnic_send_crq(adapter, &crq);
4413 if (rc)
4414 return rc;
4415 wait_for_completion(&adapter->fw_done);
4416 return adapter->fw_done_rc ? -EIO : 0;
4417}
4418
4419static int handle_query_phys_parms_rsp(union ibmvnic_crq *crq,
4420 struct ibmvnic_adapter *adapter)
4421{
4422 struct net_device *netdev = adapter->netdev;
4423 int rc;
Murilo Fossa Vicentinidd0f9d82019-09-16 11:50:37 -03004424 __be32 rspeed = cpu_to_be32(crq->query_phys_parms_rsp.speed);
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004425
4426 rc = crq->query_phys_parms_rsp.rc.code;
4427 if (rc) {
4428 netdev_err(netdev, "Error %d in QUERY_PHYS_PARMS\n", rc);
4429 return rc;
4430 }
Murilo Fossa Vicentinidd0f9d82019-09-16 11:50:37 -03004431 switch (rspeed) {
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004432 case IBMVNIC_10MBPS:
4433 adapter->speed = SPEED_10;
4434 break;
4435 case IBMVNIC_100MBPS:
4436 adapter->speed = SPEED_100;
4437 break;
4438 case IBMVNIC_1GBPS:
4439 adapter->speed = SPEED_1000;
4440 break;
4441 case IBMVNIC_10GBP:
4442 adapter->speed = SPEED_10000;
4443 break;
4444 case IBMVNIC_25GBPS:
4445 adapter->speed = SPEED_25000;
4446 break;
4447 case IBMVNIC_40GBPS:
4448 adapter->speed = SPEED_40000;
4449 break;
4450 case IBMVNIC_50GBPS:
4451 adapter->speed = SPEED_50000;
4452 break;
4453 case IBMVNIC_100GBPS:
4454 adapter->speed = SPEED_100000;
4455 break;
4456 default:
Murilo Fossa Vicentinidd0f9d82019-09-16 11:50:37 -03004457 if (netif_carrier_ok(netdev))
4458 netdev_warn(netdev, "Unknown speed 0x%08x\n", rspeed);
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004459 adapter->speed = SPEED_UNKNOWN;
4460 }
4461 if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_FULL_DUPLEX)
4462 adapter->duplex = DUPLEX_FULL;
4463 else if (crq->query_phys_parms_rsp.flags1 & IBMVNIC_HALF_DUPLEX)
4464 adapter->duplex = DUPLEX_HALF;
4465 else
4466 adapter->duplex = DUPLEX_UNKNOWN;
4467
4468 return rc;
4469}
4470
Thomas Falcon032c5e82015-12-21 11:26:06 -06004471static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
4472 struct ibmvnic_adapter *adapter)
4473{
4474 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
4475 struct net_device *netdev = adapter->netdev;
4476 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04004477 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004478 long rc;
4479
4480 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04004481 (unsigned long int)cpu_to_be64(u64_crq[0]),
4482 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06004483 switch (gen_crq->first) {
4484 case IBMVNIC_CRQ_INIT_RSP:
4485 switch (gen_crq->cmd) {
4486 case IBMVNIC_CRQ_INIT:
4487 dev_info(dev, "Partner initialized\n");
John Allen017892c12017-05-26 10:30:19 -04004488 adapter->from_passive_init = true;
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05004489 adapter->failover_pending = false;
Thomas Falcon17c87052018-05-23 13:37:58 -05004490 if (!completion_done(&adapter->init_done)) {
4491 complete(&adapter->init_done);
4492 adapter->init_done_rc = -EIO;
4493 }
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05004494 ibmvnic_reset(adapter, VNIC_RESET_FAILOVER);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004495 break;
4496 case IBMVNIC_CRQ_INIT_COMPLETE:
4497 dev_info(dev, "Partner initialization complete\n");
Thomas Falcon51536982018-05-23 13:37:56 -05004498 adapter->crq.active = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004499 send_version_xchg(adapter);
4500 break;
4501 default:
4502 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
4503 }
4504 return;
4505 case IBMVNIC_CRQ_XPORT_EVENT:
Nathan Fontenoted651a12017-05-03 14:04:38 -04004506 netif_carrier_off(netdev);
Thomas Falcon51536982018-05-23 13:37:56 -05004507 adapter->crq.active = false;
Thomas Falcon2147e3d2019-11-25 17:12:54 -06004508 /* terminate any thread waiting for a response
4509 * from the device
4510 */
4511 if (!completion_done(&adapter->fw_done)) {
4512 adapter->fw_done_rc = -EIO;
4513 complete(&adapter->fw_done);
4514 }
4515 if (!completion_done(&adapter->stats_done))
4516 complete(&adapter->stats_done);
Juliet Kim7ed5b312019-09-20 16:11:23 -04004517 if (test_bit(0, &adapter->resetting))
Thomas Falcon2770a792018-05-23 13:38:02 -05004518 adapter->force_reset_recovery = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004519 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
Nathan Fontenoted651a12017-05-03 14:04:38 -04004520 dev_info(dev, "Migrated, re-enabling adapter\n");
4521 ibmvnic_reset(adapter, VNIC_RESET_MOBILITY);
Thomas Falcondfad09a2016-08-18 11:37:51 -05004522 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
4523 dev_info(dev, "Backing device failover detected\n");
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05004524 adapter->failover_pending = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004525 } else {
4526 /* The adapter lost the connection */
4527 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
4528 gen_crq->cmd);
Nathan Fontenoted651a12017-05-03 14:04:38 -04004529 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004530 }
4531 return;
4532 case IBMVNIC_CRQ_CMD_RSP:
4533 break;
4534 default:
4535 dev_err(dev, "Got an invalid msg type 0x%02x\n",
4536 gen_crq->first);
4537 return;
4538 }
4539
4540 switch (gen_crq->cmd) {
4541 case VERSION_EXCHANGE_RSP:
4542 rc = crq->version_exchange_rsp.rc.code;
4543 if (rc) {
4544 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
4545 break;
4546 }
4547 dev_info(dev, "Partner protocol version is %d\n",
4548 crq->version_exchange_rsp.version);
4549 if (be16_to_cpu(crq->version_exchange_rsp.version) <
4550 ibmvnic_version)
4551 ibmvnic_version =
4552 be16_to_cpu(crq->version_exchange_rsp.version);
4553 send_cap_queries(adapter);
4554 break;
4555 case QUERY_CAPABILITY_RSP:
4556 handle_query_cap_rsp(crq, adapter);
4557 break;
4558 case QUERY_MAP_RSP:
4559 handle_query_map_rsp(crq, adapter);
4560 break;
4561 case REQUEST_MAP_RSP:
Thomas Falconf3be0cb2017-06-21 14:53:01 -05004562 adapter->fw_done_rc = crq->request_map_rsp.rc.code;
4563 complete(&adapter->fw_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004564 break;
4565 case REQUEST_UNMAP_RSP:
4566 handle_request_unmap_rsp(crq, adapter);
4567 break;
4568 case REQUEST_CAPABILITY_RSP:
4569 handle_request_cap_rsp(crq, adapter);
4570 break;
4571 case LOGIN_RSP:
4572 netdev_dbg(netdev, "Got Login Response\n");
4573 handle_login_rsp(crq, adapter);
4574 break;
4575 case LOGICAL_LINK_STATE_RSP:
Nathan Fontenot53da09e2017-04-21 15:39:04 -04004576 netdev_dbg(netdev,
4577 "Got Logical Link State Response, state: %d rc: %d\n",
4578 crq->logical_link_state_rsp.link_state,
4579 crq->logical_link_state_rsp.rc.code);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004580 adapter->logical_link_state =
4581 crq->logical_link_state_rsp.link_state;
Nathan Fontenot53da09e2017-04-21 15:39:04 -04004582 adapter->init_done_rc = crq->logical_link_state_rsp.rc.code;
4583 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004584 break;
4585 case LINK_STATE_INDICATION:
4586 netdev_dbg(netdev, "Got Logical Link State Indication\n");
4587 adapter->phys_link_state =
4588 crq->link_state_indication.phys_link_state;
4589 adapter->logical_link_state =
4590 crq->link_state_indication.logical_link_state;
Thomas Falcon0655f992019-05-09 23:13:44 -05004591 if (adapter->phys_link_state && adapter->logical_link_state)
4592 netif_carrier_on(netdev);
4593 else
4594 netif_carrier_off(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004595 break;
4596 case CHANGE_MAC_ADDR_RSP:
4597 netdev_dbg(netdev, "Got MAC address change Response\n");
Thomas Falconf8136142018-01-29 13:45:05 -06004598 adapter->fw_done_rc = handle_change_mac_rsp(crq, adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004599 break;
4600 case ERROR_INDICATION:
4601 netdev_dbg(netdev, "Got Error Indication\n");
4602 handle_error_indication(crq, adapter);
4603 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004604 case REQUEST_STATISTICS_RSP:
4605 netdev_dbg(netdev, "Got Statistics Response\n");
4606 complete(&adapter->stats_done);
4607 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004608 case QUERY_IP_OFFLOAD_RSP:
4609 netdev_dbg(netdev, "Got Query IP offload Response\n");
4610 handle_query_ip_offload_rsp(adapter);
4611 break;
4612 case MULTICAST_CTRL_RSP:
4613 netdev_dbg(netdev, "Got multicast control Response\n");
4614 break;
4615 case CONTROL_IP_OFFLOAD_RSP:
4616 netdev_dbg(netdev, "Got Control IP offload Response\n");
4617 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
4618 sizeof(adapter->ip_offload_ctrl),
4619 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05004620 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004621 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004622 case COLLECT_FW_TRACE_RSP:
4623 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
4624 complete(&adapter->fw_done);
4625 break;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -02004626 case GET_VPD_SIZE_RSP:
4627 handle_vpd_size_rsp(crq, adapter);
4628 break;
4629 case GET_VPD_RSP:
4630 handle_vpd_rsp(crq, adapter);
4631 break;
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -03004632 case QUERY_PHYS_PARMS_RSP:
4633 adapter->fw_done_rc = handle_query_phys_parms_rsp(crq, adapter);
4634 complete(&adapter->fw_done);
4635 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004636 default:
4637 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
4638 gen_crq->cmd);
4639 }
4640}
4641
4642static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
4643{
4644 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06004645
Thomas Falcon6c267b32017-02-15 12:17:58 -06004646 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06004647 return IRQ_HANDLED;
4648}
4649
4650static void ibmvnic_tasklet(void *data)
4651{
4652 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004653 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004654 union ibmvnic_crq *crq;
4655 unsigned long flags;
4656 bool done = false;
4657
4658 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004659 while (!done) {
4660 /* Pull all the valid messages off the CRQ */
4661 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
4662 ibmvnic_handle_crq(crq, adapter);
4663 crq->generic.first = 0;
4664 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04004665
4666 /* remain in tasklet until all
4667 * capabilities responses are received
4668 */
4669 if (!adapter->wait_capability)
4670 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004671 }
Thomas Falcon249168a2017-02-15 12:18:00 -06004672 /* if capabilities CRQ's were sent in this tasklet, the following
4673 * tasklet must wait until all responses are received
4674 */
4675 if (atomic_read(&adapter->running_cap_crqs) != 0)
4676 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004677 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004678}
4679
4680static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
4681{
4682 struct vio_dev *vdev = adapter->vdev;
4683 int rc;
4684
4685 do {
4686 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
4687 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
4688
4689 if (rc)
4690 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
4691
4692 return rc;
4693}
4694
4695static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
4696{
4697 struct ibmvnic_crq_queue *crq = &adapter->crq;
4698 struct device *dev = &adapter->vdev->dev;
4699 struct vio_dev *vdev = adapter->vdev;
4700 int rc;
4701
4702 /* Close the CRQ */
4703 do {
4704 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4705 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4706
4707 /* Clean out the queue */
4708 memset(crq->msgs, 0, PAGE_SIZE);
4709 crq->cur = 0;
Thomas Falcon51536982018-05-23 13:37:56 -05004710 crq->active = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004711
4712 /* And re-open it again */
4713 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
4714 crq->msg_token, PAGE_SIZE);
4715
4716 if (rc == H_CLOSED)
4717 /* Adapter is good, but other end is not ready */
4718 dev_warn(dev, "Partner adapter not ready\n");
4719 else if (rc != 0)
4720 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
4721
4722 return rc;
4723}
4724
Nathan Fontenotf9928872017-03-30 02:48:54 -04004725static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06004726{
4727 struct ibmvnic_crq_queue *crq = &adapter->crq;
4728 struct vio_dev *vdev = adapter->vdev;
4729 long rc;
4730
Nathan Fontenotf9928872017-03-30 02:48:54 -04004731 if (!crq->msgs)
4732 return;
4733
Thomas Falcon032c5e82015-12-21 11:26:06 -06004734 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
4735 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06004736 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004737 do {
4738 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4739 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4740
4741 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
4742 DMA_BIDIRECTIONAL);
4743 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04004744 crq->msgs = NULL;
Thomas Falcon51536982018-05-23 13:37:56 -05004745 crq->active = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004746}
4747
Nathan Fontenotf9928872017-03-30 02:48:54 -04004748static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06004749{
4750 struct ibmvnic_crq_queue *crq = &adapter->crq;
4751 struct device *dev = &adapter->vdev->dev;
4752 struct vio_dev *vdev = adapter->vdev;
4753 int rc, retrc = -ENOMEM;
4754
Nathan Fontenotf9928872017-03-30 02:48:54 -04004755 if (crq->msgs)
4756 return 0;
4757
Thomas Falcon032c5e82015-12-21 11:26:06 -06004758 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
4759 /* Should we allocate more than one page? */
4760
4761 if (!crq->msgs)
4762 return -ENOMEM;
4763
4764 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
4765 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
4766 DMA_BIDIRECTIONAL);
4767 if (dma_mapping_error(dev, crq->msg_token))
4768 goto map_failed;
4769
4770 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
4771 crq->msg_token, PAGE_SIZE);
4772
4773 if (rc == H_RESOURCE)
4774 /* maybe kexecing and resource is busy. try a reset */
4775 rc = ibmvnic_reset_crq(adapter);
4776 retrc = rc;
4777
4778 if (rc == H_CLOSED) {
4779 dev_warn(dev, "Partner adapter not ready\n");
4780 } else if (rc) {
4781 dev_warn(dev, "Error %d opening adapter\n", rc);
4782 goto reg_crq_failed;
4783 }
4784
4785 retrc = 0;
4786
Thomas Falcon6c267b32017-02-15 12:17:58 -06004787 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
4788 (unsigned long)adapter);
4789
Thomas Falcon032c5e82015-12-21 11:26:06 -06004790 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -03004791 snprintf(crq->name, sizeof(crq->name), "ibmvnic-%x",
4792 adapter->vdev->unit_address);
4793 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, crq->name, adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004794 if (rc) {
4795 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
4796 vdev->irq, rc);
4797 goto req_irq_failed;
4798 }
4799
4800 rc = vio_enable_interrupts(vdev);
4801 if (rc) {
4802 dev_err(dev, "Error %d enabling interrupts\n", rc);
4803 goto req_irq_failed;
4804 }
4805
4806 crq->cur = 0;
4807 spin_lock_init(&crq->lock);
4808
4809 return retrc;
4810
4811req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06004812 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004813 do {
4814 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4815 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4816reg_crq_failed:
4817 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
4818map_failed:
4819 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04004820 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004821 return retrc;
4822}
4823
Thomas Falcon8a348452018-05-23 13:38:00 -05004824static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter)
John Allenf6ef6402017-03-17 17:13:42 -05004825{
4826 struct device *dev = &adapter->vdev->dev;
4827 unsigned long timeout = msecs_to_jiffies(30000);
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06004828 u64 old_num_rx_queues, old_num_tx_queues;
John Allenf6ef6402017-03-17 17:13:42 -05004829 int rc;
4830
John Allen017892c12017-05-26 10:30:19 -04004831 adapter->from_passive_init = false;
4832
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06004833 old_num_rx_queues = adapter->req_rx_queues;
4834 old_num_tx_queues = adapter->req_tx_queues;
4835
Thomas Falconbbd669a2019-04-04 18:58:26 -05004836 reinit_completion(&adapter->init_done);
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04004837 adapter->init_done_rc = 0;
John Allenf6ef6402017-03-17 17:13:42 -05004838 ibmvnic_send_crq_init(adapter);
4839 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
4840 dev_err(dev, "Initialization sequence timed out\n");
John Allen017892c12017-05-26 10:30:19 -04004841 return -1;
4842 }
4843
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04004844 if (adapter->init_done_rc) {
4845 release_crq_queue(adapter);
4846 return adapter->init_done_rc;
4847 }
4848
John Allen017892c12017-05-26 10:30:19 -04004849 if (adapter->from_passive_init) {
4850 adapter->state = VNIC_OPEN;
4851 adapter->from_passive_init = false;
John Allenf6ef6402017-03-17 17:13:42 -05004852 return -1;
4853 }
4854
Juliet Kim7ed5b312019-09-20 16:11:23 -04004855 if (test_bit(0, &adapter->resetting) && !adapter->wait_for_reset &&
Nathan Fontenot30f79622018-04-06 18:37:06 -05004856 adapter->reset_reason != VNIC_RESET_MOBILITY) {
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06004857 if (adapter->req_rx_queues != old_num_rx_queues ||
4858 adapter->req_tx_queues != old_num_tx_queues) {
4859 release_sub_crqs(adapter, 0);
4860 rc = init_sub_crqs(adapter);
4861 } else {
4862 rc = reset_sub_crq_queues(adapter);
4863 }
4864 } else {
Nathan Fontenot57a49432017-05-26 10:31:12 -04004865 rc = init_sub_crqs(adapter);
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06004866 }
4867
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04004868 if (rc) {
4869 dev_err(dev, "Initialization of sub crqs failed\n");
4870 release_crq_queue(adapter);
Thomas Falcon5df969c2017-06-28 19:55:54 -05004871 return rc;
4872 }
4873
4874 rc = init_sub_crq_irqs(adapter);
4875 if (rc) {
4876 dev_err(dev, "Failed to initialize sub crq irqs\n");
4877 release_crq_queue(adapter);
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04004878 }
4879
4880 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05004881}
4882
Thomas Falcon8a348452018-05-23 13:38:00 -05004883static int ibmvnic_init(struct ibmvnic_adapter *adapter)
4884{
4885 struct device *dev = &adapter->vdev->dev;
4886 unsigned long timeout = msecs_to_jiffies(30000);
4887 int rc;
4888
4889 adapter->from_passive_init = false;
4890
Thomas Falcon8a348452018-05-23 13:38:00 -05004891 adapter->init_done_rc = 0;
4892 ibmvnic_send_crq_init(adapter);
4893 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
4894 dev_err(dev, "Initialization sequence timed out\n");
4895 return -1;
4896 }
4897
4898 if (adapter->init_done_rc) {
4899 release_crq_queue(adapter);
4900 return adapter->init_done_rc;
4901 }
4902
4903 if (adapter->from_passive_init) {
4904 adapter->state = VNIC_OPEN;
4905 adapter->from_passive_init = false;
4906 return -1;
4907 }
4908
4909 rc = init_sub_crqs(adapter);
4910 if (rc) {
4911 dev_err(dev, "Initialization of sub crqs failed\n");
4912 release_crq_queue(adapter);
4913 return rc;
4914 }
4915
4916 rc = init_sub_crq_irqs(adapter);
4917 if (rc) {
4918 dev_err(dev, "Failed to initialize sub crq irqs\n");
4919 release_crq_queue(adapter);
4920 }
4921
4922 return rc;
4923}
4924
Thomas Falcon40c9db82017-06-12 12:35:04 -05004925static struct device_attribute dev_attr_failover;
4926
Thomas Falcon032c5e82015-12-21 11:26:06 -06004927static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
4928{
4929 struct ibmvnic_adapter *adapter;
4930 struct net_device *netdev;
4931 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004932 int rc;
4933
4934 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
4935 dev->unit_address);
4936
4937 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
4938 VETH_MAC_ADDR, NULL);
4939 if (!mac_addr_p) {
4940 dev_err(&dev->dev,
4941 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
4942 __FILE__, __LINE__);
4943 return 0;
4944 }
4945
4946 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
Thomas Falcond45cc3a2017-12-18 12:52:11 -06004947 IBMVNIC_MAX_QUEUES);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004948 if (!netdev)
4949 return -ENOMEM;
4950
4951 adapter = netdev_priv(netdev);
Nathan Fontenot90c80142017-05-03 14:04:32 -04004952 adapter->state = VNIC_PROBING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06004953 dev_set_drvdata(&dev->dev, netdev);
4954 adapter->vdev = dev;
4955 adapter->netdev = netdev;
4956
4957 ether_addr_copy(adapter->mac_addr, mac_addr_p);
4958 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
4959 netdev->irq = dev->irq;
4960 netdev->netdev_ops = &ibmvnic_netdev_ops;
4961 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
4962 SET_NETDEV_DEV(netdev, &dev->dev);
4963
4964 spin_lock_init(&adapter->stats_lock);
4965
Nathan Fontenoted651a12017-05-03 14:04:38 -04004966 INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset);
Juliet Kim7ed5b312019-09-20 16:11:23 -04004967 INIT_DELAYED_WORK(&adapter->ibmvnic_delayed_reset,
4968 __ibmvnic_delayed_reset);
Nathan Fontenoted651a12017-05-03 14:04:38 -04004969 INIT_LIST_HEAD(&adapter->rwi_list);
Thomas Falcon6c5c7482018-12-10 15:22:22 -06004970 spin_lock_init(&adapter->rwi_lock);
Thomas Falconbbd669a2019-04-04 18:58:26 -05004971 init_completion(&adapter->init_done);
Thomas Falcon070eca92019-11-25 17:12:53 -06004972 init_completion(&adapter->fw_done);
4973 init_completion(&adapter->reset_done);
4974 init_completion(&adapter->stats_done);
Juliet Kim7ed5b312019-09-20 16:11:23 -04004975 clear_bit(0, &adapter->resetting);
Nathan Fontenoted651a12017-05-03 14:04:38 -04004976
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04004977 do {
Nathan Fontenot30f79622018-04-06 18:37:06 -05004978 rc = init_crq_queue(adapter);
4979 if (rc) {
4980 dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n",
4981 rc);
4982 goto ibmvnic_init_fail;
4983 }
4984
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04004985 rc = ibmvnic_init(adapter);
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05004986 if (rc && rc != EAGAIN)
4987 goto ibmvnic_init_fail;
Nathan Fontenot6a2fb0e2017-06-15 14:48:09 -04004988 } while (rc == EAGAIN);
Thomas Falcon032c5e82015-12-21 11:26:06 -06004989
Thomas Falcon07184212018-05-16 15:49:05 -05004990 rc = init_stats_buffers(adapter);
4991 if (rc)
4992 goto ibmvnic_init_fail;
4993
4994 rc = init_stats_token(adapter);
4995 if (rc)
4996 goto ibmvnic_stats_fail;
4997
Thomas Falconf39f0d12017-02-14 10:22:59 -06004998 netdev->mtu = adapter->req_mtu - ETH_HLEN;
John Allenc26eba02017-10-26 16:23:25 -05004999 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
5000 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06005001
Thomas Falcon40c9db82017-06-12 12:35:04 -05005002 rc = device_create_file(&dev->dev, &dev_attr_failover);
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05005003 if (rc)
Thomas Falcon07184212018-05-16 15:49:05 -05005004 goto ibmvnic_dev_file_err;
Thomas Falcon40c9db82017-06-12 12:35:04 -05005005
Mick Tarsele876a8a2017-09-28 13:53:18 -07005006 netif_carrier_off(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06005007 rc = register_netdev(netdev);
5008 if (rc) {
5009 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05005010 goto ibmvnic_register_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -06005011 }
5012 dev_info(&dev->dev, "ibmvnic registered\n");
5013
Nathan Fontenot90c80142017-05-03 14:04:32 -04005014 adapter->state = VNIC_PROBED;
John Allenc26eba02017-10-26 16:23:25 -05005015
5016 adapter->wait_for_reset = false;
5017
Thomas Falcon032c5e82015-12-21 11:26:06 -06005018 return 0;
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05005019
5020ibmvnic_register_fail:
5021 device_remove_file(&dev->dev, &dev_attr_failover);
5022
Thomas Falcon07184212018-05-16 15:49:05 -05005023ibmvnic_dev_file_err:
5024 release_stats_token(adapter);
5025
5026ibmvnic_stats_fail:
5027 release_stats_buffers(adapter);
5028
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05005029ibmvnic_init_fail:
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06005030 release_sub_crqs(adapter, 1);
Nathan Fontenot7c1885a2017-08-08 14:28:45 -05005031 release_crq_queue(adapter);
5032 free_netdev(netdev);
5033
5034 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06005035}
5036
5037static int ibmvnic_remove(struct vio_dev *dev)
5038{
5039 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Nathan Fontenot37489052017-04-19 13:45:04 -04005040 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06005041
Nathan Fontenot90c80142017-05-03 14:04:32 -04005042 adapter->state = VNIC_REMOVING;
Juliet Kima5681e22018-11-19 15:59:22 -06005043 rtnl_lock();
5044 unregister_netdevice(netdev);
Nathan Fontenot37489052017-04-19 13:45:04 -04005045
5046 release_resources(adapter);
Nathan Fontenotd7c0ef32018-02-19 13:30:31 -06005047 release_sub_crqs(adapter, 1);
Nathan Fontenot37489052017-04-19 13:45:04 -04005048 release_crq_queue(adapter);
5049
Thomas Falcon53cc7722018-02-26 18:10:56 -06005050 release_stats_token(adapter);
5051 release_stats_buffers(adapter);
5052
Nathan Fontenot90c80142017-05-03 14:04:32 -04005053 adapter->state = VNIC_REMOVED;
5054
Juliet Kima5681e22018-11-19 15:59:22 -06005055 rtnl_unlock();
Thomas Falcon40c9db82017-06-12 12:35:04 -05005056 device_remove_file(&dev->dev, &dev_attr_failover);
Thomas Falcon032c5e82015-12-21 11:26:06 -06005057 free_netdev(netdev);
5058 dev_set_drvdata(&dev->dev, NULL);
5059
5060 return 0;
5061}
5062
Thomas Falcon40c9db82017-06-12 12:35:04 -05005063static ssize_t failover_store(struct device *dev, struct device_attribute *attr,
5064 const char *buf, size_t count)
5065{
5066 struct net_device *netdev = dev_get_drvdata(dev);
5067 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
5068 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
5069 __be64 session_token;
5070 long rc;
5071
5072 if (!sysfs_streq(buf, "1"))
5073 return -EINVAL;
5074
5075 rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address,
5076 H_GET_SESSION_TOKEN, 0, 0, 0);
5077 if (rc) {
5078 netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n",
5079 rc);
5080 return -EINVAL;
5081 }
5082
5083 session_token = (__be64)retbuf[0];
5084 netdev_dbg(netdev, "Initiating client failover, session id %llx\n",
5085 be64_to_cpu(session_token));
5086 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
5087 H_SESSION_ERR_DETECTED, session_token, 0, 0);
5088 if (rc) {
5089 netdev_err(netdev, "Client initiated failover failed, rc %ld\n",
5090 rc);
5091 return -EINVAL;
5092 }
5093
5094 return count;
5095}
5096
Joe Perches6cbaefb2017-12-19 10:15:09 -08005097static DEVICE_ATTR_WO(failover);
Thomas Falcon40c9db82017-06-12 12:35:04 -05005098
Thomas Falcon032c5e82015-12-21 11:26:06 -06005099static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
5100{
5101 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
5102 struct ibmvnic_adapter *adapter;
5103 struct iommu_table *tbl;
5104 unsigned long ret = 0;
5105 int i;
5106
5107 tbl = get_iommu_table_base(&vdev->dev);
5108
5109 /* netdev inits at probe time along with the structures we need below*/
5110 if (!netdev)
5111 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
5112
5113 adapter = netdev_priv(netdev);
5114
5115 ret += PAGE_SIZE; /* the crq message queue */
Thomas Falcon032c5e82015-12-21 11:26:06 -06005116 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
5117
5118 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
5119 ret += 4 * PAGE_SIZE; /* the scrq message queue */
5120
5121 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
5122 i++)
5123 ret += adapter->rx_pool[i].size *
5124 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
5125
5126 return ret;
5127}
5128
5129static int ibmvnic_resume(struct device *dev)
5130{
5131 struct net_device *netdev = dev_get_drvdata(dev);
5132 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06005133
John Allencb89ba22017-06-19 11:27:53 -05005134 if (adapter->state != VNIC_OPEN)
5135 return 0;
5136
John Allena2488782017-07-24 13:26:06 -05005137 tasklet_schedule(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06005138
5139 return 0;
5140}
5141
Arvind Yadav8c37bc62017-08-17 18:52:54 +05305142static const struct vio_device_id ibmvnic_device_table[] = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06005143 {"network", "IBM,vnic"},
5144 {"", "" }
5145};
5146MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
5147
5148static const struct dev_pm_ops ibmvnic_pm_ops = {
5149 .resume = ibmvnic_resume
5150};
5151
5152static struct vio_driver ibmvnic_driver = {
5153 .id_table = ibmvnic_device_table,
5154 .probe = ibmvnic_probe,
5155 .remove = ibmvnic_remove,
5156 .get_desired_dma = ibmvnic_get_desired_dma,
5157 .name = ibmvnic_driver_name,
5158 .pm = &ibmvnic_pm_ops,
5159};
5160
5161/* module functions */
5162static int __init ibmvnic_module_init(void)
5163{
5164 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
5165 IBMVNIC_DRIVER_VERSION);
5166
5167 return vio_register_driver(&ibmvnic_driver);
5168}
5169
5170static void __exit ibmvnic_module_exit(void)
5171{
5172 vio_unregister_driver(&ibmvnic_driver);
5173}
5174
5175module_init(ibmvnic_module_init);
5176module_exit(ibmvnic_module_exit);