tsi108_eth.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  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/interrupt.h>
  29. #include <linux/net.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/delay.h>
  36. #include <linux/crc32.h>
  37. #include <linux/mii.h>
  38. #include <linux/device.h>
  39. #include <linux/pci.h>
  40. #include <linux/rtnetlink.h>
  41. #include <linux/timer.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/gfp.h>
  44. #include <asm/io.h>
  45. #include <asm/tsi108.h>
  46. #include "tsi108_eth.h"
  47. #define MII_READ_DELAY 10000 /* max link wait time in msec */
  48. #define TSI108_RXRING_LEN 256
  49. /* NOTE: The driver currently does not support receiving packets
  50. * larger than the buffer size, so don't decrease this (unless you
  51. * want to add such support).
  52. */
  53. #define TSI108_RXBUF_SIZE 1536
  54. #define TSI108_TXRING_LEN 256
  55. #define TSI108_TX_INT_FREQ 64
  56. /* Check the phy status every half a second. */
  57. #define CHECK_PHY_INTERVAL (HZ/2)
  58. static int tsi108_init_one(struct platform_device *pdev);
  59. static int tsi108_ether_remove(struct platform_device *pdev);
  60. struct tsi108_prv_data {
  61. void __iomem *regs; /* Base of normal regs */
  62. void __iomem *phyregs; /* Base of register bank used for PHY access */
  63. struct net_device *dev;
  64. struct napi_struct napi;
  65. unsigned int phy; /* Index of PHY for this interface */
  66. unsigned int irq_num;
  67. unsigned int id;
  68. unsigned int phy_type;
  69. struct timer_list timer;/* Timer that triggers the check phy function */
  70. unsigned int rxtail; /* Next entry in rxring to read */
  71. unsigned int rxhead; /* Next entry in rxring to give a new buffer */
  72. unsigned int rxfree; /* Number of free, allocated RX buffers */
  73. unsigned int rxpending; /* Non-zero if there are still descriptors
  74. * to be processed from a previous descriptor
  75. * interrupt condition that has been cleared */
  76. unsigned int txtail; /* Next TX descriptor to check status on */
  77. unsigned int txhead; /* Next TX descriptor to use */
  78. /* Number of free TX descriptors. This could be calculated from
  79. * rxhead and rxtail if one descriptor were left unused to disambiguate
  80. * full and empty conditions, but it's simpler to just keep track
  81. * explicitly. */
  82. unsigned int txfree;
  83. unsigned int phy_ok; /* The PHY is currently powered on. */
  84. /* PHY status (duplex is 1 for half, 2 for full,
  85. * so that the default 0 indicates that neither has
  86. * yet been configured). */
  87. unsigned int link_up;
  88. unsigned int speed;
  89. unsigned int duplex;
  90. tx_desc *txring;
  91. rx_desc *rxring;
  92. struct sk_buff *txskbs[TSI108_TXRING_LEN];
  93. struct sk_buff *rxskbs[TSI108_RXRING_LEN];
  94. dma_addr_t txdma, rxdma;
  95. /* txlock nests in misclock and phy_lock */
  96. spinlock_t txlock, misclock;
  97. /* stats is used to hold the upper bits of each hardware counter,
  98. * and tmpstats is used to hold the full values for returning
  99. * to the caller of get_stats(). They must be separate in case
  100. * an overflow interrupt occurs before the stats are consumed.
  101. */
  102. struct net_device_stats stats;
  103. struct net_device_stats tmpstats;
  104. /* These stats are kept separate in hardware, thus require individual
  105. * fields for handling carry. They are combined in get_stats.
  106. */
  107. unsigned long rx_fcs; /* Add to rx_frame_errors */
  108. unsigned long rx_short_fcs; /* Add to rx_frame_errors */
  109. unsigned long rx_long_fcs; /* Add to rx_frame_errors */
  110. unsigned long rx_underruns; /* Add to rx_length_errors */
  111. unsigned long rx_overruns; /* Add to rx_length_errors */
  112. unsigned long tx_coll_abort; /* Add to tx_aborted_errors/collisions */
  113. unsigned long tx_pause_drop; /* Add to tx_aborted_errors */
  114. unsigned long mc_hash[16];
  115. u32 msg_enable; /* debug message level */
  116. struct mii_if_info mii_if;
  117. unsigned int init_media;
  118. };
  119. /* Structure for a device driver */
  120. static struct platform_driver tsi_eth_driver = {
  121. .probe = tsi108_init_one,
  122. .remove = tsi108_ether_remove,
  123. .driver = {
  124. .name = "tsi-ethernet",
  125. },
  126. };
  127. static void tsi108_timed_checker(unsigned long dev_ptr);
  128. #ifdef DEBUG
  129. static void dump_eth_one(struct net_device *dev)
  130. {
  131. struct tsi108_prv_data *data = netdev_priv(dev);
  132. printk("Dumping %s...\n", dev->name);
  133. printk("intstat %x intmask %x phy_ok %d"
  134. " link %d speed %d duplex %d\n",
  135. TSI_READ(TSI108_EC_INTSTAT),
  136. TSI_READ(TSI108_EC_INTMASK), data->phy_ok,
  137. data->link_up, data->speed, data->duplex);
  138. printk("TX: head %d, tail %d, free %d, stat %x, estat %x, err %x\n",
  139. data->txhead, data->txtail, data->txfree,
  140. TSI_READ(TSI108_EC_TXSTAT),
  141. TSI_READ(TSI108_EC_TXESTAT),
  142. TSI_READ(TSI108_EC_TXERR));
  143. printk("RX: head %d, tail %d, free %d, stat %x,"
  144. " estat %x, err %x, pending %d\n\n",
  145. data->rxhead, data->rxtail, data->rxfree,
  146. TSI_READ(TSI108_EC_RXSTAT),
  147. TSI_READ(TSI108_EC_RXESTAT),
  148. TSI_READ(TSI108_EC_RXERR), data->rxpending);
  149. }
  150. #endif
  151. /* Synchronization is needed between the thread and up/down events.
  152. * Note that the PHY is accessed through the same registers for both
  153. * interfaces, so this can't be made interface-specific.
  154. */
  155. static DEFINE_SPINLOCK(phy_lock);
  156. static int tsi108_read_mii(struct tsi108_prv_data *data, int reg)
  157. {
  158. unsigned i;
  159. TSI_WRITE_PHY(TSI108_MAC_MII_ADDR,
  160. (data->phy << TSI108_MAC_MII_ADDR_PHY) |
  161. (reg << TSI108_MAC_MII_ADDR_REG));
  162. TSI_WRITE_PHY(TSI108_MAC_MII_CMD, 0);
  163. TSI_WRITE_PHY(TSI108_MAC_MII_CMD, TSI108_MAC_MII_CMD_READ);
  164. for (i = 0; i < 100; i++) {
  165. if (!(TSI_READ_PHY(TSI108_MAC_MII_IND) &
  166. (TSI108_MAC_MII_IND_NOTVALID | TSI108_MAC_MII_IND_BUSY)))
  167. break;
  168. udelay(10);
  169. }
  170. if (i == 100)
  171. return 0xffff;
  172. else
  173. return TSI_READ_PHY(TSI108_MAC_MII_DATAIN);
  174. }
  175. static void tsi108_write_mii(struct tsi108_prv_data *data,
  176. int reg, u16 val)
  177. {
  178. unsigned i = 100;
  179. TSI_WRITE_PHY(TSI108_MAC_MII_ADDR,
  180. (data->phy << TSI108_MAC_MII_ADDR_PHY) |
  181. (reg << TSI108_MAC_MII_ADDR_REG));
  182. TSI_WRITE_PHY(TSI108_MAC_MII_DATAOUT, val);
  183. while (i--) {
  184. if(!(TSI_READ_PHY(TSI108_MAC_MII_IND) &
  185. TSI108_MAC_MII_IND_BUSY))
  186. break;
  187. udelay(10);
  188. }
  189. }
  190. static int tsi108_mdio_read(struct net_device *dev, int addr, int reg)
  191. {
  192. struct tsi108_prv_data *data = netdev_priv(dev);
  193. return tsi108_read_mii(data, reg);
  194. }
  195. static void tsi108_mdio_write(struct net_device *dev, int addr, int reg, int val)
  196. {
  197. struct tsi108_prv_data *data = netdev_priv(dev);
  198. tsi108_write_mii(data, reg, val);
  199. }
  200. static inline void tsi108_write_tbi(struct tsi108_prv_data *data,
  201. int reg, u16 val)
  202. {
  203. unsigned i = 1000;
  204. TSI_WRITE(TSI108_MAC_MII_ADDR,
  205. (0x1e << TSI108_MAC_MII_ADDR_PHY)
  206. | (reg << TSI108_MAC_MII_ADDR_REG));
  207. TSI_WRITE(TSI108_MAC_MII_DATAOUT, val);
  208. while(i--) {
  209. if(!(TSI_READ(TSI108_MAC_MII_IND) & TSI108_MAC_MII_IND_BUSY))
  210. return;
  211. udelay(10);
  212. }
  213. printk(KERN_ERR "%s function time out\n", __func__);
  214. }
  215. static int mii_speed(struct mii_if_info *mii)
  216. {
  217. int advert, lpa, val, media;
  218. int lpa2 = 0;
  219. int speed;
  220. if (!mii_link_ok(mii))
  221. return 0;
  222. val = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_BMSR);
  223. if ((val & BMSR_ANEGCOMPLETE) == 0)
  224. return 0;
  225. advert = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_ADVERTISE);
  226. lpa = (*mii->mdio_read) (mii->dev, mii->phy_id, MII_LPA);
  227. media = mii_nway_result(advert & lpa);
  228. if (mii->supports_gmii)
  229. lpa2 = mii->mdio_read(mii->dev, mii->phy_id, MII_STAT1000);
  230. speed = lpa2 & (LPA_1000FULL | LPA_1000HALF) ? 1000 :
  231. (media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? 100 : 10);
  232. return speed;
  233. }
  234. static void tsi108_check_phy(struct net_device *dev)
  235. {
  236. struct tsi108_prv_data *data = netdev_priv(dev);
  237. u32 mac_cfg2_reg, portctrl_reg;
  238. u32 duplex;
  239. u32 speed;
  240. unsigned long flags;
  241. spin_lock_irqsave(&phy_lock, flags);
  242. if (!data->phy_ok)
  243. goto out;
  244. duplex = mii_check_media(&data->mii_if, netif_msg_link(data), data->init_media);
  245. data->init_media = 0;
  246. if (netif_carrier_ok(dev)) {
  247. speed = mii_speed(&data->mii_if);
  248. if ((speed != data->speed) || duplex) {
  249. mac_cfg2_reg = TSI_READ(TSI108_MAC_CFG2);
  250. portctrl_reg = TSI_READ(TSI108_EC_PORTCTRL);
  251. mac_cfg2_reg &= ~TSI108_MAC_CFG2_IFACE_MASK;
  252. if (speed == 1000) {
  253. mac_cfg2_reg |= TSI108_MAC_CFG2_GIG;
  254. portctrl_reg &= ~TSI108_EC_PORTCTRL_NOGIG;
  255. } else {
  256. mac_cfg2_reg |= TSI108_MAC_CFG2_NOGIG;
  257. portctrl_reg |= TSI108_EC_PORTCTRL_NOGIG;
  258. }
  259. data->speed = speed;
  260. if (data->mii_if.full_duplex) {
  261. mac_cfg2_reg |= TSI108_MAC_CFG2_FULLDUPLEX;
  262. portctrl_reg &= ~TSI108_EC_PORTCTRL_HALFDUPLEX;
  263. data->duplex = 2;
  264. } else {
  265. mac_cfg2_reg &= ~TSI108_MAC_CFG2_FULLDUPLEX;
  266. portctrl_reg |= TSI108_EC_PORTCTRL_HALFDUPLEX;
  267. data->duplex = 1;
  268. }
  269. TSI_WRITE(TSI108_MAC_CFG2, mac_cfg2_reg);
  270. TSI_WRITE(TSI108_EC_PORTCTRL, portctrl_reg);
  271. }
  272. if (data->link_up == 0) {
  273. /* The manual says it can take 3-4 usecs for the speed change
  274. * to take effect.
  275. */
  276. udelay(5);
  277. spin_lock(&data->txlock);
  278. if (is_valid_ether_addr(dev->dev_addr) && data->txfree)
  279. netif_wake_queue(dev);
  280. data->link_up = 1;
  281. spin_unlock(&data->txlock);
  282. }
  283. } else {
  284. if (data->link_up == 1) {
  285. netif_stop_queue(dev);
  286. data->link_up = 0;
  287. printk(KERN_NOTICE "%s : link is down\n", dev->name);
  288. }
  289. goto out;
  290. }
  291. out:
  292. spin_unlock_irqrestore(&phy_lock, flags);
  293. }
  294. static inline void
  295. tsi108_stat_carry_one(int carry, int carry_bit, int carry_shift,
  296. unsigned long *upper)
  297. {
  298. if (carry & carry_bit)
  299. *upper += carry_shift;
  300. }
  301. static void tsi108_stat_carry(struct net_device *dev)
  302. {
  303. struct tsi108_prv_data *data = netdev_priv(dev);
  304. u32 carry1, carry2;
  305. spin_lock_irq(&data->misclock);
  306. carry1 = TSI_READ(TSI108_STAT_CARRY1);
  307. carry2 = TSI_READ(TSI108_STAT_CARRY2);
  308. TSI_WRITE(TSI108_STAT_CARRY1, carry1);
  309. TSI_WRITE(TSI108_STAT_CARRY2, carry2);
  310. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXBYTES,
  311. TSI108_STAT_RXBYTES_CARRY, &data->stats.rx_bytes);
  312. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXPKTS,
  313. TSI108_STAT_RXPKTS_CARRY,
  314. &data->stats.rx_packets);
  315. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXFCS,
  316. TSI108_STAT_RXFCS_CARRY, &data->rx_fcs);
  317. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXMCAST,
  318. TSI108_STAT_RXMCAST_CARRY,
  319. &data->stats.multicast);
  320. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXALIGN,
  321. TSI108_STAT_RXALIGN_CARRY,
  322. &data->stats.rx_frame_errors);
  323. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXLENGTH,
  324. TSI108_STAT_RXLENGTH_CARRY,
  325. &data->stats.rx_length_errors);
  326. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXRUNT,
  327. TSI108_STAT_RXRUNT_CARRY, &data->rx_underruns);
  328. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXJUMBO,
  329. TSI108_STAT_RXJUMBO_CARRY, &data->rx_overruns);
  330. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXFRAG,
  331. TSI108_STAT_RXFRAG_CARRY, &data->rx_short_fcs);
  332. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXJABBER,
  333. TSI108_STAT_RXJABBER_CARRY, &data->rx_long_fcs);
  334. tsi108_stat_carry_one(carry1, TSI108_STAT_CARRY1_RXDROP,
  335. TSI108_STAT_RXDROP_CARRY,
  336. &data->stats.rx_missed_errors);
  337. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXBYTES,
  338. TSI108_STAT_TXBYTES_CARRY, &data->stats.tx_bytes);
  339. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXPKTS,
  340. TSI108_STAT_TXPKTS_CARRY,
  341. &data->stats.tx_packets);
  342. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXEXDEF,
  343. TSI108_STAT_TXEXDEF_CARRY,
  344. &data->stats.tx_aborted_errors);
  345. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXEXCOL,
  346. TSI108_STAT_TXEXCOL_CARRY, &data->tx_coll_abort);
  347. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXTCOL,
  348. TSI108_STAT_TXTCOL_CARRY,
  349. &data->stats.collisions);
  350. tsi108_stat_carry_one(carry2, TSI108_STAT_CARRY2_TXPAUSE,
  351. TSI108_STAT_TXPAUSEDROP_CARRY,
  352. &data->tx_pause_drop);
  353. spin_unlock_irq(&data->misclock);
  354. }
  355. /* Read a stat counter atomically with respect to carries.
  356. * data->misclock must be held.
  357. */
  358. static inline unsigned long
  359. tsi108_read_stat(struct tsi108_prv_data * data, int reg, int carry_bit,
  360. int carry_shift, unsigned long *upper)
  361. {
  362. int carryreg;
  363. unsigned long val;
  364. if (reg < 0xb0)
  365. carryreg = TSI108_STAT_CARRY1;
  366. else
  367. carryreg = TSI108_STAT_CARRY2;
  368. again:
  369. val = TSI_READ(reg) | *upper;
  370. /* Check to see if it overflowed, but the interrupt hasn't
  371. * been serviced yet. If so, handle the carry here, and
  372. * try again.
  373. */
  374. if (unlikely(TSI_READ(carryreg) & carry_bit)) {
  375. *upper += carry_shift;
  376. TSI_WRITE(carryreg, carry_bit);
  377. goto again;
  378. }
  379. return val;
  380. }
  381. static struct net_device_stats *tsi108_get_stats(struct net_device *dev)
  382. {
  383. unsigned long excol;
  384. struct tsi108_prv_data *data = netdev_priv(dev);
  385. spin_lock_irq(&data->misclock);
  386. data->tmpstats.rx_packets =
  387. tsi108_read_stat(data, TSI108_STAT_RXPKTS,
  388. TSI108_STAT_CARRY1_RXPKTS,
  389. TSI108_STAT_RXPKTS_CARRY, &data->stats.rx_packets);
  390. data->tmpstats.tx_packets =
  391. tsi108_read_stat(data, TSI108_STAT_TXPKTS,
  392. TSI108_STAT_CARRY2_TXPKTS,
  393. TSI108_STAT_TXPKTS_CARRY, &data->stats.tx_packets);
  394. data->tmpstats.rx_bytes =
  395. tsi108_read_stat(data, TSI108_STAT_RXBYTES,
  396. TSI108_STAT_CARRY1_RXBYTES,
  397. TSI108_STAT_RXBYTES_CARRY, &data->stats.rx_bytes);
  398. data->tmpstats.tx_bytes =
  399. tsi108_read_stat(data, TSI108_STAT_TXBYTES,
  400. TSI108_STAT_CARRY2_TXBYTES,
  401. TSI108_STAT_TXBYTES_CARRY, &data->stats.tx_bytes);
  402. data->tmpstats.multicast =
  403. tsi108_read_stat(data, TSI108_STAT_RXMCAST,
  404. TSI108_STAT_CARRY1_RXMCAST,
  405. TSI108_STAT_RXMCAST_CARRY, &data->stats.multicast);
  406. excol = tsi108_read_stat(data, TSI108_STAT_TXEXCOL,
  407. TSI108_STAT_CARRY2_TXEXCOL,
  408. TSI108_STAT_TXEXCOL_CARRY,
  409. &data->tx_coll_abort);
  410. data->tmpstats.collisions =
  411. tsi108_read_stat(data, TSI108_STAT_TXTCOL,
  412. TSI108_STAT_CARRY2_TXTCOL,
  413. TSI108_STAT_TXTCOL_CARRY, &data->stats.collisions);
  414. data->tmpstats.collisions += excol;
  415. data->tmpstats.rx_length_errors =
  416. tsi108_read_stat(data, TSI108_STAT_RXLENGTH,
  417. TSI108_STAT_CARRY1_RXLENGTH,
  418. TSI108_STAT_RXLENGTH_CARRY,
  419. &data->stats.rx_length_errors);
  420. data->tmpstats.rx_length_errors +=
  421. tsi108_read_stat(data, TSI108_STAT_RXRUNT,
  422. TSI108_STAT_CARRY1_RXRUNT,
  423. TSI108_STAT_RXRUNT_CARRY, &data->rx_underruns);
  424. data->tmpstats.rx_length_errors +=
  425. tsi108_read_stat(data, TSI108_STAT_RXJUMBO,
  426. TSI108_STAT_CARRY1_RXJUMBO,
  427. TSI108_STAT_RXJUMBO_CARRY, &data->rx_overruns);
  428. data->tmpstats.rx_frame_errors =
  429. tsi108_read_stat(data, TSI108_STAT_RXALIGN,
  430. TSI108_STAT_CARRY1_RXALIGN,
  431. TSI108_STAT_RXALIGN_CARRY,
  432. &data->stats.rx_frame_errors);
  433. data->tmpstats.rx_frame_errors +=
  434. tsi108_read_stat(data, TSI108_STAT_RXFCS,
  435. TSI108_STAT_CARRY1_RXFCS, TSI108_STAT_RXFCS_CARRY,
  436. &data->rx_fcs);
  437. data->tmpstats.rx_frame_errors +=
  438. tsi108_read_stat(data, TSI108_STAT_RXFRAG,
  439. TSI108_STAT_CARRY1_RXFRAG,
  440. TSI108_STAT_RXFRAG_CARRY, &data->rx_short_fcs);
  441. data->tmpstats.rx_missed_errors =
  442. tsi108_read_stat(data, TSI108_STAT_RXDROP,
  443. TSI108_STAT_CARRY1_RXDROP,
  444. TSI108_STAT_RXDROP_CARRY,
  445. &data->stats.rx_missed_errors);
  446. /* These three are maintained by software. */
  447. data->tmpstats.rx_fifo_errors = data->stats.rx_fifo_errors;
  448. data->tmpstats.rx_crc_errors = data->stats.rx_crc_errors;
  449. data->tmpstats.tx_aborted_errors =
  450. tsi108_read_stat(data, TSI108_STAT_TXEXDEF,
  451. TSI108_STAT_CARRY2_TXEXDEF,
  452. TSI108_STAT_TXEXDEF_CARRY,
  453. &data->stats.tx_aborted_errors);
  454. data->tmpstats.tx_aborted_errors +=
  455. tsi108_read_stat(data, TSI108_STAT_TXPAUSEDROP,
  456. TSI108_STAT_CARRY2_TXPAUSE,
  457. TSI108_STAT_TXPAUSEDROP_CARRY,
  458. &data->tx_pause_drop);
  459. data->tmpstats.tx_aborted_errors += excol;
  460. data->tmpstats.tx_errors = data->tmpstats.tx_aborted_errors;
  461. data->tmpstats.rx_errors = data->tmpstats.rx_length_errors +
  462. data->tmpstats.rx_crc_errors +
  463. data->tmpstats.rx_frame_errors +
  464. data->tmpstats.rx_fifo_errors + data->tmpstats.rx_missed_errors;
  465. spin_unlock_irq(&data->misclock);
  466. return &data->tmpstats;
  467. }
  468. static void tsi108_restart_rx(struct tsi108_prv_data * data, struct net_device *dev)
  469. {
  470. TSI_WRITE(TSI108_EC_RXQ_PTRHIGH,
  471. TSI108_EC_RXQ_PTRHIGH_VALID);
  472. TSI_WRITE(TSI108_EC_RXCTRL, TSI108_EC_RXCTRL_GO
  473. | TSI108_EC_RXCTRL_QUEUE0);
  474. }
  475. static void tsi108_restart_tx(struct tsi108_prv_data * data)
  476. {
  477. TSI_WRITE(TSI108_EC_TXQ_PTRHIGH,
  478. TSI108_EC_TXQ_PTRHIGH_VALID);
  479. TSI_WRITE(TSI108_EC_TXCTRL, TSI108_EC_TXCTRL_IDLEINT |
  480. TSI108_EC_TXCTRL_GO | TSI108_EC_TXCTRL_QUEUE0);
  481. }
  482. /* txlock must be held by caller, with IRQs disabled, and
  483. * with permission to re-enable them when the lock is dropped.
  484. */
  485. static void tsi108_complete_tx(struct net_device *dev)
  486. {
  487. struct tsi108_prv_data *data = netdev_priv(dev);
  488. int tx;
  489. struct sk_buff *skb;
  490. int release = 0;
  491. while (!data->txfree || data->txhead != data->txtail) {
  492. tx = data->txtail;
  493. if (data->txring[tx].misc & TSI108_TX_OWN)
  494. break;
  495. skb = data->txskbs[tx];
  496. if (!(data->txring[tx].misc & TSI108_TX_OK))
  497. printk("%s: bad tx packet, misc %x\n",
  498. dev->name, data->txring[tx].misc);
  499. data->txtail = (data->txtail + 1) % TSI108_TXRING_LEN;
  500. data->txfree++;
  501. if (data->txring[tx].misc & TSI108_TX_EOF) {
  502. dev_kfree_skb_any(skb);
  503. release++;
  504. }
  505. }
  506. if (release) {
  507. if (is_valid_ether_addr(dev->dev_addr) && data->link_up)
  508. netif_wake_queue(dev);
  509. }
  510. }
  511. static int tsi108_send_packet(struct sk_buff * skb, struct net_device *dev)
  512. {
  513. struct tsi108_prv_data *data = netdev_priv(dev);
  514. int frags = skb_shinfo(skb)->nr_frags + 1;
  515. int i;
  516. if (!data->phy_ok && net_ratelimit())
  517. printk(KERN_ERR "%s: Transmit while PHY is down!\n", dev->name);
  518. if (!data->link_up) {
  519. printk(KERN_ERR "%s: Transmit while link is down!\n",
  520. dev->name);
  521. netif_stop_queue(dev);
  522. return NETDEV_TX_BUSY;
  523. }
  524. if (data->txfree < MAX_SKB_FRAGS + 1) {
  525. netif_stop_queue(dev);
  526. if (net_ratelimit())
  527. printk(KERN_ERR "%s: Transmit with full tx ring!\n",
  528. dev->name);
  529. return NETDEV_TX_BUSY;
  530. }
  531. if (data->txfree - frags < MAX_SKB_FRAGS + 1) {
  532. netif_stop_queue(dev);
  533. }
  534. spin_lock_irq(&data->txlock);
  535. for (i = 0; i < frags; i++) {
  536. int misc = 0;
  537. int tx = data->txhead;
  538. /* This is done to mark every TSI108_TX_INT_FREQ tx buffers with
  539. * the interrupt bit. TX descriptor-complete interrupts are
  540. * enabled when the queue fills up, and masked when there is
  541. * still free space. This way, when saturating the outbound
  542. * link, the tx interrupts are kept to a reasonable level.
  543. * When the queue is not full, reclamation of skbs still occurs
  544. * as new packets are transmitted, or on a queue-empty
  545. * interrupt.
  546. */
  547. if ((tx % TSI108_TX_INT_FREQ == 0) &&
  548. ((TSI108_TXRING_LEN - data->txfree) >= TSI108_TX_INT_FREQ))
  549. misc = TSI108_TX_INT;
  550. data->txskbs[tx] = skb;
  551. if (i == 0) {
  552. data->txring[tx].buf0 = dma_map_single(NULL, skb->data,
  553. skb_headlen(skb), DMA_TO_DEVICE);
  554. data->txring[tx].len = skb_headlen(skb);
  555. misc |= TSI108_TX_SOF;
  556. } else {
  557. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
  558. data->txring[tx].buf0 = skb_frag_dma_map(NULL, frag,
  559. 0,
  560. skb_frag_size(frag),
  561. DMA_TO_DEVICE);
  562. data->txring[tx].len = skb_frag_size(frag);
  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 -EADDRNOTAVAIL;
  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_zalloc_coherent(NULL, rxring_size, &data->rxdma,
  1049. GFP_KERNEL);
  1050. if (!data->rxring)
  1051. return -ENOMEM;
  1052. data->txring = dma_zalloc_coherent(NULL, txring_size, &data->txdma,
  1053. GFP_KERNEL);
  1054. if (!data->txring) {
  1055. pci_free_consistent(NULL, rxring_size, data->rxring,
  1056. data->rxdma);
  1057. return -ENOMEM;
  1058. }
  1059. for (i = 0; i < TSI108_RXRING_LEN; i++) {
  1060. data->rxring[i].next0 = data->rxdma + (i + 1) * sizeof(rx_desc);
  1061. data->rxring[i].blen = TSI108_RXBUF_SIZE;
  1062. data->rxring[i].vlan = 0;
  1063. }
  1064. data->rxring[TSI108_RXRING_LEN - 1].next0 = data->rxdma;
  1065. data->rxtail = 0;
  1066. data->rxhead = 0;
  1067. for (i = 0; i < TSI108_RXRING_LEN; i++) {
  1068. struct sk_buff *skb;
  1069. skb = netdev_alloc_skb_ip_align(dev, TSI108_RXBUF_SIZE);
  1070. if (!skb) {
  1071. /* Bah. No memory for now, but maybe we'll get
  1072. * some more later.
  1073. * For now, we'll live with the smaller ring.
  1074. */
  1075. printk(KERN_WARNING
  1076. "%s: Could only allocate %d receive skb(s).\n",
  1077. dev->name, i);
  1078. data->rxhead = i;
  1079. break;
  1080. }
  1081. data->rxskbs[i] = skb;
  1082. data->rxring[i].buf0 = virt_to_phys(data->rxskbs[i]->data);
  1083. data->rxring[i].misc = TSI108_RX_OWN | TSI108_RX_INT;
  1084. }
  1085. data->rxfree = i;
  1086. TSI_WRITE(TSI108_EC_RXQ_PTRLOW, data->rxdma);
  1087. for (i = 0; i < TSI108_TXRING_LEN; i++) {
  1088. data->txring[i].next0 = data->txdma + (i + 1) * sizeof(tx_desc);
  1089. data->txring[i].misc = 0;
  1090. }
  1091. data->txring[TSI108_TXRING_LEN - 1].next0 = data->txdma;
  1092. data->txtail = 0;
  1093. data->txhead = 0;
  1094. data->txfree = TSI108_TXRING_LEN;
  1095. TSI_WRITE(TSI108_EC_TXQ_PTRLOW, data->txdma);
  1096. tsi108_init_phy(dev);
  1097. napi_enable(&data->napi);
  1098. setup_timer(&data->timer, tsi108_timed_checker, (unsigned long)dev);
  1099. mod_timer(&data->timer, jiffies + 1);
  1100. tsi108_restart_rx(data, dev);
  1101. TSI_WRITE(TSI108_EC_INTSTAT, ~0);
  1102. TSI_WRITE(TSI108_EC_INTMASK,
  1103. ~(TSI108_INT_TXQUEUE0 | TSI108_INT_RXERROR |
  1104. TSI108_INT_RXTHRESH | TSI108_INT_RXQUEUE0 |
  1105. TSI108_INT_RXOVERRUN | TSI108_INT_RXWAIT |
  1106. TSI108_INT_SFN | TSI108_INT_STATCARRY));
  1107. TSI_WRITE(TSI108_MAC_CFG1,
  1108. TSI108_MAC_CFG1_RXEN | TSI108_MAC_CFG1_TXEN);
  1109. netif_start_queue(dev);
  1110. return 0;
  1111. }
  1112. static int tsi108_close(struct net_device *dev)
  1113. {
  1114. struct tsi108_prv_data *data = netdev_priv(dev);
  1115. netif_stop_queue(dev);
  1116. napi_disable(&data->napi);
  1117. del_timer_sync(&data->timer);
  1118. tsi108_stop_ethernet(dev);
  1119. tsi108_kill_phy(dev);
  1120. TSI_WRITE(TSI108_EC_INTMASK, ~0);
  1121. TSI_WRITE(TSI108_MAC_CFG1, 0);
  1122. /* Check for any pending TX packets, and drop them. */
  1123. while (!data->txfree || data->txhead != data->txtail) {
  1124. int tx = data->txtail;
  1125. struct sk_buff *skb;
  1126. skb = data->txskbs[tx];
  1127. data->txtail = (data->txtail + 1) % TSI108_TXRING_LEN;
  1128. data->txfree++;
  1129. dev_kfree_skb(skb);
  1130. }
  1131. free_irq(data->irq_num, dev);
  1132. /* Discard the RX ring. */
  1133. while (data->rxfree) {
  1134. int rx = data->rxtail;
  1135. struct sk_buff *skb;
  1136. skb = data->rxskbs[rx];
  1137. data->rxtail = (data->rxtail + 1) % TSI108_RXRING_LEN;
  1138. data->rxfree--;
  1139. dev_kfree_skb(skb);
  1140. }
  1141. dma_free_coherent(0,
  1142. TSI108_RXRING_LEN * sizeof(rx_desc),
  1143. data->rxring, data->rxdma);
  1144. dma_free_coherent(0,
  1145. TSI108_TXRING_LEN * sizeof(tx_desc),
  1146. data->txring, data->txdma);
  1147. return 0;
  1148. }
  1149. static void tsi108_init_mac(struct net_device *dev)
  1150. {
  1151. struct tsi108_prv_data *data = netdev_priv(dev);
  1152. TSI_WRITE(TSI108_MAC_CFG2, TSI108_MAC_CFG2_DFLT_PREAMBLE |
  1153. TSI108_MAC_CFG2_PADCRC);
  1154. TSI_WRITE(TSI108_EC_TXTHRESH,
  1155. (192 << TSI108_EC_TXTHRESH_STARTFILL) |
  1156. (192 << TSI108_EC_TXTHRESH_STOPFILL));
  1157. TSI_WRITE(TSI108_STAT_CARRYMASK1,
  1158. ~(TSI108_STAT_CARRY1_RXBYTES |
  1159. TSI108_STAT_CARRY1_RXPKTS |
  1160. TSI108_STAT_CARRY1_RXFCS |
  1161. TSI108_STAT_CARRY1_RXMCAST |
  1162. TSI108_STAT_CARRY1_RXALIGN |
  1163. TSI108_STAT_CARRY1_RXLENGTH |
  1164. TSI108_STAT_CARRY1_RXRUNT |
  1165. TSI108_STAT_CARRY1_RXJUMBO |
  1166. TSI108_STAT_CARRY1_RXFRAG |
  1167. TSI108_STAT_CARRY1_RXJABBER |
  1168. TSI108_STAT_CARRY1_RXDROP));
  1169. TSI_WRITE(TSI108_STAT_CARRYMASK2,
  1170. ~(TSI108_STAT_CARRY2_TXBYTES |
  1171. TSI108_STAT_CARRY2_TXPKTS |
  1172. TSI108_STAT_CARRY2_TXEXDEF |
  1173. TSI108_STAT_CARRY2_TXEXCOL |
  1174. TSI108_STAT_CARRY2_TXTCOL |
  1175. TSI108_STAT_CARRY2_TXPAUSE));
  1176. TSI_WRITE(TSI108_EC_PORTCTRL, TSI108_EC_PORTCTRL_STATEN);
  1177. TSI_WRITE(TSI108_MAC_CFG1, 0);
  1178. TSI_WRITE(TSI108_EC_RXCFG,
  1179. TSI108_EC_RXCFG_SE | TSI108_EC_RXCFG_BFE);
  1180. TSI_WRITE(TSI108_EC_TXQ_CFG, TSI108_EC_TXQ_CFG_DESC_INT |
  1181. TSI108_EC_TXQ_CFG_EOQ_OWN_INT |
  1182. TSI108_EC_TXQ_CFG_WSWP | (TSI108_PBM_PORT <<
  1183. TSI108_EC_TXQ_CFG_SFNPORT));
  1184. TSI_WRITE(TSI108_EC_RXQ_CFG, TSI108_EC_RXQ_CFG_DESC_INT |
  1185. TSI108_EC_RXQ_CFG_EOQ_OWN_INT |
  1186. TSI108_EC_RXQ_CFG_WSWP | (TSI108_PBM_PORT <<
  1187. TSI108_EC_RXQ_CFG_SFNPORT));
  1188. TSI_WRITE(TSI108_EC_TXQ_BUFCFG,
  1189. TSI108_EC_TXQ_BUFCFG_BURST256 |
  1190. TSI108_EC_TXQ_BUFCFG_BSWP | (TSI108_PBM_PORT <<
  1191. TSI108_EC_TXQ_BUFCFG_SFNPORT));
  1192. TSI_WRITE(TSI108_EC_RXQ_BUFCFG,
  1193. TSI108_EC_RXQ_BUFCFG_BURST256 |
  1194. TSI108_EC_RXQ_BUFCFG_BSWP | (TSI108_PBM_PORT <<
  1195. TSI108_EC_RXQ_BUFCFG_SFNPORT));
  1196. TSI_WRITE(TSI108_EC_INTMASK, ~0);
  1197. }
  1198. static int tsi108_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1199. {
  1200. struct tsi108_prv_data *data = netdev_priv(dev);
  1201. unsigned long flags;
  1202. int rc;
  1203. spin_lock_irqsave(&data->txlock, flags);
  1204. rc = mii_ethtool_gset(&data->mii_if, cmd);
  1205. spin_unlock_irqrestore(&data->txlock, flags);
  1206. return rc;
  1207. }
  1208. static int tsi108_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1209. {
  1210. struct tsi108_prv_data *data = netdev_priv(dev);
  1211. unsigned long flags;
  1212. int rc;
  1213. spin_lock_irqsave(&data->txlock, flags);
  1214. rc = mii_ethtool_sset(&data->mii_if, cmd);
  1215. spin_unlock_irqrestore(&data->txlock, flags);
  1216. return rc;
  1217. }
  1218. static int tsi108_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1219. {
  1220. struct tsi108_prv_data *data = netdev_priv(dev);
  1221. if (!netif_running(dev))
  1222. return -EINVAL;
  1223. return generic_mii_ioctl(&data->mii_if, if_mii(rq), cmd, NULL);
  1224. }
  1225. static const struct ethtool_ops tsi108_ethtool_ops = {
  1226. .get_link = ethtool_op_get_link,
  1227. .get_settings = tsi108_get_settings,
  1228. .set_settings = tsi108_set_settings,
  1229. };
  1230. static const struct net_device_ops tsi108_netdev_ops = {
  1231. .ndo_open = tsi108_open,
  1232. .ndo_stop = tsi108_close,
  1233. .ndo_start_xmit = tsi108_send_packet,
  1234. .ndo_set_rx_mode = tsi108_set_rx_mode,
  1235. .ndo_get_stats = tsi108_get_stats,
  1236. .ndo_do_ioctl = tsi108_do_ioctl,
  1237. .ndo_set_mac_address = tsi108_set_mac,
  1238. .ndo_validate_addr = eth_validate_addr,
  1239. .ndo_change_mtu = eth_change_mtu,
  1240. };
  1241. static int
  1242. tsi108_init_one(struct platform_device *pdev)
  1243. {
  1244. struct net_device *dev = NULL;
  1245. struct tsi108_prv_data *data = NULL;
  1246. hw_info *einfo;
  1247. int err = 0;
  1248. einfo = dev_get_platdata(&pdev->dev);
  1249. if (NULL == einfo) {
  1250. printk(KERN_ERR "tsi-eth %d: Missing additional data!\n",
  1251. pdev->id);
  1252. return -ENODEV;
  1253. }
  1254. /* Create an ethernet device instance */
  1255. dev = alloc_etherdev(sizeof(struct tsi108_prv_data));
  1256. if (!dev)
  1257. return -ENOMEM;
  1258. printk("tsi108_eth%d: probe...\n", pdev->id);
  1259. data = netdev_priv(dev);
  1260. data->dev = dev;
  1261. pr_debug("tsi108_eth%d:regs:phyresgs:phy:irq_num=0x%x:0x%x:0x%x:0x%x\n",
  1262. pdev->id, einfo->regs, einfo->phyregs,
  1263. einfo->phy, einfo->irq_num);
  1264. data->regs = ioremap(einfo->regs, 0x400);
  1265. if (NULL == data->regs) {
  1266. err = -ENOMEM;
  1267. goto regs_fail;
  1268. }
  1269. data->phyregs = ioremap(einfo->phyregs, 0x400);
  1270. if (NULL == data->phyregs) {
  1271. err = -ENOMEM;
  1272. goto phyregs_fail;
  1273. }
  1274. /* MII setup */
  1275. data->mii_if.dev = dev;
  1276. data->mii_if.mdio_read = tsi108_mdio_read;
  1277. data->mii_if.mdio_write = tsi108_mdio_write;
  1278. data->mii_if.phy_id = einfo->phy;
  1279. data->mii_if.phy_id_mask = 0x1f;
  1280. data->mii_if.reg_num_mask = 0x1f;
  1281. data->phy = einfo->phy;
  1282. data->phy_type = einfo->phy_type;
  1283. data->irq_num = einfo->irq_num;
  1284. data->id = pdev->id;
  1285. netif_napi_add(dev, &data->napi, tsi108_poll, 64);
  1286. dev->netdev_ops = &tsi108_netdev_ops;
  1287. dev->ethtool_ops = &tsi108_ethtool_ops;
  1288. /* Apparently, the Linux networking code won't use scatter-gather
  1289. * if the hardware doesn't do checksums. However, it's faster
  1290. * to checksum in place and use SG, as (among other reasons)
  1291. * the cache won't be dirtied (which then has to be flushed
  1292. * before DMA). The checksumming is done by the driver (via
  1293. * a new function skb_csum_dev() in net/core/skbuff.c).
  1294. */
  1295. dev->features = NETIF_F_HIGHDMA;
  1296. spin_lock_init(&data->txlock);
  1297. spin_lock_init(&data->misclock);
  1298. tsi108_reset_ether(data);
  1299. tsi108_kill_phy(dev);
  1300. if ((err = tsi108_get_mac(dev)) != 0) {
  1301. printk(KERN_ERR "%s: Invalid MAC address. Please correct.\n",
  1302. dev->name);
  1303. goto register_fail;
  1304. }
  1305. tsi108_init_mac(dev);
  1306. err = register_netdev(dev);
  1307. if (err) {
  1308. printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
  1309. dev->name);
  1310. goto register_fail;
  1311. }
  1312. platform_set_drvdata(pdev, dev);
  1313. printk(KERN_INFO "%s: Tsi108 Gigabit Ethernet, MAC: %pM\n",
  1314. dev->name, dev->dev_addr);
  1315. #ifdef DEBUG
  1316. data->msg_enable = DEBUG;
  1317. dump_eth_one(dev);
  1318. #endif
  1319. return 0;
  1320. register_fail:
  1321. iounmap(data->phyregs);
  1322. phyregs_fail:
  1323. iounmap(data->regs);
  1324. regs_fail:
  1325. free_netdev(dev);
  1326. return err;
  1327. }
  1328. /* There's no way to either get interrupts from the PHY when
  1329. * something changes, or to have the Tsi108 automatically communicate
  1330. * with the PHY to reconfigure itself.
  1331. *
  1332. * Thus, we have to do it using a timer.
  1333. */
  1334. static void tsi108_timed_checker(unsigned long dev_ptr)
  1335. {
  1336. struct net_device *dev = (struct net_device *)dev_ptr;
  1337. struct tsi108_prv_data *data = netdev_priv(dev);
  1338. tsi108_check_phy(dev);
  1339. tsi108_check_rxring(dev);
  1340. mod_timer(&data->timer, jiffies + CHECK_PHY_INTERVAL);
  1341. }
  1342. static int tsi108_ether_remove(struct platform_device *pdev)
  1343. {
  1344. struct net_device *dev = platform_get_drvdata(pdev);
  1345. struct tsi108_prv_data *priv = netdev_priv(dev);
  1346. unregister_netdev(dev);
  1347. tsi108_stop_ethernet(dev);
  1348. iounmap(priv->regs);
  1349. iounmap(priv->phyregs);
  1350. free_netdev(dev);
  1351. return 0;
  1352. }
  1353. module_platform_driver(tsi_eth_driver);
  1354. MODULE_AUTHOR("Tundra Semiconductor Corporation");
  1355. MODULE_DESCRIPTION("Tsi108 Gigabit Ethernet driver");
  1356. MODULE_LICENSE("GPL");
  1357. MODULE_ALIAS("platform:tsi-ethernet");