nmclan_cs.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. /* ----------------------------------------------------------------------------
  2. Linux PCMCIA ethernet adapter driver for the New Media Ethernet LAN.
  3. nmclan_cs.c,v 0.16 1995/07/01 06:42:17 rpao Exp rpao
  4. The Ethernet LAN uses the Advanced Micro Devices (AMD) Am79C940 Media
  5. Access Controller for Ethernet (MACE). It is essentially the Am2150
  6. PCMCIA Ethernet card contained in the Am2150 Demo Kit.
  7. Written by Roger C. Pao <rpao@paonet.org>
  8. Copyright 1995 Roger C. Pao
  9. Linux 2.5 cleanups Copyright Red Hat 2003
  10. This software may be used and distributed according to the terms of
  11. the GNU General Public License.
  12. Ported to Linux 1.3.* network driver environment by
  13. Matti Aarnio <mea@utu.fi>
  14. References
  15. Am2150 Technical Reference Manual, Revision 1.0, August 17, 1993
  16. Am79C940 (MACE) Data Sheet, 1994
  17. Am79C90 (C-LANCE) Data Sheet, 1994
  18. Linux PCMCIA Programmer's Guide v1.17
  19. /usr/src/linux/net/inet/dev.c, Linux kernel 1.2.8
  20. Eric Mears, New Media Corporation
  21. Tom Pollard, New Media Corporation
  22. Dean Siasoyco, New Media Corporation
  23. Ken Lesniak, Silicon Graphics, Inc. <lesniak@boston.sgi.com>
  24. Donald Becker <becker@scyld.com>
  25. David Hinds <dahinds@users.sourceforge.net>
  26. The Linux client driver is based on the 3c589_cs.c client driver by
  27. David Hinds.
  28. The Linux network driver outline is based on the 3c589_cs.c driver,
  29. the 8390.c driver, and the example skeleton.c kernel code, which are
  30. by Donald Becker.
  31. The Am2150 network driver hardware interface code is based on the
  32. OS/9000 driver for the New Media Ethernet LAN by Eric Mears.
  33. Special thanks for testing and help in debugging this driver goes
  34. to Ken Lesniak.
  35. -------------------------------------------------------------------------------
  36. Driver Notes and Issues
  37. -------------------------------------------------------------------------------
  38. 1. Developed on a Dell 320SLi
  39. PCMCIA Card Services 2.6.2
  40. Linux dell 1.2.10 #1 Thu Jun 29 20:23:41 PDT 1995 i386
  41. 2. rc.pcmcia may require loading pcmcia_core with io_speed=300:
  42. 'insmod pcmcia_core.o io_speed=300'.
  43. This will avoid problems with fast systems which causes rx_framecnt
  44. to return random values.
  45. 3. If hot extraction does not work for you, use 'ifconfig eth0 down'
  46. before extraction.
  47. 4. There is a bad slow-down problem in this driver.
  48. 5. Future: Multicast processing. In the meantime, do _not_ compile your
  49. kernel with multicast ip enabled.
  50. -------------------------------------------------------------------------------
  51. History
  52. -------------------------------------------------------------------------------
  53. Log: nmclan_cs.c,v
  54. * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk>
  55. * Fixed hang on card eject as we probe it
  56. * Cleaned up to use new style locking.
  57. *
  58. * Revision 0.16 1995/07/01 06:42:17 rpao
  59. * Bug fix: nmclan_reset() called CardServices incorrectly.
  60. *
  61. * Revision 0.15 1995/05/24 08:09:47 rpao
  62. * Re-implement MULTI_TX dev->tbusy handling.
  63. *
  64. * Revision 0.14 1995/05/23 03:19:30 rpao
  65. * Added, in nmclan_config(), "tuple.Attributes = 0;".
  66. * Modified MACE ID check to ignore chip revision level.
  67. * Avoid tx_free_frames race condition between _start_xmit and _interrupt.
  68. *
  69. * Revision 0.13 1995/05/18 05:56:34 rpao
  70. * Statistics changes.
  71. * Bug fix: nmclan_reset did not enable TX and RX: call restore_multicast_list.
  72. * Bug fix: mace_interrupt checks ~MACE_IMR_DEFAULT. Fixes driver lockup.
  73. *
  74. * Revision 0.12 1995/05/14 00:12:23 rpao
  75. * Statistics overhaul.
  76. *
  77. 95/05/13 rpao V0.10a
  78. Bug fix: MACE statistics counters used wrong I/O ports.
  79. Bug fix: mace_interrupt() needed to allow statistics to be
  80. processed without RX or TX interrupts pending.
  81. 95/05/11 rpao V0.10
  82. Multiple transmit request processing.
  83. Modified statistics to use MACE counters where possible.
  84. 95/05/10 rpao V0.09 Bug fix: Must use IO_DATA_PATH_WIDTH_AUTO.
  85. *Released
  86. 95/05/10 rpao V0.08
  87. Bug fix: Make all non-exported functions private by using
  88. static keyword.
  89. Bug fix: Test IntrCnt _before_ reading MACE_IR.
  90. 95/05/10 rpao V0.07 Statistics.
  91. 95/05/09 rpao V0.06 Fix rx_framecnt problem by addition of PCIC wait states.
  92. ---------------------------------------------------------------------------- */
  93. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  94. #define DRV_NAME "nmclan_cs"
  95. #define DRV_VERSION "0.16"
  96. /* ----------------------------------------------------------------------------
  97. Conditional Compilation Options
  98. ---------------------------------------------------------------------------- */
  99. #define MULTI_TX 0
  100. #define RESET_ON_TIMEOUT 1
  101. #define TX_INTERRUPTABLE 1
  102. #define RESET_XILINX 0
  103. /* ----------------------------------------------------------------------------
  104. Include Files
  105. ---------------------------------------------------------------------------- */
  106. #include <linux/module.h>
  107. #include <linux/kernel.h>
  108. #include <linux/ptrace.h>
  109. #include <linux/slab.h>
  110. #include <linux/string.h>
  111. #include <linux/timer.h>
  112. #include <linux/interrupt.h>
  113. #include <linux/in.h>
  114. #include <linux/delay.h>
  115. #include <linux/ethtool.h>
  116. #include <linux/netdevice.h>
  117. #include <linux/etherdevice.h>
  118. #include <linux/skbuff.h>
  119. #include <linux/if_arp.h>
  120. #include <linux/ioport.h>
  121. #include <linux/bitops.h>
  122. #include <pcmcia/cisreg.h>
  123. #include <pcmcia/cistpl.h>
  124. #include <pcmcia/ds.h>
  125. #include <linux/uaccess.h>
  126. #include <asm/io.h>
  127. /* ----------------------------------------------------------------------------
  128. Defines
  129. ---------------------------------------------------------------------------- */
  130. #define MACE_LADRF_LEN 8
  131. /* 8 bytes in Logical Address Filter */
  132. /* Loop Control Defines */
  133. #define MACE_MAX_IR_ITERATIONS 10
  134. #define MACE_MAX_RX_ITERATIONS 12
  135. /*
  136. TBD: Dean brought this up, and I assumed the hardware would
  137. handle it:
  138. If MACE_MAX_RX_ITERATIONS is > 1, rx_framecnt may still be
  139. non-zero when the isr exits. We may not get another interrupt
  140. to process the remaining packets for some time.
  141. */
  142. /*
  143. The Am2150 has a Xilinx XC3042 field programmable gate array (FPGA)
  144. which manages the interface between the MACE and the PCMCIA bus. It
  145. also includes buffer management for the 32K x 8 SRAM to control up to
  146. four transmit and 12 receive frames at a time.
  147. */
  148. #define AM2150_MAX_TX_FRAMES 4
  149. #define AM2150_MAX_RX_FRAMES 12
  150. /* Am2150 Ethernet Card I/O Mapping */
  151. #define AM2150_RCV 0x00
  152. #define AM2150_XMT 0x04
  153. #define AM2150_XMT_SKIP 0x09
  154. #define AM2150_RCV_NEXT 0x0A
  155. #define AM2150_RCV_FRAME_COUNT 0x0B
  156. #define AM2150_MACE_BANK 0x0C
  157. #define AM2150_MACE_BASE 0x10
  158. /* MACE Registers */
  159. #define MACE_RCVFIFO 0
  160. #define MACE_XMTFIFO 1
  161. #define MACE_XMTFC 2
  162. #define MACE_XMTFS 3
  163. #define MACE_XMTRC 4
  164. #define MACE_RCVFC 5
  165. #define MACE_RCVFS 6
  166. #define MACE_FIFOFC 7
  167. #define MACE_IR 8
  168. #define MACE_IMR 9
  169. #define MACE_PR 10
  170. #define MACE_BIUCC 11
  171. #define MACE_FIFOCC 12
  172. #define MACE_MACCC 13
  173. #define MACE_PLSCC 14
  174. #define MACE_PHYCC 15
  175. #define MACE_CHIPIDL 16
  176. #define MACE_CHIPIDH 17
  177. #define MACE_IAC 18
  178. /* Reserved */
  179. #define MACE_LADRF 20
  180. #define MACE_PADR 21
  181. /* Reserved */
  182. /* Reserved */
  183. #define MACE_MPC 24
  184. /* Reserved */
  185. #define MACE_RNTPC 26
  186. #define MACE_RCVCC 27
  187. /* Reserved */
  188. #define MACE_UTR 29
  189. #define MACE_RTR1 30
  190. #define MACE_RTR2 31
  191. /* MACE Bit Masks */
  192. #define MACE_XMTRC_EXDEF 0x80
  193. #define MACE_XMTRC_XMTRC 0x0F
  194. #define MACE_XMTFS_XMTSV 0x80
  195. #define MACE_XMTFS_UFLO 0x40
  196. #define MACE_XMTFS_LCOL 0x20
  197. #define MACE_XMTFS_MORE 0x10
  198. #define MACE_XMTFS_ONE 0x08
  199. #define MACE_XMTFS_DEFER 0x04
  200. #define MACE_XMTFS_LCAR 0x02
  201. #define MACE_XMTFS_RTRY 0x01
  202. #define MACE_RCVFS_RCVSTS 0xF000
  203. #define MACE_RCVFS_OFLO 0x8000
  204. #define MACE_RCVFS_CLSN 0x4000
  205. #define MACE_RCVFS_FRAM 0x2000
  206. #define MACE_RCVFS_FCS 0x1000
  207. #define MACE_FIFOFC_RCVFC 0xF0
  208. #define MACE_FIFOFC_XMTFC 0x0F
  209. #define MACE_IR_JAB 0x80
  210. #define MACE_IR_BABL 0x40
  211. #define MACE_IR_CERR 0x20
  212. #define MACE_IR_RCVCCO 0x10
  213. #define MACE_IR_RNTPCO 0x08
  214. #define MACE_IR_MPCO 0x04
  215. #define MACE_IR_RCVINT 0x02
  216. #define MACE_IR_XMTINT 0x01
  217. #define MACE_MACCC_PROM 0x80
  218. #define MACE_MACCC_DXMT2PD 0x40
  219. #define MACE_MACCC_EMBA 0x20
  220. #define MACE_MACCC_RESERVED 0x10
  221. #define MACE_MACCC_DRCVPA 0x08
  222. #define MACE_MACCC_DRCVBC 0x04
  223. #define MACE_MACCC_ENXMT 0x02
  224. #define MACE_MACCC_ENRCV 0x01
  225. #define MACE_PHYCC_LNKFL 0x80
  226. #define MACE_PHYCC_DLNKTST 0x40
  227. #define MACE_PHYCC_REVPOL 0x20
  228. #define MACE_PHYCC_DAPC 0x10
  229. #define MACE_PHYCC_LRT 0x08
  230. #define MACE_PHYCC_ASEL 0x04
  231. #define MACE_PHYCC_RWAKE 0x02
  232. #define MACE_PHYCC_AWAKE 0x01
  233. #define MACE_IAC_ADDRCHG 0x80
  234. #define MACE_IAC_PHYADDR 0x04
  235. #define MACE_IAC_LOGADDR 0x02
  236. #define MACE_UTR_RTRE 0x80
  237. #define MACE_UTR_RTRD 0x40
  238. #define MACE_UTR_RPA 0x20
  239. #define MACE_UTR_FCOLL 0x10
  240. #define MACE_UTR_RCVFCSE 0x08
  241. #define MACE_UTR_LOOP_INCL_MENDEC 0x06
  242. #define MACE_UTR_LOOP_NO_MENDEC 0x04
  243. #define MACE_UTR_LOOP_EXTERNAL 0x02
  244. #define MACE_UTR_LOOP_NONE 0x00
  245. #define MACE_UTR_RESERVED 0x01
  246. /* Switch MACE register bank (only 0 and 1 are valid) */
  247. #define MACEBANK(win_num) outb((win_num), ioaddr + AM2150_MACE_BANK)
  248. #define MACE_IMR_DEFAULT \
  249. (0xFF - \
  250. ( \
  251. MACE_IR_CERR | \
  252. MACE_IR_RCVCCO | \
  253. MACE_IR_RNTPCO | \
  254. MACE_IR_MPCO | \
  255. MACE_IR_RCVINT | \
  256. MACE_IR_XMTINT \
  257. ) \
  258. )
  259. #undef MACE_IMR_DEFAULT
  260. #define MACE_IMR_DEFAULT 0x00 /* New statistics handling: grab everything */
  261. #define TX_TIMEOUT ((400*HZ)/1000)
  262. /* ----------------------------------------------------------------------------
  263. Type Definitions
  264. ---------------------------------------------------------------------------- */
  265. typedef struct _mace_statistics {
  266. /* MACE_XMTFS */
  267. int xmtsv;
  268. int uflo;
  269. int lcol;
  270. int more;
  271. int one;
  272. int defer;
  273. int lcar;
  274. int rtry;
  275. /* MACE_XMTRC */
  276. int exdef;
  277. int xmtrc;
  278. /* RFS1--Receive Status (RCVSTS) */
  279. int oflo;
  280. int clsn;
  281. int fram;
  282. int fcs;
  283. /* RFS2--Runt Packet Count (RNTPC) */
  284. int rfs_rntpc;
  285. /* RFS3--Receive Collision Count (RCVCC) */
  286. int rfs_rcvcc;
  287. /* MACE_IR */
  288. int jab;
  289. int babl;
  290. int cerr;
  291. int rcvcco;
  292. int rntpco;
  293. int mpco;
  294. /* MACE_MPC */
  295. int mpc;
  296. /* MACE_RNTPC */
  297. int rntpc;
  298. /* MACE_RCVCC */
  299. int rcvcc;
  300. } mace_statistics;
  301. typedef struct _mace_private {
  302. struct pcmcia_device *p_dev;
  303. mace_statistics mace_stats; /* MACE chip statistics counters */
  304. /* restore_multicast_list() state variables */
  305. int multicast_ladrf[MACE_LADRF_LEN]; /* Logical address filter */
  306. int multicast_num_addrs;
  307. char tx_free_frames; /* Number of free transmit frame buffers */
  308. char tx_irq_disabled; /* MACE TX interrupt disabled */
  309. spinlock_t bank_lock; /* Must be held if you step off bank 0 */
  310. } mace_private;
  311. /* ----------------------------------------------------------------------------
  312. Private Global Variables
  313. ---------------------------------------------------------------------------- */
  314. static const char *if_names[]={
  315. "Auto", "10baseT", "BNC",
  316. };
  317. /* ----------------------------------------------------------------------------
  318. Parameters
  319. These are the parameters that can be set during loading with
  320. 'insmod'.
  321. ---------------------------------------------------------------------------- */
  322. MODULE_DESCRIPTION("New Media PCMCIA ethernet driver");
  323. MODULE_LICENSE("GPL");
  324. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  325. /* 0=auto, 1=10baseT, 2 = 10base2, default=auto */
  326. INT_MODULE_PARM(if_port, 0);
  327. /* ----------------------------------------------------------------------------
  328. Function Prototypes
  329. ---------------------------------------------------------------------------- */
  330. static int nmclan_config(struct pcmcia_device *link);
  331. static void nmclan_release(struct pcmcia_device *link);
  332. static void nmclan_reset(struct net_device *dev);
  333. static int mace_config(struct net_device *dev, struct ifmap *map);
  334. static int mace_open(struct net_device *dev);
  335. static int mace_close(struct net_device *dev);
  336. static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
  337. struct net_device *dev);
  338. static void mace_tx_timeout(struct net_device *dev);
  339. static irqreturn_t mace_interrupt(int irq, void *dev_id);
  340. static struct net_device_stats *mace_get_stats(struct net_device *dev);
  341. static int mace_rx(struct net_device *dev, unsigned char RxCnt);
  342. static void restore_multicast_list(struct net_device *dev);
  343. static void set_multicast_list(struct net_device *dev);
  344. static const struct ethtool_ops netdev_ethtool_ops;
  345. static void nmclan_detach(struct pcmcia_device *p_dev);
  346. static const struct net_device_ops mace_netdev_ops = {
  347. .ndo_open = mace_open,
  348. .ndo_stop = mace_close,
  349. .ndo_start_xmit = mace_start_xmit,
  350. .ndo_tx_timeout = mace_tx_timeout,
  351. .ndo_set_config = mace_config,
  352. .ndo_get_stats = mace_get_stats,
  353. .ndo_set_rx_mode = set_multicast_list,
  354. .ndo_set_mac_address = eth_mac_addr,
  355. .ndo_validate_addr = eth_validate_addr,
  356. };
  357. static int nmclan_probe(struct pcmcia_device *link)
  358. {
  359. mace_private *lp;
  360. struct net_device *dev;
  361. dev_dbg(&link->dev, "nmclan_attach()\n");
  362. /* Create new ethernet device */
  363. dev = alloc_etherdev(sizeof(mace_private));
  364. if (!dev)
  365. return -ENOMEM;
  366. lp = netdev_priv(dev);
  367. lp->p_dev = link;
  368. link->priv = dev;
  369. spin_lock_init(&lp->bank_lock);
  370. link->resource[0]->end = 32;
  371. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  372. link->config_flags |= CONF_ENABLE_IRQ;
  373. link->config_index = 1;
  374. link->config_regs = PRESENT_OPTION;
  375. lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
  376. dev->netdev_ops = &mace_netdev_ops;
  377. dev->ethtool_ops = &netdev_ethtool_ops;
  378. dev->watchdog_timeo = TX_TIMEOUT;
  379. return nmclan_config(link);
  380. } /* nmclan_attach */
  381. static void nmclan_detach(struct pcmcia_device *link)
  382. {
  383. struct net_device *dev = link->priv;
  384. dev_dbg(&link->dev, "nmclan_detach\n");
  385. unregister_netdev(dev);
  386. nmclan_release(link);
  387. free_netdev(dev);
  388. } /* nmclan_detach */
  389. /* ----------------------------------------------------------------------------
  390. mace_read
  391. Reads a MACE register. This is bank independent; however, the
  392. caller must ensure that this call is not interruptable. We are
  393. assuming that during normal operation, the MACE is always in
  394. bank 0.
  395. ---------------------------------------------------------------------------- */
  396. static int mace_read(mace_private *lp, unsigned int ioaddr, int reg)
  397. {
  398. int data = 0xFF;
  399. unsigned long flags;
  400. switch (reg >> 4) {
  401. case 0: /* register 0-15 */
  402. data = inb(ioaddr + AM2150_MACE_BASE + reg);
  403. break;
  404. case 1: /* register 16-31 */
  405. spin_lock_irqsave(&lp->bank_lock, flags);
  406. MACEBANK(1);
  407. data = inb(ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
  408. MACEBANK(0);
  409. spin_unlock_irqrestore(&lp->bank_lock, flags);
  410. break;
  411. }
  412. return data & 0xFF;
  413. } /* mace_read */
  414. /* ----------------------------------------------------------------------------
  415. mace_write
  416. Writes to a MACE register. This is bank independent; however,
  417. the caller must ensure that this call is not interruptable. We
  418. are assuming that during normal operation, the MACE is always in
  419. bank 0.
  420. ---------------------------------------------------------------------------- */
  421. static void mace_write(mace_private *lp, unsigned int ioaddr, int reg,
  422. int data)
  423. {
  424. unsigned long flags;
  425. switch (reg >> 4) {
  426. case 0: /* register 0-15 */
  427. outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + reg);
  428. break;
  429. case 1: /* register 16-31 */
  430. spin_lock_irqsave(&lp->bank_lock, flags);
  431. MACEBANK(1);
  432. outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
  433. MACEBANK(0);
  434. spin_unlock_irqrestore(&lp->bank_lock, flags);
  435. break;
  436. }
  437. } /* mace_write */
  438. /* ----------------------------------------------------------------------------
  439. mace_init
  440. Resets the MACE chip.
  441. ---------------------------------------------------------------------------- */
  442. static int mace_init(mace_private *lp, unsigned int ioaddr, char *enet_addr)
  443. {
  444. int i;
  445. int ct = 0;
  446. /* MACE Software reset */
  447. mace_write(lp, ioaddr, MACE_BIUCC, 1);
  448. while (mace_read(lp, ioaddr, MACE_BIUCC) & 0x01) {
  449. /* Wait for reset bit to be cleared automatically after <= 200ns */;
  450. if(++ct > 500)
  451. {
  452. pr_err("reset failed, card removed?\n");
  453. return -1;
  454. }
  455. udelay(1);
  456. }
  457. mace_write(lp, ioaddr, MACE_BIUCC, 0);
  458. /* The Am2150 requires that the MACE FIFOs operate in burst mode. */
  459. mace_write(lp, ioaddr, MACE_FIFOCC, 0x0F);
  460. mace_write(lp,ioaddr, MACE_RCVFC, 0); /* Disable Auto Strip Receive */
  461. mace_write(lp, ioaddr, MACE_IMR, 0xFF); /* Disable all interrupts until _open */
  462. /*
  463. * Bit 2-1 PORTSEL[1-0] Port Select.
  464. * 00 AUI/10Base-2
  465. * 01 10Base-T
  466. * 10 DAI Port (reserved in Am2150)
  467. * 11 GPSI
  468. * For this card, only the first two are valid.
  469. * So, PLSCC should be set to
  470. * 0x00 for 10Base-2
  471. * 0x02 for 10Base-T
  472. * Or just set ASEL in PHYCC below!
  473. */
  474. switch (if_port) {
  475. case 1:
  476. mace_write(lp, ioaddr, MACE_PLSCC, 0x02);
  477. break;
  478. case 2:
  479. mace_write(lp, ioaddr, MACE_PLSCC, 0x00);
  480. break;
  481. default:
  482. mace_write(lp, ioaddr, MACE_PHYCC, /* ASEL */ 4);
  483. /* ASEL Auto Select. When set, the PORTSEL[1-0] bits are overridden,
  484. and the MACE device will automatically select the operating media
  485. interface port. */
  486. break;
  487. }
  488. mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_PHYADDR);
  489. /* Poll ADDRCHG bit */
  490. ct = 0;
  491. while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
  492. {
  493. if(++ ct > 500)
  494. {
  495. pr_err("ADDRCHG timeout, card removed?\n");
  496. return -1;
  497. }
  498. }
  499. /* Set PADR register */
  500. for (i = 0; i < ETH_ALEN; i++)
  501. mace_write(lp, ioaddr, MACE_PADR, enet_addr[i]);
  502. /* MAC Configuration Control Register should be written last */
  503. /* Let set_multicast_list set this. */
  504. /* mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV); */
  505. mace_write(lp, ioaddr, MACE_MACCC, 0x00);
  506. return 0;
  507. } /* mace_init */
  508. static int nmclan_config(struct pcmcia_device *link)
  509. {
  510. struct net_device *dev = link->priv;
  511. mace_private *lp = netdev_priv(dev);
  512. u8 *buf;
  513. size_t len;
  514. int i, ret;
  515. unsigned int ioaddr;
  516. dev_dbg(&link->dev, "nmclan_config\n");
  517. link->io_lines = 5;
  518. ret = pcmcia_request_io(link);
  519. if (ret)
  520. goto failed;
  521. ret = pcmcia_request_irq(link, mace_interrupt);
  522. if (ret)
  523. goto failed;
  524. ret = pcmcia_enable_device(link);
  525. if (ret)
  526. goto failed;
  527. dev->irq = link->irq;
  528. dev->base_addr = link->resource[0]->start;
  529. ioaddr = dev->base_addr;
  530. /* Read the ethernet address from the CIS. */
  531. len = pcmcia_get_tuple(link, 0x80, &buf);
  532. if (!buf || len < ETH_ALEN) {
  533. kfree(buf);
  534. goto failed;
  535. }
  536. memcpy(dev->dev_addr, buf, ETH_ALEN);
  537. kfree(buf);
  538. /* Verify configuration by reading the MACE ID. */
  539. {
  540. char sig[2];
  541. sig[0] = mace_read(lp, ioaddr, MACE_CHIPIDL);
  542. sig[1] = mace_read(lp, ioaddr, MACE_CHIPIDH);
  543. if ((sig[0] == 0x40) && ((sig[1] & 0x0F) == 0x09)) {
  544. dev_dbg(&link->dev, "nmclan_cs configured: mace id=%x %x\n",
  545. sig[0], sig[1]);
  546. } else {
  547. pr_notice("mace id not found: %x %x should be 0x40 0x?9\n",
  548. sig[0], sig[1]);
  549. return -ENODEV;
  550. }
  551. }
  552. if(mace_init(lp, ioaddr, dev->dev_addr) == -1)
  553. goto failed;
  554. /* The if_port symbol can be set when the module is loaded */
  555. if (if_port <= 2)
  556. dev->if_port = if_port;
  557. else
  558. pr_notice("invalid if_port requested\n");
  559. SET_NETDEV_DEV(dev, &link->dev);
  560. i = register_netdev(dev);
  561. if (i != 0) {
  562. pr_notice("register_netdev() failed\n");
  563. goto failed;
  564. }
  565. netdev_info(dev, "nmclan: port %#3lx, irq %d, %s port, hw_addr %pM\n",
  566. dev->base_addr, dev->irq, if_names[dev->if_port], dev->dev_addr);
  567. return 0;
  568. failed:
  569. nmclan_release(link);
  570. return -ENODEV;
  571. } /* nmclan_config */
  572. static void nmclan_release(struct pcmcia_device *link)
  573. {
  574. dev_dbg(&link->dev, "nmclan_release\n");
  575. pcmcia_disable_device(link);
  576. }
  577. static int nmclan_suspend(struct pcmcia_device *link)
  578. {
  579. struct net_device *dev = link->priv;
  580. if (link->open)
  581. netif_device_detach(dev);
  582. return 0;
  583. }
  584. static int nmclan_resume(struct pcmcia_device *link)
  585. {
  586. struct net_device *dev = link->priv;
  587. if (link->open) {
  588. nmclan_reset(dev);
  589. netif_device_attach(dev);
  590. }
  591. return 0;
  592. }
  593. /* ----------------------------------------------------------------------------
  594. nmclan_reset
  595. Reset and restore all of the Xilinx and MACE registers.
  596. ---------------------------------------------------------------------------- */
  597. static void nmclan_reset(struct net_device *dev)
  598. {
  599. mace_private *lp = netdev_priv(dev);
  600. #if RESET_XILINX
  601. struct pcmcia_device *link = &lp->link;
  602. u8 OrigCorValue;
  603. /* Save original COR value */
  604. pcmcia_read_config_byte(link, CISREG_COR, &OrigCorValue);
  605. /* Reset Xilinx */
  606. dev_dbg(&link->dev, "nmclan_reset: OrigCorValue=0x%x, resetting...\n",
  607. OrigCorValue);
  608. pcmcia_write_config_byte(link, CISREG_COR, COR_SOFT_RESET);
  609. /* Need to wait for 20 ms for PCMCIA to finish reset. */
  610. /* Restore original COR configuration index */
  611. pcmcia_write_config_byte(link, CISREG_COR,
  612. (COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK)));
  613. /* Xilinx is now completely reset along with the MACE chip. */
  614. lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
  615. #endif /* #if RESET_XILINX */
  616. /* Xilinx is now completely reset along with the MACE chip. */
  617. lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
  618. /* Reinitialize the MACE chip for operation. */
  619. mace_init(lp, dev->base_addr, dev->dev_addr);
  620. mace_write(lp, dev->base_addr, MACE_IMR, MACE_IMR_DEFAULT);
  621. /* Restore the multicast list and enable TX and RX. */
  622. restore_multicast_list(dev);
  623. } /* nmclan_reset */
  624. /* ----------------------------------------------------------------------------
  625. mace_config
  626. [Someone tell me what this is supposed to do? Is if_port a defined
  627. standard? If so, there should be defines to indicate 1=10Base-T,
  628. 2=10Base-2, etc. including limited automatic detection.]
  629. ---------------------------------------------------------------------------- */
  630. static int mace_config(struct net_device *dev, struct ifmap *map)
  631. {
  632. if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
  633. if (map->port <= 2) {
  634. dev->if_port = map->port;
  635. netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
  636. } else
  637. return -EINVAL;
  638. }
  639. return 0;
  640. } /* mace_config */
  641. /* ----------------------------------------------------------------------------
  642. mace_open
  643. Open device driver.
  644. ---------------------------------------------------------------------------- */
  645. static int mace_open(struct net_device *dev)
  646. {
  647. unsigned int ioaddr = dev->base_addr;
  648. mace_private *lp = netdev_priv(dev);
  649. struct pcmcia_device *link = lp->p_dev;
  650. if (!pcmcia_dev_present(link))
  651. return -ENODEV;
  652. link->open++;
  653. MACEBANK(0);
  654. netif_start_queue(dev);
  655. nmclan_reset(dev);
  656. return 0; /* Always succeed */
  657. } /* mace_open */
  658. /* ----------------------------------------------------------------------------
  659. mace_close
  660. Closes device driver.
  661. ---------------------------------------------------------------------------- */
  662. static int mace_close(struct net_device *dev)
  663. {
  664. unsigned int ioaddr = dev->base_addr;
  665. mace_private *lp = netdev_priv(dev);
  666. struct pcmcia_device *link = lp->p_dev;
  667. dev_dbg(&link->dev, "%s: shutting down ethercard.\n", dev->name);
  668. /* Mask off all interrupts from the MACE chip. */
  669. outb(0xFF, ioaddr + AM2150_MACE_BASE + MACE_IMR);
  670. link->open--;
  671. netif_stop_queue(dev);
  672. return 0;
  673. } /* mace_close */
  674. static void netdev_get_drvinfo(struct net_device *dev,
  675. struct ethtool_drvinfo *info)
  676. {
  677. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  678. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  679. snprintf(info->bus_info, sizeof(info->bus_info),
  680. "PCMCIA 0x%lx", dev->base_addr);
  681. }
  682. static const struct ethtool_ops netdev_ethtool_ops = {
  683. .get_drvinfo = netdev_get_drvinfo,
  684. };
  685. /* ----------------------------------------------------------------------------
  686. mace_start_xmit
  687. This routine begins the packet transmit function. When completed,
  688. it will generate a transmit interrupt.
  689. According to /usr/src/linux/net/inet/dev.c, if _start_xmit
  690. returns 0, the "packet is now solely the responsibility of the
  691. driver." If _start_xmit returns non-zero, the "transmission
  692. failed, put skb back into a list."
  693. ---------------------------------------------------------------------------- */
  694. static void mace_tx_timeout(struct net_device *dev)
  695. {
  696. mace_private *lp = netdev_priv(dev);
  697. struct pcmcia_device *link = lp->p_dev;
  698. netdev_notice(dev, "transmit timed out -- ");
  699. #if RESET_ON_TIMEOUT
  700. pr_cont("resetting card\n");
  701. pcmcia_reset_card(link->socket);
  702. #else /* #if RESET_ON_TIMEOUT */
  703. pr_cont("NOT resetting card\n");
  704. #endif /* #if RESET_ON_TIMEOUT */
  705. netif_trans_update(dev); /* prevent tx timeout */
  706. netif_wake_queue(dev);
  707. }
  708. static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
  709. struct net_device *dev)
  710. {
  711. mace_private *lp = netdev_priv(dev);
  712. unsigned int ioaddr = dev->base_addr;
  713. netif_stop_queue(dev);
  714. pr_debug("%s: mace_start_xmit(length = %ld) called.\n",
  715. dev->name, (long)skb->len);
  716. #if (!TX_INTERRUPTABLE)
  717. /* Disable MACE TX interrupts. */
  718. outb(MACE_IMR_DEFAULT | MACE_IR_XMTINT,
  719. ioaddr + AM2150_MACE_BASE + MACE_IMR);
  720. lp->tx_irq_disabled=1;
  721. #endif /* #if (!TX_INTERRUPTABLE) */
  722. {
  723. /* This block must not be interrupted by another transmit request!
  724. mace_tx_timeout will take care of timer-based retransmissions from
  725. the upper layers. The interrupt handler is guaranteed never to
  726. service a transmit interrupt while we are in here.
  727. */
  728. dev->stats.tx_bytes += skb->len;
  729. lp->tx_free_frames--;
  730. /* WARNING: Write the _exact_ number of bytes written in the header! */
  731. /* Put out the word header [must be an outw()] . . . */
  732. outw(skb->len, ioaddr + AM2150_XMT);
  733. /* . . . and the packet [may be any combination of outw() and outb()] */
  734. outsw(ioaddr + AM2150_XMT, skb->data, skb->len >> 1);
  735. if (skb->len & 1) {
  736. /* Odd byte transfer */
  737. outb(skb->data[skb->len-1], ioaddr + AM2150_XMT);
  738. }
  739. #if MULTI_TX
  740. if (lp->tx_free_frames > 0)
  741. netif_start_queue(dev);
  742. #endif /* #if MULTI_TX */
  743. }
  744. #if (!TX_INTERRUPTABLE)
  745. /* Re-enable MACE TX interrupts. */
  746. lp->tx_irq_disabled=0;
  747. outb(MACE_IMR_DEFAULT, ioaddr + AM2150_MACE_BASE + MACE_IMR);
  748. #endif /* #if (!TX_INTERRUPTABLE) */
  749. dev_kfree_skb(skb);
  750. return NETDEV_TX_OK;
  751. } /* mace_start_xmit */
  752. /* ----------------------------------------------------------------------------
  753. mace_interrupt
  754. The interrupt handler.
  755. ---------------------------------------------------------------------------- */
  756. static irqreturn_t mace_interrupt(int irq, void *dev_id)
  757. {
  758. struct net_device *dev = (struct net_device *) dev_id;
  759. mace_private *lp = netdev_priv(dev);
  760. unsigned int ioaddr;
  761. int status;
  762. int IntrCnt = MACE_MAX_IR_ITERATIONS;
  763. if (dev == NULL) {
  764. pr_debug("mace_interrupt(): irq 0x%X for unknown device.\n",
  765. irq);
  766. return IRQ_NONE;
  767. }
  768. ioaddr = dev->base_addr;
  769. if (lp->tx_irq_disabled) {
  770. const char *msg;
  771. if (lp->tx_irq_disabled)
  772. msg = "Interrupt with tx_irq_disabled";
  773. else
  774. msg = "Re-entering the interrupt handler";
  775. netdev_notice(dev, "%s [isr=%02X, imr=%02X]\n",
  776. msg,
  777. inb(ioaddr + AM2150_MACE_BASE + MACE_IR),
  778. inb(ioaddr + AM2150_MACE_BASE + MACE_IMR));
  779. /* WARNING: MACE_IR has been read! */
  780. return IRQ_NONE;
  781. }
  782. if (!netif_device_present(dev)) {
  783. netdev_dbg(dev, "interrupt from dead card\n");
  784. return IRQ_NONE;
  785. }
  786. do {
  787. /* WARNING: MACE_IR is a READ/CLEAR port! */
  788. status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR);
  789. if (!(status & ~MACE_IMR_DEFAULT) && IntrCnt == MACE_MAX_IR_ITERATIONS)
  790. return IRQ_NONE;
  791. pr_debug("mace_interrupt: irq 0x%X status 0x%X.\n", irq, status);
  792. if (status & MACE_IR_RCVINT) {
  793. mace_rx(dev, MACE_MAX_RX_ITERATIONS);
  794. }
  795. if (status & MACE_IR_XMTINT) {
  796. unsigned char fifofc;
  797. unsigned char xmtrc;
  798. unsigned char xmtfs;
  799. fifofc = inb(ioaddr + AM2150_MACE_BASE + MACE_FIFOFC);
  800. if ((fifofc & MACE_FIFOFC_XMTFC)==0) {
  801. dev->stats.tx_errors++;
  802. outb(0xFF, ioaddr + AM2150_XMT_SKIP);
  803. }
  804. /* Transmit Retry Count (XMTRC, reg 4) */
  805. xmtrc = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTRC);
  806. if (xmtrc & MACE_XMTRC_EXDEF) lp->mace_stats.exdef++;
  807. lp->mace_stats.xmtrc += (xmtrc & MACE_XMTRC_XMTRC);
  808. if (
  809. (xmtfs = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTFS)) &
  810. MACE_XMTFS_XMTSV /* Transmit Status Valid */
  811. ) {
  812. lp->mace_stats.xmtsv++;
  813. if (xmtfs & ~MACE_XMTFS_XMTSV) {
  814. if (xmtfs & MACE_XMTFS_UFLO) {
  815. /* Underflow. Indicates that the Transmit FIFO emptied before
  816. the end of frame was reached. */
  817. lp->mace_stats.uflo++;
  818. }
  819. if (xmtfs & MACE_XMTFS_LCOL) {
  820. /* Late Collision */
  821. lp->mace_stats.lcol++;
  822. }
  823. if (xmtfs & MACE_XMTFS_MORE) {
  824. /* MORE than one retry was needed */
  825. lp->mace_stats.more++;
  826. }
  827. if (xmtfs & MACE_XMTFS_ONE) {
  828. /* Exactly ONE retry occurred */
  829. lp->mace_stats.one++;
  830. }
  831. if (xmtfs & MACE_XMTFS_DEFER) {
  832. /* Transmission was defered */
  833. lp->mace_stats.defer++;
  834. }
  835. if (xmtfs & MACE_XMTFS_LCAR) {
  836. /* Loss of carrier */
  837. lp->mace_stats.lcar++;
  838. }
  839. if (xmtfs & MACE_XMTFS_RTRY) {
  840. /* Retry error: transmit aborted after 16 attempts */
  841. lp->mace_stats.rtry++;
  842. }
  843. } /* if (xmtfs & ~MACE_XMTFS_XMTSV) */
  844. } /* if (xmtfs & MACE_XMTFS_XMTSV) */
  845. dev->stats.tx_packets++;
  846. lp->tx_free_frames++;
  847. netif_wake_queue(dev);
  848. } /* if (status & MACE_IR_XMTINT) */
  849. if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) {
  850. if (status & MACE_IR_JAB) {
  851. /* Jabber Error. Excessive transmit duration (20-150ms). */
  852. lp->mace_stats.jab++;
  853. }
  854. if (status & MACE_IR_BABL) {
  855. /* Babble Error. >1518 bytes transmitted. */
  856. lp->mace_stats.babl++;
  857. }
  858. if (status & MACE_IR_CERR) {
  859. /* Collision Error. CERR indicates the absence of the
  860. Signal Quality Error Test message after a packet
  861. transmission. */
  862. lp->mace_stats.cerr++;
  863. }
  864. if (status & MACE_IR_RCVCCO) {
  865. /* Receive Collision Count Overflow; */
  866. lp->mace_stats.rcvcco++;
  867. }
  868. if (status & MACE_IR_RNTPCO) {
  869. /* Runt Packet Count Overflow */
  870. lp->mace_stats.rntpco++;
  871. }
  872. if (status & MACE_IR_MPCO) {
  873. /* Missed Packet Count Overflow */
  874. lp->mace_stats.mpco++;
  875. }
  876. } /* if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) */
  877. } while ((status & ~MACE_IMR_DEFAULT) && (--IntrCnt));
  878. return IRQ_HANDLED;
  879. } /* mace_interrupt */
  880. /* ----------------------------------------------------------------------------
  881. mace_rx
  882. Receives packets.
  883. ---------------------------------------------------------------------------- */
  884. static int mace_rx(struct net_device *dev, unsigned char RxCnt)
  885. {
  886. mace_private *lp = netdev_priv(dev);
  887. unsigned int ioaddr = dev->base_addr;
  888. unsigned char rx_framecnt;
  889. unsigned short rx_status;
  890. while (
  891. ((rx_framecnt = inb(ioaddr + AM2150_RCV_FRAME_COUNT)) > 0) &&
  892. (rx_framecnt <= 12) && /* rx_framecnt==0xFF if card is extracted. */
  893. (RxCnt--)
  894. ) {
  895. rx_status = inw(ioaddr + AM2150_RCV);
  896. pr_debug("%s: in mace_rx(), framecnt 0x%X, rx_status"
  897. " 0x%X.\n", dev->name, rx_framecnt, rx_status);
  898. if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */
  899. dev->stats.rx_errors++;
  900. if (rx_status & MACE_RCVFS_OFLO) {
  901. lp->mace_stats.oflo++;
  902. }
  903. if (rx_status & MACE_RCVFS_CLSN) {
  904. lp->mace_stats.clsn++;
  905. }
  906. if (rx_status & MACE_RCVFS_FRAM) {
  907. lp->mace_stats.fram++;
  908. }
  909. if (rx_status & MACE_RCVFS_FCS) {
  910. lp->mace_stats.fcs++;
  911. }
  912. } else {
  913. short pkt_len = (rx_status & ~MACE_RCVFS_RCVSTS) - 4;
  914. /* Auto Strip is off, always subtract 4 */
  915. struct sk_buff *skb;
  916. lp->mace_stats.rfs_rntpc += inb(ioaddr + AM2150_RCV);
  917. /* runt packet count */
  918. lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV);
  919. /* rcv collision count */
  920. pr_debug(" receiving packet size 0x%X rx_status"
  921. " 0x%X.\n", pkt_len, rx_status);
  922. skb = netdev_alloc_skb(dev, pkt_len + 2);
  923. if (skb != NULL) {
  924. skb_reserve(skb, 2);
  925. insw(ioaddr + AM2150_RCV, skb_put(skb, pkt_len), pkt_len>>1);
  926. if (pkt_len & 1)
  927. *(skb_tail_pointer(skb) - 1) = inb(ioaddr + AM2150_RCV);
  928. skb->protocol = eth_type_trans(skb, dev);
  929. netif_rx(skb); /* Send the packet to the upper (protocol) layers. */
  930. dev->stats.rx_packets++;
  931. dev->stats.rx_bytes += pkt_len;
  932. outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
  933. continue;
  934. } else {
  935. pr_debug("%s: couldn't allocate a sk_buff of size"
  936. " %d.\n", dev->name, pkt_len);
  937. dev->stats.rx_dropped++;
  938. }
  939. }
  940. outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
  941. } /* while */
  942. return 0;
  943. } /* mace_rx */
  944. /* ----------------------------------------------------------------------------
  945. pr_linux_stats
  946. ---------------------------------------------------------------------------- */
  947. static void pr_linux_stats(struct net_device_stats *pstats)
  948. {
  949. pr_debug("pr_linux_stats\n");
  950. pr_debug(" rx_packets=%-7ld tx_packets=%ld\n",
  951. (long)pstats->rx_packets, (long)pstats->tx_packets);
  952. pr_debug(" rx_errors=%-7ld tx_errors=%ld\n",
  953. (long)pstats->rx_errors, (long)pstats->tx_errors);
  954. pr_debug(" rx_dropped=%-7ld tx_dropped=%ld\n",
  955. (long)pstats->rx_dropped, (long)pstats->tx_dropped);
  956. pr_debug(" multicast=%-7ld collisions=%ld\n",
  957. (long)pstats->multicast, (long)pstats->collisions);
  958. pr_debug(" rx_length_errors=%-7ld rx_over_errors=%ld\n",
  959. (long)pstats->rx_length_errors, (long)pstats->rx_over_errors);
  960. pr_debug(" rx_crc_errors=%-7ld rx_frame_errors=%ld\n",
  961. (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors);
  962. pr_debug(" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n",
  963. (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors);
  964. pr_debug(" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n",
  965. (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors);
  966. pr_debug(" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n",
  967. (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors);
  968. pr_debug(" tx_window_errors=%ld\n",
  969. (long)pstats->tx_window_errors);
  970. } /* pr_linux_stats */
  971. /* ----------------------------------------------------------------------------
  972. pr_mace_stats
  973. ---------------------------------------------------------------------------- */
  974. static void pr_mace_stats(mace_statistics *pstats)
  975. {
  976. pr_debug("pr_mace_stats\n");
  977. pr_debug(" xmtsv=%-7d uflo=%d\n",
  978. pstats->xmtsv, pstats->uflo);
  979. pr_debug(" lcol=%-7d more=%d\n",
  980. pstats->lcol, pstats->more);
  981. pr_debug(" one=%-7d defer=%d\n",
  982. pstats->one, pstats->defer);
  983. pr_debug(" lcar=%-7d rtry=%d\n",
  984. pstats->lcar, pstats->rtry);
  985. /* MACE_XMTRC */
  986. pr_debug(" exdef=%-7d xmtrc=%d\n",
  987. pstats->exdef, pstats->xmtrc);
  988. /* RFS1--Receive Status (RCVSTS) */
  989. pr_debug(" oflo=%-7d clsn=%d\n",
  990. pstats->oflo, pstats->clsn);
  991. pr_debug(" fram=%-7d fcs=%d\n",
  992. pstats->fram, pstats->fcs);
  993. /* RFS2--Runt Packet Count (RNTPC) */
  994. /* RFS3--Receive Collision Count (RCVCC) */
  995. pr_debug(" rfs_rntpc=%-7d rfs_rcvcc=%d\n",
  996. pstats->rfs_rntpc, pstats->rfs_rcvcc);
  997. /* MACE_IR */
  998. pr_debug(" jab=%-7d babl=%d\n",
  999. pstats->jab, pstats->babl);
  1000. pr_debug(" cerr=%-7d rcvcco=%d\n",
  1001. pstats->cerr, pstats->rcvcco);
  1002. pr_debug(" rntpco=%-7d mpco=%d\n",
  1003. pstats->rntpco, pstats->mpco);
  1004. /* MACE_MPC */
  1005. pr_debug(" mpc=%d\n", pstats->mpc);
  1006. /* MACE_RNTPC */
  1007. pr_debug(" rntpc=%d\n", pstats->rntpc);
  1008. /* MACE_RCVCC */
  1009. pr_debug(" rcvcc=%d\n", pstats->rcvcc);
  1010. } /* pr_mace_stats */
  1011. /* ----------------------------------------------------------------------------
  1012. update_stats
  1013. Update statistics. We change to register window 1, so this
  1014. should be run single-threaded if the device is active. This is
  1015. expected to be a rare operation, and it's simpler for the rest
  1016. of the driver to assume that window 0 is always valid rather
  1017. than use a special window-state variable.
  1018. oflo & uflo should _never_ occur since it would mean the Xilinx
  1019. was not able to transfer data between the MACE FIFO and the
  1020. card's SRAM fast enough. If this happens, something is
  1021. seriously wrong with the hardware.
  1022. ---------------------------------------------------------------------------- */
  1023. static void update_stats(unsigned int ioaddr, struct net_device *dev)
  1024. {
  1025. mace_private *lp = netdev_priv(dev);
  1026. lp->mace_stats.rcvcc += mace_read(lp, ioaddr, MACE_RCVCC);
  1027. lp->mace_stats.rntpc += mace_read(lp, ioaddr, MACE_RNTPC);
  1028. lp->mace_stats.mpc += mace_read(lp, ioaddr, MACE_MPC);
  1029. /* At this point, mace_stats is fully updated for this call.
  1030. We may now update the netdev stats. */
  1031. /* The MACE has no equivalent for netdev stats field which are commented
  1032. out. */
  1033. /* dev->stats.multicast; */
  1034. dev->stats.collisions =
  1035. lp->mace_stats.rcvcco * 256 + lp->mace_stats.rcvcc;
  1036. /* Collision: The MACE may retry sending a packet 15 times
  1037. before giving up. The retry count is in XMTRC.
  1038. Does each retry constitute a collision?
  1039. If so, why doesn't the RCVCC record these collisions? */
  1040. /* detailed rx_errors: */
  1041. dev->stats.rx_length_errors =
  1042. lp->mace_stats.rntpco * 256 + lp->mace_stats.rntpc;
  1043. /* dev->stats.rx_over_errors */
  1044. dev->stats.rx_crc_errors = lp->mace_stats.fcs;
  1045. dev->stats.rx_frame_errors = lp->mace_stats.fram;
  1046. dev->stats.rx_fifo_errors = lp->mace_stats.oflo;
  1047. dev->stats.rx_missed_errors =
  1048. lp->mace_stats.mpco * 256 + lp->mace_stats.mpc;
  1049. /* detailed tx_errors */
  1050. dev->stats.tx_aborted_errors = lp->mace_stats.rtry;
  1051. dev->stats.tx_carrier_errors = lp->mace_stats.lcar;
  1052. /* LCAR usually results from bad cabling. */
  1053. dev->stats.tx_fifo_errors = lp->mace_stats.uflo;
  1054. dev->stats.tx_heartbeat_errors = lp->mace_stats.cerr;
  1055. /* dev->stats.tx_window_errors; */
  1056. } /* update_stats */
  1057. /* ----------------------------------------------------------------------------
  1058. mace_get_stats
  1059. Gathers ethernet statistics from the MACE chip.
  1060. ---------------------------------------------------------------------------- */
  1061. static struct net_device_stats *mace_get_stats(struct net_device *dev)
  1062. {
  1063. mace_private *lp = netdev_priv(dev);
  1064. update_stats(dev->base_addr, dev);
  1065. pr_debug("%s: updating the statistics.\n", dev->name);
  1066. pr_linux_stats(&dev->stats);
  1067. pr_mace_stats(&lp->mace_stats);
  1068. return &dev->stats;
  1069. } /* net_device_stats */
  1070. /* ----------------------------------------------------------------------------
  1071. updateCRC
  1072. Modified from Am79C90 data sheet.
  1073. ---------------------------------------------------------------------------- */
  1074. #ifdef BROKEN_MULTICAST
  1075. static void updateCRC(int *CRC, int bit)
  1076. {
  1077. static const int poly[]={
  1078. 1,1,1,0, 1,1,0,1,
  1079. 1,0,1,1, 1,0,0,0,
  1080. 1,0,0,0, 0,0,1,1,
  1081. 0,0,1,0, 0,0,0,0
  1082. }; /* CRC polynomial. poly[n] = coefficient of the x**n term of the
  1083. CRC generator polynomial. */
  1084. int j;
  1085. /* shift CRC and control bit (CRC[32]) */
  1086. for (j = 32; j > 0; j--)
  1087. CRC[j] = CRC[j-1];
  1088. CRC[0] = 0;
  1089. /* If bit XOR(control bit) = 1, set CRC = CRC XOR polynomial. */
  1090. if (bit ^ CRC[32])
  1091. for (j = 0; j < 32; j++)
  1092. CRC[j] ^= poly[j];
  1093. } /* updateCRC */
  1094. /* ----------------------------------------------------------------------------
  1095. BuildLAF
  1096. Build logical address filter.
  1097. Modified from Am79C90 data sheet.
  1098. Input
  1099. ladrf: logical address filter (contents initialized to 0)
  1100. adr: ethernet address
  1101. ---------------------------------------------------------------------------- */
  1102. static void BuildLAF(int *ladrf, int *adr)
  1103. {
  1104. int CRC[33]={1}; /* CRC register, 1 word/bit + extra control bit */
  1105. int i, byte; /* temporary array indices */
  1106. int hashcode; /* the output object */
  1107. CRC[32]=0;
  1108. for (byte = 0; byte < 6; byte++)
  1109. for (i = 0; i < 8; i++)
  1110. updateCRC(CRC, (adr[byte] >> i) & 1);
  1111. hashcode = 0;
  1112. for (i = 0; i < 6; i++)
  1113. hashcode = (hashcode << 1) + CRC[i];
  1114. byte = hashcode >> 3;
  1115. ladrf[byte] |= (1 << (hashcode & 7));
  1116. #ifdef PCMCIA_DEBUG
  1117. if (0)
  1118. printk(KERN_DEBUG " adr =%pM\n", adr);
  1119. printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode);
  1120. for (i = 0; i < 8; i++)
  1121. pr_cont(" %02X", ladrf[i]);
  1122. pr_cont("\n");
  1123. #endif
  1124. } /* BuildLAF */
  1125. /* ----------------------------------------------------------------------------
  1126. restore_multicast_list
  1127. Restores the multicast filter for MACE chip to the last
  1128. set_multicast_list() call.
  1129. Input
  1130. multicast_num_addrs
  1131. multicast_ladrf[]
  1132. ---------------------------------------------------------------------------- */
  1133. static void restore_multicast_list(struct net_device *dev)
  1134. {
  1135. mace_private *lp = netdev_priv(dev);
  1136. int num_addrs = lp->multicast_num_addrs;
  1137. int *ladrf = lp->multicast_ladrf;
  1138. unsigned int ioaddr = dev->base_addr;
  1139. int i;
  1140. pr_debug("%s: restoring Rx mode to %d addresses.\n",
  1141. dev->name, num_addrs);
  1142. if (num_addrs > 0) {
  1143. pr_debug("Attempt to restore multicast list detected.\n");
  1144. mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR);
  1145. /* Poll ADDRCHG bit */
  1146. while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
  1147. ;
  1148. /* Set LADRF register */
  1149. for (i = 0; i < MACE_LADRF_LEN; i++)
  1150. mace_write(lp, ioaddr, MACE_LADRF, ladrf[i]);
  1151. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_RCVFCSE | MACE_UTR_LOOP_EXTERNAL);
  1152. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1153. } else if (num_addrs < 0) {
  1154. /* Promiscuous mode: receive all packets */
  1155. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1156. mace_write(lp, ioaddr, MACE_MACCC,
  1157. MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
  1158. );
  1159. } else {
  1160. /* Normal mode */
  1161. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1162. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1163. }
  1164. } /* restore_multicast_list */
  1165. /* ----------------------------------------------------------------------------
  1166. set_multicast_list
  1167. Set or clear the multicast filter for this adaptor.
  1168. Input
  1169. num_addrs == -1 Promiscuous mode, receive all packets
  1170. num_addrs == 0 Normal mode, clear multicast list
  1171. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  1172. best-effort filtering.
  1173. Output
  1174. multicast_num_addrs
  1175. multicast_ladrf[]
  1176. ---------------------------------------------------------------------------- */
  1177. static void set_multicast_list(struct net_device *dev)
  1178. {
  1179. mace_private *lp = netdev_priv(dev);
  1180. int adr[ETH_ALEN] = {0}; /* Ethernet address */
  1181. struct netdev_hw_addr *ha;
  1182. #ifdef PCMCIA_DEBUG
  1183. {
  1184. static int old;
  1185. if (netdev_mc_count(dev) != old) {
  1186. old = netdev_mc_count(dev);
  1187. pr_debug("%s: setting Rx mode to %d addresses.\n",
  1188. dev->name, old);
  1189. }
  1190. }
  1191. #endif
  1192. /* Set multicast_num_addrs. */
  1193. lp->multicast_num_addrs = netdev_mc_count(dev);
  1194. /* Set multicast_ladrf. */
  1195. if (num_addrs > 0) {
  1196. /* Calculate multicast logical address filter */
  1197. memset(lp->multicast_ladrf, 0, MACE_LADRF_LEN);
  1198. netdev_for_each_mc_addr(ha, dev) {
  1199. memcpy(adr, ha->addr, ETH_ALEN);
  1200. BuildLAF(lp->multicast_ladrf, adr);
  1201. }
  1202. }
  1203. restore_multicast_list(dev);
  1204. } /* set_multicast_list */
  1205. #endif /* BROKEN_MULTICAST */
  1206. static void restore_multicast_list(struct net_device *dev)
  1207. {
  1208. unsigned int ioaddr = dev->base_addr;
  1209. mace_private *lp = netdev_priv(dev);
  1210. pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name,
  1211. lp->multicast_num_addrs);
  1212. if (dev->flags & IFF_PROMISC) {
  1213. /* Promiscuous mode: receive all packets */
  1214. mace_write(lp,ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1215. mace_write(lp, ioaddr, MACE_MACCC,
  1216. MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
  1217. );
  1218. } else {
  1219. /* Normal mode */
  1220. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1221. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1222. }
  1223. } /* restore_multicast_list */
  1224. static void set_multicast_list(struct net_device *dev)
  1225. {
  1226. mace_private *lp = netdev_priv(dev);
  1227. #ifdef PCMCIA_DEBUG
  1228. {
  1229. static int old;
  1230. if (netdev_mc_count(dev) != old) {
  1231. old = netdev_mc_count(dev);
  1232. pr_debug("%s: setting Rx mode to %d addresses.\n",
  1233. dev->name, old);
  1234. }
  1235. }
  1236. #endif
  1237. lp->multicast_num_addrs = netdev_mc_count(dev);
  1238. restore_multicast_list(dev);
  1239. } /* set_multicast_list */
  1240. static const struct pcmcia_device_id nmclan_ids[] = {
  1241. PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
  1242. PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet+", 0xebf1d60, 0xad673aaf),
  1243. PCMCIA_DEVICE_NULL,
  1244. };
  1245. MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
  1246. static struct pcmcia_driver nmclan_cs_driver = {
  1247. .owner = THIS_MODULE,
  1248. .name = "nmclan_cs",
  1249. .probe = nmclan_probe,
  1250. .remove = nmclan_detach,
  1251. .id_table = nmclan_ids,
  1252. .suspend = nmclan_suspend,
  1253. .resume = nmclan_resume,
  1254. };
  1255. module_pcmcia_driver(nmclan_cs_driver);