xref: /openbmc/linux/drivers/net/ethernet/ibm/ibmvnic.h (revision 8dda2eac)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /**************************************************************************/
3 /*                                                                        */
4 /*  IBM System i and System p Virtual NIC Device Driver                   */
5 /*  Copyright (C) 2014 IBM Corp.                                          */
6 /*  Santiago Leon (santi_leon@yahoo.com)                                  */
7 /*  Thomas Falcon (tlfalcon@linux.vnet.ibm.com)                           */
8 /*  John Allen (jallen@linux.vnet.ibm.com)                                */
9 /*                                                                        */
10 /*                                                                        */
11 /* This module contains the implementation of a virtual ethernet device   */
12 /* for use with IBM i/pSeries LPAR Linux.  It utilizes the logical LAN    */
13 /* option of the RS/6000 Platform Architecture to interface with virtual */
14 /* ethernet NICs that are presented to the partition by the hypervisor.   */
15 /*                                                                        */
16 /**************************************************************************/
17 
18 #define IBMVNIC_NAME		"ibmvnic"
19 #define IBMVNIC_DRIVER_VERSION	"1.0.1"
20 #define IBMVNIC_INVALID_MAP	-1
21 #define IBMVNIC_STATS_TIMEOUT	1
22 #define IBMVNIC_INIT_FAILED	2
23 #define IBMVNIC_OPEN_FAILED	3
24 
25 /* basic structures plus 100 2k buffers */
26 #define IBMVNIC_IO_ENTITLEMENT_DEFAULT	610305
27 
28 /* Initial module_parameters */
29 #define IBMVNIC_RX_WEIGHT		16
30 /* when changing this, update IBMVNIC_IO_ENTITLEMENT_DEFAULT */
31 #define IBMVNIC_BUFFS_PER_POOL	100
32 #define IBMVNIC_MAX_QUEUES	16
33 #define IBMVNIC_MAX_QUEUE_SZ   4096
34 #define IBMVNIC_MAX_IND_DESCS  16
35 #define IBMVNIC_IND_ARR_SZ	(IBMVNIC_MAX_IND_DESCS * 32)
36 
37 #define IBMVNIC_TSO_BUF_SZ	65536
38 #define IBMVNIC_TSO_BUFS	64
39 #define IBMVNIC_TSO_POOL_MASK	0x80000000
40 
41 #define IBMVNIC_MAX_LTB_SIZE ((1 << (MAX_ORDER - 1)) * PAGE_SIZE)
42 #define IBMVNIC_BUFFER_HLEN 500
43 
44 #define IBMVNIC_RESET_DELAY 100
45 
46 static const char ibmvnic_priv_flags[][ETH_GSTRING_LEN] = {
47 #define IBMVNIC_USE_SERVER_MAXES 0x1
48 	"use-server-maxes"
49 };
50 
51 struct ibmvnic_login_buffer {
52 	__be32 len;
53 	__be32 version;
54 #define INITIAL_VERSION_LB 1
55 	__be32 num_txcomp_subcrqs;
56 	__be32 off_txcomp_subcrqs;
57 	__be32 num_rxcomp_subcrqs;
58 	__be32 off_rxcomp_subcrqs;
59 	__be32 login_rsp_ioba;
60 	__be32 login_rsp_len;
61 	__be32 client_data_offset;
62 	__be32 client_data_len;
63 } __packed __aligned(8);
64 
65 struct ibmvnic_login_rsp_buffer {
66 	__be32 len;
67 	__be32 version;
68 #define INITIAL_VERSION_LRB 1
69 	__be32 num_txsubm_subcrqs;
70 	__be32 off_txsubm_subcrqs;
71 	__be32 num_rxadd_subcrqs;
72 	__be32 off_rxadd_subcrqs;
73 	__be32 off_rxadd_buff_size;
74 	__be32 num_supp_tx_desc;
75 	__be32 off_supp_tx_desc;
76 } __packed __aligned(8);
77 
78 struct ibmvnic_query_ip_offload_buffer {
79 	__be32 len;
80 	__be32 version;
81 #define INITIAL_VERSION_IOB 1
82 	u8 ipv4_chksum;
83 	u8 ipv6_chksum;
84 	u8 tcp_ipv4_chksum;
85 	u8 tcp_ipv6_chksum;
86 	u8 udp_ipv4_chksum;
87 	u8 udp_ipv6_chksum;
88 	u8 large_tx_ipv4;
89 	u8 large_tx_ipv6;
90 	u8 large_rx_ipv4;
91 	u8 large_rx_ipv6;
92 	u8 reserved1[14];
93 	__be16 max_ipv4_header_size;
94 	__be16 max_ipv6_header_size;
95 	__be16 max_tcp_header_size;
96 	__be16 max_udp_header_size;
97 	__be32 max_large_tx_size;
98 	__be32 max_large_rx_size;
99 	u8 reserved2[16];
100 	u8 ipv6_extension_header;
101 #define IPV6_EH_NOT_SUPPORTED	0x00
102 #define IPV6_EH_SUPPORTED_LIM	0x01
103 #define IPV6_EH_SUPPORTED	0xFF
104 	u8 tcp_pseudosum_req;
105 #define TCP_PS_NOT_REQUIRED	0x00
106 #define TCP_PS_REQUIRED		0x01
107 	u8 reserved3[30];
108 	__be16 num_ipv6_ext_headers;
109 	__be32 off_ipv6_ext_headers;
110 	u8 reserved4[154];
111 } __packed __aligned(8);
112 
113 struct ibmvnic_control_ip_offload_buffer {
114 	__be32 len;
115 	__be32 version;
116 #define INITIAL_VERSION_IOB 1
117 	u8 ipv4_chksum;
118 	u8 ipv6_chksum;
119 	u8 tcp_ipv4_chksum;
120 	u8 tcp_ipv6_chksum;
121 	u8 udp_ipv4_chksum;
122 	u8 udp_ipv6_chksum;
123 	u8 large_tx_ipv4;
124 	u8 large_tx_ipv6;
125 	u8 bad_packet_rx;
126 	u8 large_rx_ipv4;
127 	u8 large_rx_ipv6;
128 	u8 reserved4[111];
129 } __packed __aligned(8);
130 
131 struct ibmvnic_fw_component {
132 	u8 name[48];
133 	__be32 trace_buff_size;
134 	u8 correlator;
135 	u8 trace_level;
136 	u8 parent_correlator;
137 	u8 error_check_level;
138 	u8 trace_on;
139 	u8 reserved[7];
140 	u8 description[192];
141 } __packed __aligned(8);
142 
143 struct ibmvnic_fw_trace_entry {
144 	__be32 trace_id;
145 	u8 num_valid_data;
146 	u8 reserved[3];
147 	__be64 pmc_registers;
148 	__be64 timebase;
149 	__be64 trace_data[5];
150 } __packed __aligned(8);
151 
152 struct ibmvnic_statistics {
153 	__be32 version;
154 	__be32 promiscuous;
155 	__be64 rx_packets;
156 	__be64 rx_bytes;
157 	__be64 tx_packets;
158 	__be64 tx_bytes;
159 	__be64 ucast_tx_packets;
160 	__be64 ucast_rx_packets;
161 	__be64 mcast_tx_packets;
162 	__be64 mcast_rx_packets;
163 	__be64 bcast_tx_packets;
164 	__be64 bcast_rx_packets;
165 	__be64 align_errors;
166 	__be64 fcs_errors;
167 	__be64 single_collision_frames;
168 	__be64 multi_collision_frames;
169 	__be64 sqe_test_errors;
170 	__be64 deferred_tx;
171 	__be64 late_collisions;
172 	__be64 excess_collisions;
173 	__be64 internal_mac_tx_errors;
174 	__be64 carrier_sense;
175 	__be64 too_long_frames;
176 	__be64 internal_mac_rx_errors;
177 	u8 reserved[72];
178 } __packed __aligned(8);
179 
180 #define NUM_TX_STATS 3
181 struct ibmvnic_tx_queue_stats {
182 	u64 packets;
183 	u64 bytes;
184 	u64 dropped_packets;
185 };
186 
187 #define NUM_RX_STATS 3
188 struct ibmvnic_rx_queue_stats {
189 	u64 packets;
190 	u64 bytes;
191 	u64 interrupts;
192 };
193 
194 struct ibmvnic_acl_buffer {
195 	__be32 len;
196 	__be32 version;
197 #define INITIAL_VERSION_IOB 1
198 	u8 mac_acls_restrict;
199 	u8 vlan_acls_restrict;
200 	u8 reserved1[22];
201 	__be32 num_mac_addrs;
202 	__be32 offset_mac_addrs;
203 	__be32 num_vlan_ids;
204 	__be32 offset_vlan_ids;
205 	u8 reserved2[80];
206 } __packed __aligned(8);
207 
208 /* descriptors have been changed, how should this be defined?  1? 4? */
209 
210 #define IBMVNIC_TX_DESC_VERSIONS 3
211 
212 /* is this still needed? */
213 struct ibmvnic_tx_comp_desc {
214 	u8 first;
215 	u8 num_comps;
216 	__be16 rcs[5];
217 	__be32 correlators[5];
218 } __packed __aligned(8);
219 
220 /* some flags that included in v0 descriptor, which is gone
221  * only used for IBMVNIC_TCP_CHKSUM and IBMVNIC_UDP_CHKSUM
222  * and only in some offload_flags variable that doesn't seem
223  * to be used anywhere, can probably be removed?
224  */
225 
226 #define IBMVNIC_TCP_CHKSUM		0x20
227 #define IBMVNIC_UDP_CHKSUM		0x08
228 
229 struct ibmvnic_tx_desc {
230 	u8 first;
231 	u8 type;
232 
233 #define IBMVNIC_TX_DESC 0x10
234 	u8 n_crq_elem;
235 	u8 n_sge;
236 	u8 flags1;
237 #define IBMVNIC_TX_COMP_NEEDED		0x80
238 #define IBMVNIC_TX_CHKSUM_OFFLOAD	0x40
239 #define IBMVNIC_TX_LSO			0x20
240 #define IBMVNIC_TX_PROT_TCP		0x10
241 #define IBMVNIC_TX_PROT_UDP		0x08
242 #define IBMVNIC_TX_PROT_IPV4		0x04
243 #define IBMVNIC_TX_PROT_IPV6		0x02
244 #define IBMVNIC_TX_VLAN_PRESENT		0x01
245 	u8 flags2;
246 #define IBMVNIC_TX_VLAN_INSERT		0x80
247 	__be16 mss;
248 	u8 reserved[4];
249 	__be32 correlator;
250 	__be16 vlan_id;
251 	__be16 dma_reg;
252 	__be32 sge_len;
253 	__be64 ioba;
254 } __packed __aligned(8);
255 
256 struct ibmvnic_hdr_desc {
257 	u8 first;
258 	u8 type;
259 #define IBMVNIC_HDR_DESC		0x11
260 	u8 len;
261 	u8 l2_len;
262 	__be16 l3_len;
263 	u8 l4_len;
264 	u8 flag;
265 	u8 data[24];
266 } __packed __aligned(8);
267 
268 struct ibmvnic_hdr_ext_desc {
269 	u8 first;
270 	u8 type;
271 #define IBMVNIC_HDR_EXT_DESC		0x12
272 	u8 len;
273 	u8 data[29];
274 } __packed __aligned(8);
275 
276 struct ibmvnic_sge_desc {
277 	u8 first;
278 	u8 type;
279 #define IBMVNIC_SGE_DESC		0x30
280 	__be16 sge1_dma_reg;
281 	__be32 sge1_len;
282 	__be64 sge1_ioba;
283 	__be16 reserved;
284 	__be16 sge2_dma_reg;
285 	__be32 sge2_len;
286 	__be64 sge2_ioba;
287 } __packed __aligned(8);
288 
289 struct ibmvnic_rx_comp_desc {
290 	u8 first;
291 	u8 flags;
292 #define IBMVNIC_IP_CHKSUM_GOOD		0x80
293 #define IBMVNIC_TCP_UDP_CHKSUM_GOOD	0x40
294 #define IBMVNIC_END_FRAME			0x20
295 #define IBMVNIC_EXACT_MC			0x10
296 #define IBMVNIC_VLAN_STRIPPED			0x08
297 	__be16 off_frame_data;
298 	__be32 len;
299 	__be64 correlator;
300 	__be16 vlan_tci;
301 	__be16 rc;
302 	u8 reserved[12];
303 } __packed __aligned(8);
304 
305 struct ibmvnic_generic_scrq {
306 	u8 first;
307 	u8 reserved[31];
308 } __packed __aligned(8);
309 
310 struct ibmvnic_rx_buff_add_desc {
311 	u8 first;
312 	u8 reserved[7];
313 	__be64 correlator;
314 	__be32 ioba;
315 	u8 map_id;
316 	__be32 len:24;
317 	u8 reserved2[8];
318 } __packed __aligned(8);
319 
320 struct ibmvnic_rc {
321 	u8 code; /* one of enum ibmvnic_rc_codes */
322 	u8 detailed_data[3];
323 } __packed __aligned(4);
324 
325 struct ibmvnic_generic_crq {
326 	u8 first;
327 	u8 cmd;
328 	u8 params[10];
329 	struct ibmvnic_rc rc;
330 } __packed __aligned(8);
331 
332 struct ibmvnic_version_exchange {
333 	u8 first;
334 	u8 cmd;
335 	__be16 version;
336 #define IBMVNIC_INITIAL_VERSION 1
337 	u8 reserved[8];
338 	struct ibmvnic_rc rc;
339 } __packed __aligned(8);
340 
341 struct ibmvnic_capability {
342 	u8 first;
343 	u8 cmd;
344 	__be16 capability; /* one of ibmvnic_capabilities */
345 	__be64 number;
346 	struct ibmvnic_rc rc;
347 } __packed __aligned(8);
348 
349 struct ibmvnic_login {
350 	u8 first;
351 	u8 cmd;
352 	u8 reserved[6];
353 	__be32 ioba;
354 	__be32 len;
355 } __packed __aligned(8);
356 
357 struct ibmvnic_phys_parms {
358 	u8 first;
359 	u8 cmd;
360 	u8 flags1;
361 #define IBMVNIC_EXTERNAL_LOOPBACK	0x80
362 #define IBMVNIC_INTERNAL_LOOPBACK	0x40
363 #define IBMVNIC_PROMISC		0x20
364 #define IBMVNIC_PHYS_LINK_ACTIVE	0x10
365 #define IBMVNIC_AUTONEG_DUPLEX	0x08
366 #define IBMVNIC_FULL_DUPLEX	0x04
367 #define IBMVNIC_HALF_DUPLEX	0x02
368 #define IBMVNIC_CAN_CHG_PHYS_PARMS	0x01
369 	u8 flags2;
370 #define IBMVNIC_LOGICAL_LNK_ACTIVE 0x80
371 	__be32 speed;
372 #define IBMVNIC_AUTONEG		0x80000000
373 #define IBMVNIC_10MBPS		0x40000000
374 #define IBMVNIC_100MBPS		0x20000000
375 #define IBMVNIC_1GBPS		0x10000000
376 #define IBMVNIC_10GBPS		0x08000000
377 #define IBMVNIC_40GBPS		0x04000000
378 #define IBMVNIC_100GBPS		0x02000000
379 #define IBMVNIC_25GBPS		0x01000000
380 #define IBMVNIC_50GBPS		0x00800000
381 #define IBMVNIC_200GBPS		0x00400000
382 	__be32 mtu;
383 	struct ibmvnic_rc rc;
384 } __packed __aligned(8);
385 
386 struct ibmvnic_logical_link_state {
387 	u8 first;
388 	u8 cmd;
389 	u8 link_state;
390 #define IBMVNIC_LOGICAL_LNK_DN 0x00
391 #define IBMVNIC_LOGICAL_LNK_UP 0x01
392 #define IBMVNIC_LOGICAL_LNK_QUERY 0xff
393 	u8 reserved[9];
394 	struct ibmvnic_rc rc;
395 } __packed __aligned(8);
396 
397 struct ibmvnic_query_ip_offload {
398 	u8 first;
399 	u8 cmd;
400 	u8 reserved[2];
401 	__be32 len;
402 	__be32 ioba;
403 	struct ibmvnic_rc rc;
404 } __packed __aligned(8);
405 
406 struct ibmvnic_control_ip_offload {
407 	u8 first;
408 	u8 cmd;
409 	u8 reserved[2];
410 	__be32 ioba;
411 	__be32 len;
412 	struct ibmvnic_rc rc;
413 } __packed __aligned(8);
414 
415 struct ibmvnic_request_statistics {
416 	u8 first;
417 	u8 cmd;
418 	u8 flags;
419 #define IBMVNIC_PHYSICAL_PORT	0x80
420 	u8 reserved1;
421 	__be32 ioba;
422 	__be32 len;
423 	u8 reserved[4];
424 } __packed __aligned(8);
425 
426 struct ibmvnic_error_indication {
427 	u8 first;
428 	u8 cmd;
429 	u8 flags;
430 #define IBMVNIC_FATAL_ERROR	0x80
431 	u8 reserved1;
432 	__be32 error_id;
433 	__be32 detail_error_sz;
434 	__be16 error_cause;
435 	u8 reserved2[2];
436 } __packed __aligned(8);
437 
438 struct ibmvnic_link_state_indication {
439 	u8 first;
440 	u8 cmd;
441 	u8 reserved1[2];
442 	u8 phys_link_state;
443 	u8 logical_link_state;
444 	u8 reserved2[10];
445 } __packed __aligned(8);
446 
447 struct ibmvnic_change_mac_addr {
448 	u8 first;
449 	u8 cmd;
450 	u8 mac_addr[6];
451 	u8 reserved[4];
452 	struct ibmvnic_rc rc;
453 } __packed __aligned(8);
454 
455 struct ibmvnic_multicast_ctrl {
456 	u8 first;
457 	u8 cmd;
458 	u8 mac_addr[6];
459 	u8 flags;
460 #define IBMVNIC_ENABLE_MC		0x80
461 #define IBMVNIC_DISABLE_MC		0x40
462 #define IBMVNIC_ENABLE_ALL		0x20
463 #define IBMVNIC_DISABLE_ALL	0x10
464 	u8 reserved1;
465 	__be16 reserved2; /* was num_enabled_mc_addr; */
466 	struct ibmvnic_rc rc;
467 } __packed __aligned(8);
468 
469 struct ibmvnic_get_vpd_size {
470 	u8 first;
471 	u8 cmd;
472 	u8 reserved[14];
473 } __packed __aligned(8);
474 
475 struct ibmvnic_get_vpd_size_rsp {
476 	u8 first;
477 	u8 cmd;
478 	u8 reserved[2];
479 	__be64 len;
480 	struct ibmvnic_rc rc;
481 } __packed __aligned(8);
482 
483 struct ibmvnic_get_vpd {
484 	u8 first;
485 	u8 cmd;
486 	u8 reserved1[2];
487 	__be32 ioba;
488 	__be32 len;
489 	u8 reserved[4];
490 } __packed __aligned(8);
491 
492 struct ibmvnic_get_vpd_rsp {
493 	u8 first;
494 	u8 cmd;
495 	u8 reserved[10];
496 	struct ibmvnic_rc rc;
497 } __packed __aligned(8);
498 
499 struct ibmvnic_acl_change_indication {
500 	u8 first;
501 	u8 cmd;
502 	__be16 change_type;
503 #define IBMVNIC_MAC_ACL 0
504 #define IBMVNIC_VLAN_ACL 1
505 	u8 reserved[12];
506 } __packed __aligned(8);
507 
508 struct ibmvnic_acl_query {
509 	u8 first;
510 	u8 cmd;
511 	u8 reserved1[2];
512 	__be32 ioba;
513 	__be32 len;
514 	u8 reserved2[4];
515 } __packed __aligned(8);
516 
517 struct ibmvnic_tune {
518 	u8 first;
519 	u8 cmd;
520 	u8 reserved1[2];
521 	__be32 ioba;
522 	__be32 len;
523 	u8 reserved2[4];
524 } __packed __aligned(8);
525 
526 struct ibmvnic_request_map {
527 	u8 first;
528 	u8 cmd;
529 	u8 reserved1;
530 	u8 map_id;
531 	__be32 ioba;
532 	__be32 len;
533 	u8 reserved2[4];
534 } __packed __aligned(8);
535 
536 struct ibmvnic_request_map_rsp {
537 	u8 first;
538 	u8 cmd;
539 	u8 reserved1;
540 	u8 map_id;
541 	u8 reserved2[8];
542 	struct ibmvnic_rc rc;
543 } __packed __aligned(8);
544 
545 struct ibmvnic_request_unmap {
546 	u8 first;
547 	u8 cmd;
548 	u8 reserved1;
549 	u8 map_id;
550 	u8 reserved2[12];
551 } __packed __aligned(8);
552 
553 struct ibmvnic_request_unmap_rsp {
554 	u8 first;
555 	u8 cmd;
556 	u8 reserved1;
557 	u8 map_id;
558 	u8 reserved2[8];
559 	struct ibmvnic_rc rc;
560 } __packed __aligned(8);
561 
562 struct ibmvnic_query_map {
563 	u8 first;
564 	u8 cmd;
565 	u8 reserved[14];
566 } __packed __aligned(8);
567 
568 struct ibmvnic_query_map_rsp {
569 	u8 first;
570 	u8 cmd;
571 	u8 reserved;
572 	u8 page_size;
573 	__be32 tot_pages;
574 	__be32 free_pages;
575 	struct ibmvnic_rc rc;
576 } __packed __aligned(8);
577 
578 union ibmvnic_crq {
579 	struct ibmvnic_generic_crq generic;
580 	struct ibmvnic_version_exchange version_exchange;
581 	struct ibmvnic_version_exchange version_exchange_rsp;
582 	struct ibmvnic_capability query_capability;
583 	struct ibmvnic_capability query_capability_rsp;
584 	struct ibmvnic_capability request_capability;
585 	struct ibmvnic_capability request_capability_rsp;
586 	struct ibmvnic_login login;
587 	struct ibmvnic_generic_crq login_rsp;
588 	struct ibmvnic_phys_parms query_phys_parms;
589 	struct ibmvnic_phys_parms query_phys_parms_rsp;
590 	struct ibmvnic_phys_parms query_phys_capabilities;
591 	struct ibmvnic_phys_parms query_phys_capabilities_rsp;
592 	struct ibmvnic_phys_parms set_phys_parms;
593 	struct ibmvnic_phys_parms set_phys_parms_rsp;
594 	struct ibmvnic_logical_link_state logical_link_state;
595 	struct ibmvnic_logical_link_state logical_link_state_rsp;
596 	struct ibmvnic_query_ip_offload query_ip_offload;
597 	struct ibmvnic_query_ip_offload query_ip_offload_rsp;
598 	struct ibmvnic_control_ip_offload control_ip_offload;
599 	struct ibmvnic_control_ip_offload control_ip_offload_rsp;
600 	struct ibmvnic_request_statistics request_statistics;
601 	struct ibmvnic_generic_crq request_statistics_rsp;
602 	struct ibmvnic_error_indication error_indication;
603 	struct ibmvnic_link_state_indication link_state_indication;
604 	struct ibmvnic_change_mac_addr change_mac_addr;
605 	struct ibmvnic_change_mac_addr change_mac_addr_rsp;
606 	struct ibmvnic_multicast_ctrl multicast_ctrl;
607 	struct ibmvnic_multicast_ctrl multicast_ctrl_rsp;
608 	struct ibmvnic_get_vpd_size get_vpd_size;
609 	struct ibmvnic_get_vpd_size_rsp get_vpd_size_rsp;
610 	struct ibmvnic_get_vpd get_vpd;
611 	struct ibmvnic_get_vpd_rsp get_vpd_rsp;
612 	struct ibmvnic_acl_change_indication acl_change_indication;
613 	struct ibmvnic_acl_query acl_query;
614 	struct ibmvnic_generic_crq acl_query_rsp;
615 	struct ibmvnic_tune tune;
616 	struct ibmvnic_generic_crq tune_rsp;
617 	struct ibmvnic_request_map request_map;
618 	struct ibmvnic_request_map_rsp request_map_rsp;
619 	struct ibmvnic_request_unmap request_unmap;
620 	struct ibmvnic_request_unmap_rsp request_unmap_rsp;
621 	struct ibmvnic_query_map query_map;
622 	struct ibmvnic_query_map_rsp query_map_rsp;
623 };
624 
625 enum ibmvnic_rc_codes {
626 	SUCCESS = 0,
627 	PARTIALSUCCESS = 1,
628 	PERMISSION = 2,
629 	NOMEMORY = 3,
630 	PARAMETER = 4,
631 	UNKNOWNCOMMAND = 5,
632 	ABORTED = 6,
633 	INVALIDSTATE = 7,
634 	INVALIDIOBA = 8,
635 	INVALIDLENGTH = 9,
636 	UNSUPPORTEDOPTION = 10,
637 };
638 
639 enum ibmvnic_capabilities {
640 	MIN_TX_QUEUES = 1,
641 	MIN_RX_QUEUES = 2,
642 	MIN_RX_ADD_QUEUES = 3,
643 	MAX_TX_QUEUES = 4,
644 	MAX_RX_QUEUES = 5,
645 	MAX_RX_ADD_QUEUES = 6,
646 	REQ_TX_QUEUES = 7,
647 	REQ_RX_QUEUES = 8,
648 	REQ_RX_ADD_QUEUES = 9,
649 	MIN_TX_ENTRIES_PER_SUBCRQ = 10,
650 	MIN_RX_ADD_ENTRIES_PER_SUBCRQ = 11,
651 	MAX_TX_ENTRIES_PER_SUBCRQ = 12,
652 	MAX_RX_ADD_ENTRIES_PER_SUBCRQ = 13,
653 	REQ_TX_ENTRIES_PER_SUBCRQ = 14,
654 	REQ_RX_ADD_ENTRIES_PER_SUBCRQ = 15,
655 	TCP_IP_OFFLOAD = 16,
656 	PROMISC_REQUESTED = 17,
657 	PROMISC_SUPPORTED = 18,
658 	MIN_MTU = 19,
659 	MAX_MTU = 20,
660 	REQ_MTU = 21,
661 	MAX_MULTICAST_FILTERS = 22,
662 	VLAN_HEADER_INSERTION = 23,
663 	RX_VLAN_HEADER_INSERTION = 24,
664 	MAX_TX_SG_ENTRIES = 25,
665 	RX_SG_SUPPORTED = 26,
666 	RX_SG_REQUESTED = 27,
667 	OPT_TX_COMP_SUB_QUEUES = 28,
668 	OPT_RX_COMP_QUEUES = 29,
669 	OPT_RX_BUFADD_Q_PER_RX_COMP_Q = 30,
670 	OPT_TX_ENTRIES_PER_SUBCRQ = 31,
671 	OPT_RXBA_ENTRIES_PER_SUBCRQ = 32,
672 	TX_RX_DESC_REQ = 33,
673 };
674 
675 enum ibmvnic_error_cause {
676 	ADAPTER_PROBLEM = 0,
677 	BUS_PROBLEM = 1,
678 	FW_PROBLEM = 2,
679 	DD_PROBLEM = 3,
680 	EEH_RECOVERY = 4,
681 	FW_UPDATED = 5,
682 	LOW_MEMORY = 6,
683 };
684 
685 enum ibmvnic_commands {
686 	VERSION_EXCHANGE = 0x01,
687 	VERSION_EXCHANGE_RSP = 0x81,
688 	QUERY_CAPABILITY = 0x02,
689 	QUERY_CAPABILITY_RSP = 0x82,
690 	REQUEST_CAPABILITY = 0x03,
691 	REQUEST_CAPABILITY_RSP = 0x83,
692 	LOGIN = 0x04,
693 	LOGIN_RSP = 0x84,
694 	QUERY_PHYS_PARMS = 0x05,
695 	QUERY_PHYS_PARMS_RSP = 0x85,
696 	QUERY_PHYS_CAPABILITIES = 0x06,
697 	QUERY_PHYS_CAPABILITIES_RSP = 0x86,
698 	SET_PHYS_PARMS = 0x07,
699 	SET_PHYS_PARMS_RSP = 0x87,
700 	ERROR_INDICATION = 0x08,
701 	LOGICAL_LINK_STATE = 0x0C,
702 	LOGICAL_LINK_STATE_RSP = 0x8C,
703 	REQUEST_STATISTICS = 0x0D,
704 	REQUEST_STATISTICS_RSP = 0x8D,
705 	COLLECT_FW_TRACE = 0x11,
706 	COLLECT_FW_TRACE_RSP = 0x91,
707 	LINK_STATE_INDICATION = 0x12,
708 	CHANGE_MAC_ADDR = 0x13,
709 	CHANGE_MAC_ADDR_RSP = 0x93,
710 	MULTICAST_CTRL = 0x14,
711 	MULTICAST_CTRL_RSP = 0x94,
712 	GET_VPD_SIZE = 0x15,
713 	GET_VPD_SIZE_RSP = 0x95,
714 	GET_VPD = 0x16,
715 	GET_VPD_RSP = 0x96,
716 	TUNE = 0x17,
717 	TUNE_RSP = 0x97,
718 	QUERY_IP_OFFLOAD = 0x18,
719 	QUERY_IP_OFFLOAD_RSP = 0x98,
720 	CONTROL_IP_OFFLOAD = 0x19,
721 	CONTROL_IP_OFFLOAD_RSP = 0x99,
722 	ACL_CHANGE_INDICATION = 0x1A,
723 	ACL_QUERY = 0x1B,
724 	ACL_QUERY_RSP = 0x9B,
725 	QUERY_MAP = 0x1D,
726 	QUERY_MAP_RSP = 0x9D,
727 	REQUEST_MAP = 0x1E,
728 	REQUEST_MAP_RSP = 0x9E,
729 	REQUEST_UNMAP = 0x1F,
730 	REQUEST_UNMAP_RSP = 0x9F,
731 	VLAN_CTRL = 0x20,
732 	VLAN_CTRL_RSP = 0xA0,
733 };
734 
735 enum ibmvnic_crq_type {
736 	IBMVNIC_CRQ_CMD			= 0x80,
737 	IBMVNIC_CRQ_CMD_RSP		= 0x80,
738 	IBMVNIC_CRQ_INIT_CMD		= 0xC0,
739 	IBMVNIC_CRQ_INIT_RSP		= 0xC0,
740 	IBMVNIC_CRQ_XPORT_EVENT		= 0xFF,
741 };
742 
743 enum ibmvfc_crq_format {
744 	IBMVNIC_CRQ_INIT                 = 0x01,
745 	IBMVNIC_CRQ_INIT_COMPLETE        = 0x02,
746 	IBMVNIC_PARTITION_MIGRATED       = 0x06,
747 	IBMVNIC_DEVICE_FAILOVER          = 0x08,
748 };
749 
750 struct ibmvnic_crq_queue {
751 	union ibmvnic_crq *msgs;
752 	int size, cur;
753 	dma_addr_t msg_token;
754 	/* Used for serialization of msgs, cur */
755 	spinlock_t lock;
756 	bool active;
757 	char name[32];
758 };
759 
760 union sub_crq {
761 	struct ibmvnic_generic_scrq generic;
762 	struct ibmvnic_tx_comp_desc tx_comp;
763 	struct ibmvnic_tx_desc v1;
764 	struct ibmvnic_hdr_desc hdr;
765 	struct ibmvnic_hdr_ext_desc hdr_ext;
766 	struct ibmvnic_sge_desc sge;
767 	struct ibmvnic_rx_comp_desc rx_comp;
768 	struct ibmvnic_rx_buff_add_desc rx_add;
769 };
770 
771 struct ibmvnic_ind_xmit_queue {
772 	union sub_crq *indir_arr;
773 	dma_addr_t indir_dma;
774 	int index;
775 };
776 
777 struct ibmvnic_sub_crq_queue {
778 	union sub_crq *msgs;
779 	int size, cur;
780 	dma_addr_t msg_token;
781 	unsigned long crq_num;
782 	unsigned long hw_irq;
783 	unsigned int irq;
784 	unsigned int pool_index;
785 	int scrq_num;
786 	/* Used for serialization of msgs, cur */
787 	spinlock_t lock;
788 	struct sk_buff *rx_skb_top;
789 	struct ibmvnic_adapter *adapter;
790 	struct ibmvnic_ind_xmit_queue ind_buf;
791 	atomic_t used;
792 	char name[32];
793 	u64 handle;
794 } ____cacheline_aligned;
795 
796 struct ibmvnic_long_term_buff {
797 	unsigned char *buff;
798 	dma_addr_t addr;
799 	u64 size;
800 	u8 map_id;
801 };
802 
803 struct ibmvnic_tx_buff {
804 	struct sk_buff *skb;
805 	int index;
806 	int pool_index;
807 	int num_entries;
808 };
809 
810 struct ibmvnic_tx_pool {
811 	struct ibmvnic_tx_buff *tx_buff;
812 	int *free_map;
813 	int consumer_index;
814 	int producer_index;
815 	struct ibmvnic_long_term_buff long_term_buff;
816 	int num_buffers;
817 	int buf_size;
818 } ____cacheline_aligned;
819 
820 struct ibmvnic_rx_buff {
821 	struct sk_buff *skb;
822 	dma_addr_t dma;
823 	unsigned char *data;
824 	int size;
825 	int pool_index;
826 };
827 
828 struct ibmvnic_rx_pool {
829 	struct ibmvnic_rx_buff *rx_buff;
830 	int size;
831 	int index;
832 	int buff_size;
833 	atomic_t available;
834 	int *free_map;
835 	int next_free;
836 	int next_alloc;
837 	int active;
838 	struct ibmvnic_long_term_buff long_term_buff;
839 } ____cacheline_aligned;
840 
841 struct ibmvnic_vpd {
842 	unsigned char *buff;
843 	dma_addr_t dma_addr;
844 	u64 len;
845 };
846 
847 enum vnic_state {VNIC_PROBING = 1,
848 		 VNIC_PROBED,
849 		 VNIC_OPENING,
850 		 VNIC_OPEN,
851 		 VNIC_CLOSING,
852 		 VNIC_CLOSED,
853 		 VNIC_REMOVING,
854 		 VNIC_REMOVED,
855 		 VNIC_DOWN};
856 
857 enum ibmvnic_reset_reason {VNIC_RESET_FAILOVER = 1,
858 			   VNIC_RESET_MOBILITY,
859 			   VNIC_RESET_FATAL,
860 			   VNIC_RESET_NON_FATAL,
861 			   VNIC_RESET_TIMEOUT,
862 			   VNIC_RESET_CHANGE_PARAM,
863 			   VNIC_RESET_PASSIVE_INIT};
864 
865 struct ibmvnic_rwi {
866 	enum ibmvnic_reset_reason reset_reason;
867 	struct list_head list;
868 };
869 
870 struct ibmvnic_tunables {
871 	u64 rx_queues;
872 	u64 tx_queues;
873 	u64 rx_entries;
874 	u64 tx_entries;
875 	u64 mtu;
876 };
877 
878 struct ibmvnic_adapter {
879 	struct vio_dev *vdev;
880 	struct net_device *netdev;
881 	struct ibmvnic_crq_queue crq;
882 	u8 mac_addr[ETH_ALEN];
883 	struct ibmvnic_query_ip_offload_buffer ip_offload_buf;
884 	dma_addr_t ip_offload_tok;
885 	struct ibmvnic_control_ip_offload_buffer ip_offload_ctrl;
886 	dma_addr_t ip_offload_ctrl_tok;
887 	u32 msg_enable;
888 	u32 priv_flags;
889 
890 	/* Vital Product Data (VPD) */
891 	struct ibmvnic_vpd *vpd;
892 	char fw_version[32];
893 
894 	/* Statistics */
895 	struct ibmvnic_statistics stats;
896 	dma_addr_t stats_token;
897 	struct completion stats_done;
898 	int replenish_no_mem;
899 	int replenish_add_buff_success;
900 	int replenish_add_buff_failure;
901 	int replenish_task_cycles;
902 	int tx_send_failed;
903 	int tx_map_failed;
904 
905 	struct ibmvnic_tx_queue_stats *tx_stats_buffers;
906 	struct ibmvnic_rx_queue_stats *rx_stats_buffers;
907 
908 	int phys_link_state;
909 	int logical_link_state;
910 
911 	u32 speed;
912 	u8 duplex;
913 
914 	/* login data */
915 	struct ibmvnic_login_buffer *login_buf;
916 	dma_addr_t login_buf_token;
917 	int login_buf_sz;
918 
919 	struct ibmvnic_login_rsp_buffer *login_rsp_buf;
920 	dma_addr_t login_rsp_buf_token;
921 	int login_rsp_buf_sz;
922 
923 	atomic_t running_cap_crqs;
924 	bool wait_capability;
925 
926 	struct ibmvnic_sub_crq_queue **tx_scrq ____cacheline_aligned;
927 	struct ibmvnic_sub_crq_queue **rx_scrq ____cacheline_aligned;
928 
929 	/* rx structs */
930 	struct napi_struct *napi;
931 	struct ibmvnic_rx_pool *rx_pool;
932 	u64 promisc;
933 
934 	struct ibmvnic_tx_pool *tx_pool;
935 	struct ibmvnic_tx_pool *tso_pool;
936 	struct completion init_done;
937 	int init_done_rc;
938 
939 	struct completion fw_done;
940 	/* Used for serialization of device commands */
941 	struct mutex fw_lock;
942 	int fw_done_rc;
943 
944 	struct completion reset_done;
945 	int reset_done_rc;
946 	bool wait_for_reset;
947 
948 	/* partner capabilities */
949 	u64 min_tx_queues;
950 	u64 min_rx_queues;
951 	u64 min_rx_add_queues;
952 	u64 max_tx_queues;
953 	u64 max_rx_queues;
954 	u64 max_rx_add_queues;
955 	u64 req_tx_queues;
956 	u64 req_rx_queues;
957 	u64 req_rx_add_queues;
958 	u64 min_tx_entries_per_subcrq;
959 	u64 min_rx_add_entries_per_subcrq;
960 	u64 max_tx_entries_per_subcrq;
961 	u64 max_rx_add_entries_per_subcrq;
962 	u64 req_tx_entries_per_subcrq;
963 	u64 req_rx_add_entries_per_subcrq;
964 	u64 tcp_ip_offload;
965 	u64 promisc_requested;
966 	u64 promisc_supported;
967 	u64 min_mtu;
968 	u64 max_mtu;
969 	u64 req_mtu;
970 	u64 max_multicast_filters;
971 	u64 vlan_header_insertion;
972 	u64 rx_vlan_header_insertion;
973 	u64 max_tx_sg_entries;
974 	u64 rx_sg_supported;
975 	u64 rx_sg_requested;
976 	u64 opt_tx_comp_sub_queues;
977 	u64 opt_rx_comp_queues;
978 	u64 opt_rx_bufadd_q_per_rx_comp_q;
979 	u64 opt_tx_entries_per_subcrq;
980 	u64 opt_rxba_entries_per_subcrq;
981 	__be64 tx_rx_desc_req;
982 	u8 map_id;
983 	u32 num_active_rx_scrqs;
984 	u32 num_active_rx_pools;
985 	u32 num_active_rx_napi;
986 	u32 num_active_tx_scrqs;
987 	u32 num_active_tx_pools;
988 	u32 cur_rx_buf_sz;
989 
990 	struct tasklet_struct tasklet;
991 	enum vnic_state state;
992 	/* Used for serialization of state field. When taking both state
993 	 * and rwi locks, take state lock first.
994 	 */
995 	spinlock_t state_lock;
996 	enum ibmvnic_reset_reason reset_reason;
997 	struct list_head rwi_list;
998 	/* Used for serialization of rwi_list. When taking both state
999 	 * and rwi locks, take state lock first
1000 	 */
1001 	spinlock_t rwi_lock;
1002 	struct work_struct ibmvnic_reset;
1003 	struct delayed_work ibmvnic_delayed_reset;
1004 	unsigned long resetting;
1005 	bool napi_enabled, from_passive_init;
1006 	bool login_pending;
1007 	/* last device reset time */
1008 	unsigned long last_reset_time;
1009 
1010 	bool failover_pending;
1011 	bool force_reset_recovery;
1012 
1013 	struct ibmvnic_tunables desired;
1014 	struct ibmvnic_tunables fallback;
1015 };
1016