tsi108_eth.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. /***********************************************************************
  2. *
  3. * Copyright (c) 2005 Freescale Semiconductor, Inc.
  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. * Description:
  24. * Ethernet interface for Tundra TSI108 bridge chip
  25. *
  26. ***********************************************************************/
  27. #include <config.h>
  28. #if !defined(CONFIG_TSI108_ETH_NUM_PORTS) || (CONFIG_TSI108_ETH_NUM_PORTS > 2)
  29. #error "CONFIG_TSI108_ETH_NUM_PORTS must be defined as 1 or 2"
  30. #endif
  31. #include <common.h>
  32. #include <malloc.h>
  33. #include <net.h>
  34. #include <netdev.h>
  35. #include <asm/cache.h>
  36. #ifdef DEBUG
  37. #define TSI108_ETH_DEBUG 7
  38. #else
  39. #define TSI108_ETH_DEBUG 0
  40. #endif
  41. #if TSI108_ETH_DEBUG > 0
  42. #define debug_lev(lev, fmt, args...) \
  43. if (lev <= TSI108_ETH_DEBUG) \
  44. printf ("%s %d: " fmt, __FUNCTION__, __LINE__, ##args)
  45. #else
  46. #define debug_lev(lev, fmt, args...) do{}while(0)
  47. #endif
  48. #define RX_PRINT_ERRORS
  49. #define TX_PRINT_ERRORS
  50. #define ETH_BASE (CONFIG_SYS_TSI108_CSR_BASE + 0x6000)
  51. #define ETH_PORT_OFFSET 0x400
  52. #define __REG32(base, offset) (*((volatile u32 *)((char *)(base) + (offset))))
  53. #define reg_MAC_CONFIG_1(base) __REG32(base, 0x00000000)
  54. #define MAC_CONFIG_1_TX_ENABLE (0x00000001)
  55. #define MAC_CONFIG_1_SYNC_TX_ENABLE (0x00000002)
  56. #define MAC_CONFIG_1_RX_ENABLE (0x00000004)
  57. #define MAC_CONFIG_1_SYNC_RX_ENABLE (0x00000008)
  58. #define MAC_CONFIG_1_TX_FLOW_CONTROL (0x00000010)
  59. #define MAC_CONFIG_1_RX_FLOW_CONTROL (0x00000020)
  60. #define MAC_CONFIG_1_LOOP_BACK (0x00000100)
  61. #define MAC_CONFIG_1_RESET_TX_FUNCTION (0x00010000)
  62. #define MAC_CONFIG_1_RESET_RX_FUNCTION (0x00020000)
  63. #define MAC_CONFIG_1_RESET_TX_MAC (0x00040000)
  64. #define MAC_CONFIG_1_RESET_RX_MAC (0x00080000)
  65. #define MAC_CONFIG_1_SIM_RESET (0x40000000)
  66. #define MAC_CONFIG_1_SOFT_RESET (0x80000000)
  67. #define reg_MAC_CONFIG_2(base) __REG32(base, 0x00000004)
  68. #define MAC_CONFIG_2_FULL_DUPLEX (0x00000001)
  69. #define MAC_CONFIG_2_CRC_ENABLE (0x00000002)
  70. #define MAC_CONFIG_2_PAD_CRC (0x00000004)
  71. #define MAC_CONFIG_2_LENGTH_CHECK (0x00000010)
  72. #define MAC_CONFIG_2_HUGE_FRAME (0x00000020)
  73. #define MAC_CONFIG_2_INTERFACE_MODE(val) (((val) & 0x3) << 8)
  74. #define MAC_CONFIG_2_PREAMBLE_LENGTH(val) (((val) & 0xf) << 12)
  75. #define INTERFACE_MODE_NIBBLE 1 /* 10/100 Mb/s MII) */
  76. #define INTERFACE_MODE_BYTE 2 /* 1000 Mb/s GMII/TBI */
  77. #define reg_MAXIMUM_FRAME_LENGTH(base) __REG32(base, 0x00000010)
  78. #define reg_MII_MGMT_CONFIG(base) __REG32(base, 0x00000020)
  79. #define MII_MGMT_CONFIG_MGMT_CLOCK_SELECT(val) ((val) & 0x7)
  80. #define MII_MGMT_CONFIG_NO_PREAMBLE (0x00000010)
  81. #define MII_MGMT_CONFIG_SCAN_INCREMENT (0x00000020)
  82. #define MII_MGMT_CONFIG_RESET_MGMT (0x80000000)
  83. #define reg_MII_MGMT_COMMAND(base) __REG32(base, 0x00000024)
  84. #define MII_MGMT_COMMAND_READ_CYCLE (0x00000001)
  85. #define MII_MGMT_COMMAND_SCAN_CYCLE (0x00000002)
  86. #define reg_MII_MGMT_ADDRESS(base) __REG32(base, 0x00000028)
  87. #define reg_MII_MGMT_CONTROL(base) __REG32(base, 0x0000002c)
  88. #define reg_MII_MGMT_STATUS(base) __REG32(base, 0x00000030)
  89. #define reg_MII_MGMT_INDICATORS(base) __REG32(base, 0x00000034)
  90. #define MII_MGMT_INDICATORS_BUSY (0x00000001)
  91. #define MII_MGMT_INDICATORS_SCAN (0x00000002)
  92. #define MII_MGMT_INDICATORS_NOT_VALID (0x00000004)
  93. #define reg_INTERFACE_STATUS(base) __REG32(base, 0x0000003c)
  94. #define INTERFACE_STATUS_LINK_FAIL (0x00000008)
  95. #define INTERFACE_STATUS_EXCESS_DEFER (0x00000200)
  96. #define reg_STATION_ADDRESS_1(base) __REG32(base, 0x00000040)
  97. #define reg_STATION_ADDRESS_2(base) __REG32(base, 0x00000044)
  98. #define reg_PORT_CONTROL(base) __REG32(base, 0x00000200)
  99. #define PORT_CONTROL_PRI (0x00000001)
  100. #define PORT_CONTROL_BPT (0x00010000)
  101. #define PORT_CONTROL_SPD (0x00040000)
  102. #define PORT_CONTROL_RBC (0x00080000)
  103. #define PORT_CONTROL_PRB (0x00200000)
  104. #define PORT_CONTROL_DIS (0x00400000)
  105. #define PORT_CONTROL_TBI (0x00800000)
  106. #define PORT_CONTROL_STE (0x10000000)
  107. #define PORT_CONTROL_ZOR (0x20000000)
  108. #define PORT_CONTROL_CLR (0x40000000)
  109. #define PORT_CONTROL_SRT (0x80000000)
  110. #define reg_TX_CONFIG(base) __REG32(base, 0x00000220)
  111. #define TX_CONFIG_START_Q (0x00000003)
  112. #define TX_CONFIG_EHP (0x00400000)
  113. #define TX_CONFIG_CHP (0x00800000)
  114. #define TX_CONFIG_RST (0x80000000)
  115. #define reg_TX_CONTROL(base) __REG32(base, 0x00000224)
  116. #define TX_CONTROL_GO (0x00008000)
  117. #define TX_CONTROL_MP (0x01000000)
  118. #define TX_CONTROL_EAI (0x20000000)
  119. #define TX_CONTROL_ABT (0x40000000)
  120. #define TX_CONTROL_EII (0x80000000)
  121. #define reg_TX_STATUS(base) __REG32(base, 0x00000228)
  122. #define TX_STATUS_QUEUE_USABLE (0x0000000f)
  123. #define TX_STATUS_CURR_Q (0x00000300)
  124. #define TX_STATUS_ACT (0x00008000)
  125. #define TX_STATUS_QUEUE_IDLE (0x000f0000)
  126. #define TX_STATUS_EOQ_PENDING (0x0f000000)
  127. #define reg_TX_EXTENDED_STATUS(base) __REG32(base, 0x0000022c)
  128. #define TX_EXTENDED_STATUS_END_OF_QUEUE_CONDITION (0x0000000f)
  129. #define TX_EXTENDED_STATUS_END_OF_FRAME_CONDITION (0x00000f00)
  130. #define TX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
  131. #define TX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
  132. #define reg_TX_THRESHOLDS(base) __REG32(base, 0x00000230)
  133. #define reg_TX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000270)
  134. #define TX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
  135. #define TX_DIAGNOSTIC_ADDR_DFR (0x40000000)
  136. #define TX_DIAGNOSTIC_ADDR_AI (0x80000000)
  137. #define reg_TX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000274)
  138. #define reg_TX_ERROR_STATUS(base) __REG32(base, 0x00000278)
  139. #define TX_ERROR_STATUS (0x00000278)
  140. #define TX_ERROR_STATUS_QUEUE_0_ERROR_RESPONSE (0x0000000f)
  141. #define TX_ERROR_STATUS_TEA_ON_QUEUE_0 (0x00000010)
  142. #define TX_ERROR_STATUS_RER_ON_QUEUE_0 (0x00000020)
  143. #define TX_ERROR_STATUS_TER_ON_QUEUE_0 (0x00000040)
  144. #define TX_ERROR_STATUS_DER_ON_QUEUE_0 (0x00000080)
  145. #define TX_ERROR_STATUS_QUEUE_1_ERROR_RESPONSE (0x00000f00)
  146. #define TX_ERROR_STATUS_TEA_ON_QUEUE_1 (0x00001000)
  147. #define TX_ERROR_STATUS_RER_ON_QUEUE_1 (0x00002000)
  148. #define TX_ERROR_STATUS_TER_ON_QUEUE_1 (0x00004000)
  149. #define TX_ERROR_STATUS_DER_ON_QUEUE_1 (0x00008000)
  150. #define TX_ERROR_STATUS_QUEUE_2_ERROR_RESPONSE (0x000f0000)
  151. #define TX_ERROR_STATUS_TEA_ON_QUEUE_2 (0x00100000)
  152. #define TX_ERROR_STATUS_RER_ON_QUEUE_2 (0x00200000)
  153. #define TX_ERROR_STATUS_TER_ON_QUEUE_2 (0x00400000)
  154. #define TX_ERROR_STATUS_DER_ON_QUEUE_2 (0x00800000)
  155. #define TX_ERROR_STATUS_QUEUE_3_ERROR_RESPONSE (0x0f000000)
  156. #define TX_ERROR_STATUS_TEA_ON_QUEUE_3 (0x10000000)
  157. #define TX_ERROR_STATUS_RER_ON_QUEUE_3 (0x20000000)
  158. #define TX_ERROR_STATUS_TER_ON_QUEUE_3 (0x40000000)
  159. #define TX_ERROR_STATUS_DER_ON_QUEUE_3 (0x80000000)
  160. #define reg_TX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000280)
  161. #define TX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
  162. #define TX_QUEUE_0_CONFIG_BSWP (0x00000400)
  163. #define TX_QUEUE_0_CONFIG_WSWP (0x00000800)
  164. #define TX_QUEUE_0_CONFIG_AM (0x00004000)
  165. #define TX_QUEUE_0_CONFIG_GVI (0x00008000)
  166. #define TX_QUEUE_0_CONFIG_EEI (0x00010000)
  167. #define TX_QUEUE_0_CONFIG_ELI (0x00020000)
  168. #define TX_QUEUE_0_CONFIG_ENI (0x00040000)
  169. #define TX_QUEUE_0_CONFIG_ESI (0x00080000)
  170. #define TX_QUEUE_0_CONFIG_EDI (0x00100000)
  171. #define reg_TX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000284)
  172. #define TX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
  173. #define TX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
  174. #define TX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
  175. #define TX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
  176. #define OCN_PORT_HLP 0 /* HLP Interface */
  177. #define OCN_PORT_PCI_X 1 /* PCI-X Interface */
  178. #define OCN_PORT_PROCESSOR_MASTER 2 /* Processor Interface (master) */
  179. #define OCN_PORT_PROCESSOR_SLAVE 3 /* Processor Interface (slave) */
  180. #define OCN_PORT_MEMORY 4 /* Memory Controller */
  181. #define OCN_PORT_DMA 5 /* DMA Controller */
  182. #define OCN_PORT_ETHERNET 6 /* Ethernet Controller */
  183. #define OCN_PORT_PRINT 7 /* Print Engine Interface */
  184. #define reg_TX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000288)
  185. #define reg_TX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000028c)
  186. #define TX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
  187. #define reg_RX_CONFIG(base) __REG32(base, 0x00000320)
  188. #define RX_CONFIG_DEF_Q (0x00000003)
  189. #define RX_CONFIG_EMF (0x00000100)
  190. #define RX_CONFIG_EUF (0x00000200)
  191. #define RX_CONFIG_BFE (0x00000400)
  192. #define RX_CONFIG_MFE (0x00000800)
  193. #define RX_CONFIG_UFE (0x00001000)
  194. #define RX_CONFIG_SE (0x00002000)
  195. #define RX_CONFIG_ABF (0x00200000)
  196. #define RX_CONFIG_APE (0x00400000)
  197. #define RX_CONFIG_CHP (0x00800000)
  198. #define RX_CONFIG_RST (0x80000000)
  199. #define reg_RX_CONTROL(base) __REG32(base, 0x00000324)
  200. #define GE_E0_RX_CONTROL_QUEUE_ENABLES (0x0000000f)
  201. #define GE_E0_RX_CONTROL_GO (0x00008000)
  202. #define GE_E0_RX_CONTROL_EAI (0x20000000)
  203. #define GE_E0_RX_CONTROL_ABT (0x40000000)
  204. #define GE_E0_RX_CONTROL_EII (0x80000000)
  205. #define reg_RX_EXTENDED_STATUS(base) __REG32(base, 0x0000032c)
  206. #define RX_EXTENDED_STATUS (0x0000032c)
  207. #define RX_EXTENDED_STATUS_EOQ (0x0000000f)
  208. #define RX_EXTENDED_STATUS_EOQ_0 (0x00000001)
  209. #define RX_EXTENDED_STATUS_EOF (0x00000f00)
  210. #define RX_EXTENDED_STATUS_DESCRIPTOR_INTERRUPT_CONDITION (0x000f0000)
  211. #define RX_EXTENDED_STATUS_ERROR_FLAG (0x0f000000)
  212. #define reg_RX_THRESHOLDS(base) __REG32(base, 0x00000330)
  213. #define reg_RX_DIAGNOSTIC_ADDR(base) __REG32(base, 0x00000370)
  214. #define RX_DIAGNOSTIC_ADDR_INDEX (0x0000007f)
  215. #define RX_DIAGNOSTIC_ADDR_DFR (0x40000000)
  216. #define RX_DIAGNOSTIC_ADDR_AI (0x80000000)
  217. #define reg_RX_DIAGNOSTIC_DATA(base) __REG32(base, 0x00000374)
  218. #define reg_RX_QUEUE_0_CONFIG(base) __REG32(base, 0x00000380)
  219. #define RX_QUEUE_0_CONFIG_OCN_PORT (0x0000003f)
  220. #define RX_QUEUE_0_CONFIG_BSWP (0x00000400)
  221. #define RX_QUEUE_0_CONFIG_WSWP (0x00000800)
  222. #define RX_QUEUE_0_CONFIG_AM (0x00004000)
  223. #define RX_QUEUE_0_CONFIG_EEI (0x00010000)
  224. #define RX_QUEUE_0_CONFIG_ELI (0x00020000)
  225. #define RX_QUEUE_0_CONFIG_ENI (0x00040000)
  226. #define RX_QUEUE_0_CONFIG_ESI (0x00080000)
  227. #define RX_QUEUE_0_CONFIG_EDI (0x00100000)
  228. #define reg_RX_QUEUE_0_BUF_CONFIG(base) __REG32(base, 0x00000384)
  229. #define RX_QUEUE_0_BUF_CONFIG_OCN_PORT (0x0000003f)
  230. #define RX_QUEUE_0_BUF_CONFIG_BURST (0x00000300)
  231. #define RX_QUEUE_0_BUF_CONFIG_BSWP (0x00000400)
  232. #define RX_QUEUE_0_BUF_CONFIG_WSWP (0x00000800)
  233. #define reg_RX_QUEUE_0_PTR_LOW(base) __REG32(base, 0x00000388)
  234. #define reg_RX_QUEUE_0_PTR_HIGH(base) __REG32(base, 0x0000038c)
  235. #define RX_QUEUE_0_PTR_HIGH_VALID (0x80000000)
  236. /*
  237. * PHY register definitions
  238. */
  239. /* the first 15 PHY registers are standard. */
  240. #define PHY_CTRL_REG 0 /* Control Register */
  241. #define PHY_STATUS_REG 1 /* Status Regiser */
  242. #define PHY_ID1_REG 2 /* Phy Id Reg (word 1) */
  243. #define PHY_ID2_REG 3 /* Phy Id Reg (word 2) */
  244. #define PHY_AN_ADV_REG 4 /* Autoneg Advertisement */
  245. #define PHY_LP_ABILITY_REG 5 /* Link Partner Ability (Base Page) */
  246. #define PHY_AUTONEG_EXP_REG 6 /* Autoneg Expansion Reg */
  247. #define PHY_NEXT_PAGE_TX_REG 7 /* Next Page TX */
  248. #define PHY_LP_NEXT_PAGE_REG 8 /* Link Partner Next Page */
  249. #define PHY_1000T_CTRL_REG 9 /* 1000Base-T Control Reg */
  250. #define PHY_1000T_STATUS_REG 10 /* 1000Base-T Status Reg */
  251. #define PHY_EXT_STATUS_REG 11 /* Extended Status Reg */
  252. /*
  253. * PHY Register bit masks.
  254. */
  255. #define PHY_CTRL_RESET (1 << 15)
  256. #define PHY_CTRL_LOOPBACK (1 << 14)
  257. #define PHY_CTRL_SPEED0 (1 << 13)
  258. #define PHY_CTRL_AN_EN (1 << 12)
  259. #define PHY_CTRL_PWR_DN (1 << 11)
  260. #define PHY_CTRL_ISOLATE (1 << 10)
  261. #define PHY_CTRL_RESTART_AN (1 << 9)
  262. #define PHY_CTRL_FULL_DUPLEX (1 << 8)
  263. #define PHY_CTRL_CT_EN (1 << 7)
  264. #define PHY_CTRL_SPEED1 (1 << 6)
  265. #define PHY_STAT_100BASE_T4 (1 << 15)
  266. #define PHY_STAT_100BASE_X_FD (1 << 14)
  267. #define PHY_STAT_100BASE_X_HD (1 << 13)
  268. #define PHY_STAT_10BASE_T_FD (1 << 12)
  269. #define PHY_STAT_10BASE_T_HD (1 << 11)
  270. #define PHY_STAT_100BASE_T2_FD (1 << 10)
  271. #define PHY_STAT_100BASE_T2_HD (1 << 9)
  272. #define PHY_STAT_EXT_STAT (1 << 8)
  273. #define PHY_STAT_RESERVED (1 << 7)
  274. #define PHY_STAT_MFPS (1 << 6) /* Management Frames Preamble Suppression */
  275. #define PHY_STAT_AN_COMPLETE (1 << 5)
  276. #define PHY_STAT_REM_FAULT (1 << 4)
  277. #define PHY_STAT_AN_CAP (1 << 3)
  278. #define PHY_STAT_LINK_UP (1 << 2)
  279. #define PHY_STAT_JABBER (1 << 1)
  280. #define PHY_STAT_EXT_CAP (1 << 0)
  281. #define TBI_CONTROL_2 0x11
  282. #define TBI_CONTROL_2_ENABLE_COMMA_DETECT 0x0001
  283. #define TBI_CONTROL_2_ENABLE_WRAP 0x0002
  284. #define TBI_CONTROL_2_G_MII_MODE 0x0010
  285. #define TBI_CONTROL_2_RECEIVE_CLOCK_SELECT 0x0020
  286. #define TBI_CONTROL_2_AUTO_NEGOTIATION_SENSE 0x0100
  287. #define TBI_CONTROL_2_DISABLE_TRANSMIT_RUNNING_DISPARITY 0x1000
  288. #define TBI_CONTROL_2_DISABLE_RECEIVE_RUNNING_DISPARITY 0x2000
  289. #define TBI_CONTROL_2_SHORTCUT_LINK_TIMER 0x4000
  290. #define TBI_CONTROL_2_SOFT_RESET 0x8000
  291. /* marvel specific */
  292. #define MV1111_EXT_CTRL1_REG 16 /* PHY Specific Control Reg */
  293. #define MV1111_SPEC_STAT_REG 17 /* PHY Specific Status Reg */
  294. #define MV1111_EXT_CTRL2_REG 20 /* Extended PHY Specific Control Reg */
  295. /*
  296. * MARVELL 88E1111 PHY register bit masks
  297. */
  298. /* PHY Specific Status Register (MV1111_EXT_CTRL1_REG) */
  299. #define SPEC_STAT_SPEED_MASK (3 << 14)
  300. #define SPEC_STAT_FULL_DUP (1 << 13)
  301. #define SPEC_STAT_PAGE_RCVD (1 << 12)
  302. #define SPEC_STAT_RESOLVED (1 << 11) /* Speed and Duplex Resolved */
  303. #define SPEC_STAT_LINK_UP (1 << 10)
  304. #define SPEC_STAT_CABLE_LEN_MASK (7 << 7)/* Cable Length (100/1000 modes only) */
  305. #define SPEC_STAT_MDIX (1 << 6)
  306. #define SPEC_STAT_POLARITY (1 << 1)
  307. #define SPEC_STAT_JABBER (1 << 0)
  308. #define SPEED_1000 (2 << 14)
  309. #define SPEED_100 (1 << 14)
  310. #define SPEED_10 (0 << 14)
  311. #define TBI_ADDR 0x1E /* Ten Bit Interface address */
  312. /* negotiated link parameters */
  313. #define LINK_SPEED_UNKNOWN 0
  314. #define LINK_SPEED_10 1
  315. #define LINK_SPEED_100 2
  316. #define LINK_SPEED_1000 3
  317. #define LINK_DUPLEX_UNKNOWN 0
  318. #define LINK_DUPLEX_HALF 1
  319. #define LINK_DUPLEX_FULL 2
  320. static unsigned int phy_address[] = { 8, 9 };
  321. #define vuint32 volatile u32
  322. /* TX/RX buffer descriptors. MUST be cache line aligned in memory. (32 byte)
  323. * This structure is accessed by the ethernet DMA engine which means it
  324. * MUST be in LITTLE ENDIAN format */
  325. struct dma_descriptor {
  326. vuint32 start_addr0; /* buffer address, least significant bytes. */
  327. vuint32 start_addr1; /* buffer address, most significant bytes. */
  328. vuint32 next_descr_addr0;/* next descriptor address, least significant bytes. Must be 64-bit aligned. */
  329. vuint32 next_descr_addr1;/* next descriptor address, most significant bytes. */
  330. vuint32 vlan_byte_count;/* VLAN tag(top 2 bytes) and byte countt (bottom 2 bytes). */
  331. vuint32 config_status; /* Configuration/Status. */
  332. vuint32 reserved1; /* reserved to make the descriptor cache line aligned. */
  333. vuint32 reserved2; /* reserved to make the descriptor cache line aligned. */
  334. };
  335. /* last next descriptor address flag */
  336. #define DMA_DESCR_LAST (1 << 31)
  337. /* TX DMA descriptor config status bits */
  338. #define DMA_DESCR_TX_EOF (1 << 0) /* end of frame */
  339. #define DMA_DESCR_TX_SOF (1 << 1) /* start of frame */
  340. #define DMA_DESCR_TX_PFVLAN (1 << 2)
  341. #define DMA_DESCR_TX_HUGE (1 << 3)
  342. #define DMA_DESCR_TX_PAD (1 << 4)
  343. #define DMA_DESCR_TX_CRC (1 << 5)
  344. #define DMA_DESCR_TX_DESCR_INT (1 << 14)
  345. #define DMA_DESCR_TX_RETRY_COUNT 0x000F0000
  346. #define DMA_DESCR_TX_ONE_COLLISION (1 << 20)
  347. #define DMA_DESCR_TX_LATE_COLLISION (1 << 24)
  348. #define DMA_DESCR_TX_UNDERRUN (1 << 25)
  349. #define DMA_DESCR_TX_RETRY_LIMIT (1 << 26)
  350. #define DMA_DESCR_TX_OK (1 << 30)
  351. #define DMA_DESCR_TX_OWNER (1 << 31)
  352. /* RX DMA descriptor status bits */
  353. #define DMA_DESCR_RX_EOF (1 << 0)
  354. #define DMA_DESCR_RX_SOF (1 << 1)
  355. #define DMA_DESCR_RX_VTF (1 << 2)
  356. #define DMA_DESCR_RX_FRAME_IS_TYPE (1 << 3)
  357. #define DMA_DESCR_RX_SHORT_FRAME (1 << 4)
  358. #define DMA_DESCR_RX_HASH_MATCH (1 << 7)
  359. #define DMA_DESCR_RX_BAD_FRAME (1 << 8)
  360. #define DMA_DESCR_RX_OVERRUN (1 << 9)
  361. #define DMA_DESCR_RX_MAX_FRAME_LEN (1 << 11)
  362. #define DMA_DESCR_RX_CRC_ERROR (1 << 12)
  363. #define DMA_DESCR_RX_DESCR_INT (1 << 13)
  364. #define DMA_DESCR_RX_OWNER (1 << 15)
  365. #define RX_BUFFER_SIZE PKTSIZE
  366. #define NUM_RX_DESC PKTBUFSRX
  367. static struct dma_descriptor tx_descriptor __attribute__ ((aligned(32)));
  368. static struct dma_descriptor rx_descr_array[NUM_RX_DESC]
  369. __attribute__ ((aligned(32)));
  370. static struct dma_descriptor *rx_descr_current;
  371. static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis);
  372. static int tsi108_eth_send (struct eth_device *dev,
  373. volatile void *packet, int length);
  374. static int tsi108_eth_recv (struct eth_device *dev);
  375. static void tsi108_eth_halt (struct eth_device *dev);
  376. static unsigned int read_phy (unsigned int base,
  377. unsigned int phy_addr, unsigned int phy_reg);
  378. static void write_phy (unsigned int base,
  379. unsigned int phy_addr,
  380. unsigned int phy_reg, unsigned int phy_data);
  381. #if TSI108_ETH_DEBUG > 100
  382. /*
  383. * print phy debug infomation
  384. */
  385. static void dump_phy_regs (unsigned int phy_addr)
  386. {
  387. int i;
  388. printf ("PHY %d registers\n", phy_addr);
  389. for (i = 0; i <= 30; i++) {
  390. printf ("%2d 0x%04x\n", i, read_phy (ETH_BASE, phy_addr, i));
  391. }
  392. printf ("\n");
  393. }
  394. #else
  395. #define dump_phy_regs(base) do{}while(0)
  396. #endif
  397. #if TSI108_ETH_DEBUG > 100
  398. /*
  399. * print debug infomation
  400. */
  401. static void tx_diag_regs (unsigned int base)
  402. {
  403. int i;
  404. unsigned long dummy;
  405. printf ("TX diagnostics registers\n");
  406. reg_TX_DIAGNOSTIC_ADDR(base) = 0x00 | TX_DIAGNOSTIC_ADDR_AI;
  407. udelay (1000);
  408. dummy = reg_TX_DIAGNOSTIC_DATA(base);
  409. for (i = 0x00; i <= 0x05; i++) {
  410. udelay (1000);
  411. printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
  412. }
  413. reg_TX_DIAGNOSTIC_ADDR(base) = 0x40 | TX_DIAGNOSTIC_ADDR_AI;
  414. udelay (1000);
  415. dummy = reg_TX_DIAGNOSTIC_DATA(base);
  416. for (i = 0x40; i <= 0x47; i++) {
  417. udelay (1000);
  418. printf ("0x%02x 0x%08x\n", i, reg_TX_DIAGNOSTIC_DATA(base));
  419. }
  420. printf ("\n");
  421. }
  422. #else
  423. #define tx_diag_regs(base) do{}while(0)
  424. #endif
  425. #if TSI108_ETH_DEBUG > 100
  426. /*
  427. * print debug infomation
  428. */
  429. static void rx_diag_regs (unsigned int base)
  430. {
  431. int i;
  432. unsigned long dummy;
  433. printf ("RX diagnostics registers\n");
  434. reg_RX_DIAGNOSTIC_ADDR(base) = 0x00 | RX_DIAGNOSTIC_ADDR_AI;
  435. udelay (1000);
  436. dummy = reg_RX_DIAGNOSTIC_DATA(base);
  437. for (i = 0x00; i <= 0x05; i++) {
  438. udelay (1000);
  439. printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
  440. }
  441. reg_RX_DIAGNOSTIC_ADDR(base) = 0x40 | RX_DIAGNOSTIC_ADDR_AI;
  442. udelay (1000);
  443. dummy = reg_RX_DIAGNOSTIC_DATA(base);
  444. for (i = 0x08; i <= 0x0a; i++) {
  445. udelay (1000);
  446. printf ("0x%02x 0x%08x\n", i, reg_RX_DIAGNOSTIC_DATA(base));
  447. }
  448. printf ("\n");
  449. }
  450. #else
  451. #define rx_diag_regs(base) do{}while(0)
  452. #endif
  453. #if TSI108_ETH_DEBUG > 100
  454. /*
  455. * print debug infomation
  456. */
  457. static void debug_mii_regs (unsigned int base)
  458. {
  459. printf ("MII_MGMT_CONFIG 0x%08x\n", reg_MII_MGMT_CONFIG(base));
  460. printf ("MII_MGMT_COMMAND 0x%08x\n", reg_MII_MGMT_COMMAND(base));
  461. printf ("MII_MGMT_ADDRESS 0x%08x\n", reg_MII_MGMT_ADDRESS(base));
  462. printf ("MII_MGMT_CONTROL 0x%08x\n", reg_MII_MGMT_CONTROL(base));
  463. printf ("MII_MGMT_STATUS 0x%08x\n", reg_MII_MGMT_STATUS(base));
  464. printf ("MII_MGMT_INDICATORS 0x%08x\n", reg_MII_MGMT_INDICATORS(base));
  465. printf ("\n");
  466. }
  467. #else
  468. #define debug_mii_regs(base) do{}while(0)
  469. #endif
  470. /*
  471. * Wait until the phy bus is non-busy
  472. */
  473. static void phy_wait (unsigned int base, unsigned int condition)
  474. {
  475. int timeout;
  476. timeout = 0;
  477. while (reg_MII_MGMT_INDICATORS(base) & condition) {
  478. udelay (10);
  479. if (++timeout > 10000) {
  480. printf ("ERROR: timeout waiting for phy bus (%d)\n",
  481. condition);
  482. break;
  483. }
  484. }
  485. }
  486. /*
  487. * read phy register
  488. */
  489. static unsigned int read_phy (unsigned int base,
  490. unsigned int phy_addr, unsigned int phy_reg)
  491. {
  492. unsigned int value;
  493. phy_wait (base, MII_MGMT_INDICATORS_BUSY);
  494. reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
  495. /* Ensure that the Read Cycle bit is cleared prior to next read cycle */
  496. reg_MII_MGMT_COMMAND(base) = 0;
  497. /* start the read */
  498. reg_MII_MGMT_COMMAND(base) = MII_MGMT_COMMAND_READ_CYCLE;
  499. /* wait for the read to complete */
  500. phy_wait (base,
  501. MII_MGMT_INDICATORS_NOT_VALID | MII_MGMT_INDICATORS_BUSY);
  502. value = reg_MII_MGMT_STATUS(base);
  503. reg_MII_MGMT_COMMAND(base) = 0;
  504. return value;
  505. }
  506. /*
  507. * write phy register
  508. */
  509. static void write_phy (unsigned int base,
  510. unsigned int phy_addr,
  511. unsigned int phy_reg, unsigned int phy_data)
  512. {
  513. phy_wait (base, MII_MGMT_INDICATORS_BUSY);
  514. reg_MII_MGMT_ADDRESS(base) = (phy_addr << 8) | phy_reg;
  515. /* Ensure that the Read Cycle bit is cleared prior to next cycle */
  516. reg_MII_MGMT_COMMAND(base) = 0;
  517. /* start the write */
  518. reg_MII_MGMT_CONTROL(base) = phy_data;
  519. }
  520. /*
  521. * configure the marvell 88e1111 phy
  522. */
  523. static int marvell_88e_phy_config (struct eth_device *dev, int *speed,
  524. int *duplex)
  525. {
  526. unsigned long base;
  527. unsigned long phy_addr;
  528. unsigned int phy_status;
  529. unsigned int phy_spec_status;
  530. int timeout;
  531. int phy_speed;
  532. int phy_duplex;
  533. unsigned int value;
  534. phy_speed = LINK_SPEED_UNKNOWN;
  535. phy_duplex = LINK_DUPLEX_UNKNOWN;
  536. base = dev->iobase;
  537. phy_addr = (unsigned long)dev->priv;
  538. /* Take the PHY out of reset. */
  539. write_phy (ETH_BASE, phy_addr, PHY_CTRL_REG, PHY_CTRL_RESET);
  540. /* Wait for the reset process to complete. */
  541. udelay (10);
  542. timeout = 0;
  543. while ((phy_status =
  544. read_phy (ETH_BASE, phy_addr, PHY_CTRL_REG)) & PHY_CTRL_RESET) {
  545. udelay (10);
  546. if (++timeout > 10000) {
  547. printf ("ERROR: timeout waiting for phy reset\n");
  548. break;
  549. }
  550. }
  551. /* TBI Configuration. */
  552. write_phy (base, TBI_ADDR, TBI_CONTROL_2, TBI_CONTROL_2_G_MII_MODE |
  553. TBI_CONTROL_2_RECEIVE_CLOCK_SELECT);
  554. /* Wait for the link to be established. */
  555. timeout = 0;
  556. do {
  557. udelay (20000);
  558. phy_status = read_phy (ETH_BASE, phy_addr, PHY_STATUS_REG);
  559. if (++timeout > 100) {
  560. debug_lev(1, "ERROR: unable to establish link!!!\n");
  561. break;
  562. }
  563. } while ((phy_status & PHY_STAT_LINK_UP) == 0);
  564. if ((phy_status & PHY_STAT_LINK_UP) == 0)
  565. return 0;
  566. value = 0;
  567. phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
  568. if (phy_spec_status & SPEC_STAT_RESOLVED) {
  569. switch (phy_spec_status & SPEC_STAT_SPEED_MASK) {
  570. case SPEED_1000:
  571. phy_speed = LINK_SPEED_1000;
  572. value |= PHY_CTRL_SPEED1;
  573. break;
  574. case SPEED_100:
  575. phy_speed = LINK_SPEED_100;
  576. value |= PHY_CTRL_SPEED0;
  577. break;
  578. case SPEED_10:
  579. phy_speed = LINK_SPEED_10;
  580. break;
  581. }
  582. if (phy_spec_status & SPEC_STAT_FULL_DUP) {
  583. phy_duplex = LINK_DUPLEX_FULL;
  584. value |= PHY_CTRL_FULL_DUPLEX;
  585. } else
  586. phy_duplex = LINK_DUPLEX_HALF;
  587. }
  588. /* set TBI speed */
  589. write_phy (base, TBI_ADDR, PHY_CTRL_REG, value);
  590. write_phy (base, TBI_ADDR, PHY_AN_ADV_REG, 0x0060);
  591. #if TSI108_ETH_DEBUG > 0
  592. printf ("%s link is up", dev->name);
  593. phy_spec_status = read_phy (ETH_BASE, phy_addr, MV1111_SPEC_STAT_REG);
  594. if (phy_spec_status & SPEC_STAT_RESOLVED) {
  595. switch (phy_speed) {
  596. case LINK_SPEED_1000:
  597. printf (", 1000 Mbps");
  598. break;
  599. case LINK_SPEED_100:
  600. printf (", 100 Mbps");
  601. break;
  602. case LINK_SPEED_10:
  603. printf (", 10 Mbps");
  604. break;
  605. }
  606. if (phy_duplex == LINK_DUPLEX_FULL)
  607. printf (", Full duplex");
  608. else
  609. printf (", Half duplex");
  610. }
  611. printf ("\n");
  612. #endif
  613. dump_phy_regs (TBI_ADDR);
  614. if (speed)
  615. *speed = phy_speed;
  616. if (duplex)
  617. *duplex = phy_duplex;
  618. return 1;
  619. }
  620. /*
  621. * External interface
  622. *
  623. * register the tsi108 ethernet controllers with the multi-ethernet system
  624. */
  625. int tsi108_eth_initialize (bd_t * bis)
  626. {
  627. struct eth_device *dev;
  628. int index;
  629. for (index = 0; index < CONFIG_TSI108_ETH_NUM_PORTS; index++) {
  630. dev = (struct eth_device *)malloc(sizeof(struct eth_device));
  631. sprintf (dev->name, "TSI108_eth%d", index);
  632. dev->iobase = ETH_BASE + (index * ETH_PORT_OFFSET);
  633. dev->priv = (void *)(phy_address[index]);
  634. dev->init = tsi108_eth_probe;
  635. dev->halt = tsi108_eth_halt;
  636. dev->send = tsi108_eth_send;
  637. dev->recv = tsi108_eth_recv;
  638. eth_register(dev);
  639. }
  640. return index;
  641. }
  642. /*
  643. * probe for and initialize a single ethernet interface
  644. */
  645. static int tsi108_eth_probe (struct eth_device *dev, bd_t * bis)
  646. {
  647. unsigned long base;
  648. unsigned long value;
  649. int index;
  650. struct dma_descriptor *tx_descr;
  651. struct dma_descriptor *rx_descr;
  652. int speed;
  653. int duplex;
  654. base = dev->iobase;
  655. reg_PORT_CONTROL(base) = PORT_CONTROL_STE | PORT_CONTROL_BPT;
  656. /* Bring DMA/FIFO out of reset. */
  657. reg_TX_CONFIG(base) = 0x00000000;
  658. reg_RX_CONFIG(base) = 0x00000000;
  659. reg_TX_THRESHOLDS(base) = (192 << 16) | 192;
  660. reg_RX_THRESHOLDS(base) = (192 << 16) | 112;
  661. /* Bring MAC out of reset. */
  662. reg_MAC_CONFIG_1(base) = 0x00000000;
  663. /* DMA MAC configuration. */
  664. reg_MAC_CONFIG_1(base) =
  665. MAC_CONFIG_1_RX_ENABLE | MAC_CONFIG_1_TX_ENABLE;
  666. reg_MII_MGMT_CONFIG(base) = MII_MGMT_CONFIG_NO_PREAMBLE;
  667. reg_MAXIMUM_FRAME_LENGTH(base) = RX_BUFFER_SIZE;
  668. /* Note: Early tsi108 manual did not have correct byte order
  669. * for the station address.*/
  670. reg_STATION_ADDRESS_1(base) = (dev->enetaddr[5] << 24) |
  671. (dev->enetaddr[4] << 16) |
  672. (dev->enetaddr[3] << 8) | (dev->enetaddr[2] << 0);
  673. reg_STATION_ADDRESS_2(base) = (dev->enetaddr[1] << 24) |
  674. (dev->enetaddr[0] << 16);
  675. if (marvell_88e_phy_config(dev, &speed, &duplex) == 0)
  676. return -1;
  677. value =
  678. MAC_CONFIG_2_PREAMBLE_LENGTH(7) | MAC_CONFIG_2_PAD_CRC |
  679. MAC_CONFIG_2_CRC_ENABLE;
  680. if (speed == LINK_SPEED_1000)
  681. value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_BYTE);
  682. else {
  683. value |= MAC_CONFIG_2_INTERFACE_MODE(INTERFACE_MODE_NIBBLE);
  684. reg_PORT_CONTROL(base) |= PORT_CONTROL_SPD;
  685. }
  686. if (duplex == LINK_DUPLEX_FULL) {
  687. value |= MAC_CONFIG_2_FULL_DUPLEX;
  688. reg_PORT_CONTROL(base) &= ~PORT_CONTROL_BPT;
  689. } else
  690. reg_PORT_CONTROL(base) |= PORT_CONTROL_BPT;
  691. reg_MAC_CONFIG_2(base) = value;
  692. reg_RX_CONFIG(base) = RX_CONFIG_SE;
  693. reg_RX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
  694. reg_RX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
  695. /* initialize the RX DMA descriptors */
  696. rx_descr = &rx_descr_array[0];
  697. rx_descr_current = rx_descr;
  698. for (index = 0; index < NUM_RX_DESC; index++) {
  699. /* make sure the receive buffers are not in cache */
  700. invalidate_dcache_range((unsigned long)NetRxPackets[index],
  701. (unsigned long)NetRxPackets[index] +
  702. RX_BUFFER_SIZE);
  703. rx_descr->start_addr0 =
  704. cpu_to_le32((vuint32) NetRxPackets[index]);
  705. rx_descr->start_addr1 = 0;
  706. rx_descr->next_descr_addr0 =
  707. cpu_to_le32((vuint32) (rx_descr + 1));
  708. rx_descr->next_descr_addr1 = 0;
  709. rx_descr->vlan_byte_count = 0;
  710. rx_descr->config_status = cpu_to_le32((RX_BUFFER_SIZE << 16) |
  711. DMA_DESCR_RX_OWNER);
  712. rx_descr++;
  713. }
  714. rx_descr--;
  715. rx_descr->next_descr_addr0 = 0;
  716. rx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  717. /* Push the descriptors to RAM so the ethernet DMA can see them */
  718. invalidate_dcache_range((unsigned long)rx_descr_array,
  719. (unsigned long)rx_descr_array +
  720. sizeof(rx_descr_array));
  721. /* enable RX queue */
  722. reg_RX_CONTROL(base) = TX_CONTROL_GO | 0x01;
  723. reg_RX_QUEUE_0_PTR_LOW(base) = (u32) rx_descr_current;
  724. /* enable receive DMA */
  725. reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
  726. reg_TX_QUEUE_0_CONFIG(base) = OCN_PORT_MEMORY;
  727. reg_TX_QUEUE_0_BUF_CONFIG(base) = OCN_PORT_MEMORY;
  728. /* initialize the TX DMA descriptor */
  729. tx_descr = &tx_descriptor;
  730. tx_descr->start_addr0 = 0;
  731. tx_descr->start_addr1 = 0;
  732. tx_descr->next_descr_addr0 = 0;
  733. tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  734. tx_descr->vlan_byte_count = 0;
  735. tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OK |
  736. DMA_DESCR_TX_SOF |
  737. DMA_DESCR_TX_EOF);
  738. /* enable TX queue */
  739. reg_TX_CONTROL(base) = TX_CONTROL_GO | 0x01;
  740. return 0;
  741. }
  742. /*
  743. * send a packet
  744. */
  745. static int tsi108_eth_send (struct eth_device *dev,
  746. volatile void *packet, int length)
  747. {
  748. unsigned long base;
  749. int timeout;
  750. struct dma_descriptor *tx_descr;
  751. unsigned long status;
  752. base = dev->iobase;
  753. tx_descr = &tx_descriptor;
  754. /* Wait until the last packet has been transmitted. */
  755. timeout = 0;
  756. do {
  757. /* make sure we see the changes made by the DMA engine */
  758. invalidate_dcache_range((unsigned long)tx_descr,
  759. (unsigned long)tx_descr +
  760. sizeof(struct dma_descriptor));
  761. if (timeout != 0)
  762. udelay (15);
  763. if (++timeout > 10000) {
  764. tx_diag_regs(base);
  765. debug_lev(1,
  766. "ERROR: timeout waiting for last transmit packet to be sent\n");
  767. return 0;
  768. }
  769. } while (tx_descr->config_status & cpu_to_le32(DMA_DESCR_TX_OWNER));
  770. status = le32_to_cpu(tx_descr->config_status);
  771. if ((status & DMA_DESCR_TX_OK) == 0) {
  772. #ifdef TX_PRINT_ERRORS
  773. printf ("TX packet error: 0x%08lx\n %s%s%s%s\n", status,
  774. status & DMA_DESCR_TX_OK ? "tx error, " : "",
  775. status & DMA_DESCR_TX_RETRY_LIMIT ?
  776. "retry limit reached, " : "",
  777. status & DMA_DESCR_TX_UNDERRUN ? "underrun, " : "",
  778. status & DMA_DESCR_TX_LATE_COLLISION ? "late collision, "
  779. : "");
  780. #endif
  781. }
  782. debug_lev (9, "sending packet %d\n", length);
  783. tx_descr->start_addr0 = cpu_to_le32((vuint32) packet);
  784. tx_descr->start_addr1 = 0;
  785. tx_descr->next_descr_addr0 = 0;
  786. tx_descr->next_descr_addr1 = cpu_to_le32(DMA_DESCR_LAST);
  787. tx_descr->vlan_byte_count = cpu_to_le32(length);
  788. tx_descr->config_status = cpu_to_le32(DMA_DESCR_TX_OWNER |
  789. DMA_DESCR_TX_CRC |
  790. DMA_DESCR_TX_PAD |
  791. DMA_DESCR_TX_SOF |
  792. DMA_DESCR_TX_EOF);
  793. invalidate_dcache_range((unsigned long)tx_descr,
  794. (unsigned long)tx_descr +
  795. sizeof(struct dma_descriptor));
  796. invalidate_dcache_range((unsigned long)packet,
  797. (unsigned long)packet + length);
  798. reg_TX_QUEUE_0_PTR_LOW(base) = (u32) tx_descr;
  799. reg_TX_QUEUE_0_PTR_HIGH(base) = TX_QUEUE_0_PTR_HIGH_VALID;
  800. return length;
  801. }
  802. /*
  803. * Check for received packets and send them up the protocal stack
  804. */
  805. static int tsi108_eth_recv (struct eth_device *dev)
  806. {
  807. struct dma_descriptor *rx_descr;
  808. unsigned long base;
  809. int length = 0;
  810. unsigned long status;
  811. volatile uchar *buffer;
  812. base = dev->iobase;
  813. /* make sure we see the changes made by the DMA engine */
  814. invalidate_dcache_range ((unsigned long)rx_descr_array,
  815. (unsigned long)rx_descr_array +
  816. sizeof(rx_descr_array));
  817. /* process all of the received packets */
  818. rx_descr = rx_descr_current;
  819. while ((rx_descr->config_status & cpu_to_le32(DMA_DESCR_RX_OWNER)) == 0) {
  820. /* check for error */
  821. status = le32_to_cpu(rx_descr->config_status);
  822. if (status & DMA_DESCR_RX_BAD_FRAME) {
  823. #ifdef RX_PRINT_ERRORS
  824. printf ("RX packet error: 0x%08lx\n %s%s%s%s%s%s\n",
  825. status,
  826. status & DMA_DESCR_RX_FRAME_IS_TYPE ? "too big, "
  827. : "",
  828. status & DMA_DESCR_RX_SHORT_FRAME ? "too short, "
  829. : "",
  830. status & DMA_DESCR_RX_BAD_FRAME ? "bad frame, " :
  831. "",
  832. status & DMA_DESCR_RX_OVERRUN ? "overrun, " : "",
  833. status & DMA_DESCR_RX_MAX_FRAME_LEN ?
  834. "max length, " : "",
  835. status & DMA_DESCR_RX_CRC_ERROR ? "CRC error, " :
  836. "");
  837. #endif
  838. } else {
  839. length =
  840. le32_to_cpu(rx_descr->vlan_byte_count) & 0xFFFF;
  841. /*** process packet ***/
  842. buffer =
  843. (volatile uchar
  844. *)(le32_to_cpu (rx_descr->start_addr0));
  845. NetReceive (buffer, length);
  846. invalidate_dcache_range ((unsigned long)buffer,
  847. (unsigned long)buffer +
  848. RX_BUFFER_SIZE);
  849. }
  850. /* Give this buffer back to the DMA engine */
  851. rx_descr->vlan_byte_count = 0;
  852. rx_descr->config_status = cpu_to_le32 ((RX_BUFFER_SIZE << 16) |
  853. DMA_DESCR_RX_OWNER);
  854. /* move descriptor pointer forward */
  855. rx_descr =
  856. (struct dma_descriptor
  857. *)(le32_to_cpu (rx_descr->next_descr_addr0));
  858. if (rx_descr == 0)
  859. rx_descr = &rx_descr_array[0];
  860. }
  861. /* remember where we are for next time */
  862. rx_descr_current = rx_descr;
  863. /* If the DMA engine has reached the end of the queue
  864. * start over at the begining */
  865. if (reg_RX_EXTENDED_STATUS(base) & RX_EXTENDED_STATUS_EOQ_0) {
  866. reg_RX_EXTENDED_STATUS(base) = RX_EXTENDED_STATUS_EOQ_0;
  867. reg_RX_QUEUE_0_PTR_LOW(base) = (u32) & rx_descr_array[0];
  868. reg_RX_QUEUE_0_PTR_HIGH(base) = RX_QUEUE_0_PTR_HIGH_VALID;
  869. }
  870. return length;
  871. }
  872. /*
  873. * disable an ethernet interface
  874. */
  875. static void tsi108_eth_halt (struct eth_device *dev)
  876. {
  877. unsigned long base;
  878. base = dev->iobase;
  879. /* Put DMA/FIFO into reset state. */
  880. reg_TX_CONFIG(base) = TX_CONFIG_RST;
  881. reg_RX_CONFIG(base) = RX_CONFIG_RST;
  882. /* Put MAC into reset state. */
  883. reg_MAC_CONFIG_1(base) = MAC_CONFIG_1_SOFT_RESET;
  884. }