blob: a8b3c5741258be4bb457ed6a19a5155dd6e7296e [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>
Thomas Falcon032c5e82015-12-21 11:26:06 -060077
78#include "ibmvnic.h"
79
80static const char ibmvnic_driver_name[] = "ibmvnic";
81static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
82
83MODULE_AUTHOR("Santiago Leon <santi_leon@yahoo.com>");
84MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
85MODULE_LICENSE("GPL");
86MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
87
88static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
89static int ibmvnic_remove(struct vio_dev *);
90static void release_sub_crqs(struct ibmvnic_adapter *);
91static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
92static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
93static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
94static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
95static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
96 union sub_crq *sub_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -050097static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
Thomas Falcon032c5e82015-12-21 11:26:06 -060098static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
99static int enable_scrq_irq(struct ibmvnic_adapter *,
100 struct ibmvnic_sub_crq_queue *);
101static int disable_scrq_irq(struct ibmvnic_adapter *,
102 struct ibmvnic_sub_crq_queue *);
103static int pending_scrq(struct ibmvnic_adapter *,
104 struct ibmvnic_sub_crq_queue *);
105static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
106 struct ibmvnic_sub_crq_queue *);
107static int ibmvnic_poll(struct napi_struct *napi, int data);
108static void send_map_query(struct ibmvnic_adapter *adapter);
109static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
110static void send_request_unmap(struct ibmvnic_adapter *, u8);
John Allenbd0b6722017-03-17 17:13:40 -0500111static void send_login(struct ibmvnic_adapter *adapter);
112static void send_cap_queries(struct ibmvnic_adapter *adapter);
113static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
John Allenea5509f2017-03-17 17:13:43 -0500114static int ibmvnic_init(struct ibmvnic_adapter *);
Nathan Fontenotf9928872017-03-30 02:48:54 -0400115static void release_crq_queue(struct ibmvnic_adapter *);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600116
117struct ibmvnic_stat {
118 char name[ETH_GSTRING_LEN];
119 int offset;
120};
121
122#define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
123 offsetof(struct ibmvnic_statistics, stat))
124#define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
125
126static const struct ibmvnic_stat ibmvnic_stats[] = {
127 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
128 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
129 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
130 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
131 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
132 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
133 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
134 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
135 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
136 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
137 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
138 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
139 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
140 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
141 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
142 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
143 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
144 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
145 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
146 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
147 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
148 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
149};
150
151static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
152 unsigned long length, unsigned long *number,
153 unsigned long *irq)
154{
155 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
156 long rc;
157
158 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
159 *number = retbuf[0];
160 *irq = retbuf[1];
161
162 return rc;
163}
164
Thomas Falcon032c5e82015-12-21 11:26:06 -0600165static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
166 struct ibmvnic_long_term_buff *ltb, int size)
167{
168 struct device *dev = &adapter->vdev->dev;
169
170 ltb->size = size;
171 ltb->buff = dma_alloc_coherent(dev, ltb->size, &ltb->addr,
172 GFP_KERNEL);
173
174 if (!ltb->buff) {
175 dev_err(dev, "Couldn't alloc long term buffer\n");
176 return -ENOMEM;
177 }
178 ltb->map_id = adapter->map_id;
179 adapter->map_id++;
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -0500180
181 init_completion(&adapter->fw_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600182 send_request_map(adapter, ltb->addr,
183 ltb->size, ltb->map_id);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600184 wait_for_completion(&adapter->fw_done);
185 return 0;
186}
187
188static void free_long_term_buff(struct ibmvnic_adapter *adapter,
189 struct ibmvnic_long_term_buff *ltb)
190{
191 struct device *dev = &adapter->vdev->dev;
192
Nathan Fontenotc657e322017-03-30 02:49:06 -0400193 if (!ltb->buff)
194 return;
195
Thomas Falcondfad09a2016-08-18 11:37:51 -0500196 if (!adapter->failover)
197 send_request_unmap(adapter, ltb->map_id);
Brian King59af56c2017-04-19 13:44:41 -0400198 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600199}
200
Thomas Falcon032c5e82015-12-21 11:26:06 -0600201static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
202 struct ibmvnic_rx_pool *pool)
203{
204 int count = pool->size - atomic_read(&pool->available);
205 struct device *dev = &adapter->vdev->dev;
206 int buffers_added = 0;
207 unsigned long lpar_rc;
208 union sub_crq sub_crq;
209 struct sk_buff *skb;
210 unsigned int offset;
211 dma_addr_t dma_addr;
212 unsigned char *dst;
213 u64 *handle_array;
214 int shift = 0;
215 int index;
216 int i;
217
218 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
219 be32_to_cpu(adapter->login_rsp_buf->
220 off_rxadd_subcrqs));
221
222 for (i = 0; i < count; ++i) {
223 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
224 if (!skb) {
225 dev_err(dev, "Couldn't replenish rx buff\n");
226 adapter->replenish_no_mem++;
227 break;
228 }
229
230 index = pool->free_map[pool->next_free];
231
232 if (pool->rx_buff[index].skb)
233 dev_err(dev, "Inconsistent free_map!\n");
234
235 /* Copy the skb to the long term mapped DMA buffer */
236 offset = index * pool->buff_size;
237 dst = pool->long_term_buff.buff + offset;
238 memset(dst, 0, pool->buff_size);
239 dma_addr = pool->long_term_buff.addr + offset;
240 pool->rx_buff[index].data = dst;
241
242 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
243 pool->rx_buff[index].dma = dma_addr;
244 pool->rx_buff[index].skb = skb;
245 pool->rx_buff[index].pool_index = pool->index;
246 pool->rx_buff[index].size = pool->buff_size;
247
248 memset(&sub_crq, 0, sizeof(sub_crq));
249 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
250 sub_crq.rx_add.correlator =
251 cpu_to_be64((u64)&pool->rx_buff[index]);
252 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
253 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
254
255 /* The length field of the sCRQ is defined to be 24 bits so the
256 * buffer size needs to be left shifted by a byte before it is
257 * converted to big endian to prevent the last byte from being
258 * truncated.
259 */
260#ifdef __LITTLE_ENDIAN__
261 shift = 8;
262#endif
263 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
264
265 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
266 &sub_crq);
267 if (lpar_rc != H_SUCCESS)
268 goto failure;
269
270 buffers_added++;
271 adapter->replenish_add_buff_success++;
272 pool->next_free = (pool->next_free + 1) % pool->size;
273 }
274 atomic_add(buffers_added, &pool->available);
275 return;
276
277failure:
278 dev_info(dev, "replenish pools failure\n");
279 pool->free_map[pool->next_free] = index;
280 pool->rx_buff[index].skb = NULL;
281 if (!dma_mapping_error(dev, dma_addr))
282 dma_unmap_single(dev, dma_addr, pool->buff_size,
283 DMA_FROM_DEVICE);
284
285 dev_kfree_skb_any(skb);
286 adapter->replenish_add_buff_failure++;
287 atomic_add(buffers_added, &pool->available);
288}
289
290static void replenish_pools(struct ibmvnic_adapter *adapter)
291{
292 int i;
293
294 if (adapter->migrated)
295 return;
296
297 adapter->replenish_task_cycles++;
298 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
299 i++) {
300 if (adapter->rx_pool[i].active)
301 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
302 }
303}
304
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -0400305static void release_stats_token(struct ibmvnic_adapter *adapter)
306{
307 struct device *dev = &adapter->vdev->dev;
308
309 if (!adapter->stats_token)
310 return;
311
312 dma_unmap_single(dev, adapter->stats_token,
313 sizeof(struct ibmvnic_statistics),
314 DMA_FROM_DEVICE);
315 adapter->stats_token = 0;
316}
317
318static int init_stats_token(struct ibmvnic_adapter *adapter)
319{
320 struct device *dev = &adapter->vdev->dev;
321 dma_addr_t stok;
322
323 stok = dma_map_single(dev, &adapter->stats,
324 sizeof(struct ibmvnic_statistics),
325 DMA_FROM_DEVICE);
326 if (dma_mapping_error(dev, stok)) {
327 dev_err(dev, "Couldn't map stats buffer\n");
328 return -1;
329 }
330
331 adapter->stats_token = stok;
332 return 0;
333}
334
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400335static void release_rx_pools(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600336{
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400337 struct ibmvnic_rx_pool *rx_pool;
338 int rx_scrqs;
339 int i, j;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600340
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400341 if (!adapter->rx_pool)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600342 return;
343
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400344 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
345 for (i = 0; i < rx_scrqs; i++) {
346 rx_pool = &adapter->rx_pool[i];
347
348 kfree(rx_pool->free_map);
349 free_long_term_buff(adapter, &rx_pool->long_term_buff);
350
351 if (!rx_pool->rx_buff)
352 continue;
353
354 for (j = 0; j < rx_pool->size; j++) {
355 if (rx_pool->rx_buff[j].skb) {
356 dev_kfree_skb_any(rx_pool->rx_buff[i].skb);
357 rx_pool->rx_buff[i].skb = NULL;
358 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600359 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400360
361 kfree(rx_pool->rx_buff);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600362 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400363
364 kfree(adapter->rx_pool);
365 adapter->rx_pool = NULL;
366}
367
368static int init_rx_pools(struct net_device *netdev)
369{
370 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
371 struct device *dev = &adapter->vdev->dev;
372 struct ibmvnic_rx_pool *rx_pool;
373 int rxadd_subcrqs;
374 u64 *size_array;
375 int i, j;
376
377 rxadd_subcrqs =
378 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
379 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
380 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
381
382 adapter->rx_pool = kcalloc(rxadd_subcrqs,
383 sizeof(struct ibmvnic_rx_pool),
384 GFP_KERNEL);
385 if (!adapter->rx_pool) {
386 dev_err(dev, "Failed to allocate rx pools\n");
387 return -1;
388 }
389
390 for (i = 0; i < rxadd_subcrqs; i++) {
391 rx_pool = &adapter->rx_pool[i];
392
393 netdev_dbg(adapter->netdev,
394 "Initializing rx_pool %d, %lld buffs, %lld bytes each\n",
395 i, adapter->req_rx_add_entries_per_subcrq,
396 be64_to_cpu(size_array[i]));
397
398 rx_pool->size = adapter->req_rx_add_entries_per_subcrq;
399 rx_pool->index = i;
400 rx_pool->buff_size = be64_to_cpu(size_array[i]);
401 rx_pool->active = 1;
402
403 rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int),
404 GFP_KERNEL);
405 if (!rx_pool->free_map) {
406 release_rx_pools(adapter);
407 return -1;
408 }
409
410 rx_pool->rx_buff = kcalloc(rx_pool->size,
411 sizeof(struct ibmvnic_rx_buff),
412 GFP_KERNEL);
413 if (!rx_pool->rx_buff) {
414 dev_err(dev, "Couldn't alloc rx buffers\n");
415 release_rx_pools(adapter);
416 return -1;
417 }
418
419 if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
420 rx_pool->size * rx_pool->buff_size)) {
421 release_rx_pools(adapter);
422 return -1;
423 }
424
425 for (j = 0; j < rx_pool->size; ++j)
426 rx_pool->free_map[j] = j;
427
428 atomic_set(&rx_pool->available, 0);
429 rx_pool->next_alloc = 0;
430 rx_pool->next_free = 0;
431 }
432
433 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600434}
435
Nathan Fontenotc657e322017-03-30 02:49:06 -0400436static void release_tx_pools(struct ibmvnic_adapter *adapter)
437{
438 struct ibmvnic_tx_pool *tx_pool;
439 int i, tx_scrqs;
440
441 if (!adapter->tx_pool)
442 return;
443
444 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
445 for (i = 0; i < tx_scrqs; i++) {
446 tx_pool = &adapter->tx_pool[i];
447 kfree(tx_pool->tx_buff);
448 free_long_term_buff(adapter, &tx_pool->long_term_buff);
449 kfree(tx_pool->free_map);
450 }
451
452 kfree(adapter->tx_pool);
453 adapter->tx_pool = NULL;
454}
455
456static int init_tx_pools(struct net_device *netdev)
457{
458 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
459 struct device *dev = &adapter->vdev->dev;
460 struct ibmvnic_tx_pool *tx_pool;
461 int tx_subcrqs;
462 int i, j;
463
464 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
465 adapter->tx_pool = kcalloc(tx_subcrqs,
466 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
467 if (!adapter->tx_pool)
468 return -1;
469
470 for (i = 0; i < tx_subcrqs; i++) {
471 tx_pool = &adapter->tx_pool[i];
472 tx_pool->tx_buff = kcalloc(adapter->req_tx_entries_per_subcrq,
473 sizeof(struct ibmvnic_tx_buff),
474 GFP_KERNEL);
475 if (!tx_pool->tx_buff) {
476 dev_err(dev, "tx pool buffer allocation failed\n");
477 release_tx_pools(adapter);
478 return -1;
479 }
480
481 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
482 adapter->req_tx_entries_per_subcrq *
483 adapter->req_mtu)) {
484 release_tx_pools(adapter);
485 return -1;
486 }
487
488 tx_pool->free_map = kcalloc(adapter->req_tx_entries_per_subcrq,
489 sizeof(int), GFP_KERNEL);
490 if (!tx_pool->free_map) {
491 release_tx_pools(adapter);
492 return -1;
493 }
494
495 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
496 tx_pool->free_map[j] = j;
497
498 tx_pool->consumer_index = 0;
499 tx_pool->producer_index = 0;
500 }
501
502 return 0;
503}
504
Nathan Fontenotf0b8c962017-03-30 02:49:00 -0400505static void release_bounce_buffer(struct ibmvnic_adapter *adapter)
506{
507 struct device *dev = &adapter->vdev->dev;
508
509 if (!adapter->bounce_buffer)
510 return;
511
512 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
513 dma_unmap_single(dev, adapter->bounce_buffer_dma,
514 adapter->bounce_buffer_size,
515 DMA_BIDIRECTIONAL);
516 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
517 }
518
519 kfree(adapter->bounce_buffer);
520 adapter->bounce_buffer = NULL;
521}
522
523static int init_bounce_buffer(struct net_device *netdev)
524{
525 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
526 struct device *dev = &adapter->vdev->dev;
527 char *buf;
528 int buf_sz;
529 dma_addr_t map_addr;
530
531 buf_sz = (netdev->mtu + ETH_HLEN - 1) / PAGE_SIZE + 1;
532 buf = kmalloc(adapter->bounce_buffer_size, GFP_KERNEL);
533 if (!buf)
534 return -1;
535
536 map_addr = dma_map_single(dev, buf, buf_sz, DMA_TO_DEVICE);
537 if (dma_mapping_error(dev, map_addr)) {
538 dev_err(dev, "Couldn't map bounce buffer\n");
539 kfree(buf);
540 return -1;
541 }
542
543 adapter->bounce_buffer = buf;
544 adapter->bounce_buffer_size = buf_sz;
545 adapter->bounce_buffer_dma = map_addr;
546 return 0;
547}
548
Nathan Fontenot661a2622017-04-19 13:44:58 -0400549static void release_error_buffers(struct ibmvnic_adapter *adapter)
550{
551 struct device *dev = &adapter->vdev->dev;
552 struct ibmvnic_error_buff *error_buff, *tmp;
553 unsigned long flags;
554
555 spin_lock_irqsave(&adapter->error_list_lock, flags);
556 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) {
557 list_del(&error_buff->list);
558 dma_unmap_single(dev, error_buff->dma, error_buff->len,
559 DMA_FROM_DEVICE);
560 kfree(error_buff->buff);
561 kfree(error_buff);
562 }
563 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
564}
565
John Allena57a5d22017-03-17 17:13:41 -0500566static int ibmvnic_login(struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600567{
568 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allenbd0b6722017-03-17 17:13:40 -0500569 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600570 struct device *dev = &adapter->vdev->dev;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600571
John Allenbd0b6722017-03-17 17:13:40 -0500572 do {
573 if (adapter->renegotiate) {
574 adapter->renegotiate = false;
Nathan Fontenotb5108882017-03-30 02:49:18 -0400575 release_sub_crqs(adapter);
John Allenbd0b6722017-03-17 17:13:40 -0500576
577 reinit_completion(&adapter->init_done);
578 send_cap_queries(adapter);
579 if (!wait_for_completion_timeout(&adapter->init_done,
580 timeout)) {
581 dev_err(dev, "Capabilities query timeout\n");
582 return -1;
583 }
584 }
585
586 reinit_completion(&adapter->init_done);
587 send_login(adapter);
588 if (!wait_for_completion_timeout(&adapter->init_done,
589 timeout)) {
590 dev_err(dev, "Login timeout\n");
591 return -1;
592 }
593 } while (adapter->renegotiate);
594
John Allena57a5d22017-03-17 17:13:41 -0500595 return 0;
596}
597
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400598static void release_resources(struct ibmvnic_adapter *adapter)
599{
600 release_bounce_buffer(adapter);
601 release_tx_pools(adapter);
602 release_rx_pools(adapter);
603
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400604 release_stats_token(adapter);
Nathan Fontenot661a2622017-04-19 13:44:58 -0400605 release_error_buffers(adapter);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400606}
607
John Allena57a5d22017-03-17 17:13:41 -0500608static int ibmvnic_open(struct net_device *netdev)
609{
610 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
611 struct device *dev = &adapter->vdev->dev;
John Allena57a5d22017-03-17 17:13:41 -0500612 union ibmvnic_crq crq;
John Allena57a5d22017-03-17 17:13:41 -0500613 int rc = 0;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400614 int i;
John Allena57a5d22017-03-17 17:13:41 -0500615
John Allenea5509f2017-03-17 17:13:43 -0500616 if (adapter->is_closed) {
617 rc = ibmvnic_init(adapter);
618 if (rc)
619 return rc;
620 }
621
John Allena57a5d22017-03-17 17:13:41 -0500622 rc = ibmvnic_login(netdev);
623 if (rc)
624 return rc;
625
John Allenbd0b6722017-03-17 17:13:40 -0500626 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
627 if (rc) {
628 dev_err(dev, "failed to set the number of tx queues\n");
629 return -1;
630 }
631
632 rc = init_sub_crq_irqs(adapter);
633 if (rc) {
634 dev_err(dev, "failed to initialize sub crq irqs\n");
635 return -1;
636 }
637
Thomas Falcon032c5e82015-12-21 11:26:06 -0600638 adapter->map_id = 1;
639 adapter->napi = kcalloc(adapter->req_rx_queues,
640 sizeof(struct napi_struct), GFP_KERNEL);
641 if (!adapter->napi)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400642 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600643 for (i = 0; i < adapter->req_rx_queues; i++) {
644 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
645 NAPI_POLL_WEIGHT);
646 napi_enable(&adapter->napi[i]);
647 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600648
Thomas Falcon032c5e82015-12-21 11:26:06 -0600649 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400650
651 rc = init_rx_pools(netdev);
652 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400653 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600654
Nathan Fontenotc657e322017-03-30 02:49:06 -0400655 rc = init_tx_pools(netdev);
656 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400657 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600658
Nathan Fontenotf0b8c962017-03-30 02:49:00 -0400659 rc = init_bounce_buffer(netdev);
660 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400661 goto ibmvnic_open_fail;
Nathan Fontenotf0b8c962017-03-30 02:49:00 -0400662
Thomas Falcon032c5e82015-12-21 11:26:06 -0600663 replenish_pools(adapter);
664
665 /* We're ready to receive frames, enable the sub-crq interrupts and
666 * set the logical link state to up
667 */
668 for (i = 0; i < adapter->req_rx_queues; i++)
669 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
670
671 for (i = 0; i < adapter->req_tx_queues; i++)
672 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
673
674 memset(&crq, 0, sizeof(crq));
675 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
676 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
677 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_UP;
678 ibmvnic_send_crq(adapter, &crq);
679
Thomas Falconb8efb892016-07-06 15:35:15 -0500680 netif_tx_start_all_queues(netdev);
John Allenea5509f2017-03-17 17:13:43 -0500681 adapter->is_closed = false;
Thomas Falconb8efb892016-07-06 15:35:15 -0500682
Thomas Falcon032c5e82015-12-21 11:26:06 -0600683 return 0;
684
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400685ibmvnic_open_fail:
Thomas Falcon032c5e82015-12-21 11:26:06 -0600686 for (i = 0; i < adapter->req_rx_queues; i++)
Nathan Fontenote722af62017-02-10 13:29:06 -0500687 napi_disable(&adapter->napi[i]);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400688 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600689 return -ENOMEM;
690}
691
John Allenea5509f2017-03-17 17:13:43 -0500692static int ibmvnic_close(struct net_device *netdev)
693{
694 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
695 union ibmvnic_crq crq;
696 int i;
697
698 adapter->closing = true;
699
700 for (i = 0; i < adapter->req_rx_queues; i++)
701 napi_disable(&adapter->napi[i]);
702
703 if (!adapter->failover)
704 netif_tx_stop_all_queues(netdev);
705
Thomas Falcon032c5e82015-12-21 11:26:06 -0600706 memset(&crq, 0, sizeof(crq));
707 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
708 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
709 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_DN;
710 ibmvnic_send_crq(adapter, &crq);
711
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400712 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600713
John Allenea5509f2017-03-17 17:13:43 -0500714 adapter->is_closed = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600715 adapter->closing = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600716 return 0;
717}
718
Thomas Falconad7775d2016-04-01 17:20:34 -0500719/**
720 * build_hdr_data - creates L2/L3/L4 header data buffer
721 * @hdr_field - bitfield determining needed headers
722 * @skb - socket buffer
723 * @hdr_len - array of header lengths
724 * @tot_len - total length of data
725 *
726 * Reads hdr_field to determine which headers are needed by firmware.
727 * Builds a buffer containing these headers. Saves individual header
728 * lengths and total buffer length to be used to build descriptors.
729 */
730static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
731 int *hdr_len, u8 *hdr_data)
732{
733 int len = 0;
734 u8 *hdr;
735
736 hdr_len[0] = sizeof(struct ethhdr);
737
738 if (skb->protocol == htons(ETH_P_IP)) {
739 hdr_len[1] = ip_hdr(skb)->ihl * 4;
740 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
741 hdr_len[2] = tcp_hdrlen(skb);
742 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
743 hdr_len[2] = sizeof(struct udphdr);
744 } else if (skb->protocol == htons(ETH_P_IPV6)) {
745 hdr_len[1] = sizeof(struct ipv6hdr);
746 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
747 hdr_len[2] = tcp_hdrlen(skb);
748 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
749 hdr_len[2] = sizeof(struct udphdr);
750 }
751
752 memset(hdr_data, 0, 120);
753 if ((hdr_field >> 6) & 1) {
754 hdr = skb_mac_header(skb);
755 memcpy(hdr_data, hdr, hdr_len[0]);
756 len += hdr_len[0];
757 }
758
759 if ((hdr_field >> 5) & 1) {
760 hdr = skb_network_header(skb);
761 memcpy(hdr_data + len, hdr, hdr_len[1]);
762 len += hdr_len[1];
763 }
764
765 if ((hdr_field >> 4) & 1) {
766 hdr = skb_transport_header(skb);
767 memcpy(hdr_data + len, hdr, hdr_len[2]);
768 len += hdr_len[2];
769 }
770 return len;
771}
772
773/**
774 * create_hdr_descs - create header and header extension descriptors
775 * @hdr_field - bitfield determining needed headers
776 * @data - buffer containing header data
777 * @len - length of data buffer
778 * @hdr_len - array of individual header lengths
779 * @scrq_arr - descriptor array
780 *
781 * Creates header and, if needed, header extension descriptors and
782 * places them in a descriptor array, scrq_arr
783 */
784
785static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
786 union sub_crq *scrq_arr)
787{
788 union sub_crq hdr_desc;
789 int tmp_len = len;
790 u8 *data, *cur;
791 int tmp;
792
793 while (tmp_len > 0) {
794 cur = hdr_data + len - tmp_len;
795
796 memset(&hdr_desc, 0, sizeof(hdr_desc));
797 if (cur != hdr_data) {
798 data = hdr_desc.hdr_ext.data;
799 tmp = tmp_len > 29 ? 29 : tmp_len;
800 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
801 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
802 hdr_desc.hdr_ext.len = tmp;
803 } else {
804 data = hdr_desc.hdr.data;
805 tmp = tmp_len > 24 ? 24 : tmp_len;
806 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
807 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
808 hdr_desc.hdr.len = tmp;
809 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
810 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
811 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
812 hdr_desc.hdr.flag = hdr_field << 1;
813 }
814 memcpy(data, cur, tmp);
815 tmp_len -= tmp;
816 *scrq_arr = hdr_desc;
817 scrq_arr++;
818 }
819}
820
821/**
822 * build_hdr_descs_arr - build a header descriptor array
823 * @skb - socket buffer
824 * @num_entries - number of descriptors to be sent
825 * @subcrq - first TX descriptor
826 * @hdr_field - bit field determining which headers will be sent
827 *
828 * This function will build a TX descriptor array with applicable
829 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
830 */
831
832static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
833 int *num_entries, u8 hdr_field)
834{
835 int hdr_len[3] = {0, 0, 0};
836 int tot_len, len;
837 u8 *hdr_data = txbuff->hdr_data;
838
839 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
840 txbuff->hdr_data);
841 len = tot_len;
842 len -= 24;
843 if (len > 0)
844 num_entries += len % 29 ? len / 29 + 1 : len / 29;
845 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
846 txbuff->indir_arr + 1);
847}
848
Thomas Falcon032c5e82015-12-21 11:26:06 -0600849static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
850{
851 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
852 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -0500853 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600854 struct device *dev = &adapter->vdev->dev;
855 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600856 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600857 struct ibmvnic_tx_pool *tx_pool;
858 unsigned int tx_send_failed = 0;
859 unsigned int tx_map_failed = 0;
860 unsigned int tx_dropped = 0;
861 unsigned int tx_packets = 0;
862 unsigned int tx_bytes = 0;
863 dma_addr_t data_dma_addr;
864 struct netdev_queue *txq;
865 bool used_bounce = false;
866 unsigned long lpar_rc;
867 union sub_crq tx_crq;
868 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -0500869 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600870 unsigned char *dst;
871 u64 *handle_array;
872 int index = 0;
873 int ret = 0;
874
875 tx_pool = &adapter->tx_pool[queue_num];
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600876 tx_scrq = adapter->tx_scrq[queue_num];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600877 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
878 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
879 be32_to_cpu(adapter->login_rsp_buf->
880 off_txsubm_subcrqs));
881 if (adapter->migrated) {
882 tx_send_failed++;
883 tx_dropped++;
884 ret = NETDEV_TX_BUSY;
885 goto out;
886 }
887
888 index = tx_pool->free_map[tx_pool->consumer_index];
889 offset = index * adapter->req_mtu;
890 dst = tx_pool->long_term_buff.buff + offset;
891 memset(dst, 0, adapter->req_mtu);
892 skb_copy_from_linear_data(skb, dst, skb->len);
893 data_dma_addr = tx_pool->long_term_buff.addr + offset;
894
895 tx_pool->consumer_index =
896 (tx_pool->consumer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -0600897 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600898
899 tx_buff = &tx_pool->tx_buff[index];
900 tx_buff->skb = skb;
901 tx_buff->data_dma[0] = data_dma_addr;
902 tx_buff->data_len[0] = skb->len;
903 tx_buff->index = index;
904 tx_buff->pool_index = queue_num;
905 tx_buff->last_frag = true;
906 tx_buff->used_bounce = used_bounce;
907
908 memset(&tx_crq, 0, sizeof(tx_crq));
909 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
910 tx_crq.v1.type = IBMVNIC_TX_DESC;
911 tx_crq.v1.n_crq_elem = 1;
912 tx_crq.v1.n_sge = 1;
913 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
914 tx_crq.v1.correlator = cpu_to_be32(index);
915 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
916 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
917 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
918
919 if (adapter->vlan_header_insertion) {
920 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
921 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
922 }
923
924 if (skb->protocol == htons(ETH_P_IP)) {
925 if (ip_hdr(skb)->version == 4)
926 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
927 else if (ip_hdr(skb)->version == 6)
928 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
929
930 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
931 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
932 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
933 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
934 }
935
Thomas Falconad7775d2016-04-01 17:20:34 -0500936 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -0600937 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -0500938 hdrs += 2;
939 }
940 /* determine if l2/3/4 headers are sent to firmware */
941 if ((*hdrs >> 7) & 1 &&
942 (skb->protocol == htons(ETH_P_IP) ||
943 skb->protocol == htons(ETH_P_IPV6))) {
944 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
945 tx_crq.v1.n_crq_elem = num_entries;
946 tx_buff->indir_arr[0] = tx_crq;
947 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
948 sizeof(tx_buff->indir_arr),
949 DMA_TO_DEVICE);
950 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
951 if (!firmware_has_feature(FW_FEATURE_CMO))
952 dev_err(dev, "tx: unable to map descriptor array\n");
953 tx_map_failed++;
954 tx_dropped++;
955 ret = NETDEV_TX_BUSY;
956 goto out;
957 }
John Allen498cd8e2016-04-06 11:49:55 -0500958 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -0500959 (u64)tx_buff->indir_dma,
960 (u64)num_entries);
961 } else {
John Allen498cd8e2016-04-06 11:49:55 -0500962 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
963 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -0500964 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600965 if (lpar_rc != H_SUCCESS) {
966 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
967
968 if (tx_pool->consumer_index == 0)
969 tx_pool->consumer_index =
Thomas Falcon068d9f92017-03-05 12:18:42 -0600970 adapter->req_tx_entries_per_subcrq - 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600971 else
972 tx_pool->consumer_index--;
973
974 tx_send_failed++;
975 tx_dropped++;
976 ret = NETDEV_TX_BUSY;
977 goto out;
978 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600979
Brian King58c8c0c2017-04-19 13:44:47 -0400980 if (atomic_inc_return(&tx_scrq->used)
981 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600982 netdev_info(netdev, "Stopping queue %d\n", queue_num);
983 netif_stop_subqueue(netdev, queue_num);
984 }
985
Thomas Falcon032c5e82015-12-21 11:26:06 -0600986 tx_packets++;
987 tx_bytes += skb->len;
988 txq->trans_start = jiffies;
989 ret = NETDEV_TX_OK;
990
991out:
992 netdev->stats.tx_dropped += tx_dropped;
993 netdev->stats.tx_bytes += tx_bytes;
994 netdev->stats.tx_packets += tx_packets;
995 adapter->tx_send_failed += tx_send_failed;
996 adapter->tx_map_failed += tx_map_failed;
997
998 return ret;
999}
1000
1001static void ibmvnic_set_multi(struct net_device *netdev)
1002{
1003 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1004 struct netdev_hw_addr *ha;
1005 union ibmvnic_crq crq;
1006
1007 memset(&crq, 0, sizeof(crq));
1008 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1009 crq.request_capability.cmd = REQUEST_CAPABILITY;
1010
1011 if (netdev->flags & IFF_PROMISC) {
1012 if (!adapter->promisc_supported)
1013 return;
1014 } else {
1015 if (netdev->flags & IFF_ALLMULTI) {
1016 /* Accept all multicast */
1017 memset(&crq, 0, sizeof(crq));
1018 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1019 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1020 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1021 ibmvnic_send_crq(adapter, &crq);
1022 } else if (netdev_mc_empty(netdev)) {
1023 /* Reject all multicast */
1024 memset(&crq, 0, sizeof(crq));
1025 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1026 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1027 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1028 ibmvnic_send_crq(adapter, &crq);
1029 } else {
1030 /* Accept one or more multicast(s) */
1031 netdev_for_each_mc_addr(ha, netdev) {
1032 memset(&crq, 0, sizeof(crq));
1033 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1034 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1035 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1036 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1037 ha->addr);
1038 ibmvnic_send_crq(adapter, &crq);
1039 }
1040 }
1041 }
1042}
1043
1044static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1045{
1046 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1047 struct sockaddr *addr = p;
1048 union ibmvnic_crq crq;
1049
1050 if (!is_valid_ether_addr(addr->sa_data))
1051 return -EADDRNOTAVAIL;
1052
1053 memset(&crq, 0, sizeof(crq));
1054 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1055 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1056 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1057 ibmvnic_send_crq(adapter, &crq);
1058 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1059 return 0;
1060}
1061
Thomas Falcon032c5e82015-12-21 11:26:06 -06001062static void ibmvnic_tx_timeout(struct net_device *dev)
1063{
1064 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1065 int rc;
1066
1067 /* Adapter timed out, resetting it */
1068 release_sub_crqs(adapter);
1069 rc = ibmvnic_reset_crq(adapter);
1070 if (rc)
1071 dev_err(&adapter->vdev->dev, "Adapter timeout, reset failed\n");
1072 else
1073 ibmvnic_send_crq_init(adapter);
1074}
1075
1076static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
1077 struct ibmvnic_rx_buff *rx_buff)
1078{
1079 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
1080
1081 rx_buff->skb = NULL;
1082
1083 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
1084 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
1085
1086 atomic_dec(&pool->available);
1087}
1088
1089static int ibmvnic_poll(struct napi_struct *napi, int budget)
1090{
1091 struct net_device *netdev = napi->dev;
1092 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1093 int scrq_num = (int)(napi - adapter->napi);
1094 int frames_processed = 0;
1095restart_poll:
1096 while (frames_processed < budget) {
1097 struct sk_buff *skb;
1098 struct ibmvnic_rx_buff *rx_buff;
1099 union sub_crq *next;
1100 u32 length;
1101 u16 offset;
1102 u8 flags = 0;
1103
1104 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
1105 break;
1106 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
1107 rx_buff =
1108 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
1109 rx_comp.correlator);
1110 /* do error checking */
1111 if (next->rx_comp.rc) {
1112 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
1113 /* free the entry */
1114 next->rx_comp.first = 0;
1115 remove_buff_from_pool(adapter, rx_buff);
1116 break;
1117 }
1118
1119 length = be32_to_cpu(next->rx_comp.len);
1120 offset = be16_to_cpu(next->rx_comp.off_frame_data);
1121 flags = next->rx_comp.flags;
1122 skb = rx_buff->skb;
1123 skb_copy_to_linear_data(skb, rx_buff->data + offset,
1124 length);
1125 skb->vlan_tci = be16_to_cpu(next->rx_comp.vlan_tci);
1126 /* free the entry */
1127 next->rx_comp.first = 0;
1128 remove_buff_from_pool(adapter, rx_buff);
1129
1130 skb_put(skb, length);
1131 skb->protocol = eth_type_trans(skb, netdev);
1132
1133 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
1134 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
1135 skb->ip_summed = CHECKSUM_UNNECESSARY;
1136 }
1137
1138 length = skb->len;
1139 napi_gro_receive(napi, skb); /* send it up */
1140 netdev->stats.rx_packets++;
1141 netdev->stats.rx_bytes += length;
1142 frames_processed++;
1143 }
John Allen498cd8e2016-04-06 11:49:55 -05001144 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001145
1146 if (frames_processed < budget) {
1147 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08001148 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001149 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1150 napi_reschedule(napi)) {
1151 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1152 goto restart_poll;
1153 }
1154 }
1155 return frames_processed;
1156}
1157
1158#ifdef CONFIG_NET_POLL_CONTROLLER
1159static void ibmvnic_netpoll_controller(struct net_device *dev)
1160{
1161 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1162 int i;
1163
1164 replenish_pools(netdev_priv(dev));
1165 for (i = 0; i < adapter->req_rx_queues; i++)
1166 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1167 adapter->rx_scrq[i]);
1168}
1169#endif
1170
1171static const struct net_device_ops ibmvnic_netdev_ops = {
1172 .ndo_open = ibmvnic_open,
1173 .ndo_stop = ibmvnic_close,
1174 .ndo_start_xmit = ibmvnic_xmit,
1175 .ndo_set_rx_mode = ibmvnic_set_multi,
1176 .ndo_set_mac_address = ibmvnic_set_mac,
1177 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001178 .ndo_tx_timeout = ibmvnic_tx_timeout,
1179#ifdef CONFIG_NET_POLL_CONTROLLER
1180 .ndo_poll_controller = ibmvnic_netpoll_controller,
1181#endif
1182};
1183
1184/* ethtool functions */
1185
Philippe Reynes8a433792017-01-07 22:37:29 +01001186static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1187 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001188{
Philippe Reynes8a433792017-01-07 22:37:29 +01001189 u32 supported, advertising;
1190
1191 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001192 SUPPORTED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001193 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001194 ADVERTISED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001195 cmd->base.speed = SPEED_1000;
1196 cmd->base.duplex = DUPLEX_FULL;
1197 cmd->base.port = PORT_FIBRE;
1198 cmd->base.phy_address = 0;
1199 cmd->base.autoneg = AUTONEG_ENABLE;
1200
1201 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1202 supported);
1203 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1204 advertising);
1205
Thomas Falcon032c5e82015-12-21 11:26:06 -06001206 return 0;
1207}
1208
1209static void ibmvnic_get_drvinfo(struct net_device *dev,
1210 struct ethtool_drvinfo *info)
1211{
1212 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1213 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1214}
1215
1216static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1217{
1218 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1219
1220 return adapter->msg_enable;
1221}
1222
1223static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1224{
1225 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1226
1227 adapter->msg_enable = data;
1228}
1229
1230static u32 ibmvnic_get_link(struct net_device *netdev)
1231{
1232 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1233
1234 /* Don't need to send a query because we request a logical link up at
1235 * init and then we wait for link state indications
1236 */
1237 return adapter->logical_link_state;
1238}
1239
1240static void ibmvnic_get_ringparam(struct net_device *netdev,
1241 struct ethtool_ringparam *ring)
1242{
1243 ring->rx_max_pending = 0;
1244 ring->tx_max_pending = 0;
1245 ring->rx_mini_max_pending = 0;
1246 ring->rx_jumbo_max_pending = 0;
1247 ring->rx_pending = 0;
1248 ring->tx_pending = 0;
1249 ring->rx_mini_pending = 0;
1250 ring->rx_jumbo_pending = 0;
1251}
1252
1253static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1254{
1255 int i;
1256
1257 if (stringset != ETH_SS_STATS)
1258 return;
1259
1260 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1261 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1262}
1263
1264static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1265{
1266 switch (sset) {
1267 case ETH_SS_STATS:
1268 return ARRAY_SIZE(ibmvnic_stats);
1269 default:
1270 return -EOPNOTSUPP;
1271 }
1272}
1273
1274static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1275 struct ethtool_stats *stats, u64 *data)
1276{
1277 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1278 union ibmvnic_crq crq;
1279 int i;
1280
1281 memset(&crq, 0, sizeof(crq));
1282 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1283 crq.request_statistics.cmd = REQUEST_STATISTICS;
1284 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1285 crq.request_statistics.len =
1286 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06001287
1288 /* Wait for data to be written */
1289 init_completion(&adapter->stats_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05001290 ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001291 wait_for_completion(&adapter->stats_done);
1292
1293 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1294 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1295}
1296
1297static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001298 .get_drvinfo = ibmvnic_get_drvinfo,
1299 .get_msglevel = ibmvnic_get_msglevel,
1300 .set_msglevel = ibmvnic_set_msglevel,
1301 .get_link = ibmvnic_get_link,
1302 .get_ringparam = ibmvnic_get_ringparam,
1303 .get_strings = ibmvnic_get_strings,
1304 .get_sset_count = ibmvnic_get_sset_count,
1305 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01001306 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001307};
1308
1309/* Routines for managing CRQs/sCRQs */
1310
1311static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1312 struct ibmvnic_sub_crq_queue *scrq)
1313{
1314 struct device *dev = &adapter->vdev->dev;
1315 long rc;
1316
1317 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1318
1319 /* Close the sub-crqs */
1320 do {
1321 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1322 adapter->vdev->unit_address,
1323 scrq->crq_num);
1324 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1325
Thomas Falconffa73852017-04-19 13:44:29 -04001326 if (rc) {
1327 netdev_err(adapter->netdev,
1328 "Failed to release sub-CRQ %16lx, rc = %ld\n",
1329 scrq->crq_num, rc);
1330 }
1331
Thomas Falcon032c5e82015-12-21 11:26:06 -06001332 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1333 DMA_BIDIRECTIONAL);
1334 free_pages((unsigned long)scrq->msgs, 2);
1335 kfree(scrq);
1336}
1337
1338static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1339 *adapter)
1340{
1341 struct device *dev = &adapter->vdev->dev;
1342 struct ibmvnic_sub_crq_queue *scrq;
1343 int rc;
1344
1345 scrq = kmalloc(sizeof(*scrq), GFP_ATOMIC);
1346 if (!scrq)
1347 return NULL;
1348
Thomas Falcon12608c22016-10-17 15:28:09 -05001349 scrq->msgs = (union sub_crq *)__get_free_pages(GFP_ATOMIC, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001350 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
1351 if (!scrq->msgs) {
1352 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1353 goto zero_page_failed;
1354 }
1355
1356 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1357 DMA_BIDIRECTIONAL);
1358 if (dma_mapping_error(dev, scrq->msg_token)) {
1359 dev_warn(dev, "Couldn't map crq queue messages page\n");
1360 goto map_failed;
1361 }
1362
1363 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1364 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1365
1366 if (rc == H_RESOURCE)
1367 rc = ibmvnic_reset_crq(adapter);
1368
1369 if (rc == H_CLOSED) {
1370 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1371 } else if (rc) {
1372 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1373 goto reg_failed;
1374 }
1375
Thomas Falcon032c5e82015-12-21 11:26:06 -06001376 scrq->adapter = adapter;
1377 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
1378 scrq->cur = 0;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001379 atomic_set(&scrq->used, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001380 scrq->rx_skb_top = NULL;
1381 spin_lock_init(&scrq->lock);
1382
1383 netdev_dbg(adapter->netdev,
1384 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1385 scrq->crq_num, scrq->hw_irq, scrq->irq);
1386
1387 return scrq;
1388
Thomas Falcon032c5e82015-12-21 11:26:06 -06001389reg_failed:
1390 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1391 DMA_BIDIRECTIONAL);
1392map_failed:
1393 free_pages((unsigned long)scrq->msgs, 2);
1394zero_page_failed:
1395 kfree(scrq);
1396
1397 return NULL;
1398}
1399
1400static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1401{
1402 int i;
1403
1404 if (adapter->tx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001405 for (i = 0; i < adapter->req_tx_queues; i++) {
1406 if (!adapter->tx_scrq[i])
1407 continue;
1408
1409 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001410 free_irq(adapter->tx_scrq[i]->irq,
1411 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001412 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001413 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001414 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001415
1416 release_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1417 }
1418
Nathan Fontenot9501df32017-03-15 23:38:07 -04001419 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001420 adapter->tx_scrq = NULL;
1421 }
1422
1423 if (adapter->rx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001424 for (i = 0; i < adapter->req_rx_queues; i++) {
1425 if (!adapter->rx_scrq[i])
1426 continue;
1427
1428 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001429 free_irq(adapter->rx_scrq[i]->irq,
1430 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001431 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001432 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001433 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001434
1435 release_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1436 }
1437
Nathan Fontenot9501df32017-03-15 23:38:07 -04001438 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001439 adapter->rx_scrq = NULL;
1440 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001441}
1442
1443static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1444 struct ibmvnic_sub_crq_queue *scrq)
1445{
1446 struct device *dev = &adapter->vdev->dev;
1447 unsigned long rc;
1448
1449 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1450 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1451 if (rc)
1452 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1453 scrq->hw_irq, rc);
1454 return rc;
1455}
1456
1457static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1458 struct ibmvnic_sub_crq_queue *scrq)
1459{
1460 struct device *dev = &adapter->vdev->dev;
1461 unsigned long rc;
1462
1463 if (scrq->hw_irq > 0x100000000ULL) {
1464 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1465 return 1;
1466 }
1467
1468 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1469 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1470 if (rc)
1471 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1472 scrq->hw_irq, rc);
1473 return rc;
1474}
1475
1476static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1477 struct ibmvnic_sub_crq_queue *scrq)
1478{
1479 struct device *dev = &adapter->vdev->dev;
1480 struct ibmvnic_tx_buff *txbuff;
1481 union sub_crq *next;
1482 int index;
1483 int i, j;
Thomas Falconad7775d2016-04-01 17:20:34 -05001484 u8 first;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001485
1486restart_loop:
1487 while (pending_scrq(adapter, scrq)) {
1488 unsigned int pool = scrq->pool_index;
1489
1490 next = ibmvnic_next_scrq(adapter, scrq);
1491 for (i = 0; i < next->tx_comp.num_comps; i++) {
1492 if (next->tx_comp.rcs[i]) {
1493 dev_err(dev, "tx error %x\n",
1494 next->tx_comp.rcs[i]);
1495 continue;
1496 }
1497 index = be32_to_cpu(next->tx_comp.correlators[i]);
1498 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1499
1500 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1501 if (!txbuff->data_dma[j])
1502 continue;
1503
1504 txbuff->data_dma[j] = 0;
1505 txbuff->used_bounce = false;
1506 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001507 /* if sub_crq was sent indirectly */
1508 first = txbuff->indir_arr[0].generic.first;
1509 if (first == IBMVNIC_CRQ_CMD) {
1510 dma_unmap_single(dev, txbuff->indir_dma,
1511 sizeof(txbuff->indir_arr),
1512 DMA_TO_DEVICE);
1513 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001514
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001515 if (txbuff->last_frag) {
Brian King58c8c0c2017-04-19 13:44:47 -04001516 if (atomic_sub_return(next->tx_comp.num_comps,
1517 &scrq->used) <=
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001518 (adapter->req_tx_entries_per_subcrq / 2) &&
1519 netif_subqueue_stopped(adapter->netdev,
1520 txbuff->skb)) {
1521 netif_wake_subqueue(adapter->netdev,
1522 scrq->pool_index);
1523 netdev_dbg(adapter->netdev,
1524 "Started queue %d\n",
1525 scrq->pool_index);
1526 }
1527
Thomas Falcon032c5e82015-12-21 11:26:06 -06001528 dev_kfree_skb_any(txbuff->skb);
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001529 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001530
1531 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1532 producer_index] = index;
1533 adapter->tx_pool[pool].producer_index =
1534 (adapter->tx_pool[pool].producer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001535 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001536 }
1537 /* remove tx_comp scrq*/
1538 next->tx_comp.first = 0;
1539 }
1540
1541 enable_scrq_irq(adapter, scrq);
1542
1543 if (pending_scrq(adapter, scrq)) {
1544 disable_scrq_irq(adapter, scrq);
1545 goto restart_loop;
1546 }
1547
1548 return 0;
1549}
1550
1551static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
1552{
1553 struct ibmvnic_sub_crq_queue *scrq = instance;
1554 struct ibmvnic_adapter *adapter = scrq->adapter;
1555
1556 disable_scrq_irq(adapter, scrq);
1557 ibmvnic_complete_tx(adapter, scrq);
1558
1559 return IRQ_HANDLED;
1560}
1561
1562static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
1563{
1564 struct ibmvnic_sub_crq_queue *scrq = instance;
1565 struct ibmvnic_adapter *adapter = scrq->adapter;
1566
1567 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
1568 disable_scrq_irq(adapter, scrq);
1569 __napi_schedule(&adapter->napi[scrq->scrq_num]);
1570 }
1571
1572 return IRQ_HANDLED;
1573}
1574
Thomas Falconea22d512016-07-06 15:35:17 -05001575static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
1576{
1577 struct device *dev = &adapter->vdev->dev;
1578 struct ibmvnic_sub_crq_queue *scrq;
1579 int i = 0, j = 0;
1580 int rc = 0;
1581
1582 for (i = 0; i < adapter->req_tx_queues; i++) {
1583 scrq = adapter->tx_scrq[i];
1584 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
1585
Michael Ellerman99c17902016-09-10 19:59:05 +10001586 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001587 rc = -EINVAL;
1588 dev_err(dev, "Error mapping irq\n");
1589 goto req_tx_irq_failed;
1590 }
1591
1592 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
1593 0, "ibmvnic_tx", scrq);
1594
1595 if (rc) {
1596 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
1597 scrq->irq, rc);
1598 irq_dispose_mapping(scrq->irq);
1599 goto req_rx_irq_failed;
1600 }
1601 }
1602
1603 for (i = 0; i < adapter->req_rx_queues; i++) {
1604 scrq = adapter->rx_scrq[i];
1605 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10001606 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001607 rc = -EINVAL;
1608 dev_err(dev, "Error mapping irq\n");
1609 goto req_rx_irq_failed;
1610 }
1611 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
1612 0, "ibmvnic_rx", scrq);
1613 if (rc) {
1614 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
1615 scrq->irq, rc);
1616 irq_dispose_mapping(scrq->irq);
1617 goto req_rx_irq_failed;
1618 }
1619 }
1620 return rc;
1621
1622req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001623 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001624 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
1625 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001626 }
Thomas Falconea22d512016-07-06 15:35:17 -05001627 i = adapter->req_tx_queues;
1628req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001629 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001630 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
1631 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001632 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001633 release_sub_crqs(adapter);
Thomas Falconea22d512016-07-06 15:35:17 -05001634 return rc;
1635}
1636
Thomas Falcon032c5e82015-12-21 11:26:06 -06001637static void init_sub_crqs(struct ibmvnic_adapter *adapter, int retry)
1638{
1639 struct device *dev = &adapter->vdev->dev;
1640 struct ibmvnic_sub_crq_queue **allqueues;
1641 int registered_queues = 0;
1642 union ibmvnic_crq crq;
1643 int total_queues;
1644 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05001645 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001646
1647 if (!retry) {
1648 /* Sub-CRQ entries are 32 byte long */
1649 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
1650
1651 if (adapter->min_tx_entries_per_subcrq > entries_page ||
1652 adapter->min_rx_add_entries_per_subcrq > entries_page) {
1653 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
1654 goto allqueues_failed;
1655 }
1656
1657 /* Get the minimum between the queried max and the entries
1658 * that fit in our PAGE_SIZE
1659 */
1660 adapter->req_tx_entries_per_subcrq =
1661 adapter->max_tx_entries_per_subcrq > entries_page ?
1662 entries_page : adapter->max_tx_entries_per_subcrq;
1663 adapter->req_rx_add_entries_per_subcrq =
1664 adapter->max_rx_add_entries_per_subcrq > entries_page ?
1665 entries_page : adapter->max_rx_add_entries_per_subcrq;
1666
John Allen6dbcd8f2016-11-07 14:27:28 -06001667 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
1668 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
John Allen498cd8e2016-04-06 11:49:55 -05001669 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001670
Thomas Falconf39f0d12017-02-14 10:22:59 -06001671 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001672 }
1673
1674 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
1675
1676 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_ATOMIC);
1677 if (!allqueues)
1678 goto allqueues_failed;
1679
1680 for (i = 0; i < total_queues; i++) {
1681 allqueues[i] = init_sub_crq_queue(adapter);
1682 if (!allqueues[i]) {
1683 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
1684 break;
1685 }
1686 registered_queues++;
1687 }
1688
1689 /* Make sure we were able to register the minimum number of queues */
1690 if (registered_queues <
1691 adapter->min_tx_queues + adapter->min_rx_queues) {
1692 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
1693 goto tx_failed;
1694 }
1695
1696 /* Distribute the failed allocated queues*/
1697 for (i = 0; i < total_queues - registered_queues + more ; i++) {
1698 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
1699 switch (i % 3) {
1700 case 0:
1701 if (adapter->req_rx_queues > adapter->min_rx_queues)
1702 adapter->req_rx_queues--;
1703 else
1704 more++;
1705 break;
1706 case 1:
1707 if (adapter->req_tx_queues > adapter->min_tx_queues)
1708 adapter->req_tx_queues--;
1709 else
1710 more++;
1711 break;
1712 }
1713 }
1714
1715 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
1716 sizeof(*adapter->tx_scrq), GFP_ATOMIC);
1717 if (!adapter->tx_scrq)
1718 goto tx_failed;
1719
1720 for (i = 0; i < adapter->req_tx_queues; i++) {
1721 adapter->tx_scrq[i] = allqueues[i];
1722 adapter->tx_scrq[i]->pool_index = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001723 }
1724
1725 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
1726 sizeof(*adapter->rx_scrq), GFP_ATOMIC);
1727 if (!adapter->rx_scrq)
1728 goto rx_failed;
1729
1730 for (i = 0; i < adapter->req_rx_queues; i++) {
1731 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
1732 adapter->rx_scrq[i]->scrq_num = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001733 }
1734
1735 memset(&crq, 0, sizeof(crq));
1736 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1737 crq.request_capability.cmd = REQUEST_CAPABILITY;
1738
1739 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001740 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001741 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001742 ibmvnic_send_crq(adapter, &crq);
1743
1744 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001745 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001746 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001747 ibmvnic_send_crq(adapter, &crq);
1748
1749 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001750 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001751 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001752 ibmvnic_send_crq(adapter, &crq);
1753
1754 crq.request_capability.capability =
1755 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
1756 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001757 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001758 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001759 ibmvnic_send_crq(adapter, &crq);
1760
1761 crq.request_capability.capability =
1762 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
1763 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001764 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001765 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001766 ibmvnic_send_crq(adapter, &crq);
1767
1768 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06001769 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06001770 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001771 ibmvnic_send_crq(adapter, &crq);
1772
1773 if (adapter->netdev->flags & IFF_PROMISC) {
1774 if (adapter->promisc_supported) {
1775 crq.request_capability.capability =
1776 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001777 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06001778 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001779 ibmvnic_send_crq(adapter, &crq);
1780 }
1781 } else {
1782 crq.request_capability.capability =
1783 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001784 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06001785 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001786 ibmvnic_send_crq(adapter, &crq);
1787 }
1788
1789 kfree(allqueues);
1790
1791 return;
1792
Thomas Falcon032c5e82015-12-21 11:26:06 -06001793rx_failed:
1794 kfree(adapter->tx_scrq);
1795 adapter->tx_scrq = NULL;
1796tx_failed:
1797 for (i = 0; i < registered_queues; i++)
1798 release_sub_crq_queue(adapter, allqueues[i]);
1799 kfree(allqueues);
1800allqueues_failed:
1801 ibmvnic_remove(adapter->vdev);
1802}
1803
1804static int pending_scrq(struct ibmvnic_adapter *adapter,
1805 struct ibmvnic_sub_crq_queue *scrq)
1806{
1807 union sub_crq *entry = &scrq->msgs[scrq->cur];
1808
1809 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP || adapter->closing)
1810 return 1;
1811 else
1812 return 0;
1813}
1814
1815static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
1816 struct ibmvnic_sub_crq_queue *scrq)
1817{
1818 union sub_crq *entry;
1819 unsigned long flags;
1820
1821 spin_lock_irqsave(&scrq->lock, flags);
1822 entry = &scrq->msgs[scrq->cur];
1823 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1824 if (++scrq->cur == scrq->size)
1825 scrq->cur = 0;
1826 } else {
1827 entry = NULL;
1828 }
1829 spin_unlock_irqrestore(&scrq->lock, flags);
1830
1831 return entry;
1832}
1833
1834static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
1835{
1836 struct ibmvnic_crq_queue *queue = &adapter->crq;
1837 union ibmvnic_crq *crq;
1838
1839 crq = &queue->msgs[queue->cur];
1840 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1841 if (++queue->cur == queue->size)
1842 queue->cur = 0;
1843 } else {
1844 crq = NULL;
1845 }
1846
1847 return crq;
1848}
1849
1850static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
1851 union sub_crq *sub_crq)
1852{
1853 unsigned int ua = adapter->vdev->unit_address;
1854 struct device *dev = &adapter->vdev->dev;
1855 u64 *u64_crq = (u64 *)sub_crq;
1856 int rc;
1857
1858 netdev_dbg(adapter->netdev,
1859 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
1860 (unsigned long int)cpu_to_be64(remote_handle),
1861 (unsigned long int)cpu_to_be64(u64_crq[0]),
1862 (unsigned long int)cpu_to_be64(u64_crq[1]),
1863 (unsigned long int)cpu_to_be64(u64_crq[2]),
1864 (unsigned long int)cpu_to_be64(u64_crq[3]));
1865
1866 /* Make sure the hypervisor sees the complete request */
1867 mb();
1868
1869 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
1870 cpu_to_be64(remote_handle),
1871 cpu_to_be64(u64_crq[0]),
1872 cpu_to_be64(u64_crq[1]),
1873 cpu_to_be64(u64_crq[2]),
1874 cpu_to_be64(u64_crq[3]));
1875
1876 if (rc) {
1877 if (rc == H_CLOSED)
1878 dev_warn(dev, "CRQ Queue closed\n");
1879 dev_err(dev, "Send error (rc=%d)\n", rc);
1880 }
1881
1882 return rc;
1883}
1884
Thomas Falconad7775d2016-04-01 17:20:34 -05001885static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
1886 u64 remote_handle, u64 ioba, u64 num_entries)
1887{
1888 unsigned int ua = adapter->vdev->unit_address;
1889 struct device *dev = &adapter->vdev->dev;
1890 int rc;
1891
1892 /* Make sure the hypervisor sees the complete request */
1893 mb();
1894 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
1895 cpu_to_be64(remote_handle),
1896 ioba, num_entries);
1897
1898 if (rc) {
1899 if (rc == H_CLOSED)
1900 dev_warn(dev, "CRQ Queue closed\n");
1901 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
1902 }
1903
1904 return rc;
1905}
1906
Thomas Falcon032c5e82015-12-21 11:26:06 -06001907static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
1908 union ibmvnic_crq *crq)
1909{
1910 unsigned int ua = adapter->vdev->unit_address;
1911 struct device *dev = &adapter->vdev->dev;
1912 u64 *u64_crq = (u64 *)crq;
1913 int rc;
1914
1915 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
1916 (unsigned long int)cpu_to_be64(u64_crq[0]),
1917 (unsigned long int)cpu_to_be64(u64_crq[1]));
1918
1919 /* Make sure the hypervisor sees the complete request */
1920 mb();
1921
1922 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
1923 cpu_to_be64(u64_crq[0]),
1924 cpu_to_be64(u64_crq[1]));
1925
1926 if (rc) {
1927 if (rc == H_CLOSED)
1928 dev_warn(dev, "CRQ Queue closed\n");
1929 dev_warn(dev, "Send error (rc=%d)\n", rc);
1930 }
1931
1932 return rc;
1933}
1934
1935static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
1936{
1937 union ibmvnic_crq crq;
1938
1939 memset(&crq, 0, sizeof(crq));
1940 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1941 crq.generic.cmd = IBMVNIC_CRQ_INIT;
1942 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
1943
1944 return ibmvnic_send_crq(adapter, &crq);
1945}
1946
1947static int ibmvnic_send_crq_init_complete(struct ibmvnic_adapter *adapter)
1948{
1949 union ibmvnic_crq crq;
1950
1951 memset(&crq, 0, sizeof(crq));
1952 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1953 crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE;
1954 netdev_dbg(adapter->netdev, "Sending CRQ init complete\n");
1955
1956 return ibmvnic_send_crq(adapter, &crq);
1957}
1958
1959static int send_version_xchg(struct ibmvnic_adapter *adapter)
1960{
1961 union ibmvnic_crq crq;
1962
1963 memset(&crq, 0, sizeof(crq));
1964 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
1965 crq.version_exchange.cmd = VERSION_EXCHANGE;
1966 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
1967
1968 return ibmvnic_send_crq(adapter, &crq);
1969}
1970
1971static void send_login(struct ibmvnic_adapter *adapter)
1972{
1973 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
1974 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001975 struct device *dev = &adapter->vdev->dev;
1976 dma_addr_t rsp_buffer_token;
1977 dma_addr_t buffer_token;
1978 size_t rsp_buffer_size;
1979 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001980 size_t buffer_size;
1981 __be64 *tx_list_p;
1982 __be64 *rx_list_p;
1983 int i;
1984
1985 buffer_size =
1986 sizeof(struct ibmvnic_login_buffer) +
1987 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
1988
1989 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
1990 if (!login_buffer)
1991 goto buf_alloc_failed;
1992
1993 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
1994 DMA_TO_DEVICE);
1995 if (dma_mapping_error(dev, buffer_token)) {
1996 dev_err(dev, "Couldn't map login buffer\n");
1997 goto buf_map_failed;
1998 }
1999
John Allen498cd8e2016-04-06 11:49:55 -05002000 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
2001 sizeof(u64) * adapter->req_tx_queues +
2002 sizeof(u64) * adapter->req_rx_queues +
2003 sizeof(u64) * adapter->req_rx_queues +
2004 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002005
2006 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
2007 if (!login_rsp_buffer)
2008 goto buf_rsp_alloc_failed;
2009
2010 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
2011 rsp_buffer_size, DMA_FROM_DEVICE);
2012 if (dma_mapping_error(dev, rsp_buffer_token)) {
2013 dev_err(dev, "Couldn't map login rsp buffer\n");
2014 goto buf_rsp_map_failed;
2015 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04002016
Thomas Falcon032c5e82015-12-21 11:26:06 -06002017 adapter->login_buf = login_buffer;
2018 adapter->login_buf_token = buffer_token;
2019 adapter->login_buf_sz = buffer_size;
2020 adapter->login_rsp_buf = login_rsp_buffer;
2021 adapter->login_rsp_buf_token = rsp_buffer_token;
2022 adapter->login_rsp_buf_sz = rsp_buffer_size;
2023
2024 login_buffer->len = cpu_to_be32(buffer_size);
2025 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
2026 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
2027 login_buffer->off_txcomp_subcrqs =
2028 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
2029 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
2030 login_buffer->off_rxcomp_subcrqs =
2031 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
2032 sizeof(u64) * adapter->req_tx_queues);
2033 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
2034 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
2035
2036 tx_list_p = (__be64 *)((char *)login_buffer +
2037 sizeof(struct ibmvnic_login_buffer));
2038 rx_list_p = (__be64 *)((char *)login_buffer +
2039 sizeof(struct ibmvnic_login_buffer) +
2040 sizeof(u64) * adapter->req_tx_queues);
2041
2042 for (i = 0; i < adapter->req_tx_queues; i++) {
2043 if (adapter->tx_scrq[i]) {
2044 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
2045 crq_num);
2046 }
2047 }
2048
2049 for (i = 0; i < adapter->req_rx_queues; i++) {
2050 if (adapter->rx_scrq[i]) {
2051 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
2052 crq_num);
2053 }
2054 }
2055
2056 netdev_dbg(adapter->netdev, "Login Buffer:\n");
2057 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
2058 netdev_dbg(adapter->netdev, "%016lx\n",
2059 ((unsigned long int *)(adapter->login_buf))[i]);
2060 }
2061
2062 memset(&crq, 0, sizeof(crq));
2063 crq.login.first = IBMVNIC_CRQ_CMD;
2064 crq.login.cmd = LOGIN;
2065 crq.login.ioba = cpu_to_be32(buffer_token);
2066 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002067 ibmvnic_send_crq(adapter, &crq);
2068
2069 return;
2070
Thomas Falcon032c5e82015-12-21 11:26:06 -06002071buf_rsp_map_failed:
2072 kfree(login_rsp_buffer);
2073buf_rsp_alloc_failed:
2074 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
2075buf_map_failed:
2076 kfree(login_buffer);
2077buf_alloc_failed:
2078 return;
2079}
2080
2081static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
2082 u32 len, u8 map_id)
2083{
2084 union ibmvnic_crq crq;
2085
2086 memset(&crq, 0, sizeof(crq));
2087 crq.request_map.first = IBMVNIC_CRQ_CMD;
2088 crq.request_map.cmd = REQUEST_MAP;
2089 crq.request_map.map_id = map_id;
2090 crq.request_map.ioba = cpu_to_be32(addr);
2091 crq.request_map.len = cpu_to_be32(len);
2092 ibmvnic_send_crq(adapter, &crq);
2093}
2094
2095static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
2096{
2097 union ibmvnic_crq crq;
2098
2099 memset(&crq, 0, sizeof(crq));
2100 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
2101 crq.request_unmap.cmd = REQUEST_UNMAP;
2102 crq.request_unmap.map_id = map_id;
2103 ibmvnic_send_crq(adapter, &crq);
2104}
2105
2106static void send_map_query(struct ibmvnic_adapter *adapter)
2107{
2108 union ibmvnic_crq crq;
2109
2110 memset(&crq, 0, sizeof(crq));
2111 crq.query_map.first = IBMVNIC_CRQ_CMD;
2112 crq.query_map.cmd = QUERY_MAP;
2113 ibmvnic_send_crq(adapter, &crq);
2114}
2115
2116/* Send a series of CRQs requesting various capabilities of the VNIC server */
2117static void send_cap_queries(struct ibmvnic_adapter *adapter)
2118{
2119 union ibmvnic_crq crq;
2120
Thomas Falcon901e0402017-02-15 12:17:59 -06002121 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002122 memset(&crq, 0, sizeof(crq));
2123 crq.query_capability.first = IBMVNIC_CRQ_CMD;
2124 crq.query_capability.cmd = QUERY_CAPABILITY;
2125
2126 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002127 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002128 ibmvnic_send_crq(adapter, &crq);
2129
2130 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002131 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002132 ibmvnic_send_crq(adapter, &crq);
2133
2134 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002135 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002136 ibmvnic_send_crq(adapter, &crq);
2137
2138 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002139 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002140 ibmvnic_send_crq(adapter, &crq);
2141
2142 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002143 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002144 ibmvnic_send_crq(adapter, &crq);
2145
2146 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002147 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002148 ibmvnic_send_crq(adapter, &crq);
2149
2150 crq.query_capability.capability =
2151 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002152 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002153 ibmvnic_send_crq(adapter, &crq);
2154
2155 crq.query_capability.capability =
2156 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002157 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002158 ibmvnic_send_crq(adapter, &crq);
2159
2160 crq.query_capability.capability =
2161 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002162 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002163 ibmvnic_send_crq(adapter, &crq);
2164
2165 crq.query_capability.capability =
2166 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002167 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002168 ibmvnic_send_crq(adapter, &crq);
2169
2170 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
Thomas Falcon901e0402017-02-15 12:17:59 -06002171 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002172 ibmvnic_send_crq(adapter, &crq);
2173
2174 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002175 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002176 ibmvnic_send_crq(adapter, &crq);
2177
2178 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002179 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002180 ibmvnic_send_crq(adapter, &crq);
2181
2182 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002183 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002184 ibmvnic_send_crq(adapter, &crq);
2185
2186 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
Thomas Falcon901e0402017-02-15 12:17:59 -06002187 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002188 ibmvnic_send_crq(adapter, &crq);
2189
2190 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06002191 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002192 ibmvnic_send_crq(adapter, &crq);
2193
2194 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002195 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002196 ibmvnic_send_crq(adapter, &crq);
2197
2198 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002199 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002200 ibmvnic_send_crq(adapter, &crq);
2201
2202 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002203 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002204 ibmvnic_send_crq(adapter, &crq);
2205
2206 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002207 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002208 ibmvnic_send_crq(adapter, &crq);
2209
2210 crq.query_capability.capability =
2211 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06002212 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002213 ibmvnic_send_crq(adapter, &crq);
2214
2215 crq.query_capability.capability =
2216 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
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.query_capability.capability =
2221 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
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.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002226 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002227 ibmvnic_send_crq(adapter, &crq);
2228}
2229
2230static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2231{
2232 struct device *dev = &adapter->vdev->dev;
2233 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2234 union ibmvnic_crq crq;
2235 int i;
2236
2237 dma_unmap_single(dev, adapter->ip_offload_tok,
2238 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2239
2240 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2241 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2242 netdev_dbg(adapter->netdev, "%016lx\n",
2243 ((unsigned long int *)(buf))[i]);
2244
2245 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2246 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2247 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2248 buf->tcp_ipv4_chksum);
2249 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2250 buf->tcp_ipv6_chksum);
2251 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2252 buf->udp_ipv4_chksum);
2253 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2254 buf->udp_ipv6_chksum);
2255 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2256 buf->large_tx_ipv4);
2257 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2258 buf->large_tx_ipv6);
2259 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2260 buf->large_rx_ipv4);
2261 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2262 buf->large_rx_ipv6);
2263 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2264 buf->max_ipv4_header_size);
2265 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2266 buf->max_ipv6_header_size);
2267 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2268 buf->max_tcp_header_size);
2269 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2270 buf->max_udp_header_size);
2271 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2272 buf->max_large_tx_size);
2273 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2274 buf->max_large_rx_size);
2275 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2276 buf->ipv6_extension_header);
2277 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2278 buf->tcp_pseudosum_req);
2279 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2280 buf->num_ipv6_ext_headers);
2281 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2282 buf->off_ipv6_ext_headers);
2283
2284 adapter->ip_offload_ctrl_tok =
2285 dma_map_single(dev, &adapter->ip_offload_ctrl,
2286 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2287
2288 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2289 dev_err(dev, "Couldn't map ip offload control buffer\n");
2290 return;
2291 }
2292
2293 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2294 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2295 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2296 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2297 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2298
2299 /* large_tx/rx disabled for now, additional features needed */
2300 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2301 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2302 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2303 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2304
2305 adapter->netdev->features = NETIF_F_GSO;
2306
2307 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2308 adapter->netdev->features |= NETIF_F_IP_CSUM;
2309
2310 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2311 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2312
Thomas Falcon9be02cd2016-04-01 17:20:35 -05002313 if ((adapter->netdev->features &
2314 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2315 adapter->netdev->features |= NETIF_F_RXCSUM;
2316
Thomas Falcon032c5e82015-12-21 11:26:06 -06002317 memset(&crq, 0, sizeof(crq));
2318 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2319 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2320 crq.control_ip_offload.len =
2321 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2322 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2323 ibmvnic_send_crq(adapter, &crq);
2324}
2325
2326static void handle_error_info_rsp(union ibmvnic_crq *crq,
2327 struct ibmvnic_adapter *adapter)
2328{
2329 struct device *dev = &adapter->vdev->dev;
Wei Yongjun96183182016-06-27 20:48:53 +08002330 struct ibmvnic_error_buff *error_buff, *tmp;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002331 unsigned long flags;
2332 bool found = false;
2333 int i;
2334
2335 if (!crq->request_error_rsp.rc.code) {
2336 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2337 crq->request_error_rsp.rc.code);
2338 return;
2339 }
2340
2341 spin_lock_irqsave(&adapter->error_list_lock, flags);
Wei Yongjun96183182016-06-27 20:48:53 +08002342 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002343 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2344 found = true;
2345 list_del(&error_buff->list);
2346 break;
2347 }
2348 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2349
2350 if (!found) {
2351 dev_err(dev, "Couldn't find error id %x\n",
Thomas Falcon75224c92017-02-15 10:33:33 -06002352 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002353 return;
2354 }
2355
2356 dev_err(dev, "Detailed info for error id %x:",
Thomas Falcon75224c92017-02-15 10:33:33 -06002357 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002358
2359 for (i = 0; i < error_buff->len; i++) {
2360 pr_cont("%02x", (int)error_buff->buff[i]);
2361 if (i % 8 == 7)
2362 pr_cont(" ");
2363 }
2364 pr_cont("\n");
2365
2366 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2367 DMA_FROM_DEVICE);
2368 kfree(error_buff->buff);
2369 kfree(error_buff);
2370}
2371
Thomas Falcon032c5e82015-12-21 11:26:06 -06002372static void handle_error_indication(union ibmvnic_crq *crq,
2373 struct ibmvnic_adapter *adapter)
2374{
2375 int detail_len = be32_to_cpu(crq->error_indication.detail_error_sz);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002376 struct device *dev = &adapter->vdev->dev;
2377 struct ibmvnic_error_buff *error_buff;
2378 union ibmvnic_crq new_crq;
2379 unsigned long flags;
2380
2381 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2382 crq->error_indication.
2383 flags & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
Thomas Falcon75224c92017-02-15 10:33:33 -06002384 be32_to_cpu(crq->error_indication.error_id),
2385 be16_to_cpu(crq->error_indication.error_cause));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002386
2387 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2388 if (!error_buff)
2389 return;
2390
2391 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2392 if (!error_buff->buff) {
2393 kfree(error_buff);
2394 return;
2395 }
2396
2397 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2398 DMA_FROM_DEVICE);
2399 if (dma_mapping_error(dev, error_buff->dma)) {
2400 if (!firmware_has_feature(FW_FEATURE_CMO))
2401 dev_err(dev, "Couldn't map error buffer\n");
2402 kfree(error_buff->buff);
2403 kfree(error_buff);
2404 return;
2405 }
2406
Thomas Falcon032c5e82015-12-21 11:26:06 -06002407 error_buff->len = detail_len;
2408 error_buff->error_id = crq->error_indication.error_id;
2409
2410 spin_lock_irqsave(&adapter->error_list_lock, flags);
2411 list_add_tail(&error_buff->list, &adapter->errors);
2412 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2413
2414 memset(&new_crq, 0, sizeof(new_crq));
2415 new_crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2416 new_crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2417 new_crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2418 new_crq.request_error_info.len = cpu_to_be32(detail_len);
2419 new_crq.request_error_info.error_id = crq->error_indication.error_id;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002420 ibmvnic_send_crq(adapter, &new_crq);
2421}
2422
2423static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2424 struct ibmvnic_adapter *adapter)
2425{
2426 struct net_device *netdev = adapter->netdev;
2427 struct device *dev = &adapter->vdev->dev;
2428 long rc;
2429
2430 rc = crq->change_mac_addr_rsp.rc.code;
2431 if (rc) {
2432 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2433 return;
2434 }
2435 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2436 ETH_ALEN);
2437}
2438
2439static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2440 struct ibmvnic_adapter *adapter)
2441{
2442 struct device *dev = &adapter->vdev->dev;
2443 u64 *req_value;
2444 char *name;
2445
Thomas Falcon901e0402017-02-15 12:17:59 -06002446 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002447 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2448 case REQ_TX_QUEUES:
2449 req_value = &adapter->req_tx_queues;
2450 name = "tx";
2451 break;
2452 case REQ_RX_QUEUES:
2453 req_value = &adapter->req_rx_queues;
2454 name = "rx";
2455 break;
2456 case REQ_RX_ADD_QUEUES:
2457 req_value = &adapter->req_rx_add_queues;
2458 name = "rx_add";
2459 break;
2460 case REQ_TX_ENTRIES_PER_SUBCRQ:
2461 req_value = &adapter->req_tx_entries_per_subcrq;
2462 name = "tx_entries_per_subcrq";
2463 break;
2464 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2465 req_value = &adapter->req_rx_add_entries_per_subcrq;
2466 name = "rx_add_entries_per_subcrq";
2467 break;
2468 case REQ_MTU:
2469 req_value = &adapter->req_mtu;
2470 name = "mtu";
2471 break;
2472 case PROMISC_REQUESTED:
2473 req_value = &adapter->promisc;
2474 name = "promisc";
2475 break;
2476 default:
2477 dev_err(dev, "Got invalid cap request rsp %d\n",
2478 crq->request_capability.capability);
2479 return;
2480 }
2481
2482 switch (crq->request_capability_rsp.rc.code) {
2483 case SUCCESS:
2484 break;
2485 case PARTIALSUCCESS:
2486 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2487 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06002488 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06002489 number), name);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002490 release_sub_crqs(adapter);
Thomas Falcon28f4d162017-02-15 10:32:11 -06002491 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
Thomas Falconea22d512016-07-06 15:35:17 -05002492 init_sub_crqs(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002493 return;
2494 default:
2495 dev_err(dev, "Error %d in request cap rsp\n",
2496 crq->request_capability_rsp.rc.code);
2497 return;
2498 }
2499
2500 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06002501 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002502 union ibmvnic_crq newcrq;
2503 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2504 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2505 &adapter->ip_offload_buf;
2506
Thomas Falcon249168a2017-02-15 12:18:00 -06002507 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002508 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
2509 buf_sz,
2510 DMA_FROM_DEVICE);
2511
2512 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
2513 if (!firmware_has_feature(FW_FEATURE_CMO))
2514 dev_err(dev, "Couldn't map offload buffer\n");
2515 return;
2516 }
2517
2518 memset(&newcrq, 0, sizeof(newcrq));
2519 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
2520 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
2521 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
2522 newcrq.query_ip_offload.ioba =
2523 cpu_to_be32(adapter->ip_offload_tok);
2524
2525 ibmvnic_send_crq(adapter, &newcrq);
2526 }
2527}
2528
2529static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
2530 struct ibmvnic_adapter *adapter)
2531{
2532 struct device *dev = &adapter->vdev->dev;
2533 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
2534 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002535 int i;
2536
2537 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
2538 DMA_BIDIRECTIONAL);
2539 dma_unmap_single(dev, adapter->login_rsp_buf_token,
2540 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
2541
John Allen498cd8e2016-04-06 11:49:55 -05002542 /* If the number of queues requested can't be allocated by the
2543 * server, the login response will return with code 1. We will need
2544 * to resend the login buffer with fewer queues requested.
2545 */
2546 if (login_rsp_crq->generic.rc.code) {
2547 adapter->renegotiate = true;
2548 complete(&adapter->init_done);
2549 return 0;
2550 }
2551
Thomas Falcon032c5e82015-12-21 11:26:06 -06002552 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
2553 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
2554 netdev_dbg(adapter->netdev, "%016lx\n",
2555 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
2556 }
2557
2558 /* Sanity checks */
2559 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
2560 (be32_to_cpu(login->num_rxcomp_subcrqs) *
2561 adapter->req_rx_add_queues !=
2562 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
2563 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
2564 ibmvnic_remove(adapter->vdev);
2565 return -EIO;
2566 }
2567 complete(&adapter->init_done);
2568
Thomas Falcon032c5e82015-12-21 11:26:06 -06002569 return 0;
2570}
2571
2572static void handle_request_map_rsp(union ibmvnic_crq *crq,
2573 struct ibmvnic_adapter *adapter)
2574{
2575 struct device *dev = &adapter->vdev->dev;
2576 u8 map_id = crq->request_map_rsp.map_id;
2577 int tx_subcrqs;
2578 int rx_subcrqs;
2579 long rc;
2580 int i;
2581
2582 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
2583 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
2584
2585 rc = crq->request_map_rsp.rc.code;
2586 if (rc) {
2587 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
2588 adapter->map_id--;
2589 /* need to find and zero tx/rx_pool map_id */
2590 for (i = 0; i < tx_subcrqs; i++) {
2591 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
2592 adapter->tx_pool[i].long_term_buff.map_id = 0;
2593 }
2594 for (i = 0; i < rx_subcrqs; i++) {
2595 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
2596 adapter->rx_pool[i].long_term_buff.map_id = 0;
2597 }
2598 }
2599 complete(&adapter->fw_done);
2600}
2601
2602static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
2603 struct ibmvnic_adapter *adapter)
2604{
2605 struct device *dev = &adapter->vdev->dev;
2606 long rc;
2607
2608 rc = crq->request_unmap_rsp.rc.code;
2609 if (rc)
2610 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
2611}
2612
2613static void handle_query_map_rsp(union ibmvnic_crq *crq,
2614 struct ibmvnic_adapter *adapter)
2615{
2616 struct net_device *netdev = adapter->netdev;
2617 struct device *dev = &adapter->vdev->dev;
2618 long rc;
2619
2620 rc = crq->query_map_rsp.rc.code;
2621 if (rc) {
2622 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
2623 return;
2624 }
2625 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
2626 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
2627 crq->query_map_rsp.free_pages);
2628}
2629
2630static void handle_query_cap_rsp(union ibmvnic_crq *crq,
2631 struct ibmvnic_adapter *adapter)
2632{
2633 struct net_device *netdev = adapter->netdev;
2634 struct device *dev = &adapter->vdev->dev;
2635 long rc;
2636
Thomas Falcon901e0402017-02-15 12:17:59 -06002637 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002638 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06002639 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002640 rc = crq->query_capability.rc.code;
2641 if (rc) {
2642 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
2643 goto out;
2644 }
2645
2646 switch (be16_to_cpu(crq->query_capability.capability)) {
2647 case MIN_TX_QUEUES:
2648 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002649 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002650 netdev_dbg(netdev, "min_tx_queues = %lld\n",
2651 adapter->min_tx_queues);
2652 break;
2653 case MIN_RX_QUEUES:
2654 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002655 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002656 netdev_dbg(netdev, "min_rx_queues = %lld\n",
2657 adapter->min_rx_queues);
2658 break;
2659 case MIN_RX_ADD_QUEUES:
2660 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002661 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002662 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
2663 adapter->min_rx_add_queues);
2664 break;
2665 case MAX_TX_QUEUES:
2666 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002667 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002668 netdev_dbg(netdev, "max_tx_queues = %lld\n",
2669 adapter->max_tx_queues);
2670 break;
2671 case MAX_RX_QUEUES:
2672 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002673 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002674 netdev_dbg(netdev, "max_rx_queues = %lld\n",
2675 adapter->max_rx_queues);
2676 break;
2677 case MAX_RX_ADD_QUEUES:
2678 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002679 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002680 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
2681 adapter->max_rx_add_queues);
2682 break;
2683 case MIN_TX_ENTRIES_PER_SUBCRQ:
2684 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002685 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002686 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
2687 adapter->min_tx_entries_per_subcrq);
2688 break;
2689 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
2690 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002691 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002692 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
2693 adapter->min_rx_add_entries_per_subcrq);
2694 break;
2695 case MAX_TX_ENTRIES_PER_SUBCRQ:
2696 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002697 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002698 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
2699 adapter->max_tx_entries_per_subcrq);
2700 break;
2701 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
2702 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002703 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002704 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
2705 adapter->max_rx_add_entries_per_subcrq);
2706 break;
2707 case TCP_IP_OFFLOAD:
2708 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06002709 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002710 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
2711 adapter->tcp_ip_offload);
2712 break;
2713 case PROMISC_SUPPORTED:
2714 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002715 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002716 netdev_dbg(netdev, "promisc_supported = %lld\n",
2717 adapter->promisc_supported);
2718 break;
2719 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002720 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002721 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002722 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
2723 break;
2724 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002725 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002726 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002727 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
2728 break;
2729 case MAX_MULTICAST_FILTERS:
2730 adapter->max_multicast_filters =
Thomas Falconde89e852016-03-01 10:20:09 -06002731 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002732 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
2733 adapter->max_multicast_filters);
2734 break;
2735 case VLAN_HEADER_INSERTION:
2736 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06002737 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002738 if (adapter->vlan_header_insertion)
2739 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
2740 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
2741 adapter->vlan_header_insertion);
2742 break;
2743 case MAX_TX_SG_ENTRIES:
2744 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06002745 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002746 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
2747 adapter->max_tx_sg_entries);
2748 break;
2749 case RX_SG_SUPPORTED:
2750 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002751 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002752 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
2753 adapter->rx_sg_supported);
2754 break;
2755 case OPT_TX_COMP_SUB_QUEUES:
2756 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002757 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002758 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
2759 adapter->opt_tx_comp_sub_queues);
2760 break;
2761 case OPT_RX_COMP_QUEUES:
2762 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002763 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002764 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
2765 adapter->opt_rx_comp_queues);
2766 break;
2767 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
2768 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06002769 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002770 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
2771 adapter->opt_rx_bufadd_q_per_rx_comp_q);
2772 break;
2773 case OPT_TX_ENTRIES_PER_SUBCRQ:
2774 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002775 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002776 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
2777 adapter->opt_tx_entries_per_subcrq);
2778 break;
2779 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
2780 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002781 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002782 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
2783 adapter->opt_rxba_entries_per_subcrq);
2784 break;
2785 case TX_RX_DESC_REQ:
2786 adapter->tx_rx_desc_req = crq->query_capability.number;
2787 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
2788 adapter->tx_rx_desc_req);
2789 break;
2790
2791 default:
2792 netdev_err(netdev, "Got invalid cap rsp %d\n",
2793 crq->query_capability.capability);
2794 }
2795
2796out:
Thomas Falcon249168a2017-02-15 12:18:00 -06002797 if (atomic_read(&adapter->running_cap_crqs) == 0) {
2798 adapter->wait_capability = false;
Thomas Falconea22d512016-07-06 15:35:17 -05002799 init_sub_crqs(adapter, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002800 /* We're done querying the capabilities, initialize sub-crqs */
Thomas Falcon249168a2017-02-15 12:18:00 -06002801 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002802}
2803
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002804static void ibmvnic_xport_event(struct work_struct *work)
2805{
2806 struct ibmvnic_adapter *adapter = container_of(work,
2807 struct ibmvnic_adapter,
2808 ibmvnic_xport);
2809 struct device *dev = &adapter->vdev->dev;
2810 long rc;
2811
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002812 release_sub_crqs(adapter);
2813 if (adapter->migrated) {
2814 rc = ibmvnic_reenable_crq_queue(adapter);
2815 if (rc)
2816 dev_err(dev, "Error after enable rc=%ld\n", rc);
2817 adapter->migrated = false;
2818 rc = ibmvnic_send_crq_init(adapter);
2819 if (rc)
2820 dev_err(dev, "Error sending init rc=%ld\n", rc);
2821 }
2822}
2823
Thomas Falcon032c5e82015-12-21 11:26:06 -06002824static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
2825 struct ibmvnic_adapter *adapter)
2826{
2827 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
2828 struct net_device *netdev = adapter->netdev;
2829 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002830 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002831 long rc;
2832
2833 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002834 (unsigned long int)cpu_to_be64(u64_crq[0]),
2835 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002836 switch (gen_crq->first) {
2837 case IBMVNIC_CRQ_INIT_RSP:
2838 switch (gen_crq->cmd) {
2839 case IBMVNIC_CRQ_INIT:
2840 dev_info(dev, "Partner initialized\n");
2841 /* Send back a response */
2842 rc = ibmvnic_send_crq_init_complete(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05002843 if (!rc)
2844 schedule_work(&adapter->vnic_crq_init);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002845 else
2846 dev_err(dev, "Can't send initrsp rc=%ld\n", rc);
2847 break;
2848 case IBMVNIC_CRQ_INIT_COMPLETE:
2849 dev_info(dev, "Partner initialization complete\n");
2850 send_version_xchg(adapter);
2851 break;
2852 default:
2853 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
2854 }
2855 return;
2856 case IBMVNIC_CRQ_XPORT_EVENT:
2857 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
2858 dev_info(dev, "Re-enabling adapter\n");
2859 adapter->migrated = true;
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002860 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcondfad09a2016-08-18 11:37:51 -05002861 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
2862 dev_info(dev, "Backing device failover detected\n");
2863 netif_carrier_off(netdev);
2864 adapter->failover = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002865 } else {
2866 /* The adapter lost the connection */
2867 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
2868 gen_crq->cmd);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002869 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002870 }
2871 return;
2872 case IBMVNIC_CRQ_CMD_RSP:
2873 break;
2874 default:
2875 dev_err(dev, "Got an invalid msg type 0x%02x\n",
2876 gen_crq->first);
2877 return;
2878 }
2879
2880 switch (gen_crq->cmd) {
2881 case VERSION_EXCHANGE_RSP:
2882 rc = crq->version_exchange_rsp.rc.code;
2883 if (rc) {
2884 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
2885 break;
2886 }
2887 dev_info(dev, "Partner protocol version is %d\n",
2888 crq->version_exchange_rsp.version);
2889 if (be16_to_cpu(crq->version_exchange_rsp.version) <
2890 ibmvnic_version)
2891 ibmvnic_version =
2892 be16_to_cpu(crq->version_exchange_rsp.version);
2893 send_cap_queries(adapter);
2894 break;
2895 case QUERY_CAPABILITY_RSP:
2896 handle_query_cap_rsp(crq, adapter);
2897 break;
2898 case QUERY_MAP_RSP:
2899 handle_query_map_rsp(crq, adapter);
2900 break;
2901 case REQUEST_MAP_RSP:
2902 handle_request_map_rsp(crq, adapter);
2903 break;
2904 case REQUEST_UNMAP_RSP:
2905 handle_request_unmap_rsp(crq, adapter);
2906 break;
2907 case REQUEST_CAPABILITY_RSP:
2908 handle_request_cap_rsp(crq, adapter);
2909 break;
2910 case LOGIN_RSP:
2911 netdev_dbg(netdev, "Got Login Response\n");
2912 handle_login_rsp(crq, adapter);
2913 break;
2914 case LOGICAL_LINK_STATE_RSP:
2915 netdev_dbg(netdev, "Got Logical Link State Response\n");
2916 adapter->logical_link_state =
2917 crq->logical_link_state_rsp.link_state;
2918 break;
2919 case LINK_STATE_INDICATION:
2920 netdev_dbg(netdev, "Got Logical Link State Indication\n");
2921 adapter->phys_link_state =
2922 crq->link_state_indication.phys_link_state;
2923 adapter->logical_link_state =
2924 crq->link_state_indication.logical_link_state;
2925 break;
2926 case CHANGE_MAC_ADDR_RSP:
2927 netdev_dbg(netdev, "Got MAC address change Response\n");
2928 handle_change_mac_rsp(crq, adapter);
2929 break;
2930 case ERROR_INDICATION:
2931 netdev_dbg(netdev, "Got Error Indication\n");
2932 handle_error_indication(crq, adapter);
2933 break;
2934 case REQUEST_ERROR_RSP:
2935 netdev_dbg(netdev, "Got Error Detail Response\n");
2936 handle_error_info_rsp(crq, adapter);
2937 break;
2938 case REQUEST_STATISTICS_RSP:
2939 netdev_dbg(netdev, "Got Statistics Response\n");
2940 complete(&adapter->stats_done);
2941 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002942 case QUERY_IP_OFFLOAD_RSP:
2943 netdev_dbg(netdev, "Got Query IP offload Response\n");
2944 handle_query_ip_offload_rsp(adapter);
2945 break;
2946 case MULTICAST_CTRL_RSP:
2947 netdev_dbg(netdev, "Got multicast control Response\n");
2948 break;
2949 case CONTROL_IP_OFFLOAD_RSP:
2950 netdev_dbg(netdev, "Got Control IP offload Response\n");
2951 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
2952 sizeof(adapter->ip_offload_ctrl),
2953 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05002954 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002955 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002956 case COLLECT_FW_TRACE_RSP:
2957 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
2958 complete(&adapter->fw_done);
2959 break;
2960 default:
2961 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
2962 gen_crq->cmd);
2963 }
2964}
2965
2966static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
2967{
2968 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06002969
Thomas Falcon6c267b32017-02-15 12:17:58 -06002970 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06002971 return IRQ_HANDLED;
2972}
2973
2974static void ibmvnic_tasklet(void *data)
2975{
2976 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002977 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002978 union ibmvnic_crq *crq;
2979 unsigned long flags;
2980 bool done = false;
2981
2982 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002983 while (!done) {
2984 /* Pull all the valid messages off the CRQ */
2985 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
2986 ibmvnic_handle_crq(crq, adapter);
2987 crq->generic.first = 0;
2988 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04002989
2990 /* remain in tasklet until all
2991 * capabilities responses are received
2992 */
2993 if (!adapter->wait_capability)
2994 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002995 }
Thomas Falcon249168a2017-02-15 12:18:00 -06002996 /* if capabilities CRQ's were sent in this tasklet, the following
2997 * tasklet must wait until all responses are received
2998 */
2999 if (atomic_read(&adapter->running_cap_crqs) != 0)
3000 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003001 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003002}
3003
3004static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
3005{
3006 struct vio_dev *vdev = adapter->vdev;
3007 int rc;
3008
3009 do {
3010 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
3011 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
3012
3013 if (rc)
3014 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
3015
3016 return rc;
3017}
3018
3019static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
3020{
3021 struct ibmvnic_crq_queue *crq = &adapter->crq;
3022 struct device *dev = &adapter->vdev->dev;
3023 struct vio_dev *vdev = adapter->vdev;
3024 int rc;
3025
3026 /* Close the CRQ */
3027 do {
3028 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3029 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3030
3031 /* Clean out the queue */
3032 memset(crq->msgs, 0, PAGE_SIZE);
3033 crq->cur = 0;
3034
3035 /* And re-open it again */
3036 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3037 crq->msg_token, PAGE_SIZE);
3038
3039 if (rc == H_CLOSED)
3040 /* Adapter is good, but other end is not ready */
3041 dev_warn(dev, "Partner adapter not ready\n");
3042 else if (rc != 0)
3043 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3044
3045 return rc;
3046}
3047
Nathan Fontenotf9928872017-03-30 02:48:54 -04003048static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003049{
3050 struct ibmvnic_crq_queue *crq = &adapter->crq;
3051 struct vio_dev *vdev = adapter->vdev;
3052 long rc;
3053
Nathan Fontenotf9928872017-03-30 02:48:54 -04003054 if (!crq->msgs)
3055 return;
3056
Thomas Falcon032c5e82015-12-21 11:26:06 -06003057 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3058 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003059 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003060 do {
3061 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3062 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3063
3064 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3065 DMA_BIDIRECTIONAL);
3066 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003067 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003068}
3069
Nathan Fontenotf9928872017-03-30 02:48:54 -04003070static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003071{
3072 struct ibmvnic_crq_queue *crq = &adapter->crq;
3073 struct device *dev = &adapter->vdev->dev;
3074 struct vio_dev *vdev = adapter->vdev;
3075 int rc, retrc = -ENOMEM;
3076
Nathan Fontenotf9928872017-03-30 02:48:54 -04003077 if (crq->msgs)
3078 return 0;
3079
Thomas Falcon032c5e82015-12-21 11:26:06 -06003080 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3081 /* Should we allocate more than one page? */
3082
3083 if (!crq->msgs)
3084 return -ENOMEM;
3085
3086 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3087 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3088 DMA_BIDIRECTIONAL);
3089 if (dma_mapping_error(dev, crq->msg_token))
3090 goto map_failed;
3091
3092 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3093 crq->msg_token, PAGE_SIZE);
3094
3095 if (rc == H_RESOURCE)
3096 /* maybe kexecing and resource is busy. try a reset */
3097 rc = ibmvnic_reset_crq(adapter);
3098 retrc = rc;
3099
3100 if (rc == H_CLOSED) {
3101 dev_warn(dev, "Partner adapter not ready\n");
3102 } else if (rc) {
3103 dev_warn(dev, "Error %d opening adapter\n", rc);
3104 goto reg_crq_failed;
3105 }
3106
3107 retrc = 0;
3108
Thomas Falcon6c267b32017-02-15 12:17:58 -06003109 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3110 (unsigned long)adapter);
3111
Thomas Falcon032c5e82015-12-21 11:26:06 -06003112 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3113 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3114 adapter);
3115 if (rc) {
3116 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3117 vdev->irq, rc);
3118 goto req_irq_failed;
3119 }
3120
3121 rc = vio_enable_interrupts(vdev);
3122 if (rc) {
3123 dev_err(dev, "Error %d enabling interrupts\n", rc);
3124 goto req_irq_failed;
3125 }
3126
3127 crq->cur = 0;
3128 spin_lock_init(&crq->lock);
3129
3130 return retrc;
3131
3132req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06003133 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003134 do {
3135 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3136 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3137reg_crq_failed:
3138 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3139map_failed:
3140 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003141 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003142 return retrc;
3143}
3144
Thomas Falcon65dc6892016-07-06 15:35:18 -05003145static void handle_crq_init_rsp(struct work_struct *work)
3146{
3147 struct ibmvnic_adapter *adapter = container_of(work,
3148 struct ibmvnic_adapter,
3149 vnic_crq_init);
3150 struct device *dev = &adapter->vdev->dev;
3151 struct net_device *netdev = adapter->netdev;
3152 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcondfad09a2016-08-18 11:37:51 -05003153 bool restart = false;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003154 int rc;
3155
Thomas Falcondfad09a2016-08-18 11:37:51 -05003156 if (adapter->failover) {
3157 release_sub_crqs(adapter);
3158 if (netif_running(netdev)) {
3159 netif_tx_disable(netdev);
3160 ibmvnic_close(netdev);
3161 restart = true;
3162 }
3163 }
3164
Thomas Falcon65dc6892016-07-06 15:35:18 -05003165 reinit_completion(&adapter->init_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05003166 send_version_xchg(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003167 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3168 dev_err(dev, "Passive init timeout\n");
3169 goto task_failed;
3170 }
3171
Thomas Falconf39f0d12017-02-14 10:22:59 -06003172 netdev->mtu = adapter->req_mtu - ETH_HLEN;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003173
Thomas Falcondfad09a2016-08-18 11:37:51 -05003174 if (adapter->failover) {
3175 adapter->failover = false;
3176 if (restart) {
3177 rc = ibmvnic_open(netdev);
3178 if (rc)
3179 goto restart_failed;
3180 }
3181 netif_carrier_on(netdev);
3182 return;
3183 }
3184
Thomas Falcon65dc6892016-07-06 15:35:18 -05003185 rc = register_netdev(netdev);
3186 if (rc) {
3187 dev_err(dev,
3188 "failed to register netdev rc=%d\n", rc);
3189 goto register_failed;
3190 }
3191 dev_info(dev, "ibmvnic registered\n");
3192
3193 return;
3194
Thomas Falcondfad09a2016-08-18 11:37:51 -05003195restart_failed:
3196 dev_err(dev, "Failed to restart ibmvnic, rc=%d\n", rc);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003197register_failed:
3198 release_sub_crqs(adapter);
3199task_failed:
3200 dev_err(dev, "Passive initialization was not successful\n");
3201}
3202
John Allenf6ef6402017-03-17 17:13:42 -05003203static int ibmvnic_init(struct ibmvnic_adapter *adapter)
3204{
3205 struct device *dev = &adapter->vdev->dev;
3206 unsigned long timeout = msecs_to_jiffies(30000);
John Allenf6ef6402017-03-17 17:13:42 -05003207 int rc;
3208
Nathan Fontenotf9928872017-03-30 02:48:54 -04003209 rc = init_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003210 if (rc) {
3211 dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
3212 return rc;
3213 }
3214
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003215 rc = init_stats_token(adapter);
3216 if (rc) {
Nathan Fontenotf9928872017-03-30 02:48:54 -04003217 release_crq_queue(adapter);
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003218 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05003219 }
3220
John Allenf6ef6402017-03-17 17:13:42 -05003221 init_completion(&adapter->init_done);
3222 ibmvnic_send_crq_init(adapter);
3223 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3224 dev_err(dev, "Initialization sequence timed out\n");
Nathan Fontenotf9928872017-03-30 02:48:54 -04003225 release_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003226 return -1;
3227 }
3228
3229 return 0;
3230}
3231
Thomas Falcon032c5e82015-12-21 11:26:06 -06003232static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3233{
3234 struct ibmvnic_adapter *adapter;
3235 struct net_device *netdev;
3236 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003237 int rc;
3238
3239 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3240 dev->unit_address);
3241
3242 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3243 VETH_MAC_ADDR, NULL);
3244 if (!mac_addr_p) {
3245 dev_err(&dev->dev,
3246 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3247 __FILE__, __LINE__);
3248 return 0;
3249 }
3250
3251 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3252 IBMVNIC_MAX_TX_QUEUES);
3253 if (!netdev)
3254 return -ENOMEM;
3255
3256 adapter = netdev_priv(netdev);
3257 dev_set_drvdata(&dev->dev, netdev);
3258 adapter->vdev = dev;
3259 adapter->netdev = netdev;
Thomas Falcondfad09a2016-08-18 11:37:51 -05003260 adapter->failover = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003261
3262 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3263 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3264 netdev->irq = dev->irq;
3265 netdev->netdev_ops = &ibmvnic_netdev_ops;
3266 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3267 SET_NETDEV_DEV(netdev, &dev->dev);
3268
Thomas Falcon65dc6892016-07-06 15:35:18 -05003269 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05003270 INIT_WORK(&adapter->ibmvnic_xport, ibmvnic_xport_event);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003271
Thomas Falcon032c5e82015-12-21 11:26:06 -06003272 spin_lock_init(&adapter->stats_lock);
3273
Thomas Falcon032c5e82015-12-21 11:26:06 -06003274 INIT_LIST_HEAD(&adapter->errors);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003275 spin_lock_init(&adapter->error_list_lock);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003276
John Allenf6ef6402017-03-17 17:13:42 -05003277 rc = ibmvnic_init(adapter);
3278 if (rc) {
3279 free_netdev(netdev);
3280 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003281 }
3282
Thomas Falconf39f0d12017-02-14 10:22:59 -06003283 netdev->mtu = adapter->req_mtu - ETH_HLEN;
John Allenea5509f2017-03-17 17:13:43 -05003284 adapter->is_closed = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003285
3286 rc = register_netdev(netdev);
3287 if (rc) {
3288 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
John Allenf6ef6402017-03-17 17:13:42 -05003289 free_netdev(netdev);
3290 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003291 }
3292 dev_info(&dev->dev, "ibmvnic registered\n");
3293
3294 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003295}
3296
3297static int ibmvnic_remove(struct vio_dev *dev)
3298{
3299 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003300 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003301
3302 unregister_netdev(netdev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003303
3304 release_resources(adapter);
3305 release_sub_crqs(adapter);
3306 release_crq_queue(adapter);
3307
Thomas Falcon032c5e82015-12-21 11:26:06 -06003308 free_netdev(netdev);
3309 dev_set_drvdata(&dev->dev, NULL);
3310
3311 return 0;
3312}
3313
3314static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3315{
3316 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3317 struct ibmvnic_adapter *adapter;
3318 struct iommu_table *tbl;
3319 unsigned long ret = 0;
3320 int i;
3321
3322 tbl = get_iommu_table_base(&vdev->dev);
3323
3324 /* netdev inits at probe time along with the structures we need below*/
3325 if (!netdev)
3326 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3327
3328 adapter = netdev_priv(netdev);
3329
3330 ret += PAGE_SIZE; /* the crq message queue */
3331 ret += adapter->bounce_buffer_size;
3332 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3333
3334 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3335 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3336
3337 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3338 i++)
3339 ret += adapter->rx_pool[i].size *
3340 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3341
3342 return ret;
3343}
3344
3345static int ibmvnic_resume(struct device *dev)
3346{
3347 struct net_device *netdev = dev_get_drvdata(dev);
3348 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3349 int i;
3350
3351 /* kick the interrupt handlers just in case we lost an interrupt */
3352 for (i = 0; i < adapter->req_rx_queues; i++)
3353 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3354 adapter->rx_scrq[i]);
3355
3356 return 0;
3357}
3358
3359static struct vio_device_id ibmvnic_device_table[] = {
3360 {"network", "IBM,vnic"},
3361 {"", "" }
3362};
3363MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3364
3365static const struct dev_pm_ops ibmvnic_pm_ops = {
3366 .resume = ibmvnic_resume
3367};
3368
3369static struct vio_driver ibmvnic_driver = {
3370 .id_table = ibmvnic_device_table,
3371 .probe = ibmvnic_probe,
3372 .remove = ibmvnic_remove,
3373 .get_desired_dma = ibmvnic_get_desired_dma,
3374 .name = ibmvnic_driver_name,
3375 .pm = &ibmvnic_pm_ops,
3376};
3377
3378/* module functions */
3379static int __init ibmvnic_module_init(void)
3380{
3381 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3382 IBMVNIC_DRIVER_VERSION);
3383
3384 return vio_register_driver(&ibmvnic_driver);
3385}
3386
3387static void __exit ibmvnic_module_exit(void)
3388{
3389 vio_unregister_driver(&ibmvnic_driver);
3390}
3391
3392module_init(ibmvnic_module_init);
3393module_exit(ibmvnic_module_exit);