blob: e8c72abfd7accec157f5aff74afd85a7f0f2ed7f [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 Fontenot661a2622017-04-19 13:44:58 -0400505static void release_error_buffers(struct ibmvnic_adapter *adapter)
506{
507 struct device *dev = &adapter->vdev->dev;
508 struct ibmvnic_error_buff *error_buff, *tmp;
509 unsigned long flags;
510
511 spin_lock_irqsave(&adapter->error_list_lock, flags);
512 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) {
513 list_del(&error_buff->list);
514 dma_unmap_single(dev, error_buff->dma, error_buff->len,
515 DMA_FROM_DEVICE);
516 kfree(error_buff->buff);
517 kfree(error_buff);
518 }
519 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
520}
521
John Allena57a5d22017-03-17 17:13:41 -0500522static int ibmvnic_login(struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600523{
524 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allenbd0b6722017-03-17 17:13:40 -0500525 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600526 struct device *dev = &adapter->vdev->dev;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600527
John Allenbd0b6722017-03-17 17:13:40 -0500528 do {
529 if (adapter->renegotiate) {
530 adapter->renegotiate = false;
Nathan Fontenotb5108882017-03-30 02:49:18 -0400531 release_sub_crqs(adapter);
John Allenbd0b6722017-03-17 17:13:40 -0500532
533 reinit_completion(&adapter->init_done);
534 send_cap_queries(adapter);
535 if (!wait_for_completion_timeout(&adapter->init_done,
536 timeout)) {
537 dev_err(dev, "Capabilities query timeout\n");
538 return -1;
539 }
540 }
541
542 reinit_completion(&adapter->init_done);
543 send_login(adapter);
544 if (!wait_for_completion_timeout(&adapter->init_done,
545 timeout)) {
546 dev_err(dev, "Login timeout\n");
547 return -1;
548 }
549 } while (adapter->renegotiate);
550
John Allena57a5d22017-03-17 17:13:41 -0500551 return 0;
552}
553
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400554static void release_resources(struct ibmvnic_adapter *adapter)
555{
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400556 release_tx_pools(adapter);
557 release_rx_pools(adapter);
558
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400559 release_stats_token(adapter);
Nathan Fontenot661a2622017-04-19 13:44:58 -0400560 release_error_buffers(adapter);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400561}
562
John Allena57a5d22017-03-17 17:13:41 -0500563static int ibmvnic_open(struct net_device *netdev)
564{
565 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
566 struct device *dev = &adapter->vdev->dev;
John Allena57a5d22017-03-17 17:13:41 -0500567 union ibmvnic_crq crq;
John Allena57a5d22017-03-17 17:13:41 -0500568 int rc = 0;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400569 int i;
John Allena57a5d22017-03-17 17:13:41 -0500570
John Allenea5509f2017-03-17 17:13:43 -0500571 if (adapter->is_closed) {
572 rc = ibmvnic_init(adapter);
573 if (rc)
574 return rc;
575 }
576
John Allena57a5d22017-03-17 17:13:41 -0500577 rc = ibmvnic_login(netdev);
578 if (rc)
579 return rc;
580
John Allenbd0b6722017-03-17 17:13:40 -0500581 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
582 if (rc) {
583 dev_err(dev, "failed to set the number of tx queues\n");
584 return -1;
585 }
586
587 rc = init_sub_crq_irqs(adapter);
588 if (rc) {
589 dev_err(dev, "failed to initialize sub crq irqs\n");
590 return -1;
591 }
592
Thomas Falcon032c5e82015-12-21 11:26:06 -0600593 adapter->map_id = 1;
594 adapter->napi = kcalloc(adapter->req_rx_queues,
595 sizeof(struct napi_struct), GFP_KERNEL);
596 if (!adapter->napi)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400597 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600598 for (i = 0; i < adapter->req_rx_queues; i++) {
599 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
600 NAPI_POLL_WEIGHT);
601 napi_enable(&adapter->napi[i]);
602 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600603
Thomas Falcon032c5e82015-12-21 11:26:06 -0600604 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400605
606 rc = init_rx_pools(netdev);
607 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400608 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600609
Nathan Fontenotc657e322017-03-30 02:49:06 -0400610 rc = init_tx_pools(netdev);
611 if (rc)
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400612 goto ibmvnic_open_fail;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600613
Thomas Falcon032c5e82015-12-21 11:26:06 -0600614 replenish_pools(adapter);
615
616 /* We're ready to receive frames, enable the sub-crq interrupts and
617 * set the logical link state to up
618 */
619 for (i = 0; i < adapter->req_rx_queues; i++)
620 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
621
622 for (i = 0; i < adapter->req_tx_queues; i++)
623 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
624
625 memset(&crq, 0, sizeof(crq));
626 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
627 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
628 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_UP;
629 ibmvnic_send_crq(adapter, &crq);
630
Thomas Falconb8efb892016-07-06 15:35:15 -0500631 netif_tx_start_all_queues(netdev);
John Allenea5509f2017-03-17 17:13:43 -0500632 adapter->is_closed = false;
Thomas Falconb8efb892016-07-06 15:35:15 -0500633
Thomas Falcon032c5e82015-12-21 11:26:06 -0600634 return 0;
635
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400636ibmvnic_open_fail:
Thomas Falcon032c5e82015-12-21 11:26:06 -0600637 for (i = 0; i < adapter->req_rx_queues; i++)
Nathan Fontenote722af62017-02-10 13:29:06 -0500638 napi_disable(&adapter->napi[i]);
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400639 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600640 return -ENOMEM;
641}
642
Brian Kingdd9c20f2017-04-19 13:45:10 -0400643static void disable_sub_crqs(struct ibmvnic_adapter *adapter)
644{
645 int i;
646
647 if (adapter->tx_scrq) {
648 for (i = 0; i < adapter->req_tx_queues; i++)
649 if (adapter->tx_scrq[i])
650 disable_irq(adapter->tx_scrq[i]->irq);
651 }
652
653 if (adapter->rx_scrq) {
654 for (i = 0; i < adapter->req_rx_queues; i++)
655 if (adapter->rx_scrq[i])
656 disable_irq(adapter->rx_scrq[i]->irq);
657 }
658}
659
John Allenea5509f2017-03-17 17:13:43 -0500660static int ibmvnic_close(struct net_device *netdev)
661{
662 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
663 union ibmvnic_crq crq;
664 int i;
665
666 adapter->closing = true;
Brian Kingdd9c20f2017-04-19 13:45:10 -0400667 disable_sub_crqs(adapter);
John Allenea5509f2017-03-17 17:13:43 -0500668
669 for (i = 0; i < adapter->req_rx_queues; i++)
670 napi_disable(&adapter->napi[i]);
671
672 if (!adapter->failover)
673 netif_tx_stop_all_queues(netdev);
674
Thomas Falcon032c5e82015-12-21 11:26:06 -0600675 memset(&crq, 0, sizeof(crq));
676 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
677 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
678 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_DN;
679 ibmvnic_send_crq(adapter, &crq);
680
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400681 release_resources(adapter);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600682
John Allenea5509f2017-03-17 17:13:43 -0500683 adapter->is_closed = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600684 adapter->closing = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600685 return 0;
686}
687
Thomas Falconad7775d2016-04-01 17:20:34 -0500688/**
689 * build_hdr_data - creates L2/L3/L4 header data buffer
690 * @hdr_field - bitfield determining needed headers
691 * @skb - socket buffer
692 * @hdr_len - array of header lengths
693 * @tot_len - total length of data
694 *
695 * Reads hdr_field to determine which headers are needed by firmware.
696 * Builds a buffer containing these headers. Saves individual header
697 * lengths and total buffer length to be used to build descriptors.
698 */
699static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
700 int *hdr_len, u8 *hdr_data)
701{
702 int len = 0;
703 u8 *hdr;
704
705 hdr_len[0] = sizeof(struct ethhdr);
706
707 if (skb->protocol == htons(ETH_P_IP)) {
708 hdr_len[1] = ip_hdr(skb)->ihl * 4;
709 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
710 hdr_len[2] = tcp_hdrlen(skb);
711 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
712 hdr_len[2] = sizeof(struct udphdr);
713 } else if (skb->protocol == htons(ETH_P_IPV6)) {
714 hdr_len[1] = sizeof(struct ipv6hdr);
715 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
716 hdr_len[2] = tcp_hdrlen(skb);
717 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
718 hdr_len[2] = sizeof(struct udphdr);
719 }
720
721 memset(hdr_data, 0, 120);
722 if ((hdr_field >> 6) & 1) {
723 hdr = skb_mac_header(skb);
724 memcpy(hdr_data, hdr, hdr_len[0]);
725 len += hdr_len[0];
726 }
727
728 if ((hdr_field >> 5) & 1) {
729 hdr = skb_network_header(skb);
730 memcpy(hdr_data + len, hdr, hdr_len[1]);
731 len += hdr_len[1];
732 }
733
734 if ((hdr_field >> 4) & 1) {
735 hdr = skb_transport_header(skb);
736 memcpy(hdr_data + len, hdr, hdr_len[2]);
737 len += hdr_len[2];
738 }
739 return len;
740}
741
742/**
743 * create_hdr_descs - create header and header extension descriptors
744 * @hdr_field - bitfield determining needed headers
745 * @data - buffer containing header data
746 * @len - length of data buffer
747 * @hdr_len - array of individual header lengths
748 * @scrq_arr - descriptor array
749 *
750 * Creates header and, if needed, header extension descriptors and
751 * places them in a descriptor array, scrq_arr
752 */
753
754static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
755 union sub_crq *scrq_arr)
756{
757 union sub_crq hdr_desc;
758 int tmp_len = len;
759 u8 *data, *cur;
760 int tmp;
761
762 while (tmp_len > 0) {
763 cur = hdr_data + len - tmp_len;
764
765 memset(&hdr_desc, 0, sizeof(hdr_desc));
766 if (cur != hdr_data) {
767 data = hdr_desc.hdr_ext.data;
768 tmp = tmp_len > 29 ? 29 : tmp_len;
769 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
770 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
771 hdr_desc.hdr_ext.len = tmp;
772 } else {
773 data = hdr_desc.hdr.data;
774 tmp = tmp_len > 24 ? 24 : tmp_len;
775 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
776 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
777 hdr_desc.hdr.len = tmp;
778 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
779 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
780 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
781 hdr_desc.hdr.flag = hdr_field << 1;
782 }
783 memcpy(data, cur, tmp);
784 tmp_len -= tmp;
785 *scrq_arr = hdr_desc;
786 scrq_arr++;
787 }
788}
789
790/**
791 * build_hdr_descs_arr - build a header descriptor array
792 * @skb - socket buffer
793 * @num_entries - number of descriptors to be sent
794 * @subcrq - first TX descriptor
795 * @hdr_field - bit field determining which headers will be sent
796 *
797 * This function will build a TX descriptor array with applicable
798 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
799 */
800
801static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
802 int *num_entries, u8 hdr_field)
803{
804 int hdr_len[3] = {0, 0, 0};
805 int tot_len, len;
806 u8 *hdr_data = txbuff->hdr_data;
807
808 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
809 txbuff->hdr_data);
810 len = tot_len;
811 len -= 24;
812 if (len > 0)
813 num_entries += len % 29 ? len / 29 + 1 : len / 29;
814 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
815 txbuff->indir_arr + 1);
816}
817
Thomas Falcon032c5e82015-12-21 11:26:06 -0600818static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
819{
820 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
821 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -0500822 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600823 struct device *dev = &adapter->vdev->dev;
824 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600825 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600826 struct ibmvnic_tx_pool *tx_pool;
827 unsigned int tx_send_failed = 0;
828 unsigned int tx_map_failed = 0;
829 unsigned int tx_dropped = 0;
830 unsigned int tx_packets = 0;
831 unsigned int tx_bytes = 0;
832 dma_addr_t data_dma_addr;
833 struct netdev_queue *txq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600834 unsigned long lpar_rc;
835 union sub_crq tx_crq;
836 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -0500837 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600838 unsigned char *dst;
839 u64 *handle_array;
840 int index = 0;
841 int ret = 0;
842
843 tx_pool = &adapter->tx_pool[queue_num];
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600844 tx_scrq = adapter->tx_scrq[queue_num];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600845 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
846 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
847 be32_to_cpu(adapter->login_rsp_buf->
848 off_txsubm_subcrqs));
849 if (adapter->migrated) {
850 tx_send_failed++;
851 tx_dropped++;
852 ret = NETDEV_TX_BUSY;
853 goto out;
854 }
855
856 index = tx_pool->free_map[tx_pool->consumer_index];
857 offset = index * adapter->req_mtu;
858 dst = tx_pool->long_term_buff.buff + offset;
859 memset(dst, 0, adapter->req_mtu);
860 skb_copy_from_linear_data(skb, dst, skb->len);
861 data_dma_addr = tx_pool->long_term_buff.addr + offset;
862
863 tx_pool->consumer_index =
864 (tx_pool->consumer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -0600865 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600866
867 tx_buff = &tx_pool->tx_buff[index];
868 tx_buff->skb = skb;
869 tx_buff->data_dma[0] = data_dma_addr;
870 tx_buff->data_len[0] = skb->len;
871 tx_buff->index = index;
872 tx_buff->pool_index = queue_num;
873 tx_buff->last_frag = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600874
875 memset(&tx_crq, 0, sizeof(tx_crq));
876 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
877 tx_crq.v1.type = IBMVNIC_TX_DESC;
878 tx_crq.v1.n_crq_elem = 1;
879 tx_crq.v1.n_sge = 1;
880 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
881 tx_crq.v1.correlator = cpu_to_be32(index);
882 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
883 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
884 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
885
886 if (adapter->vlan_header_insertion) {
887 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
888 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
889 }
890
891 if (skb->protocol == htons(ETH_P_IP)) {
892 if (ip_hdr(skb)->version == 4)
893 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
894 else if (ip_hdr(skb)->version == 6)
895 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
896
897 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
898 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
899 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
900 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
901 }
902
Thomas Falconad7775d2016-04-01 17:20:34 -0500903 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -0600904 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -0500905 hdrs += 2;
906 }
907 /* determine if l2/3/4 headers are sent to firmware */
908 if ((*hdrs >> 7) & 1 &&
909 (skb->protocol == htons(ETH_P_IP) ||
910 skb->protocol == htons(ETH_P_IPV6))) {
911 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
912 tx_crq.v1.n_crq_elem = num_entries;
913 tx_buff->indir_arr[0] = tx_crq;
914 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
915 sizeof(tx_buff->indir_arr),
916 DMA_TO_DEVICE);
917 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
918 if (!firmware_has_feature(FW_FEATURE_CMO))
919 dev_err(dev, "tx: unable to map descriptor array\n");
920 tx_map_failed++;
921 tx_dropped++;
922 ret = NETDEV_TX_BUSY;
923 goto out;
924 }
John Allen498cd8e2016-04-06 11:49:55 -0500925 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -0500926 (u64)tx_buff->indir_dma,
927 (u64)num_entries);
928 } else {
John Allen498cd8e2016-04-06 11:49:55 -0500929 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
930 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -0500931 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600932 if (lpar_rc != H_SUCCESS) {
933 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
934
935 if (tx_pool->consumer_index == 0)
936 tx_pool->consumer_index =
Thomas Falcon068d9f92017-03-05 12:18:42 -0600937 adapter->req_tx_entries_per_subcrq - 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600938 else
939 tx_pool->consumer_index--;
940
941 tx_send_failed++;
942 tx_dropped++;
943 ret = NETDEV_TX_BUSY;
944 goto out;
945 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600946
Brian King58c8c0c2017-04-19 13:44:47 -0400947 if (atomic_inc_return(&tx_scrq->used)
948 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600949 netdev_info(netdev, "Stopping queue %d\n", queue_num);
950 netif_stop_subqueue(netdev, queue_num);
951 }
952
Thomas Falcon032c5e82015-12-21 11:26:06 -0600953 tx_packets++;
954 tx_bytes += skb->len;
955 txq->trans_start = jiffies;
956 ret = NETDEV_TX_OK;
957
958out:
959 netdev->stats.tx_dropped += tx_dropped;
960 netdev->stats.tx_bytes += tx_bytes;
961 netdev->stats.tx_packets += tx_packets;
962 adapter->tx_send_failed += tx_send_failed;
963 adapter->tx_map_failed += tx_map_failed;
964
965 return ret;
966}
967
968static void ibmvnic_set_multi(struct net_device *netdev)
969{
970 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
971 struct netdev_hw_addr *ha;
972 union ibmvnic_crq crq;
973
974 memset(&crq, 0, sizeof(crq));
975 crq.request_capability.first = IBMVNIC_CRQ_CMD;
976 crq.request_capability.cmd = REQUEST_CAPABILITY;
977
978 if (netdev->flags & IFF_PROMISC) {
979 if (!adapter->promisc_supported)
980 return;
981 } else {
982 if (netdev->flags & IFF_ALLMULTI) {
983 /* Accept all multicast */
984 memset(&crq, 0, sizeof(crq));
985 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
986 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
987 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
988 ibmvnic_send_crq(adapter, &crq);
989 } else if (netdev_mc_empty(netdev)) {
990 /* Reject all multicast */
991 memset(&crq, 0, sizeof(crq));
992 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
993 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
994 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
995 ibmvnic_send_crq(adapter, &crq);
996 } else {
997 /* Accept one or more multicast(s) */
998 netdev_for_each_mc_addr(ha, netdev) {
999 memset(&crq, 0, sizeof(crq));
1000 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1001 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1002 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1003 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1004 ha->addr);
1005 ibmvnic_send_crq(adapter, &crq);
1006 }
1007 }
1008 }
1009}
1010
1011static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1012{
1013 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1014 struct sockaddr *addr = p;
1015 union ibmvnic_crq crq;
1016
1017 if (!is_valid_ether_addr(addr->sa_data))
1018 return -EADDRNOTAVAIL;
1019
1020 memset(&crq, 0, sizeof(crq));
1021 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1022 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1023 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1024 ibmvnic_send_crq(adapter, &crq);
1025 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1026 return 0;
1027}
1028
Thomas Falcon032c5e82015-12-21 11:26:06 -06001029static void ibmvnic_tx_timeout(struct net_device *dev)
1030{
1031 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1032 int rc;
1033
1034 /* Adapter timed out, resetting it */
1035 release_sub_crqs(adapter);
1036 rc = ibmvnic_reset_crq(adapter);
1037 if (rc)
1038 dev_err(&adapter->vdev->dev, "Adapter timeout, reset failed\n");
1039 else
1040 ibmvnic_send_crq_init(adapter);
1041}
1042
1043static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
1044 struct ibmvnic_rx_buff *rx_buff)
1045{
1046 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
1047
1048 rx_buff->skb = NULL;
1049
1050 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
1051 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
1052
1053 atomic_dec(&pool->available);
1054}
1055
1056static int ibmvnic_poll(struct napi_struct *napi, int budget)
1057{
1058 struct net_device *netdev = napi->dev;
1059 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1060 int scrq_num = (int)(napi - adapter->napi);
1061 int frames_processed = 0;
1062restart_poll:
1063 while (frames_processed < budget) {
1064 struct sk_buff *skb;
1065 struct ibmvnic_rx_buff *rx_buff;
1066 union sub_crq *next;
1067 u32 length;
1068 u16 offset;
1069 u8 flags = 0;
1070
1071 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
1072 break;
1073 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
1074 rx_buff =
1075 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
1076 rx_comp.correlator);
1077 /* do error checking */
1078 if (next->rx_comp.rc) {
1079 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
1080 /* free the entry */
1081 next->rx_comp.first = 0;
1082 remove_buff_from_pool(adapter, rx_buff);
1083 break;
1084 }
1085
1086 length = be32_to_cpu(next->rx_comp.len);
1087 offset = be16_to_cpu(next->rx_comp.off_frame_data);
1088 flags = next->rx_comp.flags;
1089 skb = rx_buff->skb;
1090 skb_copy_to_linear_data(skb, rx_buff->data + offset,
1091 length);
1092 skb->vlan_tci = be16_to_cpu(next->rx_comp.vlan_tci);
1093 /* free the entry */
1094 next->rx_comp.first = 0;
1095 remove_buff_from_pool(adapter, rx_buff);
1096
1097 skb_put(skb, length);
1098 skb->protocol = eth_type_trans(skb, netdev);
1099
1100 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
1101 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
1102 skb->ip_summed = CHECKSUM_UNNECESSARY;
1103 }
1104
1105 length = skb->len;
1106 napi_gro_receive(napi, skb); /* send it up */
1107 netdev->stats.rx_packets++;
1108 netdev->stats.rx_bytes += length;
1109 frames_processed++;
1110 }
John Allen498cd8e2016-04-06 11:49:55 -05001111 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001112
1113 if (frames_processed < budget) {
1114 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08001115 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001116 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1117 napi_reschedule(napi)) {
1118 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1119 goto restart_poll;
1120 }
1121 }
1122 return frames_processed;
1123}
1124
1125#ifdef CONFIG_NET_POLL_CONTROLLER
1126static void ibmvnic_netpoll_controller(struct net_device *dev)
1127{
1128 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1129 int i;
1130
1131 replenish_pools(netdev_priv(dev));
1132 for (i = 0; i < adapter->req_rx_queues; i++)
1133 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1134 adapter->rx_scrq[i]);
1135}
1136#endif
1137
1138static const struct net_device_ops ibmvnic_netdev_ops = {
1139 .ndo_open = ibmvnic_open,
1140 .ndo_stop = ibmvnic_close,
1141 .ndo_start_xmit = ibmvnic_xmit,
1142 .ndo_set_rx_mode = ibmvnic_set_multi,
1143 .ndo_set_mac_address = ibmvnic_set_mac,
1144 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001145 .ndo_tx_timeout = ibmvnic_tx_timeout,
1146#ifdef CONFIG_NET_POLL_CONTROLLER
1147 .ndo_poll_controller = ibmvnic_netpoll_controller,
1148#endif
1149};
1150
1151/* ethtool functions */
1152
Philippe Reynes8a433792017-01-07 22:37:29 +01001153static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1154 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001155{
Philippe Reynes8a433792017-01-07 22:37:29 +01001156 u32 supported, advertising;
1157
1158 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001159 SUPPORTED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001160 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001161 ADVERTISED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001162 cmd->base.speed = SPEED_1000;
1163 cmd->base.duplex = DUPLEX_FULL;
1164 cmd->base.port = PORT_FIBRE;
1165 cmd->base.phy_address = 0;
1166 cmd->base.autoneg = AUTONEG_ENABLE;
1167
1168 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1169 supported);
1170 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1171 advertising);
1172
Thomas Falcon032c5e82015-12-21 11:26:06 -06001173 return 0;
1174}
1175
1176static void ibmvnic_get_drvinfo(struct net_device *dev,
1177 struct ethtool_drvinfo *info)
1178{
1179 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1180 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1181}
1182
1183static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1184{
1185 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1186
1187 return adapter->msg_enable;
1188}
1189
1190static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1191{
1192 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1193
1194 adapter->msg_enable = data;
1195}
1196
1197static u32 ibmvnic_get_link(struct net_device *netdev)
1198{
1199 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1200
1201 /* Don't need to send a query because we request a logical link up at
1202 * init and then we wait for link state indications
1203 */
1204 return adapter->logical_link_state;
1205}
1206
1207static void ibmvnic_get_ringparam(struct net_device *netdev,
1208 struct ethtool_ringparam *ring)
1209{
1210 ring->rx_max_pending = 0;
1211 ring->tx_max_pending = 0;
1212 ring->rx_mini_max_pending = 0;
1213 ring->rx_jumbo_max_pending = 0;
1214 ring->rx_pending = 0;
1215 ring->tx_pending = 0;
1216 ring->rx_mini_pending = 0;
1217 ring->rx_jumbo_pending = 0;
1218}
1219
1220static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1221{
1222 int i;
1223
1224 if (stringset != ETH_SS_STATS)
1225 return;
1226
1227 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1228 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1229}
1230
1231static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1232{
1233 switch (sset) {
1234 case ETH_SS_STATS:
1235 return ARRAY_SIZE(ibmvnic_stats);
1236 default:
1237 return -EOPNOTSUPP;
1238 }
1239}
1240
1241static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1242 struct ethtool_stats *stats, u64 *data)
1243{
1244 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1245 union ibmvnic_crq crq;
1246 int i;
1247
1248 memset(&crq, 0, sizeof(crq));
1249 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1250 crq.request_statistics.cmd = REQUEST_STATISTICS;
1251 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1252 crq.request_statistics.len =
1253 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06001254
1255 /* Wait for data to be written */
1256 init_completion(&adapter->stats_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05001257 ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001258 wait_for_completion(&adapter->stats_done);
1259
1260 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1261 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1262}
1263
1264static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001265 .get_drvinfo = ibmvnic_get_drvinfo,
1266 .get_msglevel = ibmvnic_get_msglevel,
1267 .set_msglevel = ibmvnic_set_msglevel,
1268 .get_link = ibmvnic_get_link,
1269 .get_ringparam = ibmvnic_get_ringparam,
1270 .get_strings = ibmvnic_get_strings,
1271 .get_sset_count = ibmvnic_get_sset_count,
1272 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01001273 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001274};
1275
1276/* Routines for managing CRQs/sCRQs */
1277
1278static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1279 struct ibmvnic_sub_crq_queue *scrq)
1280{
1281 struct device *dev = &adapter->vdev->dev;
1282 long rc;
1283
1284 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1285
1286 /* Close the sub-crqs */
1287 do {
1288 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1289 adapter->vdev->unit_address,
1290 scrq->crq_num);
1291 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1292
Thomas Falconffa73852017-04-19 13:44:29 -04001293 if (rc) {
1294 netdev_err(adapter->netdev,
1295 "Failed to release sub-CRQ %16lx, rc = %ld\n",
1296 scrq->crq_num, rc);
1297 }
1298
Thomas Falcon032c5e82015-12-21 11:26:06 -06001299 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1300 DMA_BIDIRECTIONAL);
1301 free_pages((unsigned long)scrq->msgs, 2);
1302 kfree(scrq);
1303}
1304
1305static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1306 *adapter)
1307{
1308 struct device *dev = &adapter->vdev->dev;
1309 struct ibmvnic_sub_crq_queue *scrq;
1310 int rc;
1311
Nathan Fontenot7f7adc52017-04-19 13:45:16 -04001312 scrq = kzalloc(sizeof(*scrq), GFP_ATOMIC);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001313 if (!scrq)
1314 return NULL;
1315
Nathan Fontenot7f7adc52017-04-19 13:45:16 -04001316 scrq->msgs =
1317 (union sub_crq *)__get_free_pages(GFP_ATOMIC | __GFP_ZERO, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001318 if (!scrq->msgs) {
1319 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1320 goto zero_page_failed;
1321 }
1322
1323 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1324 DMA_BIDIRECTIONAL);
1325 if (dma_mapping_error(dev, scrq->msg_token)) {
1326 dev_warn(dev, "Couldn't map crq queue messages page\n");
1327 goto map_failed;
1328 }
1329
1330 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1331 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1332
1333 if (rc == H_RESOURCE)
1334 rc = ibmvnic_reset_crq(adapter);
1335
1336 if (rc == H_CLOSED) {
1337 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1338 } else if (rc) {
1339 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1340 goto reg_failed;
1341 }
1342
Thomas Falcon032c5e82015-12-21 11:26:06 -06001343 scrq->adapter = adapter;
1344 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001345 spin_lock_init(&scrq->lock);
1346
1347 netdev_dbg(adapter->netdev,
1348 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1349 scrq->crq_num, scrq->hw_irq, scrq->irq);
1350
1351 return scrq;
1352
Thomas Falcon032c5e82015-12-21 11:26:06 -06001353reg_failed:
1354 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1355 DMA_BIDIRECTIONAL);
1356map_failed:
1357 free_pages((unsigned long)scrq->msgs, 2);
1358zero_page_failed:
1359 kfree(scrq);
1360
1361 return NULL;
1362}
1363
1364static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1365{
1366 int i;
1367
1368 if (adapter->tx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001369 for (i = 0; i < adapter->req_tx_queues; i++) {
1370 if (!adapter->tx_scrq[i])
1371 continue;
1372
1373 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001374 free_irq(adapter->tx_scrq[i]->irq,
1375 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001376 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001377 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001378 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001379
1380 release_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1381 }
1382
Nathan Fontenot9501df32017-03-15 23:38:07 -04001383 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001384 adapter->tx_scrq = NULL;
1385 }
1386
1387 if (adapter->rx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001388 for (i = 0; i < adapter->req_rx_queues; i++) {
1389 if (!adapter->rx_scrq[i])
1390 continue;
1391
1392 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001393 free_irq(adapter->rx_scrq[i]->irq,
1394 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001395 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001396 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001397 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001398
1399 release_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1400 }
1401
Nathan Fontenot9501df32017-03-15 23:38:07 -04001402 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001403 adapter->rx_scrq = NULL;
1404 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001405}
1406
1407static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1408 struct ibmvnic_sub_crq_queue *scrq)
1409{
1410 struct device *dev = &adapter->vdev->dev;
1411 unsigned long rc;
1412
1413 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1414 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1415 if (rc)
1416 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1417 scrq->hw_irq, rc);
1418 return rc;
1419}
1420
1421static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1422 struct ibmvnic_sub_crq_queue *scrq)
1423{
1424 struct device *dev = &adapter->vdev->dev;
1425 unsigned long rc;
1426
1427 if (scrq->hw_irq > 0x100000000ULL) {
1428 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1429 return 1;
1430 }
1431
1432 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1433 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1434 if (rc)
1435 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1436 scrq->hw_irq, rc);
1437 return rc;
1438}
1439
1440static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1441 struct ibmvnic_sub_crq_queue *scrq)
1442{
1443 struct device *dev = &adapter->vdev->dev;
1444 struct ibmvnic_tx_buff *txbuff;
1445 union sub_crq *next;
1446 int index;
1447 int i, j;
Thomas Falconad7775d2016-04-01 17:20:34 -05001448 u8 first;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001449
1450restart_loop:
1451 while (pending_scrq(adapter, scrq)) {
1452 unsigned int pool = scrq->pool_index;
1453
1454 next = ibmvnic_next_scrq(adapter, scrq);
1455 for (i = 0; i < next->tx_comp.num_comps; i++) {
1456 if (next->tx_comp.rcs[i]) {
1457 dev_err(dev, "tx error %x\n",
1458 next->tx_comp.rcs[i]);
1459 continue;
1460 }
1461 index = be32_to_cpu(next->tx_comp.correlators[i]);
1462 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1463
1464 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1465 if (!txbuff->data_dma[j])
1466 continue;
1467
1468 txbuff->data_dma[j] = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001469 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001470 /* if sub_crq was sent indirectly */
1471 first = txbuff->indir_arr[0].generic.first;
1472 if (first == IBMVNIC_CRQ_CMD) {
1473 dma_unmap_single(dev, txbuff->indir_dma,
1474 sizeof(txbuff->indir_arr),
1475 DMA_TO_DEVICE);
1476 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001477
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001478 if (txbuff->last_frag) {
Brian King58c8c0c2017-04-19 13:44:47 -04001479 if (atomic_sub_return(next->tx_comp.num_comps,
1480 &scrq->used) <=
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001481 (adapter->req_tx_entries_per_subcrq / 2) &&
1482 netif_subqueue_stopped(adapter->netdev,
1483 txbuff->skb)) {
1484 netif_wake_subqueue(adapter->netdev,
1485 scrq->pool_index);
1486 netdev_dbg(adapter->netdev,
1487 "Started queue %d\n",
1488 scrq->pool_index);
1489 }
1490
Thomas Falcon032c5e82015-12-21 11:26:06 -06001491 dev_kfree_skb_any(txbuff->skb);
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001492 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001493
1494 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1495 producer_index] = index;
1496 adapter->tx_pool[pool].producer_index =
1497 (adapter->tx_pool[pool].producer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001498 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001499 }
1500 /* remove tx_comp scrq*/
1501 next->tx_comp.first = 0;
1502 }
1503
1504 enable_scrq_irq(adapter, scrq);
1505
1506 if (pending_scrq(adapter, scrq)) {
1507 disable_scrq_irq(adapter, scrq);
1508 goto restart_loop;
1509 }
1510
1511 return 0;
1512}
1513
1514static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
1515{
1516 struct ibmvnic_sub_crq_queue *scrq = instance;
1517 struct ibmvnic_adapter *adapter = scrq->adapter;
1518
1519 disable_scrq_irq(adapter, scrq);
1520 ibmvnic_complete_tx(adapter, scrq);
1521
1522 return IRQ_HANDLED;
1523}
1524
1525static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
1526{
1527 struct ibmvnic_sub_crq_queue *scrq = instance;
1528 struct ibmvnic_adapter *adapter = scrq->adapter;
1529
1530 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
1531 disable_scrq_irq(adapter, scrq);
1532 __napi_schedule(&adapter->napi[scrq->scrq_num]);
1533 }
1534
1535 return IRQ_HANDLED;
1536}
1537
Thomas Falconea22d512016-07-06 15:35:17 -05001538static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
1539{
1540 struct device *dev = &adapter->vdev->dev;
1541 struct ibmvnic_sub_crq_queue *scrq;
1542 int i = 0, j = 0;
1543 int rc = 0;
1544
1545 for (i = 0; i < adapter->req_tx_queues; i++) {
1546 scrq = adapter->tx_scrq[i];
1547 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
1548
Michael Ellerman99c17902016-09-10 19:59:05 +10001549 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001550 rc = -EINVAL;
1551 dev_err(dev, "Error mapping irq\n");
1552 goto req_tx_irq_failed;
1553 }
1554
1555 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
1556 0, "ibmvnic_tx", scrq);
1557
1558 if (rc) {
1559 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
1560 scrq->irq, rc);
1561 irq_dispose_mapping(scrq->irq);
1562 goto req_rx_irq_failed;
1563 }
1564 }
1565
1566 for (i = 0; i < adapter->req_rx_queues; i++) {
1567 scrq = adapter->rx_scrq[i];
1568 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10001569 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05001570 rc = -EINVAL;
1571 dev_err(dev, "Error mapping irq\n");
1572 goto req_rx_irq_failed;
1573 }
1574 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
1575 0, "ibmvnic_rx", scrq);
1576 if (rc) {
1577 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
1578 scrq->irq, rc);
1579 irq_dispose_mapping(scrq->irq);
1580 goto req_rx_irq_failed;
1581 }
1582 }
1583 return rc;
1584
1585req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001586 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001587 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
1588 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001589 }
Thomas Falconea22d512016-07-06 15:35:17 -05001590 i = adapter->req_tx_queues;
1591req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001592 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05001593 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
1594 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05001595 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001596 release_sub_crqs(adapter);
Thomas Falconea22d512016-07-06 15:35:17 -05001597 return rc;
1598}
1599
Thomas Falcon032c5e82015-12-21 11:26:06 -06001600static void init_sub_crqs(struct ibmvnic_adapter *adapter, int retry)
1601{
1602 struct device *dev = &adapter->vdev->dev;
1603 struct ibmvnic_sub_crq_queue **allqueues;
1604 int registered_queues = 0;
1605 union ibmvnic_crq crq;
1606 int total_queues;
1607 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05001608 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001609
1610 if (!retry) {
1611 /* Sub-CRQ entries are 32 byte long */
1612 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
1613
1614 if (adapter->min_tx_entries_per_subcrq > entries_page ||
1615 adapter->min_rx_add_entries_per_subcrq > entries_page) {
1616 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
1617 goto allqueues_failed;
1618 }
1619
1620 /* Get the minimum between the queried max and the entries
1621 * that fit in our PAGE_SIZE
1622 */
1623 adapter->req_tx_entries_per_subcrq =
1624 adapter->max_tx_entries_per_subcrq > entries_page ?
1625 entries_page : adapter->max_tx_entries_per_subcrq;
1626 adapter->req_rx_add_entries_per_subcrq =
1627 adapter->max_rx_add_entries_per_subcrq > entries_page ?
1628 entries_page : adapter->max_rx_add_entries_per_subcrq;
1629
John Allen6dbcd8f2016-11-07 14:27:28 -06001630 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
1631 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
John Allen498cd8e2016-04-06 11:49:55 -05001632 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001633
Thomas Falconf39f0d12017-02-14 10:22:59 -06001634 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001635 }
1636
1637 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
1638
1639 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_ATOMIC);
1640 if (!allqueues)
1641 goto allqueues_failed;
1642
1643 for (i = 0; i < total_queues; i++) {
1644 allqueues[i] = init_sub_crq_queue(adapter);
1645 if (!allqueues[i]) {
1646 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
1647 break;
1648 }
1649 registered_queues++;
1650 }
1651
1652 /* Make sure we were able to register the minimum number of queues */
1653 if (registered_queues <
1654 adapter->min_tx_queues + adapter->min_rx_queues) {
1655 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
1656 goto tx_failed;
1657 }
1658
1659 /* Distribute the failed allocated queues*/
1660 for (i = 0; i < total_queues - registered_queues + more ; i++) {
1661 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
1662 switch (i % 3) {
1663 case 0:
1664 if (adapter->req_rx_queues > adapter->min_rx_queues)
1665 adapter->req_rx_queues--;
1666 else
1667 more++;
1668 break;
1669 case 1:
1670 if (adapter->req_tx_queues > adapter->min_tx_queues)
1671 adapter->req_tx_queues--;
1672 else
1673 more++;
1674 break;
1675 }
1676 }
1677
1678 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
1679 sizeof(*adapter->tx_scrq), GFP_ATOMIC);
1680 if (!adapter->tx_scrq)
1681 goto tx_failed;
1682
1683 for (i = 0; i < adapter->req_tx_queues; i++) {
1684 adapter->tx_scrq[i] = allqueues[i];
1685 adapter->tx_scrq[i]->pool_index = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001686 }
1687
1688 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
1689 sizeof(*adapter->rx_scrq), GFP_ATOMIC);
1690 if (!adapter->rx_scrq)
1691 goto rx_failed;
1692
1693 for (i = 0; i < adapter->req_rx_queues; i++) {
1694 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
1695 adapter->rx_scrq[i]->scrq_num = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001696 }
1697
1698 memset(&crq, 0, sizeof(crq));
1699 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1700 crq.request_capability.cmd = REQUEST_CAPABILITY;
1701
1702 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001703 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001704 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001705 ibmvnic_send_crq(adapter, &crq);
1706
1707 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001708 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001709 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001710 ibmvnic_send_crq(adapter, &crq);
1711
1712 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06001713 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06001714 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001715 ibmvnic_send_crq(adapter, &crq);
1716
1717 crq.request_capability.capability =
1718 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
1719 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001720 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001721 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001722 ibmvnic_send_crq(adapter, &crq);
1723
1724 crq.request_capability.capability =
1725 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
1726 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06001727 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06001728 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001729 ibmvnic_send_crq(adapter, &crq);
1730
1731 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06001732 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06001733 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001734 ibmvnic_send_crq(adapter, &crq);
1735
1736 if (adapter->netdev->flags & IFF_PROMISC) {
1737 if (adapter->promisc_supported) {
1738 crq.request_capability.capability =
1739 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001740 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06001741 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001742 ibmvnic_send_crq(adapter, &crq);
1743 }
1744 } else {
1745 crq.request_capability.capability =
1746 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06001747 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06001748 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001749 ibmvnic_send_crq(adapter, &crq);
1750 }
1751
1752 kfree(allqueues);
1753
1754 return;
1755
Thomas Falcon032c5e82015-12-21 11:26:06 -06001756rx_failed:
1757 kfree(adapter->tx_scrq);
1758 adapter->tx_scrq = NULL;
1759tx_failed:
1760 for (i = 0; i < registered_queues; i++)
1761 release_sub_crq_queue(adapter, allqueues[i]);
1762 kfree(allqueues);
1763allqueues_failed:
1764 ibmvnic_remove(adapter->vdev);
1765}
1766
1767static int pending_scrq(struct ibmvnic_adapter *adapter,
1768 struct ibmvnic_sub_crq_queue *scrq)
1769{
1770 union sub_crq *entry = &scrq->msgs[scrq->cur];
1771
1772 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP || adapter->closing)
1773 return 1;
1774 else
1775 return 0;
1776}
1777
1778static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
1779 struct ibmvnic_sub_crq_queue *scrq)
1780{
1781 union sub_crq *entry;
1782 unsigned long flags;
1783
1784 spin_lock_irqsave(&scrq->lock, flags);
1785 entry = &scrq->msgs[scrq->cur];
1786 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1787 if (++scrq->cur == scrq->size)
1788 scrq->cur = 0;
1789 } else {
1790 entry = NULL;
1791 }
1792 spin_unlock_irqrestore(&scrq->lock, flags);
1793
1794 return entry;
1795}
1796
1797static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
1798{
1799 struct ibmvnic_crq_queue *queue = &adapter->crq;
1800 union ibmvnic_crq *crq;
1801
1802 crq = &queue->msgs[queue->cur];
1803 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1804 if (++queue->cur == queue->size)
1805 queue->cur = 0;
1806 } else {
1807 crq = NULL;
1808 }
1809
1810 return crq;
1811}
1812
1813static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
1814 union sub_crq *sub_crq)
1815{
1816 unsigned int ua = adapter->vdev->unit_address;
1817 struct device *dev = &adapter->vdev->dev;
1818 u64 *u64_crq = (u64 *)sub_crq;
1819 int rc;
1820
1821 netdev_dbg(adapter->netdev,
1822 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
1823 (unsigned long int)cpu_to_be64(remote_handle),
1824 (unsigned long int)cpu_to_be64(u64_crq[0]),
1825 (unsigned long int)cpu_to_be64(u64_crq[1]),
1826 (unsigned long int)cpu_to_be64(u64_crq[2]),
1827 (unsigned long int)cpu_to_be64(u64_crq[3]));
1828
1829 /* Make sure the hypervisor sees the complete request */
1830 mb();
1831
1832 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
1833 cpu_to_be64(remote_handle),
1834 cpu_to_be64(u64_crq[0]),
1835 cpu_to_be64(u64_crq[1]),
1836 cpu_to_be64(u64_crq[2]),
1837 cpu_to_be64(u64_crq[3]));
1838
1839 if (rc) {
1840 if (rc == H_CLOSED)
1841 dev_warn(dev, "CRQ Queue closed\n");
1842 dev_err(dev, "Send error (rc=%d)\n", rc);
1843 }
1844
1845 return rc;
1846}
1847
Thomas Falconad7775d2016-04-01 17:20:34 -05001848static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
1849 u64 remote_handle, u64 ioba, u64 num_entries)
1850{
1851 unsigned int ua = adapter->vdev->unit_address;
1852 struct device *dev = &adapter->vdev->dev;
1853 int rc;
1854
1855 /* Make sure the hypervisor sees the complete request */
1856 mb();
1857 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
1858 cpu_to_be64(remote_handle),
1859 ioba, num_entries);
1860
1861 if (rc) {
1862 if (rc == H_CLOSED)
1863 dev_warn(dev, "CRQ Queue closed\n");
1864 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
1865 }
1866
1867 return rc;
1868}
1869
Thomas Falcon032c5e82015-12-21 11:26:06 -06001870static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
1871 union ibmvnic_crq *crq)
1872{
1873 unsigned int ua = adapter->vdev->unit_address;
1874 struct device *dev = &adapter->vdev->dev;
1875 u64 *u64_crq = (u64 *)crq;
1876 int rc;
1877
1878 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
1879 (unsigned long int)cpu_to_be64(u64_crq[0]),
1880 (unsigned long int)cpu_to_be64(u64_crq[1]));
1881
1882 /* Make sure the hypervisor sees the complete request */
1883 mb();
1884
1885 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
1886 cpu_to_be64(u64_crq[0]),
1887 cpu_to_be64(u64_crq[1]));
1888
1889 if (rc) {
1890 if (rc == H_CLOSED)
1891 dev_warn(dev, "CRQ Queue closed\n");
1892 dev_warn(dev, "Send error (rc=%d)\n", rc);
1893 }
1894
1895 return rc;
1896}
1897
1898static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
1899{
1900 union ibmvnic_crq crq;
1901
1902 memset(&crq, 0, sizeof(crq));
1903 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1904 crq.generic.cmd = IBMVNIC_CRQ_INIT;
1905 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
1906
1907 return ibmvnic_send_crq(adapter, &crq);
1908}
1909
1910static int ibmvnic_send_crq_init_complete(struct ibmvnic_adapter *adapter)
1911{
1912 union ibmvnic_crq crq;
1913
1914 memset(&crq, 0, sizeof(crq));
1915 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1916 crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE;
1917 netdev_dbg(adapter->netdev, "Sending CRQ init complete\n");
1918
1919 return ibmvnic_send_crq(adapter, &crq);
1920}
1921
1922static int send_version_xchg(struct ibmvnic_adapter *adapter)
1923{
1924 union ibmvnic_crq crq;
1925
1926 memset(&crq, 0, sizeof(crq));
1927 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
1928 crq.version_exchange.cmd = VERSION_EXCHANGE;
1929 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
1930
1931 return ibmvnic_send_crq(adapter, &crq);
1932}
1933
1934static void send_login(struct ibmvnic_adapter *adapter)
1935{
1936 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
1937 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001938 struct device *dev = &adapter->vdev->dev;
1939 dma_addr_t rsp_buffer_token;
1940 dma_addr_t buffer_token;
1941 size_t rsp_buffer_size;
1942 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001943 size_t buffer_size;
1944 __be64 *tx_list_p;
1945 __be64 *rx_list_p;
1946 int i;
1947
1948 buffer_size =
1949 sizeof(struct ibmvnic_login_buffer) +
1950 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
1951
1952 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
1953 if (!login_buffer)
1954 goto buf_alloc_failed;
1955
1956 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
1957 DMA_TO_DEVICE);
1958 if (dma_mapping_error(dev, buffer_token)) {
1959 dev_err(dev, "Couldn't map login buffer\n");
1960 goto buf_map_failed;
1961 }
1962
John Allen498cd8e2016-04-06 11:49:55 -05001963 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
1964 sizeof(u64) * adapter->req_tx_queues +
1965 sizeof(u64) * adapter->req_rx_queues +
1966 sizeof(u64) * adapter->req_rx_queues +
1967 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001968
1969 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
1970 if (!login_rsp_buffer)
1971 goto buf_rsp_alloc_failed;
1972
1973 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
1974 rsp_buffer_size, DMA_FROM_DEVICE);
1975 if (dma_mapping_error(dev, rsp_buffer_token)) {
1976 dev_err(dev, "Couldn't map login rsp buffer\n");
1977 goto buf_rsp_map_failed;
1978 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04001979
Thomas Falcon032c5e82015-12-21 11:26:06 -06001980 adapter->login_buf = login_buffer;
1981 adapter->login_buf_token = buffer_token;
1982 adapter->login_buf_sz = buffer_size;
1983 adapter->login_rsp_buf = login_rsp_buffer;
1984 adapter->login_rsp_buf_token = rsp_buffer_token;
1985 adapter->login_rsp_buf_sz = rsp_buffer_size;
1986
1987 login_buffer->len = cpu_to_be32(buffer_size);
1988 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
1989 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
1990 login_buffer->off_txcomp_subcrqs =
1991 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
1992 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
1993 login_buffer->off_rxcomp_subcrqs =
1994 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
1995 sizeof(u64) * adapter->req_tx_queues);
1996 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
1997 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
1998
1999 tx_list_p = (__be64 *)((char *)login_buffer +
2000 sizeof(struct ibmvnic_login_buffer));
2001 rx_list_p = (__be64 *)((char *)login_buffer +
2002 sizeof(struct ibmvnic_login_buffer) +
2003 sizeof(u64) * adapter->req_tx_queues);
2004
2005 for (i = 0; i < adapter->req_tx_queues; i++) {
2006 if (adapter->tx_scrq[i]) {
2007 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
2008 crq_num);
2009 }
2010 }
2011
2012 for (i = 0; i < adapter->req_rx_queues; i++) {
2013 if (adapter->rx_scrq[i]) {
2014 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
2015 crq_num);
2016 }
2017 }
2018
2019 netdev_dbg(adapter->netdev, "Login Buffer:\n");
2020 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
2021 netdev_dbg(adapter->netdev, "%016lx\n",
2022 ((unsigned long int *)(adapter->login_buf))[i]);
2023 }
2024
2025 memset(&crq, 0, sizeof(crq));
2026 crq.login.first = IBMVNIC_CRQ_CMD;
2027 crq.login.cmd = LOGIN;
2028 crq.login.ioba = cpu_to_be32(buffer_token);
2029 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002030 ibmvnic_send_crq(adapter, &crq);
2031
2032 return;
2033
Thomas Falcon032c5e82015-12-21 11:26:06 -06002034buf_rsp_map_failed:
2035 kfree(login_rsp_buffer);
2036buf_rsp_alloc_failed:
2037 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
2038buf_map_failed:
2039 kfree(login_buffer);
2040buf_alloc_failed:
2041 return;
2042}
2043
2044static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
2045 u32 len, u8 map_id)
2046{
2047 union ibmvnic_crq crq;
2048
2049 memset(&crq, 0, sizeof(crq));
2050 crq.request_map.first = IBMVNIC_CRQ_CMD;
2051 crq.request_map.cmd = REQUEST_MAP;
2052 crq.request_map.map_id = map_id;
2053 crq.request_map.ioba = cpu_to_be32(addr);
2054 crq.request_map.len = cpu_to_be32(len);
2055 ibmvnic_send_crq(adapter, &crq);
2056}
2057
2058static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
2059{
2060 union ibmvnic_crq crq;
2061
2062 memset(&crq, 0, sizeof(crq));
2063 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
2064 crq.request_unmap.cmd = REQUEST_UNMAP;
2065 crq.request_unmap.map_id = map_id;
2066 ibmvnic_send_crq(adapter, &crq);
2067}
2068
2069static void send_map_query(struct ibmvnic_adapter *adapter)
2070{
2071 union ibmvnic_crq crq;
2072
2073 memset(&crq, 0, sizeof(crq));
2074 crq.query_map.first = IBMVNIC_CRQ_CMD;
2075 crq.query_map.cmd = QUERY_MAP;
2076 ibmvnic_send_crq(adapter, &crq);
2077}
2078
2079/* Send a series of CRQs requesting various capabilities of the VNIC server */
2080static void send_cap_queries(struct ibmvnic_adapter *adapter)
2081{
2082 union ibmvnic_crq crq;
2083
Thomas Falcon901e0402017-02-15 12:17:59 -06002084 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002085 memset(&crq, 0, sizeof(crq));
2086 crq.query_capability.first = IBMVNIC_CRQ_CMD;
2087 crq.query_capability.cmd = QUERY_CAPABILITY;
2088
2089 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002090 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002091 ibmvnic_send_crq(adapter, &crq);
2092
2093 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002094 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002095 ibmvnic_send_crq(adapter, &crq);
2096
2097 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002098 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002099 ibmvnic_send_crq(adapter, &crq);
2100
2101 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002102 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002103 ibmvnic_send_crq(adapter, &crq);
2104
2105 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002106 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002107 ibmvnic_send_crq(adapter, &crq);
2108
2109 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002110 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002111 ibmvnic_send_crq(adapter, &crq);
2112
2113 crq.query_capability.capability =
2114 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002115 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002116 ibmvnic_send_crq(adapter, &crq);
2117
2118 crq.query_capability.capability =
2119 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002120 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002121 ibmvnic_send_crq(adapter, &crq);
2122
2123 crq.query_capability.capability =
2124 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002125 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002126 ibmvnic_send_crq(adapter, &crq);
2127
2128 crq.query_capability.capability =
2129 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
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(TCP_IP_OFFLOAD);
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(PROMISC_SUPPORTED);
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(MIN_MTU);
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_MTU);
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_MULTICAST_FILTERS);
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 = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06002154 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002155 ibmvnic_send_crq(adapter, &crq);
2156
2157 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002158 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002159 ibmvnic_send_crq(adapter, &crq);
2160
2161 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002162 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002163 ibmvnic_send_crq(adapter, &crq);
2164
2165 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002166 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002167 ibmvnic_send_crq(adapter, &crq);
2168
2169 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
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 =
2174 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06002175 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002176 ibmvnic_send_crq(adapter, &crq);
2177
2178 crq.query_capability.capability =
2179 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002180 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002181 ibmvnic_send_crq(adapter, &crq);
2182
2183 crq.query_capability.capability =
2184 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002185 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002186 ibmvnic_send_crq(adapter, &crq);
2187
2188 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002189 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002190 ibmvnic_send_crq(adapter, &crq);
2191}
2192
2193static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2194{
2195 struct device *dev = &adapter->vdev->dev;
2196 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2197 union ibmvnic_crq crq;
2198 int i;
2199
2200 dma_unmap_single(dev, adapter->ip_offload_tok,
2201 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2202
2203 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2204 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2205 netdev_dbg(adapter->netdev, "%016lx\n",
2206 ((unsigned long int *)(buf))[i]);
2207
2208 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2209 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2210 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2211 buf->tcp_ipv4_chksum);
2212 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2213 buf->tcp_ipv6_chksum);
2214 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2215 buf->udp_ipv4_chksum);
2216 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2217 buf->udp_ipv6_chksum);
2218 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2219 buf->large_tx_ipv4);
2220 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2221 buf->large_tx_ipv6);
2222 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2223 buf->large_rx_ipv4);
2224 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2225 buf->large_rx_ipv6);
2226 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2227 buf->max_ipv4_header_size);
2228 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2229 buf->max_ipv6_header_size);
2230 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2231 buf->max_tcp_header_size);
2232 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2233 buf->max_udp_header_size);
2234 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2235 buf->max_large_tx_size);
2236 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2237 buf->max_large_rx_size);
2238 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2239 buf->ipv6_extension_header);
2240 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2241 buf->tcp_pseudosum_req);
2242 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2243 buf->num_ipv6_ext_headers);
2244 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2245 buf->off_ipv6_ext_headers);
2246
2247 adapter->ip_offload_ctrl_tok =
2248 dma_map_single(dev, &adapter->ip_offload_ctrl,
2249 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2250
2251 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2252 dev_err(dev, "Couldn't map ip offload control buffer\n");
2253 return;
2254 }
2255
2256 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2257 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2258 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2259 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2260 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2261
2262 /* large_tx/rx disabled for now, additional features needed */
2263 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2264 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2265 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2266 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2267
2268 adapter->netdev->features = NETIF_F_GSO;
2269
2270 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2271 adapter->netdev->features |= NETIF_F_IP_CSUM;
2272
2273 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2274 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2275
Thomas Falcon9be02cd2016-04-01 17:20:35 -05002276 if ((adapter->netdev->features &
2277 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2278 adapter->netdev->features |= NETIF_F_RXCSUM;
2279
Thomas Falcon032c5e82015-12-21 11:26:06 -06002280 memset(&crq, 0, sizeof(crq));
2281 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2282 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2283 crq.control_ip_offload.len =
2284 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2285 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2286 ibmvnic_send_crq(adapter, &crq);
2287}
2288
2289static void handle_error_info_rsp(union ibmvnic_crq *crq,
2290 struct ibmvnic_adapter *adapter)
2291{
2292 struct device *dev = &adapter->vdev->dev;
Wei Yongjun96183182016-06-27 20:48:53 +08002293 struct ibmvnic_error_buff *error_buff, *tmp;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002294 unsigned long flags;
2295 bool found = false;
2296 int i;
2297
2298 if (!crq->request_error_rsp.rc.code) {
2299 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2300 crq->request_error_rsp.rc.code);
2301 return;
2302 }
2303
2304 spin_lock_irqsave(&adapter->error_list_lock, flags);
Wei Yongjun96183182016-06-27 20:48:53 +08002305 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002306 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2307 found = true;
2308 list_del(&error_buff->list);
2309 break;
2310 }
2311 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2312
2313 if (!found) {
2314 dev_err(dev, "Couldn't find error id %x\n",
Thomas Falcon75224c92017-02-15 10:33:33 -06002315 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002316 return;
2317 }
2318
2319 dev_err(dev, "Detailed info for error id %x:",
Thomas Falcon75224c92017-02-15 10:33:33 -06002320 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002321
2322 for (i = 0; i < error_buff->len; i++) {
2323 pr_cont("%02x", (int)error_buff->buff[i]);
2324 if (i % 8 == 7)
2325 pr_cont(" ");
2326 }
2327 pr_cont("\n");
2328
2329 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2330 DMA_FROM_DEVICE);
2331 kfree(error_buff->buff);
2332 kfree(error_buff);
2333}
2334
Thomas Falcon032c5e82015-12-21 11:26:06 -06002335static void handle_error_indication(union ibmvnic_crq *crq,
2336 struct ibmvnic_adapter *adapter)
2337{
2338 int detail_len = be32_to_cpu(crq->error_indication.detail_error_sz);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002339 struct device *dev = &adapter->vdev->dev;
2340 struct ibmvnic_error_buff *error_buff;
2341 union ibmvnic_crq new_crq;
2342 unsigned long flags;
2343
2344 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2345 crq->error_indication.
2346 flags & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
Thomas Falcon75224c92017-02-15 10:33:33 -06002347 be32_to_cpu(crq->error_indication.error_id),
2348 be16_to_cpu(crq->error_indication.error_cause));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002349
2350 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2351 if (!error_buff)
2352 return;
2353
2354 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2355 if (!error_buff->buff) {
2356 kfree(error_buff);
2357 return;
2358 }
2359
2360 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2361 DMA_FROM_DEVICE);
2362 if (dma_mapping_error(dev, error_buff->dma)) {
2363 if (!firmware_has_feature(FW_FEATURE_CMO))
2364 dev_err(dev, "Couldn't map error buffer\n");
2365 kfree(error_buff->buff);
2366 kfree(error_buff);
2367 return;
2368 }
2369
Thomas Falcon032c5e82015-12-21 11:26:06 -06002370 error_buff->len = detail_len;
2371 error_buff->error_id = crq->error_indication.error_id;
2372
2373 spin_lock_irqsave(&adapter->error_list_lock, flags);
2374 list_add_tail(&error_buff->list, &adapter->errors);
2375 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2376
2377 memset(&new_crq, 0, sizeof(new_crq));
2378 new_crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2379 new_crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2380 new_crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2381 new_crq.request_error_info.len = cpu_to_be32(detail_len);
2382 new_crq.request_error_info.error_id = crq->error_indication.error_id;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002383 ibmvnic_send_crq(adapter, &new_crq);
2384}
2385
2386static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2387 struct ibmvnic_adapter *adapter)
2388{
2389 struct net_device *netdev = adapter->netdev;
2390 struct device *dev = &adapter->vdev->dev;
2391 long rc;
2392
2393 rc = crq->change_mac_addr_rsp.rc.code;
2394 if (rc) {
2395 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2396 return;
2397 }
2398 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2399 ETH_ALEN);
2400}
2401
2402static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2403 struct ibmvnic_adapter *adapter)
2404{
2405 struct device *dev = &adapter->vdev->dev;
2406 u64 *req_value;
2407 char *name;
2408
Thomas Falcon901e0402017-02-15 12:17:59 -06002409 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002410 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2411 case REQ_TX_QUEUES:
2412 req_value = &adapter->req_tx_queues;
2413 name = "tx";
2414 break;
2415 case REQ_RX_QUEUES:
2416 req_value = &adapter->req_rx_queues;
2417 name = "rx";
2418 break;
2419 case REQ_RX_ADD_QUEUES:
2420 req_value = &adapter->req_rx_add_queues;
2421 name = "rx_add";
2422 break;
2423 case REQ_TX_ENTRIES_PER_SUBCRQ:
2424 req_value = &adapter->req_tx_entries_per_subcrq;
2425 name = "tx_entries_per_subcrq";
2426 break;
2427 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2428 req_value = &adapter->req_rx_add_entries_per_subcrq;
2429 name = "rx_add_entries_per_subcrq";
2430 break;
2431 case REQ_MTU:
2432 req_value = &adapter->req_mtu;
2433 name = "mtu";
2434 break;
2435 case PROMISC_REQUESTED:
2436 req_value = &adapter->promisc;
2437 name = "promisc";
2438 break;
2439 default:
2440 dev_err(dev, "Got invalid cap request rsp %d\n",
2441 crq->request_capability.capability);
2442 return;
2443 }
2444
2445 switch (crq->request_capability_rsp.rc.code) {
2446 case SUCCESS:
2447 break;
2448 case PARTIALSUCCESS:
2449 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2450 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06002451 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06002452 number), name);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002453 release_sub_crqs(adapter);
Thomas Falcon28f4d162017-02-15 10:32:11 -06002454 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
Thomas Falconea22d512016-07-06 15:35:17 -05002455 init_sub_crqs(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002456 return;
2457 default:
2458 dev_err(dev, "Error %d in request cap rsp\n",
2459 crq->request_capability_rsp.rc.code);
2460 return;
2461 }
2462
2463 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06002464 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002465 union ibmvnic_crq newcrq;
2466 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2467 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2468 &adapter->ip_offload_buf;
2469
Thomas Falcon249168a2017-02-15 12:18:00 -06002470 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002471 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
2472 buf_sz,
2473 DMA_FROM_DEVICE);
2474
2475 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
2476 if (!firmware_has_feature(FW_FEATURE_CMO))
2477 dev_err(dev, "Couldn't map offload buffer\n");
2478 return;
2479 }
2480
2481 memset(&newcrq, 0, sizeof(newcrq));
2482 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
2483 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
2484 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
2485 newcrq.query_ip_offload.ioba =
2486 cpu_to_be32(adapter->ip_offload_tok);
2487
2488 ibmvnic_send_crq(adapter, &newcrq);
2489 }
2490}
2491
2492static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
2493 struct ibmvnic_adapter *adapter)
2494{
2495 struct device *dev = &adapter->vdev->dev;
2496 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
2497 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002498 int i;
2499
2500 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
2501 DMA_BIDIRECTIONAL);
2502 dma_unmap_single(dev, adapter->login_rsp_buf_token,
2503 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
2504
John Allen498cd8e2016-04-06 11:49:55 -05002505 /* If the number of queues requested can't be allocated by the
2506 * server, the login response will return with code 1. We will need
2507 * to resend the login buffer with fewer queues requested.
2508 */
2509 if (login_rsp_crq->generic.rc.code) {
2510 adapter->renegotiate = true;
2511 complete(&adapter->init_done);
2512 return 0;
2513 }
2514
Thomas Falcon032c5e82015-12-21 11:26:06 -06002515 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
2516 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
2517 netdev_dbg(adapter->netdev, "%016lx\n",
2518 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
2519 }
2520
2521 /* Sanity checks */
2522 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
2523 (be32_to_cpu(login->num_rxcomp_subcrqs) *
2524 adapter->req_rx_add_queues !=
2525 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
2526 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
2527 ibmvnic_remove(adapter->vdev);
2528 return -EIO;
2529 }
2530 complete(&adapter->init_done);
2531
Thomas Falcon032c5e82015-12-21 11:26:06 -06002532 return 0;
2533}
2534
2535static void handle_request_map_rsp(union ibmvnic_crq *crq,
2536 struct ibmvnic_adapter *adapter)
2537{
2538 struct device *dev = &adapter->vdev->dev;
2539 u8 map_id = crq->request_map_rsp.map_id;
2540 int tx_subcrqs;
2541 int rx_subcrqs;
2542 long rc;
2543 int i;
2544
2545 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
2546 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
2547
2548 rc = crq->request_map_rsp.rc.code;
2549 if (rc) {
2550 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
2551 adapter->map_id--;
2552 /* need to find and zero tx/rx_pool map_id */
2553 for (i = 0; i < tx_subcrqs; i++) {
2554 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
2555 adapter->tx_pool[i].long_term_buff.map_id = 0;
2556 }
2557 for (i = 0; i < rx_subcrqs; i++) {
2558 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
2559 adapter->rx_pool[i].long_term_buff.map_id = 0;
2560 }
2561 }
2562 complete(&adapter->fw_done);
2563}
2564
2565static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
2566 struct ibmvnic_adapter *adapter)
2567{
2568 struct device *dev = &adapter->vdev->dev;
2569 long rc;
2570
2571 rc = crq->request_unmap_rsp.rc.code;
2572 if (rc)
2573 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
2574}
2575
2576static void handle_query_map_rsp(union ibmvnic_crq *crq,
2577 struct ibmvnic_adapter *adapter)
2578{
2579 struct net_device *netdev = adapter->netdev;
2580 struct device *dev = &adapter->vdev->dev;
2581 long rc;
2582
2583 rc = crq->query_map_rsp.rc.code;
2584 if (rc) {
2585 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
2586 return;
2587 }
2588 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
2589 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
2590 crq->query_map_rsp.free_pages);
2591}
2592
2593static void handle_query_cap_rsp(union ibmvnic_crq *crq,
2594 struct ibmvnic_adapter *adapter)
2595{
2596 struct net_device *netdev = adapter->netdev;
2597 struct device *dev = &adapter->vdev->dev;
2598 long rc;
2599
Thomas Falcon901e0402017-02-15 12:17:59 -06002600 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002601 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06002602 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002603 rc = crq->query_capability.rc.code;
2604 if (rc) {
2605 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
2606 goto out;
2607 }
2608
2609 switch (be16_to_cpu(crq->query_capability.capability)) {
2610 case MIN_TX_QUEUES:
2611 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002612 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002613 netdev_dbg(netdev, "min_tx_queues = %lld\n",
2614 adapter->min_tx_queues);
2615 break;
2616 case MIN_RX_QUEUES:
2617 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002618 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002619 netdev_dbg(netdev, "min_rx_queues = %lld\n",
2620 adapter->min_rx_queues);
2621 break;
2622 case MIN_RX_ADD_QUEUES:
2623 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002624 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002625 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
2626 adapter->min_rx_add_queues);
2627 break;
2628 case MAX_TX_QUEUES:
2629 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002630 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002631 netdev_dbg(netdev, "max_tx_queues = %lld\n",
2632 adapter->max_tx_queues);
2633 break;
2634 case MAX_RX_QUEUES:
2635 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002636 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002637 netdev_dbg(netdev, "max_rx_queues = %lld\n",
2638 adapter->max_rx_queues);
2639 break;
2640 case MAX_RX_ADD_QUEUES:
2641 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002642 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002643 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
2644 adapter->max_rx_add_queues);
2645 break;
2646 case MIN_TX_ENTRIES_PER_SUBCRQ:
2647 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002648 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002649 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
2650 adapter->min_tx_entries_per_subcrq);
2651 break;
2652 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
2653 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002654 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002655 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
2656 adapter->min_rx_add_entries_per_subcrq);
2657 break;
2658 case MAX_TX_ENTRIES_PER_SUBCRQ:
2659 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002660 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002661 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
2662 adapter->max_tx_entries_per_subcrq);
2663 break;
2664 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
2665 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002666 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002667 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
2668 adapter->max_rx_add_entries_per_subcrq);
2669 break;
2670 case TCP_IP_OFFLOAD:
2671 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06002672 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002673 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
2674 adapter->tcp_ip_offload);
2675 break;
2676 case PROMISC_SUPPORTED:
2677 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002678 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002679 netdev_dbg(netdev, "promisc_supported = %lld\n",
2680 adapter->promisc_supported);
2681 break;
2682 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002683 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002684 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002685 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
2686 break;
2687 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06002688 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06002689 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002690 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
2691 break;
2692 case MAX_MULTICAST_FILTERS:
2693 adapter->max_multicast_filters =
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, "max_multicast_filters = %lld\n",
2696 adapter->max_multicast_filters);
2697 break;
2698 case VLAN_HEADER_INSERTION:
2699 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06002700 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002701 if (adapter->vlan_header_insertion)
2702 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
2703 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
2704 adapter->vlan_header_insertion);
2705 break;
2706 case MAX_TX_SG_ENTRIES:
2707 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06002708 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002709 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
2710 adapter->max_tx_sg_entries);
2711 break;
2712 case RX_SG_SUPPORTED:
2713 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06002714 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002715 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
2716 adapter->rx_sg_supported);
2717 break;
2718 case OPT_TX_COMP_SUB_QUEUES:
2719 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002720 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002721 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
2722 adapter->opt_tx_comp_sub_queues);
2723 break;
2724 case OPT_RX_COMP_QUEUES:
2725 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06002726 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002727 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
2728 adapter->opt_rx_comp_queues);
2729 break;
2730 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
2731 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06002732 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002733 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
2734 adapter->opt_rx_bufadd_q_per_rx_comp_q);
2735 break;
2736 case OPT_TX_ENTRIES_PER_SUBCRQ:
2737 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002738 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002739 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
2740 adapter->opt_tx_entries_per_subcrq);
2741 break;
2742 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
2743 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06002744 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002745 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
2746 adapter->opt_rxba_entries_per_subcrq);
2747 break;
2748 case TX_RX_DESC_REQ:
2749 adapter->tx_rx_desc_req = crq->query_capability.number;
2750 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
2751 adapter->tx_rx_desc_req);
2752 break;
2753
2754 default:
2755 netdev_err(netdev, "Got invalid cap rsp %d\n",
2756 crq->query_capability.capability);
2757 }
2758
2759out:
Thomas Falcon249168a2017-02-15 12:18:00 -06002760 if (atomic_read(&adapter->running_cap_crqs) == 0) {
2761 adapter->wait_capability = false;
Thomas Falconea22d512016-07-06 15:35:17 -05002762 init_sub_crqs(adapter, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002763 /* We're done querying the capabilities, initialize sub-crqs */
Thomas Falcon249168a2017-02-15 12:18:00 -06002764 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002765}
2766
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002767static void ibmvnic_xport_event(struct work_struct *work)
2768{
2769 struct ibmvnic_adapter *adapter = container_of(work,
2770 struct ibmvnic_adapter,
2771 ibmvnic_xport);
2772 struct device *dev = &adapter->vdev->dev;
2773 long rc;
2774
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002775 release_sub_crqs(adapter);
2776 if (adapter->migrated) {
2777 rc = ibmvnic_reenable_crq_queue(adapter);
2778 if (rc)
2779 dev_err(dev, "Error after enable rc=%ld\n", rc);
2780 adapter->migrated = false;
2781 rc = ibmvnic_send_crq_init(adapter);
2782 if (rc)
2783 dev_err(dev, "Error sending init rc=%ld\n", rc);
2784 }
2785}
2786
Thomas Falcon032c5e82015-12-21 11:26:06 -06002787static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
2788 struct ibmvnic_adapter *adapter)
2789{
2790 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
2791 struct net_device *netdev = adapter->netdev;
2792 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002793 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002794 long rc;
2795
2796 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04002797 (unsigned long int)cpu_to_be64(u64_crq[0]),
2798 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002799 switch (gen_crq->first) {
2800 case IBMVNIC_CRQ_INIT_RSP:
2801 switch (gen_crq->cmd) {
2802 case IBMVNIC_CRQ_INIT:
2803 dev_info(dev, "Partner initialized\n");
2804 /* Send back a response */
2805 rc = ibmvnic_send_crq_init_complete(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05002806 if (!rc)
2807 schedule_work(&adapter->vnic_crq_init);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002808 else
2809 dev_err(dev, "Can't send initrsp rc=%ld\n", rc);
2810 break;
2811 case IBMVNIC_CRQ_INIT_COMPLETE:
2812 dev_info(dev, "Partner initialization complete\n");
2813 send_version_xchg(adapter);
2814 break;
2815 default:
2816 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
2817 }
2818 return;
2819 case IBMVNIC_CRQ_XPORT_EVENT:
2820 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
2821 dev_info(dev, "Re-enabling adapter\n");
2822 adapter->migrated = true;
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002823 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcondfad09a2016-08-18 11:37:51 -05002824 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
2825 dev_info(dev, "Backing device failover detected\n");
2826 netif_carrier_off(netdev);
2827 adapter->failover = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002828 } else {
2829 /* The adapter lost the connection */
2830 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
2831 gen_crq->cmd);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05002832 schedule_work(&adapter->ibmvnic_xport);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002833 }
2834 return;
2835 case IBMVNIC_CRQ_CMD_RSP:
2836 break;
2837 default:
2838 dev_err(dev, "Got an invalid msg type 0x%02x\n",
2839 gen_crq->first);
2840 return;
2841 }
2842
2843 switch (gen_crq->cmd) {
2844 case VERSION_EXCHANGE_RSP:
2845 rc = crq->version_exchange_rsp.rc.code;
2846 if (rc) {
2847 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
2848 break;
2849 }
2850 dev_info(dev, "Partner protocol version is %d\n",
2851 crq->version_exchange_rsp.version);
2852 if (be16_to_cpu(crq->version_exchange_rsp.version) <
2853 ibmvnic_version)
2854 ibmvnic_version =
2855 be16_to_cpu(crq->version_exchange_rsp.version);
2856 send_cap_queries(adapter);
2857 break;
2858 case QUERY_CAPABILITY_RSP:
2859 handle_query_cap_rsp(crq, adapter);
2860 break;
2861 case QUERY_MAP_RSP:
2862 handle_query_map_rsp(crq, adapter);
2863 break;
2864 case REQUEST_MAP_RSP:
2865 handle_request_map_rsp(crq, adapter);
2866 break;
2867 case REQUEST_UNMAP_RSP:
2868 handle_request_unmap_rsp(crq, adapter);
2869 break;
2870 case REQUEST_CAPABILITY_RSP:
2871 handle_request_cap_rsp(crq, adapter);
2872 break;
2873 case LOGIN_RSP:
2874 netdev_dbg(netdev, "Got Login Response\n");
2875 handle_login_rsp(crq, adapter);
2876 break;
2877 case LOGICAL_LINK_STATE_RSP:
2878 netdev_dbg(netdev, "Got Logical Link State Response\n");
2879 adapter->logical_link_state =
2880 crq->logical_link_state_rsp.link_state;
2881 break;
2882 case LINK_STATE_INDICATION:
2883 netdev_dbg(netdev, "Got Logical Link State Indication\n");
2884 adapter->phys_link_state =
2885 crq->link_state_indication.phys_link_state;
2886 adapter->logical_link_state =
2887 crq->link_state_indication.logical_link_state;
2888 break;
2889 case CHANGE_MAC_ADDR_RSP:
2890 netdev_dbg(netdev, "Got MAC address change Response\n");
2891 handle_change_mac_rsp(crq, adapter);
2892 break;
2893 case ERROR_INDICATION:
2894 netdev_dbg(netdev, "Got Error Indication\n");
2895 handle_error_indication(crq, adapter);
2896 break;
2897 case REQUEST_ERROR_RSP:
2898 netdev_dbg(netdev, "Got Error Detail Response\n");
2899 handle_error_info_rsp(crq, adapter);
2900 break;
2901 case REQUEST_STATISTICS_RSP:
2902 netdev_dbg(netdev, "Got Statistics Response\n");
2903 complete(&adapter->stats_done);
2904 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002905 case QUERY_IP_OFFLOAD_RSP:
2906 netdev_dbg(netdev, "Got Query IP offload Response\n");
2907 handle_query_ip_offload_rsp(adapter);
2908 break;
2909 case MULTICAST_CTRL_RSP:
2910 netdev_dbg(netdev, "Got multicast control Response\n");
2911 break;
2912 case CONTROL_IP_OFFLOAD_RSP:
2913 netdev_dbg(netdev, "Got Control IP offload Response\n");
2914 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
2915 sizeof(adapter->ip_offload_ctrl),
2916 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05002917 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002918 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002919 case COLLECT_FW_TRACE_RSP:
2920 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
2921 complete(&adapter->fw_done);
2922 break;
2923 default:
2924 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
2925 gen_crq->cmd);
2926 }
2927}
2928
2929static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
2930{
2931 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06002932
Thomas Falcon6c267b32017-02-15 12:17:58 -06002933 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06002934 return IRQ_HANDLED;
2935}
2936
2937static void ibmvnic_tasklet(void *data)
2938{
2939 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002940 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002941 union ibmvnic_crq *crq;
2942 unsigned long flags;
2943 bool done = false;
2944
2945 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002946 while (!done) {
2947 /* Pull all the valid messages off the CRQ */
2948 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
2949 ibmvnic_handle_crq(crq, adapter);
2950 crq->generic.first = 0;
2951 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04002952
2953 /* remain in tasklet until all
2954 * capabilities responses are received
2955 */
2956 if (!adapter->wait_capability)
2957 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002958 }
Thomas Falcon249168a2017-02-15 12:18:00 -06002959 /* if capabilities CRQ's were sent in this tasklet, the following
2960 * tasklet must wait until all responses are received
2961 */
2962 if (atomic_read(&adapter->running_cap_crqs) != 0)
2963 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002964 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002965}
2966
2967static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
2968{
2969 struct vio_dev *vdev = adapter->vdev;
2970 int rc;
2971
2972 do {
2973 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
2974 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
2975
2976 if (rc)
2977 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
2978
2979 return rc;
2980}
2981
2982static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
2983{
2984 struct ibmvnic_crq_queue *crq = &adapter->crq;
2985 struct device *dev = &adapter->vdev->dev;
2986 struct vio_dev *vdev = adapter->vdev;
2987 int rc;
2988
2989 /* Close the CRQ */
2990 do {
2991 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
2992 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
2993
2994 /* Clean out the queue */
2995 memset(crq->msgs, 0, PAGE_SIZE);
2996 crq->cur = 0;
2997
2998 /* And re-open it again */
2999 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3000 crq->msg_token, PAGE_SIZE);
3001
3002 if (rc == H_CLOSED)
3003 /* Adapter is good, but other end is not ready */
3004 dev_warn(dev, "Partner adapter not ready\n");
3005 else if (rc != 0)
3006 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3007
3008 return rc;
3009}
3010
Nathan Fontenotf9928872017-03-30 02:48:54 -04003011static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003012{
3013 struct ibmvnic_crq_queue *crq = &adapter->crq;
3014 struct vio_dev *vdev = adapter->vdev;
3015 long rc;
3016
Nathan Fontenotf9928872017-03-30 02:48:54 -04003017 if (!crq->msgs)
3018 return;
3019
Thomas Falcon032c5e82015-12-21 11:26:06 -06003020 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3021 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003022 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003023 do {
3024 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3025 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3026
3027 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3028 DMA_BIDIRECTIONAL);
3029 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003030 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003031}
3032
Nathan Fontenotf9928872017-03-30 02:48:54 -04003033static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003034{
3035 struct ibmvnic_crq_queue *crq = &adapter->crq;
3036 struct device *dev = &adapter->vdev->dev;
3037 struct vio_dev *vdev = adapter->vdev;
3038 int rc, retrc = -ENOMEM;
3039
Nathan Fontenotf9928872017-03-30 02:48:54 -04003040 if (crq->msgs)
3041 return 0;
3042
Thomas Falcon032c5e82015-12-21 11:26:06 -06003043 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3044 /* Should we allocate more than one page? */
3045
3046 if (!crq->msgs)
3047 return -ENOMEM;
3048
3049 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3050 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3051 DMA_BIDIRECTIONAL);
3052 if (dma_mapping_error(dev, crq->msg_token))
3053 goto map_failed;
3054
3055 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3056 crq->msg_token, PAGE_SIZE);
3057
3058 if (rc == H_RESOURCE)
3059 /* maybe kexecing and resource is busy. try a reset */
3060 rc = ibmvnic_reset_crq(adapter);
3061 retrc = rc;
3062
3063 if (rc == H_CLOSED) {
3064 dev_warn(dev, "Partner adapter not ready\n");
3065 } else if (rc) {
3066 dev_warn(dev, "Error %d opening adapter\n", rc);
3067 goto reg_crq_failed;
3068 }
3069
3070 retrc = 0;
3071
Thomas Falcon6c267b32017-02-15 12:17:58 -06003072 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3073 (unsigned long)adapter);
3074
Thomas Falcon032c5e82015-12-21 11:26:06 -06003075 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3076 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3077 adapter);
3078 if (rc) {
3079 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3080 vdev->irq, rc);
3081 goto req_irq_failed;
3082 }
3083
3084 rc = vio_enable_interrupts(vdev);
3085 if (rc) {
3086 dev_err(dev, "Error %d enabling interrupts\n", rc);
3087 goto req_irq_failed;
3088 }
3089
3090 crq->cur = 0;
3091 spin_lock_init(&crq->lock);
3092
3093 return retrc;
3094
3095req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06003096 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003097 do {
3098 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3099 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3100reg_crq_failed:
3101 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3102map_failed:
3103 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003104 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003105 return retrc;
3106}
3107
Thomas Falcon65dc6892016-07-06 15:35:18 -05003108static void handle_crq_init_rsp(struct work_struct *work)
3109{
3110 struct ibmvnic_adapter *adapter = container_of(work,
3111 struct ibmvnic_adapter,
3112 vnic_crq_init);
3113 struct device *dev = &adapter->vdev->dev;
3114 struct net_device *netdev = adapter->netdev;
3115 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcondfad09a2016-08-18 11:37:51 -05003116 bool restart = false;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003117 int rc;
3118
Thomas Falcondfad09a2016-08-18 11:37:51 -05003119 if (adapter->failover) {
3120 release_sub_crqs(adapter);
3121 if (netif_running(netdev)) {
3122 netif_tx_disable(netdev);
3123 ibmvnic_close(netdev);
3124 restart = true;
3125 }
3126 }
3127
Thomas Falcon65dc6892016-07-06 15:35:18 -05003128 reinit_completion(&adapter->init_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05003129 send_version_xchg(adapter);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003130 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3131 dev_err(dev, "Passive init timeout\n");
3132 goto task_failed;
3133 }
3134
Thomas Falconf39f0d12017-02-14 10:22:59 -06003135 netdev->mtu = adapter->req_mtu - ETH_HLEN;
Thomas Falcon65dc6892016-07-06 15:35:18 -05003136
Thomas Falcondfad09a2016-08-18 11:37:51 -05003137 if (adapter->failover) {
3138 adapter->failover = false;
3139 if (restart) {
3140 rc = ibmvnic_open(netdev);
3141 if (rc)
3142 goto restart_failed;
3143 }
3144 netif_carrier_on(netdev);
3145 return;
3146 }
3147
Thomas Falcon65dc6892016-07-06 15:35:18 -05003148 rc = register_netdev(netdev);
3149 if (rc) {
3150 dev_err(dev,
3151 "failed to register netdev rc=%d\n", rc);
3152 goto register_failed;
3153 }
3154 dev_info(dev, "ibmvnic registered\n");
3155
3156 return;
3157
Thomas Falcondfad09a2016-08-18 11:37:51 -05003158restart_failed:
3159 dev_err(dev, "Failed to restart ibmvnic, rc=%d\n", rc);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003160register_failed:
3161 release_sub_crqs(adapter);
3162task_failed:
3163 dev_err(dev, "Passive initialization was not successful\n");
3164}
3165
John Allenf6ef6402017-03-17 17:13:42 -05003166static int ibmvnic_init(struct ibmvnic_adapter *adapter)
3167{
3168 struct device *dev = &adapter->vdev->dev;
3169 unsigned long timeout = msecs_to_jiffies(30000);
John Allenf6ef6402017-03-17 17:13:42 -05003170 int rc;
3171
Nathan Fontenotf9928872017-03-30 02:48:54 -04003172 rc = init_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003173 if (rc) {
3174 dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
3175 return rc;
3176 }
3177
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003178 rc = init_stats_token(adapter);
3179 if (rc) {
Nathan Fontenotf9928872017-03-30 02:48:54 -04003180 release_crq_queue(adapter);
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -04003181 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05003182 }
3183
John Allenf6ef6402017-03-17 17:13:42 -05003184 init_completion(&adapter->init_done);
3185 ibmvnic_send_crq_init(adapter);
3186 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3187 dev_err(dev, "Initialization sequence timed out\n");
Nathan Fontenotf9928872017-03-30 02:48:54 -04003188 release_crq_queue(adapter);
John Allenf6ef6402017-03-17 17:13:42 -05003189 return -1;
3190 }
3191
3192 return 0;
3193}
3194
Thomas Falcon032c5e82015-12-21 11:26:06 -06003195static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3196{
3197 struct ibmvnic_adapter *adapter;
3198 struct net_device *netdev;
3199 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003200 int rc;
3201
3202 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3203 dev->unit_address);
3204
3205 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3206 VETH_MAC_ADDR, NULL);
3207 if (!mac_addr_p) {
3208 dev_err(&dev->dev,
3209 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3210 __FILE__, __LINE__);
3211 return 0;
3212 }
3213
3214 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3215 IBMVNIC_MAX_TX_QUEUES);
3216 if (!netdev)
3217 return -ENOMEM;
3218
3219 adapter = netdev_priv(netdev);
3220 dev_set_drvdata(&dev->dev, netdev);
3221 adapter->vdev = dev;
3222 adapter->netdev = netdev;
Thomas Falcondfad09a2016-08-18 11:37:51 -05003223 adapter->failover = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003224
3225 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3226 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3227 netdev->irq = dev->irq;
3228 netdev->netdev_ops = &ibmvnic_netdev_ops;
3229 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3230 SET_NETDEV_DEV(netdev, &dev->dev);
3231
Thomas Falcon65dc6892016-07-06 15:35:18 -05003232 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp);
Thomas Falcon9888d7b2016-10-27 12:28:51 -05003233 INIT_WORK(&adapter->ibmvnic_xport, ibmvnic_xport_event);
Thomas Falcon65dc6892016-07-06 15:35:18 -05003234
Thomas Falcon032c5e82015-12-21 11:26:06 -06003235 spin_lock_init(&adapter->stats_lock);
3236
Thomas Falcon032c5e82015-12-21 11:26:06 -06003237 INIT_LIST_HEAD(&adapter->errors);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003238 spin_lock_init(&adapter->error_list_lock);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003239
John Allenf6ef6402017-03-17 17:13:42 -05003240 rc = ibmvnic_init(adapter);
3241 if (rc) {
3242 free_netdev(netdev);
3243 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003244 }
3245
Thomas Falconf39f0d12017-02-14 10:22:59 -06003246 netdev->mtu = adapter->req_mtu - ETH_HLEN;
John Allenea5509f2017-03-17 17:13:43 -05003247 adapter->is_closed = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003248
3249 rc = register_netdev(netdev);
3250 if (rc) {
3251 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
John Allenf6ef6402017-03-17 17:13:42 -05003252 free_netdev(netdev);
3253 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003254 }
3255 dev_info(&dev->dev, "ibmvnic registered\n");
3256
3257 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003258}
3259
3260static int ibmvnic_remove(struct vio_dev *dev)
3261{
3262 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003263 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003264
3265 unregister_netdev(netdev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003266
3267 release_resources(adapter);
3268 release_sub_crqs(adapter);
3269 release_crq_queue(adapter);
3270
Thomas Falcon032c5e82015-12-21 11:26:06 -06003271 free_netdev(netdev);
3272 dev_set_drvdata(&dev->dev, NULL);
3273
3274 return 0;
3275}
3276
3277static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3278{
3279 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3280 struct ibmvnic_adapter *adapter;
3281 struct iommu_table *tbl;
3282 unsigned long ret = 0;
3283 int i;
3284
3285 tbl = get_iommu_table_base(&vdev->dev);
3286
3287 /* netdev inits at probe time along with the structures we need below*/
3288 if (!netdev)
3289 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3290
3291 adapter = netdev_priv(netdev);
3292
3293 ret += PAGE_SIZE; /* the crq message queue */
Thomas Falcon032c5e82015-12-21 11:26:06 -06003294 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3295
3296 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3297 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3298
3299 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3300 i++)
3301 ret += adapter->rx_pool[i].size *
3302 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3303
3304 return ret;
3305}
3306
3307static int ibmvnic_resume(struct device *dev)
3308{
3309 struct net_device *netdev = dev_get_drvdata(dev);
3310 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3311 int i;
3312
3313 /* kick the interrupt handlers just in case we lost an interrupt */
3314 for (i = 0; i < adapter->req_rx_queues; i++)
3315 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3316 adapter->rx_scrq[i]);
3317
3318 return 0;
3319}
3320
3321static struct vio_device_id ibmvnic_device_table[] = {
3322 {"network", "IBM,vnic"},
3323 {"", "" }
3324};
3325MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3326
3327static const struct dev_pm_ops ibmvnic_pm_ops = {
3328 .resume = ibmvnic_resume
3329};
3330
3331static struct vio_driver ibmvnic_driver = {
3332 .id_table = ibmvnic_device_table,
3333 .probe = ibmvnic_probe,
3334 .remove = ibmvnic_remove,
3335 .get_desired_dma = ibmvnic_get_desired_dma,
3336 .name = ibmvnic_driver_name,
3337 .pm = &ibmvnic_pm_ops,
3338};
3339
3340/* module functions */
3341static int __init ibmvnic_module_init(void)
3342{
3343 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3344 IBMVNIC_DRIVER_VERSION);
3345
3346 return vio_register_driver(&ibmvnic_driver);
3347}
3348
3349static void __exit ibmvnic_module_exit(void)
3350{
3351 vio_unregister_driver(&ibmvnic_driver);
3352}
3353
3354module_init(ibmvnic_module_init);
3355module_exit(ibmvnic_module_exit);