Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 2 | /* |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 3 | * Copyright (C) 2006-2011 Freescale Semiconductor, Inc. |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 4 | * |
| 5 | * Dave Liu <daveliu@freescale.com> |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
Masahiro Yamada | adae2ec | 2016-09-21 11:28:53 +0900 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Masahiro Yamada | adae2ec | 2016-09-21 11:28:53 +0900 | [diff] [blame] | 10 | #include <net.h> |
| 11 | #include <malloc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Masahiro Yamada | adae2ec | 2016-09-21 11:28:53 +0900 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <linux/immap_qe.h> |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 16 | #include "uccf.h" |
| 17 | #include "uec.h" |
| 18 | #include "uec_phy.h" |
David Saada | 6b25c13 | 2008-03-31 02:37:38 -0700 | [diff] [blame] | 19 | #include "miiphy.h" |
Qianyu Gong | ae6a758 | 2016-02-18 13:01:59 +0800 | [diff] [blame] | 20 | #include <fsl_qe.h> |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 21 | #include <phy.h> |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 22 | |
Heiko Schocher | 41b64a8 | 2020-02-06 09:48:16 +0100 | [diff] [blame] | 23 | #if !defined(CONFIG_DM_ETH) |
Richard Retanubun | 6b77814 | 2009-07-01 14:03:15 -0400 | [diff] [blame] | 24 | /* Default UTBIPAR SMI address */ |
| 25 | #ifndef CONFIG_UTBIPAR_INIT_TBIPA |
| 26 | #define CONFIG_UTBIPAR_INIT_TBIPA 0x1F |
| 27 | #endif |
| 28 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 29 | static struct uec_inf uec_info[] = { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 30 | #ifdef CONFIG_UEC_ETH1 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 31 | STD_UEC_INFO(1), /* UEC1 */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 32 | #endif |
| 33 | #ifdef CONFIG_UEC_ETH2 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 34 | STD_UEC_INFO(2), /* UEC2 */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 35 | #endif |
Joakim Tjernlund | 4e48320 | 2007-12-06 16:43:40 +0100 | [diff] [blame] | 36 | #ifdef CONFIG_UEC_ETH3 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 37 | STD_UEC_INFO(3), /* UEC3 */ |
Joakim Tjernlund | 4e48320 | 2007-12-06 16:43:40 +0100 | [diff] [blame] | 38 | #endif |
David Saada | f397883 | 2008-01-15 10:40:24 +0200 | [diff] [blame] | 39 | #ifdef CONFIG_UEC_ETH4 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 40 | STD_UEC_INFO(4), /* UEC4 */ |
David Saada | f397883 | 2008-01-15 10:40:24 +0200 | [diff] [blame] | 41 | #endif |
richardretanubun | e5167f1 | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 42 | #ifdef CONFIG_UEC_ETH5 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 43 | STD_UEC_INFO(5), /* UEC5 */ |
richardretanubun | e5167f1 | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 44 | #endif |
| 45 | #ifdef CONFIG_UEC_ETH6 |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 46 | STD_UEC_INFO(6), /* UEC6 */ |
richardretanubun | e5167f1 | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 47 | #endif |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 48 | #ifdef CONFIG_UEC_ETH7 |
| 49 | STD_UEC_INFO(7), /* UEC7 */ |
Haiying Wang | 9a38382 | 2009-05-21 15:34:14 -0400 | [diff] [blame] | 50 | #endif |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 51 | #ifdef CONFIG_UEC_ETH8 |
| 52 | STD_UEC_INFO(8), /* UEC8 */ |
richardretanubun | e5167f1 | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 53 | #endif |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 54 | }; |
Joakim Tjernlund | 4e48320 | 2007-12-06 16:43:40 +0100 | [diff] [blame] | 55 | |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 56 | #define MAXCONTROLLERS (8) |
David Saada | 6b25c13 | 2008-03-31 02:37:38 -0700 | [diff] [blame] | 57 | |
| 58 | static struct eth_device *devlist[MAXCONTROLLERS]; |
| 59 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 60 | static int uec_mac_enable(struct uec_priv *uec, comm_dir_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 61 | { |
| 62 | uec_t *uec_regs; |
| 63 | u32 maccfg1; |
| 64 | |
| 65 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 66 | printf("%s: uec not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 67 | return -EINVAL; |
| 68 | } |
| 69 | uec_regs = uec->uec_regs; |
| 70 | |
| 71 | maccfg1 = in_be32(&uec_regs->maccfg1); |
| 72 | |
| 73 | if (mode & COMM_DIR_TX) { |
| 74 | maccfg1 |= MACCFG1_ENABLE_TX; |
| 75 | out_be32(&uec_regs->maccfg1, maccfg1); |
| 76 | uec->mac_tx_enabled = 1; |
| 77 | } |
| 78 | |
| 79 | if (mode & COMM_DIR_RX) { |
| 80 | maccfg1 |= MACCFG1_ENABLE_RX; |
| 81 | out_be32(&uec_regs->maccfg1, maccfg1); |
| 82 | uec->mac_rx_enabled = 1; |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 88 | static int uec_mac_disable(struct uec_priv *uec, comm_dir_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 89 | { |
| 90 | uec_t *uec_regs; |
| 91 | u32 maccfg1; |
| 92 | |
| 93 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 94 | printf("%s: uec not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 95 | return -EINVAL; |
| 96 | } |
| 97 | uec_regs = uec->uec_regs; |
| 98 | |
| 99 | maccfg1 = in_be32(&uec_regs->maccfg1); |
| 100 | |
| 101 | if (mode & COMM_DIR_TX) { |
| 102 | maccfg1 &= ~MACCFG1_ENABLE_TX; |
| 103 | out_be32(&uec_regs->maccfg1, maccfg1); |
| 104 | uec->mac_tx_enabled = 0; |
| 105 | } |
| 106 | |
| 107 | if (mode & COMM_DIR_RX) { |
| 108 | maccfg1 &= ~MACCFG1_ENABLE_RX; |
| 109 | out_be32(&uec_regs->maccfg1, maccfg1); |
| 110 | uec->mac_rx_enabled = 0; |
| 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 116 | static int uec_graceful_stop_tx(struct uec_priv *uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 117 | { |
| 118 | ucc_fast_t *uf_regs; |
| 119 | u32 cecr_subblock; |
| 120 | u32 ucce; |
| 121 | |
| 122 | if (!uec || !uec->uccf) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 123 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 124 | return -EINVAL; |
| 125 | } |
| 126 | |
| 127 | uf_regs = uec->uccf->uf_regs; |
| 128 | |
| 129 | /* Clear the grace stop event */ |
| 130 | out_be32(&uf_regs->ucce, UCCE_GRA); |
| 131 | |
| 132 | /* Issue host command */ |
| 133 | cecr_subblock = |
| 134 | ucc_fast_get_qe_cr_subblock(uec->uec_info->uf_info.ucc_num); |
| 135 | qe_issue_cmd(QE_GRACEFUL_STOP_TX, cecr_subblock, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 136 | (u8)QE_CR_PROTOCOL_ETHERNET, 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 137 | |
| 138 | /* Wait for command to complete */ |
| 139 | do { |
| 140 | ucce = in_be32(&uf_regs->ucce); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 141 | } while (!(ucce & UCCE_GRA)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 142 | |
| 143 | uec->grace_stopped_tx = 1; |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 148 | static int uec_graceful_stop_rx(struct uec_priv *uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 149 | { |
| 150 | u32 cecr_subblock; |
| 151 | u8 ack; |
| 152 | |
| 153 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 154 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 155 | return -EINVAL; |
| 156 | } |
| 157 | |
| 158 | if (!uec->p_rx_glbl_pram) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 159 | printf("%s: No init rx global parameter\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 160 | return -EINVAL; |
| 161 | } |
| 162 | |
| 163 | /* Clear acknowledge bit */ |
| 164 | ack = uec->p_rx_glbl_pram->rxgstpack; |
| 165 | ack &= ~GRACEFUL_STOP_ACKNOWLEDGE_RX; |
| 166 | uec->p_rx_glbl_pram->rxgstpack = ack; |
| 167 | |
| 168 | /* Keep issuing cmd and checking ack bit until it is asserted */ |
| 169 | do { |
| 170 | /* Issue host command */ |
| 171 | cecr_subblock = |
| 172 | ucc_fast_get_qe_cr_subblock(uec->uec_info->uf_info.ucc_num); |
| 173 | qe_issue_cmd(QE_GRACEFUL_STOP_RX, cecr_subblock, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 174 | (u8)QE_CR_PROTOCOL_ETHERNET, 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 175 | ack = uec->p_rx_glbl_pram->rxgstpack; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 176 | } while (!(ack & GRACEFUL_STOP_ACKNOWLEDGE_RX)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 177 | |
| 178 | uec->grace_stopped_rx = 1; |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 183 | static int uec_restart_tx(struct uec_priv *uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 184 | { |
| 185 | u32 cecr_subblock; |
| 186 | |
| 187 | if (!uec || !uec->uec_info) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 188 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 189 | return -EINVAL; |
| 190 | } |
| 191 | |
| 192 | cecr_subblock = |
| 193 | ucc_fast_get_qe_cr_subblock(uec->uec_info->uf_info.ucc_num); |
| 194 | qe_issue_cmd(QE_RESTART_TX, cecr_subblock, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 195 | (u8)QE_CR_PROTOCOL_ETHERNET, 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 196 | |
| 197 | uec->grace_stopped_tx = 0; |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 202 | static int uec_restart_rx(struct uec_priv *uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 203 | { |
| 204 | u32 cecr_subblock; |
| 205 | |
| 206 | if (!uec || !uec->uec_info) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 207 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 208 | return -EINVAL; |
| 209 | } |
| 210 | |
| 211 | cecr_subblock = |
| 212 | ucc_fast_get_qe_cr_subblock(uec->uec_info->uf_info.ucc_num); |
| 213 | qe_issue_cmd(QE_RESTART_RX, cecr_subblock, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 214 | (u8)QE_CR_PROTOCOL_ETHERNET, 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 215 | |
| 216 | uec->grace_stopped_rx = 0; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 221 | static int uec_open(struct uec_priv *uec, comm_dir_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 222 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 223 | struct ucc_fast_priv *uccf; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 224 | |
| 225 | if (!uec || !uec->uccf) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 226 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 227 | return -EINVAL; |
| 228 | } |
| 229 | uccf = uec->uccf; |
| 230 | |
| 231 | /* check if the UCC number is in range. */ |
| 232 | if (uec->uec_info->uf_info.ucc_num >= UCC_MAX_NUM) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 233 | printf("%s: ucc_num out of range.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 234 | return -EINVAL; |
| 235 | } |
| 236 | |
| 237 | /* Enable MAC */ |
| 238 | uec_mac_enable(uec, mode); |
| 239 | |
| 240 | /* Enable UCC fast */ |
| 241 | ucc_fast_enable(uccf, mode); |
| 242 | |
| 243 | /* RISC microcode start */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 244 | if ((mode & COMM_DIR_TX) && uec->grace_stopped_tx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 245 | uec_restart_tx(uec); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 246 | if ((mode & COMM_DIR_RX) && uec->grace_stopped_rx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 247 | uec_restart_rx(uec); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 252 | static int uec_stop(struct uec_priv *uec, comm_dir_e mode) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 253 | { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 254 | if (!uec || !uec->uccf) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 255 | printf("%s: No handle passed.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 256 | return -EINVAL; |
| 257 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 258 | |
| 259 | /* check if the UCC number is in range. */ |
| 260 | if (uec->uec_info->uf_info.ucc_num >= UCC_MAX_NUM) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 261 | printf("%s: ucc_num out of range.\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 262 | return -EINVAL; |
| 263 | } |
| 264 | /* Stop any transmissions */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 265 | if ((mode & COMM_DIR_TX) && !uec->grace_stopped_tx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 266 | uec_graceful_stop_tx(uec); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 267 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 268 | /* Stop any receptions */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 269 | if ((mode & COMM_DIR_RX) && !uec->grace_stopped_rx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 270 | uec_graceful_stop_rx(uec); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 271 | |
| 272 | /* Disable the UCC fast */ |
| 273 | ucc_fast_disable(uec->uccf, mode); |
| 274 | |
| 275 | /* Disable the MAC */ |
| 276 | uec_mac_disable(uec, mode); |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 281 | static int uec_set_mac_duplex(struct uec_priv *uec, int duplex) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 282 | { |
| 283 | uec_t *uec_regs; |
| 284 | u32 maccfg2; |
| 285 | |
| 286 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 287 | printf("%s: uec not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 288 | return -EINVAL; |
| 289 | } |
| 290 | uec_regs = uec->uec_regs; |
| 291 | |
| 292 | if (duplex == DUPLEX_HALF) { |
| 293 | maccfg2 = in_be32(&uec_regs->maccfg2); |
| 294 | maccfg2 &= ~MACCFG2_FDX; |
| 295 | out_be32(&uec_regs->maccfg2, maccfg2); |
| 296 | } |
| 297 | |
| 298 | if (duplex == DUPLEX_FULL) { |
| 299 | maccfg2 = in_be32(&uec_regs->maccfg2); |
| 300 | maccfg2 |= MACCFG2_FDX; |
| 301 | out_be32(&uec_regs->maccfg2, maccfg2); |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 307 | static int uec_set_mac_if_mode(struct uec_priv *uec, |
| 308 | phy_interface_t if_mode, int speed) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 309 | { |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 310 | phy_interface_t enet_if_mode; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 311 | uec_t *uec_regs; |
| 312 | u32 upsmr; |
| 313 | u32 maccfg2; |
| 314 | |
| 315 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 316 | printf("%s: uec not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | } |
| 319 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 320 | uec_regs = uec->uec_regs; |
| 321 | enet_if_mode = if_mode; |
| 322 | |
| 323 | maccfg2 = in_be32(&uec_regs->maccfg2); |
| 324 | maccfg2 &= ~MACCFG2_INTERFACE_MODE_MASK; |
| 325 | |
| 326 | upsmr = in_be32(&uec->uccf->uf_regs->upsmr); |
| 327 | upsmr &= ~(UPSMR_RPM | UPSMR_TBIM | UPSMR_R10M | UPSMR_RMM); |
| 328 | |
Heiko Schocher | 40b44bc | 2010-01-20 09:04:28 +0100 | [diff] [blame] | 329 | switch (speed) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 330 | case SPEED_10: |
| 331 | maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE; |
| 332 | switch (enet_if_mode) { |
| 333 | case PHY_INTERFACE_MODE_MII: |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 334 | break; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 335 | case PHY_INTERFACE_MODE_RGMII: |
| 336 | upsmr |= (UPSMR_RPM | UPSMR_R10M); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 337 | break; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 338 | case PHY_INTERFACE_MODE_RMII: |
| 339 | upsmr |= (UPSMR_R10M | UPSMR_RMM); |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 340 | break; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 341 | default: |
| 342 | return -EINVAL; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 343 | } |
| 344 | break; |
| 345 | case SPEED_100: |
| 346 | maccfg2 |= MACCFG2_INTERFACE_MODE_NIBBLE; |
| 347 | switch (enet_if_mode) { |
| 348 | case PHY_INTERFACE_MODE_MII: |
| 349 | break; |
| 350 | case PHY_INTERFACE_MODE_RGMII: |
| 351 | upsmr |= UPSMR_RPM; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 352 | break; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 353 | case PHY_INTERFACE_MODE_RMII: |
| 354 | upsmr |= UPSMR_RMM; |
| 355 | break; |
| 356 | default: |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | break; |
| 360 | case SPEED_1000: |
| 361 | maccfg2 |= MACCFG2_INTERFACE_MODE_BYTE; |
| 362 | switch (enet_if_mode) { |
| 363 | case PHY_INTERFACE_MODE_GMII: |
| 364 | break; |
| 365 | case PHY_INTERFACE_MODE_TBI: |
| 366 | upsmr |= UPSMR_TBIM; |
| 367 | break; |
| 368 | case PHY_INTERFACE_MODE_RTBI: |
| 369 | upsmr |= (UPSMR_RPM | UPSMR_TBIM); |
| 370 | break; |
| 371 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 372 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 373 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 374 | case PHY_INTERFACE_MODE_RGMII: |
| 375 | upsmr |= UPSMR_RPM; |
| 376 | break; |
| 377 | case PHY_INTERFACE_MODE_SGMII: |
| 378 | upsmr |= UPSMR_SGMM; |
| 379 | break; |
| 380 | default: |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | break; |
| 384 | default: |
| 385 | return -EINVAL; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 386 | } |
Heiko Schocher | 40b44bc | 2010-01-20 09:04:28 +0100 | [diff] [blame] | 387 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 388 | out_be32(&uec_regs->maccfg2, maccfg2); |
| 389 | out_be32(&uec->uccf->uf_regs->upsmr, upsmr); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 394 | static int init_mii_management_configuration(uec_mii_t *uec_mii_regs) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 395 | { |
| 396 | uint timeout = 0x1000; |
| 397 | u32 miimcfg = 0; |
| 398 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 399 | miimcfg = in_be32(&uec_mii_regs->miimcfg); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 400 | miimcfg |= MIIMCFG_MNGMNT_CLC_DIV_INIT_VALUE; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 401 | out_be32(&uec_mii_regs->miimcfg, miimcfg); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 402 | |
| 403 | /* Wait until the bus is free */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 404 | while ((in_be32(&uec_mii_regs->miimcfg) & MIIMIND_BUSY) && timeout--) |
| 405 | ; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 406 | if (timeout <= 0) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 407 | printf("%s: The MII Bus is stuck!", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 408 | return -ETIMEDOUT; |
| 409 | } |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int init_phy(struct eth_device *dev) |
| 415 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 416 | struct uec_priv *uec; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 417 | uec_mii_t *umii_regs; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 418 | struct uec_mii_info *mii_info; |
| 419 | struct phy_info *curphy; |
| 420 | int err; |
| 421 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 422 | uec = (struct uec_priv *)dev->priv; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 423 | umii_regs = uec->uec_mii_regs; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 424 | |
| 425 | uec->oldlink = 0; |
| 426 | uec->oldspeed = 0; |
| 427 | uec->oldduplex = -1; |
| 428 | |
| 429 | mii_info = malloc(sizeof(*mii_info)); |
| 430 | if (!mii_info) { |
| 431 | printf("%s: Could not allocate mii_info", dev->name); |
| 432 | return -ENOMEM; |
| 433 | } |
| 434 | memset(mii_info, 0, sizeof(*mii_info)); |
| 435 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 436 | if (uec->uec_info->uf_info.eth_type == GIGA_ETH) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 437 | mii_info->speed = SPEED_1000; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 438 | else |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 439 | mii_info->speed = SPEED_100; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 440 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 441 | mii_info->duplex = DUPLEX_FULL; |
| 442 | mii_info->pause = 0; |
| 443 | mii_info->link = 1; |
| 444 | |
| 445 | mii_info->advertising = (ADVERTISED_10baseT_Half | |
| 446 | ADVERTISED_10baseT_Full | |
| 447 | ADVERTISED_100baseT_Half | |
| 448 | ADVERTISED_100baseT_Full | |
| 449 | ADVERTISED_1000baseT_Full); |
| 450 | mii_info->autoneg = 1; |
| 451 | mii_info->mii_id = uec->uec_info->phy_address; |
| 452 | mii_info->dev = dev; |
| 453 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 454 | mii_info->mdio_read = &uec_read_phy_reg; |
| 455 | mii_info->mdio_write = &uec_write_phy_reg; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 456 | |
| 457 | uec->mii_info = mii_info; |
| 458 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 459 | qe_set_mii_clk_src(uec->uec_info->uf_info.ucc_num); |
| 460 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 461 | if (init_mii_management_configuration(umii_regs)) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 462 | printf("%s: The MII Bus is stuck!", dev->name); |
| 463 | err = -1; |
| 464 | goto bus_fail; |
| 465 | } |
| 466 | |
| 467 | /* get info for this PHY */ |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 468 | curphy = uec_get_phy_info(uec->mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 469 | if (!curphy) { |
| 470 | printf("%s: No PHY found", dev->name); |
| 471 | err = -1; |
| 472 | goto no_phy; |
| 473 | } |
| 474 | |
| 475 | mii_info->phyinfo = curphy; |
| 476 | |
| 477 | /* Run the commands which initialize the PHY */ |
| 478 | if (curphy->init) { |
| 479 | err = curphy->init(uec->mii_info); |
| 480 | if (err) |
| 481 | goto phy_init_fail; |
| 482 | } |
| 483 | |
| 484 | return 0; |
| 485 | |
| 486 | phy_init_fail: |
| 487 | no_phy: |
| 488 | bus_fail: |
| 489 | free(mii_info); |
| 490 | return err; |
| 491 | } |
| 492 | |
| 493 | static void adjust_link(struct eth_device *dev) |
| 494 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 495 | struct uec_priv *uec = (struct uec_priv *)dev->priv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 496 | struct uec_mii_info *mii_info = uec->mii_info; |
| 497 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 498 | if (mii_info->link) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 499 | /* |
| 500 | * Now we make sure that we can be in full duplex mode. |
| 501 | * If not, we operate in half-duplex mode. |
| 502 | */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 503 | if (mii_info->duplex != uec->oldduplex) { |
| 504 | if (!(mii_info->duplex)) { |
| 505 | uec_set_mac_duplex(uec, DUPLEX_HALF); |
| 506 | printf("%s: Half Duplex\n", dev->name); |
| 507 | } else { |
| 508 | uec_set_mac_duplex(uec, DUPLEX_FULL); |
| 509 | printf("%s: Full Duplex\n", dev->name); |
| 510 | } |
| 511 | uec->oldduplex = mii_info->duplex; |
| 512 | } |
| 513 | |
| 514 | if (mii_info->speed != uec->oldspeed) { |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 515 | phy_interface_t mode = |
Heiko Schocher | 40b44bc | 2010-01-20 09:04:28 +0100 | [diff] [blame] | 516 | uec->uec_info->enet_interface_type; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 517 | if (uec->uec_info->uf_info.eth_type == GIGA_ETH) { |
| 518 | switch (mii_info->speed) { |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 519 | case SPEED_1000: |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 520 | break; |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 521 | case SPEED_100: |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 522 | printf("switching to rgmii 100\n"); |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 523 | mode = PHY_INTERFACE_MODE_RGMII; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 524 | break; |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 525 | case SPEED_10: |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 526 | printf("switching to rgmii 10\n"); |
Andy Fleming | 7832a46 | 2011-04-13 00:37:12 -0500 | [diff] [blame] | 527 | mode = PHY_INTERFACE_MODE_RGMII; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 528 | break; |
| 529 | default: |
| 530 | printf("%s: Ack,Speed(%d)is illegal\n", |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 531 | dev->name, mii_info->speed); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 532 | break; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 533 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 534 | } |
| 535 | |
Heiko Schocher | 40b44bc | 2010-01-20 09:04:28 +0100 | [diff] [blame] | 536 | /* change phy */ |
| 537 | change_phy_interface_mode(dev, mode, mii_info->speed); |
| 538 | /* change the MAC interface mode */ |
| 539 | uec_set_mac_if_mode(uec, mode, mii_info->speed); |
| 540 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 541 | printf("%s: Speed %dBT\n", dev->name, mii_info->speed); |
| 542 | uec->oldspeed = mii_info->speed; |
| 543 | } |
| 544 | |
| 545 | if (!uec->oldlink) { |
| 546 | printf("%s: Link is up\n", dev->name); |
| 547 | uec->oldlink = 1; |
| 548 | } |
| 549 | |
| 550 | } else { /* if (mii_info->link) */ |
| 551 | if (uec->oldlink) { |
| 552 | printf("%s: Link is down\n", dev->name); |
| 553 | uec->oldlink = 0; |
| 554 | uec->oldspeed = 0; |
| 555 | uec->oldduplex = -1; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | static void phy_change(struct eth_device *dev) |
| 561 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 562 | struct uec_priv *uec = (struct uec_priv *)dev->priv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 563 | |
York Sun | 0f57797 | 2016-11-18 11:05:38 -0800 | [diff] [blame] | 564 | #if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025) |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 565 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 566 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 567 | /* QE9 and QE12 need to be set for enabling QE MII management signals */ |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 568 | setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE9); |
| 569 | setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE12); |
| 570 | #endif |
| 571 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 572 | /* Update the link, speed, duplex */ |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 573 | uec->mii_info->phyinfo->read_status(uec->mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 574 | |
York Sun | 0f57797 | 2016-11-18 11:05:38 -0800 | [diff] [blame] | 575 | #if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025) |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 576 | /* |
| 577 | * QE12 is muxed with LBCTL, it needs to be released for enabling |
| 578 | * LBCTL signal for LBC usage. |
| 579 | */ |
| 580 | clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE12); |
| 581 | #endif |
| 582 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 583 | /* Adjust the interface according to speed */ |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 584 | adjust_link(dev); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 585 | } |
| 586 | |
Richard Retanubun | 15e467c | 2009-06-17 16:00:41 -0400 | [diff] [blame] | 587 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 588 | |
| 589 | /* |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 590 | * Find a device index from the devlist by name |
| 591 | * |
| 592 | * Returns: |
| 593 | * The index where the device is located, -1 on error |
| 594 | */ |
Mike Frysinger | 5ff5fdb | 2010-07-27 18:35:08 -0400 | [diff] [blame] | 595 | static int uec_miiphy_find_dev_by_name(const char *devname) |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 596 | { |
| 597 | int i; |
| 598 | |
| 599 | for (i = 0; i < MAXCONTROLLERS; i++) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 600 | if (strncmp(devname, devlist[i]->name, strlen(devname)) == 0) |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 601 | break; |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* If device cannot be found, returns -1 */ |
| 605 | if (i == MAXCONTROLLERS) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 606 | debug("%s: device %s not found in devlist\n", __func__, |
| 607 | devname); |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 608 | i = -1; |
| 609 | } |
| 610 | |
| 611 | return i; |
| 612 | } |
| 613 | |
| 614 | /* |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 615 | * Read a MII PHY register. |
| 616 | * |
| 617 | * Returns: |
| 618 | * 0 on success |
| 619 | */ |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 620 | static int uec_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg) |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 621 | { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 622 | unsigned short value = 0; |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 623 | int devindex = 0; |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 624 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 625 | if (!bus->name) { |
| 626 | debug("%s: NULL pointer given\n", __func__); |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 627 | } else { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 628 | devindex = uec_miiphy_find_dev_by_name(bus->name); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 629 | if (devindex >= 0) |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 630 | value = uec_read_phy_reg(devlist[devindex], addr, reg); |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 631 | } |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 632 | return value; |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Write a MII PHY register. |
| 637 | * |
| 638 | * Returns: |
| 639 | * 0 on success |
| 640 | */ |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 641 | static int uec_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg, |
| 642 | u16 value) |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 643 | { |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 644 | int devindex = 0; |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 645 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 646 | if (!bus->name) { |
| 647 | debug("%s: NULL pointer given\n", __func__); |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 648 | } else { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 649 | devindex = uec_miiphy_find_dev_by_name(bus->name); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 650 | if (devindex >= 0) |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 651 | uec_write_phy_reg(devlist[devindex], addr, reg, value); |
richardretanubun | e2fd320 | 2008-09-26 08:59:12 -0400 | [diff] [blame] | 652 | } |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 653 | return 0; |
| 654 | } |
Ben Warren | 849c722 | 2008-08-07 23:26:35 -0700 | [diff] [blame] | 655 | #endif |
| 656 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 657 | static int uec_set_mac_address(struct uec_priv *uec, u8 *mac_addr) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 658 | { |
| 659 | uec_t *uec_regs; |
| 660 | u32 mac_addr1; |
| 661 | u32 mac_addr2; |
| 662 | |
| 663 | if (!uec) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 664 | printf("%s: uec not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 665 | return -EINVAL; |
| 666 | } |
| 667 | |
| 668 | uec_regs = uec->uec_regs; |
| 669 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 670 | /* |
| 671 | * if a station address of 0x12345678ABCD, perform a write to |
| 672 | * MACSTNADDR1 of 0xCDAB7856, |
| 673 | * MACSTNADDR2 of 0x34120000 |
| 674 | */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 675 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 676 | mac_addr1 = (mac_addr[5] << 24) | (mac_addr[4] << 16) | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 677 | (mac_addr[3] << 8) | (mac_addr[2]); |
| 678 | out_be32(&uec_regs->macstnaddr1, mac_addr1); |
| 679 | |
| 680 | mac_addr2 = ((mac_addr[1] << 24) | (mac_addr[0] << 16)) & 0xffff0000; |
| 681 | out_be32(&uec_regs->macstnaddr2, mac_addr2); |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 686 | static int uec_convert_threads_num(enum uec_num_of_threads threads_num, |
| 687 | int *threads_num_ret) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 688 | { |
| 689 | int num_threads_numerica; |
| 690 | |
| 691 | switch (threads_num) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 692 | case UEC_NUM_OF_THREADS_1: |
| 693 | num_threads_numerica = 1; |
| 694 | break; |
| 695 | case UEC_NUM_OF_THREADS_2: |
| 696 | num_threads_numerica = 2; |
| 697 | break; |
| 698 | case UEC_NUM_OF_THREADS_4: |
| 699 | num_threads_numerica = 4; |
| 700 | break; |
| 701 | case UEC_NUM_OF_THREADS_6: |
| 702 | num_threads_numerica = 6; |
| 703 | break; |
| 704 | case UEC_NUM_OF_THREADS_8: |
| 705 | num_threads_numerica = 8; |
| 706 | break; |
| 707 | default: |
| 708 | printf("%s: Bad number of threads value.", |
| 709 | __func__); |
| 710 | return -EINVAL; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | *threads_num_ret = num_threads_numerica; |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 718 | static void uec_init_tx_parameter(struct uec_priv *uec, int num_threads_tx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 719 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 720 | struct uec_inf *uec_info; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 721 | u32 end_bd; |
| 722 | u8 bmrx = 0; |
| 723 | int i; |
| 724 | |
| 725 | uec_info = uec->uec_info; |
| 726 | |
| 727 | /* Alloc global Tx parameter RAM page */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 728 | uec->tx_glbl_pram_offset = |
| 729 | qe_muram_alloc(sizeof(struct uec_tx_global_pram), |
| 730 | UEC_TX_GLOBAL_PRAM_ALIGNMENT); |
| 731 | uec->p_tx_glbl_pram = (struct uec_tx_global_pram *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 732 | qe_muram_addr(uec->tx_glbl_pram_offset); |
| 733 | |
| 734 | /* Zero the global Tx prameter RAM */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 735 | memset(uec->p_tx_glbl_pram, 0, sizeof(struct uec_tx_global_pram)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 736 | |
| 737 | /* Init global Tx parameter RAM */ |
| 738 | |
| 739 | /* TEMODER, RMON statistics disable, one Tx queue */ |
| 740 | out_be16(&uec->p_tx_glbl_pram->temoder, TEMODER_INIT_VALUE); |
| 741 | |
| 742 | /* SQPTR */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 743 | uec->send_q_mem_reg_offset = |
| 744 | qe_muram_alloc(sizeof(struct uec_send_queue_qd), |
| 745 | UEC_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT); |
| 746 | uec->p_send_q_mem_reg = (struct uec_send_queue_mem_region *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 747 | qe_muram_addr(uec->send_q_mem_reg_offset); |
| 748 | out_be32(&uec->p_tx_glbl_pram->sqptr, uec->send_q_mem_reg_offset); |
| 749 | |
| 750 | /* Setup the table with TxBDs ring */ |
| 751 | end_bd = (u32)uec->p_tx_bd_ring + (uec_info->tx_bd_ring_len - 1) |
| 752 | * SIZEOFBD; |
| 753 | out_be32(&uec->p_send_q_mem_reg->sqqd[0].bd_ring_base, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 754 | (u32)(uec->p_tx_bd_ring)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 755 | out_be32(&uec->p_send_q_mem_reg->sqqd[0].last_bd_completed_address, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 756 | end_bd); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 757 | |
| 758 | /* Scheduler Base Pointer, we have only one Tx queue, no need it */ |
| 759 | out_be32(&uec->p_tx_glbl_pram->schedulerbasepointer, 0); |
| 760 | |
| 761 | /* TxRMON Base Pointer, TxRMON disable, we don't need it */ |
| 762 | out_be32(&uec->p_tx_glbl_pram->txrmonbaseptr, 0); |
| 763 | |
| 764 | /* TSTATE, global snooping, big endian, the CSB bus selected */ |
| 765 | bmrx = BMR_INIT_VALUE; |
| 766 | out_be32(&uec->p_tx_glbl_pram->tstate, ((u32)(bmrx) << BMR_SHIFT)); |
| 767 | |
| 768 | /* IPH_Offset */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 769 | for (i = 0; i < MAX_IPH_OFFSET_ENTRY; i++) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 770 | out_8(&uec->p_tx_glbl_pram->iphoffset[i], 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 771 | |
| 772 | /* VTAG table */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 773 | for (i = 0; i < UEC_TX_VTAG_TABLE_ENTRY_MAX; i++) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 774 | out_be32(&uec->p_tx_glbl_pram->vtagtable[i], 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 775 | |
| 776 | /* TQPTR */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 777 | uec->thread_dat_tx_offset = |
| 778 | qe_muram_alloc(num_threads_tx * |
| 779 | sizeof(struct uec_thread_data_tx) + |
| 780 | 32 * (num_threads_tx == 1), |
| 781 | UEC_THREAD_DATA_ALIGNMENT); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 782 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 783 | uec->p_thread_data_tx = (struct uec_thread_data_tx *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 784 | qe_muram_addr(uec->thread_dat_tx_offset); |
| 785 | out_be32(&uec->p_tx_glbl_pram->tqptr, uec->thread_dat_tx_offset); |
| 786 | } |
| 787 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 788 | static void uec_init_rx_parameter(struct uec_priv *uec, int num_threads_rx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 789 | { |
| 790 | u8 bmrx = 0; |
| 791 | int i; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 792 | struct uec_82xx_add_filtering_pram *p_af_pram; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 793 | |
| 794 | /* Allocate global Rx parameter RAM page */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 795 | uec->rx_glbl_pram_offset = |
| 796 | qe_muram_alloc(sizeof(struct uec_rx_global_pram), |
| 797 | UEC_RX_GLOBAL_PRAM_ALIGNMENT); |
| 798 | uec->p_rx_glbl_pram = (struct uec_rx_global_pram *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 799 | qe_muram_addr(uec->rx_glbl_pram_offset); |
| 800 | |
| 801 | /* Zero Global Rx parameter RAM */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 802 | memset(uec->p_rx_glbl_pram, 0, sizeof(struct uec_rx_global_pram)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 803 | |
| 804 | /* Init global Rx parameter RAM */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 805 | /* |
| 806 | * REMODER, Extended feature mode disable, VLAN disable, |
| 807 | * LossLess flow control disable, Receive firmware statisic disable, |
| 808 | * Extended address parsing mode disable, One Rx queues, |
| 809 | * Dynamic maximum/minimum frame length disable, IP checksum check |
| 810 | * disable, IP address alignment disable |
| 811 | */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 812 | out_be32(&uec->p_rx_glbl_pram->remoder, REMODER_INIT_VALUE); |
| 813 | |
| 814 | /* RQPTR */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 815 | uec->thread_dat_rx_offset = |
| 816 | qe_muram_alloc(num_threads_rx * |
| 817 | sizeof(struct uec_thread_data_rx), |
| 818 | UEC_THREAD_DATA_ALIGNMENT); |
| 819 | uec->p_thread_data_rx = (struct uec_thread_data_rx *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 820 | qe_muram_addr(uec->thread_dat_rx_offset); |
| 821 | out_be32(&uec->p_rx_glbl_pram->rqptr, uec->thread_dat_rx_offset); |
| 822 | |
| 823 | /* Type_or_Len */ |
| 824 | out_be16(&uec->p_rx_glbl_pram->typeorlen, 3072); |
| 825 | |
| 826 | /* RxRMON base pointer, we don't need it */ |
| 827 | out_be32(&uec->p_rx_glbl_pram->rxrmonbaseptr, 0); |
| 828 | |
| 829 | /* IntCoalescingPTR, we don't need it, no interrupt */ |
| 830 | out_be32(&uec->p_rx_glbl_pram->intcoalescingptr, 0); |
| 831 | |
| 832 | /* RSTATE, global snooping, big endian, the CSB bus selected */ |
| 833 | bmrx = BMR_INIT_VALUE; |
| 834 | out_8(&uec->p_rx_glbl_pram->rstate, bmrx); |
| 835 | |
| 836 | /* MRBLR */ |
| 837 | out_be16(&uec->p_rx_glbl_pram->mrblr, MAX_RXBUF_LEN); |
| 838 | |
| 839 | /* RBDQPTR */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 840 | uec->rx_bd_qs_tbl_offset = |
| 841 | qe_muram_alloc(sizeof(struct uec_rx_bd_queues_entry) + |
| 842 | sizeof(struct uec_rx_pref_bds), |
| 843 | UEC_RX_BD_QUEUES_ALIGNMENT); |
| 844 | uec->p_rx_bd_qs_tbl = (struct uec_rx_bd_queues_entry *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 845 | qe_muram_addr(uec->rx_bd_qs_tbl_offset); |
| 846 | |
| 847 | /* Zero it */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 848 | memset(uec->p_rx_bd_qs_tbl, 0, sizeof(struct uec_rx_bd_queues_entry) + |
| 849 | sizeof(struct uec_rx_pref_bds)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 850 | out_be32(&uec->p_rx_glbl_pram->rbdqptr, uec->rx_bd_qs_tbl_offset); |
| 851 | out_be32(&uec->p_rx_bd_qs_tbl->externalbdbaseptr, |
| 852 | (u32)uec->p_rx_bd_ring); |
| 853 | |
| 854 | /* MFLR */ |
| 855 | out_be16(&uec->p_rx_glbl_pram->mflr, MAX_FRAME_LEN); |
| 856 | /* MINFLR */ |
| 857 | out_be16(&uec->p_rx_glbl_pram->minflr, MIN_FRAME_LEN); |
| 858 | /* MAXD1 */ |
| 859 | out_be16(&uec->p_rx_glbl_pram->maxd1, MAX_DMA1_LEN); |
| 860 | /* MAXD2 */ |
| 861 | out_be16(&uec->p_rx_glbl_pram->maxd2, MAX_DMA2_LEN); |
| 862 | /* ECAM_PTR */ |
| 863 | out_be32(&uec->p_rx_glbl_pram->ecamptr, 0); |
| 864 | /* L2QT */ |
| 865 | out_be32(&uec->p_rx_glbl_pram->l2qt, 0); |
| 866 | /* L3QT */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 867 | for (i = 0; i < 8; i++) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 868 | out_be32(&uec->p_rx_glbl_pram->l3qt[i], 0); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 869 | |
| 870 | /* VLAN_TYPE */ |
| 871 | out_be16(&uec->p_rx_glbl_pram->vlantype, 0x8100); |
| 872 | /* TCI */ |
| 873 | out_be16(&uec->p_rx_glbl_pram->vlantci, 0); |
| 874 | |
| 875 | /* Clear PQ2 style address filtering hash table */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 876 | p_af_pram = (struct uec_82xx_add_filtering_pram *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 877 | uec->p_rx_glbl_pram->addressfiltering; |
| 878 | |
| 879 | p_af_pram->iaddr_h = 0; |
| 880 | p_af_pram->iaddr_l = 0; |
| 881 | p_af_pram->gaddr_h = 0; |
| 882 | p_af_pram->gaddr_l = 0; |
| 883 | } |
| 884 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 885 | static int uec_issue_init_enet_rxtx_cmd(struct uec_priv *uec, |
| 886 | int thread_tx, int thread_rx) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 887 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 888 | struct uec_init_cmd_pram *p_init_enet_param; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 889 | u32 init_enet_param_offset; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 890 | struct uec_inf *uec_info; |
| 891 | struct ucc_fast_inf *uf_info; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 892 | int i; |
| 893 | int snum; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 894 | u32 off; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 895 | u32 entry_val; |
| 896 | u32 command; |
| 897 | u32 cecr_subblock; |
| 898 | |
| 899 | uec_info = uec->uec_info; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 900 | uf_info = &uec_info->uf_info; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 901 | |
| 902 | /* Allocate init enet command parameter */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 903 | uec->init_enet_param_offset = |
| 904 | qe_muram_alloc(sizeof(struct uec_init_cmd_pram), 4); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 905 | init_enet_param_offset = uec->init_enet_param_offset; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 906 | uec->p_init_enet_param = (struct uec_init_cmd_pram *) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 907 | qe_muram_addr(uec->init_enet_param_offset); |
| 908 | |
| 909 | /* Zero init enet command struct */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 910 | memset((void *)uec->p_init_enet_param, 0, |
| 911 | sizeof(struct uec_init_cmd_pram)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 912 | |
| 913 | /* Init the command struct */ |
| 914 | p_init_enet_param = uec->p_init_enet_param; |
| 915 | p_init_enet_param->resinit0 = ENET_INIT_PARAM_MAGIC_RES_INIT0; |
| 916 | p_init_enet_param->resinit1 = ENET_INIT_PARAM_MAGIC_RES_INIT1; |
| 917 | p_init_enet_param->resinit2 = ENET_INIT_PARAM_MAGIC_RES_INIT2; |
| 918 | p_init_enet_param->resinit3 = ENET_INIT_PARAM_MAGIC_RES_INIT3; |
| 919 | p_init_enet_param->resinit4 = ENET_INIT_PARAM_MAGIC_RES_INIT4; |
| 920 | p_init_enet_param->largestexternallookupkeysize = 0; |
| 921 | |
| 922 | p_init_enet_param->rgftgfrxglobal |= ((u32)uec_info->num_threads_rx) |
| 923 | << ENET_INIT_PARAM_RGF_SHIFT; |
| 924 | p_init_enet_param->rgftgfrxglobal |= ((u32)uec_info->num_threads_tx) |
| 925 | << ENET_INIT_PARAM_TGF_SHIFT; |
| 926 | |
| 927 | /* Init Rx global parameter pointer */ |
| 928 | p_init_enet_param->rgftgfrxglobal |= uec->rx_glbl_pram_offset | |
Haiying Wang | 9f9d6b7 | 2009-05-21 15:32:13 -0400 | [diff] [blame] | 929 | (u32)uec_info->risc_rx; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 930 | |
| 931 | /* Init Rx threads */ |
| 932 | for (i = 0; i < (thread_rx + 1); i++) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 933 | snum = qe_get_snum(); |
| 934 | if (snum < 0) { |
| 935 | printf("%s can not get snum\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 936 | return -ENOMEM; |
| 937 | } |
| 938 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 939 | if (i == 0) { |
| 940 | off = 0; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 941 | } else { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 942 | off = qe_muram_alloc(sizeof(struct uec_thread_rx_pram), |
| 943 | UEC_THREAD_RX_PRAM_ALIGNMENT); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | entry_val = ((u32)snum << ENET_INIT_PARAM_SNUM_SHIFT) | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 947 | off | (u32)uec_info->risc_rx; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 948 | p_init_enet_param->rxthread[i] = entry_val; |
| 949 | } |
| 950 | |
| 951 | /* Init Tx global parameter pointer */ |
| 952 | p_init_enet_param->txglobal = uec->tx_glbl_pram_offset | |
Haiying Wang | 9f9d6b7 | 2009-05-21 15:32:13 -0400 | [diff] [blame] | 953 | (u32)uec_info->risc_tx; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 954 | |
| 955 | /* Init Tx threads */ |
| 956 | for (i = 0; i < thread_tx; i++) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 957 | snum = qe_get_snum(); |
| 958 | if (snum < 0) { |
| 959 | printf("%s can not get snum\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 960 | return -ENOMEM; |
| 961 | } |
| 962 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 963 | off = qe_muram_alloc(sizeof(struct uec_thread_tx_pram), |
| 964 | UEC_THREAD_TX_PRAM_ALIGNMENT); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 965 | |
| 966 | entry_val = ((u32)snum << ENET_INIT_PARAM_SNUM_SHIFT) | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 967 | off | (u32)uec_info->risc_tx; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 968 | p_init_enet_param->txthread[i] = entry_val; |
| 969 | } |
| 970 | |
| 971 | __asm__ __volatile__("sync"); |
| 972 | |
| 973 | /* Issue QE command */ |
| 974 | command = QE_INIT_TX_RX; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 975 | cecr_subblock = ucc_fast_get_qe_cr_subblock(uf_info->ucc_num); |
| 976 | qe_issue_cmd(command, cecr_subblock, (u8)QE_CR_PROTOCOL_ETHERNET, |
| 977 | init_enet_param_offset); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 978 | |
| 979 | return 0; |
| 980 | } |
| 981 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 982 | static int uec_startup(struct uec_priv *uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 983 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 984 | struct uec_inf *uec_info; |
| 985 | struct ucc_fast_inf *uf_info; |
| 986 | struct ucc_fast_priv *uccf; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 987 | ucc_fast_t *uf_regs; |
| 988 | uec_t *uec_regs; |
| 989 | int num_threads_tx; |
| 990 | int num_threads_rx; |
| 991 | u32 utbipar; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 992 | u32 length; |
| 993 | u32 align; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 994 | struct buffer_descriptor *bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 995 | u8 *buf; |
| 996 | int i; |
| 997 | |
| 998 | if (!uec || !uec->uec_info) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 999 | printf("%s: uec or uec_info not initial\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | |
| 1003 | uec_info = uec->uec_info; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1004 | uf_info = &uec_info->uf_info; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1005 | |
| 1006 | /* Check if Rx BD ring len is illegal */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1007 | if (uec_info->rx_bd_ring_len < UEC_RX_BD_RING_SIZE_MIN || |
| 1008 | (uec_info->rx_bd_ring_len % UEC_RX_BD_RING_SIZE_ALIGNMENT)) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1009 | printf("%s: Rx BD ring len must be multiple of 4, and > 8.\n", |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1010 | __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1011 | return -EINVAL; |
| 1012 | } |
| 1013 | |
| 1014 | /* Check if Tx BD ring len is illegal */ |
| 1015 | if (uec_info->tx_bd_ring_len < UEC_TX_BD_RING_SIZE_MIN) { |
| 1016 | printf("%s: Tx BD ring length must not be smaller than 2.\n", |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1017 | __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1018 | return -EINVAL; |
| 1019 | } |
| 1020 | |
| 1021 | /* Check if MRBLR is illegal */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1022 | if (MAX_RXBUF_LEN == 0 || MAX_RXBUF_LEN % UEC_MRBLR_ALIGNMENT) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1023 | printf("%s: max rx buffer length must be mutliple of 128.\n", |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1024 | __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | |
| 1028 | /* Both Rx and Tx are stopped */ |
| 1029 | uec->grace_stopped_rx = 1; |
| 1030 | uec->grace_stopped_tx = 1; |
| 1031 | |
| 1032 | /* Init UCC fast */ |
| 1033 | if (ucc_fast_init(uf_info, &uccf)) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1034 | printf("%s: failed to init ucc fast\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1035 | return -ENOMEM; |
| 1036 | } |
| 1037 | |
| 1038 | /* Save uccf */ |
| 1039 | uec->uccf = uccf; |
| 1040 | |
| 1041 | /* Convert the Tx threads number */ |
| 1042 | if (uec_convert_threads_num(uec_info->num_threads_tx, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1043 | &num_threads_tx)) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1044 | return -EINVAL; |
| 1045 | } |
| 1046 | |
| 1047 | /* Convert the Rx threads number */ |
| 1048 | if (uec_convert_threads_num(uec_info->num_threads_rx, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1049 | &num_threads_rx)) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1050 | return -EINVAL; |
| 1051 | } |
| 1052 | |
| 1053 | uf_regs = uccf->uf_regs; |
| 1054 | |
| 1055 | /* UEC register is following UCC fast registers */ |
| 1056 | uec_regs = (uec_t *)(&uf_regs->ucc_eth); |
| 1057 | |
| 1058 | /* Save the UEC register pointer to UEC private struct */ |
| 1059 | uec->uec_regs = uec_regs; |
| 1060 | |
| 1061 | /* Init UPSMR, enable hardware statistics (UCC) */ |
| 1062 | out_be32(&uec->uccf->uf_regs->upsmr, UPSMR_INIT_VALUE); |
| 1063 | |
| 1064 | /* Init MACCFG1, flow control disable, disable Tx and Rx */ |
| 1065 | out_be32(&uec_regs->maccfg1, MACCFG1_INIT_VALUE); |
| 1066 | |
| 1067 | /* Init MACCFG2, length check, MAC PAD and CRC enable */ |
| 1068 | out_be32(&uec_regs->maccfg2, MACCFG2_INIT_VALUE); |
| 1069 | |
| 1070 | /* Setup MAC interface mode */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1071 | uec_set_mac_if_mode(uec, uec_info->enet_interface_type, |
| 1072 | uec_info->speed); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1073 | |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 1074 | /* Setup MII management base */ |
| 1075 | #ifndef CONFIG_eTSEC_MDIO_BUS |
| 1076 | uec->uec_mii_regs = (uec_mii_t *)(&uec_regs->miimcfg); |
| 1077 | #else |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1078 | uec->uec_mii_regs = (uec_mii_t *)CONFIG_MIIM_ADDRESS; |
Andy Fleming | ee0e917 | 2007-08-14 00:14:25 -0500 | [diff] [blame] | 1079 | #endif |
| 1080 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1081 | /* Setup MII master clock source */ |
| 1082 | qe_set_mii_clk_src(uec_info->uf_info.ucc_num); |
| 1083 | |
| 1084 | /* Setup UTBIPAR */ |
| 1085 | utbipar = in_be32(&uec_regs->utbipar); |
| 1086 | utbipar &= ~UTBIPAR_PHY_ADDRESS_MASK; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1087 | |
Richard Retanubun | 6b77814 | 2009-07-01 14:03:15 -0400 | [diff] [blame] | 1088 | /* Initialize UTBIPAR address to CONFIG_UTBIPAR_INIT_TBIPA for ALL UEC. |
| 1089 | * This frees up the remaining SMI addresses for use. |
| 1090 | */ |
| 1091 | utbipar |= CONFIG_UTBIPAR_INIT_TBIPA << UTBIPAR_PHY_ADDRESS_SHIFT; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1092 | out_be32(&uec_regs->utbipar, utbipar); |
| 1093 | |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1094 | /* Configure the TBI for SGMII operation */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1095 | if (uec->uec_info->enet_interface_type == PHY_INTERFACE_MODE_SGMII && |
| 1096 | uec->uec_info->speed == SPEED_1000) { |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1097 | uec_write_phy_reg(uec->dev, uec_regs->utbipar, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1098 | ENET_TBI_MII_ANA, TBIANA_SETTINGS); |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1099 | |
| 1100 | uec_write_phy_reg(uec->dev, uec_regs->utbipar, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1101 | ENET_TBI_MII_TBICON, TBICON_CLK_SELECT); |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1102 | |
| 1103 | uec_write_phy_reg(uec->dev, uec_regs->utbipar, |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1104 | ENET_TBI_MII_CR, TBICR_SETTINGS); |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1107 | /* Allocate Tx BDs */ |
| 1108 | length = ((uec_info->tx_bd_ring_len * SIZEOFBD) / |
| 1109 | UEC_TX_BD_RING_SIZE_MEMORY_ALIGNMENT) * |
| 1110 | UEC_TX_BD_RING_SIZE_MEMORY_ALIGNMENT; |
| 1111 | if ((uec_info->tx_bd_ring_len * SIZEOFBD) % |
| 1112 | UEC_TX_BD_RING_SIZE_MEMORY_ALIGNMENT) { |
| 1113 | length += UEC_TX_BD_RING_SIZE_MEMORY_ALIGNMENT; |
| 1114 | } |
| 1115 | |
| 1116 | align = UEC_TX_BD_RING_ALIGNMENT; |
| 1117 | uec->tx_bd_ring_offset = (u32)malloc((u32)(length + align)); |
| 1118 | if (uec->tx_bd_ring_offset != 0) { |
| 1119 | uec->p_tx_bd_ring = (u8 *)((uec->tx_bd_ring_offset + align) |
| 1120 | & ~(align - 1)); |
| 1121 | } |
| 1122 | |
| 1123 | /* Zero all of Tx BDs */ |
| 1124 | memset((void *)(uec->tx_bd_ring_offset), 0, length + align); |
| 1125 | |
| 1126 | /* Allocate Rx BDs */ |
| 1127 | length = uec_info->rx_bd_ring_len * SIZEOFBD; |
| 1128 | align = UEC_RX_BD_RING_ALIGNMENT; |
| 1129 | uec->rx_bd_ring_offset = (u32)(malloc((u32)(length + align))); |
| 1130 | if (uec->rx_bd_ring_offset != 0) { |
| 1131 | uec->p_rx_bd_ring = (u8 *)((uec->rx_bd_ring_offset + align) |
| 1132 | & ~(align - 1)); |
| 1133 | } |
| 1134 | |
| 1135 | /* Zero all of Rx BDs */ |
| 1136 | memset((void *)(uec->rx_bd_ring_offset), 0, length + align); |
| 1137 | |
| 1138 | /* Allocate Rx buffer */ |
| 1139 | length = uec_info->rx_bd_ring_len * MAX_RXBUF_LEN; |
| 1140 | align = UEC_RX_DATA_BUF_ALIGNMENT; |
| 1141 | uec->rx_buf_offset = (u32)malloc(length + align); |
| 1142 | if (uec->rx_buf_offset != 0) { |
| 1143 | uec->p_rx_buf = (u8 *)((uec->rx_buf_offset + align) |
| 1144 | & ~(align - 1)); |
| 1145 | } |
| 1146 | |
| 1147 | /* Zero all of the Rx buffer */ |
| 1148 | memset((void *)(uec->rx_buf_offset), 0, length + align); |
| 1149 | |
| 1150 | /* Init TxBD ring */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1151 | bd = (struct buffer_descriptor *)uec->p_tx_bd_ring; |
| 1152 | uec->tx_bd = bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1153 | |
| 1154 | for (i = 0; i < uec_info->tx_bd_ring_len; i++) { |
| 1155 | BD_DATA_CLEAR(bd); |
| 1156 | BD_STATUS_SET(bd, 0); |
| 1157 | BD_LENGTH_SET(bd, 0); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1158 | bd++; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1159 | } |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1160 | BD_STATUS_SET((--bd), TX_BD_WRAP); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1161 | |
| 1162 | /* Init RxBD ring */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1163 | bd = (struct buffer_descriptor *)uec->p_rx_bd_ring; |
| 1164 | uec->rx_bd = bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1165 | buf = uec->p_rx_buf; |
| 1166 | for (i = 0; i < uec_info->rx_bd_ring_len; i++) { |
| 1167 | BD_DATA_SET(bd, buf); |
| 1168 | BD_LENGTH_SET(bd, 0); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1169 | BD_STATUS_SET(bd, RX_BD_EMPTY); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1170 | buf += MAX_RXBUF_LEN; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1171 | bd++; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1172 | } |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1173 | BD_STATUS_SET((--bd), RX_BD_WRAP | RX_BD_EMPTY); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1174 | |
| 1175 | /* Init global Tx parameter RAM */ |
| 1176 | uec_init_tx_parameter(uec, num_threads_tx); |
| 1177 | |
| 1178 | /* Init global Rx parameter RAM */ |
| 1179 | uec_init_rx_parameter(uec, num_threads_rx); |
| 1180 | |
| 1181 | /* Init ethernet Tx and Rx parameter command */ |
| 1182 | if (uec_issue_init_enet_rxtx_cmd(uec, num_threads_tx, |
| 1183 | num_threads_rx)) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1184 | printf("%s issue init enet cmd failed\n", __func__); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1185 | return -ENOMEM; |
| 1186 | } |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1191 | static int uec_init(struct eth_device *dev, struct bd_info *bd) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1192 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1193 | struct uec_priv *uec; |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1194 | int err, i; |
| 1195 | struct phy_info *curphy; |
York Sun | 0f57797 | 2016-11-18 11:05:38 -0800 | [diff] [blame] | 1196 | #if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025) |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 1197 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 1198 | #endif |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1199 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1200 | uec = (struct uec_priv *)dev->priv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1201 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1202 | if (!uec->the_first_run) { |
York Sun | 0f57797 | 2016-11-18 11:05:38 -0800 | [diff] [blame] | 1203 | #if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025) |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1204 | /* |
| 1205 | * QE9 and QE12 need to be set for enabling QE MII |
| 1206 | * management signals |
| 1207 | */ |
| 1208 | setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE9); |
| 1209 | setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE12); |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 1210 | #endif |
| 1211 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1212 | err = init_phy(dev); |
| 1213 | if (err) { |
| 1214 | printf("%s: Cannot initialize PHY, aborting.\n", |
| 1215 | dev->name); |
| 1216 | return err; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1217 | } |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1218 | |
| 1219 | curphy = uec->mii_info->phyinfo; |
| 1220 | |
| 1221 | if (curphy->config_aneg) { |
| 1222 | err = curphy->config_aneg(uec->mii_info); |
| 1223 | if (err) { |
| 1224 | printf("%s: Can't negotiate PHY\n", dev->name); |
| 1225 | return err; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /* Give PHYs up to 5 sec to report a link */ |
| 1230 | i = 50; |
| 1231 | do { |
| 1232 | err = curphy->read_status(uec->mii_info); |
Joakim Tjernlund | c96cc50 | 2010-08-11 11:44:21 +0200 | [diff] [blame] | 1233 | if (!(((i-- > 0) && !uec->mii_info->link) || err)) |
| 1234 | break; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1235 | mdelay(100); |
Joakim Tjernlund | c96cc50 | 2010-08-11 11:44:21 +0200 | [diff] [blame] | 1236 | } while (1); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1237 | |
York Sun | 0f57797 | 2016-11-18 11:05:38 -0800 | [diff] [blame] | 1238 | #if defined(CONFIG_ARCH_P1021) || defined(CONFIG_ARCH_P1025) |
Haiying Wang | 8cb2af7 | 2011-02-11 01:25:30 -0600 | [diff] [blame] | 1239 | /* QE12 needs to be released for enabling LBCTL signal*/ |
| 1240 | clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_QE12); |
| 1241 | #endif |
| 1242 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1243 | if (err || i <= 0) |
| 1244 | printf("warning: %s: timeout on PHY link\n", dev->name); |
| 1245 | |
Heiko Schocher | 40b44bc | 2010-01-20 09:04:28 +0100 | [diff] [blame] | 1246 | adjust_link(dev); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1247 | uec->the_first_run = 1; |
| 1248 | } |
| 1249 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1250 | /* Set up the MAC address */ |
| 1251 | if (dev->enetaddr[0] & 0x01) { |
| 1252 | printf("%s: MacAddress is multcast address\n", |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1253 | __func__); |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1254 | return -1; |
| 1255 | } |
| 1256 | uec_set_mac_address(uec, dev->enetaddr); |
| 1257 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1258 | err = uec_open(uec, COMM_DIR_RX_AND_TX); |
| 1259 | if (err) { |
| 1260 | printf("%s: cannot enable UEC device\n", dev->name); |
Ben Warren | de9fcb5 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 1261 | return -1; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1262 | } |
| 1263 | |
Kim Phillips | d986cba | 2008-01-15 14:11:00 -0600 | [diff] [blame] | 1264 | phy_change(dev); |
| 1265 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1266 | return uec->mii_info->link ? 0 : -1; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1267 | } |
| 1268 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1269 | static void uec_halt(struct eth_device *dev) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1270 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1271 | struct uec_priv *uec = (struct uec_priv *)dev->priv; |
| 1272 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1273 | uec_stop(uec, COMM_DIR_RX_AND_TX); |
| 1274 | } |
| 1275 | |
Joe Hershberger | 835e923 | 2012-05-22 07:56:21 +0000 | [diff] [blame] | 1276 | static int uec_send(struct eth_device *dev, void *buf, int len) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1277 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1278 | struct uec_priv *uec; |
| 1279 | struct ucc_fast_priv *uccf; |
| 1280 | struct buffer_descriptor *bd; |
Dave Liu | 663cbab | 2006-12-06 11:38:17 +0800 | [diff] [blame] | 1281 | u16 status; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1282 | int i; |
| 1283 | int result = 0; |
| 1284 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1285 | uec = (struct uec_priv *)dev->priv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1286 | uccf = uec->uccf; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1287 | bd = uec->tx_bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1288 | |
| 1289 | /* Find an empty TxBD */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1290 | for (i = 0; BD_STATUS(bd) & TX_BD_READY; i++) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1291 | if (i > 0x100000) { |
| 1292 | printf("%s: tx buffer not ready\n", dev->name); |
| 1293 | return result; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | /* Init TxBD */ |
| 1298 | BD_DATA_SET(bd, buf); |
| 1299 | BD_LENGTH_SET(bd, len); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1300 | status = BD_STATUS(bd); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1301 | status &= BD_WRAP; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1302 | status |= (TX_BD_READY | TX_BD_LAST); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1303 | BD_STATUS_SET(bd, status); |
| 1304 | |
| 1305 | /* Tell UCC to transmit the buffer */ |
| 1306 | ucc_fast_transmit_on_demand(uccf); |
| 1307 | |
| 1308 | /* Wait for buffer to be transmitted */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1309 | for (i = 0; BD_STATUS(bd) & TX_BD_READY; i++) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1310 | if (i > 0x100000) { |
| 1311 | printf("%s: tx error\n", dev->name); |
| 1312 | return result; |
| 1313 | } |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /* Ok, the buffer be transimitted */ |
| 1317 | BD_ADVANCE(bd, status, uec->p_tx_bd_ring); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1318 | uec->tx_bd = bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1319 | result = 1; |
| 1320 | |
| 1321 | return result; |
| 1322 | } |
| 1323 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1324 | static int uec_recv(struct eth_device *dev) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1325 | { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1326 | struct uec_priv *uec = dev->priv; |
| 1327 | struct buffer_descriptor *bd; |
Dave Liu | 663cbab | 2006-12-06 11:38:17 +0800 | [diff] [blame] | 1328 | u16 status; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1329 | u16 len; |
| 1330 | u8 *data; |
| 1331 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1332 | bd = uec->rx_bd; |
| 1333 | status = BD_STATUS(bd); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1334 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1335 | while (!(status & RX_BD_EMPTY)) { |
| 1336 | if (!(status & RX_BD_ERROR)) { |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1337 | data = BD_DATA(bd); |
| 1338 | len = BD_LENGTH(bd); |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 1339 | net_process_received_packet(data, len); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1340 | } else { |
| 1341 | printf("%s: Rx error\n", dev->name); |
| 1342 | } |
| 1343 | status &= BD_CLEAN; |
| 1344 | BD_LENGTH_SET(bd, 0); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1345 | BD_STATUS_SET(bd, status | RX_BD_EMPTY); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1346 | BD_ADVANCE(bd, status, uec->p_rx_bd_ring); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1347 | status = BD_STATUS(bd); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1348 | } |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1349 | uec->rx_bd = bd; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1350 | |
| 1351 | return 1; |
| 1352 | } |
| 1353 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1354 | int uec_initialize(struct bd_info *bis, struct uec_inf *uec_info) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1355 | { |
| 1356 | struct eth_device *dev; |
| 1357 | int i; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1358 | struct uec_priv *uec; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1359 | int err; |
| 1360 | |
| 1361 | dev = (struct eth_device *)malloc(sizeof(struct eth_device)); |
| 1362 | if (!dev) |
| 1363 | return 0; |
| 1364 | memset(dev, 0, sizeof(struct eth_device)); |
| 1365 | |
| 1366 | /* Allocate the UEC private struct */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1367 | uec = (struct uec_priv *)malloc(sizeof(struct uec_priv)); |
| 1368 | if (!uec) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1369 | return -ENOMEM; |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1370 | |
| 1371 | memset(uec, 0, sizeof(struct uec_priv)); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1372 | |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 1373 | /* Adjust uec_info */ |
| 1374 | #if (MAX_QE_RISC == 4) |
| 1375 | uec_info->risc_tx = QE_RISC_ALLOCATION_FOUR_RISCS; |
| 1376 | uec_info->risc_rx = QE_RISC_ALLOCATION_FOUR_RISCS; |
richardretanubun | 001090f | 2008-10-06 15:31:43 -0400 | [diff] [blame] | 1377 | #endif |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1378 | |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 1379 | devlist[uec_info->uf_info.ucc_num] = dev; |
David Saada | 6b25c13 | 2008-03-31 02:37:38 -0700 | [diff] [blame] | 1380 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1381 | uec->uec_info = uec_info; |
Haiying Wang | 893b065 | 2009-06-04 16:12:42 -0400 | [diff] [blame] | 1382 | uec->dev = dev; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1383 | |
Kim Phillips | b42cf5f | 2010-07-26 18:34:57 -0500 | [diff] [blame] | 1384 | sprintf(dev->name, "UEC%d", uec_info->uf_info.ucc_num); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1385 | dev->iobase = 0; |
| 1386 | dev->priv = (void *)uec; |
| 1387 | dev->init = uec_init; |
| 1388 | dev->halt = uec_halt; |
| 1389 | dev->send = uec_send; |
| 1390 | dev->recv = uec_recv; |
| 1391 | |
| 1392 | /* Clear the ethnet address */ |
| 1393 | for (i = 0; i < 6; i++) |
| 1394 | dev->enetaddr[i] = 0; |
| 1395 | |
| 1396 | eth_register(dev); |
| 1397 | |
| 1398 | err = uec_startup(uec); |
| 1399 | if (err) { |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1400 | printf("%s: Cannot configure net device, aborting.", dev->name); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1401 | return err; |
| 1402 | } |
| 1403 | |
Richard Retanubun | 15e467c | 2009-06-17 16:00:41 -0400 | [diff] [blame] | 1404 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 1405 | int retval; |
| 1406 | struct mii_dev *mdiodev = mdio_alloc(); |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1407 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 1408 | if (!mdiodev) |
| 1409 | return -ENOMEM; |
| 1410 | strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); |
| 1411 | mdiodev->read = uec_miiphy_read; |
| 1412 | mdiodev->write = uec_miiphy_write; |
| 1413 | |
| 1414 | retval = mdio_register(mdiodev); |
| 1415 | if (retval < 0) |
| 1416 | return retval; |
David Saada | 6b25c13 | 2008-03-31 02:37:38 -0700 | [diff] [blame] | 1417 | #endif |
| 1418 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 1419 | return 1; |
| 1420 | } |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 1421 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 1422 | int uec_eth_init(struct bd_info *bis, struct uec_inf *uecs, int num) |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 1423 | { |
| 1424 | int i; |
| 1425 | |
| 1426 | for (i = 0; i < num; i++) |
| 1427 | uec_initialize(bis, &uecs[i]); |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1432 | int uec_standard_init(struct bd_info *bis) |
Haiying Wang | 511d828 | 2009-06-04 16:12:41 -0400 | [diff] [blame] | 1433 | { |
| 1434 | return uec_eth_init(bis, uec_info, ARRAY_SIZE(uec_info)); |
| 1435 | } |
Heiko Schocher | 41b64a8 | 2020-02-06 09:48:16 +0100 | [diff] [blame] | 1436 | #endif |