blob: 99c552a79e9d2d788e4783972300fac48885372e [file] [log] [blame]
Thomas Falcon032c5e82015-12-21 11:26:06 -06001/**************************************************************************/
2/* */
3/* IBM System i and System p Virtual NIC Device Driver */
4/* Copyright (C) 2014 IBM Corp. */
5/* Santiago Leon (santi_leon@yahoo.com) */
6/* Thomas Falcon (tlfalcon@linux.vnet.ibm.com) */
7/* John Allen (jallen@linux.vnet.ibm.com) */
8/* */
9/* This program is free software; you can redistribute it and/or modify */
10/* it under the terms of the GNU General Public License as published by */
11/* the Free Software Foundation; either version 2 of the License, or */
12/* (at your option) any later version. */
13/* */
14/* This program is distributed in the hope that it will be useful, */
15/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17/* GNU General Public License for more details. */
18/* */
19/* You should have received a copy of the GNU General Public License */
20/* along with this program. */
21/* */
22/* This module contains the implementation of a virtual ethernet device */
23/* for use with IBM i/p Series LPAR Linux. It utilizes the logical LAN */
24/* option of the RS/6000 Platform Architecture to interface with virtual */
25/* ethernet NICs that are presented to the partition by the hypervisor. */
26/* */
27/* Messages are passed between the VNIC driver and the VNIC server using */
28/* Command/Response Queues (CRQs) and sub CRQs (sCRQs). CRQs are used to */
29/* issue and receive commands that initiate communication with the server */
30/* on driver initialization. Sub CRQs (sCRQs) are similar to CRQs, but */
31/* are used by the driver to notify the server that a packet is */
32/* ready for transmission or that a buffer has been added to receive a */
33/* packet. Subsequently, sCRQs are used by the server to notify the */
34/* driver that a packet transmission has been completed or that a packet */
35/* has been received and placed in a waiting buffer. */
36/* */
37/* In lieu of a more conventional "on-the-fly" DMA mapping strategy in */
38/* which skbs are DMA mapped and immediately unmapped when the transmit */
39/* or receive has been completed, the VNIC driver is required to use */
40/* "long term mapping". This entails that large, continuous DMA mapped */
41/* buffers are allocated on driver initialization and these buffers are */
42/* then continuously reused to pass skbs to and from the VNIC server. */
43/* */
44/**************************************************************************/
45
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/types.h>
49#include <linux/errno.h>
50#include <linux/completion.h>
51#include <linux/ioport.h>
52#include <linux/dma-mapping.h>
53#include <linux/kernel.h>
54#include <linux/netdevice.h>
55#include <linux/etherdevice.h>
56#include <linux/skbuff.h>
57#include <linux/init.h>
58#include <linux/delay.h>
59#include <linux/mm.h>
60#include <linux/ethtool.h>
61#include <linux/proc_fs.h>
62#include <linux/in.h>
63#include <linux/ip.h>
Thomas Falconad7775d2016-04-01 17:20:34 -050064#include <linux/ipv6.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060065#include <linux/irq.h>
66#include <linux/kthread.h>
67#include <linux/seq_file.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060068#include <linux/interrupt.h>
69#include <net/net_namespace.h>
70#include <asm/hvcall.h>
71#include <linux/atomic.h>
72#include <asm/vio.h>
73#include <asm/iommu.h>
74#include <linux/uaccess.h>
75#include <asm/firmware.h>
Thomas Falcon65dc6892016-07-06 15:35:18 -050076#include <linux/workqueue.h>
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -040077#include <linux/if_vlan.h>
Thomas Falcon032c5e82015-12-21 11:26:06 -060078
79#include "ibmvnic.h"
80
81static const char ibmvnic_driver_name[] = "ibmvnic";
82static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
83
Thomas Falcon78b07ac2017-06-01 15:32:34 -050084MODULE_AUTHOR("Santiago Leon");
Thomas Falcon032c5e82015-12-21 11:26:06 -060085MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
86MODULE_LICENSE("GPL");
87MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
88
89static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
90static int ibmvnic_remove(struct vio_dev *);
91static void release_sub_crqs(struct ibmvnic_adapter *);
92static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
93static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
94static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
95static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
96static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
97 union sub_crq *sub_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -050098static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
Thomas Falcon032c5e82015-12-21 11:26:06 -060099static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
100static int enable_scrq_irq(struct ibmvnic_adapter *,
101 struct ibmvnic_sub_crq_queue *);
102static int disable_scrq_irq(struct ibmvnic_adapter *,
103 struct ibmvnic_sub_crq_queue *);
104static int pending_scrq(struct ibmvnic_adapter *,
105 struct ibmvnic_sub_crq_queue *);
106static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
107 struct ibmvnic_sub_crq_queue *);
108static int ibmvnic_poll(struct napi_struct *napi, int data);
109static void send_map_query(struct ibmvnic_adapter *adapter);
110static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
111static void send_request_unmap(struct ibmvnic_adapter *, u8);
John Allenbd0b6722017-03-17 17:13:40 -0500112static void send_login(struct ibmvnic_adapter *adapter);
113static void send_cap_queries(struct ibmvnic_adapter *adapter);
114static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
John Allenea5509f2017-03-17 17:13:43 -0500115static int ibmvnic_init(struct ibmvnic_adapter *);
Nathan Fontenotf9928872017-03-30 02:48:54 -0400116static void release_crq_queue(struct ibmvnic_adapter *);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600117
118struct ibmvnic_stat {
119 char name[ETH_GSTRING_LEN];
120 int offset;
121};
122
123#define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
124 offsetof(struct ibmvnic_statistics, stat))
125#define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
126
127static const struct ibmvnic_stat ibmvnic_stats[] = {
128 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
129 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
130 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
131 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
132 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
133 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
134 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
135 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
136 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
137 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
138 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
139 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
140 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
141 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
142 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
143 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
144 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
145 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
146 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
147 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
148 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
149 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
150};
151
152static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
153 unsigned long length, unsigned long *number,
154 unsigned long *irq)
155{
156 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
157 long rc;
158
159 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
160 *number = retbuf[0];
161 *irq = retbuf[1];
162
163 return rc;
164}
165
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400166static void reset_long_term_buff(struct ibmvnic_adapter *adapter,
167 struct ibmvnic_long_term_buff *ltb)
168{
169 memset(ltb->buff, 0, ltb->size);
170
171 init_completion(&adapter->fw_done);
172 send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id);
173 wait_for_completion(&adapter->fw_done);
174}
175
Thomas Falcon032c5e82015-12-21 11:26:06 -0600176static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
177 struct ibmvnic_long_term_buff *ltb, int size)
178{
179 struct device *dev = &adapter->vdev->dev;
180
181 ltb->size = size;
182 ltb->buff = dma_alloc_coherent(dev, ltb->size, &ltb->addr,
183 GFP_KERNEL);
184
185 if (!ltb->buff) {
186 dev_err(dev, "Couldn't alloc long term buffer\n");
187 return -ENOMEM;
188 }
189 ltb->map_id = adapter->map_id;
190 adapter->map_id++;
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -0500191
192 init_completion(&adapter->fw_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600193 send_request_map(adapter, ltb->addr,
194 ltb->size, ltb->map_id);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600195 wait_for_completion(&adapter->fw_done);
196 return 0;
197}
198
199static void free_long_term_buff(struct ibmvnic_adapter *adapter,
200 struct ibmvnic_long_term_buff *ltb)
201{
202 struct device *dev = &adapter->vdev->dev;
203
Nathan Fontenotc657e322017-03-30 02:49:06 -0400204 if (!ltb->buff)
205 return;
206
Nathan Fontenoted651a12017-05-03 14:04:38 -0400207 if (adapter->reset_reason != VNIC_RESET_FAILOVER &&
208 adapter->reset_reason != VNIC_RESET_MOBILITY)
Thomas Falcondfad09a2016-08-18 11:37:51 -0500209 send_request_unmap(adapter, ltb->map_id);
Brian King59af56c2017-04-19 13:44:41 -0400210 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600211}
212
Thomas Falconf185a492017-05-26 10:30:48 -0400213static void deactivate_rx_pools(struct ibmvnic_adapter *adapter)
214{
215 int i;
216
217 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
218 i++)
219 adapter->rx_pool[i].active = 0;
220}
221
Thomas Falcon032c5e82015-12-21 11:26:06 -0600222static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
223 struct ibmvnic_rx_pool *pool)
224{
225 int count = pool->size - atomic_read(&pool->available);
226 struct device *dev = &adapter->vdev->dev;
227 int buffers_added = 0;
228 unsigned long lpar_rc;
229 union sub_crq sub_crq;
230 struct sk_buff *skb;
231 unsigned int offset;
232 dma_addr_t dma_addr;
233 unsigned char *dst;
234 u64 *handle_array;
235 int shift = 0;
236 int index;
237 int i;
238
Thomas Falconf185a492017-05-26 10:30:48 -0400239 if (!pool->active)
240 return;
241
Thomas Falcon032c5e82015-12-21 11:26:06 -0600242 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
243 be32_to_cpu(adapter->login_rsp_buf->
244 off_rxadd_subcrqs));
245
246 for (i = 0; i < count; ++i) {
247 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
248 if (!skb) {
249 dev_err(dev, "Couldn't replenish rx buff\n");
250 adapter->replenish_no_mem++;
251 break;
252 }
253
254 index = pool->free_map[pool->next_free];
255
256 if (pool->rx_buff[index].skb)
257 dev_err(dev, "Inconsistent free_map!\n");
258
259 /* Copy the skb to the long term mapped DMA buffer */
260 offset = index * pool->buff_size;
261 dst = pool->long_term_buff.buff + offset;
262 memset(dst, 0, pool->buff_size);
263 dma_addr = pool->long_term_buff.addr + offset;
264 pool->rx_buff[index].data = dst;
265
266 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
267 pool->rx_buff[index].dma = dma_addr;
268 pool->rx_buff[index].skb = skb;
269 pool->rx_buff[index].pool_index = pool->index;
270 pool->rx_buff[index].size = pool->buff_size;
271
272 memset(&sub_crq, 0, sizeof(sub_crq));
273 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
274 sub_crq.rx_add.correlator =
275 cpu_to_be64((u64)&pool->rx_buff[index]);
276 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
277 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
278
279 /* The length field of the sCRQ is defined to be 24 bits so the
280 * buffer size needs to be left shifted by a byte before it is
281 * converted to big endian to prevent the last byte from being
282 * truncated.
283 */
284#ifdef __LITTLE_ENDIAN__
285 shift = 8;
286#endif
287 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
288
289 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
290 &sub_crq);
291 if (lpar_rc != H_SUCCESS)
292 goto failure;
293
294 buffers_added++;
295 adapter->replenish_add_buff_success++;
296 pool->next_free = (pool->next_free + 1) % pool->size;
297 }
298 atomic_add(buffers_added, &pool->available);
299 return;
300
301failure:
302 dev_info(dev, "replenish pools failure\n");
303 pool->free_map[pool->next_free] = index;
304 pool->rx_buff[index].skb = NULL;
305 if (!dma_mapping_error(dev, dma_addr))
306 dma_unmap_single(dev, dma_addr, pool->buff_size,
307 DMA_FROM_DEVICE);
308
309 dev_kfree_skb_any(skb);
310 adapter->replenish_add_buff_failure++;
311 atomic_add(buffers_added, &pool->available);
Thomas Falconf185a492017-05-26 10:30:48 -0400312
313 if (lpar_rc == H_CLOSED) {
314 /* Disable buffer pool replenishment and report carrier off if
315 * queue is closed. Firmware guarantees that a signal will
316 * be sent to the driver, triggering a reset.
317 */
318 deactivate_rx_pools(adapter);
319 netif_carrier_off(adapter->netdev);
320 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600321}
322
323static void replenish_pools(struct ibmvnic_adapter *adapter)
324{
325 int i;
326
Thomas Falcon032c5e82015-12-21 11:26:06 -0600327 adapter->replenish_task_cycles++;
328 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
329 i++) {
330 if (adapter->rx_pool[i].active)
331 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
332 }
333}
334
Nathan Fontenot7bbc27a2017-03-30 02:49:23 -0400335static void release_stats_token(struct ibmvnic_adapter *adapter)
336{
337 struct device *dev = &adapter->vdev->dev;
338
339 if (!adapter->stats_token)
340 return;
341
342 dma_unmap_single(dev, adapter->stats_token,
343 sizeof(struct ibmvnic_statistics),
344 DMA_FROM_DEVICE);
345 adapter->stats_token = 0;
346}
347
348static int init_stats_token(struct ibmvnic_adapter *adapter)
349{
350 struct device *dev = &adapter->vdev->dev;
351 dma_addr_t stok;
352
353 stok = dma_map_single(dev, &adapter->stats,
354 sizeof(struct ibmvnic_statistics),
355 DMA_FROM_DEVICE);
356 if (dma_mapping_error(dev, stok)) {
357 dev_err(dev, "Couldn't map stats buffer\n");
358 return -1;
359 }
360
361 adapter->stats_token = stok;
362 return 0;
363}
364
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400365static int reset_rx_pools(struct ibmvnic_adapter *adapter)
366{
367 struct ibmvnic_rx_pool *rx_pool;
368 int rx_scrqs;
369 int i, j;
370
371 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
372 for (i = 0; i < rx_scrqs; i++) {
373 rx_pool = &adapter->rx_pool[i];
374
375 reset_long_term_buff(adapter, &rx_pool->long_term_buff);
376
377 for (j = 0; j < rx_pool->size; j++)
378 rx_pool->free_map[j] = j;
379
380 memset(rx_pool->rx_buff, 0,
381 rx_pool->size * sizeof(struct ibmvnic_rx_buff));
382
383 atomic_set(&rx_pool->available, 0);
384 rx_pool->next_alloc = 0;
385 rx_pool->next_free = 0;
Thomas Falconc3e53b92017-06-14 23:50:05 -0500386 rx_pool->active = 1;
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400387 }
388
389 return 0;
390}
391
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400392static void release_rx_pools(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600393{
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400394 struct ibmvnic_rx_pool *rx_pool;
395 int rx_scrqs;
396 int i, j;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600397
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400398 if (!adapter->rx_pool)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600399 return;
400
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400401 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
402 for (i = 0; i < rx_scrqs; i++) {
403 rx_pool = &adapter->rx_pool[i];
404
405 kfree(rx_pool->free_map);
406 free_long_term_buff(adapter, &rx_pool->long_term_buff);
407
408 if (!rx_pool->rx_buff)
Nathan Fontenote0ebe9422017-05-03 14:04:50 -0400409 continue;
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400410
411 for (j = 0; j < rx_pool->size; j++) {
412 if (rx_pool->rx_buff[j].skb) {
413 dev_kfree_skb_any(rx_pool->rx_buff[i].skb);
414 rx_pool->rx_buff[i].skb = NULL;
415 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600416 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400417
418 kfree(rx_pool->rx_buff);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600419 }
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400420
421 kfree(adapter->rx_pool);
422 adapter->rx_pool = NULL;
423}
424
425static int init_rx_pools(struct net_device *netdev)
426{
427 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
428 struct device *dev = &adapter->vdev->dev;
429 struct ibmvnic_rx_pool *rx_pool;
430 int rxadd_subcrqs;
431 u64 *size_array;
432 int i, j;
433
434 rxadd_subcrqs =
435 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
436 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
437 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
438
439 adapter->rx_pool = kcalloc(rxadd_subcrqs,
440 sizeof(struct ibmvnic_rx_pool),
441 GFP_KERNEL);
442 if (!adapter->rx_pool) {
443 dev_err(dev, "Failed to allocate rx pools\n");
444 return -1;
445 }
446
447 for (i = 0; i < rxadd_subcrqs; i++) {
448 rx_pool = &adapter->rx_pool[i];
449
450 netdev_dbg(adapter->netdev,
451 "Initializing rx_pool %d, %lld buffs, %lld bytes each\n",
452 i, adapter->req_rx_add_entries_per_subcrq,
453 be64_to_cpu(size_array[i]));
454
455 rx_pool->size = adapter->req_rx_add_entries_per_subcrq;
456 rx_pool->index = i;
457 rx_pool->buff_size = be64_to_cpu(size_array[i]);
458 rx_pool->active = 1;
459
460 rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int),
461 GFP_KERNEL);
462 if (!rx_pool->free_map) {
463 release_rx_pools(adapter);
464 return -1;
465 }
466
467 rx_pool->rx_buff = kcalloc(rx_pool->size,
468 sizeof(struct ibmvnic_rx_buff),
469 GFP_KERNEL);
470 if (!rx_pool->rx_buff) {
471 dev_err(dev, "Couldn't alloc rx buffers\n");
472 release_rx_pools(adapter);
473 return -1;
474 }
475
476 if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
477 rx_pool->size * rx_pool->buff_size)) {
478 release_rx_pools(adapter);
479 return -1;
480 }
481
482 for (j = 0; j < rx_pool->size; ++j)
483 rx_pool->free_map[j] = j;
484
485 atomic_set(&rx_pool->available, 0);
486 rx_pool->next_alloc = 0;
487 rx_pool->next_free = 0;
488 }
489
490 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600491}
492
Nathan Fontenot8c0543a2017-05-26 10:31:06 -0400493static int reset_tx_pools(struct ibmvnic_adapter *adapter)
494{
495 struct ibmvnic_tx_pool *tx_pool;
496 int tx_scrqs;
497 int i, j;
498
499 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
500 for (i = 0; i < tx_scrqs; i++) {
501 tx_pool = &adapter->tx_pool[i];
502
503 reset_long_term_buff(adapter, &tx_pool->long_term_buff);
504
505 memset(tx_pool->tx_buff, 0,
506 adapter->req_tx_entries_per_subcrq *
507 sizeof(struct ibmvnic_tx_buff));
508
509 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
510 tx_pool->free_map[j] = j;
511
512 tx_pool->consumer_index = 0;
513 tx_pool->producer_index = 0;
514 }
515
516 return 0;
517}
518
Nathan Fontenotc657e322017-03-30 02:49:06 -0400519static void release_tx_pools(struct ibmvnic_adapter *adapter)
520{
521 struct ibmvnic_tx_pool *tx_pool;
522 int i, tx_scrqs;
523
524 if (!adapter->tx_pool)
525 return;
526
527 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
528 for (i = 0; i < tx_scrqs; i++) {
529 tx_pool = &adapter->tx_pool[i];
530 kfree(tx_pool->tx_buff);
531 free_long_term_buff(adapter, &tx_pool->long_term_buff);
532 kfree(tx_pool->free_map);
533 }
534
535 kfree(adapter->tx_pool);
536 adapter->tx_pool = NULL;
537}
538
539static int init_tx_pools(struct net_device *netdev)
540{
541 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
542 struct device *dev = &adapter->vdev->dev;
543 struct ibmvnic_tx_pool *tx_pool;
544 int tx_subcrqs;
545 int i, j;
546
547 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
548 adapter->tx_pool = kcalloc(tx_subcrqs,
549 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
550 if (!adapter->tx_pool)
551 return -1;
552
553 for (i = 0; i < tx_subcrqs; i++) {
554 tx_pool = &adapter->tx_pool[i];
555 tx_pool->tx_buff = kcalloc(adapter->req_tx_entries_per_subcrq,
556 sizeof(struct ibmvnic_tx_buff),
557 GFP_KERNEL);
558 if (!tx_pool->tx_buff) {
559 dev_err(dev, "tx pool buffer allocation failed\n");
560 release_tx_pools(adapter);
561 return -1;
562 }
563
564 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
565 adapter->req_tx_entries_per_subcrq *
566 adapter->req_mtu)) {
567 release_tx_pools(adapter);
568 return -1;
569 }
570
571 tx_pool->free_map = kcalloc(adapter->req_tx_entries_per_subcrq,
572 sizeof(int), GFP_KERNEL);
573 if (!tx_pool->free_map) {
574 release_tx_pools(adapter);
575 return -1;
576 }
577
578 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
579 tx_pool->free_map[j] = j;
580
581 tx_pool->consumer_index = 0;
582 tx_pool->producer_index = 0;
583 }
584
585 return 0;
586}
587
Nathan Fontenot661a2622017-04-19 13:44:58 -0400588static void release_error_buffers(struct ibmvnic_adapter *adapter)
589{
590 struct device *dev = &adapter->vdev->dev;
591 struct ibmvnic_error_buff *error_buff, *tmp;
592 unsigned long flags;
593
594 spin_lock_irqsave(&adapter->error_list_lock, flags);
595 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) {
596 list_del(&error_buff->list);
597 dma_unmap_single(dev, error_buff->dma, error_buff->len,
598 DMA_FROM_DEVICE);
599 kfree(error_buff->buff);
600 kfree(error_buff);
601 }
602 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
603}
604
John Allend944c3d62017-05-26 10:30:13 -0400605static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter)
606{
607 int i;
608
609 if (adapter->napi_enabled)
610 return;
611
612 for (i = 0; i < adapter->req_rx_queues; i++)
613 napi_enable(&adapter->napi[i]);
614
615 adapter->napi_enabled = true;
616}
617
618static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter)
619{
620 int i;
621
622 if (!adapter->napi_enabled)
623 return;
624
625 for (i = 0; i < adapter->req_rx_queues; i++)
626 napi_disable(&adapter->napi[i]);
627
628 adapter->napi_enabled = false;
629}
630
John Allena57a5d22017-03-17 17:13:41 -0500631static int ibmvnic_login(struct net_device *netdev)
Thomas Falcon032c5e82015-12-21 11:26:06 -0600632{
633 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
John Allenbd0b6722017-03-17 17:13:40 -0500634 unsigned long timeout = msecs_to_jiffies(30000);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600635 struct device *dev = &adapter->vdev->dev;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600636
John Allenbd0b6722017-03-17 17:13:40 -0500637 do {
638 if (adapter->renegotiate) {
639 adapter->renegotiate = false;
Nathan Fontenotb5108882017-03-30 02:49:18 -0400640 release_sub_crqs(adapter);
John Allenbd0b6722017-03-17 17:13:40 -0500641
642 reinit_completion(&adapter->init_done);
643 send_cap_queries(adapter);
644 if (!wait_for_completion_timeout(&adapter->init_done,
645 timeout)) {
646 dev_err(dev, "Capabilities query timeout\n");
647 return -1;
648 }
649 }
650
651 reinit_completion(&adapter->init_done);
652 send_login(adapter);
653 if (!wait_for_completion_timeout(&adapter->init_done,
654 timeout)) {
655 dev_err(dev, "Login timeout\n");
656 return -1;
657 }
658 } while (adapter->renegotiate);
659
John Allena57a5d22017-03-17 17:13:41 -0500660 return 0;
661}
662
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400663static void release_resources(struct ibmvnic_adapter *adapter)
664{
Nathan Fontenotc7bac002017-05-03 14:04:44 -0400665 int i;
666
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400667 release_tx_pools(adapter);
668 release_rx_pools(adapter);
669
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400670 release_stats_token(adapter);
Nathan Fontenot661a2622017-04-19 13:44:58 -0400671 release_error_buffers(adapter);
Nathan Fontenotc7bac002017-05-03 14:04:44 -0400672
673 if (adapter->napi) {
674 for (i = 0; i < adapter->req_rx_queues; i++) {
675 if (&adapter->napi[i])
676 netif_napi_del(&adapter->napi[i]);
677 }
678 }
Nathan Fontenot1b8955e2017-03-30 02:49:29 -0400679}
680
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400681static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
682{
683 struct net_device *netdev = adapter->netdev;
684 unsigned long timeout = msecs_to_jiffies(30000);
685 union ibmvnic_crq crq;
686 bool resend;
687 int rc;
688
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400689 netdev_err(netdev, "setting link state %d\n", link_state);
690 memset(&crq, 0, sizeof(crq));
691 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
692 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
693 crq.logical_link_state.link_state = link_state;
694
695 do {
696 resend = false;
697
698 reinit_completion(&adapter->init_done);
699 rc = ibmvnic_send_crq(adapter, &crq);
700 if (rc) {
701 netdev_err(netdev, "Failed to set link state\n");
702 return rc;
703 }
704
705 if (!wait_for_completion_timeout(&adapter->init_done,
706 timeout)) {
707 netdev_err(netdev, "timeout setting link state\n");
708 return -1;
709 }
710
711 if (adapter->init_done_rc == 1) {
712 /* Partuial success, delay and re-send */
713 mdelay(1000);
714 resend = true;
715 }
716 } while (resend);
717
718 return 0;
719}
720
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400721static int set_real_num_queues(struct net_device *netdev)
722{
723 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
724 int rc;
725
726 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
727 if (rc) {
728 netdev_err(netdev, "failed to set the number of tx queues\n");
729 return rc;
730 }
731
732 rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues);
733 if (rc)
734 netdev_err(netdev, "failed to set the number of rx queues\n");
735
736 return rc;
737}
738
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400739static int init_resources(struct ibmvnic_adapter *adapter)
John Allena57a5d22017-03-17 17:13:41 -0500740{
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400741 struct net_device *netdev = adapter->netdev;
742 int i, rc;
John Allena57a5d22017-03-17 17:13:41 -0500743
Thomas Falcon7f3c6e62017-04-21 15:38:40 -0400744 rc = set_real_num_queues(netdev);
745 if (rc)
746 return rc;
John Allenbd0b6722017-03-17 17:13:40 -0500747
748 rc = init_sub_crq_irqs(adapter);
749 if (rc) {
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400750 netdev_err(netdev, "failed to initialize sub crq irqs\n");
John Allenbd0b6722017-03-17 17:13:40 -0500751 return -1;
752 }
753
Nathan Fontenot5d5e84e2017-04-21 15:38:58 -0400754 rc = init_stats_token(adapter);
755 if (rc)
756 return rc;
757
Thomas Falcon032c5e82015-12-21 11:26:06 -0600758 adapter->map_id = 1;
759 adapter->napi = kcalloc(adapter->req_rx_queues,
760 sizeof(struct napi_struct), GFP_KERNEL);
761 if (!adapter->napi)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400762 return -ENOMEM;
763
Thomas Falcon032c5e82015-12-21 11:26:06 -0600764 for (i = 0; i < adapter->req_rx_queues; i++) {
765 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
766 NAPI_POLL_WEIGHT);
Thomas Falcon032c5e82015-12-21 11:26:06 -0600767 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600768
Thomas Falcon032c5e82015-12-21 11:26:06 -0600769 send_map_query(adapter);
Nathan Fontenot0ffe2cb2017-03-30 02:49:12 -0400770
771 rc = init_rx_pools(netdev);
772 if (rc)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400773 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600774
Nathan Fontenotc657e322017-03-30 02:49:06 -0400775 rc = init_tx_pools(netdev);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400776 return rc;
777}
778
Nathan Fontenoted651a12017-05-03 14:04:38 -0400779static int __ibmvnic_open(struct net_device *netdev)
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400780{
781 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -0400782 enum vnic_state prev_state = adapter->state;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400783 int i, rc;
784
Nathan Fontenot90c80142017-05-03 14:04:32 -0400785 adapter->state = VNIC_OPENING;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600786 replenish_pools(adapter);
John Allend944c3d62017-05-26 10:30:13 -0400787 ibmvnic_napi_enable(adapter);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400788
Thomas Falcon032c5e82015-12-21 11:26:06 -0600789 /* We're ready to receive frames, enable the sub-crq interrupts and
790 * set the logical link state to up
791 */
Nathan Fontenoted651a12017-05-03 14:04:38 -0400792 for (i = 0; i < adapter->req_rx_queues; i++) {
793 if (prev_state == VNIC_CLOSED)
794 enable_irq(adapter->rx_scrq[i]->irq);
795 else
796 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
797 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600798
Nathan Fontenoted651a12017-05-03 14:04:38 -0400799 for (i = 0; i < adapter->req_tx_queues; i++) {
800 if (prev_state == VNIC_CLOSED)
801 enable_irq(adapter->tx_scrq[i]->irq);
802 else
803 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
804 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600805
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400806 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP);
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400807 if (rc) {
808 for (i = 0; i < adapter->req_rx_queues; i++)
809 napi_disable(&adapter->napi[i]);
810 release_resources(adapter);
Nathan Fontenoted651a12017-05-03 14:04:38 -0400811 return rc;
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400812 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600813
Nathan Fontenoted651a12017-05-03 14:04:38 -0400814 netif_tx_start_all_queues(netdev);
815
816 if (prev_state == VNIC_CLOSED) {
817 for (i = 0; i < adapter->req_rx_queues; i++)
818 napi_schedule(&adapter->napi[i]);
819 }
820
821 adapter->state = VNIC_OPEN;
822 return rc;
823}
824
825static int ibmvnic_open(struct net_device *netdev)
826{
827 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
828 int rc;
829
830 mutex_lock(&adapter->reset_lock);
831
832 if (adapter->state != VNIC_CLOSED) {
833 rc = ibmvnic_login(netdev);
834 if (rc) {
835 mutex_unlock(&adapter->reset_lock);
836 return rc;
837 }
838
839 rc = init_resources(adapter);
840 if (rc) {
841 netdev_err(netdev, "failed to initialize resources\n");
842 release_resources(adapter);
843 mutex_unlock(&adapter->reset_lock);
844 return rc;
845 }
846 }
847
848 rc = __ibmvnic_open(netdev);
849 mutex_unlock(&adapter->reset_lock);
850
Nathan Fontenotbfc32f22017-05-03 14:04:26 -0400851 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600852}
853
Nathan Fontenotb41b83e2017-05-03 14:04:56 -0400854static void clean_tx_pools(struct ibmvnic_adapter *adapter)
855{
856 struct ibmvnic_tx_pool *tx_pool;
857 u64 tx_entries;
858 int tx_scrqs;
859 int i, j;
860
861 if (!adapter->tx_pool)
862 return;
863
864 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
865 tx_entries = adapter->req_tx_entries_per_subcrq;
866
867 /* Free any remaining skbs in the tx buffer pools */
868 for (i = 0; i < tx_scrqs; i++) {
869 tx_pool = &adapter->tx_pool[i];
870 if (!tx_pool)
871 continue;
872
873 for (j = 0; j < tx_entries; j++) {
874 if (tx_pool->tx_buff[j].skb) {
875 dev_kfree_skb_any(tx_pool->tx_buff[j].skb);
876 tx_pool->tx_buff[j].skb = NULL;
877 }
878 }
879 }
880}
881
Nathan Fontenoted651a12017-05-03 14:04:38 -0400882static int __ibmvnic_close(struct net_device *netdev)
John Allenea5509f2017-03-17 17:13:43 -0500883{
884 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400885 int rc = 0;
John Allenea5509f2017-03-17 17:13:43 -0500886 int i;
887
Nathan Fontenot90c80142017-05-03 14:04:32 -0400888 adapter->state = VNIC_CLOSING;
Nathan Fontenoted651a12017-05-03 14:04:38 -0400889 netif_tx_stop_all_queues(netdev);
John Allend944c3d62017-05-26 10:30:13 -0400890 ibmvnic_napi_disable(adapter);
Nathan Fontenot46293b92017-05-03 14:05:02 -0400891
892 if (adapter->tx_scrq) {
893 for (i = 0; i < adapter->req_tx_queues; i++)
894 if (adapter->tx_scrq[i]->irq)
895 disable_irq(adapter->tx_scrq[i]->irq);
896 }
897
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400898 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
Nathan Fontenot46293b92017-05-03 14:05:02 -0400899 if (rc)
900 return rc;
901
902 if (adapter->rx_scrq) {
903 for (i = 0; i < adapter->req_rx_queues; i++) {
904 int retries = 10;
905
906 while (pending_scrq(adapter, adapter->rx_scrq[i])) {
907 retries--;
908 mdelay(100);
909
910 if (retries == 0)
911 break;
912 }
913
914 if (adapter->rx_scrq[i]->irq)
915 disable_irq(adapter->rx_scrq[i]->irq);
916 }
917 }
Thomas Falcon032c5e82015-12-21 11:26:06 -0600918
Thomas Falcon10f76212017-05-26 10:30:31 -0400919 clean_tx_pools(adapter);
Nathan Fontenot90c80142017-05-03 14:04:32 -0400920 adapter->state = VNIC_CLOSED;
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400921 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600922}
923
Nathan Fontenoted651a12017-05-03 14:04:38 -0400924static int ibmvnic_close(struct net_device *netdev)
925{
926 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
927 int rc;
928
929 mutex_lock(&adapter->reset_lock);
930 rc = __ibmvnic_close(netdev);
931 mutex_unlock(&adapter->reset_lock);
932
933 return rc;
934}
935
Thomas Falconad7775d2016-04-01 17:20:34 -0500936/**
937 * build_hdr_data - creates L2/L3/L4 header data buffer
938 * @hdr_field - bitfield determining needed headers
939 * @skb - socket buffer
940 * @hdr_len - array of header lengths
941 * @tot_len - total length of data
942 *
943 * Reads hdr_field to determine which headers are needed by firmware.
944 * Builds a buffer containing these headers. Saves individual header
945 * lengths and total buffer length to be used to build descriptors.
946 */
947static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
948 int *hdr_len, u8 *hdr_data)
949{
950 int len = 0;
951 u8 *hdr;
952
953 hdr_len[0] = sizeof(struct ethhdr);
954
955 if (skb->protocol == htons(ETH_P_IP)) {
956 hdr_len[1] = ip_hdr(skb)->ihl * 4;
957 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
958 hdr_len[2] = tcp_hdrlen(skb);
959 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
960 hdr_len[2] = sizeof(struct udphdr);
961 } else if (skb->protocol == htons(ETH_P_IPV6)) {
962 hdr_len[1] = sizeof(struct ipv6hdr);
963 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
964 hdr_len[2] = tcp_hdrlen(skb);
965 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
966 hdr_len[2] = sizeof(struct udphdr);
967 }
968
969 memset(hdr_data, 0, 120);
970 if ((hdr_field >> 6) & 1) {
971 hdr = skb_mac_header(skb);
972 memcpy(hdr_data, hdr, hdr_len[0]);
973 len += hdr_len[0];
974 }
975
976 if ((hdr_field >> 5) & 1) {
977 hdr = skb_network_header(skb);
978 memcpy(hdr_data + len, hdr, hdr_len[1]);
979 len += hdr_len[1];
980 }
981
982 if ((hdr_field >> 4) & 1) {
983 hdr = skb_transport_header(skb);
984 memcpy(hdr_data + len, hdr, hdr_len[2]);
985 len += hdr_len[2];
986 }
987 return len;
988}
989
990/**
991 * create_hdr_descs - create header and header extension descriptors
992 * @hdr_field - bitfield determining needed headers
993 * @data - buffer containing header data
994 * @len - length of data buffer
995 * @hdr_len - array of individual header lengths
996 * @scrq_arr - descriptor array
997 *
998 * Creates header and, if needed, header extension descriptors and
999 * places them in a descriptor array, scrq_arr
1000 */
1001
1002static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
1003 union sub_crq *scrq_arr)
1004{
1005 union sub_crq hdr_desc;
1006 int tmp_len = len;
1007 u8 *data, *cur;
1008 int tmp;
1009
1010 while (tmp_len > 0) {
1011 cur = hdr_data + len - tmp_len;
1012
1013 memset(&hdr_desc, 0, sizeof(hdr_desc));
1014 if (cur != hdr_data) {
1015 data = hdr_desc.hdr_ext.data;
1016 tmp = tmp_len > 29 ? 29 : tmp_len;
1017 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
1018 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
1019 hdr_desc.hdr_ext.len = tmp;
1020 } else {
1021 data = hdr_desc.hdr.data;
1022 tmp = tmp_len > 24 ? 24 : tmp_len;
1023 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
1024 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
1025 hdr_desc.hdr.len = tmp;
1026 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
1027 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
1028 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
1029 hdr_desc.hdr.flag = hdr_field << 1;
1030 }
1031 memcpy(data, cur, tmp);
1032 tmp_len -= tmp;
1033 *scrq_arr = hdr_desc;
1034 scrq_arr++;
1035 }
1036}
1037
1038/**
1039 * build_hdr_descs_arr - build a header descriptor array
1040 * @skb - socket buffer
1041 * @num_entries - number of descriptors to be sent
1042 * @subcrq - first TX descriptor
1043 * @hdr_field - bit field determining which headers will be sent
1044 *
1045 * This function will build a TX descriptor array with applicable
1046 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
1047 */
1048
1049static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
1050 int *num_entries, u8 hdr_field)
1051{
1052 int hdr_len[3] = {0, 0, 0};
1053 int tot_len, len;
1054 u8 *hdr_data = txbuff->hdr_data;
1055
1056 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
1057 txbuff->hdr_data);
1058 len = tot_len;
1059 len -= 24;
1060 if (len > 0)
1061 num_entries += len % 29 ? len / 29 + 1 : len / 29;
1062 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
1063 txbuff->indir_arr + 1);
1064}
1065
Thomas Falcon032c5e82015-12-21 11:26:06 -06001066static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
1067{
1068 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1069 int queue_num = skb_get_queue_mapping(skb);
Thomas Falconad7775d2016-04-01 17:20:34 -05001070 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001071 struct device *dev = &adapter->vdev->dev;
1072 struct ibmvnic_tx_buff *tx_buff = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001073 struct ibmvnic_sub_crq_queue *tx_scrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001074 struct ibmvnic_tx_pool *tx_pool;
1075 unsigned int tx_send_failed = 0;
1076 unsigned int tx_map_failed = 0;
1077 unsigned int tx_dropped = 0;
1078 unsigned int tx_packets = 0;
1079 unsigned int tx_bytes = 0;
1080 dma_addr_t data_dma_addr;
1081 struct netdev_queue *txq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001082 unsigned long lpar_rc;
1083 union sub_crq tx_crq;
1084 unsigned int offset;
Thomas Falconad7775d2016-04-01 17:20:34 -05001085 int num_entries = 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001086 unsigned char *dst;
1087 u64 *handle_array;
1088 int index = 0;
1089 int ret = 0;
1090
Nathan Fontenoted651a12017-05-03 14:04:38 -04001091 if (adapter->resetting) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001092 if (!netif_subqueue_stopped(netdev, skb))
1093 netif_stop_subqueue(netdev, queue_num);
1094 dev_kfree_skb_any(skb);
1095
Thomas Falcon032c5e82015-12-21 11:26:06 -06001096 tx_send_failed++;
1097 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001098 ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001099 goto out;
1100 }
1101
Nathan Fontenot161b8a82017-05-03 14:05:08 -04001102 tx_pool = &adapter->tx_pool[queue_num];
1103 tx_scrq = adapter->tx_scrq[queue_num];
1104 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
1105 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
1106 be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs));
1107
Thomas Falcon032c5e82015-12-21 11:26:06 -06001108 index = tx_pool->free_map[tx_pool->consumer_index];
1109 offset = index * adapter->req_mtu;
1110 dst = tx_pool->long_term_buff.buff + offset;
1111 memset(dst, 0, adapter->req_mtu);
1112 skb_copy_from_linear_data(skb, dst, skb->len);
1113 data_dma_addr = tx_pool->long_term_buff.addr + offset;
1114
1115 tx_pool->consumer_index =
1116 (tx_pool->consumer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001117 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001118
1119 tx_buff = &tx_pool->tx_buff[index];
1120 tx_buff->skb = skb;
1121 tx_buff->data_dma[0] = data_dma_addr;
1122 tx_buff->data_len[0] = skb->len;
1123 tx_buff->index = index;
1124 tx_buff->pool_index = queue_num;
1125 tx_buff->last_frag = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001126
1127 memset(&tx_crq, 0, sizeof(tx_crq));
1128 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
1129 tx_crq.v1.type = IBMVNIC_TX_DESC;
1130 tx_crq.v1.n_crq_elem = 1;
1131 tx_crq.v1.n_sge = 1;
1132 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
1133 tx_crq.v1.correlator = cpu_to_be32(index);
1134 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
1135 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
1136 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
1137
1138 if (adapter->vlan_header_insertion) {
1139 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
1140 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
1141 }
1142
1143 if (skb->protocol == htons(ETH_P_IP)) {
1144 if (ip_hdr(skb)->version == 4)
1145 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
1146 else if (ip_hdr(skb)->version == 6)
1147 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
1148
1149 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1150 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
1151 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
1152 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
1153 }
1154
Thomas Falconad7775d2016-04-01 17:20:34 -05001155 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001156 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
Thomas Falconad7775d2016-04-01 17:20:34 -05001157 hdrs += 2;
1158 }
1159 /* determine if l2/3/4 headers are sent to firmware */
1160 if ((*hdrs >> 7) & 1 &&
1161 (skb->protocol == htons(ETH_P_IP) ||
1162 skb->protocol == htons(ETH_P_IPV6))) {
1163 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
1164 tx_crq.v1.n_crq_elem = num_entries;
1165 tx_buff->indir_arr[0] = tx_crq;
1166 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
1167 sizeof(tx_buff->indir_arr),
1168 DMA_TO_DEVICE);
1169 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001170 dev_kfree_skb_any(skb);
1171 tx_buff->skb = NULL;
Thomas Falconad7775d2016-04-01 17:20:34 -05001172 if (!firmware_has_feature(FW_FEATURE_CMO))
1173 dev_err(dev, "tx: unable to map descriptor array\n");
1174 tx_map_failed++;
1175 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001176 ret = NETDEV_TX_OK;
Thomas Falconad7775d2016-04-01 17:20:34 -05001177 goto out;
1178 }
John Allen498cd8e2016-04-06 11:49:55 -05001179 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
Thomas Falconad7775d2016-04-01 17:20:34 -05001180 (u64)tx_buff->indir_dma,
1181 (u64)num_entries);
1182 } else {
John Allen498cd8e2016-04-06 11:49:55 -05001183 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
1184 &tx_crq);
Thomas Falconad7775d2016-04-01 17:20:34 -05001185 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001186 if (lpar_rc != H_SUCCESS) {
1187 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
1188
1189 if (tx_pool->consumer_index == 0)
1190 tx_pool->consumer_index =
Thomas Falcon068d9f92017-03-05 12:18:42 -06001191 adapter->req_tx_entries_per_subcrq - 1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001192 else
1193 tx_pool->consumer_index--;
1194
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001195 dev_kfree_skb_any(skb);
1196 tx_buff->skb = NULL;
1197
Thomas Falconb8c80b82017-05-26 10:30:42 -04001198 if (lpar_rc == H_CLOSED) {
1199 /* Disable TX and report carrier off if queue is closed.
1200 * Firmware guarantees that a signal will be sent to the
1201 * driver, triggering a reset or some other action.
1202 */
1203 netif_tx_stop_all_queues(netdev);
1204 netif_carrier_off(netdev);
1205 }
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001206
Thomas Falcon032c5e82015-12-21 11:26:06 -06001207 tx_send_failed++;
1208 tx_dropped++;
Thomas Falcon7f5b0302017-04-21 15:39:16 -04001209 ret = NETDEV_TX_OK;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001210 goto out;
1211 }
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001212
Brian King58c8c0c2017-04-19 13:44:47 -04001213 if (atomic_inc_return(&tx_scrq->used)
1214 >= adapter->req_tx_entries_per_subcrq) {
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001215 netdev_info(netdev, "Stopping queue %d\n", queue_num);
1216 netif_stop_subqueue(netdev, queue_num);
1217 }
1218
Thomas Falcon032c5e82015-12-21 11:26:06 -06001219 tx_packets++;
1220 tx_bytes += skb->len;
1221 txq->trans_start = jiffies;
1222 ret = NETDEV_TX_OK;
1223
1224out:
1225 netdev->stats.tx_dropped += tx_dropped;
1226 netdev->stats.tx_bytes += tx_bytes;
1227 netdev->stats.tx_packets += tx_packets;
1228 adapter->tx_send_failed += tx_send_failed;
1229 adapter->tx_map_failed += tx_map_failed;
1230
1231 return ret;
1232}
1233
1234static void ibmvnic_set_multi(struct net_device *netdev)
1235{
1236 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1237 struct netdev_hw_addr *ha;
1238 union ibmvnic_crq crq;
1239
1240 memset(&crq, 0, sizeof(crq));
1241 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1242 crq.request_capability.cmd = REQUEST_CAPABILITY;
1243
1244 if (netdev->flags & IFF_PROMISC) {
1245 if (!adapter->promisc_supported)
1246 return;
1247 } else {
1248 if (netdev->flags & IFF_ALLMULTI) {
1249 /* Accept all multicast */
1250 memset(&crq, 0, sizeof(crq));
1251 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1252 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1253 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1254 ibmvnic_send_crq(adapter, &crq);
1255 } else if (netdev_mc_empty(netdev)) {
1256 /* Reject all multicast */
1257 memset(&crq, 0, sizeof(crq));
1258 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1259 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1260 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1261 ibmvnic_send_crq(adapter, &crq);
1262 } else {
1263 /* Accept one or more multicast(s) */
1264 netdev_for_each_mc_addr(ha, netdev) {
1265 memset(&crq, 0, sizeof(crq));
1266 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1267 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1268 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1269 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1270 ha->addr);
1271 ibmvnic_send_crq(adapter, &crq);
1272 }
1273 }
1274 }
1275}
1276
1277static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1278{
1279 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1280 struct sockaddr *addr = p;
1281 union ibmvnic_crq crq;
1282
1283 if (!is_valid_ether_addr(addr->sa_data))
1284 return -EADDRNOTAVAIL;
1285
1286 memset(&crq, 0, sizeof(crq));
1287 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1288 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1289 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1290 ibmvnic_send_crq(adapter, &crq);
1291 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1292 return 0;
1293}
1294
Nathan Fontenoted651a12017-05-03 14:04:38 -04001295/**
1296 * do_reset returns zero if we are able to keep processing reset events, or
1297 * non-zero if we hit a fatal error and must halt.
1298 */
1299static int do_reset(struct ibmvnic_adapter *adapter,
1300 struct ibmvnic_rwi *rwi, u32 reset_state)
1301{
1302 struct net_device *netdev = adapter->netdev;
1303 int i, rc;
1304
1305 netif_carrier_off(netdev);
1306 adapter->reset_reason = rwi->reset_reason;
1307
1308 if (rwi->reset_reason == VNIC_RESET_MOBILITY) {
1309 rc = ibmvnic_reenable_crq_queue(adapter);
1310 if (rc)
1311 return 0;
1312 }
1313
1314 rc = __ibmvnic_close(netdev);
1315 if (rc)
1316 return rc;
1317
John Allen8cb31cf2017-05-26 10:30:37 -04001318 if (adapter->reset_reason != VNIC_RESET_NON_FATAL) {
1319 /* remove the closed state so when we call open it appears
1320 * we are coming from the probed state.
1321 */
Nathan Fontenoted651a12017-05-03 14:04:38 -04001322 adapter->state = VNIC_PROBED;
John Allen8cb31cf2017-05-26 10:30:37 -04001323
John Allen8cb31cf2017-05-26 10:30:37 -04001324 rc = ibmvnic_init(adapter);
1325 if (rc)
1326 return 0;
1327
1328 /* If the adapter was in PROBE state prior to the reset,
1329 * exit here.
1330 */
1331 if (reset_state == VNIC_PROBED)
1332 return 0;
1333
1334 rc = ibmvnic_login(netdev);
1335 if (rc) {
1336 adapter->state = VNIC_PROBED;
1337 return 0;
1338 }
1339
Nathan Fontenot8c0543a2017-05-26 10:31:06 -04001340 rc = reset_tx_pools(adapter);
1341 if (rc)
1342 return rc;
1343
1344 rc = reset_rx_pools(adapter);
John Allen8cb31cf2017-05-26 10:30:37 -04001345 if (rc)
1346 return rc;
1347
1348 if (reset_state == VNIC_CLOSED)
1349 return 0;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001350 }
1351
Nathan Fontenoted651a12017-05-03 14:04:38 -04001352 rc = __ibmvnic_open(netdev);
1353 if (rc) {
1354 if (list_empty(&adapter->rwi_list))
1355 adapter->state = VNIC_CLOSED;
1356 else
1357 adapter->state = reset_state;
1358
1359 return 0;
1360 }
1361
1362 netif_carrier_on(netdev);
1363
1364 /* kick napi */
1365 for (i = 0; i < adapter->req_rx_queues; i++)
1366 napi_schedule(&adapter->napi[i]);
1367
Nathan Fontenot61d3e1d2017-06-12 20:47:45 -04001368 if (adapter->reset_reason != VNIC_RESET_FAILOVER)
1369 netdev_notify_peers(netdev);
1370
Nathan Fontenoted651a12017-05-03 14:04:38 -04001371 return 0;
1372}
1373
1374static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter)
1375{
1376 struct ibmvnic_rwi *rwi;
1377
1378 mutex_lock(&adapter->rwi_lock);
1379
1380 if (!list_empty(&adapter->rwi_list)) {
1381 rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi,
1382 list);
1383 list_del(&rwi->list);
1384 } else {
1385 rwi = NULL;
1386 }
1387
1388 mutex_unlock(&adapter->rwi_lock);
1389 return rwi;
1390}
1391
1392static void free_all_rwi(struct ibmvnic_adapter *adapter)
1393{
1394 struct ibmvnic_rwi *rwi;
1395
1396 rwi = get_next_rwi(adapter);
1397 while (rwi) {
1398 kfree(rwi);
1399 rwi = get_next_rwi(adapter);
1400 }
1401}
1402
1403static void __ibmvnic_reset(struct work_struct *work)
1404{
1405 struct ibmvnic_rwi *rwi;
1406 struct ibmvnic_adapter *adapter;
1407 struct net_device *netdev;
1408 u32 reset_state;
1409 int rc;
1410
1411 adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);
1412 netdev = adapter->netdev;
1413
1414 mutex_lock(&adapter->reset_lock);
1415 adapter->resetting = true;
1416 reset_state = adapter->state;
1417
1418 rwi = get_next_rwi(adapter);
1419 while (rwi) {
1420 rc = do_reset(adapter, rwi, reset_state);
1421 kfree(rwi);
1422 if (rc)
1423 break;
1424
1425 rwi = get_next_rwi(adapter);
1426 }
1427
1428 if (rc) {
1429 free_all_rwi(adapter);
Wei Yongjun6d0af072017-05-18 15:24:52 +00001430 mutex_unlock(&adapter->reset_lock);
Nathan Fontenoted651a12017-05-03 14:04:38 -04001431 return;
1432 }
1433
1434 adapter->resetting = false;
1435 mutex_unlock(&adapter->reset_lock);
1436}
1437
1438static void ibmvnic_reset(struct ibmvnic_adapter *adapter,
1439 enum ibmvnic_reset_reason reason)
1440{
1441 struct ibmvnic_rwi *rwi, *tmp;
1442 struct net_device *netdev = adapter->netdev;
1443 struct list_head *entry;
1444
1445 if (adapter->state == VNIC_REMOVING ||
1446 adapter->state == VNIC_REMOVED) {
1447 netdev_dbg(netdev, "Adapter removing, skipping reset\n");
1448 return;
1449 }
1450
1451 mutex_lock(&adapter->rwi_lock);
1452
1453 list_for_each(entry, &adapter->rwi_list) {
1454 tmp = list_entry(entry, struct ibmvnic_rwi, list);
1455 if (tmp->reset_reason == reason) {
1456 netdev_err(netdev, "Matching reset found, skipping\n");
1457 mutex_unlock(&adapter->rwi_lock);
1458 return;
1459 }
1460 }
1461
1462 rwi = kzalloc(sizeof(*rwi), GFP_KERNEL);
1463 if (!rwi) {
1464 mutex_unlock(&adapter->rwi_lock);
1465 ibmvnic_close(netdev);
1466 return;
1467 }
1468
1469 rwi->reset_reason = reason;
1470 list_add_tail(&rwi->list, &adapter->rwi_list);
1471 mutex_unlock(&adapter->rwi_lock);
1472 schedule_work(&adapter->ibmvnic_reset);
1473}
1474
Thomas Falcon032c5e82015-12-21 11:26:06 -06001475static void ibmvnic_tx_timeout(struct net_device *dev)
1476{
1477 struct ibmvnic_adapter *adapter = netdev_priv(dev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001478
Nathan Fontenoted651a12017-05-03 14:04:38 -04001479 ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001480}
1481
1482static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
1483 struct ibmvnic_rx_buff *rx_buff)
1484{
1485 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
1486
1487 rx_buff->skb = NULL;
1488
1489 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
1490 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
1491
1492 atomic_dec(&pool->available);
1493}
1494
1495static int ibmvnic_poll(struct napi_struct *napi, int budget)
1496{
1497 struct net_device *netdev = napi->dev;
1498 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1499 int scrq_num = (int)(napi - adapter->napi);
1500 int frames_processed = 0;
Nathan Fontenot152ce472017-05-26 10:30:54 -04001501
1502 if (adapter->resetting)
1503 return 0;
1504
Thomas Falcon032c5e82015-12-21 11:26:06 -06001505restart_poll:
1506 while (frames_processed < budget) {
1507 struct sk_buff *skb;
1508 struct ibmvnic_rx_buff *rx_buff;
1509 union sub_crq *next;
1510 u32 length;
1511 u16 offset;
1512 u8 flags = 0;
1513
1514 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
1515 break;
1516 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
1517 rx_buff =
1518 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
1519 rx_comp.correlator);
1520 /* do error checking */
1521 if (next->rx_comp.rc) {
1522 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
1523 /* free the entry */
1524 next->rx_comp.first = 0;
1525 remove_buff_from_pool(adapter, rx_buff);
Nathan Fontenotca05e312017-05-03 14:05:14 -04001526 continue;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001527 }
1528
1529 length = be32_to_cpu(next->rx_comp.len);
1530 offset = be16_to_cpu(next->rx_comp.off_frame_data);
1531 flags = next->rx_comp.flags;
1532 skb = rx_buff->skb;
1533 skb_copy_to_linear_data(skb, rx_buff->data + offset,
1534 length);
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04001535
1536 /* VLAN Header has been stripped by the system firmware and
1537 * needs to be inserted by the driver
1538 */
1539 if (adapter->rx_vlan_header_insertion &&
1540 (flags & IBMVNIC_VLAN_STRIPPED))
1541 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
1542 ntohs(next->rx_comp.vlan_tci));
1543
Thomas Falcon032c5e82015-12-21 11:26:06 -06001544 /* free the entry */
1545 next->rx_comp.first = 0;
1546 remove_buff_from_pool(adapter, rx_buff);
1547
1548 skb_put(skb, length);
1549 skb->protocol = eth_type_trans(skb, netdev);
Thomas Falcon94ca3052017-05-03 14:05:20 -04001550 skb_record_rx_queue(skb, scrq_num);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001551
1552 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
1553 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
1554 skb->ip_summed = CHECKSUM_UNNECESSARY;
1555 }
1556
1557 length = skb->len;
1558 napi_gro_receive(napi, skb); /* send it up */
1559 netdev->stats.rx_packets++;
1560 netdev->stats.rx_bytes += length;
1561 frames_processed++;
1562 }
Nathan Fontenot152ce472017-05-26 10:30:54 -04001563
1564 if (adapter->state != VNIC_CLOSING)
1565 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001566
1567 if (frames_processed < budget) {
1568 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
Eric Dumazet6ad20162017-01-30 08:22:01 -08001569 napi_complete_done(napi, frames_processed);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001570 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1571 napi_reschedule(napi)) {
1572 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1573 goto restart_poll;
1574 }
1575 }
1576 return frames_processed;
1577}
1578
1579#ifdef CONFIG_NET_POLL_CONTROLLER
1580static void ibmvnic_netpoll_controller(struct net_device *dev)
1581{
1582 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1583 int i;
1584
1585 replenish_pools(netdev_priv(dev));
1586 for (i = 0; i < adapter->req_rx_queues; i++)
1587 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1588 adapter->rx_scrq[i]);
1589}
1590#endif
1591
John Allen3a807b72017-06-06 16:55:52 -05001592static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu)
1593{
1594 return -EOPNOTSUPP;
1595}
1596
Thomas Falcon032c5e82015-12-21 11:26:06 -06001597static const struct net_device_ops ibmvnic_netdev_ops = {
1598 .ndo_open = ibmvnic_open,
1599 .ndo_stop = ibmvnic_close,
1600 .ndo_start_xmit = ibmvnic_xmit,
1601 .ndo_set_rx_mode = ibmvnic_set_multi,
1602 .ndo_set_mac_address = ibmvnic_set_mac,
1603 .ndo_validate_addr = eth_validate_addr,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001604 .ndo_tx_timeout = ibmvnic_tx_timeout,
1605#ifdef CONFIG_NET_POLL_CONTROLLER
1606 .ndo_poll_controller = ibmvnic_netpoll_controller,
1607#endif
John Allen3a807b72017-06-06 16:55:52 -05001608 .ndo_change_mtu = ibmvnic_change_mtu,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001609};
1610
1611/* ethtool functions */
1612
Philippe Reynes8a433792017-01-07 22:37:29 +01001613static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1614 struct ethtool_link_ksettings *cmd)
Thomas Falcon032c5e82015-12-21 11:26:06 -06001615{
Philippe Reynes8a433792017-01-07 22:37:29 +01001616 u32 supported, advertising;
1617
1618 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001619 SUPPORTED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001620 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
Thomas Falcon032c5e82015-12-21 11:26:06 -06001621 ADVERTISED_FIBRE);
Philippe Reynes8a433792017-01-07 22:37:29 +01001622 cmd->base.speed = SPEED_1000;
1623 cmd->base.duplex = DUPLEX_FULL;
1624 cmd->base.port = PORT_FIBRE;
1625 cmd->base.phy_address = 0;
1626 cmd->base.autoneg = AUTONEG_ENABLE;
1627
1628 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1629 supported);
1630 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1631 advertising);
1632
Thomas Falcon032c5e82015-12-21 11:26:06 -06001633 return 0;
1634}
1635
1636static void ibmvnic_get_drvinfo(struct net_device *dev,
1637 struct ethtool_drvinfo *info)
1638{
1639 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1640 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1641}
1642
1643static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1644{
1645 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1646
1647 return adapter->msg_enable;
1648}
1649
1650static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1651{
1652 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1653
1654 adapter->msg_enable = data;
1655}
1656
1657static u32 ibmvnic_get_link(struct net_device *netdev)
1658{
1659 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1660
1661 /* Don't need to send a query because we request a logical link up at
1662 * init and then we wait for link state indications
1663 */
1664 return adapter->logical_link_state;
1665}
1666
1667static void ibmvnic_get_ringparam(struct net_device *netdev,
1668 struct ethtool_ringparam *ring)
1669{
1670 ring->rx_max_pending = 0;
1671 ring->tx_max_pending = 0;
1672 ring->rx_mini_max_pending = 0;
1673 ring->rx_jumbo_max_pending = 0;
1674 ring->rx_pending = 0;
1675 ring->tx_pending = 0;
1676 ring->rx_mini_pending = 0;
1677 ring->rx_jumbo_pending = 0;
1678}
1679
1680static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1681{
1682 int i;
1683
1684 if (stringset != ETH_SS_STATS)
1685 return;
1686
1687 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1688 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1689}
1690
1691static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1692{
1693 switch (sset) {
1694 case ETH_SS_STATS:
1695 return ARRAY_SIZE(ibmvnic_stats);
1696 default:
1697 return -EOPNOTSUPP;
1698 }
1699}
1700
1701static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1702 struct ethtool_stats *stats, u64 *data)
1703{
1704 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1705 union ibmvnic_crq crq;
1706 int i;
1707
1708 memset(&crq, 0, sizeof(crq));
1709 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1710 crq.request_statistics.cmd = REQUEST_STATISTICS;
1711 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1712 crq.request_statistics.len =
1713 cpu_to_be32(sizeof(struct ibmvnic_statistics));
Thomas Falcon032c5e82015-12-21 11:26:06 -06001714
1715 /* Wait for data to be written */
1716 init_completion(&adapter->stats_done);
Nathan Fontenotdb5d0b52017-02-10 13:45:05 -05001717 ibmvnic_send_crq(adapter, &crq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001718 wait_for_completion(&adapter->stats_done);
1719
1720 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1721 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1722}
1723
1724static const struct ethtool_ops ibmvnic_ethtool_ops = {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001725 .get_drvinfo = ibmvnic_get_drvinfo,
1726 .get_msglevel = ibmvnic_get_msglevel,
1727 .set_msglevel = ibmvnic_set_msglevel,
1728 .get_link = ibmvnic_get_link,
1729 .get_ringparam = ibmvnic_get_ringparam,
1730 .get_strings = ibmvnic_get_strings,
1731 .get_sset_count = ibmvnic_get_sset_count,
1732 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
Philippe Reynes8a433792017-01-07 22:37:29 +01001733 .get_link_ksettings = ibmvnic_get_link_ksettings,
Thomas Falcon032c5e82015-12-21 11:26:06 -06001734};
1735
1736/* Routines for managing CRQs/sCRQs */
1737
Nathan Fontenot57a49432017-05-26 10:31:12 -04001738static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter,
1739 struct ibmvnic_sub_crq_queue *scrq)
1740{
1741 int rc;
1742
1743 if (scrq->irq) {
1744 free_irq(scrq->irq, scrq);
1745 irq_dispose_mapping(scrq->irq);
1746 scrq->irq = 0;
1747 }
1748
1749 memset(scrq->msgs, 0, 2 * PAGE_SIZE);
1750 scrq->cur = 0;
1751
1752 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1753 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1754 return rc;
1755}
1756
1757static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter)
1758{
1759 int i, rc;
1760
1761 for (i = 0; i < adapter->req_tx_queues; i++) {
1762 rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1763 if (rc)
1764 return rc;
1765 }
1766
1767 for (i = 0; i < adapter->req_rx_queues; i++) {
1768 rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1769 if (rc)
1770 return rc;
1771 }
1772
1773 rc = init_sub_crq_irqs(adapter);
1774 return rc;
1775}
1776
Thomas Falcon032c5e82015-12-21 11:26:06 -06001777static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1778 struct ibmvnic_sub_crq_queue *scrq)
1779{
1780 struct device *dev = &adapter->vdev->dev;
1781 long rc;
1782
1783 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1784
1785 /* Close the sub-crqs */
1786 do {
1787 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1788 adapter->vdev->unit_address,
1789 scrq->crq_num);
1790 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1791
Thomas Falconffa73852017-04-19 13:44:29 -04001792 if (rc) {
1793 netdev_err(adapter->netdev,
1794 "Failed to release sub-CRQ %16lx, rc = %ld\n",
1795 scrq->crq_num, rc);
1796 }
1797
Thomas Falcon032c5e82015-12-21 11:26:06 -06001798 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1799 DMA_BIDIRECTIONAL);
1800 free_pages((unsigned long)scrq->msgs, 2);
1801 kfree(scrq);
1802}
1803
1804static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1805 *adapter)
1806{
1807 struct device *dev = &adapter->vdev->dev;
1808 struct ibmvnic_sub_crq_queue *scrq;
1809 int rc;
1810
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04001811 scrq = kzalloc(sizeof(*scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001812 if (!scrq)
1813 return NULL;
1814
Nathan Fontenot7f7adc52017-04-19 13:45:16 -04001815 scrq->msgs =
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04001816 (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001817 if (!scrq->msgs) {
1818 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1819 goto zero_page_failed;
1820 }
1821
1822 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1823 DMA_BIDIRECTIONAL);
1824 if (dma_mapping_error(dev, scrq->msg_token)) {
1825 dev_warn(dev, "Couldn't map crq queue messages page\n");
1826 goto map_failed;
1827 }
1828
1829 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1830 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1831
1832 if (rc == H_RESOURCE)
1833 rc = ibmvnic_reset_crq(adapter);
1834
1835 if (rc == H_CLOSED) {
1836 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1837 } else if (rc) {
1838 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1839 goto reg_failed;
1840 }
1841
Thomas Falcon032c5e82015-12-21 11:26:06 -06001842 scrq->adapter = adapter;
1843 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001844 spin_lock_init(&scrq->lock);
1845
1846 netdev_dbg(adapter->netdev,
1847 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1848 scrq->crq_num, scrq->hw_irq, scrq->irq);
1849
1850 return scrq;
1851
Thomas Falcon032c5e82015-12-21 11:26:06 -06001852reg_failed:
1853 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1854 DMA_BIDIRECTIONAL);
1855map_failed:
1856 free_pages((unsigned long)scrq->msgs, 2);
1857zero_page_failed:
1858 kfree(scrq);
1859
1860 return NULL;
1861}
1862
1863static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1864{
1865 int i;
1866
1867 if (adapter->tx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001868 for (i = 0; i < adapter->req_tx_queues; i++) {
1869 if (!adapter->tx_scrq[i])
1870 continue;
1871
1872 if (adapter->tx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001873 free_irq(adapter->tx_scrq[i]->irq,
1874 adapter->tx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001875 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001876 adapter->tx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001877 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001878
1879 release_sub_crq_queue(adapter, adapter->tx_scrq[i]);
1880 }
1881
Nathan Fontenot9501df32017-03-15 23:38:07 -04001882 kfree(adapter->tx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001883 adapter->tx_scrq = NULL;
1884 }
1885
1886 if (adapter->rx_scrq) {
Nathan Fontenotb5108882017-03-30 02:49:18 -04001887 for (i = 0; i < adapter->req_rx_queues; i++) {
1888 if (!adapter->rx_scrq[i])
1889 continue;
1890
1891 if (adapter->rx_scrq[i]->irq) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001892 free_irq(adapter->rx_scrq[i]->irq,
1893 adapter->rx_scrq[i]);
Thomas Falcon88eb98a2016-07-06 15:35:16 -05001894 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
Nathan Fontenotb5108882017-03-30 02:49:18 -04001895 adapter->rx_scrq[i]->irq = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001896 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04001897
1898 release_sub_crq_queue(adapter, adapter->rx_scrq[i]);
1899 }
1900
Nathan Fontenot9501df32017-03-15 23:38:07 -04001901 kfree(adapter->rx_scrq);
Thomas Falcon032c5e82015-12-21 11:26:06 -06001902 adapter->rx_scrq = NULL;
1903 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001904}
1905
1906static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1907 struct ibmvnic_sub_crq_queue *scrq)
1908{
1909 struct device *dev = &adapter->vdev->dev;
1910 unsigned long rc;
1911
1912 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1913 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1914 if (rc)
1915 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1916 scrq->hw_irq, rc);
1917 return rc;
1918}
1919
1920static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1921 struct ibmvnic_sub_crq_queue *scrq)
1922{
1923 struct device *dev = &adapter->vdev->dev;
1924 unsigned long rc;
1925
1926 if (scrq->hw_irq > 0x100000000ULL) {
1927 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1928 return 1;
1929 }
1930
1931 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1932 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1933 if (rc)
1934 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1935 scrq->hw_irq, rc);
1936 return rc;
1937}
1938
1939static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1940 struct ibmvnic_sub_crq_queue *scrq)
1941{
1942 struct device *dev = &adapter->vdev->dev;
1943 struct ibmvnic_tx_buff *txbuff;
1944 union sub_crq *next;
1945 int index;
1946 int i, j;
Thomas Falconad7775d2016-04-01 17:20:34 -05001947 u8 first;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001948
1949restart_loop:
1950 while (pending_scrq(adapter, scrq)) {
1951 unsigned int pool = scrq->pool_index;
1952
1953 next = ibmvnic_next_scrq(adapter, scrq);
1954 for (i = 0; i < next->tx_comp.num_comps; i++) {
1955 if (next->tx_comp.rcs[i]) {
1956 dev_err(dev, "tx error %x\n",
1957 next->tx_comp.rcs[i]);
1958 continue;
1959 }
1960 index = be32_to_cpu(next->tx_comp.correlators[i]);
1961 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1962
1963 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1964 if (!txbuff->data_dma[j])
1965 continue;
1966
1967 txbuff->data_dma[j] = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001968 }
Thomas Falconad7775d2016-04-01 17:20:34 -05001969 /* if sub_crq was sent indirectly */
1970 first = txbuff->indir_arr[0].generic.first;
1971 if (first == IBMVNIC_CRQ_CMD) {
1972 dma_unmap_single(dev, txbuff->indir_dma,
1973 sizeof(txbuff->indir_arr),
1974 DMA_TO_DEVICE);
1975 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001976
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001977 if (txbuff->last_frag) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06001978 dev_kfree_skb_any(txbuff->skb);
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04001979 txbuff->skb = NULL;
Thomas Falcon142c0ac2017-03-05 12:18:41 -06001980 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001981
1982 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1983 producer_index] = index;
1984 adapter->tx_pool[pool].producer_index =
1985 (adapter->tx_pool[pool].producer_index + 1) %
Thomas Falcon068d9f92017-03-05 12:18:42 -06001986 adapter->req_tx_entries_per_subcrq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001987 }
1988 /* remove tx_comp scrq*/
1989 next->tx_comp.first = 0;
Nathan Fontenot7c3e7de2017-05-03 14:05:25 -04001990
1991 if (atomic_sub_return(next->tx_comp.num_comps, &scrq->used) <=
1992 (adapter->req_tx_entries_per_subcrq / 2) &&
1993 __netif_subqueue_stopped(adapter->netdev,
1994 scrq->pool_index)) {
1995 netif_wake_subqueue(adapter->netdev, scrq->pool_index);
1996 netdev_info(adapter->netdev, "Started queue %d\n",
1997 scrq->pool_index);
1998 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06001999 }
2000
2001 enable_scrq_irq(adapter, scrq);
2002
2003 if (pending_scrq(adapter, scrq)) {
2004 disable_scrq_irq(adapter, scrq);
2005 goto restart_loop;
2006 }
2007
2008 return 0;
2009}
2010
2011static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
2012{
2013 struct ibmvnic_sub_crq_queue *scrq = instance;
2014 struct ibmvnic_adapter *adapter = scrq->adapter;
2015
2016 disable_scrq_irq(adapter, scrq);
2017 ibmvnic_complete_tx(adapter, scrq);
2018
2019 return IRQ_HANDLED;
2020}
2021
2022static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
2023{
2024 struct ibmvnic_sub_crq_queue *scrq = instance;
2025 struct ibmvnic_adapter *adapter = scrq->adapter;
2026
2027 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
2028 disable_scrq_irq(adapter, scrq);
2029 __napi_schedule(&adapter->napi[scrq->scrq_num]);
2030 }
2031
2032 return IRQ_HANDLED;
2033}
2034
Thomas Falconea22d512016-07-06 15:35:17 -05002035static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
2036{
2037 struct device *dev = &adapter->vdev->dev;
2038 struct ibmvnic_sub_crq_queue *scrq;
2039 int i = 0, j = 0;
2040 int rc = 0;
2041
2042 for (i = 0; i < adapter->req_tx_queues; i++) {
2043 scrq = adapter->tx_scrq[i];
2044 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
2045
Michael Ellerman99c17902016-09-10 19:59:05 +10002046 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05002047 rc = -EINVAL;
2048 dev_err(dev, "Error mapping irq\n");
2049 goto req_tx_irq_failed;
2050 }
2051
2052 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
2053 0, "ibmvnic_tx", scrq);
2054
2055 if (rc) {
2056 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
2057 scrq->irq, rc);
2058 irq_dispose_mapping(scrq->irq);
2059 goto req_rx_irq_failed;
2060 }
2061 }
2062
2063 for (i = 0; i < adapter->req_rx_queues; i++) {
2064 scrq = adapter->rx_scrq[i];
2065 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
Michael Ellerman99c17902016-09-10 19:59:05 +10002066 if (!scrq->irq) {
Thomas Falconea22d512016-07-06 15:35:17 -05002067 rc = -EINVAL;
2068 dev_err(dev, "Error mapping irq\n");
2069 goto req_rx_irq_failed;
2070 }
2071 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
2072 0, "ibmvnic_rx", scrq);
2073 if (rc) {
2074 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
2075 scrq->irq, rc);
2076 irq_dispose_mapping(scrq->irq);
2077 goto req_rx_irq_failed;
2078 }
2079 }
2080 return rc;
2081
2082req_rx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002083 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05002084 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
2085 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002086 }
Thomas Falconea22d512016-07-06 15:35:17 -05002087 i = adapter->req_tx_queues;
2088req_tx_irq_failed:
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002089 for (j = 0; j < i; j++) {
Thomas Falconea22d512016-07-06 15:35:17 -05002090 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
2091 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
Thomas Falcon8bf371e2016-10-27 12:28:52 -05002092 }
Nathan Fontenotb5108882017-03-30 02:49:18 -04002093 release_sub_crqs(adapter);
Thomas Falconea22d512016-07-06 15:35:17 -05002094 return rc;
2095}
2096
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002097static int init_sub_crqs(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002098{
2099 struct device *dev = &adapter->vdev->dev;
2100 struct ibmvnic_sub_crq_queue **allqueues;
2101 int registered_queues = 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002102 int total_queues;
2103 int more = 0;
Thomas Falconea22d512016-07-06 15:35:17 -05002104 int i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002105
Thomas Falcon032c5e82015-12-21 11:26:06 -06002106 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
2107
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002108 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002109 if (!allqueues)
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002110 return -1;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002111
2112 for (i = 0; i < total_queues; i++) {
2113 allqueues[i] = init_sub_crq_queue(adapter);
2114 if (!allqueues[i]) {
2115 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
2116 break;
2117 }
2118 registered_queues++;
2119 }
2120
2121 /* Make sure we were able to register the minimum number of queues */
2122 if (registered_queues <
2123 adapter->min_tx_queues + adapter->min_rx_queues) {
2124 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
2125 goto tx_failed;
2126 }
2127
2128 /* Distribute the failed allocated queues*/
2129 for (i = 0; i < total_queues - registered_queues + more ; i++) {
2130 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
2131 switch (i % 3) {
2132 case 0:
2133 if (adapter->req_rx_queues > adapter->min_rx_queues)
2134 adapter->req_rx_queues--;
2135 else
2136 more++;
2137 break;
2138 case 1:
2139 if (adapter->req_tx_queues > adapter->min_tx_queues)
2140 adapter->req_tx_queues--;
2141 else
2142 more++;
2143 break;
2144 }
2145 }
2146
2147 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002148 sizeof(*adapter->tx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002149 if (!adapter->tx_scrq)
2150 goto tx_failed;
2151
2152 for (i = 0; i < adapter->req_tx_queues; i++) {
2153 adapter->tx_scrq[i] = allqueues[i];
2154 adapter->tx_scrq[i]->pool_index = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002155 }
2156
2157 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04002158 sizeof(*adapter->rx_scrq), GFP_KERNEL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002159 if (!adapter->rx_scrq)
2160 goto rx_failed;
2161
2162 for (i = 0; i < adapter->req_rx_queues; i++) {
2163 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
2164 adapter->rx_scrq[i]->scrq_num = i;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002165 }
2166
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002167 kfree(allqueues);
2168 return 0;
2169
2170rx_failed:
2171 kfree(adapter->tx_scrq);
2172 adapter->tx_scrq = NULL;
2173tx_failed:
2174 for (i = 0; i < registered_queues; i++)
2175 release_sub_crq_queue(adapter, allqueues[i]);
2176 kfree(allqueues);
2177 return -1;
2178}
2179
2180static void ibmvnic_send_req_caps(struct ibmvnic_adapter *adapter, int retry)
2181{
2182 struct device *dev = &adapter->vdev->dev;
2183 union ibmvnic_crq crq;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002184
2185 if (!retry) {
2186 /* Sub-CRQ entries are 32 byte long */
2187 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
2188
2189 if (adapter->min_tx_entries_per_subcrq > entries_page ||
2190 adapter->min_rx_add_entries_per_subcrq > entries_page) {
2191 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
2192 return;
2193 }
2194
2195 /* Get the minimum between the queried max and the entries
2196 * that fit in our PAGE_SIZE
2197 */
2198 adapter->req_tx_entries_per_subcrq =
2199 adapter->max_tx_entries_per_subcrq > entries_page ?
2200 entries_page : adapter->max_tx_entries_per_subcrq;
2201 adapter->req_rx_add_entries_per_subcrq =
2202 adapter->max_rx_add_entries_per_subcrq > entries_page ?
2203 entries_page : adapter->max_rx_add_entries_per_subcrq;
2204
2205 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
2206 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
2207 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
2208
2209 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
2210 }
2211
Thomas Falcon032c5e82015-12-21 11:26:06 -06002212 memset(&crq, 0, sizeof(crq));
2213 crq.request_capability.first = IBMVNIC_CRQ_CMD;
2214 crq.request_capability.cmd = REQUEST_CAPABILITY;
2215
2216 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002217 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002218 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002219 ibmvnic_send_crq(adapter, &crq);
2220
2221 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002222 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002223 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002224 ibmvnic_send_crq(adapter, &crq);
2225
2226 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
Thomas Falconde89e852016-03-01 10:20:09 -06002227 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
Thomas Falcon901e0402017-02-15 12:17:59 -06002228 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002229 ibmvnic_send_crq(adapter, &crq);
2230
2231 crq.request_capability.capability =
2232 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
2233 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06002234 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06002235 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002236 ibmvnic_send_crq(adapter, &crq);
2237
2238 crq.request_capability.capability =
2239 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
2240 crq.request_capability.number =
Thomas Falconde89e852016-03-01 10:20:09 -06002241 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
Thomas Falcon901e0402017-02-15 12:17:59 -06002242 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002243 ibmvnic_send_crq(adapter, &crq);
2244
2245 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
Thomas Falconde89e852016-03-01 10:20:09 -06002246 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
Thomas Falcon901e0402017-02-15 12:17:59 -06002247 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002248 ibmvnic_send_crq(adapter, &crq);
2249
2250 if (adapter->netdev->flags & IFF_PROMISC) {
2251 if (adapter->promisc_supported) {
2252 crq.request_capability.capability =
2253 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06002254 crq.request_capability.number = cpu_to_be64(1);
Thomas Falcon901e0402017-02-15 12:17:59 -06002255 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002256 ibmvnic_send_crq(adapter, &crq);
2257 }
2258 } else {
2259 crq.request_capability.capability =
2260 cpu_to_be16(PROMISC_REQUESTED);
Thomas Falconde89e852016-03-01 10:20:09 -06002261 crq.request_capability.number = cpu_to_be64(0);
Thomas Falcon901e0402017-02-15 12:17:59 -06002262 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002263 ibmvnic_send_crq(adapter, &crq);
2264 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06002265}
2266
2267static int pending_scrq(struct ibmvnic_adapter *adapter,
2268 struct ibmvnic_sub_crq_queue *scrq)
2269{
2270 union sub_crq *entry = &scrq->msgs[scrq->cur];
2271
Nathan Fontenot90c80142017-05-03 14:04:32 -04002272 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP ||
2273 adapter->state == VNIC_CLOSING)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002274 return 1;
2275 else
2276 return 0;
2277}
2278
2279static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
2280 struct ibmvnic_sub_crq_queue *scrq)
2281{
2282 union sub_crq *entry;
2283 unsigned long flags;
2284
2285 spin_lock_irqsave(&scrq->lock, flags);
2286 entry = &scrq->msgs[scrq->cur];
2287 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
2288 if (++scrq->cur == scrq->size)
2289 scrq->cur = 0;
2290 } else {
2291 entry = NULL;
2292 }
2293 spin_unlock_irqrestore(&scrq->lock, flags);
2294
2295 return entry;
2296}
2297
2298static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
2299{
2300 struct ibmvnic_crq_queue *queue = &adapter->crq;
2301 union ibmvnic_crq *crq;
2302
2303 crq = &queue->msgs[queue->cur];
2304 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
2305 if (++queue->cur == queue->size)
2306 queue->cur = 0;
2307 } else {
2308 crq = NULL;
2309 }
2310
2311 return crq;
2312}
2313
2314static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
2315 union sub_crq *sub_crq)
2316{
2317 unsigned int ua = adapter->vdev->unit_address;
2318 struct device *dev = &adapter->vdev->dev;
2319 u64 *u64_crq = (u64 *)sub_crq;
2320 int rc;
2321
2322 netdev_dbg(adapter->netdev,
2323 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
2324 (unsigned long int)cpu_to_be64(remote_handle),
2325 (unsigned long int)cpu_to_be64(u64_crq[0]),
2326 (unsigned long int)cpu_to_be64(u64_crq[1]),
2327 (unsigned long int)cpu_to_be64(u64_crq[2]),
2328 (unsigned long int)cpu_to_be64(u64_crq[3]));
2329
2330 /* Make sure the hypervisor sees the complete request */
2331 mb();
2332
2333 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
2334 cpu_to_be64(remote_handle),
2335 cpu_to_be64(u64_crq[0]),
2336 cpu_to_be64(u64_crq[1]),
2337 cpu_to_be64(u64_crq[2]),
2338 cpu_to_be64(u64_crq[3]));
2339
2340 if (rc) {
2341 if (rc == H_CLOSED)
2342 dev_warn(dev, "CRQ Queue closed\n");
2343 dev_err(dev, "Send error (rc=%d)\n", rc);
2344 }
2345
2346 return rc;
2347}
2348
Thomas Falconad7775d2016-04-01 17:20:34 -05002349static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
2350 u64 remote_handle, u64 ioba, u64 num_entries)
2351{
2352 unsigned int ua = adapter->vdev->unit_address;
2353 struct device *dev = &adapter->vdev->dev;
2354 int rc;
2355
2356 /* Make sure the hypervisor sees the complete request */
2357 mb();
2358 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
2359 cpu_to_be64(remote_handle),
2360 ioba, num_entries);
2361
2362 if (rc) {
2363 if (rc == H_CLOSED)
2364 dev_warn(dev, "CRQ Queue closed\n");
2365 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
2366 }
2367
2368 return rc;
2369}
2370
Thomas Falcon032c5e82015-12-21 11:26:06 -06002371static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
2372 union ibmvnic_crq *crq)
2373{
2374 unsigned int ua = adapter->vdev->unit_address;
2375 struct device *dev = &adapter->vdev->dev;
2376 u64 *u64_crq = (u64 *)crq;
2377 int rc;
2378
2379 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
2380 (unsigned long int)cpu_to_be64(u64_crq[0]),
2381 (unsigned long int)cpu_to_be64(u64_crq[1]));
2382
2383 /* Make sure the hypervisor sees the complete request */
2384 mb();
2385
2386 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
2387 cpu_to_be64(u64_crq[0]),
2388 cpu_to_be64(u64_crq[1]));
2389
2390 if (rc) {
2391 if (rc == H_CLOSED)
2392 dev_warn(dev, "CRQ Queue closed\n");
2393 dev_warn(dev, "Send error (rc=%d)\n", rc);
2394 }
2395
2396 return rc;
2397}
2398
2399static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
2400{
2401 union ibmvnic_crq crq;
2402
2403 memset(&crq, 0, sizeof(crq));
2404 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
2405 crq.generic.cmd = IBMVNIC_CRQ_INIT;
2406 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
2407
2408 return ibmvnic_send_crq(adapter, &crq);
2409}
2410
Thomas Falcon032c5e82015-12-21 11:26:06 -06002411static int send_version_xchg(struct ibmvnic_adapter *adapter)
2412{
2413 union ibmvnic_crq crq;
2414
2415 memset(&crq, 0, sizeof(crq));
2416 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
2417 crq.version_exchange.cmd = VERSION_EXCHANGE;
2418 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
2419
2420 return ibmvnic_send_crq(adapter, &crq);
2421}
2422
2423static void send_login(struct ibmvnic_adapter *adapter)
2424{
2425 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
2426 struct ibmvnic_login_buffer *login_buffer;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002427 struct device *dev = &adapter->vdev->dev;
2428 dma_addr_t rsp_buffer_token;
2429 dma_addr_t buffer_token;
2430 size_t rsp_buffer_size;
2431 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002432 size_t buffer_size;
2433 __be64 *tx_list_p;
2434 __be64 *rx_list_p;
2435 int i;
2436
2437 buffer_size =
2438 sizeof(struct ibmvnic_login_buffer) +
2439 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
2440
2441 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
2442 if (!login_buffer)
2443 goto buf_alloc_failed;
2444
2445 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
2446 DMA_TO_DEVICE);
2447 if (dma_mapping_error(dev, buffer_token)) {
2448 dev_err(dev, "Couldn't map login buffer\n");
2449 goto buf_map_failed;
2450 }
2451
John Allen498cd8e2016-04-06 11:49:55 -05002452 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
2453 sizeof(u64) * adapter->req_tx_queues +
2454 sizeof(u64) * adapter->req_rx_queues +
2455 sizeof(u64) * adapter->req_rx_queues +
2456 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002457
2458 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
2459 if (!login_rsp_buffer)
2460 goto buf_rsp_alloc_failed;
2461
2462 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
2463 rsp_buffer_size, DMA_FROM_DEVICE);
2464 if (dma_mapping_error(dev, rsp_buffer_token)) {
2465 dev_err(dev, "Couldn't map login rsp buffer\n");
2466 goto buf_rsp_map_failed;
2467 }
Nathan Fontenot661a2622017-04-19 13:44:58 -04002468
Thomas Falcon032c5e82015-12-21 11:26:06 -06002469 adapter->login_buf = login_buffer;
2470 adapter->login_buf_token = buffer_token;
2471 adapter->login_buf_sz = buffer_size;
2472 adapter->login_rsp_buf = login_rsp_buffer;
2473 adapter->login_rsp_buf_token = rsp_buffer_token;
2474 adapter->login_rsp_buf_sz = rsp_buffer_size;
2475
2476 login_buffer->len = cpu_to_be32(buffer_size);
2477 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
2478 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
2479 login_buffer->off_txcomp_subcrqs =
2480 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
2481 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
2482 login_buffer->off_rxcomp_subcrqs =
2483 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
2484 sizeof(u64) * adapter->req_tx_queues);
2485 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
2486 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
2487
2488 tx_list_p = (__be64 *)((char *)login_buffer +
2489 sizeof(struct ibmvnic_login_buffer));
2490 rx_list_p = (__be64 *)((char *)login_buffer +
2491 sizeof(struct ibmvnic_login_buffer) +
2492 sizeof(u64) * adapter->req_tx_queues);
2493
2494 for (i = 0; i < adapter->req_tx_queues; i++) {
2495 if (adapter->tx_scrq[i]) {
2496 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
2497 crq_num);
2498 }
2499 }
2500
2501 for (i = 0; i < adapter->req_rx_queues; i++) {
2502 if (adapter->rx_scrq[i]) {
2503 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
2504 crq_num);
2505 }
2506 }
2507
2508 netdev_dbg(adapter->netdev, "Login Buffer:\n");
2509 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
2510 netdev_dbg(adapter->netdev, "%016lx\n",
2511 ((unsigned long int *)(adapter->login_buf))[i]);
2512 }
2513
2514 memset(&crq, 0, sizeof(crq));
2515 crq.login.first = IBMVNIC_CRQ_CMD;
2516 crq.login.cmd = LOGIN;
2517 crq.login.ioba = cpu_to_be32(buffer_token);
2518 crq.login.len = cpu_to_be32(buffer_size);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002519 ibmvnic_send_crq(adapter, &crq);
2520
2521 return;
2522
Thomas Falcon032c5e82015-12-21 11:26:06 -06002523buf_rsp_map_failed:
2524 kfree(login_rsp_buffer);
2525buf_rsp_alloc_failed:
2526 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
2527buf_map_failed:
2528 kfree(login_buffer);
2529buf_alloc_failed:
2530 return;
2531}
2532
2533static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
2534 u32 len, u8 map_id)
2535{
2536 union ibmvnic_crq crq;
2537
2538 memset(&crq, 0, sizeof(crq));
2539 crq.request_map.first = IBMVNIC_CRQ_CMD;
2540 crq.request_map.cmd = REQUEST_MAP;
2541 crq.request_map.map_id = map_id;
2542 crq.request_map.ioba = cpu_to_be32(addr);
2543 crq.request_map.len = cpu_to_be32(len);
2544 ibmvnic_send_crq(adapter, &crq);
2545}
2546
2547static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
2548{
2549 union ibmvnic_crq crq;
2550
2551 memset(&crq, 0, sizeof(crq));
2552 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
2553 crq.request_unmap.cmd = REQUEST_UNMAP;
2554 crq.request_unmap.map_id = map_id;
2555 ibmvnic_send_crq(adapter, &crq);
2556}
2557
2558static void send_map_query(struct ibmvnic_adapter *adapter)
2559{
2560 union ibmvnic_crq crq;
2561
2562 memset(&crq, 0, sizeof(crq));
2563 crq.query_map.first = IBMVNIC_CRQ_CMD;
2564 crq.query_map.cmd = QUERY_MAP;
2565 ibmvnic_send_crq(adapter, &crq);
2566}
2567
2568/* Send a series of CRQs requesting various capabilities of the VNIC server */
2569static void send_cap_queries(struct ibmvnic_adapter *adapter)
2570{
2571 union ibmvnic_crq crq;
2572
Thomas Falcon901e0402017-02-15 12:17:59 -06002573 atomic_set(&adapter->running_cap_crqs, 0);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002574 memset(&crq, 0, sizeof(crq));
2575 crq.query_capability.first = IBMVNIC_CRQ_CMD;
2576 crq.query_capability.cmd = QUERY_CAPABILITY;
2577
2578 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002579 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002580 ibmvnic_send_crq(adapter, &crq);
2581
2582 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002583 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002584 ibmvnic_send_crq(adapter, &crq);
2585
2586 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002587 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002588 ibmvnic_send_crq(adapter, &crq);
2589
2590 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002591 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002592 ibmvnic_send_crq(adapter, &crq);
2593
2594 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002595 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002596 ibmvnic_send_crq(adapter, &crq);
2597
2598 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002599 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002600 ibmvnic_send_crq(adapter, &crq);
2601
2602 crq.query_capability.capability =
2603 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002604 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002605 ibmvnic_send_crq(adapter, &crq);
2606
2607 crq.query_capability.capability =
2608 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002609 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002610 ibmvnic_send_crq(adapter, &crq);
2611
2612 crq.query_capability.capability =
2613 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002614 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002615 ibmvnic_send_crq(adapter, &crq);
2616
2617 crq.query_capability.capability =
2618 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002619 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002620 ibmvnic_send_crq(adapter, &crq);
2621
2622 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
Thomas Falcon901e0402017-02-15 12:17:59 -06002623 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002624 ibmvnic_send_crq(adapter, &crq);
2625
2626 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002627 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002628 ibmvnic_send_crq(adapter, &crq);
2629
2630 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002631 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002632 ibmvnic_send_crq(adapter, &crq);
2633
2634 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
Thomas Falcon901e0402017-02-15 12:17:59 -06002635 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002636 ibmvnic_send_crq(adapter, &crq);
2637
2638 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
Thomas Falcon901e0402017-02-15 12:17:59 -06002639 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002640 ibmvnic_send_crq(adapter, &crq);
2641
2642 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
Thomas Falcon901e0402017-02-15 12:17:59 -06002643 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002644 ibmvnic_send_crq(adapter, &crq);
2645
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04002646 crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION);
2647 atomic_inc(&adapter->running_cap_crqs);
2648 ibmvnic_send_crq(adapter, &crq);
2649
Thomas Falcon032c5e82015-12-21 11:26:06 -06002650 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002651 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002652 ibmvnic_send_crq(adapter, &crq);
2653
2654 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
Thomas Falcon901e0402017-02-15 12:17:59 -06002655 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002656 ibmvnic_send_crq(adapter, &crq);
2657
2658 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002659 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002660 ibmvnic_send_crq(adapter, &crq);
2661
2662 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
Thomas Falcon901e0402017-02-15 12:17:59 -06002663 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002664 ibmvnic_send_crq(adapter, &crq);
2665
2666 crq.query_capability.capability =
2667 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
Thomas Falcon901e0402017-02-15 12:17:59 -06002668 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002669 ibmvnic_send_crq(adapter, &crq);
2670
2671 crq.query_capability.capability =
2672 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002673 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002674 ibmvnic_send_crq(adapter, &crq);
2675
2676 crq.query_capability.capability =
2677 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002678 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002679 ibmvnic_send_crq(adapter, &crq);
2680
2681 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
Thomas Falcon901e0402017-02-15 12:17:59 -06002682 atomic_inc(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002683 ibmvnic_send_crq(adapter, &crq);
2684}
2685
2686static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2687{
2688 struct device *dev = &adapter->vdev->dev;
2689 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2690 union ibmvnic_crq crq;
2691 int i;
2692
2693 dma_unmap_single(dev, adapter->ip_offload_tok,
2694 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2695
2696 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2697 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2698 netdev_dbg(adapter->netdev, "%016lx\n",
2699 ((unsigned long int *)(buf))[i]);
2700
2701 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2702 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2703 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2704 buf->tcp_ipv4_chksum);
2705 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2706 buf->tcp_ipv6_chksum);
2707 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2708 buf->udp_ipv4_chksum);
2709 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2710 buf->udp_ipv6_chksum);
2711 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2712 buf->large_tx_ipv4);
2713 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2714 buf->large_tx_ipv6);
2715 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2716 buf->large_rx_ipv4);
2717 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2718 buf->large_rx_ipv6);
2719 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2720 buf->max_ipv4_header_size);
2721 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2722 buf->max_ipv6_header_size);
2723 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2724 buf->max_tcp_header_size);
2725 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2726 buf->max_udp_header_size);
2727 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2728 buf->max_large_tx_size);
2729 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2730 buf->max_large_rx_size);
2731 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2732 buf->ipv6_extension_header);
2733 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2734 buf->tcp_pseudosum_req);
2735 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2736 buf->num_ipv6_ext_headers);
2737 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2738 buf->off_ipv6_ext_headers);
2739
2740 adapter->ip_offload_ctrl_tok =
2741 dma_map_single(dev, &adapter->ip_offload_ctrl,
2742 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2743
2744 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2745 dev_err(dev, "Couldn't map ip offload control buffer\n");
2746 return;
2747 }
2748
2749 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2750 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2751 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2752 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2753 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2754
2755 /* large_tx/rx disabled for now, additional features needed */
2756 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2757 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2758 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2759 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2760
2761 adapter->netdev->features = NETIF_F_GSO;
2762
2763 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2764 adapter->netdev->features |= NETIF_F_IP_CSUM;
2765
2766 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2767 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2768
Thomas Falcon9be02cd2016-04-01 17:20:35 -05002769 if ((adapter->netdev->features &
2770 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2771 adapter->netdev->features |= NETIF_F_RXCSUM;
2772
Thomas Falcon032c5e82015-12-21 11:26:06 -06002773 memset(&crq, 0, sizeof(crq));
2774 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2775 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2776 crq.control_ip_offload.len =
2777 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2778 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2779 ibmvnic_send_crq(adapter, &crq);
2780}
2781
2782static void handle_error_info_rsp(union ibmvnic_crq *crq,
2783 struct ibmvnic_adapter *adapter)
2784{
2785 struct device *dev = &adapter->vdev->dev;
Wei Yongjun96183182016-06-27 20:48:53 +08002786 struct ibmvnic_error_buff *error_buff, *tmp;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002787 unsigned long flags;
2788 bool found = false;
2789 int i;
2790
2791 if (!crq->request_error_rsp.rc.code) {
2792 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2793 crq->request_error_rsp.rc.code);
2794 return;
2795 }
2796
2797 spin_lock_irqsave(&adapter->error_list_lock, flags);
Wei Yongjun96183182016-06-27 20:48:53 +08002798 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002799 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2800 found = true;
2801 list_del(&error_buff->list);
2802 break;
2803 }
2804 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2805
2806 if (!found) {
2807 dev_err(dev, "Couldn't find error id %x\n",
Thomas Falcon75224c92017-02-15 10:33:33 -06002808 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002809 return;
2810 }
2811
2812 dev_err(dev, "Detailed info for error id %x:",
Thomas Falcon75224c92017-02-15 10:33:33 -06002813 be32_to_cpu(crq->request_error_rsp.error_id));
Thomas Falcon032c5e82015-12-21 11:26:06 -06002814
2815 for (i = 0; i < error_buff->len; i++) {
2816 pr_cont("%02x", (int)error_buff->buff[i]);
2817 if (i % 8 == 7)
2818 pr_cont(" ");
2819 }
2820 pr_cont("\n");
2821
2822 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2823 DMA_FROM_DEVICE);
2824 kfree(error_buff->buff);
2825 kfree(error_buff);
2826}
2827
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002828static void request_error_information(struct ibmvnic_adapter *adapter,
2829 union ibmvnic_crq *err_crq)
Thomas Falcon032c5e82015-12-21 11:26:06 -06002830{
Thomas Falcon032c5e82015-12-21 11:26:06 -06002831 struct device *dev = &adapter->vdev->dev;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002832 struct net_device *netdev = adapter->netdev;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002833 struct ibmvnic_error_buff *error_buff;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002834 unsigned long timeout = msecs_to_jiffies(30000);
2835 union ibmvnic_crq crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002836 unsigned long flags;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002837 int rc, detail_len;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002838
2839 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2840 if (!error_buff)
2841 return;
2842
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002843 detail_len = be32_to_cpu(err_crq->error_indication.detail_error_sz);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002844 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2845 if (!error_buff->buff) {
2846 kfree(error_buff);
2847 return;
2848 }
2849
2850 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2851 DMA_FROM_DEVICE);
2852 if (dma_mapping_error(dev, error_buff->dma)) {
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002853 netdev_err(netdev, "Couldn't map error buffer\n");
Thomas Falcon032c5e82015-12-21 11:26:06 -06002854 kfree(error_buff->buff);
2855 kfree(error_buff);
2856 return;
2857 }
2858
Thomas Falcon032c5e82015-12-21 11:26:06 -06002859 error_buff->len = detail_len;
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002860 error_buff->error_id = err_crq->error_indication.error_id;
Thomas Falcon032c5e82015-12-21 11:26:06 -06002861
2862 spin_lock_irqsave(&adapter->error_list_lock, flags);
2863 list_add_tail(&error_buff->list, &adapter->errors);
2864 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2865
Nathan Fontenot2f9de9b2017-04-21 15:38:52 -04002866 memset(&crq, 0, sizeof(crq));
2867 crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2868 crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2869 crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2870 crq.request_error_info.len = cpu_to_be32(detail_len);
2871 crq.request_error_info.error_id = err_crq->error_indication.error_id;
2872
2873 rc = ibmvnic_send_crq(adapter, &crq);
2874 if (rc) {
2875 netdev_err(netdev, "failed to request error information\n");
2876 goto err_info_fail;
2877 }
2878
2879 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
2880 netdev_err(netdev, "timeout waiting for error information\n");
2881 goto err_info_fail;
2882 }
2883
2884 return;
2885
2886err_info_fail:
2887 spin_lock_irqsave(&adapter->error_list_lock, flags);
2888 list_del(&error_buff->list);
2889 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2890
2891 kfree(error_buff->buff);
2892 kfree(error_buff);
2893}
2894
2895static void handle_error_indication(union ibmvnic_crq *crq,
2896 struct ibmvnic_adapter *adapter)
2897{
2898 struct device *dev = &adapter->vdev->dev;
2899
2900 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2901 crq->error_indication.flags
2902 & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
2903 be32_to_cpu(crq->error_indication.error_id),
2904 be16_to_cpu(crq->error_indication.error_cause));
2905
2906 if (be32_to_cpu(crq->error_indication.error_id))
2907 request_error_information(adapter, crq);
Nathan Fontenoted651a12017-05-03 14:04:38 -04002908
2909 if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR)
2910 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
John Allen8cb31cf2017-05-26 10:30:37 -04002911 else
2912 ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002913}
2914
2915static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2916 struct ibmvnic_adapter *adapter)
2917{
2918 struct net_device *netdev = adapter->netdev;
2919 struct device *dev = &adapter->vdev->dev;
2920 long rc;
2921
2922 rc = crq->change_mac_addr_rsp.rc.code;
2923 if (rc) {
2924 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2925 return;
2926 }
2927 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2928 ETH_ALEN);
2929}
2930
2931static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2932 struct ibmvnic_adapter *adapter)
2933{
2934 struct device *dev = &adapter->vdev->dev;
2935 u64 *req_value;
2936 char *name;
2937
Thomas Falcon901e0402017-02-15 12:17:59 -06002938 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002939 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2940 case REQ_TX_QUEUES:
2941 req_value = &adapter->req_tx_queues;
2942 name = "tx";
2943 break;
2944 case REQ_RX_QUEUES:
2945 req_value = &adapter->req_rx_queues;
2946 name = "rx";
2947 break;
2948 case REQ_RX_ADD_QUEUES:
2949 req_value = &adapter->req_rx_add_queues;
2950 name = "rx_add";
2951 break;
2952 case REQ_TX_ENTRIES_PER_SUBCRQ:
2953 req_value = &adapter->req_tx_entries_per_subcrq;
2954 name = "tx_entries_per_subcrq";
2955 break;
2956 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2957 req_value = &adapter->req_rx_add_entries_per_subcrq;
2958 name = "rx_add_entries_per_subcrq";
2959 break;
2960 case REQ_MTU:
2961 req_value = &adapter->req_mtu;
2962 name = "mtu";
2963 break;
2964 case PROMISC_REQUESTED:
2965 req_value = &adapter->promisc;
2966 name = "promisc";
2967 break;
2968 default:
2969 dev_err(dev, "Got invalid cap request rsp %d\n",
2970 crq->request_capability.capability);
2971 return;
2972 }
2973
2974 switch (crq->request_capability_rsp.rc.code) {
2975 case SUCCESS:
2976 break;
2977 case PARTIALSUCCESS:
2978 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2979 *req_value,
Thomas Falcon28f4d162017-02-15 10:32:11 -06002980 (long int)be64_to_cpu(crq->request_capability_rsp.
Thomas Falcon032c5e82015-12-21 11:26:06 -06002981 number), name);
Nathan Fontenotb5108882017-03-30 02:49:18 -04002982 release_sub_crqs(adapter);
Thomas Falcon28f4d162017-02-15 10:32:11 -06002983 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04002984 ibmvnic_send_req_caps(adapter, 1);
Thomas Falcon032c5e82015-12-21 11:26:06 -06002985 return;
2986 default:
2987 dev_err(dev, "Error %d in request cap rsp\n",
2988 crq->request_capability_rsp.rc.code);
2989 return;
2990 }
2991
2992 /* Done receiving requested capabilities, query IP offload support */
Thomas Falcon901e0402017-02-15 12:17:59 -06002993 if (atomic_read(&adapter->running_cap_crqs) == 0) {
Thomas Falcon032c5e82015-12-21 11:26:06 -06002994 union ibmvnic_crq newcrq;
2995 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2996 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2997 &adapter->ip_offload_buf;
2998
Thomas Falcon249168a2017-02-15 12:18:00 -06002999 adapter->wait_capability = false;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003000 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
3001 buf_sz,
3002 DMA_FROM_DEVICE);
3003
3004 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
3005 if (!firmware_has_feature(FW_FEATURE_CMO))
3006 dev_err(dev, "Couldn't map offload buffer\n");
3007 return;
3008 }
3009
3010 memset(&newcrq, 0, sizeof(newcrq));
3011 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
3012 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
3013 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
3014 newcrq.query_ip_offload.ioba =
3015 cpu_to_be32(adapter->ip_offload_tok);
3016
3017 ibmvnic_send_crq(adapter, &newcrq);
3018 }
3019}
3020
3021static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
3022 struct ibmvnic_adapter *adapter)
3023{
3024 struct device *dev = &adapter->vdev->dev;
3025 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
3026 struct ibmvnic_login_buffer *login = adapter->login_buf;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003027 int i;
3028
3029 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
3030 DMA_BIDIRECTIONAL);
3031 dma_unmap_single(dev, adapter->login_rsp_buf_token,
3032 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
3033
John Allen498cd8e2016-04-06 11:49:55 -05003034 /* If the number of queues requested can't be allocated by the
3035 * server, the login response will return with code 1. We will need
3036 * to resend the login buffer with fewer queues requested.
3037 */
3038 if (login_rsp_crq->generic.rc.code) {
3039 adapter->renegotiate = true;
3040 complete(&adapter->init_done);
3041 return 0;
3042 }
3043
Thomas Falcon032c5e82015-12-21 11:26:06 -06003044 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
3045 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
3046 netdev_dbg(adapter->netdev, "%016lx\n",
3047 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
3048 }
3049
3050 /* Sanity checks */
3051 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
3052 (be32_to_cpu(login->num_rxcomp_subcrqs) *
3053 adapter->req_rx_add_queues !=
3054 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
3055 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
3056 ibmvnic_remove(adapter->vdev);
3057 return -EIO;
3058 }
3059 complete(&adapter->init_done);
3060
Thomas Falcon032c5e82015-12-21 11:26:06 -06003061 return 0;
3062}
3063
3064static void handle_request_map_rsp(union ibmvnic_crq *crq,
3065 struct ibmvnic_adapter *adapter)
3066{
3067 struct device *dev = &adapter->vdev->dev;
3068 u8 map_id = crq->request_map_rsp.map_id;
3069 int tx_subcrqs;
3070 int rx_subcrqs;
3071 long rc;
3072 int i;
3073
3074 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
3075 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3076
3077 rc = crq->request_map_rsp.rc.code;
3078 if (rc) {
3079 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
3080 adapter->map_id--;
3081 /* need to find and zero tx/rx_pool map_id */
3082 for (i = 0; i < tx_subcrqs; i++) {
3083 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
3084 adapter->tx_pool[i].long_term_buff.map_id = 0;
3085 }
3086 for (i = 0; i < rx_subcrqs; i++) {
3087 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
3088 adapter->rx_pool[i].long_term_buff.map_id = 0;
3089 }
3090 }
3091 complete(&adapter->fw_done);
3092}
3093
3094static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
3095 struct ibmvnic_adapter *adapter)
3096{
3097 struct device *dev = &adapter->vdev->dev;
3098 long rc;
3099
3100 rc = crq->request_unmap_rsp.rc.code;
3101 if (rc)
3102 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
3103}
3104
3105static void handle_query_map_rsp(union ibmvnic_crq *crq,
3106 struct ibmvnic_adapter *adapter)
3107{
3108 struct net_device *netdev = adapter->netdev;
3109 struct device *dev = &adapter->vdev->dev;
3110 long rc;
3111
3112 rc = crq->query_map_rsp.rc.code;
3113 if (rc) {
3114 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
3115 return;
3116 }
3117 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
3118 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
3119 crq->query_map_rsp.free_pages);
3120}
3121
3122static void handle_query_cap_rsp(union ibmvnic_crq *crq,
3123 struct ibmvnic_adapter *adapter)
3124{
3125 struct net_device *netdev = adapter->netdev;
3126 struct device *dev = &adapter->vdev->dev;
3127 long rc;
3128
Thomas Falcon901e0402017-02-15 12:17:59 -06003129 atomic_dec(&adapter->running_cap_crqs);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003130 netdev_dbg(netdev, "Outstanding queries: %d\n",
Thomas Falcon901e0402017-02-15 12:17:59 -06003131 atomic_read(&adapter->running_cap_crqs));
Thomas Falcon032c5e82015-12-21 11:26:06 -06003132 rc = crq->query_capability.rc.code;
3133 if (rc) {
3134 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
3135 goto out;
3136 }
3137
3138 switch (be16_to_cpu(crq->query_capability.capability)) {
3139 case MIN_TX_QUEUES:
3140 adapter->min_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003141 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003142 netdev_dbg(netdev, "min_tx_queues = %lld\n",
3143 adapter->min_tx_queues);
3144 break;
3145 case MIN_RX_QUEUES:
3146 adapter->min_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003147 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003148 netdev_dbg(netdev, "min_rx_queues = %lld\n",
3149 adapter->min_rx_queues);
3150 break;
3151 case MIN_RX_ADD_QUEUES:
3152 adapter->min_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003153 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003154 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
3155 adapter->min_rx_add_queues);
3156 break;
3157 case MAX_TX_QUEUES:
3158 adapter->max_tx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003159 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003160 netdev_dbg(netdev, "max_tx_queues = %lld\n",
3161 adapter->max_tx_queues);
3162 break;
3163 case MAX_RX_QUEUES:
3164 adapter->max_rx_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003165 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003166 netdev_dbg(netdev, "max_rx_queues = %lld\n",
3167 adapter->max_rx_queues);
3168 break;
3169 case MAX_RX_ADD_QUEUES:
3170 adapter->max_rx_add_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003171 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003172 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
3173 adapter->max_rx_add_queues);
3174 break;
3175 case MIN_TX_ENTRIES_PER_SUBCRQ:
3176 adapter->min_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003177 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003178 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
3179 adapter->min_tx_entries_per_subcrq);
3180 break;
3181 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
3182 adapter->min_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003183 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003184 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
3185 adapter->min_rx_add_entries_per_subcrq);
3186 break;
3187 case MAX_TX_ENTRIES_PER_SUBCRQ:
3188 adapter->max_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003189 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003190 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
3191 adapter->max_tx_entries_per_subcrq);
3192 break;
3193 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
3194 adapter->max_rx_add_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003195 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003196 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
3197 adapter->max_rx_add_entries_per_subcrq);
3198 break;
3199 case TCP_IP_OFFLOAD:
3200 adapter->tcp_ip_offload =
Thomas Falconde89e852016-03-01 10:20:09 -06003201 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003202 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
3203 adapter->tcp_ip_offload);
3204 break;
3205 case PROMISC_SUPPORTED:
3206 adapter->promisc_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06003207 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003208 netdev_dbg(netdev, "promisc_supported = %lld\n",
3209 adapter->promisc_supported);
3210 break;
3211 case MIN_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06003212 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06003213 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003214 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
3215 break;
3216 case MAX_MTU:
Thomas Falconde89e852016-03-01 10:20:09 -06003217 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
Thomas Falconf39f0d12017-02-14 10:22:59 -06003218 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003219 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
3220 break;
3221 case MAX_MULTICAST_FILTERS:
3222 adapter->max_multicast_filters =
Thomas Falconde89e852016-03-01 10:20:09 -06003223 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003224 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
3225 adapter->max_multicast_filters);
3226 break;
3227 case VLAN_HEADER_INSERTION:
3228 adapter->vlan_header_insertion =
Thomas Falconde89e852016-03-01 10:20:09 -06003229 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003230 if (adapter->vlan_header_insertion)
3231 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
3232 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
3233 adapter->vlan_header_insertion);
3234 break;
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -04003235 case RX_VLAN_HEADER_INSERTION:
3236 adapter->rx_vlan_header_insertion =
3237 be64_to_cpu(crq->query_capability.number);
3238 netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n",
3239 adapter->rx_vlan_header_insertion);
3240 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003241 case MAX_TX_SG_ENTRIES:
3242 adapter->max_tx_sg_entries =
Thomas Falconde89e852016-03-01 10:20:09 -06003243 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003244 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
3245 adapter->max_tx_sg_entries);
3246 break;
3247 case RX_SG_SUPPORTED:
3248 adapter->rx_sg_supported =
Thomas Falconde89e852016-03-01 10:20:09 -06003249 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003250 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
3251 adapter->rx_sg_supported);
3252 break;
3253 case OPT_TX_COMP_SUB_QUEUES:
3254 adapter->opt_tx_comp_sub_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003255 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003256 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
3257 adapter->opt_tx_comp_sub_queues);
3258 break;
3259 case OPT_RX_COMP_QUEUES:
3260 adapter->opt_rx_comp_queues =
Thomas Falconde89e852016-03-01 10:20:09 -06003261 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003262 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
3263 adapter->opt_rx_comp_queues);
3264 break;
3265 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
3266 adapter->opt_rx_bufadd_q_per_rx_comp_q =
Thomas Falconde89e852016-03-01 10:20:09 -06003267 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003268 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
3269 adapter->opt_rx_bufadd_q_per_rx_comp_q);
3270 break;
3271 case OPT_TX_ENTRIES_PER_SUBCRQ:
3272 adapter->opt_tx_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003273 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003274 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
3275 adapter->opt_tx_entries_per_subcrq);
3276 break;
3277 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
3278 adapter->opt_rxba_entries_per_subcrq =
Thomas Falconde89e852016-03-01 10:20:09 -06003279 be64_to_cpu(crq->query_capability.number);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003280 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
3281 adapter->opt_rxba_entries_per_subcrq);
3282 break;
3283 case TX_RX_DESC_REQ:
3284 adapter->tx_rx_desc_req = crq->query_capability.number;
3285 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
3286 adapter->tx_rx_desc_req);
3287 break;
3288
3289 default:
3290 netdev_err(netdev, "Got invalid cap rsp %d\n",
3291 crq->query_capability.capability);
3292 }
3293
3294out:
Thomas Falcon249168a2017-02-15 12:18:00 -06003295 if (atomic_read(&adapter->running_cap_crqs) == 0) {
3296 adapter->wait_capability = false;
Nathan Fontenotd346b9b2017-04-25 15:01:04 -04003297 ibmvnic_send_req_caps(adapter, 0);
Thomas Falcon249168a2017-02-15 12:18:00 -06003298 }
Thomas Falcon032c5e82015-12-21 11:26:06 -06003299}
3300
Thomas Falcon032c5e82015-12-21 11:26:06 -06003301static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3302 struct ibmvnic_adapter *adapter)
3303{
3304 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
3305 struct net_device *netdev = adapter->netdev;
3306 struct device *dev = &adapter->vdev->dev;
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04003307 u64 *u64_crq = (u64 *)crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003308 long rc;
3309
3310 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -04003311 (unsigned long int)cpu_to_be64(u64_crq[0]),
3312 (unsigned long int)cpu_to_be64(u64_crq[1]));
Thomas Falcon032c5e82015-12-21 11:26:06 -06003313 switch (gen_crq->first) {
3314 case IBMVNIC_CRQ_INIT_RSP:
3315 switch (gen_crq->cmd) {
3316 case IBMVNIC_CRQ_INIT:
3317 dev_info(dev, "Partner initialized\n");
John Allen017892c12017-05-26 10:30:19 -04003318 adapter->from_passive_init = true;
3319 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003320 break;
3321 case IBMVNIC_CRQ_INIT_COMPLETE:
3322 dev_info(dev, "Partner initialization complete\n");
3323 send_version_xchg(adapter);
3324 break;
3325 default:
3326 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
3327 }
3328 return;
3329 case IBMVNIC_CRQ_XPORT_EVENT:
Nathan Fontenoted651a12017-05-03 14:04:38 -04003330 netif_carrier_off(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003331 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
Nathan Fontenoted651a12017-05-03 14:04:38 -04003332 dev_info(dev, "Migrated, re-enabling adapter\n");
3333 ibmvnic_reset(adapter, VNIC_RESET_MOBILITY);
Thomas Falcondfad09a2016-08-18 11:37:51 -05003334 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
3335 dev_info(dev, "Backing device failover detected\n");
Nathan Fontenoted651a12017-05-03 14:04:38 -04003336 ibmvnic_reset(adapter, VNIC_RESET_FAILOVER);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003337 } else {
3338 /* The adapter lost the connection */
3339 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
3340 gen_crq->cmd);
Nathan Fontenoted651a12017-05-03 14:04:38 -04003341 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003342 }
3343 return;
3344 case IBMVNIC_CRQ_CMD_RSP:
3345 break;
3346 default:
3347 dev_err(dev, "Got an invalid msg type 0x%02x\n",
3348 gen_crq->first);
3349 return;
3350 }
3351
3352 switch (gen_crq->cmd) {
3353 case VERSION_EXCHANGE_RSP:
3354 rc = crq->version_exchange_rsp.rc.code;
3355 if (rc) {
3356 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
3357 break;
3358 }
3359 dev_info(dev, "Partner protocol version is %d\n",
3360 crq->version_exchange_rsp.version);
3361 if (be16_to_cpu(crq->version_exchange_rsp.version) <
3362 ibmvnic_version)
3363 ibmvnic_version =
3364 be16_to_cpu(crq->version_exchange_rsp.version);
3365 send_cap_queries(adapter);
3366 break;
3367 case QUERY_CAPABILITY_RSP:
3368 handle_query_cap_rsp(crq, adapter);
3369 break;
3370 case QUERY_MAP_RSP:
3371 handle_query_map_rsp(crq, adapter);
3372 break;
3373 case REQUEST_MAP_RSP:
3374 handle_request_map_rsp(crq, adapter);
3375 break;
3376 case REQUEST_UNMAP_RSP:
3377 handle_request_unmap_rsp(crq, adapter);
3378 break;
3379 case REQUEST_CAPABILITY_RSP:
3380 handle_request_cap_rsp(crq, adapter);
3381 break;
3382 case LOGIN_RSP:
3383 netdev_dbg(netdev, "Got Login Response\n");
3384 handle_login_rsp(crq, adapter);
3385 break;
3386 case LOGICAL_LINK_STATE_RSP:
Nathan Fontenot53da09e2017-04-21 15:39:04 -04003387 netdev_dbg(netdev,
3388 "Got Logical Link State Response, state: %d rc: %d\n",
3389 crq->logical_link_state_rsp.link_state,
3390 crq->logical_link_state_rsp.rc.code);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003391 adapter->logical_link_state =
3392 crq->logical_link_state_rsp.link_state;
Nathan Fontenot53da09e2017-04-21 15:39:04 -04003393 adapter->init_done_rc = crq->logical_link_state_rsp.rc.code;
3394 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003395 break;
3396 case LINK_STATE_INDICATION:
3397 netdev_dbg(netdev, "Got Logical Link State Indication\n");
3398 adapter->phys_link_state =
3399 crq->link_state_indication.phys_link_state;
3400 adapter->logical_link_state =
3401 crq->link_state_indication.logical_link_state;
3402 break;
3403 case CHANGE_MAC_ADDR_RSP:
3404 netdev_dbg(netdev, "Got MAC address change Response\n");
3405 handle_change_mac_rsp(crq, adapter);
3406 break;
3407 case ERROR_INDICATION:
3408 netdev_dbg(netdev, "Got Error Indication\n");
3409 handle_error_indication(crq, adapter);
3410 break;
3411 case REQUEST_ERROR_RSP:
3412 netdev_dbg(netdev, "Got Error Detail Response\n");
3413 handle_error_info_rsp(crq, adapter);
3414 break;
3415 case REQUEST_STATISTICS_RSP:
3416 netdev_dbg(netdev, "Got Statistics Response\n");
3417 complete(&adapter->stats_done);
3418 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003419 case QUERY_IP_OFFLOAD_RSP:
3420 netdev_dbg(netdev, "Got Query IP offload Response\n");
3421 handle_query_ip_offload_rsp(adapter);
3422 break;
3423 case MULTICAST_CTRL_RSP:
3424 netdev_dbg(netdev, "Got multicast control Response\n");
3425 break;
3426 case CONTROL_IP_OFFLOAD_RSP:
3427 netdev_dbg(netdev, "Got Control IP offload Response\n");
3428 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
3429 sizeof(adapter->ip_offload_ctrl),
3430 DMA_TO_DEVICE);
John Allenbd0b6722017-03-17 17:13:40 -05003431 complete(&adapter->init_done);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003432 break;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003433 case COLLECT_FW_TRACE_RSP:
3434 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
3435 complete(&adapter->fw_done);
3436 break;
3437 default:
3438 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
3439 gen_crq->cmd);
3440 }
3441}
3442
3443static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
3444{
3445 struct ibmvnic_adapter *adapter = instance;
Thomas Falcon6c267b32017-02-15 12:17:58 -06003446
Thomas Falcon6c267b32017-02-15 12:17:58 -06003447 tasklet_schedule(&adapter->tasklet);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003448 return IRQ_HANDLED;
3449}
3450
3451static void ibmvnic_tasklet(void *data)
3452{
3453 struct ibmvnic_adapter *adapter = data;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003454 struct ibmvnic_crq_queue *queue = &adapter->crq;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003455 union ibmvnic_crq *crq;
3456 unsigned long flags;
3457 bool done = false;
3458
3459 spin_lock_irqsave(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003460 while (!done) {
3461 /* Pull all the valid messages off the CRQ */
3462 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
3463 ibmvnic_handle_crq(crq, adapter);
3464 crq->generic.first = 0;
3465 }
Brian Kinged7ecbf2017-04-19 13:44:53 -04003466
3467 /* remain in tasklet until all
3468 * capabilities responses are received
3469 */
3470 if (!adapter->wait_capability)
3471 done = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003472 }
Thomas Falcon249168a2017-02-15 12:18:00 -06003473 /* if capabilities CRQ's were sent in this tasklet, the following
3474 * tasklet must wait until all responses are received
3475 */
3476 if (atomic_read(&adapter->running_cap_crqs) != 0)
3477 adapter->wait_capability = true;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003478 spin_unlock_irqrestore(&queue->lock, flags);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003479}
3480
3481static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
3482{
3483 struct vio_dev *vdev = adapter->vdev;
3484 int rc;
3485
3486 do {
3487 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
3488 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
3489
3490 if (rc)
3491 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
3492
3493 return rc;
3494}
3495
3496static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
3497{
3498 struct ibmvnic_crq_queue *crq = &adapter->crq;
3499 struct device *dev = &adapter->vdev->dev;
3500 struct vio_dev *vdev = adapter->vdev;
3501 int rc;
3502
3503 /* Close the CRQ */
3504 do {
3505 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3506 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3507
3508 /* Clean out the queue */
3509 memset(crq->msgs, 0, PAGE_SIZE);
3510 crq->cur = 0;
3511
3512 /* And re-open it again */
3513 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3514 crq->msg_token, PAGE_SIZE);
3515
3516 if (rc == H_CLOSED)
3517 /* Adapter is good, but other end is not ready */
3518 dev_warn(dev, "Partner adapter not ready\n");
3519 else if (rc != 0)
3520 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3521
3522 return rc;
3523}
3524
Nathan Fontenotf9928872017-03-30 02:48:54 -04003525static void release_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003526{
3527 struct ibmvnic_crq_queue *crq = &adapter->crq;
3528 struct vio_dev *vdev = adapter->vdev;
3529 long rc;
3530
Nathan Fontenotf9928872017-03-30 02:48:54 -04003531 if (!crq->msgs)
3532 return;
3533
Thomas Falcon032c5e82015-12-21 11:26:06 -06003534 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3535 free_irq(vdev->irq, adapter);
Thomas Falcon6c267b32017-02-15 12:17:58 -06003536 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003537 do {
3538 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3539 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3540
3541 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3542 DMA_BIDIRECTIONAL);
3543 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003544 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003545}
3546
Nathan Fontenotf9928872017-03-30 02:48:54 -04003547static int init_crq_queue(struct ibmvnic_adapter *adapter)
Thomas Falcon032c5e82015-12-21 11:26:06 -06003548{
3549 struct ibmvnic_crq_queue *crq = &adapter->crq;
3550 struct device *dev = &adapter->vdev->dev;
3551 struct vio_dev *vdev = adapter->vdev;
3552 int rc, retrc = -ENOMEM;
3553
Nathan Fontenotf9928872017-03-30 02:48:54 -04003554 if (crq->msgs)
3555 return 0;
3556
Thomas Falcon032c5e82015-12-21 11:26:06 -06003557 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3558 /* Should we allocate more than one page? */
3559
3560 if (!crq->msgs)
3561 return -ENOMEM;
3562
3563 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3564 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3565 DMA_BIDIRECTIONAL);
3566 if (dma_mapping_error(dev, crq->msg_token))
3567 goto map_failed;
3568
3569 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3570 crq->msg_token, PAGE_SIZE);
3571
3572 if (rc == H_RESOURCE)
3573 /* maybe kexecing and resource is busy. try a reset */
3574 rc = ibmvnic_reset_crq(adapter);
3575 retrc = rc;
3576
3577 if (rc == H_CLOSED) {
3578 dev_warn(dev, "Partner adapter not ready\n");
3579 } else if (rc) {
3580 dev_warn(dev, "Error %d opening adapter\n", rc);
3581 goto reg_crq_failed;
3582 }
3583
3584 retrc = 0;
3585
Thomas Falcon6c267b32017-02-15 12:17:58 -06003586 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3587 (unsigned long)adapter);
3588
Thomas Falcon032c5e82015-12-21 11:26:06 -06003589 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3590 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3591 adapter);
3592 if (rc) {
3593 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3594 vdev->irq, rc);
3595 goto req_irq_failed;
3596 }
3597
3598 rc = vio_enable_interrupts(vdev);
3599 if (rc) {
3600 dev_err(dev, "Error %d enabling interrupts\n", rc);
3601 goto req_irq_failed;
3602 }
3603
3604 crq->cur = 0;
3605 spin_lock_init(&crq->lock);
3606
3607 return retrc;
3608
3609req_irq_failed:
Thomas Falcon6c267b32017-02-15 12:17:58 -06003610 tasklet_kill(&adapter->tasklet);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003611 do {
3612 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3613 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3614reg_crq_failed:
3615 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3616map_failed:
3617 free_page((unsigned long)crq->msgs);
Nathan Fontenotf9928872017-03-30 02:48:54 -04003618 crq->msgs = NULL;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003619 return retrc;
3620}
3621
John Allenf6ef6402017-03-17 17:13:42 -05003622static int ibmvnic_init(struct ibmvnic_adapter *adapter)
3623{
3624 struct device *dev = &adapter->vdev->dev;
3625 unsigned long timeout = msecs_to_jiffies(30000);
John Allenf6ef6402017-03-17 17:13:42 -05003626 int rc;
3627
Nathan Fontenot28cde752017-05-26 10:31:00 -04003628 if (adapter->resetting) {
3629 rc = ibmvnic_reset_crq(adapter);
3630 if (!rc)
3631 rc = vio_enable_interrupts(adapter->vdev);
3632 } else {
3633 rc = init_crq_queue(adapter);
3634 }
3635
John Allenf6ef6402017-03-17 17:13:42 -05003636 if (rc) {
3637 dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
3638 return rc;
3639 }
3640
John Allen017892c12017-05-26 10:30:19 -04003641 adapter->from_passive_init = false;
3642
John Allenf6ef6402017-03-17 17:13:42 -05003643 init_completion(&adapter->init_done);
3644 ibmvnic_send_crq_init(adapter);
3645 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3646 dev_err(dev, "Initialization sequence timed out\n");
John Allen017892c12017-05-26 10:30:19 -04003647 return -1;
3648 }
3649
3650 if (adapter->from_passive_init) {
3651 adapter->state = VNIC_OPEN;
3652 adapter->from_passive_init = false;
John Allenf6ef6402017-03-17 17:13:42 -05003653 return -1;
3654 }
3655
Nathan Fontenot57a49432017-05-26 10:31:12 -04003656 if (adapter->resetting)
3657 rc = reset_sub_crq_queues(adapter);
3658 else
3659 rc = init_sub_crqs(adapter);
Nathan Fontenot1bb3c732017-04-25 15:01:10 -04003660 if (rc) {
3661 dev_err(dev, "Initialization of sub crqs failed\n");
3662 release_crq_queue(adapter);
3663 }
3664
3665 return rc;
John Allenf6ef6402017-03-17 17:13:42 -05003666}
3667
Thomas Falcon40c9db82017-06-12 12:35:04 -05003668static struct device_attribute dev_attr_failover;
3669
Thomas Falcon032c5e82015-12-21 11:26:06 -06003670static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3671{
3672 struct ibmvnic_adapter *adapter;
3673 struct net_device *netdev;
3674 unsigned char *mac_addr_p;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003675 int rc;
3676
3677 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3678 dev->unit_address);
3679
3680 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3681 VETH_MAC_ADDR, NULL);
3682 if (!mac_addr_p) {
3683 dev_err(&dev->dev,
3684 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3685 __FILE__, __LINE__);
3686 return 0;
3687 }
3688
3689 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3690 IBMVNIC_MAX_TX_QUEUES);
3691 if (!netdev)
3692 return -ENOMEM;
3693
3694 adapter = netdev_priv(netdev);
Nathan Fontenot90c80142017-05-03 14:04:32 -04003695 adapter->state = VNIC_PROBING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003696 dev_set_drvdata(&dev->dev, netdev);
3697 adapter->vdev = dev;
3698 adapter->netdev = netdev;
3699
3700 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3701 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3702 netdev->irq = dev->irq;
3703 netdev->netdev_ops = &ibmvnic_netdev_ops;
3704 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3705 SET_NETDEV_DEV(netdev, &dev->dev);
3706
3707 spin_lock_init(&adapter->stats_lock);
3708
Thomas Falcon032c5e82015-12-21 11:26:06 -06003709 INIT_LIST_HEAD(&adapter->errors);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003710 spin_lock_init(&adapter->error_list_lock);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003711
Nathan Fontenoted651a12017-05-03 14:04:38 -04003712 INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset);
3713 INIT_LIST_HEAD(&adapter->rwi_list);
3714 mutex_init(&adapter->reset_lock);
3715 mutex_init(&adapter->rwi_lock);
3716 adapter->resetting = false;
3717
John Allenf6ef6402017-03-17 17:13:42 -05003718 rc = ibmvnic_init(adapter);
3719 if (rc) {
3720 free_netdev(netdev);
3721 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003722 }
3723
Thomas Falconf39f0d12017-02-14 10:22:59 -06003724 netdev->mtu = adapter->req_mtu - ETH_HLEN;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003725
Thomas Falcon40c9db82017-06-12 12:35:04 -05003726 rc = device_create_file(&dev->dev, &dev_attr_failover);
3727 if (rc) {
3728 free_netdev(netdev);
3729 return rc;
3730 }
3731
Thomas Falcon032c5e82015-12-21 11:26:06 -06003732 rc = register_netdev(netdev);
3733 if (rc) {
3734 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
Thomas Falcon40c9db82017-06-12 12:35:04 -05003735 device_remove_file(&dev->dev, &dev_attr_failover);
John Allenf6ef6402017-03-17 17:13:42 -05003736 free_netdev(netdev);
3737 return rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003738 }
3739 dev_info(&dev->dev, "ibmvnic registered\n");
3740
Nathan Fontenot90c80142017-05-03 14:04:32 -04003741 adapter->state = VNIC_PROBED;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003742 return 0;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003743}
3744
3745static int ibmvnic_remove(struct vio_dev *dev)
3746{
3747 struct net_device *netdev = dev_get_drvdata(&dev->dev);
Nathan Fontenot37489052017-04-19 13:45:04 -04003748 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003749
Nathan Fontenot90c80142017-05-03 14:04:32 -04003750 adapter->state = VNIC_REMOVING;
Thomas Falcon032c5e82015-12-21 11:26:06 -06003751 unregister_netdev(netdev);
Nathan Fontenoted651a12017-05-03 14:04:38 -04003752 mutex_lock(&adapter->reset_lock);
Nathan Fontenot37489052017-04-19 13:45:04 -04003753
3754 release_resources(adapter);
3755 release_sub_crqs(adapter);
3756 release_crq_queue(adapter);
3757
Nathan Fontenot90c80142017-05-03 14:04:32 -04003758 adapter->state = VNIC_REMOVED;
3759
Nathan Fontenoted651a12017-05-03 14:04:38 -04003760 mutex_unlock(&adapter->reset_lock);
Thomas Falcon40c9db82017-06-12 12:35:04 -05003761 device_remove_file(&dev->dev, &dev_attr_failover);
Thomas Falcon032c5e82015-12-21 11:26:06 -06003762 free_netdev(netdev);
3763 dev_set_drvdata(&dev->dev, NULL);
3764
3765 return 0;
3766}
3767
Thomas Falcon40c9db82017-06-12 12:35:04 -05003768static ssize_t failover_store(struct device *dev, struct device_attribute *attr,
3769 const char *buf, size_t count)
3770{
3771 struct net_device *netdev = dev_get_drvdata(dev);
3772 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3773 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
3774 __be64 session_token;
3775 long rc;
3776
3777 if (!sysfs_streq(buf, "1"))
3778 return -EINVAL;
3779
3780 rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address,
3781 H_GET_SESSION_TOKEN, 0, 0, 0);
3782 if (rc) {
3783 netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n",
3784 rc);
3785 return -EINVAL;
3786 }
3787
3788 session_token = (__be64)retbuf[0];
3789 netdev_dbg(netdev, "Initiating client failover, session id %llx\n",
3790 be64_to_cpu(session_token));
3791 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
3792 H_SESSION_ERR_DETECTED, session_token, 0, 0);
3793 if (rc) {
3794 netdev_err(netdev, "Client initiated failover failed, rc %ld\n",
3795 rc);
3796 return -EINVAL;
3797 }
3798
3799 return count;
3800}
3801
3802static DEVICE_ATTR(failover, 0200, NULL, failover_store);
3803
Thomas Falcon032c5e82015-12-21 11:26:06 -06003804static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3805{
3806 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3807 struct ibmvnic_adapter *adapter;
3808 struct iommu_table *tbl;
3809 unsigned long ret = 0;
3810 int i;
3811
3812 tbl = get_iommu_table_base(&vdev->dev);
3813
3814 /* netdev inits at probe time along with the structures we need below*/
3815 if (!netdev)
3816 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3817
3818 adapter = netdev_priv(netdev);
3819
3820 ret += PAGE_SIZE; /* the crq message queue */
Thomas Falcon032c5e82015-12-21 11:26:06 -06003821 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3822
3823 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3824 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3825
3826 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3827 i++)
3828 ret += adapter->rx_pool[i].size *
3829 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3830
3831 return ret;
3832}
3833
3834static int ibmvnic_resume(struct device *dev)
3835{
3836 struct net_device *netdev = dev_get_drvdata(dev);
3837 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3838 int i;
3839
3840 /* kick the interrupt handlers just in case we lost an interrupt */
3841 for (i = 0; i < adapter->req_rx_queues; i++)
3842 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3843 adapter->rx_scrq[i]);
3844
3845 return 0;
3846}
3847
3848static struct vio_device_id ibmvnic_device_table[] = {
3849 {"network", "IBM,vnic"},
3850 {"", "" }
3851};
3852MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3853
3854static const struct dev_pm_ops ibmvnic_pm_ops = {
3855 .resume = ibmvnic_resume
3856};
3857
3858static struct vio_driver ibmvnic_driver = {
3859 .id_table = ibmvnic_device_table,
3860 .probe = ibmvnic_probe,
3861 .remove = ibmvnic_remove,
3862 .get_desired_dma = ibmvnic_get_desired_dma,
3863 .name = ibmvnic_driver_name,
3864 .pm = &ibmvnic_pm_ops,
3865};
3866
3867/* module functions */
3868static int __init ibmvnic_module_init(void)
3869{
3870 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3871 IBMVNIC_DRIVER_VERSION);
3872
3873 return vio_register_driver(&ibmvnic_driver);
3874}
3875
3876static void __exit ibmvnic_module_exit(void)
3877{
3878 vio_unregister_driver(&ibmvnic_driver);
3879}
3880
3881module_init(ibmvnic_module_init);
3882module_exit(ibmvnic_module_exit);