📄 cpmac.c
字号:
/*------------------------------------------------------------------------------*//* *//* Copyright (C) 2003 by Texas Instruments, Inc. All rights reserved. *//* Copyright (C) 2003 Telogy Networks. *//* *//* IMPORTANT - READ CAREFULLY BEFORE PROCEEDING TO USE SOFTWARE. *//* *//* This document is displayed for you to read prior to using the software *//* and documentation. By using the software and documentation, or opening *//* the sealed packet containing the software, or proceeding to download the *//* software from a Bulletin Board System(BBS) or a WEB Server, you agree to *//* abide by the following Texas Instruments License Agreement. If you choose *//* not to agree with these provisions, promptly discontinue use of the *//* software and documentation and return the material to the place you *//* obtained it. *//* *//* *** NOTE *** *//* *//* The licensed materials contain MIPS Technologies, Inc. confidential *//* information which is protected by the appropriate MIPS Technologies, Inc. *//* license agreement. It is your responsibility to comply with these *//* licenses. *//* *//* Texas Instruments License Agreement *//* *//* 1. License - Texas Instruments (hereinafter "TI"), grants you a license *//* to use the software program and documentation in this package ("Licensed *//* Materials") for Texas Instruments broadband products. *//* *//* 2. Restrictions - You may not reverse-assemble or reverse-compile the *//* Licensed Materials provided in object code or executable format. You may *//* not sublicense, transfer, assign, rent, or lease the Licensed Materials *//* or this Agreement without written permission from TI. *//* *//* 3. Copyright - The Licensed Materials are copyrighted. Accordingly, you *//* may either make one copy of the Licensed Materials for backup and/or *//* archival purposes or copy the Licensed Materials to another medium and *//* keep the original Licensed Materials for backup and/or archival purposes. *//* *//* 4. Runtime and Applications Software - You may create modified or *//* derivative programs of software identified as Runtime Libraries or *//* Applications Software, which, in source code form, remain subject to this *//* Agreement, but object code versions of such derivative programs are not *//* subject to this Agreement. *//* *//* 5. Warranty - TI warrants the media to be free from defects in material *//* and workmanship and that the software will substantially conform to the *//* related documentation for a period of ninety (90) days after the date of *//* your purchase. TI does not warrant that the Licensed Materials will be *//* free from error or will meet your specific requirements. *//* *//* 6. Remedies - If you find defects in the media or that the software does *//* not conform to the enclosed documentation, you may return the Licensed *//* Materials along with the purchase receipt, postage prepaid, to the *//* following address within the warranty period and receive a refund. *//* *//* TEXAS INSTRUMENTS *//* Application Specific Products, MS 8650 *//* c/o ADAM2 Application Manager *//* 12500 TI Boulevard *//* Dallas, TX 75243 - U.S.A. *//* *//* 7. Limitations - TI makes no warranty or condition, either expressed or *//* implied, including, but not limited to, any implied warranties of *//* merchantability and fitness for a particular purpose, regarding the *//* licensed materials. *//* *//* Neither TI nor any applicable licensor will be liable for any indirect, *//* incidental or consequential damages, including but not limited to loss of *//* profits. *//* *//* 8. Term - The license is effective until terminated. You may terminate *//* it at any other time by destroying the program together with all copies, *//* modifications and merged portions in any form. It also will terminate if *//* you fail to comply with any term or condition of this Agreement. *//* *//* 9. Export Control - The re-export of United States origin software and *//* documentation is subject to the U.S. Export Administration Regulations or *//* your equivalent local regulations. Compliance with such regulations is *//* your responsibility. *//* *//* *** IMPORTANT NOTICE *** *//* *//* Texas Instruments (TI) reserves the right to make changes to or to *//* discontinue any semiconductor product or service identified in this *//* publication without notice. TI advises its customers to obtain the latest *//* version of the relevant information to verify, before placing orders, *//* that the information being relied upon is current. *//* *//* TI warrants performance of its semiconductor products and related *//* software to current specifications in accordance with TI's standard *//* warranty. Testing and other quality control techniques are utilized to *//* the extent TI deems necessary to support this warranty. Unless mandated *//* by government requirements, specific testing of all parameters of each *//* device is not necessarily performed. *//* *//* Please be aware that Texas Instruments products are not intended for use *//* in life-support appliances, devices, or systems. Use of a TI product in *//* such applications without the written approval of the appropriate TI *//* officer is prohibited. Certain applications using semiconductor devices *//* may involve potential risks of injury, property damage, or loss of life. *//* In order to minimize these risks, adequate design and operating *//* safeguards should be provided by the customer to minimize inherent or *//* procedural hazards. Inclusion of TI products in such applications is *//* understood to be fully at the risk of the customer using TI devices or *//* systems. *//* *//* TI assumes no liability for TI applications assistance, customer product *//* design, software performance, or infringement of patents or services *//* described herein. Nor does TI warrant or represent that license, either *//* expressed or implied, is granted under any patent right, copyright, mask *//* work right, or other intellectual property right of TI covering or *//* relating to any combination, machine, or process in which such *//* semiconductor products or services might be or are used. *//* *//* All company and/or product names are trademarks and/or registered *//* trademarks of their respective manaufacturers. *//* *//* *//* cpmac.c: SANGAM CPMAC driver. *//* *//* Author: Nakshatra Saha <nakshatra@ti.com> *//*------------------------------------------------------------------------------*/#define BD_OFFSET 0#define RX_BUFF_SZ 1548#define TX_DELAY 10000#define RX_DELAY 500000#define TRX_MIN_DELAY 100CpmacState cpmac_sw_state;u1 sys_et_addr[6];u1 et_bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};CpmacState *cpmac_st = NULL;void FlushICache();void FlushDCache();void delay(u4 units){ volatile u4 ii; for (ii = 0; ii < units; ii++);}/* SBL_ERESCRUNCH: failed to malloc buffer for rx bds. */Status cpmac_init (void){ u4 ii; volatile unsigned int pp; Move(sed_lclEthAddr, sys_et_addr, sizeof(eth_HwAddress)); if (cpmac_st != NULL) {#if CPMAC_DEBUG sys_printf("\nInit called multiple times.");#endif return SBL_SUCCESS; } cpmac_st = (CpmacState *)KSEG1(&cpmac_sw_state); /* Placed in uncached */ /* Explicitly reset and bring it out of reset, the CPMAC. * NOTE: EMAC0 is reset here only. */ REG32_RMW(0xa8611600, 17, 17, 0); delay(1000); REG32_RMW(0xa8611600, 17, 17, 1); delay(1000); /* * Zero all of TX/RX DMA state head descriptor pointer registers. */ for (ii = 0; ii < CH_MAX; ii++) { REG32_W(CPMAC_A_TX_DMAHDP(ii), 0); REG32_W(CPMAC_A_RX_DMAHDP(ii), 0); } /* Enable TX/RX in Control registers. */ REG32_W(CPMAC_A_TX_CTRL, 1); REG32_W(CPMAC_A_RX_CTRL, 1); /* * Initialize the other registers as required - MII EN should be done * at the end. */ REG32_W(CPMAC_A_RXUNIS, 1); /* initialize `only' ch 0 */ REG32_W(CPMAC_A_RXUNIC, 0xfe); REG32_W(CPMAC_A_RX_BO, BD_OFFSET); /* Set the MAC address. */ for (ii = 0; ii < CH_MAX; ii++) { REG32_W(CPMAC_A_MACA_LO(ii), sys_et_addr[5] + ii); } REG32_W(CPMAC_A_MACA_MED, sys_et_addr[4]); REG32_W(CPMAC_A_MACA_HI, sys_et_addr[0] | (sys_et_addr[1] << 8) | (sys_et_addr[2] << 16) | (sys_et_addr[3] << 24)); REG32_RMW(CPMAC_BASE + 0x10c, 15, 0, 0x5dc); /* enable broadcast */ REG32_RMW(CPMAC_BASE + 0x100, 13, 8, 0x20);#if CPMAC_DEBUG sys_printf("\nallowed pkt sz: 0x%x", REG32_R(CPMAC_BASE + 0x10c, 31, 0));#endif /* * Initialize cpmac_st, as required, eg link_state, rx_next, et al. */ cpmac_st->link_state = LK_DN; cpmac_st->rx_next = &cpmac_st->rx[0]; /* * Initialize the TX/RX buffer descriptors. */ for (ii = 0; ii < TX_BD_COUNT; ii++) { /* Clear only the OWNS bit for the cpmac_tx to start smoothly. */ cpmac_st->tx[ii].ctrl_n_len = 0; } if (SBL_SUCCESS != cpmac_rx_bd_init(cpmac_st->rx)) { return SBL_EFAILURE; } REG32_W(CPMAC_A_MACCTRL, (CPMAC_B_MACCTRL_MII | /*| CPMAC_B_MACCTRL_TXFC | CPMAC_B_MACCTRL_RXFC | */ CPMAC_B_MACCTRL_DPLXM)); /* sekhar */ for(pp=0;pp<600000; pp++); FlushICache(); FlushDCache(); #ifdef CPMAC_DEBUG sys_printf("PHY CLK SOURCE: %d\n", REG32_R(0xA8611A00, 21,20));#endif return SBL_SUCCESS;}/* * rx_bd_head should be passed as a pointer to an array of rx bds. * This routine initializes the rx bds as well as sets the RX DMA HDP. * * rx_bd_head passed should be in KSEG1. * * SBL_SUCCESS: Success. * SBL_EFAILURE: Caller should exit. * SBL_ERESCRUNCH: Caller should exit. *//* char rx_buf[RX_BD_COUNT*RX_BUFF_SZ + (5 * RX_BD_COUNT)];*/char rx_buf[RX_BD_COUNT][RX_BUFF_SZ + 5];Status cpmac_rx_bd_init(BuffDesc *rx_bd_head){ u4 ii; char* tmp; if (rx_bd_head == NULL) { return SBL_EFAILURE; } for (ii = 0; ii < RX_BD_COUNT; ii++) { rx_bd_head[ii].next = (BuffDesc *)((ii < RX_BD_COUNT - 1) ? PHYS(&rx_bd_head[ii + 1]) : NULL); tmp = &rx_buf[ii][0]; tmp = (char *)(((((int)tmp + 3)/4) * 4) + 2);#ifdef CPMAC_DEBUG sys_printf("buf %d: %08x\n", ii, tmp);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -