1 /**************************************************************************/
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) */
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. */
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. */
19 /* You should have received a copy of the GNU General Public License */
20 /* along with this program. */
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. */
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. */
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. */
44 /**************************************************************************/
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>
60 #include <linux/ethtool.h>
61 #include <linux/proc_fs.h>
62 #include <linux/if_arp.h>
65 #include <linux/ipv6.h>
66 #include <linux/irq.h>
67 #include <linux/kthread.h>
68 #include <linux/seq_file.h>
69 #include <linux/interrupt.h>
70 #include <net/net_namespace.h>
71 #include <asm/hvcall.h>
72 #include <linux/atomic.h>
74 #include <asm/iommu.h>
75 #include <linux/uaccess.h>
76 #include <asm/firmware.h>
77 #include <linux/workqueue.h>
78 #include <linux/if_vlan.h>
79 #include <linux/utsname.h>
83 static const char ibmvnic_driver_name[] = "ibmvnic";
84 static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
86 MODULE_AUTHOR("Santiago Leon");
87 MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
91 static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
92 static int ibmvnic_remove(struct vio_dev *);
93 static void release_sub_crqs(struct ibmvnic_adapter *, bool);
94 static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
95 static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
96 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
97 static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
98 static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
99 union sub_crq *sub_crq);
100 static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
101 static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
102 static int enable_scrq_irq(struct ibmvnic_adapter *,
103 struct ibmvnic_sub_crq_queue *);
104 static int disable_scrq_irq(struct ibmvnic_adapter *,
105 struct ibmvnic_sub_crq_queue *);
106 static int pending_scrq(struct ibmvnic_adapter *,
107 struct ibmvnic_sub_crq_queue *);
108 static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
109 struct ibmvnic_sub_crq_queue *);
110 static int ibmvnic_poll(struct napi_struct *napi, int data);
111 static void send_map_query(struct ibmvnic_adapter *adapter);
112 static int send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
113 static int send_request_unmap(struct ibmvnic_adapter *, u8);
114 static int send_login(struct ibmvnic_adapter *adapter);
115 static void send_cap_queries(struct ibmvnic_adapter *adapter);
116 static int init_sub_crqs(struct ibmvnic_adapter *);
117 static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
118 static int ibmvnic_init(struct ibmvnic_adapter *);
119 static int ibmvnic_reset_init(struct ibmvnic_adapter *);
120 static void release_crq_queue(struct ibmvnic_adapter *);
121 static int __ibmvnic_set_mac(struct net_device *netdev, struct sockaddr *p);
122 static int init_crq_queue(struct ibmvnic_adapter *adapter);
124 struct ibmvnic_stat {
125 char name[ETH_GSTRING_LEN];
129 #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
130 offsetof(struct ibmvnic_statistics, stat))
131 #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
133 static const struct ibmvnic_stat ibmvnic_stats[] = {
134 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
135 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
136 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
137 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
138 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
139 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
140 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
141 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
142 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
143 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
144 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
145 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
146 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
147 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
148 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
149 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
150 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
151 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
152 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
153 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
154 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
155 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
158 static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
159 unsigned long length, unsigned long *number,
162 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
165 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
172 static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
173 struct ibmvnic_long_term_buff *ltb, int size)
175 struct device *dev = &adapter->vdev->dev;
179 ltb->buff = dma_alloc_coherent(dev, ltb->size, <b->addr,
183 dev_err(dev, "Couldn't alloc long term buffer\n");
186 ltb->map_id = adapter->map_id;
189 init_completion(&adapter->fw_done);
190 rc = send_request_map(adapter, ltb->addr,
191 ltb->size, ltb->map_id);
193 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
196 wait_for_completion(&adapter->fw_done);
198 if (adapter->fw_done_rc) {
199 dev_err(dev, "Couldn't map long term buffer,rc = %d\n",
200 adapter->fw_done_rc);
201 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
207 static void free_long_term_buff(struct ibmvnic_adapter *adapter,
208 struct ibmvnic_long_term_buff *ltb)
210 struct device *dev = &adapter->vdev->dev;
215 if (adapter->reset_reason != VNIC_RESET_FAILOVER &&
216 adapter->reset_reason != VNIC_RESET_MOBILITY)
217 send_request_unmap(adapter, ltb->map_id);
218 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
221 static int reset_long_term_buff(struct ibmvnic_adapter *adapter,
222 struct ibmvnic_long_term_buff *ltb)
226 memset(ltb->buff, 0, ltb->size);
228 init_completion(&adapter->fw_done);
229 rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id);
232 wait_for_completion(&adapter->fw_done);
234 if (adapter->fw_done_rc) {
235 dev_info(&adapter->vdev->dev,
236 "Reset failed, attempting to free and reallocate buffer\n");
237 free_long_term_buff(adapter, ltb);
238 return alloc_long_term_buff(adapter, ltb, ltb->size);
243 static void deactivate_rx_pools(struct ibmvnic_adapter *adapter)
247 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
249 adapter->rx_pool[i].active = 0;
252 static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
253 struct ibmvnic_rx_pool *pool)
255 int count = pool->size - atomic_read(&pool->available);
256 struct device *dev = &adapter->vdev->dev;
257 int buffers_added = 0;
258 unsigned long lpar_rc;
259 union sub_crq sub_crq;
272 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
273 be32_to_cpu(adapter->login_rsp_buf->
276 for (i = 0; i < count; ++i) {
277 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
279 dev_err(dev, "Couldn't replenish rx buff\n");
280 adapter->replenish_no_mem++;
284 index = pool->free_map[pool->next_free];
286 if (pool->rx_buff[index].skb)
287 dev_err(dev, "Inconsistent free_map!\n");
289 /* Copy the skb to the long term mapped DMA buffer */
290 offset = index * pool->buff_size;
291 dst = pool->long_term_buff.buff + offset;
292 memset(dst, 0, pool->buff_size);
293 dma_addr = pool->long_term_buff.addr + offset;
294 pool->rx_buff[index].data = dst;
296 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
297 pool->rx_buff[index].dma = dma_addr;
298 pool->rx_buff[index].skb = skb;
299 pool->rx_buff[index].pool_index = pool->index;
300 pool->rx_buff[index].size = pool->buff_size;
302 memset(&sub_crq, 0, sizeof(sub_crq));
303 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
304 sub_crq.rx_add.correlator =
305 cpu_to_be64((u64)&pool->rx_buff[index]);
306 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
307 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
309 /* The length field of the sCRQ is defined to be 24 bits so the
310 * buffer size needs to be left shifted by a byte before it is
311 * converted to big endian to prevent the last byte from being
314 #ifdef __LITTLE_ENDIAN__
317 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
319 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
321 if (lpar_rc != H_SUCCESS)
325 adapter->replenish_add_buff_success++;
326 pool->next_free = (pool->next_free + 1) % pool->size;
328 atomic_add(buffers_added, &pool->available);
332 if (lpar_rc != H_PARAMETER && lpar_rc != H_CLOSED)
333 dev_err_ratelimited(dev, "rx: replenish packet buffer failed\n");
334 pool->free_map[pool->next_free] = index;
335 pool->rx_buff[index].skb = NULL;
337 dev_kfree_skb_any(skb);
338 adapter->replenish_add_buff_failure++;
339 atomic_add(buffers_added, &pool->available);
341 if (lpar_rc == H_CLOSED || adapter->failover_pending) {
342 /* Disable buffer pool replenishment and report carrier off if
343 * queue is closed or pending failover.
344 * Firmware guarantees that a signal will be sent to the
345 * driver, triggering a reset.
347 deactivate_rx_pools(adapter);
348 netif_carrier_off(adapter->netdev);
352 static void replenish_pools(struct ibmvnic_adapter *adapter)
356 adapter->replenish_task_cycles++;
357 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
359 if (adapter->rx_pool[i].active)
360 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
364 static void release_stats_buffers(struct ibmvnic_adapter *adapter)
366 kfree(adapter->tx_stats_buffers);
367 kfree(adapter->rx_stats_buffers);
368 adapter->tx_stats_buffers = NULL;
369 adapter->rx_stats_buffers = NULL;
372 static int init_stats_buffers(struct ibmvnic_adapter *adapter)
374 adapter->tx_stats_buffers =
375 kcalloc(IBMVNIC_MAX_QUEUES,
376 sizeof(struct ibmvnic_tx_queue_stats),
378 if (!adapter->tx_stats_buffers)
381 adapter->rx_stats_buffers =
382 kcalloc(IBMVNIC_MAX_QUEUES,
383 sizeof(struct ibmvnic_rx_queue_stats),
385 if (!adapter->rx_stats_buffers)
391 static void release_stats_token(struct ibmvnic_adapter *adapter)
393 struct device *dev = &adapter->vdev->dev;
395 if (!adapter->stats_token)
398 dma_unmap_single(dev, adapter->stats_token,
399 sizeof(struct ibmvnic_statistics),
401 adapter->stats_token = 0;
404 static int init_stats_token(struct ibmvnic_adapter *adapter)
406 struct device *dev = &adapter->vdev->dev;
409 stok = dma_map_single(dev, &adapter->stats,
410 sizeof(struct ibmvnic_statistics),
412 if (dma_mapping_error(dev, stok)) {
413 dev_err(dev, "Couldn't map stats buffer\n");
417 adapter->stats_token = stok;
418 netdev_dbg(adapter->netdev, "Stats token initialized (%llx)\n", stok);
422 static int reset_rx_pools(struct ibmvnic_adapter *adapter)
424 struct ibmvnic_rx_pool *rx_pool;
429 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
430 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
432 rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
433 for (i = 0; i < rx_scrqs; i++) {
434 rx_pool = &adapter->rx_pool[i];
436 netdev_dbg(adapter->netdev, "Re-setting rx_pool[%d]\n", i);
438 if (rx_pool->buff_size != be64_to_cpu(size_array[i])) {
439 free_long_term_buff(adapter, &rx_pool->long_term_buff);
440 rx_pool->buff_size = be64_to_cpu(size_array[i]);
441 alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
445 rc = reset_long_term_buff(adapter,
446 &rx_pool->long_term_buff);
452 for (j = 0; j < rx_pool->size; j++)
453 rx_pool->free_map[j] = j;
455 memset(rx_pool->rx_buff, 0,
456 rx_pool->size * sizeof(struct ibmvnic_rx_buff));
458 atomic_set(&rx_pool->available, 0);
459 rx_pool->next_alloc = 0;
460 rx_pool->next_free = 0;
467 static void release_rx_pools(struct ibmvnic_adapter *adapter)
469 struct ibmvnic_rx_pool *rx_pool;
472 if (!adapter->rx_pool)
475 for (i = 0; i < adapter->num_active_rx_pools; i++) {
476 rx_pool = &adapter->rx_pool[i];
478 netdev_dbg(adapter->netdev, "Releasing rx_pool[%d]\n", i);
480 kfree(rx_pool->free_map);
481 free_long_term_buff(adapter, &rx_pool->long_term_buff);
483 if (!rx_pool->rx_buff)
486 for (j = 0; j < rx_pool->size; j++) {
487 if (rx_pool->rx_buff[j].skb) {
488 dev_kfree_skb_any(rx_pool->rx_buff[i].skb);
489 rx_pool->rx_buff[i].skb = NULL;
493 kfree(rx_pool->rx_buff);
496 kfree(adapter->rx_pool);
497 adapter->rx_pool = NULL;
498 adapter->num_active_rx_pools = 0;
501 static int init_rx_pools(struct net_device *netdev)
503 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
504 struct device *dev = &adapter->vdev->dev;
505 struct ibmvnic_rx_pool *rx_pool;
511 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
512 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
513 be32_to_cpu(adapter->login_rsp_buf->off_rxadd_buff_size));
515 adapter->rx_pool = kcalloc(rxadd_subcrqs,
516 sizeof(struct ibmvnic_rx_pool),
518 if (!adapter->rx_pool) {
519 dev_err(dev, "Failed to allocate rx pools\n");
523 adapter->num_active_rx_pools = rxadd_subcrqs;
525 for (i = 0; i < rxadd_subcrqs; i++) {
526 rx_pool = &adapter->rx_pool[i];
528 netdev_dbg(adapter->netdev,
529 "Initializing rx_pool[%d], %lld buffs, %lld bytes each\n",
530 i, adapter->req_rx_add_entries_per_subcrq,
531 be64_to_cpu(size_array[i]));
533 rx_pool->size = adapter->req_rx_add_entries_per_subcrq;
535 rx_pool->buff_size = be64_to_cpu(size_array[i]);
538 rx_pool->free_map = kcalloc(rx_pool->size, sizeof(int),
540 if (!rx_pool->free_map) {
541 release_rx_pools(adapter);
545 rx_pool->rx_buff = kcalloc(rx_pool->size,
546 sizeof(struct ibmvnic_rx_buff),
548 if (!rx_pool->rx_buff) {
549 dev_err(dev, "Couldn't alloc rx buffers\n");
550 release_rx_pools(adapter);
554 if (alloc_long_term_buff(adapter, &rx_pool->long_term_buff,
555 rx_pool->size * rx_pool->buff_size)) {
556 release_rx_pools(adapter);
560 for (j = 0; j < rx_pool->size; ++j)
561 rx_pool->free_map[j] = j;
563 atomic_set(&rx_pool->available, 0);
564 rx_pool->next_alloc = 0;
565 rx_pool->next_free = 0;
571 static int reset_one_tx_pool(struct ibmvnic_adapter *adapter,
572 struct ibmvnic_tx_pool *tx_pool)
576 rc = reset_long_term_buff(adapter, &tx_pool->long_term_buff);
580 memset(tx_pool->tx_buff, 0,
581 tx_pool->num_buffers *
582 sizeof(struct ibmvnic_tx_buff));
584 for (i = 0; i < tx_pool->num_buffers; i++)
585 tx_pool->free_map[i] = i;
587 tx_pool->consumer_index = 0;
588 tx_pool->producer_index = 0;
593 static int reset_tx_pools(struct ibmvnic_adapter *adapter)
598 tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
599 for (i = 0; i < tx_scrqs; i++) {
600 rc = reset_one_tx_pool(adapter, &adapter->tso_pool[i]);
603 rc = reset_one_tx_pool(adapter, &adapter->tx_pool[i]);
611 static void release_vpd_data(struct ibmvnic_adapter *adapter)
616 kfree(adapter->vpd->buff);
622 static void release_one_tx_pool(struct ibmvnic_adapter *adapter,
623 struct ibmvnic_tx_pool *tx_pool)
625 kfree(tx_pool->tx_buff);
626 kfree(tx_pool->free_map);
627 free_long_term_buff(adapter, &tx_pool->long_term_buff);
630 static void release_tx_pools(struct ibmvnic_adapter *adapter)
634 if (!adapter->tx_pool)
637 for (i = 0; i < adapter->num_active_tx_pools; i++) {
638 release_one_tx_pool(adapter, &adapter->tx_pool[i]);
639 release_one_tx_pool(adapter, &adapter->tso_pool[i]);
642 kfree(adapter->tx_pool);
643 adapter->tx_pool = NULL;
644 kfree(adapter->tso_pool);
645 adapter->tso_pool = NULL;
646 adapter->num_active_tx_pools = 0;
649 static int init_one_tx_pool(struct net_device *netdev,
650 struct ibmvnic_tx_pool *tx_pool,
651 int num_entries, int buf_size)
653 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
656 tx_pool->tx_buff = kcalloc(num_entries,
657 sizeof(struct ibmvnic_tx_buff),
659 if (!tx_pool->tx_buff)
662 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
663 num_entries * buf_size))
666 tx_pool->free_map = kcalloc(num_entries, sizeof(int), GFP_KERNEL);
667 if (!tx_pool->free_map)
670 for (i = 0; i < num_entries; i++)
671 tx_pool->free_map[i] = i;
673 tx_pool->consumer_index = 0;
674 tx_pool->producer_index = 0;
675 tx_pool->num_buffers = num_entries;
676 tx_pool->buf_size = buf_size;
681 static int init_tx_pools(struct net_device *netdev)
683 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
687 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
688 adapter->tx_pool = kcalloc(tx_subcrqs,
689 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
690 if (!adapter->tx_pool)
693 adapter->tso_pool = kcalloc(tx_subcrqs,
694 sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
695 if (!adapter->tso_pool)
698 adapter->num_active_tx_pools = tx_subcrqs;
700 for (i = 0; i < tx_subcrqs; i++) {
701 rc = init_one_tx_pool(netdev, &adapter->tx_pool[i],
702 adapter->req_tx_entries_per_subcrq,
703 adapter->req_mtu + VLAN_HLEN);
705 release_tx_pools(adapter);
709 init_one_tx_pool(netdev, &adapter->tso_pool[i],
713 release_tx_pools(adapter);
721 static void release_error_buffers(struct ibmvnic_adapter *adapter)
723 struct device *dev = &adapter->vdev->dev;
724 struct ibmvnic_error_buff *error_buff, *tmp;
727 spin_lock_irqsave(&adapter->error_list_lock, flags);
728 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list) {
729 list_del(&error_buff->list);
730 dma_unmap_single(dev, error_buff->dma, error_buff->len,
732 kfree(error_buff->buff);
735 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
738 static void ibmvnic_napi_enable(struct ibmvnic_adapter *adapter)
742 if (adapter->napi_enabled)
745 for (i = 0; i < adapter->req_rx_queues; i++)
746 napi_enable(&adapter->napi[i]);
748 adapter->napi_enabled = true;
751 static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter)
755 if (!adapter->napi_enabled)
758 for (i = 0; i < adapter->req_rx_queues; i++) {
759 netdev_dbg(adapter->netdev, "Disabling napi[%d]\n", i);
760 napi_disable(&adapter->napi[i]);
763 adapter->napi_enabled = false;
766 static int init_napi(struct ibmvnic_adapter *adapter)
770 adapter->napi = kcalloc(adapter->req_rx_queues,
771 sizeof(struct napi_struct), GFP_KERNEL);
775 for (i = 0; i < adapter->req_rx_queues; i++) {
776 netdev_dbg(adapter->netdev, "Adding napi[%d]\n", i);
777 netif_napi_add(adapter->netdev, &adapter->napi[i],
778 ibmvnic_poll, NAPI_POLL_WEIGHT);
781 adapter->num_active_rx_napi = adapter->req_rx_queues;
785 static void release_napi(struct ibmvnic_adapter *adapter)
792 for (i = 0; i < adapter->num_active_rx_napi; i++) {
793 if (&adapter->napi[i]) {
794 netdev_dbg(adapter->netdev,
795 "Releasing napi[%d]\n", i);
796 netif_napi_del(&adapter->napi[i]);
800 kfree(adapter->napi);
801 adapter->napi = NULL;
802 adapter->num_active_rx_napi = 0;
803 adapter->napi_enabled = false;
806 static int ibmvnic_login(struct net_device *netdev)
808 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
809 unsigned long timeout = msecs_to_jiffies(30000);
816 if (retry_count > IBMVNIC_MAX_QUEUES) {
817 netdev_warn(netdev, "Login attempts exceeded\n");
821 adapter->init_done_rc = 0;
822 reinit_completion(&adapter->init_done);
823 rc = send_login(adapter);
825 netdev_warn(netdev, "Unable to login\n");
829 if (!wait_for_completion_timeout(&adapter->init_done,
831 netdev_warn(netdev, "Login timed out\n");
835 if (adapter->init_done_rc == PARTIALSUCCESS) {
837 release_sub_crqs(adapter, 1);
841 "Received partial success, retrying...\n");
842 adapter->init_done_rc = 0;
843 reinit_completion(&adapter->init_done);
844 send_cap_queries(adapter);
845 if (!wait_for_completion_timeout(&adapter->init_done,
848 "Capabilities query timed out\n");
852 rc = init_sub_crqs(adapter);
855 "SCRQ initialization failed\n");
859 rc = init_sub_crq_irqs(adapter);
862 "SCRQ irq initialization failed\n");
865 } else if (adapter->init_done_rc) {
866 netdev_warn(netdev, "Adapter login failed\n");
871 /* handle pending MAC address changes after successful login */
872 if (adapter->mac_change_pending) {
873 __ibmvnic_set_mac(netdev, &adapter->desired.mac);
874 adapter->mac_change_pending = false;
880 static void release_login_buffer(struct ibmvnic_adapter *adapter)
882 kfree(adapter->login_buf);
883 adapter->login_buf = NULL;
886 static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
888 kfree(adapter->login_rsp_buf);
889 adapter->login_rsp_buf = NULL;
892 static void release_resources(struct ibmvnic_adapter *adapter)
894 release_vpd_data(adapter);
896 release_tx_pools(adapter);
897 release_rx_pools(adapter);
899 release_error_buffers(adapter);
900 release_napi(adapter);
901 release_login_rsp_buffer(adapter);
904 static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
906 struct net_device *netdev = adapter->netdev;
907 unsigned long timeout = msecs_to_jiffies(30000);
908 union ibmvnic_crq crq;
912 netdev_dbg(netdev, "setting link state %d\n", link_state);
914 memset(&crq, 0, sizeof(crq));
915 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
916 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
917 crq.logical_link_state.link_state = link_state;
922 reinit_completion(&adapter->init_done);
923 rc = ibmvnic_send_crq(adapter, &crq);
925 netdev_err(netdev, "Failed to set link state\n");
929 if (!wait_for_completion_timeout(&adapter->init_done,
931 netdev_err(netdev, "timeout setting link state\n");
935 if (adapter->init_done_rc == 1) {
936 /* Partuial success, delay and re-send */
939 } else if (adapter->init_done_rc) {
940 netdev_warn(netdev, "Unable to set link state, rc=%d\n",
941 adapter->init_done_rc);
942 return adapter->init_done_rc;
949 static int set_real_num_queues(struct net_device *netdev)
951 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
954 netdev_dbg(netdev, "Setting real tx/rx queues (%llx/%llx)\n",
955 adapter->req_tx_queues, adapter->req_rx_queues);
957 rc = netif_set_real_num_tx_queues(netdev, adapter->req_tx_queues);
959 netdev_err(netdev, "failed to set the number of tx queues\n");
963 rc = netif_set_real_num_rx_queues(netdev, adapter->req_rx_queues);
965 netdev_err(netdev, "failed to set the number of rx queues\n");
970 static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
972 struct device *dev = &adapter->vdev->dev;
973 union ibmvnic_crq crq;
977 if (adapter->vpd->buff)
978 len = adapter->vpd->len;
980 init_completion(&adapter->fw_done);
981 crq.get_vpd_size.first = IBMVNIC_CRQ_CMD;
982 crq.get_vpd_size.cmd = GET_VPD_SIZE;
983 rc = ibmvnic_send_crq(adapter, &crq);
986 wait_for_completion(&adapter->fw_done);
988 if (!adapter->vpd->len)
991 if (!adapter->vpd->buff)
992 adapter->vpd->buff = kzalloc(adapter->vpd->len, GFP_KERNEL);
993 else if (adapter->vpd->len != len)
995 krealloc(adapter->vpd->buff,
996 adapter->vpd->len, GFP_KERNEL);
998 if (!adapter->vpd->buff) {
999 dev_err(dev, "Could allocate VPD buffer\n");
1003 adapter->vpd->dma_addr =
1004 dma_map_single(dev, adapter->vpd->buff, adapter->vpd->len,
1006 if (dma_mapping_error(dev, adapter->vpd->dma_addr)) {
1007 dev_err(dev, "Could not map VPD buffer\n");
1008 kfree(adapter->vpd->buff);
1009 adapter->vpd->buff = NULL;
1013 reinit_completion(&adapter->fw_done);
1014 crq.get_vpd.first = IBMVNIC_CRQ_CMD;
1015 crq.get_vpd.cmd = GET_VPD;
1016 crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr);
1017 crq.get_vpd.len = cpu_to_be32((u32)adapter->vpd->len);
1018 rc = ibmvnic_send_crq(adapter, &crq);
1020 kfree(adapter->vpd->buff);
1021 adapter->vpd->buff = NULL;
1024 wait_for_completion(&adapter->fw_done);
1029 static int init_resources(struct ibmvnic_adapter *adapter)
1031 struct net_device *netdev = adapter->netdev;
1034 rc = set_real_num_queues(netdev);
1038 adapter->vpd = kzalloc(sizeof(*adapter->vpd), GFP_KERNEL);
1042 /* Vital Product Data (VPD) */
1043 rc = ibmvnic_get_vpd(adapter);
1045 netdev_err(netdev, "failed to initialize Vital Product Data (VPD)\n");
1049 adapter->map_id = 1;
1051 rc = init_napi(adapter);
1055 send_map_query(adapter);
1057 rc = init_rx_pools(netdev);
1061 rc = init_tx_pools(netdev);
1065 static int __ibmvnic_open(struct net_device *netdev)
1067 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1068 enum vnic_state prev_state = adapter->state;
1071 adapter->state = VNIC_OPENING;
1072 replenish_pools(adapter);
1073 ibmvnic_napi_enable(adapter);
1075 /* We're ready to receive frames, enable the sub-crq interrupts and
1076 * set the logical link state to up
1078 for (i = 0; i < adapter->req_rx_queues; i++) {
1079 netdev_dbg(netdev, "Enabling rx_scrq[%d] irq\n", i);
1080 if (prev_state == VNIC_CLOSED)
1081 enable_irq(adapter->rx_scrq[i]->irq);
1082 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
1085 for (i = 0; i < adapter->req_tx_queues; i++) {
1086 netdev_dbg(netdev, "Enabling tx_scrq[%d] irq\n", i);
1087 if (prev_state == VNIC_CLOSED)
1088 enable_irq(adapter->tx_scrq[i]->irq);
1089 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
1092 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_UP);
1094 for (i = 0; i < adapter->req_rx_queues; i++)
1095 napi_disable(&adapter->napi[i]);
1096 release_resources(adapter);
1100 netif_tx_start_all_queues(netdev);
1102 if (prev_state == VNIC_CLOSED) {
1103 for (i = 0; i < adapter->req_rx_queues; i++)
1104 napi_schedule(&adapter->napi[i]);
1107 adapter->state = VNIC_OPEN;
1111 static int ibmvnic_open(struct net_device *netdev)
1113 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1116 /* If device failover is pending, just set device state and return.
1117 * Device operation will be handled by reset routine.
1119 if (adapter->failover_pending) {
1120 adapter->state = VNIC_OPEN;
1124 mutex_lock(&adapter->reset_lock);
1126 if (adapter->state != VNIC_CLOSED) {
1127 rc = ibmvnic_login(netdev);
1129 mutex_unlock(&adapter->reset_lock);
1133 rc = init_resources(adapter);
1135 netdev_err(netdev, "failed to initialize resources\n");
1136 release_resources(adapter);
1137 mutex_unlock(&adapter->reset_lock);
1142 rc = __ibmvnic_open(netdev);
1143 netif_carrier_on(netdev);
1145 mutex_unlock(&adapter->reset_lock);
1150 static void clean_rx_pools(struct ibmvnic_adapter *adapter)
1152 struct ibmvnic_rx_pool *rx_pool;
1153 struct ibmvnic_rx_buff *rx_buff;
1158 if (!adapter->rx_pool)
1161 rx_scrqs = adapter->num_active_rx_pools;
1162 rx_entries = adapter->req_rx_add_entries_per_subcrq;
1164 /* Free any remaining skbs in the rx buffer pools */
1165 for (i = 0; i < rx_scrqs; i++) {
1166 rx_pool = &adapter->rx_pool[i];
1167 if (!rx_pool || !rx_pool->rx_buff)
1170 netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i);
1171 for (j = 0; j < rx_entries; j++) {
1172 rx_buff = &rx_pool->rx_buff[j];
1173 if (rx_buff && rx_buff->skb) {
1174 dev_kfree_skb_any(rx_buff->skb);
1175 rx_buff->skb = NULL;
1181 static void clean_one_tx_pool(struct ibmvnic_adapter *adapter,
1182 struct ibmvnic_tx_pool *tx_pool)
1184 struct ibmvnic_tx_buff *tx_buff;
1188 if (!tx_pool || !tx_pool->tx_buff)
1191 tx_entries = tx_pool->num_buffers;
1193 for (i = 0; i < tx_entries; i++) {
1194 tx_buff = &tx_pool->tx_buff[i];
1195 if (tx_buff && tx_buff->skb) {
1196 dev_kfree_skb_any(tx_buff->skb);
1197 tx_buff->skb = NULL;
1202 static void clean_tx_pools(struct ibmvnic_adapter *adapter)
1207 if (!adapter->tx_pool || !adapter->tso_pool)
1210 tx_scrqs = adapter->num_active_tx_pools;
1212 /* Free any remaining skbs in the tx buffer pools */
1213 for (i = 0; i < tx_scrqs; i++) {
1214 netdev_dbg(adapter->netdev, "Cleaning tx_pool[%d]\n", i);
1215 clean_one_tx_pool(adapter, &adapter->tx_pool[i]);
1216 clean_one_tx_pool(adapter, &adapter->tso_pool[i]);
1220 static void ibmvnic_disable_irqs(struct ibmvnic_adapter *adapter)
1222 struct net_device *netdev = adapter->netdev;
1225 if (adapter->tx_scrq) {
1226 for (i = 0; i < adapter->req_tx_queues; i++)
1227 if (adapter->tx_scrq[i]->irq) {
1229 "Disabling tx_scrq[%d] irq\n", i);
1230 disable_scrq_irq(adapter, adapter->tx_scrq[i]);
1231 disable_irq(adapter->tx_scrq[i]->irq);
1235 if (adapter->rx_scrq) {
1236 for (i = 0; i < adapter->req_rx_queues; i++) {
1237 if (adapter->rx_scrq[i]->irq) {
1239 "Disabling rx_scrq[%d] irq\n", i);
1240 disable_scrq_irq(adapter, adapter->rx_scrq[i]);
1241 disable_irq(adapter->rx_scrq[i]->irq);
1247 static void ibmvnic_cleanup(struct net_device *netdev)
1249 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1251 /* ensure that transmissions are stopped if called by do_reset */
1252 if (adapter->resetting)
1253 netif_tx_disable(netdev);
1255 netif_tx_stop_all_queues(netdev);
1257 ibmvnic_napi_disable(adapter);
1258 ibmvnic_disable_irqs(adapter);
1260 clean_rx_pools(adapter);
1261 clean_tx_pools(adapter);
1264 static int __ibmvnic_close(struct net_device *netdev)
1266 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1269 adapter->state = VNIC_CLOSING;
1270 rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN);
1273 adapter->state = VNIC_CLOSED;
1277 static int ibmvnic_close(struct net_device *netdev)
1279 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1282 /* If device failover is pending, just set device state and return.
1283 * Device operation will be handled by reset routine.
1285 if (adapter->failover_pending) {
1286 adapter->state = VNIC_CLOSED;
1290 mutex_lock(&adapter->reset_lock);
1291 rc = __ibmvnic_close(netdev);
1292 ibmvnic_cleanup(netdev);
1293 mutex_unlock(&adapter->reset_lock);
1299 * build_hdr_data - creates L2/L3/L4 header data buffer
1300 * @hdr_field - bitfield determining needed headers
1301 * @skb - socket buffer
1302 * @hdr_len - array of header lengths
1303 * @tot_len - total length of data
1305 * Reads hdr_field to determine which headers are needed by firmware.
1306 * Builds a buffer containing these headers. Saves individual header
1307 * lengths and total buffer length to be used to build descriptors.
1309 static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
1310 int *hdr_len, u8 *hdr_data)
1315 if (skb_vlan_tagged(skb) && !skb_vlan_tag_present(skb))
1316 hdr_len[0] = sizeof(struct vlan_ethhdr);
1318 hdr_len[0] = sizeof(struct ethhdr);
1320 if (skb->protocol == htons(ETH_P_IP)) {
1321 hdr_len[1] = ip_hdr(skb)->ihl * 4;
1322 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
1323 hdr_len[2] = tcp_hdrlen(skb);
1324 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
1325 hdr_len[2] = sizeof(struct udphdr);
1326 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1327 hdr_len[1] = sizeof(struct ipv6hdr);
1328 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
1329 hdr_len[2] = tcp_hdrlen(skb);
1330 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
1331 hdr_len[2] = sizeof(struct udphdr);
1332 } else if (skb->protocol == htons(ETH_P_ARP)) {
1333 hdr_len[1] = arp_hdr_len(skb->dev);
1337 memset(hdr_data, 0, 120);
1338 if ((hdr_field >> 6) & 1) {
1339 hdr = skb_mac_header(skb);
1340 memcpy(hdr_data, hdr, hdr_len[0]);
1344 if ((hdr_field >> 5) & 1) {
1345 hdr = skb_network_header(skb);
1346 memcpy(hdr_data + len, hdr, hdr_len[1]);
1350 if ((hdr_field >> 4) & 1) {
1351 hdr = skb_transport_header(skb);
1352 memcpy(hdr_data + len, hdr, hdr_len[2]);
1359 * create_hdr_descs - create header and header extension descriptors
1360 * @hdr_field - bitfield determining needed headers
1361 * @data - buffer containing header data
1362 * @len - length of data buffer
1363 * @hdr_len - array of individual header lengths
1364 * @scrq_arr - descriptor array
1366 * Creates header and, if needed, header extension descriptors and
1367 * places them in a descriptor array, scrq_arr
1370 static int create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
1371 union sub_crq *scrq_arr)
1373 union sub_crq hdr_desc;
1379 while (tmp_len > 0) {
1380 cur = hdr_data + len - tmp_len;
1382 memset(&hdr_desc, 0, sizeof(hdr_desc));
1383 if (cur != hdr_data) {
1384 data = hdr_desc.hdr_ext.data;
1385 tmp = tmp_len > 29 ? 29 : tmp_len;
1386 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
1387 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
1388 hdr_desc.hdr_ext.len = tmp;
1390 data = hdr_desc.hdr.data;
1391 tmp = tmp_len > 24 ? 24 : tmp_len;
1392 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
1393 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
1394 hdr_desc.hdr.len = tmp;
1395 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
1396 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
1397 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
1398 hdr_desc.hdr.flag = hdr_field << 1;
1400 memcpy(data, cur, tmp);
1402 *scrq_arr = hdr_desc;
1411 * build_hdr_descs_arr - build a header descriptor array
1412 * @skb - socket buffer
1413 * @num_entries - number of descriptors to be sent
1414 * @subcrq - first TX descriptor
1415 * @hdr_field - bit field determining which headers will be sent
1417 * This function will build a TX descriptor array with applicable
1418 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
1421 static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
1422 int *num_entries, u8 hdr_field)
1424 int hdr_len[3] = {0, 0, 0};
1426 u8 *hdr_data = txbuff->hdr_data;
1428 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
1430 *num_entries += create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
1431 txbuff->indir_arr + 1);
1434 static int ibmvnic_xmit_workarounds(struct sk_buff *skb,
1435 struct net_device *netdev)
1437 /* For some backing devices, mishandling of small packets
1438 * can result in a loss of connection or TX stall. Device
1439 * architects recommend that no packet should be smaller
1440 * than the minimum MTU value provided to the driver, so
1441 * pad any packets to that length
1443 if (skb->len < netdev->min_mtu)
1444 return skb_put_padto(skb, netdev->min_mtu);
1449 static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
1451 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1452 int queue_num = skb_get_queue_mapping(skb);
1453 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
1454 struct device *dev = &adapter->vdev->dev;
1455 struct ibmvnic_tx_buff *tx_buff = NULL;
1456 struct ibmvnic_sub_crq_queue *tx_scrq;
1457 struct ibmvnic_tx_pool *tx_pool;
1458 unsigned int tx_send_failed = 0;
1459 unsigned int tx_map_failed = 0;
1460 unsigned int tx_dropped = 0;
1461 unsigned int tx_packets = 0;
1462 unsigned int tx_bytes = 0;
1463 dma_addr_t data_dma_addr;
1464 struct netdev_queue *txq;
1465 unsigned long lpar_rc;
1466 union sub_crq tx_crq;
1467 unsigned int offset;
1468 int num_entries = 1;
1475 if (adapter->resetting) {
1476 if (!netif_subqueue_stopped(netdev, skb))
1477 netif_stop_subqueue(netdev, queue_num);
1478 dev_kfree_skb_any(skb);
1486 if (ibmvnic_xmit_workarounds(skb, netdev)) {
1492 if (skb_is_gso(skb))
1493 tx_pool = &adapter->tso_pool[queue_num];
1495 tx_pool = &adapter->tx_pool[queue_num];
1497 tx_scrq = adapter->tx_scrq[queue_num];
1498 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
1499 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
1500 be32_to_cpu(adapter->login_rsp_buf->off_txsubm_subcrqs));
1502 index = tx_pool->free_map[tx_pool->consumer_index];
1504 if (index == IBMVNIC_INVALID_MAP) {
1505 dev_kfree_skb_any(skb);
1512 tx_pool->free_map[tx_pool->consumer_index] = IBMVNIC_INVALID_MAP;
1514 offset = index * tx_pool->buf_size;
1515 dst = tx_pool->long_term_buff.buff + offset;
1516 memset(dst, 0, tx_pool->buf_size);
1517 data_dma_addr = tx_pool->long_term_buff.addr + offset;
1519 if (skb_shinfo(skb)->nr_frags) {
1523 skb_copy_from_linear_data(skb, dst, skb_headlen(skb));
1524 cur = skb_headlen(skb);
1526 /* Copy the frags */
1527 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1528 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1531 page_address(skb_frag_page(frag)) +
1532 frag->page_offset, skb_frag_size(frag));
1533 cur += skb_frag_size(frag);
1536 skb_copy_from_linear_data(skb, dst, skb->len);
1539 tx_pool->consumer_index =
1540 (tx_pool->consumer_index + 1) % tx_pool->num_buffers;
1542 tx_buff = &tx_pool->tx_buff[index];
1544 tx_buff->data_dma[0] = data_dma_addr;
1545 tx_buff->data_len[0] = skb->len;
1546 tx_buff->index = index;
1547 tx_buff->pool_index = queue_num;
1548 tx_buff->last_frag = true;
1550 memset(&tx_crq, 0, sizeof(tx_crq));
1551 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
1552 tx_crq.v1.type = IBMVNIC_TX_DESC;
1553 tx_crq.v1.n_crq_elem = 1;
1554 tx_crq.v1.n_sge = 1;
1555 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
1557 if (skb_is_gso(skb))
1558 tx_crq.v1.correlator =
1559 cpu_to_be32(index | IBMVNIC_TSO_POOL_MASK);
1561 tx_crq.v1.correlator = cpu_to_be32(index);
1562 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
1563 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
1564 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
1566 if (adapter->vlan_header_insertion) {
1567 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
1568 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
1571 if (skb->protocol == htons(ETH_P_IP)) {
1572 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
1573 proto = ip_hdr(skb)->protocol;
1574 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1575 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
1576 proto = ipv6_hdr(skb)->nexthdr;
1579 if (proto == IPPROTO_TCP)
1580 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
1581 else if (proto == IPPROTO_UDP)
1582 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
1584 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1585 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
1588 if (skb_is_gso(skb)) {
1589 tx_crq.v1.flags1 |= IBMVNIC_TX_LSO;
1590 tx_crq.v1.mss = cpu_to_be16(skb_shinfo(skb)->gso_size);
1593 /* determine if l2/3/4 headers are sent to firmware */
1594 if ((*hdrs >> 7) & 1) {
1595 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
1596 tx_crq.v1.n_crq_elem = num_entries;
1597 tx_buff->num_entries = num_entries;
1598 tx_buff->indir_arr[0] = tx_crq;
1599 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
1600 sizeof(tx_buff->indir_arr),
1602 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
1603 dev_kfree_skb_any(skb);
1604 tx_buff->skb = NULL;
1605 if (!firmware_has_feature(FW_FEATURE_CMO))
1606 dev_err(dev, "tx: unable to map descriptor array\n");
1612 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
1613 (u64)tx_buff->indir_dma,
1616 tx_buff->num_entries = num_entries;
1617 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
1620 if (lpar_rc != H_SUCCESS) {
1621 if (lpar_rc != H_CLOSED && lpar_rc != H_PARAMETER)
1622 dev_err_ratelimited(dev, "tx: send failed\n");
1623 dev_kfree_skb_any(skb);
1624 tx_buff->skb = NULL;
1626 if (lpar_rc == H_CLOSED || adapter->failover_pending) {
1627 /* Disable TX and report carrier off if queue is closed
1628 * or pending failover.
1629 * Firmware guarantees that a signal will be sent to the
1630 * driver, triggering a reset or some other action.
1632 netif_tx_stop_all_queues(netdev);
1633 netif_carrier_off(netdev);
1642 if (atomic_add_return(num_entries, &tx_scrq->used)
1643 >= adapter->req_tx_entries_per_subcrq) {
1644 netdev_dbg(netdev, "Stopping queue %d\n", queue_num);
1645 netif_stop_subqueue(netdev, queue_num);
1649 tx_bytes += skb->len;
1650 txq->trans_start = jiffies;
1655 /* roll back consumer index and map array*/
1656 if (tx_pool->consumer_index == 0)
1657 tx_pool->consumer_index =
1658 tx_pool->num_buffers - 1;
1660 tx_pool->consumer_index--;
1661 tx_pool->free_map[tx_pool->consumer_index] = index;
1663 netdev->stats.tx_dropped += tx_dropped;
1664 netdev->stats.tx_bytes += tx_bytes;
1665 netdev->stats.tx_packets += tx_packets;
1666 adapter->tx_send_failed += tx_send_failed;
1667 adapter->tx_map_failed += tx_map_failed;
1668 adapter->tx_stats_buffers[queue_num].packets += tx_packets;
1669 adapter->tx_stats_buffers[queue_num].bytes += tx_bytes;
1670 adapter->tx_stats_buffers[queue_num].dropped_packets += tx_dropped;
1675 static void ibmvnic_set_multi(struct net_device *netdev)
1677 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1678 struct netdev_hw_addr *ha;
1679 union ibmvnic_crq crq;
1681 memset(&crq, 0, sizeof(crq));
1682 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1683 crq.request_capability.cmd = REQUEST_CAPABILITY;
1685 if (netdev->flags & IFF_PROMISC) {
1686 if (!adapter->promisc_supported)
1689 if (netdev->flags & IFF_ALLMULTI) {
1690 /* Accept all multicast */
1691 memset(&crq, 0, sizeof(crq));
1692 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1693 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1694 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
1695 ibmvnic_send_crq(adapter, &crq);
1696 } else if (netdev_mc_empty(netdev)) {
1697 /* Reject all multicast */
1698 memset(&crq, 0, sizeof(crq));
1699 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1700 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1701 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
1702 ibmvnic_send_crq(adapter, &crq);
1704 /* Accept one or more multicast(s) */
1705 netdev_for_each_mc_addr(ha, netdev) {
1706 memset(&crq, 0, sizeof(crq));
1707 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
1708 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
1709 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
1710 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
1712 ibmvnic_send_crq(adapter, &crq);
1718 static int __ibmvnic_set_mac(struct net_device *netdev, struct sockaddr *p)
1720 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1721 struct sockaddr *addr = p;
1722 union ibmvnic_crq crq;
1725 if (!is_valid_ether_addr(addr->sa_data))
1726 return -EADDRNOTAVAIL;
1728 memset(&crq, 0, sizeof(crq));
1729 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
1730 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
1731 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
1733 init_completion(&adapter->fw_done);
1734 rc = ibmvnic_send_crq(adapter, &crq);
1737 wait_for_completion(&adapter->fw_done);
1738 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
1739 return adapter->fw_done_rc ? -EIO : 0;
1742 static int ibmvnic_set_mac(struct net_device *netdev, void *p)
1744 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1745 struct sockaddr *addr = p;
1748 if (adapter->state == VNIC_PROBED) {
1749 memcpy(&adapter->desired.mac, addr, sizeof(struct sockaddr));
1750 adapter->mac_change_pending = true;
1754 rc = __ibmvnic_set_mac(netdev, addr);
1760 * do_reset returns zero if we are able to keep processing reset events, or
1761 * non-zero if we hit a fatal error and must halt.
1763 static int do_reset(struct ibmvnic_adapter *adapter,
1764 struct ibmvnic_rwi *rwi, u32 reset_state)
1766 u64 old_num_rx_queues, old_num_tx_queues;
1767 struct net_device *netdev = adapter->netdev;
1770 netdev_dbg(adapter->netdev, "Re-setting driver (%d)\n",
1773 netif_carrier_off(netdev);
1774 adapter->reset_reason = rwi->reset_reason;
1776 old_num_rx_queues = adapter->req_rx_queues;
1777 old_num_tx_queues = adapter->req_tx_queues;
1779 ibmvnic_cleanup(netdev);
1781 if (adapter->reset_reason != VNIC_RESET_MOBILITY &&
1782 adapter->reset_reason != VNIC_RESET_FAILOVER) {
1783 rc = __ibmvnic_close(netdev);
1788 if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM ||
1789 adapter->wait_for_reset) {
1790 release_resources(adapter);
1791 release_sub_crqs(adapter, 1);
1792 release_crq_queue(adapter);
1795 if (adapter->reset_reason != VNIC_RESET_NON_FATAL) {
1796 /* remove the closed state so when we call open it appears
1797 * we are coming from the probed state.
1799 adapter->state = VNIC_PROBED;
1801 if (adapter->wait_for_reset) {
1802 rc = init_crq_queue(adapter);
1803 } else if (adapter->reset_reason == VNIC_RESET_MOBILITY) {
1804 rc = ibmvnic_reenable_crq_queue(adapter);
1805 release_sub_crqs(adapter, 1);
1807 rc = ibmvnic_reset_crq(adapter);
1809 rc = vio_enable_interrupts(adapter->vdev);
1813 netdev_err(adapter->netdev,
1814 "Couldn't initialize crq. rc=%d\n", rc);
1818 rc = ibmvnic_reset_init(adapter);
1820 return IBMVNIC_INIT_FAILED;
1822 /* If the adapter was in PROBE state prior to the reset,
1825 if (reset_state == VNIC_PROBED)
1828 rc = ibmvnic_login(netdev);
1830 adapter->state = VNIC_PROBED;
1834 if (adapter->reset_reason == VNIC_RESET_CHANGE_PARAM ||
1835 adapter->wait_for_reset) {
1836 rc = init_resources(adapter);
1839 } else if (adapter->req_rx_queues != old_num_rx_queues ||
1840 adapter->req_tx_queues != old_num_tx_queues) {
1841 adapter->map_id = 1;
1842 release_rx_pools(adapter);
1843 release_tx_pools(adapter);
1844 init_rx_pools(netdev);
1845 init_tx_pools(netdev);
1847 release_napi(adapter);
1850 rc = reset_tx_pools(adapter);
1854 rc = reset_rx_pools(adapter);
1858 ibmvnic_disable_irqs(adapter);
1860 adapter->state = VNIC_CLOSED;
1862 if (reset_state == VNIC_CLOSED)
1865 rc = __ibmvnic_open(netdev);
1867 if (list_empty(&adapter->rwi_list))
1868 adapter->state = VNIC_CLOSED;
1870 adapter->state = reset_state;
1876 for (i = 0; i < adapter->req_rx_queues; i++)
1877 napi_schedule(&adapter->napi[i]);
1879 if (adapter->reset_reason != VNIC_RESET_FAILOVER &&
1880 adapter->reset_reason != VNIC_RESET_CHANGE_PARAM)
1881 netdev_notify_peers(netdev);
1883 netif_carrier_on(netdev);
1888 static int do_hard_reset(struct ibmvnic_adapter *adapter,
1889 struct ibmvnic_rwi *rwi, u32 reset_state)
1891 struct net_device *netdev = adapter->netdev;
1894 netdev_dbg(adapter->netdev, "Hard resetting driver (%d)\n",
1897 netif_carrier_off(netdev);
1898 adapter->reset_reason = rwi->reset_reason;
1900 ibmvnic_cleanup(netdev);
1901 release_resources(adapter);
1902 release_sub_crqs(adapter, 0);
1903 release_crq_queue(adapter);
1905 /* remove the closed state so when we call open it appears
1906 * we are coming from the probed state.
1908 adapter->state = VNIC_PROBED;
1910 rc = init_crq_queue(adapter);
1912 netdev_err(adapter->netdev,
1913 "Couldn't initialize crq. rc=%d\n", rc);
1917 rc = ibmvnic_init(adapter);
1921 /* If the adapter was in PROBE state prior to the reset,
1924 if (reset_state == VNIC_PROBED)
1927 rc = ibmvnic_login(netdev);
1929 adapter->state = VNIC_PROBED;
1932 /* netif_set_real_num_xx_queues needs to take rtnl lock here
1933 * unless wait_for_reset is set, in which case the rtnl lock
1934 * has already been taken before initializing the reset
1936 if (!adapter->wait_for_reset) {
1938 rc = init_resources(adapter);
1941 rc = init_resources(adapter);
1946 ibmvnic_disable_irqs(adapter);
1947 adapter->state = VNIC_CLOSED;
1949 if (reset_state == VNIC_CLOSED)
1952 rc = __ibmvnic_open(netdev);
1954 if (list_empty(&adapter->rwi_list))
1955 adapter->state = VNIC_CLOSED;
1957 adapter->state = reset_state;
1962 netif_carrier_on(netdev);
1967 static struct ibmvnic_rwi *get_next_rwi(struct ibmvnic_adapter *adapter)
1969 struct ibmvnic_rwi *rwi;
1971 mutex_lock(&adapter->rwi_lock);
1973 if (!list_empty(&adapter->rwi_list)) {
1974 rwi = list_first_entry(&adapter->rwi_list, struct ibmvnic_rwi,
1976 list_del(&rwi->list);
1981 mutex_unlock(&adapter->rwi_lock);
1985 static void free_all_rwi(struct ibmvnic_adapter *adapter)
1987 struct ibmvnic_rwi *rwi;
1989 rwi = get_next_rwi(adapter);
1992 rwi = get_next_rwi(adapter);
1996 static void __ibmvnic_reset(struct work_struct *work)
1998 struct ibmvnic_rwi *rwi;
1999 struct ibmvnic_adapter *adapter;
2000 struct net_device *netdev;
2004 adapter = container_of(work, struct ibmvnic_adapter, ibmvnic_reset);
2005 netdev = adapter->netdev;
2007 mutex_lock(&adapter->reset_lock);
2008 reset_state = adapter->state;
2010 rwi = get_next_rwi(adapter);
2012 if (adapter->force_reset_recovery) {
2013 adapter->force_reset_recovery = false;
2014 rc = do_hard_reset(adapter, rwi, reset_state);
2016 rc = do_reset(adapter, rwi, reset_state);
2019 if (rc && rc != IBMVNIC_INIT_FAILED &&
2020 !adapter->force_reset_recovery)
2023 rwi = get_next_rwi(adapter);
2026 if (adapter->wait_for_reset) {
2027 adapter->wait_for_reset = false;
2028 adapter->reset_done_rc = rc;
2029 complete(&adapter->reset_done);
2033 netdev_dbg(adapter->netdev, "Reset failed\n");
2034 free_all_rwi(adapter);
2035 mutex_unlock(&adapter->reset_lock);
2039 adapter->resetting = false;
2040 mutex_unlock(&adapter->reset_lock);
2043 static int ibmvnic_reset(struct ibmvnic_adapter *adapter,
2044 enum ibmvnic_reset_reason reason)
2046 struct list_head *entry, *tmp_entry;
2047 struct ibmvnic_rwi *rwi, *tmp;
2048 struct net_device *netdev = adapter->netdev;
2051 if (adapter->state == VNIC_REMOVING ||
2052 adapter->state == VNIC_REMOVED ||
2053 adapter->failover_pending) {
2055 netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n");
2059 if (adapter->state == VNIC_PROBING) {
2060 netdev_warn(netdev, "Adapter reset during probe\n");
2061 ret = adapter->init_done_rc = EAGAIN;
2065 mutex_lock(&adapter->rwi_lock);
2067 list_for_each(entry, &adapter->rwi_list) {
2068 tmp = list_entry(entry, struct ibmvnic_rwi, list);
2069 if (tmp->reset_reason == reason) {
2070 netdev_dbg(netdev, "Skipping matching reset\n");
2071 mutex_unlock(&adapter->rwi_lock);
2077 rwi = kzalloc(sizeof(*rwi), GFP_KERNEL);
2079 mutex_unlock(&adapter->rwi_lock);
2080 ibmvnic_close(netdev);
2084 /* if we just received a transport event,
2085 * flush reset queue and process this reset
2087 if (adapter->force_reset_recovery && !list_empty(&adapter->rwi_list)) {
2088 list_for_each_safe(entry, tmp_entry, &adapter->rwi_list)
2091 rwi->reset_reason = reason;
2092 list_add_tail(&rwi->list, &adapter->rwi_list);
2093 mutex_unlock(&adapter->rwi_lock);
2094 adapter->resetting = true;
2095 netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason);
2096 schedule_work(&adapter->ibmvnic_reset);
2100 if (adapter->wait_for_reset)
2101 adapter->wait_for_reset = false;
2105 static void ibmvnic_tx_timeout(struct net_device *dev)
2107 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2109 ibmvnic_reset(adapter, VNIC_RESET_TIMEOUT);
2112 static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
2113 struct ibmvnic_rx_buff *rx_buff)
2115 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
2117 rx_buff->skb = NULL;
2119 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
2120 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
2122 atomic_dec(&pool->available);
2125 static int ibmvnic_poll(struct napi_struct *napi, int budget)
2127 struct net_device *netdev = napi->dev;
2128 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2129 int scrq_num = (int)(napi - adapter->napi);
2130 int frames_processed = 0;
2133 while (frames_processed < budget) {
2134 struct sk_buff *skb;
2135 struct ibmvnic_rx_buff *rx_buff;
2136 union sub_crq *next;
2141 if (unlikely(adapter->resetting &&
2142 adapter->reset_reason != VNIC_RESET_NON_FATAL)) {
2143 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
2144 napi_complete_done(napi, frames_processed);
2145 return frames_processed;
2148 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
2150 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
2152 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
2153 rx_comp.correlator);
2154 /* do error checking */
2155 if (next->rx_comp.rc) {
2156 netdev_dbg(netdev, "rx buffer returned with rc %x\n",
2157 be16_to_cpu(next->rx_comp.rc));
2158 /* free the entry */
2159 next->rx_comp.first = 0;
2160 dev_kfree_skb_any(rx_buff->skb);
2161 remove_buff_from_pool(adapter, rx_buff);
2163 } else if (!rx_buff->skb) {
2164 /* free the entry */
2165 next->rx_comp.first = 0;
2166 remove_buff_from_pool(adapter, rx_buff);
2170 length = be32_to_cpu(next->rx_comp.len);
2171 offset = be16_to_cpu(next->rx_comp.off_frame_data);
2172 flags = next->rx_comp.flags;
2174 skb_copy_to_linear_data(skb, rx_buff->data + offset,
2177 /* VLAN Header has been stripped by the system firmware and
2178 * needs to be inserted by the driver
2180 if (adapter->rx_vlan_header_insertion &&
2181 (flags & IBMVNIC_VLAN_STRIPPED))
2182 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2183 ntohs(next->rx_comp.vlan_tci));
2185 /* free the entry */
2186 next->rx_comp.first = 0;
2187 remove_buff_from_pool(adapter, rx_buff);
2189 skb_put(skb, length);
2190 skb->protocol = eth_type_trans(skb, netdev);
2191 skb_record_rx_queue(skb, scrq_num);
2193 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
2194 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
2195 skb->ip_summed = CHECKSUM_UNNECESSARY;
2199 napi_gro_receive(napi, skb); /* send it up */
2200 netdev->stats.rx_packets++;
2201 netdev->stats.rx_bytes += length;
2202 adapter->rx_stats_buffers[scrq_num].packets++;
2203 adapter->rx_stats_buffers[scrq_num].bytes += length;
2207 if (adapter->state != VNIC_CLOSING)
2208 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
2210 if (frames_processed < budget) {
2211 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
2212 napi_complete_done(napi, frames_processed);
2213 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
2214 napi_reschedule(napi)) {
2215 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
2219 return frames_processed;
2222 #ifdef CONFIG_NET_POLL_CONTROLLER
2223 static void ibmvnic_netpoll_controller(struct net_device *dev)
2225 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2228 replenish_pools(netdev_priv(dev));
2229 for (i = 0; i < adapter->req_rx_queues; i++)
2230 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
2231 adapter->rx_scrq[i]);
2235 static int wait_for_reset(struct ibmvnic_adapter *adapter)
2239 adapter->fallback.mtu = adapter->req_mtu;
2240 adapter->fallback.rx_queues = adapter->req_rx_queues;
2241 adapter->fallback.tx_queues = adapter->req_tx_queues;
2242 adapter->fallback.rx_entries = adapter->req_rx_add_entries_per_subcrq;
2243 adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq;
2245 init_completion(&adapter->reset_done);
2246 adapter->wait_for_reset = true;
2247 rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM);
2250 wait_for_completion(&adapter->reset_done);
2253 if (adapter->reset_done_rc) {
2255 adapter->desired.mtu = adapter->fallback.mtu;
2256 adapter->desired.rx_queues = adapter->fallback.rx_queues;
2257 adapter->desired.tx_queues = adapter->fallback.tx_queues;
2258 adapter->desired.rx_entries = adapter->fallback.rx_entries;
2259 adapter->desired.tx_entries = adapter->fallback.tx_entries;
2261 init_completion(&adapter->reset_done);
2262 adapter->wait_for_reset = true;
2263 rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM);
2266 wait_for_completion(&adapter->reset_done);
2268 adapter->wait_for_reset = false;
2273 static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu)
2275 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2277 adapter->desired.mtu = new_mtu + ETH_HLEN;
2279 return wait_for_reset(adapter);
2282 static netdev_features_t ibmvnic_features_check(struct sk_buff *skb,
2283 struct net_device *dev,
2284 netdev_features_t features)
2286 /* Some backing hardware adapters can not
2287 * handle packets with a MSS less than 224
2288 * or with only one segment.
2290 if (skb_is_gso(skb)) {
2291 if (skb_shinfo(skb)->gso_size < 224 ||
2292 skb_shinfo(skb)->gso_segs == 1)
2293 features &= ~NETIF_F_GSO_MASK;
2299 static const struct net_device_ops ibmvnic_netdev_ops = {
2300 .ndo_open = ibmvnic_open,
2301 .ndo_stop = ibmvnic_close,
2302 .ndo_start_xmit = ibmvnic_xmit,
2303 .ndo_set_rx_mode = ibmvnic_set_multi,
2304 .ndo_set_mac_address = ibmvnic_set_mac,
2305 .ndo_validate_addr = eth_validate_addr,
2306 .ndo_tx_timeout = ibmvnic_tx_timeout,
2307 #ifdef CONFIG_NET_POLL_CONTROLLER
2308 .ndo_poll_controller = ibmvnic_netpoll_controller,
2310 .ndo_change_mtu = ibmvnic_change_mtu,
2311 .ndo_features_check = ibmvnic_features_check,
2314 /* ethtool functions */
2316 static int ibmvnic_get_link_ksettings(struct net_device *netdev,
2317 struct ethtool_link_ksettings *cmd)
2319 u32 supported, advertising;
2321 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
2323 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
2325 cmd->base.speed = SPEED_1000;
2326 cmd->base.duplex = DUPLEX_FULL;
2327 cmd->base.port = PORT_FIBRE;
2328 cmd->base.phy_address = 0;
2329 cmd->base.autoneg = AUTONEG_ENABLE;
2331 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
2333 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
2339 static void ibmvnic_get_drvinfo(struct net_device *netdev,
2340 struct ethtool_drvinfo *info)
2342 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2344 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
2345 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
2346 strlcpy(info->fw_version, adapter->fw_version,
2347 sizeof(info->fw_version));
2350 static u32 ibmvnic_get_msglevel(struct net_device *netdev)
2352 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2354 return adapter->msg_enable;
2357 static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
2359 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2361 adapter->msg_enable = data;
2364 static u32 ibmvnic_get_link(struct net_device *netdev)
2366 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2368 /* Don't need to send a query because we request a logical link up at
2369 * init and then we wait for link state indications
2371 return adapter->logical_link_state;
2374 static void ibmvnic_get_ringparam(struct net_device *netdev,
2375 struct ethtool_ringparam *ring)
2377 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2379 ring->rx_max_pending = adapter->max_rx_add_entries_per_subcrq;
2380 ring->tx_max_pending = adapter->max_tx_entries_per_subcrq;
2381 ring->rx_mini_max_pending = 0;
2382 ring->rx_jumbo_max_pending = 0;
2383 ring->rx_pending = adapter->req_rx_add_entries_per_subcrq;
2384 ring->tx_pending = adapter->req_tx_entries_per_subcrq;
2385 ring->rx_mini_pending = 0;
2386 ring->rx_jumbo_pending = 0;
2389 static int ibmvnic_set_ringparam(struct net_device *netdev,
2390 struct ethtool_ringparam *ring)
2392 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2394 if (ring->rx_pending > adapter->max_rx_add_entries_per_subcrq ||
2395 ring->tx_pending > adapter->max_tx_entries_per_subcrq) {
2396 netdev_err(netdev, "Invalid request.\n");
2397 netdev_err(netdev, "Max tx buffers = %llu\n",
2398 adapter->max_rx_add_entries_per_subcrq);
2399 netdev_err(netdev, "Max rx buffers = %llu\n",
2400 adapter->max_tx_entries_per_subcrq);
2404 adapter->desired.rx_entries = ring->rx_pending;
2405 adapter->desired.tx_entries = ring->tx_pending;
2407 return wait_for_reset(adapter);
2410 static void ibmvnic_get_channels(struct net_device *netdev,
2411 struct ethtool_channels *channels)
2413 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2415 channels->max_rx = adapter->max_rx_queues;
2416 channels->max_tx = adapter->max_tx_queues;
2417 channels->max_other = 0;
2418 channels->max_combined = 0;
2419 channels->rx_count = adapter->req_rx_queues;
2420 channels->tx_count = adapter->req_tx_queues;
2421 channels->other_count = 0;
2422 channels->combined_count = 0;
2425 static int ibmvnic_set_channels(struct net_device *netdev,
2426 struct ethtool_channels *channels)
2428 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
2430 adapter->desired.rx_queues = channels->rx_count;
2431 adapter->desired.tx_queues = channels->tx_count;
2433 return wait_for_reset(adapter);
2436 static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
2438 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2441 if (stringset != ETH_SS_STATS)
2444 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
2445 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
2447 for (i = 0; i < adapter->req_tx_queues; i++) {
2448 snprintf(data, ETH_GSTRING_LEN, "tx%d_packets", i);
2449 data += ETH_GSTRING_LEN;
2451 snprintf(data, ETH_GSTRING_LEN, "tx%d_bytes", i);
2452 data += ETH_GSTRING_LEN;
2454 snprintf(data, ETH_GSTRING_LEN, "tx%d_dropped_packets", i);
2455 data += ETH_GSTRING_LEN;
2458 for (i = 0; i < adapter->req_rx_queues; i++) {
2459 snprintf(data, ETH_GSTRING_LEN, "rx%d_packets", i);
2460 data += ETH_GSTRING_LEN;
2462 snprintf(data, ETH_GSTRING_LEN, "rx%d_bytes", i);
2463 data += ETH_GSTRING_LEN;
2465 snprintf(data, ETH_GSTRING_LEN, "rx%d_interrupts", i);
2466 data += ETH_GSTRING_LEN;
2470 static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
2472 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2476 return ARRAY_SIZE(ibmvnic_stats) +
2477 adapter->req_tx_queues * NUM_TX_STATS +
2478 adapter->req_rx_queues * NUM_RX_STATS;
2484 static void ibmvnic_get_ethtool_stats(struct net_device *dev,
2485 struct ethtool_stats *stats, u64 *data)
2487 struct ibmvnic_adapter *adapter = netdev_priv(dev);
2488 union ibmvnic_crq crq;
2492 memset(&crq, 0, sizeof(crq));
2493 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
2494 crq.request_statistics.cmd = REQUEST_STATISTICS;
2495 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
2496 crq.request_statistics.len =
2497 cpu_to_be32(sizeof(struct ibmvnic_statistics));
2499 /* Wait for data to be written */
2500 init_completion(&adapter->stats_done);
2501 rc = ibmvnic_send_crq(adapter, &crq);
2504 wait_for_completion(&adapter->stats_done);
2506 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
2507 data[i] = be64_to_cpu(IBMVNIC_GET_STAT(adapter,
2508 ibmvnic_stats[i].offset));
2510 for (j = 0; j < adapter->req_tx_queues; j++) {
2511 data[i] = adapter->tx_stats_buffers[j].packets;
2513 data[i] = adapter->tx_stats_buffers[j].bytes;
2515 data[i] = adapter->tx_stats_buffers[j].dropped_packets;
2519 for (j = 0; j < adapter->req_rx_queues; j++) {
2520 data[i] = adapter->rx_stats_buffers[j].packets;
2522 data[i] = adapter->rx_stats_buffers[j].bytes;
2524 data[i] = adapter->rx_stats_buffers[j].interrupts;
2529 static const struct ethtool_ops ibmvnic_ethtool_ops = {
2530 .get_drvinfo = ibmvnic_get_drvinfo,
2531 .get_msglevel = ibmvnic_get_msglevel,
2532 .set_msglevel = ibmvnic_set_msglevel,
2533 .get_link = ibmvnic_get_link,
2534 .get_ringparam = ibmvnic_get_ringparam,
2535 .set_ringparam = ibmvnic_set_ringparam,
2536 .get_channels = ibmvnic_get_channels,
2537 .set_channels = ibmvnic_set_channels,
2538 .get_strings = ibmvnic_get_strings,
2539 .get_sset_count = ibmvnic_get_sset_count,
2540 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
2541 .get_link_ksettings = ibmvnic_get_link_ksettings,
2544 /* Routines for managing CRQs/sCRQs */
2546 static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter,
2547 struct ibmvnic_sub_crq_queue *scrq)
2552 free_irq(scrq->irq, scrq);
2553 irq_dispose_mapping(scrq->irq);
2557 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
2558 atomic_set(&scrq->used, 0);
2561 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
2562 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
2566 static int reset_sub_crq_queues(struct ibmvnic_adapter *adapter)
2570 for (i = 0; i < adapter->req_tx_queues; i++) {
2571 netdev_dbg(adapter->netdev, "Re-setting tx_scrq[%d]\n", i);
2572 rc = reset_one_sub_crq_queue(adapter, adapter->tx_scrq[i]);
2577 for (i = 0; i < adapter->req_rx_queues; i++) {
2578 netdev_dbg(adapter->netdev, "Re-setting rx_scrq[%d]\n", i);
2579 rc = reset_one_sub_crq_queue(adapter, adapter->rx_scrq[i]);
2587 static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
2588 struct ibmvnic_sub_crq_queue *scrq,
2591 struct device *dev = &adapter->vdev->dev;
2594 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
2597 /* Close the sub-crqs */
2599 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
2600 adapter->vdev->unit_address,
2602 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
2605 netdev_err(adapter->netdev,
2606 "Failed to release sub-CRQ %16lx, rc = %ld\n",
2611 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
2613 free_pages((unsigned long)scrq->msgs, 2);
2617 static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
2620 struct device *dev = &adapter->vdev->dev;
2621 struct ibmvnic_sub_crq_queue *scrq;
2624 scrq = kzalloc(sizeof(*scrq), GFP_KERNEL);
2629 (union sub_crq *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 2);
2631 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
2632 goto zero_page_failed;
2635 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
2637 if (dma_mapping_error(dev, scrq->msg_token)) {
2638 dev_warn(dev, "Couldn't map crq queue messages page\n");
2642 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
2643 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
2645 if (rc == H_RESOURCE)
2646 rc = ibmvnic_reset_crq(adapter);
2648 if (rc == H_CLOSED) {
2649 dev_warn(dev, "Partner adapter not ready, waiting.\n");
2651 dev_warn(dev, "Error %d registering sub-crq\n", rc);
2655 scrq->adapter = adapter;
2656 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
2657 spin_lock_init(&scrq->lock);
2659 netdev_dbg(adapter->netdev,
2660 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
2661 scrq->crq_num, scrq->hw_irq, scrq->irq);
2666 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
2669 free_pages((unsigned long)scrq->msgs, 2);
2676 static void release_sub_crqs(struct ibmvnic_adapter *adapter, bool do_h_free)
2680 if (adapter->tx_scrq) {
2681 for (i = 0; i < adapter->num_active_tx_scrqs; i++) {
2682 if (!adapter->tx_scrq[i])
2685 netdev_dbg(adapter->netdev, "Releasing tx_scrq[%d]\n",
2687 if (adapter->tx_scrq[i]->irq) {
2688 free_irq(adapter->tx_scrq[i]->irq,
2689 adapter->tx_scrq[i]);
2690 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
2691 adapter->tx_scrq[i]->irq = 0;
2694 release_sub_crq_queue(adapter, adapter->tx_scrq[i],
2698 kfree(adapter->tx_scrq);
2699 adapter->tx_scrq = NULL;
2700 adapter->num_active_tx_scrqs = 0;
2703 if (adapter->rx_scrq) {
2704 for (i = 0; i < adapter->num_active_rx_scrqs; i++) {
2705 if (!adapter->rx_scrq[i])
2708 netdev_dbg(adapter->netdev, "Releasing rx_scrq[%d]\n",
2710 if (adapter->rx_scrq[i]->irq) {
2711 free_irq(adapter->rx_scrq[i]->irq,
2712 adapter->rx_scrq[i]);
2713 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
2714 adapter->rx_scrq[i]->irq = 0;
2717 release_sub_crq_queue(adapter, adapter->rx_scrq[i],
2721 kfree(adapter->rx_scrq);
2722 adapter->rx_scrq = NULL;
2723 adapter->num_active_rx_scrqs = 0;
2727 static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
2728 struct ibmvnic_sub_crq_queue *scrq)
2730 struct device *dev = &adapter->vdev->dev;
2733 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
2734 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
2736 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
2741 static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
2742 struct ibmvnic_sub_crq_queue *scrq)
2744 struct device *dev = &adapter->vdev->dev;
2747 if (scrq->hw_irq > 0x100000000ULL) {
2748 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
2752 if (adapter->resetting &&
2753 adapter->reset_reason == VNIC_RESET_MOBILITY) {
2754 u64 val = (0xff000000) | scrq->hw_irq;
2756 rc = plpar_hcall_norets(H_EOI, val);
2758 dev_err(dev, "H_EOI FAILED irq 0x%llx. rc=%ld\n",
2762 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
2763 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
2765 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
2770 static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
2771 struct ibmvnic_sub_crq_queue *scrq)
2773 struct device *dev = &adapter->vdev->dev;
2774 struct ibmvnic_tx_pool *tx_pool;
2775 struct ibmvnic_tx_buff *txbuff;
2776 union sub_crq *next;
2782 while (pending_scrq(adapter, scrq)) {
2783 unsigned int pool = scrq->pool_index;
2784 int num_entries = 0;
2786 next = ibmvnic_next_scrq(adapter, scrq);
2787 for (i = 0; i < next->tx_comp.num_comps; i++) {
2788 if (next->tx_comp.rcs[i]) {
2789 dev_err(dev, "tx error %x\n",
2790 next->tx_comp.rcs[i]);
2793 index = be32_to_cpu(next->tx_comp.correlators[i]);
2794 if (index & IBMVNIC_TSO_POOL_MASK) {
2795 tx_pool = &adapter->tso_pool[pool];
2796 index &= ~IBMVNIC_TSO_POOL_MASK;
2798 tx_pool = &adapter->tx_pool[pool];
2801 txbuff = &tx_pool->tx_buff[index];
2803 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
2804 if (!txbuff->data_dma[j])
2807 txbuff->data_dma[j] = 0;
2809 /* if sub_crq was sent indirectly */
2810 first = &txbuff->indir_arr[0].generic.first;
2811 if (*first == IBMVNIC_CRQ_CMD) {
2812 dma_unmap_single(dev, txbuff->indir_dma,
2813 sizeof(txbuff->indir_arr),
2818 if (txbuff->last_frag) {
2819 dev_kfree_skb_any(txbuff->skb);
2823 num_entries += txbuff->num_entries;
2825 tx_pool->free_map[tx_pool->producer_index] = index;
2826 tx_pool->producer_index =
2827 (tx_pool->producer_index + 1) %
2828 tx_pool->num_buffers;
2830 /* remove tx_comp scrq*/
2831 next->tx_comp.first = 0;
2833 if (atomic_sub_return(num_entries, &scrq->used) <=
2834 (adapter->req_tx_entries_per_subcrq / 2) &&
2835 __netif_subqueue_stopped(adapter->netdev,
2836 scrq->pool_index)) {
2837 netif_wake_subqueue(adapter->netdev, scrq->pool_index);
2838 netdev_dbg(adapter->netdev, "Started queue %d\n",
2843 enable_scrq_irq(adapter, scrq);
2845 if (pending_scrq(adapter, scrq)) {
2846 disable_scrq_irq(adapter, scrq);
2853 static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
2855 struct ibmvnic_sub_crq_queue *scrq = instance;
2856 struct ibmvnic_adapter *adapter = scrq->adapter;
2858 disable_scrq_irq(adapter, scrq);
2859 ibmvnic_complete_tx(adapter, scrq);
2864 static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
2866 struct ibmvnic_sub_crq_queue *scrq = instance;
2867 struct ibmvnic_adapter *adapter = scrq->adapter;
2869 /* When booting a kdump kernel we can hit pending interrupts
2870 * prior to completing driver initialization.
2872 if (unlikely(adapter->state != VNIC_OPEN))
2875 adapter->rx_stats_buffers[scrq->scrq_num].interrupts++;
2877 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
2878 disable_scrq_irq(adapter, scrq);
2879 __napi_schedule(&adapter->napi[scrq->scrq_num]);
2885 static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
2887 struct device *dev = &adapter->vdev->dev;
2888 struct ibmvnic_sub_crq_queue *scrq;
2892 for (i = 0; i < adapter->req_tx_queues; i++) {
2893 netdev_dbg(adapter->netdev, "Initializing tx_scrq[%d] irq\n",
2895 scrq = adapter->tx_scrq[i];
2896 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
2900 dev_err(dev, "Error mapping irq\n");
2901 goto req_tx_irq_failed;
2904 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
2905 0, "ibmvnic_tx", scrq);
2908 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
2910 irq_dispose_mapping(scrq->irq);
2911 goto req_tx_irq_failed;
2915 for (i = 0; i < adapter->req_rx_queues; i++) {
2916 netdev_dbg(adapter->netdev, "Initializing rx_scrq[%d] irq\n",
2918 scrq = adapter->rx_scrq[i];
2919 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
2922 dev_err(dev, "Error mapping irq\n");
2923 goto req_rx_irq_failed;
2925 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
2926 0, "ibmvnic_rx", scrq);
2928 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
2930 irq_dispose_mapping(scrq->irq);
2931 goto req_rx_irq_failed;
2937 for (j = 0; j < i; j++) {
2938 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
2939 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
2941 i = adapter->req_tx_queues;
2943 for (j = 0; j < i; j++) {
2944 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
2945 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
2947 release_sub_crqs(adapter, 1);
2951 static int init_sub_crqs(struct ibmvnic_adapter *adapter)
2953 struct device *dev = &adapter->vdev->dev;
2954 struct ibmvnic_sub_crq_queue **allqueues;
2955 int registered_queues = 0;
2960 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
2962 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_KERNEL);
2966 for (i = 0; i < total_queues; i++) {
2967 allqueues[i] = init_sub_crq_queue(adapter);
2968 if (!allqueues[i]) {
2969 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
2972 registered_queues++;
2975 /* Make sure we were able to register the minimum number of queues */
2976 if (registered_queues <
2977 adapter->min_tx_queues + adapter->min_rx_queues) {
2978 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
2982 /* Distribute the failed allocated queues*/
2983 for (i = 0; i < total_queues - registered_queues + more ; i++) {
2984 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
2987 if (adapter->req_rx_queues > adapter->min_rx_queues)
2988 adapter->req_rx_queues--;
2993 if (adapter->req_tx_queues > adapter->min_tx_queues)
2994 adapter->req_tx_queues--;
3001 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
3002 sizeof(*adapter->tx_scrq), GFP_KERNEL);
3003 if (!adapter->tx_scrq)
3006 for (i = 0; i < adapter->req_tx_queues; i++) {
3007 adapter->tx_scrq[i] = allqueues[i];
3008 adapter->tx_scrq[i]->pool_index = i;
3009 adapter->num_active_tx_scrqs++;
3012 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
3013 sizeof(*adapter->rx_scrq), GFP_KERNEL);
3014 if (!adapter->rx_scrq)
3017 for (i = 0; i < adapter->req_rx_queues; i++) {
3018 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
3019 adapter->rx_scrq[i]->scrq_num = i;
3020 adapter->num_active_rx_scrqs++;
3027 kfree(adapter->tx_scrq);
3028 adapter->tx_scrq = NULL;
3030 for (i = 0; i < registered_queues; i++)
3031 release_sub_crq_queue(adapter, allqueues[i], 1);
3036 static void ibmvnic_send_req_caps(struct ibmvnic_adapter *adapter, int retry)
3038 struct device *dev = &adapter->vdev->dev;
3039 union ibmvnic_crq crq;
3043 /* Sub-CRQ entries are 32 byte long */
3044 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
3046 if (adapter->min_tx_entries_per_subcrq > entries_page ||
3047 adapter->min_rx_add_entries_per_subcrq > entries_page) {
3048 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
3052 if (adapter->desired.mtu)
3053 adapter->req_mtu = adapter->desired.mtu;
3055 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
3057 if (!adapter->desired.tx_entries)
3058 adapter->desired.tx_entries =
3059 adapter->max_tx_entries_per_subcrq;
3060 if (!adapter->desired.rx_entries)
3061 adapter->desired.rx_entries =
3062 adapter->max_rx_add_entries_per_subcrq;
3064 max_entries = IBMVNIC_MAX_LTB_SIZE /
3065 (adapter->req_mtu + IBMVNIC_BUFFER_HLEN);
3067 if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) *
3068 adapter->desired.tx_entries > IBMVNIC_MAX_LTB_SIZE) {
3069 adapter->desired.tx_entries = max_entries;
3072 if ((adapter->req_mtu + IBMVNIC_BUFFER_HLEN) *
3073 adapter->desired.rx_entries > IBMVNIC_MAX_LTB_SIZE) {
3074 adapter->desired.rx_entries = max_entries;
3077 if (adapter->desired.tx_entries)
3078 adapter->req_tx_entries_per_subcrq =
3079 adapter->desired.tx_entries;
3081 adapter->req_tx_entries_per_subcrq =
3082 adapter->max_tx_entries_per_subcrq;
3084 if (adapter->desired.rx_entries)
3085 adapter->req_rx_add_entries_per_subcrq =
3086 adapter->desired.rx_entries;
3088 adapter->req_rx_add_entries_per_subcrq =
3089 adapter->max_rx_add_entries_per_subcrq;
3091 if (adapter->desired.tx_queues)
3092 adapter->req_tx_queues =
3093 adapter->desired.tx_queues;
3095 adapter->req_tx_queues =
3096 adapter->opt_tx_comp_sub_queues;
3098 if (adapter->desired.rx_queues)
3099 adapter->req_rx_queues =
3100 adapter->desired.rx_queues;
3102 adapter->req_rx_queues =
3103 adapter->opt_rx_comp_queues;
3105 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
3108 memset(&crq, 0, sizeof(crq));
3109 crq.request_capability.first = IBMVNIC_CRQ_CMD;
3110 crq.request_capability.cmd = REQUEST_CAPABILITY;
3112 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
3113 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
3114 atomic_inc(&adapter->running_cap_crqs);
3115 ibmvnic_send_crq(adapter, &crq);
3117 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
3118 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
3119 atomic_inc(&adapter->running_cap_crqs);
3120 ibmvnic_send_crq(adapter, &crq);
3122 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
3123 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
3124 atomic_inc(&adapter->running_cap_crqs);
3125 ibmvnic_send_crq(adapter, &crq);
3127 crq.request_capability.capability =
3128 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
3129 crq.request_capability.number =
3130 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
3131 atomic_inc(&adapter->running_cap_crqs);
3132 ibmvnic_send_crq(adapter, &crq);
3134 crq.request_capability.capability =
3135 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
3136 crq.request_capability.number =
3137 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
3138 atomic_inc(&adapter->running_cap_crqs);
3139 ibmvnic_send_crq(adapter, &crq);
3141 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
3142 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
3143 atomic_inc(&adapter->running_cap_crqs);
3144 ibmvnic_send_crq(adapter, &crq);
3146 if (adapter->netdev->flags & IFF_PROMISC) {
3147 if (adapter->promisc_supported) {
3148 crq.request_capability.capability =
3149 cpu_to_be16(PROMISC_REQUESTED);
3150 crq.request_capability.number = cpu_to_be64(1);
3151 atomic_inc(&adapter->running_cap_crqs);
3152 ibmvnic_send_crq(adapter, &crq);
3155 crq.request_capability.capability =
3156 cpu_to_be16(PROMISC_REQUESTED);
3157 crq.request_capability.number = cpu_to_be64(0);
3158 atomic_inc(&adapter->running_cap_crqs);
3159 ibmvnic_send_crq(adapter, &crq);
3163 static int pending_scrq(struct ibmvnic_adapter *adapter,
3164 struct ibmvnic_sub_crq_queue *scrq)
3166 union sub_crq *entry = &scrq->msgs[scrq->cur];
3168 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP)
3174 static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
3175 struct ibmvnic_sub_crq_queue *scrq)
3177 union sub_crq *entry;
3178 unsigned long flags;
3180 spin_lock_irqsave(&scrq->lock, flags);
3181 entry = &scrq->msgs[scrq->cur];
3182 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
3183 if (++scrq->cur == scrq->size)
3188 spin_unlock_irqrestore(&scrq->lock, flags);
3193 static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
3195 struct ibmvnic_crq_queue *queue = &adapter->crq;
3196 union ibmvnic_crq *crq;
3198 crq = &queue->msgs[queue->cur];
3199 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
3200 if (++queue->cur == queue->size)
3209 static void print_subcrq_error(struct device *dev, int rc, const char *func)
3213 dev_warn_ratelimited(dev,
3214 "%s failed: Send request is malformed or adapter failover pending. (rc=%d)\n",
3218 dev_warn_ratelimited(dev,
3219 "%s failed: Backing queue closed. Adapter is down or failover pending. (rc=%d)\n",
3223 dev_err_ratelimited(dev, "%s failed: (rc=%d)\n", func, rc);
3228 static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
3229 union sub_crq *sub_crq)
3231 unsigned int ua = adapter->vdev->unit_address;
3232 struct device *dev = &adapter->vdev->dev;
3233 u64 *u64_crq = (u64 *)sub_crq;
3236 netdev_dbg(adapter->netdev,
3237 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
3238 (unsigned long int)cpu_to_be64(remote_handle),
3239 (unsigned long int)cpu_to_be64(u64_crq[0]),
3240 (unsigned long int)cpu_to_be64(u64_crq[1]),
3241 (unsigned long int)cpu_to_be64(u64_crq[2]),
3242 (unsigned long int)cpu_to_be64(u64_crq[3]));
3244 /* Make sure the hypervisor sees the complete request */
3247 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
3248 cpu_to_be64(remote_handle),
3249 cpu_to_be64(u64_crq[0]),
3250 cpu_to_be64(u64_crq[1]),
3251 cpu_to_be64(u64_crq[2]),
3252 cpu_to_be64(u64_crq[3]));
3255 print_subcrq_error(dev, rc, __func__);
3260 static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
3261 u64 remote_handle, u64 ioba, u64 num_entries)
3263 unsigned int ua = adapter->vdev->unit_address;
3264 struct device *dev = &adapter->vdev->dev;
3267 /* Make sure the hypervisor sees the complete request */
3269 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
3270 cpu_to_be64(remote_handle),
3274 print_subcrq_error(dev, rc, __func__);
3279 static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
3280 union ibmvnic_crq *crq)
3282 unsigned int ua = adapter->vdev->unit_address;
3283 struct device *dev = &adapter->vdev->dev;
3284 u64 *u64_crq = (u64 *)crq;
3287 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
3288 (unsigned long int)cpu_to_be64(u64_crq[0]),
3289 (unsigned long int)cpu_to_be64(u64_crq[1]));
3291 if (!adapter->crq.active &&
3292 crq->generic.first != IBMVNIC_CRQ_INIT_CMD) {
3293 dev_warn(dev, "Invalid request detected while CRQ is inactive, possible device state change during reset\n");
3297 /* Make sure the hypervisor sees the complete request */
3300 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
3301 cpu_to_be64(u64_crq[0]),
3302 cpu_to_be64(u64_crq[1]));
3305 if (rc == H_CLOSED) {
3306 dev_warn(dev, "CRQ Queue closed\n");
3307 if (adapter->resetting)
3308 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
3311 dev_warn(dev, "Send error (rc=%d)\n", rc);
3317 static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
3319 union ibmvnic_crq crq;
3321 memset(&crq, 0, sizeof(crq));
3322 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
3323 crq.generic.cmd = IBMVNIC_CRQ_INIT;
3324 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
3326 return ibmvnic_send_crq(adapter, &crq);
3329 static int send_version_xchg(struct ibmvnic_adapter *adapter)
3331 union ibmvnic_crq crq;
3333 memset(&crq, 0, sizeof(crq));
3334 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
3335 crq.version_exchange.cmd = VERSION_EXCHANGE;
3336 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
3338 return ibmvnic_send_crq(adapter, &crq);
3341 struct vnic_login_client_data {
3347 static int vnic_client_data_len(struct ibmvnic_adapter *adapter)
3351 /* Calculate the amount of buffer space needed for the
3352 * vnic client data in the login buffer. There are four entries,
3353 * OS name, LPAR name, device name, and a null last entry.
3355 len = 4 * sizeof(struct vnic_login_client_data);
3356 len += 6; /* "Linux" plus NULL */
3357 len += strlen(utsname()->nodename) + 1;
3358 len += strlen(adapter->netdev->name) + 1;
3363 static void vnic_add_client_data(struct ibmvnic_adapter *adapter,
3364 struct vnic_login_client_data *vlcd)
3366 const char *os_name = "Linux";
3369 /* Type 1 - LPAR OS */
3371 len = strlen(os_name) + 1;
3372 vlcd->len = cpu_to_be16(len);
3373 strncpy(vlcd->name, os_name, len);
3374 vlcd = (struct vnic_login_client_data *)(vlcd->name + len);
3376 /* Type 2 - LPAR name */
3378 len = strlen(utsname()->nodename) + 1;
3379 vlcd->len = cpu_to_be16(len);
3380 strncpy(vlcd->name, utsname()->nodename, len);
3381 vlcd = (struct vnic_login_client_data *)(vlcd->name + len);
3383 /* Type 3 - device name */
3385 len = strlen(adapter->netdev->name) + 1;
3386 vlcd->len = cpu_to_be16(len);
3387 strncpy(vlcd->name, adapter->netdev->name, len);
3390 static int send_login(struct ibmvnic_adapter *adapter)
3392 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
3393 struct ibmvnic_login_buffer *login_buffer;
3394 struct device *dev = &adapter->vdev->dev;
3395 dma_addr_t rsp_buffer_token;
3396 dma_addr_t buffer_token;
3397 size_t rsp_buffer_size;
3398 union ibmvnic_crq crq;
3402 int client_data_len;
3403 struct vnic_login_client_data *vlcd;
3406 if (!adapter->tx_scrq || !adapter->rx_scrq) {
3407 netdev_err(adapter->netdev,
3408 "RX or TX queues are not allocated, device login failed\n");
3412 release_login_rsp_buffer(adapter);
3413 client_data_len = vnic_client_data_len(adapter);
3416 sizeof(struct ibmvnic_login_buffer) +
3417 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues) +
3420 login_buffer = kzalloc(buffer_size, GFP_ATOMIC);
3422 goto buf_alloc_failed;
3424 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
3426 if (dma_mapping_error(dev, buffer_token)) {
3427 dev_err(dev, "Couldn't map login buffer\n");
3428 goto buf_map_failed;
3431 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
3432 sizeof(u64) * adapter->req_tx_queues +
3433 sizeof(u64) * adapter->req_rx_queues +
3434 sizeof(u64) * adapter->req_rx_queues +
3435 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
3437 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
3438 if (!login_rsp_buffer)
3439 goto buf_rsp_alloc_failed;
3441 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
3442 rsp_buffer_size, DMA_FROM_DEVICE);
3443 if (dma_mapping_error(dev, rsp_buffer_token)) {
3444 dev_err(dev, "Couldn't map login rsp buffer\n");
3445 goto buf_rsp_map_failed;
3448 adapter->login_buf = login_buffer;
3449 adapter->login_buf_token = buffer_token;
3450 adapter->login_buf_sz = buffer_size;
3451 adapter->login_rsp_buf = login_rsp_buffer;
3452 adapter->login_rsp_buf_token = rsp_buffer_token;
3453 adapter->login_rsp_buf_sz = rsp_buffer_size;
3455 login_buffer->len = cpu_to_be32(buffer_size);
3456 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
3457 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
3458 login_buffer->off_txcomp_subcrqs =
3459 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
3460 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
3461 login_buffer->off_rxcomp_subcrqs =
3462 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
3463 sizeof(u64) * adapter->req_tx_queues);
3464 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
3465 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
3467 tx_list_p = (__be64 *)((char *)login_buffer +
3468 sizeof(struct ibmvnic_login_buffer));
3469 rx_list_p = (__be64 *)((char *)login_buffer +
3470 sizeof(struct ibmvnic_login_buffer) +
3471 sizeof(u64) * adapter->req_tx_queues);
3473 for (i = 0; i < adapter->req_tx_queues; i++) {
3474 if (adapter->tx_scrq[i]) {
3475 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
3480 for (i = 0; i < adapter->req_rx_queues; i++) {
3481 if (adapter->rx_scrq[i]) {
3482 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
3487 /* Insert vNIC login client data */
3488 vlcd = (struct vnic_login_client_data *)
3489 ((char *)rx_list_p + (sizeof(u64) * adapter->req_rx_queues));
3490 login_buffer->client_data_offset =
3491 cpu_to_be32((char *)vlcd - (char *)login_buffer);
3492 login_buffer->client_data_len = cpu_to_be32(client_data_len);
3494 vnic_add_client_data(adapter, vlcd);
3496 netdev_dbg(adapter->netdev, "Login Buffer:\n");
3497 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
3498 netdev_dbg(adapter->netdev, "%016lx\n",
3499 ((unsigned long int *)(adapter->login_buf))[i]);
3502 memset(&crq, 0, sizeof(crq));
3503 crq.login.first = IBMVNIC_CRQ_CMD;
3504 crq.login.cmd = LOGIN;
3505 crq.login.ioba = cpu_to_be32(buffer_token);
3506 crq.login.len = cpu_to_be32(buffer_size);
3507 ibmvnic_send_crq(adapter, &crq);
3512 kfree(login_rsp_buffer);
3513 buf_rsp_alloc_failed:
3514 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
3516 kfree(login_buffer);
3521 static int send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
3524 union ibmvnic_crq crq;
3526 memset(&crq, 0, sizeof(crq));
3527 crq.request_map.first = IBMVNIC_CRQ_CMD;
3528 crq.request_map.cmd = REQUEST_MAP;
3529 crq.request_map.map_id = map_id;
3530 crq.request_map.ioba = cpu_to_be32(addr);
3531 crq.request_map.len = cpu_to_be32(len);
3532 return ibmvnic_send_crq(adapter, &crq);
3535 static int send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
3537 union ibmvnic_crq crq;
3539 memset(&crq, 0, sizeof(crq));
3540 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
3541 crq.request_unmap.cmd = REQUEST_UNMAP;
3542 crq.request_unmap.map_id = map_id;
3543 return ibmvnic_send_crq(adapter, &crq);
3546 static void send_map_query(struct ibmvnic_adapter *adapter)
3548 union ibmvnic_crq crq;
3550 memset(&crq, 0, sizeof(crq));
3551 crq.query_map.first = IBMVNIC_CRQ_CMD;
3552 crq.query_map.cmd = QUERY_MAP;
3553 ibmvnic_send_crq(adapter, &crq);
3556 /* Send a series of CRQs requesting various capabilities of the VNIC server */
3557 static void send_cap_queries(struct ibmvnic_adapter *adapter)
3559 union ibmvnic_crq crq;
3561 atomic_set(&adapter->running_cap_crqs, 0);
3562 memset(&crq, 0, sizeof(crq));
3563 crq.query_capability.first = IBMVNIC_CRQ_CMD;
3564 crq.query_capability.cmd = QUERY_CAPABILITY;
3566 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
3567 atomic_inc(&adapter->running_cap_crqs);
3568 ibmvnic_send_crq(adapter, &crq);
3570 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
3571 atomic_inc(&adapter->running_cap_crqs);
3572 ibmvnic_send_crq(adapter, &crq);
3574 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
3575 atomic_inc(&adapter->running_cap_crqs);
3576 ibmvnic_send_crq(adapter, &crq);
3578 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
3579 atomic_inc(&adapter->running_cap_crqs);
3580 ibmvnic_send_crq(adapter, &crq);
3582 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
3583 atomic_inc(&adapter->running_cap_crqs);
3584 ibmvnic_send_crq(adapter, &crq);
3586 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
3587 atomic_inc(&adapter->running_cap_crqs);
3588 ibmvnic_send_crq(adapter, &crq);
3590 crq.query_capability.capability =
3591 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
3592 atomic_inc(&adapter->running_cap_crqs);
3593 ibmvnic_send_crq(adapter, &crq);
3595 crq.query_capability.capability =
3596 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
3597 atomic_inc(&adapter->running_cap_crqs);
3598 ibmvnic_send_crq(adapter, &crq);
3600 crq.query_capability.capability =
3601 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
3602 atomic_inc(&adapter->running_cap_crqs);
3603 ibmvnic_send_crq(adapter, &crq);
3605 crq.query_capability.capability =
3606 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
3607 atomic_inc(&adapter->running_cap_crqs);
3608 ibmvnic_send_crq(adapter, &crq);
3610 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
3611 atomic_inc(&adapter->running_cap_crqs);
3612 ibmvnic_send_crq(adapter, &crq);
3614 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
3615 atomic_inc(&adapter->running_cap_crqs);
3616 ibmvnic_send_crq(adapter, &crq);
3618 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
3619 atomic_inc(&adapter->running_cap_crqs);
3620 ibmvnic_send_crq(adapter, &crq);
3622 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
3623 atomic_inc(&adapter->running_cap_crqs);
3624 ibmvnic_send_crq(adapter, &crq);
3626 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
3627 atomic_inc(&adapter->running_cap_crqs);
3628 ibmvnic_send_crq(adapter, &crq);
3630 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
3631 atomic_inc(&adapter->running_cap_crqs);
3632 ibmvnic_send_crq(adapter, &crq);
3634 crq.query_capability.capability = cpu_to_be16(RX_VLAN_HEADER_INSERTION);
3635 atomic_inc(&adapter->running_cap_crqs);
3636 ibmvnic_send_crq(adapter, &crq);
3638 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
3639 atomic_inc(&adapter->running_cap_crqs);
3640 ibmvnic_send_crq(adapter, &crq);
3642 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
3643 atomic_inc(&adapter->running_cap_crqs);
3644 ibmvnic_send_crq(adapter, &crq);
3646 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
3647 atomic_inc(&adapter->running_cap_crqs);
3648 ibmvnic_send_crq(adapter, &crq);
3650 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
3651 atomic_inc(&adapter->running_cap_crqs);
3652 ibmvnic_send_crq(adapter, &crq);
3654 crq.query_capability.capability =
3655 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
3656 atomic_inc(&adapter->running_cap_crqs);
3657 ibmvnic_send_crq(adapter, &crq);
3659 crq.query_capability.capability =
3660 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
3661 atomic_inc(&adapter->running_cap_crqs);
3662 ibmvnic_send_crq(adapter, &crq);
3664 crq.query_capability.capability =
3665 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
3666 atomic_inc(&adapter->running_cap_crqs);
3667 ibmvnic_send_crq(adapter, &crq);
3669 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
3670 atomic_inc(&adapter->running_cap_crqs);
3671 ibmvnic_send_crq(adapter, &crq);
3674 static void handle_vpd_size_rsp(union ibmvnic_crq *crq,
3675 struct ibmvnic_adapter *adapter)
3677 struct device *dev = &adapter->vdev->dev;
3679 if (crq->get_vpd_size_rsp.rc.code) {
3680 dev_err(dev, "Error retrieving VPD size, rc=%x\n",
3681 crq->get_vpd_size_rsp.rc.code);
3682 complete(&adapter->fw_done);
3686 adapter->vpd->len = be64_to_cpu(crq->get_vpd_size_rsp.len);
3687 complete(&adapter->fw_done);
3690 static void handle_vpd_rsp(union ibmvnic_crq *crq,
3691 struct ibmvnic_adapter *adapter)
3693 struct device *dev = &adapter->vdev->dev;
3694 unsigned char *substr = NULL;
3695 u8 fw_level_len = 0;
3697 memset(adapter->fw_version, 0, 32);
3699 dma_unmap_single(dev, adapter->vpd->dma_addr, adapter->vpd->len,
3702 if (crq->get_vpd_rsp.rc.code) {
3703 dev_err(dev, "Error retrieving VPD from device, rc=%x\n",
3704 crq->get_vpd_rsp.rc.code);
3708 /* get the position of the firmware version info
3709 * located after the ASCII 'RM' substring in the buffer
3711 substr = strnstr(adapter->vpd->buff, "RM", adapter->vpd->len);
3713 dev_info(dev, "Warning - No FW level has been provided in the VPD buffer by the VIOS Server\n");
3717 /* get length of firmware level ASCII substring */
3718 if ((substr + 2) < (adapter->vpd->buff + adapter->vpd->len)) {
3719 fw_level_len = *(substr + 2);
3721 dev_info(dev, "Length of FW substr extrapolated VDP buff\n");
3725 /* copy firmware version string from vpd into adapter */
3726 if ((substr + 3 + fw_level_len) <
3727 (adapter->vpd->buff + adapter->vpd->len)) {
3728 strncpy((char *)adapter->fw_version, substr + 3, fw_level_len);
3730 dev_info(dev, "FW substr extrapolated VPD buff\n");
3734 if (adapter->fw_version[0] == '\0')
3735 strncpy((char *)adapter->fw_version, "N/A", 3 * sizeof(char));
3736 complete(&adapter->fw_done);
3739 static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
3741 struct device *dev = &adapter->vdev->dev;
3742 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
3743 union ibmvnic_crq crq;
3746 dma_unmap_single(dev, adapter->ip_offload_tok,
3747 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
3749 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
3750 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
3751 netdev_dbg(adapter->netdev, "%016lx\n",
3752 ((unsigned long int *)(buf))[i]);
3754 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
3755 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
3756 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
3757 buf->tcp_ipv4_chksum);
3758 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
3759 buf->tcp_ipv6_chksum);
3760 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
3761 buf->udp_ipv4_chksum);
3762 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
3763 buf->udp_ipv6_chksum);
3764 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
3765 buf->large_tx_ipv4);
3766 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
3767 buf->large_tx_ipv6);
3768 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
3769 buf->large_rx_ipv4);
3770 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
3771 buf->large_rx_ipv6);
3772 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
3773 buf->max_ipv4_header_size);
3774 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
3775 buf->max_ipv6_header_size);
3776 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
3777 buf->max_tcp_header_size);
3778 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
3779 buf->max_udp_header_size);
3780 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
3781 buf->max_large_tx_size);
3782 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
3783 buf->max_large_rx_size);
3784 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
3785 buf->ipv6_extension_header);
3786 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
3787 buf->tcp_pseudosum_req);
3788 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
3789 buf->num_ipv6_ext_headers);
3790 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
3791 buf->off_ipv6_ext_headers);
3793 adapter->ip_offload_ctrl_tok =
3794 dma_map_single(dev, &adapter->ip_offload_ctrl,
3795 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
3797 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
3798 dev_err(dev, "Couldn't map ip offload control buffer\n");
3802 adapter->ip_offload_ctrl.len =
3803 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
3804 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
3805 adapter->ip_offload_ctrl.ipv4_chksum = buf->ipv4_chksum;
3806 adapter->ip_offload_ctrl.ipv6_chksum = buf->ipv6_chksum;
3807 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
3808 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
3809 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
3810 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
3811 adapter->ip_offload_ctrl.large_tx_ipv4 = buf->large_tx_ipv4;
3812 adapter->ip_offload_ctrl.large_tx_ipv6 = buf->large_tx_ipv6;
3814 /* large_rx disabled for now, additional features needed */
3815 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
3816 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
3818 adapter->netdev->features = NETIF_F_SG | NETIF_F_GSO;
3820 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
3821 adapter->netdev->features |= NETIF_F_IP_CSUM;
3823 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
3824 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
3826 if ((adapter->netdev->features &
3827 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
3828 adapter->netdev->features |= NETIF_F_RXCSUM;
3830 if (buf->large_tx_ipv4)
3831 adapter->netdev->features |= NETIF_F_TSO;
3832 if (buf->large_tx_ipv6)
3833 adapter->netdev->features |= NETIF_F_TSO6;
3835 adapter->netdev->hw_features |= adapter->netdev->features;
3837 memset(&crq, 0, sizeof(crq));
3838 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
3839 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
3840 crq.control_ip_offload.len =
3841 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
3842 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
3843 ibmvnic_send_crq(adapter, &crq);
3846 static void handle_error_info_rsp(union ibmvnic_crq *crq,
3847 struct ibmvnic_adapter *adapter)
3849 struct device *dev = &adapter->vdev->dev;
3850 struct ibmvnic_error_buff *error_buff, *tmp;
3851 unsigned long flags;
3855 if (!crq->request_error_rsp.rc.code) {
3856 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
3857 crq->request_error_rsp.rc.code);
3861 spin_lock_irqsave(&adapter->error_list_lock, flags);
3862 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
3863 if (error_buff->error_id == crq->request_error_rsp.error_id) {
3865 list_del(&error_buff->list);
3868 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
3871 dev_err(dev, "Couldn't find error id %x\n",
3872 be32_to_cpu(crq->request_error_rsp.error_id));
3876 dev_err(dev, "Detailed info for error id %x:",
3877 be32_to_cpu(crq->request_error_rsp.error_id));
3879 for (i = 0; i < error_buff->len; i++) {
3880 pr_cont("%02x", (int)error_buff->buff[i]);
3886 dma_unmap_single(dev, error_buff->dma, error_buff->len,
3888 kfree(error_buff->buff);
3892 static void request_error_information(struct ibmvnic_adapter *adapter,
3893 union ibmvnic_crq *err_crq)
3895 struct device *dev = &adapter->vdev->dev;
3896 struct net_device *netdev = adapter->netdev;
3897 struct ibmvnic_error_buff *error_buff;
3898 unsigned long timeout = msecs_to_jiffies(30000);
3899 union ibmvnic_crq crq;
3900 unsigned long flags;
3903 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
3907 detail_len = be32_to_cpu(err_crq->error_indication.detail_error_sz);
3908 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
3909 if (!error_buff->buff) {
3914 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
3916 if (dma_mapping_error(dev, error_buff->dma)) {
3917 netdev_err(netdev, "Couldn't map error buffer\n");
3918 kfree(error_buff->buff);
3923 error_buff->len = detail_len;
3924 error_buff->error_id = err_crq->error_indication.error_id;
3926 spin_lock_irqsave(&adapter->error_list_lock, flags);
3927 list_add_tail(&error_buff->list, &adapter->errors);
3928 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
3930 memset(&crq, 0, sizeof(crq));
3931 crq.request_error_info.first = IBMVNIC_CRQ_CMD;
3932 crq.request_error_info.cmd = REQUEST_ERROR_INFO;
3933 crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
3934 crq.request_error_info.len = cpu_to_be32(detail_len);
3935 crq.request_error_info.error_id = err_crq->error_indication.error_id;
3937 rc = ibmvnic_send_crq(adapter, &crq);
3939 netdev_err(netdev, "failed to request error information\n");
3943 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3944 netdev_err(netdev, "timeout waiting for error information\n");
3951 spin_lock_irqsave(&adapter->error_list_lock, flags);
3952 list_del(&error_buff->list);
3953 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
3955 kfree(error_buff->buff);
3959 static void handle_error_indication(union ibmvnic_crq *crq,
3960 struct ibmvnic_adapter *adapter)
3962 struct device *dev = &adapter->vdev->dev;
3964 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
3965 crq->error_indication.flags
3966 & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
3967 be32_to_cpu(crq->error_indication.error_id),
3968 be16_to_cpu(crq->error_indication.error_cause));
3970 if (be32_to_cpu(crq->error_indication.error_id))
3971 request_error_information(adapter, crq);
3973 if (crq->error_indication.flags & IBMVNIC_FATAL_ERROR)
3974 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
3976 ibmvnic_reset(adapter, VNIC_RESET_NON_FATAL);
3979 static int handle_change_mac_rsp(union ibmvnic_crq *crq,
3980 struct ibmvnic_adapter *adapter)
3982 struct net_device *netdev = adapter->netdev;
3983 struct device *dev = &adapter->vdev->dev;
3986 rc = crq->change_mac_addr_rsp.rc.code;
3988 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
3991 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
3994 complete(&adapter->fw_done);
3998 static void handle_request_cap_rsp(union ibmvnic_crq *crq,
3999 struct ibmvnic_adapter *adapter)
4001 struct device *dev = &adapter->vdev->dev;
4005 atomic_dec(&adapter->running_cap_crqs);
4006 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
4008 req_value = &adapter->req_tx_queues;
4012 req_value = &adapter->req_rx_queues;
4015 case REQ_RX_ADD_QUEUES:
4016 req_value = &adapter->req_rx_add_queues;
4019 case REQ_TX_ENTRIES_PER_SUBCRQ:
4020 req_value = &adapter->req_tx_entries_per_subcrq;
4021 name = "tx_entries_per_subcrq";
4023 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
4024 req_value = &adapter->req_rx_add_entries_per_subcrq;
4025 name = "rx_add_entries_per_subcrq";
4028 req_value = &adapter->req_mtu;
4031 case PROMISC_REQUESTED:
4032 req_value = &adapter->promisc;
4036 dev_err(dev, "Got invalid cap request rsp %d\n",
4037 crq->request_capability.capability);
4041 switch (crq->request_capability_rsp.rc.code) {
4044 case PARTIALSUCCESS:
4045 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
4047 (long int)be64_to_cpu(crq->request_capability_rsp.
4050 if (be16_to_cpu(crq->request_capability_rsp.capability) ==
4052 pr_err("mtu of %llu is not supported. Reverting.\n",
4054 *req_value = adapter->fallback.mtu;
4057 be64_to_cpu(crq->request_capability_rsp.number);
4060 ibmvnic_send_req_caps(adapter, 1);
4063 dev_err(dev, "Error %d in request cap rsp\n",
4064 crq->request_capability_rsp.rc.code);
4068 /* Done receiving requested capabilities, query IP offload support */
4069 if (atomic_read(&adapter->running_cap_crqs) == 0) {
4070 union ibmvnic_crq newcrq;
4071 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
4072 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
4073 &adapter->ip_offload_buf;
4075 adapter->wait_capability = false;
4076 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
4080 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
4081 if (!firmware_has_feature(FW_FEATURE_CMO))
4082 dev_err(dev, "Couldn't map offload buffer\n");
4086 memset(&newcrq, 0, sizeof(newcrq));
4087 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
4088 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
4089 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
4090 newcrq.query_ip_offload.ioba =
4091 cpu_to_be32(adapter->ip_offload_tok);
4093 ibmvnic_send_crq(adapter, &newcrq);
4097 static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
4098 struct ibmvnic_adapter *adapter)
4100 struct device *dev = &adapter->vdev->dev;
4101 struct net_device *netdev = adapter->netdev;
4102 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
4103 struct ibmvnic_login_buffer *login = adapter->login_buf;
4106 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
4108 dma_unmap_single(dev, adapter->login_rsp_buf_token,
4109 adapter->login_rsp_buf_sz, DMA_FROM_DEVICE);
4111 /* If the number of queues requested can't be allocated by the
4112 * server, the login response will return with code 1. We will need
4113 * to resend the login buffer with fewer queues requested.
4115 if (login_rsp_crq->generic.rc.code) {
4116 adapter->init_done_rc = login_rsp_crq->generic.rc.code;
4117 complete(&adapter->init_done);
4121 netdev->mtu = adapter->req_mtu - ETH_HLEN;
4123 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
4124 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
4125 netdev_dbg(adapter->netdev, "%016lx\n",
4126 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
4130 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
4131 (be32_to_cpu(login->num_rxcomp_subcrqs) *
4132 adapter->req_rx_add_queues !=
4133 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
4134 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
4135 ibmvnic_remove(adapter->vdev);
4138 release_login_buffer(adapter);
4139 complete(&adapter->init_done);
4144 static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
4145 struct ibmvnic_adapter *adapter)
4147 struct device *dev = &adapter->vdev->dev;
4150 rc = crq->request_unmap_rsp.rc.code;
4152 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
4155 static void handle_query_map_rsp(union ibmvnic_crq *crq,
4156 struct ibmvnic_adapter *adapter)
4158 struct net_device *netdev = adapter->netdev;
4159 struct device *dev = &adapter->vdev->dev;
4162 rc = crq->query_map_rsp.rc.code;
4164 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
4167 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
4168 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
4169 crq->query_map_rsp.free_pages);
4172 static void handle_query_cap_rsp(union ibmvnic_crq *crq,
4173 struct ibmvnic_adapter *adapter)
4175 struct net_device *netdev = adapter->netdev;
4176 struct device *dev = &adapter->vdev->dev;
4179 atomic_dec(&adapter->running_cap_crqs);
4180 netdev_dbg(netdev, "Outstanding queries: %d\n",
4181 atomic_read(&adapter->running_cap_crqs));
4182 rc = crq->query_capability.rc.code;
4184 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
4188 switch (be16_to_cpu(crq->query_capability.capability)) {
4190 adapter->min_tx_queues =
4191 be64_to_cpu(crq->query_capability.number);
4192 netdev_dbg(netdev, "min_tx_queues = %lld\n",
4193 adapter->min_tx_queues);
4196 adapter->min_rx_queues =
4197 be64_to_cpu(crq->query_capability.number);
4198 netdev_dbg(netdev, "min_rx_queues = %lld\n",
4199 adapter->min_rx_queues);
4201 case MIN_RX_ADD_QUEUES:
4202 adapter->min_rx_add_queues =
4203 be64_to_cpu(crq->query_capability.number);
4204 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
4205 adapter->min_rx_add_queues);
4208 adapter->max_tx_queues =
4209 be64_to_cpu(crq->query_capability.number);
4210 netdev_dbg(netdev, "max_tx_queues = %lld\n",
4211 adapter->max_tx_queues);
4214 adapter->max_rx_queues =
4215 be64_to_cpu(crq->query_capability.number);
4216 netdev_dbg(netdev, "max_rx_queues = %lld\n",
4217 adapter->max_rx_queues);
4219 case MAX_RX_ADD_QUEUES:
4220 adapter->max_rx_add_queues =
4221 be64_to_cpu(crq->query_capability.number);
4222 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
4223 adapter->max_rx_add_queues);
4225 case MIN_TX_ENTRIES_PER_SUBCRQ:
4226 adapter->min_tx_entries_per_subcrq =
4227 be64_to_cpu(crq->query_capability.number);
4228 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
4229 adapter->min_tx_entries_per_subcrq);
4231 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
4232 adapter->min_rx_add_entries_per_subcrq =
4233 be64_to_cpu(crq->query_capability.number);
4234 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
4235 adapter->min_rx_add_entries_per_subcrq);
4237 case MAX_TX_ENTRIES_PER_SUBCRQ:
4238 adapter->max_tx_entries_per_subcrq =
4239 be64_to_cpu(crq->query_capability.number);
4240 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
4241 adapter->max_tx_entries_per_subcrq);
4243 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
4244 adapter->max_rx_add_entries_per_subcrq =
4245 be64_to_cpu(crq->query_capability.number);
4246 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
4247 adapter->max_rx_add_entries_per_subcrq);
4249 case TCP_IP_OFFLOAD:
4250 adapter->tcp_ip_offload =
4251 be64_to_cpu(crq->query_capability.number);
4252 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
4253 adapter->tcp_ip_offload);
4255 case PROMISC_SUPPORTED:
4256 adapter->promisc_supported =
4257 be64_to_cpu(crq->query_capability.number);
4258 netdev_dbg(netdev, "promisc_supported = %lld\n",
4259 adapter->promisc_supported);
4262 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
4263 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
4264 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
4267 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
4268 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
4269 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
4271 case MAX_MULTICAST_FILTERS:
4272 adapter->max_multicast_filters =
4273 be64_to_cpu(crq->query_capability.number);
4274 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
4275 adapter->max_multicast_filters);
4277 case VLAN_HEADER_INSERTION:
4278 adapter->vlan_header_insertion =
4279 be64_to_cpu(crq->query_capability.number);
4280 if (adapter->vlan_header_insertion)
4281 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
4282 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
4283 adapter->vlan_header_insertion);
4285 case RX_VLAN_HEADER_INSERTION:
4286 adapter->rx_vlan_header_insertion =
4287 be64_to_cpu(crq->query_capability.number);
4288 netdev_dbg(netdev, "rx_vlan_header_insertion = %lld\n",
4289 adapter->rx_vlan_header_insertion);
4291 case MAX_TX_SG_ENTRIES:
4292 adapter->max_tx_sg_entries =
4293 be64_to_cpu(crq->query_capability.number);
4294 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
4295 adapter->max_tx_sg_entries);
4297 case RX_SG_SUPPORTED:
4298 adapter->rx_sg_supported =
4299 be64_to_cpu(crq->query_capability.number);
4300 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
4301 adapter->rx_sg_supported);
4303 case OPT_TX_COMP_SUB_QUEUES:
4304 adapter->opt_tx_comp_sub_queues =
4305 be64_to_cpu(crq->query_capability.number);
4306 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
4307 adapter->opt_tx_comp_sub_queues);
4309 case OPT_RX_COMP_QUEUES:
4310 adapter->opt_rx_comp_queues =
4311 be64_to_cpu(crq->query_capability.number);
4312 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
4313 adapter->opt_rx_comp_queues);
4315 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
4316 adapter->opt_rx_bufadd_q_per_rx_comp_q =
4317 be64_to_cpu(crq->query_capability.number);
4318 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
4319 adapter->opt_rx_bufadd_q_per_rx_comp_q);
4321 case OPT_TX_ENTRIES_PER_SUBCRQ:
4322 adapter->opt_tx_entries_per_subcrq =
4323 be64_to_cpu(crq->query_capability.number);
4324 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
4325 adapter->opt_tx_entries_per_subcrq);
4327 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
4328 adapter->opt_rxba_entries_per_subcrq =
4329 be64_to_cpu(crq->query_capability.number);
4330 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
4331 adapter->opt_rxba_entries_per_subcrq);
4333 case TX_RX_DESC_REQ:
4334 adapter->tx_rx_desc_req = crq->query_capability.number;
4335 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
4336 adapter->tx_rx_desc_req);
4340 netdev_err(netdev, "Got invalid cap rsp %d\n",
4341 crq->query_capability.capability);
4345 if (atomic_read(&adapter->running_cap_crqs) == 0) {
4346 adapter->wait_capability = false;
4347 ibmvnic_send_req_caps(adapter, 0);
4351 static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
4352 struct ibmvnic_adapter *adapter)
4354 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
4355 struct net_device *netdev = adapter->netdev;
4356 struct device *dev = &adapter->vdev->dev;
4357 u64 *u64_crq = (u64 *)crq;
4360 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
4361 (unsigned long int)cpu_to_be64(u64_crq[0]),
4362 (unsigned long int)cpu_to_be64(u64_crq[1]));
4363 switch (gen_crq->first) {
4364 case IBMVNIC_CRQ_INIT_RSP:
4365 switch (gen_crq->cmd) {
4366 case IBMVNIC_CRQ_INIT:
4367 dev_info(dev, "Partner initialized\n");
4368 adapter->from_passive_init = true;
4369 adapter->failover_pending = false;
4370 if (!completion_done(&adapter->init_done)) {
4371 complete(&adapter->init_done);
4372 adapter->init_done_rc = -EIO;
4374 ibmvnic_reset(adapter, VNIC_RESET_FAILOVER);
4376 case IBMVNIC_CRQ_INIT_COMPLETE:
4377 dev_info(dev, "Partner initialization complete\n");
4378 adapter->crq.active = true;
4379 send_version_xchg(adapter);
4382 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
4385 case IBMVNIC_CRQ_XPORT_EVENT:
4386 netif_carrier_off(netdev);
4387 adapter->crq.active = false;
4388 if (adapter->resetting)
4389 adapter->force_reset_recovery = true;
4390 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
4391 dev_info(dev, "Migrated, re-enabling adapter\n");
4392 ibmvnic_reset(adapter, VNIC_RESET_MOBILITY);
4393 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
4394 dev_info(dev, "Backing device failover detected\n");
4395 adapter->failover_pending = true;
4397 /* The adapter lost the connection */
4398 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
4400 ibmvnic_reset(adapter, VNIC_RESET_FATAL);
4403 case IBMVNIC_CRQ_CMD_RSP:
4406 dev_err(dev, "Got an invalid msg type 0x%02x\n",
4411 switch (gen_crq->cmd) {
4412 case VERSION_EXCHANGE_RSP:
4413 rc = crq->version_exchange_rsp.rc.code;
4415 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
4418 dev_info(dev, "Partner protocol version is %d\n",
4419 crq->version_exchange_rsp.version);
4420 if (be16_to_cpu(crq->version_exchange_rsp.version) <
4423 be16_to_cpu(crq->version_exchange_rsp.version);
4424 send_cap_queries(adapter);
4426 case QUERY_CAPABILITY_RSP:
4427 handle_query_cap_rsp(crq, adapter);
4430 handle_query_map_rsp(crq, adapter);
4432 case REQUEST_MAP_RSP:
4433 adapter->fw_done_rc = crq->request_map_rsp.rc.code;
4434 complete(&adapter->fw_done);
4436 case REQUEST_UNMAP_RSP:
4437 handle_request_unmap_rsp(crq, adapter);
4439 case REQUEST_CAPABILITY_RSP:
4440 handle_request_cap_rsp(crq, adapter);
4443 netdev_dbg(netdev, "Got Login Response\n");
4444 handle_login_rsp(crq, adapter);
4446 case LOGICAL_LINK_STATE_RSP:
4448 "Got Logical Link State Response, state: %d rc: %d\n",
4449 crq->logical_link_state_rsp.link_state,
4450 crq->logical_link_state_rsp.rc.code);
4451 adapter->logical_link_state =
4452 crq->logical_link_state_rsp.link_state;
4453 adapter->init_done_rc = crq->logical_link_state_rsp.rc.code;
4454 complete(&adapter->init_done);
4456 case LINK_STATE_INDICATION:
4457 netdev_dbg(netdev, "Got Logical Link State Indication\n");
4458 adapter->phys_link_state =
4459 crq->link_state_indication.phys_link_state;
4460 adapter->logical_link_state =
4461 crq->link_state_indication.logical_link_state;
4463 case CHANGE_MAC_ADDR_RSP:
4464 netdev_dbg(netdev, "Got MAC address change Response\n");
4465 adapter->fw_done_rc = handle_change_mac_rsp(crq, adapter);
4467 case ERROR_INDICATION:
4468 netdev_dbg(netdev, "Got Error Indication\n");
4469 handle_error_indication(crq, adapter);
4471 case REQUEST_ERROR_RSP:
4472 netdev_dbg(netdev, "Got Error Detail Response\n");
4473 handle_error_info_rsp(crq, adapter);
4475 case REQUEST_STATISTICS_RSP:
4476 netdev_dbg(netdev, "Got Statistics Response\n");
4477 complete(&adapter->stats_done);
4479 case QUERY_IP_OFFLOAD_RSP:
4480 netdev_dbg(netdev, "Got Query IP offload Response\n");
4481 handle_query_ip_offload_rsp(adapter);
4483 case MULTICAST_CTRL_RSP:
4484 netdev_dbg(netdev, "Got multicast control Response\n");
4486 case CONTROL_IP_OFFLOAD_RSP:
4487 netdev_dbg(netdev, "Got Control IP offload Response\n");
4488 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
4489 sizeof(adapter->ip_offload_ctrl),
4491 complete(&adapter->init_done);
4493 case COLLECT_FW_TRACE_RSP:
4494 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
4495 complete(&adapter->fw_done);
4497 case GET_VPD_SIZE_RSP:
4498 handle_vpd_size_rsp(crq, adapter);
4501 handle_vpd_rsp(crq, adapter);
4504 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
4509 static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
4511 struct ibmvnic_adapter *adapter = instance;
4513 tasklet_schedule(&adapter->tasklet);
4517 static void ibmvnic_tasklet(void *data)
4519 struct ibmvnic_adapter *adapter = data;
4520 struct ibmvnic_crq_queue *queue = &adapter->crq;
4521 union ibmvnic_crq *crq;
4522 unsigned long flags;
4525 spin_lock_irqsave(&queue->lock, flags);
4527 /* Pull all the valid messages off the CRQ */
4528 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
4529 ibmvnic_handle_crq(crq, adapter);
4530 crq->generic.first = 0;
4533 /* remain in tasklet until all
4534 * capabilities responses are received
4536 if (!adapter->wait_capability)
4539 /* if capabilities CRQ's were sent in this tasklet, the following
4540 * tasklet must wait until all responses are received
4542 if (atomic_read(&adapter->running_cap_crqs) != 0)
4543 adapter->wait_capability = true;
4544 spin_unlock_irqrestore(&queue->lock, flags);
4547 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
4549 struct vio_dev *vdev = adapter->vdev;
4553 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
4554 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
4557 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
4562 static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
4564 struct ibmvnic_crq_queue *crq = &adapter->crq;
4565 struct device *dev = &adapter->vdev->dev;
4566 struct vio_dev *vdev = adapter->vdev;
4571 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4572 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4574 /* Clean out the queue */
4575 memset(crq->msgs, 0, PAGE_SIZE);
4577 crq->active = false;
4579 /* And re-open it again */
4580 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
4581 crq->msg_token, PAGE_SIZE);
4584 /* Adapter is good, but other end is not ready */
4585 dev_warn(dev, "Partner adapter not ready\n");
4587 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
4592 static void release_crq_queue(struct ibmvnic_adapter *adapter)
4594 struct ibmvnic_crq_queue *crq = &adapter->crq;
4595 struct vio_dev *vdev = adapter->vdev;
4601 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
4602 free_irq(vdev->irq, adapter);
4603 tasklet_kill(&adapter->tasklet);
4605 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4606 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4608 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
4610 free_page((unsigned long)crq->msgs);
4612 crq->active = false;
4615 static int init_crq_queue(struct ibmvnic_adapter *adapter)
4617 struct ibmvnic_crq_queue *crq = &adapter->crq;
4618 struct device *dev = &adapter->vdev->dev;
4619 struct vio_dev *vdev = adapter->vdev;
4620 int rc, retrc = -ENOMEM;
4625 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
4626 /* Should we allocate more than one page? */
4631 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
4632 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
4634 if (dma_mapping_error(dev, crq->msg_token))
4637 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
4638 crq->msg_token, PAGE_SIZE);
4640 if (rc == H_RESOURCE)
4641 /* maybe kexecing and resource is busy. try a reset */
4642 rc = ibmvnic_reset_crq(adapter);
4645 if (rc == H_CLOSED) {
4646 dev_warn(dev, "Partner adapter not ready\n");
4648 dev_warn(dev, "Error %d opening adapter\n", rc);
4649 goto reg_crq_failed;
4654 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
4655 (unsigned long)adapter);
4657 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
4658 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
4661 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
4663 goto req_irq_failed;
4666 rc = vio_enable_interrupts(vdev);
4668 dev_err(dev, "Error %d enabling interrupts\n", rc);
4669 goto req_irq_failed;
4673 spin_lock_init(&crq->lock);
4678 tasklet_kill(&adapter->tasklet);
4680 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
4681 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
4683 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
4685 free_page((unsigned long)crq->msgs);
4690 static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter)
4692 struct device *dev = &adapter->vdev->dev;
4693 unsigned long timeout = msecs_to_jiffies(30000);
4694 u64 old_num_rx_queues, old_num_tx_queues;
4697 adapter->from_passive_init = false;
4699 old_num_rx_queues = adapter->req_rx_queues;
4700 old_num_tx_queues = adapter->req_tx_queues;
4702 init_completion(&adapter->init_done);
4703 adapter->init_done_rc = 0;
4704 ibmvnic_send_crq_init(adapter);
4705 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
4706 dev_err(dev, "Initialization sequence timed out\n");
4710 if (adapter->init_done_rc) {
4711 release_crq_queue(adapter);
4712 return adapter->init_done_rc;
4715 if (adapter->from_passive_init) {
4716 adapter->state = VNIC_OPEN;
4717 adapter->from_passive_init = false;
4721 if (adapter->resetting && !adapter->wait_for_reset &&
4722 adapter->reset_reason != VNIC_RESET_MOBILITY) {
4723 if (adapter->req_rx_queues != old_num_rx_queues ||
4724 adapter->req_tx_queues != old_num_tx_queues) {
4725 release_sub_crqs(adapter, 0);
4726 rc = init_sub_crqs(adapter);
4728 rc = reset_sub_crq_queues(adapter);
4731 rc = init_sub_crqs(adapter);
4735 dev_err(dev, "Initialization of sub crqs failed\n");
4736 release_crq_queue(adapter);
4740 rc = init_sub_crq_irqs(adapter);
4742 dev_err(dev, "Failed to initialize sub crq irqs\n");
4743 release_crq_queue(adapter);
4749 static int ibmvnic_init(struct ibmvnic_adapter *adapter)
4751 struct device *dev = &adapter->vdev->dev;
4752 unsigned long timeout = msecs_to_jiffies(30000);
4755 adapter->from_passive_init = false;
4757 init_completion(&adapter->init_done);
4758 adapter->init_done_rc = 0;
4759 ibmvnic_send_crq_init(adapter);
4760 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
4761 dev_err(dev, "Initialization sequence timed out\n");
4765 if (adapter->init_done_rc) {
4766 release_crq_queue(adapter);
4767 return adapter->init_done_rc;
4770 if (adapter->from_passive_init) {
4771 adapter->state = VNIC_OPEN;
4772 adapter->from_passive_init = false;
4776 rc = init_sub_crqs(adapter);
4778 dev_err(dev, "Initialization of sub crqs failed\n");
4779 release_crq_queue(adapter);
4783 rc = init_sub_crq_irqs(adapter);
4785 dev_err(dev, "Failed to initialize sub crq irqs\n");
4786 release_crq_queue(adapter);
4792 static struct device_attribute dev_attr_failover;
4794 static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
4796 struct ibmvnic_adapter *adapter;
4797 struct net_device *netdev;
4798 unsigned char *mac_addr_p;
4801 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
4804 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
4805 VETH_MAC_ADDR, NULL);
4808 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
4809 __FILE__, __LINE__);
4813 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
4814 IBMVNIC_MAX_QUEUES);
4818 adapter = netdev_priv(netdev);
4819 adapter->state = VNIC_PROBING;
4820 dev_set_drvdata(&dev->dev, netdev);
4821 adapter->vdev = dev;
4822 adapter->netdev = netdev;
4824 ether_addr_copy(adapter->mac_addr, mac_addr_p);
4825 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
4826 netdev->irq = dev->irq;
4827 netdev->netdev_ops = &ibmvnic_netdev_ops;
4828 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
4829 SET_NETDEV_DEV(netdev, &dev->dev);
4831 spin_lock_init(&adapter->stats_lock);
4833 INIT_LIST_HEAD(&adapter->errors);
4834 spin_lock_init(&adapter->error_list_lock);
4836 INIT_WORK(&adapter->ibmvnic_reset, __ibmvnic_reset);
4837 INIT_LIST_HEAD(&adapter->rwi_list);
4838 mutex_init(&adapter->reset_lock);
4839 mutex_init(&adapter->rwi_lock);
4840 adapter->resetting = false;
4842 adapter->mac_change_pending = false;
4845 rc = init_crq_queue(adapter);
4847 dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n",
4849 goto ibmvnic_init_fail;
4852 rc = ibmvnic_init(adapter);
4853 if (rc && rc != EAGAIN)
4854 goto ibmvnic_init_fail;
4855 } while (rc == EAGAIN);
4857 rc = init_stats_buffers(adapter);
4859 goto ibmvnic_init_fail;
4861 rc = init_stats_token(adapter);
4863 goto ibmvnic_stats_fail;
4865 netdev->mtu = adapter->req_mtu - ETH_HLEN;
4866 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
4867 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
4869 rc = device_create_file(&dev->dev, &dev_attr_failover);
4871 goto ibmvnic_dev_file_err;
4873 netif_carrier_off(netdev);
4874 rc = register_netdev(netdev);
4876 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
4877 goto ibmvnic_register_fail;
4879 dev_info(&dev->dev, "ibmvnic registered\n");
4881 adapter->state = VNIC_PROBED;
4883 adapter->wait_for_reset = false;
4887 ibmvnic_register_fail:
4888 device_remove_file(&dev->dev, &dev_attr_failover);
4890 ibmvnic_dev_file_err:
4891 release_stats_token(adapter);
4894 release_stats_buffers(adapter);
4897 release_sub_crqs(adapter, 1);
4898 release_crq_queue(adapter);
4899 free_netdev(netdev);
4904 static int ibmvnic_remove(struct vio_dev *dev)
4906 struct net_device *netdev = dev_get_drvdata(&dev->dev);
4907 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
4909 adapter->state = VNIC_REMOVING;
4910 unregister_netdev(netdev);
4911 mutex_lock(&adapter->reset_lock);
4913 release_resources(adapter);
4914 release_sub_crqs(adapter, 1);
4915 release_crq_queue(adapter);
4917 release_stats_token(adapter);
4918 release_stats_buffers(adapter);
4920 adapter->state = VNIC_REMOVED;
4922 mutex_unlock(&adapter->reset_lock);
4923 device_remove_file(&dev->dev, &dev_attr_failover);
4924 free_netdev(netdev);
4925 dev_set_drvdata(&dev->dev, NULL);
4930 static ssize_t failover_store(struct device *dev, struct device_attribute *attr,
4931 const char *buf, size_t count)
4933 struct net_device *netdev = dev_get_drvdata(dev);
4934 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
4935 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
4936 __be64 session_token;
4939 if (!sysfs_streq(buf, "1"))
4942 rc = plpar_hcall(H_VIOCTL, retbuf, adapter->vdev->unit_address,
4943 H_GET_SESSION_TOKEN, 0, 0, 0);
4945 netdev_err(netdev, "Couldn't retrieve session token, rc %ld\n",
4950 session_token = (__be64)retbuf[0];
4951 netdev_dbg(netdev, "Initiating client failover, session id %llx\n",
4952 be64_to_cpu(session_token));
4953 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
4954 H_SESSION_ERR_DETECTED, session_token, 0, 0);
4956 netdev_err(netdev, "Client initiated failover failed, rc %ld\n",
4964 static DEVICE_ATTR_WO(failover);
4966 static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
4968 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
4969 struct ibmvnic_adapter *adapter;
4970 struct iommu_table *tbl;
4971 unsigned long ret = 0;
4974 tbl = get_iommu_table_base(&vdev->dev);
4976 /* netdev inits at probe time along with the structures we need below*/
4978 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
4980 adapter = netdev_priv(netdev);
4982 ret += PAGE_SIZE; /* the crq message queue */
4983 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
4985 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
4986 ret += 4 * PAGE_SIZE; /* the scrq message queue */
4988 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
4990 ret += adapter->rx_pool[i].size *
4991 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
4996 static int ibmvnic_resume(struct device *dev)
4998 struct net_device *netdev = dev_get_drvdata(dev);
4999 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
5001 if (adapter->state != VNIC_OPEN)
5004 tasklet_schedule(&adapter->tasklet);
5009 static const struct vio_device_id ibmvnic_device_table[] = {
5010 {"network", "IBM,vnic"},
5013 MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
5015 static const struct dev_pm_ops ibmvnic_pm_ops = {
5016 .resume = ibmvnic_resume
5019 static struct vio_driver ibmvnic_driver = {
5020 .id_table = ibmvnic_device_table,
5021 .probe = ibmvnic_probe,
5022 .remove = ibmvnic_remove,
5023 .get_desired_dma = ibmvnic_get_desired_dma,
5024 .name = ibmvnic_driver_name,
5025 .pm = &ibmvnic_pm_ops,
5028 /* module functions */
5029 static int __init ibmvnic_module_init(void)
5031 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
5032 IBMVNIC_DRIVER_VERSION);
5034 return vio_register_driver(&ibmvnic_driver);
5037 static void __exit ibmvnic_module_exit(void)
5039 vio_unregister_driver(&ibmvnic_driver);
5042 module_init(ibmvnic_module_init);
5043 module_exit(ibmvnic_module_exit);