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>
64 #include <linux/ipv6.h>
65 #include <linux/irq.h>
66 #include <linux/kthread.h>
67 #include <linux/seq_file.h>
68 #include <linux/debugfs.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>
81 static const char ibmvnic_driver_name[] = "ibmvnic";
82 static const char ibmvnic_driver_string[] = "IBM System i/p Virtual NIC Driver";
84 MODULE_AUTHOR("Santiago Leon <santi_leon@yahoo.com>");
85 MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
86 MODULE_LICENSE("GPL");
87 MODULE_VERSION(IBMVNIC_DRIVER_VERSION);
89 static int ibmvnic_version = IBMVNIC_INITIAL_VERSION;
90 static int ibmvnic_remove(struct vio_dev *);
91 static void release_sub_crqs(struct ibmvnic_adapter *);
92 static void release_sub_crqs_no_irqs(struct ibmvnic_adapter *);
93 static int ibmvnic_reset_crq(struct ibmvnic_adapter *);
94 static int ibmvnic_send_crq_init(struct ibmvnic_adapter *);
95 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *);
96 static int ibmvnic_send_crq(struct ibmvnic_adapter *, union ibmvnic_crq *);
97 static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
98 union sub_crq *sub_crq);
99 static int send_subcrq_indirect(struct ibmvnic_adapter *, u64, u64, u64);
100 static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance);
101 static int enable_scrq_irq(struct ibmvnic_adapter *,
102 struct ibmvnic_sub_crq_queue *);
103 static int disable_scrq_irq(struct ibmvnic_adapter *,
104 struct ibmvnic_sub_crq_queue *);
105 static int pending_scrq(struct ibmvnic_adapter *,
106 struct ibmvnic_sub_crq_queue *);
107 static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *,
108 struct ibmvnic_sub_crq_queue *);
109 static int ibmvnic_poll(struct napi_struct *napi, int data);
110 static void send_map_query(struct ibmvnic_adapter *adapter);
111 static void send_request_map(struct ibmvnic_adapter *, dma_addr_t, __be32, u8);
112 static void send_request_unmap(struct ibmvnic_adapter *, u8);
114 struct ibmvnic_stat {
115 char name[ETH_GSTRING_LEN];
119 #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
120 offsetof(struct ibmvnic_statistics, stat))
121 #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
123 static const struct ibmvnic_stat ibmvnic_stats[] = {
124 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets)},
125 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes)},
126 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets)},
127 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes)},
128 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets)},
129 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets)},
130 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets)},
131 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets)},
132 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets)},
133 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets)},
134 {"align_errors", IBMVNIC_STAT_OFF(align_errors)},
135 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors)},
136 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames)},
137 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames)},
138 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors)},
139 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx)},
140 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions)},
141 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions)},
142 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors)},
143 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense)},
144 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames)},
145 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors)},
148 static long h_reg_sub_crq(unsigned long unit_address, unsigned long token,
149 unsigned long length, unsigned long *number,
152 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
155 rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, token, length);
162 /* net_device_ops functions */
164 static void init_rx_pool(struct ibmvnic_adapter *adapter,
165 struct ibmvnic_rx_pool *rx_pool, int num, int index,
166 int buff_size, int active)
168 netdev_dbg(adapter->netdev,
169 "Initializing rx_pool %d, %d buffs, %d bytes each\n",
170 index, num, buff_size);
172 rx_pool->index = index;
173 rx_pool->buff_size = buff_size;
174 rx_pool->active = active;
177 static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
178 struct ibmvnic_long_term_buff *ltb, int size)
180 struct device *dev = &adapter->vdev->dev;
183 ltb->buff = dma_alloc_coherent(dev, ltb->size, <b->addr,
187 dev_err(dev, "Couldn't alloc long term buffer\n");
190 ltb->map_id = adapter->map_id;
193 init_completion(&adapter->fw_done);
194 send_request_map(adapter, ltb->addr,
195 ltb->size, ltb->map_id);
196 wait_for_completion(&adapter->fw_done);
200 static void free_long_term_buff(struct ibmvnic_adapter *adapter,
201 struct ibmvnic_long_term_buff *ltb)
203 struct device *dev = &adapter->vdev->dev;
205 dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
206 if (!adapter->failover)
207 send_request_unmap(adapter, ltb->map_id);
210 static int alloc_rx_pool(struct ibmvnic_adapter *adapter,
211 struct ibmvnic_rx_pool *pool)
213 struct device *dev = &adapter->vdev->dev;
216 pool->free_map = kcalloc(pool->size, sizeof(int), GFP_KERNEL);
220 pool->rx_buff = kcalloc(pool->size, sizeof(struct ibmvnic_rx_buff),
223 if (!pool->rx_buff) {
224 dev_err(dev, "Couldn't alloc rx buffers\n");
225 kfree(pool->free_map);
229 if (alloc_long_term_buff(adapter, &pool->long_term_buff,
230 pool->size * pool->buff_size)) {
231 kfree(pool->free_map);
232 kfree(pool->rx_buff);
236 for (i = 0; i < pool->size; ++i)
237 pool->free_map[i] = i;
239 atomic_set(&pool->available, 0);
240 pool->next_alloc = 0;
246 static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
247 struct ibmvnic_rx_pool *pool)
249 int count = pool->size - atomic_read(&pool->available);
250 struct device *dev = &adapter->vdev->dev;
251 int buffers_added = 0;
252 unsigned long lpar_rc;
253 union sub_crq sub_crq;
263 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
264 be32_to_cpu(adapter->login_rsp_buf->
267 for (i = 0; i < count; ++i) {
268 skb = alloc_skb(pool->buff_size, GFP_ATOMIC);
270 dev_err(dev, "Couldn't replenish rx buff\n");
271 adapter->replenish_no_mem++;
275 index = pool->free_map[pool->next_free];
277 if (pool->rx_buff[index].skb)
278 dev_err(dev, "Inconsistent free_map!\n");
280 /* Copy the skb to the long term mapped DMA buffer */
281 offset = index * pool->buff_size;
282 dst = pool->long_term_buff.buff + offset;
283 memset(dst, 0, pool->buff_size);
284 dma_addr = pool->long_term_buff.addr + offset;
285 pool->rx_buff[index].data = dst;
287 pool->free_map[pool->next_free] = IBMVNIC_INVALID_MAP;
288 pool->rx_buff[index].dma = dma_addr;
289 pool->rx_buff[index].skb = skb;
290 pool->rx_buff[index].pool_index = pool->index;
291 pool->rx_buff[index].size = pool->buff_size;
293 memset(&sub_crq, 0, sizeof(sub_crq));
294 sub_crq.rx_add.first = IBMVNIC_CRQ_CMD;
295 sub_crq.rx_add.correlator =
296 cpu_to_be64((u64)&pool->rx_buff[index]);
297 sub_crq.rx_add.ioba = cpu_to_be32(dma_addr);
298 sub_crq.rx_add.map_id = pool->long_term_buff.map_id;
300 /* The length field of the sCRQ is defined to be 24 bits so the
301 * buffer size needs to be left shifted by a byte before it is
302 * converted to big endian to prevent the last byte from being
305 #ifdef __LITTLE_ENDIAN__
308 sub_crq.rx_add.len = cpu_to_be32(pool->buff_size << shift);
310 lpar_rc = send_subcrq(adapter, handle_array[pool->index],
312 if (lpar_rc != H_SUCCESS)
316 adapter->replenish_add_buff_success++;
317 pool->next_free = (pool->next_free + 1) % pool->size;
319 atomic_add(buffers_added, &pool->available);
323 dev_info(dev, "replenish pools failure\n");
324 pool->free_map[pool->next_free] = index;
325 pool->rx_buff[index].skb = NULL;
326 if (!dma_mapping_error(dev, dma_addr))
327 dma_unmap_single(dev, dma_addr, pool->buff_size,
330 dev_kfree_skb_any(skb);
331 adapter->replenish_add_buff_failure++;
332 atomic_add(buffers_added, &pool->available);
335 static void replenish_pools(struct ibmvnic_adapter *adapter)
339 if (adapter->migrated)
342 adapter->replenish_task_cycles++;
343 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
345 if (adapter->rx_pool[i].active)
346 replenish_rx_pool(adapter, &adapter->rx_pool[i]);
350 static void free_rx_pool(struct ibmvnic_adapter *adapter,
351 struct ibmvnic_rx_pool *pool)
355 kfree(pool->free_map);
356 pool->free_map = NULL;
361 for (i = 0; i < pool->size; i++) {
362 if (pool->rx_buff[i].skb) {
363 dev_kfree_skb_any(pool->rx_buff[i].skb);
364 pool->rx_buff[i].skb = NULL;
367 kfree(pool->rx_buff);
368 pool->rx_buff = NULL;
371 static int ibmvnic_open(struct net_device *netdev)
373 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
374 struct device *dev = &adapter->vdev->dev;
375 struct ibmvnic_tx_pool *tx_pool;
376 union ibmvnic_crq crq;
383 be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
385 be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
386 size_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
387 be32_to_cpu(adapter->login_rsp_buf->
388 off_rxadd_buff_size));
390 adapter->napi = kcalloc(adapter->req_rx_queues,
391 sizeof(struct napi_struct), GFP_KERNEL);
393 goto alloc_napi_failed;
394 for (i = 0; i < adapter->req_rx_queues; i++) {
395 netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
397 napi_enable(&adapter->napi[i]);
400 kcalloc(rxadd_subcrqs, sizeof(struct ibmvnic_rx_pool), GFP_KERNEL);
402 if (!adapter->rx_pool)
403 goto rx_pool_arr_alloc_failed;
404 send_map_query(adapter);
405 for (i = 0; i < rxadd_subcrqs; i++) {
406 init_rx_pool(adapter, &adapter->rx_pool[i],
407 adapter->req_rx_add_entries_per_subcrq, i,
408 be64_to_cpu(size_array[i]), 1);
409 if (alloc_rx_pool(adapter, &adapter->rx_pool[i])) {
410 dev_err(dev, "Couldn't alloc rx pool\n");
411 goto rx_pool_alloc_failed;
415 kcalloc(tx_subcrqs, sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
417 if (!adapter->tx_pool)
418 goto tx_pool_arr_alloc_failed;
419 for (i = 0; i < tx_subcrqs; i++) {
420 tx_pool = &adapter->tx_pool[i];
422 kcalloc(adapter->req_tx_entries_per_subcrq,
423 sizeof(struct ibmvnic_tx_buff), GFP_KERNEL);
424 if (!tx_pool->tx_buff)
425 goto tx_pool_alloc_failed;
427 if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
428 adapter->req_tx_entries_per_subcrq *
430 goto tx_ltb_alloc_failed;
433 kcalloc(adapter->req_tx_entries_per_subcrq,
434 sizeof(int), GFP_KERNEL);
435 if (!tx_pool->free_map)
436 goto tx_fm_alloc_failed;
438 for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
439 tx_pool->free_map[j] = j;
441 tx_pool->consumer_index = 0;
442 tx_pool->producer_index = 0;
444 adapter->bounce_buffer_size =
445 (netdev->mtu + ETH_HLEN - 1) / PAGE_SIZE + 1;
446 adapter->bounce_buffer = kmalloc(adapter->bounce_buffer_size,
448 if (!adapter->bounce_buffer)
449 goto bounce_alloc_failed;
451 adapter->bounce_buffer_dma = dma_map_single(dev, adapter->bounce_buffer,
452 adapter->bounce_buffer_size,
454 if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
455 dev_err(dev, "Couldn't map tx bounce buffer\n");
456 goto bounce_map_failed;
458 replenish_pools(adapter);
460 /* We're ready to receive frames, enable the sub-crq interrupts and
461 * set the logical link state to up
463 for (i = 0; i < adapter->req_rx_queues; i++)
464 enable_scrq_irq(adapter, adapter->rx_scrq[i]);
466 for (i = 0; i < adapter->req_tx_queues; i++)
467 enable_scrq_irq(adapter, adapter->tx_scrq[i]);
469 memset(&crq, 0, sizeof(crq));
470 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
471 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
472 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_UP;
473 ibmvnic_send_crq(adapter, &crq);
475 netif_tx_start_all_queues(netdev);
480 kfree(adapter->bounce_buffer);
483 kfree(adapter->tx_pool[i].free_map);
485 free_long_term_buff(adapter, &adapter->tx_pool[i].long_term_buff);
487 kfree(adapter->tx_pool[i].tx_buff);
488 tx_pool_alloc_failed:
489 for (j = 0; j < i; j++) {
490 kfree(adapter->tx_pool[j].tx_buff);
491 free_long_term_buff(adapter,
492 &adapter->tx_pool[j].long_term_buff);
493 kfree(adapter->tx_pool[j].free_map);
495 kfree(adapter->tx_pool);
496 adapter->tx_pool = NULL;
497 tx_pool_arr_alloc_failed:
499 rx_pool_alloc_failed:
500 for (j = 0; j < i; j++) {
501 free_rx_pool(adapter, &adapter->rx_pool[j]);
502 free_long_term_buff(adapter,
503 &adapter->rx_pool[j].long_term_buff);
505 kfree(adapter->rx_pool);
506 adapter->rx_pool = NULL;
507 rx_pool_arr_alloc_failed:
508 for (i = 0; i < adapter->req_rx_queues; i++)
509 napi_disable(&adapter->napi[i]);
514 static int ibmvnic_close(struct net_device *netdev)
516 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
517 struct device *dev = &adapter->vdev->dev;
518 union ibmvnic_crq crq;
521 adapter->closing = true;
523 for (i = 0; i < adapter->req_rx_queues; i++)
524 napi_disable(&adapter->napi[i]);
526 if (!adapter->failover)
527 netif_tx_stop_all_queues(netdev);
529 if (adapter->bounce_buffer) {
530 if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) {
531 dma_unmap_single(&adapter->vdev->dev,
532 adapter->bounce_buffer_dma,
533 adapter->bounce_buffer_size,
535 adapter->bounce_buffer_dma = DMA_ERROR_CODE;
537 kfree(adapter->bounce_buffer);
538 adapter->bounce_buffer = NULL;
541 memset(&crq, 0, sizeof(crq));
542 crq.logical_link_state.first = IBMVNIC_CRQ_CMD;
543 crq.logical_link_state.cmd = LOGICAL_LINK_STATE;
544 crq.logical_link_state.link_state = IBMVNIC_LOGICAL_LNK_DN;
545 ibmvnic_send_crq(adapter, &crq);
547 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
549 kfree(adapter->tx_pool[i].tx_buff);
550 free_long_term_buff(adapter,
551 &adapter->tx_pool[i].long_term_buff);
552 kfree(adapter->tx_pool[i].free_map);
554 kfree(adapter->tx_pool);
555 adapter->tx_pool = NULL;
557 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
559 free_rx_pool(adapter, &adapter->rx_pool[i]);
560 free_long_term_buff(adapter,
561 &adapter->rx_pool[i].long_term_buff);
563 kfree(adapter->rx_pool);
564 adapter->rx_pool = NULL;
566 adapter->closing = false;
572 * build_hdr_data - creates L2/L3/L4 header data buffer
573 * @hdr_field - bitfield determining needed headers
574 * @skb - socket buffer
575 * @hdr_len - array of header lengths
576 * @tot_len - total length of data
578 * Reads hdr_field to determine which headers are needed by firmware.
579 * Builds a buffer containing these headers. Saves individual header
580 * lengths and total buffer length to be used to build descriptors.
582 static int build_hdr_data(u8 hdr_field, struct sk_buff *skb,
583 int *hdr_len, u8 *hdr_data)
588 hdr_len[0] = sizeof(struct ethhdr);
590 if (skb->protocol == htons(ETH_P_IP)) {
591 hdr_len[1] = ip_hdr(skb)->ihl * 4;
592 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
593 hdr_len[2] = tcp_hdrlen(skb);
594 else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
595 hdr_len[2] = sizeof(struct udphdr);
596 } else if (skb->protocol == htons(ETH_P_IPV6)) {
597 hdr_len[1] = sizeof(struct ipv6hdr);
598 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
599 hdr_len[2] = tcp_hdrlen(skb);
600 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
601 hdr_len[2] = sizeof(struct udphdr);
604 memset(hdr_data, 0, 120);
605 if ((hdr_field >> 6) & 1) {
606 hdr = skb_mac_header(skb);
607 memcpy(hdr_data, hdr, hdr_len[0]);
611 if ((hdr_field >> 5) & 1) {
612 hdr = skb_network_header(skb);
613 memcpy(hdr_data + len, hdr, hdr_len[1]);
617 if ((hdr_field >> 4) & 1) {
618 hdr = skb_transport_header(skb);
619 memcpy(hdr_data + len, hdr, hdr_len[2]);
626 * create_hdr_descs - create header and header extension descriptors
627 * @hdr_field - bitfield determining needed headers
628 * @data - buffer containing header data
629 * @len - length of data buffer
630 * @hdr_len - array of individual header lengths
631 * @scrq_arr - descriptor array
633 * Creates header and, if needed, header extension descriptors and
634 * places them in a descriptor array, scrq_arr
637 static void create_hdr_descs(u8 hdr_field, u8 *hdr_data, int len, int *hdr_len,
638 union sub_crq *scrq_arr)
640 union sub_crq hdr_desc;
645 while (tmp_len > 0) {
646 cur = hdr_data + len - tmp_len;
648 memset(&hdr_desc, 0, sizeof(hdr_desc));
649 if (cur != hdr_data) {
650 data = hdr_desc.hdr_ext.data;
651 tmp = tmp_len > 29 ? 29 : tmp_len;
652 hdr_desc.hdr_ext.first = IBMVNIC_CRQ_CMD;
653 hdr_desc.hdr_ext.type = IBMVNIC_HDR_EXT_DESC;
654 hdr_desc.hdr_ext.len = tmp;
656 data = hdr_desc.hdr.data;
657 tmp = tmp_len > 24 ? 24 : tmp_len;
658 hdr_desc.hdr.first = IBMVNIC_CRQ_CMD;
659 hdr_desc.hdr.type = IBMVNIC_HDR_DESC;
660 hdr_desc.hdr.len = tmp;
661 hdr_desc.hdr.l2_len = (u8)hdr_len[0];
662 hdr_desc.hdr.l3_len = cpu_to_be16((u16)hdr_len[1]);
663 hdr_desc.hdr.l4_len = (u8)hdr_len[2];
664 hdr_desc.hdr.flag = hdr_field << 1;
666 memcpy(data, cur, tmp);
668 *scrq_arr = hdr_desc;
674 * build_hdr_descs_arr - build a header descriptor array
675 * @skb - socket buffer
676 * @num_entries - number of descriptors to be sent
677 * @subcrq - first TX descriptor
678 * @hdr_field - bit field determining which headers will be sent
680 * This function will build a TX descriptor array with applicable
681 * L2/L3/L4 packet header descriptors to be sent by send_subcrq_indirect.
684 static void build_hdr_descs_arr(struct ibmvnic_tx_buff *txbuff,
685 int *num_entries, u8 hdr_field)
687 int hdr_len[3] = {0, 0, 0};
689 u8 *hdr_data = txbuff->hdr_data;
691 tot_len = build_hdr_data(hdr_field, txbuff->skb, hdr_len,
696 num_entries += len % 29 ? len / 29 + 1 : len / 29;
697 create_hdr_descs(hdr_field, hdr_data, tot_len, hdr_len,
698 txbuff->indir_arr + 1);
701 static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev)
703 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
704 int queue_num = skb_get_queue_mapping(skb);
705 u8 *hdrs = (u8 *)&adapter->tx_rx_desc_req;
706 struct device *dev = &adapter->vdev->dev;
707 struct ibmvnic_tx_buff *tx_buff = NULL;
708 struct ibmvnic_sub_crq_queue *tx_scrq;
709 struct ibmvnic_tx_pool *tx_pool;
710 unsigned int tx_send_failed = 0;
711 unsigned int tx_map_failed = 0;
712 unsigned int tx_dropped = 0;
713 unsigned int tx_packets = 0;
714 unsigned int tx_bytes = 0;
715 dma_addr_t data_dma_addr;
716 struct netdev_queue *txq;
717 bool used_bounce = false;
718 unsigned long lpar_rc;
719 union sub_crq tx_crq;
727 tx_pool = &adapter->tx_pool[queue_num];
728 tx_scrq = adapter->tx_scrq[queue_num];
729 txq = netdev_get_tx_queue(netdev, skb_get_queue_mapping(skb));
730 handle_array = (u64 *)((u8 *)(adapter->login_rsp_buf) +
731 be32_to_cpu(adapter->login_rsp_buf->
732 off_txsubm_subcrqs));
733 if (adapter->migrated) {
736 ret = NETDEV_TX_BUSY;
740 index = tx_pool->free_map[tx_pool->consumer_index];
741 offset = index * adapter->req_mtu;
742 dst = tx_pool->long_term_buff.buff + offset;
743 memset(dst, 0, adapter->req_mtu);
744 skb_copy_from_linear_data(skb, dst, skb->len);
745 data_dma_addr = tx_pool->long_term_buff.addr + offset;
747 tx_pool->consumer_index =
748 (tx_pool->consumer_index + 1) %
749 adapter->req_tx_entries_per_subcrq;
751 tx_buff = &tx_pool->tx_buff[index];
753 tx_buff->data_dma[0] = data_dma_addr;
754 tx_buff->data_len[0] = skb->len;
755 tx_buff->index = index;
756 tx_buff->pool_index = queue_num;
757 tx_buff->last_frag = true;
758 tx_buff->used_bounce = used_bounce;
760 memset(&tx_crq, 0, sizeof(tx_crq));
761 tx_crq.v1.first = IBMVNIC_CRQ_CMD;
762 tx_crq.v1.type = IBMVNIC_TX_DESC;
763 tx_crq.v1.n_crq_elem = 1;
765 tx_crq.v1.flags1 = IBMVNIC_TX_COMP_NEEDED;
766 tx_crq.v1.correlator = cpu_to_be32(index);
767 tx_crq.v1.dma_reg = cpu_to_be16(tx_pool->long_term_buff.map_id);
768 tx_crq.v1.sge_len = cpu_to_be32(skb->len);
769 tx_crq.v1.ioba = cpu_to_be64(data_dma_addr);
771 if (adapter->vlan_header_insertion) {
772 tx_crq.v1.flags2 |= IBMVNIC_TX_VLAN_INSERT;
773 tx_crq.v1.vlan_id = cpu_to_be16(skb->vlan_tci);
776 if (skb->protocol == htons(ETH_P_IP)) {
777 if (ip_hdr(skb)->version == 4)
778 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV4;
779 else if (ip_hdr(skb)->version == 6)
780 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_IPV6;
782 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
783 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_TCP;
784 else if (ip_hdr(skb)->protocol != IPPROTO_TCP)
785 tx_crq.v1.flags1 |= IBMVNIC_TX_PROT_UDP;
788 if (skb->ip_summed == CHECKSUM_PARTIAL) {
789 tx_crq.v1.flags1 |= IBMVNIC_TX_CHKSUM_OFFLOAD;
792 /* determine if l2/3/4 headers are sent to firmware */
793 if ((*hdrs >> 7) & 1 &&
794 (skb->protocol == htons(ETH_P_IP) ||
795 skb->protocol == htons(ETH_P_IPV6))) {
796 build_hdr_descs_arr(tx_buff, &num_entries, *hdrs);
797 tx_crq.v1.n_crq_elem = num_entries;
798 tx_buff->indir_arr[0] = tx_crq;
799 tx_buff->indir_dma = dma_map_single(dev, tx_buff->indir_arr,
800 sizeof(tx_buff->indir_arr),
802 if (dma_mapping_error(dev, tx_buff->indir_dma)) {
803 if (!firmware_has_feature(FW_FEATURE_CMO))
804 dev_err(dev, "tx: unable to map descriptor array\n");
807 ret = NETDEV_TX_BUSY;
810 lpar_rc = send_subcrq_indirect(adapter, handle_array[queue_num],
811 (u64)tx_buff->indir_dma,
814 lpar_rc = send_subcrq(adapter, handle_array[queue_num],
817 if (lpar_rc != H_SUCCESS) {
818 dev_err(dev, "tx failed with code %ld\n", lpar_rc);
820 if (tx_pool->consumer_index == 0)
821 tx_pool->consumer_index =
822 adapter->req_tx_entries_per_subcrq - 1;
824 tx_pool->consumer_index--;
828 ret = NETDEV_TX_BUSY;
832 atomic_inc(&tx_scrq->used);
834 if (atomic_read(&tx_scrq->used) >= adapter->req_tx_entries_per_subcrq) {
835 netdev_info(netdev, "Stopping queue %d\n", queue_num);
836 netif_stop_subqueue(netdev, queue_num);
840 tx_bytes += skb->len;
841 txq->trans_start = jiffies;
845 netdev->stats.tx_dropped += tx_dropped;
846 netdev->stats.tx_bytes += tx_bytes;
847 netdev->stats.tx_packets += tx_packets;
848 adapter->tx_send_failed += tx_send_failed;
849 adapter->tx_map_failed += tx_map_failed;
854 static void ibmvnic_set_multi(struct net_device *netdev)
856 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
857 struct netdev_hw_addr *ha;
858 union ibmvnic_crq crq;
860 memset(&crq, 0, sizeof(crq));
861 crq.request_capability.first = IBMVNIC_CRQ_CMD;
862 crq.request_capability.cmd = REQUEST_CAPABILITY;
864 if (netdev->flags & IFF_PROMISC) {
865 if (!adapter->promisc_supported)
868 if (netdev->flags & IFF_ALLMULTI) {
869 /* Accept all multicast */
870 memset(&crq, 0, sizeof(crq));
871 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
872 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
873 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_ALL;
874 ibmvnic_send_crq(adapter, &crq);
875 } else if (netdev_mc_empty(netdev)) {
876 /* Reject all multicast */
877 memset(&crq, 0, sizeof(crq));
878 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
879 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
880 crq.multicast_ctrl.flags = IBMVNIC_DISABLE_ALL;
881 ibmvnic_send_crq(adapter, &crq);
883 /* Accept one or more multicast(s) */
884 netdev_for_each_mc_addr(ha, netdev) {
885 memset(&crq, 0, sizeof(crq));
886 crq.multicast_ctrl.first = IBMVNIC_CRQ_CMD;
887 crq.multicast_ctrl.cmd = MULTICAST_CTRL;
888 crq.multicast_ctrl.flags = IBMVNIC_ENABLE_MC;
889 ether_addr_copy(&crq.multicast_ctrl.mac_addr[0],
891 ibmvnic_send_crq(adapter, &crq);
897 static int ibmvnic_set_mac(struct net_device *netdev, void *p)
899 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
900 struct sockaddr *addr = p;
901 union ibmvnic_crq crq;
903 if (!is_valid_ether_addr(addr->sa_data))
904 return -EADDRNOTAVAIL;
906 memset(&crq, 0, sizeof(crq));
907 crq.change_mac_addr.first = IBMVNIC_CRQ_CMD;
908 crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
909 ether_addr_copy(&crq.change_mac_addr.mac_addr[0], addr->sa_data);
910 ibmvnic_send_crq(adapter, &crq);
911 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
915 static void ibmvnic_tx_timeout(struct net_device *dev)
917 struct ibmvnic_adapter *adapter = netdev_priv(dev);
920 /* Adapter timed out, resetting it */
921 release_sub_crqs(adapter);
922 rc = ibmvnic_reset_crq(adapter);
924 dev_err(&adapter->vdev->dev, "Adapter timeout, reset failed\n");
926 ibmvnic_send_crq_init(adapter);
929 static void remove_buff_from_pool(struct ibmvnic_adapter *adapter,
930 struct ibmvnic_rx_buff *rx_buff)
932 struct ibmvnic_rx_pool *pool = &adapter->rx_pool[rx_buff->pool_index];
936 pool->free_map[pool->next_alloc] = (int)(rx_buff - pool->rx_buff);
937 pool->next_alloc = (pool->next_alloc + 1) % pool->size;
939 atomic_dec(&pool->available);
942 static int ibmvnic_poll(struct napi_struct *napi, int budget)
944 struct net_device *netdev = napi->dev;
945 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
946 int scrq_num = (int)(napi - adapter->napi);
947 int frames_processed = 0;
949 while (frames_processed < budget) {
951 struct ibmvnic_rx_buff *rx_buff;
957 if (!pending_scrq(adapter, adapter->rx_scrq[scrq_num]))
959 next = ibmvnic_next_scrq(adapter, adapter->rx_scrq[scrq_num]);
961 (struct ibmvnic_rx_buff *)be64_to_cpu(next->
963 /* do error checking */
964 if (next->rx_comp.rc) {
965 netdev_err(netdev, "rx error %x\n", next->rx_comp.rc);
967 next->rx_comp.first = 0;
968 remove_buff_from_pool(adapter, rx_buff);
972 length = be32_to_cpu(next->rx_comp.len);
973 offset = be16_to_cpu(next->rx_comp.off_frame_data);
974 flags = next->rx_comp.flags;
976 skb_copy_to_linear_data(skb, rx_buff->data + offset,
978 skb->vlan_tci = be16_to_cpu(next->rx_comp.vlan_tci);
980 next->rx_comp.first = 0;
981 remove_buff_from_pool(adapter, rx_buff);
983 skb_put(skb, length);
984 skb->protocol = eth_type_trans(skb, netdev);
986 if (flags & IBMVNIC_IP_CHKSUM_GOOD &&
987 flags & IBMVNIC_TCP_UDP_CHKSUM_GOOD) {
988 skb->ip_summed = CHECKSUM_UNNECESSARY;
992 napi_gro_receive(napi, skb); /* send it up */
993 netdev->stats.rx_packets++;
994 netdev->stats.rx_bytes += length;
997 replenish_rx_pool(adapter, &adapter->rx_pool[scrq_num]);
999 if (frames_processed < budget) {
1000 enable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1001 napi_complete_done(napi, frames_processed);
1002 if (pending_scrq(adapter, adapter->rx_scrq[scrq_num]) &&
1003 napi_reschedule(napi)) {
1004 disable_scrq_irq(adapter, adapter->rx_scrq[scrq_num]);
1008 return frames_processed;
1011 #ifdef CONFIG_NET_POLL_CONTROLLER
1012 static void ibmvnic_netpoll_controller(struct net_device *dev)
1014 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1017 replenish_pools(netdev_priv(dev));
1018 for (i = 0; i < adapter->req_rx_queues; i++)
1019 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
1020 adapter->rx_scrq[i]);
1024 static const struct net_device_ops ibmvnic_netdev_ops = {
1025 .ndo_open = ibmvnic_open,
1026 .ndo_stop = ibmvnic_close,
1027 .ndo_start_xmit = ibmvnic_xmit,
1028 .ndo_set_rx_mode = ibmvnic_set_multi,
1029 .ndo_set_mac_address = ibmvnic_set_mac,
1030 .ndo_validate_addr = eth_validate_addr,
1031 .ndo_tx_timeout = ibmvnic_tx_timeout,
1032 #ifdef CONFIG_NET_POLL_CONTROLLER
1033 .ndo_poll_controller = ibmvnic_netpoll_controller,
1037 /* ethtool functions */
1039 static int ibmvnic_get_link_ksettings(struct net_device *netdev,
1040 struct ethtool_link_ksettings *cmd)
1042 u32 supported, advertising;
1044 supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
1046 advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg |
1048 cmd->base.speed = SPEED_1000;
1049 cmd->base.duplex = DUPLEX_FULL;
1050 cmd->base.port = PORT_FIBRE;
1051 cmd->base.phy_address = 0;
1052 cmd->base.autoneg = AUTONEG_ENABLE;
1054 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1056 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1062 static void ibmvnic_get_drvinfo(struct net_device *dev,
1063 struct ethtool_drvinfo *info)
1065 strlcpy(info->driver, ibmvnic_driver_name, sizeof(info->driver));
1066 strlcpy(info->version, IBMVNIC_DRIVER_VERSION, sizeof(info->version));
1069 static u32 ibmvnic_get_msglevel(struct net_device *netdev)
1071 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1073 return adapter->msg_enable;
1076 static void ibmvnic_set_msglevel(struct net_device *netdev, u32 data)
1078 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1080 adapter->msg_enable = data;
1083 static u32 ibmvnic_get_link(struct net_device *netdev)
1085 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
1087 /* Don't need to send a query because we request a logical link up at
1088 * init and then we wait for link state indications
1090 return adapter->logical_link_state;
1093 static void ibmvnic_get_ringparam(struct net_device *netdev,
1094 struct ethtool_ringparam *ring)
1096 ring->rx_max_pending = 0;
1097 ring->tx_max_pending = 0;
1098 ring->rx_mini_max_pending = 0;
1099 ring->rx_jumbo_max_pending = 0;
1100 ring->rx_pending = 0;
1101 ring->tx_pending = 0;
1102 ring->rx_mini_pending = 0;
1103 ring->rx_jumbo_pending = 0;
1106 static void ibmvnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1110 if (stringset != ETH_SS_STATS)
1113 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++, data += ETH_GSTRING_LEN)
1114 memcpy(data, ibmvnic_stats[i].name, ETH_GSTRING_LEN);
1117 static int ibmvnic_get_sset_count(struct net_device *dev, int sset)
1121 return ARRAY_SIZE(ibmvnic_stats);
1127 static void ibmvnic_get_ethtool_stats(struct net_device *dev,
1128 struct ethtool_stats *stats, u64 *data)
1130 struct ibmvnic_adapter *adapter = netdev_priv(dev);
1131 union ibmvnic_crq crq;
1134 memset(&crq, 0, sizeof(crq));
1135 crq.request_statistics.first = IBMVNIC_CRQ_CMD;
1136 crq.request_statistics.cmd = REQUEST_STATISTICS;
1137 crq.request_statistics.ioba = cpu_to_be32(adapter->stats_token);
1138 crq.request_statistics.len =
1139 cpu_to_be32(sizeof(struct ibmvnic_statistics));
1141 /* Wait for data to be written */
1142 init_completion(&adapter->stats_done);
1143 ibmvnic_send_crq(adapter, &crq);
1144 wait_for_completion(&adapter->stats_done);
1146 for (i = 0; i < ARRAY_SIZE(ibmvnic_stats); i++)
1147 data[i] = IBMVNIC_GET_STAT(adapter, ibmvnic_stats[i].offset);
1150 static const struct ethtool_ops ibmvnic_ethtool_ops = {
1151 .get_drvinfo = ibmvnic_get_drvinfo,
1152 .get_msglevel = ibmvnic_get_msglevel,
1153 .set_msglevel = ibmvnic_set_msglevel,
1154 .get_link = ibmvnic_get_link,
1155 .get_ringparam = ibmvnic_get_ringparam,
1156 .get_strings = ibmvnic_get_strings,
1157 .get_sset_count = ibmvnic_get_sset_count,
1158 .get_ethtool_stats = ibmvnic_get_ethtool_stats,
1159 .get_link_ksettings = ibmvnic_get_link_ksettings,
1162 /* Routines for managing CRQs/sCRQs */
1164 static void release_sub_crq_queue(struct ibmvnic_adapter *adapter,
1165 struct ibmvnic_sub_crq_queue *scrq)
1167 struct device *dev = &adapter->vdev->dev;
1170 netdev_dbg(adapter->netdev, "Releasing sub-CRQ\n");
1172 /* Close the sub-crqs */
1174 rc = plpar_hcall_norets(H_FREE_SUB_CRQ,
1175 adapter->vdev->unit_address,
1177 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
1179 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1181 free_pages((unsigned long)scrq->msgs, 2);
1185 static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1188 struct device *dev = &adapter->vdev->dev;
1189 struct ibmvnic_sub_crq_queue *scrq;
1192 scrq = kmalloc(sizeof(*scrq), GFP_ATOMIC);
1196 scrq->msgs = (union sub_crq *)__get_free_pages(GFP_ATOMIC, 2);
1197 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
1199 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
1200 goto zero_page_failed;
1203 scrq->msg_token = dma_map_single(dev, scrq->msgs, 4 * PAGE_SIZE,
1205 if (dma_mapping_error(dev, scrq->msg_token)) {
1206 dev_warn(dev, "Couldn't map crq queue messages page\n");
1210 rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token,
1211 4 * PAGE_SIZE, &scrq->crq_num, &scrq->hw_irq);
1213 if (rc == H_RESOURCE)
1214 rc = ibmvnic_reset_crq(adapter);
1216 if (rc == H_CLOSED) {
1217 dev_warn(dev, "Partner adapter not ready, waiting.\n");
1219 dev_warn(dev, "Error %d registering sub-crq\n", rc);
1223 scrq->adapter = adapter;
1224 scrq->size = 4 * PAGE_SIZE / sizeof(*scrq->msgs);
1226 atomic_set(&scrq->used, 0);
1227 scrq->rx_skb_top = NULL;
1228 spin_lock_init(&scrq->lock);
1230 netdev_dbg(adapter->netdev,
1231 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1232 scrq->crq_num, scrq->hw_irq, scrq->irq);
1237 dma_unmap_single(dev, scrq->msg_token, 4 * PAGE_SIZE,
1240 free_pages((unsigned long)scrq->msgs, 2);
1247 static void release_sub_crqs(struct ibmvnic_adapter *adapter)
1251 if (adapter->tx_scrq) {
1252 for (i = 0; i < adapter->req_tx_queues; i++)
1253 if (adapter->tx_scrq[i]) {
1254 free_irq(adapter->tx_scrq[i]->irq,
1255 adapter->tx_scrq[i]);
1256 irq_dispose_mapping(adapter->tx_scrq[i]->irq);
1257 release_sub_crq_queue(adapter,
1258 adapter->tx_scrq[i]);
1260 kfree(adapter->tx_scrq);
1261 adapter->tx_scrq = NULL;
1264 if (adapter->rx_scrq) {
1265 for (i = 0; i < adapter->req_rx_queues; i++)
1266 if (adapter->rx_scrq[i]) {
1267 free_irq(adapter->rx_scrq[i]->irq,
1268 adapter->rx_scrq[i]);
1269 irq_dispose_mapping(adapter->rx_scrq[i]->irq);
1270 release_sub_crq_queue(adapter,
1271 adapter->rx_scrq[i]);
1273 kfree(adapter->rx_scrq);
1274 adapter->rx_scrq = NULL;
1278 static void release_sub_crqs_no_irqs(struct ibmvnic_adapter *adapter)
1282 if (adapter->tx_scrq) {
1283 for (i = 0; i < adapter->req_tx_queues; i++)
1284 if (adapter->tx_scrq[i])
1285 release_sub_crq_queue(adapter,
1286 adapter->tx_scrq[i]);
1287 adapter->tx_scrq = NULL;
1290 if (adapter->rx_scrq) {
1291 for (i = 0; i < adapter->req_rx_queues; i++)
1292 if (adapter->rx_scrq[i])
1293 release_sub_crq_queue(adapter,
1294 adapter->rx_scrq[i]);
1295 adapter->rx_scrq = NULL;
1299 static int disable_scrq_irq(struct ibmvnic_adapter *adapter,
1300 struct ibmvnic_sub_crq_queue *scrq)
1302 struct device *dev = &adapter->vdev->dev;
1305 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1306 H_DISABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1308 dev_err(dev, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1313 static int enable_scrq_irq(struct ibmvnic_adapter *adapter,
1314 struct ibmvnic_sub_crq_queue *scrq)
1316 struct device *dev = &adapter->vdev->dev;
1319 if (scrq->hw_irq > 0x100000000ULL) {
1320 dev_err(dev, "bad hw_irq = %lx\n", scrq->hw_irq);
1324 rc = plpar_hcall_norets(H_VIOCTL, adapter->vdev->unit_address,
1325 H_ENABLE_VIO_INTERRUPT, scrq->hw_irq, 0, 0);
1327 dev_err(dev, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1332 static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter,
1333 struct ibmvnic_sub_crq_queue *scrq)
1335 struct device *dev = &adapter->vdev->dev;
1336 struct ibmvnic_tx_buff *txbuff;
1337 union sub_crq *next;
1343 while (pending_scrq(adapter, scrq)) {
1344 unsigned int pool = scrq->pool_index;
1346 next = ibmvnic_next_scrq(adapter, scrq);
1347 for (i = 0; i < next->tx_comp.num_comps; i++) {
1348 if (next->tx_comp.rcs[i]) {
1349 dev_err(dev, "tx error %x\n",
1350 next->tx_comp.rcs[i]);
1353 index = be32_to_cpu(next->tx_comp.correlators[i]);
1354 txbuff = &adapter->tx_pool[pool].tx_buff[index];
1356 for (j = 0; j < IBMVNIC_MAX_FRAGS_PER_CRQ; j++) {
1357 if (!txbuff->data_dma[j])
1360 txbuff->data_dma[j] = 0;
1361 txbuff->used_bounce = false;
1363 /* if sub_crq was sent indirectly */
1364 first = txbuff->indir_arr[0].generic.first;
1365 if (first == IBMVNIC_CRQ_CMD) {
1366 dma_unmap_single(dev, txbuff->indir_dma,
1367 sizeof(txbuff->indir_arr),
1371 if (txbuff->last_frag) {
1372 atomic_dec(&scrq->used);
1374 if (atomic_read(&scrq->used) <=
1375 (adapter->req_tx_entries_per_subcrq / 2) &&
1376 netif_subqueue_stopped(adapter->netdev,
1378 netif_wake_subqueue(adapter->netdev,
1380 netdev_dbg(adapter->netdev,
1381 "Started queue %d\n",
1385 dev_kfree_skb_any(txbuff->skb);
1388 adapter->tx_pool[pool].free_map[adapter->tx_pool[pool].
1389 producer_index] = index;
1390 adapter->tx_pool[pool].producer_index =
1391 (adapter->tx_pool[pool].producer_index + 1) %
1392 adapter->req_tx_entries_per_subcrq;
1394 /* remove tx_comp scrq*/
1395 next->tx_comp.first = 0;
1398 enable_scrq_irq(adapter, scrq);
1400 if (pending_scrq(adapter, scrq)) {
1401 disable_scrq_irq(adapter, scrq);
1408 static irqreturn_t ibmvnic_interrupt_tx(int irq, void *instance)
1410 struct ibmvnic_sub_crq_queue *scrq = instance;
1411 struct ibmvnic_adapter *adapter = scrq->adapter;
1413 disable_scrq_irq(adapter, scrq);
1414 ibmvnic_complete_tx(adapter, scrq);
1419 static irqreturn_t ibmvnic_interrupt_rx(int irq, void *instance)
1421 struct ibmvnic_sub_crq_queue *scrq = instance;
1422 struct ibmvnic_adapter *adapter = scrq->adapter;
1424 if (napi_schedule_prep(&adapter->napi[scrq->scrq_num])) {
1425 disable_scrq_irq(adapter, scrq);
1426 __napi_schedule(&adapter->napi[scrq->scrq_num]);
1432 static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
1434 struct device *dev = &adapter->vdev->dev;
1435 struct ibmvnic_sub_crq_queue *scrq;
1439 for (i = 0; i < adapter->req_tx_queues; i++) {
1440 scrq = adapter->tx_scrq[i];
1441 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
1445 dev_err(dev, "Error mapping irq\n");
1446 goto req_tx_irq_failed;
1449 rc = request_irq(scrq->irq, ibmvnic_interrupt_tx,
1450 0, "ibmvnic_tx", scrq);
1453 dev_err(dev, "Couldn't register tx irq 0x%x. rc=%d\n",
1455 irq_dispose_mapping(scrq->irq);
1456 goto req_rx_irq_failed;
1460 for (i = 0; i < adapter->req_rx_queues; i++) {
1461 scrq = adapter->rx_scrq[i];
1462 scrq->irq = irq_create_mapping(NULL, scrq->hw_irq);
1465 dev_err(dev, "Error mapping irq\n");
1466 goto req_rx_irq_failed;
1468 rc = request_irq(scrq->irq, ibmvnic_interrupt_rx,
1469 0, "ibmvnic_rx", scrq);
1471 dev_err(dev, "Couldn't register rx irq 0x%x. rc=%d\n",
1473 irq_dispose_mapping(scrq->irq);
1474 goto req_rx_irq_failed;
1480 for (j = 0; j < i; j++) {
1481 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
1482 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
1484 i = adapter->req_tx_queues;
1486 for (j = 0; j < i; j++) {
1487 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
1488 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
1490 release_sub_crqs_no_irqs(adapter);
1494 static void init_sub_crqs(struct ibmvnic_adapter *adapter, int retry)
1496 struct device *dev = &adapter->vdev->dev;
1497 struct ibmvnic_sub_crq_queue **allqueues;
1498 int registered_queues = 0;
1499 union ibmvnic_crq crq;
1505 /* Sub-CRQ entries are 32 byte long */
1506 int entries_page = 4 * PAGE_SIZE / (sizeof(u64) * 4);
1508 if (adapter->min_tx_entries_per_subcrq > entries_page ||
1509 adapter->min_rx_add_entries_per_subcrq > entries_page) {
1510 dev_err(dev, "Fatal, invalid entries per sub-crq\n");
1511 goto allqueues_failed;
1514 /* Get the minimum between the queried max and the entries
1515 * that fit in our PAGE_SIZE
1517 adapter->req_tx_entries_per_subcrq =
1518 adapter->max_tx_entries_per_subcrq > entries_page ?
1519 entries_page : adapter->max_tx_entries_per_subcrq;
1520 adapter->req_rx_add_entries_per_subcrq =
1521 adapter->max_rx_add_entries_per_subcrq > entries_page ?
1522 entries_page : adapter->max_rx_add_entries_per_subcrq;
1524 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
1525 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
1526 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
1528 adapter->req_mtu = adapter->netdev->mtu + ETH_HLEN;
1531 total_queues = adapter->req_tx_queues + adapter->req_rx_queues;
1533 allqueues = kcalloc(total_queues, sizeof(*allqueues), GFP_ATOMIC);
1535 goto allqueues_failed;
1537 for (i = 0; i < total_queues; i++) {
1538 allqueues[i] = init_sub_crq_queue(adapter);
1539 if (!allqueues[i]) {
1540 dev_warn(dev, "Couldn't allocate all sub-crqs\n");
1543 registered_queues++;
1546 /* Make sure we were able to register the minimum number of queues */
1547 if (registered_queues <
1548 adapter->min_tx_queues + adapter->min_rx_queues) {
1549 dev_err(dev, "Fatal: Couldn't init min number of sub-crqs\n");
1553 /* Distribute the failed allocated queues*/
1554 for (i = 0; i < total_queues - registered_queues + more ; i++) {
1555 netdev_dbg(adapter->netdev, "Reducing number of queues\n");
1558 if (adapter->req_rx_queues > adapter->min_rx_queues)
1559 adapter->req_rx_queues--;
1564 if (adapter->req_tx_queues > adapter->min_tx_queues)
1565 adapter->req_tx_queues--;
1572 adapter->tx_scrq = kcalloc(adapter->req_tx_queues,
1573 sizeof(*adapter->tx_scrq), GFP_ATOMIC);
1574 if (!adapter->tx_scrq)
1577 for (i = 0; i < adapter->req_tx_queues; i++) {
1578 adapter->tx_scrq[i] = allqueues[i];
1579 adapter->tx_scrq[i]->pool_index = i;
1582 adapter->rx_scrq = kcalloc(adapter->req_rx_queues,
1583 sizeof(*adapter->rx_scrq), GFP_ATOMIC);
1584 if (!adapter->rx_scrq)
1587 for (i = 0; i < adapter->req_rx_queues; i++) {
1588 adapter->rx_scrq[i] = allqueues[i + adapter->req_tx_queues];
1589 adapter->rx_scrq[i]->scrq_num = i;
1592 memset(&crq, 0, sizeof(crq));
1593 crq.request_capability.first = IBMVNIC_CRQ_CMD;
1594 crq.request_capability.cmd = REQUEST_CAPABILITY;
1596 crq.request_capability.capability = cpu_to_be16(REQ_TX_QUEUES);
1597 crq.request_capability.number = cpu_to_be64(adapter->req_tx_queues);
1598 atomic_inc(&adapter->running_cap_crqs);
1599 ibmvnic_send_crq(adapter, &crq);
1601 crq.request_capability.capability = cpu_to_be16(REQ_RX_QUEUES);
1602 crq.request_capability.number = cpu_to_be64(adapter->req_rx_queues);
1603 atomic_inc(&adapter->running_cap_crqs);
1604 ibmvnic_send_crq(adapter, &crq);
1606 crq.request_capability.capability = cpu_to_be16(REQ_RX_ADD_QUEUES);
1607 crq.request_capability.number = cpu_to_be64(adapter->req_rx_add_queues);
1608 atomic_inc(&adapter->running_cap_crqs);
1609 ibmvnic_send_crq(adapter, &crq);
1611 crq.request_capability.capability =
1612 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ);
1613 crq.request_capability.number =
1614 cpu_to_be64(adapter->req_tx_entries_per_subcrq);
1615 atomic_inc(&adapter->running_cap_crqs);
1616 ibmvnic_send_crq(adapter, &crq);
1618 crq.request_capability.capability =
1619 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ);
1620 crq.request_capability.number =
1621 cpu_to_be64(adapter->req_rx_add_entries_per_subcrq);
1622 atomic_inc(&adapter->running_cap_crqs);
1623 ibmvnic_send_crq(adapter, &crq);
1625 crq.request_capability.capability = cpu_to_be16(REQ_MTU);
1626 crq.request_capability.number = cpu_to_be64(adapter->req_mtu);
1627 atomic_inc(&adapter->running_cap_crqs);
1628 ibmvnic_send_crq(adapter, &crq);
1630 if (adapter->netdev->flags & IFF_PROMISC) {
1631 if (adapter->promisc_supported) {
1632 crq.request_capability.capability =
1633 cpu_to_be16(PROMISC_REQUESTED);
1634 crq.request_capability.number = cpu_to_be64(1);
1635 atomic_inc(&adapter->running_cap_crqs);
1636 ibmvnic_send_crq(adapter, &crq);
1639 crq.request_capability.capability =
1640 cpu_to_be16(PROMISC_REQUESTED);
1641 crq.request_capability.number = cpu_to_be64(0);
1642 atomic_inc(&adapter->running_cap_crqs);
1643 ibmvnic_send_crq(adapter, &crq);
1651 kfree(adapter->tx_scrq);
1652 adapter->tx_scrq = NULL;
1654 for (i = 0; i < registered_queues; i++)
1655 release_sub_crq_queue(adapter, allqueues[i]);
1658 ibmvnic_remove(adapter->vdev);
1661 static int pending_scrq(struct ibmvnic_adapter *adapter,
1662 struct ibmvnic_sub_crq_queue *scrq)
1664 union sub_crq *entry = &scrq->msgs[scrq->cur];
1666 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP || adapter->closing)
1672 static union sub_crq *ibmvnic_next_scrq(struct ibmvnic_adapter *adapter,
1673 struct ibmvnic_sub_crq_queue *scrq)
1675 union sub_crq *entry;
1676 unsigned long flags;
1678 spin_lock_irqsave(&scrq->lock, flags);
1679 entry = &scrq->msgs[scrq->cur];
1680 if (entry->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1681 if (++scrq->cur == scrq->size)
1686 spin_unlock_irqrestore(&scrq->lock, flags);
1691 static union ibmvnic_crq *ibmvnic_next_crq(struct ibmvnic_adapter *adapter)
1693 struct ibmvnic_crq_queue *queue = &adapter->crq;
1694 union ibmvnic_crq *crq;
1696 crq = &queue->msgs[queue->cur];
1697 if (crq->generic.first & IBMVNIC_CRQ_CMD_RSP) {
1698 if (++queue->cur == queue->size)
1707 static int send_subcrq(struct ibmvnic_adapter *adapter, u64 remote_handle,
1708 union sub_crq *sub_crq)
1710 unsigned int ua = adapter->vdev->unit_address;
1711 struct device *dev = &adapter->vdev->dev;
1712 u64 *u64_crq = (u64 *)sub_crq;
1715 netdev_dbg(adapter->netdev,
1716 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
1717 (unsigned long int)cpu_to_be64(remote_handle),
1718 (unsigned long int)cpu_to_be64(u64_crq[0]),
1719 (unsigned long int)cpu_to_be64(u64_crq[1]),
1720 (unsigned long int)cpu_to_be64(u64_crq[2]),
1721 (unsigned long int)cpu_to_be64(u64_crq[3]));
1723 /* Make sure the hypervisor sees the complete request */
1726 rc = plpar_hcall_norets(H_SEND_SUB_CRQ, ua,
1727 cpu_to_be64(remote_handle),
1728 cpu_to_be64(u64_crq[0]),
1729 cpu_to_be64(u64_crq[1]),
1730 cpu_to_be64(u64_crq[2]),
1731 cpu_to_be64(u64_crq[3]));
1735 dev_warn(dev, "CRQ Queue closed\n");
1736 dev_err(dev, "Send error (rc=%d)\n", rc);
1742 static int send_subcrq_indirect(struct ibmvnic_adapter *adapter,
1743 u64 remote_handle, u64 ioba, u64 num_entries)
1745 unsigned int ua = adapter->vdev->unit_address;
1746 struct device *dev = &adapter->vdev->dev;
1749 /* Make sure the hypervisor sees the complete request */
1751 rc = plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT, ua,
1752 cpu_to_be64(remote_handle),
1757 dev_warn(dev, "CRQ Queue closed\n");
1758 dev_err(dev, "Send (indirect) error (rc=%d)\n", rc);
1764 static int ibmvnic_send_crq(struct ibmvnic_adapter *adapter,
1765 union ibmvnic_crq *crq)
1767 unsigned int ua = adapter->vdev->unit_address;
1768 struct device *dev = &adapter->vdev->dev;
1769 u64 *u64_crq = (u64 *)crq;
1772 netdev_dbg(adapter->netdev, "Sending CRQ: %016lx %016lx\n",
1773 (unsigned long int)cpu_to_be64(u64_crq[0]),
1774 (unsigned long int)cpu_to_be64(u64_crq[1]));
1776 /* Make sure the hypervisor sees the complete request */
1779 rc = plpar_hcall_norets(H_SEND_CRQ, ua,
1780 cpu_to_be64(u64_crq[0]),
1781 cpu_to_be64(u64_crq[1]));
1785 dev_warn(dev, "CRQ Queue closed\n");
1786 dev_warn(dev, "Send error (rc=%d)\n", rc);
1792 static int ibmvnic_send_crq_init(struct ibmvnic_adapter *adapter)
1794 union ibmvnic_crq crq;
1796 memset(&crq, 0, sizeof(crq));
1797 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1798 crq.generic.cmd = IBMVNIC_CRQ_INIT;
1799 netdev_dbg(adapter->netdev, "Sending CRQ init\n");
1801 return ibmvnic_send_crq(adapter, &crq);
1804 static int ibmvnic_send_crq_init_complete(struct ibmvnic_adapter *adapter)
1806 union ibmvnic_crq crq;
1808 memset(&crq, 0, sizeof(crq));
1809 crq.generic.first = IBMVNIC_CRQ_INIT_CMD;
1810 crq.generic.cmd = IBMVNIC_CRQ_INIT_COMPLETE;
1811 netdev_dbg(adapter->netdev, "Sending CRQ init complete\n");
1813 return ibmvnic_send_crq(adapter, &crq);
1816 static int send_version_xchg(struct ibmvnic_adapter *adapter)
1818 union ibmvnic_crq crq;
1820 memset(&crq, 0, sizeof(crq));
1821 crq.version_exchange.first = IBMVNIC_CRQ_CMD;
1822 crq.version_exchange.cmd = VERSION_EXCHANGE;
1823 crq.version_exchange.version = cpu_to_be16(ibmvnic_version);
1825 return ibmvnic_send_crq(adapter, &crq);
1828 static void send_login(struct ibmvnic_adapter *adapter)
1830 struct ibmvnic_login_rsp_buffer *login_rsp_buffer;
1831 struct ibmvnic_login_buffer *login_buffer;
1832 struct ibmvnic_inflight_cmd *inflight_cmd;
1833 struct device *dev = &adapter->vdev->dev;
1834 dma_addr_t rsp_buffer_token;
1835 dma_addr_t buffer_token;
1836 size_t rsp_buffer_size;
1837 union ibmvnic_crq crq;
1838 unsigned long flags;
1845 sizeof(struct ibmvnic_login_buffer) +
1846 sizeof(u64) * (adapter->req_tx_queues + adapter->req_rx_queues);
1848 login_buffer = kmalloc(buffer_size, GFP_ATOMIC);
1850 goto buf_alloc_failed;
1852 buffer_token = dma_map_single(dev, login_buffer, buffer_size,
1854 if (dma_mapping_error(dev, buffer_token)) {
1855 dev_err(dev, "Couldn't map login buffer\n");
1856 goto buf_map_failed;
1859 rsp_buffer_size = sizeof(struct ibmvnic_login_rsp_buffer) +
1860 sizeof(u64) * adapter->req_tx_queues +
1861 sizeof(u64) * adapter->req_rx_queues +
1862 sizeof(u64) * adapter->req_rx_queues +
1863 sizeof(u8) * IBMVNIC_TX_DESC_VERSIONS;
1865 login_rsp_buffer = kmalloc(rsp_buffer_size, GFP_ATOMIC);
1866 if (!login_rsp_buffer)
1867 goto buf_rsp_alloc_failed;
1869 rsp_buffer_token = dma_map_single(dev, login_rsp_buffer,
1870 rsp_buffer_size, DMA_FROM_DEVICE);
1871 if (dma_mapping_error(dev, rsp_buffer_token)) {
1872 dev_err(dev, "Couldn't map login rsp buffer\n");
1873 goto buf_rsp_map_failed;
1875 inflight_cmd = kmalloc(sizeof(*inflight_cmd), GFP_ATOMIC);
1876 if (!inflight_cmd) {
1877 dev_err(dev, "Couldn't allocate inflight_cmd\n");
1878 goto inflight_alloc_failed;
1880 adapter->login_buf = login_buffer;
1881 adapter->login_buf_token = buffer_token;
1882 adapter->login_buf_sz = buffer_size;
1883 adapter->login_rsp_buf = login_rsp_buffer;
1884 adapter->login_rsp_buf_token = rsp_buffer_token;
1885 adapter->login_rsp_buf_sz = rsp_buffer_size;
1887 login_buffer->len = cpu_to_be32(buffer_size);
1888 login_buffer->version = cpu_to_be32(INITIAL_VERSION_LB);
1889 login_buffer->num_txcomp_subcrqs = cpu_to_be32(adapter->req_tx_queues);
1890 login_buffer->off_txcomp_subcrqs =
1891 cpu_to_be32(sizeof(struct ibmvnic_login_buffer));
1892 login_buffer->num_rxcomp_subcrqs = cpu_to_be32(adapter->req_rx_queues);
1893 login_buffer->off_rxcomp_subcrqs =
1894 cpu_to_be32(sizeof(struct ibmvnic_login_buffer) +
1895 sizeof(u64) * adapter->req_tx_queues);
1896 login_buffer->login_rsp_ioba = cpu_to_be32(rsp_buffer_token);
1897 login_buffer->login_rsp_len = cpu_to_be32(rsp_buffer_size);
1899 tx_list_p = (__be64 *)((char *)login_buffer +
1900 sizeof(struct ibmvnic_login_buffer));
1901 rx_list_p = (__be64 *)((char *)login_buffer +
1902 sizeof(struct ibmvnic_login_buffer) +
1903 sizeof(u64) * adapter->req_tx_queues);
1905 for (i = 0; i < adapter->req_tx_queues; i++) {
1906 if (adapter->tx_scrq[i]) {
1907 tx_list_p[i] = cpu_to_be64(adapter->tx_scrq[i]->
1912 for (i = 0; i < adapter->req_rx_queues; i++) {
1913 if (adapter->rx_scrq[i]) {
1914 rx_list_p[i] = cpu_to_be64(adapter->rx_scrq[i]->
1919 netdev_dbg(adapter->netdev, "Login Buffer:\n");
1920 for (i = 0; i < (adapter->login_buf_sz - 1) / 8 + 1; i++) {
1921 netdev_dbg(adapter->netdev, "%016lx\n",
1922 ((unsigned long int *)(adapter->login_buf))[i]);
1925 memset(&crq, 0, sizeof(crq));
1926 crq.login.first = IBMVNIC_CRQ_CMD;
1927 crq.login.cmd = LOGIN;
1928 crq.login.ioba = cpu_to_be32(buffer_token);
1929 crq.login.len = cpu_to_be32(buffer_size);
1931 memcpy(&inflight_cmd->crq, &crq, sizeof(crq));
1933 spin_lock_irqsave(&adapter->inflight_lock, flags);
1934 list_add_tail(&inflight_cmd->list, &adapter->inflight);
1935 spin_unlock_irqrestore(&adapter->inflight_lock, flags);
1937 ibmvnic_send_crq(adapter, &crq);
1941 inflight_alloc_failed:
1942 dma_unmap_single(dev, rsp_buffer_token, rsp_buffer_size,
1945 kfree(login_rsp_buffer);
1946 buf_rsp_alloc_failed:
1947 dma_unmap_single(dev, buffer_token, buffer_size, DMA_TO_DEVICE);
1949 kfree(login_buffer);
1954 static void send_request_map(struct ibmvnic_adapter *adapter, dma_addr_t addr,
1957 union ibmvnic_crq crq;
1959 memset(&crq, 0, sizeof(crq));
1960 crq.request_map.first = IBMVNIC_CRQ_CMD;
1961 crq.request_map.cmd = REQUEST_MAP;
1962 crq.request_map.map_id = map_id;
1963 crq.request_map.ioba = cpu_to_be32(addr);
1964 crq.request_map.len = cpu_to_be32(len);
1965 ibmvnic_send_crq(adapter, &crq);
1968 static void send_request_unmap(struct ibmvnic_adapter *adapter, u8 map_id)
1970 union ibmvnic_crq crq;
1972 memset(&crq, 0, sizeof(crq));
1973 crq.request_unmap.first = IBMVNIC_CRQ_CMD;
1974 crq.request_unmap.cmd = REQUEST_UNMAP;
1975 crq.request_unmap.map_id = map_id;
1976 ibmvnic_send_crq(adapter, &crq);
1979 static void send_map_query(struct ibmvnic_adapter *adapter)
1981 union ibmvnic_crq crq;
1983 memset(&crq, 0, sizeof(crq));
1984 crq.query_map.first = IBMVNIC_CRQ_CMD;
1985 crq.query_map.cmd = QUERY_MAP;
1986 ibmvnic_send_crq(adapter, &crq);
1989 /* Send a series of CRQs requesting various capabilities of the VNIC server */
1990 static void send_cap_queries(struct ibmvnic_adapter *adapter)
1992 union ibmvnic_crq crq;
1994 atomic_set(&adapter->running_cap_crqs, 0);
1995 memset(&crq, 0, sizeof(crq));
1996 crq.query_capability.first = IBMVNIC_CRQ_CMD;
1997 crq.query_capability.cmd = QUERY_CAPABILITY;
1999 crq.query_capability.capability = cpu_to_be16(MIN_TX_QUEUES);
2000 atomic_inc(&adapter->running_cap_crqs);
2001 ibmvnic_send_crq(adapter, &crq);
2003 crq.query_capability.capability = cpu_to_be16(MIN_RX_QUEUES);
2004 atomic_inc(&adapter->running_cap_crqs);
2005 ibmvnic_send_crq(adapter, &crq);
2007 crq.query_capability.capability = cpu_to_be16(MIN_RX_ADD_QUEUES);
2008 atomic_inc(&adapter->running_cap_crqs);
2009 ibmvnic_send_crq(adapter, &crq);
2011 crq.query_capability.capability = cpu_to_be16(MAX_TX_QUEUES);
2012 atomic_inc(&adapter->running_cap_crqs);
2013 ibmvnic_send_crq(adapter, &crq);
2015 crq.query_capability.capability = cpu_to_be16(MAX_RX_QUEUES);
2016 atomic_inc(&adapter->running_cap_crqs);
2017 ibmvnic_send_crq(adapter, &crq);
2019 crq.query_capability.capability = cpu_to_be16(MAX_RX_ADD_QUEUES);
2020 atomic_inc(&adapter->running_cap_crqs);
2021 ibmvnic_send_crq(adapter, &crq);
2023 crq.query_capability.capability =
2024 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ);
2025 atomic_inc(&adapter->running_cap_crqs);
2026 ibmvnic_send_crq(adapter, &crq);
2028 crq.query_capability.capability =
2029 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ);
2030 atomic_inc(&adapter->running_cap_crqs);
2031 ibmvnic_send_crq(adapter, &crq);
2033 crq.query_capability.capability =
2034 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ);
2035 atomic_inc(&adapter->running_cap_crqs);
2036 ibmvnic_send_crq(adapter, &crq);
2038 crq.query_capability.capability =
2039 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ);
2040 atomic_inc(&adapter->running_cap_crqs);
2041 ibmvnic_send_crq(adapter, &crq);
2043 crq.query_capability.capability = cpu_to_be16(TCP_IP_OFFLOAD);
2044 atomic_inc(&adapter->running_cap_crqs);
2045 ibmvnic_send_crq(adapter, &crq);
2047 crq.query_capability.capability = cpu_to_be16(PROMISC_SUPPORTED);
2048 atomic_inc(&adapter->running_cap_crqs);
2049 ibmvnic_send_crq(adapter, &crq);
2051 crq.query_capability.capability = cpu_to_be16(MIN_MTU);
2052 atomic_inc(&adapter->running_cap_crqs);
2053 ibmvnic_send_crq(adapter, &crq);
2055 crq.query_capability.capability = cpu_to_be16(MAX_MTU);
2056 atomic_inc(&adapter->running_cap_crqs);
2057 ibmvnic_send_crq(adapter, &crq);
2059 crq.query_capability.capability = cpu_to_be16(MAX_MULTICAST_FILTERS);
2060 atomic_inc(&adapter->running_cap_crqs);
2061 ibmvnic_send_crq(adapter, &crq);
2063 crq.query_capability.capability = cpu_to_be16(VLAN_HEADER_INSERTION);
2064 atomic_inc(&adapter->running_cap_crqs);
2065 ibmvnic_send_crq(adapter, &crq);
2067 crq.query_capability.capability = cpu_to_be16(MAX_TX_SG_ENTRIES);
2068 atomic_inc(&adapter->running_cap_crqs);
2069 ibmvnic_send_crq(adapter, &crq);
2071 crq.query_capability.capability = cpu_to_be16(RX_SG_SUPPORTED);
2072 atomic_inc(&adapter->running_cap_crqs);
2073 ibmvnic_send_crq(adapter, &crq);
2075 crq.query_capability.capability = cpu_to_be16(OPT_TX_COMP_SUB_QUEUES);
2076 atomic_inc(&adapter->running_cap_crqs);
2077 ibmvnic_send_crq(adapter, &crq);
2079 crq.query_capability.capability = cpu_to_be16(OPT_RX_COMP_QUEUES);
2080 atomic_inc(&adapter->running_cap_crqs);
2081 ibmvnic_send_crq(adapter, &crq);
2083 crq.query_capability.capability =
2084 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q);
2085 atomic_inc(&adapter->running_cap_crqs);
2086 ibmvnic_send_crq(adapter, &crq);
2088 crq.query_capability.capability =
2089 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ);
2090 atomic_inc(&adapter->running_cap_crqs);
2091 ibmvnic_send_crq(adapter, &crq);
2093 crq.query_capability.capability =
2094 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ);
2095 atomic_inc(&adapter->running_cap_crqs);
2096 ibmvnic_send_crq(adapter, &crq);
2098 crq.query_capability.capability = cpu_to_be16(TX_RX_DESC_REQ);
2099 atomic_inc(&adapter->running_cap_crqs);
2100 ibmvnic_send_crq(adapter, &crq);
2103 static void handle_query_ip_offload_rsp(struct ibmvnic_adapter *adapter)
2105 struct device *dev = &adapter->vdev->dev;
2106 struct ibmvnic_query_ip_offload_buffer *buf = &adapter->ip_offload_buf;
2107 union ibmvnic_crq crq;
2110 dma_unmap_single(dev, adapter->ip_offload_tok,
2111 sizeof(adapter->ip_offload_buf), DMA_FROM_DEVICE);
2113 netdev_dbg(adapter->netdev, "Query IP Offload Buffer:\n");
2114 for (i = 0; i < (sizeof(adapter->ip_offload_buf) - 1) / 8 + 1; i++)
2115 netdev_dbg(adapter->netdev, "%016lx\n",
2116 ((unsigned long int *)(buf))[i]);
2118 netdev_dbg(adapter->netdev, "ipv4_chksum = %d\n", buf->ipv4_chksum);
2119 netdev_dbg(adapter->netdev, "ipv6_chksum = %d\n", buf->ipv6_chksum);
2120 netdev_dbg(adapter->netdev, "tcp_ipv4_chksum = %d\n",
2121 buf->tcp_ipv4_chksum);
2122 netdev_dbg(adapter->netdev, "tcp_ipv6_chksum = %d\n",
2123 buf->tcp_ipv6_chksum);
2124 netdev_dbg(adapter->netdev, "udp_ipv4_chksum = %d\n",
2125 buf->udp_ipv4_chksum);
2126 netdev_dbg(adapter->netdev, "udp_ipv6_chksum = %d\n",
2127 buf->udp_ipv6_chksum);
2128 netdev_dbg(adapter->netdev, "large_tx_ipv4 = %d\n",
2129 buf->large_tx_ipv4);
2130 netdev_dbg(adapter->netdev, "large_tx_ipv6 = %d\n",
2131 buf->large_tx_ipv6);
2132 netdev_dbg(adapter->netdev, "large_rx_ipv4 = %d\n",
2133 buf->large_rx_ipv4);
2134 netdev_dbg(adapter->netdev, "large_rx_ipv6 = %d\n",
2135 buf->large_rx_ipv6);
2136 netdev_dbg(adapter->netdev, "max_ipv4_hdr_sz = %d\n",
2137 buf->max_ipv4_header_size);
2138 netdev_dbg(adapter->netdev, "max_ipv6_hdr_sz = %d\n",
2139 buf->max_ipv6_header_size);
2140 netdev_dbg(adapter->netdev, "max_tcp_hdr_size = %d\n",
2141 buf->max_tcp_header_size);
2142 netdev_dbg(adapter->netdev, "max_udp_hdr_size = %d\n",
2143 buf->max_udp_header_size);
2144 netdev_dbg(adapter->netdev, "max_large_tx_size = %d\n",
2145 buf->max_large_tx_size);
2146 netdev_dbg(adapter->netdev, "max_large_rx_size = %d\n",
2147 buf->max_large_rx_size);
2148 netdev_dbg(adapter->netdev, "ipv6_ext_hdr = %d\n",
2149 buf->ipv6_extension_header);
2150 netdev_dbg(adapter->netdev, "tcp_pseudosum_req = %d\n",
2151 buf->tcp_pseudosum_req);
2152 netdev_dbg(adapter->netdev, "num_ipv6_ext_hd = %d\n",
2153 buf->num_ipv6_ext_headers);
2154 netdev_dbg(adapter->netdev, "off_ipv6_ext_hd = %d\n",
2155 buf->off_ipv6_ext_headers);
2157 adapter->ip_offload_ctrl_tok =
2158 dma_map_single(dev, &adapter->ip_offload_ctrl,
2159 sizeof(adapter->ip_offload_ctrl), DMA_TO_DEVICE);
2161 if (dma_mapping_error(dev, adapter->ip_offload_ctrl_tok)) {
2162 dev_err(dev, "Couldn't map ip offload control buffer\n");
2166 adapter->ip_offload_ctrl.version = cpu_to_be32(INITIAL_VERSION_IOB);
2167 adapter->ip_offload_ctrl.tcp_ipv4_chksum = buf->tcp_ipv4_chksum;
2168 adapter->ip_offload_ctrl.udp_ipv4_chksum = buf->udp_ipv4_chksum;
2169 adapter->ip_offload_ctrl.tcp_ipv6_chksum = buf->tcp_ipv6_chksum;
2170 adapter->ip_offload_ctrl.udp_ipv6_chksum = buf->udp_ipv6_chksum;
2172 /* large_tx/rx disabled for now, additional features needed */
2173 adapter->ip_offload_ctrl.large_tx_ipv4 = 0;
2174 adapter->ip_offload_ctrl.large_tx_ipv6 = 0;
2175 adapter->ip_offload_ctrl.large_rx_ipv4 = 0;
2176 adapter->ip_offload_ctrl.large_rx_ipv6 = 0;
2178 adapter->netdev->features = NETIF_F_GSO;
2180 if (buf->tcp_ipv4_chksum || buf->udp_ipv4_chksum)
2181 adapter->netdev->features |= NETIF_F_IP_CSUM;
2183 if (buf->tcp_ipv6_chksum || buf->udp_ipv6_chksum)
2184 adapter->netdev->features |= NETIF_F_IPV6_CSUM;
2186 if ((adapter->netdev->features &
2187 (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)))
2188 adapter->netdev->features |= NETIF_F_RXCSUM;
2190 memset(&crq, 0, sizeof(crq));
2191 crq.control_ip_offload.first = IBMVNIC_CRQ_CMD;
2192 crq.control_ip_offload.cmd = CONTROL_IP_OFFLOAD;
2193 crq.control_ip_offload.len =
2194 cpu_to_be32(sizeof(adapter->ip_offload_ctrl));
2195 crq.control_ip_offload.ioba = cpu_to_be32(adapter->ip_offload_ctrl_tok);
2196 ibmvnic_send_crq(adapter, &crq);
2199 static void handle_error_info_rsp(union ibmvnic_crq *crq,
2200 struct ibmvnic_adapter *adapter)
2202 struct device *dev = &adapter->vdev->dev;
2203 struct ibmvnic_error_buff *error_buff, *tmp;
2204 unsigned long flags;
2208 if (!crq->request_error_rsp.rc.code) {
2209 dev_info(dev, "Request Error Rsp returned with rc=%x\n",
2210 crq->request_error_rsp.rc.code);
2214 spin_lock_irqsave(&adapter->error_list_lock, flags);
2215 list_for_each_entry_safe(error_buff, tmp, &adapter->errors, list)
2216 if (error_buff->error_id == crq->request_error_rsp.error_id) {
2218 list_del(&error_buff->list);
2221 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2224 dev_err(dev, "Couldn't find error id %x\n",
2225 be32_to_cpu(crq->request_error_rsp.error_id));
2229 dev_err(dev, "Detailed info for error id %x:",
2230 be32_to_cpu(crq->request_error_rsp.error_id));
2232 for (i = 0; i < error_buff->len; i++) {
2233 pr_cont("%02x", (int)error_buff->buff[i]);
2239 dma_unmap_single(dev, error_buff->dma, error_buff->len,
2241 kfree(error_buff->buff);
2245 static void handle_dump_size_rsp(union ibmvnic_crq *crq,
2246 struct ibmvnic_adapter *adapter)
2248 int len = be32_to_cpu(crq->request_dump_size_rsp.len);
2249 struct ibmvnic_inflight_cmd *inflight_cmd;
2250 struct device *dev = &adapter->vdev->dev;
2251 union ibmvnic_crq newcrq;
2252 unsigned long flags;
2254 /* allocate and map buffer */
2255 adapter->dump_data = kmalloc(len, GFP_KERNEL);
2256 if (!adapter->dump_data) {
2257 complete(&adapter->fw_done);
2261 adapter->dump_data_token = dma_map_single(dev, adapter->dump_data, len,
2264 if (dma_mapping_error(dev, adapter->dump_data_token)) {
2265 if (!firmware_has_feature(FW_FEATURE_CMO))
2266 dev_err(dev, "Couldn't map dump data\n");
2267 kfree(adapter->dump_data);
2268 complete(&adapter->fw_done);
2272 inflight_cmd = kmalloc(sizeof(*inflight_cmd), GFP_ATOMIC);
2273 if (!inflight_cmd) {
2274 dma_unmap_single(dev, adapter->dump_data_token, len,
2276 kfree(adapter->dump_data);
2277 complete(&adapter->fw_done);
2281 memset(&newcrq, 0, sizeof(newcrq));
2282 newcrq.request_dump.first = IBMVNIC_CRQ_CMD;
2283 newcrq.request_dump.cmd = REQUEST_DUMP;
2284 newcrq.request_dump.ioba = cpu_to_be32(adapter->dump_data_token);
2285 newcrq.request_dump.len = cpu_to_be32(adapter->dump_data_size);
2287 memcpy(&inflight_cmd->crq, &newcrq, sizeof(newcrq));
2289 spin_lock_irqsave(&adapter->inflight_lock, flags);
2290 list_add_tail(&inflight_cmd->list, &adapter->inflight);
2291 spin_unlock_irqrestore(&adapter->inflight_lock, flags);
2293 ibmvnic_send_crq(adapter, &newcrq);
2296 static void handle_error_indication(union ibmvnic_crq *crq,
2297 struct ibmvnic_adapter *adapter)
2299 int detail_len = be32_to_cpu(crq->error_indication.detail_error_sz);
2300 struct ibmvnic_inflight_cmd *inflight_cmd;
2301 struct device *dev = &adapter->vdev->dev;
2302 struct ibmvnic_error_buff *error_buff;
2303 union ibmvnic_crq new_crq;
2304 unsigned long flags;
2306 dev_err(dev, "Firmware reports %serror id %x, cause %d\n",
2307 crq->error_indication.
2308 flags & IBMVNIC_FATAL_ERROR ? "FATAL " : "",
2309 be32_to_cpu(crq->error_indication.error_id),
2310 be16_to_cpu(crq->error_indication.error_cause));
2312 error_buff = kmalloc(sizeof(*error_buff), GFP_ATOMIC);
2316 error_buff->buff = kmalloc(detail_len, GFP_ATOMIC);
2317 if (!error_buff->buff) {
2322 error_buff->dma = dma_map_single(dev, error_buff->buff, detail_len,
2324 if (dma_mapping_error(dev, error_buff->dma)) {
2325 if (!firmware_has_feature(FW_FEATURE_CMO))
2326 dev_err(dev, "Couldn't map error buffer\n");
2327 kfree(error_buff->buff);
2332 inflight_cmd = kmalloc(sizeof(*inflight_cmd), GFP_ATOMIC);
2333 if (!inflight_cmd) {
2334 dma_unmap_single(dev, error_buff->dma, detail_len,
2336 kfree(error_buff->buff);
2341 error_buff->len = detail_len;
2342 error_buff->error_id = crq->error_indication.error_id;
2344 spin_lock_irqsave(&adapter->error_list_lock, flags);
2345 list_add_tail(&error_buff->list, &adapter->errors);
2346 spin_unlock_irqrestore(&adapter->error_list_lock, flags);
2348 memset(&new_crq, 0, sizeof(new_crq));
2349 new_crq.request_error_info.first = IBMVNIC_CRQ_CMD;
2350 new_crq.request_error_info.cmd = REQUEST_ERROR_INFO;
2351 new_crq.request_error_info.ioba = cpu_to_be32(error_buff->dma);
2352 new_crq.request_error_info.len = cpu_to_be32(detail_len);
2353 new_crq.request_error_info.error_id = crq->error_indication.error_id;
2355 memcpy(&inflight_cmd->crq, &crq, sizeof(crq));
2357 spin_lock_irqsave(&adapter->inflight_lock, flags);
2358 list_add_tail(&inflight_cmd->list, &adapter->inflight);
2359 spin_unlock_irqrestore(&adapter->inflight_lock, flags);
2361 ibmvnic_send_crq(adapter, &new_crq);
2364 static void handle_change_mac_rsp(union ibmvnic_crq *crq,
2365 struct ibmvnic_adapter *adapter)
2367 struct net_device *netdev = adapter->netdev;
2368 struct device *dev = &adapter->vdev->dev;
2371 rc = crq->change_mac_addr_rsp.rc.code;
2373 dev_err(dev, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc);
2376 memcpy(netdev->dev_addr, &crq->change_mac_addr_rsp.mac_addr[0],
2380 static void handle_request_cap_rsp(union ibmvnic_crq *crq,
2381 struct ibmvnic_adapter *adapter)
2383 struct device *dev = &adapter->vdev->dev;
2387 atomic_dec(&adapter->running_cap_crqs);
2388 switch (be16_to_cpu(crq->request_capability_rsp.capability)) {
2390 req_value = &adapter->req_tx_queues;
2394 req_value = &adapter->req_rx_queues;
2397 case REQ_RX_ADD_QUEUES:
2398 req_value = &adapter->req_rx_add_queues;
2401 case REQ_TX_ENTRIES_PER_SUBCRQ:
2402 req_value = &adapter->req_tx_entries_per_subcrq;
2403 name = "tx_entries_per_subcrq";
2405 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ:
2406 req_value = &adapter->req_rx_add_entries_per_subcrq;
2407 name = "rx_add_entries_per_subcrq";
2410 req_value = &adapter->req_mtu;
2413 case PROMISC_REQUESTED:
2414 req_value = &adapter->promisc;
2418 dev_err(dev, "Got invalid cap request rsp %d\n",
2419 crq->request_capability.capability);
2423 switch (crq->request_capability_rsp.rc.code) {
2426 case PARTIALSUCCESS:
2427 dev_info(dev, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2429 (long int)be64_to_cpu(crq->request_capability_rsp.
2431 release_sub_crqs_no_irqs(adapter);
2432 *req_value = be64_to_cpu(crq->request_capability_rsp.number);
2433 init_sub_crqs(adapter, 1);
2436 dev_err(dev, "Error %d in request cap rsp\n",
2437 crq->request_capability_rsp.rc.code);
2441 /* Done receiving requested capabilities, query IP offload support */
2442 if (atomic_read(&adapter->running_cap_crqs) == 0) {
2443 union ibmvnic_crq newcrq;
2444 int buf_sz = sizeof(struct ibmvnic_query_ip_offload_buffer);
2445 struct ibmvnic_query_ip_offload_buffer *ip_offload_buf =
2446 &adapter->ip_offload_buf;
2448 adapter->wait_capability = false;
2449 adapter->ip_offload_tok = dma_map_single(dev, ip_offload_buf,
2453 if (dma_mapping_error(dev, adapter->ip_offload_tok)) {
2454 if (!firmware_has_feature(FW_FEATURE_CMO))
2455 dev_err(dev, "Couldn't map offload buffer\n");
2459 memset(&newcrq, 0, sizeof(newcrq));
2460 newcrq.query_ip_offload.first = IBMVNIC_CRQ_CMD;
2461 newcrq.query_ip_offload.cmd = QUERY_IP_OFFLOAD;
2462 newcrq.query_ip_offload.len = cpu_to_be32(buf_sz);
2463 newcrq.query_ip_offload.ioba =
2464 cpu_to_be32(adapter->ip_offload_tok);
2466 ibmvnic_send_crq(adapter, &newcrq);
2470 static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
2471 struct ibmvnic_adapter *adapter)
2473 struct device *dev = &adapter->vdev->dev;
2474 struct ibmvnic_login_rsp_buffer *login_rsp = adapter->login_rsp_buf;
2475 struct ibmvnic_login_buffer *login = adapter->login_buf;
2476 union ibmvnic_crq crq;
2479 dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
2481 dma_unmap_single(dev, adapter->login_rsp_buf_token,
2482 adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
2484 /* If the number of queues requested can't be allocated by the
2485 * server, the login response will return with code 1. We will need
2486 * to resend the login buffer with fewer queues requested.
2488 if (login_rsp_crq->generic.rc.code) {
2489 adapter->renegotiate = true;
2490 complete(&adapter->init_done);
2494 netdev_dbg(adapter->netdev, "Login Response Buffer:\n");
2495 for (i = 0; i < (adapter->login_rsp_buf_sz - 1) / 8 + 1; i++) {
2496 netdev_dbg(adapter->netdev, "%016lx\n",
2497 ((unsigned long int *)(adapter->login_rsp_buf))[i]);
2501 if (login->num_txcomp_subcrqs != login_rsp->num_txsubm_subcrqs ||
2502 (be32_to_cpu(login->num_rxcomp_subcrqs) *
2503 adapter->req_rx_add_queues !=
2504 be32_to_cpu(login_rsp->num_rxadd_subcrqs))) {
2505 dev_err(dev, "FATAL: Inconsistent login and login rsp\n");
2506 ibmvnic_remove(adapter->vdev);
2509 complete(&adapter->init_done);
2511 memset(&crq, 0, sizeof(crq));
2512 crq.request_ras_comp_num.first = IBMVNIC_CRQ_CMD;
2513 crq.request_ras_comp_num.cmd = REQUEST_RAS_COMP_NUM;
2514 ibmvnic_send_crq(adapter, &crq);
2519 static void handle_request_map_rsp(union ibmvnic_crq *crq,
2520 struct ibmvnic_adapter *adapter)
2522 struct device *dev = &adapter->vdev->dev;
2523 u8 map_id = crq->request_map_rsp.map_id;
2529 tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
2530 rx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
2532 rc = crq->request_map_rsp.rc.code;
2534 dev_err(dev, "Error %ld in REQUEST_MAP_RSP\n", rc);
2536 /* need to find and zero tx/rx_pool map_id */
2537 for (i = 0; i < tx_subcrqs; i++) {
2538 if (adapter->tx_pool[i].long_term_buff.map_id == map_id)
2539 adapter->tx_pool[i].long_term_buff.map_id = 0;
2541 for (i = 0; i < rx_subcrqs; i++) {
2542 if (adapter->rx_pool[i].long_term_buff.map_id == map_id)
2543 adapter->rx_pool[i].long_term_buff.map_id = 0;
2546 complete(&adapter->fw_done);
2549 static void handle_request_unmap_rsp(union ibmvnic_crq *crq,
2550 struct ibmvnic_adapter *adapter)
2552 struct device *dev = &adapter->vdev->dev;
2555 rc = crq->request_unmap_rsp.rc.code;
2557 dev_err(dev, "Error %ld in REQUEST_UNMAP_RSP\n", rc);
2560 static void handle_query_map_rsp(union ibmvnic_crq *crq,
2561 struct ibmvnic_adapter *adapter)
2563 struct net_device *netdev = adapter->netdev;
2564 struct device *dev = &adapter->vdev->dev;
2567 rc = crq->query_map_rsp.rc.code;
2569 dev_err(dev, "Error %ld in QUERY_MAP_RSP\n", rc);
2572 netdev_dbg(netdev, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
2573 crq->query_map_rsp.page_size, crq->query_map_rsp.tot_pages,
2574 crq->query_map_rsp.free_pages);
2577 static void handle_query_cap_rsp(union ibmvnic_crq *crq,
2578 struct ibmvnic_adapter *adapter)
2580 struct net_device *netdev = adapter->netdev;
2581 struct device *dev = &adapter->vdev->dev;
2584 atomic_dec(&adapter->running_cap_crqs);
2585 netdev_dbg(netdev, "Outstanding queries: %d\n",
2586 atomic_read(&adapter->running_cap_crqs));
2587 rc = crq->query_capability.rc.code;
2589 dev_err(dev, "Error %ld in QUERY_CAP_RSP\n", rc);
2593 switch (be16_to_cpu(crq->query_capability.capability)) {
2595 adapter->min_tx_queues =
2596 be64_to_cpu(crq->query_capability.number);
2597 netdev_dbg(netdev, "min_tx_queues = %lld\n",
2598 adapter->min_tx_queues);
2601 adapter->min_rx_queues =
2602 be64_to_cpu(crq->query_capability.number);
2603 netdev_dbg(netdev, "min_rx_queues = %lld\n",
2604 adapter->min_rx_queues);
2606 case MIN_RX_ADD_QUEUES:
2607 adapter->min_rx_add_queues =
2608 be64_to_cpu(crq->query_capability.number);
2609 netdev_dbg(netdev, "min_rx_add_queues = %lld\n",
2610 adapter->min_rx_add_queues);
2613 adapter->max_tx_queues =
2614 be64_to_cpu(crq->query_capability.number);
2615 netdev_dbg(netdev, "max_tx_queues = %lld\n",
2616 adapter->max_tx_queues);
2619 adapter->max_rx_queues =
2620 be64_to_cpu(crq->query_capability.number);
2621 netdev_dbg(netdev, "max_rx_queues = %lld\n",
2622 adapter->max_rx_queues);
2624 case MAX_RX_ADD_QUEUES:
2625 adapter->max_rx_add_queues =
2626 be64_to_cpu(crq->query_capability.number);
2627 netdev_dbg(netdev, "max_rx_add_queues = %lld\n",
2628 adapter->max_rx_add_queues);
2630 case MIN_TX_ENTRIES_PER_SUBCRQ:
2631 adapter->min_tx_entries_per_subcrq =
2632 be64_to_cpu(crq->query_capability.number);
2633 netdev_dbg(netdev, "min_tx_entries_per_subcrq = %lld\n",
2634 adapter->min_tx_entries_per_subcrq);
2636 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ:
2637 adapter->min_rx_add_entries_per_subcrq =
2638 be64_to_cpu(crq->query_capability.number);
2639 netdev_dbg(netdev, "min_rx_add_entrs_per_subcrq = %lld\n",
2640 adapter->min_rx_add_entries_per_subcrq);
2642 case MAX_TX_ENTRIES_PER_SUBCRQ:
2643 adapter->max_tx_entries_per_subcrq =
2644 be64_to_cpu(crq->query_capability.number);
2645 netdev_dbg(netdev, "max_tx_entries_per_subcrq = %lld\n",
2646 adapter->max_tx_entries_per_subcrq);
2648 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ:
2649 adapter->max_rx_add_entries_per_subcrq =
2650 be64_to_cpu(crq->query_capability.number);
2651 netdev_dbg(netdev, "max_rx_add_entrs_per_subcrq = %lld\n",
2652 adapter->max_rx_add_entries_per_subcrq);
2654 case TCP_IP_OFFLOAD:
2655 adapter->tcp_ip_offload =
2656 be64_to_cpu(crq->query_capability.number);
2657 netdev_dbg(netdev, "tcp_ip_offload = %lld\n",
2658 adapter->tcp_ip_offload);
2660 case PROMISC_SUPPORTED:
2661 adapter->promisc_supported =
2662 be64_to_cpu(crq->query_capability.number);
2663 netdev_dbg(netdev, "promisc_supported = %lld\n",
2664 adapter->promisc_supported);
2667 adapter->min_mtu = be64_to_cpu(crq->query_capability.number);
2668 netdev->min_mtu = adapter->min_mtu - ETH_HLEN;
2669 netdev_dbg(netdev, "min_mtu = %lld\n", adapter->min_mtu);
2672 adapter->max_mtu = be64_to_cpu(crq->query_capability.number);
2673 netdev->max_mtu = adapter->max_mtu - ETH_HLEN;
2674 netdev_dbg(netdev, "max_mtu = %lld\n", adapter->max_mtu);
2676 case MAX_MULTICAST_FILTERS:
2677 adapter->max_multicast_filters =
2678 be64_to_cpu(crq->query_capability.number);
2679 netdev_dbg(netdev, "max_multicast_filters = %lld\n",
2680 adapter->max_multicast_filters);
2682 case VLAN_HEADER_INSERTION:
2683 adapter->vlan_header_insertion =
2684 be64_to_cpu(crq->query_capability.number);
2685 if (adapter->vlan_header_insertion)
2686 netdev->features |= NETIF_F_HW_VLAN_STAG_TX;
2687 netdev_dbg(netdev, "vlan_header_insertion = %lld\n",
2688 adapter->vlan_header_insertion);
2690 case MAX_TX_SG_ENTRIES:
2691 adapter->max_tx_sg_entries =
2692 be64_to_cpu(crq->query_capability.number);
2693 netdev_dbg(netdev, "max_tx_sg_entries = %lld\n",
2694 adapter->max_tx_sg_entries);
2696 case RX_SG_SUPPORTED:
2697 adapter->rx_sg_supported =
2698 be64_to_cpu(crq->query_capability.number);
2699 netdev_dbg(netdev, "rx_sg_supported = %lld\n",
2700 adapter->rx_sg_supported);
2702 case OPT_TX_COMP_SUB_QUEUES:
2703 adapter->opt_tx_comp_sub_queues =
2704 be64_to_cpu(crq->query_capability.number);
2705 netdev_dbg(netdev, "opt_tx_comp_sub_queues = %lld\n",
2706 adapter->opt_tx_comp_sub_queues);
2708 case OPT_RX_COMP_QUEUES:
2709 adapter->opt_rx_comp_queues =
2710 be64_to_cpu(crq->query_capability.number);
2711 netdev_dbg(netdev, "opt_rx_comp_queues = %lld\n",
2712 adapter->opt_rx_comp_queues);
2714 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q:
2715 adapter->opt_rx_bufadd_q_per_rx_comp_q =
2716 be64_to_cpu(crq->query_capability.number);
2717 netdev_dbg(netdev, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
2718 adapter->opt_rx_bufadd_q_per_rx_comp_q);
2720 case OPT_TX_ENTRIES_PER_SUBCRQ:
2721 adapter->opt_tx_entries_per_subcrq =
2722 be64_to_cpu(crq->query_capability.number);
2723 netdev_dbg(netdev, "opt_tx_entries_per_subcrq = %lld\n",
2724 adapter->opt_tx_entries_per_subcrq);
2726 case OPT_RXBA_ENTRIES_PER_SUBCRQ:
2727 adapter->opt_rxba_entries_per_subcrq =
2728 be64_to_cpu(crq->query_capability.number);
2729 netdev_dbg(netdev, "opt_rxba_entries_per_subcrq = %lld\n",
2730 adapter->opt_rxba_entries_per_subcrq);
2732 case TX_RX_DESC_REQ:
2733 adapter->tx_rx_desc_req = crq->query_capability.number;
2734 netdev_dbg(netdev, "tx_rx_desc_req = %llx\n",
2735 adapter->tx_rx_desc_req);
2739 netdev_err(netdev, "Got invalid cap rsp %d\n",
2740 crq->query_capability.capability);
2744 if (atomic_read(&adapter->running_cap_crqs) == 0) {
2745 adapter->wait_capability = false;
2746 init_sub_crqs(adapter, 0);
2747 /* We're done querying the capabilities, initialize sub-crqs */
2751 static void handle_control_ras_rsp(union ibmvnic_crq *crq,
2752 struct ibmvnic_adapter *adapter)
2754 u8 correlator = crq->control_ras_rsp.correlator;
2755 struct device *dev = &adapter->vdev->dev;
2759 if (crq->control_ras_rsp.rc.code) {
2760 dev_warn(dev, "Control ras failed rc=%d\n",
2761 crq->control_ras_rsp.rc.code);
2765 for (i = 0; i < adapter->ras_comp_num; i++) {
2766 if (adapter->ras_comps[i].correlator == correlator) {
2773 dev_warn(dev, "Correlator not found on control_ras_rsp\n");
2777 switch (crq->control_ras_rsp.op) {
2778 case IBMVNIC_TRACE_LEVEL:
2779 adapter->ras_comps[i].trace_level = crq->control_ras.level;
2781 case IBMVNIC_ERROR_LEVEL:
2782 adapter->ras_comps[i].error_check_level =
2783 crq->control_ras.level;
2785 case IBMVNIC_TRACE_PAUSE:
2786 adapter->ras_comp_int[i].paused = 1;
2788 case IBMVNIC_TRACE_RESUME:
2789 adapter->ras_comp_int[i].paused = 0;
2791 case IBMVNIC_TRACE_ON:
2792 adapter->ras_comps[i].trace_on = 1;
2794 case IBMVNIC_TRACE_OFF:
2795 adapter->ras_comps[i].trace_on = 0;
2797 case IBMVNIC_CHG_TRACE_BUFF_SZ:
2798 /* trace_buff_sz is 3 bytes, stuff it into an int */
2799 ((u8 *)(&adapter->ras_comps[i].trace_buff_size))[0] = 0;
2800 ((u8 *)(&adapter->ras_comps[i].trace_buff_size))[1] =
2801 crq->control_ras_rsp.trace_buff_sz[0];
2802 ((u8 *)(&adapter->ras_comps[i].trace_buff_size))[2] =
2803 crq->control_ras_rsp.trace_buff_sz[1];
2804 ((u8 *)(&adapter->ras_comps[i].trace_buff_size))[3] =
2805 crq->control_ras_rsp.trace_buff_sz[2];
2808 dev_err(dev, "invalid op %d on control_ras_rsp",
2809 crq->control_ras_rsp.op);
2813 static ssize_t trace_read(struct file *file, char __user *user_buf, size_t len,
2816 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2817 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2818 struct device *dev = &adapter->vdev->dev;
2819 struct ibmvnic_fw_trace_entry *trace;
2820 int num = ras_comp_int->num;
2821 union ibmvnic_crq crq;
2822 dma_addr_t trace_tok;
2824 if (*ppos >= be32_to_cpu(adapter->ras_comps[num].trace_buff_size))
2828 dma_alloc_coherent(dev,
2829 be32_to_cpu(adapter->ras_comps[num].
2830 trace_buff_size), &trace_tok,
2833 dev_err(dev, "Couldn't alloc trace buffer\n");
2837 memset(&crq, 0, sizeof(crq));
2838 crq.collect_fw_trace.first = IBMVNIC_CRQ_CMD;
2839 crq.collect_fw_trace.cmd = COLLECT_FW_TRACE;
2840 crq.collect_fw_trace.correlator = adapter->ras_comps[num].correlator;
2841 crq.collect_fw_trace.ioba = cpu_to_be32(trace_tok);
2842 crq.collect_fw_trace.len = adapter->ras_comps[num].trace_buff_size;
2844 init_completion(&adapter->fw_done);
2845 ibmvnic_send_crq(adapter, &crq);
2846 wait_for_completion(&adapter->fw_done);
2848 if (*ppos + len > be32_to_cpu(adapter->ras_comps[num].trace_buff_size))
2850 be32_to_cpu(adapter->ras_comps[num].trace_buff_size) -
2853 copy_to_user(user_buf, &((u8 *)trace)[*ppos], len);
2855 dma_free_coherent(dev,
2856 be32_to_cpu(adapter->ras_comps[num].trace_buff_size),
2862 static const struct file_operations trace_ops = {
2863 .owner = THIS_MODULE,
2864 .open = simple_open,
2868 static ssize_t paused_read(struct file *file, char __user *user_buf, size_t len,
2871 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2872 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2873 int num = ras_comp_int->num;
2874 char buff[5]; /* 1 or 0 plus \n and \0 */
2877 size = sprintf(buff, "%d\n", adapter->ras_comp_int[num].paused);
2882 copy_to_user(user_buf, buff, size);
2887 static ssize_t paused_write(struct file *file, const char __user *user_buf,
2888 size_t len, loff_t *ppos)
2890 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2891 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2892 int num = ras_comp_int->num;
2893 union ibmvnic_crq crq;
2895 char buff[9]; /* decimal max int plus \n and \0 */
2897 copy_from_user(buff, user_buf, sizeof(buff));
2898 val = kstrtoul(buff, 10, NULL);
2900 adapter->ras_comp_int[num].paused = val ? 1 : 0;
2902 memset(&crq, 0, sizeof(crq));
2903 crq.control_ras.first = IBMVNIC_CRQ_CMD;
2904 crq.control_ras.cmd = CONTROL_RAS;
2905 crq.control_ras.correlator = adapter->ras_comps[num].correlator;
2906 crq.control_ras.op = val ? IBMVNIC_TRACE_PAUSE : IBMVNIC_TRACE_RESUME;
2907 ibmvnic_send_crq(adapter, &crq);
2912 static const struct file_operations paused_ops = {
2913 .owner = THIS_MODULE,
2914 .open = simple_open,
2915 .read = paused_read,
2916 .write = paused_write,
2919 static ssize_t tracing_read(struct file *file, char __user *user_buf,
2920 size_t len, loff_t *ppos)
2922 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2923 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2924 int num = ras_comp_int->num;
2925 char buff[5]; /* 1 or 0 plus \n and \0 */
2928 size = sprintf(buff, "%d\n", adapter->ras_comps[num].trace_on);
2933 copy_to_user(user_buf, buff, size);
2938 static ssize_t tracing_write(struct file *file, const char __user *user_buf,
2939 size_t len, loff_t *ppos)
2941 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2942 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2943 int num = ras_comp_int->num;
2944 union ibmvnic_crq crq;
2946 char buff[9]; /* decimal max int plus \n and \0 */
2948 copy_from_user(buff, user_buf, sizeof(buff));
2949 val = kstrtoul(buff, 10, NULL);
2951 memset(&crq, 0, sizeof(crq));
2952 crq.control_ras.first = IBMVNIC_CRQ_CMD;
2953 crq.control_ras.cmd = CONTROL_RAS;
2954 crq.control_ras.correlator = adapter->ras_comps[num].correlator;
2955 crq.control_ras.op = val ? IBMVNIC_TRACE_ON : IBMVNIC_TRACE_OFF;
2960 static const struct file_operations tracing_ops = {
2961 .owner = THIS_MODULE,
2962 .open = simple_open,
2963 .read = tracing_read,
2964 .write = tracing_write,
2967 static ssize_t error_level_read(struct file *file, char __user *user_buf,
2968 size_t len, loff_t *ppos)
2970 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2971 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2972 int num = ras_comp_int->num;
2973 char buff[5]; /* decimal max char plus \n and \0 */
2976 size = sprintf(buff, "%d\n", adapter->ras_comps[num].error_check_level);
2981 copy_to_user(user_buf, buff, size);
2986 static ssize_t error_level_write(struct file *file, const char __user *user_buf,
2987 size_t len, loff_t *ppos)
2989 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
2990 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
2991 int num = ras_comp_int->num;
2992 union ibmvnic_crq crq;
2994 char buff[9]; /* decimal max int plus \n and \0 */
2996 copy_from_user(buff, user_buf, sizeof(buff));
2997 val = kstrtoul(buff, 10, NULL);
3002 memset(&crq, 0, sizeof(crq));
3003 crq.control_ras.first = IBMVNIC_CRQ_CMD;
3004 crq.control_ras.cmd = CONTROL_RAS;
3005 crq.control_ras.correlator = adapter->ras_comps[num].correlator;
3006 crq.control_ras.op = IBMVNIC_ERROR_LEVEL;
3007 crq.control_ras.level = val;
3008 ibmvnic_send_crq(adapter, &crq);
3013 static const struct file_operations error_level_ops = {
3014 .owner = THIS_MODULE,
3015 .open = simple_open,
3016 .read = error_level_read,
3017 .write = error_level_write,
3020 static ssize_t trace_level_read(struct file *file, char __user *user_buf,
3021 size_t len, loff_t *ppos)
3023 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
3024 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
3025 int num = ras_comp_int->num;
3026 char buff[5]; /* decimal max char plus \n and \0 */
3029 size = sprintf(buff, "%d\n", adapter->ras_comps[num].trace_level);
3033 copy_to_user(user_buf, buff, size);
3038 static ssize_t trace_level_write(struct file *file, const char __user *user_buf,
3039 size_t len, loff_t *ppos)
3041 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
3042 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
3043 union ibmvnic_crq crq;
3045 char buff[9]; /* decimal max int plus \n and \0 */
3047 copy_from_user(buff, user_buf, sizeof(buff));
3048 val = kstrtoul(buff, 10, NULL);
3052 memset(&crq, 0, sizeof(crq));
3053 crq.control_ras.first = IBMVNIC_CRQ_CMD;
3054 crq.control_ras.cmd = CONTROL_RAS;
3055 crq.control_ras.correlator =
3056 adapter->ras_comps[ras_comp_int->num].correlator;
3057 crq.control_ras.op = IBMVNIC_TRACE_LEVEL;
3058 crq.control_ras.level = val;
3059 ibmvnic_send_crq(adapter, &crq);
3064 static const struct file_operations trace_level_ops = {
3065 .owner = THIS_MODULE,
3066 .open = simple_open,
3067 .read = trace_level_read,
3068 .write = trace_level_write,
3071 static ssize_t trace_buff_size_read(struct file *file, char __user *user_buf,
3072 size_t len, loff_t *ppos)
3074 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
3075 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
3076 int num = ras_comp_int->num;
3077 char buff[9]; /* decimal max int plus \n and \0 */
3080 size = sprintf(buff, "%d\n", adapter->ras_comps[num].trace_buff_size);
3084 copy_to_user(user_buf, buff, size);
3089 static ssize_t trace_buff_size_write(struct file *file,
3090 const char __user *user_buf, size_t len,
3093 struct ibmvnic_fw_comp_internal *ras_comp_int = file->private_data;
3094 struct ibmvnic_adapter *adapter = ras_comp_int->adapter;
3095 union ibmvnic_crq crq;
3097 char buff[9]; /* decimal max int plus \n and \0 */
3099 copy_from_user(buff, user_buf, sizeof(buff));
3100 val = kstrtoul(buff, 10, NULL);
3102 memset(&crq, 0, sizeof(crq));
3103 crq.control_ras.first = IBMVNIC_CRQ_CMD;
3104 crq.control_ras.cmd = CONTROL_RAS;
3105 crq.control_ras.correlator =
3106 adapter->ras_comps[ras_comp_int->num].correlator;
3107 crq.control_ras.op = IBMVNIC_CHG_TRACE_BUFF_SZ;
3108 /* trace_buff_sz is 3 bytes, stuff an int into it */
3109 crq.control_ras.trace_buff_sz[0] = ((u8 *)(&val))[5];
3110 crq.control_ras.trace_buff_sz[1] = ((u8 *)(&val))[6];
3111 crq.control_ras.trace_buff_sz[2] = ((u8 *)(&val))[7];
3112 ibmvnic_send_crq(adapter, &crq);
3117 static const struct file_operations trace_size_ops = {
3118 .owner = THIS_MODULE,
3119 .open = simple_open,
3120 .read = trace_buff_size_read,
3121 .write = trace_buff_size_write,
3124 static void handle_request_ras_comps_rsp(union ibmvnic_crq *crq,
3125 struct ibmvnic_adapter *adapter)
3127 struct device *dev = &adapter->vdev->dev;
3128 struct dentry *dir_ent;
3132 debugfs_remove_recursive(adapter->ras_comps_ent);
3134 adapter->ras_comps_ent = debugfs_create_dir("ras_comps",
3135 adapter->debugfs_dir);
3136 if (!adapter->ras_comps_ent || IS_ERR(adapter->ras_comps_ent)) {
3137 dev_info(dev, "debugfs create ras_comps dir failed\n");
3141 for (i = 0; i < adapter->ras_comp_num; i++) {
3142 dir_ent = debugfs_create_dir(adapter->ras_comps[i].name,
3143 adapter->ras_comps_ent);
3144 if (!dir_ent || IS_ERR(dir_ent)) {
3145 dev_info(dev, "debugfs create %s dir failed\n",
3146 adapter->ras_comps[i].name);
3150 adapter->ras_comp_int[i].adapter = adapter;
3151 adapter->ras_comp_int[i].num = i;
3152 adapter->ras_comp_int[i].desc_blob.data =
3153 &adapter->ras_comps[i].description;
3154 adapter->ras_comp_int[i].desc_blob.size =
3155 sizeof(adapter->ras_comps[i].description);
3157 /* Don't need to remember the dentry's because the debugfs dir
3158 * gets removed recursively
3160 ent = debugfs_create_blob("description", S_IRUGO, dir_ent,
3161 &adapter->ras_comp_int[i].desc_blob);
3162 ent = debugfs_create_file("trace_buf_size", S_IRUGO | S_IWUSR,
3163 dir_ent, &adapter->ras_comp_int[i],
3165 ent = debugfs_create_file("trace_level",
3167 (adapter->ras_comps[i].trace_level !=
3168 0xFF ? S_IWUSR : 0),
3169 dir_ent, &adapter->ras_comp_int[i],
3171 ent = debugfs_create_file("error_level",
3174 ras_comps[i].error_check_level !=
3175 0xFF ? S_IWUSR : 0),
3176 dir_ent, &adapter->ras_comp_int[i],
3178 ent = debugfs_create_file("tracing", S_IRUGO | S_IWUSR,
3179 dir_ent, &adapter->ras_comp_int[i],
3181 ent = debugfs_create_file("paused", S_IRUGO | S_IWUSR,
3182 dir_ent, &adapter->ras_comp_int[i],
3184 ent = debugfs_create_file("trace", S_IRUGO, dir_ent,
3185 &adapter->ras_comp_int[i],
3190 static void handle_request_ras_comp_num_rsp(union ibmvnic_crq *crq,
3191 struct ibmvnic_adapter *adapter)
3193 int len = adapter->ras_comp_num * sizeof(struct ibmvnic_fw_component);
3194 struct device *dev = &adapter->vdev->dev;
3195 union ibmvnic_crq newcrq;
3197 adapter->ras_comps = dma_alloc_coherent(dev, len,
3198 &adapter->ras_comps_tok,
3200 if (!adapter->ras_comps) {
3201 if (!firmware_has_feature(FW_FEATURE_CMO))
3202 dev_err(dev, "Couldn't alloc fw comps buffer\n");
3206 adapter->ras_comp_int = kmalloc(adapter->ras_comp_num *
3207 sizeof(struct ibmvnic_fw_comp_internal),
3209 if (!adapter->ras_comp_int)
3210 dma_free_coherent(dev, len, adapter->ras_comps,
3211 adapter->ras_comps_tok);
3213 memset(&newcrq, 0, sizeof(newcrq));
3214 newcrq.request_ras_comps.first = IBMVNIC_CRQ_CMD;
3215 newcrq.request_ras_comps.cmd = REQUEST_RAS_COMPS;
3216 newcrq.request_ras_comps.ioba = cpu_to_be32(adapter->ras_comps_tok);
3217 newcrq.request_ras_comps.len = cpu_to_be32(len);
3218 ibmvnic_send_crq(adapter, &newcrq);
3221 static void ibmvnic_free_inflight(struct ibmvnic_adapter *adapter)
3223 struct ibmvnic_inflight_cmd *inflight_cmd, *tmp1;
3224 struct device *dev = &adapter->vdev->dev;
3225 struct ibmvnic_error_buff *error_buff, *tmp2;
3226 unsigned long flags;
3227 unsigned long flags2;
3229 spin_lock_irqsave(&adapter->inflight_lock, flags);
3230 list_for_each_entry_safe(inflight_cmd, tmp1, &adapter->inflight, list) {
3231 switch (inflight_cmd->crq.generic.cmd) {
3233 dma_unmap_single(dev, adapter->login_buf_token,
3234 adapter->login_buf_sz,
3236 dma_unmap_single(dev, adapter->login_rsp_buf_token,
3237 adapter->login_rsp_buf_sz,
3239 kfree(adapter->login_rsp_buf);
3240 kfree(adapter->login_buf);
3243 complete(&adapter->fw_done);
3245 case REQUEST_ERROR_INFO:
3246 spin_lock_irqsave(&adapter->error_list_lock, flags2);
3247 list_for_each_entry_safe(error_buff, tmp2,
3248 &adapter->errors, list) {
3249 dma_unmap_single(dev, error_buff->dma,
3252 kfree(error_buff->buff);
3253 list_del(&error_buff->list);
3256 spin_unlock_irqrestore(&adapter->error_list_lock,
3260 list_del(&inflight_cmd->list);
3261 kfree(inflight_cmd);
3263 spin_unlock_irqrestore(&adapter->inflight_lock, flags);
3266 static void ibmvnic_xport_event(struct work_struct *work)
3268 struct ibmvnic_adapter *adapter = container_of(work,
3269 struct ibmvnic_adapter,
3271 struct device *dev = &adapter->vdev->dev;
3274 ibmvnic_free_inflight(adapter);
3275 release_sub_crqs(adapter);
3276 if (adapter->migrated) {
3277 rc = ibmvnic_reenable_crq_queue(adapter);
3279 dev_err(dev, "Error after enable rc=%ld\n", rc);
3280 adapter->migrated = false;
3281 rc = ibmvnic_send_crq_init(adapter);
3283 dev_err(dev, "Error sending init rc=%ld\n", rc);
3287 static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3288 struct ibmvnic_adapter *adapter)
3290 struct ibmvnic_generic_crq *gen_crq = &crq->generic;
3291 struct net_device *netdev = adapter->netdev;
3292 struct device *dev = &adapter->vdev->dev;
3295 netdev_dbg(netdev, "Handling CRQ: %016lx %016lx\n",
3296 ((unsigned long int *)crq)[0],
3297 ((unsigned long int *)crq)[1]);
3298 switch (gen_crq->first) {
3299 case IBMVNIC_CRQ_INIT_RSP:
3300 switch (gen_crq->cmd) {
3301 case IBMVNIC_CRQ_INIT:
3302 dev_info(dev, "Partner initialized\n");
3303 /* Send back a response */
3304 rc = ibmvnic_send_crq_init_complete(adapter);
3306 schedule_work(&adapter->vnic_crq_init);
3308 dev_err(dev, "Can't send initrsp rc=%ld\n", rc);
3310 case IBMVNIC_CRQ_INIT_COMPLETE:
3311 dev_info(dev, "Partner initialization complete\n");
3312 send_version_xchg(adapter);
3315 dev_err(dev, "Unknown crq cmd: %d\n", gen_crq->cmd);
3318 case IBMVNIC_CRQ_XPORT_EVENT:
3319 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
3320 dev_info(dev, "Re-enabling adapter\n");
3321 adapter->migrated = true;
3322 schedule_work(&adapter->ibmvnic_xport);
3323 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
3324 dev_info(dev, "Backing device failover detected\n");
3325 netif_carrier_off(netdev);
3326 adapter->failover = true;
3328 /* The adapter lost the connection */
3329 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
3331 schedule_work(&adapter->ibmvnic_xport);
3334 case IBMVNIC_CRQ_CMD_RSP:
3337 dev_err(dev, "Got an invalid msg type 0x%02x\n",
3342 switch (gen_crq->cmd) {
3343 case VERSION_EXCHANGE_RSP:
3344 rc = crq->version_exchange_rsp.rc.code;
3346 dev_err(dev, "Error %ld in VERSION_EXCHG_RSP\n", rc);
3349 dev_info(dev, "Partner protocol version is %d\n",
3350 crq->version_exchange_rsp.version);
3351 if (be16_to_cpu(crq->version_exchange_rsp.version) <
3354 be16_to_cpu(crq->version_exchange_rsp.version);
3355 send_cap_queries(adapter);
3357 case QUERY_CAPABILITY_RSP:
3358 handle_query_cap_rsp(crq, adapter);
3361 handle_query_map_rsp(crq, adapter);
3363 case REQUEST_MAP_RSP:
3364 handle_request_map_rsp(crq, adapter);
3366 case REQUEST_UNMAP_RSP:
3367 handle_request_unmap_rsp(crq, adapter);
3369 case REQUEST_CAPABILITY_RSP:
3370 handle_request_cap_rsp(crq, adapter);
3373 netdev_dbg(netdev, "Got Login Response\n");
3374 handle_login_rsp(crq, adapter);
3376 case LOGICAL_LINK_STATE_RSP:
3377 netdev_dbg(netdev, "Got Logical Link State Response\n");
3378 adapter->logical_link_state =
3379 crq->logical_link_state_rsp.link_state;
3381 case LINK_STATE_INDICATION:
3382 netdev_dbg(netdev, "Got Logical Link State Indication\n");
3383 adapter->phys_link_state =
3384 crq->link_state_indication.phys_link_state;
3385 adapter->logical_link_state =
3386 crq->link_state_indication.logical_link_state;
3388 case CHANGE_MAC_ADDR_RSP:
3389 netdev_dbg(netdev, "Got MAC address change Response\n");
3390 handle_change_mac_rsp(crq, adapter);
3392 case ERROR_INDICATION:
3393 netdev_dbg(netdev, "Got Error Indication\n");
3394 handle_error_indication(crq, adapter);
3396 case REQUEST_ERROR_RSP:
3397 netdev_dbg(netdev, "Got Error Detail Response\n");
3398 handle_error_info_rsp(crq, adapter);
3400 case REQUEST_STATISTICS_RSP:
3401 netdev_dbg(netdev, "Got Statistics Response\n");
3402 complete(&adapter->stats_done);
3404 case REQUEST_DUMP_SIZE_RSP:
3405 netdev_dbg(netdev, "Got Request Dump Size Response\n");
3406 handle_dump_size_rsp(crq, adapter);
3408 case REQUEST_DUMP_RSP:
3409 netdev_dbg(netdev, "Got Request Dump Response\n");
3410 complete(&adapter->fw_done);
3412 case QUERY_IP_OFFLOAD_RSP:
3413 netdev_dbg(netdev, "Got Query IP offload Response\n");
3414 handle_query_ip_offload_rsp(adapter);
3416 case MULTICAST_CTRL_RSP:
3417 netdev_dbg(netdev, "Got multicast control Response\n");
3419 case CONTROL_IP_OFFLOAD_RSP:
3420 netdev_dbg(netdev, "Got Control IP offload Response\n");
3421 dma_unmap_single(dev, adapter->ip_offload_ctrl_tok,
3422 sizeof(adapter->ip_offload_ctrl),
3424 /* We're done with the queries, perform the login */
3425 send_login(adapter);
3427 case REQUEST_RAS_COMP_NUM_RSP:
3428 netdev_dbg(netdev, "Got Request RAS Comp Num Response\n");
3429 if (crq->request_ras_comp_num_rsp.rc.code == 10) {
3430 netdev_dbg(netdev, "Request RAS Comp Num not supported\n");
3433 adapter->ras_comp_num =
3434 be32_to_cpu(crq->request_ras_comp_num_rsp.num_components);
3435 handle_request_ras_comp_num_rsp(crq, adapter);
3437 case REQUEST_RAS_COMPS_RSP:
3438 netdev_dbg(netdev, "Got Request RAS Comps Response\n");
3439 handle_request_ras_comps_rsp(crq, adapter);
3441 case CONTROL_RAS_RSP:
3442 netdev_dbg(netdev, "Got Control RAS Response\n");
3443 handle_control_ras_rsp(crq, adapter);
3445 case COLLECT_FW_TRACE_RSP:
3446 netdev_dbg(netdev, "Got Collect firmware trace Response\n");
3447 complete(&adapter->fw_done);
3450 netdev_err(netdev, "Got an invalid cmd type 0x%02x\n",
3455 static irqreturn_t ibmvnic_interrupt(int irq, void *instance)
3457 struct ibmvnic_adapter *adapter = instance;
3458 unsigned long flags;
3460 spin_lock_irqsave(&adapter->crq.lock, flags);
3461 vio_disable_interrupts(adapter->vdev);
3462 tasklet_schedule(&adapter->tasklet);
3463 spin_unlock_irqrestore(&adapter->crq.lock, flags);
3467 static void ibmvnic_tasklet(void *data)
3469 struct ibmvnic_adapter *adapter = data;
3470 struct ibmvnic_crq_queue *queue = &adapter->crq;
3471 struct vio_dev *vdev = adapter->vdev;
3472 union ibmvnic_crq *crq;
3473 unsigned long flags;
3476 spin_lock_irqsave(&queue->lock, flags);
3477 vio_disable_interrupts(vdev);
3479 /* Pull all the valid messages off the CRQ */
3480 while ((crq = ibmvnic_next_crq(adapter)) != NULL) {
3481 ibmvnic_handle_crq(crq, adapter);
3482 crq->generic.first = 0;
3484 vio_enable_interrupts(vdev);
3485 crq = ibmvnic_next_crq(adapter);
3487 vio_disable_interrupts(vdev);
3488 ibmvnic_handle_crq(crq, adapter);
3489 crq->generic.first = 0;
3491 /* remain in tasklet until all
3492 * capabilities responses are received
3494 if (!adapter->wait_capability)
3498 /* if capabilities CRQ's were sent in this tasklet, the following
3499 * tasklet must wait until all responses are received
3501 if (atomic_read(&adapter->running_cap_crqs) != 0)
3502 adapter->wait_capability = true;
3503 spin_unlock_irqrestore(&queue->lock, flags);
3506 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter *adapter)
3508 struct vio_dev *vdev = adapter->vdev;
3512 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
3513 } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
3516 dev_err(&vdev->dev, "Error enabling adapter (rc=%d)\n", rc);
3521 static int ibmvnic_reset_crq(struct ibmvnic_adapter *adapter)
3523 struct ibmvnic_crq_queue *crq = &adapter->crq;
3524 struct device *dev = &adapter->vdev->dev;
3525 struct vio_dev *vdev = adapter->vdev;
3530 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3531 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3533 /* Clean out the queue */
3534 memset(crq->msgs, 0, PAGE_SIZE);
3537 /* And re-open it again */
3538 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3539 crq->msg_token, PAGE_SIZE);
3542 /* Adapter is good, but other end is not ready */
3543 dev_warn(dev, "Partner adapter not ready\n");
3545 dev_warn(dev, "Couldn't register crq (rc=%d)\n", rc);
3550 static void ibmvnic_release_crq_queue(struct ibmvnic_adapter *adapter)
3552 struct ibmvnic_crq_queue *crq = &adapter->crq;
3553 struct vio_dev *vdev = adapter->vdev;
3556 netdev_dbg(adapter->netdev, "Releasing CRQ\n");
3557 free_irq(vdev->irq, adapter);
3558 tasklet_kill(&adapter->tasklet);
3560 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3561 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3563 dma_unmap_single(&vdev->dev, crq->msg_token, PAGE_SIZE,
3565 free_page((unsigned long)crq->msgs);
3568 static int ibmvnic_init_crq_queue(struct ibmvnic_adapter *adapter)
3570 struct ibmvnic_crq_queue *crq = &adapter->crq;
3571 struct device *dev = &adapter->vdev->dev;
3572 struct vio_dev *vdev = adapter->vdev;
3573 int rc, retrc = -ENOMEM;
3575 crq->msgs = (union ibmvnic_crq *)get_zeroed_page(GFP_KERNEL);
3576 /* Should we allocate more than one page? */
3581 crq->size = PAGE_SIZE / sizeof(*crq->msgs);
3582 crq->msg_token = dma_map_single(dev, crq->msgs, PAGE_SIZE,
3584 if (dma_mapping_error(dev, crq->msg_token))
3587 rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
3588 crq->msg_token, PAGE_SIZE);
3590 if (rc == H_RESOURCE)
3591 /* maybe kexecing and resource is busy. try a reset */
3592 rc = ibmvnic_reset_crq(adapter);
3595 if (rc == H_CLOSED) {
3596 dev_warn(dev, "Partner adapter not ready\n");
3598 dev_warn(dev, "Error %d opening adapter\n", rc);
3599 goto reg_crq_failed;
3604 tasklet_init(&adapter->tasklet, (void *)ibmvnic_tasklet,
3605 (unsigned long)adapter);
3607 netdev_dbg(adapter->netdev, "registering irq 0x%x\n", vdev->irq);
3608 rc = request_irq(vdev->irq, ibmvnic_interrupt, 0, IBMVNIC_NAME,
3611 dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n",
3613 goto req_irq_failed;
3616 rc = vio_enable_interrupts(vdev);
3618 dev_err(dev, "Error %d enabling interrupts\n", rc);
3619 goto req_irq_failed;
3623 spin_lock_init(&crq->lock);
3628 tasklet_kill(&adapter->tasklet);
3630 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
3631 } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
3633 dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
3635 free_page((unsigned long)crq->msgs);
3639 /* debugfs for dump */
3640 static int ibmvnic_dump_show(struct seq_file *seq, void *v)
3642 struct net_device *netdev = seq->private;
3643 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3644 struct device *dev = &adapter->vdev->dev;
3645 union ibmvnic_crq crq;
3647 memset(&crq, 0, sizeof(crq));
3648 crq.request_dump_size.first = IBMVNIC_CRQ_CMD;
3649 crq.request_dump_size.cmd = REQUEST_DUMP_SIZE;
3651 init_completion(&adapter->fw_done);
3652 ibmvnic_send_crq(adapter, &crq);
3653 wait_for_completion(&adapter->fw_done);
3655 seq_write(seq, adapter->dump_data, adapter->dump_data_size);
3657 dma_unmap_single(dev, adapter->dump_data_token, adapter->dump_data_size,
3660 kfree(adapter->dump_data);
3665 static int ibmvnic_dump_open(struct inode *inode, struct file *file)
3667 return single_open(file, ibmvnic_dump_show, inode->i_private);
3670 static const struct file_operations ibmvnic_dump_ops = {
3671 .owner = THIS_MODULE,
3672 .open = ibmvnic_dump_open,
3674 .llseek = seq_lseek,
3675 .release = single_release,
3678 static void handle_crq_init_rsp(struct work_struct *work)
3680 struct ibmvnic_adapter *adapter = container_of(work,
3681 struct ibmvnic_adapter,
3683 struct device *dev = &adapter->vdev->dev;
3684 struct net_device *netdev = adapter->netdev;
3685 unsigned long timeout = msecs_to_jiffies(30000);
3686 bool restart = false;
3689 if (adapter->failover) {
3690 release_sub_crqs(adapter);
3691 if (netif_running(netdev)) {
3692 netif_tx_disable(netdev);
3693 ibmvnic_close(netdev);
3698 reinit_completion(&adapter->init_done);
3699 send_version_xchg(adapter);
3700 if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
3701 dev_err(dev, "Passive init timeout\n");
3706 if (adapter->renegotiate) {
3707 adapter->renegotiate = false;
3708 release_sub_crqs_no_irqs(adapter);
3710 reinit_completion(&adapter->init_done);
3711 send_cap_queries(adapter);
3712 if (!wait_for_completion_timeout(&adapter->init_done,
3714 dev_err(dev, "Passive init timeout\n");
3718 } while (adapter->renegotiate);
3719 rc = init_sub_crq_irqs(adapter);
3724 netdev->real_num_tx_queues = adapter->req_tx_queues;
3725 netdev->mtu = adapter->req_mtu - ETH_HLEN;
3727 if (adapter->failover) {
3728 adapter->failover = false;
3730 rc = ibmvnic_open(netdev);
3732 goto restart_failed;
3734 netif_carrier_on(netdev);
3738 rc = register_netdev(netdev);
3741 "failed to register netdev rc=%d\n", rc);
3742 goto register_failed;
3744 dev_info(dev, "ibmvnic registered\n");
3749 dev_err(dev, "Failed to restart ibmvnic, rc=%d\n", rc);
3751 release_sub_crqs(adapter);
3753 dev_err(dev, "Passive initialization was not successful\n");
3756 static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3758 unsigned long timeout = msecs_to_jiffies(30000);
3759 struct ibmvnic_adapter *adapter;
3760 struct net_device *netdev;
3761 unsigned char *mac_addr_p;
3763 char buf[17]; /* debugfs name buf */
3766 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
3769 mac_addr_p = (unsigned char *)vio_get_attribute(dev,
3770 VETH_MAC_ADDR, NULL);
3773 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3774 __FILE__, __LINE__);
3778 netdev = alloc_etherdev_mq(sizeof(struct ibmvnic_adapter),
3779 IBMVNIC_MAX_TX_QUEUES);
3783 adapter = netdev_priv(netdev);
3784 dev_set_drvdata(&dev->dev, netdev);
3785 adapter->vdev = dev;
3786 adapter->netdev = netdev;
3787 adapter->failover = false;
3789 ether_addr_copy(adapter->mac_addr, mac_addr_p);
3790 ether_addr_copy(netdev->dev_addr, adapter->mac_addr);
3791 netdev->irq = dev->irq;
3792 netdev->netdev_ops = &ibmvnic_netdev_ops;
3793 netdev->ethtool_ops = &ibmvnic_ethtool_ops;
3794 SET_NETDEV_DEV(netdev, &dev->dev);
3796 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp);
3797 INIT_WORK(&adapter->ibmvnic_xport, ibmvnic_xport_event);
3799 spin_lock_init(&adapter->stats_lock);
3801 rc = ibmvnic_init_crq_queue(adapter);
3803 dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n", rc);
3807 INIT_LIST_HEAD(&adapter->errors);
3808 INIT_LIST_HEAD(&adapter->inflight);
3809 spin_lock_init(&adapter->error_list_lock);
3810 spin_lock_init(&adapter->inflight_lock);
3812 adapter->stats_token = dma_map_single(&dev->dev, &adapter->stats,
3813 sizeof(struct ibmvnic_statistics),
3815 if (dma_mapping_error(&dev->dev, adapter->stats_token)) {
3816 if (!firmware_has_feature(FW_FEATURE_CMO))
3817 dev_err(&dev->dev, "Couldn't map stats buffer\n");
3822 snprintf(buf, sizeof(buf), "ibmvnic_%x", dev->unit_address);
3823 ent = debugfs_create_dir(buf, NULL);
3824 if (!ent || IS_ERR(ent)) {
3825 dev_info(&dev->dev, "debugfs create directory failed\n");
3826 adapter->debugfs_dir = NULL;
3828 adapter->debugfs_dir = ent;
3829 ent = debugfs_create_file("dump", S_IRUGO, adapter->debugfs_dir,
3830 netdev, &ibmvnic_dump_ops);
3831 if (!ent || IS_ERR(ent)) {
3833 "debugfs create dump file failed\n");
3834 adapter->debugfs_dump = NULL;
3836 adapter->debugfs_dump = ent;
3840 init_completion(&adapter->init_done);
3841 ibmvnic_send_crq_init(adapter);
3842 if (!wait_for_completion_timeout(&adapter->init_done, timeout))
3846 if (adapter->renegotiate) {
3847 adapter->renegotiate = false;
3848 release_sub_crqs_no_irqs(adapter);
3850 reinit_completion(&adapter->init_done);
3851 send_cap_queries(adapter);
3852 if (!wait_for_completion_timeout(&adapter->init_done,
3856 } while (adapter->renegotiate);
3858 rc = init_sub_crq_irqs(adapter);
3860 dev_err(&dev->dev, "failed to initialize sub crq irqs\n");
3864 netdev->real_num_tx_queues = adapter->req_tx_queues;
3865 netdev->mtu = adapter->req_mtu - ETH_HLEN;
3867 rc = register_netdev(netdev);
3869 dev_err(&dev->dev, "failed to register netdev rc=%d\n", rc);
3872 dev_info(&dev->dev, "ibmvnic registered\n");
3877 release_sub_crqs(adapter);
3879 if (adapter->debugfs_dir && !IS_ERR(adapter->debugfs_dir))
3880 debugfs_remove_recursive(adapter->debugfs_dir);
3882 ibmvnic_release_crq_queue(adapter);
3884 free_netdev(netdev);
3888 static int ibmvnic_remove(struct vio_dev *dev)
3890 struct net_device *netdev = dev_get_drvdata(&dev->dev);
3891 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3893 unregister_netdev(netdev);
3895 release_sub_crqs(adapter);
3897 ibmvnic_release_crq_queue(adapter);
3899 if (adapter->debugfs_dir && !IS_ERR(adapter->debugfs_dir))
3900 debugfs_remove_recursive(adapter->debugfs_dir);
3902 dma_unmap_single(&dev->dev, adapter->stats_token,
3903 sizeof(struct ibmvnic_statistics), DMA_FROM_DEVICE);
3905 if (adapter->ras_comps)
3906 dma_free_coherent(&dev->dev,
3907 adapter->ras_comp_num *
3908 sizeof(struct ibmvnic_fw_component),
3909 adapter->ras_comps, adapter->ras_comps_tok);
3911 kfree(adapter->ras_comp_int);
3913 free_netdev(netdev);
3914 dev_set_drvdata(&dev->dev, NULL);
3919 static unsigned long ibmvnic_get_desired_dma(struct vio_dev *vdev)
3921 struct net_device *netdev = dev_get_drvdata(&vdev->dev);
3922 struct ibmvnic_adapter *adapter;
3923 struct iommu_table *tbl;
3924 unsigned long ret = 0;
3927 tbl = get_iommu_table_base(&vdev->dev);
3929 /* netdev inits at probe time along with the structures we need below*/
3931 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT, tbl);
3933 adapter = netdev_priv(netdev);
3935 ret += PAGE_SIZE; /* the crq message queue */
3936 ret += adapter->bounce_buffer_size;
3937 ret += IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics), tbl);
3939 for (i = 0; i < adapter->req_tx_queues + adapter->req_rx_queues; i++)
3940 ret += 4 * PAGE_SIZE; /* the scrq message queue */
3942 for (i = 0; i < be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
3944 ret += adapter->rx_pool[i].size *
3945 IOMMU_PAGE_ALIGN(adapter->rx_pool[i].buff_size, tbl);
3950 static int ibmvnic_resume(struct device *dev)
3952 struct net_device *netdev = dev_get_drvdata(dev);
3953 struct ibmvnic_adapter *adapter = netdev_priv(netdev);
3956 /* kick the interrupt handlers just in case we lost an interrupt */
3957 for (i = 0; i < adapter->req_rx_queues; i++)
3958 ibmvnic_interrupt_rx(adapter->rx_scrq[i]->irq,
3959 adapter->rx_scrq[i]);
3964 static struct vio_device_id ibmvnic_device_table[] = {
3965 {"network", "IBM,vnic"},
3968 MODULE_DEVICE_TABLE(vio, ibmvnic_device_table);
3970 static const struct dev_pm_ops ibmvnic_pm_ops = {
3971 .resume = ibmvnic_resume
3974 static struct vio_driver ibmvnic_driver = {
3975 .id_table = ibmvnic_device_table,
3976 .probe = ibmvnic_probe,
3977 .remove = ibmvnic_remove,
3978 .get_desired_dma = ibmvnic_get_desired_dma,
3979 .name = ibmvnic_driver_name,
3980 .pm = &ibmvnic_pm_ops,
3983 /* module functions */
3984 static int __init ibmvnic_module_init(void)
3986 pr_info("%s: %s %s\n", ibmvnic_driver_name, ibmvnic_driver_string,
3987 IBMVNIC_DRIVER_VERSION);
3989 return vio_register_driver(&ibmvnic_driver);
3992 static void __exit ibmvnic_module_exit(void)
3994 vio_unregister_driver(&ibmvnic_driver);
3997 module_init(ibmvnic_module_init);
3998 module_exit(ibmvnic_module_exit);