uli526x.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  1. /*
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. as published by the Free Software Foundation; either version 2
  5. of the License, or (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #define DRV_NAME "uli526x"
  13. #define DRV_VERSION "0.9.3"
  14. #define DRV_RELDATE "2005-7-29"
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/timer.h>
  19. #include <linux/errno.h>
  20. #include <linux/ioport.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/pci.h>
  23. #include <linux/init.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/delay.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/bitops.h>
  32. #include <asm/processor.h>
  33. #include <asm/io.h>
  34. #include <asm/dma.h>
  35. #include <asm/uaccess.h>
  36. #define uw32(reg, val) iowrite32(val, ioaddr + (reg))
  37. #define ur32(reg) ioread32(ioaddr + (reg))
  38. /* Board/System/Debug information/definition ---------------- */
  39. #define PCI_ULI5261_ID 0x526110B9 /* ULi M5261 ID*/
  40. #define PCI_ULI5263_ID 0x526310B9 /* ULi M5263 ID*/
  41. #define ULI526X_IO_SIZE 0x100
  42. #define TX_DESC_CNT 0x20 /* Allocated Tx descriptors */
  43. #define RX_DESC_CNT 0x30 /* Allocated Rx descriptors */
  44. #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2) /* Max TX packet count */
  45. #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3) /* TX wakeup count */
  46. #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
  47. #define TX_BUF_ALLOC 0x600
  48. #define RX_ALLOC_SIZE 0x620
  49. #define ULI526X_RESET 1
  50. #define CR0_DEFAULT 0
  51. #define CR6_DEFAULT 0x22200000
  52. #define CR7_DEFAULT 0x180c1
  53. #define CR15_DEFAULT 0x06 /* TxJabber RxWatchdog */
  54. #define TDES0_ERR_MASK 0x4302 /* TXJT, LC, EC, FUE */
  55. #define MAX_PACKET_SIZE 1514
  56. #define ULI5261_MAX_MULTICAST 14
  57. #define RX_COPY_SIZE 100
  58. #define MAX_CHECK_PACKET 0x8000
  59. #define ULI526X_10MHF 0
  60. #define ULI526X_100MHF 1
  61. #define ULI526X_10MFD 4
  62. #define ULI526X_100MFD 5
  63. #define ULI526X_AUTO 8
  64. #define ULI526X_TXTH_72 0x400000 /* TX TH 72 byte */
  65. #define ULI526X_TXTH_96 0x404000 /* TX TH 96 byte */
  66. #define ULI526X_TXTH_128 0x0000 /* TX TH 128 byte */
  67. #define ULI526X_TXTH_256 0x4000 /* TX TH 256 byte */
  68. #define ULI526X_TXTH_512 0x8000 /* TX TH 512 byte */
  69. #define ULI526X_TXTH_1K 0xC000 /* TX TH 1K byte */
  70. #define ULI526X_TIMER_WUT (jiffies + HZ * 1)/* timer wakeup time : 1 second */
  71. #define ULI526X_TX_TIMEOUT ((16*HZ)/2) /* tx packet time-out time 8 s" */
  72. #define ULI526X_TX_KICK (4*HZ/2) /* tx packet Kick-out time 2 s" */
  73. #define ULI526X_DBUG(dbug_now, msg, value) \
  74. do { \
  75. if (uli526x_debug || (dbug_now)) \
  76. pr_err("%s %lx\n", (msg), (long) (value)); \
  77. } while (0)
  78. #define SHOW_MEDIA_TYPE(mode) \
  79. pr_err("Change Speed to %sMhz %s duplex\n", \
  80. mode & 1 ? "100" : "10", \
  81. mode & 4 ? "full" : "half");
  82. /* CR9 definition: SROM/MII */
  83. #define CR9_SROM_READ 0x4800
  84. #define CR9_SRCS 0x1
  85. #define CR9_SRCLK 0x2
  86. #define CR9_CRDOUT 0x8
  87. #define SROM_DATA_0 0x0
  88. #define SROM_DATA_1 0x4
  89. #define PHY_DATA_1 0x20000
  90. #define PHY_DATA_0 0x00000
  91. #define MDCLKH 0x10000
  92. #define PHY_POWER_DOWN 0x800
  93. #define SROM_V41_CODE 0x14
  94. /* Structure/enum declaration ------------------------------- */
  95. struct tx_desc {
  96. __le32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */
  97. char *tx_buf_ptr; /* Data for us */
  98. struct tx_desc *next_tx_desc;
  99. } __attribute__(( aligned(32) ));
  100. struct rx_desc {
  101. __le32 rdes0, rdes1, rdes2, rdes3; /* Data for the card */
  102. struct sk_buff *rx_skb_ptr; /* Data for us */
  103. struct rx_desc *next_rx_desc;
  104. } __attribute__(( aligned(32) ));
  105. struct uli526x_board_info {
  106. struct uli_phy_ops {
  107. void (*write)(struct uli526x_board_info *, u8, u8, u16);
  108. u16 (*read)(struct uli526x_board_info *, u8, u8);
  109. } phy;
  110. struct net_device *next_dev; /* next device */
  111. struct pci_dev *pdev; /* PCI device */
  112. spinlock_t lock;
  113. void __iomem *ioaddr; /* I/O base address */
  114. u32 cr0_data;
  115. u32 cr5_data;
  116. u32 cr6_data;
  117. u32 cr7_data;
  118. u32 cr15_data;
  119. /* pointer for memory physical address */
  120. dma_addr_t buf_pool_dma_ptr; /* Tx buffer pool memory */
  121. dma_addr_t buf_pool_dma_start; /* Tx buffer pool align dword */
  122. dma_addr_t desc_pool_dma_ptr; /* descriptor pool memory */
  123. dma_addr_t first_tx_desc_dma;
  124. dma_addr_t first_rx_desc_dma;
  125. /* descriptor pointer */
  126. unsigned char *buf_pool_ptr; /* Tx buffer pool memory */
  127. unsigned char *buf_pool_start; /* Tx buffer pool align dword */
  128. unsigned char *desc_pool_ptr; /* descriptor pool memory */
  129. struct tx_desc *first_tx_desc;
  130. struct tx_desc *tx_insert_ptr;
  131. struct tx_desc *tx_remove_ptr;
  132. struct rx_desc *first_rx_desc;
  133. struct rx_desc *rx_insert_ptr;
  134. struct rx_desc *rx_ready_ptr; /* packet come pointer */
  135. unsigned long tx_packet_cnt; /* transmitted packet count */
  136. unsigned long rx_avail_cnt; /* available rx descriptor count */
  137. unsigned long interval_rx_cnt; /* rx packet count a callback time */
  138. u16 dbug_cnt;
  139. u16 NIC_capability; /* NIC media capability */
  140. u16 PHY_reg4; /* Saved Phyxcer register 4 value */
  141. u8 media_mode; /* user specify media mode */
  142. u8 op_mode; /* real work media mode */
  143. u8 phy_addr;
  144. u8 link_failed; /* Ever link failed */
  145. u8 wait_reset; /* Hardware failed, need to reset */
  146. struct timer_list timer;
  147. /* Driver defined statistic counter */
  148. unsigned long tx_fifo_underrun;
  149. unsigned long tx_loss_carrier;
  150. unsigned long tx_no_carrier;
  151. unsigned long tx_late_collision;
  152. unsigned long tx_excessive_collision;
  153. unsigned long tx_jabber_timeout;
  154. unsigned long reset_count;
  155. unsigned long reset_cr8;
  156. unsigned long reset_fatal;
  157. unsigned long reset_TXtimeout;
  158. /* NIC SROM data */
  159. unsigned char srom[128];
  160. u8 init;
  161. };
  162. enum uli526x_offsets {
  163. DCR0 = 0x00, DCR1 = 0x08, DCR2 = 0x10, DCR3 = 0x18, DCR4 = 0x20,
  164. DCR5 = 0x28, DCR6 = 0x30, DCR7 = 0x38, DCR8 = 0x40, DCR9 = 0x48,
  165. DCR10 = 0x50, DCR11 = 0x58, DCR12 = 0x60, DCR13 = 0x68, DCR14 = 0x70,
  166. DCR15 = 0x78
  167. };
  168. enum uli526x_CR6_bits {
  169. CR6_RXSC = 0x2, CR6_PBF = 0x8, CR6_PM = 0x40, CR6_PAM = 0x80,
  170. CR6_FDM = 0x200, CR6_TXSC = 0x2000, CR6_STI = 0x100000,
  171. CR6_SFT = 0x200000, CR6_RXA = 0x40000000, CR6_NO_PURGE = 0x20000000
  172. };
  173. /* Global variable declaration ----------------------------- */
  174. static int printed_version;
  175. static const char version[] =
  176. "ULi M5261/M5263 net driver, version " DRV_VERSION " (" DRV_RELDATE ")";
  177. static int uli526x_debug;
  178. static unsigned char uli526x_media_mode = ULI526X_AUTO;
  179. static u32 uli526x_cr6_user_set;
  180. /* For module input parameter */
  181. static int debug;
  182. static u32 cr6set;
  183. static int mode = 8;
  184. /* function declaration ------------------------------------- */
  185. static int uli526x_open(struct net_device *);
  186. static netdev_tx_t uli526x_start_xmit(struct sk_buff *,
  187. struct net_device *);
  188. static int uli526x_stop(struct net_device *);
  189. static void uli526x_set_filter_mode(struct net_device *);
  190. static const struct ethtool_ops netdev_ethtool_ops;
  191. static u16 read_srom_word(struct uli526x_board_info *, int);
  192. static irqreturn_t uli526x_interrupt(int, void *);
  193. #ifdef CONFIG_NET_POLL_CONTROLLER
  194. static void uli526x_poll(struct net_device *dev);
  195. #endif
  196. static void uli526x_descriptor_init(struct net_device *, void __iomem *);
  197. static void allocate_rx_buffer(struct net_device *);
  198. static void update_cr6(u32, void __iomem *);
  199. static void send_filter_frame(struct net_device *, int);
  200. static u16 phy_readby_cr9(struct uli526x_board_info *, u8, u8);
  201. static u16 phy_readby_cr10(struct uli526x_board_info *, u8, u8);
  202. static void phy_writeby_cr9(struct uli526x_board_info *, u8, u8, u16);
  203. static void phy_writeby_cr10(struct uli526x_board_info *, u8, u8, u16);
  204. static void phy_write_1bit(struct uli526x_board_info *db, u32);
  205. static u16 phy_read_1bit(struct uli526x_board_info *db);
  206. static u8 uli526x_sense_speed(struct uli526x_board_info *);
  207. static void uli526x_process_mode(struct uli526x_board_info *);
  208. static void uli526x_timer(unsigned long);
  209. static void uli526x_rx_packet(struct net_device *, struct uli526x_board_info *);
  210. static void uli526x_free_tx_pkt(struct net_device *, struct uli526x_board_info *);
  211. static void uli526x_reuse_skb(struct uli526x_board_info *, struct sk_buff *);
  212. static void uli526x_dynamic_reset(struct net_device *);
  213. static void uli526x_free_rxbuffer(struct uli526x_board_info *);
  214. static void uli526x_init(struct net_device *);
  215. static void uli526x_set_phyxcer(struct uli526x_board_info *);
  216. static void srom_clk_write(struct uli526x_board_info *db, u32 data)
  217. {
  218. void __iomem *ioaddr = db->ioaddr;
  219. uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS);
  220. udelay(5);
  221. uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS | CR9_SRCLK);
  222. udelay(5);
  223. uw32(DCR9, data | CR9_SROM_READ | CR9_SRCS);
  224. udelay(5);
  225. }
  226. /* ULI526X network board routine ---------------------------- */
  227. static const struct net_device_ops netdev_ops = {
  228. .ndo_open = uli526x_open,
  229. .ndo_stop = uli526x_stop,
  230. .ndo_start_xmit = uli526x_start_xmit,
  231. .ndo_set_rx_mode = uli526x_set_filter_mode,
  232. .ndo_change_mtu = eth_change_mtu,
  233. .ndo_set_mac_address = eth_mac_addr,
  234. .ndo_validate_addr = eth_validate_addr,
  235. #ifdef CONFIG_NET_POLL_CONTROLLER
  236. .ndo_poll_controller = uli526x_poll,
  237. #endif
  238. };
  239. /*
  240. * Search ULI526X board, allocate space and register it
  241. */
  242. static int uli526x_init_one(struct pci_dev *pdev,
  243. const struct pci_device_id *ent)
  244. {
  245. struct uli526x_board_info *db; /* board information structure */
  246. struct net_device *dev;
  247. void __iomem *ioaddr;
  248. int i, err;
  249. ULI526X_DBUG(0, "uli526x_init_one()", 0);
  250. if (!printed_version++)
  251. pr_info("%s\n", version);
  252. /* Init network device */
  253. dev = alloc_etherdev(sizeof(*db));
  254. if (dev == NULL)
  255. return -ENOMEM;
  256. SET_NETDEV_DEV(dev, &pdev->dev);
  257. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  258. pr_warn("32-bit PCI DMA not available\n");
  259. err = -ENODEV;
  260. goto err_out_free;
  261. }
  262. /* Enable Master/IO access, Disable memory access */
  263. err = pci_enable_device(pdev);
  264. if (err)
  265. goto err_out_free;
  266. if (!pci_resource_start(pdev, 0)) {
  267. pr_err("I/O base is zero\n");
  268. err = -ENODEV;
  269. goto err_out_disable;
  270. }
  271. if (pci_resource_len(pdev, 0) < (ULI526X_IO_SIZE) ) {
  272. pr_err("Allocated I/O size too small\n");
  273. err = -ENODEV;
  274. goto err_out_disable;
  275. }
  276. err = pci_request_regions(pdev, DRV_NAME);
  277. if (err < 0) {
  278. pr_err("Failed to request PCI regions\n");
  279. goto err_out_disable;
  280. }
  281. /* Init system & device */
  282. db = netdev_priv(dev);
  283. /* Allocate Tx/Rx descriptor memory */
  284. err = -ENOMEM;
  285. db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
  286. if (!db->desc_pool_ptr)
  287. goto err_out_release;
  288. db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
  289. if (!db->buf_pool_ptr)
  290. goto err_out_free_tx_desc;
  291. db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
  292. db->first_tx_desc_dma = db->desc_pool_dma_ptr;
  293. db->buf_pool_start = db->buf_pool_ptr;
  294. db->buf_pool_dma_start = db->buf_pool_dma_ptr;
  295. switch (ent->driver_data) {
  296. case PCI_ULI5263_ID:
  297. db->phy.write = phy_writeby_cr10;
  298. db->phy.read = phy_readby_cr10;
  299. break;
  300. default:
  301. db->phy.write = phy_writeby_cr9;
  302. db->phy.read = phy_readby_cr9;
  303. break;
  304. }
  305. /* IO region. */
  306. ioaddr = pci_iomap(pdev, 0, 0);
  307. if (!ioaddr)
  308. goto err_out_free_tx_buf;
  309. db->ioaddr = ioaddr;
  310. db->pdev = pdev;
  311. db->init = 1;
  312. pci_set_drvdata(pdev, dev);
  313. /* Register some necessary functions */
  314. dev->netdev_ops = &netdev_ops;
  315. dev->ethtool_ops = &netdev_ethtool_ops;
  316. spin_lock_init(&db->lock);
  317. /* read 64 word srom data */
  318. for (i = 0; i < 64; i++)
  319. ((__le16 *) db->srom)[i] = cpu_to_le16(read_srom_word(db, i));
  320. /* Set Node address */
  321. if(((u16 *) db->srom)[0] == 0xffff || ((u16 *) db->srom)[0] == 0) /* SROM absent, so read MAC address from ID Table */
  322. {
  323. uw32(DCR0, 0x10000); //Diagnosis mode
  324. uw32(DCR13, 0x1c0); //Reset dianostic pointer port
  325. uw32(DCR14, 0); //Clear reset port
  326. uw32(DCR14, 0x10); //Reset ID Table pointer
  327. uw32(DCR14, 0); //Clear reset port
  328. uw32(DCR13, 0); //Clear CR13
  329. uw32(DCR13, 0x1b0); //Select ID Table access port
  330. //Read MAC address from CR14
  331. for (i = 0; i < 6; i++)
  332. dev->dev_addr[i] = ur32(DCR14);
  333. //Read end
  334. uw32(DCR13, 0); //Clear CR13
  335. uw32(DCR0, 0); //Clear CR0
  336. udelay(10);
  337. }
  338. else /*Exist SROM*/
  339. {
  340. for (i = 0; i < 6; i++)
  341. dev->dev_addr[i] = db->srom[20 + i];
  342. }
  343. err = register_netdev (dev);
  344. if (err)
  345. goto err_out_unmap;
  346. netdev_info(dev, "ULi M%04lx at pci%s, %pM, irq %d\n",
  347. ent->driver_data >> 16, pci_name(pdev),
  348. dev->dev_addr, pdev->irq);
  349. pci_set_master(pdev);
  350. return 0;
  351. err_out_unmap:
  352. pci_iounmap(pdev, db->ioaddr);
  353. err_out_free_tx_buf:
  354. pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
  355. db->buf_pool_ptr, db->buf_pool_dma_ptr);
  356. err_out_free_tx_desc:
  357. pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20,
  358. db->desc_pool_ptr, db->desc_pool_dma_ptr);
  359. err_out_release:
  360. pci_release_regions(pdev);
  361. err_out_disable:
  362. pci_disable_device(pdev);
  363. err_out_free:
  364. free_netdev(dev);
  365. return err;
  366. }
  367. static void uli526x_remove_one(struct pci_dev *pdev)
  368. {
  369. struct net_device *dev = pci_get_drvdata(pdev);
  370. struct uli526x_board_info *db = netdev_priv(dev);
  371. unregister_netdev(dev);
  372. pci_iounmap(pdev, db->ioaddr);
  373. pci_free_consistent(db->pdev, sizeof(struct tx_desc) *
  374. DESC_ALL_CNT + 0x20, db->desc_pool_ptr,
  375. db->desc_pool_dma_ptr);
  376. pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
  377. db->buf_pool_ptr, db->buf_pool_dma_ptr);
  378. pci_release_regions(pdev);
  379. pci_disable_device(pdev);
  380. free_netdev(dev);
  381. }
  382. /*
  383. * Open the interface.
  384. * The interface is opened whenever "ifconfig" activates it.
  385. */
  386. static int uli526x_open(struct net_device *dev)
  387. {
  388. int ret;
  389. struct uli526x_board_info *db = netdev_priv(dev);
  390. ULI526X_DBUG(0, "uli526x_open", 0);
  391. /* system variable init */
  392. db->cr6_data = CR6_DEFAULT | uli526x_cr6_user_set;
  393. db->tx_packet_cnt = 0;
  394. db->rx_avail_cnt = 0;
  395. db->link_failed = 1;
  396. netif_carrier_off(dev);
  397. db->wait_reset = 0;
  398. db->NIC_capability = 0xf; /* All capability*/
  399. db->PHY_reg4 = 0x1e0;
  400. /* CR6 operation mode decision */
  401. db->cr6_data |= ULI526X_TXTH_256;
  402. db->cr0_data = CR0_DEFAULT;
  403. /* Initialize ULI526X board */
  404. uli526x_init(dev);
  405. ret = request_irq(db->pdev->irq, uli526x_interrupt, IRQF_SHARED,
  406. dev->name, dev);
  407. if (ret)
  408. return ret;
  409. /* Active System Interface */
  410. netif_wake_queue(dev);
  411. /* set and active a timer process */
  412. init_timer(&db->timer);
  413. db->timer.expires = ULI526X_TIMER_WUT + HZ * 2;
  414. db->timer.data = (unsigned long)dev;
  415. db->timer.function = uli526x_timer;
  416. add_timer(&db->timer);
  417. return 0;
  418. }
  419. /* Initialize ULI526X board
  420. * Reset ULI526X board
  421. * Initialize TX/Rx descriptor chain structure
  422. * Send the set-up frame
  423. * Enable Tx/Rx machine
  424. */
  425. static void uli526x_init(struct net_device *dev)
  426. {
  427. struct uli526x_board_info *db = netdev_priv(dev);
  428. struct uli_phy_ops *phy = &db->phy;
  429. void __iomem *ioaddr = db->ioaddr;
  430. u8 phy_tmp;
  431. u8 timeout;
  432. u16 phy_reg_reset;
  433. ULI526X_DBUG(0, "uli526x_init()", 0);
  434. /* Reset M526x MAC controller */
  435. uw32(DCR0, ULI526X_RESET); /* RESET MAC */
  436. udelay(100);
  437. uw32(DCR0, db->cr0_data);
  438. udelay(5);
  439. /* Phy addr : In some boards,M5261/M5263 phy address != 1 */
  440. db->phy_addr = 1;
  441. for (phy_tmp = 0; phy_tmp < 32; phy_tmp++) {
  442. u16 phy_value;
  443. phy_value = phy->read(db, phy_tmp, 3); //peer add
  444. if (phy_value != 0xffff && phy_value != 0) {
  445. db->phy_addr = phy_tmp;
  446. break;
  447. }
  448. }
  449. if (phy_tmp == 32)
  450. pr_warn("Can not find the phy address!!!\n");
  451. /* Parser SROM and media mode */
  452. db->media_mode = uli526x_media_mode;
  453. /* phyxcer capability setting */
  454. phy_reg_reset = phy->read(db, db->phy_addr, 0);
  455. phy_reg_reset = (phy_reg_reset | 0x8000);
  456. phy->write(db, db->phy_addr, 0, phy_reg_reset);
  457. /* See IEEE 802.3-2002.pdf (Section 2, Chapter "22.2.4 Management
  458. * functions") or phy data sheet for details on phy reset
  459. */
  460. udelay(500);
  461. timeout = 10;
  462. while (timeout-- && phy->read(db, db->phy_addr, 0) & 0x8000)
  463. udelay(100);
  464. /* Process Phyxcer Media Mode */
  465. uli526x_set_phyxcer(db);
  466. /* Media Mode Process */
  467. if ( !(db->media_mode & ULI526X_AUTO) )
  468. db->op_mode = db->media_mode; /* Force Mode */
  469. /* Initialize Transmit/Receive descriptor and CR3/4 */
  470. uli526x_descriptor_init(dev, ioaddr);
  471. /* Init CR6 to program M526X operation */
  472. update_cr6(db->cr6_data, ioaddr);
  473. /* Send setup frame */
  474. send_filter_frame(dev, netdev_mc_count(dev)); /* M5261/M5263 */
  475. /* Init CR7, interrupt active bit */
  476. db->cr7_data = CR7_DEFAULT;
  477. uw32(DCR7, db->cr7_data);
  478. /* Init CR15, Tx jabber and Rx watchdog timer */
  479. uw32(DCR15, db->cr15_data);
  480. /* Enable ULI526X Tx/Rx function */
  481. db->cr6_data |= CR6_RXSC | CR6_TXSC;
  482. update_cr6(db->cr6_data, ioaddr);
  483. }
  484. /*
  485. * Hardware start transmission.
  486. * Send a packet to media from the upper layer.
  487. */
  488. static netdev_tx_t uli526x_start_xmit(struct sk_buff *skb,
  489. struct net_device *dev)
  490. {
  491. struct uli526x_board_info *db = netdev_priv(dev);
  492. void __iomem *ioaddr = db->ioaddr;
  493. struct tx_desc *txptr;
  494. unsigned long flags;
  495. ULI526X_DBUG(0, "uli526x_start_xmit", 0);
  496. /* Resource flag check */
  497. netif_stop_queue(dev);
  498. /* Too large packet check */
  499. if (skb->len > MAX_PACKET_SIZE) {
  500. netdev_err(dev, "big packet = %d\n", (u16)skb->len);
  501. dev_kfree_skb_any(skb);
  502. return NETDEV_TX_OK;
  503. }
  504. spin_lock_irqsave(&db->lock, flags);
  505. /* No Tx resource check, it never happen nromally */
  506. if (db->tx_packet_cnt >= TX_FREE_DESC_CNT) {
  507. spin_unlock_irqrestore(&db->lock, flags);
  508. netdev_err(dev, "No Tx resource %ld\n", db->tx_packet_cnt);
  509. return NETDEV_TX_BUSY;
  510. }
  511. /* Disable NIC interrupt */
  512. uw32(DCR7, 0);
  513. /* transmit this packet */
  514. txptr = db->tx_insert_ptr;
  515. skb_copy_from_linear_data(skb, txptr->tx_buf_ptr, skb->len);
  516. txptr->tdes1 = cpu_to_le32(0xe1000000 | skb->len);
  517. /* Point to next transmit free descriptor */
  518. db->tx_insert_ptr = txptr->next_tx_desc;
  519. /* Transmit Packet Process */
  520. if (db->tx_packet_cnt < TX_DESC_CNT) {
  521. txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
  522. db->tx_packet_cnt++; /* Ready to send */
  523. uw32(DCR1, 0x1); /* Issue Tx polling */
  524. dev->trans_start = jiffies; /* saved time stamp */
  525. }
  526. /* Tx resource check */
  527. if ( db->tx_packet_cnt < TX_FREE_DESC_CNT )
  528. netif_wake_queue(dev);
  529. /* Restore CR7 to enable interrupt */
  530. spin_unlock_irqrestore(&db->lock, flags);
  531. uw32(DCR7, db->cr7_data);
  532. /* free this SKB */
  533. dev_consume_skb_any(skb);
  534. return NETDEV_TX_OK;
  535. }
  536. /*
  537. * Stop the interface.
  538. * The interface is stopped when it is brought.
  539. */
  540. static int uli526x_stop(struct net_device *dev)
  541. {
  542. struct uli526x_board_info *db = netdev_priv(dev);
  543. void __iomem *ioaddr = db->ioaddr;
  544. /* disable system */
  545. netif_stop_queue(dev);
  546. /* deleted timer */
  547. del_timer_sync(&db->timer);
  548. /* Reset & stop ULI526X board */
  549. uw32(DCR0, ULI526X_RESET);
  550. udelay(5);
  551. db->phy.write(db, db->phy_addr, 0, 0x8000);
  552. /* free interrupt */
  553. free_irq(db->pdev->irq, dev);
  554. /* free allocated rx buffer */
  555. uli526x_free_rxbuffer(db);
  556. return 0;
  557. }
  558. /*
  559. * M5261/M5263 insterrupt handler
  560. * receive the packet to upper layer, free the transmitted packet
  561. */
  562. static irqreturn_t uli526x_interrupt(int irq, void *dev_id)
  563. {
  564. struct net_device *dev = dev_id;
  565. struct uli526x_board_info *db = netdev_priv(dev);
  566. void __iomem *ioaddr = db->ioaddr;
  567. unsigned long flags;
  568. spin_lock_irqsave(&db->lock, flags);
  569. uw32(DCR7, 0);
  570. /* Got ULI526X status */
  571. db->cr5_data = ur32(DCR5);
  572. uw32(DCR5, db->cr5_data);
  573. if ( !(db->cr5_data & 0x180c1) ) {
  574. /* Restore CR7 to enable interrupt mask */
  575. uw32(DCR7, db->cr7_data);
  576. spin_unlock_irqrestore(&db->lock, flags);
  577. return IRQ_HANDLED;
  578. }
  579. /* Check system status */
  580. if (db->cr5_data & 0x2000) {
  581. /* system bus error happen */
  582. ULI526X_DBUG(1, "System bus error happen. CR5=", db->cr5_data);
  583. db->reset_fatal++;
  584. db->wait_reset = 1; /* Need to RESET */
  585. spin_unlock_irqrestore(&db->lock, flags);
  586. return IRQ_HANDLED;
  587. }
  588. /* Received the coming packet */
  589. if ( (db->cr5_data & 0x40) && db->rx_avail_cnt )
  590. uli526x_rx_packet(dev, db);
  591. /* reallocate rx descriptor buffer */
  592. if (db->rx_avail_cnt<RX_DESC_CNT)
  593. allocate_rx_buffer(dev);
  594. /* Free the transmitted descriptor */
  595. if ( db->cr5_data & 0x01)
  596. uli526x_free_tx_pkt(dev, db);
  597. /* Restore CR7 to enable interrupt mask */
  598. uw32(DCR7, db->cr7_data);
  599. spin_unlock_irqrestore(&db->lock, flags);
  600. return IRQ_HANDLED;
  601. }
  602. #ifdef CONFIG_NET_POLL_CONTROLLER
  603. static void uli526x_poll(struct net_device *dev)
  604. {
  605. struct uli526x_board_info *db = netdev_priv(dev);
  606. /* ISR grabs the irqsave lock, so this should be safe */
  607. uli526x_interrupt(db->pdev->irq, dev);
  608. }
  609. #endif
  610. /*
  611. * Free TX resource after TX complete
  612. */
  613. static void uli526x_free_tx_pkt(struct net_device *dev,
  614. struct uli526x_board_info * db)
  615. {
  616. struct tx_desc *txptr;
  617. u32 tdes0;
  618. txptr = db->tx_remove_ptr;
  619. while(db->tx_packet_cnt) {
  620. tdes0 = le32_to_cpu(txptr->tdes0);
  621. if (tdes0 & 0x80000000)
  622. break;
  623. /* A packet sent completed */
  624. db->tx_packet_cnt--;
  625. dev->stats.tx_packets++;
  626. /* Transmit statistic counter */
  627. if ( tdes0 != 0x7fffffff ) {
  628. dev->stats.collisions += (tdes0 >> 3) & 0xf;
  629. dev->stats.tx_bytes += le32_to_cpu(txptr->tdes1) & 0x7ff;
  630. if (tdes0 & TDES0_ERR_MASK) {
  631. dev->stats.tx_errors++;
  632. if (tdes0 & 0x0002) { /* UnderRun */
  633. db->tx_fifo_underrun++;
  634. if ( !(db->cr6_data & CR6_SFT) ) {
  635. db->cr6_data = db->cr6_data | CR6_SFT;
  636. update_cr6(db->cr6_data, db->ioaddr);
  637. }
  638. }
  639. if (tdes0 & 0x0100)
  640. db->tx_excessive_collision++;
  641. if (tdes0 & 0x0200)
  642. db->tx_late_collision++;
  643. if (tdes0 & 0x0400)
  644. db->tx_no_carrier++;
  645. if (tdes0 & 0x0800)
  646. db->tx_loss_carrier++;
  647. if (tdes0 & 0x4000)
  648. db->tx_jabber_timeout++;
  649. }
  650. }
  651. txptr = txptr->next_tx_desc;
  652. }/* End of while */
  653. /* Update TX remove pointer to next */
  654. db->tx_remove_ptr = txptr;
  655. /* Resource available check */
  656. if ( db->tx_packet_cnt < TX_WAKE_DESC_CNT )
  657. netif_wake_queue(dev); /* Active upper layer, send again */
  658. }
  659. /*
  660. * Receive the come packet and pass to upper layer
  661. */
  662. static void uli526x_rx_packet(struct net_device *dev, struct uli526x_board_info * db)
  663. {
  664. struct rx_desc *rxptr;
  665. struct sk_buff *skb;
  666. int rxlen;
  667. u32 rdes0;
  668. rxptr = db->rx_ready_ptr;
  669. while(db->rx_avail_cnt) {
  670. rdes0 = le32_to_cpu(rxptr->rdes0);
  671. if (rdes0 & 0x80000000) /* packet owner check */
  672. {
  673. break;
  674. }
  675. db->rx_avail_cnt--;
  676. db->interval_rx_cnt++;
  677. pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2), RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
  678. if ( (rdes0 & 0x300) != 0x300) {
  679. /* A packet without First/Last flag */
  680. /* reuse this SKB */
  681. ULI526X_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
  682. uli526x_reuse_skb(db, rxptr->rx_skb_ptr);
  683. } else {
  684. /* A packet with First/Last flag */
  685. rxlen = ( (rdes0 >> 16) & 0x3fff) - 4;
  686. /* error summary bit check */
  687. if (rdes0 & 0x8000) {
  688. /* This is a error packet */
  689. dev->stats.rx_errors++;
  690. if (rdes0 & 1)
  691. dev->stats.rx_fifo_errors++;
  692. if (rdes0 & 2)
  693. dev->stats.rx_crc_errors++;
  694. if (rdes0 & 0x80)
  695. dev->stats.rx_length_errors++;
  696. }
  697. if ( !(rdes0 & 0x8000) ||
  698. ((db->cr6_data & CR6_PM) && (rxlen>6)) ) {
  699. struct sk_buff *new_skb = NULL;
  700. skb = rxptr->rx_skb_ptr;
  701. /* Good packet, send to upper layer */
  702. /* Shorst packet used new SKB */
  703. if ((rxlen < RX_COPY_SIZE) &&
  704. (((new_skb = netdev_alloc_skb(dev, rxlen + 2)) != NULL))) {
  705. skb = new_skb;
  706. /* size less than COPY_SIZE, allocate a rxlen SKB */
  707. skb_reserve(skb, 2); /* 16byte align */
  708. memcpy(skb_put(skb, rxlen),
  709. skb_tail_pointer(rxptr->rx_skb_ptr),
  710. rxlen);
  711. uli526x_reuse_skb(db, rxptr->rx_skb_ptr);
  712. } else
  713. skb_put(skb, rxlen);
  714. skb->protocol = eth_type_trans(skb, dev);
  715. netif_rx(skb);
  716. dev->stats.rx_packets++;
  717. dev->stats.rx_bytes += rxlen;
  718. } else {
  719. /* Reuse SKB buffer when the packet is error */
  720. ULI526X_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
  721. uli526x_reuse_skb(db, rxptr->rx_skb_ptr);
  722. }
  723. }
  724. rxptr = rxptr->next_rx_desc;
  725. }
  726. db->rx_ready_ptr = rxptr;
  727. }
  728. /*
  729. * Set ULI526X multicast address
  730. */
  731. static void uli526x_set_filter_mode(struct net_device * dev)
  732. {
  733. struct uli526x_board_info *db = netdev_priv(dev);
  734. unsigned long flags;
  735. ULI526X_DBUG(0, "uli526x_set_filter_mode()", 0);
  736. spin_lock_irqsave(&db->lock, flags);
  737. if (dev->flags & IFF_PROMISC) {
  738. ULI526X_DBUG(0, "Enable PROM Mode", 0);
  739. db->cr6_data |= CR6_PM | CR6_PBF;
  740. update_cr6(db->cr6_data, db->ioaddr);
  741. spin_unlock_irqrestore(&db->lock, flags);
  742. return;
  743. }
  744. if (dev->flags & IFF_ALLMULTI ||
  745. netdev_mc_count(dev) > ULI5261_MAX_MULTICAST) {
  746. ULI526X_DBUG(0, "Pass all multicast address",
  747. netdev_mc_count(dev));
  748. db->cr6_data &= ~(CR6_PM | CR6_PBF);
  749. db->cr6_data |= CR6_PAM;
  750. spin_unlock_irqrestore(&db->lock, flags);
  751. return;
  752. }
  753. ULI526X_DBUG(0, "Set multicast address", netdev_mc_count(dev));
  754. send_filter_frame(dev, netdev_mc_count(dev)); /* M5261/M5263 */
  755. spin_unlock_irqrestore(&db->lock, flags);
  756. }
  757. static void
  758. ULi_ethtool_gset(struct uli526x_board_info *db, struct ethtool_cmd *ecmd)
  759. {
  760. ecmd->supported = (SUPPORTED_10baseT_Half |
  761. SUPPORTED_10baseT_Full |
  762. SUPPORTED_100baseT_Half |
  763. SUPPORTED_100baseT_Full |
  764. SUPPORTED_Autoneg |
  765. SUPPORTED_MII);
  766. ecmd->advertising = (ADVERTISED_10baseT_Half |
  767. ADVERTISED_10baseT_Full |
  768. ADVERTISED_100baseT_Half |
  769. ADVERTISED_100baseT_Full |
  770. ADVERTISED_Autoneg |
  771. ADVERTISED_MII);
  772. ecmd->port = PORT_MII;
  773. ecmd->phy_address = db->phy_addr;
  774. ecmd->transceiver = XCVR_EXTERNAL;
  775. ethtool_cmd_speed_set(ecmd, SPEED_10);
  776. ecmd->duplex = DUPLEX_HALF;
  777. if(db->op_mode==ULI526X_100MHF || db->op_mode==ULI526X_100MFD)
  778. {
  779. ethtool_cmd_speed_set(ecmd, SPEED_100);
  780. }
  781. if(db->op_mode==ULI526X_10MFD || db->op_mode==ULI526X_100MFD)
  782. {
  783. ecmd->duplex = DUPLEX_FULL;
  784. }
  785. if(db->link_failed)
  786. {
  787. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  788. ecmd->duplex = DUPLEX_UNKNOWN;
  789. }
  790. if (db->media_mode & ULI526X_AUTO)
  791. {
  792. ecmd->autoneg = AUTONEG_ENABLE;
  793. }
  794. }
  795. static void netdev_get_drvinfo(struct net_device *dev,
  796. struct ethtool_drvinfo *info)
  797. {
  798. struct uli526x_board_info *np = netdev_priv(dev);
  799. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  800. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  801. strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
  802. }
  803. static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) {
  804. struct uli526x_board_info *np = netdev_priv(dev);
  805. ULi_ethtool_gset(np, cmd);
  806. return 0;
  807. }
  808. static u32 netdev_get_link(struct net_device *dev) {
  809. struct uli526x_board_info *np = netdev_priv(dev);
  810. if(np->link_failed)
  811. return 0;
  812. else
  813. return 1;
  814. }
  815. static void uli526x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  816. {
  817. wol->supported = WAKE_PHY | WAKE_MAGIC;
  818. wol->wolopts = 0;
  819. }
  820. static const struct ethtool_ops netdev_ethtool_ops = {
  821. .get_drvinfo = netdev_get_drvinfo,
  822. .get_settings = netdev_get_settings,
  823. .get_link = netdev_get_link,
  824. .get_wol = uli526x_get_wol,
  825. };
  826. /*
  827. * A periodic timer routine
  828. * Dynamic media sense, allocate Rx buffer...
  829. */
  830. static void uli526x_timer(unsigned long data)
  831. {
  832. struct net_device *dev = (struct net_device *) data;
  833. struct uli526x_board_info *db = netdev_priv(dev);
  834. struct uli_phy_ops *phy = &db->phy;
  835. void __iomem *ioaddr = db->ioaddr;
  836. unsigned long flags;
  837. u8 tmp_cr12 = 0;
  838. u32 tmp_cr8;
  839. //ULI526X_DBUG(0, "uli526x_timer()", 0);
  840. spin_lock_irqsave(&db->lock, flags);
  841. /* Dynamic reset ULI526X : system error or transmit time-out */
  842. tmp_cr8 = ur32(DCR8);
  843. if ( (db->interval_rx_cnt==0) && (tmp_cr8) ) {
  844. db->reset_cr8++;
  845. db->wait_reset = 1;
  846. }
  847. db->interval_rx_cnt = 0;
  848. /* TX polling kick monitor */
  849. if ( db->tx_packet_cnt &&
  850. time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_KICK) ) {
  851. uw32(DCR1, 0x1); // Tx polling again
  852. // TX Timeout
  853. if ( time_after(jiffies, dev_trans_start(dev) + ULI526X_TX_TIMEOUT) ) {
  854. db->reset_TXtimeout++;
  855. db->wait_reset = 1;
  856. netdev_err(dev, " Tx timeout - resetting\n");
  857. }
  858. }
  859. if (db->wait_reset) {
  860. ULI526X_DBUG(0, "Dynamic Reset device", db->tx_packet_cnt);
  861. db->reset_count++;
  862. uli526x_dynamic_reset(dev);
  863. db->timer.expires = ULI526X_TIMER_WUT;
  864. add_timer(&db->timer);
  865. spin_unlock_irqrestore(&db->lock, flags);
  866. return;
  867. }
  868. /* Link status check, Dynamic media type change */
  869. if ((phy->read(db, db->phy_addr, 5) & 0x01e0)!=0)
  870. tmp_cr12 = 3;
  871. if ( !(tmp_cr12 & 0x3) && !db->link_failed ) {
  872. /* Link Failed */
  873. ULI526X_DBUG(0, "Link Failed", tmp_cr12);
  874. netif_carrier_off(dev);
  875. netdev_info(dev, "NIC Link is Down\n");
  876. db->link_failed = 1;
  877. /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
  878. /* AUTO don't need */
  879. if ( !(db->media_mode & 0x8) )
  880. phy->write(db, db->phy_addr, 0, 0x1000);
  881. /* AUTO mode, if INT phyxcer link failed, select EXT device */
  882. if (db->media_mode & ULI526X_AUTO) {
  883. db->cr6_data&=~0x00000200; /* bit9=0, HD mode */
  884. update_cr6(db->cr6_data, db->ioaddr);
  885. }
  886. } else
  887. if ((tmp_cr12 & 0x3) && db->link_failed) {
  888. ULI526X_DBUG(0, "Link link OK", tmp_cr12);
  889. db->link_failed = 0;
  890. /* Auto Sense Speed */
  891. if ( (db->media_mode & ULI526X_AUTO) &&
  892. uli526x_sense_speed(db) )
  893. db->link_failed = 1;
  894. uli526x_process_mode(db);
  895. if(db->link_failed==0)
  896. {
  897. netdev_info(dev, "NIC Link is Up %d Mbps %s duplex\n",
  898. (db->op_mode == ULI526X_100MHF ||
  899. db->op_mode == ULI526X_100MFD)
  900. ? 100 : 10,
  901. (db->op_mode == ULI526X_10MFD ||
  902. db->op_mode == ULI526X_100MFD)
  903. ? "Full" : "Half");
  904. netif_carrier_on(dev);
  905. }
  906. /* SHOW_MEDIA_TYPE(db->op_mode); */
  907. }
  908. else if(!(tmp_cr12 & 0x3) && db->link_failed)
  909. {
  910. if(db->init==1)
  911. {
  912. netdev_info(dev, "NIC Link is Down\n");
  913. netif_carrier_off(dev);
  914. }
  915. }
  916. db->init = 0;
  917. /* Timer active again */
  918. db->timer.expires = ULI526X_TIMER_WUT;
  919. add_timer(&db->timer);
  920. spin_unlock_irqrestore(&db->lock, flags);
  921. }
  922. /*
  923. * Stop ULI526X board
  924. * Free Tx/Rx allocated memory
  925. * Init system variable
  926. */
  927. static void uli526x_reset_prepare(struct net_device *dev)
  928. {
  929. struct uli526x_board_info *db = netdev_priv(dev);
  930. void __iomem *ioaddr = db->ioaddr;
  931. /* Sopt MAC controller */
  932. db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
  933. update_cr6(db->cr6_data, ioaddr);
  934. uw32(DCR7, 0); /* Disable Interrupt */
  935. uw32(DCR5, ur32(DCR5));
  936. /* Disable upper layer interface */
  937. netif_stop_queue(dev);
  938. /* Free Rx Allocate buffer */
  939. uli526x_free_rxbuffer(db);
  940. /* system variable init */
  941. db->tx_packet_cnt = 0;
  942. db->rx_avail_cnt = 0;
  943. db->link_failed = 1;
  944. db->init=1;
  945. db->wait_reset = 0;
  946. }
  947. /*
  948. * Dynamic reset the ULI526X board
  949. * Stop ULI526X board
  950. * Free Tx/Rx allocated memory
  951. * Reset ULI526X board
  952. * Re-initialize ULI526X board
  953. */
  954. static void uli526x_dynamic_reset(struct net_device *dev)
  955. {
  956. ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
  957. uli526x_reset_prepare(dev);
  958. /* Re-initialize ULI526X board */
  959. uli526x_init(dev);
  960. /* Restart upper layer interface */
  961. netif_wake_queue(dev);
  962. }
  963. #ifdef CONFIG_PM
  964. /*
  965. * Suspend the interface.
  966. */
  967. static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
  968. {
  969. struct net_device *dev = pci_get_drvdata(pdev);
  970. pci_power_t power_state;
  971. int err;
  972. ULI526X_DBUG(0, "uli526x_suspend", 0);
  973. pci_save_state(pdev);
  974. if (!netif_running(dev))
  975. return 0;
  976. netif_device_detach(dev);
  977. uli526x_reset_prepare(dev);
  978. power_state = pci_choose_state(pdev, state);
  979. pci_enable_wake(pdev, power_state, 0);
  980. err = pci_set_power_state(pdev, power_state);
  981. if (err) {
  982. netif_device_attach(dev);
  983. /* Re-initialize ULI526X board */
  984. uli526x_init(dev);
  985. /* Restart upper layer interface */
  986. netif_wake_queue(dev);
  987. }
  988. return err;
  989. }
  990. /*
  991. * Resume the interface.
  992. */
  993. static int uli526x_resume(struct pci_dev *pdev)
  994. {
  995. struct net_device *dev = pci_get_drvdata(pdev);
  996. int err;
  997. ULI526X_DBUG(0, "uli526x_resume", 0);
  998. pci_restore_state(pdev);
  999. if (!netif_running(dev))
  1000. return 0;
  1001. err = pci_set_power_state(pdev, PCI_D0);
  1002. if (err) {
  1003. netdev_warn(dev, "Could not put device into D0\n");
  1004. return err;
  1005. }
  1006. netif_device_attach(dev);
  1007. /* Re-initialize ULI526X board */
  1008. uli526x_init(dev);
  1009. /* Restart upper layer interface */
  1010. netif_wake_queue(dev);
  1011. return 0;
  1012. }
  1013. #else /* !CONFIG_PM */
  1014. #define uli526x_suspend NULL
  1015. #define uli526x_resume NULL
  1016. #endif /* !CONFIG_PM */
  1017. /*
  1018. * free all allocated rx buffer
  1019. */
  1020. static void uli526x_free_rxbuffer(struct uli526x_board_info * db)
  1021. {
  1022. ULI526X_DBUG(0, "uli526x_free_rxbuffer()", 0);
  1023. /* free allocated rx buffer */
  1024. while (db->rx_avail_cnt) {
  1025. dev_kfree_skb(db->rx_ready_ptr->rx_skb_ptr);
  1026. db->rx_ready_ptr = db->rx_ready_ptr->next_rx_desc;
  1027. db->rx_avail_cnt--;
  1028. }
  1029. }
  1030. /*
  1031. * Reuse the SK buffer
  1032. */
  1033. static void uli526x_reuse_skb(struct uli526x_board_info *db, struct sk_buff * skb)
  1034. {
  1035. struct rx_desc *rxptr = db->rx_insert_ptr;
  1036. if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
  1037. rxptr->rx_skb_ptr = skb;
  1038. rxptr->rdes2 = cpu_to_le32(pci_map_single(db->pdev,
  1039. skb_tail_pointer(skb),
  1040. RX_ALLOC_SIZE,
  1041. PCI_DMA_FROMDEVICE));
  1042. wmb();
  1043. rxptr->rdes0 = cpu_to_le32(0x80000000);
  1044. db->rx_avail_cnt++;
  1045. db->rx_insert_ptr = rxptr->next_rx_desc;
  1046. } else
  1047. ULI526X_DBUG(0, "SK Buffer reuse method error", db->rx_avail_cnt);
  1048. }
  1049. /*
  1050. * Initialize transmit/Receive descriptor
  1051. * Using Chain structure, and allocate Tx/Rx buffer
  1052. */
  1053. static void uli526x_descriptor_init(struct net_device *dev, void __iomem *ioaddr)
  1054. {
  1055. struct uli526x_board_info *db = netdev_priv(dev);
  1056. struct tx_desc *tmp_tx;
  1057. struct rx_desc *tmp_rx;
  1058. unsigned char *tmp_buf;
  1059. dma_addr_t tmp_tx_dma, tmp_rx_dma;
  1060. dma_addr_t tmp_buf_dma;
  1061. int i;
  1062. ULI526X_DBUG(0, "uli526x_descriptor_init()", 0);
  1063. /* tx descriptor start pointer */
  1064. db->tx_insert_ptr = db->first_tx_desc;
  1065. db->tx_remove_ptr = db->first_tx_desc;
  1066. uw32(DCR4, db->first_tx_desc_dma); /* TX DESC address */
  1067. /* rx descriptor start pointer */
  1068. db->first_rx_desc = (void *)db->first_tx_desc + sizeof(struct tx_desc) * TX_DESC_CNT;
  1069. db->first_rx_desc_dma = db->first_tx_desc_dma + sizeof(struct tx_desc) * TX_DESC_CNT;
  1070. db->rx_insert_ptr = db->first_rx_desc;
  1071. db->rx_ready_ptr = db->first_rx_desc;
  1072. uw32(DCR3, db->first_rx_desc_dma); /* RX DESC address */
  1073. /* Init Transmit chain */
  1074. tmp_buf = db->buf_pool_start;
  1075. tmp_buf_dma = db->buf_pool_dma_start;
  1076. tmp_tx_dma = db->first_tx_desc_dma;
  1077. for (tmp_tx = db->first_tx_desc, i = 0; i < TX_DESC_CNT; i++, tmp_tx++) {
  1078. tmp_tx->tx_buf_ptr = tmp_buf;
  1079. tmp_tx->tdes0 = cpu_to_le32(0);
  1080. tmp_tx->tdes1 = cpu_to_le32(0x81000000); /* IC, chain */
  1081. tmp_tx->tdes2 = cpu_to_le32(tmp_buf_dma);
  1082. tmp_tx_dma += sizeof(struct tx_desc);
  1083. tmp_tx->tdes3 = cpu_to_le32(tmp_tx_dma);
  1084. tmp_tx->next_tx_desc = tmp_tx + 1;
  1085. tmp_buf = tmp_buf + TX_BUF_ALLOC;
  1086. tmp_buf_dma = tmp_buf_dma + TX_BUF_ALLOC;
  1087. }
  1088. (--tmp_tx)->tdes3 = cpu_to_le32(db->first_tx_desc_dma);
  1089. tmp_tx->next_tx_desc = db->first_tx_desc;
  1090. /* Init Receive descriptor chain */
  1091. tmp_rx_dma=db->first_rx_desc_dma;
  1092. for (tmp_rx = db->first_rx_desc, i = 0; i < RX_DESC_CNT; i++, tmp_rx++) {
  1093. tmp_rx->rdes0 = cpu_to_le32(0);
  1094. tmp_rx->rdes1 = cpu_to_le32(0x01000600);
  1095. tmp_rx_dma += sizeof(struct rx_desc);
  1096. tmp_rx->rdes3 = cpu_to_le32(tmp_rx_dma);
  1097. tmp_rx->next_rx_desc = tmp_rx + 1;
  1098. }
  1099. (--tmp_rx)->rdes3 = cpu_to_le32(db->first_rx_desc_dma);
  1100. tmp_rx->next_rx_desc = db->first_rx_desc;
  1101. /* pre-allocate Rx buffer */
  1102. allocate_rx_buffer(dev);
  1103. }
  1104. /*
  1105. * Update CR6 value
  1106. * Firstly stop ULI526X, then written value and start
  1107. */
  1108. static void update_cr6(u32 cr6_data, void __iomem *ioaddr)
  1109. {
  1110. uw32(DCR6, cr6_data);
  1111. udelay(5);
  1112. }
  1113. /*
  1114. * Send a setup frame for M5261/M5263
  1115. * This setup frame initialize ULI526X address filter mode
  1116. */
  1117. #ifdef __BIG_ENDIAN
  1118. #define FLT_SHIFT 16
  1119. #else
  1120. #define FLT_SHIFT 0
  1121. #endif
  1122. static void send_filter_frame(struct net_device *dev, int mc_cnt)
  1123. {
  1124. struct uli526x_board_info *db = netdev_priv(dev);
  1125. void __iomem *ioaddr = db->ioaddr;
  1126. struct netdev_hw_addr *ha;
  1127. struct tx_desc *txptr;
  1128. u16 * addrptr;
  1129. u32 * suptr;
  1130. int i;
  1131. ULI526X_DBUG(0, "send_filter_frame()", 0);
  1132. txptr = db->tx_insert_ptr;
  1133. suptr = (u32 *) txptr->tx_buf_ptr;
  1134. /* Node address */
  1135. addrptr = (u16 *) dev->dev_addr;
  1136. *suptr++ = addrptr[0] << FLT_SHIFT;
  1137. *suptr++ = addrptr[1] << FLT_SHIFT;
  1138. *suptr++ = addrptr[2] << FLT_SHIFT;
  1139. /* broadcast address */
  1140. *suptr++ = 0xffff << FLT_SHIFT;
  1141. *suptr++ = 0xffff << FLT_SHIFT;
  1142. *suptr++ = 0xffff << FLT_SHIFT;
  1143. /* fit the multicast address */
  1144. netdev_for_each_mc_addr(ha, dev) {
  1145. addrptr = (u16 *) ha->addr;
  1146. *suptr++ = addrptr[0] << FLT_SHIFT;
  1147. *suptr++ = addrptr[1] << FLT_SHIFT;
  1148. *suptr++ = addrptr[2] << FLT_SHIFT;
  1149. }
  1150. for (i = netdev_mc_count(dev); i < 14; i++) {
  1151. *suptr++ = 0xffff << FLT_SHIFT;
  1152. *suptr++ = 0xffff << FLT_SHIFT;
  1153. *suptr++ = 0xffff << FLT_SHIFT;
  1154. }
  1155. /* prepare the setup frame */
  1156. db->tx_insert_ptr = txptr->next_tx_desc;
  1157. txptr->tdes1 = cpu_to_le32(0x890000c0);
  1158. /* Resource Check and Send the setup packet */
  1159. if (db->tx_packet_cnt < TX_DESC_CNT) {
  1160. /* Resource Empty */
  1161. db->tx_packet_cnt++;
  1162. txptr->tdes0 = cpu_to_le32(0x80000000);
  1163. update_cr6(db->cr6_data | 0x2000, ioaddr);
  1164. uw32(DCR1, 0x1); /* Issue Tx polling */
  1165. update_cr6(db->cr6_data, ioaddr);
  1166. dev->trans_start = jiffies;
  1167. } else
  1168. netdev_err(dev, "No Tx resource - Send_filter_frame!\n");
  1169. }
  1170. /*
  1171. * Allocate rx buffer,
  1172. * As possible as allocate maxiumn Rx buffer
  1173. */
  1174. static void allocate_rx_buffer(struct net_device *dev)
  1175. {
  1176. struct uli526x_board_info *db = netdev_priv(dev);
  1177. struct rx_desc *rxptr;
  1178. struct sk_buff *skb;
  1179. rxptr = db->rx_insert_ptr;
  1180. while(db->rx_avail_cnt < RX_DESC_CNT) {
  1181. skb = netdev_alloc_skb(dev, RX_ALLOC_SIZE);
  1182. if (skb == NULL)
  1183. break;
  1184. rxptr->rx_skb_ptr = skb; /* FIXME (?) */
  1185. rxptr->rdes2 = cpu_to_le32(pci_map_single(db->pdev,
  1186. skb_tail_pointer(skb),
  1187. RX_ALLOC_SIZE,
  1188. PCI_DMA_FROMDEVICE));
  1189. wmb();
  1190. rxptr->rdes0 = cpu_to_le32(0x80000000);
  1191. rxptr = rxptr->next_rx_desc;
  1192. db->rx_avail_cnt++;
  1193. }
  1194. db->rx_insert_ptr = rxptr;
  1195. }
  1196. /*
  1197. * Read one word data from the serial ROM
  1198. */
  1199. static u16 read_srom_word(struct uli526x_board_info *db, int offset)
  1200. {
  1201. void __iomem *ioaddr = db->ioaddr;
  1202. u16 srom_data = 0;
  1203. int i;
  1204. uw32(DCR9, CR9_SROM_READ);
  1205. uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1206. /* Send the Read Command 110b */
  1207. srom_clk_write(db, SROM_DATA_1);
  1208. srom_clk_write(db, SROM_DATA_1);
  1209. srom_clk_write(db, SROM_DATA_0);
  1210. /* Send the offset */
  1211. for (i = 5; i >= 0; i--) {
  1212. srom_data = (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0;
  1213. srom_clk_write(db, srom_data);
  1214. }
  1215. uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1216. for (i = 16; i > 0; i--) {
  1217. uw32(DCR9, CR9_SROM_READ | CR9_SRCS | CR9_SRCLK);
  1218. udelay(5);
  1219. srom_data = (srom_data << 1) |
  1220. ((ur32(DCR9) & CR9_CRDOUT) ? 1 : 0);
  1221. uw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1222. udelay(5);
  1223. }
  1224. uw32(DCR9, CR9_SROM_READ);
  1225. return srom_data;
  1226. }
  1227. /*
  1228. * Auto sense the media mode
  1229. */
  1230. static u8 uli526x_sense_speed(struct uli526x_board_info * db)
  1231. {
  1232. struct uli_phy_ops *phy = &db->phy;
  1233. u8 ErrFlag = 0;
  1234. u16 phy_mode;
  1235. phy_mode = phy->read(db, db->phy_addr, 1);
  1236. phy_mode = phy->read(db, db->phy_addr, 1);
  1237. if ( (phy_mode & 0x24) == 0x24 ) {
  1238. phy_mode = ((phy->read(db, db->phy_addr, 5) & 0x01e0)<<7);
  1239. if(phy_mode&0x8000)
  1240. phy_mode = 0x8000;
  1241. else if(phy_mode&0x4000)
  1242. phy_mode = 0x4000;
  1243. else if(phy_mode&0x2000)
  1244. phy_mode = 0x2000;
  1245. else
  1246. phy_mode = 0x1000;
  1247. switch (phy_mode) {
  1248. case 0x1000: db->op_mode = ULI526X_10MHF; break;
  1249. case 0x2000: db->op_mode = ULI526X_10MFD; break;
  1250. case 0x4000: db->op_mode = ULI526X_100MHF; break;
  1251. case 0x8000: db->op_mode = ULI526X_100MFD; break;
  1252. default: db->op_mode = ULI526X_10MHF; ErrFlag = 1; break;
  1253. }
  1254. } else {
  1255. db->op_mode = ULI526X_10MHF;
  1256. ULI526X_DBUG(0, "Link Failed :", phy_mode);
  1257. ErrFlag = 1;
  1258. }
  1259. return ErrFlag;
  1260. }
  1261. /*
  1262. * Set 10/100 phyxcer capability
  1263. * AUTO mode : phyxcer register4 is NIC capability
  1264. * Force mode: phyxcer register4 is the force media
  1265. */
  1266. static void uli526x_set_phyxcer(struct uli526x_board_info *db)
  1267. {
  1268. struct uli_phy_ops *phy = &db->phy;
  1269. u16 phy_reg;
  1270. /* Phyxcer capability setting */
  1271. phy_reg = phy->read(db, db->phy_addr, 4) & ~0x01e0;
  1272. if (db->media_mode & ULI526X_AUTO) {
  1273. /* AUTO Mode */
  1274. phy_reg |= db->PHY_reg4;
  1275. } else {
  1276. /* Force Mode */
  1277. switch(db->media_mode) {
  1278. case ULI526X_10MHF: phy_reg |= 0x20; break;
  1279. case ULI526X_10MFD: phy_reg |= 0x40; break;
  1280. case ULI526X_100MHF: phy_reg |= 0x80; break;
  1281. case ULI526X_100MFD: phy_reg |= 0x100; break;
  1282. }
  1283. }
  1284. /* Write new capability to Phyxcer Reg4 */
  1285. if ( !(phy_reg & 0x01e0)) {
  1286. phy_reg|=db->PHY_reg4;
  1287. db->media_mode|=ULI526X_AUTO;
  1288. }
  1289. phy->write(db, db->phy_addr, 4, phy_reg);
  1290. /* Restart Auto-Negotiation */
  1291. phy->write(db, db->phy_addr, 0, 0x1200);
  1292. udelay(50);
  1293. }
  1294. /*
  1295. * Process op-mode
  1296. AUTO mode : PHY controller in Auto-negotiation Mode
  1297. * Force mode: PHY controller in force mode with HUB
  1298. * N-way force capability with SWITCH
  1299. */
  1300. static void uli526x_process_mode(struct uli526x_board_info *db)
  1301. {
  1302. struct uli_phy_ops *phy = &db->phy;
  1303. u16 phy_reg;
  1304. /* Full Duplex Mode Check */
  1305. if (db->op_mode & 0x4)
  1306. db->cr6_data |= CR6_FDM; /* Set Full Duplex Bit */
  1307. else
  1308. db->cr6_data &= ~CR6_FDM; /* Clear Full Duplex Bit */
  1309. update_cr6(db->cr6_data, db->ioaddr);
  1310. /* 10/100M phyxcer force mode need */
  1311. if (!(db->media_mode & 0x8)) {
  1312. /* Forece Mode */
  1313. phy_reg = phy->read(db, db->phy_addr, 6);
  1314. if (!(phy_reg & 0x1)) {
  1315. /* parter without N-Way capability */
  1316. phy_reg = 0x0;
  1317. switch(db->op_mode) {
  1318. case ULI526X_10MHF: phy_reg = 0x0; break;
  1319. case ULI526X_10MFD: phy_reg = 0x100; break;
  1320. case ULI526X_100MHF: phy_reg = 0x2000; break;
  1321. case ULI526X_100MFD: phy_reg = 0x2100; break;
  1322. }
  1323. phy->write(db, db->phy_addr, 0, phy_reg);
  1324. }
  1325. }
  1326. }
  1327. /* M5261/M5263 Chip */
  1328. static void phy_writeby_cr9(struct uli526x_board_info *db, u8 phy_addr,
  1329. u8 offset, u16 phy_data)
  1330. {
  1331. u16 i;
  1332. /* Send 33 synchronization clock to Phy controller */
  1333. for (i = 0; i < 35; i++)
  1334. phy_write_1bit(db, PHY_DATA_1);
  1335. /* Send start command(01) to Phy */
  1336. phy_write_1bit(db, PHY_DATA_0);
  1337. phy_write_1bit(db, PHY_DATA_1);
  1338. /* Send write command(01) to Phy */
  1339. phy_write_1bit(db, PHY_DATA_0);
  1340. phy_write_1bit(db, PHY_DATA_1);
  1341. /* Send Phy address */
  1342. for (i = 0x10; i > 0; i = i >> 1)
  1343. phy_write_1bit(db, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
  1344. /* Send register address */
  1345. for (i = 0x10; i > 0; i = i >> 1)
  1346. phy_write_1bit(db, offset & i ? PHY_DATA_1 : PHY_DATA_0);
  1347. /* written trasnition */
  1348. phy_write_1bit(db, PHY_DATA_1);
  1349. phy_write_1bit(db, PHY_DATA_0);
  1350. /* Write a word data to PHY controller */
  1351. for (i = 0x8000; i > 0; i >>= 1)
  1352. phy_write_1bit(db, phy_data & i ? PHY_DATA_1 : PHY_DATA_0);
  1353. }
  1354. static u16 phy_readby_cr9(struct uli526x_board_info *db, u8 phy_addr, u8 offset)
  1355. {
  1356. u16 phy_data;
  1357. int i;
  1358. /* Send 33 synchronization clock to Phy controller */
  1359. for (i = 0; i < 35; i++)
  1360. phy_write_1bit(db, PHY_DATA_1);
  1361. /* Send start command(01) to Phy */
  1362. phy_write_1bit(db, PHY_DATA_0);
  1363. phy_write_1bit(db, PHY_DATA_1);
  1364. /* Send read command(10) to Phy */
  1365. phy_write_1bit(db, PHY_DATA_1);
  1366. phy_write_1bit(db, PHY_DATA_0);
  1367. /* Send Phy address */
  1368. for (i = 0x10; i > 0; i = i >> 1)
  1369. phy_write_1bit(db, phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
  1370. /* Send register address */
  1371. for (i = 0x10; i > 0; i = i >> 1)
  1372. phy_write_1bit(db, offset & i ? PHY_DATA_1 : PHY_DATA_0);
  1373. /* Skip transition state */
  1374. phy_read_1bit(db);
  1375. /* read 16bit data */
  1376. for (phy_data = 0, i = 0; i < 16; i++) {
  1377. phy_data <<= 1;
  1378. phy_data |= phy_read_1bit(db);
  1379. }
  1380. return phy_data;
  1381. }
  1382. static u16 phy_readby_cr10(struct uli526x_board_info *db, u8 phy_addr,
  1383. u8 offset)
  1384. {
  1385. void __iomem *ioaddr = db->ioaddr;
  1386. u32 cr10_value = phy_addr;
  1387. cr10_value = (cr10_value << 5) + offset;
  1388. cr10_value = (cr10_value << 16) + 0x08000000;
  1389. uw32(DCR10, cr10_value);
  1390. udelay(1);
  1391. while (1) {
  1392. cr10_value = ur32(DCR10);
  1393. if (cr10_value & 0x10000000)
  1394. break;
  1395. }
  1396. return cr10_value & 0x0ffff;
  1397. }
  1398. static void phy_writeby_cr10(struct uli526x_board_info *db, u8 phy_addr,
  1399. u8 offset, u16 phy_data)
  1400. {
  1401. void __iomem *ioaddr = db->ioaddr;
  1402. u32 cr10_value = phy_addr;
  1403. cr10_value = (cr10_value << 5) + offset;
  1404. cr10_value = (cr10_value << 16) + 0x04000000 + phy_data;
  1405. uw32(DCR10, cr10_value);
  1406. udelay(1);
  1407. }
  1408. /*
  1409. * Write one bit data to Phy Controller
  1410. */
  1411. static void phy_write_1bit(struct uli526x_board_info *db, u32 data)
  1412. {
  1413. void __iomem *ioaddr = db->ioaddr;
  1414. uw32(DCR9, data); /* MII Clock Low */
  1415. udelay(1);
  1416. uw32(DCR9, data | MDCLKH); /* MII Clock High */
  1417. udelay(1);
  1418. uw32(DCR9, data); /* MII Clock Low */
  1419. udelay(1);
  1420. }
  1421. /*
  1422. * Read one bit phy data from PHY controller
  1423. */
  1424. static u16 phy_read_1bit(struct uli526x_board_info *db)
  1425. {
  1426. void __iomem *ioaddr = db->ioaddr;
  1427. u16 phy_data;
  1428. uw32(DCR9, 0x50000);
  1429. udelay(1);
  1430. phy_data = (ur32(DCR9) >> 19) & 0x1;
  1431. uw32(DCR9, 0x40000);
  1432. udelay(1);
  1433. return phy_data;
  1434. }
  1435. static const struct pci_device_id uli526x_pci_tbl[] = {
  1436. { 0x10B9, 0x5261, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_ULI5261_ID },
  1437. { 0x10B9, 0x5263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_ULI5263_ID },
  1438. { 0, }
  1439. };
  1440. MODULE_DEVICE_TABLE(pci, uli526x_pci_tbl);
  1441. static struct pci_driver uli526x_driver = {
  1442. .name = "uli526x",
  1443. .id_table = uli526x_pci_tbl,
  1444. .probe = uli526x_init_one,
  1445. .remove = uli526x_remove_one,
  1446. .suspend = uli526x_suspend,
  1447. .resume = uli526x_resume,
  1448. };
  1449. MODULE_AUTHOR("Peer Chen, peer.chen@uli.com.tw");
  1450. MODULE_DESCRIPTION("ULi M5261/M5263 fast ethernet driver");
  1451. MODULE_LICENSE("GPL");
  1452. module_param(debug, int, 0644);
  1453. module_param(mode, int, 0);
  1454. module_param(cr6set, int, 0);
  1455. MODULE_PARM_DESC(debug, "ULi M5261/M5263 enable debugging (0-1)");
  1456. MODULE_PARM_DESC(mode, "ULi M5261/M5263: Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
  1457. /* Description:
  1458. * when user used insmod to add module, system invoked init_module()
  1459. * to register the services.
  1460. */
  1461. static int __init uli526x_init_module(void)
  1462. {
  1463. pr_info("%s\n", version);
  1464. printed_version = 1;
  1465. ULI526X_DBUG(0, "init_module() ", debug);
  1466. if (debug)
  1467. uli526x_debug = debug; /* set debug flag */
  1468. if (cr6set)
  1469. uli526x_cr6_user_set = cr6set;
  1470. switch (mode) {
  1471. case ULI526X_10MHF:
  1472. case ULI526X_100MHF:
  1473. case ULI526X_10MFD:
  1474. case ULI526X_100MFD:
  1475. uli526x_media_mode = mode;
  1476. break;
  1477. default:
  1478. uli526x_media_mode = ULI526X_AUTO;
  1479. break;
  1480. }
  1481. return pci_register_driver(&uli526x_driver);
  1482. }
  1483. /*
  1484. * Description:
  1485. * when user used rmmod to delete module, system invoked clean_module()
  1486. * to un-register all registered services.
  1487. */
  1488. static void __exit uli526x_cleanup_module(void)
  1489. {
  1490. ULI526X_DBUG(0, "uli526x_cleanup_module() ", debug);
  1491. pci_unregister_driver(&uli526x_driver);
  1492. }
  1493. module_init(uli526x_init_module);
  1494. module_exit(uli526x_cleanup_module);