blob: 18673e2fe91b003dc9590c4f2f3b402360e4e983 [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
604 release_sub_crqs(adapter);
605 release_crq_queue(adapter);
606
607 release_stats_token(adapter);
Nathan Fontenot661a2622017-04-19 13:44:58 -0400608 release_error_buffers(adapter);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400609}
610
John Allena57a5d22017-03-17 17:13:41 -0500611static int ibmvnic_open(struct net_device *netdev)
612{
613 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
614 struct device *dev = &adapter->vdev->dev;
John Allena57a5d22017-03-17 17:13:41 -0500615 union ibmvnic_crq crq;
John Allena57a5d22017-03-17 17:13:41 -0500616 int rc = 0;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400617 int i;
John Allena57a5d22017-03-17 17:13:41 -0500618
John Allenea5509f2017-03-17 17:13:43 -0500619 if (adapter->is_closed) {
620 rc = ibmvnic_init(adapter);
621 if (rc)
622 return rc;
623 }
624
John Allena57a5d22017-03-17 17:13:41 -0500625 rc = ibmvnic_login(netdev);
626 if (rc)
627 return rc;
628
John Allenbd0b6722017-03-17 17:13:40 -0500629 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
630 if (rc) {
631 dev_err(dev, "failed to set the number of tx queues\n");
632 return -1;
633 }
634
635 rc = init_sub_crq_irqs(adapter);
636 if (rc) {
637 dev_err(dev, "failed to initialize sub crq irqs\n");
638 return -1;
639 }
640
Thomas Falcon032c5e82015-12-21 11:26:06 -0600641 adapter->map_id = 1;
642 adapter->napi = kcalloc(adapter->req_rx_queues,
643 sizeof(struct napi_struct), GFP_KERNEL);
644 if (!adapter->napi)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400645 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600646 for (i = 0; i < adapter->req_rx_queues; i++) {
647 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
648 NAPI_POLL_WEIGHT);
649 napi_enable(&adapter->napi[i]);
650 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600651
Thomas Falcon032c5e82015-12-21 11:26:06 -0600652 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400653
654 rc = init_rx_pools(netdev);
655 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400656 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600657
Nathan Fontenotc657e322017-03-30 02:49:06 -0400658 rc = init_tx_pools(netdev);
659 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400660 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600661
Nathan Fontenotf0b8c962017-03-30 02:49:00 -0400662 rc = init_bounce_buffer(netdev);
663 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400664 goto ibmvnic_open_fail;
Nathan Fontenotf0b8c962017-03-30 02:49:00 -0400665
Thomas Falcon032c5e82015-12-21 11:26:06 -0600666 replenish_pools(adapter);
667
668 /* We're ready to receive frames, enable the sub-crq interrupts and
669 * set the logical link state to up
670 */
671 for (i = 0; i < adapter->req_rx_queues; i++)
672 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
673
674 for (i = 0; i < adapter->req_tx_queues; i++)
675 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
676
677 memset(&crq, 0, sizeof(crq));
678 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
679 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
680 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_UP;
681 ibmvnic_send_crq(adapter, &crq);
682
Thomas Falconb8efb892016-07-06 15:35:15 -0500683 netif_tx_start_all_queues(netdev);
John Allenea5509f2017-03-17 17:13:43 -0500684 adapter->is_closed = false;
Thomas Falconb8efb892016-07-06 15:35:15 -0500685
Thomas Falcon032c5e82015-12-21 11:26:06 -0600686 return 0;
687
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400688ibmvnic_open_fail:
Thomas Falcon032c5e82015-12-21 11:26:06 -0600689 for (i = 0; i < adapter->req_rx_queues; i++)
Nathan Fontenote722af62017-02-10 13:29:06 -0500690 napi_disable(&adapter->napi[i]);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400691 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600692 return -ENOMEM;
693}
694
John Allenea5509f2017-03-17 17:13:43 -0500695static int ibmvnic_close(struct net_device *netdev)
696{
697 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
698 union ibmvnic_crq crq;
699 int i;
700
701 adapter->closing = true;
702
703 for (i = 0; i < adapter->req_rx_queues; i++)
704 napi_disable(&adapter->napi[i]);
705
706 if (!adapter->failover)
707 netif_tx_stop_all_queues(netdev);
708
Thomas Falcon032c5e82015-12-21 11:26:06 -0600709 memset(&crq, 0, sizeof(crq));
710 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
711 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
712 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_DN;
713 ibmvnic_send_crq(adapter, &crq);
714
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400715 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600716
John Allenea5509f2017-03-17 17:13:43 -0500717 adapter->is_closed = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600718 adapter->closing = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600719 return 0;
720}
721
Thomas Falconad7775d2016-04-01 17:20:34 -0500722/**
723 * build_hdr_data - creates L2/L3/L4 header data buffer
724 * @hdr_field - bitfield determining needed headers
725 * @skb - socket buffer
726 * @hdr_len - array of header lengths
727 * @tot_len - total length of data
728 *
729 * Reads hdr_field to determine which headers are needed by firmware.
730 * Builds a buffer containing these headers. Saves individual header
731 * lengths and total buffer length to be used to build descriptors.
732 */
733static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
734 int *hdr_len, u8 *hdr_data)
735{
736 int len = 0;
737 u8 *hdr;
738
739 hdr_len[0] = sizeof(struct ethhdr);
740
741 if (skb->protocol == htons(ETH_P_IP)) {
742 hdr_len[1] = ip_hdr(skb)->ihl * 4;
743 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
744 hdr_len[2] = tcp_hdrlen(skb);
745 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
746 hdr_len[2] = sizeof(struct udphdr);
747 } else if (skb->protocol == htons(ETH_P_IPV6)) {
748 hdr_len[1] = sizeof(struct ipv6hdr);
749 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
750 hdr_len[2] = tcp_hdrlen(skb);
751 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
752 hdr_len[2] = sizeof(struct udphdr);
753 }
754
755 memset(hdr_data, 0, 120);
756 if ((hdr_field >> 6) & 1) {
757 hdr = skb_mac_header(skb);
758 memcpy(hdr_data, hdr, hdr_len[0]);
759 len += hdr_len[0];
760 }
761
762 if ((hdr_field >> 5) & 1) {
763 hdr = skb_network_header(skb);
764 memcpy(hdr_data + len, hdr, hdr_len[1]);
765 len += hdr_len[1];
766 }
767
768 if ((hdr_field >> 4) & 1) {
769 hdr = skb_transport_header(skb);
770 memcpy(hdr_data + len, hdr, hdr_len[2]);
771 len += hdr_len[2];
772 }
773 return len;
774}
775
776/**
777 * create_hdr_descs - create header and header extension descriptors
778 * @hdr_field - bitfield determining needed headers
779 * @data - buffer containing header data
780 * @len - length of data buffer
781 * @hdr_len - array of individual header lengths
782 * @scrq_arr - descriptor array
783 *
784 * Creates header and, if needed, header extension descriptors and
785 * places them in a descriptor array, scrq_arr
786 */
787
788static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
789 union sub_crq *scrq_arr)
790{
791 union sub_crq hdr_desc;
792 int tmp_len = len;
793 u8 *data, *cur;
794 int tmp;
795
796 while (tmp_len > 0) {
797 cur = hdr_data + len - tmp_len;
798
799 memset(&hdr_desc, 0, sizeof(hdr_desc));
800 if (cur != hdr_data) {
801 data = hdr_desc.hdr_ext.data;
802 tmp = tmp_len > 29 ? 29 : tmp_len;
803 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
804 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
805 hdr_desc.hdr_ext.len = tmp;
806 } else {
807 data = hdr_desc.hdr.data;
808 tmp = tmp_len > 24 ? 24 : tmp_len;
809 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
810 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
811 hdr_desc.hdr.len = tmp;
812 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
813 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
814 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
815 hdr_desc.hdr.flag = hdr_field << 1;
816 }
817 memcpy(data, cur, tmp);
818 tmp_len -= tmp;
819 *scrq_arr = hdr_desc;
820 scrq_arr++;
821 }
822}
823
824/**
825 * build_hdr_descs_arr - build a header descriptor array
826 * @skb - socket buffer
827 * @num_entries - number of descriptors to be sent
828 * @subcrq - first TX descriptor
829 * @hdr_field - bit field determining which headers will be sent
830 *
831 * This function will build a TX descriptor array with applicable
832 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
833 */
834
835static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
836 int *num_entries, u8 hdr_field)
837{
838 int hdr_len[3] = {0, 0, 0};
839 int tot_len, len;
840 u8 *hdr_data = txbuff->hdr_data;
841
842 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
843 txbuff->hdr_data);
844 len = tot_len;
845 len -= 24;
846 if (len > 0)
847 num_entries += len % 29 ? len / 29 + 1 : len / 29;
848 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
849 txbuff->indir_arr + 1);
850}
851
Thomas Falcon032c5e82015-12-21 11:26:06 -0600852static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
853{
854 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
855 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -0500856 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600857 struct device *dev = &adapter->vdev->dev;
858 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600859 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600860 struct ibmvnic_tx_pool *tx_pool;
861 unsigned int tx_send_failed = 0;
862 unsigned int tx_map_failed = 0;
863 unsigned int tx_dropped = 0;
864 unsigned int tx_packets = 0;
865 unsigned int tx_bytes = 0;
866 dma_addr_t data_dma_addr;
867 struct netdev_queue *txq;
868 bool used_bounce = false;
869 unsigned long lpar_rc;
870 union sub_crq tx_crq;
871 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -0500872 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600873 unsigned char *dst;
874 u64 *handle_array;
875 int index = 0;
876 int ret = 0;
877
878 tx_pool = &adapter->tx_pool[queue_num];
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600879 tx_scrq = adapter->tx_scrq[queue_num];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600880 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
881 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
882 be32_to_cpu(adapter->login_rsp_buf->
883 off_txsubm_subcrqs));
884 if (adapter->migrated) {
885 tx_send_failed++;
886 tx_dropped++;
887 ret = NETDEV_TX_BUSY;
888 goto out;
889 }
890
891 index = tx_pool->free_map[tx_pool->consumer_index];
892 offset = index * adapter->req_mtu;
893 dst = tx_pool->long_term_buff.buff + offset;
894 memset(dst, 0, adapter->req_mtu);
895 skb_copy_from_linear_data(skb, dst, skb->len);
896 data_dma_addr = tx_pool->long_term_buff.addr + offset;
897
898 tx_pool->consumer_index =
899 (tx_pool->consumer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -0600900 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600901
902 tx_buff = &tx_pool->tx_buff[index];
903 tx_buff->skb = skb;
904 tx_buff->data_dma[0] = data_dma_addr;
905 tx_buff->data_len[0] = skb->len;
906 tx_buff->index = index;
907 tx_buff->pool_index = queue_num;
908 tx_buff->last_frag = true;
909 tx_buff->used_bounce = used_bounce;
910
911 memset(&tx_crq, 0, sizeof(tx_crq));
912 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
913 tx_crq.v1.type = IBMVNIC_TX_DESC;
914 tx_crq.v1.n_crq_elem = 1;
915 tx_crq.v1.n_sge = 1;
916 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
917 tx_crq.v1.correlator = cpu_to_be32(index);
918 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
919 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
920 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
921
922 if (adapter->vlan_header_insertion) {
923 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
924 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
925 }
926
927 if (skb->protocol == htons(ETH_P_IP)) {
928 if (ip_hdr(skb)->version == 4)
929 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
930 else if (ip_hdr(skb)->version == 6)
931 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
932
933 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
934 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
935 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
936 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
937 }
938
Thomas Falconad7775d2016-04-01 17:20:34 -0500939 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -0600940 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -0500941 hdrs += 2;
942 }
943 /* determine if l2/3/4 headers are sent to firmware */
944 if ((*hdrs >> 7) & 1 &&
945 (skb->protocol == htons(ETH_P_IP) ||
946 skb->protocol == htons(ETH_P_IPV6))) {
947 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
948 tx_crq.v1.n_crq_elem = num_entries;
949 tx_buff->indir_arr[0] = tx_crq;
950 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
951 sizeof(tx_buff->indir_arr),
952 DMA_TO_DEVICE);
953 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
954 if (!firmware_has_feature(FW_FEATURE_CMO))
955 dev_err(dev, "tx: unable to map descriptor array\n");
956 tx_map_failed++;
957 tx_dropped++;
958 ret = NETDEV_TX_BUSY;
959 goto out;
960 }
John Allen498cd8e2016-04-06 11:49:55 -0500961 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -0500962 (u64)tx_buff->indir_dma,
963 (u64)num_entries);
964 } else {
John Allen498cd8e2016-04-06 11:49:55 -0500965 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
966 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -0500967 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600968 if (lpar_rc != H_SUCCESS) {
969 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
970
971 if (tx_pool->consumer_index == 0)
972 tx_pool->consumer_index =
Thomas Falcon068d9f92017-03-05 12:18:42 -0600973 adapter->req_tx_entries_per_subcrq - 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600974 else
975 tx_pool->consumer_index--;
976
977 tx_send_failed++;
978 tx_dropped++;
979 ret = NETDEV_TX_BUSY;
980 goto out;
981 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600982
Brian King58c8c0c2017-04-19 13:44:47 -0400983 if (atomic_inc_return(&tx_scrq->used)
984 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600985 netdev_info(netdev, "Stopping queue %d\n", queue_num);
986 netif_stop_subqueue(netdev, queue_num);
987 }
988
Thomas Falcon032c5e82015-12-21 11:26:06 -0600989 tx_packets++;
990 tx_bytes += skb->len;
991 txq->trans_start = jiffies;
992 ret = NETDEV_TX_OK;
993
994out:
995 netdev->stats.tx_dropped += tx_dropped;
996 netdev->stats.tx_bytes += tx_bytes;
997 netdev->stats.tx_packets += tx_packets;
998 adapter->tx_send_failed += tx_send_failed;
999 adapter->tx_map_failed += tx_map_failed;
1000
1001 return ret;
1002}
1003
1004static void ibmvnic_set_multi(struct net_device *netdev)
1005{
1006 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1007 struct netdev_hw_addr *ha;
1008 union ibmvnic_crq crq;
1009
1010 memset(&crq, 0, sizeof(crq));
1011 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1012 crq.request_capability.cmd = REQUEST_CAPABILITY;
1013
1014 if (netdev->flags & IFF_PROMISC) {
1015 if (!adapter->promisc_supported)
1016 return;
1017 } else {
1018 if (netdev->flags & IFF_ALLMULTI) {
1019 /* Accept all multicast */
1020 memset(&crq, 0, sizeof(crq));
1021 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1022 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1023 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1024 ibmvnic_send_crq(adapter, &crq);
1025 } else if (netdev_mc_empty(netdev)) {
1026 /* Reject all multicast */
1027 memset(&crq, 0, sizeof(crq));
1028 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1029 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1030 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1031 ibmvnic_send_crq(adapter, &crq);
1032 } else {
1033 /* Accept one or more multicast(s) */
1034 netdev_for_each_mc_addr(ha, netdev) {
1035 memset(&crq, 0, sizeof(crq));
1036 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1037 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1038 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1039 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1040 ha->addr);
1041 ibmvnic_send_crq(adapter, &crq);
1042 }
1043 }
1044 }
1045}
1046
1047static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1048{
1049 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1050 struct sockaddr *addr = p;
1051 union ibmvnic_crq crq;
1052
1053 if (!is_valid_ether_addr(addr->sa_data))
1054 return -EADDRNOTAVAIL;
1055
1056 memset(&crq, 0, sizeof(crq));
1057 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1058 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1059 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1060 ibmvnic_send_crq(adapter, &crq);
1061 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1062 return 0;
1063}
1064
Thomas Falcon032c5e82015-12-21 11:26:06 -06001065static void ibmvnic_tx_timeout(struct net_device *dev)
1066{
1067 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1068 int rc;
1069
1070 /* Adapter timed out, resetting it */
1071 release_sub_crqs(adapter);
1072 rc = ibmvnic_reset_crq(adapter);
1073 if (rc)
1074 dev_err(&adapter->vdev->dev, "Adapter timeout, reset failed\n");
1075 else
1076 ibmvnic_send_crq_init(adapter);
1077}
1078
1079static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
1080 struct ibmvnic_rx_buff *rx_buff)
1081{
1082 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
1083
1084 rx_buff->skb = NULL;
1085
1086 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
1087 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
1088
1089 atomic_dec(&pool->available);
1090}
1091
1092static int ibmvnic_poll(struct napi_struct *napi, int budget)
1093{
1094 struct net_device *netdev = napi->dev;
1095 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1096 int scrq_num = (int)(napi - adapter->napi);
1097 int frames_processed = 0;
1098restart_poll:
1099 while (frames_processed < budget) {
1100 struct sk_buff *skb;
1101 struct ibmvnic_rx_buff *rx_buff;
1102 union sub_crq *next;
1103 u32 length;
1104 u16 offset;
1105 u8 flags = 0;
1106
1107 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
1108 break;
1109 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
1110 rx_buff =
1111 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
1112 rx_comp.correlator);
1113 /* do error checking */
1114 if (next->rx_comp.rc) {
1115 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
1116 /* free the entry */
1117 next->rx_comp.first = 0;
1118 remove_buff_from_pool(adapter, rx_buff);
1119 break;
1120 }
1121
1122 length = be32_to_cpu(next->rx_comp.len);
1123 offset = be16_to_cpu(next->rx_comp.off_frame_data);
1124 flags = next->rx_comp.flags;
1125 skb = rx_buff->skb;
1126 skb_copy_to_linear_data(skb, rx_buff->data + offset,
1127 length);
1128 skb->vlan_tci = be16_to_cpu(next->rx_comp.vlan_tci);
1129 /* free the entry */
1130 next->rx_comp.first = 0;
1131 remove_buff_from_pool(adapter, rx_buff);
1132
1133 skb_put(skb, length);
1134 skb->protocol = eth_type_trans(skb, netdev);
1135
1136 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
1137 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
1138 skb->ip_summed = CHECKSUM_UNNECESSARY;
1139 }
1140
1141 length = skb->len;
1142 napi_gro_receive(napi, skb); /* send it up */
1143 netdev->stats.rx_packets++;
1144 netdev->stats.rx_bytes += length;
1145 frames_processed++;
1146 }
John Allen498cd8e2016-04-06 11:49:55 -05001147 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001148
1149 if (frames_processed < budget) {
1150 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08001151 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001152 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1153 napi_reschedule(napi)) {
1154 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1155 goto restart_poll;
1156 }
1157 }
1158 return frames_processed;
1159}
1160
1161#ifdef CONFIG_NET_POLL_CONTROLLER
1162static void ibmvnic_netpoll_controller(struct net_device *dev)
1163{
1164 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1165 int i;
1166
1167 replenish_pools(netdev_priv(dev));
1168 for (i = 0; i < adapter->req_rx_queues; i++)
1169 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1170 adapter->rx_scrq[i]);
1171}
1172#endif
1173
1174static const struct net_device_ops ibmvnic_netdev_ops = {
1175 .ndo_open = ibmvnic_open,
1176 .ndo_stop = ibmvnic_close,
1177 .ndo_start_xmit = ibmvnic_xmit,
1178 .ndo_set_rx_mode = ibmvnic_set_multi,
1179 .ndo_set_mac_address = ibmvnic_set_mac,
1180 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001181 .ndo_tx_timeout = ibmvnic_tx_timeout,
1182#ifdef CONFIG_NET_POLL_CONTROLLER
1183 .ndo_poll_controller = ibmvnic_netpoll_controller,
1184#endif
1185};
1186
1187/* ethtool functions */
1188
Philippe Reynes8a433792017-01-07 22:37:29 +01001189static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1190 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001191{
Philippe Reynes8a433792017-01-07 22:37:29 +01001192 u32 supported, advertising;
1193
1194 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001195 SUPPORTED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001196 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001197 ADVERTISED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001198 cmd->base.speed = SPEED_1000;
1199 cmd->base.duplex = DUPLEX_FULL;
1200 cmd->base.port = PORT_FIBRE;
1201 cmd->base.phy_address = 0;
1202 cmd->base.autoneg = AUTONEG_ENABLE;
1203
1204 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1205 supported);
1206 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1207 advertising);
1208
Thomas Falcon032c5e82015-12-21 11:26:06 -06001209 return 0;
1210}
1211
1212static void ibmvnic_get_drvinfo(struct net_device *dev,
1213 struct ethtool_drvinfo *info)
1214{
1215 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1216 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1217}
1218
1219static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1220{
1221 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1222
1223 return adapter->msg_enable;
1224}
1225
1226static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1227{
1228 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1229
1230 adapter->msg_enable = data;
1231}
1232
1233static u32 ibmvnic_get_link(struct net_device *netdev)
1234{
1235 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1236
1237 /* Don't need to send a query because we request a logical link up at
1238 * init and then we wait for link state indications
1239 */
1240 return adapter->logical_link_state;
1241}
1242
1243static void ibmvnic_get_ringparam(struct net_device *netdev,
1244 struct ethtool_ringparam *ring)
1245{
1246 ring->rx_max_pending = 0;
1247 ring->tx_max_pending = 0;
1248 ring->rx_mini_max_pending = 0;
1249 ring->rx_jumbo_max_pending = 0;
1250 ring->rx_pending = 0;
1251 ring->tx_pending = 0;
1252 ring->rx_mini_pending = 0;
1253 ring->rx_jumbo_pending = 0;
1254}
1255
1256static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1257{
1258 int i;
1259
1260 if (stringset != ETH_SS_STATS)
1261 return;
1262
1263 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1264 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1265}
1266
1267static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1268{
1269 switch (sset) {
1270 case ETH_SS_STATS:
1271 return ARRAY_SIZE(ibmvnic_stats);
1272 default:
1273 return -EOPNOTSUPP;
1274 }
1275}
1276
1277static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1278 struct ethtool_stats *stats, u64 *data)
1279{
1280 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1281 union ibmvnic_crq crq;
1282 int i;
1283
1284 memset(&crq, 0, sizeof(crq));
1285 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1286 crq.request_statistics.cmd = REQUEST_STATISTICS;
1287 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1288 crq.request_statistics.len =
1289 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06001290
1291 /* Wait for data to be written */
1292 init_completion(&adapter->stats_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05001293 ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001294 wait_for_completion(&adapter->stats_done);
1295
1296 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1297 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1298}
1299
1300static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001301 .get_drvinfo = ibmvnic_get_drvinfo,
1302 .get_msglevel = ibmvnic_get_msglevel,
1303 .set_msglevel = ibmvnic_set_msglevel,
1304 .get_link = ibmvnic_get_link,
1305 .get_ringparam = ibmvnic_get_ringparam,
1306 .get_strings = ibmvnic_get_strings,
1307 .get_sset_count = ibmvnic_get_sset_count,
1308 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01001309 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001310};
1311
1312/* Routines for managing CRQs/sCRQs */
1313
1314static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1315 struct ibmvnic_sub_crq_queue *scrq)
1316{
1317 struct device *dev = &adapter->vdev->dev;
1318 long rc;
1319
1320 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1321
1322 /* Close the sub-crqs */
1323 do {
1324 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1325 adapter->vdev->unit_address,
1326 scrq->crq_num);
1327 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1328
Thomas Falconffa73852017-04-19 13:44:29 -04001329 if (rc) {
1330 netdev_err(adapter->netdev,
1331 "Failed to release sub-CRQ %16lx, rc = %ld\n",
1332 scrq->crq_num, rc);
1333 }
1334
Thomas Falcon032c5e82015-12-21 11:26:06 -06001335 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1336 DMA_BIDIRECTIONAL);
1337 free_pages((unsigned long)scrq->msgs, 2);
1338 kfree(scrq);
1339}
1340
1341static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1342 *adapter)
1343{
1344 struct device *dev = &adapter->vdev->dev;
1345 struct ibmvnic_sub_crq_queue *scrq;
1346 int rc;
1347
1348 scrq = kmalloc(sizeof(*scrq), GFP_ATOMIC);
1349 if (!scrq)
1350 return NULL;
1351
Thomas Falcon12608c22016-10-17 15:28:09 -05001352 scrq->msgs = (union sub_crq *)__get_free_pages(GFP_ATOMIC, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001353 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
1354 if (!scrq->msgs) {
1355 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1356 goto zero_page_failed;
1357 }
1358
1359 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1360 DMA_BIDIRECTIONAL);
1361 if (dma_mapping_error(dev, scrq->msg_token)) {
1362 dev_warn(dev, "Couldn't map crq queue messages page\n");
1363 goto map_failed;
1364 }
1365
1366 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1367 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1368
1369 if (rc == H_RESOURCE)
1370 rc = ibmvnic_reset_crq(adapter);
1371
1372 if (rc == H_CLOSED) {
1373 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1374 } else if (rc) {
1375 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1376 goto reg_failed;
1377 }
1378
Thomas Falcon032c5e82015-12-21 11:26:06 -06001379 scrq->adapter = adapter;
1380 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
1381 scrq->cur = 0;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001382 atomic_set(&scrq->used, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001383 scrq->rx_skb_top = NULL;
1384 spin_lock_init(&scrq->lock);
1385
1386 netdev_dbg(adapter->netdev,
1387 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1388 scrq->crq_num, scrq->hw_irq, scrq->irq);
1389
1390 return scrq;
1391
Thomas Falcon032c5e82015-12-21 11:26:06 -06001392reg_failed:
1393 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1394 DMA_BIDIRECTIONAL);
1395map_failed:
1396 free_pages((unsigned long)scrq->msgs, 2);
1397zero_page_failed:
1398 kfree(scrq);
1399
1400 return NULL;
1401}
1402
1403static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1404{
1405 int i;
1406
1407 if (adapter->tx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001408 for (i = 0; i < adapter->req_tx_queues; i++) {
1409 if (!adapter->tx_scrq[i])
1410 continue;
1411
1412 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001413 free_irq(adapter->tx_scrq[i]->irq,
1414 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001415 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001416 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001417 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001418
1419 release_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1420 }
1421
Nathan Fontenot9501df32017-03-15 23:38:07 -04001422 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001423 adapter->tx_scrq = NULL;
1424 }
1425
1426 if (adapter->rx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001427 for (i = 0; i < adapter->req_rx_queues; i++) {
1428 if (!adapter->rx_scrq[i])
1429 continue;
1430
1431 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001432 free_irq(adapter->rx_scrq[i]->irq,
1433 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001434 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001435 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001436 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001437
1438 release_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1439 }
1440
Nathan Fontenot9501df32017-03-15 23:38:07 -04001441 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001442 adapter->rx_scrq = NULL;
1443 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001444}
1445
1446static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1447 struct ibmvnic_sub_crq_queue *scrq)
1448{
1449 struct device *dev = &adapter->vdev->dev;
1450 unsigned long rc;
1451
1452 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1453 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1454 if (rc)
1455 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1456 scrq->hw_irq, rc);
1457 return rc;
1458}
1459
1460static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1461 struct ibmvnic_sub_crq_queue *scrq)
1462{
1463 struct device *dev = &adapter->vdev->dev;
1464 unsigned long rc;
1465
1466 if (scrq->hw_irq > 0x100000000ULL) {
1467 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1468 return 1;
1469 }
1470
1471 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1472 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1473 if (rc)
1474 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1475 scrq->hw_irq, rc);
1476 return rc;
1477}
1478
1479static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1480 struct ibmvnic_sub_crq_queue *scrq)
1481{
1482 struct device *dev = &adapter->vdev->dev;
1483 struct ibmvnic_tx_buff *txbuff;
1484 union sub_crq *next;
1485 int index;
1486 int i, j;
Thomas Falconad7775d2016-04-01 17:20:34 -05001487 u8 first;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001488
1489restart_loop:
1490 while (pending_scrq(adapter, scrq)) {
1491 unsigned int pool = scrq->pool_index;
1492
1493 next = ibmvnic_next_scrq(adapter, scrq);
1494 for (i = 0; i < next->tx_comp.num_comps; i++) {
1495 if (next->tx_comp.rcs[i]) {
1496 dev_err(dev, "tx error %x\n",
1497 next->tx_comp.rcs[i]);
1498 continue;
1499 }
1500 index = be32_to_cpu(next->tx_comp.correlators[i]);
1501 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1502
1503 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1504 if (!txbuff->data_dma[j])
1505 continue;
1506
1507 txbuff->data_dma[j] = 0;
1508 txbuff->used_bounce = false;
1509 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001510 /* if sub_crq was sent indirectly */
1511 first = txbuff->indir_arr[0].generic.first;
1512 if (first == IBMVNIC_CRQ_CMD) {
1513 dma_unmap_single(dev, txbuff->indir_dma,
1514 sizeof(txbuff->indir_arr),
1515 DMA_TO_DEVICE);
1516 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001517
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001518 if (txbuff->last_frag) {
Brian King58c8c0c2017-04-19 13:44:47 -04001519 if (atomic_sub_return(next->tx_comp.num_comps,
1520 &scrq->used) <=
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001521 (adapter->req_tx_entries_per_subcrq / 2) &&
1522 netif_subqueue_stopped(adapter->netdev,
1523 txbuff->skb)) {
1524 netif_wake_subqueue(adapter->netdev,
1525 scrq->pool_index);
1526 netdev_dbg(adapter->netdev,
1527 "Started queue %d\n",
1528 scrq->pool_index);
1529 }
1530
Thomas Falcon032c5e82015-12-21 11:26:06 -06001531 dev_kfree_skb_any(txbuff->skb);
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001532 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001533
1534 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1535 producer_index] = index;
1536 adapter->tx_pool[pool].producer_index =
1537 (adapter->tx_pool[pool].producer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001538 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001539 }
1540 /* remove tx_comp scrq*/
1541 next->tx_comp.first = 0;
1542 }
1543
1544 enable_scrq_irq(adapter, scrq);
1545
1546 if (pending_scrq(adapter, scrq)) {
1547 disable_scrq_irq(adapter, scrq);
1548 goto restart_loop;
1549 }
1550
1551 return 0;
1552}
1553
1554static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
1555{
1556 struct ibmvnic_sub_crq_queue *scrq = instance;
1557 struct ibmvnic_adapter *adapter = scrq->adapter;
1558
1559 disable_scrq_irq(adapter, scrq);
1560 ibmvnic_complete_tx(adapter, scrq);
1561
1562 return IRQ_HANDLED;
1563}
1564
1565static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
1566{
1567 struct ibmvnic_sub_crq_queue *scrq = instance;
1568 struct ibmvnic_adapter *adapter = scrq->adapter;
1569
1570 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
1571 disable_scrq_irq(adapter, scrq);
1572 __napi_schedule(&adapter->napi[scrq->scrq_num]);
1573 }
1574
1575 return IRQ_HANDLED;
1576}
1577
Thomas Falconea22d512016-07-06 15:35:17 -05001578static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
1579{
1580 struct device *dev = &adapter->vdev->dev;
1581 struct ibmvnic_sub_crq_queue *scrq;
1582 int i = 0, j = 0;
1583 int rc = 0;
1584
1585 for (i = 0; i < adapter->req_tx_queues; i++) {
1586 scrq = adapter->tx_scrq[i];
1587 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
1588
Michael Ellerman99c17902016-09-10 19:59:05 +10001589 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001590 rc = -EINVAL;
1591 dev_err(dev, "Error mapping irq\n");
1592 goto req_tx_irq_failed;
1593 }
1594
1595 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
1596 0, "ibmvnic_tx", scrq);
1597
1598 if (rc) {
1599 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
1600 scrq->irq, rc);
1601 irq_dispose_mapping(scrq->irq);
1602 goto req_rx_irq_failed;
1603 }
1604 }
1605
1606 for (i = 0; i < adapter->req_rx_queues; i++) {
1607 scrq = adapter->rx_scrq[i];
1608 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10001609 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001610 rc = -EINVAL;
1611 dev_err(dev, "Error mapping irq\n");
1612 goto req_rx_irq_failed;
1613 }
1614 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
1615 0, "ibmvnic_rx", scrq);
1616 if (rc) {
1617 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
1618 scrq->irq, rc);
1619 irq_dispose_mapping(scrq->irq);
1620 goto req_rx_irq_failed;
1621 }
1622 }
1623 return rc;
1624
1625req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001626 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001627 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
1628 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001629 }
Thomas Falconea22d512016-07-06 15:35:17 -05001630 i = adapter->req_tx_queues;
1631req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001632 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001633 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
1634 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001635 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001636 release_sub_crqs(adapter);
Thomas Falconea22d512016-07-06 15:35:17 -05001637 return rc;
1638}
1639
Thomas Falcon032c5e82015-12-21 11:26:06 -06001640static void init_sub_crqs(struct ibmvnic_adapter *adapter, int retry)
1641{
1642 struct device *dev = &adapter->vdev->dev;
1643 struct ibmvnic_sub_crq_queue **allqueues;
1644 int registered_queues = 0;
1645 union ibmvnic_crq crq;
1646 int total_queues;
1647 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05001648 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001649
1650 if (!retry) {
1651 /* Sub-CRQ entries are 32 byte long */
1652 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
1653
1654 if (adapter->min_tx_entries_per_subcrq > entries_page ||
1655 adapter->min_rx_add_entries_per_subcrq > entries_page) {
1656 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
1657 goto allqueues_failed;
1658 }
1659
1660 /* Get the minimum between the queried max and the entries
1661 * that fit in our PAGE_SIZE
1662 */
1663 adapter->req_tx_entries_per_subcrq =
1664 adapter->max_tx_entries_per_subcrq > entries_page ?
1665 entries_page : adapter->max_tx_entries_per_subcrq;
1666 adapter->req_rx_add_entries_per_subcrq =
1667 adapter->max_rx_add_entries_per_subcrq > entries_page ?
1668 entries_page : adapter->max_rx_add_entries_per_subcrq;
1669
John Allen6dbcd8f2016-11-07 14:27:28 -06001670 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
1671 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
John Allen498cd8e2016-04-06 11:49:55 -05001672 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001673
Thomas Falconf39f0d12017-02-14 10:22:59 -06001674 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001675 }
1676
1677 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
1678
1679 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_ATOMIC);
1680 if (!allqueues)
1681 goto allqueues_failed;
1682
1683 for (i = 0; i < total_queues; i++) {
1684 allqueues[i] = init_sub_crq_queue(adapter);
1685 if (!allqueues[i]) {
1686 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
1687 break;
1688 }
1689 registered_queues++;
1690 }
1691
1692 /* Make sure we were able to register the minimum number of queues */
1693 if (registered_queues <
1694 adapter->min_tx_queues + adapter->min_rx_queues) {
1695 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
1696 goto tx_failed;
1697 }
1698
1699 /* Distribute the failed allocated queues*/
1700 for (i = 0; i < total_queues - registered_queues + more ; i++) {
1701 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
1702 switch (i % 3) {
1703 case 0:
1704 if (adapter->req_rx_queues > adapter->min_rx_queues)
1705 adapter->req_rx_queues--;
1706 else
1707 more++;
1708 break;
1709 case 1:
1710 if (adapter->req_tx_queues > adapter->min_tx_queues)
1711 adapter->req_tx_queues--;
1712 else
1713 more++;
1714 break;
1715 }
1716 }
1717
1718 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
1719 sizeof(*adapter->tx_scrq), GFP_ATOMIC);
1720 if (!adapter->tx_scrq)
1721 goto tx_failed;
1722
1723 for (i = 0; i < adapter->req_tx_queues; i++) {
1724 adapter->tx_scrq[i] = allqueues[i];
1725 adapter->tx_scrq[i]->pool_index = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001726 }
1727
1728 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
1729 sizeof(*adapter->rx_scrq), GFP_ATOMIC);
1730 if (!adapter->rx_scrq)
1731 goto rx_failed;
1732
1733 for (i = 0; i < adapter->req_rx_queues; i++) {
1734 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
1735 adapter->rx_scrq[i]->scrq_num = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001736 }
1737
1738 memset(&crq, 0, sizeof(crq));
1739 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1740 crq.request_capability.cmd = REQUEST_CAPABILITY;
1741
1742 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001743 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001744 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001745 ibmvnic_send_crq(adapter, &crq);
1746
1747 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001748 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001749 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001750 ibmvnic_send_crq(adapter, &crq);
1751
1752 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001753 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001754 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001755 ibmvnic_send_crq(adapter, &crq);
1756
1757 crq.request_capability.capability =
1758 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
1759 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001760 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001761 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001762 ibmvnic_send_crq(adapter, &crq);
1763
1764 crq.request_capability.capability =
1765 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
1766 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001767 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001768 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001769 ibmvnic_send_crq(adapter, &crq);
1770
1771 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06001772 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06001773 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001774 ibmvnic_send_crq(adapter, &crq);
1775
1776 if (adapter->netdev->flags & IFF_PROMISC) {
1777 if (adapter->promisc_supported) {
1778 crq.request_capability.capability =
1779 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001780 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06001781 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001782 ibmvnic_send_crq(adapter, &crq);
1783 }
1784 } else {
1785 crq.request_capability.capability =
1786 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001787 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06001788 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001789 ibmvnic_send_crq(adapter, &crq);
1790 }
1791
1792 kfree(allqueues);
1793
1794 return;
1795
Thomas Falcon032c5e82015-12-21 11:26:06 -06001796rx_failed:
1797 kfree(adapter->tx_scrq);
1798 adapter->tx_scrq = NULL;
1799tx_failed:
1800 for (i = 0; i < registered_queues; i++)
1801 release_sub_crq_queue(adapter, allqueues[i]);
1802 kfree(allqueues);
1803allqueues_failed:
1804 ibmvnic_remove(adapter->vdev);
1805}
1806
1807static int pending_scrq(struct ibmvnic_adapter *adapter,
1808 struct ibmvnic_sub_crq_queue *scrq)
1809{
1810 union sub_crq *entry = &scrq->msgs[scrq->cur];
1811
1812 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP || adapter->closing)
1813 return 1;
1814 else
1815 return 0;
1816}
1817
1818static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
1819 struct ibmvnic_sub_crq_queue *scrq)
1820{
1821 union sub_crq *entry;
1822 unsigned long flags;
1823
1824 spin_lock_irqsave(&scrq->lock, flags);
1825 entry = &scrq->msgs[scrq->cur];
1826 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1827 if (++scrq->cur == scrq->size)
1828 scrq->cur = 0;
1829 } else {
1830 entry = NULL;
1831 }
1832 spin_unlock_irqrestore(&scrq->lock, flags);
1833
1834 return entry;
1835}
1836
1837static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
1838{
1839 struct ibmvnic_crq_queue *queue = &adapter->crq;
1840 union ibmvnic_crq *crq;
1841
1842 crq = &queue->msgs[queue->cur];
1843 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1844 if (++queue->cur == queue->size)
1845 queue->cur = 0;
1846 } else {
1847 crq = NULL;
1848 }
1849
1850 return crq;
1851}
1852
1853static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
1854 union sub_crq *sub_crq)
1855{
1856 unsigned int ua = adapter->vdev->unit_address;
1857 struct device *dev = &adapter->vdev->dev;
1858 u64 *u64_crq = (u64 *)sub_crq;
1859 int rc;
1860
1861 netdev_dbg(adapter->netdev,
1862 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
1863 (unsigned long int)cpu_to_be64(remote_handle),
1864 (unsigned long int)cpu_to_be64(u64_crq[0]),
1865 (unsigned long int)cpu_to_be64(u64_crq[1]),
1866 (unsigned long int)cpu_to_be64(u64_crq[2]),
1867 (unsigned long int)cpu_to_be64(u64_crq[3]));
1868
1869 /* Make sure the hypervisor sees the complete request */
1870 mb();
1871
1872 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
1873 cpu_to_be64(remote_handle),
1874 cpu_to_be64(u64_crq[0]),
1875 cpu_to_be64(u64_crq[1]),
1876 cpu_to_be64(u64_crq[2]),
1877 cpu_to_be64(u64_crq[3]));
1878
1879 if (rc) {
1880 if (rc == H_CLOSED)
1881 dev_warn(dev, "CRQ Queue closed\n");
1882 dev_err(dev, "Send error (rc=%d)\n", rc);
1883 }
1884
1885 return rc;
1886}
1887
Thomas Falconad7775d2016-04-01 17:20:34 -05001888static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
1889 u64 remote_handle, u64 ioba, u64 num_entries)
1890{
1891 unsigned int ua = adapter->vdev->unit_address;
1892 struct device *dev = &adapter->vdev->dev;
1893 int rc;
1894
1895 /* Make sure the hypervisor sees the complete request */
1896 mb();
1897 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
1898 cpu_to_be64(remote_handle),
1899 ioba, num_entries);
1900
1901 if (rc) {
1902 if (rc == H_CLOSED)
1903 dev_warn(dev, "CRQ Queue closed\n");
1904 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
1905 }
1906
1907 return rc;
1908}
1909
Thomas Falcon032c5e82015-12-21 11:26:06 -06001910static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
1911 union ibmvnic_crq *crq)
1912{
1913 unsigned int ua = adapter->vdev->unit_address;
1914 struct device *dev = &adapter->vdev->dev;
1915 u64 *u64_crq = (u64 *)crq;
1916 int rc;
1917
1918 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
1919 (unsigned long int)cpu_to_be64(u64_crq[0]),
1920 (unsigned long int)cpu_to_be64(u64_crq[1]));
1921
1922 /* Make sure the hypervisor sees the complete request */
1923 mb();
1924
1925 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
1926 cpu_to_be64(u64_crq[0]),
1927 cpu_to_be64(u64_crq[1]));
1928
1929 if (rc) {
1930 if (rc == H_CLOSED)
1931 dev_warn(dev, "CRQ Queue closed\n");
1932 dev_warn(dev, "Send error (rc=%d)\n", rc);
1933 }
1934
1935 return rc;
1936}
1937
1938static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
1939{
1940 union ibmvnic_crq crq;
1941
1942 memset(&crq, 0, sizeof(crq));
1943 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1944 crq.generic.cmd = IBMVNIC_CRQ_INIT;
1945 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
1946
1947 return ibmvnic_send_crq(adapter, &crq);
1948}
1949
1950static int ibmvnic_send_crq_init_complete(struct ibmvnic_adapter *adapter)
1951{
1952 union ibmvnic_crq crq;
1953
1954 memset(&crq, 0, sizeof(crq));
1955 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1956 crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE;
1957 netdev_dbg(adapter->netdev, "Sending CRQ init complete\n");
1958
1959 return ibmvnic_send_crq(adapter, &crq);
1960}
1961
1962static int send_version_xchg(struct ibmvnic_adapter *adapter)
1963{
1964 union ibmvnic_crq crq;
1965
1966 memset(&crq, 0, sizeof(crq));
1967 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
1968 crq.version_exchange.cmd = VERSION_EXCHANGE;
1969 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
1970
1971 return ibmvnic_send_crq(adapter, &crq);
1972}
1973
1974static void send_login(struct ibmvnic_adapter *adapter)
1975{
1976 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
1977 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001978 struct device *dev = &adapter->vdev->dev;
1979 dma_addr_t rsp_buffer_token;
1980 dma_addr_t buffer_token;
1981 size_t rsp_buffer_size;
1982 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001983 size_t buffer_size;
1984 __be64 *tx_list_p;
1985 __be64 *rx_list_p;
1986 int i;
1987
1988 buffer_size =
1989 sizeof(struct ibmvnic_login_buffer) +
1990 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
1991
1992 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
1993 if (!login_buffer)
1994 goto buf_alloc_failed;
1995
1996 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
1997 DMA_TO_DEVICE);
1998 if (dma_mapping_error(dev, buffer_token)) {
1999 dev_err(dev, "Couldn't map login buffer\n");
2000 goto buf_map_failed;
2001 }
2002
John Allen498cd8e2016-04-06 11:49:55 -05002003 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
2004 sizeof(u64) * adapter->req_tx_queues +
2005 sizeof(u64) * adapter->req_rx_queues +
2006 sizeof(u64) * adapter->req_rx_queues +
2007 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002008
2009 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
2010 if (!login_rsp_buffer)
2011 goto buf_rsp_alloc_failed;
2012
2013 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
2014 rsp_buffer_size, DMA_FROM_DEVICE);
2015 if (dma_mapping_error(dev, rsp_buffer_token)) {
2016 dev_err(dev, "Couldn't map login rsp buffer\n");
2017 goto buf_rsp_map_failed;
2018 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04002019
Thomas Falcon032c5e82015-12-21 11:26:06 -06002020 adapter->login_buf = login_buffer;
2021 adapter->login_buf_token = buffer_token;
2022 adapter->login_buf_sz = buffer_size;
2023 adapter->login_rsp_buf = login_rsp_buffer;
2024 adapter->login_rsp_buf_token = rsp_buffer_token;
2025 adapter->login_rsp_buf_sz = rsp_buffer_size;
2026
2027 login_buffer->len = cpu_to_be32(buffer_size);
2028 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
2029 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
2030 login_buffer->off_txcomp_subcrqs =
2031 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
2032 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
2033 login_buffer->off_rxcomp_subcrqs =
2034 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
2035 sizeof(u64) * adapter->req_tx_queues);
2036 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
2037 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
2038
2039 tx_list_p = (__be64 *)((char *)login_buffer +
2040 sizeof(struct ibmvnic_login_buffer));
2041 rx_list_p = (__be64 *)((char *)login_buffer +
2042 sizeof(struct ibmvnic_login_buffer) +
2043 sizeof(u64) * adapter->req_tx_queues);
2044
2045 for (i = 0; i < adapter->req_tx_queues; i++) {
2046 if (adapter->tx_scrq[i]) {
2047 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
2048 crq_num);
2049 }
2050 }
2051
2052 for (i = 0; i < adapter->req_rx_queues; i++) {
2053 if (adapter->rx_scrq[i]) {
2054 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
2055 crq_num);
2056 }
2057 }
2058
2059 netdev_dbg(adapter->netdev, "Login Buffer:\n");
2060 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
2061 netdev_dbg(adapter->netdev, "%016lx\n",
2062 ((unsigned long int *)(adapter->login_buf))[i]);
2063 }
2064
2065 memset(&crq, 0, sizeof(crq));
2066 crq.login.first = IBMVNIC_CRQ_CMD;
2067 crq.login.cmd = LOGIN;
2068 crq.login.ioba = cpu_to_be32(buffer_token);
2069 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002070 ibmvnic_send_crq(adapter, &crq);
2071
2072 return;
2073
Thomas Falcon032c5e82015-12-21 11:26:06 -06002074buf_rsp_map_failed:
2075 kfree(login_rsp_buffer);
2076buf_rsp_alloc_failed:
2077 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
2078buf_map_failed:
2079 kfree(login_buffer);
2080buf_alloc_failed:
2081 return;
2082}
2083
2084static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
2085 u32 len, u8 map_id)
2086{
2087 union ibmvnic_crq crq;
2088
2089 memset(&crq, 0, sizeof(crq));
2090 crq.request_map.first = IBMVNIC_CRQ_CMD;
2091 crq.request_map.cmd = REQUEST_MAP;
2092 crq.request_map.map_id = map_id;
2093 crq.request_map.ioba = cpu_to_be32(addr);
2094 crq.request_map.len = cpu_to_be32(len);
2095 ibmvnic_send_crq(adapter, &crq);
2096}
2097
2098static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
2099{
2100 union ibmvnic_crq crq;
2101
2102 memset(&crq, 0, sizeof(crq));
2103 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
2104 crq.request_unmap.cmd = REQUEST_UNMAP;
2105 crq.request_unmap.map_id = map_id;
2106 ibmvnic_send_crq(adapter, &crq);
2107}
2108
2109static void send_map_query(struct ibmvnic_adapter *adapter)
2110{
2111 union ibmvnic_crq crq;
2112
2113 memset(&crq, 0, sizeof(crq));
2114 crq.query_map.first = IBMVNIC_CRQ_CMD;
2115 crq.query_map.cmd = QUERY_MAP;
2116 ibmvnic_send_crq(adapter, &crq);
2117}
2118
2119/* Send a series of CRQs requesting various capabilities of the VNIC server */
2120static void send_cap_queries(struct ibmvnic_adapter *adapter)
2121{
2122 union ibmvnic_crq crq;
2123
Thomas Falcon901e0402017-02-15 12:17:59 -06002124 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002125 memset(&crq, 0, sizeof(crq));
2126 crq.query_capability.first = IBMVNIC_CRQ_CMD;
2127 crq.query_capability.cmd = QUERY_CAPABILITY;
2128
2129 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002130 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002131 ibmvnic_send_crq(adapter, &crq);
2132
2133 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002134 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002135 ibmvnic_send_crq(adapter, &crq);
2136
2137 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002138 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002139 ibmvnic_send_crq(adapter, &crq);
2140
2141 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002142 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002143 ibmvnic_send_crq(adapter, &crq);
2144
2145 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002146 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002147 ibmvnic_send_crq(adapter, &crq);
2148
2149 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002150 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002151 ibmvnic_send_crq(adapter, &crq);
2152
2153 crq.query_capability.capability =
2154 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002155 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002156 ibmvnic_send_crq(adapter, &crq);
2157
2158 crq.query_capability.capability =
2159 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002160 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002161 ibmvnic_send_crq(adapter, &crq);
2162
2163 crq.query_capability.capability =
2164 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002165 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002166 ibmvnic_send_crq(adapter, &crq);
2167
2168 crq.query_capability.capability =
2169 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002170 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002171 ibmvnic_send_crq(adapter, &crq);
2172
2173 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
Thomas Falcon901e0402017-02-15 12:17:59 -06002174 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002175 ibmvnic_send_crq(adapter, &crq);
2176
2177 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002178 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002179 ibmvnic_send_crq(adapter, &crq);
2180
2181 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002182 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002183 ibmvnic_send_crq(adapter, &crq);
2184
2185 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002186 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002187 ibmvnic_send_crq(adapter, &crq);
2188
2189 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
Thomas Falcon901e0402017-02-15 12:17:59 -06002190 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002191 ibmvnic_send_crq(adapter, &crq);
2192
2193 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06002194 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002195 ibmvnic_send_crq(adapter, &crq);
2196
2197 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002198 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002199 ibmvnic_send_crq(adapter, &crq);
2200
2201 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002202 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002203 ibmvnic_send_crq(adapter, &crq);
2204
2205 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002206 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002207 ibmvnic_send_crq(adapter, &crq);
2208
2209 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002210 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002211 ibmvnic_send_crq(adapter, &crq);
2212
2213 crq.query_capability.capability =
2214 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06002215 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002216 ibmvnic_send_crq(adapter, &crq);
2217
2218 crq.query_capability.capability =
2219 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002220 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002221 ibmvnic_send_crq(adapter, &crq);
2222
2223 crq.query_capability.capability =
2224 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002225 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002226 ibmvnic_send_crq(adapter, &crq);
2227
2228 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002229 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002230 ibmvnic_send_crq(adapter, &crq);
2231}
2232
2233static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2234{
2235 struct device *dev = &adapter->vdev->dev;
2236 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2237 union ibmvnic_crq crq;
2238 int i;
2239
2240 dma_unmap_single(dev, adapter->ip_offload_tok,
2241 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2242
2243 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2244 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2245 netdev_dbg(adapter->netdev, "%016lx\n",
2246 ((unsigned long int *)(buf))[i]);
2247
2248 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2249 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2250 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2251 buf->tcp_ipv4_chksum);
2252 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2253 buf->tcp_ipv6_chksum);
2254 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2255 buf->udp_ipv4_chksum);
2256 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2257 buf->udp_ipv6_chksum);
2258 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2259 buf->large_tx_ipv4);
2260 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2261 buf->large_tx_ipv6);
2262 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2263 buf->large_rx_ipv4);
2264 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2265 buf->large_rx_ipv6);
2266 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2267 buf->max_ipv4_header_size);
2268 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2269 buf->max_ipv6_header_size);
2270 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2271 buf->max_tcp_header_size);
2272 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2273 buf->max_udp_header_size);
2274 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2275 buf->max_large_tx_size);
2276 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2277 buf->max_large_rx_size);
2278 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2279 buf->ipv6_extension_header);
2280 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2281 buf->tcp_pseudosum_req);
2282 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2283 buf->num_ipv6_ext_headers);
2284 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2285 buf->off_ipv6_ext_headers);
2286
2287 adapter->ip_offload_ctrl_tok =
2288 dma_map_single(dev, &adapter->ip_offload_ctrl,
2289 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2290
2291 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2292 dev_err(dev, "Couldn't map ip offload control buffer\n");
2293 return;
2294 }
2295
2296 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2297 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2298 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2299 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2300 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2301
2302 /* large_tx/rx disabled for now, additional features needed */
2303 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2304 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2305 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2306 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2307
2308 adapter->netdev->features = NETIF_F_GSO;
2309
2310 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2311 adapter->netdev->features |= NETIF_F_IP_CSUM;
2312
2313 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2314 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2315
Thomas Falcon9be02cd2016-04-01 17:20:35 -05002316 if ((adapter->netdev->features &
2317 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2318 adapter->netdev->features |= NETIF_F_RXCSUM;
2319
Thomas Falcon032c5e82015-12-21 11:26:06 -06002320 memset(&crq, 0, sizeof(crq));
2321 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2322 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2323 crq.control_ip_offload.len =
2324 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2325 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2326 ibmvnic_send_crq(adapter, &crq);
2327}
2328
2329static void handle_error_info_rsp(union ibmvnic_crq *crq,
2330 struct ibmvnic_adapter *adapter)
2331{
2332 struct device *dev = &adapter->vdev->dev;
Wei Yongjun96183182016-06-27 20:48:53 +08002333 struct ibmvnic_error_buff *error_buff, *tmp;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002334 unsigned long flags;
2335 bool found = false;
2336 int i;
2337
2338 if (!crq->request_error_rsp.rc.code) {
2339 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2340 crq->request_error_rsp.rc.code);
2341 return;
2342 }
2343
2344 spin_lock_irqsave(&adapter->error_list_lock, flags);
Wei Yongjun96183182016-06-27 20:48:53 +08002345 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002346 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2347 found = true;
2348 list_del(&error_buff->list);
2349 break;
2350 }
2351 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2352
2353 if (!found) {
2354 dev_err(dev, "Couldn't find error id %x\n",
Thomas Falcon75224c92017-02-15 10:33:33 -06002355 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002356 return;
2357 }
2358
2359 dev_err(dev, "Detailed info for error id %x:",
Thomas Falcon75224c92017-02-15 10:33:33 -06002360 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002361
2362 for (i = 0; i < error_buff->len; i++) {
2363 pr_cont("%02x", (int)error_buff->buff[i]);
2364 if (i % 8 == 7)
2365 pr_cont(" ");
2366 }
2367 pr_cont("\n");
2368
2369 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2370 DMA_FROM_DEVICE);
2371 kfree(error_buff->buff);
2372 kfree(error_buff);
2373}
2374
Thomas Falcon032c5e82015-12-21 11:26:06 -06002375static void handle_error_indication(union ibmvnic_crq *crq,
2376 struct ibmvnic_adapter *adapter)
2377{
2378 int detail_len = be32_to_cpu(crq->error_indication.detail_error_sz);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002379 struct device *dev = &adapter->vdev->dev;
2380 struct ibmvnic_error_buff *error_buff;
2381 union ibmvnic_crq new_crq;
2382 unsigned long flags;
2383
2384 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2385 crq->error_indication.
2386 flags & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
Thomas Falcon75224c92017-02-15 10:33:33 -06002387 be32_to_cpu(crq->error_indication.error_id),
2388 be16_to_cpu(crq->error_indication.error_cause));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002389
2390 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2391 if (!error_buff)
2392 return;
2393
2394 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2395 if (!error_buff->buff) {
2396 kfree(error_buff);
2397 return;
2398 }
2399
2400 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2401 DMA_FROM_DEVICE);
2402 if (dma_mapping_error(dev, error_buff->dma)) {
2403 if (!firmware_has_feature(FW_FEATURE_CMO))
2404 dev_err(dev, "Couldn't map error buffer\n");
2405 kfree(error_buff->buff);
2406 kfree(error_buff);
2407 return;
2408 }
2409
Thomas Falcon032c5e82015-12-21 11:26:06 -06002410 error_buff->len = detail_len;
2411 error_buff->error_id = crq->error_indication.error_id;
2412
2413 spin_lock_irqsave(&adapter->error_list_lock, flags);
2414 list_add_tail(&error_buff->list, &adapter->errors);
2415 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2416
2417 memset(&new_crq, 0, sizeof(new_crq));
2418 new_crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2419 new_crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2420 new_crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2421 new_crq.request_error_info.len = cpu_to_be32(detail_len);
2422 new_crq.request_error_info.error_id = crq->error_indication.error_id;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002423 ibmvnic_send_crq(adapter, &new_crq);
2424}
2425
2426static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2427 struct ibmvnic_adapter *adapter)
2428{
2429 struct net_device *netdev = adapter->netdev;
2430 struct device *dev = &adapter->vdev->dev;
2431 long rc;
2432
2433 rc = crq->change_mac_addr_rsp.rc.code;
2434 if (rc) {
2435 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2436 return;
2437 }
2438 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2439 ETH_ALEN);
2440}
2441
2442static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2443 struct ibmvnic_adapter *adapter)
2444{
2445 struct device *dev = &adapter->vdev->dev;
2446 u64 *req_value;
2447 char *name;
2448
Thomas Falcon901e0402017-02-15 12:17:59 -06002449 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002450 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2451 case REQ_TX_QUEUES:
2452 req_value = &adapter->req_tx_queues;
2453 name = "tx";
2454 break;
2455 case REQ_RX_QUEUES:
2456 req_value = &adapter->req_rx_queues;
2457 name = "rx";
2458 break;
2459 case REQ_RX_ADD_QUEUES:
2460 req_value = &adapter->req_rx_add_queues;
2461 name = "rx_add";
2462 break;
2463 case REQ_TX_ENTRIES_PER_SUBCRQ:
2464 req_value = &adapter->req_tx_entries_per_subcrq;
2465 name = "tx_entries_per_subcrq";
2466 break;
2467 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2468 req_value = &adapter->req_rx_add_entries_per_subcrq;
2469 name = "rx_add_entries_per_subcrq";
2470 break;
2471 case REQ_MTU:
2472 req_value = &adapter->req_mtu;
2473 name = "mtu";
2474 break;
2475 case PROMISC_REQUESTED:
2476 req_value = &adapter->promisc;
2477 name = "promisc";
2478 break;
2479 default:
2480 dev_err(dev, "Got invalid cap request rsp %d\n",
2481 crq->request_capability.capability);
2482 return;
2483 }
2484
2485 switch (crq->request_capability_rsp.rc.code) {
2486 case SUCCESS:
2487 break;
2488 case PARTIALSUCCESS:
2489 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2490 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06002491 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06002492 number), name);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002493 release_sub_crqs(adapter);
Thomas Falcon28f4d162017-02-15 10:32:11 -06002494 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
Thomas Falconea22d512016-07-06 15:35:17 -05002495 init_sub_crqs(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002496 return;
2497 default:
2498 dev_err(dev, "Error %d in request cap rsp\n",
2499 crq->request_capability_rsp.rc.code);
2500 return;
2501 }
2502
2503 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06002504 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002505 union ibmvnic_crq newcrq;
2506 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2507 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2508 &adapter->ip_offload_buf;
2509
Thomas Falcon249168a2017-02-15 12:18:00 -06002510 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002511 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
2512 buf_sz,
2513 DMA_FROM_DEVICE);
2514
2515 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
2516 if (!firmware_has_feature(FW_FEATURE_CMO))
2517 dev_err(dev, "Couldn't map offload buffer\n");
2518 return;
2519 }
2520
2521 memset(&newcrq, 0, sizeof(newcrq));
2522 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
2523 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
2524 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
2525 newcrq.query_ip_offload.ioba =
2526 cpu_to_be32(adapter->ip_offload_tok);
2527
2528 ibmvnic_send_crq(adapter, &newcrq);
2529 }
2530}
2531
2532static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
2533 struct ibmvnic_adapter *adapter)
2534{
2535 struct device *dev = &adapter->vdev->dev;
2536 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
2537 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002538 int i;
2539
2540 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
2541 DMA_BIDIRECTIONAL);
2542 dma_unmap_single(dev, adapter->login_rsp_buf_token,
2543 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
2544
John Allen498cd8e2016-04-06 11:49:55 -05002545 /* If the number of queues requested can't be allocated by the
2546 * server, the login response will return with code 1. We will need
2547 * to resend the login buffer with fewer queues requested.
2548 */
2549 if (login_rsp_crq->generic.rc.code) {
2550 adapter->renegotiate = true;
2551 complete(&adapter->init_done);
2552 return 0;
2553 }
2554
Thomas Falcon032c5e82015-12-21 11:26:06 -06002555 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
2556 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
2557 netdev_dbg(adapter->netdev, "%016lx\n",
2558 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
2559 }
2560
2561 /* Sanity checks */
2562 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
2563 (be32_to_cpu(login->num_rxcomp_subcrqs) *
2564 adapter->req_rx_add_queues !=
2565 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
2566 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
2567 ibmvnic_remove(adapter->vdev);
2568 return -EIO;
2569 }
2570 complete(&adapter->init_done);
2571
Thomas Falcon032c5e82015-12-21 11:26:06 -06002572 return 0;
2573}
2574
2575static void handle_request_map_rsp(union ibmvnic_crq *crq,
2576 struct ibmvnic_adapter *adapter)
2577{
2578 struct device *dev = &adapter->vdev->dev;
2579 u8 map_id = crq->request_map_rsp.map_id;
2580 int tx_subcrqs;
2581 int rx_subcrqs;
2582 long rc;
2583 int i;
2584
2585 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
2586 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
2587
2588 rc = crq->request_map_rsp.rc.code;
2589 if (rc) {
2590 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
2591 adapter->map_id--;
2592 /* need to find and zero tx/rx_pool map_id */
2593 for (i = 0; i < tx_subcrqs; i++) {
2594 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
2595 adapter->tx_pool[i].long_term_buff.map_id = 0;
2596 }
2597 for (i = 0; i < rx_subcrqs; i++) {
2598 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
2599 adapter->rx_pool[i].long_term_buff.map_id = 0;
2600 }
2601 }
2602 complete(&adapter->fw_done);
2603}
2604
2605static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
2606 struct ibmvnic_adapter *adapter)
2607{
2608 struct device *dev = &adapter->vdev->dev;
2609 long rc;
2610
2611 rc = crq->request_unmap_rsp.rc.code;
2612 if (rc)
2613 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
2614}
2615
2616static void handle_query_map_rsp(union ibmvnic_crq *crq,
2617 struct ibmvnic_adapter *adapter)
2618{
2619 struct net_device *netdev = adapter->netdev;
2620 struct device *dev = &adapter->vdev->dev;
2621 long rc;
2622
2623 rc = crq->query_map_rsp.rc.code;
2624 if (rc) {
2625 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
2626 return;
2627 }
2628 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
2629 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
2630 crq->query_map_rsp.free_pages);
2631}
2632
2633static void handle_query_cap_rsp(union ibmvnic_crq *crq,
2634 struct ibmvnic_adapter *adapter)
2635{
2636 struct net_device *netdev = adapter->netdev;
2637 struct device *dev = &adapter->vdev->dev;
2638 long rc;
2639
Thomas Falcon901e0402017-02-15 12:17:59 -06002640 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002641 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06002642 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002643 rc = crq->query_capability.rc.code;
2644 if (rc) {
2645 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
2646 goto out;
2647 }
2648
2649 switch (be16_to_cpu(crq->query_capability.capability)) {
2650 case MIN_TX_QUEUES:
2651 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002652 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002653 netdev_dbg(netdev, "min_tx_queues = %lld\n",
2654 adapter->min_tx_queues);
2655 break;
2656 case MIN_RX_QUEUES:
2657 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002658 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002659 netdev_dbg(netdev, "min_rx_queues = %lld\n",
2660 adapter->min_rx_queues);
2661 break;
2662 case MIN_RX_ADD_QUEUES:
2663 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002664 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002665 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
2666 adapter->min_rx_add_queues);
2667 break;
2668 case MAX_TX_QUEUES:
2669 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002670 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002671 netdev_dbg(netdev, "max_tx_queues = %lld\n",
2672 adapter->max_tx_queues);
2673 break;
2674 case MAX_RX_QUEUES:
2675 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002676 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002677 netdev_dbg(netdev, "max_rx_queues = %lld\n",
2678 adapter->max_rx_queues);
2679 break;
2680 case MAX_RX_ADD_QUEUES:
2681 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002682 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002683 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
2684 adapter->max_rx_add_queues);
2685 break;
2686 case MIN_TX_ENTRIES_PER_SUBCRQ:
2687 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002688 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002689 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
2690 adapter->min_tx_entries_per_subcrq);
2691 break;
2692 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
2693 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002694 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002695 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
2696 adapter->min_rx_add_entries_per_subcrq);
2697 break;
2698 case MAX_TX_ENTRIES_PER_SUBCRQ:
2699 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002700 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002701 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
2702 adapter->max_tx_entries_per_subcrq);
2703 break;
2704 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
2705 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002706 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002707 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
2708 adapter->max_rx_add_entries_per_subcrq);
2709 break;
2710 case TCP_IP_OFFLOAD:
2711 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06002712 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002713 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
2714 adapter->tcp_ip_offload);
2715 break;
2716 case PROMISC_SUPPORTED:
2717 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002718 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002719 netdev_dbg(netdev, "promisc_supported = %lld\n",
2720 adapter->promisc_supported);
2721 break;
2722 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002723 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002724 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002725 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
2726 break;
2727 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002728 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002729 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002730 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
2731 break;
2732 case MAX_MULTICAST_FILTERS:
2733 adapter->max_multicast_filters =
Thomas Falconde89e852016-03-01 10:20:09 -06002734 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002735 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
2736 adapter->max_multicast_filters);
2737 break;
2738 case VLAN_HEADER_INSERTION:
2739 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06002740 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002741 if (adapter->vlan_header_insertion)
2742 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
2743 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
2744 adapter->vlan_header_insertion);
2745 break;
2746 case MAX_TX_SG_ENTRIES:
2747 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06002748 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002749 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
2750 adapter->max_tx_sg_entries);
2751 break;
2752 case RX_SG_SUPPORTED:
2753 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002754 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002755 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
2756 adapter->rx_sg_supported);
2757 break;
2758 case OPT_TX_COMP_SUB_QUEUES:
2759 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002760 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002761 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
2762 adapter->opt_tx_comp_sub_queues);
2763 break;
2764 case OPT_RX_COMP_QUEUES:
2765 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002766 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002767 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
2768 adapter->opt_rx_comp_queues);
2769 break;
2770 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
2771 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06002772 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002773 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
2774 adapter->opt_rx_bufadd_q_per_rx_comp_q);
2775 break;
2776 case OPT_TX_ENTRIES_PER_SUBCRQ:
2777 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002778 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002779 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
2780 adapter->opt_tx_entries_per_subcrq);
2781 break;
2782 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
2783 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002784 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002785 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
2786 adapter->opt_rxba_entries_per_subcrq);
2787 break;
2788 case TX_RX_DESC_REQ:
2789 adapter->tx_rx_desc_req = crq->query_capability.number;
2790 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
2791 adapter->tx_rx_desc_req);
2792 break;
2793
2794 default:
2795 netdev_err(netdev, "Got invalid cap rsp %d\n",
2796 crq->query_capability.capability);
2797 }
2798
2799out:
Thomas Falcon249168a2017-02-15 12:18:00 -06002800 if (atomic_read(&adapter->running_cap_crqs) == 0) {
2801 adapter->wait_capability = false;
Thomas Falconea22d512016-07-06 15:35:17 -05002802 init_sub_crqs(adapter, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002803 /* We're done querying the capabilities, initialize sub-crqs */
Thomas Falcon249168a2017-02-15 12:18:00 -06002804 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002805}
2806
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002807static void ibmvnic_xport_event(struct work_struct *work)
2808{
2809 struct ibmvnic_adapter *adapter = container_of(work,
2810 struct ibmvnic_adapter,
2811 ibmvnic_xport);
2812 struct device *dev = &adapter->vdev->dev;
2813 long rc;
2814
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002815 release_sub_crqs(adapter);
2816 if (adapter->migrated) {
2817 rc = ibmvnic_reenable_crq_queue(adapter);
2818 if (rc)
2819 dev_err(dev, "Error after enable rc=%ld\n", rc);
2820 adapter->migrated = false;
2821 rc = ibmvnic_send_crq_init(adapter);
2822 if (rc)
2823 dev_err(dev, "Error sending init rc=%ld\n", rc);
2824 }
2825}
2826
Thomas Falcon032c5e82015-12-21 11:26:06 -06002827static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
2828 struct ibmvnic_adapter *adapter)
2829{
2830 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
2831 struct net_device *netdev = adapter->netdev;
2832 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002833 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002834 long rc;
2835
2836 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002837 (unsigned long int)cpu_to_be64(u64_crq[0]),
2838 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002839 switch (gen_crq->first) {
2840 case IBMVNIC_CRQ_INIT_RSP:
2841 switch (gen_crq->cmd) {
2842 case IBMVNIC_CRQ_INIT:
2843 dev_info(dev, "Partner initialized\n");
2844 /* Send back a response */
2845 rc = ibmvnic_send_crq_init_complete(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05002846 if (!rc)
2847 schedule_work(&adapter->vnic_crq_init);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002848 else
2849 dev_err(dev, "Can't send initrsp rc=%ld\n", rc);
2850 break;
2851 case IBMVNIC_CRQ_INIT_COMPLETE:
2852 dev_info(dev, "Partner initialization complete\n");
2853 send_version_xchg(adapter);
2854 break;
2855 default:
2856 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
2857 }
2858 return;
2859 case IBMVNIC_CRQ_XPORT_EVENT:
2860 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
2861 dev_info(dev, "Re-enabling adapter\n");
2862 adapter->migrated = true;
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002863 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcondfad09a2016-08-18 11:37:51 -05002864 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
2865 dev_info(dev, "Backing device failover detected\n");
2866 netif_carrier_off(netdev);
2867 adapter->failover = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002868 } else {
2869 /* The adapter lost the connection */
2870 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
2871 gen_crq->cmd);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002872 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002873 }
2874 return;
2875 case IBMVNIC_CRQ_CMD_RSP:
2876 break;
2877 default:
2878 dev_err(dev, "Got an invalid msg type 0x%02x\n",
2879 gen_crq->first);
2880 return;
2881 }
2882
2883 switch (gen_crq->cmd) {
2884 case VERSION_EXCHANGE_RSP:
2885 rc = crq->version_exchange_rsp.rc.code;
2886 if (rc) {
2887 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
2888 break;
2889 }
2890 dev_info(dev, "Partner protocol version is %d\n",
2891 crq->version_exchange_rsp.version);
2892 if (be16_to_cpu(crq->version_exchange_rsp.version) <
2893 ibmvnic_version)
2894 ibmvnic_version =
2895 be16_to_cpu(crq->version_exchange_rsp.version);
2896 send_cap_queries(adapter);
2897 break;
2898 case QUERY_CAPABILITY_RSP:
2899 handle_query_cap_rsp(crq, adapter);
2900 break;
2901 case QUERY_MAP_RSP:
2902 handle_query_map_rsp(crq, adapter);
2903 break;
2904 case REQUEST_MAP_RSP:
2905 handle_request_map_rsp(crq, adapter);
2906 break;
2907 case REQUEST_UNMAP_RSP:
2908 handle_request_unmap_rsp(crq, adapter);
2909 break;
2910 case REQUEST_CAPABILITY_RSP:
2911 handle_request_cap_rsp(crq, adapter);
2912 break;
2913 case LOGIN_RSP:
2914 netdev_dbg(netdev, "Got Login Response\n");
2915 handle_login_rsp(crq, adapter);
2916 break;
2917 case LOGICAL_LINK_STATE_RSP:
2918 netdev_dbg(netdev, "Got Logical Link State Response\n");
2919 adapter->logical_link_state =
2920 crq->logical_link_state_rsp.link_state;
2921 break;
2922 case LINK_STATE_INDICATION:
2923 netdev_dbg(netdev, "Got Logical Link State Indication\n");
2924 adapter->phys_link_state =
2925 crq->link_state_indication.phys_link_state;
2926 adapter->logical_link_state =
2927 crq->link_state_indication.logical_link_state;
2928 break;
2929 case CHANGE_MAC_ADDR_RSP:
2930 netdev_dbg(netdev, "Got MAC address change Response\n");
2931 handle_change_mac_rsp(crq, adapter);
2932 break;
2933 case ERROR_INDICATION:
2934 netdev_dbg(netdev, "Got Error Indication\n");
2935 handle_error_indication(crq, adapter);
2936 break;
2937 case REQUEST_ERROR_RSP:
2938 netdev_dbg(netdev, "Got Error Detail Response\n");
2939 handle_error_info_rsp(crq, adapter);
2940 break;
2941 case REQUEST_STATISTICS_RSP:
2942 netdev_dbg(netdev, "Got Statistics Response\n");
2943 complete(&adapter->stats_done);
2944 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002945 case QUERY_IP_OFFLOAD_RSP:
2946 netdev_dbg(netdev, "Got Query IP offload Response\n");
2947 handle_query_ip_offload_rsp(adapter);
2948 break;
2949 case MULTICAST_CTRL_RSP:
2950 netdev_dbg(netdev, "Got multicast control Response\n");
2951 break;
2952 case CONTROL_IP_OFFLOAD_RSP:
2953 netdev_dbg(netdev, "Got Control IP offload Response\n");
2954 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
2955 sizeof(adapter->ip_offload_ctrl),
2956 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05002957 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002958 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002959 case COLLECT_FW_TRACE_RSP:
2960 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
2961 complete(&adapter->fw_done);
2962 break;
2963 default:
2964 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
2965 gen_crq->cmd);
2966 }
2967}
2968
2969static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
2970{
2971 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06002972
Thomas Falcon6c267b32017-02-15 12:17:58 -06002973 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06002974 return IRQ_HANDLED;
2975}
2976
2977static void ibmvnic_tasklet(void *data)
2978{
2979 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002980 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002981 union ibmvnic_crq *crq;
2982 unsigned long flags;
2983 bool done = false;
2984
2985 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002986 while (!done) {
2987 /* Pull all the valid messages off the CRQ */
2988 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
2989 ibmvnic_handle_crq(crq, adapter);
2990 crq->generic.first = 0;
2991 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04002992
2993 /* remain in tasklet until all
2994 * capabilities responses are received
2995 */
2996 if (!adapter->wait_capability)
2997 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002998 }
Thomas Falcon249168a2017-02-15 12:18:00 -06002999 /* if capabilities CRQ's were sent in this tasklet, the following
3000 * tasklet must wait until all responses are received
3001 */
3002 if (atomic_read(&adapter->running_cap_crqs) != 0)
3003 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003004 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003005}
3006
3007static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
3008{
3009 struct vio_dev *vdev = adapter->vdev;
3010 int rc;
3011
3012 do {
3013 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
3014 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
3015
3016 if (rc)
3017 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
3018
3019 return rc;
3020}
3021
3022static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
3023{
3024 struct ibmvnic_crq_queue *crq = &adapter->crq;
3025 struct device *dev = &adapter->vdev->dev;
3026 struct vio_dev *vdev = adapter->vdev;
3027 int rc;
3028
3029 /* Close the CRQ */
3030 do {
3031 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3032 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3033
3034 /* Clean out the queue */
3035 memset(crq->msgs, 0, PAGE_SIZE);
3036 crq->cur = 0;
3037
3038 /* And re-open it again */
3039 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3040 crq->msg_token, PAGE_SIZE);
3041
3042 if (rc == H_CLOSED)
3043 /* Adapter is good, but other end is not ready */
3044 dev_warn(dev, "Partner adapter not ready\n");
3045 else if (rc != 0)
3046 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3047
3048 return rc;
3049}
3050
Nathan Fontenotf9928872017-03-30 02:48:54 -04003051static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003052{
3053 struct ibmvnic_crq_queue *crq = &adapter->crq;
3054 struct vio_dev *vdev = adapter->vdev;
3055 long rc;
3056
Nathan Fontenotf9928872017-03-30 02:48:54 -04003057 if (!crq->msgs)
3058 return;
3059
Thomas Falcon032c5e82015-12-21 11:26:06 -06003060 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3061 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003062 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003063 do {
3064 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3065 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3066
3067 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3068 DMA_BIDIRECTIONAL);
3069 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003070 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003071}
3072
Nathan Fontenotf9928872017-03-30 02:48:54 -04003073static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003074{
3075 struct ibmvnic_crq_queue *crq = &adapter->crq;
3076 struct device *dev = &adapter->vdev->dev;
3077 struct vio_dev *vdev = adapter->vdev;
3078 int rc, retrc = -ENOMEM;
3079
Nathan Fontenotf9928872017-03-30 02:48:54 -04003080 if (crq->msgs)
3081 return 0;
3082
Thomas Falcon032c5e82015-12-21 11:26:06 -06003083 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3084 /* Should we allocate more than one page? */
3085
3086 if (!crq->msgs)
3087 return -ENOMEM;
3088
3089 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3090 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3091 DMA_BIDIRECTIONAL);
3092 if (dma_mapping_error(dev, crq->msg_token))
3093 goto map_failed;
3094
3095 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3096 crq->msg_token, PAGE_SIZE);
3097
3098 if (rc == H_RESOURCE)
3099 /* maybe kexecing and resource is busy. try a reset */
3100 rc = ibmvnic_reset_crq(adapter);
3101 retrc = rc;
3102
3103 if (rc == H_CLOSED) {
3104 dev_warn(dev, "Partner adapter not ready\n");
3105 } else if (rc) {
3106 dev_warn(dev, "Error %d opening adapter\n", rc);
3107 goto reg_crq_failed;
3108 }
3109
3110 retrc = 0;
3111
Thomas Falcon6c267b32017-02-15 12:17:58 -06003112 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3113 (unsigned long)adapter);
3114
Thomas Falcon032c5e82015-12-21 11:26:06 -06003115 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3116 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3117 adapter);
3118 if (rc) {
3119 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3120 vdev->irq, rc);
3121 goto req_irq_failed;
3122 }
3123
3124 rc = vio_enable_interrupts(vdev);
3125 if (rc) {
3126 dev_err(dev, "Error %d enabling interrupts\n", rc);
3127 goto req_irq_failed;
3128 }
3129
3130 crq->cur = 0;
3131 spin_lock_init(&crq->lock);
3132
3133 return retrc;
3134
3135req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06003136 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003137 do {
3138 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3139 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3140reg_crq_failed:
3141 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3142map_failed:
3143 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003144 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003145 return retrc;
3146}
3147
Thomas Falcon65dc6892016-07-06 15:35:18 -05003148static void handle_crq_init_rsp(struct work_struct *work)
3149{
3150 struct ibmvnic_adapter *adapter = container_of(work,
3151 struct ibmvnic_adapter,
3152 vnic_crq_init);
3153 struct device *dev = &adapter->vdev->dev;
3154 struct net_device *netdev = adapter->netdev;
3155 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcondfad09a2016-08-18 11:37:51 -05003156 bool restart = false;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003157 int rc;
3158
Thomas Falcondfad09a2016-08-18 11:37:51 -05003159 if (adapter->failover) {
3160 release_sub_crqs(adapter);
3161 if (netif_running(netdev)) {
3162 netif_tx_disable(netdev);
3163 ibmvnic_close(netdev);
3164 restart = true;
3165 }
3166 }
3167
Thomas Falcon65dc6892016-07-06 15:35:18 -05003168 reinit_completion(&adapter->init_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05003169 send_version_xchg(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003170 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3171 dev_err(dev, "Passive init timeout\n");
3172 goto task_failed;
3173 }
3174
Thomas Falconf39f0d12017-02-14 10:22:59 -06003175 netdev->mtu = adapter->req_mtu - ETH_HLEN;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003176
Thomas Falcondfad09a2016-08-18 11:37:51 -05003177 if (adapter->failover) {
3178 adapter->failover = false;
3179 if (restart) {
3180 rc = ibmvnic_open(netdev);
3181 if (rc)
3182 goto restart_failed;
3183 }
3184 netif_carrier_on(netdev);
3185 return;
3186 }
3187
Thomas Falcon65dc6892016-07-06 15:35:18 -05003188 rc = register_netdev(netdev);
3189 if (rc) {
3190 dev_err(dev,
3191 "failed to register netdev rc=%d\n", rc);
3192 goto register_failed;
3193 }
3194 dev_info(dev, "ibmvnic registered\n");
3195
3196 return;
3197
Thomas Falcondfad09a2016-08-18 11:37:51 -05003198restart_failed:
3199 dev_err(dev, "Failed to restart ibmvnic, rc=%d\n", rc);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003200register_failed:
3201 release_sub_crqs(adapter);
3202task_failed:
3203 dev_err(dev, "Passive initialization was not successful\n");
3204}
3205
John Allenf6ef6402017-03-17 17:13:42 -05003206static int ibmvnic_init(struct ibmvnic_adapter *adapter)
3207{
3208 struct device *dev = &adapter->vdev->dev;
3209 unsigned long timeout = msecs_to_jiffies(30000);
John Allenf6ef6402017-03-17 17:13:42 -05003210 int rc;
3211
Nathan Fontenotf9928872017-03-30 02:48:54 -04003212 rc = init_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003213 if (rc) {
3214 dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
3215 return rc;
3216 }
3217
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003218 rc = init_stats_token(adapter);
3219 if (rc) {
Nathan Fontenotf9928872017-03-30 02:48:54 -04003220 release_crq_queue(adapter);
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003221 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05003222 }
3223
John Allenf6ef6402017-03-17 17:13:42 -05003224 init_completion(&adapter->init_done);
3225 ibmvnic_send_crq_init(adapter);
3226 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3227 dev_err(dev, "Initialization sequence timed out\n");
Nathan Fontenotf9928872017-03-30 02:48:54 -04003228 release_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003229 return -1;
3230 }
3231
3232 return 0;
3233}
3234
Thomas Falcon032c5e82015-12-21 11:26:06 -06003235static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3236{
3237 struct ibmvnic_adapter *adapter;
3238 struct net_device *netdev;
3239 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003240 int rc;
3241
3242 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3243 dev->unit_address);
3244
3245 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3246 VETH_MAC_ADDR, NULL);
3247 if (!mac_addr_p) {
3248 dev_err(&dev->dev,
3249 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3250 __FILE__, __LINE__);
3251 return 0;
3252 }
3253
3254 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3255 IBMVNIC_MAX_TX_QUEUES);
3256 if (!netdev)
3257 return -ENOMEM;
3258
3259 adapter = netdev_priv(netdev);
3260 dev_set_drvdata(&dev->dev, netdev);
3261 adapter->vdev = dev;
3262 adapter->netdev = netdev;
Thomas Falcondfad09a2016-08-18 11:37:51 -05003263 adapter->failover = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003264
3265 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3266 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3267 netdev->irq = dev->irq;
3268 netdev->netdev_ops = &ibmvnic_netdev_ops;
3269 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3270 SET_NETDEV_DEV(netdev, &dev->dev);
3271
Thomas Falcon65dc6892016-07-06 15:35:18 -05003272 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05003273 INIT_WORK(&adapter->ibmvnic_xport, ibmvnic_xport_event);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003274
Thomas Falcon032c5e82015-12-21 11:26:06 -06003275 spin_lock_init(&adapter->stats_lock);
3276
Thomas Falcon032c5e82015-12-21 11:26:06 -06003277 INIT_LIST_HEAD(&adapter->errors);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003278 spin_lock_init(&adapter->error_list_lock);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003279
John Allenf6ef6402017-03-17 17:13:42 -05003280 rc = ibmvnic_init(adapter);
3281 if (rc) {
3282 free_netdev(netdev);
3283 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003284 }
3285
Thomas Falconf39f0d12017-02-14 10:22:59 -06003286 netdev->mtu = adapter->req_mtu - ETH_HLEN;
John Allenea5509f2017-03-17 17:13:43 -05003287 adapter->is_closed = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003288
3289 rc = register_netdev(netdev);
3290 if (rc) {
3291 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
John Allenf6ef6402017-03-17 17:13:42 -05003292 free_netdev(netdev);
3293 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003294 }
3295 dev_info(&dev->dev, "ibmvnic registered\n");
3296
3297 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003298}
3299
3300static int ibmvnic_remove(struct vio_dev *dev)
3301{
3302 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003303
3304 unregister_netdev(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003305 free_netdev(netdev);
3306 dev_set_drvdata(&dev->dev, NULL);
3307
3308 return 0;
3309}
3310
3311static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3312{
3313 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3314 struct ibmvnic_adapter *adapter;
3315 struct iommu_table *tbl;
3316 unsigned long ret = 0;
3317 int i;
3318
3319 tbl = get_iommu_table_base(&vdev->dev);
3320
3321 /* netdev inits at probe time along with the structures we need below*/
3322 if (!netdev)
3323 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3324
3325 adapter = netdev_priv(netdev);
3326
3327 ret += PAGE_SIZE; /* the crq message queue */
3328 ret += adapter->bounce_buffer_size;
3329 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3330
3331 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3332 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3333
3334 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3335 i++)
3336 ret += adapter->rx_pool[i].size *
3337 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3338
3339 return ret;
3340}
3341
3342static int ibmvnic_resume(struct device *dev)
3343{
3344 struct net_device *netdev = dev_get_drvdata(dev);
3345 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3346 int i;
3347
3348 /* kick the interrupt handlers just in case we lost an interrupt */
3349 for (i = 0; i < adapter->req_rx_queues; i++)
3350 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3351 adapter->rx_scrq[i]);
3352
3353 return 0;
3354}
3355
3356static struct vio_device_id ibmvnic_device_table[] = {
3357 {"network", "IBM,vnic"},
3358 {"", "" }
3359};
3360MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3361
3362static const struct dev_pm_ops ibmvnic_pm_ops = {
3363 .resume = ibmvnic_resume
3364};
3365
3366static struct vio_driver ibmvnic_driver = {
3367 .id_table = ibmvnic_device_table,
3368 .probe = ibmvnic_probe,
3369 .remove = ibmvnic_remove,
3370 .get_desired_dma = ibmvnic_get_desired_dma,
3371 .name = ibmvnic_driver_name,
3372 .pm = &ibmvnic_pm_ops,
3373};
3374
3375/* module functions */
3376static int __init ibmvnic_module_init(void)
3377{
3378 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3379 IBMVNIC_DRIVER_VERSION);
3380
3381 return vio_register_driver(&ibmvnic_driver);
3382}
3383
3384static void __exit ibmvnic_module_exit(void)
3385{
3386 vio_unregister_driver(&ibmvnic_driver);
3387}
3388
3389module_init(ibmvnic_module_init);
3390module_exit(ibmvnic_module_exit);