• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*  Marvell OcteonTx2 CGX driver
3  *
4  * Copyright (C) 2018 Marvell International Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 
11 #ifndef CGX_H
12 #define CGX_H
13 
14 #include "mbox.h"
15 #include "cgx_fw_if.h"
16 
17  /* PCI device IDs */
18 #define	PCI_DEVID_OCTEONTX2_CGX		0xA059
19 
20 /* PCI BAR nos */
21 #define PCI_CFG_REG_BAR_NUM		0
22 
23 #define CGX_ID_MASK			0x7
24 #define MAX_LMAC_PER_CGX		4
25 #define CGX_FIFO_LEN			65536 /* 64K for both Rx & Tx */
26 #define CGX_OFFSET(x)			((x) * MAX_LMAC_PER_CGX)
27 
28 /* Registers */
29 #define CGXX_CMRX_CFG			0x00
30 #define CMR_EN				BIT_ULL(55)
31 #define DATA_PKT_TX_EN			BIT_ULL(53)
32 #define DATA_PKT_RX_EN			BIT_ULL(54)
33 #define CGX_LMAC_TYPE_SHIFT		40
34 #define CGX_LMAC_TYPE_MASK		0xF
35 #define CGXX_CMRX_INT			0x040
36 #define FW_CGX_INT			BIT_ULL(1)
37 #define CGXX_CMRX_INT_ENA_W1S		0x058
38 #define CGXX_CMRX_RX_ID_MAP		0x060
39 #define CGXX_CMRX_RX_STAT0		0x070
40 #define CGXX_CMRX_RX_LMACS		0x128
41 #define CGXX_CMRX_RX_DMAC_CTL0		0x1F8
42 #define CGX_DMAC_CTL0_CAM_ENABLE	BIT_ULL(3)
43 #define CGX_DMAC_CAM_ACCEPT		BIT_ULL(3)
44 #define CGX_DMAC_MCAST_MODE		BIT_ULL(1)
45 #define CGX_DMAC_BCAST_MODE		BIT_ULL(0)
46 #define CGXX_CMRX_RX_DMAC_CAM0		0x200
47 #define CGX_DMAC_CAM_ADDR_ENABLE	BIT_ULL(48)
48 #define CGXX_CMRX_RX_DMAC_CAM1		0x400
49 #define CGX_RX_DMAC_ADR_MASK		GENMASK_ULL(47, 0)
50 #define CGXX_CMRX_TX_STAT0		0x700
51 #define CGXX_SCRATCH0_REG		0x1050
52 #define CGXX_SCRATCH1_REG		0x1058
53 #define CGX_CONST			0x2000
54 #define CGXX_SPUX_CONTROL1		0x10000
55 #define CGXX_SPUX_CONTROL1_LBK		BIT_ULL(14)
56 #define CGXX_GMP_PCS_MRX_CTL		0x30000
57 #define CGXX_GMP_PCS_MRX_CTL_LBK	BIT_ULL(14)
58 
59 #define CGXX_SMUX_RX_FRM_CTL		0x20020
60 #define CGX_SMUX_RX_FRM_CTL_CTL_BCK	BIT_ULL(3)
61 #define CGX_SMUX_RX_FRM_CTL_PTP_MODE	BIT_ULL(12)
62 #define CGXX_GMP_GMI_RXX_FRM_CTL	0x38028
63 #define CGX_GMP_GMI_RXX_FRM_CTL_CTL_BCK	BIT_ULL(3)
64 #define CGX_GMP_GMI_RXX_FRM_CTL_PTP_MODE BIT_ULL(12)
65 #define CGXX_SMUX_TX_CTL		0x20178
66 #define CGXX_SMUX_TX_PAUSE_PKT_TIME	0x20110
67 #define CGXX_SMUX_TX_PAUSE_PKT_INTERVAL	0x20120
68 #define CGXX_GMP_GMI_TX_PAUSE_PKT_TIME	0x38230
69 #define CGXX_GMP_GMI_TX_PAUSE_PKT_INTERVAL	0x38248
70 #define CGX_SMUX_TX_CTL_L2P_BP_CONV	BIT_ULL(7)
71 #define CGXX_CMR_RX_OVR_BP		0x130
72 #define CGX_CMR_RX_OVR_BP_EN(X)		BIT_ULL(((X) + 8))
73 #define CGX_CMR_RX_OVR_BP_BP(X)		BIT_ULL(((X) + 4))
74 
75 #define CGX_COMMAND_REG			CGXX_SCRATCH1_REG
76 #define CGX_EVENT_REG			CGXX_SCRATCH0_REG
77 #define CGX_CMD_TIMEOUT			2200 /* msecs */
78 #define DEFAULT_PAUSE_TIME		0x7FF
79 
80 #define CGX_NVEC			37
81 #define CGX_LMAC_FWI			0
82 
83 enum  cgx_nix_stat_type {
84 	NIX_STATS_RX,
85 	NIX_STATS_TX,
86 };
87 
88 enum LMAC_TYPE {
89 	LMAC_MODE_SGMII		= 0,
90 	LMAC_MODE_XAUI		= 1,
91 	LMAC_MODE_RXAUI		= 2,
92 	LMAC_MODE_10G_R		= 3,
93 	LMAC_MODE_40G_R		= 4,
94 	LMAC_MODE_QSGMII	= 6,
95 	LMAC_MODE_25G_R		= 7,
96 	LMAC_MODE_50G_R		= 8,
97 	LMAC_MODE_100G_R	= 9,
98 	LMAC_MODE_USXGMII	= 10,
99 	LMAC_MODE_MAX,
100 };
101 
102 struct cgx_link_event {
103 	struct cgx_link_user_info link_uinfo;
104 	u8 cgx_id;
105 	u8 lmac_id;
106 };
107 
108 /**
109  * struct cgx_event_cb
110  * @notify_link_chg:	callback for link change notification
111  * @data:	data passed to callback function
112  */
113 struct cgx_event_cb {
114 	int (*notify_link_chg)(struct cgx_link_event *event, void *data);
115 	void *data;
116 };
117 
118 extern struct pci_driver cgx_driver;
119 
120 int cgx_get_cgxcnt_max(void);
121 int cgx_get_cgxid(void *cgxd);
122 int cgx_get_lmac_cnt(void *cgxd);
123 void *cgx_get_pdata(int cgx_id);
124 int cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind);
125 int cgx_lmac_evh_register(struct cgx_event_cb *cb, void *cgxd, int lmac_id);
126 int cgx_lmac_evh_unregister(void *cgxd, int lmac_id);
127 int cgx_get_tx_stats(void *cgxd, int lmac_id, int idx, u64 *tx_stat);
128 int cgx_get_rx_stats(void *cgxd, int lmac_id, int idx, u64 *rx_stat);
129 int cgx_lmac_rx_tx_enable(void *cgxd, int lmac_id, bool enable);
130 int cgx_lmac_tx_enable(void *cgxd, int lmac_id, bool enable);
131 int cgx_lmac_addr_set(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
132 u64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id);
133 void cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable);
134 void cgx_lmac_enadis_rx_pause_fwding(void *cgxd, int lmac_id, bool enable);
135 int cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable);
136 int cgx_get_link_info(void *cgxd, int lmac_id,
137 		      struct cgx_link_user_info *linfo);
138 int cgx_lmac_linkup_start(void *cgxd);
139 int cgx_get_fwdata_base(u64 *base);
140 int cgx_lmac_get_pause_frm(void *cgxd, int lmac_id,
141 			   u8 *tx_pause, u8 *rx_pause);
142 int cgx_lmac_set_pause_frm(void *cgxd, int lmac_id,
143 			   u8 tx_pause, u8 rx_pause);
144 void cgx_lmac_ptp_config(void *cgxd, int lmac_id, bool enable);
145 
146 #endif /* CGX_H */
147