18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright Gavin Shan, IBM Corporation 2016.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __NCSI_INTERNAL_H__
78c2ecf20Sopenharmony_ci#define __NCSI_INTERNAL_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cienum {
108c2ecf20Sopenharmony_ci	NCSI_CAP_BASE		= 0,
118c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC	= 0,
128c2ecf20Sopenharmony_ci	NCSI_CAP_BC,
138c2ecf20Sopenharmony_ci	NCSI_CAP_MC,
148c2ecf20Sopenharmony_ci	NCSI_CAP_BUFFER,
158c2ecf20Sopenharmony_ci	NCSI_CAP_AEN,
168c2ecf20Sopenharmony_ci	NCSI_CAP_VLAN,
178c2ecf20Sopenharmony_ci	NCSI_CAP_MAX
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cienum {
218c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA             = 0x01, /* HW arbitration           */
228c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HDS             = 0x02, /* HNC driver status change */
238c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_FC              = 0x04, /* HNC to MC flow control   */
248c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_FC1             = 0x08, /* MC to HNC flow control   */
258c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_MC              = 0x10, /* Global MC filtering      */
268c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_UNKNOWN     = 0x00, /* Unknown HW arbitration   */
278c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_SUPPORT     = 0x20, /* Supported HW arbitration */
288c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration        */
298c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_RESERVED    = 0x60, /* Reserved HW arbitration  */
308c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_MASK        = 0x60, /* Mask for HW arbitration  */
318c2ecf20Sopenharmony_ci	NCSI_CAP_GENERIC_MASK            = 0x7f,
328c2ecf20Sopenharmony_ci	NCSI_CAP_BC_ARP                  = 0x01, /* ARP packet filtering     */
338c2ecf20Sopenharmony_ci	NCSI_CAP_BC_DHCPC                = 0x02, /* DHCP client filtering    */
348c2ecf20Sopenharmony_ci	NCSI_CAP_BC_DHCPS                = 0x04, /* DHCP server filtering    */
358c2ecf20Sopenharmony_ci	NCSI_CAP_BC_NETBIOS              = 0x08, /* NetBIOS packet filtering */
368c2ecf20Sopenharmony_ci	NCSI_CAP_BC_MASK                 = 0x0f,
378c2ecf20Sopenharmony_ci	NCSI_CAP_MC_IPV6_NEIGHBOR        = 0x01, /* IPv6 neighbor filtering  */
388c2ecf20Sopenharmony_ci	NCSI_CAP_MC_IPV6_ROUTER          = 0x02, /* IPv6 router filering     */
398c2ecf20Sopenharmony_ci	NCSI_CAP_MC_DHCPV6_RELAY         = 0x04, /* DHCPv6 relay / server MC */
408c2ecf20Sopenharmony_ci	NCSI_CAP_MC_DHCPV6_WELL_KNOWN    = 0x08, /* DHCPv6 well-known MC     */
418c2ecf20Sopenharmony_ci	NCSI_CAP_MC_IPV6_MLD             = 0x10, /* IPv6 MLD filtering       */
428c2ecf20Sopenharmony_ci	NCSI_CAP_MC_IPV6_NEIGHBOR_S      = 0x20, /* IPv6 neighbour filtering */
438c2ecf20Sopenharmony_ci	NCSI_CAP_MC_MASK                 = 0x3f,
448c2ecf20Sopenharmony_ci	NCSI_CAP_AEN_LSC                 = 0x01, /* Link status change       */
458c2ecf20Sopenharmony_ci	NCSI_CAP_AEN_CR                  = 0x02, /* Configuration required   */
468c2ecf20Sopenharmony_ci	NCSI_CAP_AEN_HDS                 = 0x04, /* HNC driver status        */
478c2ecf20Sopenharmony_ci	NCSI_CAP_AEN_MASK                = 0x07,
488c2ecf20Sopenharmony_ci	NCSI_CAP_VLAN_ONLY               = 0x01, /* Filter VLAN packet only  */
498c2ecf20Sopenharmony_ci	NCSI_CAP_VLAN_NO                 = 0x02, /* Filter VLAN and non-VLAN */
508c2ecf20Sopenharmony_ci	NCSI_CAP_VLAN_ANY                = 0x04, /* Filter Any-and-non-VLAN  */
518c2ecf20Sopenharmony_ci	NCSI_CAP_VLAN_MASK               = 0x07
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cienum {
558c2ecf20Sopenharmony_ci	NCSI_MODE_BASE		= 0,
568c2ecf20Sopenharmony_ci	NCSI_MODE_ENABLE	= 0,
578c2ecf20Sopenharmony_ci	NCSI_MODE_TX_ENABLE,
588c2ecf20Sopenharmony_ci	NCSI_MODE_LINK,
598c2ecf20Sopenharmony_ci	NCSI_MODE_VLAN,
608c2ecf20Sopenharmony_ci	NCSI_MODE_BC,
618c2ecf20Sopenharmony_ci	NCSI_MODE_MC,
628c2ecf20Sopenharmony_ci	NCSI_MODE_AEN,
638c2ecf20Sopenharmony_ci	NCSI_MODE_FC,
648c2ecf20Sopenharmony_ci	NCSI_MODE_MAX
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* Supported media status bits for Mellanox Mac affinity command.
688c2ecf20Sopenharmony_ci * Bit (0-2) for different protocol support; Bit 1 for RBT support,
698c2ecf20Sopenharmony_ci * bit 1 for SMBUS support and bit 2 for PCIE support. Bit (3-5)
708c2ecf20Sopenharmony_ci * for different protocol availability. Bit 4 for RBT, bit 4 for
718c2ecf20Sopenharmony_ci * SMBUS and bit 5 for PCIE.
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_cienum {
748c2ecf20Sopenharmony_ci	MLX_MC_RBT_SUPPORT  = 0x01, /* MC supports RBT         */
758c2ecf20Sopenharmony_ci	MLX_MC_RBT_AVL      = 0x08, /* RBT medium is available */
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* OEM Vendor Manufacture ID */
798c2ecf20Sopenharmony_ci#define NCSI_OEM_MFR_MLX_ID             0x8119
808c2ecf20Sopenharmony_ci#define NCSI_OEM_MFR_BCM_ID             0x113d
818c2ecf20Sopenharmony_ci/* Broadcom specific OEM Command */
828c2ecf20Sopenharmony_ci#define NCSI_OEM_BCM_CMD_GMA            0x01   /* CMD ID for Get MAC */
838c2ecf20Sopenharmony_ci/* Mellanox specific OEM Command */
848c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA            0x00   /* CMD ID for Get MAC */
858c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA_PARAM      0x1b   /* Parameter for GMA  */
868c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF           0x01   /* CMD ID for Set MC Affinity */
878c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF_PARAM     0x07   /* Parameter for SMAF         */
888c2ecf20Sopenharmony_ci/* OEM Command payload lengths*/
898c2ecf20Sopenharmony_ci#define NCSI_OEM_BCM_CMD_GMA_LEN        12
908c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA_LEN        8
918c2ecf20Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF_LEN        60
928c2ecf20Sopenharmony_ci/* Offset in OEM request */
938c2ecf20Sopenharmony_ci#define MLX_SMAF_MAC_ADDR_OFFSET         8     /* Offset for MAC in SMAF    */
948c2ecf20Sopenharmony_ci#define MLX_SMAF_MED_SUPPORT_OFFSET      14    /* Offset for medium in SMAF */
958c2ecf20Sopenharmony_ci/* Mac address offset in OEM response */
968c2ecf20Sopenharmony_ci#define BCM_MAC_ADDR_OFFSET             28
978c2ecf20Sopenharmony_ci#define MLX_MAC_ADDR_OFFSET             8
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistruct ncsi_channel_version {
1018c2ecf20Sopenharmony_ci	u8   major;		/* NCSI version major */
1028c2ecf20Sopenharmony_ci	u8   minor;		/* NCSI version minor */
1038c2ecf20Sopenharmony_ci	u8   update;		/* NCSI version update */
1048c2ecf20Sopenharmony_ci	char alpha1;		/* NCSI version alpha1 */
1058c2ecf20Sopenharmony_ci	char alpha2;		/* NCSI version alpha2 */
1068c2ecf20Sopenharmony_ci	u8  fw_name[12];	/* Firmware name string                */
1078c2ecf20Sopenharmony_ci	u32 fw_version;		/* Firmware version                   */
1088c2ecf20Sopenharmony_ci	u16 pci_ids[4];		/* PCI identification                 */
1098c2ecf20Sopenharmony_ci	u32 mf_id;		/* Manufacture ID                     */
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistruct ncsi_channel_cap {
1138c2ecf20Sopenharmony_ci	u32 index;	/* Index of channel capabilities */
1148c2ecf20Sopenharmony_ci	u32 cap;	/* NCSI channel capability       */
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistruct ncsi_channel_mode {
1188c2ecf20Sopenharmony_ci	u32 index;	/* Index of channel modes      */
1198c2ecf20Sopenharmony_ci	u32 enable;	/* Enabled or disabled         */
1208c2ecf20Sopenharmony_ci	u32 size;	/* Valid entries in ncm_data[] */
1218c2ecf20Sopenharmony_ci	u32 data[8];	/* Data entries                */
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct ncsi_channel_mac_filter {
1258c2ecf20Sopenharmony_ci	u8	n_uc;
1268c2ecf20Sopenharmony_ci	u8	n_mc;
1278c2ecf20Sopenharmony_ci	u8	n_mixed;
1288c2ecf20Sopenharmony_ci	u64	bitmap;
1298c2ecf20Sopenharmony_ci	unsigned char	*addrs;
1308c2ecf20Sopenharmony_ci};
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistruct ncsi_channel_vlan_filter {
1338c2ecf20Sopenharmony_ci	u8	n_vids;
1348c2ecf20Sopenharmony_ci	u64	bitmap;
1358c2ecf20Sopenharmony_ci	u16	*vids;
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistruct ncsi_channel_stats {
1398c2ecf20Sopenharmony_ci	u32 hnc_cnt_hi;		/* Counter cleared            */
1408c2ecf20Sopenharmony_ci	u32 hnc_cnt_lo;		/* Counter cleared            */
1418c2ecf20Sopenharmony_ci	u32 hnc_rx_bytes;	/* Rx bytes                   */
1428c2ecf20Sopenharmony_ci	u32 hnc_tx_bytes;	/* Tx bytes                   */
1438c2ecf20Sopenharmony_ci	u32 hnc_rx_uc_pkts;	/* Rx UC packets              */
1448c2ecf20Sopenharmony_ci	u32 hnc_rx_mc_pkts;     /* Rx MC packets              */
1458c2ecf20Sopenharmony_ci	u32 hnc_rx_bc_pkts;	/* Rx BC packets              */
1468c2ecf20Sopenharmony_ci	u32 hnc_tx_uc_pkts;	/* Tx UC packets              */
1478c2ecf20Sopenharmony_ci	u32 hnc_tx_mc_pkts;	/* Tx MC packets              */
1488c2ecf20Sopenharmony_ci	u32 hnc_tx_bc_pkts;	/* Tx BC packets              */
1498c2ecf20Sopenharmony_ci	u32 hnc_fcs_err;	/* FCS errors                 */
1508c2ecf20Sopenharmony_ci	u32 hnc_align_err;	/* Alignment errors           */
1518c2ecf20Sopenharmony_ci	u32 hnc_false_carrier;	/* False carrier detection    */
1528c2ecf20Sopenharmony_ci	u32 hnc_runt_pkts;	/* Rx runt packets            */
1538c2ecf20Sopenharmony_ci	u32 hnc_jabber_pkts;	/* Rx jabber packets          */
1548c2ecf20Sopenharmony_ci	u32 hnc_rx_pause_xon;	/* Rx pause XON frames        */
1558c2ecf20Sopenharmony_ci	u32 hnc_rx_pause_xoff;	/* Rx XOFF frames             */
1568c2ecf20Sopenharmony_ci	u32 hnc_tx_pause_xon;	/* Tx XON frames              */
1578c2ecf20Sopenharmony_ci	u32 hnc_tx_pause_xoff;	/* Tx XOFF frames             */
1588c2ecf20Sopenharmony_ci	u32 hnc_tx_s_collision;	/* Single collision frames    */
1598c2ecf20Sopenharmony_ci	u32 hnc_tx_m_collision;	/* Multiple collision frames  */
1608c2ecf20Sopenharmony_ci	u32 hnc_l_collision;	/* Late collision frames      */
1618c2ecf20Sopenharmony_ci	u32 hnc_e_collision;	/* Excessive collision frames */
1628c2ecf20Sopenharmony_ci	u32 hnc_rx_ctl_frames;	/* Rx control frames          */
1638c2ecf20Sopenharmony_ci	u32 hnc_rx_64_frames;	/* Rx 64-bytes frames         */
1648c2ecf20Sopenharmony_ci	u32 hnc_rx_127_frames;	/* Rx 65-127 bytes frames     */
1658c2ecf20Sopenharmony_ci	u32 hnc_rx_255_frames;	/* Rx 128-255 bytes frames    */
1668c2ecf20Sopenharmony_ci	u32 hnc_rx_511_frames;	/* Rx 256-511 bytes frames    */
1678c2ecf20Sopenharmony_ci	u32 hnc_rx_1023_frames;	/* Rx 512-1023 bytes frames   */
1688c2ecf20Sopenharmony_ci	u32 hnc_rx_1522_frames;	/* Rx 1024-1522 bytes frames  */
1698c2ecf20Sopenharmony_ci	u32 hnc_rx_9022_frames;	/* Rx 1523-9022 bytes frames  */
1708c2ecf20Sopenharmony_ci	u32 hnc_tx_64_frames;	/* Tx 64-bytes frames         */
1718c2ecf20Sopenharmony_ci	u32 hnc_tx_127_frames;	/* Tx 65-127 bytes frames     */
1728c2ecf20Sopenharmony_ci	u32 hnc_tx_255_frames;	/* Tx 128-255 bytes frames    */
1738c2ecf20Sopenharmony_ci	u32 hnc_tx_511_frames;	/* Tx 256-511 bytes frames    */
1748c2ecf20Sopenharmony_ci	u32 hnc_tx_1023_frames;	/* Tx 512-1023 bytes frames   */
1758c2ecf20Sopenharmony_ci	u32 hnc_tx_1522_frames;	/* Tx 1024-1522 bytes frames  */
1768c2ecf20Sopenharmony_ci	u32 hnc_tx_9022_frames;	/* Tx 1523-9022 bytes frames  */
1778c2ecf20Sopenharmony_ci	u32 hnc_rx_valid_bytes;	/* Rx valid bytes             */
1788c2ecf20Sopenharmony_ci	u32 hnc_rx_runt_pkts;	/* Rx error runt packets      */
1798c2ecf20Sopenharmony_ci	u32 hnc_rx_jabber_pkts;	/* Rx error jabber packets    */
1808c2ecf20Sopenharmony_ci	u32 ncsi_rx_cmds;	/* Rx NCSI commands           */
1818c2ecf20Sopenharmony_ci	u32 ncsi_dropped_cmds;	/* Dropped commands           */
1828c2ecf20Sopenharmony_ci	u32 ncsi_cmd_type_errs;	/* Command type errors        */
1838c2ecf20Sopenharmony_ci	u32 ncsi_cmd_csum_errs;	/* Command checksum errors    */
1848c2ecf20Sopenharmony_ci	u32 ncsi_rx_pkts;	/* Rx NCSI packets            */
1858c2ecf20Sopenharmony_ci	u32 ncsi_tx_pkts;	/* Tx NCSI packets            */
1868c2ecf20Sopenharmony_ci	u32 ncsi_tx_aen_pkts;	/* Tx AEN packets             */
1878c2ecf20Sopenharmony_ci	u32 pt_tx_pkts;		/* Tx packets                 */
1888c2ecf20Sopenharmony_ci	u32 pt_tx_dropped;	/* Tx dropped packets         */
1898c2ecf20Sopenharmony_ci	u32 pt_tx_channel_err;	/* Tx channel errors          */
1908c2ecf20Sopenharmony_ci	u32 pt_tx_us_err;	/* Tx undersize errors        */
1918c2ecf20Sopenharmony_ci	u32 pt_rx_pkts;		/* Rx packets                 */
1928c2ecf20Sopenharmony_ci	u32 pt_rx_dropped;	/* Rx dropped packets         */
1938c2ecf20Sopenharmony_ci	u32 pt_rx_channel_err;	/* Rx channel errors          */
1948c2ecf20Sopenharmony_ci	u32 pt_rx_us_err;	/* Rx undersize errors        */
1958c2ecf20Sopenharmony_ci	u32 pt_rx_os_err;	/* Rx oversize errors         */
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistruct ncsi_dev_priv;
1998c2ecf20Sopenharmony_cistruct ncsi_package;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#define NCSI_PACKAGE_SHIFT	5
2028c2ecf20Sopenharmony_ci#define NCSI_PACKAGE_INDEX(c)	(((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
2038c2ecf20Sopenharmony_ci#define NCSI_RESERVED_CHANNEL	0x1f
2048c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_INDEX(c)	((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
2058c2ecf20Sopenharmony_ci#define NCSI_TO_CHANNEL(p, c)	(((p) << NCSI_PACKAGE_SHIFT) | (c))
2068c2ecf20Sopenharmony_ci#define NCSI_MAX_PACKAGE	8
2078c2ecf20Sopenharmony_ci#define NCSI_MAX_CHANNEL	32
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct ncsi_channel {
2108c2ecf20Sopenharmony_ci	unsigned char               id;
2118c2ecf20Sopenharmony_ci	int                         state;
2128c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_INACTIVE		1
2138c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_ACTIVE		2
2148c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_INVISIBLE		3
2158c2ecf20Sopenharmony_ci	bool                        reconfigure_needed;
2168c2ecf20Sopenharmony_ci	spinlock_t                  lock;	/* Protect filters etc */
2178c2ecf20Sopenharmony_ci	struct ncsi_package         *package;
2188c2ecf20Sopenharmony_ci	struct ncsi_channel_version version;
2198c2ecf20Sopenharmony_ci	struct ncsi_channel_cap	    caps[NCSI_CAP_MAX];
2208c2ecf20Sopenharmony_ci	struct ncsi_channel_mode    modes[NCSI_MODE_MAX];
2218c2ecf20Sopenharmony_ci	/* Filtering Settings */
2228c2ecf20Sopenharmony_ci	struct ncsi_channel_mac_filter	mac_filter;
2238c2ecf20Sopenharmony_ci	struct ncsi_channel_vlan_filter	vlan_filter;
2248c2ecf20Sopenharmony_ci	struct ncsi_channel_stats   stats;
2258c2ecf20Sopenharmony_ci	struct {
2268c2ecf20Sopenharmony_ci		struct timer_list   timer;
2278c2ecf20Sopenharmony_ci		bool                enabled;
2288c2ecf20Sopenharmony_ci		unsigned int        state;
2298c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_START	0
2308c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_RETRY	1
2318c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_WAIT	2
2328c2ecf20Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_WAIT_MAX	5
2338c2ecf20Sopenharmony_ci	} monitor;
2348c2ecf20Sopenharmony_ci	struct list_head            node;
2358c2ecf20Sopenharmony_ci	struct list_head            link;
2368c2ecf20Sopenharmony_ci};
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistruct ncsi_package {
2398c2ecf20Sopenharmony_ci	unsigned char        id;          /* NCSI 3-bits package ID */
2408c2ecf20Sopenharmony_ci	unsigned char        uuid[16];    /* UUID                   */
2418c2ecf20Sopenharmony_ci	struct ncsi_dev_priv *ndp;        /* NCSI device            */
2428c2ecf20Sopenharmony_ci	spinlock_t           lock;        /* Protect the package    */
2438c2ecf20Sopenharmony_ci	unsigned int         channel_num; /* Number of channels     */
2448c2ecf20Sopenharmony_ci	struct list_head     channels;    /* List of chanels        */
2458c2ecf20Sopenharmony_ci	struct list_head     node;        /* Form list of packages  */
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	bool                 multi_channel; /* Enable multiple channels  */
2488c2ecf20Sopenharmony_ci	u32                  channel_whitelist; /* Channels to configure */
2498c2ecf20Sopenharmony_ci	struct ncsi_channel  *preferred_channel; /* Primary channel      */
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistruct ncsi_request {
2538c2ecf20Sopenharmony_ci	unsigned char        id;      /* Request ID - 0 to 255           */
2548c2ecf20Sopenharmony_ci	bool                 used;    /* Request that has been assigned  */
2558c2ecf20Sopenharmony_ci	unsigned int         flags;   /* NCSI request property           */
2568c2ecf20Sopenharmony_ci#define NCSI_REQ_FLAG_EVENT_DRIVEN	1
2578c2ecf20Sopenharmony_ci#define NCSI_REQ_FLAG_NETLINK_DRIVEN	2
2588c2ecf20Sopenharmony_ci	struct ncsi_dev_priv *ndp;    /* Associated NCSI device          */
2598c2ecf20Sopenharmony_ci	struct sk_buff       *cmd;    /* Associated NCSI command packet  */
2608c2ecf20Sopenharmony_ci	struct sk_buff       *rsp;    /* Associated NCSI response packet */
2618c2ecf20Sopenharmony_ci	struct timer_list    timer;   /* Timer on waiting for response   */
2628c2ecf20Sopenharmony_ci	bool                 enabled; /* Time has been enabled or not    */
2638c2ecf20Sopenharmony_ci	u32                  snd_seq;     /* netlink sending sequence number */
2648c2ecf20Sopenharmony_ci	u32                  snd_portid;  /* netlink portid of sender        */
2658c2ecf20Sopenharmony_ci	struct nlmsghdr      nlhdr;       /* netlink message header          */
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cienum {
2698c2ecf20Sopenharmony_ci	ncsi_dev_state_major		= 0xff00,
2708c2ecf20Sopenharmony_ci	ncsi_dev_state_minor		= 0x00ff,
2718c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_deselect	= 0x0201,
2728c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_package,
2738c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_channel,
2748c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_mlx_gma,
2758c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_mlx_smaf,
2768c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_cis,
2778c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_gvi,
2788c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_gc,
2798c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_gls,
2808c2ecf20Sopenharmony_ci	ncsi_dev_state_probe_dp,
2818c2ecf20Sopenharmony_ci	ncsi_dev_state_config_sp	= 0x0301,
2828c2ecf20Sopenharmony_ci	ncsi_dev_state_config_cis,
2838c2ecf20Sopenharmony_ci	ncsi_dev_state_config_oem_gma,
2848c2ecf20Sopenharmony_ci	ncsi_dev_state_config_clear_vids,
2858c2ecf20Sopenharmony_ci	ncsi_dev_state_config_svf,
2868c2ecf20Sopenharmony_ci	ncsi_dev_state_config_ev,
2878c2ecf20Sopenharmony_ci	ncsi_dev_state_config_sma,
2888c2ecf20Sopenharmony_ci	ncsi_dev_state_config_ebf,
2898c2ecf20Sopenharmony_ci	ncsi_dev_state_config_dgmf,
2908c2ecf20Sopenharmony_ci	ncsi_dev_state_config_ecnt,
2918c2ecf20Sopenharmony_ci	ncsi_dev_state_config_ec,
2928c2ecf20Sopenharmony_ci	ncsi_dev_state_config_ae,
2938c2ecf20Sopenharmony_ci	ncsi_dev_state_config_gls,
2948c2ecf20Sopenharmony_ci	ncsi_dev_state_config_done,
2958c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_select	= 0x0401,
2968c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_gls,
2978c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_dcnt,
2988c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_dc,
2998c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_deselect,
3008c2ecf20Sopenharmony_ci	ncsi_dev_state_suspend_done
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_cistruct vlan_vid {
3048c2ecf20Sopenharmony_ci	struct list_head list;
3058c2ecf20Sopenharmony_ci	__be16 proto;
3068c2ecf20Sopenharmony_ci	u16 vid;
3078c2ecf20Sopenharmony_ci};
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistruct ncsi_dev_priv {
3108c2ecf20Sopenharmony_ci	struct ncsi_dev     ndev;            /* Associated NCSI device     */
3118c2ecf20Sopenharmony_ci	unsigned int        flags;           /* NCSI device flags          */
3128c2ecf20Sopenharmony_ci#define NCSI_DEV_PROBED		1            /* Finalized NCSI topology    */
3138c2ecf20Sopenharmony_ci#define NCSI_DEV_HWA		2            /* Enabled HW arbitration     */
3148c2ecf20Sopenharmony_ci#define NCSI_DEV_RESHUFFLE	4
3158c2ecf20Sopenharmony_ci#define NCSI_DEV_RESET		8            /* Reset state of NC          */
3168c2ecf20Sopenharmony_ci	unsigned int        gma_flag;        /* OEM GMA flag               */
3178c2ecf20Sopenharmony_ci	spinlock_t          lock;            /* Protect the NCSI device    */
3188c2ecf20Sopenharmony_ci	unsigned int        package_probe_id;/* Current ID during probe    */
3198c2ecf20Sopenharmony_ci	unsigned int        package_num;     /* Number of packages         */
3208c2ecf20Sopenharmony_ci	struct list_head    packages;        /* List of packages           */
3218c2ecf20Sopenharmony_ci	struct ncsi_channel *hot_channel;    /* Channel was ever active    */
3228c2ecf20Sopenharmony_ci	struct ncsi_request requests[256];   /* Request table              */
3238c2ecf20Sopenharmony_ci	unsigned int        request_id;      /* Last used request ID       */
3248c2ecf20Sopenharmony_ci#define NCSI_REQ_START_IDX	1
3258c2ecf20Sopenharmony_ci	unsigned int        pending_req_num; /* Number of pending requests */
3268c2ecf20Sopenharmony_ci	struct ncsi_package *active_package; /* Currently handled package  */
3278c2ecf20Sopenharmony_ci	struct ncsi_channel *active_channel; /* Currently handled channel  */
3288c2ecf20Sopenharmony_ci	struct list_head    channel_queue;   /* Config queue of channels   */
3298c2ecf20Sopenharmony_ci	struct work_struct  work;            /* For channel management     */
3308c2ecf20Sopenharmony_ci	struct packet_type  ptype;           /* NCSI packet Rx handler     */
3318c2ecf20Sopenharmony_ci	struct list_head    node;            /* Form NCSI device list      */
3328c2ecf20Sopenharmony_ci#define NCSI_MAX_VLAN_VIDS	15
3338c2ecf20Sopenharmony_ci	struct list_head    vlan_vids;       /* List of active VLAN IDs */
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	bool                multi_package;   /* Enable multiple packages   */
3368c2ecf20Sopenharmony_ci	bool                mlx_multi_host;  /* Enable multi host Mellanox */
3378c2ecf20Sopenharmony_ci	u32                 package_whitelist; /* Packages to configure    */
3388c2ecf20Sopenharmony_ci};
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistruct ncsi_cmd_arg {
3418c2ecf20Sopenharmony_ci	struct ncsi_dev_priv *ndp;        /* Associated NCSI device        */
3428c2ecf20Sopenharmony_ci	unsigned char        type;        /* Command in the NCSI packet    */
3438c2ecf20Sopenharmony_ci	unsigned char        id;          /* Request ID (sequence number)  */
3448c2ecf20Sopenharmony_ci	unsigned char        package;     /* Destination package ID        */
3458c2ecf20Sopenharmony_ci	unsigned char        channel;     /* Detination channel ID or 0x1f */
3468c2ecf20Sopenharmony_ci	unsigned short       payload;     /* Command packet payload length */
3478c2ecf20Sopenharmony_ci	unsigned int         req_flags;   /* NCSI request properties       */
3488c2ecf20Sopenharmony_ci	union {
3498c2ecf20Sopenharmony_ci		unsigned char  bytes[16]; /* Command packet specific data  */
3508c2ecf20Sopenharmony_ci		unsigned short words[8];
3518c2ecf20Sopenharmony_ci		unsigned int   dwords[4];
3528c2ecf20Sopenharmony_ci	};
3538c2ecf20Sopenharmony_ci	unsigned char        *data;       /* NCSI OEM data                 */
3548c2ecf20Sopenharmony_ci	struct genl_info     *info;       /* Netlink information           */
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ciextern struct list_head ncsi_dev_list;
3588c2ecf20Sopenharmony_ciextern spinlock_t ncsi_dev_lock;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci#define TO_NCSI_DEV_PRIV(nd) \
3618c2ecf20Sopenharmony_ci	container_of(nd, struct ncsi_dev_priv, ndev)
3628c2ecf20Sopenharmony_ci#define NCSI_FOR_EACH_DEV(ndp) \
3638c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
3648c2ecf20Sopenharmony_ci#define NCSI_FOR_EACH_PACKAGE(ndp, np) \
3658c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(np, &ndp->packages, node)
3668c2ecf20Sopenharmony_ci#define NCSI_FOR_EACH_CHANNEL(np, nc) \
3678c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(nc, &np->channels, node)
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci/* Resources */
3708c2ecf20Sopenharmony_ciint ncsi_reset_dev(struct ncsi_dev *nd);
3718c2ecf20Sopenharmony_civoid ncsi_start_channel_monitor(struct ncsi_channel *nc);
3728c2ecf20Sopenharmony_civoid ncsi_stop_channel_monitor(struct ncsi_channel *nc);
3738c2ecf20Sopenharmony_cistruct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
3748c2ecf20Sopenharmony_ci				       unsigned char id);
3758c2ecf20Sopenharmony_cistruct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
3768c2ecf20Sopenharmony_ci				      unsigned char id);
3778c2ecf20Sopenharmony_cistruct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
3788c2ecf20Sopenharmony_ci				       unsigned char id);
3798c2ecf20Sopenharmony_cistruct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
3808c2ecf20Sopenharmony_ci				      unsigned char id);
3818c2ecf20Sopenharmony_civoid ncsi_remove_package(struct ncsi_package *np);
3828c2ecf20Sopenharmony_civoid ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
3838c2ecf20Sopenharmony_ci				   unsigned char id,
3848c2ecf20Sopenharmony_ci				   struct ncsi_package **np,
3858c2ecf20Sopenharmony_ci				   struct ncsi_channel **nc);
3868c2ecf20Sopenharmony_cistruct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
3878c2ecf20Sopenharmony_ci					unsigned int req_flags);
3888c2ecf20Sopenharmony_civoid ncsi_free_request(struct ncsi_request *nr);
3898c2ecf20Sopenharmony_cistruct ncsi_dev *ncsi_find_dev(struct net_device *dev);
3908c2ecf20Sopenharmony_ciint ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
3918c2ecf20Sopenharmony_cibool ncsi_channel_has_link(struct ncsi_channel *channel);
3928c2ecf20Sopenharmony_cibool ncsi_channel_is_last(struct ncsi_dev_priv *ndp,
3938c2ecf20Sopenharmony_ci			  struct ncsi_channel *channel);
3948c2ecf20Sopenharmony_ciint ncsi_update_tx_channel(struct ncsi_dev_priv *ndp,
3958c2ecf20Sopenharmony_ci			   struct ncsi_package *np,
3968c2ecf20Sopenharmony_ci			   struct ncsi_channel *disable,
3978c2ecf20Sopenharmony_ci			   struct ncsi_channel *enable);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci/* Packet handlers */
4008c2ecf20Sopenharmony_ciu32 ncsi_calculate_checksum(unsigned char *data, int len);
4018c2ecf20Sopenharmony_ciint ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
4028c2ecf20Sopenharmony_ciint ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
4038c2ecf20Sopenharmony_ci		 struct packet_type *pt, struct net_device *orig_dev);
4048c2ecf20Sopenharmony_ciint ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci#endif /* __NCSI_INTERNAL_H__ */
407