dmfe.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /*
  2. A Davicom DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802 NIC fast
  3. ethernet driver for Linux.
  4. Copyright (C) 1997 Sten Wang
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. DAVICOM Web-Site: www.davicom.com.tw
  14. Author: Sten Wang, 886-3-5798797-8517, E-mail: sten_wang@davicom.com.tw
  15. Maintainer: Tobias Ringstrom <tori@unhappy.mine.nu>
  16. (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
  17. Marcelo Tosatti <marcelo@conectiva.com.br> :
  18. Made it compile in 2.3 (device to net_device)
  19. Alan Cox <alan@lxorguk.ukuu.org.uk> :
  20. Cleaned up for kernel merge.
  21. Removed the back compatibility support
  22. Reformatted, fixing spelling etc as I went
  23. Removed IRQ 0-15 assumption
  24. Jeff Garzik <jgarzik@pobox.com> :
  25. Updated to use new PCI driver API.
  26. Resource usage cleanups.
  27. Report driver version to user.
  28. Tobias Ringstrom <tori@unhappy.mine.nu> :
  29. Cleaned up and added SMP safety. Thanks go to Jeff Garzik,
  30. Andrew Morton and Frank Davis for the SMP safety fixes.
  31. Vojtech Pavlik <vojtech@suse.cz> :
  32. Cleaned up pointer arithmetics.
  33. Fixed a lot of 64bit issues.
  34. Cleaned up printk()s a bit.
  35. Fixed some obvious big endian problems.
  36. Tobias Ringstrom <tori@unhappy.mine.nu> :
  37. Use time_after for jiffies calculation. Added ethtool
  38. support. Updated PCI resource allocation. Do not
  39. forget to unmap PCI mapped skbs.
  40. Alan Cox <alan@lxorguk.ukuu.org.uk>
  41. Added new PCI identifiers provided by Clear Zhang at ALi
  42. for their 1563 ethernet device.
  43. TODO
  44. Check on 64 bit boxes.
  45. Check and fix on big endian boxes.
  46. Test and make sure PCI latency is now correct for all cases.
  47. */
  48. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  49. #define DRV_NAME "dmfe"
  50. #define DRV_VERSION "1.36.4"
  51. #define DRV_RELDATE "2002-01-17"
  52. #include <linux/module.h>
  53. #include <linux/kernel.h>
  54. #include <linux/string.h>
  55. #include <linux/timer.h>
  56. #include <linux/ptrace.h>
  57. #include <linux/errno.h>
  58. #include <linux/ioport.h>
  59. #include <linux/interrupt.h>
  60. #include <linux/pci.h>
  61. #include <linux/dma-mapping.h>
  62. #include <linux/init.h>
  63. #include <linux/netdevice.h>
  64. #include <linux/etherdevice.h>
  65. #include <linux/ethtool.h>
  66. #include <linux/skbuff.h>
  67. #include <linux/delay.h>
  68. #include <linux/spinlock.h>
  69. #include <linux/crc32.h>
  70. #include <linux/bitops.h>
  71. #include <asm/processor.h>
  72. #include <asm/io.h>
  73. #include <asm/dma.h>
  74. #include <linux/uaccess.h>
  75. #include <asm/irq.h>
  76. #ifdef CONFIG_TULIP_DM910X
  77. #include <linux/of.h>
  78. #endif
  79. /* Board/System/Debug information/definition ---------------- */
  80. #define PCI_DM9132_ID 0x91321282 /* Davicom DM9132 ID */
  81. #define PCI_DM9102_ID 0x91021282 /* Davicom DM9102 ID */
  82. #define PCI_DM9100_ID 0x91001282 /* Davicom DM9100 ID */
  83. #define PCI_DM9009_ID 0x90091282 /* Davicom DM9009 ID */
  84. #define DM9102_IO_SIZE 0x80
  85. #define DM9102A_IO_SIZE 0x100
  86. #define TX_MAX_SEND_CNT 0x1 /* Maximum tx packet per time */
  87. #define TX_DESC_CNT 0x10 /* Allocated Tx descriptors */
  88. #define RX_DESC_CNT 0x20 /* Allocated Rx descriptors */
  89. #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2) /* Max TX packet count */
  90. #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3) /* TX wakeup count */
  91. #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
  92. #define TX_BUF_ALLOC 0x600
  93. #define RX_ALLOC_SIZE 0x620
  94. #define DM910X_RESET 1
  95. #define CR0_DEFAULT 0x00E00000 /* TX & RX burst mode */
  96. #define CR6_DEFAULT 0x00080000 /* HD */
  97. #define CR7_DEFAULT 0x180c1
  98. #define CR15_DEFAULT 0x06 /* TxJabber RxWatchdog */
  99. #define TDES0_ERR_MASK 0x4302 /* TXJT, LC, EC, FUE */
  100. #define MAX_PACKET_SIZE 1514
  101. #define DMFE_MAX_MULTICAST 14
  102. #define RX_COPY_SIZE 100
  103. #define MAX_CHECK_PACKET 0x8000
  104. #define DM9801_NOISE_FLOOR 8
  105. #define DM9802_NOISE_FLOOR 5
  106. #define DMFE_WOL_LINKCHANGE 0x20000000
  107. #define DMFE_WOL_SAMPLEPACKET 0x10000000
  108. #define DMFE_WOL_MAGICPACKET 0x08000000
  109. #define DMFE_10MHF 0
  110. #define DMFE_100MHF 1
  111. #define DMFE_10MFD 4
  112. #define DMFE_100MFD 5
  113. #define DMFE_AUTO 8
  114. #define DMFE_1M_HPNA 0x10
  115. #define DMFE_TXTH_72 0x400000 /* TX TH 72 byte */
  116. #define DMFE_TXTH_96 0x404000 /* TX TH 96 byte */
  117. #define DMFE_TXTH_128 0x0000 /* TX TH 128 byte */
  118. #define DMFE_TXTH_256 0x4000 /* TX TH 256 byte */
  119. #define DMFE_TXTH_512 0x8000 /* TX TH 512 byte */
  120. #define DMFE_TXTH_1K 0xC000 /* TX TH 1K byte */
  121. #define DMFE_TIMER_WUT (jiffies + HZ * 1)/* timer wakeup time : 1 second */
  122. #define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */
  123. #define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */
  124. #define dw32(reg, val) iowrite32(val, ioaddr + (reg))
  125. #define dw16(reg, val) iowrite16(val, ioaddr + (reg))
  126. #define dr32(reg) ioread32(ioaddr + (reg))
  127. #define dr16(reg) ioread16(ioaddr + (reg))
  128. #define dr8(reg) ioread8(ioaddr + (reg))
  129. #define DMFE_DBUG(dbug_now, msg, value) \
  130. do { \
  131. if (dmfe_debug || (dbug_now)) \
  132. pr_err("%s %lx\n", \
  133. (msg), (long) (value)); \
  134. } while (0)
  135. #define SHOW_MEDIA_TYPE(mode) \
  136. pr_info("Change Speed to %sMhz %s duplex\n" , \
  137. (mode & 1) ? "100":"10", \
  138. (mode & 4) ? "full":"half");
  139. /* CR9 definition: SROM/MII */
  140. #define CR9_SROM_READ 0x4800
  141. #define CR9_SRCS 0x1
  142. #define CR9_SRCLK 0x2
  143. #define CR9_CRDOUT 0x8
  144. #define SROM_DATA_0 0x0
  145. #define SROM_DATA_1 0x4
  146. #define PHY_DATA_1 0x20000
  147. #define PHY_DATA_0 0x00000
  148. #define MDCLKH 0x10000
  149. #define PHY_POWER_DOWN 0x800
  150. #define SROM_V41_CODE 0x14
  151. #define __CHK_IO_SIZE(pci_id, dev_rev) \
  152. (( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x30) ) ? \
  153. DM9102A_IO_SIZE: DM9102_IO_SIZE)
  154. #define CHK_IO_SIZE(pci_dev) \
  155. (__CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, \
  156. (pci_dev)->revision))
  157. /* Structure/enum declaration ------------------------------- */
  158. struct tx_desc {
  159. __le32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */
  160. char *tx_buf_ptr; /* Data for us */
  161. struct tx_desc *next_tx_desc;
  162. } __attribute__(( aligned(32) ));
  163. struct rx_desc {
  164. __le32 rdes0, rdes1, rdes2, rdes3; /* Data for the card */
  165. struct sk_buff *rx_skb_ptr; /* Data for us */
  166. struct rx_desc *next_rx_desc;
  167. } __attribute__(( aligned(32) ));
  168. struct dmfe_board_info {
  169. u32 chip_id; /* Chip vendor/Device ID */
  170. u8 chip_revision; /* Chip revision */
  171. struct net_device *next_dev; /* next device */
  172. struct pci_dev *pdev; /* PCI device */
  173. spinlock_t lock;
  174. void __iomem *ioaddr; /* I/O base address */
  175. u32 cr0_data;
  176. u32 cr5_data;
  177. u32 cr6_data;
  178. u32 cr7_data;
  179. u32 cr15_data;
  180. /* pointer for memory physical address */
  181. dma_addr_t buf_pool_dma_ptr; /* Tx buffer pool memory */
  182. dma_addr_t buf_pool_dma_start; /* Tx buffer pool align dword */
  183. dma_addr_t desc_pool_dma_ptr; /* descriptor pool memory */
  184. dma_addr_t first_tx_desc_dma;
  185. dma_addr_t first_rx_desc_dma;
  186. /* descriptor pointer */
  187. unsigned char *buf_pool_ptr; /* Tx buffer pool memory */
  188. unsigned char *buf_pool_start; /* Tx buffer pool align dword */
  189. unsigned char *desc_pool_ptr; /* descriptor pool memory */
  190. struct tx_desc *first_tx_desc;
  191. struct tx_desc *tx_insert_ptr;
  192. struct tx_desc *tx_remove_ptr;
  193. struct rx_desc *first_rx_desc;
  194. struct rx_desc *rx_insert_ptr;
  195. struct rx_desc *rx_ready_ptr; /* packet come pointer */
  196. unsigned long tx_packet_cnt; /* transmitted packet count */
  197. unsigned long tx_queue_cnt; /* wait to send packet count */
  198. unsigned long rx_avail_cnt; /* available rx descriptor count */
  199. unsigned long interval_rx_cnt; /* rx packet count a callback time */
  200. u16 HPNA_command; /* For HPNA register 16 */
  201. u16 HPNA_timer; /* For HPNA remote device check */
  202. u16 dbug_cnt;
  203. u16 NIC_capability; /* NIC media capability */
  204. u16 PHY_reg4; /* Saved Phyxcer register 4 value */
  205. u8 HPNA_present; /* 0:none, 1:DM9801, 2:DM9802 */
  206. u8 chip_type; /* Keep DM9102A chip type */
  207. u8 media_mode; /* user specify media mode */
  208. u8 op_mode; /* real work media mode */
  209. u8 phy_addr;
  210. u8 wait_reset; /* Hardware failed, need to reset */
  211. u8 dm910x_chk_mode; /* Operating mode check */
  212. u8 first_in_callback; /* Flag to record state */
  213. u8 wol_mode; /* user WOL settings */
  214. struct timer_list timer;
  215. /* Driver defined statistic counter */
  216. unsigned long tx_fifo_underrun;
  217. unsigned long tx_loss_carrier;
  218. unsigned long tx_no_carrier;
  219. unsigned long tx_late_collision;
  220. unsigned long tx_excessive_collision;
  221. unsigned long tx_jabber_timeout;
  222. unsigned long reset_count;
  223. unsigned long reset_cr8;
  224. unsigned long reset_fatal;
  225. unsigned long reset_TXtimeout;
  226. /* NIC SROM data */
  227. unsigned char srom[128];
  228. };
  229. enum dmfe_offsets {
  230. DCR0 = 0x00, DCR1 = 0x08, DCR2 = 0x10, DCR3 = 0x18, DCR4 = 0x20,
  231. DCR5 = 0x28, DCR6 = 0x30, DCR7 = 0x38, DCR8 = 0x40, DCR9 = 0x48,
  232. DCR10 = 0x50, DCR11 = 0x58, DCR12 = 0x60, DCR13 = 0x68, DCR14 = 0x70,
  233. DCR15 = 0x78
  234. };
  235. enum dmfe_CR6_bits {
  236. CR6_RXSC = 0x2, CR6_PBF = 0x8, CR6_PM = 0x40, CR6_PAM = 0x80,
  237. CR6_FDM = 0x200, CR6_TXSC = 0x2000, CR6_STI = 0x100000,
  238. CR6_SFT = 0x200000, CR6_RXA = 0x40000000, CR6_NO_PURGE = 0x20000000
  239. };
  240. /* Global variable declaration ----------------------------- */
  241. static int printed_version;
  242. static const char version[] =
  243. "Davicom DM9xxx net driver, version " DRV_VERSION " (" DRV_RELDATE ")";
  244. static int dmfe_debug;
  245. static unsigned char dmfe_media_mode = DMFE_AUTO;
  246. static u32 dmfe_cr6_user_set;
  247. /* For module input parameter */
  248. static int debug;
  249. static u32 cr6set;
  250. static unsigned char mode = 8;
  251. static u8 chkmode = 1;
  252. static u8 HPNA_mode; /* Default: Low Power/High Speed */
  253. static u8 HPNA_rx_cmd; /* Default: Disable Rx remote command */
  254. static u8 HPNA_tx_cmd; /* Default: Don't issue remote command */
  255. static u8 HPNA_NoiseFloor; /* Default: HPNA NoiseFloor */
  256. static u8 SF_mode; /* Special Function: 1:VLAN, 2:RX Flow Control
  257. 4: TX pause packet */
  258. /* function declaration ------------------------------------- */
  259. static int dmfe_open(struct net_device *);
  260. static netdev_tx_t dmfe_start_xmit(struct sk_buff *, struct net_device *);
  261. static int dmfe_stop(struct net_device *);
  262. static void dmfe_set_filter_mode(struct net_device *);
  263. static const struct ethtool_ops netdev_ethtool_ops;
  264. static u16 read_srom_word(void __iomem *, int);
  265. static irqreturn_t dmfe_interrupt(int , void *);
  266. #ifdef CONFIG_NET_POLL_CONTROLLER
  267. static void poll_dmfe (struct net_device *dev);
  268. #endif
  269. static void dmfe_descriptor_init(struct net_device *);
  270. static void allocate_rx_buffer(struct net_device *);
  271. static void update_cr6(u32, void __iomem *);
  272. static void send_filter_frame(struct net_device *);
  273. static void dm9132_id_table(struct net_device *);
  274. static u16 dmfe_phy_read(void __iomem *, u8, u8, u32);
  275. static void dmfe_phy_write(void __iomem *, u8, u8, u16, u32);
  276. static void dmfe_phy_write_1bit(void __iomem *, u32);
  277. static u16 dmfe_phy_read_1bit(void __iomem *);
  278. static u8 dmfe_sense_speed(struct dmfe_board_info *);
  279. static void dmfe_process_mode(struct dmfe_board_info *);
  280. static void dmfe_timer(struct timer_list *);
  281. static inline u32 cal_CRC(unsigned char *, unsigned int, u8);
  282. static void dmfe_rx_packet(struct net_device *, struct dmfe_board_info *);
  283. static void dmfe_free_tx_pkt(struct net_device *, struct dmfe_board_info *);
  284. static void dmfe_reuse_skb(struct dmfe_board_info *, struct sk_buff *);
  285. static void dmfe_dynamic_reset(struct net_device *);
  286. static void dmfe_free_rxbuffer(struct dmfe_board_info *);
  287. static void dmfe_init_dm910x(struct net_device *);
  288. static void dmfe_parse_srom(struct dmfe_board_info *);
  289. static void dmfe_program_DM9801(struct dmfe_board_info *, int);
  290. static void dmfe_program_DM9802(struct dmfe_board_info *);
  291. static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * );
  292. static void dmfe_set_phyxcer(struct dmfe_board_info *);
  293. /* DM910X network board routine ---------------------------- */
  294. static const struct net_device_ops netdev_ops = {
  295. .ndo_open = dmfe_open,
  296. .ndo_stop = dmfe_stop,
  297. .ndo_start_xmit = dmfe_start_xmit,
  298. .ndo_set_rx_mode = dmfe_set_filter_mode,
  299. .ndo_set_mac_address = eth_mac_addr,
  300. .ndo_validate_addr = eth_validate_addr,
  301. #ifdef CONFIG_NET_POLL_CONTROLLER
  302. .ndo_poll_controller = poll_dmfe,
  303. #endif
  304. };
  305. /*
  306. * Search DM910X board ,allocate space and register it
  307. */
  308. static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  309. {
  310. struct dmfe_board_info *db; /* board information structure */
  311. struct net_device *dev;
  312. u32 pci_pmr;
  313. int i, err;
  314. DMFE_DBUG(0, "dmfe_init_one()", 0);
  315. if (!printed_version++)
  316. pr_info("%s\n", version);
  317. /*
  318. * SPARC on-board DM910x chips should be handled by the main
  319. * tulip driver, except for early DM9100s.
  320. */
  321. #ifdef CONFIG_TULIP_DM910X
  322. if ((ent->driver_data == PCI_DM9100_ID && pdev->revision >= 0x30) ||
  323. ent->driver_data == PCI_DM9102_ID) {
  324. struct device_node *dp = pci_device_to_OF_node(pdev);
  325. if (dp && of_get_property(dp, "local-mac-address", NULL)) {
  326. pr_info("skipping on-board DM910x (use tulip)\n");
  327. return -ENODEV;
  328. }
  329. }
  330. #endif
  331. /* Init network device */
  332. dev = alloc_etherdev(sizeof(*db));
  333. if (dev == NULL)
  334. return -ENOMEM;
  335. SET_NETDEV_DEV(dev, &pdev->dev);
  336. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  337. pr_warn("32-bit PCI DMA not available\n");
  338. err = -ENODEV;
  339. goto err_out_free;
  340. }
  341. /* Enable Master/IO access, Disable memory access */
  342. err = pci_enable_device(pdev);
  343. if (err)
  344. goto err_out_free;
  345. if (!pci_resource_start(pdev, 0)) {
  346. pr_err("I/O base is zero\n");
  347. err = -ENODEV;
  348. goto err_out_disable;
  349. }
  350. if (pci_resource_len(pdev, 0) < (CHK_IO_SIZE(pdev)) ) {
  351. pr_err("Allocated I/O size too small\n");
  352. err = -ENODEV;
  353. goto err_out_disable;
  354. }
  355. #if 0 /* pci_{enable_device,set_master} sets minimum latency for us now */
  356. /* Set Latency Timer 80h */
  357. /* FIXME: setting values > 32 breaks some SiS 559x stuff.
  358. Need a PCI quirk.. */
  359. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  360. #endif
  361. if (pci_request_regions(pdev, DRV_NAME)) {
  362. pr_err("Failed to request PCI regions\n");
  363. err = -ENODEV;
  364. goto err_out_disable;
  365. }
  366. /* Init system & device */
  367. db = netdev_priv(dev);
  368. /* Allocate Tx/Rx descriptor memory */
  369. db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) *
  370. DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
  371. if (!db->desc_pool_ptr) {
  372. err = -ENOMEM;
  373. goto err_out_res;
  374. }
  375. db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
  376. TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
  377. if (!db->buf_pool_ptr) {
  378. err = -ENOMEM;
  379. goto err_out_free_desc;
  380. }
  381. db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
  382. db->first_tx_desc_dma = db->desc_pool_dma_ptr;
  383. db->buf_pool_start = db->buf_pool_ptr;
  384. db->buf_pool_dma_start = db->buf_pool_dma_ptr;
  385. db->chip_id = ent->driver_data;
  386. /* IO type range. */
  387. db->ioaddr = pci_iomap(pdev, 0, 0);
  388. if (!db->ioaddr) {
  389. err = -ENOMEM;
  390. goto err_out_free_buf;
  391. }
  392. db->chip_revision = pdev->revision;
  393. db->wol_mode = 0;
  394. db->pdev = pdev;
  395. pci_set_drvdata(pdev, dev);
  396. dev->netdev_ops = &netdev_ops;
  397. dev->ethtool_ops = &netdev_ethtool_ops;
  398. netif_carrier_off(dev);
  399. spin_lock_init(&db->lock);
  400. pci_read_config_dword(pdev, 0x50, &pci_pmr);
  401. pci_pmr &= 0x70000;
  402. if ( (pci_pmr == 0x10000) && (db->chip_revision == 0x31) )
  403. db->chip_type = 1; /* DM9102A E3 */
  404. else
  405. db->chip_type = 0;
  406. /* read 64 word srom data */
  407. for (i = 0; i < 64; i++) {
  408. ((__le16 *) db->srom)[i] =
  409. cpu_to_le16(read_srom_word(db->ioaddr, i));
  410. }
  411. /* Set Node address */
  412. for (i = 0; i < 6; i++)
  413. dev->dev_addr[i] = db->srom[20 + i];
  414. err = register_netdev (dev);
  415. if (err)
  416. goto err_out_unmap;
  417. dev_info(&dev->dev, "Davicom DM%04lx at pci%s, %pM, irq %d\n",
  418. ent->driver_data >> 16,
  419. pci_name(pdev), dev->dev_addr, pdev->irq);
  420. pci_set_master(pdev);
  421. return 0;
  422. err_out_unmap:
  423. pci_iounmap(pdev, db->ioaddr);
  424. err_out_free_buf:
  425. pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
  426. db->buf_pool_ptr, db->buf_pool_dma_ptr);
  427. err_out_free_desc:
  428. pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20,
  429. db->desc_pool_ptr, db->desc_pool_dma_ptr);
  430. err_out_res:
  431. pci_release_regions(pdev);
  432. err_out_disable:
  433. pci_disable_device(pdev);
  434. err_out_free:
  435. free_netdev(dev);
  436. return err;
  437. }
  438. static void dmfe_remove_one(struct pci_dev *pdev)
  439. {
  440. struct net_device *dev = pci_get_drvdata(pdev);
  441. struct dmfe_board_info *db = netdev_priv(dev);
  442. DMFE_DBUG(0, "dmfe_remove_one()", 0);
  443. if (dev) {
  444. unregister_netdev(dev);
  445. pci_iounmap(db->pdev, db->ioaddr);
  446. pci_free_consistent(db->pdev, sizeof(struct tx_desc) *
  447. DESC_ALL_CNT + 0x20, db->desc_pool_ptr,
  448. db->desc_pool_dma_ptr);
  449. pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
  450. db->buf_pool_ptr, db->buf_pool_dma_ptr);
  451. pci_release_regions(pdev);
  452. free_netdev(dev); /* free board information */
  453. }
  454. DMFE_DBUG(0, "dmfe_remove_one() exit", 0);
  455. }
  456. /*
  457. * Open the interface.
  458. * The interface is opened whenever "ifconfig" actives it.
  459. */
  460. static int dmfe_open(struct net_device *dev)
  461. {
  462. struct dmfe_board_info *db = netdev_priv(dev);
  463. const int irq = db->pdev->irq;
  464. int ret;
  465. DMFE_DBUG(0, "dmfe_open", 0);
  466. ret = request_irq(irq, dmfe_interrupt, IRQF_SHARED, dev->name, dev);
  467. if (ret)
  468. return ret;
  469. /* system variable init */
  470. db->cr6_data = CR6_DEFAULT | dmfe_cr6_user_set;
  471. db->tx_packet_cnt = 0;
  472. db->tx_queue_cnt = 0;
  473. db->rx_avail_cnt = 0;
  474. db->wait_reset = 0;
  475. db->first_in_callback = 0;
  476. db->NIC_capability = 0xf; /* All capability*/
  477. db->PHY_reg4 = 0x1e0;
  478. /* CR6 operation mode decision */
  479. if ( !chkmode || (db->chip_id == PCI_DM9132_ID) ||
  480. (db->chip_revision >= 0x30) ) {
  481. db->cr6_data |= DMFE_TXTH_256;
  482. db->cr0_data = CR0_DEFAULT;
  483. db->dm910x_chk_mode=4; /* Enter the normal mode */
  484. } else {
  485. db->cr6_data |= CR6_SFT; /* Store & Forward mode */
  486. db->cr0_data = 0;
  487. db->dm910x_chk_mode = 1; /* Enter the check mode */
  488. }
  489. /* Initialize DM910X board */
  490. dmfe_init_dm910x(dev);
  491. /* Active System Interface */
  492. netif_wake_queue(dev);
  493. /* set and active a timer process */
  494. timer_setup(&db->timer, dmfe_timer, 0);
  495. db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
  496. add_timer(&db->timer);
  497. return 0;
  498. }
  499. /* Initialize DM910X board
  500. * Reset DM910X board
  501. * Initialize TX/Rx descriptor chain structure
  502. * Send the set-up frame
  503. * Enable Tx/Rx machine
  504. */
  505. static void dmfe_init_dm910x(struct net_device *dev)
  506. {
  507. struct dmfe_board_info *db = netdev_priv(dev);
  508. void __iomem *ioaddr = db->ioaddr;
  509. DMFE_DBUG(0, "dmfe_init_dm910x()", 0);
  510. /* Reset DM910x MAC controller */
  511. dw32(DCR0, DM910X_RESET); /* RESET MAC */
  512. udelay(100);
  513. dw32(DCR0, db->cr0_data);
  514. udelay(5);
  515. /* Phy addr : DM910(A)2/DM9132/9801, phy address = 1 */
  516. db->phy_addr = 1;
  517. /* Parser SROM and media mode */
  518. dmfe_parse_srom(db);
  519. db->media_mode = dmfe_media_mode;
  520. /* RESET Phyxcer Chip by GPR port bit 7 */
  521. dw32(DCR12, 0x180); /* Let bit 7 output port */
  522. if (db->chip_id == PCI_DM9009_ID) {
  523. dw32(DCR12, 0x80); /* Issue RESET signal */
  524. mdelay(300); /* Delay 300 ms */
  525. }
  526. dw32(DCR12, 0x0); /* Clear RESET signal */
  527. /* Process Phyxcer Media Mode */
  528. if ( !(db->media_mode & 0x10) ) /* Force 1M mode */
  529. dmfe_set_phyxcer(db);
  530. /* Media Mode Process */
  531. if ( !(db->media_mode & DMFE_AUTO) )
  532. db->op_mode = db->media_mode; /* Force Mode */
  533. /* Initialize Transmit/Receive descriptor and CR3/4 */
  534. dmfe_descriptor_init(dev);
  535. /* Init CR6 to program DM910x operation */
  536. update_cr6(db->cr6_data, ioaddr);
  537. /* Send setup frame */
  538. if (db->chip_id == PCI_DM9132_ID)
  539. dm9132_id_table(dev); /* DM9132 */
  540. else
  541. send_filter_frame(dev); /* DM9102/DM9102A */
  542. /* Init CR7, interrupt active bit */
  543. db->cr7_data = CR7_DEFAULT;
  544. dw32(DCR7, db->cr7_data);
  545. /* Init CR15, Tx jabber and Rx watchdog timer */
  546. dw32(DCR15, db->cr15_data);
  547. /* Enable DM910X Tx/Rx function */
  548. db->cr6_data |= CR6_RXSC | CR6_TXSC | 0x40000;
  549. update_cr6(db->cr6_data, ioaddr);
  550. }
  551. /*
  552. * Hardware start transmission.
  553. * Send a packet to media from the upper layer.
  554. */
  555. static netdev_tx_t dmfe_start_xmit(struct sk_buff *skb,
  556. struct net_device *dev)
  557. {
  558. struct dmfe_board_info *db = netdev_priv(dev);
  559. void __iomem *ioaddr = db->ioaddr;
  560. struct tx_desc *txptr;
  561. unsigned long flags;
  562. DMFE_DBUG(0, "dmfe_start_xmit", 0);
  563. /* Too large packet check */
  564. if (skb->len > MAX_PACKET_SIZE) {
  565. pr_err("big packet = %d\n", (u16)skb->len);
  566. dev_kfree_skb_any(skb);
  567. return NETDEV_TX_OK;
  568. }
  569. /* Resource flag check */
  570. netif_stop_queue(dev);
  571. spin_lock_irqsave(&db->lock, flags);
  572. /* No Tx resource check, it never happen nromally */
  573. if (db->tx_queue_cnt >= TX_FREE_DESC_CNT) {
  574. spin_unlock_irqrestore(&db->lock, flags);
  575. pr_err("No Tx resource %ld\n", db->tx_queue_cnt);
  576. return NETDEV_TX_BUSY;
  577. }
  578. /* Disable NIC interrupt */
  579. dw32(DCR7, 0);
  580. /* transmit this packet */
  581. txptr = db->tx_insert_ptr;
  582. skb_copy_from_linear_data(skb, txptr->tx_buf_ptr, skb->len);
  583. txptr->tdes1 = cpu_to_le32(0xe1000000 | skb->len);
  584. /* Point to next transmit free descriptor */
  585. db->tx_insert_ptr = txptr->next_tx_desc;
  586. /* Transmit Packet Process */
  587. if ( (!db->tx_queue_cnt) && (db->tx_packet_cnt < TX_MAX_SEND_CNT) ) {
  588. txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
  589. db->tx_packet_cnt++; /* Ready to send */
  590. dw32(DCR1, 0x1); /* Issue Tx polling */
  591. netif_trans_update(dev); /* saved time stamp */
  592. } else {
  593. db->tx_queue_cnt++; /* queue TX packet */
  594. dw32(DCR1, 0x1); /* Issue Tx polling */
  595. }
  596. /* Tx resource check */
  597. if ( db->tx_queue_cnt < TX_FREE_DESC_CNT )
  598. netif_wake_queue(dev);
  599. /* Restore CR7 to enable interrupt */
  600. spin_unlock_irqrestore(&db->lock, flags);
  601. dw32(DCR7, db->cr7_data);
  602. /* free this SKB */
  603. dev_consume_skb_any(skb);
  604. return NETDEV_TX_OK;
  605. }
  606. /*
  607. * Stop the interface.
  608. * The interface is stopped when it is brought.
  609. */
  610. static int dmfe_stop(struct net_device *dev)
  611. {
  612. struct dmfe_board_info *db = netdev_priv(dev);
  613. void __iomem *ioaddr = db->ioaddr;
  614. DMFE_DBUG(0, "dmfe_stop", 0);
  615. /* disable system */
  616. netif_stop_queue(dev);
  617. /* deleted timer */
  618. del_timer_sync(&db->timer);
  619. /* Reset & stop DM910X board */
  620. dw32(DCR0, DM910X_RESET);
  621. udelay(100);
  622. dmfe_phy_write(ioaddr, db->phy_addr, 0, 0x8000, db->chip_id);
  623. /* free interrupt */
  624. free_irq(db->pdev->irq, dev);
  625. /* free allocated rx buffer */
  626. dmfe_free_rxbuffer(db);
  627. #if 0
  628. /* show statistic counter */
  629. printk("FU:%lx EC:%lx LC:%lx NC:%lx LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n",
  630. db->tx_fifo_underrun, db->tx_excessive_collision,
  631. db->tx_late_collision, db->tx_no_carrier, db->tx_loss_carrier,
  632. db->tx_jabber_timeout, db->reset_count, db->reset_cr8,
  633. db->reset_fatal, db->reset_TXtimeout);
  634. #endif
  635. return 0;
  636. }
  637. /*
  638. * DM9102 insterrupt handler
  639. * receive the packet to upper layer, free the transmitted packet
  640. */
  641. static irqreturn_t dmfe_interrupt(int irq, void *dev_id)
  642. {
  643. struct net_device *dev = dev_id;
  644. struct dmfe_board_info *db = netdev_priv(dev);
  645. void __iomem *ioaddr = db->ioaddr;
  646. unsigned long flags;
  647. DMFE_DBUG(0, "dmfe_interrupt()", 0);
  648. spin_lock_irqsave(&db->lock, flags);
  649. /* Got DM910X status */
  650. db->cr5_data = dr32(DCR5);
  651. dw32(DCR5, db->cr5_data);
  652. if ( !(db->cr5_data & 0xc1) ) {
  653. spin_unlock_irqrestore(&db->lock, flags);
  654. return IRQ_HANDLED;
  655. }
  656. /* Disable all interrupt in CR7 to solve the interrupt edge problem */
  657. dw32(DCR7, 0);
  658. /* Check system status */
  659. if (db->cr5_data & 0x2000) {
  660. /* system bus error happen */
  661. DMFE_DBUG(1, "System bus error happen. CR5=", db->cr5_data);
  662. db->reset_fatal++;
  663. db->wait_reset = 1; /* Need to RESET */
  664. spin_unlock_irqrestore(&db->lock, flags);
  665. return IRQ_HANDLED;
  666. }
  667. /* Received the coming packet */
  668. if ( (db->cr5_data & 0x40) && db->rx_avail_cnt )
  669. dmfe_rx_packet(dev, db);
  670. /* reallocate rx descriptor buffer */
  671. if (db->rx_avail_cnt<RX_DESC_CNT)
  672. allocate_rx_buffer(dev);
  673. /* Free the transmitted descriptor */
  674. if ( db->cr5_data & 0x01)
  675. dmfe_free_tx_pkt(dev, db);
  676. /* Mode Check */
  677. if (db->dm910x_chk_mode & 0x2) {
  678. db->dm910x_chk_mode = 0x4;
  679. db->cr6_data |= 0x100;
  680. update_cr6(db->cr6_data, ioaddr);
  681. }
  682. /* Restore CR7 to enable interrupt mask */
  683. dw32(DCR7, db->cr7_data);
  684. spin_unlock_irqrestore(&db->lock, flags);
  685. return IRQ_HANDLED;
  686. }
  687. #ifdef CONFIG_NET_POLL_CONTROLLER
  688. /*
  689. * Polling 'interrupt' - used by things like netconsole to send skbs
  690. * without having to re-enable interrupts. It's not called while
  691. * the interrupt routine is executing.
  692. */
  693. static void poll_dmfe (struct net_device *dev)
  694. {
  695. struct dmfe_board_info *db = netdev_priv(dev);
  696. const int irq = db->pdev->irq;
  697. /* disable_irq here is not very nice, but with the lockless
  698. interrupt handler we have no other choice. */
  699. disable_irq(irq);
  700. dmfe_interrupt (irq, dev);
  701. enable_irq(irq);
  702. }
  703. #endif
  704. /*
  705. * Free TX resource after TX complete
  706. */
  707. static void dmfe_free_tx_pkt(struct net_device *dev, struct dmfe_board_info *db)
  708. {
  709. struct tx_desc *txptr;
  710. void __iomem *ioaddr = db->ioaddr;
  711. u32 tdes0;
  712. txptr = db->tx_remove_ptr;
  713. while(db->tx_packet_cnt) {
  714. tdes0 = le32_to_cpu(txptr->tdes0);
  715. if (tdes0 & 0x80000000)
  716. break;
  717. /* A packet sent completed */
  718. db->tx_packet_cnt--;
  719. dev->stats.tx_packets++;
  720. /* Transmit statistic counter */
  721. if ( tdes0 != 0x7fffffff ) {
  722. dev->stats.collisions += (tdes0 >> 3) & 0xf;
  723. dev->stats.tx_bytes += le32_to_cpu(txptr->tdes1) & 0x7ff;
  724. if (tdes0 & TDES0_ERR_MASK) {
  725. dev->stats.tx_errors++;
  726. if (tdes0 & 0x0002) { /* UnderRun */
  727. db->tx_fifo_underrun++;
  728. if ( !(db->cr6_data & CR6_SFT) ) {
  729. db->cr6_data = db->cr6_data | CR6_SFT;
  730. update_cr6(db->cr6_data, ioaddr);
  731. }
  732. }
  733. if (tdes0 & 0x0100)
  734. db->tx_excessive_collision++;
  735. if (tdes0 & 0x0200)
  736. db->tx_late_collision++;
  737. if (tdes0 & 0x0400)
  738. db->tx_no_carrier++;
  739. if (tdes0 & 0x0800)
  740. db->tx_loss_carrier++;
  741. if (tdes0 & 0x4000)
  742. db->tx_jabber_timeout++;
  743. }
  744. }
  745. txptr = txptr->next_tx_desc;
  746. }/* End of while */
  747. /* Update TX remove pointer to next */
  748. db->tx_remove_ptr = txptr;
  749. /* Send the Tx packet in queue */
  750. if ( (db->tx_packet_cnt < TX_MAX_SEND_CNT) && db->tx_queue_cnt ) {
  751. txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
  752. db->tx_packet_cnt++; /* Ready to send */
  753. db->tx_queue_cnt--;
  754. dw32(DCR1, 0x1); /* Issue Tx polling */
  755. netif_trans_update(dev); /* saved time stamp */
  756. }
  757. /* Resource available check */
  758. if ( db->tx_queue_cnt < TX_WAKE_DESC_CNT )
  759. netif_wake_queue(dev); /* Active upper layer, send again */
  760. }
  761. /*
  762. * Calculate the CRC valude of the Rx packet
  763. * flag = 1 : return the reverse CRC (for the received packet CRC)
  764. * 0 : return the normal CRC (for Hash Table index)
  765. */
  766. static inline u32 cal_CRC(unsigned char * Data, unsigned int Len, u8 flag)
  767. {
  768. u32 crc = crc32(~0, Data, Len);
  769. if (flag) crc = ~crc;
  770. return crc;
  771. }
  772. /*
  773. * Receive the come packet and pass to upper layer
  774. */
  775. static void dmfe_rx_packet(struct net_device *dev, struct dmfe_board_info *db)
  776. {
  777. struct rx_desc *rxptr;
  778. struct sk_buff *skb, *newskb;
  779. int rxlen;
  780. u32 rdes0;
  781. rxptr = db->rx_ready_ptr;
  782. while(db->rx_avail_cnt) {
  783. rdes0 = le32_to_cpu(rxptr->rdes0);
  784. if (rdes0 & 0x80000000) /* packet owner check */
  785. break;
  786. db->rx_avail_cnt--;
  787. db->interval_rx_cnt++;
  788. pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2),
  789. RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
  790. if ( (rdes0 & 0x300) != 0x300) {
  791. /* A packet without First/Last flag */
  792. /* reuse this SKB */
  793. DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
  794. dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
  795. } else {
  796. /* A packet with First/Last flag */
  797. rxlen = ( (rdes0 >> 16) & 0x3fff) - 4;
  798. /* error summary bit check */
  799. if (rdes0 & 0x8000) {
  800. /* This is a error packet */
  801. dev->stats.rx_errors++;
  802. if (rdes0 & 1)
  803. dev->stats.rx_fifo_errors++;
  804. if (rdes0 & 2)
  805. dev->stats.rx_crc_errors++;
  806. if (rdes0 & 0x80)
  807. dev->stats.rx_length_errors++;
  808. }
  809. if ( !(rdes0 & 0x8000) ||
  810. ((db->cr6_data & CR6_PM) && (rxlen>6)) ) {
  811. skb = rxptr->rx_skb_ptr;
  812. /* Received Packet CRC check need or not */
  813. if ( (db->dm910x_chk_mode & 1) &&
  814. (cal_CRC(skb->data, rxlen, 1) !=
  815. (*(u32 *) (skb->data+rxlen) ))) { /* FIXME (?) */
  816. /* Found a error received packet */
  817. dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
  818. db->dm910x_chk_mode = 3;
  819. } else {
  820. /* Good packet, send to upper layer */
  821. /* Shorst packet used new SKB */
  822. if ((rxlen < RX_COPY_SIZE) &&
  823. ((newskb = netdev_alloc_skb(dev, rxlen + 2))
  824. != NULL)) {
  825. skb = newskb;
  826. /* size less than COPY_SIZE, allocate a rxlen SKB */
  827. skb_reserve(skb, 2); /* 16byte align */
  828. skb_copy_from_linear_data(rxptr->rx_skb_ptr,
  829. skb_put(skb, rxlen),
  830. rxlen);
  831. dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
  832. } else
  833. skb_put(skb, rxlen);
  834. skb->protocol = eth_type_trans(skb, dev);
  835. netif_rx(skb);
  836. dev->stats.rx_packets++;
  837. dev->stats.rx_bytes += rxlen;
  838. }
  839. } else {
  840. /* Reuse SKB buffer when the packet is error */
  841. DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
  842. dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
  843. }
  844. }
  845. rxptr = rxptr->next_rx_desc;
  846. }
  847. db->rx_ready_ptr = rxptr;
  848. }
  849. /*
  850. * Set DM910X multicast address
  851. */
  852. static void dmfe_set_filter_mode(struct net_device *dev)
  853. {
  854. struct dmfe_board_info *db = netdev_priv(dev);
  855. unsigned long flags;
  856. int mc_count = netdev_mc_count(dev);
  857. DMFE_DBUG(0, "dmfe_set_filter_mode()", 0);
  858. spin_lock_irqsave(&db->lock, flags);
  859. if (dev->flags & IFF_PROMISC) {
  860. DMFE_DBUG(0, "Enable PROM Mode", 0);
  861. db->cr6_data |= CR6_PM | CR6_PBF;
  862. update_cr6(db->cr6_data, db->ioaddr);
  863. spin_unlock_irqrestore(&db->lock, flags);
  864. return;
  865. }
  866. if (dev->flags & IFF_ALLMULTI || mc_count > DMFE_MAX_MULTICAST) {
  867. DMFE_DBUG(0, "Pass all multicast address", mc_count);
  868. db->cr6_data &= ~(CR6_PM | CR6_PBF);
  869. db->cr6_data |= CR6_PAM;
  870. spin_unlock_irqrestore(&db->lock, flags);
  871. return;
  872. }
  873. DMFE_DBUG(0, "Set multicast address", mc_count);
  874. if (db->chip_id == PCI_DM9132_ID)
  875. dm9132_id_table(dev); /* DM9132 */
  876. else
  877. send_filter_frame(dev); /* DM9102/DM9102A */
  878. spin_unlock_irqrestore(&db->lock, flags);
  879. }
  880. /*
  881. * Ethtool interace
  882. */
  883. static void dmfe_ethtool_get_drvinfo(struct net_device *dev,
  884. struct ethtool_drvinfo *info)
  885. {
  886. struct dmfe_board_info *np = netdev_priv(dev);
  887. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  888. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  889. strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
  890. }
  891. static int dmfe_ethtool_set_wol(struct net_device *dev,
  892. struct ethtool_wolinfo *wolinfo)
  893. {
  894. struct dmfe_board_info *db = netdev_priv(dev);
  895. if (wolinfo->wolopts & (WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
  896. WAKE_ARP | WAKE_MAGICSECURE))
  897. return -EOPNOTSUPP;
  898. db->wol_mode = wolinfo->wolopts;
  899. return 0;
  900. }
  901. static void dmfe_ethtool_get_wol(struct net_device *dev,
  902. struct ethtool_wolinfo *wolinfo)
  903. {
  904. struct dmfe_board_info *db = netdev_priv(dev);
  905. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  906. wolinfo->wolopts = db->wol_mode;
  907. }
  908. static const struct ethtool_ops netdev_ethtool_ops = {
  909. .get_drvinfo = dmfe_ethtool_get_drvinfo,
  910. .get_link = ethtool_op_get_link,
  911. .set_wol = dmfe_ethtool_set_wol,
  912. .get_wol = dmfe_ethtool_get_wol,
  913. };
  914. /*
  915. * A periodic timer routine
  916. * Dynamic media sense, allocate Rx buffer...
  917. */
  918. static void dmfe_timer(struct timer_list *t)
  919. {
  920. struct dmfe_board_info *db = from_timer(db, t, timer);
  921. struct net_device *dev = pci_get_drvdata(db->pdev);
  922. void __iomem *ioaddr = db->ioaddr;
  923. u32 tmp_cr8;
  924. unsigned char tmp_cr12;
  925. unsigned long flags;
  926. int link_ok, link_ok_phy;
  927. DMFE_DBUG(0, "dmfe_timer()", 0);
  928. spin_lock_irqsave(&db->lock, flags);
  929. /* Media mode process when Link OK before enter this route */
  930. if (db->first_in_callback == 0) {
  931. db->first_in_callback = 1;
  932. if (db->chip_type && (db->chip_id==PCI_DM9102_ID)) {
  933. db->cr6_data &= ~0x40000;
  934. update_cr6(db->cr6_data, ioaddr);
  935. dmfe_phy_write(ioaddr, db->phy_addr, 0, 0x1000, db->chip_id);
  936. db->cr6_data |= 0x40000;
  937. update_cr6(db->cr6_data, ioaddr);
  938. db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
  939. add_timer(&db->timer);
  940. spin_unlock_irqrestore(&db->lock, flags);
  941. return;
  942. }
  943. }
  944. /* Operating Mode Check */
  945. if ( (db->dm910x_chk_mode & 0x1) &&
  946. (dev->stats.rx_packets > MAX_CHECK_PACKET) )
  947. db->dm910x_chk_mode = 0x4;
  948. /* Dynamic reset DM910X : system error or transmit time-out */
  949. tmp_cr8 = dr32(DCR8);
  950. if ( (db->interval_rx_cnt==0) && (tmp_cr8) ) {
  951. db->reset_cr8++;
  952. db->wait_reset = 1;
  953. }
  954. db->interval_rx_cnt = 0;
  955. /* TX polling kick monitor */
  956. if ( db->tx_packet_cnt &&
  957. time_after(jiffies, dev_trans_start(dev) + DMFE_TX_KICK) ) {
  958. dw32(DCR1, 0x1); /* Tx polling again */
  959. /* TX Timeout */
  960. if (time_after(jiffies, dev_trans_start(dev) + DMFE_TX_TIMEOUT) ) {
  961. db->reset_TXtimeout++;
  962. db->wait_reset = 1;
  963. dev_warn(&dev->dev, "Tx timeout - resetting\n");
  964. }
  965. }
  966. if (db->wait_reset) {
  967. DMFE_DBUG(0, "Dynamic Reset device", db->tx_packet_cnt);
  968. db->reset_count++;
  969. dmfe_dynamic_reset(dev);
  970. db->first_in_callback = 0;
  971. db->timer.expires = DMFE_TIMER_WUT;
  972. add_timer(&db->timer);
  973. spin_unlock_irqrestore(&db->lock, flags);
  974. return;
  975. }
  976. /* Link status check, Dynamic media type change */
  977. if (db->chip_id == PCI_DM9132_ID)
  978. tmp_cr12 = dr8(DCR9 + 3); /* DM9132 */
  979. else
  980. tmp_cr12 = dr8(DCR12); /* DM9102/DM9102A */
  981. if ( ((db->chip_id == PCI_DM9102_ID) &&
  982. (db->chip_revision == 0x30)) ||
  983. ((db->chip_id == PCI_DM9132_ID) &&
  984. (db->chip_revision == 0x10)) ) {
  985. /* DM9102A Chip */
  986. if (tmp_cr12 & 2)
  987. link_ok = 0;
  988. else
  989. link_ok = 1;
  990. }
  991. else
  992. /*0x43 is used instead of 0x3 because bit 6 should represent
  993. link status of external PHY */
  994. link_ok = (tmp_cr12 & 0x43) ? 1 : 0;
  995. /* If chip reports that link is failed it could be because external
  996. PHY link status pin is not connected correctly to chip
  997. To be sure ask PHY too.
  998. */
  999. /* need a dummy read because of PHY's register latch*/
  1000. dmfe_phy_read (db->ioaddr, db->phy_addr, 1, db->chip_id);
  1001. link_ok_phy = (dmfe_phy_read (db->ioaddr,
  1002. db->phy_addr, 1, db->chip_id) & 0x4) ? 1 : 0;
  1003. if (link_ok_phy != link_ok) {
  1004. DMFE_DBUG (0, "PHY and chip report different link status", 0);
  1005. link_ok = link_ok | link_ok_phy;
  1006. }
  1007. if ( !link_ok && netif_carrier_ok(dev)) {
  1008. /* Link Failed */
  1009. DMFE_DBUG(0, "Link Failed", tmp_cr12);
  1010. netif_carrier_off(dev);
  1011. /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
  1012. /* AUTO or force 1M Homerun/Longrun don't need */
  1013. if ( !(db->media_mode & 0x38) )
  1014. dmfe_phy_write(db->ioaddr, db->phy_addr,
  1015. 0, 0x1000, db->chip_id);
  1016. /* AUTO mode, if INT phyxcer link failed, select EXT device */
  1017. if (db->media_mode & DMFE_AUTO) {
  1018. /* 10/100M link failed, used 1M Home-Net */
  1019. db->cr6_data|=0x00040000; /* bit18=1, MII */
  1020. db->cr6_data&=~0x00000200; /* bit9=0, HD mode */
  1021. update_cr6(db->cr6_data, ioaddr);
  1022. }
  1023. } else if (!netif_carrier_ok(dev)) {
  1024. DMFE_DBUG(0, "Link link OK", tmp_cr12);
  1025. /* Auto Sense Speed */
  1026. if ( !(db->media_mode & DMFE_AUTO) || !dmfe_sense_speed(db)) {
  1027. netif_carrier_on(dev);
  1028. SHOW_MEDIA_TYPE(db->op_mode);
  1029. }
  1030. dmfe_process_mode(db);
  1031. }
  1032. /* HPNA remote command check */
  1033. if (db->HPNA_command & 0xf00) {
  1034. db->HPNA_timer--;
  1035. if (!db->HPNA_timer)
  1036. dmfe_HPNA_remote_cmd_chk(db);
  1037. }
  1038. /* Timer active again */
  1039. db->timer.expires = DMFE_TIMER_WUT;
  1040. add_timer(&db->timer);
  1041. spin_unlock_irqrestore(&db->lock, flags);
  1042. }
  1043. /*
  1044. * Dynamic reset the DM910X board
  1045. * Stop DM910X board
  1046. * Free Tx/Rx allocated memory
  1047. * Reset DM910X board
  1048. * Re-initialize DM910X board
  1049. */
  1050. static void dmfe_dynamic_reset(struct net_device *dev)
  1051. {
  1052. struct dmfe_board_info *db = netdev_priv(dev);
  1053. void __iomem *ioaddr = db->ioaddr;
  1054. DMFE_DBUG(0, "dmfe_dynamic_reset()", 0);
  1055. /* Sopt MAC controller */
  1056. db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
  1057. update_cr6(db->cr6_data, ioaddr);
  1058. dw32(DCR7, 0); /* Disable Interrupt */
  1059. dw32(DCR5, dr32(DCR5));
  1060. /* Disable upper layer interface */
  1061. netif_stop_queue(dev);
  1062. /* Free Rx Allocate buffer */
  1063. dmfe_free_rxbuffer(db);
  1064. /* system variable init */
  1065. db->tx_packet_cnt = 0;
  1066. db->tx_queue_cnt = 0;
  1067. db->rx_avail_cnt = 0;
  1068. netif_carrier_off(dev);
  1069. db->wait_reset = 0;
  1070. /* Re-initialize DM910X board */
  1071. dmfe_init_dm910x(dev);
  1072. /* Restart upper layer interface */
  1073. netif_wake_queue(dev);
  1074. }
  1075. /*
  1076. * free all allocated rx buffer
  1077. */
  1078. static void dmfe_free_rxbuffer(struct dmfe_board_info * db)
  1079. {
  1080. DMFE_DBUG(0, "dmfe_free_rxbuffer()", 0);
  1081. /* free allocated rx buffer */
  1082. while (db->rx_avail_cnt) {
  1083. dev_kfree_skb(db->rx_ready_ptr->rx_skb_ptr);
  1084. db->rx_ready_ptr = db->rx_ready_ptr->next_rx_desc;
  1085. db->rx_avail_cnt--;
  1086. }
  1087. }
  1088. /*
  1089. * Reuse the SK buffer
  1090. */
  1091. static void dmfe_reuse_skb(struct dmfe_board_info *db, struct sk_buff * skb)
  1092. {
  1093. struct rx_desc *rxptr = db->rx_insert_ptr;
  1094. if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
  1095. rxptr->rx_skb_ptr = skb;
  1096. rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev,
  1097. skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
  1098. wmb();
  1099. rxptr->rdes0 = cpu_to_le32(0x80000000);
  1100. db->rx_avail_cnt++;
  1101. db->rx_insert_ptr = rxptr->next_rx_desc;
  1102. } else
  1103. DMFE_DBUG(0, "SK Buffer reuse method error", db->rx_avail_cnt);
  1104. }
  1105. /*
  1106. * Initialize transmit/Receive descriptor
  1107. * Using Chain structure, and allocate Tx/Rx buffer
  1108. */
  1109. static void dmfe_descriptor_init(struct net_device *dev)
  1110. {
  1111. struct dmfe_board_info *db = netdev_priv(dev);
  1112. void __iomem *ioaddr = db->ioaddr;
  1113. struct tx_desc *tmp_tx;
  1114. struct rx_desc *tmp_rx;
  1115. unsigned char *tmp_buf;
  1116. dma_addr_t tmp_tx_dma, tmp_rx_dma;
  1117. dma_addr_t tmp_buf_dma;
  1118. int i;
  1119. DMFE_DBUG(0, "dmfe_descriptor_init()", 0);
  1120. /* tx descriptor start pointer */
  1121. db->tx_insert_ptr = db->first_tx_desc;
  1122. db->tx_remove_ptr = db->first_tx_desc;
  1123. dw32(DCR4, db->first_tx_desc_dma); /* TX DESC address */
  1124. /* rx descriptor start pointer */
  1125. db->first_rx_desc = (void *)db->first_tx_desc +
  1126. sizeof(struct tx_desc) * TX_DESC_CNT;
  1127. db->first_rx_desc_dma = db->first_tx_desc_dma +
  1128. sizeof(struct tx_desc) * TX_DESC_CNT;
  1129. db->rx_insert_ptr = db->first_rx_desc;
  1130. db->rx_ready_ptr = db->first_rx_desc;
  1131. dw32(DCR3, db->first_rx_desc_dma); /* RX DESC address */
  1132. /* Init Transmit chain */
  1133. tmp_buf = db->buf_pool_start;
  1134. tmp_buf_dma = db->buf_pool_dma_start;
  1135. tmp_tx_dma = db->first_tx_desc_dma;
  1136. for (tmp_tx = db->first_tx_desc, i = 0; i < TX_DESC_CNT; i++, tmp_tx++) {
  1137. tmp_tx->tx_buf_ptr = tmp_buf;
  1138. tmp_tx->tdes0 = cpu_to_le32(0);
  1139. tmp_tx->tdes1 = cpu_to_le32(0x81000000); /* IC, chain */
  1140. tmp_tx->tdes2 = cpu_to_le32(tmp_buf_dma);
  1141. tmp_tx_dma += sizeof(struct tx_desc);
  1142. tmp_tx->tdes3 = cpu_to_le32(tmp_tx_dma);
  1143. tmp_tx->next_tx_desc = tmp_tx + 1;
  1144. tmp_buf = tmp_buf + TX_BUF_ALLOC;
  1145. tmp_buf_dma = tmp_buf_dma + TX_BUF_ALLOC;
  1146. }
  1147. (--tmp_tx)->tdes3 = cpu_to_le32(db->first_tx_desc_dma);
  1148. tmp_tx->next_tx_desc = db->first_tx_desc;
  1149. /* Init Receive descriptor chain */
  1150. tmp_rx_dma=db->first_rx_desc_dma;
  1151. for (tmp_rx = db->first_rx_desc, i = 0; i < RX_DESC_CNT; i++, tmp_rx++) {
  1152. tmp_rx->rdes0 = cpu_to_le32(0);
  1153. tmp_rx->rdes1 = cpu_to_le32(0x01000600);
  1154. tmp_rx_dma += sizeof(struct rx_desc);
  1155. tmp_rx->rdes3 = cpu_to_le32(tmp_rx_dma);
  1156. tmp_rx->next_rx_desc = tmp_rx + 1;
  1157. }
  1158. (--tmp_rx)->rdes3 = cpu_to_le32(db->first_rx_desc_dma);
  1159. tmp_rx->next_rx_desc = db->first_rx_desc;
  1160. /* pre-allocate Rx buffer */
  1161. allocate_rx_buffer(dev);
  1162. }
  1163. /*
  1164. * Update CR6 value
  1165. * Firstly stop DM910X , then written value and start
  1166. */
  1167. static void update_cr6(u32 cr6_data, void __iomem *ioaddr)
  1168. {
  1169. u32 cr6_tmp;
  1170. cr6_tmp = cr6_data & ~0x2002; /* stop Tx/Rx */
  1171. dw32(DCR6, cr6_tmp);
  1172. udelay(5);
  1173. dw32(DCR6, cr6_data);
  1174. udelay(5);
  1175. }
  1176. /*
  1177. * Send a setup frame for DM9132
  1178. * This setup frame initialize DM910X address filter mode
  1179. */
  1180. static void dm9132_id_table(struct net_device *dev)
  1181. {
  1182. struct dmfe_board_info *db = netdev_priv(dev);
  1183. void __iomem *ioaddr = db->ioaddr + 0xc0;
  1184. u16 *addrptr = (u16 *)dev->dev_addr;
  1185. struct netdev_hw_addr *ha;
  1186. u16 i, hash_table[4];
  1187. /* Node address */
  1188. for (i = 0; i < 3; i++) {
  1189. dw16(0, addrptr[i]);
  1190. ioaddr += 4;
  1191. }
  1192. /* Clear Hash Table */
  1193. memset(hash_table, 0, sizeof(hash_table));
  1194. /* broadcast address */
  1195. hash_table[3] = 0x8000;
  1196. /* the multicast address in Hash Table : 64 bits */
  1197. netdev_for_each_mc_addr(ha, dev) {
  1198. u32 hash_val = cal_CRC((char *)ha->addr, 6, 0) & 0x3f;
  1199. hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
  1200. }
  1201. /* Write the hash table to MAC MD table */
  1202. for (i = 0; i < 4; i++, ioaddr += 4)
  1203. dw16(0, hash_table[i]);
  1204. }
  1205. /*
  1206. * Send a setup frame for DM9102/DM9102A
  1207. * This setup frame initialize DM910X address filter mode
  1208. */
  1209. static void send_filter_frame(struct net_device *dev)
  1210. {
  1211. struct dmfe_board_info *db = netdev_priv(dev);
  1212. struct netdev_hw_addr *ha;
  1213. struct tx_desc *txptr;
  1214. u16 * addrptr;
  1215. u32 * suptr;
  1216. int i;
  1217. DMFE_DBUG(0, "send_filter_frame()", 0);
  1218. txptr = db->tx_insert_ptr;
  1219. suptr = (u32 *) txptr->tx_buf_ptr;
  1220. /* Node address */
  1221. addrptr = (u16 *) dev->dev_addr;
  1222. *suptr++ = addrptr[0];
  1223. *suptr++ = addrptr[1];
  1224. *suptr++ = addrptr[2];
  1225. /* broadcast address */
  1226. *suptr++ = 0xffff;
  1227. *suptr++ = 0xffff;
  1228. *suptr++ = 0xffff;
  1229. /* fit the multicast address */
  1230. netdev_for_each_mc_addr(ha, dev) {
  1231. addrptr = (u16 *) ha->addr;
  1232. *suptr++ = addrptr[0];
  1233. *suptr++ = addrptr[1];
  1234. *suptr++ = addrptr[2];
  1235. }
  1236. for (i = netdev_mc_count(dev); i < 14; i++) {
  1237. *suptr++ = 0xffff;
  1238. *suptr++ = 0xffff;
  1239. *suptr++ = 0xffff;
  1240. }
  1241. /* prepare the setup frame */
  1242. db->tx_insert_ptr = txptr->next_tx_desc;
  1243. txptr->tdes1 = cpu_to_le32(0x890000c0);
  1244. /* Resource Check and Send the setup packet */
  1245. if (!db->tx_packet_cnt) {
  1246. void __iomem *ioaddr = db->ioaddr;
  1247. /* Resource Empty */
  1248. db->tx_packet_cnt++;
  1249. txptr->tdes0 = cpu_to_le32(0x80000000);
  1250. update_cr6(db->cr6_data | 0x2000, ioaddr);
  1251. dw32(DCR1, 0x1); /* Issue Tx polling */
  1252. update_cr6(db->cr6_data, ioaddr);
  1253. netif_trans_update(dev);
  1254. } else
  1255. db->tx_queue_cnt++; /* Put in TX queue */
  1256. }
  1257. /*
  1258. * Allocate rx buffer,
  1259. * As possible as allocate maxiumn Rx buffer
  1260. */
  1261. static void allocate_rx_buffer(struct net_device *dev)
  1262. {
  1263. struct dmfe_board_info *db = netdev_priv(dev);
  1264. struct rx_desc *rxptr;
  1265. struct sk_buff *skb;
  1266. rxptr = db->rx_insert_ptr;
  1267. while(db->rx_avail_cnt < RX_DESC_CNT) {
  1268. if ( ( skb = netdev_alloc_skb(dev, RX_ALLOC_SIZE) ) == NULL )
  1269. break;
  1270. rxptr->rx_skb_ptr = skb; /* FIXME (?) */
  1271. rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data,
  1272. RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
  1273. wmb();
  1274. rxptr->rdes0 = cpu_to_le32(0x80000000);
  1275. rxptr = rxptr->next_rx_desc;
  1276. db->rx_avail_cnt++;
  1277. }
  1278. db->rx_insert_ptr = rxptr;
  1279. }
  1280. static void srom_clk_write(void __iomem *ioaddr, u32 data)
  1281. {
  1282. static const u32 cmd[] = {
  1283. CR9_SROM_READ | CR9_SRCS,
  1284. CR9_SROM_READ | CR9_SRCS | CR9_SRCLK,
  1285. CR9_SROM_READ | CR9_SRCS
  1286. };
  1287. int i;
  1288. for (i = 0; i < ARRAY_SIZE(cmd); i++) {
  1289. dw32(DCR9, data | cmd[i]);
  1290. udelay(5);
  1291. }
  1292. }
  1293. /*
  1294. * Read one word data from the serial ROM
  1295. */
  1296. static u16 read_srom_word(void __iomem *ioaddr, int offset)
  1297. {
  1298. u16 srom_data;
  1299. int i;
  1300. dw32(DCR9, CR9_SROM_READ);
  1301. udelay(5);
  1302. dw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1303. udelay(5);
  1304. /* Send the Read Command 110b */
  1305. srom_clk_write(ioaddr, SROM_DATA_1);
  1306. srom_clk_write(ioaddr, SROM_DATA_1);
  1307. srom_clk_write(ioaddr, SROM_DATA_0);
  1308. /* Send the offset */
  1309. for (i = 5; i >= 0; i--) {
  1310. srom_data = (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0;
  1311. srom_clk_write(ioaddr, srom_data);
  1312. }
  1313. dw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1314. udelay(5);
  1315. for (i = 16; i > 0; i--) {
  1316. dw32(DCR9, CR9_SROM_READ | CR9_SRCS | CR9_SRCLK);
  1317. udelay(5);
  1318. srom_data = (srom_data << 1) |
  1319. ((dr32(DCR9) & CR9_CRDOUT) ? 1 : 0);
  1320. dw32(DCR9, CR9_SROM_READ | CR9_SRCS);
  1321. udelay(5);
  1322. }
  1323. dw32(DCR9, CR9_SROM_READ);
  1324. udelay(5);
  1325. return srom_data;
  1326. }
  1327. /*
  1328. * Auto sense the media mode
  1329. */
  1330. static u8 dmfe_sense_speed(struct dmfe_board_info *db)
  1331. {
  1332. void __iomem *ioaddr = db->ioaddr;
  1333. u8 ErrFlag = 0;
  1334. u16 phy_mode;
  1335. /* CR6 bit18=0, select 10/100M */
  1336. update_cr6(db->cr6_data & ~0x40000, ioaddr);
  1337. phy_mode = dmfe_phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id);
  1338. phy_mode = dmfe_phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id);
  1339. if ( (phy_mode & 0x24) == 0x24 ) {
  1340. if (db->chip_id == PCI_DM9132_ID) /* DM9132 */
  1341. phy_mode = dmfe_phy_read(db->ioaddr,
  1342. db->phy_addr, 7, db->chip_id) & 0xf000;
  1343. else /* DM9102/DM9102A */
  1344. phy_mode = dmfe_phy_read(db->ioaddr,
  1345. db->phy_addr, 17, db->chip_id) & 0xf000;
  1346. switch (phy_mode) {
  1347. case 0x1000: db->op_mode = DMFE_10MHF; break;
  1348. case 0x2000: db->op_mode = DMFE_10MFD; break;
  1349. case 0x4000: db->op_mode = DMFE_100MHF; break;
  1350. case 0x8000: db->op_mode = DMFE_100MFD; break;
  1351. default: db->op_mode = DMFE_10MHF;
  1352. ErrFlag = 1;
  1353. break;
  1354. }
  1355. } else {
  1356. db->op_mode = DMFE_10MHF;
  1357. DMFE_DBUG(0, "Link Failed :", phy_mode);
  1358. ErrFlag = 1;
  1359. }
  1360. return ErrFlag;
  1361. }
  1362. /*
  1363. * Set 10/100 phyxcer capability
  1364. * AUTO mode : phyxcer register4 is NIC capability
  1365. * Force mode: phyxcer register4 is the force media
  1366. */
  1367. static void dmfe_set_phyxcer(struct dmfe_board_info *db)
  1368. {
  1369. void __iomem *ioaddr = db->ioaddr;
  1370. u16 phy_reg;
  1371. /* Select 10/100M phyxcer */
  1372. db->cr6_data &= ~0x40000;
  1373. update_cr6(db->cr6_data, ioaddr);
  1374. /* DM9009 Chip: Phyxcer reg18 bit12=0 */
  1375. if (db->chip_id == PCI_DM9009_ID) {
  1376. phy_reg = dmfe_phy_read(db->ioaddr,
  1377. db->phy_addr, 18, db->chip_id) & ~0x1000;
  1378. dmfe_phy_write(db->ioaddr,
  1379. db->phy_addr, 18, phy_reg, db->chip_id);
  1380. }
  1381. /* Phyxcer capability setting */
  1382. phy_reg = dmfe_phy_read(db->ioaddr, db->phy_addr, 4, db->chip_id) & ~0x01e0;
  1383. if (db->media_mode & DMFE_AUTO) {
  1384. /* AUTO Mode */
  1385. phy_reg |= db->PHY_reg4;
  1386. } else {
  1387. /* Force Mode */
  1388. switch(db->media_mode) {
  1389. case DMFE_10MHF: phy_reg |= 0x20; break;
  1390. case DMFE_10MFD: phy_reg |= 0x40; break;
  1391. case DMFE_100MHF: phy_reg |= 0x80; break;
  1392. case DMFE_100MFD: phy_reg |= 0x100; break;
  1393. }
  1394. if (db->chip_id == PCI_DM9009_ID) phy_reg &= 0x61;
  1395. }
  1396. /* Write new capability to Phyxcer Reg4 */
  1397. if ( !(phy_reg & 0x01e0)) {
  1398. phy_reg|=db->PHY_reg4;
  1399. db->media_mode|=DMFE_AUTO;
  1400. }
  1401. dmfe_phy_write(db->ioaddr, db->phy_addr, 4, phy_reg, db->chip_id);
  1402. /* Restart Auto-Negotiation */
  1403. if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) )
  1404. dmfe_phy_write(db->ioaddr, db->phy_addr, 0, 0x1800, db->chip_id);
  1405. if ( !db->chip_type )
  1406. dmfe_phy_write(db->ioaddr, db->phy_addr, 0, 0x1200, db->chip_id);
  1407. }
  1408. /*
  1409. * Process op-mode
  1410. * AUTO mode : PHY controller in Auto-negotiation Mode
  1411. * Force mode: PHY controller in force mode with HUB
  1412. * N-way force capability with SWITCH
  1413. */
  1414. static void dmfe_process_mode(struct dmfe_board_info *db)
  1415. {
  1416. u16 phy_reg;
  1417. /* Full Duplex Mode Check */
  1418. if (db->op_mode & 0x4)
  1419. db->cr6_data |= CR6_FDM; /* Set Full Duplex Bit */
  1420. else
  1421. db->cr6_data &= ~CR6_FDM; /* Clear Full Duplex Bit */
  1422. /* Transciver Selection */
  1423. if (db->op_mode & 0x10) /* 1M HomePNA */
  1424. db->cr6_data |= 0x40000;/* External MII select */
  1425. else
  1426. db->cr6_data &= ~0x40000;/* Internal 10/100 transciver */
  1427. update_cr6(db->cr6_data, db->ioaddr);
  1428. /* 10/100M phyxcer force mode need */
  1429. if ( !(db->media_mode & 0x18)) {
  1430. /* Forece Mode */
  1431. phy_reg = dmfe_phy_read(db->ioaddr, db->phy_addr, 6, db->chip_id);
  1432. if ( !(phy_reg & 0x1) ) {
  1433. /* parter without N-Way capability */
  1434. phy_reg = 0x0;
  1435. switch(db->op_mode) {
  1436. case DMFE_10MHF: phy_reg = 0x0; break;
  1437. case DMFE_10MFD: phy_reg = 0x100; break;
  1438. case DMFE_100MHF: phy_reg = 0x2000; break;
  1439. case DMFE_100MFD: phy_reg = 0x2100; break;
  1440. }
  1441. dmfe_phy_write(db->ioaddr,
  1442. db->phy_addr, 0, phy_reg, db->chip_id);
  1443. if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) )
  1444. mdelay(20);
  1445. dmfe_phy_write(db->ioaddr,
  1446. db->phy_addr, 0, phy_reg, db->chip_id);
  1447. }
  1448. }
  1449. }
  1450. /*
  1451. * Write a word to Phy register
  1452. */
  1453. static void dmfe_phy_write(void __iomem *ioaddr, u8 phy_addr, u8 offset,
  1454. u16 phy_data, u32 chip_id)
  1455. {
  1456. u16 i;
  1457. if (chip_id == PCI_DM9132_ID) {
  1458. dw16(0x80 + offset * 4, phy_data);
  1459. } else {
  1460. /* DM9102/DM9102A Chip */
  1461. /* Send 33 synchronization clock to Phy controller */
  1462. for (i = 0; i < 35; i++)
  1463. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1464. /* Send start command(01) to Phy */
  1465. dmfe_phy_write_1bit(ioaddr, PHY_DATA_0);
  1466. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1467. /* Send write command(01) to Phy */
  1468. dmfe_phy_write_1bit(ioaddr, PHY_DATA_0);
  1469. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1470. /* Send Phy address */
  1471. for (i = 0x10; i > 0; i = i >> 1)
  1472. dmfe_phy_write_1bit(ioaddr,
  1473. phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
  1474. /* Send register address */
  1475. for (i = 0x10; i > 0; i = i >> 1)
  1476. dmfe_phy_write_1bit(ioaddr,
  1477. offset & i ? PHY_DATA_1 : PHY_DATA_0);
  1478. /* written trasnition */
  1479. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1480. dmfe_phy_write_1bit(ioaddr, PHY_DATA_0);
  1481. /* Write a word data to PHY controller */
  1482. for ( i = 0x8000; i > 0; i >>= 1)
  1483. dmfe_phy_write_1bit(ioaddr,
  1484. phy_data & i ? PHY_DATA_1 : PHY_DATA_0);
  1485. }
  1486. }
  1487. /*
  1488. * Read a word data from phy register
  1489. */
  1490. static u16 dmfe_phy_read(void __iomem *ioaddr, u8 phy_addr, u8 offset, u32 chip_id)
  1491. {
  1492. int i;
  1493. u16 phy_data;
  1494. if (chip_id == PCI_DM9132_ID) {
  1495. /* DM9132 Chip */
  1496. phy_data = dr16(0x80 + offset * 4);
  1497. } else {
  1498. /* DM9102/DM9102A Chip */
  1499. /* Send 33 synchronization clock to Phy controller */
  1500. for (i = 0; i < 35; i++)
  1501. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1502. /* Send start command(01) to Phy */
  1503. dmfe_phy_write_1bit(ioaddr, PHY_DATA_0);
  1504. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1505. /* Send read command(10) to Phy */
  1506. dmfe_phy_write_1bit(ioaddr, PHY_DATA_1);
  1507. dmfe_phy_write_1bit(ioaddr, PHY_DATA_0);
  1508. /* Send Phy address */
  1509. for (i = 0x10; i > 0; i = i >> 1)
  1510. dmfe_phy_write_1bit(ioaddr,
  1511. phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
  1512. /* Send register address */
  1513. for (i = 0x10; i > 0; i = i >> 1)
  1514. dmfe_phy_write_1bit(ioaddr,
  1515. offset & i ? PHY_DATA_1 : PHY_DATA_0);
  1516. /* Skip transition state */
  1517. dmfe_phy_read_1bit(ioaddr);
  1518. /* read 16bit data */
  1519. for (phy_data = 0, i = 0; i < 16; i++) {
  1520. phy_data <<= 1;
  1521. phy_data |= dmfe_phy_read_1bit(ioaddr);
  1522. }
  1523. }
  1524. return phy_data;
  1525. }
  1526. /*
  1527. * Write one bit data to Phy Controller
  1528. */
  1529. static void dmfe_phy_write_1bit(void __iomem *ioaddr, u32 phy_data)
  1530. {
  1531. dw32(DCR9, phy_data); /* MII Clock Low */
  1532. udelay(1);
  1533. dw32(DCR9, phy_data | MDCLKH); /* MII Clock High */
  1534. udelay(1);
  1535. dw32(DCR9, phy_data); /* MII Clock Low */
  1536. udelay(1);
  1537. }
  1538. /*
  1539. * Read one bit phy data from PHY controller
  1540. */
  1541. static u16 dmfe_phy_read_1bit(void __iomem *ioaddr)
  1542. {
  1543. u16 phy_data;
  1544. dw32(DCR9, 0x50000);
  1545. udelay(1);
  1546. phy_data = (dr32(DCR9) >> 19) & 0x1;
  1547. dw32(DCR9, 0x40000);
  1548. udelay(1);
  1549. return phy_data;
  1550. }
  1551. /*
  1552. * Parser SROM and media mode
  1553. */
  1554. static void dmfe_parse_srom(struct dmfe_board_info * db)
  1555. {
  1556. char * srom = db->srom;
  1557. int dmfe_mode, tmp_reg;
  1558. DMFE_DBUG(0, "dmfe_parse_srom() ", 0);
  1559. /* Init CR15 */
  1560. db->cr15_data = CR15_DEFAULT;
  1561. /* Check SROM Version */
  1562. if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) {
  1563. /* SROM V4.01 */
  1564. /* Get NIC support media mode */
  1565. db->NIC_capability = le16_to_cpup((__le16 *) (srom + 34));
  1566. db->PHY_reg4 = 0;
  1567. for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
  1568. switch( db->NIC_capability & tmp_reg ) {
  1569. case 0x1: db->PHY_reg4 |= 0x0020; break;
  1570. case 0x2: db->PHY_reg4 |= 0x0040; break;
  1571. case 0x4: db->PHY_reg4 |= 0x0080; break;
  1572. case 0x8: db->PHY_reg4 |= 0x0100; break;
  1573. }
  1574. }
  1575. /* Media Mode Force or not check */
  1576. dmfe_mode = (le32_to_cpup((__le32 *) (srom + 34)) &
  1577. le32_to_cpup((__le32 *) (srom + 36)));
  1578. switch(dmfe_mode) {
  1579. case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */
  1580. case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */
  1581. case 0x8: dmfe_media_mode = DMFE_100MFD; break; /* 100MFD */
  1582. case 0x100:
  1583. case 0x200: dmfe_media_mode = DMFE_1M_HPNA; break;/* HomePNA */
  1584. }
  1585. /* Special Function setting */
  1586. /* VLAN function */
  1587. if ( (SF_mode & 0x1) || (srom[43] & 0x80) )
  1588. db->cr15_data |= 0x40;
  1589. /* Flow Control */
  1590. if ( (SF_mode & 0x2) || (srom[40] & 0x1) )
  1591. db->cr15_data |= 0x400;
  1592. /* TX pause packet */
  1593. if ( (SF_mode & 0x4) || (srom[40] & 0xe) )
  1594. db->cr15_data |= 0x9800;
  1595. }
  1596. /* Parse HPNA parameter */
  1597. db->HPNA_command = 1;
  1598. /* Accept remote command or not */
  1599. if (HPNA_rx_cmd == 0)
  1600. db->HPNA_command |= 0x8000;
  1601. /* Issue remote command & operation mode */
  1602. if (HPNA_tx_cmd == 1)
  1603. switch(HPNA_mode) { /* Issue Remote Command */
  1604. case 0: db->HPNA_command |= 0x0904; break;
  1605. case 1: db->HPNA_command |= 0x0a00; break;
  1606. case 2: db->HPNA_command |= 0x0506; break;
  1607. case 3: db->HPNA_command |= 0x0602; break;
  1608. }
  1609. else
  1610. switch(HPNA_mode) { /* Don't Issue */
  1611. case 0: db->HPNA_command |= 0x0004; break;
  1612. case 1: db->HPNA_command |= 0x0000; break;
  1613. case 2: db->HPNA_command |= 0x0006; break;
  1614. case 3: db->HPNA_command |= 0x0002; break;
  1615. }
  1616. /* Check DM9801 or DM9802 present or not */
  1617. db->HPNA_present = 0;
  1618. update_cr6(db->cr6_data | 0x40000, db->ioaddr);
  1619. tmp_reg = dmfe_phy_read(db->ioaddr, db->phy_addr, 3, db->chip_id);
  1620. if ( ( tmp_reg & 0xfff0 ) == 0xb900 ) {
  1621. /* DM9801 or DM9802 present */
  1622. db->HPNA_timer = 8;
  1623. if ( dmfe_phy_read(db->ioaddr, db->phy_addr, 31, db->chip_id) == 0x4404) {
  1624. /* DM9801 HomeRun */
  1625. db->HPNA_present = 1;
  1626. dmfe_program_DM9801(db, tmp_reg);
  1627. } else {
  1628. /* DM9802 LongRun */
  1629. db->HPNA_present = 2;
  1630. dmfe_program_DM9802(db);
  1631. }
  1632. }
  1633. }
  1634. /*
  1635. * Init HomeRun DM9801
  1636. */
  1637. static void dmfe_program_DM9801(struct dmfe_board_info * db, int HPNA_rev)
  1638. {
  1639. uint reg17, reg25;
  1640. if ( !HPNA_NoiseFloor ) HPNA_NoiseFloor = DM9801_NOISE_FLOOR;
  1641. switch(HPNA_rev) {
  1642. case 0xb900: /* DM9801 E3 */
  1643. db->HPNA_command |= 0x1000;
  1644. reg25 = dmfe_phy_read(db->ioaddr, db->phy_addr, 24, db->chip_id);
  1645. reg25 = ( (reg25 + HPNA_NoiseFloor) & 0xff) | 0xf000;
  1646. reg17 = dmfe_phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
  1647. break;
  1648. case 0xb901: /* DM9801 E4 */
  1649. reg25 = dmfe_phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
  1650. reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor;
  1651. reg17 = dmfe_phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
  1652. reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor + 3;
  1653. break;
  1654. case 0xb902: /* DM9801 E5 */
  1655. case 0xb903: /* DM9801 E6 */
  1656. default:
  1657. db->HPNA_command |= 0x1000;
  1658. reg25 = dmfe_phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
  1659. reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor - 5;
  1660. reg17 = dmfe_phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
  1661. reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor;
  1662. break;
  1663. }
  1664. dmfe_phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command, db->chip_id);
  1665. dmfe_phy_write(db->ioaddr, db->phy_addr, 17, reg17, db->chip_id);
  1666. dmfe_phy_write(db->ioaddr, db->phy_addr, 25, reg25, db->chip_id);
  1667. }
  1668. /*
  1669. * Init HomeRun DM9802
  1670. */
  1671. static void dmfe_program_DM9802(struct dmfe_board_info * db)
  1672. {
  1673. uint phy_reg;
  1674. if ( !HPNA_NoiseFloor ) HPNA_NoiseFloor = DM9802_NOISE_FLOOR;
  1675. dmfe_phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command, db->chip_id);
  1676. phy_reg = dmfe_phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
  1677. phy_reg = ( phy_reg & 0xff00) + HPNA_NoiseFloor;
  1678. dmfe_phy_write(db->ioaddr, db->phy_addr, 25, phy_reg, db->chip_id);
  1679. }
  1680. /*
  1681. * Check remote HPNA power and speed status. If not correct,
  1682. * issue command again.
  1683. */
  1684. static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * db)
  1685. {
  1686. uint phy_reg;
  1687. /* Got remote device status */
  1688. phy_reg = dmfe_phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id) & 0x60;
  1689. switch(phy_reg) {
  1690. case 0x00: phy_reg = 0x0a00;break; /* LP/LS */
  1691. case 0x20: phy_reg = 0x0900;break; /* LP/HS */
  1692. case 0x40: phy_reg = 0x0600;break; /* HP/LS */
  1693. case 0x60: phy_reg = 0x0500;break; /* HP/HS */
  1694. }
  1695. /* Check remote device status match our setting ot not */
  1696. if ( phy_reg != (db->HPNA_command & 0x0f00) ) {
  1697. dmfe_phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command,
  1698. db->chip_id);
  1699. db->HPNA_timer=8;
  1700. } else
  1701. db->HPNA_timer=600; /* Match, every 10 minutes, check */
  1702. }
  1703. static const struct pci_device_id dmfe_pci_tbl[] = {
  1704. { 0x1282, 0x9132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9132_ID },
  1705. { 0x1282, 0x9102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9102_ID },
  1706. { 0x1282, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9100_ID },
  1707. { 0x1282, 0x9009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9009_ID },
  1708. { 0, }
  1709. };
  1710. MODULE_DEVICE_TABLE(pci, dmfe_pci_tbl);
  1711. #ifdef CONFIG_PM
  1712. static int dmfe_suspend(struct pci_dev *pci_dev, pm_message_t state)
  1713. {
  1714. struct net_device *dev = pci_get_drvdata(pci_dev);
  1715. struct dmfe_board_info *db = netdev_priv(dev);
  1716. void __iomem *ioaddr = db->ioaddr;
  1717. u32 tmp;
  1718. /* Disable upper layer interface */
  1719. netif_device_detach(dev);
  1720. /* Disable Tx/Rx */
  1721. db->cr6_data &= ~(CR6_RXSC | CR6_TXSC);
  1722. update_cr6(db->cr6_data, ioaddr);
  1723. /* Disable Interrupt */
  1724. dw32(DCR7, 0);
  1725. dw32(DCR5, dr32(DCR5));
  1726. /* Fre RX buffers */
  1727. dmfe_free_rxbuffer(db);
  1728. /* Enable WOL */
  1729. pci_read_config_dword(pci_dev, 0x40, &tmp);
  1730. tmp &= ~(DMFE_WOL_LINKCHANGE|DMFE_WOL_MAGICPACKET);
  1731. if (db->wol_mode & WAKE_PHY)
  1732. tmp |= DMFE_WOL_LINKCHANGE;
  1733. if (db->wol_mode & WAKE_MAGIC)
  1734. tmp |= DMFE_WOL_MAGICPACKET;
  1735. pci_write_config_dword(pci_dev, 0x40, tmp);
  1736. pci_enable_wake(pci_dev, PCI_D3hot, 1);
  1737. pci_enable_wake(pci_dev, PCI_D3cold, 1);
  1738. /* Power down device*/
  1739. pci_save_state(pci_dev);
  1740. pci_set_power_state(pci_dev, pci_choose_state (pci_dev, state));
  1741. return 0;
  1742. }
  1743. static int dmfe_resume(struct pci_dev *pci_dev)
  1744. {
  1745. struct net_device *dev = pci_get_drvdata(pci_dev);
  1746. u32 tmp;
  1747. pci_set_power_state(pci_dev, PCI_D0);
  1748. pci_restore_state(pci_dev);
  1749. /* Re-initialize DM910X board */
  1750. dmfe_init_dm910x(dev);
  1751. /* Disable WOL */
  1752. pci_read_config_dword(pci_dev, 0x40, &tmp);
  1753. tmp &= ~(DMFE_WOL_LINKCHANGE | DMFE_WOL_MAGICPACKET);
  1754. pci_write_config_dword(pci_dev, 0x40, tmp);
  1755. pci_enable_wake(pci_dev, PCI_D3hot, 0);
  1756. pci_enable_wake(pci_dev, PCI_D3cold, 0);
  1757. /* Restart upper layer interface */
  1758. netif_device_attach(dev);
  1759. return 0;
  1760. }
  1761. #else
  1762. #define dmfe_suspend NULL
  1763. #define dmfe_resume NULL
  1764. #endif
  1765. static struct pci_driver dmfe_driver = {
  1766. .name = "dmfe",
  1767. .id_table = dmfe_pci_tbl,
  1768. .probe = dmfe_init_one,
  1769. .remove = dmfe_remove_one,
  1770. .suspend = dmfe_suspend,
  1771. .resume = dmfe_resume
  1772. };
  1773. MODULE_AUTHOR("Sten Wang, sten_wang@davicom.com.tw");
  1774. MODULE_DESCRIPTION("Davicom DM910X fast ethernet driver");
  1775. MODULE_LICENSE("GPL");
  1776. MODULE_VERSION(DRV_VERSION);
  1777. module_param(debug, int, 0);
  1778. module_param(mode, byte, 0);
  1779. module_param(cr6set, int, 0);
  1780. module_param(chkmode, byte, 0);
  1781. module_param(HPNA_mode, byte, 0);
  1782. module_param(HPNA_rx_cmd, byte, 0);
  1783. module_param(HPNA_tx_cmd, byte, 0);
  1784. module_param(HPNA_NoiseFloor, byte, 0);
  1785. module_param(SF_mode, byte, 0);
  1786. MODULE_PARM_DESC(debug, "Davicom DM9xxx enable debugging (0-1)");
  1787. MODULE_PARM_DESC(mode, "Davicom DM9xxx: "
  1788. "Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
  1789. MODULE_PARM_DESC(SF_mode, "Davicom DM9xxx special function "
  1790. "(bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)");
  1791. /* Description:
  1792. * when user used insmod to add module, system invoked init_module()
  1793. * to initialize and register.
  1794. */
  1795. static int __init dmfe_init_module(void)
  1796. {
  1797. int rc;
  1798. pr_info("%s\n", version);
  1799. printed_version = 1;
  1800. DMFE_DBUG(0, "init_module() ", debug);
  1801. if (debug)
  1802. dmfe_debug = debug; /* set debug flag */
  1803. if (cr6set)
  1804. dmfe_cr6_user_set = cr6set;
  1805. switch (mode) {
  1806. case DMFE_10MHF:
  1807. case DMFE_100MHF:
  1808. case DMFE_10MFD:
  1809. case DMFE_100MFD:
  1810. case DMFE_1M_HPNA:
  1811. dmfe_media_mode = mode;
  1812. break;
  1813. default:
  1814. dmfe_media_mode = DMFE_AUTO;
  1815. break;
  1816. }
  1817. if (HPNA_mode > 4)
  1818. HPNA_mode = 0; /* Default: LP/HS */
  1819. if (HPNA_rx_cmd > 1)
  1820. HPNA_rx_cmd = 0; /* Default: Ignored remote cmd */
  1821. if (HPNA_tx_cmd > 1)
  1822. HPNA_tx_cmd = 0; /* Default: Don't issue remote cmd */
  1823. if (HPNA_NoiseFloor > 15)
  1824. HPNA_NoiseFloor = 0;
  1825. rc = pci_register_driver(&dmfe_driver);
  1826. if (rc < 0)
  1827. return rc;
  1828. return 0;
  1829. }
  1830. /*
  1831. * Description:
  1832. * when user used rmmod to delete module, system invoked clean_module()
  1833. * to un-register all registered services.
  1834. */
  1835. static void __exit dmfe_cleanup_module(void)
  1836. {
  1837. DMFE_DBUG(0, "dmfe_cleanup_module() ", debug);
  1838. pci_unregister_driver(&dmfe_driver);
  1839. }
  1840. module_init(dmfe_init_module);
  1841. module_exit(dmfe_cleanup_module);