blob: 4a7a56ff74ce16af8682808b9ae41c68e90a39b6 [file] [log] [blame]
Thomas Gleixnerd5bb9942019-05-23 11:14:51 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Thomas Falcon032c5e82015-12-21 11:26:06 -06002/**************************************************************************/
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/* */
Thomas Falcon032c5e82015-12-21 11:26:06 -060010/* */
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"
Thomas Falcon9fa2f2c2016-10-17 15:56:29 -050019#define IBMVNIC_DRIVER_VERSION "1.0.1"
Thomas Falcon032c5e82015-12-21 11:26:06 -060020#define IBMVNIC_INVALID_MAP -1
Juliet Kimb27507b2019-09-20 16:11:22 -040021#define IBMVNIC_OPEN_FAILED 3
John Allen2a1bf512017-10-26 16:24:15 -050022
Thomas Falcon032c5e82015-12-21 11:26:06 -060023/* basic structures plus 100 2k buffers */
24#define IBMVNIC_IO_ENTITLEMENT_DEFAULT 610305
25
26/* Initial module_parameters */
27#define IBMVNIC_RX_WEIGHT 16
28/* when changing this, update IBMVNIC_IO_ENTITLEMENT_DEFAULT */
29#define IBMVNIC_BUFFS_PER_POOL 100
Thomas Falconad95a242018-09-28 18:38:24 -050030#define IBMVNIC_MAX_QUEUES 16
Thomas Falcon20b5ba12018-09-28 18:38:25 -050031#define IBMVNIC_MAX_QUEUE_SZ 4096
Dany Maddena6f2fe52021-02-12 15:16:30 -050032#define IBMVNIC_MAX_IND_DESCS 16
Thomas Falconf019fb62020-11-18 19:12:17 -060033#define IBMVNIC_IND_ARR_SZ (IBMVNIC_MAX_IND_DESCS * 32)
Thomas Falcon032c5e82015-12-21 11:26:06 -060034
Thomas Falconfdb06102017-10-17 12:36:55 -050035#define IBMVNIC_TSO_BUF_SZ 65536
36#define IBMVNIC_TSO_BUFS 64
Thomas Falcon06b3e352018-03-16 20:00:28 -050037#define IBMVNIC_TSO_POOL_MASK 0x80000000
Thomas Falconfdb06102017-10-17 12:36:55 -050038
John Allenc26eba02017-10-26 16:23:25 -050039#define IBMVNIC_MAX_LTB_SIZE ((1 << (MAX_ORDER - 1)) * PAGE_SIZE)
40#define IBMVNIC_BUFFER_HLEN 500
41
Juliet Kim7ed5b312019-09-20 16:11:23 -040042#define IBMVNIC_RESET_DELAY 100
43
Thomas Falcon723ad912018-09-28 18:38:26 -050044static const char ibmvnic_priv_flags[][ETH_GSTRING_LEN] = {
45#define IBMVNIC_USE_SERVER_MAXES 0x1
46 "use-server-maxes"
47};
48
Thomas Falcon032c5e82015-12-21 11:26:06 -060049struct ibmvnic_login_buffer {
50 __be32 len;
51 __be32 version;
52#define INITIAL_VERSION_LB 1
53 __be32 num_txcomp_subcrqs;
54 __be32 off_txcomp_subcrqs;
55 __be32 num_rxcomp_subcrqs;
56 __be32 off_rxcomp_subcrqs;
57 __be32 login_rsp_ioba;
58 __be32 login_rsp_len;
Nathan Fontenot37798d02017-11-08 11:23:56 -060059 __be32 client_data_offset;
60 __be32 client_data_len;
Thomas Falcon032c5e82015-12-21 11:26:06 -060061} __packed __aligned(8);
62
63struct ibmvnic_login_rsp_buffer {
64 __be32 len;
65 __be32 version;
66#define INITIAL_VERSION_LRB 1
67 __be32 num_txsubm_subcrqs;
68 __be32 off_txsubm_subcrqs;
69 __be32 num_rxadd_subcrqs;
70 __be32 off_rxadd_subcrqs;
71 __be32 off_rxadd_buff_size;
72 __be32 num_supp_tx_desc;
73 __be32 off_supp_tx_desc;
74} __packed __aligned(8);
75
76struct ibmvnic_query_ip_offload_buffer {
77 __be32 len;
78 __be32 version;
79#define INITIAL_VERSION_IOB 1
80 u8 ipv4_chksum;
81 u8 ipv6_chksum;
82 u8 tcp_ipv4_chksum;
83 u8 tcp_ipv6_chksum;
84 u8 udp_ipv4_chksum;
85 u8 udp_ipv6_chksum;
86 u8 large_tx_ipv4;
87 u8 large_tx_ipv6;
88 u8 large_rx_ipv4;
89 u8 large_rx_ipv6;
90 u8 reserved1[14];
91 __be16 max_ipv4_header_size;
92 __be16 max_ipv6_header_size;
93 __be16 max_tcp_header_size;
94 __be16 max_udp_header_size;
95 __be32 max_large_tx_size;
96 __be32 max_large_rx_size;
97 u8 reserved2[16];
98 u8 ipv6_extension_header;
99#define IPV6_EH_NOT_SUPPORTED 0x00
100#define IPV6_EH_SUPPORTED_LIM 0x01
101#define IPV6_EH_SUPPORTED 0xFF
102 u8 tcp_pseudosum_req;
103#define TCP_PS_NOT_REQUIRED 0x00
104#define TCP_PS_REQUIRED 0x01
105 u8 reserved3[30];
106 __be16 num_ipv6_ext_headers;
107 __be32 off_ipv6_ext_headers;
108 u8 reserved4[154];
109} __packed __aligned(8);
110
111struct ibmvnic_control_ip_offload_buffer {
112 __be32 len;
113 __be32 version;
114#define INITIAL_VERSION_IOB 1
115 u8 ipv4_chksum;
116 u8 ipv6_chksum;
117 u8 tcp_ipv4_chksum;
118 u8 tcp_ipv6_chksum;
119 u8 udp_ipv4_chksum;
120 u8 udp_ipv6_chksum;
121 u8 large_tx_ipv4;
122 u8 large_tx_ipv6;
123 u8 bad_packet_rx;
124 u8 large_rx_ipv4;
125 u8 large_rx_ipv6;
126 u8 reserved4[111];
127} __packed __aligned(8);
128
129struct ibmvnic_fw_component {
130 u8 name[48];
131 __be32 trace_buff_size;
132 u8 correlator;
133 u8 trace_level;
134 u8 parent_correlator;
135 u8 error_check_level;
136 u8 trace_on;
137 u8 reserved[7];
138 u8 description[192];
139} __packed __aligned(8);
140
141struct ibmvnic_fw_trace_entry {
142 __be32 trace_id;
143 u8 num_valid_data;
144 u8 reserved[3];
145 __be64 pmc_registers;
146 __be64 timebase;
147 __be64 trace_data[5];
148} __packed __aligned(8);
149
150struct ibmvnic_statistics {
151 __be32 version;
152 __be32 promiscuous;
153 __be64 rx_packets;
154 __be64 rx_bytes;
155 __be64 tx_packets;
156 __be64 tx_bytes;
157 __be64 ucast_tx_packets;
158 __be64 ucast_rx_packets;
159 __be64 mcast_tx_packets;
160 __be64 mcast_rx_packets;
161 __be64 bcast_tx_packets;
162 __be64 bcast_rx_packets;
163 __be64 align_errors;
164 __be64 fcs_errors;
165 __be64 single_collision_frames;
166 __be64 multi_collision_frames;
167 __be64 sqe_test_errors;
168 __be64 deferred_tx;
169 __be64 late_collisions;
170 __be64 excess_collisions;
171 __be64 internal_mac_tx_errors;
172 __be64 carrier_sense;
173 __be64 too_long_frames;
174 __be64 internal_mac_rx_errors;
175 u8 reserved[72];
176} __packed __aligned(8);
177
John Allen3d52b592017-08-02 16:44:14 -0500178#define NUM_TX_STATS 3
179struct ibmvnic_tx_queue_stats {
180 u64 packets;
181 u64 bytes;
182 u64 dropped_packets;
183};
184
185#define NUM_RX_STATS 3
186struct ibmvnic_rx_queue_stats {
187 u64 packets;
188 u64 bytes;
189 u64 interrupts;
190};
191
Thomas Falcon032c5e82015-12-21 11:26:06 -0600192struct ibmvnic_acl_buffer {
193 __be32 len;
194 __be32 version;
195#define INITIAL_VERSION_IOB 1
196 u8 mac_acls_restrict;
197 u8 vlan_acls_restrict;
198 u8 reserved1[22];
199 __be32 num_mac_addrs;
200 __be32 offset_mac_addrs;
201 __be32 num_vlan_ids;
202 __be32 offset_vlan_ids;
203 u8 reserved2[80];
204} __packed __aligned(8);
205
206/* descriptors have been changed, how should this be defined? 1? 4? */
207
208#define IBMVNIC_TX_DESC_VERSIONS 3
209
210/* is this still needed? */
211struct ibmvnic_tx_comp_desc {
212 u8 first;
213 u8 num_comps;
214 __be16 rcs[5];
215 __be32 correlators[5];
216} __packed __aligned(8);
217
218/* some flags that included in v0 descriptor, which is gone
219 * only used for IBMVNIC_TCP_CHKSUM and IBMVNIC_UDP_CHKSUM
220 * and only in some offload_flags variable that doesn't seem
221 * to be used anywhere, can probably be removed?
222 */
223
224#define IBMVNIC_TCP_CHKSUM 0x20
225#define IBMVNIC_UDP_CHKSUM 0x08
226
Thomas Falcon032c5e82015-12-21 11:26:06 -0600227struct 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
254struct 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
266struct 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
274struct 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
287struct 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
303struct ibmvnic_generic_scrq {
304 u8 first;
305 u8 reserved[31];
306} __packed __aligned(8);
307
308struct 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
318struct ibmvnic_rc {
319 u8 code; /* one of enum ibmvnic_rc_codes */
320 u8 detailed_data[3];
321} __packed __aligned(4);
322
323struct ibmvnic_generic_crq {
324 u8 first;
325 u8 cmd;
326 u8 params[10];
327 struct ibmvnic_rc rc;
328} __packed __aligned(8);
329
330struct 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
339struct ibmvnic_capability {
340 u8 first;
341 u8 cmd;
342 __be16 capability; /* one of ibmvnic_capabilities */
Thomas Falconde89e852016-03-01 10:20:09 -0600343 __be64 number;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600344 struct ibmvnic_rc rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600345} __packed __aligned(8);
346
347struct ibmvnic_login {
348 u8 first;
349 u8 cmd;
350 u8 reserved[6];
351 __be32 ioba;
352 __be32 len;
353} __packed __aligned(8);
354
355struct 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;
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -0300370#define IBMVNIC_AUTONEG 0x80000000
371#define IBMVNIC_10MBPS 0x40000000
372#define IBMVNIC_100MBPS 0x20000000
373#define IBMVNIC_1GBPS 0x10000000
Lijun Panb9cd7952020-09-27 19:06:25 -0500374#define IBMVNIC_10GBPS 0x08000000
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -0300375#define IBMVNIC_40GBPS 0x04000000
376#define IBMVNIC_100GBPS 0x02000000
377#define IBMVNIC_25GBPS 0x01000000
378#define IBMVNIC_50GBPS 0x00800000
379#define IBMVNIC_200GBPS 0x00400000
Thomas Falcon032c5e82015-12-21 11:26:06 -0600380 __be32 mtu;
381 struct ibmvnic_rc rc;
382} __packed __aligned(8);
383
384struct 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
395struct 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
404struct 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
Thomas Falcon032c5e82015-12-21 11:26:06 -0600413struct ibmvnic_request_statistics {
414 u8 first;
415 u8 cmd;
416 u8 flags;
417#define IBMVNIC_PHYSICAL_PORT 0x80
418 u8 reserved1;
419 __be32 ioba;
420 __be32 len;
421 u8 reserved[4];
422} __packed __aligned(8);
423
Thomas Falcon032c5e82015-12-21 11:26:06 -0600424struct ibmvnic_error_indication {
425 u8 first;
426 u8 cmd;
427 u8 flags;
428#define IBMVNIC_FATAL_ERROR 0x80
429 u8 reserved1;
430 __be32 error_id;
431 __be32 detail_error_sz;
432 __be16 error_cause;
433 u8 reserved2[2];
434} __packed __aligned(8);
435
Thomas Falcon032c5e82015-12-21 11:26:06 -0600436struct ibmvnic_link_state_indication {
437 u8 first;
438 u8 cmd;
439 u8 reserved1[2];
440 u8 phys_link_state;
441 u8 logical_link_state;
442 u8 reserved2[10];
443} __packed __aligned(8);
444
445struct ibmvnic_change_mac_addr {
446 u8 first;
447 u8 cmd;
448 u8 mac_addr[6];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600449 u8 reserved[4];
Murilo Fossa Vicentini993a82b2017-04-19 13:44:35 -0400450 struct ibmvnic_rc rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600451} __packed __aligned(8);
452
453struct ibmvnic_multicast_ctrl {
454 u8 first;
455 u8 cmd;
456 u8 mac_addr[6];
457 u8 flags;
458#define IBMVNIC_ENABLE_MC 0x80
459#define IBMVNIC_DISABLE_MC 0x40
460#define IBMVNIC_ENABLE_ALL 0x20
461#define IBMVNIC_DISABLE_ALL 0x10
462 u8 reserved1;
463 __be16 reserved2; /* was num_enabled_mc_addr; */
464 struct ibmvnic_rc rc;
465} __packed __aligned(8);
466
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200467struct ibmvnic_get_vpd_size {
468 u8 first;
469 u8 cmd;
470 u8 reserved[14];
471} __packed __aligned(8);
472
Thomas Falcon032c5e82015-12-21 11:26:06 -0600473struct ibmvnic_get_vpd_size_rsp {
474 u8 first;
475 u8 cmd;
476 u8 reserved[2];
477 __be64 len;
478 struct ibmvnic_rc rc;
479} __packed __aligned(8);
480
481struct ibmvnic_get_vpd {
482 u8 first;
483 u8 cmd;
484 u8 reserved1[2];
485 __be32 ioba;
486 __be32 len;
487 u8 reserved[4];
488} __packed __aligned(8);
489
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200490struct ibmvnic_get_vpd_rsp {
491 u8 first;
492 u8 cmd;
493 u8 reserved[10];
494 struct ibmvnic_rc rc;
495} __packed __aligned(8);
496
Thomas Falcon032c5e82015-12-21 11:26:06 -0600497struct ibmvnic_acl_change_indication {
498 u8 first;
499 u8 cmd;
500 __be16 change_type;
501#define IBMVNIC_MAC_ACL 0
502#define IBMVNIC_VLAN_ACL 1
503 u8 reserved[12];
504} __packed __aligned(8);
505
506struct ibmvnic_acl_query {
507 u8 first;
508 u8 cmd;
509 u8 reserved1[2];
510 __be32 ioba;
511 __be32 len;
512 u8 reserved2[4];
513} __packed __aligned(8);
514
515struct ibmvnic_tune {
516 u8 first;
517 u8 cmd;
518 u8 reserved1[2];
519 __be32 ioba;
520 __be32 len;
521 u8 reserved2[4];
522} __packed __aligned(8);
523
524struct ibmvnic_request_map {
525 u8 first;
526 u8 cmd;
527 u8 reserved1;
528 u8 map_id;
529 __be32 ioba;
530 __be32 len;
531 u8 reserved2[4];
532} __packed __aligned(8);
533
534struct ibmvnic_request_map_rsp {
535 u8 first;
536 u8 cmd;
537 u8 reserved1;
538 u8 map_id;
Thomas Falcon288ccb72017-06-21 14:53:00 -0500539 u8 reserved2[8];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600540 struct ibmvnic_rc rc;
541} __packed __aligned(8);
542
543struct ibmvnic_request_unmap {
544 u8 first;
545 u8 cmd;
546 u8 reserved1;
547 u8 map_id;
548 u8 reserved2[12];
549} __packed __aligned(8);
550
551struct ibmvnic_request_unmap_rsp {
552 u8 first;
553 u8 cmd;
554 u8 reserved1;
555 u8 map_id;
556 u8 reserved2[8];
557 struct ibmvnic_rc rc;
558} __packed __aligned(8);
559
560struct ibmvnic_query_map {
561 u8 first;
562 u8 cmd;
563 u8 reserved[14];
564} __packed __aligned(8);
565
566struct ibmvnic_query_map_rsp {
567 u8 first;
568 u8 cmd;
569 u8 reserved;
570 u8 page_size;
571 __be32 tot_pages;
572 __be32 free_pages;
573 struct ibmvnic_rc rc;
574} __packed __aligned(8);
575
576union ibmvnic_crq {
577 struct ibmvnic_generic_crq generic;
578 struct ibmvnic_version_exchange version_exchange;
579 struct ibmvnic_version_exchange version_exchange_rsp;
580 struct ibmvnic_capability query_capability;
581 struct ibmvnic_capability query_capability_rsp;
582 struct ibmvnic_capability request_capability;
583 struct ibmvnic_capability request_capability_rsp;
584 struct ibmvnic_login login;
585 struct ibmvnic_generic_crq login_rsp;
586 struct ibmvnic_phys_parms query_phys_parms;
587 struct ibmvnic_phys_parms query_phys_parms_rsp;
588 struct ibmvnic_phys_parms query_phys_capabilities;
589 struct ibmvnic_phys_parms query_phys_capabilities_rsp;
590 struct ibmvnic_phys_parms set_phys_parms;
591 struct ibmvnic_phys_parms set_phys_parms_rsp;
592 struct ibmvnic_logical_link_state logical_link_state;
593 struct ibmvnic_logical_link_state logical_link_state_rsp;
594 struct ibmvnic_query_ip_offload query_ip_offload;
595 struct ibmvnic_query_ip_offload query_ip_offload_rsp;
596 struct ibmvnic_control_ip_offload control_ip_offload;
597 struct ibmvnic_control_ip_offload control_ip_offload_rsp;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600598 struct ibmvnic_request_statistics request_statistics;
599 struct ibmvnic_generic_crq request_statistics_rsp;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600600 struct ibmvnic_error_indication error_indication;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600601 struct ibmvnic_link_state_indication link_state_indication;
602 struct ibmvnic_change_mac_addr change_mac_addr;
603 struct ibmvnic_change_mac_addr change_mac_addr_rsp;
604 struct ibmvnic_multicast_ctrl multicast_ctrl;
605 struct ibmvnic_multicast_ctrl multicast_ctrl_rsp;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200606 struct ibmvnic_get_vpd_size get_vpd_size;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600607 struct ibmvnic_get_vpd_size_rsp get_vpd_size_rsp;
608 struct ibmvnic_get_vpd get_vpd;
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200609 struct ibmvnic_get_vpd_rsp get_vpd_rsp;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600610 struct ibmvnic_acl_change_indication acl_change_indication;
611 struct ibmvnic_acl_query acl_query;
612 struct ibmvnic_generic_crq acl_query_rsp;
613 struct ibmvnic_tune tune;
614 struct ibmvnic_generic_crq tune_rsp;
615 struct ibmvnic_request_map request_map;
616 struct ibmvnic_request_map_rsp request_map_rsp;
617 struct ibmvnic_request_unmap request_unmap;
618 struct ibmvnic_request_unmap_rsp request_unmap_rsp;
619 struct ibmvnic_query_map query_map;
620 struct ibmvnic_query_map_rsp query_map_rsp;
621};
622
623enum ibmvnic_rc_codes {
624 SUCCESS = 0,
625 PARTIALSUCCESS = 1,
626 PERMISSION = 2,
627 NOMEMORY = 3,
628 PARAMETER = 4,
629 UNKNOWNCOMMAND = 5,
630 ABORTED = 6,
631 INVALIDSTATE = 7,
632 INVALIDIOBA = 8,
633 INVALIDLENGTH = 9,
634 UNSUPPORTEDOPTION = 10,
635};
636
637enum ibmvnic_capabilities {
638 MIN_TX_QUEUES = 1,
639 MIN_RX_QUEUES = 2,
640 MIN_RX_ADD_QUEUES = 3,
641 MAX_TX_QUEUES = 4,
642 MAX_RX_QUEUES = 5,
643 MAX_RX_ADD_QUEUES = 6,
644 REQ_TX_QUEUES = 7,
645 REQ_RX_QUEUES = 8,
646 REQ_RX_ADD_QUEUES = 9,
647 MIN_TX_ENTRIES_PER_SUBCRQ = 10,
648 MIN_RX_ADD_ENTRIES_PER_SUBCRQ = 11,
649 MAX_TX_ENTRIES_PER_SUBCRQ = 12,
650 MAX_RX_ADD_ENTRIES_PER_SUBCRQ = 13,
651 REQ_TX_ENTRIES_PER_SUBCRQ = 14,
652 REQ_RX_ADD_ENTRIES_PER_SUBCRQ = 15,
653 TCP_IP_OFFLOAD = 16,
654 PROMISC_REQUESTED = 17,
655 PROMISC_SUPPORTED = 18,
656 MIN_MTU = 19,
657 MAX_MTU = 20,
658 REQ_MTU = 21,
659 MAX_MULTICAST_FILTERS = 22,
660 VLAN_HEADER_INSERTION = 23,
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -0400661 RX_VLAN_HEADER_INSERTION = 24,
Thomas Falcon032c5e82015-12-21 11:26:06 -0600662 MAX_TX_SG_ENTRIES = 25,
663 RX_SG_SUPPORTED = 26,
664 RX_SG_REQUESTED = 27,
665 OPT_TX_COMP_SUB_QUEUES = 28,
666 OPT_RX_COMP_QUEUES = 29,
667 OPT_RX_BUFADD_Q_PER_RX_COMP_Q = 30,
668 OPT_TX_ENTRIES_PER_SUBCRQ = 31,
669 OPT_RXBA_ENTRIES_PER_SUBCRQ = 32,
670 TX_RX_DESC_REQ = 33,
671};
672
673enum ibmvnic_error_cause {
674 ADAPTER_PROBLEM = 0,
675 BUS_PROBLEM = 1,
676 FW_PROBLEM = 2,
677 DD_PROBLEM = 3,
678 EEH_RECOVERY = 4,
679 FW_UPDATED = 5,
680 LOW_MEMORY = 6,
681};
682
683enum ibmvnic_commands {
684 VERSION_EXCHANGE = 0x01,
685 VERSION_EXCHANGE_RSP = 0x81,
686 QUERY_CAPABILITY = 0x02,
687 QUERY_CAPABILITY_RSP = 0x82,
688 REQUEST_CAPABILITY = 0x03,
689 REQUEST_CAPABILITY_RSP = 0x83,
690 LOGIN = 0x04,
691 LOGIN_RSP = 0x84,
692 QUERY_PHYS_PARMS = 0x05,
693 QUERY_PHYS_PARMS_RSP = 0x85,
694 QUERY_PHYS_CAPABILITIES = 0x06,
695 QUERY_PHYS_CAPABILITIES_RSP = 0x86,
696 SET_PHYS_PARMS = 0x07,
697 SET_PHYS_PARMS_RSP = 0x87,
698 ERROR_INDICATION = 0x08,
Thomas Falcon032c5e82015-12-21 11:26:06 -0600699 LOGICAL_LINK_STATE = 0x0C,
700 LOGICAL_LINK_STATE_RSP = 0x8C,
701 REQUEST_STATISTICS = 0x0D,
702 REQUEST_STATISTICS_RSP = 0x8D,
Thomas Falcon032c5e82015-12-21 11:26:06 -0600703 COLLECT_FW_TRACE = 0x11,
704 COLLECT_FW_TRACE_RSP = 0x91,
705 LINK_STATE_INDICATION = 0x12,
706 CHANGE_MAC_ADDR = 0x13,
707 CHANGE_MAC_ADDR_RSP = 0x93,
708 MULTICAST_CTRL = 0x14,
709 MULTICAST_CTRL_RSP = 0x94,
710 GET_VPD_SIZE = 0x15,
711 GET_VPD_SIZE_RSP = 0x95,
712 GET_VPD = 0x16,
713 GET_VPD_RSP = 0x96,
714 TUNE = 0x17,
715 TUNE_RSP = 0x97,
716 QUERY_IP_OFFLOAD = 0x18,
717 QUERY_IP_OFFLOAD_RSP = 0x98,
718 CONTROL_IP_OFFLOAD = 0x19,
719 CONTROL_IP_OFFLOAD_RSP = 0x99,
720 ACL_CHANGE_INDICATION = 0x1A,
721 ACL_QUERY = 0x1B,
722 ACL_QUERY_RSP = 0x9B,
Thomas Falcon032c5e82015-12-21 11:26:06 -0600723 QUERY_MAP = 0x1D,
724 QUERY_MAP_RSP = 0x9D,
725 REQUEST_MAP = 0x1E,
726 REQUEST_MAP_RSP = 0x9E,
727 REQUEST_UNMAP = 0x1F,
728 REQUEST_UNMAP_RSP = 0x9F,
729 VLAN_CTRL = 0x20,
730 VLAN_CTRL_RSP = 0xA0,
731};
732
733enum ibmvnic_crq_type {
734 IBMVNIC_CRQ_CMD = 0x80,
735 IBMVNIC_CRQ_CMD_RSP = 0x80,
736 IBMVNIC_CRQ_INIT_CMD = 0xC0,
737 IBMVNIC_CRQ_INIT_RSP = 0xC0,
738 IBMVNIC_CRQ_XPORT_EVENT = 0xFF,
739};
740
741enum ibmvfc_crq_format {
742 IBMVNIC_CRQ_INIT = 0x01,
743 IBMVNIC_CRQ_INIT_COMPLETE = 0x02,
744 IBMVNIC_PARTITION_MIGRATED = 0x06,
Thomas Falcondfad09a2016-08-18 11:37:51 -0500745 IBMVNIC_DEVICE_FAILOVER = 0x08,
Thomas Falcon032c5e82015-12-21 11:26:06 -0600746};
747
748struct ibmvnic_crq_queue {
749 union ibmvnic_crq *msgs;
750 int size, cur;
751 dma_addr_t msg_token;
Lijun Pana369d962021-02-11 00:43:23 -0600752 /* Used for serialization of msgs, cur */
Thomas Falcon032c5e82015-12-21 11:26:06 -0600753 spinlock_t lock;
Thomas Falcon51536982018-05-23 13:37:56 -0500754 bool active;
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -0300755 char name[32];
Thomas Falcon032c5e82015-12-21 11:26:06 -0600756};
757
758union sub_crq {
759 struct ibmvnic_generic_scrq generic;
760 struct ibmvnic_tx_comp_desc tx_comp;
761 struct ibmvnic_tx_desc v1;
762 struct ibmvnic_hdr_desc hdr;
763 struct ibmvnic_hdr_ext_desc hdr_ext;
764 struct ibmvnic_sge_desc sge;
765 struct ibmvnic_rx_comp_desc rx_comp;
766 struct ibmvnic_rx_buff_add_desc rx_add;
767};
768
Thomas Falconf019fb62020-11-18 19:12:17 -0600769struct ibmvnic_ind_xmit_queue {
770 union sub_crq *indir_arr;
771 dma_addr_t indir_dma;
772 int index;
773};
774
Thomas Falcon032c5e82015-12-21 11:26:06 -0600775struct ibmvnic_sub_crq_queue {
776 union sub_crq *msgs;
777 int size, cur;
778 dma_addr_t msg_token;
779 unsigned long crq_num;
780 unsigned long hw_irq;
781 unsigned int irq;
782 unsigned int pool_index;
783 int scrq_num;
Lijun Pana369d962021-02-11 00:43:23 -0600784 /* Used for serialization of msgs, cur */
Thomas Falcon032c5e82015-12-21 11:26:06 -0600785 spinlock_t lock;
786 struct sk_buff *rx_skb_top;
787 struct ibmvnic_adapter *adapter;
Thomas Falconf019fb62020-11-18 19:12:17 -0600788 struct ibmvnic_ind_xmit_queue ind_buf;
Thomas Falcon142c0ac2017-03-05 12:18:41 -0600789 atomic_t used;
Murilo Fossa Vicentinie56e2512019-04-25 11:02:33 -0300790 char name[32];
Cristobal Fornof3ae59c2020-08-19 13:16:23 -0500791 u64 handle;
Dwip N. Banerjee9a87c3f2020-11-18 19:12:22 -0600792} ____cacheline_aligned;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600793
794struct ibmvnic_long_term_buff {
795 unsigned char *buff;
796 dma_addr_t addr;
797 u64 size;
798 u8 map_id;
799};
800
801struct ibmvnic_tx_buff {
802 struct sk_buff *skb;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600803 int index;
804 int pool_index;
Thomas Falconffc385b2018-02-18 10:08:41 -0600805 int num_entries;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600806};
807
808struct ibmvnic_tx_pool {
809 struct ibmvnic_tx_buff *tx_buff;
810 int *free_map;
811 int consumer_index;
812 int producer_index;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600813 struct ibmvnic_long_term_buff long_term_buff;
Thomas Falcon4bd95a52018-03-16 20:00:24 -0500814 int num_buffers;
815 int buf_size;
Dwip N. Banerjee9a87c3f2020-11-18 19:12:22 -0600816} ____cacheline_aligned;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600817
818struct ibmvnic_rx_buff {
819 struct sk_buff *skb;
820 dma_addr_t dma;
821 unsigned char *data;
822 int size;
823 int pool_index;
824};
825
826struct ibmvnic_rx_pool {
827 struct ibmvnic_rx_buff *rx_buff;
Sukadev Bhattiprolu0df7b9a2021-09-14 20:52:53 -0700828 int size; /* # of buffers in the pool */
Thomas Falcon032c5e82015-12-21 11:26:06 -0600829 int index;
830 int buff_size;
831 atomic_t available;
832 int *free_map;
833 int next_free;
834 int next_alloc;
835 int active;
836 struct ibmvnic_long_term_buff long_term_buff;
Dwip N. Banerjee9a87c3f2020-11-18 19:12:22 -0600837} ____cacheline_aligned;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600838
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200839struct ibmvnic_vpd {
840 unsigned char *buff;
841 dma_addr_t dma_addr;
842 u64 len;
843};
844
Nathan Fontenot90c80142017-05-03 14:04:32 -0400845enum vnic_state {VNIC_PROBING = 1,
846 VNIC_PROBED,
847 VNIC_OPENING,
848 VNIC_OPEN,
849 VNIC_CLOSING,
850 VNIC_CLOSED,
851 VNIC_REMOVING,
Cristobal Forno53f8b1b2021-06-10 11:08:35 -0600852 VNIC_REMOVED,
853 VNIC_DOWN};
Nathan Fontenot90c80142017-05-03 14:04:32 -0400854
Nathan Fontenoted651a12017-05-03 14:04:38 -0400855enum ibmvnic_reset_reason {VNIC_RESET_FAILOVER = 1,
856 VNIC_RESET_MOBILITY,
857 VNIC_RESET_FATAL,
John Allen8cb31cf2017-05-26 10:30:37 -0400858 VNIC_RESET_NON_FATAL,
John Allenc26eba02017-10-26 16:23:25 -0500859 VNIC_RESET_TIMEOUT,
Cristobal Forno53f8b1b2021-06-10 11:08:35 -0600860 VNIC_RESET_CHANGE_PARAM,
861 VNIC_RESET_PASSIVE_INIT};
Nathan Fontenoted651a12017-05-03 14:04:38 -0400862
863struct ibmvnic_rwi {
864 enum ibmvnic_reset_reason reset_reason;
865 struct list_head list;
866};
867
John Allenc26eba02017-10-26 16:23:25 -0500868struct ibmvnic_tunables {
869 u64 rx_queues;
870 u64 tx_queues;
871 u64 rx_entries;
872 u64 tx_entries;
873 u64 mtu;
John Allenc26eba02017-10-26 16:23:25 -0500874};
875
Thomas Falcon032c5e82015-12-21 11:26:06 -0600876struct ibmvnic_adapter {
877 struct vio_dev *vdev;
878 struct net_device *netdev;
879 struct ibmvnic_crq_queue crq;
880 u8 mac_addr[ETH_ALEN];
881 struct ibmvnic_query_ip_offload_buffer ip_offload_buf;
882 dma_addr_t ip_offload_tok;
883 struct ibmvnic_control_ip_offload_buffer ip_offload_ctrl;
884 dma_addr_t ip_offload_ctrl_tok;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600885 u32 msg_enable;
Thomas Falcon723ad912018-09-28 18:38:26 -0500886 u32 priv_flags;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600887
Desnes Augusto Nunes do Rosario4e6759b2017-11-13 15:59:19 -0200888 /* Vital Product Data (VPD) */
889 struct ibmvnic_vpd *vpd;
890 char fw_version[32];
891
Thomas Falcon032c5e82015-12-21 11:26:06 -0600892 /* Statistics */
Thomas Falcon032c5e82015-12-21 11:26:06 -0600893 struct ibmvnic_statistics stats;
894 dma_addr_t stats_token;
895 struct completion stats_done;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600896 int replenish_no_mem;
897 int replenish_add_buff_success;
898 int replenish_add_buff_failure;
899 int replenish_task_cycles;
900 int tx_send_failed;
901 int tx_map_failed;
902
John Allen3d52b592017-08-02 16:44:14 -0500903 struct ibmvnic_tx_queue_stats *tx_stats_buffers;
904 struct ibmvnic_rx_queue_stats *rx_stats_buffers;
905
Thomas Falcon032c5e82015-12-21 11:26:06 -0600906 int phys_link_state;
907 int logical_link_state;
908
Murilo Fossa Vicentinif8d6ae02019-03-19 10:28:51 -0300909 u32 speed;
910 u8 duplex;
911
Thomas Falcon032c5e82015-12-21 11:26:06 -0600912 /* login data */
913 struct ibmvnic_login_buffer *login_buf;
914 dma_addr_t login_buf_token;
915 int login_buf_sz;
916
917 struct ibmvnic_login_rsp_buffer *login_rsp_buf;
918 dma_addr_t login_rsp_buf_token;
919 int login_rsp_buf_sz;
920
Thomas Falcon901e0402017-02-15 12:17:59 -0600921 atomic_t running_cap_crqs;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600922
Dwip N. Banerjee9a87c3f2020-11-18 19:12:22 -0600923 struct ibmvnic_sub_crq_queue **tx_scrq ____cacheline_aligned;
924 struct ibmvnic_sub_crq_queue **rx_scrq ____cacheline_aligned;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600925
926 /* rx structs */
927 struct napi_struct *napi;
928 struct ibmvnic_rx_pool *rx_pool;
929 u64 promisc;
930
931 struct ibmvnic_tx_pool *tx_pool;
Thomas Falcon4bd95a52018-03-16 20:00:24 -0500932 struct ibmvnic_tx_pool *tso_pool;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600933 struct completion init_done;
Nathan Fontenot53da09e2017-04-21 15:39:04 -0400934 int init_done_rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600935
Thomas Falcon032c5e82015-12-21 11:26:06 -0600936 struct completion fw_done;
Thomas Falconff25dcb2019-11-25 17:12:56 -0600937 /* Used for serialization of device commands */
938 struct mutex fw_lock;
Thomas Falconf3be0cb2017-06-21 14:53:01 -0500939 int fw_done_rc;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600940
John Allenc26eba02017-10-26 16:23:25 -0500941 struct completion reset_done;
942 int reset_done_rc;
943 bool wait_for_reset;
944
Thomas Falcon032c5e82015-12-21 11:26:06 -0600945 /* partner capabilities */
946 u64 min_tx_queues;
947 u64 min_rx_queues;
948 u64 min_rx_add_queues;
949 u64 max_tx_queues;
950 u64 max_rx_queues;
951 u64 max_rx_add_queues;
952 u64 req_tx_queues;
953 u64 req_rx_queues;
954 u64 req_rx_add_queues;
955 u64 min_tx_entries_per_subcrq;
956 u64 min_rx_add_entries_per_subcrq;
957 u64 max_tx_entries_per_subcrq;
958 u64 max_rx_add_entries_per_subcrq;
959 u64 req_tx_entries_per_subcrq;
960 u64 req_rx_add_entries_per_subcrq;
961 u64 tcp_ip_offload;
962 u64 promisc_requested;
963 u64 promisc_supported;
964 u64 min_mtu;
965 u64 max_mtu;
966 u64 req_mtu;
Sukadev Bhattiprolubbd80932021-09-14 20:52:59 -0700967 u64 prev_mtu;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600968 u64 max_multicast_filters;
969 u64 vlan_header_insertion;
Murilo Fossa Vicentini6052d5e2017-04-21 15:38:46 -0400970 u64 rx_vlan_header_insertion;
Thomas Falcon032c5e82015-12-21 11:26:06 -0600971 u64 max_tx_sg_entries;
972 u64 rx_sg_supported;
973 u64 rx_sg_requested;
974 u64 opt_tx_comp_sub_queues;
975 u64 opt_rx_comp_queues;
976 u64 opt_rx_bufadd_q_per_rx_comp_q;
977 u64 opt_tx_entries_per_subcrq;
978 u64 opt_rxba_entries_per_subcrq;
979 __be64 tx_rx_desc_req;
Sukadev Bhattiprolu129854f02021-09-14 20:52:56 -0700980#define MAX_MAP_ID 255
981 DECLARE_BITMAP(map_ids, MAX_MAP_ID);
Nathan Fontenot82e3be32018-02-21 21:33:56 -0600982 u32 num_active_rx_scrqs;
983 u32 num_active_rx_pools;
984 u32 num_active_rx_napi;
985 u32 num_active_tx_scrqs;
986 u32 num_active_tx_pools;
Sukadev Bhattiprolu489de952021-09-14 20:52:58 -0700987
988 u32 prev_rx_pool_size;
Sukadev Bhattiprolubbd80932021-09-14 20:52:59 -0700989 u32 prev_tx_pool_size;
Thomas Falcon507ebe62020-08-21 13:39:01 -0500990 u32 cur_rx_buf_sz;
Sukadev Bhattiprolu489de952021-09-14 20:52:58 -0700991 u32 prev_rx_buf_sz;
Thomas Falcon65dc6892016-07-06 15:35:18 -0500992
Thomas Falcon6c267b32017-02-15 12:17:58 -0600993 struct tasklet_struct tasklet;
Nathan Fontenot90c80142017-05-03 14:04:32 -0400994 enum vnic_state state;
Jakub Kicinskib646acd52021-02-16 22:58:44 -0800995 /* Used for serialization of state field. When taking both state
996 * and rwi locks, take state lock first.
997 */
Lijun Pana369d962021-02-11 00:43:23 -0600998 spinlock_t state_lock;
Nathan Fontenoted651a12017-05-03 14:04:38 -0400999 enum ibmvnic_reset_reason reset_reason;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001000 struct list_head rwi_list;
Jakub Kicinskib646acd52021-02-16 22:58:44 -08001001 /* Used for serialization of rwi_list. When taking both state
1002 * and rwi locks, take state lock first
1003 */
Lijun Pana369d962021-02-11 00:43:23 -06001004 spinlock_t rwi_lock;
Nathan Fontenoted651a12017-05-03 14:04:38 -04001005 struct work_struct ibmvnic_reset;
Juliet Kim7ed5b312019-09-20 16:11:23 -04001006 struct delayed_work ibmvnic_delayed_reset;
1007 unsigned long resetting;
John Allen017892c12017-05-26 10:30:19 -04001008 bool napi_enabled, from_passive_init;
Sukadev Bhattiprolu76cdc5c2020-11-25 18:04:29 -06001009 bool login_pending;
Dany Maddena86d5c62020-11-25 18:04:31 -06001010 /* last device reset time */
1011 unsigned long last_reset_time;
John Allenc26eba02017-10-26 16:23:25 -05001012
Thomas Falcon5a18e1e2018-04-06 18:37:05 -05001013 bool failover_pending;
Thomas Falcon2770a792018-05-23 13:38:02 -05001014 bool force_reset_recovery;
John Allenc26eba02017-10-26 16:23:25 -05001015
1016 struct ibmvnic_tunables desired;
1017 struct ibmvnic_tunables fallback;
Thomas Falcon032c5e82015-12-21 11:26:06 -06001018};