ether.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. /*
  25. * Ethernet test
  26. *
  27. * The Serial Communication Controllers (SCC) listed in ctlr_list array below
  28. * are tested in the loopback ethernet mode.
  29. * The controllers are configured accordingly and several packets
  30. * are transmitted. The configurable test parameters are:
  31. * MIN_PACKET_LENGTH - minimum size of packet to transmit
  32. * MAX_PACKET_LENGTH - maximum size of packet to transmit
  33. * TEST_NUM - number of tests
  34. */
  35. #ifdef CONFIG_POST
  36. #include <post.h>
  37. #if defined(CONFIG_8xx)
  38. #include <commproc.h>
  39. #elif defined(CONFIG_MPC8260)
  40. #include <asm/cpm_8260.h>
  41. #else
  42. #error "Apparently a bad configuration, please fix."
  43. #endif
  44. #include <command.h>
  45. #include <net.h>
  46. #if CONFIG_POST & CFG_POST_ETHER
  47. #define MIN_PACKET_LENGTH 64
  48. #define MAX_PACKET_LENGTH 256
  49. #define TEST_NUM 1
  50. #define CTLR_SCC 0
  51. extern void spi_init_f (void);
  52. extern void spi_init_r (void);
  53. /* The list of controllers to test */
  54. #if defined(CONFIG_MPC823)
  55. static int ctlr_list[][2] = { {CTLR_SCC, 1} };
  56. #else
  57. static int ctlr_list[][2] = { };
  58. #endif
  59. #define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
  60. static struct {
  61. void (*init) (int index);
  62. int (*send) (int index, volatile void *packet, int length);
  63. int (*recv) (int index, void *packet, int length);
  64. } ctlr_proc[1];
  65. static char *ctlr_name[1] = { "SCC" };
  66. static int used_by_uart[1] = { -1 };
  67. static int used_by_ether[1] = { -1 };
  68. /* Ethernet Transmit and Receive Buffers */
  69. #define DBUF_LENGTH 1520
  70. #define TX_BUF_CNT 2
  71. #define TOUT_LOOP 100
  72. static char txbuf[DBUF_LENGTH];
  73. static uint rxIdx; /* index of the current RX buffer */
  74. static uint txIdx; /* index of the current TX buffer */
  75. /*
  76. * SCC Ethernet Tx and Rx buffer descriptors allocated at the
  77. * immr->udata_bd address on Dual-Port RAM
  78. * Provide for Double Buffering
  79. */
  80. typedef volatile struct CommonBufferDescriptor {
  81. cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
  82. cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
  83. } RTXBD;
  84. static RTXBD *rtx;
  85. /*
  86. * SCC callbacks
  87. */
  88. static void scc_init (int scc_index)
  89. {
  90. DECLARE_GLOBAL_DATA_PTR;
  91. bd_t *bd = gd->bd;
  92. static int proff[] =
  93. { PROFF_SCC1, PROFF_SCC2, PROFF_SCC3, PROFF_SCC4 };
  94. static unsigned int cpm_cr[] =
  95. { CPM_CR_CH_SCC1, CPM_CR_CH_SCC2, CPM_CR_CH_SCC3,
  96. CPM_CR_CH_SCC4 };
  97. int i;
  98. scc_enet_t *pram_ptr;
  99. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  100. immr->im_cpm.cp_scc[scc_index].scc_gsmrl &=
  101. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  102. #if defined(CONFIG_FADS)
  103. #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC86xADS)
  104. /* The FADS860T and MPC86xADS don't use the MODEM_EN or DATA_VOICE signals. */
  105. *((uint *) BCSR4) &= ~BCSR4_ETHLOOP;
  106. *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL;
  107. *((uint *) BCSR1) &= ~BCSR1_ETHEN;
  108. #else
  109. *((uint *) BCSR4) &= ~(BCSR4_ETHLOOP | BCSR4_MODEM_EN);
  110. *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL | BCSR4_DATA_VOICE;
  111. *((uint *) BCSR1) &= ~BCSR1_ETHEN;
  112. #endif
  113. #endif
  114. pram_ptr = (scc_enet_t *) & (immr->im_cpm.cp_dparam[proff[scc_index]]);
  115. rxIdx = 0;
  116. txIdx = 0;
  117. #ifdef CFG_ALLOC_DPRAM
  118. rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
  119. dpram_alloc_align (sizeof (RTXBD), 8));
  120. #else
  121. rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_SCC_BASE);
  122. #endif
  123. #if 0
  124. #if (defined(PA_ENET_RXD) && defined(PA_ENET_TXD))
  125. /* Configure port A pins for Txd and Rxd.
  126. */
  127. immr->im_ioport.iop_papar |= (PA_ENET_RXD | PA_ENET_TXD);
  128. immr->im_ioport.iop_padir &= ~(PA_ENET_RXD | PA_ENET_TXD);
  129. immr->im_ioport.iop_paodr &= ~PA_ENET_TXD;
  130. #elif (defined(PB_ENET_RXD) && defined(PB_ENET_TXD))
  131. /* Configure port B pins for Txd and Rxd.
  132. */
  133. immr->im_cpm.cp_pbpar |= (PB_ENET_RXD | PB_ENET_TXD);
  134. immr->im_cpm.cp_pbdir &= ~(PB_ENET_RXD | PB_ENET_TXD);
  135. immr->im_cpm.cp_pbodr &= ~PB_ENET_TXD;
  136. #else
  137. #error Configuration Error: exactly ONE of PA_ENET_[RT]XD, PB_ENET_[RT]XD must be defined
  138. #endif
  139. #if defined(PC_ENET_LBK)
  140. /* Configure port C pins to disable External Loopback
  141. */
  142. immr->im_ioport.iop_pcpar &= ~PC_ENET_LBK;
  143. immr->im_ioport.iop_pcdir |= PC_ENET_LBK;
  144. immr->im_ioport.iop_pcso &= ~PC_ENET_LBK;
  145. immr->im_ioport.iop_pcdat &= ~PC_ENET_LBK; /* Disable Loopback */
  146. #endif /* PC_ENET_LBK */
  147. /* Configure port C pins to enable CLSN and RENA.
  148. */
  149. immr->im_ioport.iop_pcpar &= ~(PC_ENET_CLSN | PC_ENET_RENA);
  150. immr->im_ioport.iop_pcdir &= ~(PC_ENET_CLSN | PC_ENET_RENA);
  151. immr->im_ioport.iop_pcso |= (PC_ENET_CLSN | PC_ENET_RENA);
  152. /* Configure port A for TCLK and RCLK.
  153. */
  154. immr->im_ioport.iop_papar |= (PA_ENET_TCLK | PA_ENET_RCLK);
  155. immr->im_ioport.iop_padir &= ~(PA_ENET_TCLK | PA_ENET_RCLK);
  156. /*
  157. * Configure Serial Interface clock routing -- see section 16.7.5.3
  158. * First, clear all SCC bits to zero, then set the ones we want.
  159. */
  160. immr->im_cpm.cp_sicr &= ~SICR_ENET_MASK;
  161. immr->im_cpm.cp_sicr |= SICR_ENET_CLKRT;
  162. #else
  163. /*
  164. * SCC2 receive clock is BRG2
  165. * SCC2 transmit clock is BRG3
  166. */
  167. immr->im_cpm.cp_brgc2 = 0x0001000C;
  168. immr->im_cpm.cp_brgc3 = 0x0001000C;
  169. immr->im_cpm.cp_sicr &= ~0x00003F00;
  170. immr->im_cpm.cp_sicr |= 0x00000a00;
  171. #endif /* 0 */
  172. /*
  173. * Initialize SDCR -- see section 16.9.23.7
  174. * SDMA configuration register
  175. */
  176. immr->im_siu_conf.sc_sdcr = 0x01;
  177. /*
  178. * Setup SCC Ethernet Parameter RAM
  179. */
  180. pram_ptr->sen_genscc.scc_rfcr = 0x18; /* Normal Operation and Mot byte ordering */
  181. pram_ptr->sen_genscc.scc_tfcr = 0x18; /* Mot byte ordering, Normal access */
  182. pram_ptr->sen_genscc.scc_mrblr = DBUF_LENGTH; /* max. ET package len 1520 */
  183. pram_ptr->sen_genscc.scc_rbase = (unsigned int) (&rtx->rxbd[0]); /* Set RXBD tbl start at Dual Port */
  184. pram_ptr->sen_genscc.scc_tbase = (unsigned int) (&rtx->txbd[0]); /* Set TXBD tbl start at Dual Port */
  185. /*
  186. * Setup Receiver Buffer Descriptors (13.14.24.18)
  187. * Settings:
  188. * Empty, Wrap
  189. */
  190. for (i = 0; i < PKTBUFSRX; i++) {
  191. rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
  192. rtx->rxbd[i].cbd_datlen = 0; /* Reset */
  193. rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
  194. }
  195. rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
  196. /*
  197. * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
  198. * Settings:
  199. * Add PADs to Short FRAMES, Wrap, Last, Tx CRC
  200. */
  201. for (i = 0; i < TX_BUF_CNT; i++) {
  202. rtx->txbd[i].cbd_sc =
  203. (BD_ENET_TX_PAD | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  204. rtx->txbd[i].cbd_datlen = 0; /* Reset */
  205. rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
  206. }
  207. rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
  208. /*
  209. * Enter Command: Initialize Rx Params for SCC
  210. */
  211. do { /* Spin until ready to issue command */
  212. __asm__ ("eieio");
  213. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  214. /* Issue command */
  215. immr->im_cpm.cp_cpcr =
  216. ((CPM_CR_INIT_RX << 8) | (cpm_cr[scc_index] << 4) |
  217. CPM_CR_FLG);
  218. do { /* Spin until command processed */
  219. __asm__ ("eieio");
  220. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  221. /*
  222. * Ethernet Specific Parameter RAM
  223. * see table 13-16, pg. 660,
  224. * pg. 681 (example with suggested settings)
  225. */
  226. pram_ptr->sen_cpres = ~(0x0); /* Preset CRC */
  227. pram_ptr->sen_cmask = 0xdebb20e3; /* Constant Mask for CRC */
  228. pram_ptr->sen_crcec = 0x0; /* Error Counter CRC (unused) */
  229. pram_ptr->sen_alec = 0x0; /* Alignment Error Counter (unused) */
  230. pram_ptr->sen_disfc = 0x0; /* Discard Frame Counter (unused) */
  231. pram_ptr->sen_pads = 0x8888; /* Short Frame PAD Characters */
  232. pram_ptr->sen_retlim = 15; /* Retry Limit Threshold */
  233. pram_ptr->sen_maxflr = 1518; /* MAX Frame Length Register */
  234. pram_ptr->sen_minflr = 64; /* MIN Frame Length Register */
  235. pram_ptr->sen_maxd1 = DBUF_LENGTH; /* MAX DMA1 Length Register */
  236. pram_ptr->sen_maxd2 = DBUF_LENGTH; /* MAX DMA2 Length Register */
  237. pram_ptr->sen_gaddr1 = 0x0; /* Group Address Filter 1 (unused) */
  238. pram_ptr->sen_gaddr2 = 0x0; /* Group Address Filter 2 (unused) */
  239. pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */
  240. pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
  241. #define ea bd->bi_enetaddr
  242. pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4];
  243. pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2];
  244. pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0];
  245. #undef ea
  246. pram_ptr->sen_pper = 0x0; /* Persistence (unused) */
  247. pram_ptr->sen_iaddr1 = 0x0; /* Individual Address Filter 1 (unused) */
  248. pram_ptr->sen_iaddr2 = 0x0; /* Individual Address Filter 2 (unused) */
  249. pram_ptr->sen_iaddr3 = 0x0; /* Individual Address Filter 3 (unused) */
  250. pram_ptr->sen_iaddr4 = 0x0; /* Individual Address Filter 4 (unused) */
  251. pram_ptr->sen_taddrh = 0x0; /* Tmp Address (MSB) (unused) */
  252. pram_ptr->sen_taddrm = 0x0; /* Tmp Address (unused) */
  253. pram_ptr->sen_taddrl = 0x0; /* Tmp Address (LSB) (unused) */
  254. /*
  255. * Enter Command: Initialize Tx Params for SCC
  256. */
  257. do { /* Spin until ready to issue command */
  258. __asm__ ("eieio");
  259. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  260. /* Issue command */
  261. immr->im_cpm.cp_cpcr =
  262. ((CPM_CR_INIT_TX << 8) | (cpm_cr[scc_index] << 4) |
  263. CPM_CR_FLG);
  264. do { /* Spin until command processed */
  265. __asm__ ("eieio");
  266. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  267. /*
  268. * Mask all Events in SCCM - we use polling mode
  269. */
  270. immr->im_cpm.cp_scc[scc_index].scc_sccm = 0;
  271. /*
  272. * Clear Events in SCCE -- Clear bits by writing 1's
  273. */
  274. immr->im_cpm.cp_scc[scc_index].scc_scce = ~(0x0);
  275. /*
  276. * Initialize GSMR High 32-Bits
  277. * Settings: Normal Mode
  278. */
  279. immr->im_cpm.cp_scc[scc_index].scc_gsmrh = 0;
  280. /*
  281. * Initialize GSMR Low 32-Bits, but do not Enable Transmit/Receive
  282. * Settings:
  283. * TCI = Invert
  284. * TPL = 48 bits
  285. * TPP = Repeating 10's
  286. * LOOP = Loopback
  287. * MODE = Ethernet
  288. */
  289. immr->im_cpm.cp_scc[scc_index].scc_gsmrl = (SCC_GSMRL_TCI |
  290. SCC_GSMRL_TPL_48 |
  291. SCC_GSMRL_TPP_10 |
  292. SCC_GSMRL_DIAG_LOOP |
  293. SCC_GSMRL_MODE_ENET);
  294. /*
  295. * Initialize the DSR -- see section 13.14.4 (pg. 513) v0.4
  296. */
  297. immr->im_cpm.cp_scc[scc_index].scc_dsr = 0xd555;
  298. /*
  299. * Initialize the PSMR
  300. * Settings:
  301. * CRC = 32-Bit CCITT
  302. * NIB = Begin searching for SFD 22 bits after RENA
  303. * LPB = Loopback Enable (Needed when FDE is set)
  304. */
  305. immr->im_cpm.cp_scc[scc_index].scc_psmr = SCC_PSMR_ENCRC |
  306. SCC_PSMR_NIB22 | SCC_PSMR_LPB;
  307. #if 0
  308. /*
  309. * Configure Ethernet TENA Signal
  310. */
  311. #if (defined(PC_ENET_TENA) && !defined(PB_ENET_TENA))
  312. immr->im_ioport.iop_pcpar |= PC_ENET_TENA;
  313. immr->im_ioport.iop_pcdir &= ~PC_ENET_TENA;
  314. #elif (defined(PB_ENET_TENA) && !defined(PC_ENET_TENA))
  315. immr->im_cpm.cp_pbpar |= PB_ENET_TENA;
  316. immr->im_cpm.cp_pbdir |= PB_ENET_TENA;
  317. #else
  318. #error Configuration Error: exactly ONE of PB_ENET_TENA, PC_ENET_TENA must be defined
  319. #endif
  320. #if defined(CONFIG_ADS) && defined(CONFIG_MPC860)
  321. /*
  322. * Port C is used to control the PHY,MC68160.
  323. */
  324. immr->im_ioport.iop_pcdir |=
  325. (PC_ENET_ETHLOOP | PC_ENET_TPFLDL | PC_ENET_TPSQEL);
  326. immr->im_ioport.iop_pcdat |= PC_ENET_TPFLDL;
  327. immr->im_ioport.iop_pcdat &= ~(PC_ENET_ETHLOOP | PC_ENET_TPSQEL);
  328. *((uint *) BCSR1) &= ~BCSR1_ETHEN;
  329. #endif /* MPC860ADS */
  330. #if defined(CONFIG_AMX860)
  331. /*
  332. * Port B is used to control the PHY,MC68160.
  333. */
  334. immr->im_cpm.cp_pbdir |=
  335. (PB_ENET_ETHLOOP | PB_ENET_TPFLDL | PB_ENET_TPSQEL);
  336. immr->im_cpm.cp_pbdat |= PB_ENET_TPFLDL;
  337. immr->im_cpm.cp_pbdat &= ~(PB_ENET_ETHLOOP | PB_ENET_TPSQEL);
  338. immr->im_ioport.iop_pddir |= PD_ENET_ETH_EN;
  339. immr->im_ioport.iop_pddat &= ~PD_ENET_ETH_EN;
  340. #endif /* AMX860 */
  341. #endif /* 0 */
  342. #ifdef CONFIG_RPXCLASSIC
  343. *((uchar *) BCSR0) &= ~BCSR0_ETHLPBK;
  344. *((uchar *) BCSR0) |= (BCSR0_ETHEN | BCSR0_COLTEST | BCSR0_FULLDPLX);
  345. #endif
  346. #ifdef CONFIG_RPXLITE
  347. *((uchar *) BCSR0) |= BCSR0_ETHEN;
  348. #endif
  349. #ifdef CONFIG_MBX
  350. board_ether_init ();
  351. #endif
  352. /*
  353. * Set the ENT/ENR bits in the GSMR Low -- Enable Transmit/Receive
  354. */
  355. immr->im_cpm.cp_scc[scc_index].scc_gsmrl |=
  356. (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  357. /*
  358. * Work around transmit problem with first eth packet
  359. */
  360. #if defined (CONFIG_FADS)
  361. udelay (10000); /* wait 10 ms */
  362. #elif defined (CONFIG_AMX860) || defined(CONFIG_RPXCLASSIC)
  363. udelay (100000); /* wait 100 ms */
  364. #endif
  365. }
  366. static int scc_send (int index, volatile void *packet, int length)
  367. {
  368. int i, j = 0;
  369. while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
  370. udelay (1); /* will also trigger Wd if needed */
  371. j++;
  372. }
  373. if (j >= TOUT_LOOP)
  374. printf ("TX not ready\n");
  375. rtx->txbd[txIdx].cbd_bufaddr = (uint) packet;
  376. rtx->txbd[txIdx].cbd_datlen = length;
  377. rtx->txbd[txIdx].cbd_sc |=
  378. (BD_ENET_TX_READY | BD_ENET_TX_LAST | BD_ENET_TX_WRAP);
  379. while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
  380. udelay (1); /* will also trigger Wd if needed */
  381. j++;
  382. }
  383. if (j >= TOUT_LOOP)
  384. printf ("TX timeout\n");
  385. i = (rtx->txbd[txIdx].
  386. cbd_sc & BD_ENET_TX_STATS) /* return only status bits */ ;
  387. return i;
  388. }
  389. static int scc_recv (int index, void *packet, int max_length)
  390. {
  391. int length = -1;
  392. if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
  393. goto Done; /* nothing received */
  394. }
  395. if (!(rtx->rxbd[rxIdx].cbd_sc & 0x003f)) {
  396. length = rtx->rxbd[rxIdx].cbd_datlen - 4;
  397. memcpy (packet,
  398. (void *) (NetRxPackets[rxIdx]),
  399. length < max_length ? length : max_length);
  400. }
  401. /* Give the buffer back to the SCC. */
  402. rtx->rxbd[rxIdx].cbd_datlen = 0;
  403. /* wrap around buffer index when necessary */
  404. if ((rxIdx + 1) >= PKTBUFSRX) {
  405. rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
  406. (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
  407. rxIdx = 0;
  408. } else {
  409. rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
  410. rxIdx++;
  411. }
  412. Done:
  413. return length;
  414. }
  415. /*
  416. * Test routines
  417. */
  418. static void packet_fill (char *packet, int length)
  419. {
  420. char c = (char) length;
  421. int i;
  422. packet[0] = 0xFF;
  423. packet[1] = 0xFF;
  424. packet[2] = 0xFF;
  425. packet[3] = 0xFF;
  426. packet[4] = 0xFF;
  427. packet[5] = 0xFF;
  428. for (i = 6; i < length; i++) {
  429. packet[i] = c++;
  430. }
  431. }
  432. static int packet_check (char *packet, int length)
  433. {
  434. char c = (char) length;
  435. int i;
  436. for (i = 6; i < length; i++) {
  437. if (packet[i] != c++)
  438. return -1;
  439. }
  440. return 0;
  441. }
  442. static int test_ctlr (int ctlr, int index)
  443. {
  444. int res = -1;
  445. char packet_send[MAX_PACKET_LENGTH];
  446. char packet_recv[MAX_PACKET_LENGTH];
  447. int length;
  448. int i;
  449. int l;
  450. ctlr_proc[ctlr].init (index);
  451. for (i = 0; i < TEST_NUM; i++) {
  452. for (l = MIN_PACKET_LENGTH; l <= MAX_PACKET_LENGTH; l++) {
  453. packet_fill (packet_send, l);
  454. ctlr_proc[ctlr].send (index, packet_send, l);
  455. length = ctlr_proc[ctlr].recv (index, packet_recv,
  456. MAX_PACKET_LENGTH);
  457. if (length != l || packet_check (packet_recv, length) < 0) {
  458. goto Done;
  459. }
  460. }
  461. }
  462. res = 0;
  463. Done:
  464. #if !defined(CONFIG_8xx_CONS_NONE)
  465. if (used_by_uart[ctlr] == index) {
  466. serial_init ();
  467. }
  468. #endif
  469. #if defined(SCC_ENET)
  470. if (used_by_ether[ctlr] == index) {
  471. DECLARE_GLOBAL_DATA_PTR;
  472. eth_init (gd->bd);
  473. }
  474. #endif
  475. /*
  476. * SCC2 Ethernet parameter RAM space overlaps
  477. * the SPI parameter RAM space. So we need to restore
  478. * the SPI configuration after SCC2 ethernet test.
  479. */
  480. #if defined(CONFIG_SPI)
  481. if (ctlr == CTLR_SCC && index == 1) {
  482. spi_init_f ();
  483. spi_init_r ();
  484. }
  485. #endif
  486. if (res != 0) {
  487. post_log ("ethernet %s%d test failed\n", ctlr_name[ctlr],
  488. index + 1);
  489. }
  490. return res;
  491. }
  492. int ether_post_test (int flags)
  493. {
  494. int res = 0;
  495. int i;
  496. #if defined(CONFIG_8xx_CONS_SCC1)
  497. used_by_uart[CTLR_SCC] = 0;
  498. #elif defined(CONFIG_8xx_CONS_SCC2)
  499. used_by_uart[CTLR_SCC] = 1;
  500. #elif defined(CONFIG_8xx_CONS_SCC3)
  501. used_by_uart[CTLR_SCC] = 2;
  502. #elif defined(CONFIG_8xx_CONS_SCC4)
  503. used_by_uart[CTLR_SCC] = 3;
  504. #endif
  505. #if defined(SCC_ENET)
  506. used_by_ether[CTLR_SCC] = SCC_ENET;
  507. #endif
  508. ctlr_proc[CTLR_SCC].init = scc_init;
  509. ctlr_proc[CTLR_SCC].send = scc_send;
  510. ctlr_proc[CTLR_SCC].recv = scc_recv;
  511. for (i = 0; i < CTRL_LIST_SIZE; i++) {
  512. if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
  513. res = -1;
  514. }
  515. }
  516. return res;
  517. }
  518. #endif /* CONFIG_POST & CFG_POST_ETHER */
  519. #endif /* CONFIG_POST */