Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /**************************************************************************/
0003 /*                                                                        */
0004 /*  IBM System i and System p Virtual NIC Device Driver                   */
0005 /*  Copyright (C) 2014 IBM Corp.                                          */
0006 /*  Santiago Leon (santi_leon@yahoo.com)                                  */
0007 /*  Thomas Falcon (tlfalcon@linux.vnet.ibm.com)                           */
0008 /*  John Allen (jallen@linux.vnet.ibm.com)                                */
0009 /*                                                                        */
0010 /*                                                                        */
0011 /* This module contains the implementation of a virtual ethernet device   */
0012 /* for use with IBM i/pSeries LPAR Linux.  It utilizes the logical LAN    */
0013 /* option of the RS/6000 Platform Architecture to interface with virtual */
0014 /* ethernet NICs that are presented to the partition by the hypervisor.   */
0015 /*                                                                        */
0016 /**************************************************************************/
0017 
0018 #define IBMVNIC_NAME        "ibmvnic"
0019 #define IBMVNIC_DRIVER_VERSION  "1.0.1"
0020 #define IBMVNIC_INVALID_MAP -1
0021 #define IBMVNIC_OPEN_FAILED 3
0022 
0023 /* basic structures plus 100 2k buffers */
0024 #define IBMVNIC_IO_ENTITLEMENT_DEFAULT  610305
0025 
0026 /* Initial module_parameters */
0027 #define IBMVNIC_RX_WEIGHT       16
0028 /* when changing this, update IBMVNIC_IO_ENTITLEMENT_DEFAULT */
0029 #define IBMVNIC_BUFFS_PER_POOL  100
0030 #define IBMVNIC_MAX_QUEUES  16
0031 #define IBMVNIC_MAX_QUEUE_SZ   4096
0032 #define IBMVNIC_MAX_IND_DESCS  16
0033 #define IBMVNIC_IND_ARR_SZ  (IBMVNIC_MAX_IND_DESCS * 32)
0034 
0035 #define IBMVNIC_TSO_BUF_SZ  65536
0036 #define IBMVNIC_TSO_BUFS    64
0037 #define IBMVNIC_TSO_POOL_MASK   0x80000000
0038 
0039 /* A VNIC adapter has set of Rx and Tx pools (aka queues). Each Rx/Tx pool
0040  * has a set of buffers. The size of each buffer is determined by the MTU.
0041  *
0042  * Each Rx/Tx pool is also associated with a DMA region that is shared
0043  * with the "hardware" (VIOS) and used to send/receive packets. The DMA
0044  * region is also referred to as a Long Term Buffer or LTB.
0045  *
0046  * The size of the DMA region required for an Rx/Tx pool depends on the
0047  * number and size (MTU) of the buffers in the pool. At the max levels
0048  * of 4096 jumbo frames (MTU=9000) we will need about 9K*4K = 36MB plus
0049  * some padding.
0050  *
0051  * But the size of a single DMA region is limited by MAX_ORDER in the
0052  * kernel (about 16MB currently).  To support say 4K Jumbo frames, we
0053  * use a set of LTBs (struct ltb_set) per pool.
0054  *
0055  * IBMVNIC_ONE_LTB_MAX  - max size of each LTB supported by kernel
0056  * IBMVNIC_ONE_LTB_SIZE - current max size of each LTB in an ltb_set
0057  * (must be <= IBMVNIC_ONE_LTB_MAX)
0058  * IBMVNIC_LTB_SET_SIZE - current size of all LTBs in an ltb_set
0059  *
0060  * Each VNIC can have upto 16 Rx, 16 Tx and 16 TSO pools. The TSO pools
0061  * are of fixed length (IBMVNIC_TSO_BUF_SZ * IBMVNIC_TSO_BUFS) of 4MB.
0062  *
0063  * The Rx and Tx pools can have upto 4096 buffers. The max size of these
0064  * buffers is about 9588 (for jumbo frames, including IBMVNIC_BUFFER_HLEN).
0065  * So, setting the IBMVNIC_LTB_SET_SIZE for a pool to 4096 * 9588 ~= 38MB.
0066  *
0067  * There is a trade-off in setting IBMVNIC_ONE_LTB_SIZE. If it is large,
0068  * the allocation of the LTB can fail when system is low in memory. If
0069  * its too small, we would need several mappings for each of the Rx/
0070  * Tx/TSO pools but there is a limit of 255 mappings per vnic in the
0071  * VNIC protocol.
0072  *
0073  * So setting IBMVNIC_ONE_LTB_SIZE to 8MB. With IBMVNIC_LTB_SET_SIZE set
0074  * to 38MB, we will need 5 LTBs per Rx and Tx pool and 1 LTB per TSO
0075  * pool for the 4MB. Thus the 16 Rx and Tx queues require 32 * 5 = 160
0076  * plus 16 for the TSO pools for a total of 176 LTB mappings per VNIC.
0077  */
0078 #define IBMVNIC_ONE_LTB_MAX ((u32)((1 << (MAX_ORDER - 1)) * PAGE_SIZE))
0079 #define IBMVNIC_ONE_LTB_SIZE    min((u32)(8 << 20), IBMVNIC_ONE_LTB_MAX)
0080 #define IBMVNIC_LTB_SET_SIZE    (38 << 20)
0081 
0082 #define IBMVNIC_BUFFER_HLEN     500
0083 #define IBMVNIC_RESET_DELAY 100
0084 
0085 struct ibmvnic_login_buffer {
0086     __be32 len;
0087     __be32 version;
0088 #define INITIAL_VERSION_LB 1
0089     __be32 num_txcomp_subcrqs;
0090     __be32 off_txcomp_subcrqs;
0091     __be32 num_rxcomp_subcrqs;
0092     __be32 off_rxcomp_subcrqs;
0093     __be32 login_rsp_ioba;
0094     __be32 login_rsp_len;
0095     __be32 client_data_offset;
0096     __be32 client_data_len;
0097 } __packed __aligned(8);
0098 
0099 struct ibmvnic_login_rsp_buffer {
0100     __be32 len;
0101     __be32 version;
0102 #define INITIAL_VERSION_LRB 1
0103     __be32 num_txsubm_subcrqs;
0104     __be32 off_txsubm_subcrqs;
0105     __be32 num_rxadd_subcrqs;
0106     __be32 off_rxadd_subcrqs;
0107     __be32 off_rxadd_buff_size;
0108     __be32 num_supp_tx_desc;
0109     __be32 off_supp_tx_desc;
0110 } __packed __aligned(8);
0111 
0112 struct ibmvnic_query_ip_offload_buffer {
0113     __be32 len;
0114     __be32 version;
0115 #define INITIAL_VERSION_IOB 1
0116     u8 ipv4_chksum;
0117     u8 ipv6_chksum;
0118     u8 tcp_ipv4_chksum;
0119     u8 tcp_ipv6_chksum;
0120     u8 udp_ipv4_chksum;
0121     u8 udp_ipv6_chksum;
0122     u8 large_tx_ipv4;
0123     u8 large_tx_ipv6;
0124     u8 large_rx_ipv4;
0125     u8 large_rx_ipv6;
0126     u8 reserved1[14];
0127     __be16 max_ipv4_header_size;
0128     __be16 max_ipv6_header_size;
0129     __be16 max_tcp_header_size;
0130     __be16 max_udp_header_size;
0131     __be32 max_large_tx_size;
0132     __be32 max_large_rx_size;
0133     u8 reserved2[16];
0134     u8 ipv6_extension_header;
0135 #define IPV6_EH_NOT_SUPPORTED   0x00
0136 #define IPV6_EH_SUPPORTED_LIM   0x01
0137 #define IPV6_EH_SUPPORTED   0xFF
0138     u8 tcp_pseudosum_req;
0139 #define TCP_PS_NOT_REQUIRED 0x00
0140 #define TCP_PS_REQUIRED     0x01
0141     u8 reserved3[30];
0142     __be16 num_ipv6_ext_headers;
0143     __be32 off_ipv6_ext_headers;
0144     u8 reserved4[154];
0145 } __packed __aligned(8);
0146 
0147 struct ibmvnic_control_ip_offload_buffer {
0148     __be32 len;
0149     __be32 version;
0150 #define INITIAL_VERSION_IOB 1
0151     u8 ipv4_chksum;
0152     u8 ipv6_chksum;
0153     u8 tcp_ipv4_chksum;
0154     u8 tcp_ipv6_chksum;
0155     u8 udp_ipv4_chksum;
0156     u8 udp_ipv6_chksum;
0157     u8 large_tx_ipv4;
0158     u8 large_tx_ipv6;
0159     u8 bad_packet_rx;
0160     u8 large_rx_ipv4;
0161     u8 large_rx_ipv6;
0162     u8 reserved4[111];
0163 } __packed __aligned(8);
0164 
0165 struct ibmvnic_fw_component {
0166     u8 name[48];
0167     __be32 trace_buff_size;
0168     u8 correlator;
0169     u8 trace_level;
0170     u8 parent_correlator;
0171     u8 error_check_level;
0172     u8 trace_on;
0173     u8 reserved[7];
0174     u8 description[192];
0175 } __packed __aligned(8);
0176 
0177 struct ibmvnic_fw_trace_entry {
0178     __be32 trace_id;
0179     u8 num_valid_data;
0180     u8 reserved[3];
0181     __be64 pmc_registers;
0182     __be64 timebase;
0183     __be64 trace_data[5];
0184 } __packed __aligned(8);
0185 
0186 struct ibmvnic_statistics {
0187     __be32 version;
0188     __be32 promiscuous;
0189     __be64 rx_packets;
0190     __be64 rx_bytes;
0191     __be64 tx_packets;
0192     __be64 tx_bytes;
0193     __be64 ucast_tx_packets;
0194     __be64 ucast_rx_packets;
0195     __be64 mcast_tx_packets;
0196     __be64 mcast_rx_packets;
0197     __be64 bcast_tx_packets;
0198     __be64 bcast_rx_packets;
0199     __be64 align_errors;
0200     __be64 fcs_errors;
0201     __be64 single_collision_frames;
0202     __be64 multi_collision_frames;
0203     __be64 sqe_test_errors;
0204     __be64 deferred_tx;
0205     __be64 late_collisions;
0206     __be64 excess_collisions;
0207     __be64 internal_mac_tx_errors;
0208     __be64 carrier_sense;
0209     __be64 too_long_frames;
0210     __be64 internal_mac_rx_errors;
0211     u8 reserved[72];
0212 } __packed __aligned(8);
0213 
0214 #define NUM_TX_STATS 3
0215 struct ibmvnic_tx_queue_stats {
0216     u64 packets;
0217     u64 bytes;
0218     u64 dropped_packets;
0219 };
0220 
0221 #define NUM_RX_STATS 3
0222 struct ibmvnic_rx_queue_stats {
0223     u64 packets;
0224     u64 bytes;
0225     u64 interrupts;
0226 };
0227 
0228 struct ibmvnic_acl_buffer {
0229     __be32 len;
0230     __be32 version;
0231 #define INITIAL_VERSION_IOB 1
0232     u8 mac_acls_restrict;
0233     u8 vlan_acls_restrict;
0234     u8 reserved1[22];
0235     __be32 num_mac_addrs;
0236     __be32 offset_mac_addrs;
0237     __be32 num_vlan_ids;
0238     __be32 offset_vlan_ids;
0239     u8 reserved2[80];
0240 } __packed __aligned(8);
0241 
0242 /* descriptors have been changed, how should this be defined?  1? 4? */
0243 
0244 #define IBMVNIC_TX_DESC_VERSIONS 3
0245 
0246 /* is this still needed? */
0247 struct ibmvnic_tx_comp_desc {
0248     u8 first;
0249     u8 num_comps;
0250     __be16 rcs[5];
0251     __be32 correlators[5];
0252 } __packed __aligned(8);
0253 
0254 /* some flags that included in v0 descriptor, which is gone
0255  * only used for IBMVNIC_TCP_CHKSUM and IBMVNIC_UDP_CHKSUM
0256  * and only in some offload_flags variable that doesn't seem
0257  * to be used anywhere, can probably be removed?
0258  */
0259 
0260 #define IBMVNIC_TCP_CHKSUM      0x20
0261 #define IBMVNIC_UDP_CHKSUM      0x08
0262 
0263 struct ibmvnic_tx_desc {
0264     u8 first;
0265     u8 type;
0266 
0267 #define IBMVNIC_TX_DESC 0x10
0268     u8 n_crq_elem;
0269     u8 n_sge;
0270     u8 flags1;
0271 #define IBMVNIC_TX_COMP_NEEDED      0x80
0272 #define IBMVNIC_TX_CHKSUM_OFFLOAD   0x40
0273 #define IBMVNIC_TX_LSO          0x20
0274 #define IBMVNIC_TX_PROT_TCP     0x10
0275 #define IBMVNIC_TX_PROT_UDP     0x08
0276 #define IBMVNIC_TX_PROT_IPV4        0x04
0277 #define IBMVNIC_TX_PROT_IPV6        0x02
0278 #define IBMVNIC_TX_VLAN_PRESENT     0x01
0279     u8 flags2;
0280 #define IBMVNIC_TX_VLAN_INSERT      0x80
0281     __be16 mss;
0282     u8 reserved[4];
0283     __be32 correlator;
0284     __be16 vlan_id;
0285     __be16 dma_reg;
0286     __be32 sge_len;
0287     __be64 ioba;
0288 } __packed __aligned(8);
0289 
0290 struct ibmvnic_hdr_desc {
0291     u8 first;
0292     u8 type;
0293 #define IBMVNIC_HDR_DESC        0x11
0294     u8 len;
0295     u8 l2_len;
0296     __be16 l3_len;
0297     u8 l4_len;
0298     u8 flag;
0299     u8 data[24];
0300 } __packed __aligned(8);
0301 
0302 struct ibmvnic_hdr_ext_desc {
0303     u8 first;
0304     u8 type;
0305 #define IBMVNIC_HDR_EXT_DESC        0x12
0306     u8 len;
0307     u8 data[29];
0308 } __packed __aligned(8);
0309 
0310 struct ibmvnic_sge_desc {
0311     u8 first;
0312     u8 type;
0313 #define IBMVNIC_SGE_DESC        0x30
0314     __be16 sge1_dma_reg;
0315     __be32 sge1_len;
0316     __be64 sge1_ioba;
0317     __be16 reserved;
0318     __be16 sge2_dma_reg;
0319     __be32 sge2_len;
0320     __be64 sge2_ioba;
0321 } __packed __aligned(8);
0322 
0323 struct ibmvnic_rx_comp_desc {
0324     u8 first;
0325     u8 flags;
0326 #define IBMVNIC_IP_CHKSUM_GOOD      0x80
0327 #define IBMVNIC_TCP_UDP_CHKSUM_GOOD 0x40
0328 #define IBMVNIC_END_FRAME           0x20
0329 #define IBMVNIC_EXACT_MC            0x10
0330 #define IBMVNIC_VLAN_STRIPPED           0x08
0331     __be16 off_frame_data;
0332     __be32 len;
0333     __be64 correlator;
0334     __be16 vlan_tci;
0335     __be16 rc;
0336     u8 reserved[12];
0337 } __packed __aligned(8);
0338 
0339 struct ibmvnic_generic_scrq {
0340     u8 first;
0341     u8 reserved[31];
0342 } __packed __aligned(8);
0343 
0344 struct ibmvnic_rx_buff_add_desc {
0345     u8 first;
0346     u8 reserved[7];
0347     __be64 correlator;
0348     __be32 ioba;
0349     u8 map_id;
0350     __be32 len:24;
0351     u8 reserved2[8];
0352 } __packed __aligned(8);
0353 
0354 struct ibmvnic_rc {
0355     u8 code; /* one of enum ibmvnic_rc_codes */
0356     u8 detailed_data[3];
0357 } __packed __aligned(4);
0358 
0359 struct ibmvnic_generic_crq {
0360     u8 first;
0361     u8 cmd;
0362     u8 params[10];
0363     struct ibmvnic_rc rc;
0364 } __packed __aligned(8);
0365 
0366 struct ibmvnic_version_exchange {
0367     u8 first;
0368     u8 cmd;
0369     __be16 version;
0370 #define IBMVNIC_INITIAL_VERSION 1
0371     u8 reserved[8];
0372     struct ibmvnic_rc rc;
0373 } __packed __aligned(8);
0374 
0375 struct ibmvnic_capability {
0376     u8 first;
0377     u8 cmd;
0378     __be16 capability; /* one of ibmvnic_capabilities */
0379     __be64 number;
0380     struct ibmvnic_rc rc;
0381 } __packed __aligned(8);
0382 
0383 struct ibmvnic_login {
0384     u8 first;
0385     u8 cmd;
0386     u8 reserved[6];
0387     __be32 ioba;
0388     __be32 len;
0389 } __packed __aligned(8);
0390 
0391 struct ibmvnic_phys_parms {
0392     u8 first;
0393     u8 cmd;
0394     u8 flags1;
0395 #define IBMVNIC_EXTERNAL_LOOPBACK   0x80
0396 #define IBMVNIC_INTERNAL_LOOPBACK   0x40
0397 #define IBMVNIC_PROMISC     0x20
0398 #define IBMVNIC_PHYS_LINK_ACTIVE    0x10
0399 #define IBMVNIC_AUTONEG_DUPLEX  0x08
0400 #define IBMVNIC_FULL_DUPLEX 0x04
0401 #define IBMVNIC_HALF_DUPLEX 0x02
0402 #define IBMVNIC_CAN_CHG_PHYS_PARMS  0x01
0403     u8 flags2;
0404 #define IBMVNIC_LOGICAL_LNK_ACTIVE 0x80
0405     __be32 speed;
0406 #define IBMVNIC_AUTONEG     0x80000000
0407 #define IBMVNIC_10MBPS      0x40000000
0408 #define IBMVNIC_100MBPS     0x20000000
0409 #define IBMVNIC_1GBPS       0x10000000
0410 #define IBMVNIC_10GBPS      0x08000000
0411 #define IBMVNIC_40GBPS      0x04000000
0412 #define IBMVNIC_100GBPS     0x02000000
0413 #define IBMVNIC_25GBPS      0x01000000
0414 #define IBMVNIC_50GBPS      0x00800000
0415 #define IBMVNIC_200GBPS     0x00400000
0416     __be32 mtu;
0417     struct ibmvnic_rc rc;
0418 } __packed __aligned(8);
0419 
0420 struct ibmvnic_logical_link_state {
0421     u8 first;
0422     u8 cmd;
0423     u8 link_state;
0424 #define IBMVNIC_LOGICAL_LNK_DN 0x00
0425 #define IBMVNIC_LOGICAL_LNK_UP 0x01
0426 #define IBMVNIC_LOGICAL_LNK_QUERY 0xff
0427     u8 reserved[9];
0428     struct ibmvnic_rc rc;
0429 } __packed __aligned(8);
0430 
0431 struct ibmvnic_query_ip_offload {
0432     u8 first;
0433     u8 cmd;
0434     u8 reserved[2];
0435     __be32 len;
0436     __be32 ioba;
0437     struct ibmvnic_rc rc;
0438 } __packed __aligned(8);
0439 
0440 struct ibmvnic_control_ip_offload {
0441     u8 first;
0442     u8 cmd;
0443     u8 reserved[2];
0444     __be32 ioba;
0445     __be32 len;
0446     struct ibmvnic_rc rc;
0447 } __packed __aligned(8);
0448 
0449 struct ibmvnic_request_statistics {
0450     u8 first;
0451     u8 cmd;
0452     u8 flags;
0453 #define IBMVNIC_PHYSICAL_PORT   0x80
0454     u8 reserved1;
0455     __be32 ioba;
0456     __be32 len;
0457     u8 reserved[4];
0458 } __packed __aligned(8);
0459 
0460 struct ibmvnic_error_indication {
0461     u8 first;
0462     u8 cmd;
0463     u8 flags;
0464 #define IBMVNIC_FATAL_ERROR 0x80
0465     u8 reserved1;
0466     __be32 error_id;
0467     __be32 detail_error_sz;
0468     __be16 error_cause;
0469     u8 reserved2[2];
0470 } __packed __aligned(8);
0471 
0472 struct ibmvnic_link_state_indication {
0473     u8 first;
0474     u8 cmd;
0475     u8 reserved1[2];
0476     u8 phys_link_state;
0477     u8 logical_link_state;
0478     u8 reserved2[10];
0479 } __packed __aligned(8);
0480 
0481 struct ibmvnic_change_mac_addr {
0482     u8 first;
0483     u8 cmd;
0484     u8 mac_addr[6];
0485     u8 reserved[4];
0486     struct ibmvnic_rc rc;
0487 } __packed __aligned(8);
0488 
0489 struct ibmvnic_multicast_ctrl {
0490     u8 first;
0491     u8 cmd;
0492     u8 mac_addr[6];
0493     u8 flags;
0494 #define IBMVNIC_ENABLE_MC       0x80
0495 #define IBMVNIC_DISABLE_MC      0x40
0496 #define IBMVNIC_ENABLE_ALL      0x20
0497 #define IBMVNIC_DISABLE_ALL 0x10
0498     u8 reserved1;
0499     __be16 reserved2; /* was num_enabled_mc_addr; */
0500     struct ibmvnic_rc rc;
0501 } __packed __aligned(8);
0502 
0503 struct ibmvnic_get_vpd_size {
0504     u8 first;
0505     u8 cmd;
0506     u8 reserved[14];
0507 } __packed __aligned(8);
0508 
0509 struct ibmvnic_get_vpd_size_rsp {
0510     u8 first;
0511     u8 cmd;
0512     u8 reserved[2];
0513     __be64 len;
0514     struct ibmvnic_rc rc;
0515 } __packed __aligned(8);
0516 
0517 struct ibmvnic_get_vpd {
0518     u8 first;
0519     u8 cmd;
0520     u8 reserved1[2];
0521     __be32 ioba;
0522     __be32 len;
0523     u8 reserved[4];
0524 } __packed __aligned(8);
0525 
0526 struct ibmvnic_get_vpd_rsp {
0527     u8 first;
0528     u8 cmd;
0529     u8 reserved[10];
0530     struct ibmvnic_rc rc;
0531 } __packed __aligned(8);
0532 
0533 struct ibmvnic_acl_change_indication {
0534     u8 first;
0535     u8 cmd;
0536     __be16 change_type;
0537 #define IBMVNIC_MAC_ACL 0
0538 #define IBMVNIC_VLAN_ACL 1
0539     u8 reserved[12];
0540 } __packed __aligned(8);
0541 
0542 struct ibmvnic_acl_query {
0543     u8 first;
0544     u8 cmd;
0545     u8 reserved1[2];
0546     __be32 ioba;
0547     __be32 len;
0548     u8 reserved2[4];
0549 } __packed __aligned(8);
0550 
0551 struct ibmvnic_tune {
0552     u8 first;
0553     u8 cmd;
0554     u8 reserved1[2];
0555     __be32 ioba;
0556     __be32 len;
0557     u8 reserved2[4];
0558 } __packed __aligned(8);
0559 
0560 struct ibmvnic_request_map {
0561     u8 first;
0562     u8 cmd;
0563     u8 reserved1;
0564     u8 map_id;
0565     __be32 ioba;
0566     __be32 len;
0567     u8 reserved2[4];
0568 } __packed __aligned(8);
0569 
0570 struct ibmvnic_request_map_rsp {
0571     u8 first;
0572     u8 cmd;
0573     u8 reserved1;
0574     u8 map_id;
0575     u8 reserved2[8];
0576     struct ibmvnic_rc rc;
0577 } __packed __aligned(8);
0578 
0579 struct ibmvnic_request_unmap {
0580     u8 first;
0581     u8 cmd;
0582     u8 reserved1;
0583     u8 map_id;
0584     u8 reserved2[12];
0585 } __packed __aligned(8);
0586 
0587 struct ibmvnic_request_unmap_rsp {
0588     u8 first;
0589     u8 cmd;
0590     u8 reserved1;
0591     u8 map_id;
0592     u8 reserved2[8];
0593     struct ibmvnic_rc rc;
0594 } __packed __aligned(8);
0595 
0596 struct ibmvnic_query_map {
0597     u8 first;
0598     u8 cmd;
0599     u8 reserved[14];
0600 } __packed __aligned(8);
0601 
0602 struct ibmvnic_query_map_rsp {
0603     u8 first;
0604     u8 cmd;
0605     u8 reserved;
0606     u8 page_size;
0607     __be32 tot_pages;
0608     __be32 free_pages;
0609     struct ibmvnic_rc rc;
0610 } __packed __aligned(8);
0611 
0612 union ibmvnic_crq {
0613     struct ibmvnic_generic_crq generic;
0614     struct ibmvnic_version_exchange version_exchange;
0615     struct ibmvnic_version_exchange version_exchange_rsp;
0616     struct ibmvnic_capability query_capability;
0617     struct ibmvnic_capability query_capability_rsp;
0618     struct ibmvnic_capability request_capability;
0619     struct ibmvnic_capability request_capability_rsp;
0620     struct ibmvnic_login login;
0621     struct ibmvnic_generic_crq login_rsp;
0622     struct ibmvnic_phys_parms query_phys_parms;
0623     struct ibmvnic_phys_parms query_phys_parms_rsp;
0624     struct ibmvnic_phys_parms query_phys_capabilities;
0625     struct ibmvnic_phys_parms query_phys_capabilities_rsp;
0626     struct ibmvnic_phys_parms set_phys_parms;
0627     struct ibmvnic_phys_parms set_phys_parms_rsp;
0628     struct ibmvnic_logical_link_state logical_link_state;
0629     struct ibmvnic_logical_link_state logical_link_state_rsp;
0630     struct ibmvnic_query_ip_offload query_ip_offload;
0631     struct ibmvnic_query_ip_offload query_ip_offload_rsp;
0632     struct ibmvnic_control_ip_offload control_ip_offload;
0633     struct ibmvnic_control_ip_offload control_ip_offload_rsp;
0634     struct ibmvnic_request_statistics request_statistics;
0635     struct ibmvnic_generic_crq request_statistics_rsp;
0636     struct ibmvnic_error_indication error_indication;
0637     struct ibmvnic_link_state_indication link_state_indication;
0638     struct ibmvnic_change_mac_addr change_mac_addr;
0639     struct ibmvnic_change_mac_addr change_mac_addr_rsp;
0640     struct ibmvnic_multicast_ctrl multicast_ctrl;
0641     struct ibmvnic_multicast_ctrl multicast_ctrl_rsp;
0642     struct ibmvnic_get_vpd_size get_vpd_size;
0643     struct ibmvnic_get_vpd_size_rsp get_vpd_size_rsp;
0644     struct ibmvnic_get_vpd get_vpd;
0645     struct ibmvnic_get_vpd_rsp get_vpd_rsp;
0646     struct ibmvnic_acl_change_indication acl_change_indication;
0647     struct ibmvnic_acl_query acl_query;
0648     struct ibmvnic_generic_crq acl_query_rsp;
0649     struct ibmvnic_tune tune;
0650     struct ibmvnic_generic_crq tune_rsp;
0651     struct ibmvnic_request_map request_map;
0652     struct ibmvnic_request_map_rsp request_map_rsp;
0653     struct ibmvnic_request_unmap request_unmap;
0654     struct ibmvnic_request_unmap_rsp request_unmap_rsp;
0655     struct ibmvnic_query_map query_map;
0656     struct ibmvnic_query_map_rsp query_map_rsp;
0657 };
0658 
0659 enum ibmvnic_rc_codes {
0660     SUCCESS = 0,
0661     PARTIALSUCCESS = 1,
0662     PERMISSION = 2,
0663     NOMEMORY = 3,
0664     PARAMETER = 4,
0665     UNKNOWNCOMMAND = 5,
0666     ABORTED = 6,
0667     INVALIDSTATE = 7,
0668     INVALIDIOBA = 8,
0669     INVALIDLENGTH = 9,
0670     UNSUPPORTEDOPTION = 10,
0671 };
0672 
0673 enum ibmvnic_capabilities {
0674     MIN_TX_QUEUES = 1,
0675     MIN_RX_QUEUES = 2,
0676     MIN_RX_ADD_QUEUES = 3,
0677     MAX_TX_QUEUES = 4,
0678     MAX_RX_QUEUES = 5,
0679     MAX_RX_ADD_QUEUES = 6,
0680     REQ_TX_QUEUES = 7,
0681     REQ_RX_QUEUES = 8,
0682     REQ_RX_ADD_QUEUES = 9,
0683     MIN_TX_ENTRIES_PER_SUBCRQ = 10,
0684     MIN_RX_ADD_ENTRIES_PER_SUBCRQ = 11,
0685     MAX_TX_ENTRIES_PER_SUBCRQ = 12,
0686     MAX_RX_ADD_ENTRIES_PER_SUBCRQ = 13,
0687     REQ_TX_ENTRIES_PER_SUBCRQ = 14,
0688     REQ_RX_ADD_ENTRIES_PER_SUBCRQ = 15,
0689     TCP_IP_OFFLOAD = 16,
0690     PROMISC_REQUESTED = 17,
0691     PROMISC_SUPPORTED = 18,
0692     MIN_MTU = 19,
0693     MAX_MTU = 20,
0694     REQ_MTU = 21,
0695     MAX_MULTICAST_FILTERS = 22,
0696     VLAN_HEADER_INSERTION = 23,
0697     RX_VLAN_HEADER_INSERTION = 24,
0698     MAX_TX_SG_ENTRIES = 25,
0699     RX_SG_SUPPORTED = 26,
0700     RX_SG_REQUESTED = 27,
0701     OPT_TX_COMP_SUB_QUEUES = 28,
0702     OPT_RX_COMP_QUEUES = 29,
0703     OPT_RX_BUFADD_Q_PER_RX_COMP_Q = 30,
0704     OPT_TX_ENTRIES_PER_SUBCRQ = 31,
0705     OPT_RXBA_ENTRIES_PER_SUBCRQ = 32,
0706     TX_RX_DESC_REQ = 33,
0707 };
0708 
0709 enum ibmvnic_error_cause {
0710     ADAPTER_PROBLEM = 0,
0711     BUS_PROBLEM = 1,
0712     FW_PROBLEM = 2,
0713     DD_PROBLEM = 3,
0714     EEH_RECOVERY = 4,
0715     FW_UPDATED = 5,
0716     LOW_MEMORY = 6,
0717 };
0718 
0719 enum ibmvnic_commands {
0720     VERSION_EXCHANGE = 0x01,
0721     VERSION_EXCHANGE_RSP = 0x81,
0722     QUERY_CAPABILITY = 0x02,
0723     QUERY_CAPABILITY_RSP = 0x82,
0724     REQUEST_CAPABILITY = 0x03,
0725     REQUEST_CAPABILITY_RSP = 0x83,
0726     LOGIN = 0x04,
0727     LOGIN_RSP = 0x84,
0728     QUERY_PHYS_PARMS = 0x05,
0729     QUERY_PHYS_PARMS_RSP = 0x85,
0730     QUERY_PHYS_CAPABILITIES = 0x06,
0731     QUERY_PHYS_CAPABILITIES_RSP = 0x86,
0732     SET_PHYS_PARMS = 0x07,
0733     SET_PHYS_PARMS_RSP = 0x87,
0734     ERROR_INDICATION = 0x08,
0735     LOGICAL_LINK_STATE = 0x0C,
0736     LOGICAL_LINK_STATE_RSP = 0x8C,
0737     REQUEST_STATISTICS = 0x0D,
0738     REQUEST_STATISTICS_RSP = 0x8D,
0739     COLLECT_FW_TRACE = 0x11,
0740     COLLECT_FW_TRACE_RSP = 0x91,
0741     LINK_STATE_INDICATION = 0x12,
0742     CHANGE_MAC_ADDR = 0x13,
0743     CHANGE_MAC_ADDR_RSP = 0x93,
0744     MULTICAST_CTRL = 0x14,
0745     MULTICAST_CTRL_RSP = 0x94,
0746     GET_VPD_SIZE = 0x15,
0747     GET_VPD_SIZE_RSP = 0x95,
0748     GET_VPD = 0x16,
0749     GET_VPD_RSP = 0x96,
0750     TUNE = 0x17,
0751     TUNE_RSP = 0x97,
0752     QUERY_IP_OFFLOAD = 0x18,
0753     QUERY_IP_OFFLOAD_RSP = 0x98,
0754     CONTROL_IP_OFFLOAD = 0x19,
0755     CONTROL_IP_OFFLOAD_RSP = 0x99,
0756     ACL_CHANGE_INDICATION = 0x1A,
0757     ACL_QUERY = 0x1B,
0758     ACL_QUERY_RSP = 0x9B,
0759     QUERY_MAP = 0x1D,
0760     QUERY_MAP_RSP = 0x9D,
0761     REQUEST_MAP = 0x1E,
0762     REQUEST_MAP_RSP = 0x9E,
0763     REQUEST_UNMAP = 0x1F,
0764     REQUEST_UNMAP_RSP = 0x9F,
0765     VLAN_CTRL = 0x20,
0766     VLAN_CTRL_RSP = 0xA0,
0767 };
0768 
0769 enum ibmvnic_crq_type {
0770     IBMVNIC_CRQ_CMD         = 0x80,
0771     IBMVNIC_CRQ_CMD_RSP     = 0x80,
0772     IBMVNIC_CRQ_INIT_CMD        = 0xC0,
0773     IBMVNIC_CRQ_INIT_RSP        = 0xC0,
0774     IBMVNIC_CRQ_XPORT_EVENT     = 0xFF,
0775 };
0776 
0777 enum ibmvfc_crq_format {
0778     IBMVNIC_CRQ_INIT                 = 0x01,
0779     IBMVNIC_CRQ_INIT_COMPLETE        = 0x02,
0780     IBMVNIC_PARTITION_MIGRATED       = 0x06,
0781     IBMVNIC_DEVICE_FAILOVER          = 0x08,
0782 };
0783 
0784 struct ibmvnic_crq_queue {
0785     union ibmvnic_crq *msgs;
0786     int size, cur;
0787     dma_addr_t msg_token;
0788     /* Used for serialization of msgs, cur */
0789     spinlock_t lock;
0790     bool active;
0791     char name[32];
0792 };
0793 
0794 union sub_crq {
0795     struct ibmvnic_generic_scrq generic;
0796     struct ibmvnic_tx_comp_desc tx_comp;
0797     struct ibmvnic_tx_desc v1;
0798     struct ibmvnic_hdr_desc hdr;
0799     struct ibmvnic_hdr_ext_desc hdr_ext;
0800     struct ibmvnic_sge_desc sge;
0801     struct ibmvnic_rx_comp_desc rx_comp;
0802     struct ibmvnic_rx_buff_add_desc rx_add;
0803 };
0804 
0805 struct ibmvnic_ind_xmit_queue {
0806     union sub_crq *indir_arr;
0807     dma_addr_t indir_dma;
0808     int index;
0809 };
0810 
0811 struct ibmvnic_sub_crq_queue {
0812     union sub_crq *msgs;
0813     int size, cur;
0814     dma_addr_t msg_token;
0815     unsigned long crq_num;
0816     unsigned long hw_irq;
0817     unsigned int irq;
0818     unsigned int pool_index;
0819     int scrq_num;
0820     /* Used for serialization of msgs, cur */
0821     spinlock_t lock;
0822     struct sk_buff *rx_skb_top;
0823     struct ibmvnic_adapter *adapter;
0824     struct ibmvnic_ind_xmit_queue ind_buf;
0825     atomic_t used;
0826     char name[32];
0827     u64 handle;
0828 } ____cacheline_aligned;
0829 
0830 struct ibmvnic_long_term_buff {
0831     unsigned char *buff;
0832     dma_addr_t addr;
0833     u64 size;
0834     u8 map_id;
0835 };
0836 
0837 struct ibmvnic_ltb_set {
0838     int num_ltbs;
0839     struct ibmvnic_long_term_buff *ltbs;
0840 };
0841 
0842 struct ibmvnic_tx_buff {
0843     struct sk_buff *skb;
0844     int index;
0845     int pool_index;
0846     int num_entries;
0847 };
0848 
0849 struct ibmvnic_tx_pool {
0850     struct ibmvnic_tx_buff *tx_buff;
0851     int *free_map;
0852     int consumer_index;
0853     int producer_index;
0854     struct ibmvnic_ltb_set ltb_set;
0855     int num_buffers;
0856     int buf_size;
0857 } ____cacheline_aligned;
0858 
0859 struct ibmvnic_rx_buff {
0860     struct sk_buff *skb;
0861     dma_addr_t dma;
0862     unsigned char *data;
0863     int size;
0864     int pool_index;
0865 };
0866 
0867 struct ibmvnic_rx_pool {
0868     struct ibmvnic_rx_buff *rx_buff;
0869     int size;           /* # of buffers in the pool */
0870     int index;
0871     int buff_size;
0872     atomic_t available;
0873     int *free_map;
0874     int next_free;
0875     int next_alloc;
0876     int active;
0877     struct ibmvnic_ltb_set ltb_set;
0878 } ____cacheline_aligned;
0879 
0880 struct ibmvnic_vpd {
0881     unsigned char *buff;
0882     dma_addr_t dma_addr;
0883     u64 len;
0884 };
0885 
0886 enum vnic_state {VNIC_PROBING = 1,
0887          VNIC_PROBED,
0888          VNIC_OPENING,
0889          VNIC_OPEN,
0890          VNIC_CLOSING,
0891          VNIC_CLOSED,
0892          VNIC_REMOVING,
0893          VNIC_REMOVED,
0894          VNIC_DOWN};
0895 
0896 enum ibmvnic_reset_reason {VNIC_RESET_FAILOVER = 1,
0897                VNIC_RESET_MOBILITY,
0898                VNIC_RESET_FATAL,
0899                VNIC_RESET_NON_FATAL,
0900                VNIC_RESET_TIMEOUT,
0901                VNIC_RESET_CHANGE_PARAM,
0902                VNIC_RESET_PASSIVE_INIT};
0903 
0904 struct ibmvnic_rwi {
0905     enum ibmvnic_reset_reason reset_reason;
0906     struct list_head list;
0907 };
0908 
0909 struct ibmvnic_tunables {
0910     u64 rx_queues;
0911     u64 tx_queues;
0912     u64 rx_entries;
0913     u64 tx_entries;
0914     u64 mtu;
0915 };
0916 
0917 struct ibmvnic_adapter {
0918     struct vio_dev *vdev;
0919     struct net_device *netdev;
0920     struct ibmvnic_crq_queue crq;
0921     u8 mac_addr[ETH_ALEN];
0922     struct ibmvnic_query_ip_offload_buffer ip_offload_buf;
0923     dma_addr_t ip_offload_tok;
0924     struct ibmvnic_control_ip_offload_buffer ip_offload_ctrl;
0925     dma_addr_t ip_offload_ctrl_tok;
0926     u32 msg_enable;
0927 
0928     /* Vital Product Data (VPD) */
0929     struct ibmvnic_vpd *vpd;
0930     char fw_version[32];
0931 
0932     /* Statistics */
0933     struct ibmvnic_statistics stats;
0934     dma_addr_t stats_token;
0935     struct completion stats_done;
0936     int replenish_no_mem;
0937     int replenish_add_buff_success;
0938     int replenish_add_buff_failure;
0939     int replenish_task_cycles;
0940     int tx_send_failed;
0941     int tx_map_failed;
0942 
0943     struct ibmvnic_tx_queue_stats *tx_stats_buffers;
0944     struct ibmvnic_rx_queue_stats *rx_stats_buffers;
0945 
0946     int phys_link_state;
0947     int logical_link_state;
0948 
0949     u32 speed;
0950     u8 duplex;
0951 
0952     /* login data */
0953     struct ibmvnic_login_buffer *login_buf;
0954     dma_addr_t login_buf_token;
0955     int login_buf_sz;
0956 
0957     struct ibmvnic_login_rsp_buffer *login_rsp_buf;
0958     dma_addr_t login_rsp_buf_token;
0959     int login_rsp_buf_sz;
0960 
0961     atomic_t running_cap_crqs;
0962 
0963     struct ibmvnic_sub_crq_queue **tx_scrq ____cacheline_aligned;
0964     struct ibmvnic_sub_crq_queue **rx_scrq ____cacheline_aligned;
0965 
0966     /* rx structs */
0967     struct napi_struct *napi;
0968     struct ibmvnic_rx_pool *rx_pool;
0969     u64 promisc;
0970 
0971     struct ibmvnic_tx_pool *tx_pool;
0972     struct ibmvnic_tx_pool *tso_pool;
0973     struct completion probe_done;
0974     struct completion init_done;
0975     int init_done_rc;
0976 
0977     struct completion fw_done;
0978     /* Used for serialization of device commands */
0979     struct mutex fw_lock;
0980     int fw_done_rc;
0981 
0982     struct completion reset_done;
0983     int reset_done_rc;
0984     bool wait_for_reset;
0985 
0986     /* partner capabilities */
0987     u64 min_tx_queues;
0988     u64 min_rx_queues;
0989     u64 min_rx_add_queues;
0990     u64 max_tx_queues;
0991     u64 max_rx_queues;
0992     u64 max_rx_add_queues;
0993     u64 req_tx_queues;
0994     u64 req_rx_queues;
0995     u64 req_rx_add_queues;
0996     u64 min_tx_entries_per_subcrq;
0997     u64 min_rx_add_entries_per_subcrq;
0998     u64 max_tx_entries_per_subcrq;
0999     u64 max_rx_add_entries_per_subcrq;
1000     u64 req_tx_entries_per_subcrq;
1001     u64 req_rx_add_entries_per_subcrq;
1002     u64 tcp_ip_offload;
1003     u64 promisc_requested;
1004     u64 promisc_supported;
1005     u64 min_mtu;
1006     u64 max_mtu;
1007     u64 req_mtu;
1008     u64 prev_mtu;
1009     u64 max_multicast_filters;
1010     u64 vlan_header_insertion;
1011     u64 rx_vlan_header_insertion;
1012     u64 max_tx_sg_entries;
1013     u64 rx_sg_supported;
1014     u64 rx_sg_requested;
1015     u64 opt_tx_comp_sub_queues;
1016     u64 opt_rx_comp_queues;
1017     u64 opt_rx_bufadd_q_per_rx_comp_q;
1018     u64 opt_tx_entries_per_subcrq;
1019     u64 opt_rxba_entries_per_subcrq;
1020     __be64 tx_rx_desc_req;
1021 #define MAX_MAP_ID  255
1022     DECLARE_BITMAP(map_ids, MAX_MAP_ID);
1023     u32 num_active_rx_scrqs;
1024     u32 num_active_rx_pools;
1025     u32 num_active_rx_napi;
1026     u32 num_active_tx_scrqs;
1027     u32 num_active_tx_pools;
1028 
1029     u32 prev_rx_pool_size;
1030     u32 prev_tx_pool_size;
1031     u32 cur_rx_buf_sz;
1032     u32 prev_rx_buf_sz;
1033 
1034     struct tasklet_struct tasklet;
1035     enum vnic_state state;
1036     /* Used for serialization of state field. When taking both state
1037      * and rwi locks, take state lock first.
1038      */
1039     spinlock_t state_lock;
1040     enum ibmvnic_reset_reason reset_reason;
1041     struct list_head rwi_list;
1042     /* Used for serialization of rwi_list. When taking both state
1043      * and rwi locks, take state lock first
1044      */
1045     spinlock_t rwi_lock;
1046     struct work_struct ibmvnic_reset;
1047     struct delayed_work ibmvnic_delayed_reset;
1048     unsigned long resetting;
1049     /* last device reset time */
1050     unsigned long last_reset_time;
1051 
1052     bool napi_enabled;
1053     bool from_passive_init;
1054     bool login_pending;
1055     /* protected by rcu */
1056     bool tx_queues_active;
1057     bool failover_pending;
1058     bool force_reset_recovery;
1059 
1060     struct ibmvnic_tunables desired;
1061     struct ibmvnic_tunables fallback;
1062 };