at91_emac.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. /*
  2. * Copyright (C) 2006-2007 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. */
  33. /*
  34. * $Id: at91_emac.c 5472 2013-12-06 00:16:28Z olereinhardt $
  35. */
  36. #include <cfg/os.h>
  37. #include <cfg/dev.h>
  38. #include <arch/arm.h>
  39. #include <cfg/arch/gpio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <sys/atom.h>
  43. #include <sys/heap.h>
  44. #include <sys/thread.h>
  45. #include <sys/event.h>
  46. #include <sys/timer.h>
  47. #include <sys/confnet.h>
  48. #include <netinet/if_ether.h>
  49. #include <net/ether.h>
  50. #include <net/if_var.h>
  51. #include <dev/irqreg.h>
  52. #include <dev/at91_emac.h>
  53. #include <dev/phy.h>
  54. #include <stdio.h>
  55. /* WARNING: Variadic macros are C99 and may fail with C89 compilers. */
  56. #ifdef NUTDEBUG
  57. #include <stdio.h>
  58. #include <arpa/inet.h>
  59. #define EMPRINTF(args,...) printf(args,##__VA_ARGS__);fflush(stdout)
  60. #else
  61. #define EMPRINTF(args,...)
  62. #endif
  63. #ifndef NUT_THREAD_NICRXSTACK
  64. /* arm-elf-gcc used 168 bytes with optimized, 412 bytes with debug code. */
  65. #define NUT_THREAD_NICRXSTACK 320
  66. #endif
  67. #ifndef EMAC_RX_BUFFERS
  68. #define EMAC_RX_BUFFERS 32
  69. #endif
  70. #define EMAC_RX_BUFSIZ 128
  71. #define EMAC_TX_BUFFERS 2
  72. #ifndef EMAC_TX_BUFSIZ
  73. #define EMAC_TX_BUFSIZ 1536
  74. #endif
  75. #ifndef EMAC_LINK_LOOPS
  76. #define EMAC_LINK_LOOPS 1000
  77. #endif
  78. /*!
  79. * \brief PHY address.
  80. *
  81. * Any other than 0 seems to create problems with Atmel's evaluation kits.
  82. */
  83. #ifndef NIC_PHY_ADDR
  84. #define NIC_PHY_ADDR 0
  85. #endif
  86. /*!
  87. * \brief PHY ID.
  88. *
  89. * If set to 0xffffffff, the PHY id will be ignored.
  90. */
  91. #ifndef NIC_PHY_UID
  92. #define NIC_PHY_UID 0xffffffff
  93. #endif
  94. /*!
  95. * \brief Check all known PHY IDs.
  96. *
  97. * If defined, perform the old PHY checks. This ensures compatibility
  98. * at the cost of bloat. Should be removed later on when all boards
  99. * have their PHY ids in their configuration.
  100. */
  101. #define CHECK_ALL_KNOWN_PHY_IDS
  102. #if defined (MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
  103. /*!
  104. * The AT91SAM9260-EK board is delivered with RMII by default. Thus.
  105. * we use the reduced MII for this CPU. However, this should be
  106. * handled by the Configurator.
  107. */
  108. #define PHY_MODE_RMII
  109. //#define EMAC_PIO_PER PIOA_PER
  110. //#define EMAC_PIO_OER PIOA_OER
  111. //#define EMAC_PIO_CODR PIOA_CODR
  112. #define EMAC_PIO_ASR PIOA_ASR
  113. #define EMAC_PIO_BSR PIOA_BSR
  114. #define EMAC_PIO_PDR PIOA_PDR
  115. #define PHY_TXD0_BIT PA12_ETX0_A /*!< \brief Transmit data bit 0 pin. */
  116. #define PHY_TXD1_BIT PA13_ETX1_A /*!< \brief Transmit data bit 1 pin. */
  117. #define PHY_RXD0_AD0_BIT PA14_ERX0_A /*!< \brief Receive data bit 0 pin. */
  118. #define PHY_RXD1_AD1_BIT PA15_ERX1_A /*!< \brief Receive data bit 1 pin. */
  119. #define PHY_TXEN_BIT PA16_ETXEN_A /*!< \brief Transmit enable pin. */
  120. #define PHY_RXDV_TESTMODE_BIT PA17_ERXDV_A /*!< \brief Data valid pin. */
  121. #define PHY_RXER_RXD4_RPTR_BIT PA18_ERXER_A /*!< \brief Receive error pin. */
  122. #define PHY_TXCLK_ISOLATE_BIT PA19_ETXCK_A /*!< \brief Transmit clock pin. */
  123. #define PHY_MDC_BIT PA20_EMDC_A /*!< \brief Management data clock pin. */
  124. #define PHY_MDIO_BIT PA21_EMDIO_A /*!< \brief Management data I/O pin. */
  125. #ifndef PHY_MODE_RMII
  126. #define PHY_TXD2_BIT PA10_ETX2_B /*!< \brief Transmit data bit 2 pin. */
  127. #define PHY_TXD3_BIT PA11_ETX3_B /*!< \brief Transmit data bit 3 pin. */
  128. #define PHY_TXER_TXD4_BIT PA22_ETXER_B /*!< \brief Transmit error pin. */
  129. #define PHY_RXCLK_10BTSER_BIT PA27_ERXCK_B /*!< \brief Receive clock pin. */
  130. #define PHY_COL_RMII_BIT PA29_ECOL_B /*!< \brief Collision detect pin. */
  131. #endif
  132. #define PHY_RXD2_AD2_BIT PA25_ERX2_B /*!< \brief Receive data bit 2 pin. */
  133. #define PHY_RXD3_AD3_BIT PA26_ERX3_B /*!< \brief Receive data bit 3 pin. */
  134. #define PHY_CRS_AD4_BIT PA28_ECRS_B /*!< \brief Carrier sense pin. */
  135. #define PHY_MII_PINS_A 0 \
  136. | _BV(PHY_TXD0_BIT) \
  137. | _BV(PHY_TXD1_BIT) \
  138. | _BV(PHY_RXD0_AD0_BIT) \
  139. | _BV(PHY_RXD1_AD1_BIT) \
  140. | _BV(PHY_TXEN_BIT) \
  141. | _BV(PHY_RXDV_TESTMODE_BIT) \
  142. | _BV(PHY_RXER_RXD4_RPTR_BIT) \
  143. | _BV(PHY_TXCLK_ISOLATE_BIT) \
  144. | _BV(PHY_MDC_BIT) \
  145. | _BV(PHY_MDIO_BIT)
  146. #ifdef PHY_MODE_RMII
  147. #define PHY_MII_PINS_B 0
  148. #else
  149. #define PHY_MII_PINS_B 0 \
  150. | _BV(PHY_TXD2_BIT) \
  151. | _BV(PHY_TXD3_BIT) \
  152. | _BV(PHY_TXER_TXD4_BIT) \
  153. | _BV(PHY_RXD2_AD2_BIT) \
  154. | _BV(PHY_RXD3_AD3_BIT) \
  155. | _BV(PHY_RXCLK_10BTSER_BIT) \
  156. | _BV(PHY_CRS_AD4_BIT) \
  157. | _BV(PHY_COL_RMII_BIT)
  158. #endif
  159. #elif defined (MCU_AT91SAM7X)
  160. #define EMAC_PIO_PER PIOB_PER
  161. #define EMAC_PIO_OER PIOB_OER
  162. #define EMAC_PIO_CODR PIOB_CODR
  163. #define EMAC_PIO_SODR PIOB_SODR
  164. #define EMAC_PIO_PUER PIOB_PUER
  165. #define EMAC_PIO_PUDR PIOB_PUDR
  166. #define EMAC_PIO_ASR PIOB_ASR
  167. #define EMAC_PIO_BSR PIOB_BSR
  168. #define EMAC_PIO_PDR PIOB_PDR
  169. #define PHY_TXCLK_ISOLATE_BIT 0
  170. #define PHY_REFCLK_XT2_BIT 0
  171. #define PHY_TXEN_BIT 1
  172. #define PHY_TXD0_BIT 2
  173. #define PHY_TXD1_BIT 3
  174. #define PHY_CRS_AD4_BIT 4
  175. #define PHY_RXD0_AD0_BIT 5
  176. #define PHY_RXD1_AD1_BIT 6
  177. #define PHY_RXER_RXD4_RPTR_BIT 7
  178. #define PHY_MDC_BIT 8
  179. #define PHY_MDIO_BIT 9
  180. #define PHY_TXD2_BIT 10
  181. #define PHY_TXD3_BIT 11
  182. #define PHY_TXER_TXD4_BIT 12
  183. #define PHY_RXD2_AD2_BIT 13
  184. #define PHY_RXD3_AD3_BIT 14
  185. #define PHY_RXDV_TESTMODE_BIT 15
  186. #define PHY_COL_RMII_BIT 16
  187. #define PHY_RXCLK_10BTSER_BIT 17
  188. #define PHY_MDINTR_BIT 26
  189. #define PHY_MII_PINS_A 0 \
  190. | _BV(PHY_REFCLK_XT2_BIT) \
  191. | _BV(PHY_TXEN_BIT) \
  192. | _BV(PHY_TXD0_BIT) \
  193. | _BV(PHY_TXD1_BIT) \
  194. | _BV(PHY_CRS_AD4_BIT) \
  195. | _BV(PHY_RXD0_AD0_BIT) \
  196. | _BV(PHY_RXD1_AD1_BIT) \
  197. | _BV(PHY_RXER_RXD4_RPTR_BIT) \
  198. | _BV(PHY_MDC_BIT) \
  199. | _BV(PHY_MDIO_BIT) \
  200. | _BV(PHY_TXD2_BIT) \
  201. | _BV(PHY_TXD3_BIT) \
  202. | _BV(PHY_TXER_TXD4_BIT) \
  203. | _BV(PHY_RXD2_AD2_BIT) \
  204. | _BV(PHY_RXD3_AD3_BIT) \
  205. | _BV(PHY_RXDV_TESTMODE_BIT) \
  206. | _BV(PHY_COL_RMII_BIT) \
  207. | _BV(PHY_RXCLK_10BTSER_BIT)
  208. #define PHY_MII_PINS_B 0
  209. #endif
  210. /*!
  211. * \brief Network interface controller information structure.
  212. */
  213. struct _EMACINFO {
  214. #ifdef NUT_PERFMON
  215. uint32_t ni_rx_packets; /*!< Number of packets received. */
  216. uint32_t ni_tx_packets; /*!< Number of packets sent. */
  217. uint32_t ni_overruns; /*!< Number of packet overruns. */
  218. uint32_t ni_rx_frame_errors; /*!< Number of frame errors. */
  219. uint32_t ni_rx_crc_errors; /*!< Number of CRC errors. */
  220. uint32_t ni_rx_missed_errors; /*!< Number of missed packets. */
  221. #endif
  222. HANDLE volatile ni_rx_rdy; /*!< Receiver event queue. */
  223. HANDLE volatile ni_tx_rdy; /*!< Transmitter event queue. */
  224. HANDLE ni_mutex; /*!< Access mutex semaphore. */
  225. volatile int ni_tx_queued; /*!< Number of packets in transmission queue. */
  226. volatile int ni_tx_quelen; /*!< Number of bytes in transmission queue not sent. */
  227. volatile int ni_insane; /*!< Set by error detection. */
  228. int ni_iomode; /*!< 8 or 16 bit access. 32 bit is not supported. */
  229. };
  230. /*!
  231. * \brief Network interface controller information type.
  232. */
  233. typedef struct _EMACINFO EMACINFO;
  234. /*
  235. * TODO: Buffers and their descriptors should be part of the EMACINFO
  236. * structure. Actually there will be no dual Ethernet chip (sure?),
  237. * but just to keep the code clean.
  238. */
  239. typedef struct _BufDescriptor {
  240. unsigned int addr;
  241. unsigned int stat;
  242. } BufDescriptor;
  243. static volatile BufDescriptor txBufTab[EMAC_TX_BUFFERS];
  244. static volatile uint8_t txBuf[EMAC_TX_BUFFERS * EMAC_TX_BUFSIZ] NUT_ALIGNED_TYPE(8);
  245. static unsigned int txBufIdx;
  246. static volatile BufDescriptor rxBufTab[EMAC_RX_BUFFERS];
  247. static volatile uint8_t rxBuf[EMAC_RX_BUFFERS * EMAC_RX_BUFSIZ] NUT_ALIGNED_TYPE(8);
  248. static unsigned int rxBufIdx;
  249. #define RXBUF_OWNERSHIP 0x00000001
  250. #define RXBUF_WRAP 0x00000002
  251. #define RXBUF_ADDRMASK 0xFFFFFFFC
  252. #define RXS_BROADCAST_ADDR 0x80000000 /*!< \brief Broadcast address detected. */
  253. #define RXS_MULTICAST_HASH 0x40000000 /*!< \brief Multicast hash match. */
  254. #define RXS_UNICAST_HASH 0x20000000 /*!< \brief Unicast hash match. */
  255. #define RXS_EXTERNAL_ADDR 0x10000000 /*!< \brief External address match. */
  256. #define RXS_SA1_ADDR 0x04000000 /*!< \brief Specific address register 1 match. */
  257. #define RXS_SA2_ADDR 0x02000000 /*!< \brief Specific address register 2 match. */
  258. #define RXS_SA3_ADDR 0x01000000 /*!< \brief Specific address register 3 match. */
  259. #define RXS_SA4_ADDR 0x00800000 /*!< \brief Specific address register 4 match. */
  260. #define RXS_TYPE_ID 0x00400000 /*!< \brief Type ID match. */
  261. #define RXS_VLAN_TAG 0x00200000 /*!< \brief VLAN tag detected. */
  262. #define RXS_PRIORITY_TAG 0x00100000 /*!< \brief Priority tag detected. */
  263. #define RXS_VLAN_PRIORITY 0x000E0000 /*!< \brief VLAN priority. */
  264. #define RXS_CFI_IND 0x00010000 /*!< \brief Concatenation format indicator. */
  265. #define RXS_EOF 0x00008000 /*!< \brief End of frame. */
  266. #define RXS_SOF 0x00004000 /*!< \brief Start of frame. */
  267. #define RXS_RBF_OFFSET 0x00003000 /*!< \brief Receive buffer offset mask. */
  268. #define RXS_LENGTH_FRAME 0x000007FF /*!< \brief Length of frame including FCS. */
  269. #define TXS_USED 0x80000000 /*!< \brief Used buffer. */
  270. #define TXS_WRAP 0x40000000 /*!< \brief Last descriptor. */
  271. #define TXS_ERROR 0x20000000 /*!< \brief Retry limit exceeded. */
  272. #define TXS_UNDERRUN 0x10000000 /*!< \brief Transmit underrun. */
  273. #define TXS_NO_BUFFER 0x08000000 /*!< \brief Buffer exhausted. */
  274. #define TXS_NO_CRC 0x00010000 /*!< \brief CRC not appended. */
  275. #define TXS_LAST_BUFF 0x00008000 /*!< \brief Last buffer of frame. */
  276. #define MII_DM9161_ID 0x0181b8a0
  277. #define MII_AM79C875_ID 0x00225540
  278. #define MII_MICREL_ID 0x00221610
  279. #define MII_LAN8700_ID 0x0007c0c0
  280. #define MII_LAN8710_ID 0x0007C0F0
  281. /*!
  282. * \addtogroup xgNutArchArmAt91Emac
  283. */
  284. /*@{*/
  285. /*!
  286. * \brief Read contents of PHY register.
  287. *
  288. * \param reg PHY register number.
  289. *
  290. * \return Contents of the specified register.
  291. */
  292. static uint16_t phy_inw(uint8_t reg)
  293. {
  294. /* PHY read command. */
  295. outr(EMAC_MAN, EMAC_SOF | EMAC_RW_READ | EMAC_CODE |
  296. (NIC_PHY_ADDR << EMAC_PHYA_LSB) | (reg << EMAC_REGA_LSB));
  297. /* Wait until PHY logic completed. */
  298. while ((inr(EMAC_NSR) & EMAC_IDLE) == 0);
  299. /* Get data from PHY maintenance register. */
  300. return (uint16_t) (inr(EMAC_MAN) >> EMAC_DATA_LSB);
  301. }
  302. /*!
  303. * \brief Write value to PHY register.
  304. *
  305. * \param reg PHY register number.
  306. * \param val Value to write.
  307. */
  308. static void phy_outw(uint8_t reg, uint16_t val)
  309. {
  310. /* PHY write command. */
  311. outr(EMAC_MAN, EMAC_SOF | EMAC_RW_WRITE | EMAC_CODE |
  312. (NIC_PHY_ADDR << EMAC_PHYA_LSB) | (reg << EMAC_REGA_LSB) | val);
  313. /* Wait until PHY logic completed. */
  314. while ((inr(EMAC_NSR) & EMAC_IDLE) == 0);
  315. }
  316. /*!
  317. * \brief Reset the Ethernet controller.
  318. *
  319. * \return 0 on success, -1 otherwise.
  320. */
  321. static int EmacReset(uint32_t tmo)
  322. {
  323. int rc = 0;
  324. uint32_t reg_ncfgr;
  325. uint32_t phyval;
  326. int link_wait;
  327. EMPRINTF("EmacReset(%lu)\n", tmo);
  328. /* Enable power sources if not yet enabled */
  329. outr(PMC_PCER, _BV(PIOA_ID));
  330. outr(PMC_PCER, _BV(PIOB_ID));
  331. outr(PMC_PCER, _BV(EMAC_ID));
  332. /* Configure MII port. */
  333. outr(EMAC_PIO_ASR, PHY_MII_PINS_A);
  334. outr(EMAC_PIO_BSR, PHY_MII_PINS_B);
  335. outr(EMAC_PIO_PDR, PHY_MII_PINS_A | PHY_MII_PINS_B);
  336. /* Enable receive and transmit clocks and set MII mode. */
  337. #ifdef PHY_MODE_RMII
  338. outr(EMAC_USRIO, EMAC_RMII | EMAC_CLKEN);
  339. #else
  340. outr(EMAC_USRIO, EMAC_CLKEN);
  341. #endif
  342. /* Enable management port. */
  343. outr(EMAC_NCR, inr(EMAC_NCR) | EMAC_MPE);
  344. outr(EMAC_NCFGR, inr(EMAC_NCFGR) | EMAC_CLK_HCLK_64);
  345. /* Wait for PHY ready. */
  346. NutDelay(255);
  347. /* Register PHY */
  348. rc = NutRegisterPhy( 1, phy_outw, phy_inw);
  349. #if NIC_PHY_UID == MII_LAN8710_ID
  350. /* Set LAN8710 to AUTO-MDIX and MII mode.
  351. * This overides configuration set by config pins of the chip.
  352. */
  353. phyval = 18 << 16; // Store phy register address in upper 16 bits
  354. NutPhyCtl (PHY_GET_REGVAL, &phyval);
  355. phyval |= 0x00E0;
  356. phyval |= 18 << 16; // Store phy register address in upper 16 bits again
  357. NutPhyCtl (PHY_SET_REGVAL, &phyval);
  358. /* Soft Reset LAN7810 */
  359. phyval = 1;
  360. NutPhyCtl(PHY_CTL_RESET, &phyval);
  361. #endif
  362. #ifndef PHY_MODE_RMII
  363. /* Clear MII isolate. */
  364. phyval = 0;
  365. NutPhyCtl(PHY_CTL_ISOLATE, &phyval);
  366. #endif
  367. /* Restart autonegotiation */
  368. phyval = 1;
  369. NutPhyCtl(PHY_CTL_AUTONEG_RE, &phyval);
  370. /* Wait for auto negotiation completed and link established. */
  371. for (link_wait = tmo;; link_wait--) {
  372. phyval = 0;
  373. NutPhyCtl(PHY_GET_STATUS, &phyval);
  374. if((phyval & PHY_STATUS_HAS_LINK) && (phyval & PHY_STATUS_AUTONEG_OK)) {
  375. /* Check link state and configure EMAC accordingly */
  376. reg_ncfgr = inr(EMAC_NCFGR);
  377. if (phyval & PHY_STATUS_FULLDUPLEX) {
  378. reg_ncfgr |= EMAC_FD;
  379. } else {
  380. reg_ncfgr &= ~EMAC_FD;
  381. }
  382. if (phyval & PHY_STATUS_100M) {
  383. reg_ncfgr |= EMAC_SPD;
  384. } else {
  385. reg_ncfgr &= ~EMAC_SPD;
  386. }
  387. outr(EMAC_NCFGR, reg_ncfgr);
  388. break;
  389. }
  390. if (link_wait == 0) {
  391. EMPRINTF("NO LINK!\n");
  392. /* Return error on link timeout. */
  393. outr(EMAC_NCR, inr(EMAC_NCR) & ~EMAC_MPE);
  394. return -1;
  395. }
  396. NutSleep(10);
  397. }
  398. /* Disable management port. */
  399. outr(EMAC_NCR, inr(EMAC_NCR) & ~EMAC_MPE);
  400. EMPRINTF("EmacReset() DONE\n");
  401. return rc;
  402. }
  403. /*
  404. * NIC interrupt entry.
  405. */
  406. static void EmacInterrupt(void *arg)
  407. {
  408. unsigned int isr;
  409. EMACINFO *ni = (EMACINFO *) ((NUTDEVICE *) arg)->dev_dcb;
  410. /* Read interrupt status and disable interrupts. */
  411. isr = inr(EMAC_ISR);
  412. /* Receiver interrupt. */
  413. //if ((isr & EMAC_RCOMP) != 0 || (isr & EMAC_ROVR) != 0 || (inr(EMAC_RSR) & EMAC_REC) != 0) {
  414. if ((isr & (EMAC_RCOMP | EMAC_ROVR | EMAC_RXUBR)) != 0) {
  415. //outr(EMAC_RSR, EMAC_REC);
  416. outr(EMAC_IDR, EMAC_RCOMP | EMAC_ROVR | EMAC_RXUBR);
  417. NutEventPostFromIrq(&ni->ni_rx_rdy);
  418. }
  419. /* Transmitter interrupt. */
  420. if ((isr & EMAC_TCOMP) != 0 || (inr(EMAC_TSR) & EMAC_COMP) != 0) {
  421. //outr(EMAC_TSR, EMAC_COMP);
  422. NutEventPostFromIrq(&ni->ni_tx_rdy);
  423. }
  424. }
  425. /*!
  426. * \brief Fetch the next packet out of the receive buffers.
  427. *
  428. * \return 0 on success, -1 otherwise.
  429. */
  430. static int EmacGetPacket(EMACINFO * ni, NETBUF ** nbp)
  431. {
  432. int rc = -1;
  433. unsigned int fbc = 0;
  434. unsigned int i;
  435. *nbp = NULL;
  436. /*
  437. * Search the next frame start. Release any fragment.
  438. */
  439. while ((rxBufTab[rxBufIdx].addr & RXBUF_OWNERSHIP) != 0 && (rxBufTab[rxBufIdx].stat & RXS_SOF) == 0) {
  440. rxBufTab[rxBufIdx].addr &= ~(RXBUF_OWNERSHIP);
  441. rxBufIdx++;
  442. if (rxBufIdx >= EMAC_RX_BUFFERS) {
  443. rxBufIdx = 0;
  444. }
  445. }
  446. /*
  447. * Determine the size of the next frame.
  448. */
  449. i = rxBufIdx;
  450. while (rxBufTab[i].addr & RXBUF_OWNERSHIP) {
  451. if (i != rxBufIdx && (rxBufTab[i].stat & RXS_SOF) != 0) {
  452. do {
  453. rxBufTab[rxBufIdx].addr &= ~(RXBUF_OWNERSHIP);
  454. rxBufIdx++;
  455. if (rxBufIdx >= EMAC_RX_BUFFERS) {
  456. rxBufIdx = 0;
  457. }
  458. } while ((rxBufTab[rxBufIdx].addr & RXBUF_OWNERSHIP) != 0 && (rxBufTab[rxBufIdx].stat & RXS_SOF) == 0);
  459. break;
  460. }
  461. if ((fbc = rxBufTab[i].stat & RXS_LENGTH_FRAME) != 0) {
  462. break;
  463. }
  464. i++;
  465. if (i >= EMAC_RX_BUFFERS) {
  466. i = 0;
  467. }
  468. }
  469. if (fbc) {
  470. /*
  471. * Receiving long packets is unexpected. Let's declare the
  472. * chip insane. Short packets will be handled by the caller.
  473. */
  474. if (fbc > 1536) {
  475. ni->ni_insane = 1;
  476. } else {
  477. *nbp = NutNetBufAlloc(0, NBAF_DATALINK + 2, (uint16_t)fbc);
  478. if (*nbp != NULL) {
  479. uint8_t *bp = (uint8_t *) (* nbp)->nb_dl.vp;
  480. unsigned int len;
  481. while (fbc) {
  482. if (fbc > EMAC_RX_BUFSIZ) {
  483. len = EMAC_RX_BUFSIZ;
  484. } else {
  485. len = fbc;
  486. }
  487. memcpy(bp, (void *) (rxBufTab[rxBufIdx].addr & RXBUF_ADDRMASK), len);
  488. rxBufTab[rxBufIdx].addr &= ~RXBUF_OWNERSHIP;
  489. rxBufIdx++;
  490. if (rxBufIdx >= EMAC_RX_BUFFERS) {
  491. rxBufIdx = 0;
  492. }
  493. fbc -= len;
  494. bp += len;
  495. }
  496. rc = 0;
  497. }
  498. }
  499. }
  500. return rc;
  501. }
  502. /*!
  503. * \brief Load a packet into the nic's transmit ring buffer.
  504. *
  505. * \todo This routine simply does not work. Any idea?
  506. *
  507. * \param nb Network buffer structure containing the packet to be sent.
  508. * The structure must have been allocated by a previous
  509. * call NutNetBufAlloc(). This routine will automatically
  510. * release the buffer in case of an error.
  511. *
  512. * \return 0 on success, -1 in case of any errors. Errors
  513. * will automatically release the network buffer
  514. * structure.
  515. */
  516. static int EmacPutPacket(int bufnum, EMACINFO * ni, NETBUF * nb)
  517. {
  518. int rc = -1;
  519. unsigned int sz;
  520. uint8_t *buf;
  521. /*
  522. * Calculate the number of bytes to be send. Do not send packets
  523. * larger than the Ethernet maximum transfer unit. The MTU
  524. * consist of 1500 data bytes plus the 14 byte Ethernet header
  525. * plus 4 bytes CRC. We check the data bytes only.
  526. */
  527. if ((sz = nb->nb_nw.sz + nb->nb_tp.sz + nb->nb_ap.sz) > ETHERMTU) {
  528. return -1;
  529. }
  530. sz += nb->nb_dl.sz;
  531. if (sz & 1) {
  532. sz++;
  533. }
  534. /* Disable EMAC interrupts. */
  535. NutIrqDisable(&sig_EMAC);
  536. /* TODO: Check for link. */
  537. if (ni->ni_insane == 0) {
  538. buf = (uint8_t *) txBufTab[bufnum].addr;
  539. memcpy(buf, nb->nb_dl.vp, nb->nb_dl.sz);
  540. buf += nb->nb_dl.sz;
  541. memcpy(buf, nb->nb_nw.vp, nb->nb_nw.sz);
  542. buf += nb->nb_nw.sz;
  543. memcpy(buf, nb->nb_tp.vp, nb->nb_tp.sz);
  544. buf += nb->nb_tp.sz;
  545. memcpy(buf, nb->nb_ap.vp, nb->nb_ap.sz);
  546. sz |= TXS_LAST_BUFF;
  547. if (bufnum) {
  548. sz |= TXS_WRAP;
  549. }
  550. txBufTab[bufnum].stat = sz;
  551. outr(EMAC_NCR, inr(EMAC_NCR) | EMAC_TSTART);
  552. rc = 0;
  553. #ifdef NUT_PERFMON
  554. ni->ni_tx_packets++;
  555. #endif
  556. }
  557. /* Enable EMAC interrupts. */
  558. NutIrqEnable(&sig_EMAC);
  559. return rc;
  560. }
  561. /*!
  562. * \brief Fire up the network interface.
  563. *
  564. * NIC interrupts must be disabled when calling this function.
  565. *
  566. * \param mac Six byte unique MAC address.
  567. */
  568. static int EmacStart(const uint8_t * mac)
  569. {
  570. unsigned int i;
  571. EMPRINTF("EmacStart(%02x:%02x:%02x:%02x:%02x:%02x)\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
  572. /* Set local MAC address. */
  573. outr(EMAC_SA1L, (mac[3] << 24) | (mac[2] << 16) | (mac[1] << 8) | mac[0]);
  574. outr(EMAC_SA1H, (mac[5] << 8) | mac[4]);
  575. /* Initialize receive buffer descriptors. */
  576. for (i = 0; i < EMAC_RX_BUFFERS - 1; i++) {
  577. rxBufTab[i].addr = (unsigned int) (&rxBuf[i * EMAC_RX_BUFSIZ]) & RXBUF_ADDRMASK;
  578. }
  579. rxBufTab[i].addr = ((unsigned int) (&rxBuf[i * EMAC_RX_BUFSIZ]) & RXBUF_ADDRMASK) | RXBUF_WRAP;
  580. outr(EMAC_RBQP, (unsigned int) rxBufTab);
  581. /* Initialize transmit buffer descriptors. */
  582. txBufTab[0].addr = (unsigned int) (&txBuf[0]);
  583. txBufTab[0].stat = TXS_USED;
  584. txBufTab[1].addr = (unsigned int) (&txBuf[EMAC_TX_BUFSIZ]);
  585. txBufTab[1].stat = TXS_USED | TXS_WRAP;
  586. outr(EMAC_TBQP, (unsigned int) txBufTab);
  587. /* Clear receiver status. */
  588. outr(EMAC_RSR, EMAC_OVR | EMAC_REC | EMAC_BNA);
  589. /* Discard FCS. */
  590. outr(EMAC_NCFGR, inr(EMAC_NCFGR) | EMAC_DRFCS);
  591. /* Enable receiver, transmitter and statistics. */
  592. outr(EMAC_NCR, inr(EMAC_NCR) | EMAC_TE | EMAC_RE | EMAC_WESTAT);
  593. EMPRINTF("EmacStart() DONE\n");
  594. return 0;
  595. }
  596. /*! \fn EmacRxThread(void *arg)
  597. * \brief NIC receiver thread.
  598. *
  599. */
  600. THREAD(EmacRxThread, arg)
  601. {
  602. NUTDEVICE *dev = arg;
  603. IFNET *ifn = (IFNET *) dev->dev_icb;
  604. EMACINFO *ni = (EMACINFO *) dev->dev_dcb;
  605. NETBUF *nb;
  606. EMPRINTF("EmacRxThread() INIT\n");
  607. /*
  608. * This is a temporary hack. Due to a change in initialization,
  609. * we may not have got a MAC address yet. Wait until a valid one
  610. * has been set.
  611. */
  612. while (!ETHER_IS_UNICAST(ifn->if_mac)) {
  613. NutSleep(10);
  614. }
  615. /*
  616. * Do not continue unless we managed to start the NIC. We are
  617. * trapped here if the Ethernet link cannot be established.
  618. * This happens, for example, if no Ethernet cable is plugged
  619. * in.
  620. */
  621. EMPRINTF(" Call EmacStart()\n");
  622. while (EmacStart(ifn->if_mac)) {
  623. EmacReset(EMAC_LINK_LOOPS);
  624. NutSleep(1000);
  625. }
  626. /* Initialize the access mutex. */
  627. NutEventPost(&ni->ni_mutex);
  628. /* Run at high priority. */
  629. NutThreadSetPriority(9);
  630. /* Enable receive and transmit interrupts. */
  631. outr(EMAC_IER, EMAC_ROVR | EMAC_TCOMP | EMAC_TUND | EMAC_RXUBR | EMAC_RCOMP);
  632. NutIrqEnable(&sig_EMAC);
  633. for (;;) {
  634. /*
  635. * Wait for the arrival of new packets or poll the receiver every
  636. * 500 milliseconds. This short timeout helps a bit to deal with
  637. * the SAM9260 Ethernet problem.
  638. *
  639. * Sometimes an interrupt status change doesn't trigger an interrupt.
  640. * We need to read the status register, so that the flags get cleared
  641. * and the next change triggers an interrupt again.
  642. */
  643. if (NutEventWait(&ni->ni_rx_rdy, 500)) {
  644. inr(EMAC_ISR);
  645. }
  646. /*
  647. * Fetch all packets from the NIC's internal buffer and pass
  648. * them to the registered handler.
  649. */
  650. while (EmacGetPacket(ni, &nb) == 0) {
  651. /* Discard short packets. */
  652. if (nb->nb_dl.sz < 60) {
  653. NutNetBufFree(nb);
  654. } else {
  655. (*ifn->if_recv) (dev, nb);
  656. }
  657. }
  658. outr(EMAC_IER, EMAC_ROVR | EMAC_RXUBR | EMAC_RCOMP);
  659. /* We got a weird chip, try to restart it. */
  660. while (ni->ni_insane) {
  661. EmacReset(EMAC_LINK_LOOPS);
  662. if (EmacStart(ifn->if_mac) == 0) {
  663. ni->ni_insane = 0;
  664. ni->ni_tx_queued = 0;
  665. ni->ni_tx_quelen = 0;
  666. NutIrqEnable(&sig_EMAC);
  667. } else {
  668. NutSleep(1000);
  669. }
  670. }
  671. }
  672. }
  673. /*!
  674. * \brief Send Ethernet packet.
  675. *
  676. * \param dev Identifies the device to use.
  677. * \param nb Network buffer structure containing the packet to be sent.
  678. * The structure must have been allocated by a previous
  679. * call NutNetBufAlloc().
  680. *
  681. * \return 0 on success, -1 in case of any errors.
  682. */
  683. int EmacOutput(NUTDEVICE * dev, NETBUF * nb)
  684. {
  685. static uint32_t mx_wait = 5000;
  686. int rc = -1;
  687. EMACINFO *ni = (EMACINFO *) dev->dev_dcb;
  688. /*
  689. * After initialization we are waiting for a long time to give
  690. * the PHY a chance to establish an Ethernet link.
  691. */
  692. while (rc) {
  693. if (ni->ni_insane) {
  694. break;
  695. }
  696. if (NutEventWait(&ni->ni_mutex, mx_wait)) {
  697. break;
  698. }
  699. /* Check for packet queue space. */
  700. if ((txBufTab[txBufIdx].stat & TXS_USED) == 0) {
  701. if (NutEventWait(&ni->ni_tx_rdy, 500)) {
  702. /*
  703. * We may have a timeout here because the last status change
  704. * didn't trigger an interrupt. Reading the status register
  705. * will clear the current status and the next change triggers
  706. * an interrupt again, hopefully.
  707. */
  708. inr(EMAC_ISR);
  709. if ((txBufTab[txBufIdx].stat & TXS_USED) == 0) {
  710. /* No queue space. Release the lock and give up. */
  711. txBufTab[txBufIdx].stat |= TXS_USED;
  712. txBufIdx++;
  713. txBufIdx &= 1;
  714. NutEventPost(&ni->ni_mutex);
  715. break;
  716. }
  717. }
  718. } else {
  719. if (inr(EMAC_TSR) & EMAC_UND) {
  720. txBufIdx = 0;
  721. outr(EMAC_TSR, EMAC_UND);
  722. }
  723. if (inr(EMAC_TSR) & EMAC_COMP) {
  724. outr(EMAC_TSR, EMAC_COMP);
  725. }
  726. if ((rc = EmacPutPacket(txBufIdx, ni, nb)) == 0) {
  727. txBufIdx++;
  728. txBufIdx &= 1;
  729. }
  730. }
  731. NutEventPost(&ni->ni_mutex);
  732. }
  733. /*
  734. * Probably no Ethernet link. Significantly reduce the waiting
  735. * time, so following transmission will soon return an error.
  736. */
  737. if (rc) {
  738. mx_wait = 500;
  739. } else {
  740. /* Ethernet works. Set a long waiting time in case we
  741. temporarily lose the link next time. */
  742. mx_wait = 5000;
  743. }
  744. return rc;
  745. }
  746. /*!
  747. * \brief Initialize Ethernet hardware.
  748. *
  749. * Applications should do not directly call this function. It is
  750. * automatically executed during during device registration by
  751. * NutRegisterDevice().
  752. *
  753. * \param dev Identifies the device to initialize.
  754. */
  755. int EmacInit(NUTDEVICE * dev)
  756. {
  757. EMACINFO *ni = (EMACINFO *) dev->dev_dcb;
  758. EMPRINTF("EmacInit()\n");
  759. /* Reset the controller. */
  760. if (EmacReset(EMAC_LINK_LOOPS)) {
  761. if (EmacReset(EMAC_LINK_LOOPS)) {
  762. return -1;
  763. }
  764. }
  765. /* Clear EMACINFO structure. */
  766. memset(ni, 0, sizeof(EMACINFO));
  767. /* Register interrupt handler. */
  768. if (NutRegisterIrqHandler(&sig_EMAC, EmacInterrupt, dev)) {
  769. EMPRINTF(" IRQR CRASHED\n");
  770. return -1;
  771. }
  772. EMPRINTF(" IRQR OK\n");
  773. /* Start the receiver thread. */
  774. if (NutThreadCreate("emacrx", EmacRxThread, dev,
  775. (NUT_THREAD_NICRXSTACK * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD) == NULL) {
  776. EMPRINTF(" THREAD CRASHED\n");
  777. return -1;
  778. }
  779. EMPRINTF("EmacInit() DONE\n");
  780. return 0;
  781. }
  782. /*!
  783. * \brief Update the multicast hash.
  784. *
  785. * This function must be called after the multicast list changed.
  786. *
  787. * \param mclst Pointer to the first entry of the linked list of
  788. * multicast entries.
  789. */
  790. static void EmacHashUpdate(MCASTENTRY *mclst)
  791. {
  792. int i;
  793. int j;
  794. int b;
  795. int idx;
  796. uint32_t hash[2] = { 0, 0 };
  797. /* Determine the hash bit for each entry. */
  798. while (mclst) {
  799. /* For each bit of the index. */
  800. for (idx = 0, i = 0; i < 6; i++) {
  801. /* Xor every 6th bit in the address. */
  802. for (b = 0, j = i; j < 48; j += 6) {
  803. b ^= (mclst->mca_ha[j >> 3] & (1 << (j & 0x07))) != 0;
  804. }
  805. idx |= b << i;
  806. }
  807. /* Set the bit given by the 6 bit index. */
  808. hash[idx > 31] |= 1 << (idx & 31);
  809. mclst = mclst->mca_next;
  810. }
  811. /* Set result in the hash register. */
  812. outr(EMAC_HRB, hash[0]);
  813. outr(EMAC_HRT, hash[1]);
  814. /* Enable or disable multicast hash. */
  815. if (hash[0] || hash[1]) {
  816. outr(EMAC_NCFGR, inr(EMAC_NCFGR) | EMAC_MTI);
  817. } else {
  818. outr(EMAC_NCFGR, inr(EMAC_NCFGR) & ~EMAC_MTI);
  819. }
  820. }
  821. /*!
  822. * \brief Get multicast entry of a given IP address.
  823. *
  824. * \todo This function should be shared by all Ethernet drivers.
  825. *
  826. * \param ifn Pointer to the network interface structure.
  827. * \param ip IP address of the entry to retrieve.
  828. *
  829. * \return Pointer to the entry or NULL if none exists.
  830. */
  831. static MCASTENTRY *McastIpEntry(IFNET *ifn, uint32_t ip)
  832. {
  833. MCASTENTRY *mca = ifn->if_mcast;
  834. while (mca) {
  835. if (ip == mca->mca_ip) {
  836. break;
  837. }
  838. mca = mca->mca_next;
  839. }
  840. return mca;
  841. }
  842. /*!
  843. * \brief Add a given IP address to the multicast list.
  844. *
  845. * \todo This function should be shared by all Ethernet drivers.
  846. *
  847. * \param ifn Pointer to the network interface structure.
  848. * \param ip IP address of the new entry.
  849. *
  850. * \return Pointer to the requested entry, either a new one or
  851. * an already existing entry. In case of a failure, NULL
  852. * is returned.
  853. */
  854. static MCASTENTRY *McastAddEntry(IFNET *ifn, uint32_t ip)
  855. {
  856. MCASTENTRY *mca;
  857. mca = McastIpEntry(ifn, ip);
  858. if (mca == NULL) {
  859. mca = malloc(sizeof(MCASTENTRY));
  860. if (mca) {
  861. mca->mca_ip = ip;
  862. /* Set the IANA OUI. */
  863. mca->mca_ha[0] = 0x01;
  864. mca->mca_ha[1] = 0x00;
  865. mca->mca_ha[2] = 0x5e;
  866. /* Map the lower 23 bits of the IP address to the MAC address.
  867. Note that Nut/Net IP addresses are in network byte order. */
  868. mca->mca_ha[3] = (ip >> 8) & 0x7f;
  869. mca->mca_ha[4] = (ip >> 16) & 0xff;
  870. mca->mca_ha[5] = (ip >> 24) & 0xff;
  871. /* Add the new entry to the front of the list. */
  872. mca->mca_next = ifn->if_mcast;
  873. ifn->if_mcast = mca;
  874. /* Update the EMAC's multicast hash. */
  875. EmacHashUpdate(mca);
  876. }
  877. }
  878. return mca;
  879. }
  880. /*!
  881. * \brief Remove multicast entry of a given IP address.
  882. *
  883. * \param ifn Pointer to the network interface structure.
  884. * \param ip IP address of the entry to remove.
  885. */
  886. static void McastDelEntry(IFNET *ifn, uint32_t ip)
  887. {
  888. MCASTENTRY *mca = ifn->if_mcast;
  889. MCASTENTRY **lnk = &ifn->if_mcast;
  890. while (mca) {
  891. if (mca->mca_ip == ip) {
  892. *lnk = mca->mca_next;
  893. free(mca);
  894. break;
  895. }
  896. lnk = &mca->mca_next;
  897. mca = *lnk;
  898. }
  899. /* Update the EMAC's multicast hash. */
  900. EmacHashUpdate(mca);
  901. }
  902. /*!
  903. * \brief Perform Ethernet control functions.
  904. *
  905. * \param dev Identifies the device that receives the device-control
  906. * function.
  907. * \param req Requested control function. May be set to one of the
  908. * following constants:
  909. * - SIOCSIFADDR sets interface MAC address passed in buffer.
  910. * - SIOCGIFADDR copies current interface MAC address to buffer.
  911. * - SIOCADDMULTI adds multicast entry for IP in buffer.
  912. * - SIOCDELMULTI removes multicast entry of IP in buffer.
  913. * \param conf Points to a buffer that contains any data required for
  914. * the given control function or receives data from that
  915. * function.
  916. * \return 0 on success, -1 otherwise.
  917. *
  918. * \warning Timeout values are given in milliseconds and are limited to
  919. * the granularity of the system timer.
  920. *
  921. * \note For ATmega103, only 8 data bits, 1 stop bit and no parity are allowed.
  922. *
  923. */
  924. static int EmacIoCtl(NUTDEVICE * dev, int req, void *conf)
  925. {
  926. int rc = 0;
  927. IFNET *ifn = (IFNET *) dev->dev_icb;
  928. uint32_t ip;
  929. switch (req) {
  930. case SIOCSIFADDR:
  931. /* Set interface hardware address. */
  932. memcpy(ifn->if_mac, conf, sizeof(ifn->if_mac));
  933. break;
  934. case SIOCGIFADDR:
  935. /* Get interface hardware address. */
  936. memcpy(conf, ifn->if_mac, sizeof(ifn->if_mac));
  937. break;
  938. case SIOCADDMULTI:
  939. /* Add multicast address. */
  940. memcpy(&ip, conf, sizeof(ip));
  941. if (McastAddEntry(ifn, ip) == NULL) {
  942. rc = -1;
  943. }
  944. break;
  945. case SIOCDELMULTI:
  946. /* Delete multicast address. */
  947. memcpy(&ip, conf, sizeof(ip));
  948. McastDelEntry(ifn, ip);
  949. break;
  950. default:
  951. rc = -1;
  952. break;
  953. }
  954. return rc;
  955. }
  956. static EMACINFO dcb_eth0;
  957. /*!
  958. * \brief Network interface information structure.
  959. *
  960. * Used to call.
  961. */
  962. static IFNET ifn_eth0 = {
  963. IFT_ETHER, /*!< \brief Interface type, if_type. */
  964. 0, /*!< \brief Interface flags, if_flags. */
  965. {0, 0, 0, 0, 0, 0}, /*!< \brief Hardware net address, if_mac. */
  966. 0, /*!< \brief IP address, if_local_ip. */
  967. 0, /*!< \brief Remote IP address for point to point, if_remote_ip. */
  968. 0, /*!< \brief IP network mask, if_mask. */
  969. ETHERMTU, /*!< \brief Maximum size of a transmission unit, if_mtu. */
  970. 0, /*!< \brief Packet identifier, if_pkt_id. */
  971. 0, /*!< \brief Linked list of arp entries, arpTable. */
  972. 0, /*!< \brief Linked list of multicast address entries, if_mcast. */
  973. NutEtherInput, /*!< \brief Routine to pass received data to, if_recv(). */
  974. EmacOutput, /*!< \brief Driver output routine, if_send(). */
  975. NutEtherOutput, /*!< \brief Media output routine, if_output(). */
  976. NULL /*!< \brief Interface specific control function, if_ioctl(). */
  977. #ifdef NUT_PERFMON
  978. , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  979. #endif
  980. };
  981. /*!
  982. * \brief Device information structure.
  983. *
  984. * A pointer to this structure must be passed to NutRegisterDevice()
  985. * to bind this Ethernet device driver to the Nut/OS kernel.
  986. * An application may then call NutNetIfConfig() with the name \em eth0
  987. * of this driver to initialize the network interface.
  988. *
  989. */
  990. NUTDEVICE devAt91Emac = {
  991. 0, /*!< \brief Pointer to next device. */
  992. {'e', 't', 'h', '0', 0, 0, 0, 0, 0}, /*!< \brief Unique device name. */
  993. IFTYP_NET, /*!< \brief Type of device. */
  994. 0, /*!< \brief Base address. */
  995. 0, /*!< \brief First interrupt number. */
  996. &ifn_eth0, /*!< \brief Interface control block. */
  997. &dcb_eth0, /*!< \brief Driver control block. */
  998. EmacInit, /*!< \brief Driver initialization routine. */
  999. EmacIoCtl, /*!< \brief Driver specific control function. */
  1000. 0, /*!< \brief Read from device. */
  1001. 0, /*!< \brief Write to device. */
  1002. #ifdef __HARVARD_ARCH__
  1003. 0, /*!< \brief Write from program space data to device. */
  1004. #endif
  1005. 0, /*!< \brief Open a device or file. */
  1006. 0, /*!< \brief Close a device or file. */
  1007. 0, /*!< \brief Request file size. */
  1008. 0, /*!< \brief Select function, optional, not yet implemented */
  1009. };
  1010. /*@}*/