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/seq_file.h>
78 #include <linux/workqueue.h>
82 static const char ibmvnic_driver_name
[] = "ibmvnic";
83 static const char ibmvnic_driver_string
[] = "IBM System i/p Virtual NIC Driver";
85 MODULE_AUTHOR("Santiago Leon <santi_leon@yahoo.com>");
86 MODULE_DESCRIPTION("IBM System i/p Virtual NIC Driver");
87 MODULE_LICENSE("GPL");
88 MODULE_VERSION(IBMVNIC_DRIVER_VERSION
);
90 static int ibmvnic_version
= IBMVNIC_INITIAL_VERSION
;
91 static int ibmvnic_remove(struct vio_dev
*);
92 static void release_sub_crqs(struct ibmvnic_adapter
*);
93 static void release_sub_crqs_no_irqs(struct ibmvnic_adapter
*);
94 static int ibmvnic_reset_crq(struct ibmvnic_adapter
*);
95 static int ibmvnic_send_crq_init(struct ibmvnic_adapter
*);
96 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter
*);
97 static int ibmvnic_send_crq(struct ibmvnic_adapter
*, union ibmvnic_crq
*);
98 static int send_subcrq(struct ibmvnic_adapter
*adapter
, u64 remote_handle
,
99 union sub_crq
*sub_crq
);
100 static int send_subcrq_indirect(struct ibmvnic_adapter
*, u64
, u64
, u64
);
101 static irqreturn_t
ibmvnic_interrupt_rx(int irq
, void *instance
);
102 static int enable_scrq_irq(struct ibmvnic_adapter
*,
103 struct ibmvnic_sub_crq_queue
*);
104 static int disable_scrq_irq(struct ibmvnic_adapter
*,
105 struct ibmvnic_sub_crq_queue
*);
106 static int pending_scrq(struct ibmvnic_adapter
*,
107 struct ibmvnic_sub_crq_queue
*);
108 static union sub_crq
*ibmvnic_next_scrq(struct ibmvnic_adapter
*,
109 struct ibmvnic_sub_crq_queue
*);
110 static int ibmvnic_poll(struct napi_struct
*napi
, int data
);
111 static void send_map_query(struct ibmvnic_adapter
*adapter
);
112 static void send_request_map(struct ibmvnic_adapter
*, dma_addr_t
, __be32
, u8
);
113 static void send_request_unmap(struct ibmvnic_adapter
*, u8
);
115 struct ibmvnic_stat
{
116 char name
[ETH_GSTRING_LEN
];
120 #define IBMVNIC_STAT_OFF(stat) (offsetof(struct ibmvnic_adapter, stats) + \
121 offsetof(struct ibmvnic_statistics, stat))
122 #define IBMVNIC_GET_STAT(a, off) (*((u64 *)(((unsigned long)(a)) + off)))
124 static const struct ibmvnic_stat ibmvnic_stats
[] = {
125 {"rx_packets", IBMVNIC_STAT_OFF(rx_packets
)},
126 {"rx_bytes", IBMVNIC_STAT_OFF(rx_bytes
)},
127 {"tx_packets", IBMVNIC_STAT_OFF(tx_packets
)},
128 {"tx_bytes", IBMVNIC_STAT_OFF(tx_bytes
)},
129 {"ucast_tx_packets", IBMVNIC_STAT_OFF(ucast_tx_packets
)},
130 {"ucast_rx_packets", IBMVNIC_STAT_OFF(ucast_rx_packets
)},
131 {"mcast_tx_packets", IBMVNIC_STAT_OFF(mcast_tx_packets
)},
132 {"mcast_rx_packets", IBMVNIC_STAT_OFF(mcast_rx_packets
)},
133 {"bcast_tx_packets", IBMVNIC_STAT_OFF(bcast_tx_packets
)},
134 {"bcast_rx_packets", IBMVNIC_STAT_OFF(bcast_rx_packets
)},
135 {"align_errors", IBMVNIC_STAT_OFF(align_errors
)},
136 {"fcs_errors", IBMVNIC_STAT_OFF(fcs_errors
)},
137 {"single_collision_frames", IBMVNIC_STAT_OFF(single_collision_frames
)},
138 {"multi_collision_frames", IBMVNIC_STAT_OFF(multi_collision_frames
)},
139 {"sqe_test_errors", IBMVNIC_STAT_OFF(sqe_test_errors
)},
140 {"deferred_tx", IBMVNIC_STAT_OFF(deferred_tx
)},
141 {"late_collisions", IBMVNIC_STAT_OFF(late_collisions
)},
142 {"excess_collisions", IBMVNIC_STAT_OFF(excess_collisions
)},
143 {"internal_mac_tx_errors", IBMVNIC_STAT_OFF(internal_mac_tx_errors
)},
144 {"carrier_sense", IBMVNIC_STAT_OFF(carrier_sense
)},
145 {"too_long_frames", IBMVNIC_STAT_OFF(too_long_frames
)},
146 {"internal_mac_rx_errors", IBMVNIC_STAT_OFF(internal_mac_rx_errors
)},
149 static long h_reg_sub_crq(unsigned long unit_address
, unsigned long token
,
150 unsigned long length
, unsigned long *number
,
153 unsigned long retbuf
[PLPAR_HCALL_BUFSIZE
];
156 rc
= plpar_hcall(H_REG_SUB_CRQ
, retbuf
, unit_address
, token
, length
);
163 /* net_device_ops functions */
165 static void init_rx_pool(struct ibmvnic_adapter
*adapter
,
166 struct ibmvnic_rx_pool
*rx_pool
, int num
, int index
,
167 int buff_size
, int active
)
169 netdev_dbg(adapter
->netdev
,
170 "Initializing rx_pool %d, %d buffs, %d bytes each\n",
171 index
, num
, buff_size
);
173 rx_pool
->index
= index
;
174 rx_pool
->buff_size
= buff_size
;
175 rx_pool
->active
= active
;
178 static int alloc_long_term_buff(struct ibmvnic_adapter
*adapter
,
179 struct ibmvnic_long_term_buff
*ltb
, int size
)
181 struct device
*dev
= &adapter
->vdev
->dev
;
184 ltb
->buff
= dma_alloc_coherent(dev
, ltb
->size
, <b
->addr
,
188 dev_err(dev
, "Couldn't alloc long term buffer\n");
191 ltb
->map_id
= adapter
->map_id
;
193 send_request_map(adapter
, ltb
->addr
,
194 ltb
->size
, ltb
->map_id
);
195 init_completion(&adapter
->fw_done
);
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 IBMVNIC_BUFFS_PER_POOL
, 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
->max_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
->max_tx_entries_per_subcrq
*
430 goto tx_ltb_alloc_failed
;
433 kcalloc(adapter
->max_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
->max_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_enable(&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_tx_pool
*tx_pool
;
709 unsigned int tx_send_failed
= 0;
710 unsigned int tx_map_failed
= 0;
711 unsigned int tx_dropped
= 0;
712 unsigned int tx_packets
= 0;
713 unsigned int tx_bytes
= 0;
714 dma_addr_t data_dma_addr
;
715 struct netdev_queue
*txq
;
716 bool used_bounce
= false;
717 unsigned long lpar_rc
;
718 union sub_crq tx_crq
;
726 tx_pool
= &adapter
->tx_pool
[queue_num
];
727 txq
= netdev_get_tx_queue(netdev
, skb_get_queue_mapping(skb
));
728 handle_array
= (u64
*)((u8
*)(adapter
->login_rsp_buf
) +
729 be32_to_cpu(adapter
->login_rsp_buf
->
730 off_txsubm_subcrqs
));
731 if (adapter
->migrated
) {
734 ret
= NETDEV_TX_BUSY
;
738 index
= tx_pool
->free_map
[tx_pool
->consumer_index
];
739 offset
= index
* adapter
->req_mtu
;
740 dst
= tx_pool
->long_term_buff
.buff
+ offset
;
741 memset(dst
, 0, adapter
->req_mtu
);
742 skb_copy_from_linear_data(skb
, dst
, skb
->len
);
743 data_dma_addr
= tx_pool
->long_term_buff
.addr
+ offset
;
745 tx_pool
->consumer_index
=
746 (tx_pool
->consumer_index
+ 1) %
747 adapter
->max_tx_entries_per_subcrq
;
749 tx_buff
= &tx_pool
->tx_buff
[index
];
751 tx_buff
->data_dma
[0] = data_dma_addr
;
752 tx_buff
->data_len
[0] = skb
->len
;
753 tx_buff
->index
= index
;
754 tx_buff
->pool_index
= queue_num
;
755 tx_buff
->last_frag
= true;
756 tx_buff
->used_bounce
= used_bounce
;
758 memset(&tx_crq
, 0, sizeof(tx_crq
));
759 tx_crq
.v1
.first
= IBMVNIC_CRQ_CMD
;
760 tx_crq
.v1
.type
= IBMVNIC_TX_DESC
;
761 tx_crq
.v1
.n_crq_elem
= 1;
763 tx_crq
.v1
.flags1
= IBMVNIC_TX_COMP_NEEDED
;
764 tx_crq
.v1
.correlator
= cpu_to_be32(index
);
765 tx_crq
.v1
.dma_reg
= cpu_to_be16(tx_pool
->long_term_buff
.map_id
);
766 tx_crq
.v1
.sge_len
= cpu_to_be32(skb
->len
);
767 tx_crq
.v1
.ioba
= cpu_to_be64(data_dma_addr
);
769 if (adapter
->vlan_header_insertion
) {
770 tx_crq
.v1
.flags2
|= IBMVNIC_TX_VLAN_INSERT
;
771 tx_crq
.v1
.vlan_id
= cpu_to_be16(skb
->vlan_tci
);
774 if (skb
->protocol
== htons(ETH_P_IP
)) {
775 if (ip_hdr(skb
)->version
== 4)
776 tx_crq
.v1
.flags1
|= IBMVNIC_TX_PROT_IPV4
;
777 else if (ip_hdr(skb
)->version
== 6)
778 tx_crq
.v1
.flags1
|= IBMVNIC_TX_PROT_IPV6
;
780 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
781 tx_crq
.v1
.flags1
|= IBMVNIC_TX_PROT_TCP
;
782 else if (ip_hdr(skb
)->protocol
!= IPPROTO_TCP
)
783 tx_crq
.v1
.flags1
|= IBMVNIC_TX_PROT_UDP
;
786 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
787 tx_crq
.v1
.flags1
|= IBMVNIC_TX_CHKSUM_OFFLOAD
;
790 /* determine if l2/3/4 headers are sent to firmware */
791 if ((*hdrs
>> 7) & 1 &&
792 (skb
->protocol
== htons(ETH_P_IP
) ||
793 skb
->protocol
== htons(ETH_P_IPV6
))) {
794 build_hdr_descs_arr(tx_buff
, &num_entries
, *hdrs
);
795 tx_crq
.v1
.n_crq_elem
= num_entries
;
796 tx_buff
->indir_arr
[0] = tx_crq
;
797 tx_buff
->indir_dma
= dma_map_single(dev
, tx_buff
->indir_arr
,
798 sizeof(tx_buff
->indir_arr
),
800 if (dma_mapping_error(dev
, tx_buff
->indir_dma
)) {
801 if (!firmware_has_feature(FW_FEATURE_CMO
))
802 dev_err(dev
, "tx: unable to map descriptor array\n");
805 ret
= NETDEV_TX_BUSY
;
808 lpar_rc
= send_subcrq_indirect(adapter
, handle_array
[queue_num
],
809 (u64
)tx_buff
->indir_dma
,
812 lpar_rc
= send_subcrq(adapter
, handle_array
[queue_num
],
815 if (lpar_rc
!= H_SUCCESS
) {
816 dev_err(dev
, "tx failed with code %ld\n", lpar_rc
);
818 if (tx_pool
->consumer_index
== 0)
819 tx_pool
->consumer_index
=
820 adapter
->max_tx_entries_per_subcrq
- 1;
822 tx_pool
->consumer_index
--;
826 ret
= NETDEV_TX_BUSY
;
830 tx_bytes
+= skb
->len
;
831 txq
->trans_start
= jiffies
;
835 netdev
->stats
.tx_dropped
+= tx_dropped
;
836 netdev
->stats
.tx_bytes
+= tx_bytes
;
837 netdev
->stats
.tx_packets
+= tx_packets
;
838 adapter
->tx_send_failed
+= tx_send_failed
;
839 adapter
->tx_map_failed
+= tx_map_failed
;
844 static void ibmvnic_set_multi(struct net_device
*netdev
)
846 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
847 struct netdev_hw_addr
*ha
;
848 union ibmvnic_crq crq
;
850 memset(&crq
, 0, sizeof(crq
));
851 crq
.request_capability
.first
= IBMVNIC_CRQ_CMD
;
852 crq
.request_capability
.cmd
= REQUEST_CAPABILITY
;
854 if (netdev
->flags
& IFF_PROMISC
) {
855 if (!adapter
->promisc_supported
)
858 if (netdev
->flags
& IFF_ALLMULTI
) {
859 /* Accept all multicast */
860 memset(&crq
, 0, sizeof(crq
));
861 crq
.multicast_ctrl
.first
= IBMVNIC_CRQ_CMD
;
862 crq
.multicast_ctrl
.cmd
= MULTICAST_CTRL
;
863 crq
.multicast_ctrl
.flags
= IBMVNIC_ENABLE_ALL
;
864 ibmvnic_send_crq(adapter
, &crq
);
865 } else if (netdev_mc_empty(netdev
)) {
866 /* Reject all multicast */
867 memset(&crq
, 0, sizeof(crq
));
868 crq
.multicast_ctrl
.first
= IBMVNIC_CRQ_CMD
;
869 crq
.multicast_ctrl
.cmd
= MULTICAST_CTRL
;
870 crq
.multicast_ctrl
.flags
= IBMVNIC_DISABLE_ALL
;
871 ibmvnic_send_crq(adapter
, &crq
);
873 /* Accept one or more multicast(s) */
874 netdev_for_each_mc_addr(ha
, netdev
) {
875 memset(&crq
, 0, sizeof(crq
));
876 crq
.multicast_ctrl
.first
= IBMVNIC_CRQ_CMD
;
877 crq
.multicast_ctrl
.cmd
= MULTICAST_CTRL
;
878 crq
.multicast_ctrl
.flags
= IBMVNIC_ENABLE_MC
;
879 ether_addr_copy(&crq
.multicast_ctrl
.mac_addr
[0],
881 ibmvnic_send_crq(adapter
, &crq
);
887 static int ibmvnic_set_mac(struct net_device
*netdev
, void *p
)
889 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
890 struct sockaddr
*addr
= p
;
891 union ibmvnic_crq crq
;
893 if (!is_valid_ether_addr(addr
->sa_data
))
894 return -EADDRNOTAVAIL
;
896 memset(&crq
, 0, sizeof(crq
));
897 crq
.change_mac_addr
.first
= IBMVNIC_CRQ_CMD
;
898 crq
.change_mac_addr
.cmd
= CHANGE_MAC_ADDR
;
899 ether_addr_copy(&crq
.change_mac_addr
.mac_addr
[0], addr
->sa_data
);
900 ibmvnic_send_crq(adapter
, &crq
);
901 /* netdev->dev_addr is changed in handle_change_mac_rsp function */
905 static int ibmvnic_change_mtu(struct net_device
*netdev
, int new_mtu
)
907 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
909 if (new_mtu
> adapter
->req_mtu
|| new_mtu
< adapter
->min_mtu
)
912 netdev
->mtu
= new_mtu
;
916 static void ibmvnic_tx_timeout(struct net_device
*dev
)
918 struct ibmvnic_adapter
*adapter
= netdev_priv(dev
);
921 /* Adapter timed out, resetting it */
922 release_sub_crqs(adapter
);
923 rc
= ibmvnic_reset_crq(adapter
);
925 dev_err(&adapter
->vdev
->dev
, "Adapter timeout, reset failed\n");
927 ibmvnic_send_crq_init(adapter
);
930 static void remove_buff_from_pool(struct ibmvnic_adapter
*adapter
,
931 struct ibmvnic_rx_buff
*rx_buff
)
933 struct ibmvnic_rx_pool
*pool
= &adapter
->rx_pool
[rx_buff
->pool_index
];
937 pool
->free_map
[pool
->next_alloc
] = (int)(rx_buff
- pool
->rx_buff
);
938 pool
->next_alloc
= (pool
->next_alloc
+ 1) % pool
->size
;
940 atomic_dec(&pool
->available
);
943 static int ibmvnic_poll(struct napi_struct
*napi
, int budget
)
945 struct net_device
*netdev
= napi
->dev
;
946 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
947 int scrq_num
= (int)(napi
- adapter
->napi
);
948 int frames_processed
= 0;
950 while (frames_processed
< budget
) {
952 struct ibmvnic_rx_buff
*rx_buff
;
958 if (!pending_scrq(adapter
, adapter
->rx_scrq
[scrq_num
]))
960 next
= ibmvnic_next_scrq(adapter
, adapter
->rx_scrq
[scrq_num
]);
962 (struct ibmvnic_rx_buff
*)be64_to_cpu(next
->
964 /* do error checking */
965 if (next
->rx_comp
.rc
) {
966 netdev_err(netdev
, "rx error %x\n", next
->rx_comp
.rc
);
968 next
->rx_comp
.first
= 0;
969 remove_buff_from_pool(adapter
, rx_buff
);
973 length
= be32_to_cpu(next
->rx_comp
.len
);
974 offset
= be16_to_cpu(next
->rx_comp
.off_frame_data
);
975 flags
= next
->rx_comp
.flags
;
977 skb_copy_to_linear_data(skb
, rx_buff
->data
+ offset
,
979 skb
->vlan_tci
= be16_to_cpu(next
->rx_comp
.vlan_tci
);
981 next
->rx_comp
.first
= 0;
982 remove_buff_from_pool(adapter
, rx_buff
);
984 skb_put(skb
, length
);
985 skb
->protocol
= eth_type_trans(skb
, netdev
);
987 if (flags
& IBMVNIC_IP_CHKSUM_GOOD
&&
988 flags
& IBMVNIC_TCP_UDP_CHKSUM_GOOD
) {
989 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
993 napi_gro_receive(napi
, skb
); /* send it up */
994 netdev
->stats
.rx_packets
++;
995 netdev
->stats
.rx_bytes
+= length
;
998 replenish_rx_pool(adapter
, &adapter
->rx_pool
[scrq_num
]);
1000 if (frames_processed
< budget
) {
1001 enable_scrq_irq(adapter
, adapter
->rx_scrq
[scrq_num
]);
1002 napi_complete(napi
);
1003 if (pending_scrq(adapter
, adapter
->rx_scrq
[scrq_num
]) &&
1004 napi_reschedule(napi
)) {
1005 disable_scrq_irq(adapter
, adapter
->rx_scrq
[scrq_num
]);
1009 return frames_processed
;
1012 #ifdef CONFIG_NET_POLL_CONTROLLER
1013 static void ibmvnic_netpoll_controller(struct net_device
*dev
)
1015 struct ibmvnic_adapter
*adapter
= netdev_priv(dev
);
1018 replenish_pools(netdev_priv(dev
));
1019 for (i
= 0; i
< adapter
->req_rx_queues
; i
++)
1020 ibmvnic_interrupt_rx(adapter
->rx_scrq
[i
]->irq
,
1021 adapter
->rx_scrq
[i
]);
1025 static const struct net_device_ops ibmvnic_netdev_ops
= {
1026 .ndo_open
= ibmvnic_open
,
1027 .ndo_stop
= ibmvnic_close
,
1028 .ndo_start_xmit
= ibmvnic_xmit
,
1029 .ndo_set_rx_mode
= ibmvnic_set_multi
,
1030 .ndo_set_mac_address
= ibmvnic_set_mac
,
1031 .ndo_validate_addr
= eth_validate_addr
,
1032 .ndo_change_mtu
= ibmvnic_change_mtu
,
1033 .ndo_tx_timeout
= ibmvnic_tx_timeout
,
1034 #ifdef CONFIG_NET_POLL_CONTROLLER
1035 .ndo_poll_controller
= ibmvnic_netpoll_controller
,
1039 /* ethtool functions */
1041 static int ibmvnic_get_settings(struct net_device
*netdev
,
1042 struct ethtool_cmd
*cmd
)
1044 cmd
->supported
= (SUPPORTED_1000baseT_Full
| SUPPORTED_Autoneg
|
1046 cmd
->advertising
= (ADVERTISED_1000baseT_Full
| ADVERTISED_Autoneg
|
1048 ethtool_cmd_speed_set(cmd
, SPEED_1000
);
1049 cmd
->duplex
= DUPLEX_FULL
;
1050 cmd
->port
= PORT_FIBRE
;
1051 cmd
->phy_address
= 0;
1052 cmd
->transceiver
= XCVR_INTERNAL
;
1053 cmd
->autoneg
= AUTONEG_ENABLE
;
1059 static void ibmvnic_get_drvinfo(struct net_device
*dev
,
1060 struct ethtool_drvinfo
*info
)
1062 strlcpy(info
->driver
, ibmvnic_driver_name
, sizeof(info
->driver
));
1063 strlcpy(info
->version
, IBMVNIC_DRIVER_VERSION
, sizeof(info
->version
));
1066 static u32
ibmvnic_get_msglevel(struct net_device
*netdev
)
1068 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
1070 return adapter
->msg_enable
;
1073 static void ibmvnic_set_msglevel(struct net_device
*netdev
, u32 data
)
1075 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
1077 adapter
->msg_enable
= data
;
1080 static u32
ibmvnic_get_link(struct net_device
*netdev
)
1082 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
1084 /* Don't need to send a query because we request a logical link up at
1085 * init and then we wait for link state indications
1087 return adapter
->logical_link_state
;
1090 static void ibmvnic_get_ringparam(struct net_device
*netdev
,
1091 struct ethtool_ringparam
*ring
)
1093 ring
->rx_max_pending
= 0;
1094 ring
->tx_max_pending
= 0;
1095 ring
->rx_mini_max_pending
= 0;
1096 ring
->rx_jumbo_max_pending
= 0;
1097 ring
->rx_pending
= 0;
1098 ring
->tx_pending
= 0;
1099 ring
->rx_mini_pending
= 0;
1100 ring
->rx_jumbo_pending
= 0;
1103 static void ibmvnic_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
1107 if (stringset
!= ETH_SS_STATS
)
1110 for (i
= 0; i
< ARRAY_SIZE(ibmvnic_stats
); i
++, data
+= ETH_GSTRING_LEN
)
1111 memcpy(data
, ibmvnic_stats
[i
].name
, ETH_GSTRING_LEN
);
1114 static int ibmvnic_get_sset_count(struct net_device
*dev
, int sset
)
1118 return ARRAY_SIZE(ibmvnic_stats
);
1124 static void ibmvnic_get_ethtool_stats(struct net_device
*dev
,
1125 struct ethtool_stats
*stats
, u64
*data
)
1127 struct ibmvnic_adapter
*adapter
= netdev_priv(dev
);
1128 union ibmvnic_crq crq
;
1131 memset(&crq
, 0, sizeof(crq
));
1132 crq
.request_statistics
.first
= IBMVNIC_CRQ_CMD
;
1133 crq
.request_statistics
.cmd
= REQUEST_STATISTICS
;
1134 crq
.request_statistics
.ioba
= cpu_to_be32(adapter
->stats_token
);
1135 crq
.request_statistics
.len
=
1136 cpu_to_be32(sizeof(struct ibmvnic_statistics
));
1137 ibmvnic_send_crq(adapter
, &crq
);
1139 /* Wait for data to be written */
1140 init_completion(&adapter
->stats_done
);
1141 wait_for_completion(&adapter
->stats_done
);
1143 for (i
= 0; i
< ARRAY_SIZE(ibmvnic_stats
); i
++)
1144 data
[i
] = IBMVNIC_GET_STAT(adapter
, ibmvnic_stats
[i
].offset
);
1147 static const struct ethtool_ops ibmvnic_ethtool_ops
= {
1148 .get_settings
= ibmvnic_get_settings
,
1149 .get_drvinfo
= ibmvnic_get_drvinfo
,
1150 .get_msglevel
= ibmvnic_get_msglevel
,
1151 .set_msglevel
= ibmvnic_set_msglevel
,
1152 .get_link
= ibmvnic_get_link
,
1153 .get_ringparam
= ibmvnic_get_ringparam
,
1154 .get_strings
= ibmvnic_get_strings
,
1155 .get_sset_count
= ibmvnic_get_sset_count
,
1156 .get_ethtool_stats
= ibmvnic_get_ethtool_stats
,
1159 /* Routines for managing CRQs/sCRQs */
1161 static void release_sub_crq_queue(struct ibmvnic_adapter
*adapter
,
1162 struct ibmvnic_sub_crq_queue
*scrq
)
1164 struct device
*dev
= &adapter
->vdev
->dev
;
1167 netdev_dbg(adapter
->netdev
, "Releasing sub-CRQ\n");
1169 /* Close the sub-crqs */
1171 rc
= plpar_hcall_norets(H_FREE_SUB_CRQ
,
1172 adapter
->vdev
->unit_address
,
1174 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
1176 dma_unmap_single(dev
, scrq
->msg_token
, 4 * PAGE_SIZE
,
1178 free_pages((unsigned long)scrq
->msgs
, 2);
1182 static struct ibmvnic_sub_crq_queue
*init_sub_crq_queue(struct ibmvnic_adapter
1185 struct device
*dev
= &adapter
->vdev
->dev
;
1186 struct ibmvnic_sub_crq_queue
*scrq
;
1189 scrq
= kmalloc(sizeof(*scrq
), GFP_ATOMIC
);
1193 scrq
->msgs
= (union sub_crq
*)__get_free_pages(GFP_ATOMIC
, 2);
1194 memset(scrq
->msgs
, 0, 4 * PAGE_SIZE
);
1196 dev_warn(dev
, "Couldn't allocate crq queue messages page\n");
1197 goto zero_page_failed
;
1200 scrq
->msg_token
= dma_map_single(dev
, scrq
->msgs
, 4 * PAGE_SIZE
,
1202 if (dma_mapping_error(dev
, scrq
->msg_token
)) {
1203 dev_warn(dev
, "Couldn't map crq queue messages page\n");
1207 rc
= h_reg_sub_crq(adapter
->vdev
->unit_address
, scrq
->msg_token
,
1208 4 * PAGE_SIZE
, &scrq
->crq_num
, &scrq
->hw_irq
);
1210 if (rc
== H_RESOURCE
)
1211 rc
= ibmvnic_reset_crq(adapter
);
1213 if (rc
== H_CLOSED
) {
1214 dev_warn(dev
, "Partner adapter not ready, waiting.\n");
1216 dev_warn(dev
, "Error %d registering sub-crq\n", rc
);
1220 scrq
->adapter
= adapter
;
1221 scrq
->size
= 4 * PAGE_SIZE
/ sizeof(*scrq
->msgs
);
1223 scrq
->rx_skb_top
= NULL
;
1224 spin_lock_init(&scrq
->lock
);
1226 netdev_dbg(adapter
->netdev
,
1227 "sub-crq initialized, num %lx, hw_irq=%lx, irq=%x\n",
1228 scrq
->crq_num
, scrq
->hw_irq
, scrq
->irq
);
1233 dma_unmap_single(dev
, scrq
->msg_token
, 4 * PAGE_SIZE
,
1236 free_pages((unsigned long)scrq
->msgs
, 2);
1243 static void release_sub_crqs(struct ibmvnic_adapter
*adapter
)
1247 if (adapter
->tx_scrq
) {
1248 for (i
= 0; i
< adapter
->req_tx_queues
; i
++)
1249 if (adapter
->tx_scrq
[i
]) {
1250 free_irq(adapter
->tx_scrq
[i
]->irq
,
1251 adapter
->tx_scrq
[i
]);
1252 irq_dispose_mapping(adapter
->tx_scrq
[i
]->irq
);
1253 release_sub_crq_queue(adapter
,
1254 adapter
->tx_scrq
[i
]);
1256 adapter
->tx_scrq
= NULL
;
1259 if (adapter
->rx_scrq
) {
1260 for (i
= 0; i
< adapter
->req_rx_queues
; i
++)
1261 if (adapter
->rx_scrq
[i
]) {
1262 free_irq(adapter
->rx_scrq
[i
]->irq
,
1263 adapter
->rx_scrq
[i
]);
1264 irq_dispose_mapping(adapter
->rx_scrq
[i
]->irq
);
1265 release_sub_crq_queue(adapter
,
1266 adapter
->rx_scrq
[i
]);
1268 adapter
->rx_scrq
= NULL
;
1271 adapter
->requested_caps
= 0;
1274 static void release_sub_crqs_no_irqs(struct ibmvnic_adapter
*adapter
)
1278 if (adapter
->tx_scrq
) {
1279 for (i
= 0; i
< adapter
->req_tx_queues
; i
++)
1280 if (adapter
->tx_scrq
[i
])
1281 release_sub_crq_queue(adapter
,
1282 adapter
->tx_scrq
[i
]);
1283 adapter
->tx_scrq
= NULL
;
1286 if (adapter
->rx_scrq
) {
1287 for (i
= 0; i
< adapter
->req_rx_queues
; i
++)
1288 if (adapter
->rx_scrq
[i
])
1289 release_sub_crq_queue(adapter
,
1290 adapter
->rx_scrq
[i
]);
1291 adapter
->rx_scrq
= NULL
;
1294 adapter
->requested_caps
= 0;
1297 static int disable_scrq_irq(struct ibmvnic_adapter
*adapter
,
1298 struct ibmvnic_sub_crq_queue
*scrq
)
1300 struct device
*dev
= &adapter
->vdev
->dev
;
1303 rc
= plpar_hcall_norets(H_VIOCTL
, adapter
->vdev
->unit_address
,
1304 H_DISABLE_VIO_INTERRUPT
, scrq
->hw_irq
, 0, 0);
1306 dev_err(dev
, "Couldn't disable scrq irq 0x%lx. rc=%ld\n",
1311 static int enable_scrq_irq(struct ibmvnic_adapter
*adapter
,
1312 struct ibmvnic_sub_crq_queue
*scrq
)
1314 struct device
*dev
= &adapter
->vdev
->dev
;
1317 if (scrq
->hw_irq
> 0x100000000ULL
) {
1318 dev_err(dev
, "bad hw_irq = %lx\n", scrq
->hw_irq
);
1322 rc
= plpar_hcall_norets(H_VIOCTL
, adapter
->vdev
->unit_address
,
1323 H_ENABLE_VIO_INTERRUPT
, scrq
->hw_irq
, 0, 0);
1325 dev_err(dev
, "Couldn't enable scrq irq 0x%lx. rc=%ld\n",
1330 static int ibmvnic_complete_tx(struct ibmvnic_adapter
*adapter
,
1331 struct ibmvnic_sub_crq_queue
*scrq
)
1333 struct device
*dev
= &adapter
->vdev
->dev
;
1334 struct ibmvnic_tx_buff
*txbuff
;
1335 union sub_crq
*next
;
1341 while (pending_scrq(adapter
, scrq
)) {
1342 unsigned int pool
= scrq
->pool_index
;
1344 next
= ibmvnic_next_scrq(adapter
, scrq
);
1345 for (i
= 0; i
< next
->tx_comp
.num_comps
; i
++) {
1346 if (next
->tx_comp
.rcs
[i
]) {
1347 dev_err(dev
, "tx error %x\n",
1348 next
->tx_comp
.rcs
[i
]);
1351 index
= be32_to_cpu(next
->tx_comp
.correlators
[i
]);
1352 txbuff
= &adapter
->tx_pool
[pool
].tx_buff
[index
];
1354 for (j
= 0; j
< IBMVNIC_MAX_FRAGS_PER_CRQ
; j
++) {
1355 if (!txbuff
->data_dma
[j
])
1358 txbuff
->data_dma
[j
] = 0;
1359 txbuff
->used_bounce
= false;
1361 /* if sub_crq was sent indirectly */
1362 first
= txbuff
->indir_arr
[0].generic
.first
;
1363 if (first
== IBMVNIC_CRQ_CMD
) {
1364 dma_unmap_single(dev
, txbuff
->indir_dma
,
1365 sizeof(txbuff
->indir_arr
),
1369 if (txbuff
->last_frag
)
1370 dev_kfree_skb_any(txbuff
->skb
);
1372 adapter
->tx_pool
[pool
].free_map
[adapter
->tx_pool
[pool
].
1373 producer_index
] = index
;
1374 adapter
->tx_pool
[pool
].producer_index
=
1375 (adapter
->tx_pool
[pool
].producer_index
+ 1) %
1376 adapter
->max_tx_entries_per_subcrq
;
1378 /* remove tx_comp scrq*/
1379 next
->tx_comp
.first
= 0;
1382 enable_scrq_irq(adapter
, scrq
);
1384 if (pending_scrq(adapter
, scrq
)) {
1385 disable_scrq_irq(adapter
, scrq
);
1392 static irqreturn_t
ibmvnic_interrupt_tx(int irq
, void *instance
)
1394 struct ibmvnic_sub_crq_queue
*scrq
= instance
;
1395 struct ibmvnic_adapter
*adapter
= scrq
->adapter
;
1397 disable_scrq_irq(adapter
, scrq
);
1398 ibmvnic_complete_tx(adapter
, scrq
);
1403 static irqreturn_t
ibmvnic_interrupt_rx(int irq
, void *instance
)
1405 struct ibmvnic_sub_crq_queue
*scrq
= instance
;
1406 struct ibmvnic_adapter
*adapter
= scrq
->adapter
;
1408 if (napi_schedule_prep(&adapter
->napi
[scrq
->scrq_num
])) {
1409 disable_scrq_irq(adapter
, scrq
);
1410 __napi_schedule(&adapter
->napi
[scrq
->scrq_num
]);
1416 static int init_sub_crq_irqs(struct ibmvnic_adapter
*adapter
)
1418 struct device
*dev
= &adapter
->vdev
->dev
;
1419 struct ibmvnic_sub_crq_queue
*scrq
;
1423 for (i
= 0; i
< adapter
->req_tx_queues
; i
++) {
1424 scrq
= adapter
->tx_scrq
[i
];
1425 scrq
->irq
= irq_create_mapping(NULL
, scrq
->hw_irq
);
1429 dev_err(dev
, "Error mapping irq\n");
1430 goto req_tx_irq_failed
;
1433 rc
= request_irq(scrq
->irq
, ibmvnic_interrupt_tx
,
1434 0, "ibmvnic_tx", scrq
);
1437 dev_err(dev
, "Couldn't register tx irq 0x%x. rc=%d\n",
1439 irq_dispose_mapping(scrq
->irq
);
1440 goto req_rx_irq_failed
;
1444 for (i
= 0; i
< adapter
->req_rx_queues
; i
++) {
1445 scrq
= adapter
->rx_scrq
[i
];
1446 scrq
->irq
= irq_create_mapping(NULL
, scrq
->hw_irq
);
1449 dev_err(dev
, "Error mapping irq\n");
1450 goto req_rx_irq_failed
;
1452 rc
= request_irq(scrq
->irq
, ibmvnic_interrupt_rx
,
1453 0, "ibmvnic_rx", scrq
);
1455 dev_err(dev
, "Couldn't register rx irq 0x%x. rc=%d\n",
1457 irq_dispose_mapping(scrq
->irq
);
1458 goto req_rx_irq_failed
;
1464 for (j
= 0; j
< i
; j
++) {
1465 free_irq(adapter
->rx_scrq
[j
]->irq
, adapter
->rx_scrq
[j
]);
1466 irq_dispose_mapping(adapter
->rx_scrq
[j
]->irq
);
1468 i
= adapter
->req_tx_queues
;
1470 for (j
= 0; j
< i
; j
++) {
1471 free_irq(adapter
->tx_scrq
[j
]->irq
, adapter
->tx_scrq
[j
]);
1472 irq_dispose_mapping(adapter
->rx_scrq
[j
]->irq
);
1474 release_sub_crqs_no_irqs(adapter
);
1478 static void init_sub_crqs(struct ibmvnic_adapter
*adapter
, int retry
)
1480 struct device
*dev
= &adapter
->vdev
->dev
;
1481 struct ibmvnic_sub_crq_queue
**allqueues
;
1482 int registered_queues
= 0;
1483 union ibmvnic_crq crq
;
1489 /* Sub-CRQ entries are 32 byte long */
1490 int entries_page
= 4 * PAGE_SIZE
/ (sizeof(u64
) * 4);
1492 if (adapter
->min_tx_entries_per_subcrq
> entries_page
||
1493 adapter
->min_rx_add_entries_per_subcrq
> entries_page
) {
1494 dev_err(dev
, "Fatal, invalid entries per sub-crq\n");
1495 goto allqueues_failed
;
1498 /* Get the minimum between the queried max and the entries
1499 * that fit in our PAGE_SIZE
1501 adapter
->req_tx_entries_per_subcrq
=
1502 adapter
->max_tx_entries_per_subcrq
> entries_page
?
1503 entries_page
: adapter
->max_tx_entries_per_subcrq
;
1504 adapter
->req_rx_add_entries_per_subcrq
=
1505 adapter
->max_rx_add_entries_per_subcrq
> entries_page
?
1506 entries_page
: adapter
->max_rx_add_entries_per_subcrq
;
1508 /* Choosing the maximum number of queues supported by firmware*/
1509 adapter
->req_tx_queues
= adapter
->max_tx_queues
;
1510 adapter
->req_rx_queues
= adapter
->max_rx_queues
;
1511 adapter
->req_rx_add_queues
= adapter
->max_rx_add_queues
;
1513 adapter
->req_mtu
= adapter
->max_mtu
;
1516 total_queues
= adapter
->req_tx_queues
+ adapter
->req_rx_queues
;
1518 allqueues
= kcalloc(total_queues
, sizeof(*allqueues
), GFP_ATOMIC
);
1520 goto allqueues_failed
;
1522 for (i
= 0; i
< total_queues
; i
++) {
1523 allqueues
[i
] = init_sub_crq_queue(adapter
);
1524 if (!allqueues
[i
]) {
1525 dev_warn(dev
, "Couldn't allocate all sub-crqs\n");
1528 registered_queues
++;
1531 /* Make sure we were able to register the minimum number of queues */
1532 if (registered_queues
<
1533 adapter
->min_tx_queues
+ adapter
->min_rx_queues
) {
1534 dev_err(dev
, "Fatal: Couldn't init min number of sub-crqs\n");
1538 /* Distribute the failed allocated queues*/
1539 for (i
= 0; i
< total_queues
- registered_queues
+ more
; i
++) {
1540 netdev_dbg(adapter
->netdev
, "Reducing number of queues\n");
1543 if (adapter
->req_rx_queues
> adapter
->min_rx_queues
)
1544 adapter
->req_rx_queues
--;
1549 if (adapter
->req_tx_queues
> adapter
->min_tx_queues
)
1550 adapter
->req_tx_queues
--;
1557 adapter
->tx_scrq
= kcalloc(adapter
->req_tx_queues
,
1558 sizeof(*adapter
->tx_scrq
), GFP_ATOMIC
);
1559 if (!adapter
->tx_scrq
)
1562 for (i
= 0; i
< adapter
->req_tx_queues
; i
++) {
1563 adapter
->tx_scrq
[i
] = allqueues
[i
];
1564 adapter
->tx_scrq
[i
]->pool_index
= i
;
1567 adapter
->rx_scrq
= kcalloc(adapter
->req_rx_queues
,
1568 sizeof(*adapter
->rx_scrq
), GFP_ATOMIC
);
1569 if (!adapter
->rx_scrq
)
1572 for (i
= 0; i
< adapter
->req_rx_queues
; i
++) {
1573 adapter
->rx_scrq
[i
] = allqueues
[i
+ adapter
->req_tx_queues
];
1574 adapter
->rx_scrq
[i
]->scrq_num
= i
;
1577 memset(&crq
, 0, sizeof(crq
));
1578 crq
.request_capability
.first
= IBMVNIC_CRQ_CMD
;
1579 crq
.request_capability
.cmd
= REQUEST_CAPABILITY
;
1581 crq
.request_capability
.capability
= cpu_to_be16(REQ_TX_QUEUES
);
1582 crq
.request_capability
.number
= cpu_to_be64(adapter
->req_tx_queues
);
1583 ibmvnic_send_crq(adapter
, &crq
);
1585 crq
.request_capability
.capability
= cpu_to_be16(REQ_RX_QUEUES
);
1586 crq
.request_capability
.number
= cpu_to_be64(adapter
->req_rx_queues
);
1587 ibmvnic_send_crq(adapter
, &crq
);
1589 crq
.request_capability
.capability
= cpu_to_be16(REQ_RX_ADD_QUEUES
);
1590 crq
.request_capability
.number
= cpu_to_be64(adapter
->req_rx_add_queues
);
1591 ibmvnic_send_crq(adapter
, &crq
);
1593 crq
.request_capability
.capability
=
1594 cpu_to_be16(REQ_TX_ENTRIES_PER_SUBCRQ
);
1595 crq
.request_capability
.number
=
1596 cpu_to_be64(adapter
->req_tx_entries_per_subcrq
);
1597 ibmvnic_send_crq(adapter
, &crq
);
1599 crq
.request_capability
.capability
=
1600 cpu_to_be16(REQ_RX_ADD_ENTRIES_PER_SUBCRQ
);
1601 crq
.request_capability
.number
=
1602 cpu_to_be64(adapter
->req_rx_add_entries_per_subcrq
);
1603 ibmvnic_send_crq(adapter
, &crq
);
1605 crq
.request_capability
.capability
= cpu_to_be16(REQ_MTU
);
1606 crq
.request_capability
.number
= cpu_to_be64(adapter
->req_mtu
);
1607 ibmvnic_send_crq(adapter
, &crq
);
1609 if (adapter
->netdev
->flags
& IFF_PROMISC
) {
1610 if (adapter
->promisc_supported
) {
1611 crq
.request_capability
.capability
=
1612 cpu_to_be16(PROMISC_REQUESTED
);
1613 crq
.request_capability
.number
= cpu_to_be64(1);
1614 ibmvnic_send_crq(adapter
, &crq
);
1617 crq
.request_capability
.capability
=
1618 cpu_to_be16(PROMISC_REQUESTED
);
1619 crq
.request_capability
.number
= cpu_to_be64(0);
1620 ibmvnic_send_crq(adapter
, &crq
);
1628 kfree(adapter
->tx_scrq
);
1629 adapter
->tx_scrq
= NULL
;
1631 for (i
= 0; i
< registered_queues
; i
++)
1632 release_sub_crq_queue(adapter
, allqueues
[i
]);
1635 ibmvnic_remove(adapter
->vdev
);
1638 static int pending_scrq(struct ibmvnic_adapter
*adapter
,
1639 struct ibmvnic_sub_crq_queue
*scrq
)
1641 union sub_crq
*entry
= &scrq
->msgs
[scrq
->cur
];
1643 if (entry
->generic
.first
& IBMVNIC_CRQ_CMD_RSP
|| adapter
->closing
)
1649 static union sub_crq
*ibmvnic_next_scrq(struct ibmvnic_adapter
*adapter
,
1650 struct ibmvnic_sub_crq_queue
*scrq
)
1652 union sub_crq
*entry
;
1653 unsigned long flags
;
1655 spin_lock_irqsave(&scrq
->lock
, flags
);
1656 entry
= &scrq
->msgs
[scrq
->cur
];
1657 if (entry
->generic
.first
& IBMVNIC_CRQ_CMD_RSP
) {
1658 if (++scrq
->cur
== scrq
->size
)
1663 spin_unlock_irqrestore(&scrq
->lock
, flags
);
1668 static union ibmvnic_crq
*ibmvnic_next_crq(struct ibmvnic_adapter
*adapter
)
1670 struct ibmvnic_crq_queue
*queue
= &adapter
->crq
;
1671 union ibmvnic_crq
*crq
;
1673 crq
= &queue
->msgs
[queue
->cur
];
1674 if (crq
->generic
.first
& IBMVNIC_CRQ_CMD_RSP
) {
1675 if (++queue
->cur
== queue
->size
)
1684 static int send_subcrq(struct ibmvnic_adapter
*adapter
, u64 remote_handle
,
1685 union sub_crq
*sub_crq
)
1687 unsigned int ua
= adapter
->vdev
->unit_address
;
1688 struct device
*dev
= &adapter
->vdev
->dev
;
1689 u64
*u64_crq
= (u64
*)sub_crq
;
1692 netdev_dbg(adapter
->netdev
,
1693 "Sending sCRQ %016lx: %016lx %016lx %016lx %016lx\n",
1694 (unsigned long int)cpu_to_be64(remote_handle
),
1695 (unsigned long int)cpu_to_be64(u64_crq
[0]),
1696 (unsigned long int)cpu_to_be64(u64_crq
[1]),
1697 (unsigned long int)cpu_to_be64(u64_crq
[2]),
1698 (unsigned long int)cpu_to_be64(u64_crq
[3]));
1700 /* Make sure the hypervisor sees the complete request */
1703 rc
= plpar_hcall_norets(H_SEND_SUB_CRQ
, ua
,
1704 cpu_to_be64(remote_handle
),
1705 cpu_to_be64(u64_crq
[0]),
1706 cpu_to_be64(u64_crq
[1]),
1707 cpu_to_be64(u64_crq
[2]),
1708 cpu_to_be64(u64_crq
[3]));
1712 dev_warn(dev
, "CRQ Queue closed\n");
1713 dev_err(dev
, "Send error (rc=%d)\n", rc
);
1719 static int send_subcrq_indirect(struct ibmvnic_adapter
*adapter
,
1720 u64 remote_handle
, u64 ioba
, u64 num_entries
)
1722 unsigned int ua
= adapter
->vdev
->unit_address
;
1723 struct device
*dev
= &adapter
->vdev
->dev
;
1726 /* Make sure the hypervisor sees the complete request */
1728 rc
= plpar_hcall_norets(H_SEND_SUB_CRQ_INDIRECT
, ua
,
1729 cpu_to_be64(remote_handle
),
1734 dev_warn(dev
, "CRQ Queue closed\n");
1735 dev_err(dev
, "Send (indirect) error (rc=%d)\n", rc
);
1741 static int ibmvnic_send_crq(struct ibmvnic_adapter
*adapter
,
1742 union ibmvnic_crq
*crq
)
1744 unsigned int ua
= adapter
->vdev
->unit_address
;
1745 struct device
*dev
= &adapter
->vdev
->dev
;
1746 u64
*u64_crq
= (u64
*)crq
;
1749 netdev_dbg(adapter
->netdev
, "Sending CRQ: %016lx %016lx\n",
1750 (unsigned long int)cpu_to_be64(u64_crq
[0]),
1751 (unsigned long int)cpu_to_be64(u64_crq
[1]));
1753 /* Make sure the hypervisor sees the complete request */
1756 rc
= plpar_hcall_norets(H_SEND_CRQ
, ua
,
1757 cpu_to_be64(u64_crq
[0]),
1758 cpu_to_be64(u64_crq
[1]));
1762 dev_warn(dev
, "CRQ Queue closed\n");
1763 dev_warn(dev
, "Send error (rc=%d)\n", rc
);
1769 static int ibmvnic_send_crq_init(struct ibmvnic_adapter
*adapter
)
1771 union ibmvnic_crq crq
;
1773 memset(&crq
, 0, sizeof(crq
));
1774 crq
.generic
.first
= IBMVNIC_CRQ_INIT_CMD
;
1775 crq
.generic
.cmd
= IBMVNIC_CRQ_INIT
;
1776 netdev_dbg(adapter
->netdev
, "Sending CRQ init\n");
1778 return ibmvnic_send_crq(adapter
, &crq
);
1781 static int ibmvnic_send_crq_init_complete(struct ibmvnic_adapter
*adapter
)
1783 union ibmvnic_crq crq
;
1785 memset(&crq
, 0, sizeof(crq
));
1786 crq
.generic
.first
= IBMVNIC_CRQ_INIT_CMD
;
1787 crq
.generic
.cmd
= IBMVNIC_CRQ_INIT_COMPLETE
;
1788 netdev_dbg(adapter
->netdev
, "Sending CRQ init complete\n");
1790 return ibmvnic_send_crq(adapter
, &crq
);
1793 static int send_version_xchg(struct ibmvnic_adapter
*adapter
)
1795 union ibmvnic_crq crq
;
1797 memset(&crq
, 0, sizeof(crq
));
1798 crq
.version_exchange
.first
= IBMVNIC_CRQ_CMD
;
1799 crq
.version_exchange
.cmd
= VERSION_EXCHANGE
;
1800 crq
.version_exchange
.version
= cpu_to_be16(ibmvnic_version
);
1802 return ibmvnic_send_crq(adapter
, &crq
);
1805 static void send_login(struct ibmvnic_adapter
*adapter
)
1807 struct ibmvnic_login_rsp_buffer
*login_rsp_buffer
;
1808 struct ibmvnic_login_buffer
*login_buffer
;
1809 struct ibmvnic_inflight_cmd
*inflight_cmd
;
1810 struct device
*dev
= &adapter
->vdev
->dev
;
1811 dma_addr_t rsp_buffer_token
;
1812 dma_addr_t buffer_token
;
1813 size_t rsp_buffer_size
;
1814 union ibmvnic_crq crq
;
1815 unsigned long flags
;
1822 sizeof(struct ibmvnic_login_buffer
) +
1823 sizeof(u64
) * (adapter
->req_tx_queues
+ adapter
->req_rx_queues
);
1825 login_buffer
= kmalloc(buffer_size
, GFP_ATOMIC
);
1827 goto buf_alloc_failed
;
1829 buffer_token
= dma_map_single(dev
, login_buffer
, buffer_size
,
1831 if (dma_mapping_error(dev
, buffer_token
)) {
1832 dev_err(dev
, "Couldn't map login buffer\n");
1833 goto buf_map_failed
;
1836 rsp_buffer_size
= sizeof(struct ibmvnic_login_rsp_buffer
) +
1837 sizeof(u64
) * adapter
->req_tx_queues
+
1838 sizeof(u64
) * adapter
->req_rx_queues
+
1839 sizeof(u64
) * adapter
->req_rx_queues
+
1840 sizeof(u8
) * IBMVNIC_TX_DESC_VERSIONS
;
1842 login_rsp_buffer
= kmalloc(rsp_buffer_size
, GFP_ATOMIC
);
1843 if (!login_rsp_buffer
)
1844 goto buf_rsp_alloc_failed
;
1846 rsp_buffer_token
= dma_map_single(dev
, login_rsp_buffer
,
1847 rsp_buffer_size
, DMA_FROM_DEVICE
);
1848 if (dma_mapping_error(dev
, rsp_buffer_token
)) {
1849 dev_err(dev
, "Couldn't map login rsp buffer\n");
1850 goto buf_rsp_map_failed
;
1852 inflight_cmd
= kmalloc(sizeof(*inflight_cmd
), GFP_ATOMIC
);
1853 if (!inflight_cmd
) {
1854 dev_err(dev
, "Couldn't allocate inflight_cmd\n");
1855 goto inflight_alloc_failed
;
1857 adapter
->login_buf
= login_buffer
;
1858 adapter
->login_buf_token
= buffer_token
;
1859 adapter
->login_buf_sz
= buffer_size
;
1860 adapter
->login_rsp_buf
= login_rsp_buffer
;
1861 adapter
->login_rsp_buf_token
= rsp_buffer_token
;
1862 adapter
->login_rsp_buf_sz
= rsp_buffer_size
;
1864 login_buffer
->len
= cpu_to_be32(buffer_size
);
1865 login_buffer
->version
= cpu_to_be32(INITIAL_VERSION_LB
);
1866 login_buffer
->num_txcomp_subcrqs
= cpu_to_be32(adapter
->req_tx_queues
);
1867 login_buffer
->off_txcomp_subcrqs
=
1868 cpu_to_be32(sizeof(struct ibmvnic_login_buffer
));
1869 login_buffer
->num_rxcomp_subcrqs
= cpu_to_be32(adapter
->req_rx_queues
);
1870 login_buffer
->off_rxcomp_subcrqs
=
1871 cpu_to_be32(sizeof(struct ibmvnic_login_buffer
) +
1872 sizeof(u64
) * adapter
->req_tx_queues
);
1873 login_buffer
->login_rsp_ioba
= cpu_to_be32(rsp_buffer_token
);
1874 login_buffer
->login_rsp_len
= cpu_to_be32(rsp_buffer_size
);
1876 tx_list_p
= (__be64
*)((char *)login_buffer
+
1877 sizeof(struct ibmvnic_login_buffer
));
1878 rx_list_p
= (__be64
*)((char *)login_buffer
+
1879 sizeof(struct ibmvnic_login_buffer
) +
1880 sizeof(u64
) * adapter
->req_tx_queues
);
1882 for (i
= 0; i
< adapter
->req_tx_queues
; i
++) {
1883 if (adapter
->tx_scrq
[i
]) {
1884 tx_list_p
[i
] = cpu_to_be64(adapter
->tx_scrq
[i
]->
1889 for (i
= 0; i
< adapter
->req_rx_queues
; i
++) {
1890 if (adapter
->rx_scrq
[i
]) {
1891 rx_list_p
[i
] = cpu_to_be64(adapter
->rx_scrq
[i
]->
1896 netdev_dbg(adapter
->netdev
, "Login Buffer:\n");
1897 for (i
= 0; i
< (adapter
->login_buf_sz
- 1) / 8 + 1; i
++) {
1898 netdev_dbg(adapter
->netdev
, "%016lx\n",
1899 ((unsigned long int *)(adapter
->login_buf
))[i
]);
1902 memset(&crq
, 0, sizeof(crq
));
1903 crq
.login
.first
= IBMVNIC_CRQ_CMD
;
1904 crq
.login
.cmd
= LOGIN
;
1905 crq
.login
.ioba
= cpu_to_be32(buffer_token
);
1906 crq
.login
.len
= cpu_to_be32(buffer_size
);
1908 memcpy(&inflight_cmd
->crq
, &crq
, sizeof(crq
));
1910 spin_lock_irqsave(&adapter
->inflight_lock
, flags
);
1911 list_add_tail(&inflight_cmd
->list
, &adapter
->inflight
);
1912 spin_unlock_irqrestore(&adapter
->inflight_lock
, flags
);
1914 ibmvnic_send_crq(adapter
, &crq
);
1918 inflight_alloc_failed
:
1919 dma_unmap_single(dev
, rsp_buffer_token
, rsp_buffer_size
,
1922 kfree(login_rsp_buffer
);
1923 buf_rsp_alloc_failed
:
1924 dma_unmap_single(dev
, buffer_token
, buffer_size
, DMA_TO_DEVICE
);
1926 kfree(login_buffer
);
1931 static void send_request_map(struct ibmvnic_adapter
*adapter
, dma_addr_t addr
,
1934 union ibmvnic_crq crq
;
1936 memset(&crq
, 0, sizeof(crq
));
1937 crq
.request_map
.first
= IBMVNIC_CRQ_CMD
;
1938 crq
.request_map
.cmd
= REQUEST_MAP
;
1939 crq
.request_map
.map_id
= map_id
;
1940 crq
.request_map
.ioba
= cpu_to_be32(addr
);
1941 crq
.request_map
.len
= cpu_to_be32(len
);
1942 ibmvnic_send_crq(adapter
, &crq
);
1945 static void send_request_unmap(struct ibmvnic_adapter
*adapter
, u8 map_id
)
1947 union ibmvnic_crq crq
;
1949 memset(&crq
, 0, sizeof(crq
));
1950 crq
.request_unmap
.first
= IBMVNIC_CRQ_CMD
;
1951 crq
.request_unmap
.cmd
= REQUEST_UNMAP
;
1952 crq
.request_unmap
.map_id
= map_id
;
1953 ibmvnic_send_crq(adapter
, &crq
);
1956 static void send_map_query(struct ibmvnic_adapter
*adapter
)
1958 union ibmvnic_crq crq
;
1960 memset(&crq
, 0, sizeof(crq
));
1961 crq
.query_map
.first
= IBMVNIC_CRQ_CMD
;
1962 crq
.query_map
.cmd
= QUERY_MAP
;
1963 ibmvnic_send_crq(adapter
, &crq
);
1966 /* Send a series of CRQs requesting various capabilities of the VNIC server */
1967 static void send_cap_queries(struct ibmvnic_adapter
*adapter
)
1969 union ibmvnic_crq crq
;
1971 atomic_set(&adapter
->running_cap_queries
, 0);
1972 memset(&crq
, 0, sizeof(crq
));
1973 crq
.query_capability
.first
= IBMVNIC_CRQ_CMD
;
1974 crq
.query_capability
.cmd
= QUERY_CAPABILITY
;
1976 crq
.query_capability
.capability
= cpu_to_be16(MIN_TX_QUEUES
);
1977 atomic_inc(&adapter
->running_cap_queries
);
1978 ibmvnic_send_crq(adapter
, &crq
);
1980 crq
.query_capability
.capability
= cpu_to_be16(MIN_RX_QUEUES
);
1981 atomic_inc(&adapter
->running_cap_queries
);
1982 ibmvnic_send_crq(adapter
, &crq
);
1984 crq
.query_capability
.capability
= cpu_to_be16(MIN_RX_ADD_QUEUES
);
1985 atomic_inc(&adapter
->running_cap_queries
);
1986 ibmvnic_send_crq(adapter
, &crq
);
1988 crq
.query_capability
.capability
= cpu_to_be16(MAX_TX_QUEUES
);
1989 atomic_inc(&adapter
->running_cap_queries
);
1990 ibmvnic_send_crq(adapter
, &crq
);
1992 crq
.query_capability
.capability
= cpu_to_be16(MAX_RX_QUEUES
);
1993 atomic_inc(&adapter
->running_cap_queries
);
1994 ibmvnic_send_crq(adapter
, &crq
);
1996 crq
.query_capability
.capability
= cpu_to_be16(MAX_RX_ADD_QUEUES
);
1997 atomic_inc(&adapter
->running_cap_queries
);
1998 ibmvnic_send_crq(adapter
, &crq
);
2000 crq
.query_capability
.capability
=
2001 cpu_to_be16(MIN_TX_ENTRIES_PER_SUBCRQ
);
2002 atomic_inc(&adapter
->running_cap_queries
);
2003 ibmvnic_send_crq(adapter
, &crq
);
2005 crq
.query_capability
.capability
=
2006 cpu_to_be16(MIN_RX_ADD_ENTRIES_PER_SUBCRQ
);
2007 atomic_inc(&adapter
->running_cap_queries
);
2008 ibmvnic_send_crq(adapter
, &crq
);
2010 crq
.query_capability
.capability
=
2011 cpu_to_be16(MAX_TX_ENTRIES_PER_SUBCRQ
);
2012 atomic_inc(&adapter
->running_cap_queries
);
2013 ibmvnic_send_crq(adapter
, &crq
);
2015 crq
.query_capability
.capability
=
2016 cpu_to_be16(MAX_RX_ADD_ENTRIES_PER_SUBCRQ
);
2017 atomic_inc(&adapter
->running_cap_queries
);
2018 ibmvnic_send_crq(adapter
, &crq
);
2020 crq
.query_capability
.capability
= cpu_to_be16(TCP_IP_OFFLOAD
);
2021 atomic_inc(&adapter
->running_cap_queries
);
2022 ibmvnic_send_crq(adapter
, &crq
);
2024 crq
.query_capability
.capability
= cpu_to_be16(PROMISC_SUPPORTED
);
2025 atomic_inc(&adapter
->running_cap_queries
);
2026 ibmvnic_send_crq(adapter
, &crq
);
2028 crq
.query_capability
.capability
= cpu_to_be16(MIN_MTU
);
2029 atomic_inc(&adapter
->running_cap_queries
);
2030 ibmvnic_send_crq(adapter
, &crq
);
2032 crq
.query_capability
.capability
= cpu_to_be16(MAX_MTU
);
2033 atomic_inc(&adapter
->running_cap_queries
);
2034 ibmvnic_send_crq(adapter
, &crq
);
2036 crq
.query_capability
.capability
= cpu_to_be16(MAX_MULTICAST_FILTERS
);
2037 atomic_inc(&adapter
->running_cap_queries
);
2038 ibmvnic_send_crq(adapter
, &crq
);
2040 crq
.query_capability
.capability
= cpu_to_be16(VLAN_HEADER_INSERTION
);
2041 atomic_inc(&adapter
->running_cap_queries
);
2042 ibmvnic_send_crq(adapter
, &crq
);
2044 crq
.query_capability
.capability
= cpu_to_be16(MAX_TX_SG_ENTRIES
);
2045 atomic_inc(&adapter
->running_cap_queries
);
2046 ibmvnic_send_crq(adapter
, &crq
);
2048 crq
.query_capability
.capability
= cpu_to_be16(RX_SG_SUPPORTED
);
2049 atomic_inc(&adapter
->running_cap_queries
);
2050 ibmvnic_send_crq(adapter
, &crq
);
2052 crq
.query_capability
.capability
= cpu_to_be16(OPT_TX_COMP_SUB_QUEUES
);
2053 atomic_inc(&adapter
->running_cap_queries
);
2054 ibmvnic_send_crq(adapter
, &crq
);
2056 crq
.query_capability
.capability
= cpu_to_be16(OPT_RX_COMP_QUEUES
);
2057 atomic_inc(&adapter
->running_cap_queries
);
2058 ibmvnic_send_crq(adapter
, &crq
);
2060 crq
.query_capability
.capability
=
2061 cpu_to_be16(OPT_RX_BUFADD_Q_PER_RX_COMP_Q
);
2062 atomic_inc(&adapter
->running_cap_queries
);
2063 ibmvnic_send_crq(adapter
, &crq
);
2065 crq
.query_capability
.capability
=
2066 cpu_to_be16(OPT_TX_ENTRIES_PER_SUBCRQ
);
2067 atomic_inc(&adapter
->running_cap_queries
);
2068 ibmvnic_send_crq(adapter
, &crq
);
2070 crq
.query_capability
.capability
=
2071 cpu_to_be16(OPT_RXBA_ENTRIES_PER_SUBCRQ
);
2072 atomic_inc(&adapter
->running_cap_queries
);
2073 ibmvnic_send_crq(adapter
, &crq
);
2075 crq
.query_capability
.capability
= cpu_to_be16(TX_RX_DESC_REQ
);
2076 atomic_inc(&adapter
->running_cap_queries
);
2077 ibmvnic_send_crq(adapter
, &crq
);
2080 static void handle_query_ip_offload_rsp(struct ibmvnic_adapter
*adapter
)
2082 struct device
*dev
= &adapter
->vdev
->dev
;
2083 struct ibmvnic_query_ip_offload_buffer
*buf
= &adapter
->ip_offload_buf
;
2084 union ibmvnic_crq crq
;
2087 dma_unmap_single(dev
, adapter
->ip_offload_tok
,
2088 sizeof(adapter
->ip_offload_buf
), DMA_FROM_DEVICE
);
2090 netdev_dbg(adapter
->netdev
, "Query IP Offload Buffer:\n");
2091 for (i
= 0; i
< (sizeof(adapter
->ip_offload_buf
) - 1) / 8 + 1; i
++)
2092 netdev_dbg(adapter
->netdev
, "%016lx\n",
2093 ((unsigned long int *)(buf
))[i
]);
2095 netdev_dbg(adapter
->netdev
, "ipv4_chksum = %d\n", buf
->ipv4_chksum
);
2096 netdev_dbg(adapter
->netdev
, "ipv6_chksum = %d\n", buf
->ipv6_chksum
);
2097 netdev_dbg(adapter
->netdev
, "tcp_ipv4_chksum = %d\n",
2098 buf
->tcp_ipv4_chksum
);
2099 netdev_dbg(adapter
->netdev
, "tcp_ipv6_chksum = %d\n",
2100 buf
->tcp_ipv6_chksum
);
2101 netdev_dbg(adapter
->netdev
, "udp_ipv4_chksum = %d\n",
2102 buf
->udp_ipv4_chksum
);
2103 netdev_dbg(adapter
->netdev
, "udp_ipv6_chksum = %d\n",
2104 buf
->udp_ipv6_chksum
);
2105 netdev_dbg(adapter
->netdev
, "large_tx_ipv4 = %d\n",
2106 buf
->large_tx_ipv4
);
2107 netdev_dbg(adapter
->netdev
, "large_tx_ipv6 = %d\n",
2108 buf
->large_tx_ipv6
);
2109 netdev_dbg(adapter
->netdev
, "large_rx_ipv4 = %d\n",
2110 buf
->large_rx_ipv4
);
2111 netdev_dbg(adapter
->netdev
, "large_rx_ipv6 = %d\n",
2112 buf
->large_rx_ipv6
);
2113 netdev_dbg(adapter
->netdev
, "max_ipv4_hdr_sz = %d\n",
2114 buf
->max_ipv4_header_size
);
2115 netdev_dbg(adapter
->netdev
, "max_ipv6_hdr_sz = %d\n",
2116 buf
->max_ipv6_header_size
);
2117 netdev_dbg(adapter
->netdev
, "max_tcp_hdr_size = %d\n",
2118 buf
->max_tcp_header_size
);
2119 netdev_dbg(adapter
->netdev
, "max_udp_hdr_size = %d\n",
2120 buf
->max_udp_header_size
);
2121 netdev_dbg(adapter
->netdev
, "max_large_tx_size = %d\n",
2122 buf
->max_large_tx_size
);
2123 netdev_dbg(adapter
->netdev
, "max_large_rx_size = %d\n",
2124 buf
->max_large_rx_size
);
2125 netdev_dbg(adapter
->netdev
, "ipv6_ext_hdr = %d\n",
2126 buf
->ipv6_extension_header
);
2127 netdev_dbg(adapter
->netdev
, "tcp_pseudosum_req = %d\n",
2128 buf
->tcp_pseudosum_req
);
2129 netdev_dbg(adapter
->netdev
, "num_ipv6_ext_hd = %d\n",
2130 buf
->num_ipv6_ext_headers
);
2131 netdev_dbg(adapter
->netdev
, "off_ipv6_ext_hd = %d\n",
2132 buf
->off_ipv6_ext_headers
);
2134 adapter
->ip_offload_ctrl_tok
=
2135 dma_map_single(dev
, &adapter
->ip_offload_ctrl
,
2136 sizeof(adapter
->ip_offload_ctrl
), DMA_TO_DEVICE
);
2138 if (dma_mapping_error(dev
, adapter
->ip_offload_ctrl_tok
)) {
2139 dev_err(dev
, "Couldn't map ip offload control buffer\n");
2143 adapter
->ip_offload_ctrl
.version
= cpu_to_be32(INITIAL_VERSION_IOB
);
2144 adapter
->ip_offload_ctrl
.tcp_ipv4_chksum
= buf
->tcp_ipv4_chksum
;
2145 adapter
->ip_offload_ctrl
.udp_ipv4_chksum
= buf
->udp_ipv4_chksum
;
2146 adapter
->ip_offload_ctrl
.tcp_ipv6_chksum
= buf
->tcp_ipv6_chksum
;
2147 adapter
->ip_offload_ctrl
.udp_ipv6_chksum
= buf
->udp_ipv6_chksum
;
2149 /* large_tx/rx disabled for now, additional features needed */
2150 adapter
->ip_offload_ctrl
.large_tx_ipv4
= 0;
2151 adapter
->ip_offload_ctrl
.large_tx_ipv6
= 0;
2152 adapter
->ip_offload_ctrl
.large_rx_ipv4
= 0;
2153 adapter
->ip_offload_ctrl
.large_rx_ipv6
= 0;
2155 adapter
->netdev
->features
= NETIF_F_GSO
;
2157 if (buf
->tcp_ipv4_chksum
|| buf
->udp_ipv4_chksum
)
2158 adapter
->netdev
->features
|= NETIF_F_IP_CSUM
;
2160 if (buf
->tcp_ipv6_chksum
|| buf
->udp_ipv6_chksum
)
2161 adapter
->netdev
->features
|= NETIF_F_IPV6_CSUM
;
2163 if ((adapter
->netdev
->features
&
2164 (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
)))
2165 adapter
->netdev
->features
|= NETIF_F_RXCSUM
;
2167 memset(&crq
, 0, sizeof(crq
));
2168 crq
.control_ip_offload
.first
= IBMVNIC_CRQ_CMD
;
2169 crq
.control_ip_offload
.cmd
= CONTROL_IP_OFFLOAD
;
2170 crq
.control_ip_offload
.len
=
2171 cpu_to_be32(sizeof(adapter
->ip_offload_ctrl
));
2172 crq
.control_ip_offload
.ioba
= cpu_to_be32(adapter
->ip_offload_ctrl_tok
);
2173 ibmvnic_send_crq(adapter
, &crq
);
2176 static void handle_error_info_rsp(union ibmvnic_crq
*crq
,
2177 struct ibmvnic_adapter
*adapter
)
2179 struct device
*dev
= &adapter
->vdev
->dev
;
2180 struct ibmvnic_error_buff
*error_buff
, *tmp
;
2181 unsigned long flags
;
2185 if (!crq
->request_error_rsp
.rc
.code
) {
2186 dev_info(dev
, "Request Error Rsp returned with rc=%x\n",
2187 crq
->request_error_rsp
.rc
.code
);
2191 spin_lock_irqsave(&adapter
->error_list_lock
, flags
);
2192 list_for_each_entry_safe(error_buff
, tmp
, &adapter
->errors
, list
)
2193 if (error_buff
->error_id
== crq
->request_error_rsp
.error_id
) {
2195 list_del(&error_buff
->list
);
2198 spin_unlock_irqrestore(&adapter
->error_list_lock
, flags
);
2201 dev_err(dev
, "Couldn't find error id %x\n",
2202 crq
->request_error_rsp
.error_id
);
2206 dev_err(dev
, "Detailed info for error id %x:",
2207 crq
->request_error_rsp
.error_id
);
2209 for (i
= 0; i
< error_buff
->len
; i
++) {
2210 pr_cont("%02x", (int)error_buff
->buff
[i
]);
2216 dma_unmap_single(dev
, error_buff
->dma
, error_buff
->len
,
2218 kfree(error_buff
->buff
);
2222 static void handle_dump_size_rsp(union ibmvnic_crq
*crq
,
2223 struct ibmvnic_adapter
*adapter
)
2225 int len
= be32_to_cpu(crq
->request_dump_size_rsp
.len
);
2226 struct ibmvnic_inflight_cmd
*inflight_cmd
;
2227 struct device
*dev
= &adapter
->vdev
->dev
;
2228 union ibmvnic_crq newcrq
;
2229 unsigned long flags
;
2231 /* allocate and map buffer */
2232 adapter
->dump_data
= kmalloc(len
, GFP_KERNEL
);
2233 if (!adapter
->dump_data
) {
2234 complete(&adapter
->fw_done
);
2238 adapter
->dump_data_token
= dma_map_single(dev
, adapter
->dump_data
, len
,
2241 if (dma_mapping_error(dev
, adapter
->dump_data_token
)) {
2242 if (!firmware_has_feature(FW_FEATURE_CMO
))
2243 dev_err(dev
, "Couldn't map dump data\n");
2244 kfree(adapter
->dump_data
);
2245 complete(&adapter
->fw_done
);
2249 inflight_cmd
= kmalloc(sizeof(*inflight_cmd
), GFP_ATOMIC
);
2250 if (!inflight_cmd
) {
2251 dma_unmap_single(dev
, adapter
->dump_data_token
, len
,
2253 kfree(adapter
->dump_data
);
2254 complete(&adapter
->fw_done
);
2258 memset(&newcrq
, 0, sizeof(newcrq
));
2259 newcrq
.request_dump
.first
= IBMVNIC_CRQ_CMD
;
2260 newcrq
.request_dump
.cmd
= REQUEST_DUMP
;
2261 newcrq
.request_dump
.ioba
= cpu_to_be32(adapter
->dump_data_token
);
2262 newcrq
.request_dump
.len
= cpu_to_be32(adapter
->dump_data_size
);
2264 memcpy(&inflight_cmd
->crq
, &newcrq
, sizeof(newcrq
));
2266 spin_lock_irqsave(&adapter
->inflight_lock
, flags
);
2267 list_add_tail(&inflight_cmd
->list
, &adapter
->inflight
);
2268 spin_unlock_irqrestore(&adapter
->inflight_lock
, flags
);
2270 ibmvnic_send_crq(adapter
, &newcrq
);
2273 static void handle_error_indication(union ibmvnic_crq
*crq
,
2274 struct ibmvnic_adapter
*adapter
)
2276 int detail_len
= be32_to_cpu(crq
->error_indication
.detail_error_sz
);
2277 struct ibmvnic_inflight_cmd
*inflight_cmd
;
2278 struct device
*dev
= &adapter
->vdev
->dev
;
2279 struct ibmvnic_error_buff
*error_buff
;
2280 union ibmvnic_crq new_crq
;
2281 unsigned long flags
;
2283 dev_err(dev
, "Firmware reports %serror id %x, cause %d\n",
2284 crq
->error_indication
.
2285 flags
& IBMVNIC_FATAL_ERROR
? "FATAL " : "",
2286 crq
->error_indication
.error_id
,
2287 crq
->error_indication
.error_cause
);
2289 error_buff
= kmalloc(sizeof(*error_buff
), GFP_ATOMIC
);
2293 error_buff
->buff
= kmalloc(detail_len
, GFP_ATOMIC
);
2294 if (!error_buff
->buff
) {
2299 error_buff
->dma
= dma_map_single(dev
, error_buff
->buff
, detail_len
,
2301 if (dma_mapping_error(dev
, error_buff
->dma
)) {
2302 if (!firmware_has_feature(FW_FEATURE_CMO
))
2303 dev_err(dev
, "Couldn't map error buffer\n");
2304 kfree(error_buff
->buff
);
2309 inflight_cmd
= kmalloc(sizeof(*inflight_cmd
), GFP_ATOMIC
);
2310 if (!inflight_cmd
) {
2311 dma_unmap_single(dev
, error_buff
->dma
, detail_len
,
2313 kfree(error_buff
->buff
);
2318 error_buff
->len
= detail_len
;
2319 error_buff
->error_id
= crq
->error_indication
.error_id
;
2321 spin_lock_irqsave(&adapter
->error_list_lock
, flags
);
2322 list_add_tail(&error_buff
->list
, &adapter
->errors
);
2323 spin_unlock_irqrestore(&adapter
->error_list_lock
, flags
);
2325 memset(&new_crq
, 0, sizeof(new_crq
));
2326 new_crq
.request_error_info
.first
= IBMVNIC_CRQ_CMD
;
2327 new_crq
.request_error_info
.cmd
= REQUEST_ERROR_INFO
;
2328 new_crq
.request_error_info
.ioba
= cpu_to_be32(error_buff
->dma
);
2329 new_crq
.request_error_info
.len
= cpu_to_be32(detail_len
);
2330 new_crq
.request_error_info
.error_id
= crq
->error_indication
.error_id
;
2332 memcpy(&inflight_cmd
->crq
, &crq
, sizeof(crq
));
2334 spin_lock_irqsave(&adapter
->inflight_lock
, flags
);
2335 list_add_tail(&inflight_cmd
->list
, &adapter
->inflight
);
2336 spin_unlock_irqrestore(&adapter
->inflight_lock
, flags
);
2338 ibmvnic_send_crq(adapter
, &new_crq
);
2341 static void handle_change_mac_rsp(union ibmvnic_crq
*crq
,
2342 struct ibmvnic_adapter
*adapter
)
2344 struct net_device
*netdev
= adapter
->netdev
;
2345 struct device
*dev
= &adapter
->vdev
->dev
;
2348 rc
= crq
->change_mac_addr_rsp
.rc
.code
;
2350 dev_err(dev
, "Error %ld in CHANGE_MAC_ADDR_RSP\n", rc
);
2353 memcpy(netdev
->dev_addr
, &crq
->change_mac_addr_rsp
.mac_addr
[0],
2357 static void handle_request_cap_rsp(union ibmvnic_crq
*crq
,
2358 struct ibmvnic_adapter
*adapter
)
2360 struct device
*dev
= &adapter
->vdev
->dev
;
2364 switch (be16_to_cpu(crq
->request_capability_rsp
.capability
)) {
2366 req_value
= &adapter
->req_tx_queues
;
2370 req_value
= &adapter
->req_rx_queues
;
2373 case REQ_RX_ADD_QUEUES
:
2374 req_value
= &adapter
->req_rx_add_queues
;
2377 case REQ_TX_ENTRIES_PER_SUBCRQ
:
2378 req_value
= &adapter
->req_tx_entries_per_subcrq
;
2379 name
= "tx_entries_per_subcrq";
2381 case REQ_RX_ADD_ENTRIES_PER_SUBCRQ
:
2382 req_value
= &adapter
->req_rx_add_entries_per_subcrq
;
2383 name
= "rx_add_entries_per_subcrq";
2386 req_value
= &adapter
->req_mtu
;
2389 case PROMISC_REQUESTED
:
2390 req_value
= &adapter
->promisc
;
2394 dev_err(dev
, "Got invalid cap request rsp %d\n",
2395 crq
->request_capability
.capability
);
2399 switch (crq
->request_capability_rsp
.rc
.code
) {
2402 case PARTIALSUCCESS
:
2403 dev_info(dev
, "req=%lld, rsp=%ld in %s queue, retrying.\n",
2405 (long int)be32_to_cpu(crq
->request_capability_rsp
.
2407 release_sub_crqs_no_irqs(adapter
);
2408 *req_value
= be32_to_cpu(crq
->request_capability_rsp
.number
);
2409 init_sub_crqs(adapter
, 1);
2412 dev_err(dev
, "Error %d in request cap rsp\n",
2413 crq
->request_capability_rsp
.rc
.code
);
2417 /* Done receiving requested capabilities, query IP offload support */
2418 if (++adapter
->requested_caps
== 7) {
2419 union ibmvnic_crq newcrq
;
2420 int buf_sz
= sizeof(struct ibmvnic_query_ip_offload_buffer
);
2421 struct ibmvnic_query_ip_offload_buffer
*ip_offload_buf
=
2422 &adapter
->ip_offload_buf
;
2424 adapter
->ip_offload_tok
= dma_map_single(dev
, ip_offload_buf
,
2428 if (dma_mapping_error(dev
, adapter
->ip_offload_tok
)) {
2429 if (!firmware_has_feature(FW_FEATURE_CMO
))
2430 dev_err(dev
, "Couldn't map offload buffer\n");
2434 memset(&newcrq
, 0, sizeof(newcrq
));
2435 newcrq
.query_ip_offload
.first
= IBMVNIC_CRQ_CMD
;
2436 newcrq
.query_ip_offload
.cmd
= QUERY_IP_OFFLOAD
;
2437 newcrq
.query_ip_offload
.len
= cpu_to_be32(buf_sz
);
2438 newcrq
.query_ip_offload
.ioba
=
2439 cpu_to_be32(adapter
->ip_offload_tok
);
2441 ibmvnic_send_crq(adapter
, &newcrq
);
2445 static int handle_login_rsp(union ibmvnic_crq
*login_rsp_crq
,
2446 struct ibmvnic_adapter
*adapter
)
2448 struct device
*dev
= &adapter
->vdev
->dev
;
2449 struct ibmvnic_login_rsp_buffer
*login_rsp
= adapter
->login_rsp_buf
;
2450 struct ibmvnic_login_buffer
*login
= adapter
->login_buf
;
2451 union ibmvnic_crq crq
;
2454 dma_unmap_single(dev
, adapter
->login_buf_token
, adapter
->login_buf_sz
,
2456 dma_unmap_single(dev
, adapter
->login_rsp_buf_token
,
2457 adapter
->login_rsp_buf_sz
, DMA_BIDIRECTIONAL
);
2459 /* If the number of queues requested can't be allocated by the
2460 * server, the login response will return with code 1. We will need
2461 * to resend the login buffer with fewer queues requested.
2463 if (login_rsp_crq
->generic
.rc
.code
) {
2464 adapter
->renegotiate
= true;
2465 complete(&adapter
->init_done
);
2469 netdev_dbg(adapter
->netdev
, "Login Response Buffer:\n");
2470 for (i
= 0; i
< (adapter
->login_rsp_buf_sz
- 1) / 8 + 1; i
++) {
2471 netdev_dbg(adapter
->netdev
, "%016lx\n",
2472 ((unsigned long int *)(adapter
->login_rsp_buf
))[i
]);
2476 if (login
->num_txcomp_subcrqs
!= login_rsp
->num_txsubm_subcrqs
||
2477 (be32_to_cpu(login
->num_rxcomp_subcrqs
) *
2478 adapter
->req_rx_add_queues
!=
2479 be32_to_cpu(login_rsp
->num_rxadd_subcrqs
))) {
2480 dev_err(dev
, "FATAL: Inconsistent login and login rsp\n");
2481 ibmvnic_remove(adapter
->vdev
);
2484 complete(&adapter
->init_done
);
2486 memset(&crq
, 0, sizeof(crq
));
2487 crq
.request_ras_comp_num
.first
= IBMVNIC_CRQ_CMD
;
2488 crq
.request_ras_comp_num
.cmd
= REQUEST_RAS_COMP_NUM
;
2489 ibmvnic_send_crq(adapter
, &crq
);
2494 static void handle_request_map_rsp(union ibmvnic_crq
*crq
,
2495 struct ibmvnic_adapter
*adapter
)
2497 struct device
*dev
= &adapter
->vdev
->dev
;
2498 u8 map_id
= crq
->request_map_rsp
.map_id
;
2504 tx_subcrqs
= be32_to_cpu(adapter
->login_rsp_buf
->num_txsubm_subcrqs
);
2505 rx_subcrqs
= be32_to_cpu(adapter
->login_rsp_buf
->num_rxadd_subcrqs
);
2507 rc
= crq
->request_map_rsp
.rc
.code
;
2509 dev_err(dev
, "Error %ld in REQUEST_MAP_RSP\n", rc
);
2511 /* need to find and zero tx/rx_pool map_id */
2512 for (i
= 0; i
< tx_subcrqs
; i
++) {
2513 if (adapter
->tx_pool
[i
].long_term_buff
.map_id
== map_id
)
2514 adapter
->tx_pool
[i
].long_term_buff
.map_id
= 0;
2516 for (i
= 0; i
< rx_subcrqs
; i
++) {
2517 if (adapter
->rx_pool
[i
].long_term_buff
.map_id
== map_id
)
2518 adapter
->rx_pool
[i
].long_term_buff
.map_id
= 0;
2521 complete(&adapter
->fw_done
);
2524 static void handle_request_unmap_rsp(union ibmvnic_crq
*crq
,
2525 struct ibmvnic_adapter
*adapter
)
2527 struct device
*dev
= &adapter
->vdev
->dev
;
2530 rc
= crq
->request_unmap_rsp
.rc
.code
;
2532 dev_err(dev
, "Error %ld in REQUEST_UNMAP_RSP\n", rc
);
2535 static void handle_query_map_rsp(union ibmvnic_crq
*crq
,
2536 struct ibmvnic_adapter
*adapter
)
2538 struct net_device
*netdev
= adapter
->netdev
;
2539 struct device
*dev
= &adapter
->vdev
->dev
;
2542 rc
= crq
->query_map_rsp
.rc
.code
;
2544 dev_err(dev
, "Error %ld in QUERY_MAP_RSP\n", rc
);
2547 netdev_dbg(netdev
, "page_size = %d\ntot_pages = %d\nfree_pages = %d\n",
2548 crq
->query_map_rsp
.page_size
, crq
->query_map_rsp
.tot_pages
,
2549 crq
->query_map_rsp
.free_pages
);
2552 static void handle_query_cap_rsp(union ibmvnic_crq
*crq
,
2553 struct ibmvnic_adapter
*adapter
)
2555 struct net_device
*netdev
= adapter
->netdev
;
2556 struct device
*dev
= &adapter
->vdev
->dev
;
2559 atomic_dec(&adapter
->running_cap_queries
);
2560 netdev_dbg(netdev
, "Outstanding queries: %d\n",
2561 atomic_read(&adapter
->running_cap_queries
));
2562 rc
= crq
->query_capability
.rc
.code
;
2564 dev_err(dev
, "Error %ld in QUERY_CAP_RSP\n", rc
);
2568 switch (be16_to_cpu(crq
->query_capability
.capability
)) {
2570 adapter
->min_tx_queues
=
2571 be64_to_cpu(crq
->query_capability
.number
);
2572 netdev_dbg(netdev
, "min_tx_queues = %lld\n",
2573 adapter
->min_tx_queues
);
2576 adapter
->min_rx_queues
=
2577 be64_to_cpu(crq
->query_capability
.number
);
2578 netdev_dbg(netdev
, "min_rx_queues = %lld\n",
2579 adapter
->min_rx_queues
);
2581 case MIN_RX_ADD_QUEUES
:
2582 adapter
->min_rx_add_queues
=
2583 be64_to_cpu(crq
->query_capability
.number
);
2584 netdev_dbg(netdev
, "min_rx_add_queues = %lld\n",
2585 adapter
->min_rx_add_queues
);
2588 adapter
->max_tx_queues
=
2589 be64_to_cpu(crq
->query_capability
.number
);
2590 netdev_dbg(netdev
, "max_tx_queues = %lld\n",
2591 adapter
->max_tx_queues
);
2594 adapter
->max_rx_queues
=
2595 be64_to_cpu(crq
->query_capability
.number
);
2596 netdev_dbg(netdev
, "max_rx_queues = %lld\n",
2597 adapter
->max_rx_queues
);
2599 case MAX_RX_ADD_QUEUES
:
2600 adapter
->max_rx_add_queues
=
2601 be64_to_cpu(crq
->query_capability
.number
);
2602 netdev_dbg(netdev
, "max_rx_add_queues = %lld\n",
2603 adapter
->max_rx_add_queues
);
2605 case MIN_TX_ENTRIES_PER_SUBCRQ
:
2606 adapter
->min_tx_entries_per_subcrq
=
2607 be64_to_cpu(crq
->query_capability
.number
);
2608 netdev_dbg(netdev
, "min_tx_entries_per_subcrq = %lld\n",
2609 adapter
->min_tx_entries_per_subcrq
);
2611 case MIN_RX_ADD_ENTRIES_PER_SUBCRQ
:
2612 adapter
->min_rx_add_entries_per_subcrq
=
2613 be64_to_cpu(crq
->query_capability
.number
);
2614 netdev_dbg(netdev
, "min_rx_add_entrs_per_subcrq = %lld\n",
2615 adapter
->min_rx_add_entries_per_subcrq
);
2617 case MAX_TX_ENTRIES_PER_SUBCRQ
:
2618 adapter
->max_tx_entries_per_subcrq
=
2619 be64_to_cpu(crq
->query_capability
.number
);
2620 netdev_dbg(netdev
, "max_tx_entries_per_subcrq = %lld\n",
2621 adapter
->max_tx_entries_per_subcrq
);
2623 case MAX_RX_ADD_ENTRIES_PER_SUBCRQ
:
2624 adapter
->max_rx_add_entries_per_subcrq
=
2625 be64_to_cpu(crq
->query_capability
.number
);
2626 netdev_dbg(netdev
, "max_rx_add_entrs_per_subcrq = %lld\n",
2627 adapter
->max_rx_add_entries_per_subcrq
);
2629 case TCP_IP_OFFLOAD
:
2630 adapter
->tcp_ip_offload
=
2631 be64_to_cpu(crq
->query_capability
.number
);
2632 netdev_dbg(netdev
, "tcp_ip_offload = %lld\n",
2633 adapter
->tcp_ip_offload
);
2635 case PROMISC_SUPPORTED
:
2636 adapter
->promisc_supported
=
2637 be64_to_cpu(crq
->query_capability
.number
);
2638 netdev_dbg(netdev
, "promisc_supported = %lld\n",
2639 adapter
->promisc_supported
);
2642 adapter
->min_mtu
= be64_to_cpu(crq
->query_capability
.number
);
2643 netdev_dbg(netdev
, "min_mtu = %lld\n", adapter
->min_mtu
);
2646 adapter
->max_mtu
= be64_to_cpu(crq
->query_capability
.number
);
2647 netdev_dbg(netdev
, "max_mtu = %lld\n", adapter
->max_mtu
);
2649 case MAX_MULTICAST_FILTERS
:
2650 adapter
->max_multicast_filters
=
2651 be64_to_cpu(crq
->query_capability
.number
);
2652 netdev_dbg(netdev
, "max_multicast_filters = %lld\n",
2653 adapter
->max_multicast_filters
);
2655 case VLAN_HEADER_INSERTION
:
2656 adapter
->vlan_header_insertion
=
2657 be64_to_cpu(crq
->query_capability
.number
);
2658 if (adapter
->vlan_header_insertion
)
2659 netdev
->features
|= NETIF_F_HW_VLAN_STAG_TX
;
2660 netdev_dbg(netdev
, "vlan_header_insertion = %lld\n",
2661 adapter
->vlan_header_insertion
);
2663 case MAX_TX_SG_ENTRIES
:
2664 adapter
->max_tx_sg_entries
=
2665 be64_to_cpu(crq
->query_capability
.number
);
2666 netdev_dbg(netdev
, "max_tx_sg_entries = %lld\n",
2667 adapter
->max_tx_sg_entries
);
2669 case RX_SG_SUPPORTED
:
2670 adapter
->rx_sg_supported
=
2671 be64_to_cpu(crq
->query_capability
.number
);
2672 netdev_dbg(netdev
, "rx_sg_supported = %lld\n",
2673 adapter
->rx_sg_supported
);
2675 case OPT_TX_COMP_SUB_QUEUES
:
2676 adapter
->opt_tx_comp_sub_queues
=
2677 be64_to_cpu(crq
->query_capability
.number
);
2678 netdev_dbg(netdev
, "opt_tx_comp_sub_queues = %lld\n",
2679 adapter
->opt_tx_comp_sub_queues
);
2681 case OPT_RX_COMP_QUEUES
:
2682 adapter
->opt_rx_comp_queues
=
2683 be64_to_cpu(crq
->query_capability
.number
);
2684 netdev_dbg(netdev
, "opt_rx_comp_queues = %lld\n",
2685 adapter
->opt_rx_comp_queues
);
2687 case OPT_RX_BUFADD_Q_PER_RX_COMP_Q
:
2688 adapter
->opt_rx_bufadd_q_per_rx_comp_q
=
2689 be64_to_cpu(crq
->query_capability
.number
);
2690 netdev_dbg(netdev
, "opt_rx_bufadd_q_per_rx_comp_q = %lld\n",
2691 adapter
->opt_rx_bufadd_q_per_rx_comp_q
);
2693 case OPT_TX_ENTRIES_PER_SUBCRQ
:
2694 adapter
->opt_tx_entries_per_subcrq
=
2695 be64_to_cpu(crq
->query_capability
.number
);
2696 netdev_dbg(netdev
, "opt_tx_entries_per_subcrq = %lld\n",
2697 adapter
->opt_tx_entries_per_subcrq
);
2699 case OPT_RXBA_ENTRIES_PER_SUBCRQ
:
2700 adapter
->opt_rxba_entries_per_subcrq
=
2701 be64_to_cpu(crq
->query_capability
.number
);
2702 netdev_dbg(netdev
, "opt_rxba_entries_per_subcrq = %lld\n",
2703 adapter
->opt_rxba_entries_per_subcrq
);
2705 case TX_RX_DESC_REQ
:
2706 adapter
->tx_rx_desc_req
= crq
->query_capability
.number
;
2707 netdev_dbg(netdev
, "tx_rx_desc_req = %llx\n",
2708 adapter
->tx_rx_desc_req
);
2712 netdev_err(netdev
, "Got invalid cap rsp %d\n",
2713 crq
->query_capability
.capability
);
2717 if (atomic_read(&adapter
->running_cap_queries
) == 0)
2718 init_sub_crqs(adapter
, 0);
2719 /* We're done querying the capabilities, initialize sub-crqs */
2722 static void handle_control_ras_rsp(union ibmvnic_crq
*crq
,
2723 struct ibmvnic_adapter
*adapter
)
2725 u8 correlator
= crq
->control_ras_rsp
.correlator
;
2726 struct device
*dev
= &adapter
->vdev
->dev
;
2730 if (crq
->control_ras_rsp
.rc
.code
) {
2731 dev_warn(dev
, "Control ras failed rc=%d\n",
2732 crq
->control_ras_rsp
.rc
.code
);
2736 for (i
= 0; i
< adapter
->ras_comp_num
; i
++) {
2737 if (adapter
->ras_comps
[i
].correlator
== correlator
) {
2744 dev_warn(dev
, "Correlator not found on control_ras_rsp\n");
2748 switch (crq
->control_ras_rsp
.op
) {
2749 case IBMVNIC_TRACE_LEVEL
:
2750 adapter
->ras_comps
[i
].trace_level
= crq
->control_ras
.level
;
2752 case IBMVNIC_ERROR_LEVEL
:
2753 adapter
->ras_comps
[i
].error_check_level
=
2754 crq
->control_ras
.level
;
2756 case IBMVNIC_TRACE_PAUSE
:
2757 adapter
->ras_comp_int
[i
].paused
= 1;
2759 case IBMVNIC_TRACE_RESUME
:
2760 adapter
->ras_comp_int
[i
].paused
= 0;
2762 case IBMVNIC_TRACE_ON
:
2763 adapter
->ras_comps
[i
].trace_on
= 1;
2765 case IBMVNIC_TRACE_OFF
:
2766 adapter
->ras_comps
[i
].trace_on
= 0;
2768 case IBMVNIC_CHG_TRACE_BUFF_SZ
:
2769 /* trace_buff_sz is 3 bytes, stuff it into an int */
2770 ((u8
*)(&adapter
->ras_comps
[i
].trace_buff_size
))[0] = 0;
2771 ((u8
*)(&adapter
->ras_comps
[i
].trace_buff_size
))[1] =
2772 crq
->control_ras_rsp
.trace_buff_sz
[0];
2773 ((u8
*)(&adapter
->ras_comps
[i
].trace_buff_size
))[2] =
2774 crq
->control_ras_rsp
.trace_buff_sz
[1];
2775 ((u8
*)(&adapter
->ras_comps
[i
].trace_buff_size
))[3] =
2776 crq
->control_ras_rsp
.trace_buff_sz
[2];
2779 dev_err(dev
, "invalid op %d on control_ras_rsp",
2780 crq
->control_ras_rsp
.op
);
2784 static ssize_t
trace_read(struct file
*file
, char __user
*user_buf
, size_t len
,
2787 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2788 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2789 struct device
*dev
= &adapter
->vdev
->dev
;
2790 struct ibmvnic_fw_trace_entry
*trace
;
2791 int num
= ras_comp_int
->num
;
2792 union ibmvnic_crq crq
;
2793 dma_addr_t trace_tok
;
2795 if (*ppos
>= be32_to_cpu(adapter
->ras_comps
[num
].trace_buff_size
))
2799 dma_alloc_coherent(dev
,
2800 be32_to_cpu(adapter
->ras_comps
[num
].
2801 trace_buff_size
), &trace_tok
,
2804 dev_err(dev
, "Couldn't alloc trace buffer\n");
2808 memset(&crq
, 0, sizeof(crq
));
2809 crq
.collect_fw_trace
.first
= IBMVNIC_CRQ_CMD
;
2810 crq
.collect_fw_trace
.cmd
= COLLECT_FW_TRACE
;
2811 crq
.collect_fw_trace
.correlator
= adapter
->ras_comps
[num
].correlator
;
2812 crq
.collect_fw_trace
.ioba
= cpu_to_be32(trace_tok
);
2813 crq
.collect_fw_trace
.len
= adapter
->ras_comps
[num
].trace_buff_size
;
2814 ibmvnic_send_crq(adapter
, &crq
);
2816 init_completion(&adapter
->fw_done
);
2817 wait_for_completion(&adapter
->fw_done
);
2819 if (*ppos
+ len
> be32_to_cpu(adapter
->ras_comps
[num
].trace_buff_size
))
2821 be32_to_cpu(adapter
->ras_comps
[num
].trace_buff_size
) -
2824 copy_to_user(user_buf
, &((u8
*)trace
)[*ppos
], len
);
2826 dma_free_coherent(dev
,
2827 be32_to_cpu(adapter
->ras_comps
[num
].trace_buff_size
),
2833 static const struct file_operations trace_ops
= {
2834 .owner
= THIS_MODULE
,
2835 .open
= simple_open
,
2839 static ssize_t
paused_read(struct file
*file
, char __user
*user_buf
, size_t len
,
2842 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2843 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2844 int num
= ras_comp_int
->num
;
2845 char buff
[5]; /* 1 or 0 plus \n and \0 */
2848 size
= sprintf(buff
, "%d\n", adapter
->ras_comp_int
[num
].paused
);
2853 copy_to_user(user_buf
, buff
, size
);
2858 static ssize_t
paused_write(struct file
*file
, const char __user
*user_buf
,
2859 size_t len
, loff_t
*ppos
)
2861 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2862 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2863 int num
= ras_comp_int
->num
;
2864 union ibmvnic_crq crq
;
2866 char buff
[9]; /* decimal max int plus \n and \0 */
2868 copy_from_user(buff
, user_buf
, sizeof(buff
));
2869 val
= kstrtoul(buff
, 10, NULL
);
2871 adapter
->ras_comp_int
[num
].paused
= val
? 1 : 0;
2873 memset(&crq
, 0, sizeof(crq
));
2874 crq
.control_ras
.first
= IBMVNIC_CRQ_CMD
;
2875 crq
.control_ras
.cmd
= CONTROL_RAS
;
2876 crq
.control_ras
.correlator
= adapter
->ras_comps
[num
].correlator
;
2877 crq
.control_ras
.op
= val
? IBMVNIC_TRACE_PAUSE
: IBMVNIC_TRACE_RESUME
;
2878 ibmvnic_send_crq(adapter
, &crq
);
2883 static const struct file_operations paused_ops
= {
2884 .owner
= THIS_MODULE
,
2885 .open
= simple_open
,
2886 .read
= paused_read
,
2887 .write
= paused_write
,
2890 static ssize_t
tracing_read(struct file
*file
, char __user
*user_buf
,
2891 size_t len
, loff_t
*ppos
)
2893 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2894 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2895 int num
= ras_comp_int
->num
;
2896 char buff
[5]; /* 1 or 0 plus \n and \0 */
2899 size
= sprintf(buff
, "%d\n", adapter
->ras_comps
[num
].trace_on
);
2904 copy_to_user(user_buf
, buff
, size
);
2909 static ssize_t
tracing_write(struct file
*file
, const char __user
*user_buf
,
2910 size_t len
, loff_t
*ppos
)
2912 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2913 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2914 int num
= ras_comp_int
->num
;
2915 union ibmvnic_crq crq
;
2917 char buff
[9]; /* decimal max int plus \n and \0 */
2919 copy_from_user(buff
, user_buf
, sizeof(buff
));
2920 val
= kstrtoul(buff
, 10, NULL
);
2922 memset(&crq
, 0, sizeof(crq
));
2923 crq
.control_ras
.first
= IBMVNIC_CRQ_CMD
;
2924 crq
.control_ras
.cmd
= CONTROL_RAS
;
2925 crq
.control_ras
.correlator
= adapter
->ras_comps
[num
].correlator
;
2926 crq
.control_ras
.op
= val
? IBMVNIC_TRACE_ON
: IBMVNIC_TRACE_OFF
;
2931 static const struct file_operations tracing_ops
= {
2932 .owner
= THIS_MODULE
,
2933 .open
= simple_open
,
2934 .read
= tracing_read
,
2935 .write
= tracing_write
,
2938 static ssize_t
error_level_read(struct file
*file
, 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 char buff
[5]; /* decimal max char plus \n and \0 */
2947 size
= sprintf(buff
, "%d\n", adapter
->ras_comps
[num
].error_check_level
);
2952 copy_to_user(user_buf
, buff
, size
);
2957 static ssize_t
error_level_write(struct file
*file
, const char __user
*user_buf
,
2958 size_t len
, loff_t
*ppos
)
2960 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2961 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2962 int num
= ras_comp_int
->num
;
2963 union ibmvnic_crq crq
;
2965 char buff
[9]; /* decimal max int plus \n and \0 */
2967 copy_from_user(buff
, user_buf
, sizeof(buff
));
2968 val
= kstrtoul(buff
, 10, NULL
);
2973 memset(&crq
, 0, sizeof(crq
));
2974 crq
.control_ras
.first
= IBMVNIC_CRQ_CMD
;
2975 crq
.control_ras
.cmd
= CONTROL_RAS
;
2976 crq
.control_ras
.correlator
= adapter
->ras_comps
[num
].correlator
;
2977 crq
.control_ras
.op
= IBMVNIC_ERROR_LEVEL
;
2978 crq
.control_ras
.level
= val
;
2979 ibmvnic_send_crq(adapter
, &crq
);
2984 static const struct file_operations error_level_ops
= {
2985 .owner
= THIS_MODULE
,
2986 .open
= simple_open
,
2987 .read
= error_level_read
,
2988 .write
= error_level_write
,
2991 static ssize_t
trace_level_read(struct file
*file
, char __user
*user_buf
,
2992 size_t len
, loff_t
*ppos
)
2994 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
2995 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
2996 int num
= ras_comp_int
->num
;
2997 char buff
[5]; /* decimal max char plus \n and \0 */
3000 size
= sprintf(buff
, "%d\n", adapter
->ras_comps
[num
].trace_level
);
3004 copy_to_user(user_buf
, buff
, size
);
3009 static ssize_t
trace_level_write(struct file
*file
, const char __user
*user_buf
,
3010 size_t len
, loff_t
*ppos
)
3012 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
3013 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
3014 union ibmvnic_crq crq
;
3016 char buff
[9]; /* decimal max int plus \n and \0 */
3018 copy_from_user(buff
, user_buf
, sizeof(buff
));
3019 val
= kstrtoul(buff
, 10, NULL
);
3023 memset(&crq
, 0, sizeof(crq
));
3024 crq
.control_ras
.first
= IBMVNIC_CRQ_CMD
;
3025 crq
.control_ras
.cmd
= CONTROL_RAS
;
3026 crq
.control_ras
.correlator
=
3027 adapter
->ras_comps
[ras_comp_int
->num
].correlator
;
3028 crq
.control_ras
.op
= IBMVNIC_TRACE_LEVEL
;
3029 crq
.control_ras
.level
= val
;
3030 ibmvnic_send_crq(adapter
, &crq
);
3035 static const struct file_operations trace_level_ops
= {
3036 .owner
= THIS_MODULE
,
3037 .open
= simple_open
,
3038 .read
= trace_level_read
,
3039 .write
= trace_level_write
,
3042 static ssize_t
trace_buff_size_read(struct file
*file
, char __user
*user_buf
,
3043 size_t len
, loff_t
*ppos
)
3045 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
3046 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
3047 int num
= ras_comp_int
->num
;
3048 char buff
[9]; /* decimal max int plus \n and \0 */
3051 size
= sprintf(buff
, "%d\n", adapter
->ras_comps
[num
].trace_buff_size
);
3055 copy_to_user(user_buf
, buff
, size
);
3060 static ssize_t
trace_buff_size_write(struct file
*file
,
3061 const char __user
*user_buf
, size_t len
,
3064 struct ibmvnic_fw_comp_internal
*ras_comp_int
= file
->private_data
;
3065 struct ibmvnic_adapter
*adapter
= ras_comp_int
->adapter
;
3066 union ibmvnic_crq crq
;
3068 char buff
[9]; /* decimal max int plus \n and \0 */
3070 copy_from_user(buff
, user_buf
, sizeof(buff
));
3071 val
= kstrtoul(buff
, 10, NULL
);
3073 memset(&crq
, 0, sizeof(crq
));
3074 crq
.control_ras
.first
= IBMVNIC_CRQ_CMD
;
3075 crq
.control_ras
.cmd
= CONTROL_RAS
;
3076 crq
.control_ras
.correlator
=
3077 adapter
->ras_comps
[ras_comp_int
->num
].correlator
;
3078 crq
.control_ras
.op
= IBMVNIC_CHG_TRACE_BUFF_SZ
;
3079 /* trace_buff_sz is 3 bytes, stuff an int into it */
3080 crq
.control_ras
.trace_buff_sz
[0] = ((u8
*)(&val
))[5];
3081 crq
.control_ras
.trace_buff_sz
[1] = ((u8
*)(&val
))[6];
3082 crq
.control_ras
.trace_buff_sz
[2] = ((u8
*)(&val
))[7];
3083 ibmvnic_send_crq(adapter
, &crq
);
3088 static const struct file_operations trace_size_ops
= {
3089 .owner
= THIS_MODULE
,
3090 .open
= simple_open
,
3091 .read
= trace_buff_size_read
,
3092 .write
= trace_buff_size_write
,
3095 static void handle_request_ras_comps_rsp(union ibmvnic_crq
*crq
,
3096 struct ibmvnic_adapter
*adapter
)
3098 struct device
*dev
= &adapter
->vdev
->dev
;
3099 struct dentry
*dir_ent
;
3103 debugfs_remove_recursive(adapter
->ras_comps_ent
);
3105 adapter
->ras_comps_ent
= debugfs_create_dir("ras_comps",
3106 adapter
->debugfs_dir
);
3107 if (!adapter
->ras_comps_ent
|| IS_ERR(adapter
->ras_comps_ent
)) {
3108 dev_info(dev
, "debugfs create ras_comps dir failed\n");
3112 for (i
= 0; i
< adapter
->ras_comp_num
; i
++) {
3113 dir_ent
= debugfs_create_dir(adapter
->ras_comps
[i
].name
,
3114 adapter
->ras_comps_ent
);
3115 if (!dir_ent
|| IS_ERR(dir_ent
)) {
3116 dev_info(dev
, "debugfs create %s dir failed\n",
3117 adapter
->ras_comps
[i
].name
);
3121 adapter
->ras_comp_int
[i
].adapter
= adapter
;
3122 adapter
->ras_comp_int
[i
].num
= i
;
3123 adapter
->ras_comp_int
[i
].desc_blob
.data
=
3124 &adapter
->ras_comps
[i
].description
;
3125 adapter
->ras_comp_int
[i
].desc_blob
.size
=
3126 sizeof(adapter
->ras_comps
[i
].description
);
3128 /* Don't need to remember the dentry's because the debugfs dir
3129 * gets removed recursively
3131 ent
= debugfs_create_blob("description", S_IRUGO
, dir_ent
,
3132 &adapter
->ras_comp_int
[i
].desc_blob
);
3133 ent
= debugfs_create_file("trace_buf_size", S_IRUGO
| S_IWUSR
,
3134 dir_ent
, &adapter
->ras_comp_int
[i
],
3136 ent
= debugfs_create_file("trace_level",
3138 (adapter
->ras_comps
[i
].trace_level
!=
3139 0xFF ? S_IWUSR
: 0),
3140 dir_ent
, &adapter
->ras_comp_int
[i
],
3142 ent
= debugfs_create_file("error_level",
3145 ras_comps
[i
].error_check_level
!=
3146 0xFF ? S_IWUSR
: 0),
3147 dir_ent
, &adapter
->ras_comp_int
[i
],
3149 ent
= debugfs_create_file("tracing", S_IRUGO
| S_IWUSR
,
3150 dir_ent
, &adapter
->ras_comp_int
[i
],
3152 ent
= debugfs_create_file("paused", S_IRUGO
| S_IWUSR
,
3153 dir_ent
, &adapter
->ras_comp_int
[i
],
3155 ent
= debugfs_create_file("trace", S_IRUGO
, dir_ent
,
3156 &adapter
->ras_comp_int
[i
],
3161 static void handle_request_ras_comp_num_rsp(union ibmvnic_crq
*crq
,
3162 struct ibmvnic_adapter
*adapter
)
3164 int len
= adapter
->ras_comp_num
* sizeof(struct ibmvnic_fw_component
);
3165 struct device
*dev
= &adapter
->vdev
->dev
;
3166 union ibmvnic_crq newcrq
;
3168 adapter
->ras_comps
= dma_alloc_coherent(dev
, len
,
3169 &adapter
->ras_comps_tok
,
3171 if (!adapter
->ras_comps
) {
3172 if (!firmware_has_feature(FW_FEATURE_CMO
))
3173 dev_err(dev
, "Couldn't alloc fw comps buffer\n");
3177 adapter
->ras_comp_int
= kmalloc(adapter
->ras_comp_num
*
3178 sizeof(struct ibmvnic_fw_comp_internal
),
3180 if (!adapter
->ras_comp_int
)
3181 dma_free_coherent(dev
, len
, adapter
->ras_comps
,
3182 adapter
->ras_comps_tok
);
3184 memset(&newcrq
, 0, sizeof(newcrq
));
3185 newcrq
.request_ras_comps
.first
= IBMVNIC_CRQ_CMD
;
3186 newcrq
.request_ras_comps
.cmd
= REQUEST_RAS_COMPS
;
3187 newcrq
.request_ras_comps
.ioba
= cpu_to_be32(adapter
->ras_comps_tok
);
3188 newcrq
.request_ras_comps
.len
= cpu_to_be32(len
);
3189 ibmvnic_send_crq(adapter
, &newcrq
);
3192 static void ibmvnic_free_inflight(struct ibmvnic_adapter
*adapter
)
3194 struct ibmvnic_inflight_cmd
*inflight_cmd
, *tmp1
;
3195 struct device
*dev
= &adapter
->vdev
->dev
;
3196 struct ibmvnic_error_buff
*error_buff
, *tmp2
;
3197 unsigned long flags
;
3198 unsigned long flags2
;
3200 spin_lock_irqsave(&adapter
->inflight_lock
, flags
);
3201 list_for_each_entry_safe(inflight_cmd
, tmp1
, &adapter
->inflight
, list
) {
3202 switch (inflight_cmd
->crq
.generic
.cmd
) {
3204 dma_unmap_single(dev
, adapter
->login_buf_token
,
3205 adapter
->login_buf_sz
,
3207 dma_unmap_single(dev
, adapter
->login_rsp_buf_token
,
3208 adapter
->login_rsp_buf_sz
,
3210 kfree(adapter
->login_rsp_buf
);
3211 kfree(adapter
->login_buf
);
3214 complete(&adapter
->fw_done
);
3216 case REQUEST_ERROR_INFO
:
3217 spin_lock_irqsave(&adapter
->error_list_lock
, flags2
);
3218 list_for_each_entry_safe(error_buff
, tmp2
,
3219 &adapter
->errors
, list
) {
3220 dma_unmap_single(dev
, error_buff
->dma
,
3223 kfree(error_buff
->buff
);
3224 list_del(&error_buff
->list
);
3227 spin_unlock_irqrestore(&adapter
->error_list_lock
,
3231 list_del(&inflight_cmd
->list
);
3232 kfree(inflight_cmd
);
3234 spin_unlock_irqrestore(&adapter
->inflight_lock
, flags
);
3237 static void ibmvnic_xport_event(struct work_struct
*work
)
3239 struct ibmvnic_adapter
*adapter
= container_of(work
,
3240 struct ibmvnic_adapter
,
3242 struct device
*dev
= &adapter
->vdev
->dev
;
3245 ibmvnic_free_inflight(adapter
);
3246 release_sub_crqs(adapter
);
3247 if (adapter
->migrated
) {
3248 rc
= ibmvnic_reenable_crq_queue(adapter
);
3250 dev_err(dev
, "Error after enable rc=%ld\n", rc
);
3251 adapter
->migrated
= false;
3252 rc
= ibmvnic_send_crq_init(adapter
);
3254 dev_err(dev
, "Error sending init rc=%ld\n", rc
);
3258 static void ibmvnic_handle_crq(union ibmvnic_crq
*crq
,
3259 struct ibmvnic_adapter
*adapter
)
3261 struct ibmvnic_generic_crq
*gen_crq
= &crq
->generic
;
3262 struct net_device
*netdev
= adapter
->netdev
;
3263 struct device
*dev
= &adapter
->vdev
->dev
;
3266 netdev_dbg(netdev
, "Handling CRQ: %016lx %016lx\n",
3267 ((unsigned long int *)crq
)[0],
3268 ((unsigned long int *)crq
)[1]);
3269 switch (gen_crq
->first
) {
3270 case IBMVNIC_CRQ_INIT_RSP
:
3271 switch (gen_crq
->cmd
) {
3272 case IBMVNIC_CRQ_INIT
:
3273 dev_info(dev
, "Partner initialized\n");
3274 /* Send back a response */
3275 rc
= ibmvnic_send_crq_init_complete(adapter
);
3277 schedule_work(&adapter
->vnic_crq_init
);
3279 dev_err(dev
, "Can't send initrsp rc=%ld\n", rc
);
3281 case IBMVNIC_CRQ_INIT_COMPLETE
:
3282 dev_info(dev
, "Partner initialization complete\n");
3283 send_version_xchg(adapter
);
3286 dev_err(dev
, "Unknown crq cmd: %d\n", gen_crq
->cmd
);
3289 case IBMVNIC_CRQ_XPORT_EVENT
:
3290 if (gen_crq
->cmd
== IBMVNIC_PARTITION_MIGRATED
) {
3291 dev_info(dev
, "Re-enabling adapter\n");
3292 adapter
->migrated
= true;
3293 schedule_work(&adapter
->ibmvnic_xport
);
3294 } else if (gen_crq
->cmd
== IBMVNIC_DEVICE_FAILOVER
) {
3295 dev_info(dev
, "Backing device failover detected\n");
3296 netif_carrier_off(netdev
);
3297 adapter
->failover
= true;
3299 /* The adapter lost the connection */
3300 dev_err(dev
, "Virtual Adapter failed (rc=%d)\n",
3302 schedule_work(&adapter
->ibmvnic_xport
);
3305 case IBMVNIC_CRQ_CMD_RSP
:
3308 dev_err(dev
, "Got an invalid msg type 0x%02x\n",
3313 switch (gen_crq
->cmd
) {
3314 case VERSION_EXCHANGE_RSP
:
3315 rc
= crq
->version_exchange_rsp
.rc
.code
;
3317 dev_err(dev
, "Error %ld in VERSION_EXCHG_RSP\n", rc
);
3320 dev_info(dev
, "Partner protocol version is %d\n",
3321 crq
->version_exchange_rsp
.version
);
3322 if (be16_to_cpu(crq
->version_exchange_rsp
.version
) <
3325 be16_to_cpu(crq
->version_exchange_rsp
.version
);
3326 send_cap_queries(adapter
);
3328 case QUERY_CAPABILITY_RSP
:
3329 handle_query_cap_rsp(crq
, adapter
);
3332 handle_query_map_rsp(crq
, adapter
);
3334 case REQUEST_MAP_RSP
:
3335 handle_request_map_rsp(crq
, adapter
);
3337 case REQUEST_UNMAP_RSP
:
3338 handle_request_unmap_rsp(crq
, adapter
);
3340 case REQUEST_CAPABILITY_RSP
:
3341 handle_request_cap_rsp(crq
, adapter
);
3344 netdev_dbg(netdev
, "Got Login Response\n");
3345 handle_login_rsp(crq
, adapter
);
3347 case LOGICAL_LINK_STATE_RSP
:
3348 netdev_dbg(netdev
, "Got Logical Link State Response\n");
3349 adapter
->logical_link_state
=
3350 crq
->logical_link_state_rsp
.link_state
;
3352 case LINK_STATE_INDICATION
:
3353 netdev_dbg(netdev
, "Got Logical Link State Indication\n");
3354 adapter
->phys_link_state
=
3355 crq
->link_state_indication
.phys_link_state
;
3356 adapter
->logical_link_state
=
3357 crq
->link_state_indication
.logical_link_state
;
3359 case CHANGE_MAC_ADDR_RSP
:
3360 netdev_dbg(netdev
, "Got MAC address change Response\n");
3361 handle_change_mac_rsp(crq
, adapter
);
3363 case ERROR_INDICATION
:
3364 netdev_dbg(netdev
, "Got Error Indication\n");
3365 handle_error_indication(crq
, adapter
);
3367 case REQUEST_ERROR_RSP
:
3368 netdev_dbg(netdev
, "Got Error Detail Response\n");
3369 handle_error_info_rsp(crq
, adapter
);
3371 case REQUEST_STATISTICS_RSP
:
3372 netdev_dbg(netdev
, "Got Statistics Response\n");
3373 complete(&adapter
->stats_done
);
3375 case REQUEST_DUMP_SIZE_RSP
:
3376 netdev_dbg(netdev
, "Got Request Dump Size Response\n");
3377 handle_dump_size_rsp(crq
, adapter
);
3379 case REQUEST_DUMP_RSP
:
3380 netdev_dbg(netdev
, "Got Request Dump Response\n");
3381 complete(&adapter
->fw_done
);
3383 case QUERY_IP_OFFLOAD_RSP
:
3384 netdev_dbg(netdev
, "Got Query IP offload Response\n");
3385 handle_query_ip_offload_rsp(adapter
);
3387 case MULTICAST_CTRL_RSP
:
3388 netdev_dbg(netdev
, "Got multicast control Response\n");
3390 case CONTROL_IP_OFFLOAD_RSP
:
3391 netdev_dbg(netdev
, "Got Control IP offload Response\n");
3392 dma_unmap_single(dev
, adapter
->ip_offload_ctrl_tok
,
3393 sizeof(adapter
->ip_offload_ctrl
),
3395 /* We're done with the queries, perform the login */
3396 send_login(adapter
);
3398 case REQUEST_RAS_COMP_NUM_RSP
:
3399 netdev_dbg(netdev
, "Got Request RAS Comp Num Response\n");
3400 if (crq
->request_ras_comp_num_rsp
.rc
.code
== 10) {
3401 netdev_dbg(netdev
, "Request RAS Comp Num not supported\n");
3404 adapter
->ras_comp_num
=
3405 be32_to_cpu(crq
->request_ras_comp_num_rsp
.num_components
);
3406 handle_request_ras_comp_num_rsp(crq
, adapter
);
3408 case REQUEST_RAS_COMPS_RSP
:
3409 netdev_dbg(netdev
, "Got Request RAS Comps Response\n");
3410 handle_request_ras_comps_rsp(crq
, adapter
);
3412 case CONTROL_RAS_RSP
:
3413 netdev_dbg(netdev
, "Got Control RAS Response\n");
3414 handle_control_ras_rsp(crq
, adapter
);
3416 case COLLECT_FW_TRACE_RSP
:
3417 netdev_dbg(netdev
, "Got Collect firmware trace Response\n");
3418 complete(&adapter
->fw_done
);
3421 netdev_err(netdev
, "Got an invalid cmd type 0x%02x\n",
3426 static irqreturn_t
ibmvnic_interrupt(int irq
, void *instance
)
3428 struct ibmvnic_adapter
*adapter
= instance
;
3429 struct ibmvnic_crq_queue
*queue
= &adapter
->crq
;
3430 struct vio_dev
*vdev
= adapter
->vdev
;
3431 union ibmvnic_crq
*crq
;
3432 unsigned long flags
;
3435 spin_lock_irqsave(&queue
->lock
, flags
);
3436 vio_disable_interrupts(vdev
);
3438 /* Pull all the valid messages off the CRQ */
3439 while ((crq
= ibmvnic_next_crq(adapter
)) != NULL
) {
3440 ibmvnic_handle_crq(crq
, adapter
);
3441 crq
->generic
.first
= 0;
3443 vio_enable_interrupts(vdev
);
3444 crq
= ibmvnic_next_crq(adapter
);
3446 vio_disable_interrupts(vdev
);
3447 ibmvnic_handle_crq(crq
, adapter
);
3448 crq
->generic
.first
= 0;
3453 spin_unlock_irqrestore(&queue
->lock
, flags
);
3457 static int ibmvnic_reenable_crq_queue(struct ibmvnic_adapter
*adapter
)
3459 struct vio_dev
*vdev
= adapter
->vdev
;
3463 rc
= plpar_hcall_norets(H_ENABLE_CRQ
, vdev
->unit_address
);
3464 } while (rc
== H_IN_PROGRESS
|| rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
3467 dev_err(&vdev
->dev
, "Error enabling adapter (rc=%d)\n", rc
);
3472 static int ibmvnic_reset_crq(struct ibmvnic_adapter
*adapter
)
3474 struct ibmvnic_crq_queue
*crq
= &adapter
->crq
;
3475 struct device
*dev
= &adapter
->vdev
->dev
;
3476 struct vio_dev
*vdev
= adapter
->vdev
;
3481 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
3482 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
3484 /* Clean out the queue */
3485 memset(crq
->msgs
, 0, PAGE_SIZE
);
3488 /* And re-open it again */
3489 rc
= plpar_hcall_norets(H_REG_CRQ
, vdev
->unit_address
,
3490 crq
->msg_token
, PAGE_SIZE
);
3493 /* Adapter is good, but other end is not ready */
3494 dev_warn(dev
, "Partner adapter not ready\n");
3496 dev_warn(dev
, "Couldn't register crq (rc=%d)\n", rc
);
3501 static void ibmvnic_release_crq_queue(struct ibmvnic_adapter
*adapter
)
3503 struct ibmvnic_crq_queue
*crq
= &adapter
->crq
;
3504 struct vio_dev
*vdev
= adapter
->vdev
;
3507 netdev_dbg(adapter
->netdev
, "Releasing CRQ\n");
3508 free_irq(vdev
->irq
, adapter
);
3510 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
3511 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
3513 dma_unmap_single(&vdev
->dev
, crq
->msg_token
, PAGE_SIZE
,
3515 free_page((unsigned long)crq
->msgs
);
3518 static int ibmvnic_init_crq_queue(struct ibmvnic_adapter
*adapter
)
3520 struct ibmvnic_crq_queue
*crq
= &adapter
->crq
;
3521 struct device
*dev
= &adapter
->vdev
->dev
;
3522 struct vio_dev
*vdev
= adapter
->vdev
;
3523 int rc
, retrc
= -ENOMEM
;
3525 crq
->msgs
= (union ibmvnic_crq
*)get_zeroed_page(GFP_KERNEL
);
3526 /* Should we allocate more than one page? */
3531 crq
->size
= PAGE_SIZE
/ sizeof(*crq
->msgs
);
3532 crq
->msg_token
= dma_map_single(dev
, crq
->msgs
, PAGE_SIZE
,
3534 if (dma_mapping_error(dev
, crq
->msg_token
))
3537 rc
= plpar_hcall_norets(H_REG_CRQ
, vdev
->unit_address
,
3538 crq
->msg_token
, PAGE_SIZE
);
3540 if (rc
== H_RESOURCE
)
3541 /* maybe kexecing and resource is busy. try a reset */
3542 rc
= ibmvnic_reset_crq(adapter
);
3545 if (rc
== H_CLOSED
) {
3546 dev_warn(dev
, "Partner adapter not ready\n");
3548 dev_warn(dev
, "Error %d opening adapter\n", rc
);
3549 goto reg_crq_failed
;
3554 netdev_dbg(adapter
->netdev
, "registering irq 0x%x\n", vdev
->irq
);
3555 rc
= request_irq(vdev
->irq
, ibmvnic_interrupt
, 0, IBMVNIC_NAME
,
3558 dev_err(dev
, "Couldn't register irq 0x%x. rc=%d\n",
3560 goto req_irq_failed
;
3563 rc
= vio_enable_interrupts(vdev
);
3565 dev_err(dev
, "Error %d enabling interrupts\n", rc
);
3566 goto req_irq_failed
;
3570 spin_lock_init(&crq
->lock
);
3576 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
3577 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
3579 dma_unmap_single(dev
, crq
->msg_token
, PAGE_SIZE
, DMA_BIDIRECTIONAL
);
3581 free_page((unsigned long)crq
->msgs
);
3585 /* debugfs for dump */
3586 static int ibmvnic_dump_show(struct seq_file
*seq
, void *v
)
3588 struct net_device
*netdev
= seq
->private;
3589 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
3590 struct device
*dev
= &adapter
->vdev
->dev
;
3591 union ibmvnic_crq crq
;
3593 memset(&crq
, 0, sizeof(crq
));
3594 crq
.request_dump_size
.first
= IBMVNIC_CRQ_CMD
;
3595 crq
.request_dump_size
.cmd
= REQUEST_DUMP_SIZE
;
3596 ibmvnic_send_crq(adapter
, &crq
);
3598 init_completion(&adapter
->fw_done
);
3599 wait_for_completion(&adapter
->fw_done
);
3601 seq_write(seq
, adapter
->dump_data
, adapter
->dump_data_size
);
3603 dma_unmap_single(dev
, adapter
->dump_data_token
, adapter
->dump_data_size
,
3606 kfree(adapter
->dump_data
);
3611 static int ibmvnic_dump_open(struct inode
*inode
, struct file
*file
)
3613 return single_open(file
, ibmvnic_dump_show
, inode
->i_private
);
3616 static const struct file_operations ibmvnic_dump_ops
= {
3617 .owner
= THIS_MODULE
,
3618 .open
= ibmvnic_dump_open
,
3620 .llseek
= seq_lseek
,
3621 .release
= single_release
,
3624 static void handle_crq_init_rsp(struct work_struct
*work
)
3626 struct ibmvnic_adapter
*adapter
= container_of(work
,
3627 struct ibmvnic_adapter
,
3629 struct device
*dev
= &adapter
->vdev
->dev
;
3630 struct net_device
*netdev
= adapter
->netdev
;
3631 unsigned long timeout
= msecs_to_jiffies(30000);
3632 bool restart
= false;
3635 if (adapter
->failover
) {
3636 release_sub_crqs(adapter
);
3637 if (netif_running(netdev
)) {
3638 netif_tx_disable(netdev
);
3639 ibmvnic_close(netdev
);
3644 send_version_xchg(adapter
);
3645 reinit_completion(&adapter
->init_done
);
3646 if (!wait_for_completion_timeout(&adapter
->init_done
, timeout
)) {
3647 dev_err(dev
, "Passive init timeout\n");
3652 if (adapter
->renegotiate
) {
3653 adapter
->renegotiate
= false;
3654 release_sub_crqs_no_irqs(adapter
);
3655 send_cap_queries(adapter
);
3657 reinit_completion(&adapter
->init_done
);
3658 if (!wait_for_completion_timeout(&adapter
->init_done
,
3660 dev_err(dev
, "Passive init timeout\n");
3664 } while (adapter
->renegotiate
);
3665 rc
= init_sub_crq_irqs(adapter
);
3670 netdev
->real_num_tx_queues
= adapter
->req_tx_queues
;
3671 netdev
->mtu
= adapter
->req_mtu
;
3673 if (adapter
->failover
) {
3674 adapter
->failover
= false;
3676 rc
= ibmvnic_open(netdev
);
3678 goto restart_failed
;
3680 netif_carrier_on(netdev
);
3684 rc
= register_netdev(netdev
);
3687 "failed to register netdev rc=%d\n", rc
);
3688 goto register_failed
;
3690 dev_info(dev
, "ibmvnic registered\n");
3695 dev_err(dev
, "Failed to restart ibmvnic, rc=%d\n", rc
);
3697 release_sub_crqs(adapter
);
3699 dev_err(dev
, "Passive initialization was not successful\n");
3702 static int ibmvnic_probe(struct vio_dev
*dev
, const struct vio_device_id
*id
)
3704 unsigned long timeout
= msecs_to_jiffies(30000);
3705 struct ibmvnic_adapter
*adapter
;
3706 struct net_device
*netdev
;
3707 unsigned char *mac_addr_p
;
3709 char buf
[16]; /* debugfs name buf */
3712 dev_dbg(&dev
->dev
, "entering ibmvnic_probe for UA 0x%x\n",
3715 mac_addr_p
= (unsigned char *)vio_get_attribute(dev
,
3716 VETH_MAC_ADDR
, NULL
);
3719 "(%s:%3.3d) ERROR: Can't find MAC_ADDR attribute\n",
3720 __FILE__
, __LINE__
);
3724 netdev
= alloc_etherdev_mq(sizeof(struct ibmvnic_adapter
),
3725 IBMVNIC_MAX_TX_QUEUES
);
3729 adapter
= netdev_priv(netdev
);
3730 dev_set_drvdata(&dev
->dev
, netdev
);
3731 adapter
->vdev
= dev
;
3732 adapter
->netdev
= netdev
;
3733 adapter
->failover
= false;
3735 ether_addr_copy(adapter
->mac_addr
, mac_addr_p
);
3736 ether_addr_copy(netdev
->dev_addr
, adapter
->mac_addr
);
3737 netdev
->irq
= dev
->irq
;
3738 netdev
->netdev_ops
= &ibmvnic_netdev_ops
;
3739 netdev
->ethtool_ops
= &ibmvnic_ethtool_ops
;
3740 SET_NETDEV_DEV(netdev
, &dev
->dev
);
3742 INIT_WORK(&adapter
->vnic_crq_init
, handle_crq_init_rsp
);
3743 INIT_WORK(&adapter
->ibmvnic_xport
, ibmvnic_xport_event
);
3745 spin_lock_init(&adapter
->stats_lock
);
3747 rc
= ibmvnic_init_crq_queue(adapter
);
3749 dev_err(&dev
->dev
, "Couldn't initialize crq. rc=%d\n", rc
);
3753 INIT_LIST_HEAD(&adapter
->errors
);
3754 INIT_LIST_HEAD(&adapter
->inflight
);
3755 spin_lock_init(&adapter
->error_list_lock
);
3756 spin_lock_init(&adapter
->inflight_lock
);
3758 adapter
->stats_token
= dma_map_single(&dev
->dev
, &adapter
->stats
,
3759 sizeof(struct ibmvnic_statistics
),
3761 if (dma_mapping_error(&dev
->dev
, adapter
->stats_token
)) {
3762 if (!firmware_has_feature(FW_FEATURE_CMO
))
3763 dev_err(&dev
->dev
, "Couldn't map stats buffer\n");
3768 snprintf(buf
, sizeof(buf
), "ibmvnic_%x", dev
->unit_address
);
3769 ent
= debugfs_create_dir(buf
, NULL
);
3770 if (!ent
|| IS_ERR(ent
)) {
3771 dev_info(&dev
->dev
, "debugfs create directory failed\n");
3772 adapter
->debugfs_dir
= NULL
;
3774 adapter
->debugfs_dir
= ent
;
3775 ent
= debugfs_create_file("dump", S_IRUGO
, adapter
->debugfs_dir
,
3776 netdev
, &ibmvnic_dump_ops
);
3777 if (!ent
|| IS_ERR(ent
)) {
3779 "debugfs create dump file failed\n");
3780 adapter
->debugfs_dump
= NULL
;
3782 adapter
->debugfs_dump
= ent
;
3785 ibmvnic_send_crq_init(adapter
);
3787 init_completion(&adapter
->init_done
);
3788 if (!wait_for_completion_timeout(&adapter
->init_done
, timeout
))
3792 if (adapter
->renegotiate
) {
3793 adapter
->renegotiate
= false;
3794 release_sub_crqs_no_irqs(adapter
);
3795 send_cap_queries(adapter
);
3797 reinit_completion(&adapter
->init_done
);
3798 if (!wait_for_completion_timeout(&adapter
->init_done
,
3802 } while (adapter
->renegotiate
);
3804 rc
= init_sub_crq_irqs(adapter
);
3806 dev_err(&dev
->dev
, "failed to initialize sub crq irqs\n");
3810 netdev
->real_num_tx_queues
= adapter
->req_tx_queues
;
3811 netdev
->mtu
= adapter
->req_mtu
;
3813 rc
= register_netdev(netdev
);
3815 dev_err(&dev
->dev
, "failed to register netdev rc=%d\n", rc
);
3818 dev_info(&dev
->dev
, "ibmvnic registered\n");
3823 release_sub_crqs(adapter
);
3825 if (adapter
->debugfs_dir
&& !IS_ERR(adapter
->debugfs_dir
))
3826 debugfs_remove_recursive(adapter
->debugfs_dir
);
3828 ibmvnic_release_crq_queue(adapter
);
3830 free_netdev(netdev
);
3834 static int ibmvnic_remove(struct vio_dev
*dev
)
3836 struct net_device
*netdev
= dev_get_drvdata(&dev
->dev
);
3837 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
3839 unregister_netdev(netdev
);
3841 release_sub_crqs(adapter
);
3843 ibmvnic_release_crq_queue(adapter
);
3845 if (adapter
->debugfs_dir
&& !IS_ERR(adapter
->debugfs_dir
))
3846 debugfs_remove_recursive(adapter
->debugfs_dir
);
3848 if (adapter
->ras_comps
)
3849 dma_free_coherent(&dev
->dev
,
3850 adapter
->ras_comp_num
*
3851 sizeof(struct ibmvnic_fw_component
),
3852 adapter
->ras_comps
, adapter
->ras_comps_tok
);
3854 kfree(adapter
->ras_comp_int
);
3856 free_netdev(netdev
);
3857 dev_set_drvdata(&dev
->dev
, NULL
);
3862 static unsigned long ibmvnic_get_desired_dma(struct vio_dev
*vdev
)
3864 struct net_device
*netdev
= dev_get_drvdata(&vdev
->dev
);
3865 struct ibmvnic_adapter
*adapter
;
3866 struct iommu_table
*tbl
;
3867 unsigned long ret
= 0;
3870 tbl
= get_iommu_table_base(&vdev
->dev
);
3872 /* netdev inits at probe time along with the structures we need below*/
3874 return IOMMU_PAGE_ALIGN(IBMVNIC_IO_ENTITLEMENT_DEFAULT
, tbl
);
3876 adapter
= netdev_priv(netdev
);
3878 ret
+= PAGE_SIZE
; /* the crq message queue */
3879 ret
+= adapter
->bounce_buffer_size
;
3880 ret
+= IOMMU_PAGE_ALIGN(sizeof(struct ibmvnic_statistics
), tbl
);
3882 for (i
= 0; i
< adapter
->req_tx_queues
+ adapter
->req_rx_queues
; i
++)
3883 ret
+= 4 * PAGE_SIZE
; /* the scrq message queue */
3885 for (i
= 0; i
< be32_to_cpu(adapter
->login_rsp_buf
->num_rxadd_subcrqs
);
3887 ret
+= adapter
->rx_pool
[i
].size
*
3888 IOMMU_PAGE_ALIGN(adapter
->rx_pool
[i
].buff_size
, tbl
);
3893 static int ibmvnic_resume(struct device
*dev
)
3895 struct net_device
*netdev
= dev_get_drvdata(dev
);
3896 struct ibmvnic_adapter
*adapter
= netdev_priv(netdev
);
3899 /* kick the interrupt handlers just in case we lost an interrupt */
3900 for (i
= 0; i
< adapter
->req_rx_queues
; i
++)
3901 ibmvnic_interrupt_rx(adapter
->rx_scrq
[i
]->irq
,
3902 adapter
->rx_scrq
[i
]);
3907 static struct vio_device_id ibmvnic_device_table
[] = {
3908 {"network", "IBM,vnic"},
3911 MODULE_DEVICE_TABLE(vio
, ibmvnic_device_table
);
3913 static const struct dev_pm_ops ibmvnic_pm_ops
= {
3914 .resume
= ibmvnic_resume
3917 static struct vio_driver ibmvnic_driver
= {
3918 .id_table
= ibmvnic_device_table
,
3919 .probe
= ibmvnic_probe
,
3920 .remove
= ibmvnic_remove
,
3921 .get_desired_dma
= ibmvnic_get_desired_dma
,
3922 .name
= ibmvnic_driver_name
,
3923 .pm
= &ibmvnic_pm_ops
,
3926 /* module functions */
3927 static int __init
ibmvnic_module_init(void)
3929 pr_info("%s: %s %s\n", ibmvnic_driver_name
, ibmvnic_driver_string
,
3930 IBMVNIC_DRIVER_VERSION
);
3932 return vio_register_driver(&ibmvnic_driver
);
3935 static void __exit
ibmvnic_module_exit(void)
3937 vio_unregister_driver(&ibmvnic_driver
);
3940 module_init(ibmvnic_module_init
);
3941 module_exit(ibmvnic_module_exit
);