tsi108_eth.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. /*******************************************************************************
  2. Copyright(c) 2006 Tundra Semiconductor Corporation.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. *******************************************************************************/
  15. /* This driver is based on the driver code originally developed
  16. * for the Intel IOC80314 (ForestLake) Gigabit Ethernet by
  17. * scott.wood@timesys.com * Copyright (C) 2003 TimeSys Corporation
  18. *
  19. * Currently changes from original version are:
  20. * - porting to Tsi108-based platform and kernel 2.6 (kong.lai@tundra.com)
  21. * - modifications to handle two ports independently and support for
  22. * additional PHY devices (alexandre.bounine@tundra.com)
  23. * - Get hardware information from platform device. (tie-fei.zang@freescale.com)
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/types.h>
  28. #include <linux/init.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/net.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/etherdevice.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/delay.h>
  37. #include <linux/crc32.h>
  38. #include <linux/mii.h>
  39. #include <linux/device.h>
  40. #include <linux/pci.h>
  41. #include <linux/rtnetlink.h>
  42. #include <linux/timer.h>
  43. #include <linux/platform_device.h>
  44. #include <linux/gfp.h>
  45. #include <asm/system.h>
  46. #include <asm/io.h>
  47. #include <asm/tsi108.h>
  48. #include "tsi108_eth.h"
  49. #define MII_READ_DELAY 10000 /* max link wait time in msec */
  50. #define TSI108_RXRING_LEN 256
  51. /* NOTE: The driver currently does not support receiving packets
  52. * larger than the buffer size, so don't decrease this (unless you
  53. * want to add such support).
  54. */
  55. #define TSI108_RXBUF_SIZE 1536
  56. #define TSI108_TXRING_LEN 256
  57. #define TSI108_TX_INT_FREQ 64
  58. /* Check the phy status every half a second. */
  59. #define CHECK_PHY_INTERVAL (HZ/2)
  60. static int tsi108_init_one(struct platform_device *pdev);
  61. static int tsi108_ether_remove(struct platform_device *pdev);
  62. struct tsi108_prv_data {
  63. void __iomem *regs; /* Base of normal regs */
  64. void __iomem *phyregs; /* Base of register bank used for PHY access */
  65. struct net_device *dev;
  66. struct napi_struct napi;
  67. unsigned int phy; /* Index of PHY for this interface */
  68. unsigned int irq_num;
  69. unsigned int id;
  70. unsigned int phy_type;
  71. struct timer_list timer;/* Timer that triggers the check phy function */
  72. unsigned int rxtail; /* Next entry in rxring to read */
  73. unsigned int rxhead; /* Next entry in rxring to give a new buffer */
  74. unsigned int rxfree; /* Number of free, allocated RX buffers */
  75. unsigned int rxpending; /* Non-zero if there are still descriptors
  76. * to be processed from a previous descriptor
  77. * interrupt condition that has been cleared */
  78. unsigned int txtail; /* Next TX descriptor to check status on */
  79. unsigned int txhead; /* Next TX descriptor to use */
  80. /* Number of free TX descriptors. This could be calculated from
  81. * rxhead and rxtail if one descriptor were left unused to disambiguate
  82. * full and empty conditions, but it's simpler to just keep track
  83. * explicitly. */
  84. unsigned int txfree;
  85. unsigned int phy_ok; /* The PHY is currently powered on. */
  86. /* PHY status (duplex is 1 for half, 2 for full,
  87. * so that the default 0 indicates that neither has
  88. * yet been configured). */
  89. unsigned int link_up;
  90. unsigned int speed;
  91. unsigned int duplex;
  92. tx_desc *txring;
  93. rx_desc *rxring;
  94. struct sk_buff *txskbs[TSI108_TXRING_LEN];
  95. struct sk_buff *rxskbs[TSI108_RXRING_LEN];
  96. dma_addr_t txdma, rxdma;
  97. /* txlock nests in misclock and phy_lock */
  98. spinlock_t txlock, misclock;
  99. /* stats is used to hold the upper bits of each hardware counter,
  100. * and tmpstats is used to hold the full values for returning
  101. * to the caller of get_stats(). They must be separate in case
  102. * an overflow interrupt occurs before the stats are consumed.
  103. */
  104. struct net_device_stats stats;
  105. struct net_device_stats tmpstats;
  106. /* These stats are kept separate in hardware, thus require individual
  107. * fields for handling carry. They are combined in get_stats.
  108. */
  109. unsigned long rx_fcs; /* Add to rx_frame_errors */
  110. unsigned long rx_short_fcs; /* Add to rx_frame_errors */
  111. unsigned long rx_long_fcs; /* Add to rx_frame_errors */
  112. unsigned long rx_underruns; /* Add to rx_length_errors */
  113. unsigned long rx_overruns; /* Add to rx_length_errors */
  114. unsigned long tx_coll_abort; /* Add to tx_aborted_errors/collisions */
  115. unsigned long tx_pause_drop; /* Add to tx_aborted_errors */
  116. unsigned long mc_hash[16];
  117. u32 msg_enable; /* debug message level */
  118. struct mii_if_info mii_if;
  119. unsigned int init_media;
  120. };
  121. /* Structure for a device driver */
  122. static struct platform_driver tsi_eth_driver = {
  123. .probe = tsi108_init_one,
  124. .remove = tsi108_ether_remove,
  125. .driver = {
  126. .name = "tsi-ethernet",
  127. .owner = THIS_MODULE,
  128. },
  129. };
  130. static void tsi108_timed_checker(unsigned long dev_ptr);
  131. static void dump_eth_one(struct net_device *dev)
  132. {
  133. struct tsi108_prv_data *data = netdev_priv(dev);
  134. printk("Dumping %s...\n", dev->name);
  135. printk("intstat %x intmask %x phy_ok %d"
  136. " link %d speed %d duplex %d\n",
  137. TSI_READ(TSI108_EC_INTSTAT),
  138. TSI_READ(TSI108_EC_INTMASK), data->phy_ok,
  139. data->link_up, data->speed, data->duplex);
  140. printk("TX: head %d, tail %d, free %d, stat %x, estat %x, err %x\n",
  141. data->txhead, data->txtail, data->txfree,
  142. TSI_READ(TSI108_EC_TXSTAT),
  143. TSI_READ(TSI108_EC_TXESTAT),
  144. TSI_READ(TSI108_EC_TXERR));
  145. printk("RX: head %d, tail %d, free %d, stat %x,"
  146. " estat %x, err %x, pending %d\n\n",
  147. data->rxhead, data->rxtail, data->rxfree,
  148. TSI_READ(TSI108_EC_RXSTAT),
  149. TSI_READ(TSI108_EC_RXESTAT),
  150. TSI_READ(TSI108_EC_RXERR), data->rxpending);
  151. }
  152. /* Synchronization is needed between the thread and up/down events.
  153. * Note that the PHY is accessed through the same registers for both
  154. * interfaces, so this can't be made interface-specific.
  155. */
  156. static DEFINE_SPINLOCK(phy_lock);
  157. static int tsi108_read_mii(struct tsi108_prv_data *data, int reg)
  158. {
  159. unsigned i;
  160. TSI_WRITE_PHY(TSI108_MAC_MII_ADDR,
  161. (data->phy << TSI108_MAC_MII_ADDR_PHY) |
  162. (reg << TSI108_MAC_MII_ADDR_REG));
  163. TSI_WRITE_PHY(TSI108_MAC_MII_CMD, 0);
  164. TSI_WRITE_PHY(TSI108_MAC_MII_CMD, TSI108_MAC_MII_CMD_READ);
  165. for (i = 0; i < 100; i++) {
  166. if (!(TSI_READ_PHY(TSI108_MAC_MII_IND) &
  167. (TSI108_MAC_MII_IND_NOTVALID | TSI108_MAC_MII_IND_BUSY)))
  168. break;
  169. udelay(10);
  170. }
  171. if (i == 100)
  172. return 0xffff;
  173. else
  174. return TSI_READ_PHY(TSI108_MAC_MII_DATAIN);
  175. }
  176. static void tsi108_write_mii(struct tsi108_prv_data *data,
  177. int reg, u16 val)
  178. {
  179. unsigned i = 100;
  180. TSI_WRITE_PHY(TSI108_MAC_MII_ADDR,
  181. (data->phy << TSI108_MAC_MII_ADDR_PHY) |
  182. (reg << TSI108_MAC_MII_ADDR_REG));
  183. TSI_WRITE_PHY(TSI108_MAC_MII_DATAOUT, val);
  184. while (i--) {
  185. if(!(TSI_READ_PHY(TSI108_MAC_MII_IND) &
  186. TSI108_MAC_MII_IND_BUSY))
  187. break;
  188. udelay(10);
  189. }
  190. }
  191. static int tsi108_mdio_read(struct net_device *dev, int addr, int reg)
  192. {
  193. struct tsi108_prv_data *data = netdev_priv(dev);
  194. return tsi108_read_mii(data, reg);
  195. }
  196. static void tsi108_mdio_write(struct net_device *dev, int addr, int reg, int val)
  197. {
  198. struct tsi108_prv_data *data = netdev_priv(dev);
  199. tsi108_write_mii(data, reg, val);
  200. }
  201. static inline void tsi108_write_tbi(struct tsi108_prv_data *data,
  202. int reg, u16 val)
  203. {
  204. unsigned i = 1000;
  205. TSI_WRITE(TSI108_MAC_MII_ADDR,
  206. (0x1e << TSI108_MAC_MII_ADDR_PHY)
  207. | (reg << TSI108_MAC_MII_ADDR_REG));
  208. TSI_WRITE(TSI108_MAC_MII_DATAOUT, val);
  209. while(i--) {
  210. if(!(TSI_READ(TSI108_MAC_MII_IND) & TSI108_MAC_MII_IND_BUSY))
  211. return;
  212. udelay(10);
  213. }
  214. printk(KERN_ERR "%s function time out\n", __func__);
  215. }
  216. static int mii_speed(struct mii_if_info *mii)
  217. {
  218. int advert, lpa, val, media;
  219. int lpa2 = 0;
  220. int speed;
  221. if (!mii_link_ok(mii))
  222. return 0;
  223. val = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_BMSR);
  224. if ((val & BMSR_ANEGCOMPLETE) == 0)
  225. return 0;
  226. advert = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_ADVERTISE);
  227. lpa = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_LPA);
  228. media = mii_nway_result(advert & lpa);
  229. if (mii->supports_gmii)
  230. lpa2 = mii->mdio_read(mii->dev, mii->phy_id, MII_STAT1000);
  231. speed = lpa2 & (LPA_1000FULL | LPA_1000HALF) ? 1000 :
  232. (media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? 100 : 10);
  233. return speed;
  234. }
  235. static void tsi108_check_phy(struct net_device *dev)
  236. {
  237. struct tsi108_prv_data *data = netdev_priv(dev);
  238. u32 mac_cfg2_reg, portctrl_reg;
  239. u32 duplex;
  240. u32 speed;
  241. unsigned long flags;
  242. spin_lock_irqsave(&phy_lock, flags);
  243. if (!data->phy_ok)
  244. goto out;
  245. duplex = mii_check_media(&data->mii_if, netif_msg_link(data), data->init_media);
  246. data->init_media = 0;
  247. if (netif_carrier_ok(dev)) {
  248. speed = mii_speed(&data->mii_if);
  249. if ((speed != data->speed) || duplex) {
  250. mac_cfg2_reg = TSI_READ(TSI108_MAC_CFG2);
  251. portctrl_reg = TSI_READ(TSI108_EC_PORTCTRL);
  252. mac_cfg2_reg &= ~TSI108_MAC_CFG2_IFACE_MASK;
  253. if (speed == 1000) {
  254. mac_cfg2_reg |= TSI108_MAC_CFG2_GIG;
  255. portctrl_reg &= ~TSI108_EC_PORTCTRL_NOGIG;
  256. } else {
  257. mac_cfg2_reg |= TSI108_MAC_CFG2_NOGIG;
  258. portctrl_reg |= TSI108_EC_PORTCTRL_NOGIG;
  259. }
  260. data->speed = speed;
  261. if (data->mii_if.full_duplex) {
  262. mac_cfg2_reg |= TSI108_MAC_CFG2_FULLDUPLEX;
  263. portctrl_reg &= ~TSI108_EC_PORTCTRL_HALFDUPLEX;
  264. data->duplex = 2;
  265. } else {
  266. mac_cfg2_reg &= ~TSI108_MAC_CFG2_FULLDUPLEX;
  267. portctrl_reg |= TSI108_EC_PORTCTRL_HALFDUPLEX;
  268. data->duplex = 1;
  269. }
  270. TSI_WRITE(TSI108_MAC_CFG2, mac_cfg2_reg);
  271. TSI_WRITE(TSI108_EC_PORTCTRL, portctrl_reg);
  272. }
  273. if (data->link_up == 0) {
  274. /* The manual says it can take 3-4 usecs for the speed change
  275. * to take effect.
  276. */
  277. udelay(5);
  278. spin_lock(&data->txlock);
  279. if (is_valid_ether_addr(dev->dev_addr) && data->txfree)
  280. netif_wake_queue(dev);
  281. data->link_up = 1;
  282. spin_unlock(&data->txlock);
  283. }
  284. } else {
  285. if (data->link_up == 1) {
  286. netif_stop_queue(dev);
  287. data->link_up = 0;
  288. printk(KERN_NOTICE "%s : link is down\n", dev->name);
  289. }
  290. goto out;
  291. }
  292. out:
  293. spin_unlock_irqrestore(&phy_lock, flags);
  294. }
  295. static inline void
  296. tsi108_stat_carry_one(int carry, int carry_bit, int carry_shift,
  297. unsigned long *upper)
  298. {
  299. if (carry & carry_bit)
  300. *upper += carry_shift;
  301. }
  302. static void tsi108_stat_carry(struct net_device *dev)
  303. {
  304. struct tsi108_prv_data *data = netdev_priv(dev);
  305. u32 carry1, carry2;
  306. spin_lock_irq(&data->misclock);
  307. carry1 = TSI_READ(TSI108_STAT_CARRY1);
  308. carry2 = TSI_READ(TSI108_STAT_CARRY2);
  309. TSI_WRITE(TSI108_STAT_CARRY1, carry1);
  310. TSI_WRITE(TSI108_STAT_CARRY2, carry2);
  311. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXBYTES,
  312. TSI108_STAT_RXBYTES_CARRY, &data->stats.rx_bytes);
  313. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXPKTS,
  314. TSI108_STAT_RXPKTS_CARRY,
  315. &data->stats.rx_packets);
  316. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXFCS,
  317. TSI108_STAT_RXFCS_CARRY, &data->rx_fcs);
  318. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXMCAST,
  319. TSI108_STAT_RXMCAST_CARRY,
  320. &data->stats.multicast);
  321. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXALIGN,
  322. TSI108_STAT_RXALIGN_CARRY,
  323. &data->stats.rx_frame_errors);
  324. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXLENGTH,
  325. TSI108_STAT_RXLENGTH_CARRY,
  326. &data->stats.rx_length_errors);
  327. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXRUNT,
  328. TSI108_STAT_RXRUNT_CARRY, &data->rx_underruns);
  329. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXJUMBO,
  330. TSI108_STAT_RXJUMBO_CARRY, &data->rx_overruns);
  331. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXFRAG,
  332. TSI108_STAT_RXFRAG_CARRY, &data->rx_short_fcs);
  333. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXJABBER,
  334. TSI108_STAT_RXJABBER_CARRY, &data->rx_long_fcs);
  335. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXDROP,
  336. TSI108_STAT_RXDROP_CARRY,
  337. &data->stats.rx_missed_errors);
  338. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXBYTES,
  339. TSI108_STAT_TXBYTES_CARRY, &data->stats.tx_bytes);
  340. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXPKTS,
  341. TSI108_STAT_TXPKTS_CARRY,
  342. &data->stats.tx_packets);
  343. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXEXDEF,
  344. TSI108_STAT_TXEXDEF_CARRY,
  345. &data->stats.tx_aborted_errors);
  346. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXEXCOL,
  347. TSI108_STAT_TXEXCOL_CARRY, &data->tx_coll_abort);
  348. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXTCOL,
  349. TSI108_STAT_TXTCOL_CARRY,
  350. &data->stats.collisions);
  351. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXPAUSE,
  352. TSI108_STAT_TXPAUSEDROP_CARRY,
  353. &data->tx_pause_drop);
  354. spin_unlock_irq(&data->misclock);
  355. }
  356. /* Read a stat counter atomically with respect to carries.
  357. * data->misclock must be held.
  358. */
  359. static inline unsigned long
  360. tsi108_read_stat(struct tsi108_prv_data * data, int reg, int carry_bit,
  361. int carry_shift, unsigned long *upper)
  362. {
  363. int carryreg;
  364. unsigned long val;
  365. if (reg < 0xb0)
  366. carryreg = TSI108_STAT_CARRY1;
  367. else
  368. carryreg = TSI108_STAT_CARRY2;
  369. again:
  370. val = TSI_READ(reg) | *upper;
  371. /* Check to see if it overflowed, but the interrupt hasn't
  372. * been serviced yet. If so, handle the carry here, and
  373. * try again.
  374. */
  375. if (unlikely(TSI_READ(carryreg) & carry_bit)) {
  376. *upper += carry_shift;
  377. TSI_WRITE(carryreg, carry_bit);
  378. goto again;
  379. }
  380. return val;
  381. }
  382. static struct net_device_stats *tsi108_get_stats(struct net_device *dev)
  383. {
  384. unsigned long excol;
  385. struct tsi108_prv_data *data = netdev_priv(dev);
  386. spin_lock_irq(&data->misclock);
  387. data->tmpstats.rx_packets =
  388. tsi108_read_stat(data, TSI108_STAT_RXPKTS,
  389. TSI108_STAT_CARRY1_RXPKTS,
  390. TSI108_STAT_RXPKTS_CARRY, &data->stats.rx_packets);
  391. data->tmpstats.tx_packets =
  392. tsi108_read_stat(data, TSI108_STAT_TXPKTS,
  393. TSI108_STAT_CARRY2_TXPKTS,
  394. TSI108_STAT_TXPKTS_CARRY, &data->stats.tx_packets);
  395. data->tmpstats.rx_bytes =
  396. tsi108_read_stat(data, TSI108_STAT_RXBYTES,
  397. TSI108_STAT_CARRY1_RXBYTES,
  398. TSI108_STAT_RXBYTES_CARRY, &data->stats.rx_bytes);
  399. data->tmpstats.tx_bytes =
  400. tsi108_read_stat(data, TSI108_STAT_TXBYTES,
  401. TSI108_STAT_CARRY2_TXBYTES,
  402. TSI108_STAT_TXBYTES_CARRY, &data->stats.tx_bytes);
  403. data->tmpstats.multicast =
  404. tsi108_read_stat(data, TSI108_STAT_RXMCAST,
  405. TSI108_STAT_CARRY1_RXMCAST,
  406. TSI108_STAT_RXMCAST_CARRY, &data->stats.multicast);
  407. excol = tsi108_read_stat(data, TSI108_STAT_TXEXCOL,
  408. TSI108_STAT_CARRY2_TXEXCOL,
  409. TSI108_STAT_TXEXCOL_CARRY,
  410. &data->tx_coll_abort);
  411. data->tmpstats.collisions =
  412. tsi108_read_stat(data, TSI108_STAT_TXTCOL,
  413. TSI108_STAT_CARRY2_TXTCOL,
  414. TSI108_STAT_TXTCOL_CARRY, &data->stats.collisions);
  415. data->tmpstats.collisions += excol;
  416. data->tmpstats.rx_length_errors =
  417. tsi108_read_stat(data, TSI108_STAT_RXLENGTH,
  418. TSI108_STAT_CARRY1_RXLENGTH,
  419. TSI108_STAT_RXLENGTH_CARRY,
  420. &data->stats.rx_length_errors);
  421. data->tmpstats.rx_length_errors +=
  422. tsi108_read_stat(data, TSI108_STAT_RXRUNT,
  423. TSI108_STAT_CARRY1_RXRUNT,
  424. TSI108_STAT_RXRUNT_CARRY, &data->rx_underruns);
  425. data->tmpstats.rx_length_errors +=
  426. tsi108_read_stat(data, TSI108_STAT_RXJUMBO,
  427. TSI108_STAT_CARRY1_RXJUMBO,
  428. TSI108_STAT_RXJUMBO_CARRY, &data->rx_overruns);
  429. data->tmpstats.rx_frame_errors =
  430. tsi108_read_stat(data, TSI108_STAT_RXALIGN,
  431. TSI108_STAT_CARRY1_RXALIGN,
  432. TSI108_STAT_RXALIGN_CARRY,
  433. &data->stats.rx_frame_errors);
  434. data->tmpstats.rx_frame_errors +=
  435. tsi108_read_stat(data, TSI108_STAT_RXFCS,
  436. TSI108_STAT_CARRY1_RXFCS, TSI108_STAT_RXFCS_CARRY,
  437. &data->rx_fcs);
  438. data->tmpstats.rx_frame_errors +=
  439. tsi108_read_stat(data, TSI108_STAT_RXFRAG,
  440. TSI108_STAT_CARRY1_RXFRAG,
  441. TSI108_STAT_RXFRAG_CARRY, &data->rx_short_fcs);
  442. data->tmpstats.rx_missed_errors =
  443. tsi108_read_stat(data, TSI108_STAT_RXDROP,
  444. TSI108_STAT_CARRY1_RXDROP,
  445. TSI108_STAT_RXDROP_CARRY,
  446. &data->stats.rx_missed_errors);
  447. /* These three are maintained by software. */
  448. data->tmpstats.rx_fifo_errors = data->stats.rx_fifo_errors;
  449. data->tmpstats.rx_crc_errors = data->stats.rx_crc_errors;
  450. data->tmpstats.tx_aborted_errors =
  451. tsi108_read_stat(data, TSI108_STAT_TXEXDEF,
  452. TSI108_STAT_CARRY2_TXEXDEF,
  453. TSI108_STAT_TXEXDEF_CARRY,
  454. &data->stats.tx_aborted_errors);
  455. data->tmpstats.tx_aborted_errors +=
  456. tsi108_read_stat(data, TSI108_STAT_TXPAUSEDROP,
  457. TSI108_STAT_CARRY2_TXPAUSE,
  458. TSI108_STAT_TXPAUSEDROP_CARRY,
  459. &data->tx_pause_drop);
  460. data->tmpstats.tx_aborted_errors += excol;
  461. data->tmpstats.tx_errors = data->tmpstats.tx_aborted_errors;
  462. data->tmpstats.rx_errors = data->tmpstats.rx_length_errors +
  463. data->tmpstats.rx_crc_errors +
  464. data->tmpstats.rx_frame_errors +
  465. data->tmpstats.rx_fifo_errors + data->tmpstats.rx_missed_errors;
  466. spin_unlock_irq(&data->misclock);
  467. return &data->tmpstats;
  468. }
  469. static void tsi108_restart_rx(struct tsi108_prv_data * data, struct net_device *dev)
  470. {
  471. TSI_WRITE(TSI108_EC_RXQ_PTRHIGH,
  472. TSI108_EC_RXQ_PTRHIGH_VALID);
  473. TSI_WRITE(TSI108_EC_RXCTRL, TSI108_EC_RXCTRL_GO
  474. | TSI108_EC_RXCTRL_QUEUE0);
  475. }
  476. static void tsi108_restart_tx(struct tsi108_prv_data * data)
  477. {
  478. TSI_WRITE(TSI108_EC_TXQ_PTRHIGH,
  479. TSI108_EC_TXQ_PTRHIGH_VALID);
  480. TSI_WRITE(TSI108_EC_TXCTRL, TSI108_EC_TXCTRL_IDLEINT |
  481. TSI108_EC_TXCTRL_GO | TSI108_EC_TXCTRL_QUEUE0);
  482. }
  483. /* txlock must be held by caller, with IRQs disabled, and
  484. * with permission to re-enable them when the lock is dropped.
  485. */
  486. static void tsi108_complete_tx(struct net_device *dev)
  487. {
  488. struct tsi108_prv_data *data = netdev_priv(dev);
  489. int tx;
  490. struct sk_buff *skb;
  491. int release = 0;
  492. while (!data->txfree || data->txhead != data->txtail) {
  493. tx = data->txtail;
  494. if (data->txring[tx].misc & TSI108_TX_OWN)
  495. break;
  496. skb = data->txskbs[tx];
  497. if (!(data->txring[tx].misc & TSI108_TX_OK))
  498. printk("%s: bad tx packet, misc %x\n",
  499. dev->name, data->txring[tx].misc);
  500. data->txtail = (data->txtail + 1) % TSI108_TXRING_LEN;
  501. data->txfree++;
  502. if (data->txring[tx].misc & TSI108_TX_EOF) {
  503. dev_kfree_skb_any(skb);
  504. release++;
  505. }
  506. }
  507. if (release) {
  508. if (is_valid_ether_addr(dev->dev_addr) && data->link_up)
  509. netif_wake_queue(dev);
  510. }
  511. }
  512. static int tsi108_send_packet(struct sk_buff * skb, struct net_device *dev)
  513. {
  514. struct tsi108_prv_data *data = netdev_priv(dev);
  515. int frags = skb_shinfo(skb)->nr_frags + 1;
  516. int i;
  517. if (!data->phy_ok && net_ratelimit())
  518. printk(KERN_ERR "%s: Transmit while PHY is down!\n", dev->name);
  519. if (!data->link_up) {
  520. printk(KERN_ERR "%s: Transmit while link is down!\n",
  521. dev->name);
  522. netif_stop_queue(dev);
  523. return NETDEV_TX_BUSY;
  524. }
  525. if (data->txfree < MAX_SKB_FRAGS + 1) {
  526. netif_stop_queue(dev);
  527. if (net_ratelimit())
  528. printk(KERN_ERR "%s: Transmit with full tx ring!\n",
  529. dev->name);
  530. return NETDEV_TX_BUSY;
  531. }
  532. if (data->txfree - frags < MAX_SKB_FRAGS + 1) {
  533. netif_stop_queue(dev);
  534. }
  535. spin_lock_irq(&data->txlock);
  536. for (i = 0; i < frags; i++) {
  537. int misc = 0;
  538. int tx = data->txhead;
  539. /* This is done to mark every TSI108_TX_INT_FREQ tx buffers with
  540. * the interrupt bit. TX descriptor-complete interrupts are
  541. * enabled when the queue fills up, and masked when there is
  542. * still free space. This way, when saturating the outbound
  543. * link, the tx interrupts are kept to a reasonable level.
  544. * When the queue is not full, reclamation of skbs still occurs
  545. * as new packets are transmitted, or on a queue-empty
  546. * interrupt.
  547. */
  548. if ((tx % TSI108_TX_INT_FREQ == 0) &&
  549. ((TSI108_TXRING_LEN - data->txfree) >= TSI108_TX_INT_FREQ))
  550. misc = TSI108_TX_INT;
  551. data->txskbs[tx] = skb;
  552. if (i == 0) {
  553. data->txring[tx].buf0 = dma_map_single(NULL, skb->data,
  554. skb_headlen(skb), DMA_TO_DEVICE);
  555. data->txring[tx].len = skb_headlen(skb);
  556. misc |= TSI108_TX_SOF;
  557. } else {
  558. skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
  559. data->txring[tx].buf0 =
  560. dma_map_page(NULL, frag->page, frag->page_offset,
  561. frag->size, DMA_TO_DEVICE);
  562. data->txring[tx].len = frag->size;
  563. }
  564. if (i == frags - 1)
  565. misc |= TSI108_TX_EOF;
  566. if (netif_msg_pktdata(data)) {
  567. int i;
  568. printk("%s: Tx Frame contents (%d)\n", dev->name,
  569. skb->len);
  570. for (i = 0; i < skb->len; i++)
  571. printk(" %2.2x", skb->data[i]);
  572. printk(".\n");
  573. }
  574. data->txring[tx].misc = misc | TSI108_TX_OWN;
  575. data->txhead = (data->txhead + 1) % TSI108_TXRING_LEN;
  576. data->txfree--;
  577. }
  578. tsi108_complete_tx(dev);
  579. /* This must be done after the check for completed tx descriptors,
  580. * so that the tail pointer is correct.
  581. */
  582. if (!(TSI_READ(TSI108_EC_TXSTAT) & TSI108_EC_TXSTAT_QUEUE0))
  583. tsi108_restart_tx(data);
  584. spin_unlock_irq(&data->txlock);
  585. return NETDEV_TX_OK;
  586. }
  587. static int tsi108_complete_rx(struct net_device *dev, int budget)
  588. {
  589. struct tsi108_prv_data *data = netdev_priv(dev);
  590. int done = 0;
  591. while (data->rxfree && done != budget) {
  592. int rx = data->rxtail;
  593. struct sk_buff *skb;
  594. if (data->rxring[rx].misc & TSI108_RX_OWN)
  595. break;
  596. skb = data->rxskbs[rx];
  597. data->rxtail = (data->rxtail + 1) % TSI108_RXRING_LEN;
  598. data->rxfree--;
  599. done++;
  600. if (data->rxring[rx].misc & TSI108_RX_BAD) {
  601. spin_lock_irq(&data->misclock);
  602. if (data->rxring[rx].misc & TSI108_RX_CRC)
  603. data->stats.rx_crc_errors++;
  604. if (data->rxring[rx].misc & TSI108_RX_OVER)
  605. data->stats.rx_fifo_errors++;
  606. spin_unlock_irq(&data->misclock);
  607. dev_kfree_skb_any(skb);
  608. continue;
  609. }
  610. if (netif_msg_pktdata(data)) {
  611. int i;
  612. printk("%s: Rx Frame contents (%d)\n",
  613. dev->name, data->rxring[rx].len);
  614. for (i = 0; i < data->rxring[rx].len; i++)
  615. printk(" %2.2x", skb->data[i]);
  616. printk(".\n");
  617. }
  618. skb_put(skb, data->rxring[rx].len);
  619. skb->protocol = eth_type_trans(skb, dev);
  620. netif_receive_skb(skb);
  621. }
  622. return done;
  623. }
  624. static int tsi108_refill_rx(struct net_device *dev, int budget)
  625. {
  626. struct tsi108_prv_data *data = netdev_priv(dev);
  627. int done = 0;
  628. while (data->rxfree != TSI108_RXRING_LEN && done != budget) {
  629. int rx = data->rxhead;
  630. struct sk_buff *skb;
  631. skb = netdev_alloc_skb_ip_align(dev, TSI108_RXBUF_SIZE);
  632. data->rxskbs[rx] = skb;
  633. if (!skb)
  634. break;
  635. data->rxring[rx].buf0 = dma_map_single(NULL, skb->data,
  636. TSI108_RX_SKB_SIZE,
  637. DMA_FROM_DEVICE);
  638. /* Sometimes the hardware sets blen to zero after packet
  639. * reception, even though the manual says that it's only ever
  640. * modified by the driver.
  641. */
  642. data->rxring[rx].blen = TSI108_RX_SKB_SIZE;
  643. data->rxring[rx].misc = TSI108_RX_OWN | TSI108_RX_INT;
  644. data->rxhead = (data->rxhead + 1) % TSI108_RXRING_LEN;
  645. data->rxfree++;
  646. done++;
  647. }
  648. if (done != 0 && !(TSI_READ(TSI108_EC_RXSTAT) &
  649. TSI108_EC_RXSTAT_QUEUE0))
  650. tsi108_restart_rx(data, dev);
  651. return done;
  652. }
  653. static int tsi108_poll(struct napi_struct *napi, int budget)
  654. {
  655. struct tsi108_prv_data *data = container_of(napi, struct tsi108_prv_data, napi);
  656. struct net_device *dev = data->dev;
  657. u32 estat = TSI_READ(TSI108_EC_RXESTAT);
  658. u32 intstat = TSI_READ(TSI108_EC_INTSTAT);
  659. int num_received = 0, num_filled = 0;
  660. intstat &= TSI108_INT_RXQUEUE0 | TSI108_INT_RXTHRESH |
  661. TSI108_INT_RXOVERRUN | TSI108_INT_RXERROR | TSI108_INT_RXWAIT;
  662. TSI_WRITE(TSI108_EC_RXESTAT, estat);
  663. TSI_WRITE(TSI108_EC_INTSTAT, intstat);
  664. if (data->rxpending || (estat & TSI108_EC_RXESTAT_Q0_DESCINT))
  665. num_received = tsi108_complete_rx(dev, budget);
  666. /* This should normally fill no more slots than the number of
  667. * packets received in tsi108_complete_rx(). The exception
  668. * is when we previously ran out of memory for RX SKBs. In that
  669. * case, it's helpful to obey the budget, not only so that the
  670. * CPU isn't hogged, but so that memory (which may still be low)
  671. * is not hogged by one device.
  672. *
  673. * A work unit is considered to be two SKBs to allow us to catch
  674. * up when the ring has shrunk due to out-of-memory but we're
  675. * still removing the full budget's worth of packets each time.
  676. */
  677. if (data->rxfree < TSI108_RXRING_LEN)
  678. num_filled = tsi108_refill_rx(dev, budget * 2);
  679. if (intstat & TSI108_INT_RXERROR) {
  680. u32 err = TSI_READ(TSI108_EC_RXERR);
  681. TSI_WRITE(TSI108_EC_RXERR, err);
  682. if (err) {
  683. if (net_ratelimit())
  684. printk(KERN_DEBUG "%s: RX error %x\n",
  685. dev->name, err);
  686. if (!(TSI_READ(TSI108_EC_RXSTAT) &
  687. TSI108_EC_RXSTAT_QUEUE0))
  688. tsi108_restart_rx(data, dev);
  689. }
  690. }
  691. if (intstat & TSI108_INT_RXOVERRUN) {
  692. spin_lock_irq(&data->misclock);
  693. data->stats.rx_fifo_errors++;
  694. spin_unlock_irq(&data->misclock);
  695. }
  696. if (num_received < budget) {
  697. data->rxpending = 0;
  698. napi_complete(napi);
  699. TSI_WRITE(TSI108_EC_INTMASK,
  700. TSI_READ(TSI108_EC_INTMASK)
  701. & ~(TSI108_INT_RXQUEUE0
  702. | TSI108_INT_RXTHRESH |
  703. TSI108_INT_RXOVERRUN |
  704. TSI108_INT_RXERROR |
  705. TSI108_INT_RXWAIT));
  706. } else {
  707. data->rxpending = 1;
  708. }
  709. return num_received;
  710. }
  711. static void tsi108_rx_int(struct net_device *dev)
  712. {
  713. struct tsi108_prv_data *data = netdev_priv(dev);
  714. /* A race could cause dev to already be scheduled, so it's not an
  715. * error if that happens (and interrupts shouldn't be re-masked,
  716. * because that can cause harmful races, if poll has already
  717. * unmasked them but not cleared LINK_STATE_SCHED).
  718. *
  719. * This can happen if this code races with tsi108_poll(), which masks
  720. * the interrupts after tsi108_irq_one() read the mask, but before
  721. * napi_schedule is called. It could also happen due to calls
  722. * from tsi108_check_rxring().
  723. */
  724. if (napi_schedule_prep(&data->napi)) {
  725. /* Mask, rather than ack, the receive interrupts. The ack
  726. * will happen in tsi108_poll().
  727. */
  728. TSI_WRITE(TSI108_EC_INTMASK,
  729. TSI_READ(TSI108_EC_INTMASK) |
  730. TSI108_INT_RXQUEUE0
  731. | TSI108_INT_RXTHRESH |
  732. TSI108_INT_RXOVERRUN | TSI108_INT_RXERROR |
  733. TSI108_INT_RXWAIT);
  734. __napi_schedule(&data->napi);
  735. } else {
  736. if (!netif_running(dev)) {
  737. /* This can happen if an interrupt occurs while the
  738. * interface is being brought down, as the START
  739. * bit is cleared before the stop function is called.
  740. *
  741. * In this case, the interrupts must be masked, or
  742. * they will continue indefinitely.
  743. *
  744. * There's a race here if the interface is brought down
  745. * and then up in rapid succession, as the device could
  746. * be made running after the above check and before
  747. * the masking below. This will only happen if the IRQ
  748. * thread has a lower priority than the task brining
  749. * up the interface. Fixing this race would likely
  750. * require changes in generic code.
  751. */
  752. TSI_WRITE(TSI108_EC_INTMASK,
  753. TSI_READ
  754. (TSI108_EC_INTMASK) |
  755. TSI108_INT_RXQUEUE0 |
  756. TSI108_INT_RXTHRESH |
  757. TSI108_INT_RXOVERRUN |
  758. TSI108_INT_RXERROR |
  759. TSI108_INT_RXWAIT);
  760. }
  761. }
  762. }
  763. /* If the RX ring has run out of memory, try periodically
  764. * to allocate some more, as otherwise poll would never
  765. * get called (apart from the initial end-of-queue condition).
  766. *
  767. * This is called once per second (by default) from the thread.
  768. */
  769. static void tsi108_check_rxring(struct net_device *dev)
  770. {
  771. struct tsi108_prv_data *data = netdev_priv(dev);
  772. /* A poll is scheduled, as opposed to caling tsi108_refill_rx
  773. * directly, so as to keep the receive path single-threaded
  774. * (and thus not needing a lock).
  775. */
  776. if (netif_running(dev) && data->rxfree < TSI108_RXRING_LEN / 4)
  777. tsi108_rx_int(dev);
  778. }
  779. static void tsi108_tx_int(struct net_device *dev)
  780. {
  781. struct tsi108_prv_data *data = netdev_priv(dev);
  782. u32 estat = TSI_READ(TSI108_EC_TXESTAT);
  783. TSI_WRITE(TSI108_EC_TXESTAT, estat);
  784. TSI_WRITE(TSI108_EC_INTSTAT, TSI108_INT_TXQUEUE0 |
  785. TSI108_INT_TXIDLE | TSI108_INT_TXERROR);
  786. if (estat & TSI108_EC_TXESTAT_Q0_ERR) {
  787. u32 err = TSI_READ(TSI108_EC_TXERR);
  788. TSI_WRITE(TSI108_EC_TXERR, err);
  789. if (err && net_ratelimit())
  790. printk(KERN_ERR "%s: TX error %x\n", dev->name, err);
  791. }
  792. if (estat & (TSI108_EC_TXESTAT_Q0_DESCINT | TSI108_EC_TXESTAT_Q0_EOQ)) {
  793. spin_lock(&data->txlock);
  794. tsi108_complete_tx(dev);
  795. spin_unlock(&data->txlock);
  796. }
  797. }
  798. static irqreturn_t tsi108_irq(int irq, void *dev_id)
  799. {
  800. struct net_device *dev = dev_id;
  801. struct tsi108_prv_data *data = netdev_priv(dev);
  802. u32 stat = TSI_READ(TSI108_EC_INTSTAT);
  803. if (!(stat & TSI108_INT_ANY))
  804. return IRQ_NONE; /* Not our interrupt */
  805. stat &= ~TSI_READ(TSI108_EC_INTMASK);
  806. if (stat & (TSI108_INT_TXQUEUE0 | TSI108_INT_TXIDLE |
  807. TSI108_INT_TXERROR))
  808. tsi108_tx_int(dev);
  809. if (stat & (TSI108_INT_RXQUEUE0 | TSI108_INT_RXTHRESH |
  810. TSI108_INT_RXWAIT | TSI108_INT_RXOVERRUN |
  811. TSI108_INT_RXERROR))
  812. tsi108_rx_int(dev);
  813. if (stat & TSI108_INT_SFN) {
  814. if (net_ratelimit())
  815. printk(KERN_DEBUG "%s: SFN error\n", dev->name);
  816. TSI_WRITE(TSI108_EC_INTSTAT, TSI108_INT_SFN);
  817. }
  818. if (stat & TSI108_INT_STATCARRY) {
  819. tsi108_stat_carry(dev);
  820. TSI_WRITE(TSI108_EC_INTSTAT, TSI108_INT_STATCARRY);
  821. }
  822. return IRQ_HANDLED;
  823. }
  824. static void tsi108_stop_ethernet(struct net_device *dev)
  825. {
  826. struct tsi108_prv_data *data = netdev_priv(dev);
  827. int i = 1000;
  828. /* Disable all TX and RX queues ... */
  829. TSI_WRITE(TSI108_EC_TXCTRL, 0);
  830. TSI_WRITE(TSI108_EC_RXCTRL, 0);
  831. /* ...and wait for them to become idle */
  832. while(i--) {
  833. if(!(TSI_READ(TSI108_EC_TXSTAT) & TSI108_EC_TXSTAT_ACTIVE))
  834. break;
  835. udelay(10);
  836. }
  837. i = 1000;
  838. while(i--){
  839. if(!(TSI_READ(TSI108_EC_RXSTAT) & TSI108_EC_RXSTAT_ACTIVE))
  840. return;
  841. udelay(10);
  842. }
  843. printk(KERN_ERR "%s function time out\n", __func__);
  844. }
  845. static void tsi108_reset_ether(struct tsi108_prv_data * data)
  846. {
  847. TSI_WRITE(TSI108_MAC_CFG1, TSI108_MAC_CFG1_SOFTRST);
  848. udelay(100);
  849. TSI_WRITE(TSI108_MAC_CFG1, 0);
  850. TSI_WRITE(TSI108_EC_PORTCTRL, TSI108_EC_PORTCTRL_STATRST);
  851. udelay(100);
  852. TSI_WRITE(TSI108_EC_PORTCTRL,
  853. TSI_READ(TSI108_EC_PORTCTRL) &
  854. ~TSI108_EC_PORTCTRL_STATRST);
  855. TSI_WRITE(TSI108_EC_TXCFG, TSI108_EC_TXCFG_RST);
  856. udelay(100);
  857. TSI_WRITE(TSI108_EC_TXCFG,
  858. TSI_READ(TSI108_EC_TXCFG) &
  859. ~TSI108_EC_TXCFG_RST);
  860. TSI_WRITE(TSI108_EC_RXCFG, TSI108_EC_RXCFG_RST);
  861. udelay(100);
  862. TSI_WRITE(TSI108_EC_RXCFG,
  863. TSI_READ(TSI108_EC_RXCFG) &
  864. ~TSI108_EC_RXCFG_RST);
  865. TSI_WRITE(TSI108_MAC_MII_MGMT_CFG,
  866. TSI_READ(TSI108_MAC_MII_MGMT_CFG) |
  867. TSI108_MAC_MII_MGMT_RST);
  868. udelay(100);
  869. TSI_WRITE(TSI108_MAC_MII_MGMT_CFG,
  870. (TSI_READ(TSI108_MAC_MII_MGMT_CFG) &
  871. ~(TSI108_MAC_MII_MGMT_RST |
  872. TSI108_MAC_MII_MGMT_CLK)) | 0x07);
  873. }
  874. static int tsi108_get_mac(struct net_device *dev)
  875. {
  876. struct tsi108_prv_data *data = netdev_priv(dev);
  877. u32 word1 = TSI_READ(TSI108_MAC_ADDR1);
  878. u32 word2 = TSI_READ(TSI108_MAC_ADDR2);
  879. /* Note that the octets are reversed from what the manual says,
  880. * producing an even weirder ordering...
  881. */
  882. if (word2 == 0 && word1 == 0) {
  883. dev->dev_addr[0] = 0x00;
  884. dev->dev_addr[1] = 0x06;
  885. dev->dev_addr[2] = 0xd2;
  886. dev->dev_addr[3] = 0x00;
  887. dev->dev_addr[4] = 0x00;
  888. if (0x8 == data->phy)
  889. dev->dev_addr[5] = 0x01;
  890. else
  891. dev->dev_addr[5] = 0x02;
  892. word2 = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 24);
  893. word1 = (dev->dev_addr[2] << 0) | (dev->dev_addr[3] << 8) |
  894. (dev->dev_addr[4] << 16) | (dev->dev_addr[5] << 24);
  895. TSI_WRITE(TSI108_MAC_ADDR1, word1);
  896. TSI_WRITE(TSI108_MAC_ADDR2, word2);
  897. } else {
  898. dev->dev_addr[0] = (word2 >> 16) & 0xff;
  899. dev->dev_addr[1] = (word2 >> 24) & 0xff;
  900. dev->dev_addr[2] = (word1 >> 0) & 0xff;
  901. dev->dev_addr[3] = (word1 >> 8) & 0xff;
  902. dev->dev_addr[4] = (word1 >> 16) & 0xff;
  903. dev->dev_addr[5] = (word1 >> 24) & 0xff;
  904. }
  905. if (!is_valid_ether_addr(dev->dev_addr)) {
  906. printk(KERN_ERR
  907. "%s: Invalid MAC address. word1: %08x, word2: %08x\n",
  908. dev->name, word1, word2);
  909. return -EINVAL;
  910. }
  911. return 0;
  912. }
  913. static int tsi108_set_mac(struct net_device *dev, void *addr)
  914. {
  915. struct tsi108_prv_data *data = netdev_priv(dev);
  916. u32 word1, word2;
  917. int i;
  918. if (!is_valid_ether_addr(addr))
  919. return -EINVAL;
  920. for (i = 0; i < 6; i++)
  921. /* +2 is for the offset of the HW addr type */
  922. dev->dev_addr[i] = ((unsigned char *)addr)[i + 2];
  923. word2 = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 24);
  924. word1 = (dev->dev_addr[2] << 0) | (dev->dev_addr[3] << 8) |
  925. (dev->dev_addr[4] << 16) | (dev->dev_addr[5] << 24);
  926. spin_lock_irq(&data->misclock);
  927. TSI_WRITE(TSI108_MAC_ADDR1, word1);
  928. TSI_WRITE(TSI108_MAC_ADDR2, word2);
  929. spin_lock(&data->txlock);
  930. if (data->txfree && data->link_up)
  931. netif_wake_queue(dev);
  932. spin_unlock(&data->txlock);
  933. spin_unlock_irq(&data->misclock);
  934. return 0;
  935. }
  936. /* Protected by dev->xmit_lock. */
  937. static void tsi108_set_rx_mode(struct net_device *dev)
  938. {
  939. struct tsi108_prv_data *data = netdev_priv(dev);
  940. u32 rxcfg = TSI_READ(TSI108_EC_RXCFG);
  941. if (dev->flags & IFF_PROMISC) {
  942. rxcfg &= ~(TSI108_EC_RXCFG_UC_HASH | TSI108_EC_RXCFG_MC_HASH);
  943. rxcfg |= TSI108_EC_RXCFG_UFE | TSI108_EC_RXCFG_MFE;
  944. goto out;
  945. }
  946. rxcfg &= ~(TSI108_EC_RXCFG_UFE | TSI108_EC_RXCFG_MFE);
  947. if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
  948. int i;
  949. struct netdev_hw_addr *ha;
  950. rxcfg |= TSI108_EC_RXCFG_MFE | TSI108_EC_RXCFG_MC_HASH;
  951. memset(data->mc_hash, 0, sizeof(data->mc_hash));
  952. netdev_for_each_mc_addr(ha, dev) {
  953. u32 hash, crc;
  954. crc = ether_crc(6, ha->addr);
  955. hash = crc >> 23;
  956. __set_bit(hash, &data->mc_hash[0]);
  957. }
  958. TSI_WRITE(TSI108_EC_HASHADDR,
  959. TSI108_EC_HASHADDR_AUTOINC |
  960. TSI108_EC_HASHADDR_MCAST);
  961. for (i = 0; i < 16; i++) {
  962. /* The manual says that the hardware may drop
  963. * back-to-back writes to the data register.
  964. */
  965. udelay(1);
  966. TSI_WRITE(TSI108_EC_HASHDATA,
  967. data->mc_hash[i]);
  968. }
  969. }
  970. out:
  971. TSI_WRITE(TSI108_EC_RXCFG, rxcfg);
  972. }
  973. static void tsi108_init_phy(struct net_device *dev)
  974. {
  975. struct tsi108_prv_data *data = netdev_priv(dev);
  976. u32 i = 0;
  977. u16 phyval = 0;
  978. unsigned long flags;
  979. spin_lock_irqsave(&phy_lock, flags);
  980. tsi108_write_mii(data, MII_BMCR, BMCR_RESET);
  981. while (--i) {
  982. if(!(tsi108_read_mii(data, MII_BMCR) & BMCR_RESET))
  983. break;
  984. udelay(10);
  985. }
  986. if (i == 0)
  987. printk(KERN_ERR "%s function time out\n", __func__);
  988. if (data->phy_type == TSI108_PHY_BCM54XX) {
  989. tsi108_write_mii(data, 0x09, 0x0300);
  990. tsi108_write_mii(data, 0x10, 0x1020);
  991. tsi108_write_mii(data, 0x1c, 0x8c00);
  992. }
  993. tsi108_write_mii(data,
  994. MII_BMCR,
  995. BMCR_ANENABLE | BMCR_ANRESTART);
  996. while (tsi108_read_mii(data, MII_BMCR) & BMCR_ANRESTART)
  997. cpu_relax();
  998. /* Set G/MII mode and receive clock select in TBI control #2. The
  999. * second port won't work if this isn't done, even though we don't
  1000. * use TBI mode.
  1001. */
  1002. tsi108_write_tbi(data, 0x11, 0x30);
  1003. /* FIXME: It seems to take more than 2 back-to-back reads to the
  1004. * PHY_STAT register before the link up status bit is set.
  1005. */
  1006. data->link_up = 0;
  1007. while (!((phyval = tsi108_read_mii(data, MII_BMSR)) &
  1008. BMSR_LSTATUS)) {
  1009. if (i++ > (MII_READ_DELAY / 10)) {
  1010. break;
  1011. }
  1012. spin_unlock_irqrestore(&phy_lock, flags);
  1013. msleep(10);
  1014. spin_lock_irqsave(&phy_lock, flags);
  1015. }
  1016. data->mii_if.supports_gmii = mii_check_gmii_support(&data->mii_if);
  1017. printk(KERN_DEBUG "PHY_STAT reg contains %08x\n", phyval);
  1018. data->phy_ok = 1;
  1019. data->init_media = 1;
  1020. spin_unlock_irqrestore(&phy_lock, flags);
  1021. }
  1022. static void tsi108_kill_phy(struct net_device *dev)
  1023. {
  1024. struct tsi108_prv_data *data = netdev_priv(dev);
  1025. unsigned long flags;
  1026. spin_lock_irqsave(&phy_lock, flags);
  1027. tsi108_write_mii(data, MII_BMCR, BMCR_PDOWN);
  1028. data->phy_ok = 0;
  1029. spin_unlock_irqrestore(&phy_lock, flags);
  1030. }
  1031. static int tsi108_open(struct net_device *dev)
  1032. {
  1033. int i;
  1034. struct tsi108_prv_data *data = netdev_priv(dev);
  1035. unsigned int rxring_size = TSI108_RXRING_LEN * sizeof(rx_desc);
  1036. unsigned int txring_size = TSI108_TXRING_LEN * sizeof(tx_desc);
  1037. i = request_irq(data->irq_num, tsi108_irq, 0, dev->name, dev);
  1038. if (i != 0) {
  1039. printk(KERN_ERR "tsi108_eth%d: Could not allocate IRQ%d.\n",
  1040. data->id, data->irq_num);
  1041. return i;
  1042. } else {
  1043. dev->irq = data->irq_num;
  1044. printk(KERN_NOTICE
  1045. "tsi108_open : Port %d Assigned IRQ %d to %s\n",
  1046. data->id, dev->irq, dev->name);
  1047. }
  1048. data->rxring = dma_alloc_coherent(NULL, rxring_size,
  1049. &data->rxdma, GFP_KERNEL);
  1050. if (!data->rxring) {
  1051. printk(KERN_DEBUG
  1052. "TSI108_ETH: failed to allocate memory for rxring!\n");
  1053. return -ENOMEM;
  1054. } else {
  1055. memset(data->rxring, 0, rxring_size);
  1056. }
  1057. data->txring = dma_alloc_coherent(NULL, txring_size,
  1058. &data->txdma, GFP_KERNEL);
  1059. if (!data->txring) {
  1060. printk(KERN_DEBUG
  1061. "TSI108_ETH: failed to allocate memory for txring!\n");
  1062. pci_free_consistent(0, rxring_size, data->rxring, data->rxdma);
  1063. return -ENOMEM;
  1064. } else {
  1065. memset(data->txring, 0, txring_size);
  1066. }
  1067. for (i = 0; i < TSI108_RXRING_LEN; i++) {
  1068. data->rxring[i].next0 = data->rxdma + (i + 1) * sizeof(rx_desc);
  1069. data->rxring[i].blen = TSI108_RXBUF_SIZE;
  1070. data->rxring[i].vlan = 0;
  1071. }
  1072. data->rxring[TSI108_RXRING_LEN - 1].next0 = data->rxdma;
  1073. data->rxtail = 0;
  1074. data->rxhead = 0;
  1075. for (i = 0; i < TSI108_RXRING_LEN; i++) {
  1076. struct sk_buff *skb;
  1077. skb = netdev_alloc_skb_ip_align(dev, TSI108_RXBUF_SIZE);
  1078. if (!skb) {
  1079. /* Bah. No memory for now, but maybe we'll get
  1080. * some more later.
  1081. * For now, we'll live with the smaller ring.
  1082. */
  1083. printk(KERN_WARNING
  1084. "%s: Could only allocate %d receive skb(s).\n",
  1085. dev->name, i);
  1086. data->rxhead = i;
  1087. break;
  1088. }
  1089. data->rxskbs[i] = skb;
  1090. data->rxskbs[i] = skb;
  1091. data->rxring[i].buf0 = virt_to_phys(data->rxskbs[i]->data);
  1092. data->rxring[i].misc = TSI108_RX_OWN | TSI108_RX_INT;
  1093. }
  1094. data->rxfree = i;
  1095. TSI_WRITE(TSI108_EC_RXQ_PTRLOW, data->rxdma);
  1096. for (i = 0; i < TSI108_TXRING_LEN; i++) {
  1097. data->txring[i].next0 = data->txdma + (i + 1) * sizeof(tx_desc);
  1098. data->txring[i].misc = 0;
  1099. }
  1100. data->txring[TSI108_TXRING_LEN - 1].next0 = data->txdma;
  1101. data->txtail = 0;
  1102. data->txhead = 0;
  1103. data->txfree = TSI108_TXRING_LEN;
  1104. TSI_WRITE(TSI108_EC_TXQ_PTRLOW, data->txdma);
  1105. tsi108_init_phy(dev);
  1106. napi_enable(&data->napi);
  1107. setup_timer(&data->timer, tsi108_timed_checker, (unsigned long)dev);
  1108. mod_timer(&data->timer, jiffies + 1);
  1109. tsi108_restart_rx(data, dev);
  1110. TSI_WRITE(TSI108_EC_INTSTAT, ~0);
  1111. TSI_WRITE(TSI108_EC_INTMASK,
  1112. ~(TSI108_INT_TXQUEUE0 | TSI108_INT_RXERROR |
  1113. TSI108_INT_RXTHRESH | TSI108_INT_RXQUEUE0 |
  1114. TSI108_INT_RXOVERRUN | TSI108_INT_RXWAIT |
  1115. TSI108_INT_SFN | TSI108_INT_STATCARRY));
  1116. TSI_WRITE(TSI108_MAC_CFG1,
  1117. TSI108_MAC_CFG1_RXEN | TSI108_MAC_CFG1_TXEN);
  1118. netif_start_queue(dev);
  1119. return 0;
  1120. }
  1121. static int tsi108_close(struct net_device *dev)
  1122. {
  1123. struct tsi108_prv_data *data = netdev_priv(dev);
  1124. netif_stop_queue(dev);
  1125. napi_disable(&data->napi);
  1126. del_timer_sync(&data->timer);
  1127. tsi108_stop_ethernet(dev);
  1128. tsi108_kill_phy(dev);
  1129. TSI_WRITE(TSI108_EC_INTMASK, ~0);
  1130. TSI_WRITE(TSI108_MAC_CFG1, 0);
  1131. /* Check for any pending TX packets, and drop them. */
  1132. while (!data->txfree || data->txhead != data->txtail) {
  1133. int tx = data->txtail;
  1134. struct sk_buff *skb;
  1135. skb = data->txskbs[tx];
  1136. data->txtail = (data->txtail + 1) % TSI108_TXRING_LEN;
  1137. data->txfree++;
  1138. dev_kfree_skb(skb);
  1139. }
  1140. free_irq(data->irq_num, dev);
  1141. /* Discard the RX ring. */
  1142. while (data->rxfree) {
  1143. int rx = data->rxtail;
  1144. struct sk_buff *skb;
  1145. skb = data->rxskbs[rx];
  1146. data->rxtail = (data->rxtail + 1) % TSI108_RXRING_LEN;
  1147. data->rxfree--;
  1148. dev_kfree_skb(skb);
  1149. }
  1150. dma_free_coherent(0,
  1151. TSI108_RXRING_LEN * sizeof(rx_desc),
  1152. data->rxring, data->rxdma);
  1153. dma_free_coherent(0,
  1154. TSI108_TXRING_LEN * sizeof(tx_desc),
  1155. data->txring, data->txdma);
  1156. return 0;
  1157. }
  1158. static void tsi108_init_mac(struct net_device *dev)
  1159. {
  1160. struct tsi108_prv_data *data = netdev_priv(dev);
  1161. TSI_WRITE(TSI108_MAC_CFG2, TSI108_MAC_CFG2_DFLT_PREAMBLE |
  1162. TSI108_MAC_CFG2_PADCRC);
  1163. TSI_WRITE(TSI108_EC_TXTHRESH,
  1164. (192 << TSI108_EC_TXTHRESH_STARTFILL) |
  1165. (192 << TSI108_EC_TXTHRESH_STOPFILL));
  1166. TSI_WRITE(TSI108_STAT_CARRYMASK1,
  1167. ~(TSI108_STAT_CARRY1_RXBYTES |
  1168. TSI108_STAT_CARRY1_RXPKTS |
  1169. TSI108_STAT_CARRY1_RXFCS |
  1170. TSI108_STAT_CARRY1_RXMCAST |
  1171. TSI108_STAT_CARRY1_RXALIGN |
  1172. TSI108_STAT_CARRY1_RXLENGTH |
  1173. TSI108_STAT_CARRY1_RXRUNT |
  1174. TSI108_STAT_CARRY1_RXJUMBO |
  1175. TSI108_STAT_CARRY1_RXFRAG |
  1176. TSI108_STAT_CARRY1_RXJABBER |
  1177. TSI108_STAT_CARRY1_RXDROP));
  1178. TSI_WRITE(TSI108_STAT_CARRYMASK2,
  1179. ~(TSI108_STAT_CARRY2_TXBYTES |
  1180. TSI108_STAT_CARRY2_TXPKTS |
  1181. TSI108_STAT_CARRY2_TXEXDEF |
  1182. TSI108_STAT_CARRY2_TXEXCOL |
  1183. TSI108_STAT_CARRY2_TXTCOL |
  1184. TSI108_STAT_CARRY2_TXPAUSE));
  1185. TSI_WRITE(TSI108_EC_PORTCTRL, TSI108_EC_PORTCTRL_STATEN);
  1186. TSI_WRITE(TSI108_MAC_CFG1, 0);
  1187. TSI_WRITE(TSI108_EC_RXCFG,
  1188. TSI108_EC_RXCFG_SE | TSI108_EC_RXCFG_BFE);
  1189. TSI_WRITE(TSI108_EC_TXQ_CFG, TSI108_EC_TXQ_CFG_DESC_INT |
  1190. TSI108_EC_TXQ_CFG_EOQ_OWN_INT |
  1191. TSI108_EC_TXQ_CFG_WSWP | (TSI108_PBM_PORT <<
  1192. TSI108_EC_TXQ_CFG_SFNPORT));
  1193. TSI_WRITE(TSI108_EC_RXQ_CFG, TSI108_EC_RXQ_CFG_DESC_INT |
  1194. TSI108_EC_RXQ_CFG_EOQ_OWN_INT |
  1195. TSI108_EC_RXQ_CFG_WSWP | (TSI108_PBM_PORT <<
  1196. TSI108_EC_RXQ_CFG_SFNPORT));
  1197. TSI_WRITE(TSI108_EC_TXQ_BUFCFG,
  1198. TSI108_EC_TXQ_BUFCFG_BURST256 |
  1199. TSI108_EC_TXQ_BUFCFG_BSWP | (TSI108_PBM_PORT <<
  1200. TSI108_EC_TXQ_BUFCFG_SFNPORT));
  1201. TSI_WRITE(TSI108_EC_RXQ_BUFCFG,
  1202. TSI108_EC_RXQ_BUFCFG_BURST256 |
  1203. TSI108_EC_RXQ_BUFCFG_BSWP | (TSI108_PBM_PORT <<
  1204. TSI108_EC_RXQ_BUFCFG_SFNPORT));
  1205. TSI_WRITE(TSI108_EC_INTMASK, ~0);
  1206. }
  1207. static int tsi108_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1208. {
  1209. struct tsi108_prv_data *data = netdev_priv(dev);
  1210. unsigned long flags;
  1211. int rc;
  1212. spin_lock_irqsave(&data->txlock, flags);
  1213. rc = mii_ethtool_gset(&data->mii_if, cmd);
  1214. spin_unlock_irqrestore(&data->txlock, flags);
  1215. return rc;
  1216. }
  1217. static int tsi108_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1218. {
  1219. struct tsi108_prv_data *data = netdev_priv(dev);
  1220. unsigned long flags;
  1221. int rc;
  1222. spin_lock_irqsave(&data->txlock, flags);
  1223. rc = mii_ethtool_sset(&data->mii_if, cmd);
  1224. spin_unlock_irqrestore(&data->txlock, flags);
  1225. return rc;
  1226. }
  1227. static int tsi108_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1228. {
  1229. struct tsi108_prv_data *data = netdev_priv(dev);
  1230. if (!netif_running(dev))
  1231. return -EINVAL;
  1232. return generic_mii_ioctl(&data->mii_if, if_mii(rq), cmd, NULL);
  1233. }
  1234. static const struct ethtool_ops tsi108_ethtool_ops = {
  1235. .get_link = ethtool_op_get_link,
  1236. .get_settings = tsi108_get_settings,
  1237. .set_settings = tsi108_set_settings,
  1238. };
  1239. static const struct net_device_ops tsi108_netdev_ops = {
  1240. .ndo_open = tsi108_open,
  1241. .ndo_stop = tsi108_close,
  1242. .ndo_start_xmit = tsi108_send_packet,
  1243. .ndo_set_multicast_list = tsi108_set_rx_mode,
  1244. .ndo_get_stats = tsi108_get_stats,
  1245. .ndo_do_ioctl = tsi108_do_ioctl,
  1246. .ndo_set_mac_address = tsi108_set_mac,
  1247. .ndo_validate_addr = eth_validate_addr,
  1248. .ndo_change_mtu = eth_change_mtu,
  1249. };
  1250. static int
  1251. tsi108_init_one(struct platform_device *pdev)
  1252. {
  1253. struct net_device *dev = NULL;
  1254. struct tsi108_prv_data *data = NULL;
  1255. hw_info *einfo;
  1256. int err = 0;
  1257. einfo = pdev->dev.platform_data;
  1258. if (NULL == einfo) {
  1259. printk(KERN_ERR "tsi-eth %d: Missing additional data!\n",
  1260. pdev->id);
  1261. return -ENODEV;
  1262. }
  1263. /* Create an ethernet device instance */
  1264. dev = alloc_etherdev(sizeof(struct tsi108_prv_data));
  1265. if (!dev) {
  1266. printk("tsi108_eth: Could not allocate a device structure\n");
  1267. return -ENOMEM;
  1268. }
  1269. printk("tsi108_eth%d: probe...\n", pdev->id);
  1270. data = netdev_priv(dev);
  1271. data->dev = dev;
  1272. pr_debug("tsi108_eth%d:regs:phyresgs:phy:irq_num=0x%x:0x%x:0x%x:0x%x\n",
  1273. pdev->id, einfo->regs, einfo->phyregs,
  1274. einfo->phy, einfo->irq_num);
  1275. data->regs = ioremap(einfo->regs, 0x400);
  1276. if (NULL == data->regs) {
  1277. err = -ENOMEM;
  1278. goto regs_fail;
  1279. }
  1280. data->phyregs = ioremap(einfo->phyregs, 0x400);
  1281. if (NULL == data->phyregs) {
  1282. err = -ENOMEM;
  1283. goto regs_fail;
  1284. }
  1285. /* MII setup */
  1286. data->mii_if.dev = dev;
  1287. data->mii_if.mdio_read = tsi108_mdio_read;
  1288. data->mii_if.mdio_write = tsi108_mdio_write;
  1289. data->mii_if.phy_id = einfo->phy;
  1290. data->mii_if.phy_id_mask = 0x1f;
  1291. data->mii_if.reg_num_mask = 0x1f;
  1292. data->phy = einfo->phy;
  1293. data->phy_type = einfo->phy_type;
  1294. data->irq_num = einfo->irq_num;
  1295. data->id = pdev->id;
  1296. netif_napi_add(dev, &data->napi, tsi108_poll, 64);
  1297. dev->netdev_ops = &tsi108_netdev_ops;
  1298. dev->ethtool_ops = &tsi108_ethtool_ops;
  1299. /* Apparently, the Linux networking code won't use scatter-gather
  1300. * if the hardware doesn't do checksums. However, it's faster
  1301. * to checksum in place and use SG, as (among other reasons)
  1302. * the cache won't be dirtied (which then has to be flushed
  1303. * before DMA). The checksumming is done by the driver (via
  1304. * a new function skb_csum_dev() in net/core/skbuff.c).
  1305. */
  1306. dev->features = NETIF_F_HIGHDMA;
  1307. spin_lock_init(&data->txlock);
  1308. spin_lock_init(&data->misclock);
  1309. tsi108_reset_ether(data);
  1310. tsi108_kill_phy(dev);
  1311. if ((err = tsi108_get_mac(dev)) != 0) {
  1312. printk(KERN_ERR "%s: Invalid MAC address. Please correct.\n",
  1313. dev->name);
  1314. goto register_fail;
  1315. }
  1316. tsi108_init_mac(dev);
  1317. err = register_netdev(dev);
  1318. if (err) {
  1319. printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
  1320. dev->name);
  1321. goto register_fail;
  1322. }
  1323. platform_set_drvdata(pdev, dev);
  1324. printk(KERN_INFO "%s: Tsi108 Gigabit Ethernet, MAC: %pM\n",
  1325. dev->name, dev->dev_addr);
  1326. #ifdef DEBUG
  1327. data->msg_enable = DEBUG;
  1328. dump_eth_one(dev);
  1329. #endif
  1330. return 0;
  1331. register_fail:
  1332. iounmap(data->regs);
  1333. iounmap(data->phyregs);
  1334. regs_fail:
  1335. free_netdev(dev);
  1336. return err;
  1337. }
  1338. /* There's no way to either get interrupts from the PHY when
  1339. * something changes, or to have the Tsi108 automatically communicate
  1340. * with the PHY to reconfigure itself.
  1341. *
  1342. * Thus, we have to do it using a timer.
  1343. */
  1344. static void tsi108_timed_checker(unsigned long dev_ptr)
  1345. {
  1346. struct net_device *dev = (struct net_device *)dev_ptr;
  1347. struct tsi108_prv_data *data = netdev_priv(dev);
  1348. tsi108_check_phy(dev);
  1349. tsi108_check_rxring(dev);
  1350. mod_timer(&data->timer, jiffies + CHECK_PHY_INTERVAL);
  1351. }
  1352. static int tsi108_ether_init(void)
  1353. {
  1354. int ret;
  1355. ret = platform_driver_register (&tsi_eth_driver);
  1356. if (ret < 0){
  1357. printk("tsi108_ether_init: error initializing ethernet "
  1358. "device\n");
  1359. return ret;
  1360. }
  1361. return 0;
  1362. }
  1363. static int tsi108_ether_remove(struct platform_device *pdev)
  1364. {
  1365. struct net_device *dev = platform_get_drvdata(pdev);
  1366. struct tsi108_prv_data *priv = netdev_priv(dev);
  1367. unregister_netdev(dev);
  1368. tsi108_stop_ethernet(dev);
  1369. platform_set_drvdata(pdev, NULL);
  1370. iounmap(priv->regs);
  1371. iounmap(priv->phyregs);
  1372. free_netdev(dev);
  1373. return 0;
  1374. }
  1375. static void tsi108_ether_exit(void)
  1376. {
  1377. platform_driver_unregister(&tsi_eth_driver);
  1378. }
  1379. module_init(tsi108_ether_init);
  1380. module_exit(tsi108_ether_exit);
  1381. MODULE_AUTHOR("Tundra Semiconductor Corporation");
  1382. MODULE_DESCRIPTION("Tsi108 Gigabit Ethernet driver");
  1383. MODULE_LICENSE("GPL");
  1384. MODULE_ALIAS("platform:tsi-ethernet");