18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * IBM Power Virtual Ethernet Device Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) IBM Corporation, 2003, 2010
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors: Dave Larson <larson1@us.ibm.com>
88c2ecf20Sopenharmony_ci *	    Santiago Leon <santil@linux.vnet.ibm.com>
98c2ecf20Sopenharmony_ci *	    Brian King <brking@linux.vnet.ibm.com>
108c2ecf20Sopenharmony_ci *	    Robert Jennings <rcj@linux.vnet.ibm.com>
118c2ecf20Sopenharmony_ci *	    Anton Blanchard <anton@au.ibm.com>
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef _IBMVETH_H
158c2ecf20Sopenharmony_ci#define _IBMVETH_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* constants for H_MULTICAST_CTRL */
188c2ecf20Sopenharmony_ci#define IbmVethMcastReceptionModifyBit     0x80000UL
198c2ecf20Sopenharmony_ci#define IbmVethMcastReceptionEnableBit     0x20000UL
208c2ecf20Sopenharmony_ci#define IbmVethMcastFilterModifyBit        0x40000UL
218c2ecf20Sopenharmony_ci#define IbmVethMcastFilterEnableBit        0x10000UL
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define IbmVethMcastEnableRecv       (IbmVethMcastReceptionModifyBit | IbmVethMcastReceptionEnableBit)
248c2ecf20Sopenharmony_ci#define IbmVethMcastDisableRecv      (IbmVethMcastReceptionModifyBit)
258c2ecf20Sopenharmony_ci#define IbmVethMcastEnableFiltering  (IbmVethMcastFilterModifyBit | IbmVethMcastFilterEnableBit)
268c2ecf20Sopenharmony_ci#define IbmVethMcastDisableFiltering (IbmVethMcastFilterModifyBit)
278c2ecf20Sopenharmony_ci#define IbmVethMcastAddFilter        0x1UL
288c2ecf20Sopenharmony_ci#define IbmVethMcastRemoveFilter     0x2UL
298c2ecf20Sopenharmony_ci#define IbmVethMcastClearFilterTable 0x3UL
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_LRG_SR_ENABLED	0x0000000000010000UL
328c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_LRG_SND_SUPPORT	0x0000000000008000UL
338c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_PADDED_PKT_CSUM	0x0000000000002000UL
348c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_TRUNK_PRI_MASK	0x0000000000000F00UL
358c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_IPV6_TCP_CSUM		0x0000000000000004UL
368c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_IPV4_TCP_CSUM		0x0000000000000002UL
378c2ecf20Sopenharmony_ci#define IBMVETH_ILLAN_ACTIVE_TRUNK		0x0000000000000001UL
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* hcall macros */
408c2ecf20Sopenharmony_ci#define h_register_logical_lan(ua, buflst, rxq, fltlst, mac) \
418c2ecf20Sopenharmony_ci  plpar_hcall_norets(H_REGISTER_LOGICAL_LAN, ua, buflst, rxq, fltlst, mac)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define h_free_logical_lan(ua) \
448c2ecf20Sopenharmony_ci  plpar_hcall_norets(H_FREE_LOGICAL_LAN, ua)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define h_add_logical_lan_buffer(ua, buf) \
478c2ecf20Sopenharmony_ci  plpar_hcall_norets(H_ADD_LOGICAL_LAN_BUFFER, ua, buf)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline long h_send_logical_lan(unsigned long unit_address,
508c2ecf20Sopenharmony_ci		unsigned long desc1, unsigned long desc2, unsigned long desc3,
518c2ecf20Sopenharmony_ci		unsigned long desc4, unsigned long desc5, unsigned long desc6,
528c2ecf20Sopenharmony_ci		unsigned long corellator_in, unsigned long *corellator_out,
538c2ecf20Sopenharmony_ci		unsigned long mss, unsigned long large_send_support)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	long rc;
568c2ecf20Sopenharmony_ci	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	if (large_send_support)
598c2ecf20Sopenharmony_ci		rc = plpar_hcall9(H_SEND_LOGICAL_LAN, retbuf, unit_address,
608c2ecf20Sopenharmony_ci				  desc1, desc2, desc3, desc4, desc5, desc6,
618c2ecf20Sopenharmony_ci				  corellator_in, mss);
628c2ecf20Sopenharmony_ci	else
638c2ecf20Sopenharmony_ci		rc = plpar_hcall9(H_SEND_LOGICAL_LAN, retbuf, unit_address,
648c2ecf20Sopenharmony_ci				  desc1, desc2, desc3, desc4, desc5, desc6,
658c2ecf20Sopenharmony_ci				  corellator_in);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	*corellator_out = retbuf[0];
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	return rc;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistatic inline long h_illan_attributes(unsigned long unit_address,
738c2ecf20Sopenharmony_ci				      unsigned long reset_mask, unsigned long set_mask,
748c2ecf20Sopenharmony_ci				      unsigned long *ret_attributes)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	long rc;
778c2ecf20Sopenharmony_ci	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	rc = plpar_hcall(H_ILLAN_ATTRIBUTES, retbuf, unit_address,
808c2ecf20Sopenharmony_ci			 reset_mask, set_mask);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	*ret_attributes = retbuf[0];
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	return rc;
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define h_multicast_ctrl(ua, cmd, mac) \
888c2ecf20Sopenharmony_ci  plpar_hcall_norets(H_MULTICAST_CTRL, ua, cmd, mac)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define h_change_logical_lan_mac(ua, mac) \
918c2ecf20Sopenharmony_ci  plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define IBMVETH_NUM_BUFF_POOLS 5
948c2ecf20Sopenharmony_ci#define IBMVETH_IO_ENTITLEMENT_DEFAULT 4243456 /* MTU of 1500 needs 4.2Mb */
958c2ecf20Sopenharmony_ci#define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */
968c2ecf20Sopenharmony_ci#define IBMVETH_MIN_MTU 68
978c2ecf20Sopenharmony_ci#define IBMVETH_MAX_POOL_COUNT 4096
988c2ecf20Sopenharmony_ci#define IBMVETH_BUFF_LIST_SIZE 4096
998c2ecf20Sopenharmony_ci#define IBMVETH_FILT_LIST_SIZE 4096
1008c2ecf20Sopenharmony_ci#define IBMVETH_MAX_BUF_SIZE (1024 * 128)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 };
1038c2ecf20Sopenharmony_cistatic int pool_count[] = { 256, 512, 256, 256, 256 };
1048c2ecf20Sopenharmony_cistatic int pool_count_cmo[] = { 256, 512, 256, 256, 64 };
1058c2ecf20Sopenharmony_cistatic int pool_active[] = { 1, 1, 0, 0, 1};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define IBM_VETH_INVALID_MAP ((u16)0xffff)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistruct ibmveth_buff_pool {
1108c2ecf20Sopenharmony_ci    u32 size;
1118c2ecf20Sopenharmony_ci    u32 index;
1128c2ecf20Sopenharmony_ci    u32 buff_size;
1138c2ecf20Sopenharmony_ci    u32 threshold;
1148c2ecf20Sopenharmony_ci    atomic_t available;
1158c2ecf20Sopenharmony_ci    u32 consumer_index;
1168c2ecf20Sopenharmony_ci    u32 producer_index;
1178c2ecf20Sopenharmony_ci    u16 *free_map;
1188c2ecf20Sopenharmony_ci    dma_addr_t *dma_addr;
1198c2ecf20Sopenharmony_ci    struct sk_buff **skbuff;
1208c2ecf20Sopenharmony_ci    int active;
1218c2ecf20Sopenharmony_ci    struct kobject kobj;
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct ibmveth_rx_q {
1258c2ecf20Sopenharmony_ci    u64        index;
1268c2ecf20Sopenharmony_ci    u64        num_slots;
1278c2ecf20Sopenharmony_ci    u64        toggle;
1288c2ecf20Sopenharmony_ci    dma_addr_t queue_dma;
1298c2ecf20Sopenharmony_ci    u32        queue_len;
1308c2ecf20Sopenharmony_ci    struct ibmveth_rx_q_entry *queue_addr;
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistruct ibmveth_adapter {
1348c2ecf20Sopenharmony_ci    struct vio_dev *vdev;
1358c2ecf20Sopenharmony_ci    struct net_device *netdev;
1368c2ecf20Sopenharmony_ci    struct napi_struct napi;
1378c2ecf20Sopenharmony_ci    unsigned int mcastFilterSize;
1388c2ecf20Sopenharmony_ci    void * buffer_list_addr;
1398c2ecf20Sopenharmony_ci    void * filter_list_addr;
1408c2ecf20Sopenharmony_ci    dma_addr_t buffer_list_dma;
1418c2ecf20Sopenharmony_ci    dma_addr_t filter_list_dma;
1428c2ecf20Sopenharmony_ci    struct ibmveth_buff_pool rx_buff_pool[IBMVETH_NUM_BUFF_POOLS];
1438c2ecf20Sopenharmony_ci    struct ibmveth_rx_q rx_queue;
1448c2ecf20Sopenharmony_ci    int pool_config;
1458c2ecf20Sopenharmony_ci    int rx_csum;
1468c2ecf20Sopenharmony_ci    int large_send;
1478c2ecf20Sopenharmony_ci    bool is_active_trunk;
1488c2ecf20Sopenharmony_ci    void *bounce_buffer;
1498c2ecf20Sopenharmony_ci    dma_addr_t bounce_buffer_dma;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci    u64 fw_ipv6_csum_support;
1528c2ecf20Sopenharmony_ci    u64 fw_ipv4_csum_support;
1538c2ecf20Sopenharmony_ci    u64 fw_large_send_support;
1548c2ecf20Sopenharmony_ci    /* adapter specific stats */
1558c2ecf20Sopenharmony_ci    u64 replenish_task_cycles;
1568c2ecf20Sopenharmony_ci    u64 replenish_no_mem;
1578c2ecf20Sopenharmony_ci    u64 replenish_add_buff_failure;
1588c2ecf20Sopenharmony_ci    u64 replenish_add_buff_success;
1598c2ecf20Sopenharmony_ci    u64 rx_invalid_buffer;
1608c2ecf20Sopenharmony_ci    u64 rx_no_buffer;
1618c2ecf20Sopenharmony_ci    u64 tx_map_failed;
1628c2ecf20Sopenharmony_ci    u64 tx_send_failed;
1638c2ecf20Sopenharmony_ci    u64 tx_large_packets;
1648c2ecf20Sopenharmony_ci    u64 rx_large_packets;
1658c2ecf20Sopenharmony_ci    /* Ethtool settings */
1668c2ecf20Sopenharmony_ci	u8 duplex;
1678c2ecf20Sopenharmony_ci	u32 speed;
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/*
1718c2ecf20Sopenharmony_ci * We pass struct ibmveth_buf_desc_fields to the hypervisor in registers,
1728c2ecf20Sopenharmony_ci * so we don't need to byteswap the two elements. However since we use
1738c2ecf20Sopenharmony_ci * a union (ibmveth_buf_desc) to convert from the struct to a u64 we
1748c2ecf20Sopenharmony_ci * do end up with endian specific ordering of the elements and that
1758c2ecf20Sopenharmony_ci * needs correcting.
1768c2ecf20Sopenharmony_ci */
1778c2ecf20Sopenharmony_cistruct ibmveth_buf_desc_fields {
1788c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
1798c2ecf20Sopenharmony_ci	u32 flags_len;
1808c2ecf20Sopenharmony_ci	u32 address;
1818c2ecf20Sopenharmony_ci#else
1828c2ecf20Sopenharmony_ci	u32 address;
1838c2ecf20Sopenharmony_ci	u32 flags_len;
1848c2ecf20Sopenharmony_ci#endif
1858c2ecf20Sopenharmony_ci#define IBMVETH_BUF_VALID	0x80000000
1868c2ecf20Sopenharmony_ci#define IBMVETH_BUF_TOGGLE	0x40000000
1878c2ecf20Sopenharmony_ci#define IBMVETH_BUF_LRG_SND     0x04000000
1888c2ecf20Sopenharmony_ci#define IBMVETH_BUF_NO_CSUM	0x02000000
1898c2ecf20Sopenharmony_ci#define IBMVETH_BUF_CSUM_GOOD	0x01000000
1908c2ecf20Sopenharmony_ci#define IBMVETH_BUF_LEN_MASK	0x00FFFFFF
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ciunion ibmveth_buf_desc {
1948c2ecf20Sopenharmony_ci    u64 desc;
1958c2ecf20Sopenharmony_ci    struct ibmveth_buf_desc_fields fields;
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistruct ibmveth_rx_q_entry {
1998c2ecf20Sopenharmony_ci	__be32 flags_off;
2008c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_TOGGLE		0x80000000
2018c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_TOGGLE_SHIFT	31
2028c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_VALID		0x40000000
2038c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_LRG_PKT		0x04000000
2048c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_NO_CSUM		0x02000000
2058c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_CSUM_GOOD		0x01000000
2068c2ecf20Sopenharmony_ci#define IBMVETH_RXQ_OFF_MASK		0x0000FFFF
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	__be32 length;
2098c2ecf20Sopenharmony_ci	/* correlator is only used by the OS, no need to byte swap */
2108c2ecf20Sopenharmony_ci	u64 correlator;
2118c2ecf20Sopenharmony_ci};
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#endif /* _IBMVETH_H */
214