blob: 5c45ad56d0a565d496638ff488eddcd23bdacfac [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kumar Gala2683c532011-04-13 08:37:44 -05002/*
3 * Copyright 2009-2011 Freescale Semiconductor, Inc.
Kumar Gala2683c532011-04-13 08:37:44 -05004 */
5
6#ifndef __FM_H__
7#define __FM_H__
8
Claudiu Manoilde9ad7a2014-09-05 13:52:36 +08009#include <phy.h>
Kumar Gala2683c532011-04-13 08:37:44 -050010#include <fm_eth.h>
Shaohui Xie513eaf22015-10-26 19:47:47 +080011#include <fsl_fman.h>
Kumar Gala2683c532011-04-13 08:37:44 -050012
13/* Port ID */
14#define OH_PORT_ID_BASE 0x01
15#define MAX_NUM_OH_PORT 7
16#define RX_PORT_1G_BASE 0x08
Tom Rini0a2bac72022-11-16 13:10:29 -050017#define MAX_NUM_RX_PORT_1G CFG_SYS_NUM_FM1_DTSEC
Kumar Gala2683c532011-04-13 08:37:44 -050018#define RX_PORT_10G_BASE 0x10
Shengzhou Liu4227e492013-11-22 17:39:09 +080019#define RX_PORT_10G_BASE2 0x08
Kumar Gala2683c532011-04-13 08:37:44 -050020#define TX_PORT_1G_BASE 0x28
Tom Rini0a2bac72022-11-16 13:10:29 -050021#define MAX_NUM_TX_PORT_1G CFG_SYS_NUM_FM1_DTSEC
Kumar Gala2683c532011-04-13 08:37:44 -050022#define TX_PORT_10G_BASE 0x30
Shengzhou Liu4227e492013-11-22 17:39:09 +080023#define TX_PORT_10G_BASE2 0x28
Zhao Qiang1ae99192013-09-04 10:11:27 +080024#define MIIM_TIMEOUT 0xFFFF
Kumar Gala2683c532011-04-13 08:37:44 -050025
26struct fm_muram {
Hou Zhiqiangea52d332015-10-26 19:47:44 +080027 void *base;
28 void *top;
29 size_t size;
30 void *alloc;
Kumar Gala2683c532011-04-13 08:37:44 -050031};
32#define FM_MURAM_RES_SIZE 0x01000
33
34/* Rx/Tx buffer descriptor */
35struct fm_port_bd {
36 u16 status;
37 u16 len;
38 u32 res0;
39 u16 res1;
40 u16 buf_ptr_hi;
41 u32 buf_ptr_lo;
42};
43
44/* Common BD flags */
45#define BD_LAST 0x0800
46
47/* Rx BD status flags */
48#define RxBD_EMPTY 0x8000
49#define RxBD_LAST BD_LAST
50#define RxBD_FIRST 0x0400
51#define RxBD_PHYS_ERR 0x0008
52#define RxBD_SIZE_ERR 0x0004
53#define RxBD_ERROR (RxBD_PHYS_ERR | RxBD_SIZE_ERR)
54
55/* Tx BD status flags */
56#define TxBD_READY 0x8000
57#define TxBD_LAST BD_LAST
58
Madalin Bucurb76b0a62020-04-23 16:25:19 +030059enum fm_mac_type {
60#ifdef CONFIG_SYS_FMAN_V3
61 FM_MEMAC,
62#else
63 FM_DTSEC,
64 FM_TGEC,
65#endif
66};
Madalin Bucurb76b0a62020-04-23 16:25:19 +030067
68/* Fman ethernet private struct */
Kumar Gala2683c532011-04-13 08:37:44 -050069/* Rx/Tx queue descriptor */
70struct fm_port_qd {
71 u16 gen;
72 u16 bd_ring_base_hi;
73 u32 bd_ring_base_lo;
74 u16 bd_ring_size;
75 u16 offset_in;
76 u16 offset_out;
77 u16 res0;
78 u32 res1[0x4];
79};
80
81/* IM global parameter RAM */
82struct fm_port_global_pram {
83 u32 mode; /* independent mode register */
84 u32 rxqd_ptr; /* Rx queue descriptor pointer */
85 u32 txqd_ptr; /* Tx queue descriptor pointer */
86 u16 mrblr; /* max Rx buffer length */
87 u16 rxqd_bsy_cnt; /* RxQD busy counter, should be cleared */
88 u32 res0[0x4];
89 struct fm_port_qd rxqd; /* Rx queue descriptor */
90 struct fm_port_qd txqd; /* Tx queue descriptor */
91 u32 res1[0x28];
92};
93
94#define FM_PRAM_SIZE sizeof(struct fm_port_global_pram)
95#define FM_PRAM_ALIGN 256
96#define PRAM_MODE_GLOBAL 0x20000000
97#define PRAM_MODE_GRACEFUL_STOP 0x00800000
98
York Sunab507fb2016-11-16 16:06:48 -080099#if defined(CONFIG_ARCH_P1023)
Kumar Gala2683c532011-04-13 08:37:44 -0500100#define FM_FREE_POOL_SIZE 0x2000 /* 8K bytes */
101#else
102#define FM_FREE_POOL_SIZE 0x20000 /* 128K bytes */
103#endif
104#define FM_FREE_POOL_ALIGN 256
105
Hou Zhiqiangea52d332015-10-26 19:47:44 +0800106void *fm_muram_alloc(int fm_idx, size_t size, ulong align);
107void *fm_muram_base(int fm_idx);
Sean Anderson394b4ef2022-12-29 11:53:00 -0500108int fm_init_common(int index, struct ccsr_fman *reg, const char *firmware_name);
Kumar Gala2683c532011-04-13 08:37:44 -0500109int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info);
110phy_interface_t fman_port_enet_if(enum fm_port port);
Kumar Gala5536d922011-09-14 12:01:35 -0500111void fman_disable_port(enum fm_port port);
Valentin Longchamp51b2ca32013-10-18 11:47:21 +0200112void fman_enable_port(enum fm_port port);
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300113int fman_id(struct udevice *dev);
114void *fman_port(struct udevice *dev, int num);
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300115void *fman_mdio(struct udevice *dev, enum fm_mac_type type, int num);
Kumar Gala2683c532011-04-13 08:37:44 -0500116
117struct fsl_enet_mac {
118 void *base; /* MAC controller registers base address */
119 void *phyregs;
120 int max_rx_len;
121 void (*init_mac)(struct fsl_enet_mac *mac);
122 void (*enable_mac)(struct fsl_enet_mac *mac);
123 void (*disable_mac)(struct fsl_enet_mac *mac);
124 void (*set_mac_addr)(struct fsl_enet_mac *mac, u8 *mac_addr);
125 void (*set_if_mode)(struct fsl_enet_mac *mac, phy_interface_t type,
126 int speed);
127};
128
129/* Fman ethernet private struct */
130struct fm_eth {
131 int fm_index; /* Fman index */
132 u32 num; /* 0..n-1 for give type */
133 struct fm_bmi_tx_port *tx_port;
134 struct fm_bmi_rx_port *rx_port;
135 enum fm_eth_type type; /* 1G or 10G ethernet */
136 phy_interface_t enet_if;
137 struct fsl_enet_mac *mac; /* MAC controller */
138 struct mii_dev *bus;
139 struct phy_device *phydev;
140 int phyaddr;
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300141 enum fm_mac_type mac_type;
142 struct udevice *dev;
143 struct udevice *pcs_mdio;
Kumar Gala2683c532011-04-13 08:37:44 -0500144 int max_rx_len;
145 struct fm_port_global_pram *rx_pram; /* Rx parameter table */
146 struct fm_port_global_pram *tx_pram; /* Tx parameter table */
147 void *rx_bd_ring; /* Rx BD ring base */
148 void *cur_rxbd; /* current Rx BD */
149 void *rx_buf; /* Rx buffer base */
150 void *tx_bd_ring; /* Tx BD ring base */
151 void *cur_txbd; /* current Tx BD */
152};
153
154#define RX_BD_RING_SIZE 8
155#define TX_BD_RING_SIZE 8
156#define MAX_RXBUF_LOG2 11
157#define MAX_RXBUF_LEN (1 << MAX_RXBUF_LOG2)
158
Rotariu Marian-Cristian092af032014-05-19 10:59:52 +0300159#define PORT_IS_ENABLED(port) (fm_port_to_index(port) == -1 ? \
160 0 : fm_info[fm_port_to_index(port)].enabled)
Shengzhou Liu0348bf82013-03-25 07:39:29 +0000161
Kumar Gala2683c532011-04-13 08:37:44 -0500162#endif /* __FM_H__ */