162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright Gavin Shan, IBM Corporation 2016.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef __NCSI_INTERNAL_H__
762306a36Sopenharmony_ci#define __NCSI_INTERNAL_H__
862306a36Sopenharmony_ci
962306a36Sopenharmony_cienum {
1062306a36Sopenharmony_ci	NCSI_CAP_BASE		= 0,
1162306a36Sopenharmony_ci	NCSI_CAP_GENERIC	= 0,
1262306a36Sopenharmony_ci	NCSI_CAP_BC,
1362306a36Sopenharmony_ci	NCSI_CAP_MC,
1462306a36Sopenharmony_ci	NCSI_CAP_BUFFER,
1562306a36Sopenharmony_ci	NCSI_CAP_AEN,
1662306a36Sopenharmony_ci	NCSI_CAP_VLAN,
1762306a36Sopenharmony_ci	NCSI_CAP_MAX
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cienum {
2162306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA             = 0x01, /* HW arbitration           */
2262306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HDS             = 0x02, /* HNC driver status change */
2362306a36Sopenharmony_ci	NCSI_CAP_GENERIC_FC              = 0x04, /* HNC to MC flow control   */
2462306a36Sopenharmony_ci	NCSI_CAP_GENERIC_FC1             = 0x08, /* MC to HNC flow control   */
2562306a36Sopenharmony_ci	NCSI_CAP_GENERIC_MC              = 0x10, /* Global MC filtering      */
2662306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_UNKNOWN     = 0x00, /* Unknown HW arbitration   */
2762306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_SUPPORT     = 0x20, /* Supported HW arbitration */
2862306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration        */
2962306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_RESERVED    = 0x60, /* Reserved HW arbitration  */
3062306a36Sopenharmony_ci	NCSI_CAP_GENERIC_HWA_MASK        = 0x60, /* Mask for HW arbitration  */
3162306a36Sopenharmony_ci	NCSI_CAP_GENERIC_MASK            = 0x7f,
3262306a36Sopenharmony_ci	NCSI_CAP_BC_ARP                  = 0x01, /* ARP packet filtering     */
3362306a36Sopenharmony_ci	NCSI_CAP_BC_DHCPC                = 0x02, /* DHCP client filtering    */
3462306a36Sopenharmony_ci	NCSI_CAP_BC_DHCPS                = 0x04, /* DHCP server filtering    */
3562306a36Sopenharmony_ci	NCSI_CAP_BC_NETBIOS              = 0x08, /* NetBIOS packet filtering */
3662306a36Sopenharmony_ci	NCSI_CAP_BC_MASK                 = 0x0f,
3762306a36Sopenharmony_ci	NCSI_CAP_MC_IPV6_NEIGHBOR        = 0x01, /* IPv6 neighbor filtering  */
3862306a36Sopenharmony_ci	NCSI_CAP_MC_IPV6_ROUTER          = 0x02, /* IPv6 router filering     */
3962306a36Sopenharmony_ci	NCSI_CAP_MC_DHCPV6_RELAY         = 0x04, /* DHCPv6 relay / server MC */
4062306a36Sopenharmony_ci	NCSI_CAP_MC_DHCPV6_WELL_KNOWN    = 0x08, /* DHCPv6 well-known MC     */
4162306a36Sopenharmony_ci	NCSI_CAP_MC_IPV6_MLD             = 0x10, /* IPv6 MLD filtering       */
4262306a36Sopenharmony_ci	NCSI_CAP_MC_IPV6_NEIGHBOR_S      = 0x20, /* IPv6 neighbour filtering */
4362306a36Sopenharmony_ci	NCSI_CAP_MC_MASK                 = 0x3f,
4462306a36Sopenharmony_ci	NCSI_CAP_AEN_LSC                 = 0x01, /* Link status change       */
4562306a36Sopenharmony_ci	NCSI_CAP_AEN_CR                  = 0x02, /* Configuration required   */
4662306a36Sopenharmony_ci	NCSI_CAP_AEN_HDS                 = 0x04, /* HNC driver status        */
4762306a36Sopenharmony_ci	NCSI_CAP_AEN_MASK                = 0x07,
4862306a36Sopenharmony_ci	NCSI_CAP_VLAN_ONLY               = 0x01, /* Filter VLAN packet only  */
4962306a36Sopenharmony_ci	NCSI_CAP_VLAN_NO                 = 0x02, /* Filter VLAN and non-VLAN */
5062306a36Sopenharmony_ci	NCSI_CAP_VLAN_ANY                = 0x04, /* Filter Any-and-non-VLAN  */
5162306a36Sopenharmony_ci	NCSI_CAP_VLAN_MASK               = 0x07
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cienum {
5562306a36Sopenharmony_ci	NCSI_MODE_BASE		= 0,
5662306a36Sopenharmony_ci	NCSI_MODE_ENABLE	= 0,
5762306a36Sopenharmony_ci	NCSI_MODE_TX_ENABLE,
5862306a36Sopenharmony_ci	NCSI_MODE_LINK,
5962306a36Sopenharmony_ci	NCSI_MODE_VLAN,
6062306a36Sopenharmony_ci	NCSI_MODE_BC,
6162306a36Sopenharmony_ci	NCSI_MODE_MC,
6262306a36Sopenharmony_ci	NCSI_MODE_AEN,
6362306a36Sopenharmony_ci	NCSI_MODE_FC,
6462306a36Sopenharmony_ci	NCSI_MODE_MAX
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/* Supported media status bits for Mellanox Mac affinity command.
6862306a36Sopenharmony_ci * Bit (0-2) for different protocol support; Bit 1 for RBT support,
6962306a36Sopenharmony_ci * bit 1 for SMBUS support and bit 2 for PCIE support. Bit (3-5)
7062306a36Sopenharmony_ci * for different protocol availability. Bit 4 for RBT, bit 4 for
7162306a36Sopenharmony_ci * SMBUS and bit 5 for PCIE.
7262306a36Sopenharmony_ci */
7362306a36Sopenharmony_cienum {
7462306a36Sopenharmony_ci	MLX_MC_RBT_SUPPORT  = 0x01, /* MC supports RBT         */
7562306a36Sopenharmony_ci	MLX_MC_RBT_AVL      = 0x08, /* RBT medium is available */
7662306a36Sopenharmony_ci};
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* OEM Vendor Manufacture ID */
7962306a36Sopenharmony_ci#define NCSI_OEM_MFR_MLX_ID             0x8119
8062306a36Sopenharmony_ci#define NCSI_OEM_MFR_BCM_ID             0x113d
8162306a36Sopenharmony_ci#define NCSI_OEM_MFR_INTEL_ID           0x157
8262306a36Sopenharmony_ci/* Intel specific OEM command */
8362306a36Sopenharmony_ci#define NCSI_OEM_INTEL_CMD_GMA          0x06   /* CMD ID for Get MAC */
8462306a36Sopenharmony_ci#define NCSI_OEM_INTEL_CMD_KEEP_PHY     0x20   /* CMD ID for Keep PHY up */
8562306a36Sopenharmony_ci/* Broadcom specific OEM Command */
8662306a36Sopenharmony_ci#define NCSI_OEM_BCM_CMD_GMA            0x01   /* CMD ID for Get MAC */
8762306a36Sopenharmony_ci/* Mellanox specific OEM Command */
8862306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA            0x00   /* CMD ID for Get MAC */
8962306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA_PARAM      0x1b   /* Parameter for GMA  */
9062306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF           0x01   /* CMD ID for Set MC Affinity */
9162306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF_PARAM     0x07   /* Parameter for SMAF         */
9262306a36Sopenharmony_ci/* OEM Command payload lengths*/
9362306a36Sopenharmony_ci#define NCSI_OEM_INTEL_CMD_GMA_LEN      5
9462306a36Sopenharmony_ci#define NCSI_OEM_INTEL_CMD_KEEP_PHY_LEN 7
9562306a36Sopenharmony_ci#define NCSI_OEM_BCM_CMD_GMA_LEN        12
9662306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_GMA_LEN        8
9762306a36Sopenharmony_ci#define NCSI_OEM_MLX_CMD_SMAF_LEN        60
9862306a36Sopenharmony_ci/* Offset in OEM request */
9962306a36Sopenharmony_ci#define MLX_SMAF_MAC_ADDR_OFFSET         8     /* Offset for MAC in SMAF    */
10062306a36Sopenharmony_ci#define MLX_SMAF_MED_SUPPORT_OFFSET      14    /* Offset for medium in SMAF */
10162306a36Sopenharmony_ci/* Mac address offset in OEM response */
10262306a36Sopenharmony_ci#define BCM_MAC_ADDR_OFFSET             28
10362306a36Sopenharmony_ci#define MLX_MAC_ADDR_OFFSET             8
10462306a36Sopenharmony_ci#define INTEL_MAC_ADDR_OFFSET           1
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistruct ncsi_channel_version {
10862306a36Sopenharmony_ci	u8   major;		/* NCSI version major */
10962306a36Sopenharmony_ci	u8   minor;		/* NCSI version minor */
11062306a36Sopenharmony_ci	u8   update;		/* NCSI version update */
11162306a36Sopenharmony_ci	char alpha1;		/* NCSI version alpha1 */
11262306a36Sopenharmony_ci	char alpha2;		/* NCSI version alpha2 */
11362306a36Sopenharmony_ci	u8  fw_name[12];	/* Firmware name string                */
11462306a36Sopenharmony_ci	u32 fw_version;		/* Firmware version                   */
11562306a36Sopenharmony_ci	u16 pci_ids[4];		/* PCI identification                 */
11662306a36Sopenharmony_ci	u32 mf_id;		/* Manufacture ID                     */
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistruct ncsi_channel_cap {
12062306a36Sopenharmony_ci	u32 index;	/* Index of channel capabilities */
12162306a36Sopenharmony_ci	u32 cap;	/* NCSI channel capability       */
12262306a36Sopenharmony_ci};
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistruct ncsi_channel_mode {
12562306a36Sopenharmony_ci	u32 index;	/* Index of channel modes      */
12662306a36Sopenharmony_ci	u32 enable;	/* Enabled or disabled         */
12762306a36Sopenharmony_ci	u32 size;	/* Valid entries in ncm_data[] */
12862306a36Sopenharmony_ci	u32 data[8];	/* Data entries                */
12962306a36Sopenharmony_ci};
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cistruct ncsi_channel_mac_filter {
13262306a36Sopenharmony_ci	u8	n_uc;
13362306a36Sopenharmony_ci	u8	n_mc;
13462306a36Sopenharmony_ci	u8	n_mixed;
13562306a36Sopenharmony_ci	u64	bitmap;
13662306a36Sopenharmony_ci	unsigned char	*addrs;
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_cistruct ncsi_channel_vlan_filter {
14062306a36Sopenharmony_ci	u8	n_vids;
14162306a36Sopenharmony_ci	u64	bitmap;
14262306a36Sopenharmony_ci	u16	*vids;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct ncsi_channel_stats {
14662306a36Sopenharmony_ci	u32 hnc_cnt_hi;		/* Counter cleared            */
14762306a36Sopenharmony_ci	u32 hnc_cnt_lo;		/* Counter cleared            */
14862306a36Sopenharmony_ci	u32 hnc_rx_bytes;	/* Rx bytes                   */
14962306a36Sopenharmony_ci	u32 hnc_tx_bytes;	/* Tx bytes                   */
15062306a36Sopenharmony_ci	u32 hnc_rx_uc_pkts;	/* Rx UC packets              */
15162306a36Sopenharmony_ci	u32 hnc_rx_mc_pkts;     /* Rx MC packets              */
15262306a36Sopenharmony_ci	u32 hnc_rx_bc_pkts;	/* Rx BC packets              */
15362306a36Sopenharmony_ci	u32 hnc_tx_uc_pkts;	/* Tx UC packets              */
15462306a36Sopenharmony_ci	u32 hnc_tx_mc_pkts;	/* Tx MC packets              */
15562306a36Sopenharmony_ci	u32 hnc_tx_bc_pkts;	/* Tx BC packets              */
15662306a36Sopenharmony_ci	u32 hnc_fcs_err;	/* FCS errors                 */
15762306a36Sopenharmony_ci	u32 hnc_align_err;	/* Alignment errors           */
15862306a36Sopenharmony_ci	u32 hnc_false_carrier;	/* False carrier detection    */
15962306a36Sopenharmony_ci	u32 hnc_runt_pkts;	/* Rx runt packets            */
16062306a36Sopenharmony_ci	u32 hnc_jabber_pkts;	/* Rx jabber packets          */
16162306a36Sopenharmony_ci	u32 hnc_rx_pause_xon;	/* Rx pause XON frames        */
16262306a36Sopenharmony_ci	u32 hnc_rx_pause_xoff;	/* Rx XOFF frames             */
16362306a36Sopenharmony_ci	u32 hnc_tx_pause_xon;	/* Tx XON frames              */
16462306a36Sopenharmony_ci	u32 hnc_tx_pause_xoff;	/* Tx XOFF frames             */
16562306a36Sopenharmony_ci	u32 hnc_tx_s_collision;	/* Single collision frames    */
16662306a36Sopenharmony_ci	u32 hnc_tx_m_collision;	/* Multiple collision frames  */
16762306a36Sopenharmony_ci	u32 hnc_l_collision;	/* Late collision frames      */
16862306a36Sopenharmony_ci	u32 hnc_e_collision;	/* Excessive collision frames */
16962306a36Sopenharmony_ci	u32 hnc_rx_ctl_frames;	/* Rx control frames          */
17062306a36Sopenharmony_ci	u32 hnc_rx_64_frames;	/* Rx 64-bytes frames         */
17162306a36Sopenharmony_ci	u32 hnc_rx_127_frames;	/* Rx 65-127 bytes frames     */
17262306a36Sopenharmony_ci	u32 hnc_rx_255_frames;	/* Rx 128-255 bytes frames    */
17362306a36Sopenharmony_ci	u32 hnc_rx_511_frames;	/* Rx 256-511 bytes frames    */
17462306a36Sopenharmony_ci	u32 hnc_rx_1023_frames;	/* Rx 512-1023 bytes frames   */
17562306a36Sopenharmony_ci	u32 hnc_rx_1522_frames;	/* Rx 1024-1522 bytes frames  */
17662306a36Sopenharmony_ci	u32 hnc_rx_9022_frames;	/* Rx 1523-9022 bytes frames  */
17762306a36Sopenharmony_ci	u32 hnc_tx_64_frames;	/* Tx 64-bytes frames         */
17862306a36Sopenharmony_ci	u32 hnc_tx_127_frames;	/* Tx 65-127 bytes frames     */
17962306a36Sopenharmony_ci	u32 hnc_tx_255_frames;	/* Tx 128-255 bytes frames    */
18062306a36Sopenharmony_ci	u32 hnc_tx_511_frames;	/* Tx 256-511 bytes frames    */
18162306a36Sopenharmony_ci	u32 hnc_tx_1023_frames;	/* Tx 512-1023 bytes frames   */
18262306a36Sopenharmony_ci	u32 hnc_tx_1522_frames;	/* Tx 1024-1522 bytes frames  */
18362306a36Sopenharmony_ci	u32 hnc_tx_9022_frames;	/* Tx 1523-9022 bytes frames  */
18462306a36Sopenharmony_ci	u32 hnc_rx_valid_bytes;	/* Rx valid bytes             */
18562306a36Sopenharmony_ci	u32 hnc_rx_runt_pkts;	/* Rx error runt packets      */
18662306a36Sopenharmony_ci	u32 hnc_rx_jabber_pkts;	/* Rx error jabber packets    */
18762306a36Sopenharmony_ci	u32 ncsi_rx_cmds;	/* Rx NCSI commands           */
18862306a36Sopenharmony_ci	u32 ncsi_dropped_cmds;	/* Dropped commands           */
18962306a36Sopenharmony_ci	u32 ncsi_cmd_type_errs;	/* Command type errors        */
19062306a36Sopenharmony_ci	u32 ncsi_cmd_csum_errs;	/* Command checksum errors    */
19162306a36Sopenharmony_ci	u32 ncsi_rx_pkts;	/* Rx NCSI packets            */
19262306a36Sopenharmony_ci	u32 ncsi_tx_pkts;	/* Tx NCSI packets            */
19362306a36Sopenharmony_ci	u32 ncsi_tx_aen_pkts;	/* Tx AEN packets             */
19462306a36Sopenharmony_ci	u32 pt_tx_pkts;		/* Tx packets                 */
19562306a36Sopenharmony_ci	u32 pt_tx_dropped;	/* Tx dropped packets         */
19662306a36Sopenharmony_ci	u32 pt_tx_channel_err;	/* Tx channel errors          */
19762306a36Sopenharmony_ci	u32 pt_tx_us_err;	/* Tx undersize errors        */
19862306a36Sopenharmony_ci	u32 pt_rx_pkts;		/* Rx packets                 */
19962306a36Sopenharmony_ci	u32 pt_rx_dropped;	/* Rx dropped packets         */
20062306a36Sopenharmony_ci	u32 pt_rx_channel_err;	/* Rx channel errors          */
20162306a36Sopenharmony_ci	u32 pt_rx_us_err;	/* Rx undersize errors        */
20262306a36Sopenharmony_ci	u32 pt_rx_os_err;	/* Rx oversize errors         */
20362306a36Sopenharmony_ci};
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct ncsi_dev_priv;
20662306a36Sopenharmony_cistruct ncsi_package;
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci#define NCSI_PACKAGE_SHIFT	5
20962306a36Sopenharmony_ci#define NCSI_PACKAGE_INDEX(c)	(((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
21062306a36Sopenharmony_ci#define NCSI_RESERVED_CHANNEL	0x1f
21162306a36Sopenharmony_ci#define NCSI_CHANNEL_INDEX(c)	((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
21262306a36Sopenharmony_ci#define NCSI_TO_CHANNEL(p, c)	(((p) << NCSI_PACKAGE_SHIFT) | (c))
21362306a36Sopenharmony_ci#define NCSI_MAX_PACKAGE	8
21462306a36Sopenharmony_ci#define NCSI_MAX_CHANNEL	32
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_cistruct ncsi_channel {
21762306a36Sopenharmony_ci	unsigned char               id;
21862306a36Sopenharmony_ci	int                         state;
21962306a36Sopenharmony_ci#define NCSI_CHANNEL_INACTIVE		1
22062306a36Sopenharmony_ci#define NCSI_CHANNEL_ACTIVE		2
22162306a36Sopenharmony_ci#define NCSI_CHANNEL_INVISIBLE		3
22262306a36Sopenharmony_ci	bool                        reconfigure_needed;
22362306a36Sopenharmony_ci	spinlock_t                  lock;	/* Protect filters etc */
22462306a36Sopenharmony_ci	struct ncsi_package         *package;
22562306a36Sopenharmony_ci	struct ncsi_channel_version version;
22662306a36Sopenharmony_ci	struct ncsi_channel_cap	    caps[NCSI_CAP_MAX];
22762306a36Sopenharmony_ci	struct ncsi_channel_mode    modes[NCSI_MODE_MAX];
22862306a36Sopenharmony_ci	/* Filtering Settings */
22962306a36Sopenharmony_ci	struct ncsi_channel_mac_filter	mac_filter;
23062306a36Sopenharmony_ci	struct ncsi_channel_vlan_filter	vlan_filter;
23162306a36Sopenharmony_ci	struct ncsi_channel_stats   stats;
23262306a36Sopenharmony_ci	struct {
23362306a36Sopenharmony_ci		struct timer_list   timer;
23462306a36Sopenharmony_ci		bool                enabled;
23562306a36Sopenharmony_ci		unsigned int        state;
23662306a36Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_START	0
23762306a36Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_RETRY	1
23862306a36Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_WAIT	2
23962306a36Sopenharmony_ci#define NCSI_CHANNEL_MONITOR_WAIT_MAX	5
24062306a36Sopenharmony_ci	} monitor;
24162306a36Sopenharmony_ci	struct list_head            node;
24262306a36Sopenharmony_ci	struct list_head            link;
24362306a36Sopenharmony_ci};
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_cistruct ncsi_package {
24662306a36Sopenharmony_ci	unsigned char        id;          /* NCSI 3-bits package ID */
24762306a36Sopenharmony_ci	unsigned char        uuid[16];    /* UUID                   */
24862306a36Sopenharmony_ci	struct ncsi_dev_priv *ndp;        /* NCSI device            */
24962306a36Sopenharmony_ci	spinlock_t           lock;        /* Protect the package    */
25062306a36Sopenharmony_ci	unsigned int         channel_num; /* Number of channels     */
25162306a36Sopenharmony_ci	struct list_head     channels;    /* List of channels        */
25262306a36Sopenharmony_ci	struct list_head     node;        /* Form list of packages  */
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	bool                 multi_channel; /* Enable multiple channels  */
25562306a36Sopenharmony_ci	u32                  channel_whitelist; /* Channels to configure */
25662306a36Sopenharmony_ci	struct ncsi_channel  *preferred_channel; /* Primary channel      */
25762306a36Sopenharmony_ci};
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_cistruct ncsi_request {
26062306a36Sopenharmony_ci	unsigned char        id;      /* Request ID - 0 to 255           */
26162306a36Sopenharmony_ci	bool                 used;    /* Request that has been assigned  */
26262306a36Sopenharmony_ci	unsigned int         flags;   /* NCSI request property           */
26362306a36Sopenharmony_ci#define NCSI_REQ_FLAG_EVENT_DRIVEN	1
26462306a36Sopenharmony_ci#define NCSI_REQ_FLAG_NETLINK_DRIVEN	2
26562306a36Sopenharmony_ci	struct ncsi_dev_priv *ndp;    /* Associated NCSI device          */
26662306a36Sopenharmony_ci	struct sk_buff       *cmd;    /* Associated NCSI command packet  */
26762306a36Sopenharmony_ci	struct sk_buff       *rsp;    /* Associated NCSI response packet */
26862306a36Sopenharmony_ci	struct timer_list    timer;   /* Timer on waiting for response   */
26962306a36Sopenharmony_ci	bool                 enabled; /* Time has been enabled or not    */
27062306a36Sopenharmony_ci	u32                  snd_seq;     /* netlink sending sequence number */
27162306a36Sopenharmony_ci	u32                  snd_portid;  /* netlink portid of sender        */
27262306a36Sopenharmony_ci	struct nlmsghdr      nlhdr;       /* netlink message header          */
27362306a36Sopenharmony_ci};
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_cienum {
27662306a36Sopenharmony_ci	ncsi_dev_state_major		= 0xff00,
27762306a36Sopenharmony_ci	ncsi_dev_state_minor		= 0x00ff,
27862306a36Sopenharmony_ci	ncsi_dev_state_probe_deselect	= 0x0201,
27962306a36Sopenharmony_ci	ncsi_dev_state_probe_package,
28062306a36Sopenharmony_ci	ncsi_dev_state_probe_channel,
28162306a36Sopenharmony_ci	ncsi_dev_state_probe_mlx_gma,
28262306a36Sopenharmony_ci	ncsi_dev_state_probe_mlx_smaf,
28362306a36Sopenharmony_ci	ncsi_dev_state_probe_cis,
28462306a36Sopenharmony_ci	ncsi_dev_state_probe_keep_phy,
28562306a36Sopenharmony_ci	ncsi_dev_state_probe_gvi,
28662306a36Sopenharmony_ci	ncsi_dev_state_probe_gc,
28762306a36Sopenharmony_ci	ncsi_dev_state_probe_gls,
28862306a36Sopenharmony_ci	ncsi_dev_state_probe_dp,
28962306a36Sopenharmony_ci	ncsi_dev_state_config_sp	= 0x0301,
29062306a36Sopenharmony_ci	ncsi_dev_state_config_cis,
29162306a36Sopenharmony_ci	ncsi_dev_state_config_oem_gma,
29262306a36Sopenharmony_ci	ncsi_dev_state_config_clear_vids,
29362306a36Sopenharmony_ci	ncsi_dev_state_config_svf,
29462306a36Sopenharmony_ci	ncsi_dev_state_config_ev,
29562306a36Sopenharmony_ci	ncsi_dev_state_config_sma,
29662306a36Sopenharmony_ci	ncsi_dev_state_config_ebf,
29762306a36Sopenharmony_ci	ncsi_dev_state_config_dgmf,
29862306a36Sopenharmony_ci	ncsi_dev_state_config_ecnt,
29962306a36Sopenharmony_ci	ncsi_dev_state_config_ec,
30062306a36Sopenharmony_ci	ncsi_dev_state_config_ae,
30162306a36Sopenharmony_ci	ncsi_dev_state_config_gls,
30262306a36Sopenharmony_ci	ncsi_dev_state_config_done,
30362306a36Sopenharmony_ci	ncsi_dev_state_suspend_select	= 0x0401,
30462306a36Sopenharmony_ci	ncsi_dev_state_suspend_gls,
30562306a36Sopenharmony_ci	ncsi_dev_state_suspend_dcnt,
30662306a36Sopenharmony_ci	ncsi_dev_state_suspend_dc,
30762306a36Sopenharmony_ci	ncsi_dev_state_suspend_deselect,
30862306a36Sopenharmony_ci	ncsi_dev_state_suspend_done
30962306a36Sopenharmony_ci};
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_cistruct vlan_vid {
31262306a36Sopenharmony_ci	struct list_head list;
31362306a36Sopenharmony_ci	__be16 proto;
31462306a36Sopenharmony_ci	u16 vid;
31562306a36Sopenharmony_ci};
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_cistruct ncsi_dev_priv {
31862306a36Sopenharmony_ci	struct ncsi_dev     ndev;            /* Associated NCSI device     */
31962306a36Sopenharmony_ci	unsigned int        flags;           /* NCSI device flags          */
32062306a36Sopenharmony_ci#define NCSI_DEV_PROBED		1            /* Finalized NCSI topology    */
32162306a36Sopenharmony_ci#define NCSI_DEV_HWA		2            /* Enabled HW arbitration     */
32262306a36Sopenharmony_ci#define NCSI_DEV_RESHUFFLE	4
32362306a36Sopenharmony_ci#define NCSI_DEV_RESET		8            /* Reset state of NC          */
32462306a36Sopenharmony_ci	unsigned int        gma_flag;        /* OEM GMA flag               */
32562306a36Sopenharmony_ci	spinlock_t          lock;            /* Protect the NCSI device    */
32662306a36Sopenharmony_ci	unsigned int        package_probe_id;/* Current ID during probe    */
32762306a36Sopenharmony_ci	unsigned int        package_num;     /* Number of packages         */
32862306a36Sopenharmony_ci	struct list_head    packages;        /* List of packages           */
32962306a36Sopenharmony_ci	struct ncsi_channel *hot_channel;    /* Channel was ever active    */
33062306a36Sopenharmony_ci	struct ncsi_request requests[256];   /* Request table              */
33162306a36Sopenharmony_ci	unsigned int        request_id;      /* Last used request ID       */
33262306a36Sopenharmony_ci#define NCSI_REQ_START_IDX	1
33362306a36Sopenharmony_ci	unsigned int        pending_req_num; /* Number of pending requests */
33462306a36Sopenharmony_ci	struct ncsi_package *active_package; /* Currently handled package  */
33562306a36Sopenharmony_ci	struct ncsi_channel *active_channel; /* Currently handled channel  */
33662306a36Sopenharmony_ci	struct list_head    channel_queue;   /* Config queue of channels   */
33762306a36Sopenharmony_ci	struct work_struct  work;            /* For channel management     */
33862306a36Sopenharmony_ci	struct packet_type  ptype;           /* NCSI packet Rx handler     */
33962306a36Sopenharmony_ci	struct list_head    node;            /* Form NCSI device list      */
34062306a36Sopenharmony_ci#define NCSI_MAX_VLAN_VIDS	15
34162306a36Sopenharmony_ci	struct list_head    vlan_vids;       /* List of active VLAN IDs */
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci	bool                multi_package;   /* Enable multiple packages   */
34462306a36Sopenharmony_ci	bool                mlx_multi_host;  /* Enable multi host Mellanox */
34562306a36Sopenharmony_ci	u32                 package_whitelist; /* Packages to configure    */
34662306a36Sopenharmony_ci};
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_cistruct ncsi_cmd_arg {
34962306a36Sopenharmony_ci	struct ncsi_dev_priv *ndp;        /* Associated NCSI device        */
35062306a36Sopenharmony_ci	unsigned char        type;        /* Command in the NCSI packet    */
35162306a36Sopenharmony_ci	unsigned char        id;          /* Request ID (sequence number)  */
35262306a36Sopenharmony_ci	unsigned char        package;     /* Destination package ID        */
35362306a36Sopenharmony_ci	unsigned char        channel;     /* Destination channel ID or 0x1f */
35462306a36Sopenharmony_ci	unsigned short       payload;     /* Command packet payload length */
35562306a36Sopenharmony_ci	unsigned int         req_flags;   /* NCSI request properties       */
35662306a36Sopenharmony_ci	union {
35762306a36Sopenharmony_ci		unsigned char  bytes[16]; /* Command packet specific data  */
35862306a36Sopenharmony_ci		unsigned short words[8];
35962306a36Sopenharmony_ci		unsigned int   dwords[4];
36062306a36Sopenharmony_ci	};
36162306a36Sopenharmony_ci	unsigned char        *data;       /* NCSI OEM data                 */
36262306a36Sopenharmony_ci	struct genl_info     *info;       /* Netlink information           */
36362306a36Sopenharmony_ci};
36462306a36Sopenharmony_ci
36562306a36Sopenharmony_ciextern struct list_head ncsi_dev_list;
36662306a36Sopenharmony_ciextern spinlock_t ncsi_dev_lock;
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci#define TO_NCSI_DEV_PRIV(nd) \
36962306a36Sopenharmony_ci	container_of(nd, struct ncsi_dev_priv, ndev)
37062306a36Sopenharmony_ci#define NCSI_FOR_EACH_DEV(ndp) \
37162306a36Sopenharmony_ci	list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
37262306a36Sopenharmony_ci#define NCSI_FOR_EACH_PACKAGE(ndp, np) \
37362306a36Sopenharmony_ci	list_for_each_entry_rcu(np, &ndp->packages, node)
37462306a36Sopenharmony_ci#define NCSI_FOR_EACH_CHANNEL(np, nc) \
37562306a36Sopenharmony_ci	list_for_each_entry_rcu(nc, &np->channels, node)
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci/* Resources */
37862306a36Sopenharmony_ciint ncsi_reset_dev(struct ncsi_dev *nd);
37962306a36Sopenharmony_civoid ncsi_start_channel_monitor(struct ncsi_channel *nc);
38062306a36Sopenharmony_civoid ncsi_stop_channel_monitor(struct ncsi_channel *nc);
38162306a36Sopenharmony_cistruct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
38262306a36Sopenharmony_ci				       unsigned char id);
38362306a36Sopenharmony_cistruct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
38462306a36Sopenharmony_ci				      unsigned char id);
38562306a36Sopenharmony_cistruct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
38662306a36Sopenharmony_ci				       unsigned char id);
38762306a36Sopenharmony_cistruct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
38862306a36Sopenharmony_ci				      unsigned char id);
38962306a36Sopenharmony_civoid ncsi_remove_package(struct ncsi_package *np);
39062306a36Sopenharmony_civoid ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
39162306a36Sopenharmony_ci				   unsigned char id,
39262306a36Sopenharmony_ci				   struct ncsi_package **np,
39362306a36Sopenharmony_ci				   struct ncsi_channel **nc);
39462306a36Sopenharmony_cistruct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
39562306a36Sopenharmony_ci					unsigned int req_flags);
39662306a36Sopenharmony_civoid ncsi_free_request(struct ncsi_request *nr);
39762306a36Sopenharmony_cistruct ncsi_dev *ncsi_find_dev(struct net_device *dev);
39862306a36Sopenharmony_ciint ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
39962306a36Sopenharmony_cibool ncsi_channel_has_link(struct ncsi_channel *channel);
40062306a36Sopenharmony_cibool ncsi_channel_is_last(struct ncsi_dev_priv *ndp,
40162306a36Sopenharmony_ci			  struct ncsi_channel *channel);
40262306a36Sopenharmony_ciint ncsi_update_tx_channel(struct ncsi_dev_priv *ndp,
40362306a36Sopenharmony_ci			   struct ncsi_package *np,
40462306a36Sopenharmony_ci			   struct ncsi_channel *disable,
40562306a36Sopenharmony_ci			   struct ncsi_channel *enable);
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci/* Packet handlers */
40862306a36Sopenharmony_ciu32 ncsi_calculate_checksum(unsigned char *data, int len);
40962306a36Sopenharmony_ciint ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
41062306a36Sopenharmony_ciint ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
41162306a36Sopenharmony_ci		 struct packet_type *pt, struct net_device *orig_dev);
41262306a36Sopenharmony_ciint ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci#endif /* __NCSI_INTERNAL_H__ */
415