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