nmclan_cs.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  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 <[email protected]>
  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 <[email protected]>
  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. <[email protected]>
  24. Donald Becker <[email protected]>
  25. David Hinds <[email protected]>
  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 <[email protected]>
  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. /* ----------------------------------------------------------------------------
  96. Conditional Compilation Options
  97. ---------------------------------------------------------------------------- */
  98. #define MULTI_TX 0
  99. #define RESET_ON_TIMEOUT 1
  100. #define TX_INTERRUPTABLE 1
  101. #define RESET_XILINX 0
  102. /* ----------------------------------------------------------------------------
  103. Include Files
  104. ---------------------------------------------------------------------------- */
  105. #include <linux/module.h>
  106. #include <linux/kernel.h>
  107. #include <linux/ptrace.h>
  108. #include <linux/slab.h>
  109. #include <linux/string.h>
  110. #include <linux/timer.h>
  111. #include <linux/interrupt.h>
  112. #include <linux/in.h>
  113. #include <linux/delay.h>
  114. #include <linux/ethtool.h>
  115. #include <linux/netdevice.h>
  116. #include <linux/etherdevice.h>
  117. #include <linux/skbuff.h>
  118. #include <linux/if_arp.h>
  119. #include <linux/ioport.h>
  120. #include <linux/bitops.h>
  121. #include <pcmcia/cisreg.h>
  122. #include <pcmcia/cistpl.h>
  123. #include <pcmcia/ds.h>
  124. #include <linux/uaccess.h>
  125. #include <asm/io.h>
  126. /* ----------------------------------------------------------------------------
  127. Defines
  128. ---------------------------------------------------------------------------- */
  129. #define MACE_LADRF_LEN 8
  130. /* 8 bytes in Logical Address Filter */
  131. /* Loop Control Defines */
  132. #define MACE_MAX_IR_ITERATIONS 10
  133. #define MACE_MAX_RX_ITERATIONS 12
  134. /*
  135. TBD: Dean brought this up, and I assumed the hardware would
  136. handle it:
  137. If MACE_MAX_RX_ITERATIONS is > 1, rx_framecnt may still be
  138. non-zero when the isr exits. We may not get another interrupt
  139. to process the remaining packets for some time.
  140. */
  141. /*
  142. The Am2150 has a Xilinx XC3042 field programmable gate array (FPGA)
  143. which manages the interface between the MACE and the PCMCIA bus. It
  144. also includes buffer management for the 32K x 8 SRAM to control up to
  145. four transmit and 12 receive frames at a time.
  146. */
  147. #define AM2150_MAX_TX_FRAMES 4
  148. #define AM2150_MAX_RX_FRAMES 12
  149. /* Am2150 Ethernet Card I/O Mapping */
  150. #define AM2150_RCV 0x00
  151. #define AM2150_XMT 0x04
  152. #define AM2150_XMT_SKIP 0x09
  153. #define AM2150_RCV_NEXT 0x0A
  154. #define AM2150_RCV_FRAME_COUNT 0x0B
  155. #define AM2150_MACE_BANK 0x0C
  156. #define AM2150_MACE_BASE 0x10
  157. /* MACE Registers */
  158. #define MACE_RCVFIFO 0
  159. #define MACE_XMTFIFO 1
  160. #define MACE_XMTFC 2
  161. #define MACE_XMTFS 3
  162. #define MACE_XMTRC 4
  163. #define MACE_RCVFC 5
  164. #define MACE_RCVFS 6
  165. #define MACE_FIFOFC 7
  166. #define MACE_IR 8
  167. #define MACE_IMR 9
  168. #define MACE_PR 10
  169. #define MACE_BIUCC 11
  170. #define MACE_FIFOCC 12
  171. #define MACE_MACCC 13
  172. #define MACE_PLSCC 14
  173. #define MACE_PHYCC 15
  174. #define MACE_CHIPIDL 16
  175. #define MACE_CHIPIDH 17
  176. #define MACE_IAC 18
  177. /* Reserved */
  178. #define MACE_LADRF 20
  179. #define MACE_PADR 21
  180. /* Reserved */
  181. /* Reserved */
  182. #define MACE_MPC 24
  183. /* Reserved */
  184. #define MACE_RNTPC 26
  185. #define MACE_RCVCC 27
  186. /* Reserved */
  187. #define MACE_UTR 29
  188. #define MACE_RTR1 30
  189. #define MACE_RTR2 31
  190. /* MACE Bit Masks */
  191. #define MACE_XMTRC_EXDEF 0x80
  192. #define MACE_XMTRC_XMTRC 0x0F
  193. #define MACE_XMTFS_XMTSV 0x80
  194. #define MACE_XMTFS_UFLO 0x40
  195. #define MACE_XMTFS_LCOL 0x20
  196. #define MACE_XMTFS_MORE 0x10
  197. #define MACE_XMTFS_ONE 0x08
  198. #define MACE_XMTFS_DEFER 0x04
  199. #define MACE_XMTFS_LCAR 0x02
  200. #define MACE_XMTFS_RTRY 0x01
  201. #define MACE_RCVFS_RCVSTS 0xF000
  202. #define MACE_RCVFS_OFLO 0x8000
  203. #define MACE_RCVFS_CLSN 0x4000
  204. #define MACE_RCVFS_FRAM 0x2000
  205. #define MACE_RCVFS_FCS 0x1000
  206. #define MACE_FIFOFC_RCVFC 0xF0
  207. #define MACE_FIFOFC_XMTFC 0x0F
  208. #define MACE_IR_JAB 0x80
  209. #define MACE_IR_BABL 0x40
  210. #define MACE_IR_CERR 0x20
  211. #define MACE_IR_RCVCCO 0x10
  212. #define MACE_IR_RNTPCO 0x08
  213. #define MACE_IR_MPCO 0x04
  214. #define MACE_IR_RCVINT 0x02
  215. #define MACE_IR_XMTINT 0x01
  216. #define MACE_MACCC_PROM 0x80
  217. #define MACE_MACCC_DXMT2PD 0x40
  218. #define MACE_MACCC_EMBA 0x20
  219. #define MACE_MACCC_RESERVED 0x10
  220. #define MACE_MACCC_DRCVPA 0x08
  221. #define MACE_MACCC_DRCVBC 0x04
  222. #define MACE_MACCC_ENXMT 0x02
  223. #define MACE_MACCC_ENRCV 0x01
  224. #define MACE_PHYCC_LNKFL 0x80
  225. #define MACE_PHYCC_DLNKTST 0x40
  226. #define MACE_PHYCC_REVPOL 0x20
  227. #define MACE_PHYCC_DAPC 0x10
  228. #define MACE_PHYCC_LRT 0x08
  229. #define MACE_PHYCC_ASEL 0x04
  230. #define MACE_PHYCC_RWAKE 0x02
  231. #define MACE_PHYCC_AWAKE 0x01
  232. #define MACE_IAC_ADDRCHG 0x80
  233. #define MACE_IAC_PHYADDR 0x04
  234. #define MACE_IAC_LOGADDR 0x02
  235. #define MACE_UTR_RTRE 0x80
  236. #define MACE_UTR_RTRD 0x40
  237. #define MACE_UTR_RPA 0x20
  238. #define MACE_UTR_FCOLL 0x10
  239. #define MACE_UTR_RCVFCSE 0x08
  240. #define MACE_UTR_LOOP_INCL_MENDEC 0x06
  241. #define MACE_UTR_LOOP_NO_MENDEC 0x04
  242. #define MACE_UTR_LOOP_EXTERNAL 0x02
  243. #define MACE_UTR_LOOP_NONE 0x00
  244. #define MACE_UTR_RESERVED 0x01
  245. /* Switch MACE register bank (only 0 and 1 are valid) */
  246. #define MACEBANK(win_num) outb((win_num), ioaddr + AM2150_MACE_BANK)
  247. #define MACE_IMR_DEFAULT \
  248. (0xFF - \
  249. ( \
  250. MACE_IR_CERR | \
  251. MACE_IR_RCVCCO | \
  252. MACE_IR_RNTPCO | \
  253. MACE_IR_MPCO | \
  254. MACE_IR_RCVINT | \
  255. MACE_IR_XMTINT \
  256. ) \
  257. )
  258. #undef MACE_IMR_DEFAULT
  259. #define MACE_IMR_DEFAULT 0x00 /* New statistics handling: grab everything */
  260. #define TX_TIMEOUT ((400*HZ)/1000)
  261. /* ----------------------------------------------------------------------------
  262. Type Definitions
  263. ---------------------------------------------------------------------------- */
  264. typedef struct _mace_statistics {
  265. /* MACE_XMTFS */
  266. int xmtsv;
  267. int uflo;
  268. int lcol;
  269. int more;
  270. int one;
  271. int defer;
  272. int lcar;
  273. int rtry;
  274. /* MACE_XMTRC */
  275. int exdef;
  276. int xmtrc;
  277. /* RFS1--Receive Status (RCVSTS) */
  278. int oflo;
  279. int clsn;
  280. int fram;
  281. int fcs;
  282. /* RFS2--Runt Packet Count (RNTPC) */
  283. int rfs_rntpc;
  284. /* RFS3--Receive Collision Count (RCVCC) */
  285. int rfs_rcvcc;
  286. /* MACE_IR */
  287. int jab;
  288. int babl;
  289. int cerr;
  290. int rcvcco;
  291. int rntpco;
  292. int mpco;
  293. /* MACE_MPC */
  294. int mpc;
  295. /* MACE_RNTPC */
  296. int rntpc;
  297. /* MACE_RCVCC */
  298. int rcvcc;
  299. } mace_statistics;
  300. typedef struct _mace_private {
  301. struct pcmcia_device *p_dev;
  302. mace_statistics mace_stats; /* MACE chip statistics counters */
  303. /* restore_multicast_list() state variables */
  304. int multicast_ladrf[MACE_LADRF_LEN]; /* Logical address filter */
  305. int multicast_num_addrs;
  306. char tx_free_frames; /* Number of free transmit frame buffers */
  307. char tx_irq_disabled; /* MACE TX interrupt disabled */
  308. spinlock_t bank_lock; /* Must be held if you step off bank 0 */
  309. } mace_private;
  310. /* ----------------------------------------------------------------------------
  311. Private Global Variables
  312. ---------------------------------------------------------------------------- */
  313. static const char *if_names[]={
  314. "Auto", "10baseT", "BNC",
  315. };
  316. /* ----------------------------------------------------------------------------
  317. Parameters
  318. These are the parameters that can be set during loading with
  319. 'insmod'.
  320. ---------------------------------------------------------------------------- */
  321. MODULE_DESCRIPTION("New Media PCMCIA ethernet driver");
  322. MODULE_LICENSE("GPL");
  323. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  324. /* 0=auto, 1=10baseT, 2 = 10base2, default=auto */
  325. INT_MODULE_PARM(if_port, 0);
  326. /* ----------------------------------------------------------------------------
  327. Function Prototypes
  328. ---------------------------------------------------------------------------- */
  329. static int nmclan_config(struct pcmcia_device *link);
  330. static void nmclan_release(struct pcmcia_device *link);
  331. static void nmclan_reset(struct net_device *dev);
  332. static int mace_config(struct net_device *dev, struct ifmap *map);
  333. static int mace_open(struct net_device *dev);
  334. static int mace_close(struct net_device *dev);
  335. static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
  336. struct net_device *dev);
  337. static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue);
  338. static irqreturn_t mace_interrupt(int irq, void *dev_id);
  339. static struct net_device_stats *mace_get_stats(struct net_device *dev);
  340. static int mace_rx(struct net_device *dev, unsigned char RxCnt);
  341. static void restore_multicast_list(struct net_device *dev);
  342. static void set_multicast_list(struct net_device *dev);
  343. static const struct ethtool_ops netdev_ethtool_ops;
  344. static void nmclan_detach(struct pcmcia_device *p_dev);
  345. static const struct net_device_ops mace_netdev_ops = {
  346. .ndo_open = mace_open,
  347. .ndo_stop = mace_close,
  348. .ndo_start_xmit = mace_start_xmit,
  349. .ndo_tx_timeout = mace_tx_timeout,
  350. .ndo_set_config = mace_config,
  351. .ndo_get_stats = mace_get_stats,
  352. .ndo_set_rx_mode = set_multicast_list,
  353. .ndo_set_mac_address = eth_mac_addr,
  354. .ndo_validate_addr = eth_validate_addr,
  355. };
  356. static int nmclan_probe(struct pcmcia_device *link)
  357. {
  358. mace_private *lp;
  359. struct net_device *dev;
  360. dev_dbg(&link->dev, "nmclan_attach()\n");
  361. /* Create new ethernet device */
  362. dev = alloc_etherdev(sizeof(mace_private));
  363. if (!dev)
  364. return -ENOMEM;
  365. lp = netdev_priv(dev);
  366. lp->p_dev = link;
  367. link->priv = dev;
  368. spin_lock_init(&lp->bank_lock);
  369. link->resource[0]->end = 32;
  370. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  371. link->config_flags |= CONF_ENABLE_IRQ;
  372. link->config_index = 1;
  373. link->config_regs = PRESENT_OPTION;
  374. lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
  375. dev->netdev_ops = &mace_netdev_ops;
  376. dev->ethtool_ops = &netdev_ethtool_ops;
  377. dev->watchdog_timeo = TX_TIMEOUT;
  378. return nmclan_config(link);
  379. } /* nmclan_attach */
  380. static void nmclan_detach(struct pcmcia_device *link)
  381. {
  382. struct net_device *dev = link->priv;
  383. dev_dbg(&link->dev, "nmclan_detach\n");
  384. unregister_netdev(dev);
  385. nmclan_release(link);
  386. free_netdev(dev);
  387. } /* nmclan_detach */
  388. /* ----------------------------------------------------------------------------
  389. mace_read
  390. Reads a MACE register. This is bank independent; however, the
  391. caller must ensure that this call is not interruptable. We are
  392. assuming that during normal operation, the MACE is always in
  393. bank 0.
  394. ---------------------------------------------------------------------------- */
  395. static int mace_read(mace_private *lp, unsigned int ioaddr, int reg)
  396. {
  397. int data = 0xFF;
  398. unsigned long flags;
  399. switch (reg >> 4) {
  400. case 0: /* register 0-15 */
  401. data = inb(ioaddr + AM2150_MACE_BASE + reg);
  402. break;
  403. case 1: /* register 16-31 */
  404. spin_lock_irqsave(&lp->bank_lock, flags);
  405. MACEBANK(1);
  406. data = inb(ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
  407. MACEBANK(0);
  408. spin_unlock_irqrestore(&lp->bank_lock, flags);
  409. break;
  410. }
  411. return data & 0xFF;
  412. } /* mace_read */
  413. /* ----------------------------------------------------------------------------
  414. mace_write
  415. Writes to a MACE register. This is bank independent; however,
  416. the caller must ensure that this call is not interruptable. We
  417. are assuming that during normal operation, the MACE is always in
  418. bank 0.
  419. ---------------------------------------------------------------------------- */
  420. static void mace_write(mace_private *lp, unsigned int ioaddr, int reg,
  421. int data)
  422. {
  423. unsigned long flags;
  424. switch (reg >> 4) {
  425. case 0: /* register 0-15 */
  426. outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + reg);
  427. break;
  428. case 1: /* register 16-31 */
  429. spin_lock_irqsave(&lp->bank_lock, flags);
  430. MACEBANK(1);
  431. outb(data & 0xFF, ioaddr + AM2150_MACE_BASE + (reg & 0x0F));
  432. MACEBANK(0);
  433. spin_unlock_irqrestore(&lp->bank_lock, flags);
  434. break;
  435. }
  436. } /* mace_write */
  437. /* ----------------------------------------------------------------------------
  438. mace_init
  439. Resets the MACE chip.
  440. ---------------------------------------------------------------------------- */
  441. static int mace_init(mace_private *lp, unsigned int ioaddr,
  442. const 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. eth_hw_addr_set(dev, buf);
  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. goto failed;
  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. strscpy(info->driver, DRV_NAME, sizeof(info->driver));
  678. snprintf(info->bus_info, sizeof(info->bus_info),
  679. "PCMCIA 0x%lx", dev->base_addr);
  680. }
  681. static const struct ethtool_ops netdev_ethtool_ops = {
  682. .get_drvinfo = netdev_get_drvinfo,
  683. };
  684. /* ----------------------------------------------------------------------------
  685. mace_start_xmit
  686. This routine begins the packet transmit function. When completed,
  687. it will generate a transmit interrupt.
  688. According to /usr/src/linux/net/inet/dev.c, if _start_xmit
  689. returns 0, the "packet is now solely the responsibility of the
  690. driver." If _start_xmit returns non-zero, the "transmission
  691. failed, put skb back into a list."
  692. ---------------------------------------------------------------------------- */
  693. static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue)
  694. {
  695. mace_private *lp = netdev_priv(dev);
  696. struct pcmcia_device *link = lp->p_dev;
  697. netdev_notice(dev, "transmit timed out -- ");
  698. #if RESET_ON_TIMEOUT
  699. pr_cont("resetting card\n");
  700. pcmcia_reset_card(link->socket);
  701. #else /* #if RESET_ON_TIMEOUT */
  702. pr_cont("NOT resetting card\n");
  703. #endif /* #if RESET_ON_TIMEOUT */
  704. netif_trans_update(dev); /* prevent tx timeout */
  705. netif_wake_queue(dev);
  706. }
  707. static netdev_tx_t mace_start_xmit(struct sk_buff *skb,
  708. struct net_device *dev)
  709. {
  710. mace_private *lp = netdev_priv(dev);
  711. unsigned int ioaddr = dev->base_addr;
  712. netif_stop_queue(dev);
  713. pr_debug("%s: mace_start_xmit(length = %ld) called.\n",
  714. dev->name, (long)skb->len);
  715. #if (!TX_INTERRUPTABLE)
  716. /* Disable MACE TX interrupts. */
  717. outb(MACE_IMR_DEFAULT | MACE_IR_XMTINT,
  718. ioaddr + AM2150_MACE_BASE + MACE_IMR);
  719. lp->tx_irq_disabled=1;
  720. #endif /* #if (!TX_INTERRUPTABLE) */
  721. {
  722. /* This block must not be interrupted by another transmit request!
  723. mace_tx_timeout will take care of timer-based retransmissions from
  724. the upper layers. The interrupt handler is guaranteed never to
  725. service a transmit interrupt while we are in here.
  726. */
  727. dev->stats.tx_bytes += skb->len;
  728. lp->tx_free_frames--;
  729. /* WARNING: Write the _exact_ number of bytes written in the header! */
  730. /* Put out the word header [must be an outw()] . . . */
  731. outw(skb->len, ioaddr + AM2150_XMT);
  732. /* . . . and the packet [may be any combination of outw() and outb()] */
  733. outsw(ioaddr + AM2150_XMT, skb->data, skb->len >> 1);
  734. if (skb->len & 1) {
  735. /* Odd byte transfer */
  736. outb(skb->data[skb->len-1], ioaddr + AM2150_XMT);
  737. }
  738. #if MULTI_TX
  739. if (lp->tx_free_frames > 0)
  740. netif_start_queue(dev);
  741. #endif /* #if MULTI_TX */
  742. }
  743. #if (!TX_INTERRUPTABLE)
  744. /* Re-enable MACE TX interrupts. */
  745. lp->tx_irq_disabled=0;
  746. outb(MACE_IMR_DEFAULT, ioaddr + AM2150_MACE_BASE + MACE_IMR);
  747. #endif /* #if (!TX_INTERRUPTABLE) */
  748. dev_kfree_skb(skb);
  749. return NETDEV_TX_OK;
  750. } /* mace_start_xmit */
  751. /* ----------------------------------------------------------------------------
  752. mace_interrupt
  753. The interrupt handler.
  754. ---------------------------------------------------------------------------- */
  755. static irqreturn_t mace_interrupt(int irq, void *dev_id)
  756. {
  757. struct net_device *dev = (struct net_device *) dev_id;
  758. mace_private *lp = netdev_priv(dev);
  759. unsigned int ioaddr;
  760. int status;
  761. int IntrCnt = MACE_MAX_IR_ITERATIONS;
  762. if (!dev) {
  763. pr_debug("mace_interrupt(): irq 0x%X for unknown device.\n",
  764. irq);
  765. return IRQ_NONE;
  766. }
  767. ioaddr = dev->base_addr;
  768. if (lp->tx_irq_disabled) {
  769. const char *msg;
  770. if (lp->tx_irq_disabled)
  771. msg = "Interrupt with tx_irq_disabled";
  772. else
  773. msg = "Re-entering the interrupt handler";
  774. netdev_notice(dev, "%s [isr=%02X, imr=%02X]\n",
  775. msg,
  776. inb(ioaddr + AM2150_MACE_BASE + MACE_IR),
  777. inb(ioaddr + AM2150_MACE_BASE + MACE_IMR));
  778. /* WARNING: MACE_IR has been read! */
  779. return IRQ_NONE;
  780. }
  781. if (!netif_device_present(dev)) {
  782. netdev_dbg(dev, "interrupt from dead card\n");
  783. return IRQ_NONE;
  784. }
  785. do {
  786. /* WARNING: MACE_IR is a READ/CLEAR port! */
  787. status = inb(ioaddr + AM2150_MACE_BASE + MACE_IR);
  788. if (!(status & ~MACE_IMR_DEFAULT) && IntrCnt == MACE_MAX_IR_ITERATIONS)
  789. return IRQ_NONE;
  790. pr_debug("mace_interrupt: irq 0x%X status 0x%X.\n", irq, status);
  791. if (status & MACE_IR_RCVINT) {
  792. mace_rx(dev, MACE_MAX_RX_ITERATIONS);
  793. }
  794. if (status & MACE_IR_XMTINT) {
  795. unsigned char fifofc;
  796. unsigned char xmtrc;
  797. unsigned char xmtfs;
  798. fifofc = inb(ioaddr + AM2150_MACE_BASE + MACE_FIFOFC);
  799. if ((fifofc & MACE_FIFOFC_XMTFC)==0) {
  800. dev->stats.tx_errors++;
  801. outb(0xFF, ioaddr + AM2150_XMT_SKIP);
  802. }
  803. /* Transmit Retry Count (XMTRC, reg 4) */
  804. xmtrc = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTRC);
  805. if (xmtrc & MACE_XMTRC_EXDEF) lp->mace_stats.exdef++;
  806. lp->mace_stats.xmtrc += (xmtrc & MACE_XMTRC_XMTRC);
  807. if (
  808. (xmtfs = inb(ioaddr + AM2150_MACE_BASE + MACE_XMTFS)) &
  809. MACE_XMTFS_XMTSV /* Transmit Status Valid */
  810. ) {
  811. lp->mace_stats.xmtsv++;
  812. if (xmtfs & ~MACE_XMTFS_XMTSV) {
  813. if (xmtfs & MACE_XMTFS_UFLO) {
  814. /* Underflow. Indicates that the Transmit FIFO emptied before
  815. the end of frame was reached. */
  816. lp->mace_stats.uflo++;
  817. }
  818. if (xmtfs & MACE_XMTFS_LCOL) {
  819. /* Late Collision */
  820. lp->mace_stats.lcol++;
  821. }
  822. if (xmtfs & MACE_XMTFS_MORE) {
  823. /* MORE than one retry was needed */
  824. lp->mace_stats.more++;
  825. }
  826. if (xmtfs & MACE_XMTFS_ONE) {
  827. /* Exactly ONE retry occurred */
  828. lp->mace_stats.one++;
  829. }
  830. if (xmtfs & MACE_XMTFS_DEFER) {
  831. /* Transmission was defered */
  832. lp->mace_stats.defer++;
  833. }
  834. if (xmtfs & MACE_XMTFS_LCAR) {
  835. /* Loss of carrier */
  836. lp->mace_stats.lcar++;
  837. }
  838. if (xmtfs & MACE_XMTFS_RTRY) {
  839. /* Retry error: transmit aborted after 16 attempts */
  840. lp->mace_stats.rtry++;
  841. }
  842. } /* if (xmtfs & ~MACE_XMTFS_XMTSV) */
  843. } /* if (xmtfs & MACE_XMTFS_XMTSV) */
  844. dev->stats.tx_packets++;
  845. lp->tx_free_frames++;
  846. netif_wake_queue(dev);
  847. } /* if (status & MACE_IR_XMTINT) */
  848. if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) {
  849. if (status & MACE_IR_JAB) {
  850. /* Jabber Error. Excessive transmit duration (20-150ms). */
  851. lp->mace_stats.jab++;
  852. }
  853. if (status & MACE_IR_BABL) {
  854. /* Babble Error. >1518 bytes transmitted. */
  855. lp->mace_stats.babl++;
  856. }
  857. if (status & MACE_IR_CERR) {
  858. /* Collision Error. CERR indicates the absence of the
  859. Signal Quality Error Test message after a packet
  860. transmission. */
  861. lp->mace_stats.cerr++;
  862. }
  863. if (status & MACE_IR_RCVCCO) {
  864. /* Receive Collision Count Overflow; */
  865. lp->mace_stats.rcvcco++;
  866. }
  867. if (status & MACE_IR_RNTPCO) {
  868. /* Runt Packet Count Overflow */
  869. lp->mace_stats.rntpco++;
  870. }
  871. if (status & MACE_IR_MPCO) {
  872. /* Missed Packet Count Overflow */
  873. lp->mace_stats.mpco++;
  874. }
  875. } /* if (status & ~MACE_IMR_DEFAULT & ~MACE_IR_RCVINT & ~MACE_IR_XMTINT) */
  876. } while ((status & ~MACE_IMR_DEFAULT) && (--IntrCnt));
  877. return IRQ_HANDLED;
  878. } /* mace_interrupt */
  879. /* ----------------------------------------------------------------------------
  880. mace_rx
  881. Receives packets.
  882. ---------------------------------------------------------------------------- */
  883. static int mace_rx(struct net_device *dev, unsigned char RxCnt)
  884. {
  885. mace_private *lp = netdev_priv(dev);
  886. unsigned int ioaddr = dev->base_addr;
  887. unsigned char rx_framecnt;
  888. unsigned short rx_status;
  889. while (
  890. ((rx_framecnt = inb(ioaddr + AM2150_RCV_FRAME_COUNT)) > 0) &&
  891. (rx_framecnt <= 12) && /* rx_framecnt==0xFF if card is extracted. */
  892. (RxCnt--)
  893. ) {
  894. rx_status = inw(ioaddr + AM2150_RCV);
  895. pr_debug("%s: in mace_rx(), framecnt 0x%X, rx_status"
  896. " 0x%X.\n", dev->name, rx_framecnt, rx_status);
  897. if (rx_status & MACE_RCVFS_RCVSTS) { /* Error, update stats. */
  898. dev->stats.rx_errors++;
  899. if (rx_status & MACE_RCVFS_OFLO) {
  900. lp->mace_stats.oflo++;
  901. }
  902. if (rx_status & MACE_RCVFS_CLSN) {
  903. lp->mace_stats.clsn++;
  904. }
  905. if (rx_status & MACE_RCVFS_FRAM) {
  906. lp->mace_stats.fram++;
  907. }
  908. if (rx_status & MACE_RCVFS_FCS) {
  909. lp->mace_stats.fcs++;
  910. }
  911. } else {
  912. short pkt_len = (rx_status & ~MACE_RCVFS_RCVSTS) - 4;
  913. /* Auto Strip is off, always subtract 4 */
  914. struct sk_buff *skb;
  915. lp->mace_stats.rfs_rntpc += inb(ioaddr + AM2150_RCV);
  916. /* runt packet count */
  917. lp->mace_stats.rfs_rcvcc += inb(ioaddr + AM2150_RCV);
  918. /* rcv collision count */
  919. pr_debug(" receiving packet size 0x%X rx_status"
  920. " 0x%X.\n", pkt_len, rx_status);
  921. skb = netdev_alloc_skb(dev, pkt_len + 2);
  922. if (skb) {
  923. skb_reserve(skb, 2);
  924. insw(ioaddr + AM2150_RCV, skb_put(skb, pkt_len), pkt_len>>1);
  925. if (pkt_len & 1)
  926. *(skb_tail_pointer(skb) - 1) = inb(ioaddr + AM2150_RCV);
  927. skb->protocol = eth_type_trans(skb, dev);
  928. netif_rx(skb); /* Send the packet to the upper (protocol) layers. */
  929. dev->stats.rx_packets++;
  930. dev->stats.rx_bytes += pkt_len;
  931. outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
  932. continue;
  933. } else {
  934. pr_debug("%s: couldn't allocate a sk_buff of size"
  935. " %d.\n", dev->name, pkt_len);
  936. dev->stats.rx_dropped++;
  937. }
  938. }
  939. outb(0xFF, ioaddr + AM2150_RCV_NEXT); /* skip to next frame */
  940. } /* while */
  941. return 0;
  942. } /* mace_rx */
  943. /* ----------------------------------------------------------------------------
  944. pr_linux_stats
  945. ---------------------------------------------------------------------------- */
  946. static void pr_linux_stats(struct net_device_stats *pstats)
  947. {
  948. pr_debug("pr_linux_stats\n");
  949. pr_debug(" rx_packets=%-7ld tx_packets=%ld\n",
  950. (long)pstats->rx_packets, (long)pstats->tx_packets);
  951. pr_debug(" rx_errors=%-7ld tx_errors=%ld\n",
  952. (long)pstats->rx_errors, (long)pstats->tx_errors);
  953. pr_debug(" rx_dropped=%-7ld tx_dropped=%ld\n",
  954. (long)pstats->rx_dropped, (long)pstats->tx_dropped);
  955. pr_debug(" multicast=%-7ld collisions=%ld\n",
  956. (long)pstats->multicast, (long)pstats->collisions);
  957. pr_debug(" rx_length_errors=%-7ld rx_over_errors=%ld\n",
  958. (long)pstats->rx_length_errors, (long)pstats->rx_over_errors);
  959. pr_debug(" rx_crc_errors=%-7ld rx_frame_errors=%ld\n",
  960. (long)pstats->rx_crc_errors, (long)pstats->rx_frame_errors);
  961. pr_debug(" rx_fifo_errors=%-7ld rx_missed_errors=%ld\n",
  962. (long)pstats->rx_fifo_errors, (long)pstats->rx_missed_errors);
  963. pr_debug(" tx_aborted_errors=%-7ld tx_carrier_errors=%ld\n",
  964. (long)pstats->tx_aborted_errors, (long)pstats->tx_carrier_errors);
  965. pr_debug(" tx_fifo_errors=%-7ld tx_heartbeat_errors=%ld\n",
  966. (long)pstats->tx_fifo_errors, (long)pstats->tx_heartbeat_errors);
  967. pr_debug(" tx_window_errors=%ld\n",
  968. (long)pstats->tx_window_errors);
  969. } /* pr_linux_stats */
  970. /* ----------------------------------------------------------------------------
  971. pr_mace_stats
  972. ---------------------------------------------------------------------------- */
  973. static void pr_mace_stats(mace_statistics *pstats)
  974. {
  975. pr_debug("pr_mace_stats\n");
  976. pr_debug(" xmtsv=%-7d uflo=%d\n",
  977. pstats->xmtsv, pstats->uflo);
  978. pr_debug(" lcol=%-7d more=%d\n",
  979. pstats->lcol, pstats->more);
  980. pr_debug(" one=%-7d defer=%d\n",
  981. pstats->one, pstats->defer);
  982. pr_debug(" lcar=%-7d rtry=%d\n",
  983. pstats->lcar, pstats->rtry);
  984. /* MACE_XMTRC */
  985. pr_debug(" exdef=%-7d xmtrc=%d\n",
  986. pstats->exdef, pstats->xmtrc);
  987. /* RFS1--Receive Status (RCVSTS) */
  988. pr_debug(" oflo=%-7d clsn=%d\n",
  989. pstats->oflo, pstats->clsn);
  990. pr_debug(" fram=%-7d fcs=%d\n",
  991. pstats->fram, pstats->fcs);
  992. /* RFS2--Runt Packet Count (RNTPC) */
  993. /* RFS3--Receive Collision Count (RCVCC) */
  994. pr_debug(" rfs_rntpc=%-7d rfs_rcvcc=%d\n",
  995. pstats->rfs_rntpc, pstats->rfs_rcvcc);
  996. /* MACE_IR */
  997. pr_debug(" jab=%-7d babl=%d\n",
  998. pstats->jab, pstats->babl);
  999. pr_debug(" cerr=%-7d rcvcco=%d\n",
  1000. pstats->cerr, pstats->rcvcco);
  1001. pr_debug(" rntpco=%-7d mpco=%d\n",
  1002. pstats->rntpco, pstats->mpco);
  1003. /* MACE_MPC */
  1004. pr_debug(" mpc=%d\n", pstats->mpc);
  1005. /* MACE_RNTPC */
  1006. pr_debug(" rntpc=%d\n", pstats->rntpc);
  1007. /* MACE_RCVCC */
  1008. pr_debug(" rcvcc=%d\n", pstats->rcvcc);
  1009. } /* pr_mace_stats */
  1010. /* ----------------------------------------------------------------------------
  1011. update_stats
  1012. Update statistics. We change to register window 1, so this
  1013. should be run single-threaded if the device is active. This is
  1014. expected to be a rare operation, and it's simpler for the rest
  1015. of the driver to assume that window 0 is always valid rather
  1016. than use a special window-state variable.
  1017. oflo & uflo should _never_ occur since it would mean the Xilinx
  1018. was not able to transfer data between the MACE FIFO and the
  1019. card's SRAM fast enough. If this happens, something is
  1020. seriously wrong with the hardware.
  1021. ---------------------------------------------------------------------------- */
  1022. static void update_stats(unsigned int ioaddr, struct net_device *dev)
  1023. {
  1024. mace_private *lp = netdev_priv(dev);
  1025. lp->mace_stats.rcvcc += mace_read(lp, ioaddr, MACE_RCVCC);
  1026. lp->mace_stats.rntpc += mace_read(lp, ioaddr, MACE_RNTPC);
  1027. lp->mace_stats.mpc += mace_read(lp, ioaddr, MACE_MPC);
  1028. /* At this point, mace_stats is fully updated for this call.
  1029. We may now update the netdev stats. */
  1030. /* The MACE has no equivalent for netdev stats field which are commented
  1031. out. */
  1032. /* dev->stats.multicast; */
  1033. dev->stats.collisions =
  1034. lp->mace_stats.rcvcco * 256 + lp->mace_stats.rcvcc;
  1035. /* Collision: The MACE may retry sending a packet 15 times
  1036. before giving up. The retry count is in XMTRC.
  1037. Does each retry constitute a collision?
  1038. If so, why doesn't the RCVCC record these collisions? */
  1039. /* detailed rx_errors: */
  1040. dev->stats.rx_length_errors =
  1041. lp->mace_stats.rntpco * 256 + lp->mace_stats.rntpc;
  1042. /* dev->stats.rx_over_errors */
  1043. dev->stats.rx_crc_errors = lp->mace_stats.fcs;
  1044. dev->stats.rx_frame_errors = lp->mace_stats.fram;
  1045. dev->stats.rx_fifo_errors = lp->mace_stats.oflo;
  1046. dev->stats.rx_missed_errors =
  1047. lp->mace_stats.mpco * 256 + lp->mace_stats.mpc;
  1048. /* detailed tx_errors */
  1049. dev->stats.tx_aborted_errors = lp->mace_stats.rtry;
  1050. dev->stats.tx_carrier_errors = lp->mace_stats.lcar;
  1051. /* LCAR usually results from bad cabling. */
  1052. dev->stats.tx_fifo_errors = lp->mace_stats.uflo;
  1053. dev->stats.tx_heartbeat_errors = lp->mace_stats.cerr;
  1054. /* dev->stats.tx_window_errors; */
  1055. } /* update_stats */
  1056. /* ----------------------------------------------------------------------------
  1057. mace_get_stats
  1058. Gathers ethernet statistics from the MACE chip.
  1059. ---------------------------------------------------------------------------- */
  1060. static struct net_device_stats *mace_get_stats(struct net_device *dev)
  1061. {
  1062. mace_private *lp = netdev_priv(dev);
  1063. update_stats(dev->base_addr, dev);
  1064. pr_debug("%s: updating the statistics.\n", dev->name);
  1065. pr_linux_stats(&dev->stats);
  1066. pr_mace_stats(&lp->mace_stats);
  1067. return &dev->stats;
  1068. } /* net_device_stats */
  1069. /* ----------------------------------------------------------------------------
  1070. updateCRC
  1071. Modified from Am79C90 data sheet.
  1072. ---------------------------------------------------------------------------- */
  1073. #ifdef BROKEN_MULTICAST
  1074. static void updateCRC(int *CRC, int bit)
  1075. {
  1076. static const int poly[]={
  1077. 1,1,1,0, 1,1,0,1,
  1078. 1,0,1,1, 1,0,0,0,
  1079. 1,0,0,0, 0,0,1,1,
  1080. 0,0,1,0, 0,0,0,0
  1081. }; /* CRC polynomial. poly[n] = coefficient of the x**n term of the
  1082. CRC generator polynomial. */
  1083. int j;
  1084. /* shift CRC and control bit (CRC[32]) */
  1085. for (j = 32; j > 0; j--)
  1086. CRC[j] = CRC[j-1];
  1087. CRC[0] = 0;
  1088. /* If bit XOR(control bit) = 1, set CRC = CRC XOR polynomial. */
  1089. if (bit ^ CRC[32])
  1090. for (j = 0; j < 32; j++)
  1091. CRC[j] ^= poly[j];
  1092. } /* updateCRC */
  1093. /* ----------------------------------------------------------------------------
  1094. BuildLAF
  1095. Build logical address filter.
  1096. Modified from Am79C90 data sheet.
  1097. Input
  1098. ladrf: logical address filter (contents initialized to 0)
  1099. adr: ethernet address
  1100. ---------------------------------------------------------------------------- */
  1101. static void BuildLAF(int *ladrf, int *adr)
  1102. {
  1103. int CRC[33]={1}; /* CRC register, 1 word/bit + extra control bit */
  1104. int i, byte; /* temporary array indices */
  1105. int hashcode; /* the output object */
  1106. CRC[32]=0;
  1107. for (byte = 0; byte < 6; byte++)
  1108. for (i = 0; i < 8; i++)
  1109. updateCRC(CRC, (adr[byte] >> i) & 1);
  1110. hashcode = 0;
  1111. for (i = 0; i < 6; i++)
  1112. hashcode = (hashcode << 1) + CRC[i];
  1113. byte = hashcode >> 3;
  1114. ladrf[byte] |= (1 << (hashcode & 7));
  1115. #ifdef PCMCIA_DEBUG
  1116. if (0)
  1117. printk(KERN_DEBUG " adr =%pM\n", adr);
  1118. printk(KERN_DEBUG " hashcode = %d(decimal), ladrf[0:63] =", hashcode);
  1119. for (i = 0; i < 8; i++)
  1120. pr_cont(" %02X", ladrf[i]);
  1121. pr_cont("\n");
  1122. #endif
  1123. } /* BuildLAF */
  1124. /* ----------------------------------------------------------------------------
  1125. restore_multicast_list
  1126. Restores the multicast filter for MACE chip to the last
  1127. set_multicast_list() call.
  1128. Input
  1129. multicast_num_addrs
  1130. multicast_ladrf[]
  1131. ---------------------------------------------------------------------------- */
  1132. static void restore_multicast_list(struct net_device *dev)
  1133. {
  1134. mace_private *lp = netdev_priv(dev);
  1135. int num_addrs = lp->multicast_num_addrs;
  1136. int *ladrf = lp->multicast_ladrf;
  1137. unsigned int ioaddr = dev->base_addr;
  1138. int i;
  1139. pr_debug("%s: restoring Rx mode to %d addresses.\n",
  1140. dev->name, num_addrs);
  1141. if (num_addrs > 0) {
  1142. pr_debug("Attempt to restore multicast list detected.\n");
  1143. mace_write(lp, ioaddr, MACE_IAC, MACE_IAC_ADDRCHG | MACE_IAC_LOGADDR);
  1144. /* Poll ADDRCHG bit */
  1145. while (mace_read(lp, ioaddr, MACE_IAC) & MACE_IAC_ADDRCHG)
  1146. ;
  1147. /* Set LADRF register */
  1148. for (i = 0; i < MACE_LADRF_LEN; i++)
  1149. mace_write(lp, ioaddr, MACE_LADRF, ladrf[i]);
  1150. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_RCVFCSE | MACE_UTR_LOOP_EXTERNAL);
  1151. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1152. } else if (num_addrs < 0) {
  1153. /* Promiscuous mode: receive all packets */
  1154. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1155. mace_write(lp, ioaddr, MACE_MACCC,
  1156. MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
  1157. );
  1158. } else {
  1159. /* Normal mode */
  1160. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1161. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1162. }
  1163. } /* restore_multicast_list */
  1164. /* ----------------------------------------------------------------------------
  1165. set_multicast_list
  1166. Set or clear the multicast filter for this adaptor.
  1167. Input
  1168. num_addrs == -1 Promiscuous mode, receive all packets
  1169. num_addrs == 0 Normal mode, clear multicast list
  1170. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  1171. best-effort filtering.
  1172. Output
  1173. multicast_num_addrs
  1174. multicast_ladrf[]
  1175. ---------------------------------------------------------------------------- */
  1176. static void set_multicast_list(struct net_device *dev)
  1177. {
  1178. mace_private *lp = netdev_priv(dev);
  1179. int adr[ETH_ALEN] = {0}; /* Ethernet address */
  1180. struct netdev_hw_addr *ha;
  1181. #ifdef PCMCIA_DEBUG
  1182. {
  1183. static int old;
  1184. if (netdev_mc_count(dev) != old) {
  1185. old = netdev_mc_count(dev);
  1186. pr_debug("%s: setting Rx mode to %d addresses.\n",
  1187. dev->name, old);
  1188. }
  1189. }
  1190. #endif
  1191. /* Set multicast_num_addrs. */
  1192. lp->multicast_num_addrs = netdev_mc_count(dev);
  1193. /* Set multicast_ladrf. */
  1194. if (num_addrs > 0) {
  1195. /* Calculate multicast logical address filter */
  1196. memset(lp->multicast_ladrf, 0, MACE_LADRF_LEN);
  1197. netdev_for_each_mc_addr(ha, dev) {
  1198. memcpy(adr, ha->addr, ETH_ALEN);
  1199. BuildLAF(lp->multicast_ladrf, adr);
  1200. }
  1201. }
  1202. restore_multicast_list(dev);
  1203. } /* set_multicast_list */
  1204. #endif /* BROKEN_MULTICAST */
  1205. static void restore_multicast_list(struct net_device *dev)
  1206. {
  1207. unsigned int ioaddr = dev->base_addr;
  1208. mace_private *lp = netdev_priv(dev);
  1209. pr_debug("%s: restoring Rx mode to %d addresses.\n", dev->name,
  1210. lp->multicast_num_addrs);
  1211. if (dev->flags & IFF_PROMISC) {
  1212. /* Promiscuous mode: receive all packets */
  1213. mace_write(lp,ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1214. mace_write(lp, ioaddr, MACE_MACCC,
  1215. MACE_MACCC_PROM | MACE_MACCC_ENXMT | MACE_MACCC_ENRCV
  1216. );
  1217. } else {
  1218. /* Normal mode */
  1219. mace_write(lp, ioaddr, MACE_UTR, MACE_UTR_LOOP_EXTERNAL);
  1220. mace_write(lp, ioaddr, MACE_MACCC, MACE_MACCC_ENXMT | MACE_MACCC_ENRCV);
  1221. }
  1222. } /* restore_multicast_list */
  1223. static void set_multicast_list(struct net_device *dev)
  1224. {
  1225. mace_private *lp = netdev_priv(dev);
  1226. #ifdef PCMCIA_DEBUG
  1227. {
  1228. static int old;
  1229. if (netdev_mc_count(dev) != old) {
  1230. old = netdev_mc_count(dev);
  1231. pr_debug("%s: setting Rx mode to %d addresses.\n",
  1232. dev->name, old);
  1233. }
  1234. }
  1235. #endif
  1236. lp->multicast_num_addrs = netdev_mc_count(dev);
  1237. restore_multicast_list(dev);
  1238. } /* set_multicast_list */
  1239. static const struct pcmcia_device_id nmclan_ids[] = {
  1240. PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
  1241. PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet+", 0xebf1d60, 0xad673aaf),
  1242. PCMCIA_DEVICE_NULL,
  1243. };
  1244. MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
  1245. static struct pcmcia_driver nmclan_cs_driver = {
  1246. .owner = THIS_MODULE,
  1247. .name = "nmclan_cs",
  1248. .probe = nmclan_probe,
  1249. .remove = nmclan_detach,
  1250. .id_table = nmclan_ids,
  1251. .suspend = nmclan_suspend,
  1252. .resume = nmclan_resume,
  1253. };
  1254. module_pcmcia_driver(nmclan_cs_driver);