blob: 5f197a982958bc09ed4ff8b87b1a44ec23cc4a16 [file] [log] [blame]
Kumar Gala2683c532011-04-13 08:37:44 -05001/*
2 * Copyright 2009-2011 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kumar Gala2683c532011-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 Qiang1ae99192013-09-04 10:11:27 +080024#define MIIM_TIMEOUT 0xFFFF
Kumar Gala2683c532011-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 Gala5536d922011-09-14 12:01:35 -0500101void fman_disable_port(enum fm_port port);
Kumar Gala2683c532011-04-13 08:37:44 -0500102
103struct fsl_enet_mac {
104 void *base; /* MAC controller registers base address */
105 void *phyregs;
106 int max_rx_len;
107 void (*init_mac)(struct fsl_enet_mac *mac);
108 void (*enable_mac)(struct fsl_enet_mac *mac);
109 void (*disable_mac)(struct fsl_enet_mac *mac);
110 void (*set_mac_addr)(struct fsl_enet_mac *mac, u8 *mac_addr);
111 void (*set_if_mode)(struct fsl_enet_mac *mac, phy_interface_t type,
112 int speed);
113};
114
115/* Fman ethernet private struct */
116struct fm_eth {
117 int fm_index; /* Fman index */
118 u32 num; /* 0..n-1 for give type */
119 struct fm_bmi_tx_port *tx_port;
120 struct fm_bmi_rx_port *rx_port;
121 enum fm_eth_type type; /* 1G or 10G ethernet */
122 phy_interface_t enet_if;
123 struct fsl_enet_mac *mac; /* MAC controller */
124 struct mii_dev *bus;
125 struct phy_device *phydev;
126 int phyaddr;
127 struct eth_device *dev;
128 int max_rx_len;
129 struct fm_port_global_pram *rx_pram; /* Rx parameter table */
130 struct fm_port_global_pram *tx_pram; /* Tx parameter table */
131 void *rx_bd_ring; /* Rx BD ring base */
132 void *cur_rxbd; /* current Rx BD */
133 void *rx_buf; /* Rx buffer base */
134 void *tx_bd_ring; /* Tx BD ring base */
135 void *cur_txbd; /* current Tx BD */
136};
137
138#define RX_BD_RING_SIZE 8
139#define TX_BD_RING_SIZE 8
140#define MAX_RXBUF_LOG2 11
141#define MAX_RXBUF_LEN (1 << MAX_RXBUF_LOG2)
142
Shengzhou Liu0348bf82013-03-25 07:39:29 +0000143#define PORT_IS_ENABLED(port) fm_info[fm_port_to_index(port)].enabled
144
Kumar Gala2683c532011-04-13 08:37:44 -0500145#endif /* __FM_H__ */