blob: 3ec49a4f3b0dd7eccfefd52eec63a87c761efd82 [file] [log] [blame]
Kumar Galac916d7c2011-04-13 08:37:44 -05001/*
2 * Copyright 2009-2011 Freescale Semiconductor, Inc.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Galac916d7c2011-04-13 08:37:44 -05005 */
6
7#ifndef __FM_H__
8#define __FM_H__
9
10#include <common.h>
11#include <fm_eth.h>
12#include <asm/fsl_enet.h>
13#include <asm/fsl_fman.h>
14
15/* Port ID */
16#define OH_PORT_ID_BASE 0x01
17#define MAX_NUM_OH_PORT 7
18#define RX_PORT_1G_BASE 0x08
19#define MAX_NUM_RX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
20#define RX_PORT_10G_BASE 0x10
21#define TX_PORT_1G_BASE 0x28
22#define MAX_NUM_TX_PORT_1G CONFIG_SYS_NUM_FM1_DTSEC
23#define TX_PORT_10G_BASE 0x30
Zhao Qiangffee1dd2013-09-04 10:11:27 +080024#define MIIM_TIMEOUT 0xFFFF
Kumar Galac916d7c2011-04-13 08:37:44 -050025
26struct fm_muram {
27 u32 base;
28 u32 top;
29 u32 size;
30 u32 alloc;
31};
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
59/* Rx/Tx queue descriptor */
60struct fm_port_qd {
61 u16 gen;
62 u16 bd_ring_base_hi;
63 u32 bd_ring_base_lo;
64 u16 bd_ring_size;
65 u16 offset_in;
66 u16 offset_out;
67 u16 res0;
68 u32 res1[0x4];
69};
70
71/* IM global parameter RAM */
72struct fm_port_global_pram {
73 u32 mode; /* independent mode register */
74 u32 rxqd_ptr; /* Rx queue descriptor pointer */
75 u32 txqd_ptr; /* Tx queue descriptor pointer */
76 u16 mrblr; /* max Rx buffer length */
77 u16 rxqd_bsy_cnt; /* RxQD busy counter, should be cleared */
78 u32 res0[0x4];
79 struct fm_port_qd rxqd; /* Rx queue descriptor */
80 struct fm_port_qd txqd; /* Tx queue descriptor */
81 u32 res1[0x28];
82};
83
84#define FM_PRAM_SIZE sizeof(struct fm_port_global_pram)
85#define FM_PRAM_ALIGN 256
86#define PRAM_MODE_GLOBAL 0x20000000
87#define PRAM_MODE_GRACEFUL_STOP 0x00800000
88
89#if defined(CONFIG_P1017) || defined(CONFIG_P1023)
90#define FM_FREE_POOL_SIZE 0x2000 /* 8K bytes */
91#else
92#define FM_FREE_POOL_SIZE 0x20000 /* 128K bytes */
93#endif
94#define FM_FREE_POOL_ALIGN 256
95
96u32 fm_muram_alloc(int fm_idx, u32 size, u32 align);
97u32 fm_muram_base(int fm_idx);
98int fm_init_common(int index, struct ccsr_fman *reg);
99int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info);
100phy_interface_t fman_port_enet_if(enum fm_port port);
Kumar Gala69a85242011-09-14 12:01:35 -0500101void fman_disable_port(enum fm_port port);
Valentin Longchampf51d3b72013-10-18 11:47:21 +0200102void fman_enable_port(enum fm_port port);
Kumar Galac916d7c2011-04-13 08:37:44 -0500103
104struct fsl_enet_mac {
105 void *base; /* MAC controller registers base address */
106 void *phyregs;
107 int max_rx_len;
108 void (*init_mac)(struct fsl_enet_mac *mac);
109 void (*enable_mac)(struct fsl_enet_mac *mac);
110 void (*disable_mac)(struct fsl_enet_mac *mac);
111 void (*set_mac_addr)(struct fsl_enet_mac *mac, u8 *mac_addr);
112 void (*set_if_mode)(struct fsl_enet_mac *mac, phy_interface_t type,
113 int speed);
114};
115
116/* Fman ethernet private struct */
117struct fm_eth {
118 int fm_index; /* Fman index */
119 u32 num; /* 0..n-1 for give type */
120 struct fm_bmi_tx_port *tx_port;
121 struct fm_bmi_rx_port *rx_port;
122 enum fm_eth_type type; /* 1G or 10G ethernet */
123 phy_interface_t enet_if;
124 struct fsl_enet_mac *mac; /* MAC controller */
125 struct mii_dev *bus;
126 struct phy_device *phydev;
127 int phyaddr;
128 struct eth_device *dev;
129 int max_rx_len;
130 struct fm_port_global_pram *rx_pram; /* Rx parameter table */
131 struct fm_port_global_pram *tx_pram; /* Tx parameter table */
132 void *rx_bd_ring; /* Rx BD ring base */
133 void *cur_rxbd; /* current Rx BD */
134 void *rx_buf; /* Rx buffer base */
135 void *tx_bd_ring; /* Tx BD ring base */
136 void *cur_txbd; /* current Tx BD */
137};
138
139#define RX_BD_RING_SIZE 8
140#define TX_BD_RING_SIZE 8
141#define MAX_RXBUF_LOG2 11
142#define MAX_RXBUF_LEN (1 << MAX_RXBUF_LOG2)
143
Shengzhou Liuae8a5d12013-03-25 07:39:29 +0000144#define PORT_IS_ENABLED(port) fm_info[fm_port_to_index(port)].enabled
145
Kumar Galac916d7c2011-04-13 08:37:44 -0500146#endif /* __FM_H__ */