blob: 78fdd4f0e341d4b7acf7640f5057621d8dcb6113 [file] [log] [blame]
Thomas Falcon032c5e82015-12-21 11:26:06 -06001/**************************************************************************/
2/* */
3/* IBM System i and System p Virtual NIC Device Driver */
4/* Copyright (C) 2014 IBM Corp. */
5/* Santiago Leon (santi_leon@yahoo.com) */
6/* Thomas Falcon (tlfalcon@linux.vnet.ibm.com) */
7/* John Allen (jallen@linux.vnet.ibm.com) */
8/* */
9/* This program is free software; you can redistribute it and/or modify */
10/* it under the terms of the GNU General Public License as published by */
11/* the Free Software Foundation; either version 2 of the License, or */
12/* (at your option) any later version. */
13/* */
14/* This program is distributed in the hope that it will be useful, */
15/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17/* GNU General Public License for more details. */
18/* */
19/* You should have received a copy of the GNU General Public License */
20/* along with this program. */
21/* */
22/* This module contains the implementation of a virtual ethernet device */
23/* for use with IBM i/p Series LPAR Linux. It utilizes the logical LAN */
24/* option of the RS/6000 Platform Architecture to interface with virtual */
25/* ethernet NICs that are presented to the partition by the hypervisor. */
26/* */
27/* Messages are passed between the VNIC driver and the VNIC server using */
28/* Command/Response Queues (CRQs) and sub CRQs (sCRQs). CRQs are used to */
29/* issue and receive commands that initiate communication with the server */
30/* on driver initialization. Sub CRQs (sCRQs) are similar to CRQs, but */
31/* are used by the driver to notify the server that a packet is */
32/* ready for transmission or that a buffer has been added to receive a */
33/* packet. Subsequently, sCRQs are used by the server to notify the */
34/* driver that a packet transmission has been completed or that a packet */
35/* has been received and placed in a waiting buffer. */
36/* */
37/* In lieu of a more conventional "on-the-fly" DMA mapping strategy in */
38/* which skbs are DMA mapped and immediately unmapped when the transmit */
39/* or receive has been completed, the VNIC driver is required to use */
40/* "long term mapping". This entails that large, continuous DMA mapped */
41/* buffers are allocated on driver initialization and these buffers are */
42/* then continuously reused to pass skbs to and from the VNIC server. */
43/* */
44/**************************************************************************/
45
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/types.h>
49#include <linux/errno.h>
50#include <linux/completion.h>
51#include <linux/ioport.h>
52#include <linux/dma-mapping.h>
53#include <linux/kernel.h>
54#include <linux/netdevice.h>
55#include <linux/etherdevice.h>
56#include <linux/skbuff.h>
57#include <linux/init.h>
58#include <linux/delay.h>
59#include <linux/mm.h>
60#include <linux/ethtool.h>
61#include <linux/proc_fs.h>
62#include <linux/in.h>
63#include <linux/ip.h>
Thomas Falconad7775d2016-04-01 17:20:34 -050064#include <linux/ipv6.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060065#include <linux/irq.h>
66#include <linux/kthread.h>
67#include <linux/seq_file.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060068#include <linux/interrupt.h>
69#include <net/net_namespace.h>
70#include <asm/hvcall.h>
71#include <linux/atomic.h>
72#include <asm/vio.h>
73#include <asm/iommu.h>
74#include <linux/uaccess.h>
75#include <asm/firmware.h>
Thomas Falcon65dc6892016-07-06 15:35:18 -050076#include <linux/workqueue.h>
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -040077#include <linux/if_vlan.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060078
79#include "ibmvnic.h"
80
81static const char ibmvnic_driver_name[] = "ibmvnic";
82static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
83
Thomas Falcon78b07ac2017-06-01 15:32:34 -050084MODULE_AUTHOR("Santiago Leon");
Thomas Falcon032c5e82015-12-21 11:26:06 -060085MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
86MODULE_LICENSE("GPL");
87MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
88
89static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
90static int ibmvnic_remove(struct vio_dev *);
91static void release_sub_crqs(struct ibmvnic_adapter *);
92static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
93static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
94static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
95static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
96static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
97 union sub_crq *sub_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -050098static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
Thomas Falcon032c5e82015-12-21 11:26:06 -060099static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
100static int enable_scrq_irq(struct ibmvnic_adapter *,
101 struct ibmvnic_sub_crq_queue *);
102static int disable_scrq_irq(struct ibmvnic_adapter *,
103 struct ibmvnic_sub_crq_queue *);
104static int pending_scrq(struct ibmvnic_adapter *,
105 struct ibmvnic_sub_crq_queue *);
106static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
107 struct ibmvnic_sub_crq_queue *);
108static int ibmvnic_poll(struct napi_struct *napi, int data);
109static void send_map_query(struct ibmvnic_adapter *adapter);
110static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
111static void send_request_unmap(struct ibmvnic_adapter *, u8);
John Allenbd0b6722017-03-17 17:13:40 -0500112static void send_login(struct ibmvnic_adapter *adapter);
113static void send_cap_queries(struct ibmvnic_adapter *adapter);
114static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
John Allenea5509f2017-03-17 17:13:43 -0500115static int ibmvnic_init(struct ibmvnic_adapter *);
Nathan Fontenotf9928872017-03-30 02:48:54 -0400116static void release_crq_queue(struct ibmvnic_adapter *);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600117
118struct ibmvnic_stat {
119 char name[ETH_GSTRING_LEN];
120 int offset;
121};
122
123#define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
124 offsetof(struct ibmvnic_statistics, stat))
125#define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
126
127static const struct ibmvnic_stat ibmvnic_stats[] = {
128 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
129 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
130 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
131 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
132 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
133 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
134 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
135 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
136 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
137 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
138 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
139 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
140 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
141 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
142 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
143 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
144 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
145 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
146 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
147 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
148 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
149 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
150};
151
152static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
153 unsigned long length, unsigned long *number,
154 unsigned long *irq)
155{
156 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
157 long rc;
158
159 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
160 *number = retbuf[0];
161 *irq = retbuf[1];
162
163 return rc;
164}
165
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400166static void reset_long_term_buff(struct ibmvnic_adapter *adapter,
167 struct ibmvnic_long_term_buff *ltb)
168{
169 memset(ltb->buff, 0, ltb->size);
170
171 init_completion(&adapter->fw_done);
172 send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id);
173 wait_for_completion(&adapter->fw_done);
174}
175
Thomas Falcon032c5e82015-12-21 11:26:06 -0600176static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
177 struct ibmvnic_long_term_buff *ltb, int size)
178{
179 struct device *dev = &adapter->vdev->dev;
180
181 ltb->size = size;
182 ltb->buff = dma_alloc_coherent(dev, ltb->size, &ltb->addr,
183 GFP_KERNEL);
184
185 if (!ltb->buff) {
186 dev_err(dev, "Couldn't alloc long term buffer\n");
187 return -ENOMEM;
188 }
189 ltb->map_id = adapter->map_id;
190 adapter->map_id++;
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -0500191
192 init_completion(&adapter->fw_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600193 send_request_map(adapter, ltb->addr,
194 ltb->size, ltb->map_id);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600195 wait_for_completion(&adapter->fw_done);
196 return 0;
197}
198
199static void free_long_term_buff(struct ibmvnic_adapter *adapter,
200 struct ibmvnic_long_term_buff *ltb)
201{
202 struct device *dev = &adapter->vdev->dev;
203
Nathan Fontenotc657e322017-03-30 02:49:06 -0400204 if (!ltb->buff)
205 return;
206
Nathan Fontenoted651a12017-05-03 14:04:38 -0400207 if (adapter->reset_reason != VNIC_RESET_FAILOVER &&
208 adapter->reset_reason != VNIC_RESET_MOBILITY)
Thomas Falcondfad09a2016-08-18 11:37:51 -0500209 send_request_unmap(adapter, ltb->map_id);
Brian King59af56c2017-04-19 13:44:41 -0400210 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600211}
212
Thomas Falconf185a492017-05-26 10:30:48 -0400213static void deactivate_rx_pools(struct ibmvnic_adapter *adapter)
214{
215 int i;
216
217 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
218 i++)
219 adapter->rx_pool[i].active = 0;
220}
221
Thomas Falcon032c5e82015-12-21 11:26:06 -0600222static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
223 struct ibmvnic_rx_pool *pool)
224{
225 int count = pool->size - atomic_read(&pool->available);
226 struct device *dev = &adapter->vdev->dev;
227 int buffers_added = 0;
228 unsigned long lpar_rc;
229 union sub_crq sub_crq;
230 struct sk_buff *skb;
231 unsigned int offset;
232 dma_addr_t dma_addr;
233 unsigned char *dst;
234 u64 *handle_array;
235 int shift = 0;
236 int index;
237 int i;
238
Thomas Falconf185a492017-05-26 10:30:48 -0400239 if (!pool->active)
240 return;
241
Thomas Falcon032c5e82015-12-21 11:26:06 -0600242 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
243 be32_to_cpu(adapter->login_rsp_buf->
244 off_rxadd_subcrqs));
245
246 for (i = 0; i < count; ++i) {
247 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
248 if (!skb) {
249 dev_err(dev, "Couldn't replenish rx buff\n");
250 adapter->replenish_no_mem++;
251 break;
252 }
253
254 index = pool->free_map[pool->next_free];
255
256 if (pool->rx_buff[index].skb)
257 dev_err(dev, "Inconsistent free_map!\n");
258
259 /* Copy the skb to the long term mapped DMA buffer */
260 offset = index * pool->buff_size;
261 dst = pool->long_term_buff.buff + offset;
262 memset(dst, 0, pool->buff_size);
263 dma_addr = pool->long_term_buff.addr + offset;
264 pool->rx_buff[index].data = dst;
265
266 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
267 pool->rx_buff[index].dma = dma_addr;
268 pool->rx_buff[index].skb = skb;
269 pool->rx_buff[index].pool_index = pool->index;
270 pool->rx_buff[index].size = pool->buff_size;
271
272 memset(&sub_crq, 0, sizeof(sub_crq));
273 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
274 sub_crq.rx_add.correlator =
275 cpu_to_be64((u64)&pool->rx_buff[index]);
276 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
277 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
278
279 /* The length field of the sCRQ is defined to be 24 bits so the
280 * buffer size needs to be left shifted by a byte before it is
281 * converted to big endian to prevent the last byte from being
282 * truncated.
283 */
284#ifdef __LITTLE_ENDIAN__
285 shift = 8;
286#endif
287 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
288
289 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
290 &sub_crq);
291 if (lpar_rc != H_SUCCESS)
292 goto failure;
293
294 buffers_added++;
295 adapter->replenish_add_buff_success++;
296 pool->next_free = (pool->next_free + 1) % pool->size;
297 }
298 atomic_add(buffers_added, &pool->available);
299 return;
300
301failure:
302 dev_info(dev, "replenish pools failure\n");
303 pool->free_map[pool->next_free] = index;
304 pool->rx_buff[index].skb = NULL;
305 if (!dma_mapping_error(dev, dma_addr))
306 dma_unmap_single(dev, dma_addr, pool->buff_size,
307 DMA_FROM_DEVICE);
308
309 dev_kfree_skb_any(skb);
310 adapter->replenish_add_buff_failure++;
311 atomic_add(buffers_added, &pool->available);
Thomas Falconf185a492017-05-26 10:30:48 -0400312
313 if (lpar_rc == H_CLOSED) {
314 /* Disable buffer pool replenishment and report carrier off if
315 * queue is closed. Firmware guarantees that a signal will
316 * be sent to the driver, triggering a reset.
317 */
318 deactivate_rx_pools(adapter);
319 netif_carrier_off(adapter->netdev);
320 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600321}
322
323static void replenish_pools(struct ibmvnic_adapter *adapter)
324{
325 int i;
326
Thomas Falcon032c5e82015-12-21 11:26:06 -0600327 adapter->replenish_task_cycles++;
328 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
329 i++) {
330 if (adapter->rx_pool[i].active)
331 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
332 }
333}
334
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -0400335static void release_stats_token(struct ibmvnic_adapter *adapter)
336{
337 struct device *dev = &adapter->vdev->dev;
338
339 if (!adapter->stats_token)
340 return;
341
342 dma_unmap_single(dev, adapter->stats_token,
343 sizeof(struct ibmvnic_statistics),
344 DMA_FROM_DEVICE);
345 adapter->stats_token = 0;
346}
347
348static int init_stats_token(struct ibmvnic_adapter *adapter)
349{
350 struct device *dev = &adapter->vdev->dev;
351 dma_addr_t stok;
352
353 stok = dma_map_single(dev, &adapter->stats,
354 sizeof(struct ibmvnic_statistics),
355 DMA_FROM_DEVICE);
356 if (dma_mapping_error(dev, stok)) {
357 dev_err(dev, "Couldn't map stats buffer\n");
358 return -1;
359 }
360
361 adapter->stats_token = stok;
362 return 0;
363}
364
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400365static int reset_rx_pools(struct ibmvnic_adapter *adapter)
366{
367 struct ibmvnic_rx_pool *rx_pool;
368 int rx_scrqs;
369 int i, j;
370
371 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
372 for (i = 0; i < rx_scrqs; i++) {
373 rx_pool = &adapter->rx_pool[i];
374
375 reset_long_term_buff(adapter, &rx_pool->long_term_buff);
376
377 for (j = 0; j < rx_pool->size; j++)
378 rx_pool->free_map[j] = j;
379
380 memset(rx_pool->rx_buff, 0,
381 rx_pool->size * sizeof(struct ibmvnic_rx_buff));
382
383 atomic_set(&rx_pool->available, 0);
384 rx_pool->next_alloc = 0;
385 rx_pool->next_free = 0;
386 }
387
388 return 0;
389}
390
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400391static void release_rx_pools(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600392{
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400393 struct ibmvnic_rx_pool *rx_pool;
394 int rx_scrqs;
395 int i, j;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600396
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400397 if (!adapter->rx_pool)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600398 return;
399
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400400 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
401 for (i = 0; i < rx_scrqs; i++) {
402 rx_pool = &adapter->rx_pool[i];
403
404 kfree(rx_pool->free_map);
405 free_long_term_buff(adapter, &rx_pool->long_term_buff);
406
407 if (!rx_pool->rx_buff)
Nathan Fontenote0ebe9422017-05-03 14:04:50 -0400408 continue;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400409
410 for (j = 0; j < rx_pool->size; j++) {
411 if (rx_pool->rx_buff[j].skb) {
412 dev_kfree_skb_any(rx_pool->rx_buff[i].skb);
413 rx_pool->rx_buff[i].skb = NULL;
414 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600415 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400416
417 kfree(rx_pool->rx_buff);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600418 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400419
420 kfree(adapter->rx_pool);
421 adapter->rx_pool = NULL;
422}
423
424static int init_rx_pools(struct net_device *netdev)
425{
426 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
427 struct device *dev = &adapter->vdev->dev;
428 struct ibmvnic_rx_pool *rx_pool;
429 int rxadd_subcrqs;
430 u64 *size_array;
431 int i, j;
432
433 rxadd_subcrqs =
434 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
435 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
436 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
437
438 adapter->rx_pool = kcalloc(rxadd_subcrqs,
439 sizeof(struct ibmvnic_rx_pool),
440 GFP_KERNEL);
441 if (!adapter->rx_pool) {
442 dev_err(dev, "Failed to allocate rx pools\n");
443 return -1;
444 }
445
446 for (i = 0; i < rxadd_subcrqs; i++) {
447 rx_pool = &adapter->rx_pool[i];
448
449 netdev_dbg(adapter->netdev,
450 "Initializing rx_pool %d, %lld buffs, %lld bytes each\n",
451 i, adapter->req_rx_add_entries_per_subcrq,
452 be64_to_cpu(size_array[i]));
453
454 rx_pool->size = adapter->req_rx_add_entries_per_subcrq;
455 rx_pool->index = i;
456 rx_pool->buff_size = be64_to_cpu(size_array[i]);
457 rx_pool->active = 1;
458
459 rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int),
460 GFP_KERNEL);
461 if (!rx_pool->free_map) {
462 release_rx_pools(adapter);
463 return -1;
464 }
465
466 rx_pool->rx_buff = kcalloc(rx_pool->size,
467 sizeof(struct ibmvnic_rx_buff),
468 GFP_KERNEL);
469 if (!rx_pool->rx_buff) {
470 dev_err(dev, "Couldn't alloc rx buffers\n");
471 release_rx_pools(adapter);
472 return -1;
473 }
474
475 if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
476 rx_pool->size * rx_pool->buff_size)) {
477 release_rx_pools(adapter);
478 return -1;
479 }
480
481 for (j = 0; j < rx_pool->size; ++j)
482 rx_pool->free_map[j] = j;
483
484 atomic_set(&rx_pool->available, 0);
485 rx_pool->next_alloc = 0;
486 rx_pool->next_free = 0;
487 }
488
489 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600490}
491
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400492static int reset_tx_pools(struct ibmvnic_adapter *adapter)
493{
494 struct ibmvnic_tx_pool *tx_pool;
495 int tx_scrqs;
496 int i, j;
497
498 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
499 for (i = 0; i < tx_scrqs; i++) {
500 tx_pool = &adapter->tx_pool[i];
501
502 reset_long_term_buff(adapter, &tx_pool->long_term_buff);
503
504 memset(tx_pool->tx_buff, 0,
505 adapter->req_tx_entries_per_subcrq *
506 sizeof(struct ibmvnic_tx_buff));
507
508 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
509 tx_pool->free_map[j] = j;
510
511 tx_pool->consumer_index = 0;
512 tx_pool->producer_index = 0;
513 }
514
515 return 0;
516}
517
Nathan Fontenotc657e322017-03-30 02:49:06 -0400518static void release_tx_pools(struct ibmvnic_adapter *adapter)
519{
520 struct ibmvnic_tx_pool *tx_pool;
521 int i, tx_scrqs;
522
523 if (!adapter->tx_pool)
524 return;
525
526 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
527 for (i = 0; i < tx_scrqs; i++) {
528 tx_pool = &adapter->tx_pool[i];
529 kfree(tx_pool->tx_buff);
530 free_long_term_buff(adapter, &tx_pool->long_term_buff);
531 kfree(tx_pool->free_map);
532 }
533
534 kfree(adapter->tx_pool);
535 adapter->tx_pool = NULL;
536}
537
538static int init_tx_pools(struct net_device *netdev)
539{
540 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
541 struct device *dev = &adapter->vdev->dev;
542 struct ibmvnic_tx_pool *tx_pool;
543 int tx_subcrqs;
544 int i, j;
545
546 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
547 adapter->tx_pool = kcalloc(tx_subcrqs,
548 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
549 if (!adapter->tx_pool)
550 return -1;
551
552 for (i = 0; i < tx_subcrqs; i++) {
553 tx_pool = &adapter->tx_pool[i];
554 tx_pool->tx_buff = kcalloc(adapter->req_tx_entries_per_subcrq,
555 sizeof(struct ibmvnic_tx_buff),
556 GFP_KERNEL);
557 if (!tx_pool->tx_buff) {
558 dev_err(dev, "tx pool buffer allocation failed\n");
559 release_tx_pools(adapter);
560 return -1;
561 }
562
563 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
564 adapter->req_tx_entries_per_subcrq *
565 adapter->req_mtu)) {
566 release_tx_pools(adapter);
567 return -1;
568 }
569
570 tx_pool->free_map = kcalloc(adapter->req_tx_entries_per_subcrq,
571 sizeof(int), GFP_KERNEL);
572 if (!tx_pool->free_map) {
573 release_tx_pools(adapter);
574 return -1;
575 }
576
577 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
578 tx_pool->free_map[j] = j;
579
580 tx_pool->consumer_index = 0;
581 tx_pool->producer_index = 0;
582 }
583
584 return 0;
585}
586
Nathan Fontenot661a2622017-04-19 13:44:58 -0400587static void release_error_buffers(struct ibmvnic_adapter *adapter)
588{
589 struct device *dev = &adapter->vdev->dev;
590 struct ibmvnic_error_buff *error_buff, *tmp;
591 unsigned long flags;
592
593 spin_lock_irqsave(&adapter->error_list_lock, flags);
594 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) {
595 list_del(&error_buff->list);
596 dma_unmap_single(dev, error_buff->dma, error_buff->len,
597 DMA_FROM_DEVICE);
598 kfree(error_buff->buff);
599 kfree(error_buff);
600 }
601 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
602}
603
John Allend944c3d62017-05-26 10:30:13 -0400604static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter)
605{
606 int i;
607
608 if (adapter->napi_enabled)
609 return;
610
611 for (i = 0; i < adapter->req_rx_queues; i++)
612 napi_enable(&adapter->napi[i]);
613
614 adapter->napi_enabled = true;
615}
616
617static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter)
618{
619 int i;
620
621 if (!adapter->napi_enabled)
622 return;
623
624 for (i = 0; i < adapter->req_rx_queues; i++)
625 napi_disable(&adapter->napi[i]);
626
627 adapter->napi_enabled = false;
628}
629
John Allena57a5d22017-03-17 17:13:41 -0500630static int ibmvnic_login(struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600631{
632 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allenbd0b6722017-03-17 17:13:40 -0500633 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600634 struct device *dev = &adapter->vdev->dev;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600635
John Allenbd0b6722017-03-17 17:13:40 -0500636 do {
637 if (adapter->renegotiate) {
638 adapter->renegotiate = false;
Nathan Fontenotb5108882017-03-30 02:49:18 -0400639 release_sub_crqs(adapter);
John Allenbd0b6722017-03-17 17:13:40 -0500640
641 reinit_completion(&adapter->init_done);
642 send_cap_queries(adapter);
643 if (!wait_for_completion_timeout(&adapter->init_done,
644 timeout)) {
645 dev_err(dev, "Capabilities query timeout\n");
646 return -1;
647 }
648 }
649
650 reinit_completion(&adapter->init_done);
651 send_login(adapter);
652 if (!wait_for_completion_timeout(&adapter->init_done,
653 timeout)) {
654 dev_err(dev, "Login timeout\n");
655 return -1;
656 }
657 } while (adapter->renegotiate);
658
John Allena57a5d22017-03-17 17:13:41 -0500659 return 0;
660}
661
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400662static void release_resources(struct ibmvnic_adapter *adapter)
663{
Nathan Fontenotc7bac002017-05-03 14:04:44 -0400664 int i;
665
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400666 release_tx_pools(adapter);
667 release_rx_pools(adapter);
668
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400669 release_stats_token(adapter);
Nathan Fontenot661a2622017-04-19 13:44:58 -0400670 release_error_buffers(adapter);
Nathan Fontenotc7bac002017-05-03 14:04:44 -0400671
672 if (adapter->napi) {
673 for (i = 0; i < adapter->req_rx_queues; i++) {
674 if (&adapter->napi[i])
675 netif_napi_del(&adapter->napi[i]);
676 }
677 }
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400678}
679
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400680static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
681{
682 struct net_device *netdev = adapter->netdev;
683 unsigned long timeout = msecs_to_jiffies(30000);
684 union ibmvnic_crq crq;
685 bool resend;
686 int rc;
687
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400688 netdev_err(netdev, "setting link state %d\n", link_state);
689 memset(&crq, 0, sizeof(crq));
690 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
691 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
692 crq.logical_link_state.link_state = link_state;
693
694 do {
695 resend = false;
696
697 reinit_completion(&adapter->init_done);
698 rc = ibmvnic_send_crq(adapter, &crq);
699 if (rc) {
700 netdev_err(netdev, "Failed to set link state\n");
701 return rc;
702 }
703
704 if (!wait_for_completion_timeout(&adapter->init_done,
705 timeout)) {
706 netdev_err(netdev, "timeout setting link state\n");
707 return -1;
708 }
709
710 if (adapter->init_done_rc == 1) {
711 /* Partuial success, delay and re-send */
712 mdelay(1000);
713 resend = true;
714 }
715 } while (resend);
716
717 return 0;
718}
719
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400720static int set_real_num_queues(struct net_device *netdev)
721{
722 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
723 int rc;
724
725 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
726 if (rc) {
727 netdev_err(netdev, "failed to set the number of tx queues\n");
728 return rc;
729 }
730
731 rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues);
732 if (rc)
733 netdev_err(netdev, "failed to set the number of rx queues\n");
734
735 return rc;
736}
737
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400738static int init_resources(struct ibmvnic_adapter *adapter)
John Allena57a5d22017-03-17 17:13:41 -0500739{
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400740 struct net_device *netdev = adapter->netdev;
741 int i, rc;
John Allena57a5d22017-03-17 17:13:41 -0500742
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400743 rc = set_real_num_queues(netdev);
744 if (rc)
745 return rc;
John Allenbd0b6722017-03-17 17:13:40 -0500746
747 rc = init_sub_crq_irqs(adapter);
748 if (rc) {
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400749 netdev_err(netdev, "failed to initialize sub crq irqs\n");
John Allenbd0b6722017-03-17 17:13:40 -0500750 return -1;
751 }
752
Nathan Fontenot5d5e84e2017-04-21 15:38:58 -0400753 rc = init_stats_token(adapter);
754 if (rc)
755 return rc;
756
Thomas Falcon032c5e82015-12-21 11:26:06 -0600757 adapter->map_id = 1;
758 adapter->napi = kcalloc(adapter->req_rx_queues,
759 sizeof(struct napi_struct), GFP_KERNEL);
760 if (!adapter->napi)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400761 return -ENOMEM;
762
Thomas Falcon032c5e82015-12-21 11:26:06 -0600763 for (i = 0; i < adapter->req_rx_queues; i++) {
764 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
765 NAPI_POLL_WEIGHT);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600766 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600767
Thomas Falcon032c5e82015-12-21 11:26:06 -0600768 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400769
770 rc = init_rx_pools(netdev);
771 if (rc)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400772 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600773
Nathan Fontenotc657e322017-03-30 02:49:06 -0400774 rc = init_tx_pools(netdev);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400775 return rc;
776}
777
Nathan Fontenoted651a12017-05-03 14:04:38 -0400778static int __ibmvnic_open(struct net_device *netdev)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400779{
780 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -0400781 enum vnic_state prev_state = adapter->state;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400782 int i, rc;
783
Nathan Fontenot90c80142017-05-03 14:04:32 -0400784 adapter->state = VNIC_OPENING;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600785 replenish_pools(adapter);
John Allend944c3d62017-05-26 10:30:13 -0400786 ibmvnic_napi_enable(adapter);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400787
Thomas Falcon032c5e82015-12-21 11:26:06 -0600788 /* We're ready to receive frames, enable the sub-crq interrupts and
789 * set the logical link state to up
790 */
Nathan Fontenoted651a12017-05-03 14:04:38 -0400791 for (i = 0; i < adapter->req_rx_queues; i++) {
792 if (prev_state == VNIC_CLOSED)
793 enable_irq(adapter->rx_scrq[i]->irq);
794 else
795 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
796 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600797
Nathan Fontenoted651a12017-05-03 14:04:38 -0400798 for (i = 0; i < adapter->req_tx_queues; i++) {
799 if (prev_state == VNIC_CLOSED)
800 enable_irq(adapter->tx_scrq[i]->irq);
801 else
802 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
803 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600804
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400805 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400806 if (rc) {
807 for (i = 0; i < adapter->req_rx_queues; i++)
808 napi_disable(&adapter->napi[i]);
809 release_resources(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -0400810 return rc;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400811 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600812
Nathan Fontenoted651a12017-05-03 14:04:38 -0400813 netif_tx_start_all_queues(netdev);
814
815 if (prev_state == VNIC_CLOSED) {
816 for (i = 0; i < adapter->req_rx_queues; i++)
817 napi_schedule(&adapter->napi[i]);
818 }
819
820 adapter->state = VNIC_OPEN;
821 return rc;
822}
823
824static int ibmvnic_open(struct net_device *netdev)
825{
826 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
827 int rc;
828
829 mutex_lock(&adapter->reset_lock);
830
831 if (adapter->state != VNIC_CLOSED) {
832 rc = ibmvnic_login(netdev);
833 if (rc) {
834 mutex_unlock(&adapter->reset_lock);
835 return rc;
836 }
837
838 rc = init_resources(adapter);
839 if (rc) {
840 netdev_err(netdev, "failed to initialize resources\n");
841 release_resources(adapter);
842 mutex_unlock(&adapter->reset_lock);
843 return rc;
844 }
845 }
846
847 rc = __ibmvnic_open(netdev);
848 mutex_unlock(&adapter->reset_lock);
849
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400850 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600851}
852
Nathan Fontenotb41b83e2017-05-03 14:04:56 -0400853static void clean_tx_pools(struct ibmvnic_adapter *adapter)
854{
855 struct ibmvnic_tx_pool *tx_pool;
856 u64 tx_entries;
857 int tx_scrqs;
858 int i, j;
859
860 if (!adapter->tx_pool)
861 return;
862
863 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
864 tx_entries = adapter->req_tx_entries_per_subcrq;
865
866 /* Free any remaining skbs in the tx buffer pools */
867 for (i = 0; i < tx_scrqs; i++) {
868 tx_pool = &adapter->tx_pool[i];
869 if (!tx_pool)
870 continue;
871
872 for (j = 0; j < tx_entries; j++) {
873 if (tx_pool->tx_buff[j].skb) {
874 dev_kfree_skb_any(tx_pool->tx_buff[j].skb);
875 tx_pool->tx_buff[j].skb = NULL;
876 }
877 }
878 }
879}
880
Nathan Fontenoted651a12017-05-03 14:04:38 -0400881static int __ibmvnic_close(struct net_device *netdev)
John Allenea5509f2017-03-17 17:13:43 -0500882{
883 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400884 int rc = 0;
John Allenea5509f2017-03-17 17:13:43 -0500885 int i;
886
Nathan Fontenot90c80142017-05-03 14:04:32 -0400887 adapter->state = VNIC_CLOSING;
Nathan Fontenoted651a12017-05-03 14:04:38 -0400888 netif_tx_stop_all_queues(netdev);
John Allend944c3d62017-05-26 10:30:13 -0400889 ibmvnic_napi_disable(adapter);
Nathan Fontenot46293b92017-05-03 14:05:02 -0400890
891 if (adapter->tx_scrq) {
892 for (i = 0; i < adapter->req_tx_queues; i++)
893 if (adapter->tx_scrq[i]->irq)
894 disable_irq(adapter->tx_scrq[i]->irq);
895 }
896
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400897 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
Nathan Fontenot46293b92017-05-03 14:05:02 -0400898 if (rc)
899 return rc;
900
901 if (adapter->rx_scrq) {
902 for (i = 0; i < adapter->req_rx_queues; i++) {
903 int retries = 10;
904
905 while (pending_scrq(adapter, adapter->rx_scrq[i])) {
906 retries--;
907 mdelay(100);
908
909 if (retries == 0)
910 break;
911 }
912
913 if (adapter->rx_scrq[i]->irq)
914 disable_irq(adapter->rx_scrq[i]->irq);
915 }
916 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600917
Thomas Falcon10f76212017-05-26 10:30:31 -0400918 clean_tx_pools(adapter);
Nathan Fontenot90c80142017-05-03 14:04:32 -0400919 adapter->state = VNIC_CLOSED;
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400920 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600921}
922
Nathan Fontenoted651a12017-05-03 14:04:38 -0400923static int ibmvnic_close(struct net_device *netdev)
924{
925 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
926 int rc;
927
928 mutex_lock(&adapter->reset_lock);
929 rc = __ibmvnic_close(netdev);
930 mutex_unlock(&adapter->reset_lock);
931
932 return rc;
933}
934
Thomas Falconad7775d2016-04-01 17:20:34 -0500935/**
936 * build_hdr_data - creates L2/L3/L4 header data buffer
937 * @hdr_field - bitfield determining needed headers
938 * @skb - socket buffer
939 * @hdr_len - array of header lengths
940 * @tot_len - total length of data
941 *
942 * Reads hdr_field to determine which headers are needed by firmware.
943 * Builds a buffer containing these headers. Saves individual header
944 * lengths and total buffer length to be used to build descriptors.
945 */
946static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
947 int *hdr_len, u8 *hdr_data)
948{
949 int len = 0;
950 u8 *hdr;
951
952 hdr_len[0] = sizeof(struct ethhdr);
953
954 if (skb->protocol == htons(ETH_P_IP)) {
955 hdr_len[1] = ip_hdr(skb)->ihl * 4;
956 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
957 hdr_len[2] = tcp_hdrlen(skb);
958 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
959 hdr_len[2] = sizeof(struct udphdr);
960 } else if (skb->protocol == htons(ETH_P_IPV6)) {
961 hdr_len[1] = sizeof(struct ipv6hdr);
962 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
963 hdr_len[2] = tcp_hdrlen(skb);
964 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
965 hdr_len[2] = sizeof(struct udphdr);
966 }
967
968 memset(hdr_data, 0, 120);
969 if ((hdr_field >> 6) & 1) {
970 hdr = skb_mac_header(skb);
971 memcpy(hdr_data, hdr, hdr_len[0]);
972 len += hdr_len[0];
973 }
974
975 if ((hdr_field >> 5) & 1) {
976 hdr = skb_network_header(skb);
977 memcpy(hdr_data + len, hdr, hdr_len[1]);
978 len += hdr_len[1];
979 }
980
981 if ((hdr_field >> 4) & 1) {
982 hdr = skb_transport_header(skb);
983 memcpy(hdr_data + len, hdr, hdr_len[2]);
984 len += hdr_len[2];
985 }
986 return len;
987}
988
989/**
990 * create_hdr_descs - create header and header extension descriptors
991 * @hdr_field - bitfield determining needed headers
992 * @data - buffer containing header data
993 * @len - length of data buffer
994 * @hdr_len - array of individual header lengths
995 * @scrq_arr - descriptor array
996 *
997 * Creates header and, if needed, header extension descriptors and
998 * places them in a descriptor array, scrq_arr
999 */
1000
1001static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
1002 union sub_crq *scrq_arr)
1003{
1004 union sub_crq hdr_desc;
1005 int tmp_len = len;
1006 u8 *data, *cur;
1007 int tmp;
1008
1009 while (tmp_len > 0) {
1010 cur = hdr_data + len - tmp_len;
1011
1012 memset(&hdr_desc, 0, sizeof(hdr_desc));
1013 if (cur != hdr_data) {
1014 data = hdr_desc.hdr_ext.data;
1015 tmp = tmp_len > 29 ? 29 : tmp_len;
1016 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
1017 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
1018 hdr_desc.hdr_ext.len = tmp;
1019 } else {
1020 data = hdr_desc.hdr.data;
1021 tmp = tmp_len > 24 ? 24 : tmp_len;
1022 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
1023 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
1024 hdr_desc.hdr.len = tmp;
1025 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
1026 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
1027 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
1028 hdr_desc.hdr.flag = hdr_field << 1;
1029 }
1030 memcpy(data, cur, tmp);
1031 tmp_len -= tmp;
1032 *scrq_arr = hdr_desc;
1033 scrq_arr++;
1034 }
1035}
1036
1037/**
1038 * build_hdr_descs_arr - build a header descriptor array
1039 * @skb - socket buffer
1040 * @num_entries - number of descriptors to be sent
1041 * @subcrq - first TX descriptor
1042 * @hdr_field - bit field determining which headers will be sent
1043 *
1044 * This function will build a TX descriptor array with applicable
1045 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
1046 */
1047
1048static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
1049 int *num_entries, u8 hdr_field)
1050{
1051 int hdr_len[3] = {0, 0, 0};
1052 int tot_len, len;
1053 u8 *hdr_data = txbuff->hdr_data;
1054
1055 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
1056 txbuff->hdr_data);
1057 len = tot_len;
1058 len -= 24;
1059 if (len > 0)
1060 num_entries += len % 29 ? len / 29 + 1 : len / 29;
1061 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
1062 txbuff->indir_arr + 1);
1063}
1064
Thomas Falcon032c5e82015-12-21 11:26:06 -06001065static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
1066{
1067 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1068 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -05001069 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001070 struct device *dev = &adapter->vdev->dev;
1071 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001072 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001073 struct ibmvnic_tx_pool *tx_pool;
1074 unsigned int tx_send_failed = 0;
1075 unsigned int tx_map_failed = 0;
1076 unsigned int tx_dropped = 0;
1077 unsigned int tx_packets = 0;
1078 unsigned int tx_bytes = 0;
1079 dma_addr_t data_dma_addr;
1080 struct netdev_queue *txq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001081 unsigned long lpar_rc;
1082 union sub_crq tx_crq;
1083 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -05001084 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001085 unsigned char *dst;
1086 u64 *handle_array;
1087 int index = 0;
1088 int ret = 0;
1089
Nathan Fontenoted651a12017-05-03 14:04:38 -04001090 if (adapter->resetting) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001091 if (!netif_subqueue_stopped(netdev, skb))
1092 netif_stop_subqueue(netdev, queue_num);
1093 dev_kfree_skb_any(skb);
1094
Thomas Falcon032c5e82015-12-21 11:26:06 -06001095 tx_send_failed++;
1096 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001097 ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001098 goto out;
1099 }
1100
Nathan Fontenot161b8a82017-05-03 14:05:08 -04001101 tx_pool = &adapter->tx_pool[queue_num];
1102 tx_scrq = adapter->tx_scrq[queue_num];
1103 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
1104 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
1105 be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs));
1106
Thomas Falcon032c5e82015-12-21 11:26:06 -06001107 index = tx_pool->free_map[tx_pool->consumer_index];
1108 offset = index * adapter->req_mtu;
1109 dst = tx_pool->long_term_buff.buff + offset;
1110 memset(dst, 0, adapter->req_mtu);
1111 skb_copy_from_linear_data(skb, dst, skb->len);
1112 data_dma_addr = tx_pool->long_term_buff.addr + offset;
1113
1114 tx_pool->consumer_index =
1115 (tx_pool->consumer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001116 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001117
1118 tx_buff = &tx_pool->tx_buff[index];
1119 tx_buff->skb = skb;
1120 tx_buff->data_dma[0] = data_dma_addr;
1121 tx_buff->data_len[0] = skb->len;
1122 tx_buff->index = index;
1123 tx_buff->pool_index = queue_num;
1124 tx_buff->last_frag = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001125
1126 memset(&tx_crq, 0, sizeof(tx_crq));
1127 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
1128 tx_crq.v1.type = IBMVNIC_TX_DESC;
1129 tx_crq.v1.n_crq_elem = 1;
1130 tx_crq.v1.n_sge = 1;
1131 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
1132 tx_crq.v1.correlator = cpu_to_be32(index);
1133 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
1134 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
1135 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
1136
1137 if (adapter->vlan_header_insertion) {
1138 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
1139 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
1140 }
1141
1142 if (skb->protocol == htons(ETH_P_IP)) {
1143 if (ip_hdr(skb)->version == 4)
1144 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
1145 else if (ip_hdr(skb)->version == 6)
1146 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
1147
1148 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1149 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
1150 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
1151 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
1152 }
1153
Thomas Falconad7775d2016-04-01 17:20:34 -05001154 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001155 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -05001156 hdrs += 2;
1157 }
1158 /* determine if l2/3/4 headers are sent to firmware */
1159 if ((*hdrs >> 7) & 1 &&
1160 (skb->protocol == htons(ETH_P_IP) ||
1161 skb->protocol == htons(ETH_P_IPV6))) {
1162 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
1163 tx_crq.v1.n_crq_elem = num_entries;
1164 tx_buff->indir_arr[0] = tx_crq;
1165 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
1166 sizeof(tx_buff->indir_arr),
1167 DMA_TO_DEVICE);
1168 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001169 dev_kfree_skb_any(skb);
1170 tx_buff->skb = NULL;
Thomas Falconad7775d2016-04-01 17:20:34 -05001171 if (!firmware_has_feature(FW_FEATURE_CMO))
1172 dev_err(dev, "tx: unable to map descriptor array\n");
1173 tx_map_failed++;
1174 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001175 ret = NETDEV_TX_OK;
Thomas Falconad7775d2016-04-01 17:20:34 -05001176 goto out;
1177 }
John Allen498cd8e2016-04-06 11:49:55 -05001178 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -05001179 (u64)tx_buff->indir_dma,
1180 (u64)num_entries);
1181 } else {
John Allen498cd8e2016-04-06 11:49:55 -05001182 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
1183 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -05001184 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001185 if (lpar_rc != H_SUCCESS) {
1186 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
1187
1188 if (tx_pool->consumer_index == 0)
1189 tx_pool->consumer_index =
Thomas Falcon068d9f92017-03-05 12:18:42 -06001190 adapter->req_tx_entries_per_subcrq - 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001191 else
1192 tx_pool->consumer_index--;
1193
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001194 dev_kfree_skb_any(skb);
1195 tx_buff->skb = NULL;
1196
Thomas Falconb8c80b82017-05-26 10:30:42 -04001197 if (lpar_rc == H_CLOSED) {
1198 /* Disable TX and report carrier off if queue is closed.
1199 * Firmware guarantees that a signal will be sent to the
1200 * driver, triggering a reset or some other action.
1201 */
1202 netif_tx_stop_all_queues(netdev);
1203 netif_carrier_off(netdev);
1204 }
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001205
Thomas Falcon032c5e82015-12-21 11:26:06 -06001206 tx_send_failed++;
1207 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001208 ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001209 goto out;
1210 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001211
Brian King58c8c0c2017-04-19 13:44:47 -04001212 if (atomic_inc_return(&tx_scrq->used)
1213 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001214 netdev_info(netdev, "Stopping queue %d\n", queue_num);
1215 netif_stop_subqueue(netdev, queue_num);
1216 }
1217
Thomas Falcon032c5e82015-12-21 11:26:06 -06001218 tx_packets++;
1219 tx_bytes += skb->len;
1220 txq->trans_start = jiffies;
1221 ret = NETDEV_TX_OK;
1222
1223out:
1224 netdev->stats.tx_dropped += tx_dropped;
1225 netdev->stats.tx_bytes += tx_bytes;
1226 netdev->stats.tx_packets += tx_packets;
1227 adapter->tx_send_failed += tx_send_failed;
1228 adapter->tx_map_failed += tx_map_failed;
1229
1230 return ret;
1231}
1232
1233static void ibmvnic_set_multi(struct net_device *netdev)
1234{
1235 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1236 struct netdev_hw_addr *ha;
1237 union ibmvnic_crq crq;
1238
1239 memset(&crq, 0, sizeof(crq));
1240 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1241 crq.request_capability.cmd = REQUEST_CAPABILITY;
1242
1243 if (netdev->flags & IFF_PROMISC) {
1244 if (!adapter->promisc_supported)
1245 return;
1246 } else {
1247 if (netdev->flags & IFF_ALLMULTI) {
1248 /* Accept all multicast */
1249 memset(&crq, 0, sizeof(crq));
1250 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1251 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1252 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1253 ibmvnic_send_crq(adapter, &crq);
1254 } else if (netdev_mc_empty(netdev)) {
1255 /* Reject all multicast */
1256 memset(&crq, 0, sizeof(crq));
1257 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1258 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1259 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1260 ibmvnic_send_crq(adapter, &crq);
1261 } else {
1262 /* Accept one or more multicast(s) */
1263 netdev_for_each_mc_addr(ha, netdev) {
1264 memset(&crq, 0, sizeof(crq));
1265 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1266 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1267 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1268 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1269 ha->addr);
1270 ibmvnic_send_crq(adapter, &crq);
1271 }
1272 }
1273 }
1274}
1275
1276static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1277{
1278 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1279 struct sockaddr *addr = p;
1280 union ibmvnic_crq crq;
1281
1282 if (!is_valid_ether_addr(addr->sa_data))
1283 return -EADDRNOTAVAIL;
1284
1285 memset(&crq, 0, sizeof(crq));
1286 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1287 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1288 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1289 ibmvnic_send_crq(adapter, &crq);
1290 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1291 return 0;
1292}
1293
Nathan Fontenoted651a12017-05-03 14:04:38 -04001294/**
1295 * do_reset returns zero if we are able to keep processing reset events, or
1296 * non-zero if we hit a fatal error and must halt.
1297 */
1298static int do_reset(struct ibmvnic_adapter *adapter,
1299 struct ibmvnic_rwi *rwi, u32 reset_state)
1300{
1301 struct net_device *netdev = adapter->netdev;
1302 int i, rc;
1303
1304 netif_carrier_off(netdev);
1305 adapter->reset_reason = rwi->reset_reason;
1306
1307 if (rwi->reset_reason == VNIC_RESET_MOBILITY) {
1308 rc = ibmvnic_reenable_crq_queue(adapter);
1309 if (rc)
1310 return 0;
1311 }
1312
1313 rc = __ibmvnic_close(netdev);
1314 if (rc)
1315 return rc;
1316
John Allen8cb31cf2017-05-26 10:30:37 -04001317 if (adapter->reset_reason != VNIC_RESET_NON_FATAL) {
1318 /* remove the closed state so when we call open it appears
1319 * we are coming from the probed state.
1320 */
Nathan Fontenoted651a12017-05-03 14:04:38 -04001321 adapter->state = VNIC_PROBED;
John Allen8cb31cf2017-05-26 10:30:37 -04001322
John Allen8cb31cf2017-05-26 10:30:37 -04001323 rc = ibmvnic_init(adapter);
1324 if (rc)
1325 return 0;
1326
1327 /* If the adapter was in PROBE state prior to the reset,
1328 * exit here.
1329 */
1330 if (reset_state == VNIC_PROBED)
1331 return 0;
1332
1333 rc = ibmvnic_login(netdev);
1334 if (rc) {
1335 adapter->state = VNIC_PROBED;
1336 return 0;
1337 }
1338
Nathan Fontenot8c0543a2017-05-26 10:31:06 -04001339 rc = reset_tx_pools(adapter);
1340 if (rc)
1341 return rc;
1342
1343 rc = reset_rx_pools(adapter);
John Allen8cb31cf2017-05-26 10:30:37 -04001344 if (rc)
1345 return rc;
1346
1347 if (reset_state == VNIC_CLOSED)
1348 return 0;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001349 }
1350
Nathan Fontenoted651a12017-05-03 14:04:38 -04001351 rc = __ibmvnic_open(netdev);
1352 if (rc) {
1353 if (list_empty(&adapter->rwi_list))
1354 adapter->state = VNIC_CLOSED;
1355 else
1356 adapter->state = reset_state;
1357
1358 return 0;
1359 }
1360
1361 netif_carrier_on(netdev);
1362
1363 /* kick napi */
1364 for (i = 0; i < adapter->req_rx_queues; i++)
1365 napi_schedule(&adapter->napi[i]);
1366
Nathan Fontenot61d3e1d2017-06-12 20:47:45 -04001367 if (adapter->reset_reason != VNIC_RESET_FAILOVER)
1368 netdev_notify_peers(netdev);
1369
Nathan Fontenoted651a12017-05-03 14:04:38 -04001370 return 0;
1371}
1372
1373static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter)
1374{
1375 struct ibmvnic_rwi *rwi;
1376
1377 mutex_lock(&adapter->rwi_lock);
1378
1379 if (!list_empty(&adapter->rwi_list)) {
1380 rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi,
1381 list);
1382 list_del(&rwi->list);
1383 } else {
1384 rwi = NULL;
1385 }
1386
1387 mutex_unlock(&adapter->rwi_lock);
1388 return rwi;
1389}
1390
1391static void free_all_rwi(struct ibmvnic_adapter *adapter)
1392{
1393 struct ibmvnic_rwi *rwi;
1394
1395 rwi = get_next_rwi(adapter);
1396 while (rwi) {
1397 kfree(rwi);
1398 rwi = get_next_rwi(adapter);
1399 }
1400}
1401
1402static void __ibmvnic_reset(struct work_struct *work)
1403{
1404 struct ibmvnic_rwi *rwi;
1405 struct ibmvnic_adapter *adapter;
1406 struct net_device *netdev;
1407 u32 reset_state;
1408 int rc;
1409
1410 adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);
1411 netdev = adapter->netdev;
1412
1413 mutex_lock(&adapter->reset_lock);
1414 adapter->resetting = true;
1415 reset_state = adapter->state;
1416
1417 rwi = get_next_rwi(adapter);
1418 while (rwi) {
1419 rc = do_reset(adapter, rwi, reset_state);
1420 kfree(rwi);
1421 if (rc)
1422 break;
1423
1424 rwi = get_next_rwi(adapter);
1425 }
1426
1427 if (rc) {
1428 free_all_rwi(adapter);
Wei Yongjun6d0af072017-05-18 15:24:52 +00001429 mutex_unlock(&adapter->reset_lock);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001430 return;
1431 }
1432
1433 adapter->resetting = false;
1434 mutex_unlock(&adapter->reset_lock);
1435}
1436
1437static void ibmvnic_reset(struct ibmvnic_adapter *adapter,
1438 enum ibmvnic_reset_reason reason)
1439{
1440 struct ibmvnic_rwi *rwi, *tmp;
1441 struct net_device *netdev = adapter->netdev;
1442 struct list_head *entry;
1443
1444 if (adapter->state == VNIC_REMOVING ||
1445 adapter->state == VNIC_REMOVED) {
1446 netdev_dbg(netdev, "Adapter removing, skipping reset\n");
1447 return;
1448 }
1449
1450 mutex_lock(&adapter->rwi_lock);
1451
1452 list_for_each(entry, &adapter->rwi_list) {
1453 tmp = list_entry(entry, struct ibmvnic_rwi, list);
1454 if (tmp->reset_reason == reason) {
1455 netdev_err(netdev, "Matching reset found, skipping\n");
1456 mutex_unlock(&adapter->rwi_lock);
1457 return;
1458 }
1459 }
1460
1461 rwi = kzalloc(sizeof(*rwi), GFP_KERNEL);
1462 if (!rwi) {
1463 mutex_unlock(&adapter->rwi_lock);
1464 ibmvnic_close(netdev);
1465 return;
1466 }
1467
1468 rwi->reset_reason = reason;
1469 list_add_tail(&rwi->list, &adapter->rwi_list);
1470 mutex_unlock(&adapter->rwi_lock);
1471 schedule_work(&adapter->ibmvnic_reset);
1472}
1473
Thomas Falcon032c5e82015-12-21 11:26:06 -06001474static void ibmvnic_tx_timeout(struct net_device *dev)
1475{
1476 struct ibmvnic_adapter *adapter = netdev_priv(dev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001477
Nathan Fontenoted651a12017-05-03 14:04:38 -04001478 ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001479}
1480
1481static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
1482 struct ibmvnic_rx_buff *rx_buff)
1483{
1484 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
1485
1486 rx_buff->skb = NULL;
1487
1488 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
1489 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
1490
1491 atomic_dec(&pool->available);
1492}
1493
1494static int ibmvnic_poll(struct napi_struct *napi, int budget)
1495{
1496 struct net_device *netdev = napi->dev;
1497 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1498 int scrq_num = (int)(napi - adapter->napi);
1499 int frames_processed = 0;
Nathan Fontenot152ce472017-05-26 10:30:54 -04001500
1501 if (adapter->resetting)
1502 return 0;
1503
Thomas Falcon032c5e82015-12-21 11:26:06 -06001504restart_poll:
1505 while (frames_processed < budget) {
1506 struct sk_buff *skb;
1507 struct ibmvnic_rx_buff *rx_buff;
1508 union sub_crq *next;
1509 u32 length;
1510 u16 offset;
1511 u8 flags = 0;
1512
1513 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
1514 break;
1515 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
1516 rx_buff =
1517 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
1518 rx_comp.correlator);
1519 /* do error checking */
1520 if (next->rx_comp.rc) {
1521 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
1522 /* free the entry */
1523 next->rx_comp.first = 0;
1524 remove_buff_from_pool(adapter, rx_buff);
Nathan Fontenotca05e312017-05-03 14:05:14 -04001525 continue;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001526 }
1527
1528 length = be32_to_cpu(next->rx_comp.len);
1529 offset = be16_to_cpu(next->rx_comp.off_frame_data);
1530 flags = next->rx_comp.flags;
1531 skb = rx_buff->skb;
1532 skb_copy_to_linear_data(skb, rx_buff->data + offset,
1533 length);
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04001534
1535 /* VLAN Header has been stripped by the system firmware and
1536 * needs to be inserted by the driver
1537 */
1538 if (adapter->rx_vlan_header_insertion &&
1539 (flags & IBMVNIC_VLAN_STRIPPED))
1540 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
1541 ntohs(next->rx_comp.vlan_tci));
1542
Thomas Falcon032c5e82015-12-21 11:26:06 -06001543 /* free the entry */
1544 next->rx_comp.first = 0;
1545 remove_buff_from_pool(adapter, rx_buff);
1546
1547 skb_put(skb, length);
1548 skb->protocol = eth_type_trans(skb, netdev);
Thomas Falcon94ca3052017-05-03 14:05:20 -04001549 skb_record_rx_queue(skb, scrq_num);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001550
1551 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
1552 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
1553 skb->ip_summed = CHECKSUM_UNNECESSARY;
1554 }
1555
1556 length = skb->len;
1557 napi_gro_receive(napi, skb); /* send it up */
1558 netdev->stats.rx_packets++;
1559 netdev->stats.rx_bytes += length;
1560 frames_processed++;
1561 }
Nathan Fontenot152ce472017-05-26 10:30:54 -04001562
1563 if (adapter->state != VNIC_CLOSING)
1564 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001565
1566 if (frames_processed < budget) {
1567 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08001568 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001569 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1570 napi_reschedule(napi)) {
1571 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1572 goto restart_poll;
1573 }
1574 }
1575 return frames_processed;
1576}
1577
1578#ifdef CONFIG_NET_POLL_CONTROLLER
1579static void ibmvnic_netpoll_controller(struct net_device *dev)
1580{
1581 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1582 int i;
1583
1584 replenish_pools(netdev_priv(dev));
1585 for (i = 0; i < adapter->req_rx_queues; i++)
1586 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1587 adapter->rx_scrq[i]);
1588}
1589#endif
1590
John Allen3a807b72017-06-06 16:55:52 -05001591static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu)
1592{
1593 return -EOPNOTSUPP;
1594}
1595
Thomas Falcon032c5e82015-12-21 11:26:06 -06001596static const struct net_device_ops ibmvnic_netdev_ops = {
1597 .ndo_open = ibmvnic_open,
1598 .ndo_stop = ibmvnic_close,
1599 .ndo_start_xmit = ibmvnic_xmit,
1600 .ndo_set_rx_mode = ibmvnic_set_multi,
1601 .ndo_set_mac_address = ibmvnic_set_mac,
1602 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001603 .ndo_tx_timeout = ibmvnic_tx_timeout,
1604#ifdef CONFIG_NET_POLL_CONTROLLER
1605 .ndo_poll_controller = ibmvnic_netpoll_controller,
1606#endif
John Allen3a807b72017-06-06 16:55:52 -05001607 .ndo_change_mtu = ibmvnic_change_mtu,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001608};
1609
1610/* ethtool functions */
1611
Philippe Reynes8a433792017-01-07 22:37:29 +01001612static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1613 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001614{
Philippe Reynes8a433792017-01-07 22:37:29 +01001615 u32 supported, advertising;
1616
1617 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001618 SUPPORTED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001619 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001620 ADVERTISED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001621 cmd->base.speed = SPEED_1000;
1622 cmd->base.duplex = DUPLEX_FULL;
1623 cmd->base.port = PORT_FIBRE;
1624 cmd->base.phy_address = 0;
1625 cmd->base.autoneg = AUTONEG_ENABLE;
1626
1627 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1628 supported);
1629 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1630 advertising);
1631
Thomas Falcon032c5e82015-12-21 11:26:06 -06001632 return 0;
1633}
1634
1635static void ibmvnic_get_drvinfo(struct net_device *dev,
1636 struct ethtool_drvinfo *info)
1637{
1638 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1639 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1640}
1641
1642static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1643{
1644 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1645
1646 return adapter->msg_enable;
1647}
1648
1649static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1650{
1651 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1652
1653 adapter->msg_enable = data;
1654}
1655
1656static u32 ibmvnic_get_link(struct net_device *netdev)
1657{
1658 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1659
1660 /* Don't need to send a query because we request a logical link up at
1661 * init and then we wait for link state indications
1662 */
1663 return adapter->logical_link_state;
1664}
1665
1666static void ibmvnic_get_ringparam(struct net_device *netdev,
1667 struct ethtool_ringparam *ring)
1668{
1669 ring->rx_max_pending = 0;
1670 ring->tx_max_pending = 0;
1671 ring->rx_mini_max_pending = 0;
1672 ring->rx_jumbo_max_pending = 0;
1673 ring->rx_pending = 0;
1674 ring->tx_pending = 0;
1675 ring->rx_mini_pending = 0;
1676 ring->rx_jumbo_pending = 0;
1677}
1678
1679static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1680{
1681 int i;
1682
1683 if (stringset != ETH_SS_STATS)
1684 return;
1685
1686 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1687 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1688}
1689
1690static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1691{
1692 switch (sset) {
1693 case ETH_SS_STATS:
1694 return ARRAY_SIZE(ibmvnic_stats);
1695 default:
1696 return -EOPNOTSUPP;
1697 }
1698}
1699
1700static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1701 struct ethtool_stats *stats, u64 *data)
1702{
1703 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1704 union ibmvnic_crq crq;
1705 int i;
1706
1707 memset(&crq, 0, sizeof(crq));
1708 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1709 crq.request_statistics.cmd = REQUEST_STATISTICS;
1710 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1711 crq.request_statistics.len =
1712 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06001713
1714 /* Wait for data to be written */
1715 init_completion(&adapter->stats_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05001716 ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001717 wait_for_completion(&adapter->stats_done);
1718
1719 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1720 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1721}
1722
1723static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001724 .get_drvinfo = ibmvnic_get_drvinfo,
1725 .get_msglevel = ibmvnic_get_msglevel,
1726 .set_msglevel = ibmvnic_set_msglevel,
1727 .get_link = ibmvnic_get_link,
1728 .get_ringparam = ibmvnic_get_ringparam,
1729 .get_strings = ibmvnic_get_strings,
1730 .get_sset_count = ibmvnic_get_sset_count,
1731 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01001732 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001733};
1734
1735/* Routines for managing CRQs/sCRQs */
1736
Nathan Fontenot57a49432017-05-26 10:31:12 -04001737static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter,
1738 struct ibmvnic_sub_crq_queue *scrq)
1739{
1740 int rc;
1741
1742 if (scrq->irq) {
1743 free_irq(scrq->irq, scrq);
1744 irq_dispose_mapping(scrq->irq);
1745 scrq->irq = 0;
1746 }
1747
1748 memset(scrq->msgs, 0, 2 * PAGE_SIZE);
1749 scrq->cur = 0;
1750
1751 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1752 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1753 return rc;
1754}
1755
1756static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter)
1757{
1758 int i, rc;
1759
1760 for (i = 0; i < adapter->req_tx_queues; i++) {
1761 rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1762 if (rc)
1763 return rc;
1764 }
1765
1766 for (i = 0; i < adapter->req_rx_queues; i++) {
1767 rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1768 if (rc)
1769 return rc;
1770 }
1771
1772 rc = init_sub_crq_irqs(adapter);
1773 return rc;
1774}
1775
Thomas Falcon032c5e82015-12-21 11:26:06 -06001776static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1777 struct ibmvnic_sub_crq_queue *scrq)
1778{
1779 struct device *dev = &adapter->vdev->dev;
1780 long rc;
1781
1782 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1783
1784 /* Close the sub-crqs */
1785 do {
1786 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1787 adapter->vdev->unit_address,
1788 scrq->crq_num);
1789 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1790
Thomas Falconffa73852017-04-19 13:44:29 -04001791 if (rc) {
1792 netdev_err(adapter->netdev,
1793 "Failed to release sub-CRQ %16lx, rc = %ld\n",
1794 scrq->crq_num, rc);
1795 }
1796
Thomas Falcon032c5e82015-12-21 11:26:06 -06001797 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1798 DMA_BIDIRECTIONAL);
1799 free_pages((unsigned long)scrq->msgs, 2);
1800 kfree(scrq);
1801}
1802
1803static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1804 *adapter)
1805{
1806 struct device *dev = &adapter->vdev->dev;
1807 struct ibmvnic_sub_crq_queue *scrq;
1808 int rc;
1809
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04001810 scrq = kzalloc(sizeof(*scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001811 if (!scrq)
1812 return NULL;
1813
Nathan Fontenot7f7adc52017-04-19 13:45:16 -04001814 scrq->msgs =
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04001815 (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001816 if (!scrq->msgs) {
1817 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1818 goto zero_page_failed;
1819 }
1820
1821 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1822 DMA_BIDIRECTIONAL);
1823 if (dma_mapping_error(dev, scrq->msg_token)) {
1824 dev_warn(dev, "Couldn't map crq queue messages page\n");
1825 goto map_failed;
1826 }
1827
1828 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1829 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1830
1831 if (rc == H_RESOURCE)
1832 rc = ibmvnic_reset_crq(adapter);
1833
1834 if (rc == H_CLOSED) {
1835 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1836 } else if (rc) {
1837 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1838 goto reg_failed;
1839 }
1840
Thomas Falcon032c5e82015-12-21 11:26:06 -06001841 scrq->adapter = adapter;
1842 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001843 spin_lock_init(&scrq->lock);
1844
1845 netdev_dbg(adapter->netdev,
1846 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1847 scrq->crq_num, scrq->hw_irq, scrq->irq);
1848
1849 return scrq;
1850
Thomas Falcon032c5e82015-12-21 11:26:06 -06001851reg_failed:
1852 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1853 DMA_BIDIRECTIONAL);
1854map_failed:
1855 free_pages((unsigned long)scrq->msgs, 2);
1856zero_page_failed:
1857 kfree(scrq);
1858
1859 return NULL;
1860}
1861
1862static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1863{
1864 int i;
1865
1866 if (adapter->tx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001867 for (i = 0; i < adapter->req_tx_queues; i++) {
1868 if (!adapter->tx_scrq[i])
1869 continue;
1870
1871 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001872 free_irq(adapter->tx_scrq[i]->irq,
1873 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001874 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001875 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001876 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001877
1878 release_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1879 }
1880
Nathan Fontenot9501df32017-03-15 23:38:07 -04001881 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001882 adapter->tx_scrq = NULL;
1883 }
1884
1885 if (adapter->rx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001886 for (i = 0; i < adapter->req_rx_queues; i++) {
1887 if (!adapter->rx_scrq[i])
1888 continue;
1889
1890 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001891 free_irq(adapter->rx_scrq[i]->irq,
1892 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001893 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001894 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001895 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001896
1897 release_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1898 }
1899
Nathan Fontenot9501df32017-03-15 23:38:07 -04001900 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001901 adapter->rx_scrq = NULL;
1902 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001903}
1904
1905static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1906 struct ibmvnic_sub_crq_queue *scrq)
1907{
1908 struct device *dev = &adapter->vdev->dev;
1909 unsigned long rc;
1910
1911 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1912 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1913 if (rc)
1914 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1915 scrq->hw_irq, rc);
1916 return rc;
1917}
1918
1919static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1920 struct ibmvnic_sub_crq_queue *scrq)
1921{
1922 struct device *dev = &adapter->vdev->dev;
1923 unsigned long rc;
1924
1925 if (scrq->hw_irq > 0x100000000ULL) {
1926 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1927 return 1;
1928 }
1929
1930 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1931 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1932 if (rc)
1933 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1934 scrq->hw_irq, rc);
1935 return rc;
1936}
1937
1938static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1939 struct ibmvnic_sub_crq_queue *scrq)
1940{
1941 struct device *dev = &adapter->vdev->dev;
1942 struct ibmvnic_tx_buff *txbuff;
1943 union sub_crq *next;
1944 int index;
1945 int i, j;
Thomas Falconad7775d2016-04-01 17:20:34 -05001946 u8 first;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001947
1948restart_loop:
1949 while (pending_scrq(adapter, scrq)) {
1950 unsigned int pool = scrq->pool_index;
1951
1952 next = ibmvnic_next_scrq(adapter, scrq);
1953 for (i = 0; i < next->tx_comp.num_comps; i++) {
1954 if (next->tx_comp.rcs[i]) {
1955 dev_err(dev, "tx error %x\n",
1956 next->tx_comp.rcs[i]);
1957 continue;
1958 }
1959 index = be32_to_cpu(next->tx_comp.correlators[i]);
1960 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1961
1962 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1963 if (!txbuff->data_dma[j])
1964 continue;
1965
1966 txbuff->data_dma[j] = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001967 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001968 /* if sub_crq was sent indirectly */
1969 first = txbuff->indir_arr[0].generic.first;
1970 if (first == IBMVNIC_CRQ_CMD) {
1971 dma_unmap_single(dev, txbuff->indir_dma,
1972 sizeof(txbuff->indir_arr),
1973 DMA_TO_DEVICE);
1974 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001975
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001976 if (txbuff->last_frag) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001977 dev_kfree_skb_any(txbuff->skb);
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04001978 txbuff->skb = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001979 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001980
1981 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1982 producer_index] = index;
1983 adapter->tx_pool[pool].producer_index =
1984 (adapter->tx_pool[pool].producer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001985 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001986 }
1987 /* remove tx_comp scrq*/
1988 next->tx_comp.first = 0;
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04001989
1990 if (atomic_sub_return(next->tx_comp.num_comps, &scrq->used) <=
1991 (adapter->req_tx_entries_per_subcrq / 2) &&
1992 __netif_subqueue_stopped(adapter->netdev,
1993 scrq->pool_index)) {
1994 netif_wake_subqueue(adapter->netdev, scrq->pool_index);
1995 netdev_info(adapter->netdev, "Started queue %d\n",
1996 scrq->pool_index);
1997 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001998 }
1999
2000 enable_scrq_irq(adapter, scrq);
2001
2002 if (pending_scrq(adapter, scrq)) {
2003 disable_scrq_irq(adapter, scrq);
2004 goto restart_loop;
2005 }
2006
2007 return 0;
2008}
2009
2010static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
2011{
2012 struct ibmvnic_sub_crq_queue *scrq = instance;
2013 struct ibmvnic_adapter *adapter = scrq->adapter;
2014
2015 disable_scrq_irq(adapter, scrq);
2016 ibmvnic_complete_tx(adapter, scrq);
2017
2018 return IRQ_HANDLED;
2019}
2020
2021static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
2022{
2023 struct ibmvnic_sub_crq_queue *scrq = instance;
2024 struct ibmvnic_adapter *adapter = scrq->adapter;
2025
2026 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
2027 disable_scrq_irq(adapter, scrq);
2028 __napi_schedule(&adapter->napi[scrq->scrq_num]);
2029 }
2030
2031 return IRQ_HANDLED;
2032}
2033
Thomas Falconea22d512016-07-06 15:35:17 -05002034static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
2035{
2036 struct device *dev = &adapter->vdev->dev;
2037 struct ibmvnic_sub_crq_queue *scrq;
2038 int i = 0, j = 0;
2039 int rc = 0;
2040
2041 for (i = 0; i < adapter->req_tx_queues; i++) {
2042 scrq = adapter->tx_scrq[i];
2043 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
2044
Michael Ellerman99c17902016-09-10 19:59:05 +10002045 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05002046 rc = -EINVAL;
2047 dev_err(dev, "Error mapping irq\n");
2048 goto req_tx_irq_failed;
2049 }
2050
2051 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
2052 0, "ibmvnic_tx", scrq);
2053
2054 if (rc) {
2055 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
2056 scrq->irq, rc);
2057 irq_dispose_mapping(scrq->irq);
2058 goto req_rx_irq_failed;
2059 }
2060 }
2061
2062 for (i = 0; i < adapter->req_rx_queues; i++) {
2063 scrq = adapter->rx_scrq[i];
2064 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10002065 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05002066 rc = -EINVAL;
2067 dev_err(dev, "Error mapping irq\n");
2068 goto req_rx_irq_failed;
2069 }
2070 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
2071 0, "ibmvnic_rx", scrq);
2072 if (rc) {
2073 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
2074 scrq->irq, rc);
2075 irq_dispose_mapping(scrq->irq);
2076 goto req_rx_irq_failed;
2077 }
2078 }
2079 return rc;
2080
2081req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002082 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05002083 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
2084 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002085 }
Thomas Falconea22d512016-07-06 15:35:17 -05002086 i = adapter->req_tx_queues;
2087req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002088 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05002089 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
2090 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002091 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04002092 release_sub_crqs(adapter);
Thomas Falconea22d512016-07-06 15:35:17 -05002093 return rc;
2094}
2095
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002096static int init_sub_crqs(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002097{
2098 struct device *dev = &adapter->vdev->dev;
2099 struct ibmvnic_sub_crq_queue **allqueues;
2100 int registered_queues = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002101 int total_queues;
2102 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05002103 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002104
Thomas Falcon032c5e82015-12-21 11:26:06 -06002105 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
2106
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002107 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002108 if (!allqueues)
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002109 return -1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002110
2111 for (i = 0; i < total_queues; i++) {
2112 allqueues[i] = init_sub_crq_queue(adapter);
2113 if (!allqueues[i]) {
2114 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
2115 break;
2116 }
2117 registered_queues++;
2118 }
2119
2120 /* Make sure we were able to register the minimum number of queues */
2121 if (registered_queues <
2122 adapter->min_tx_queues + adapter->min_rx_queues) {
2123 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
2124 goto tx_failed;
2125 }
2126
2127 /* Distribute the failed allocated queues*/
2128 for (i = 0; i < total_queues - registered_queues + more ; i++) {
2129 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
2130 switch (i % 3) {
2131 case 0:
2132 if (adapter->req_rx_queues > adapter->min_rx_queues)
2133 adapter->req_rx_queues--;
2134 else
2135 more++;
2136 break;
2137 case 1:
2138 if (adapter->req_tx_queues > adapter->min_tx_queues)
2139 adapter->req_tx_queues--;
2140 else
2141 more++;
2142 break;
2143 }
2144 }
2145
2146 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002147 sizeof(*adapter->tx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002148 if (!adapter->tx_scrq)
2149 goto tx_failed;
2150
2151 for (i = 0; i < adapter->req_tx_queues; i++) {
2152 adapter->tx_scrq[i] = allqueues[i];
2153 adapter->tx_scrq[i]->pool_index = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002154 }
2155
2156 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002157 sizeof(*adapter->rx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002158 if (!adapter->rx_scrq)
2159 goto rx_failed;
2160
2161 for (i = 0; i < adapter->req_rx_queues; i++) {
2162 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
2163 adapter->rx_scrq[i]->scrq_num = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002164 }
2165
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002166 kfree(allqueues);
2167 return 0;
2168
2169rx_failed:
2170 kfree(adapter->tx_scrq);
2171 adapter->tx_scrq = NULL;
2172tx_failed:
2173 for (i = 0; i < registered_queues; i++)
2174 release_sub_crq_queue(adapter, allqueues[i]);
2175 kfree(allqueues);
2176 return -1;
2177}
2178
2179static void ibmvnic_send_req_caps(struct ibmvnic_adapter *adapter, int retry)
2180{
2181 struct device *dev = &adapter->vdev->dev;
2182 union ibmvnic_crq crq;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002183
2184 if (!retry) {
2185 /* Sub-CRQ entries are 32 byte long */
2186 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
2187
2188 if (adapter->min_tx_entries_per_subcrq > entries_page ||
2189 adapter->min_rx_add_entries_per_subcrq > entries_page) {
2190 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
2191 return;
2192 }
2193
2194 /* Get the minimum between the queried max and the entries
2195 * that fit in our PAGE_SIZE
2196 */
2197 adapter->req_tx_entries_per_subcrq =
2198 adapter->max_tx_entries_per_subcrq > entries_page ?
2199 entries_page : adapter->max_tx_entries_per_subcrq;
2200 adapter->req_rx_add_entries_per_subcrq =
2201 adapter->max_rx_add_entries_per_subcrq > entries_page ?
2202 entries_page : adapter->max_rx_add_entries_per_subcrq;
2203
2204 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
2205 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
2206 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
2207
2208 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
2209 }
2210
Thomas Falcon032c5e82015-12-21 11:26:06 -06002211 memset(&crq, 0, sizeof(crq));
2212 crq.request_capability.first = IBMVNIC_CRQ_CMD;
2213 crq.request_capability.cmd = REQUEST_CAPABILITY;
2214
2215 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002216 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002217 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002218 ibmvnic_send_crq(adapter, &crq);
2219
2220 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002221 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002222 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002223 ibmvnic_send_crq(adapter, &crq);
2224
2225 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002226 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002227 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002228 ibmvnic_send_crq(adapter, &crq);
2229
2230 crq.request_capability.capability =
2231 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
2232 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06002233 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06002234 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002235 ibmvnic_send_crq(adapter, &crq);
2236
2237 crq.request_capability.capability =
2238 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
2239 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06002240 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06002241 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002242 ibmvnic_send_crq(adapter, &crq);
2243
2244 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06002245 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06002246 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002247 ibmvnic_send_crq(adapter, &crq);
2248
2249 if (adapter->netdev->flags & IFF_PROMISC) {
2250 if (adapter->promisc_supported) {
2251 crq.request_capability.capability =
2252 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06002253 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06002254 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002255 ibmvnic_send_crq(adapter, &crq);
2256 }
2257 } else {
2258 crq.request_capability.capability =
2259 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06002260 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06002261 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002262 ibmvnic_send_crq(adapter, &crq);
2263 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002264}
2265
2266static int pending_scrq(struct ibmvnic_adapter *adapter,
2267 struct ibmvnic_sub_crq_queue *scrq)
2268{
2269 union sub_crq *entry = &scrq->msgs[scrq->cur];
2270
Nathan Fontenot90c80142017-05-03 14:04:32 -04002271 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP ||
2272 adapter->state == VNIC_CLOSING)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002273 return 1;
2274 else
2275 return 0;
2276}
2277
2278static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
2279 struct ibmvnic_sub_crq_queue *scrq)
2280{
2281 union sub_crq *entry;
2282 unsigned long flags;
2283
2284 spin_lock_irqsave(&scrq->lock, flags);
2285 entry = &scrq->msgs[scrq->cur];
2286 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
2287 if (++scrq->cur == scrq->size)
2288 scrq->cur = 0;
2289 } else {
2290 entry = NULL;
2291 }
2292 spin_unlock_irqrestore(&scrq->lock, flags);
2293
2294 return entry;
2295}
2296
2297static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
2298{
2299 struct ibmvnic_crq_queue *queue = &adapter->crq;
2300 union ibmvnic_crq *crq;
2301
2302 crq = &queue->msgs[queue->cur];
2303 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
2304 if (++queue->cur == queue->size)
2305 queue->cur = 0;
2306 } else {
2307 crq = NULL;
2308 }
2309
2310 return crq;
2311}
2312
2313static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
2314 union sub_crq *sub_crq)
2315{
2316 unsigned int ua = adapter->vdev->unit_address;
2317 struct device *dev = &adapter->vdev->dev;
2318 u64 *u64_crq = (u64 *)sub_crq;
2319 int rc;
2320
2321 netdev_dbg(adapter->netdev,
2322 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
2323 (unsigned long int)cpu_to_be64(remote_handle),
2324 (unsigned long int)cpu_to_be64(u64_crq[0]),
2325 (unsigned long int)cpu_to_be64(u64_crq[1]),
2326 (unsigned long int)cpu_to_be64(u64_crq[2]),
2327 (unsigned long int)cpu_to_be64(u64_crq[3]));
2328
2329 /* Make sure the hypervisor sees the complete request */
2330 mb();
2331
2332 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
2333 cpu_to_be64(remote_handle),
2334 cpu_to_be64(u64_crq[0]),
2335 cpu_to_be64(u64_crq[1]),
2336 cpu_to_be64(u64_crq[2]),
2337 cpu_to_be64(u64_crq[3]));
2338
2339 if (rc) {
2340 if (rc == H_CLOSED)
2341 dev_warn(dev, "CRQ Queue closed\n");
2342 dev_err(dev, "Send error (rc=%d)\n", rc);
2343 }
2344
2345 return rc;
2346}
2347
Thomas Falconad7775d2016-04-01 17:20:34 -05002348static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
2349 u64 remote_handle, u64 ioba, u64 num_entries)
2350{
2351 unsigned int ua = adapter->vdev->unit_address;
2352 struct device *dev = &adapter->vdev->dev;
2353 int rc;
2354
2355 /* Make sure the hypervisor sees the complete request */
2356 mb();
2357 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
2358 cpu_to_be64(remote_handle),
2359 ioba, num_entries);
2360
2361 if (rc) {
2362 if (rc == H_CLOSED)
2363 dev_warn(dev, "CRQ Queue closed\n");
2364 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
2365 }
2366
2367 return rc;
2368}
2369
Thomas Falcon032c5e82015-12-21 11:26:06 -06002370static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
2371 union ibmvnic_crq *crq)
2372{
2373 unsigned int ua = adapter->vdev->unit_address;
2374 struct device *dev = &adapter->vdev->dev;
2375 u64 *u64_crq = (u64 *)crq;
2376 int rc;
2377
2378 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
2379 (unsigned long int)cpu_to_be64(u64_crq[0]),
2380 (unsigned long int)cpu_to_be64(u64_crq[1]));
2381
2382 /* Make sure the hypervisor sees the complete request */
2383 mb();
2384
2385 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
2386 cpu_to_be64(u64_crq[0]),
2387 cpu_to_be64(u64_crq[1]));
2388
2389 if (rc) {
2390 if (rc == H_CLOSED)
2391 dev_warn(dev, "CRQ Queue closed\n");
2392 dev_warn(dev, "Send error (rc=%d)\n", rc);
2393 }
2394
2395 return rc;
2396}
2397
2398static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
2399{
2400 union ibmvnic_crq crq;
2401
2402 memset(&crq, 0, sizeof(crq));
2403 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
2404 crq.generic.cmd = IBMVNIC_CRQ_INIT;
2405 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
2406
2407 return ibmvnic_send_crq(adapter, &crq);
2408}
2409
Thomas Falcon032c5e82015-12-21 11:26:06 -06002410static int send_version_xchg(struct ibmvnic_adapter *adapter)
2411{
2412 union ibmvnic_crq crq;
2413
2414 memset(&crq, 0, sizeof(crq));
2415 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
2416 crq.version_exchange.cmd = VERSION_EXCHANGE;
2417 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
2418
2419 return ibmvnic_send_crq(adapter, &crq);
2420}
2421
2422static void send_login(struct ibmvnic_adapter *adapter)
2423{
2424 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
2425 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002426 struct device *dev = &adapter->vdev->dev;
2427 dma_addr_t rsp_buffer_token;
2428 dma_addr_t buffer_token;
2429 size_t rsp_buffer_size;
2430 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002431 size_t buffer_size;
2432 __be64 *tx_list_p;
2433 __be64 *rx_list_p;
2434 int i;
2435
2436 buffer_size =
2437 sizeof(struct ibmvnic_login_buffer) +
2438 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
2439
2440 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
2441 if (!login_buffer)
2442 goto buf_alloc_failed;
2443
2444 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
2445 DMA_TO_DEVICE);
2446 if (dma_mapping_error(dev, buffer_token)) {
2447 dev_err(dev, "Couldn't map login buffer\n");
2448 goto buf_map_failed;
2449 }
2450
John Allen498cd8e2016-04-06 11:49:55 -05002451 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
2452 sizeof(u64) * adapter->req_tx_queues +
2453 sizeof(u64) * adapter->req_rx_queues +
2454 sizeof(u64) * adapter->req_rx_queues +
2455 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002456
2457 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
2458 if (!login_rsp_buffer)
2459 goto buf_rsp_alloc_failed;
2460
2461 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
2462 rsp_buffer_size, DMA_FROM_DEVICE);
2463 if (dma_mapping_error(dev, rsp_buffer_token)) {
2464 dev_err(dev, "Couldn't map login rsp buffer\n");
2465 goto buf_rsp_map_failed;
2466 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04002467
Thomas Falcon032c5e82015-12-21 11:26:06 -06002468 adapter->login_buf = login_buffer;
2469 adapter->login_buf_token = buffer_token;
2470 adapter->login_buf_sz = buffer_size;
2471 adapter->login_rsp_buf = login_rsp_buffer;
2472 adapter->login_rsp_buf_token = rsp_buffer_token;
2473 adapter->login_rsp_buf_sz = rsp_buffer_size;
2474
2475 login_buffer->len = cpu_to_be32(buffer_size);
2476 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
2477 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
2478 login_buffer->off_txcomp_subcrqs =
2479 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
2480 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
2481 login_buffer->off_rxcomp_subcrqs =
2482 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
2483 sizeof(u64) * adapter->req_tx_queues);
2484 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
2485 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
2486
2487 tx_list_p = (__be64 *)((char *)login_buffer +
2488 sizeof(struct ibmvnic_login_buffer));
2489 rx_list_p = (__be64 *)((char *)login_buffer +
2490 sizeof(struct ibmvnic_login_buffer) +
2491 sizeof(u64) * adapter->req_tx_queues);
2492
2493 for (i = 0; i < adapter->req_tx_queues; i++) {
2494 if (adapter->tx_scrq[i]) {
2495 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
2496 crq_num);
2497 }
2498 }
2499
2500 for (i = 0; i < adapter->req_rx_queues; i++) {
2501 if (adapter->rx_scrq[i]) {
2502 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
2503 crq_num);
2504 }
2505 }
2506
2507 netdev_dbg(adapter->netdev, "Login Buffer:\n");
2508 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
2509 netdev_dbg(adapter->netdev, "%016lx\n",
2510 ((unsigned long int *)(adapter->login_buf))[i]);
2511 }
2512
2513 memset(&crq, 0, sizeof(crq));
2514 crq.login.first = IBMVNIC_CRQ_CMD;
2515 crq.login.cmd = LOGIN;
2516 crq.login.ioba = cpu_to_be32(buffer_token);
2517 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002518 ibmvnic_send_crq(adapter, &crq);
2519
2520 return;
2521
Thomas Falcon032c5e82015-12-21 11:26:06 -06002522buf_rsp_map_failed:
2523 kfree(login_rsp_buffer);
2524buf_rsp_alloc_failed:
2525 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
2526buf_map_failed:
2527 kfree(login_buffer);
2528buf_alloc_failed:
2529 return;
2530}
2531
2532static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
2533 u32 len, u8 map_id)
2534{
2535 union ibmvnic_crq crq;
2536
2537 memset(&crq, 0, sizeof(crq));
2538 crq.request_map.first = IBMVNIC_CRQ_CMD;
2539 crq.request_map.cmd = REQUEST_MAP;
2540 crq.request_map.map_id = map_id;
2541 crq.request_map.ioba = cpu_to_be32(addr);
2542 crq.request_map.len = cpu_to_be32(len);
2543 ibmvnic_send_crq(adapter, &crq);
2544}
2545
2546static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
2547{
2548 union ibmvnic_crq crq;
2549
2550 memset(&crq, 0, sizeof(crq));
2551 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
2552 crq.request_unmap.cmd = REQUEST_UNMAP;
2553 crq.request_unmap.map_id = map_id;
2554 ibmvnic_send_crq(adapter, &crq);
2555}
2556
2557static void send_map_query(struct ibmvnic_adapter *adapter)
2558{
2559 union ibmvnic_crq crq;
2560
2561 memset(&crq, 0, sizeof(crq));
2562 crq.query_map.first = IBMVNIC_CRQ_CMD;
2563 crq.query_map.cmd = QUERY_MAP;
2564 ibmvnic_send_crq(adapter, &crq);
2565}
2566
2567/* Send a series of CRQs requesting various capabilities of the VNIC server */
2568static void send_cap_queries(struct ibmvnic_adapter *adapter)
2569{
2570 union ibmvnic_crq crq;
2571
Thomas Falcon901e0402017-02-15 12:17:59 -06002572 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002573 memset(&crq, 0, sizeof(crq));
2574 crq.query_capability.first = IBMVNIC_CRQ_CMD;
2575 crq.query_capability.cmd = QUERY_CAPABILITY;
2576
2577 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002578 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002579 ibmvnic_send_crq(adapter, &crq);
2580
2581 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002582 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002583 ibmvnic_send_crq(adapter, &crq);
2584
2585 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002586 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002587 ibmvnic_send_crq(adapter, &crq);
2588
2589 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002590 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002591 ibmvnic_send_crq(adapter, &crq);
2592
2593 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002594 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002595 ibmvnic_send_crq(adapter, &crq);
2596
2597 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002598 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002599 ibmvnic_send_crq(adapter, &crq);
2600
2601 crq.query_capability.capability =
2602 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002603 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002604 ibmvnic_send_crq(adapter, &crq);
2605
2606 crq.query_capability.capability =
2607 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002608 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002609 ibmvnic_send_crq(adapter, &crq);
2610
2611 crq.query_capability.capability =
2612 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002613 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002614 ibmvnic_send_crq(adapter, &crq);
2615
2616 crq.query_capability.capability =
2617 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002618 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002619 ibmvnic_send_crq(adapter, &crq);
2620
2621 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
Thomas Falcon901e0402017-02-15 12:17:59 -06002622 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002623 ibmvnic_send_crq(adapter, &crq);
2624
2625 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002626 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002627 ibmvnic_send_crq(adapter, &crq);
2628
2629 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002630 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002631 ibmvnic_send_crq(adapter, &crq);
2632
2633 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002634 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002635 ibmvnic_send_crq(adapter, &crq);
2636
2637 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
Thomas Falcon901e0402017-02-15 12:17:59 -06002638 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002639 ibmvnic_send_crq(adapter, &crq);
2640
2641 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06002642 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002643 ibmvnic_send_crq(adapter, &crq);
2644
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04002645 crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION);
2646 atomic_inc(&adapter->running_cap_crqs);
2647 ibmvnic_send_crq(adapter, &crq);
2648
Thomas Falcon032c5e82015-12-21 11:26:06 -06002649 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002650 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002651 ibmvnic_send_crq(adapter, &crq);
2652
2653 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002654 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002655 ibmvnic_send_crq(adapter, &crq);
2656
2657 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002658 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002659 ibmvnic_send_crq(adapter, &crq);
2660
2661 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002662 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002663 ibmvnic_send_crq(adapter, &crq);
2664
2665 crq.query_capability.capability =
2666 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06002667 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002668 ibmvnic_send_crq(adapter, &crq);
2669
2670 crq.query_capability.capability =
2671 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002672 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002673 ibmvnic_send_crq(adapter, &crq);
2674
2675 crq.query_capability.capability =
2676 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002677 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002678 ibmvnic_send_crq(adapter, &crq);
2679
2680 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002681 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002682 ibmvnic_send_crq(adapter, &crq);
2683}
2684
2685static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2686{
2687 struct device *dev = &adapter->vdev->dev;
2688 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2689 union ibmvnic_crq crq;
2690 int i;
2691
2692 dma_unmap_single(dev, adapter->ip_offload_tok,
2693 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2694
2695 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2696 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2697 netdev_dbg(adapter->netdev, "%016lx\n",
2698 ((unsigned long int *)(buf))[i]);
2699
2700 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2701 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2702 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2703 buf->tcp_ipv4_chksum);
2704 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2705 buf->tcp_ipv6_chksum);
2706 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2707 buf->udp_ipv4_chksum);
2708 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2709 buf->udp_ipv6_chksum);
2710 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2711 buf->large_tx_ipv4);
2712 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2713 buf->large_tx_ipv6);
2714 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2715 buf->large_rx_ipv4);
2716 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2717 buf->large_rx_ipv6);
2718 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2719 buf->max_ipv4_header_size);
2720 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2721 buf->max_ipv6_header_size);
2722 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2723 buf->max_tcp_header_size);
2724 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2725 buf->max_udp_header_size);
2726 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2727 buf->max_large_tx_size);
2728 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2729 buf->max_large_rx_size);
2730 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2731 buf->ipv6_extension_header);
2732 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2733 buf->tcp_pseudosum_req);
2734 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2735 buf->num_ipv6_ext_headers);
2736 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2737 buf->off_ipv6_ext_headers);
2738
2739 adapter->ip_offload_ctrl_tok =
2740 dma_map_single(dev, &adapter->ip_offload_ctrl,
2741 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2742
2743 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2744 dev_err(dev, "Couldn't map ip offload control buffer\n");
2745 return;
2746 }
2747
2748 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2749 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2750 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2751 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2752 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2753
2754 /* large_tx/rx disabled for now, additional features needed */
2755 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2756 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2757 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2758 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2759
2760 adapter->netdev->features = NETIF_F_GSO;
2761
2762 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2763 adapter->netdev->features |= NETIF_F_IP_CSUM;
2764
2765 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2766 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2767
Thomas Falcon9be02cd2016-04-01 17:20:35 -05002768 if ((adapter->netdev->features &
2769 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2770 adapter->netdev->features |= NETIF_F_RXCSUM;
2771
Thomas Falcon032c5e82015-12-21 11:26:06 -06002772 memset(&crq, 0, sizeof(crq));
2773 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2774 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2775 crq.control_ip_offload.len =
2776 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2777 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2778 ibmvnic_send_crq(adapter, &crq);
2779}
2780
2781static void handle_error_info_rsp(union ibmvnic_crq *crq,
2782 struct ibmvnic_adapter *adapter)
2783{
2784 struct device *dev = &adapter->vdev->dev;
Wei Yongjun96183182016-06-27 20:48:53 +08002785 struct ibmvnic_error_buff *error_buff, *tmp;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002786 unsigned long flags;
2787 bool found = false;
2788 int i;
2789
2790 if (!crq->request_error_rsp.rc.code) {
2791 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2792 crq->request_error_rsp.rc.code);
2793 return;
2794 }
2795
2796 spin_lock_irqsave(&adapter->error_list_lock, flags);
Wei Yongjun96183182016-06-27 20:48:53 +08002797 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002798 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2799 found = true;
2800 list_del(&error_buff->list);
2801 break;
2802 }
2803 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2804
2805 if (!found) {
2806 dev_err(dev, "Couldn't find error id %x\n",
Thomas Falcon75224c92017-02-15 10:33:33 -06002807 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002808 return;
2809 }
2810
2811 dev_err(dev, "Detailed info for error id %x:",
Thomas Falcon75224c92017-02-15 10:33:33 -06002812 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002813
2814 for (i = 0; i < error_buff->len; i++) {
2815 pr_cont("%02x", (int)error_buff->buff[i]);
2816 if (i % 8 == 7)
2817 pr_cont(" ");
2818 }
2819 pr_cont("\n");
2820
2821 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2822 DMA_FROM_DEVICE);
2823 kfree(error_buff->buff);
2824 kfree(error_buff);
2825}
2826
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002827static void request_error_information(struct ibmvnic_adapter *adapter,
2828 union ibmvnic_crq *err_crq)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002829{
Thomas Falcon032c5e82015-12-21 11:26:06 -06002830 struct device *dev = &adapter->vdev->dev;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002831 struct net_device *netdev = adapter->netdev;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002832 struct ibmvnic_error_buff *error_buff;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002833 unsigned long timeout = msecs_to_jiffies(30000);
2834 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002835 unsigned long flags;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002836 int rc, detail_len;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002837
2838 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2839 if (!error_buff)
2840 return;
2841
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002842 detail_len = be32_to_cpu(err_crq->error_indication.detail_error_sz);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002843 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2844 if (!error_buff->buff) {
2845 kfree(error_buff);
2846 return;
2847 }
2848
2849 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2850 DMA_FROM_DEVICE);
2851 if (dma_mapping_error(dev, error_buff->dma)) {
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002852 netdev_err(netdev, "Couldn't map error buffer\n");
Thomas Falcon032c5e82015-12-21 11:26:06 -06002853 kfree(error_buff->buff);
2854 kfree(error_buff);
2855 return;
2856 }
2857
Thomas Falcon032c5e82015-12-21 11:26:06 -06002858 error_buff->len = detail_len;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002859 error_buff->error_id = err_crq->error_indication.error_id;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002860
2861 spin_lock_irqsave(&adapter->error_list_lock, flags);
2862 list_add_tail(&error_buff->list, &adapter->errors);
2863 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2864
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002865 memset(&crq, 0, sizeof(crq));
2866 crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2867 crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2868 crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2869 crq.request_error_info.len = cpu_to_be32(detail_len);
2870 crq.request_error_info.error_id = err_crq->error_indication.error_id;
2871
2872 rc = ibmvnic_send_crq(adapter, &crq);
2873 if (rc) {
2874 netdev_err(netdev, "failed to request error information\n");
2875 goto err_info_fail;
2876 }
2877
2878 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
2879 netdev_err(netdev, "timeout waiting for error information\n");
2880 goto err_info_fail;
2881 }
2882
2883 return;
2884
2885err_info_fail:
2886 spin_lock_irqsave(&adapter->error_list_lock, flags);
2887 list_del(&error_buff->list);
2888 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2889
2890 kfree(error_buff->buff);
2891 kfree(error_buff);
2892}
2893
2894static void handle_error_indication(union ibmvnic_crq *crq,
2895 struct ibmvnic_adapter *adapter)
2896{
2897 struct device *dev = &adapter->vdev->dev;
2898
2899 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2900 crq->error_indication.flags
2901 & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
2902 be32_to_cpu(crq->error_indication.error_id),
2903 be16_to_cpu(crq->error_indication.error_cause));
2904
2905 if (be32_to_cpu(crq->error_indication.error_id))
2906 request_error_information(adapter, crq);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002907
2908 if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR)
2909 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
John Allen8cb31cf2017-05-26 10:30:37 -04002910 else
2911 ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002912}
2913
2914static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2915 struct ibmvnic_adapter *adapter)
2916{
2917 struct net_device *netdev = adapter->netdev;
2918 struct device *dev = &adapter->vdev->dev;
2919 long rc;
2920
2921 rc = crq->change_mac_addr_rsp.rc.code;
2922 if (rc) {
2923 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2924 return;
2925 }
2926 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2927 ETH_ALEN);
2928}
2929
2930static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2931 struct ibmvnic_adapter *adapter)
2932{
2933 struct device *dev = &adapter->vdev->dev;
2934 u64 *req_value;
2935 char *name;
2936
Thomas Falcon901e0402017-02-15 12:17:59 -06002937 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002938 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2939 case REQ_TX_QUEUES:
2940 req_value = &adapter->req_tx_queues;
2941 name = "tx";
2942 break;
2943 case REQ_RX_QUEUES:
2944 req_value = &adapter->req_rx_queues;
2945 name = "rx";
2946 break;
2947 case REQ_RX_ADD_QUEUES:
2948 req_value = &adapter->req_rx_add_queues;
2949 name = "rx_add";
2950 break;
2951 case REQ_TX_ENTRIES_PER_SUBCRQ:
2952 req_value = &adapter->req_tx_entries_per_subcrq;
2953 name = "tx_entries_per_subcrq";
2954 break;
2955 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2956 req_value = &adapter->req_rx_add_entries_per_subcrq;
2957 name = "rx_add_entries_per_subcrq";
2958 break;
2959 case REQ_MTU:
2960 req_value = &adapter->req_mtu;
2961 name = "mtu";
2962 break;
2963 case PROMISC_REQUESTED:
2964 req_value = &adapter->promisc;
2965 name = "promisc";
2966 break;
2967 default:
2968 dev_err(dev, "Got invalid cap request rsp %d\n",
2969 crq->request_capability.capability);
2970 return;
2971 }
2972
2973 switch (crq->request_capability_rsp.rc.code) {
2974 case SUCCESS:
2975 break;
2976 case PARTIALSUCCESS:
2977 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2978 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06002979 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06002980 number), name);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002981 release_sub_crqs(adapter);
Thomas Falcon28f4d162017-02-15 10:32:11 -06002982 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002983 ibmvnic_send_req_caps(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002984 return;
2985 default:
2986 dev_err(dev, "Error %d in request cap rsp\n",
2987 crq->request_capability_rsp.rc.code);
2988 return;
2989 }
2990
2991 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06002992 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002993 union ibmvnic_crq newcrq;
2994 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2995 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2996 &adapter->ip_offload_buf;
2997
Thomas Falcon249168a2017-02-15 12:18:00 -06002998 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002999 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
3000 buf_sz,
3001 DMA_FROM_DEVICE);
3002
3003 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
3004 if (!firmware_has_feature(FW_FEATURE_CMO))
3005 dev_err(dev, "Couldn't map offload buffer\n");
3006 return;
3007 }
3008
3009 memset(&newcrq, 0, sizeof(newcrq));
3010 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
3011 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
3012 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
3013 newcrq.query_ip_offload.ioba =
3014 cpu_to_be32(adapter->ip_offload_tok);
3015
3016 ibmvnic_send_crq(adapter, &newcrq);
3017 }
3018}
3019
3020static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
3021 struct ibmvnic_adapter *adapter)
3022{
3023 struct device *dev = &adapter->vdev->dev;
3024 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
3025 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003026 int i;
3027
3028 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
3029 DMA_BIDIRECTIONAL);
3030 dma_unmap_single(dev, adapter->login_rsp_buf_token,
3031 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
3032
John Allen498cd8e2016-04-06 11:49:55 -05003033 /* If the number of queues requested can't be allocated by the
3034 * server, the login response will return with code 1. We will need
3035 * to resend the login buffer with fewer queues requested.
3036 */
3037 if (login_rsp_crq->generic.rc.code) {
3038 adapter->renegotiate = true;
3039 complete(&adapter->init_done);
3040 return 0;
3041 }
3042
Thomas Falcon032c5e82015-12-21 11:26:06 -06003043 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
3044 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
3045 netdev_dbg(adapter->netdev, "%016lx\n",
3046 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
3047 }
3048
3049 /* Sanity checks */
3050 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
3051 (be32_to_cpu(login->num_rxcomp_subcrqs) *
3052 adapter->req_rx_add_queues !=
3053 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
3054 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
3055 ibmvnic_remove(adapter->vdev);
3056 return -EIO;
3057 }
3058 complete(&adapter->init_done);
3059
Thomas Falcon032c5e82015-12-21 11:26:06 -06003060 return 0;
3061}
3062
3063static void handle_request_map_rsp(union ibmvnic_crq *crq,
3064 struct ibmvnic_adapter *adapter)
3065{
3066 struct device *dev = &adapter->vdev->dev;
3067 u8 map_id = crq->request_map_rsp.map_id;
3068 int tx_subcrqs;
3069 int rx_subcrqs;
3070 long rc;
3071 int i;
3072
3073 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
3074 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3075
3076 rc = crq->request_map_rsp.rc.code;
3077 if (rc) {
3078 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
3079 adapter->map_id--;
3080 /* need to find and zero tx/rx_pool map_id */
3081 for (i = 0; i < tx_subcrqs; i++) {
3082 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
3083 adapter->tx_pool[i].long_term_buff.map_id = 0;
3084 }
3085 for (i = 0; i < rx_subcrqs; i++) {
3086 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
3087 adapter->rx_pool[i].long_term_buff.map_id = 0;
3088 }
3089 }
3090 complete(&adapter->fw_done);
3091}
3092
3093static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
3094 struct ibmvnic_adapter *adapter)
3095{
3096 struct device *dev = &adapter->vdev->dev;
3097 long rc;
3098
3099 rc = crq->request_unmap_rsp.rc.code;
3100 if (rc)
3101 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
3102}
3103
3104static void handle_query_map_rsp(union ibmvnic_crq *crq,
3105 struct ibmvnic_adapter *adapter)
3106{
3107 struct net_device *netdev = adapter->netdev;
3108 struct device *dev = &adapter->vdev->dev;
3109 long rc;
3110
3111 rc = crq->query_map_rsp.rc.code;
3112 if (rc) {
3113 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
3114 return;
3115 }
3116 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
3117 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
3118 crq->query_map_rsp.free_pages);
3119}
3120
3121static void handle_query_cap_rsp(union ibmvnic_crq *crq,
3122 struct ibmvnic_adapter *adapter)
3123{
3124 struct net_device *netdev = adapter->netdev;
3125 struct device *dev = &adapter->vdev->dev;
3126 long rc;
3127
Thomas Falcon901e0402017-02-15 12:17:59 -06003128 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003129 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06003130 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06003131 rc = crq->query_capability.rc.code;
3132 if (rc) {
3133 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
3134 goto out;
3135 }
3136
3137 switch (be16_to_cpu(crq->query_capability.capability)) {
3138 case MIN_TX_QUEUES:
3139 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003140 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003141 netdev_dbg(netdev, "min_tx_queues = %lld\n",
3142 adapter->min_tx_queues);
3143 break;
3144 case MIN_RX_QUEUES:
3145 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003146 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003147 netdev_dbg(netdev, "min_rx_queues = %lld\n",
3148 adapter->min_rx_queues);
3149 break;
3150 case MIN_RX_ADD_QUEUES:
3151 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003152 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003153 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
3154 adapter->min_rx_add_queues);
3155 break;
3156 case MAX_TX_QUEUES:
3157 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003158 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003159 netdev_dbg(netdev, "max_tx_queues = %lld\n",
3160 adapter->max_tx_queues);
3161 break;
3162 case MAX_RX_QUEUES:
3163 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003164 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003165 netdev_dbg(netdev, "max_rx_queues = %lld\n",
3166 adapter->max_rx_queues);
3167 break;
3168 case MAX_RX_ADD_QUEUES:
3169 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003170 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003171 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
3172 adapter->max_rx_add_queues);
3173 break;
3174 case MIN_TX_ENTRIES_PER_SUBCRQ:
3175 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003176 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003177 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
3178 adapter->min_tx_entries_per_subcrq);
3179 break;
3180 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
3181 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003182 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003183 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
3184 adapter->min_rx_add_entries_per_subcrq);
3185 break;
3186 case MAX_TX_ENTRIES_PER_SUBCRQ:
3187 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003188 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003189 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
3190 adapter->max_tx_entries_per_subcrq);
3191 break;
3192 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
3193 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003194 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003195 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
3196 adapter->max_rx_add_entries_per_subcrq);
3197 break;
3198 case TCP_IP_OFFLOAD:
3199 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06003200 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003201 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
3202 adapter->tcp_ip_offload);
3203 break;
3204 case PROMISC_SUPPORTED:
3205 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06003206 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003207 netdev_dbg(netdev, "promisc_supported = %lld\n",
3208 adapter->promisc_supported);
3209 break;
3210 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06003211 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06003212 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003213 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
3214 break;
3215 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06003216 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06003217 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003218 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
3219 break;
3220 case MAX_MULTICAST_FILTERS:
3221 adapter->max_multicast_filters =
Thomas Falconde89e852016-03-01 10:20:09 -06003222 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003223 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
3224 adapter->max_multicast_filters);
3225 break;
3226 case VLAN_HEADER_INSERTION:
3227 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06003228 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003229 if (adapter->vlan_header_insertion)
3230 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
3231 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
3232 adapter->vlan_header_insertion);
3233 break;
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04003234 case RX_VLAN_HEADER_INSERTION:
3235 adapter->rx_vlan_header_insertion =
3236 be64_to_cpu(crq->query_capability.number);
3237 netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n",
3238 adapter->rx_vlan_header_insertion);
3239 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003240 case MAX_TX_SG_ENTRIES:
3241 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06003242 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003243 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
3244 adapter->max_tx_sg_entries);
3245 break;
3246 case RX_SG_SUPPORTED:
3247 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06003248 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003249 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
3250 adapter->rx_sg_supported);
3251 break;
3252 case OPT_TX_COMP_SUB_QUEUES:
3253 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003254 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003255 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
3256 adapter->opt_tx_comp_sub_queues);
3257 break;
3258 case OPT_RX_COMP_QUEUES:
3259 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003260 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003261 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
3262 adapter->opt_rx_comp_queues);
3263 break;
3264 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
3265 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06003266 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003267 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
3268 adapter->opt_rx_bufadd_q_per_rx_comp_q);
3269 break;
3270 case OPT_TX_ENTRIES_PER_SUBCRQ:
3271 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003272 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003273 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
3274 adapter->opt_tx_entries_per_subcrq);
3275 break;
3276 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
3277 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003278 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003279 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
3280 adapter->opt_rxba_entries_per_subcrq);
3281 break;
3282 case TX_RX_DESC_REQ:
3283 adapter->tx_rx_desc_req = crq->query_capability.number;
3284 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
3285 adapter->tx_rx_desc_req);
3286 break;
3287
3288 default:
3289 netdev_err(netdev, "Got invalid cap rsp %d\n",
3290 crq->query_capability.capability);
3291 }
3292
3293out:
Thomas Falcon249168a2017-02-15 12:18:00 -06003294 if (atomic_read(&adapter->running_cap_crqs) == 0) {
3295 adapter->wait_capability = false;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003296 ibmvnic_send_req_caps(adapter, 0);
Thomas Falcon249168a2017-02-15 12:18:00 -06003297 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06003298}
3299
Thomas Falcon032c5e82015-12-21 11:26:06 -06003300static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3301 struct ibmvnic_adapter *adapter)
3302{
3303 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
3304 struct net_device *netdev = adapter->netdev;
3305 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04003306 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003307 long rc;
3308
3309 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04003310 (unsigned long int)cpu_to_be64(u64_crq[0]),
3311 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06003312 switch (gen_crq->first) {
3313 case IBMVNIC_CRQ_INIT_RSP:
3314 switch (gen_crq->cmd) {
3315 case IBMVNIC_CRQ_INIT:
3316 dev_info(dev, "Partner initialized\n");
John Allen017892c12017-05-26 10:30:19 -04003317 adapter->from_passive_init = true;
3318 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003319 break;
3320 case IBMVNIC_CRQ_INIT_COMPLETE:
3321 dev_info(dev, "Partner initialization complete\n");
3322 send_version_xchg(adapter);
3323 break;
3324 default:
3325 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
3326 }
3327 return;
3328 case IBMVNIC_CRQ_XPORT_EVENT:
Nathan Fontenoted651a12017-05-03 14:04:38 -04003329 netif_carrier_off(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003330 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
Nathan Fontenoted651a12017-05-03 14:04:38 -04003331 dev_info(dev, "Migrated, re-enabling adapter\n");
3332 ibmvnic_reset(adapter, VNIC_RESET_MOBILITY);
Thomas Falcondfad09a2016-08-18 11:37:51 -05003333 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
3334 dev_info(dev, "Backing device failover detected\n");
Nathan Fontenoted651a12017-05-03 14:04:38 -04003335 ibmvnic_reset(adapter, VNIC_RESET_FAILOVER);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003336 } else {
3337 /* The adapter lost the connection */
3338 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
3339 gen_crq->cmd);
Nathan Fontenoted651a12017-05-03 14:04:38 -04003340 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003341 }
3342 return;
3343 case IBMVNIC_CRQ_CMD_RSP:
3344 break;
3345 default:
3346 dev_err(dev, "Got an invalid msg type 0x%02x\n",
3347 gen_crq->first);
3348 return;
3349 }
3350
3351 switch (gen_crq->cmd) {
3352 case VERSION_EXCHANGE_RSP:
3353 rc = crq->version_exchange_rsp.rc.code;
3354 if (rc) {
3355 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
3356 break;
3357 }
3358 dev_info(dev, "Partner protocol version is %d\n",
3359 crq->version_exchange_rsp.version);
3360 if (be16_to_cpu(crq->version_exchange_rsp.version) <
3361 ibmvnic_version)
3362 ibmvnic_version =
3363 be16_to_cpu(crq->version_exchange_rsp.version);
3364 send_cap_queries(adapter);
3365 break;
3366 case QUERY_CAPABILITY_RSP:
3367 handle_query_cap_rsp(crq, adapter);
3368 break;
3369 case QUERY_MAP_RSP:
3370 handle_query_map_rsp(crq, adapter);
3371 break;
3372 case REQUEST_MAP_RSP:
3373 handle_request_map_rsp(crq, adapter);
3374 break;
3375 case REQUEST_UNMAP_RSP:
3376 handle_request_unmap_rsp(crq, adapter);
3377 break;
3378 case REQUEST_CAPABILITY_RSP:
3379 handle_request_cap_rsp(crq, adapter);
3380 break;
3381 case LOGIN_RSP:
3382 netdev_dbg(netdev, "Got Login Response\n");
3383 handle_login_rsp(crq, adapter);
3384 break;
3385 case LOGICAL_LINK_STATE_RSP:
Nathan Fontenot53da09e2017-04-21 15:39:04 -04003386 netdev_dbg(netdev,
3387 "Got Logical Link State Response, state: %d rc: %d\n",
3388 crq->logical_link_state_rsp.link_state,
3389 crq->logical_link_state_rsp.rc.code);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003390 adapter->logical_link_state =
3391 crq->logical_link_state_rsp.link_state;
Nathan Fontenot53da09e2017-04-21 15:39:04 -04003392 adapter->init_done_rc = crq->logical_link_state_rsp.rc.code;
3393 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003394 break;
3395 case LINK_STATE_INDICATION:
3396 netdev_dbg(netdev, "Got Logical Link State Indication\n");
3397 adapter->phys_link_state =
3398 crq->link_state_indication.phys_link_state;
3399 adapter->logical_link_state =
3400 crq->link_state_indication.logical_link_state;
3401 break;
3402 case CHANGE_MAC_ADDR_RSP:
3403 netdev_dbg(netdev, "Got MAC address change Response\n");
3404 handle_change_mac_rsp(crq, adapter);
3405 break;
3406 case ERROR_INDICATION:
3407 netdev_dbg(netdev, "Got Error Indication\n");
3408 handle_error_indication(crq, adapter);
3409 break;
3410 case REQUEST_ERROR_RSP:
3411 netdev_dbg(netdev, "Got Error Detail Response\n");
3412 handle_error_info_rsp(crq, adapter);
3413 break;
3414 case REQUEST_STATISTICS_RSP:
3415 netdev_dbg(netdev, "Got Statistics Response\n");
3416 complete(&adapter->stats_done);
3417 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003418 case QUERY_IP_OFFLOAD_RSP:
3419 netdev_dbg(netdev, "Got Query IP offload Response\n");
3420 handle_query_ip_offload_rsp(adapter);
3421 break;
3422 case MULTICAST_CTRL_RSP:
3423 netdev_dbg(netdev, "Got multicast control Response\n");
3424 break;
3425 case CONTROL_IP_OFFLOAD_RSP:
3426 netdev_dbg(netdev, "Got Control IP offload Response\n");
3427 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
3428 sizeof(adapter->ip_offload_ctrl),
3429 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05003430 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003431 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003432 case COLLECT_FW_TRACE_RSP:
3433 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
3434 complete(&adapter->fw_done);
3435 break;
3436 default:
3437 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
3438 gen_crq->cmd);
3439 }
3440}
3441
3442static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
3443{
3444 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06003445
Thomas Falcon6c267b32017-02-15 12:17:58 -06003446 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003447 return IRQ_HANDLED;
3448}
3449
3450static void ibmvnic_tasklet(void *data)
3451{
3452 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003453 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003454 union ibmvnic_crq *crq;
3455 unsigned long flags;
3456 bool done = false;
3457
3458 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003459 while (!done) {
3460 /* Pull all the valid messages off the CRQ */
3461 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
3462 ibmvnic_handle_crq(crq, adapter);
3463 crq->generic.first = 0;
3464 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04003465
3466 /* remain in tasklet until all
3467 * capabilities responses are received
3468 */
3469 if (!adapter->wait_capability)
3470 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003471 }
Thomas Falcon249168a2017-02-15 12:18:00 -06003472 /* if capabilities CRQ's were sent in this tasklet, the following
3473 * tasklet must wait until all responses are received
3474 */
3475 if (atomic_read(&adapter->running_cap_crqs) != 0)
3476 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003477 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003478}
3479
3480static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
3481{
3482 struct vio_dev *vdev = adapter->vdev;
3483 int rc;
3484
3485 do {
3486 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
3487 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
3488
3489 if (rc)
3490 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
3491
3492 return rc;
3493}
3494
3495static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
3496{
3497 struct ibmvnic_crq_queue *crq = &adapter->crq;
3498 struct device *dev = &adapter->vdev->dev;
3499 struct vio_dev *vdev = adapter->vdev;
3500 int rc;
3501
3502 /* Close the CRQ */
3503 do {
3504 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3505 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3506
3507 /* Clean out the queue */
3508 memset(crq->msgs, 0, PAGE_SIZE);
3509 crq->cur = 0;
3510
3511 /* And re-open it again */
3512 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3513 crq->msg_token, PAGE_SIZE);
3514
3515 if (rc == H_CLOSED)
3516 /* Adapter is good, but other end is not ready */
3517 dev_warn(dev, "Partner adapter not ready\n");
3518 else if (rc != 0)
3519 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3520
3521 return rc;
3522}
3523
Nathan Fontenotf9928872017-03-30 02:48:54 -04003524static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003525{
3526 struct ibmvnic_crq_queue *crq = &adapter->crq;
3527 struct vio_dev *vdev = adapter->vdev;
3528 long rc;
3529
Nathan Fontenotf9928872017-03-30 02:48:54 -04003530 if (!crq->msgs)
3531 return;
3532
Thomas Falcon032c5e82015-12-21 11:26:06 -06003533 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3534 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003535 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003536 do {
3537 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3538 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3539
3540 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3541 DMA_BIDIRECTIONAL);
3542 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003543 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003544}
3545
Nathan Fontenotf9928872017-03-30 02:48:54 -04003546static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003547{
3548 struct ibmvnic_crq_queue *crq = &adapter->crq;
3549 struct device *dev = &adapter->vdev->dev;
3550 struct vio_dev *vdev = adapter->vdev;
3551 int rc, retrc = -ENOMEM;
3552
Nathan Fontenotf9928872017-03-30 02:48:54 -04003553 if (crq->msgs)
3554 return 0;
3555
Thomas Falcon032c5e82015-12-21 11:26:06 -06003556 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3557 /* Should we allocate more than one page? */
3558
3559 if (!crq->msgs)
3560 return -ENOMEM;
3561
3562 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3563 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3564 DMA_BIDIRECTIONAL);
3565 if (dma_mapping_error(dev, crq->msg_token))
3566 goto map_failed;
3567
3568 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3569 crq->msg_token, PAGE_SIZE);
3570
3571 if (rc == H_RESOURCE)
3572 /* maybe kexecing and resource is busy. try a reset */
3573 rc = ibmvnic_reset_crq(adapter);
3574 retrc = rc;
3575
3576 if (rc == H_CLOSED) {
3577 dev_warn(dev, "Partner adapter not ready\n");
3578 } else if (rc) {
3579 dev_warn(dev, "Error %d opening adapter\n", rc);
3580 goto reg_crq_failed;
3581 }
3582
3583 retrc = 0;
3584
Thomas Falcon6c267b32017-02-15 12:17:58 -06003585 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3586 (unsigned long)adapter);
3587
Thomas Falcon032c5e82015-12-21 11:26:06 -06003588 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3589 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3590 adapter);
3591 if (rc) {
3592 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3593 vdev->irq, rc);
3594 goto req_irq_failed;
3595 }
3596
3597 rc = vio_enable_interrupts(vdev);
3598 if (rc) {
3599 dev_err(dev, "Error %d enabling interrupts\n", rc);
3600 goto req_irq_failed;
3601 }
3602
3603 crq->cur = 0;
3604 spin_lock_init(&crq->lock);
3605
3606 return retrc;
3607
3608req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06003609 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003610 do {
3611 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3612 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3613reg_crq_failed:
3614 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3615map_failed:
3616 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003617 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003618 return retrc;
3619}
3620
John Allenf6ef6402017-03-17 17:13:42 -05003621static int ibmvnic_init(struct ibmvnic_adapter *adapter)
3622{
3623 struct device *dev = &adapter->vdev->dev;
3624 unsigned long timeout = msecs_to_jiffies(30000);
John Allenf6ef6402017-03-17 17:13:42 -05003625 int rc;
3626
Nathan Fontenot28cde752017-05-26 10:31:00 -04003627 if (adapter->resetting) {
3628 rc = ibmvnic_reset_crq(adapter);
3629 if (!rc)
3630 rc = vio_enable_interrupts(adapter->vdev);
3631 } else {
3632 rc = init_crq_queue(adapter);
3633 }
3634
John Allenf6ef6402017-03-17 17:13:42 -05003635 if (rc) {
3636 dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
3637 return rc;
3638 }
3639
John Allen017892c12017-05-26 10:30:19 -04003640 adapter->from_passive_init = false;
3641
John Allenf6ef6402017-03-17 17:13:42 -05003642 init_completion(&adapter->init_done);
3643 ibmvnic_send_crq_init(adapter);
3644 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3645 dev_err(dev, "Initialization sequence timed out\n");
John Allen017892c12017-05-26 10:30:19 -04003646 return -1;
3647 }
3648
3649 if (adapter->from_passive_init) {
3650 adapter->state = VNIC_OPEN;
3651 adapter->from_passive_init = false;
John Allenf6ef6402017-03-17 17:13:42 -05003652 return -1;
3653 }
3654
Nathan Fontenot57a49432017-05-26 10:31:12 -04003655 if (adapter->resetting)
3656 rc = reset_sub_crq_queues(adapter);
3657 else
3658 rc = init_sub_crqs(adapter);
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04003659 if (rc) {
3660 dev_err(dev, "Initialization of sub crqs failed\n");
3661 release_crq_queue(adapter);
3662 }
3663
3664 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05003665}
3666
Thomas Falcon40c9db82017-06-12 12:35:04 -05003667static struct device_attribute dev_attr_failover;
3668
Thomas Falcon032c5e82015-12-21 11:26:06 -06003669static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3670{
3671 struct ibmvnic_adapter *adapter;
3672 struct net_device *netdev;
3673 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003674 int rc;
3675
3676 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3677 dev->unit_address);
3678
3679 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3680 VETH_MAC_ADDR, NULL);
3681 if (!mac_addr_p) {
3682 dev_err(&dev->dev,
3683 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3684 __FILE__, __LINE__);
3685 return 0;
3686 }
3687
3688 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3689 IBMVNIC_MAX_TX_QUEUES);
3690 if (!netdev)
3691 return -ENOMEM;
3692
3693 adapter = netdev_priv(netdev);
Nathan Fontenot90c80142017-05-03 14:04:32 -04003694 adapter->state = VNIC_PROBING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003695 dev_set_drvdata(&dev->dev, netdev);
3696 adapter->vdev = dev;
3697 adapter->netdev = netdev;
3698
3699 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3700 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3701 netdev->irq = dev->irq;
3702 netdev->netdev_ops = &ibmvnic_netdev_ops;
3703 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3704 SET_NETDEV_DEV(netdev, &dev->dev);
3705
3706 spin_lock_init(&adapter->stats_lock);
3707
Thomas Falcon032c5e82015-12-21 11:26:06 -06003708 INIT_LIST_HEAD(&adapter->errors);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003709 spin_lock_init(&adapter->error_list_lock);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003710
Nathan Fontenoted651a12017-05-03 14:04:38 -04003711 INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset);
3712 INIT_LIST_HEAD(&adapter->rwi_list);
3713 mutex_init(&adapter->reset_lock);
3714 mutex_init(&adapter->rwi_lock);
3715 adapter->resetting = false;
3716
John Allenf6ef6402017-03-17 17:13:42 -05003717 rc = ibmvnic_init(adapter);
3718 if (rc) {
3719 free_netdev(netdev);
3720 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003721 }
3722
Thomas Falconf39f0d12017-02-14 10:22:59 -06003723 netdev->mtu = adapter->req_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003724
Thomas Falcon40c9db82017-06-12 12:35:04 -05003725 rc = device_create_file(&dev->dev, &dev_attr_failover);
3726 if (rc) {
3727 free_netdev(netdev);
3728 return rc;
3729 }
3730
Thomas Falcon032c5e82015-12-21 11:26:06 -06003731 rc = register_netdev(netdev);
3732 if (rc) {
3733 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
Thomas Falcon40c9db82017-06-12 12:35:04 -05003734 device_remove_file(&dev->dev, &dev_attr_failover);
John Allenf6ef6402017-03-17 17:13:42 -05003735 free_netdev(netdev);
3736 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003737 }
3738 dev_info(&dev->dev, "ibmvnic registered\n");
3739
Nathan Fontenot90c80142017-05-03 14:04:32 -04003740 adapter->state = VNIC_PROBED;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003741 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003742}
3743
3744static int ibmvnic_remove(struct vio_dev *dev)
3745{
3746 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003747 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003748
Nathan Fontenot90c80142017-05-03 14:04:32 -04003749 adapter->state = VNIC_REMOVING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003750 unregister_netdev(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -04003751 mutex_lock(&adapter->reset_lock);
Nathan Fontenot37489052017-04-19 13:45:04 -04003752
3753 release_resources(adapter);
3754 release_sub_crqs(adapter);
3755 release_crq_queue(adapter);
3756
Nathan Fontenot90c80142017-05-03 14:04:32 -04003757 adapter->state = VNIC_REMOVED;
3758
Nathan Fontenoted651a12017-05-03 14:04:38 -04003759 mutex_unlock(&adapter->reset_lock);
Thomas Falcon40c9db82017-06-12 12:35:04 -05003760 device_remove_file(&dev->dev, &dev_attr_failover);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003761 free_netdev(netdev);
3762 dev_set_drvdata(&dev->dev, NULL);
3763
3764 return 0;
3765}
3766
Thomas Falcon40c9db82017-06-12 12:35:04 -05003767static ssize_t failover_store(struct device *dev, struct device_attribute *attr,
3768 const char *buf, size_t count)
3769{
3770 struct net_device *netdev = dev_get_drvdata(dev);
3771 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3772 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
3773 __be64 session_token;
3774 long rc;
3775
3776 if (!sysfs_streq(buf, "1"))
3777 return -EINVAL;
3778
3779 rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address,
3780 H_GET_SESSION_TOKEN, 0, 0, 0);
3781 if (rc) {
3782 netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n",
3783 rc);
3784 return -EINVAL;
3785 }
3786
3787 session_token = (__be64)retbuf[0];
3788 netdev_dbg(netdev, "Initiating client failover, session id %llx\n",
3789 be64_to_cpu(session_token));
3790 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
3791 H_SESSION_ERR_DETECTED, session_token, 0, 0);
3792 if (rc) {
3793 netdev_err(netdev, "Client initiated failover failed, rc %ld\n",
3794 rc);
3795 return -EINVAL;
3796 }
3797
3798 return count;
3799}
3800
3801static DEVICE_ATTR(failover, 0200, NULL, failover_store);
3802
Thomas Falcon032c5e82015-12-21 11:26:06 -06003803static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3804{
3805 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3806 struct ibmvnic_adapter *adapter;
3807 struct iommu_table *tbl;
3808 unsigned long ret = 0;
3809 int i;
3810
3811 tbl = get_iommu_table_base(&vdev->dev);
3812
3813 /* netdev inits at probe time along with the structures we need below*/
3814 if (!netdev)
3815 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3816
3817 adapter = netdev_priv(netdev);
3818
3819 ret += PAGE_SIZE; /* the crq message queue */
Thomas Falcon032c5e82015-12-21 11:26:06 -06003820 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3821
3822 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3823 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3824
3825 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3826 i++)
3827 ret += adapter->rx_pool[i].size *
3828 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3829
3830 return ret;
3831}
3832
3833static int ibmvnic_resume(struct device *dev)
3834{
3835 struct net_device *netdev = dev_get_drvdata(dev);
3836 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3837 int i;
3838
3839 /* kick the interrupt handlers just in case we lost an interrupt */
3840 for (i = 0; i < adapter->req_rx_queues; i++)
3841 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3842 adapter->rx_scrq[i]);
3843
3844 return 0;
3845}
3846
3847static struct vio_device_id ibmvnic_device_table[] = {
3848 {"network", "IBM,vnic"},
3849 {"", "" }
3850};
3851MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3852
3853static const struct dev_pm_ops ibmvnic_pm_ops = {
3854 .resume = ibmvnic_resume
3855};
3856
3857static struct vio_driver ibmvnic_driver = {
3858 .id_table = ibmvnic_device_table,
3859 .probe = ibmvnic_probe,
3860 .remove = ibmvnic_remove,
3861 .get_desired_dma = ibmvnic_get_desired_dma,
3862 .name = ibmvnic_driver_name,
3863 .pm = &ibmvnic_pm_ops,
3864};
3865
3866/* module functions */
3867static int __init ibmvnic_module_init(void)
3868{
3869 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3870 IBMVNIC_DRIVER_VERSION);
3871
3872 return vio_register_driver(&ibmvnic_driver);
3873}
3874
3875static void __exit ibmvnic_module_exit(void)
3876{
3877 vio_unregister_driver(&ibmvnic_driver);
3878}
3879
3880module_init(ibmvnic_module_init);
3881module_exit(ibmvnic_module_exit);