xirc2ps_cs.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  1. /* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03)
  2. * Xircom CreditCard Ethernet Adapter IIps driver
  3. * Xircom Realport 10/100 (RE-100) driver
  4. *
  5. * This driver supports various Xircom CreditCard Ethernet adapters
  6. * including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56,
  7. * CE3-100, CE3B, RE-100, REM10BT, and REM56G-100.
  8. *
  9. * 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not
  10. * autodetect the media properly. In this case use the
  11. * if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options
  12. * to force the media type.
  13. *
  14. * Written originally by Werner Koch based on David Hinds' skeleton of the
  15. * PCMCIA driver.
  16. *
  17. * Copyright (c) 1997,1998 Werner Koch (dd9jn)
  18. *
  19. * This driver is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * It is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  32. *
  33. *
  34. * ALTERNATIVELY, this driver may be distributed under the terms of
  35. * the following license, in which case the provisions of this license
  36. * are required INSTEAD OF the GNU General Public License. (This clause
  37. * is necessary due to a potential bad interaction between the GPL and
  38. * the restrictions contained in a BSD-style copyright.)
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. * 1. Redistributions of source code must retain the above copyright
  44. * notice, and the entire permission notice in its entirety,
  45. * including the disclaimer of warranties.
  46. * 2. Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in the
  48. * documentation and/or other materials provided with the distribution.
  49. * 3. The name of the author may not be used to endorse or promote
  50. * products derived from this software without specific prior
  51. * written permission.
  52. *
  53. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  54. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  55. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  56. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  57. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  58. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  59. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  61. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  62. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  63. * OF THE POSSIBILITY OF SUCH DAMAGE.
  64. */
  65. #include <linux/module.h>
  66. #include <linux/kernel.h>
  67. #include <linux/init.h>
  68. #include <linux/ptrace.h>
  69. #include <linux/slab.h>
  70. #include <linux/string.h>
  71. #include <linux/timer.h>
  72. #include <linux/interrupt.h>
  73. #include <linux/in.h>
  74. #include <linux/delay.h>
  75. #include <linux/ethtool.h>
  76. #include <linux/netdevice.h>
  77. #include <linux/etherdevice.h>
  78. #include <linux/skbuff.h>
  79. #include <linux/if_arp.h>
  80. #include <linux/ioport.h>
  81. #include <linux/bitops.h>
  82. #include <pcmcia/cs_types.h>
  83. #include <pcmcia/cs.h>
  84. #include <pcmcia/cistpl.h>
  85. #include <pcmcia/cisreg.h>
  86. #include <pcmcia/ciscode.h>
  87. #include <asm/io.h>
  88. #include <asm/system.h>
  89. #include <asm/uaccess.h>
  90. #ifndef MANFID_COMPAQ
  91. #define MANFID_COMPAQ 0x0138
  92. #define MANFID_COMPAQ2 0x0183 /* is this correct? */
  93. #endif
  94. #include <pcmcia/ds.h>
  95. /* Time in jiffies before concluding Tx hung */
  96. #define TX_TIMEOUT ((400*HZ)/1000)
  97. /****************
  98. * Some constants used to access the hardware
  99. */
  100. /* Register offsets and value constans */
  101. #define XIRCREG_CR 0 /* Command register (wr) */
  102. enum xirc_cr {
  103. TransmitPacket = 0x01,
  104. SoftReset = 0x02,
  105. EnableIntr = 0x04,
  106. ForceIntr = 0x08,
  107. ClearTxFIFO = 0x10,
  108. ClearRxOvrun = 0x20,
  109. RestartTx = 0x40
  110. };
  111. #define XIRCREG_ESR 0 /* Ethernet status register (rd) */
  112. enum xirc_esr {
  113. FullPktRcvd = 0x01, /* full packet in receive buffer */
  114. PktRejected = 0x04, /* a packet has been rejected */
  115. TxPktPend = 0x08, /* TX Packet Pending */
  116. IncorPolarity = 0x10,
  117. MediaSelect = 0x20 /* set if TP, clear if AUI */
  118. };
  119. #define XIRCREG_PR 1 /* Page Register select */
  120. #define XIRCREG_EDP 4 /* Ethernet Data Port Register */
  121. #define XIRCREG_ISR 6 /* Ethernet Interrupt Status Register */
  122. enum xirc_isr {
  123. TxBufOvr = 0x01, /* TX Buffer Overflow */
  124. PktTxed = 0x02, /* Packet Transmitted */
  125. MACIntr = 0x04, /* MAC Interrupt occurred */
  126. TxResGrant = 0x08, /* Tx Reservation Granted */
  127. RxFullPkt = 0x20, /* Rx Full Packet */
  128. RxPktRej = 0x40, /* Rx Packet Rejected */
  129. ForcedIntr= 0x80 /* Forced Interrupt */
  130. };
  131. #define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/
  132. #define XIRCREG1_IMR1 13
  133. #define XIRCREG0_TSO 8 /* Transmit Space Open Register (on page 0)*/
  134. #define XIRCREG0_TRS 10 /* Transmit reservation Size Register (page 0)*/
  135. #define XIRCREG0_DO 12 /* Data Offset Register (page 0) (wr) */
  136. #define XIRCREG0_RSR 12 /* Receive Status Register (page 0) (rd) */
  137. enum xirc_rsr {
  138. PhyPkt = 0x01, /* set:physical packet, clear: multicast packet */
  139. BrdcstPkt = 0x02, /* set if it is a broadcast packet */
  140. PktTooLong = 0x04, /* set if packet length > 1518 */
  141. AlignErr = 0x10, /* incorrect CRC and last octet not complete */
  142. CRCErr = 0x20, /* incorrect CRC and last octet is complete */
  143. PktRxOk = 0x80 /* received ok */
  144. };
  145. #define XIRCREG0_PTR 13 /* packets transmitted register (rd) */
  146. #define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */
  147. #define XIRCREG1_ECR 14 /* ethernet configurationn register */
  148. enum xirc_ecr {
  149. FullDuplex = 0x04, /* enable full duplex mode */
  150. LongTPMode = 0x08, /* adjust for longer lengths of TP cable */
  151. DisablePolCor = 0x10,/* disable auto polarity correction */
  152. DisableLinkPulse = 0x20, /* disable link pulse generation */
  153. DisableAutoTx = 0x40, /* disable auto-transmit */
  154. };
  155. #define XIRCREG2_RBS 8 /* receive buffer start register */
  156. #define XIRCREG2_LED 10 /* LED Configuration register */
  157. /* values for the leds: Bits 2-0 for led 1
  158. * 0 disabled Bits 5-3 for led 2
  159. * 1 collision
  160. * 2 noncollision
  161. * 3 link_detected
  162. * 4 incor_polarity
  163. * 5 jabber
  164. * 6 auto_assertion
  165. * 7 rx_tx_activity
  166. */
  167. #define XIRCREG2_MSR 12 /* Mohawk specific register */
  168. #define XIRCREG4_GPR0 8 /* General Purpose Register 0 */
  169. #define XIRCREG4_GPR1 9 /* General Purpose Register 1 */
  170. #define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/
  171. #define XIRCREG4_BOV 10 /* Bonding Version Register */
  172. #define XIRCREG4_LMA 12 /* Local Memory Address Register */
  173. #define XIRCREG4_LMD 14 /* Local Memory Data Port */
  174. /* MAC register can only by accessed with 8 bit operations */
  175. #define XIRCREG40_CMD0 8 /* Command Register (wr) */
  176. enum xirc_cmd { /* Commands */
  177. Transmit = 0x01,
  178. EnableRecv = 0x04,
  179. DisableRecv = 0x08,
  180. Abort = 0x10,
  181. Online = 0x20,
  182. IntrAck = 0x40,
  183. Offline = 0x80
  184. };
  185. #define XIRCREG5_RHSA0 10 /* Rx Host Start Address */
  186. #define XIRCREG40_RXST0 9 /* Receive Status Register */
  187. #define XIRCREG40_TXST0 11 /* Transmit Status Register 0 */
  188. #define XIRCREG40_TXST1 12 /* Transmit Status Register 10 */
  189. #define XIRCREG40_RMASK0 13 /* Receive Mask Register */
  190. #define XIRCREG40_TMASK0 14 /* Transmit Mask Register 0 */
  191. #define XIRCREG40_TMASK1 15 /* Transmit Mask Register 0 */
  192. #define XIRCREG42_SWC0 8 /* Software Configuration 0 */
  193. #define XIRCREG42_SWC1 9 /* Software Configuration 1 */
  194. #define XIRCREG42_BOC 10 /* Back-Off Configuration */
  195. #define XIRCREG44_TDR0 8 /* Time Domain Reflectometry 0 */
  196. #define XIRCREG44_TDR1 9 /* Time Domain Reflectometry 1 */
  197. #define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */
  198. #define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */
  199. #define XIRCREG45_REV 15 /* Revision Register (rd) */
  200. #define XIRCREG50_IA 8 /* Individual Address (8-13) */
  201. static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
  202. /****************
  203. * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
  204. * you do not define PCMCIA_DEBUG at all, all the debug code will be
  205. * left out. If you compile with PCMCIA_DEBUG=0, the debug code will
  206. * be present but disabled -- but it can then be enabled for specific
  207. * modules at load time with a 'pc_debug=#' option to insmod.
  208. */
  209. #ifdef PCMCIA_DEBUG
  210. static int pc_debug = PCMCIA_DEBUG;
  211. module_param(pc_debug, int, 0);
  212. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KDBG_XIRC args)
  213. #else
  214. #define DEBUG(n, args...)
  215. #endif
  216. #define KDBG_XIRC KERN_DEBUG "xirc2ps_cs: "
  217. #define KERR_XIRC KERN_ERR "xirc2ps_cs: "
  218. #define KWRN_XIRC KERN_WARNING "xirc2ps_cs: "
  219. #define KNOT_XIRC KERN_NOTICE "xirc2ps_cs: "
  220. #define KINF_XIRC KERN_INFO "xirc2ps_cs: "
  221. /* card types */
  222. #define XIR_UNKNOWN 0 /* unknown: not supported */
  223. #define XIR_CE 1 /* (prodid 1) different hardware: not supported */
  224. #define XIR_CE2 2 /* (prodid 2) */
  225. #define XIR_CE3 3 /* (prodid 3) */
  226. #define XIR_CEM 4 /* (prodid 1) different hardware: not supported */
  227. #define XIR_CEM2 5 /* (prodid 2) */
  228. #define XIR_CEM3 6 /* (prodid 3) */
  229. #define XIR_CEM33 7 /* (prodid 4) */
  230. #define XIR_CEM56M 8 /* (prodid 5) */
  231. #define XIR_CEM56 9 /* (prodid 6) */
  232. #define XIR_CM28 10 /* (prodid 3) modem only: not supported here */
  233. #define XIR_CM33 11 /* (prodid 4) modem only: not supported here */
  234. #define XIR_CM56 12 /* (prodid 5) modem only: not supported here */
  235. #define XIR_CG 13 /* (prodid 1) GSM modem only: not supported */
  236. #define XIR_CBE 14 /* (prodid 1) cardbus ethernet: not supported */
  237. /*====================================================================*/
  238. /* Module parameters */
  239. MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
  240. MODULE_LICENSE("Dual MPL/GPL");
  241. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  242. INT_MODULE_PARM(if_port, 0);
  243. INT_MODULE_PARM(full_duplex, 0);
  244. INT_MODULE_PARM(do_sound, 1);
  245. INT_MODULE_PARM(lockup_hack, 0); /* anti lockup hack */
  246. /*====================================================================*/
  247. /* We do not process more than these number of bytes during one
  248. * interrupt. (Of course we receive complete packets, so this is not
  249. * an exact value).
  250. * Something between 2000..22000; first value gives best interrupt latency,
  251. * the second enables the usage of the complete on-chip buffer. We use the
  252. * high value as the initial value.
  253. */
  254. static unsigned maxrx_bytes = 22000;
  255. /* MII management prototypes */
  256. static void mii_idle(unsigned int ioaddr);
  257. static void mii_putbit(unsigned int ioaddr, unsigned data);
  258. static int mii_getbit(unsigned int ioaddr);
  259. static void mii_wbits(unsigned int ioaddr, unsigned data, int len);
  260. static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
  261. static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
  262. unsigned data, int len);
  263. /*
  264. * The event() function is this driver's Card Services event handler.
  265. * It will be called by Card Services when an appropriate card status
  266. * event is received. The config() and release() entry points are
  267. * used to configure or release a socket, in response to card insertion
  268. * and ejection events. They are invoked from the event handler.
  269. */
  270. static int has_ce2_string(struct pcmcia_device * link);
  271. static int xirc2ps_config(struct pcmcia_device * link);
  272. static void xirc2ps_release(struct pcmcia_device * link);
  273. /****************
  274. * The attach() and detach() entry points are used to create and destroy
  275. * "instances" of the driver, where each instance represents everything
  276. * needed to manage one actual PCMCIA card.
  277. */
  278. static void xirc2ps_detach(struct pcmcia_device *p_dev);
  279. /****************
  280. * You'll also need to prototype all the functions that will actually
  281. * be used to talk to your device. See 'pcmem_cs' for a good example
  282. * of a fully self-sufficient driver; the other drivers rely more or
  283. * less on other parts of the kernel.
  284. */
  285. static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
  286. /****************
  287. * A linked list of "instances" of the device. Each actual
  288. * PCMCIA card corresponds to one device instance, and is described
  289. * by one struct pcmcia_device structure (defined in ds.h).
  290. *
  291. * You may not want to use a linked list for this -- for example, the
  292. * memory card driver uses an array of struct pcmcia_device pointers, where minor
  293. * device numbers are used to derive the corresponding array index.
  294. */
  295. /****************
  296. * A driver needs to provide a dev_node_t structure for each device
  297. * on a card. In some cases, there is only one device per card (for
  298. * example, ethernet cards, modems). In other cases, there may be
  299. * many actual or logical devices (SCSI adapters, memory cards with
  300. * multiple partitions). The dev_node_t structures need to be kept
  301. * in a linked list starting at the 'dev' field of a struct pcmcia_device
  302. * structure. We allocate them in the card's private data structure,
  303. * because they generally can't be allocated dynamically.
  304. */
  305. typedef struct local_info_t {
  306. struct net_device *dev;
  307. struct pcmcia_device *p_dev;
  308. dev_node_t node;
  309. int card_type;
  310. int probe_port;
  311. int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
  312. int mohawk; /* a CE3 type card */
  313. int dingo; /* a CEM56 type card */
  314. int new_mii; /* has full 10baseT/100baseT MII */
  315. int modem; /* is a multi function card (i.e with a modem) */
  316. void __iomem *dingo_ccr; /* only used for CEM56 cards */
  317. unsigned last_ptr_value; /* last packets transmitted value */
  318. const char *manf_str;
  319. struct work_struct tx_timeout_task;
  320. } local_info_t;
  321. /****************
  322. * Some more prototypes
  323. */
  324. static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
  325. static void xirc_tx_timeout(struct net_device *dev);
  326. static void xirc2ps_tx_timeout_task(struct work_struct *work);
  327. static void set_addresses(struct net_device *dev);
  328. static void set_multicast_list(struct net_device *dev);
  329. static int set_card_type(struct pcmcia_device *link, const void *s);
  330. static int do_config(struct net_device *dev, struct ifmap *map);
  331. static int do_open(struct net_device *dev);
  332. static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  333. static const struct ethtool_ops netdev_ethtool_ops;
  334. static void hardreset(struct net_device *dev);
  335. static void do_reset(struct net_device *dev, int full);
  336. static int init_mii(struct net_device *dev);
  337. static void do_powerdown(struct net_device *dev);
  338. static int do_stop(struct net_device *dev);
  339. /*=============== Helper functions =========================*/
  340. static int
  341. first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
  342. {
  343. int err;
  344. if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
  345. (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
  346. err = pcmcia_parse_tuple(tuple, parse);
  347. return err;
  348. }
  349. static int
  350. next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
  351. {
  352. int err;
  353. if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
  354. (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
  355. err = pcmcia_parse_tuple(tuple, parse);
  356. return err;
  357. }
  358. #define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
  359. #define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
  360. #define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
  361. #define PutByte(reg,value) outb((value), ioaddr+(reg))
  362. #define PutWord(reg,value) outw((value), ioaddr+(reg))
  363. /*====== Functions used for debugging =================================*/
  364. #if defined(PCMCIA_DEBUG) && 0 /* reading regs may change system status */
  365. static void
  366. PrintRegisters(struct net_device *dev)
  367. {
  368. unsigned int ioaddr = dev->base_addr;
  369. if (pc_debug > 1) {
  370. int i, page;
  371. printk(KDBG_XIRC "Register common: ");
  372. for (i = 0; i < 8; i++)
  373. printk(" %2.2x", GetByte(i));
  374. printk("\n");
  375. for (page = 0; page <= 8; page++) {
  376. printk(KDBG_XIRC "Register page %2x: ", page);
  377. SelectPage(page);
  378. for (i = 8; i < 16; i++)
  379. printk(" %2.2x", GetByte(i));
  380. printk("\n");
  381. }
  382. for (page=0x40 ; page <= 0x5f; page++) {
  383. if (page == 0x43 || (page >= 0x46 && page <= 0x4f)
  384. || (page >= 0x51 && page <=0x5e))
  385. continue;
  386. printk(KDBG_XIRC "Register page %2x: ", page);
  387. SelectPage(page);
  388. for (i = 8; i < 16; i++)
  389. printk(" %2.2x", GetByte(i));
  390. printk("\n");
  391. }
  392. }
  393. }
  394. #endif /* PCMCIA_DEBUG */
  395. /*============== MII Management functions ===============*/
  396. /****************
  397. * Turn around for read
  398. */
  399. static void
  400. mii_idle(unsigned int ioaddr)
  401. {
  402. PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
  403. udelay(1);
  404. PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
  405. udelay(1);
  406. }
  407. /****************
  408. * Write a bit to MDI/O
  409. */
  410. static void
  411. mii_putbit(unsigned int ioaddr, unsigned data)
  412. {
  413. #if 1
  414. if (data) {
  415. PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
  416. udelay(1);
  417. PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
  418. udelay(1);
  419. } else {
  420. PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
  421. udelay(1);
  422. PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
  423. udelay(1);
  424. }
  425. #else
  426. if (data) {
  427. PutWord(XIRCREG2_GPR2-1, 0x0e0e);
  428. udelay(1);
  429. PutWord(XIRCREG2_GPR2-1, 0x0f0f);
  430. udelay(1);
  431. } else {
  432. PutWord(XIRCREG2_GPR2-1, 0x0c0c);
  433. udelay(1);
  434. PutWord(XIRCREG2_GPR2-1, 0x0d0d);
  435. udelay(1);
  436. }
  437. #endif
  438. }
  439. /****************
  440. * Get a bit from MDI/O
  441. */
  442. static int
  443. mii_getbit(unsigned int ioaddr)
  444. {
  445. unsigned d;
  446. PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
  447. udelay(1);
  448. d = GetByte(XIRCREG2_GPR2); /* read MDIO */
  449. PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
  450. udelay(1);
  451. return d & 0x20; /* read MDIO */
  452. }
  453. static void
  454. mii_wbits(unsigned int ioaddr, unsigned data, int len)
  455. {
  456. unsigned m = 1 << (len-1);
  457. for (; m; m >>= 1)
  458. mii_putbit(ioaddr, data & m);
  459. }
  460. static unsigned
  461. mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg)
  462. {
  463. int i;
  464. unsigned data=0, m;
  465. SelectPage(2);
  466. for (i=0; i < 32; i++) /* 32 bit preamble */
  467. mii_putbit(ioaddr, 1);
  468. mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */
  469. mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
  470. mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */
  471. mii_idle(ioaddr); /* turn around */
  472. mii_getbit(ioaddr);
  473. for (m = 1<<15; m; m >>= 1)
  474. if (mii_getbit(ioaddr))
  475. data |= m;
  476. mii_idle(ioaddr);
  477. return data;
  478. }
  479. static void
  480. mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data,
  481. int len)
  482. {
  483. int i;
  484. SelectPage(2);
  485. for (i=0; i < 32; i++) /* 32 bit preamble */
  486. mii_putbit(ioaddr, 1);
  487. mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */
  488. mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
  489. mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */
  490. mii_putbit(ioaddr, 1); /* turn around */
  491. mii_putbit(ioaddr, 0);
  492. mii_wbits(ioaddr, data, len); /* And write the data */
  493. mii_idle(ioaddr);
  494. }
  495. /*============= Main bulk of functions =========================*/
  496. static const struct net_device_ops netdev_ops = {
  497. .ndo_open = do_open,
  498. .ndo_stop = do_stop,
  499. .ndo_start_xmit = do_start_xmit,
  500. .ndo_tx_timeout = xirc_tx_timeout,
  501. .ndo_set_config = do_config,
  502. .ndo_do_ioctl = do_ioctl,
  503. .ndo_set_multicast_list = set_multicast_list,
  504. .ndo_change_mtu = eth_change_mtu,
  505. .ndo_set_mac_address = eth_mac_addr,
  506. .ndo_validate_addr = eth_validate_addr,
  507. };
  508. /****************
  509. * xirc2ps_attach() creates an "instance" of the driver, allocating
  510. * local data structures for one device. The device is registered
  511. * with Card Services.
  512. *
  513. * The dev_link structure is initialized, but we don't actually
  514. * configure the card at this point -- we wait until we receive a
  515. * card insertion event.
  516. */
  517. static int
  518. xirc2ps_probe(struct pcmcia_device *link)
  519. {
  520. struct net_device *dev;
  521. local_info_t *local;
  522. DEBUG(0, "attach()\n");
  523. /* Allocate the device structure */
  524. dev = alloc_etherdev(sizeof(local_info_t));
  525. if (!dev)
  526. return -ENOMEM;
  527. local = netdev_priv(dev);
  528. local->dev = dev;
  529. local->p_dev = link;
  530. link->priv = dev;
  531. /* General socket configuration */
  532. link->conf.Attributes = CONF_ENABLE_IRQ;
  533. link->conf.IntType = INT_MEMORY_AND_IO;
  534. link->conf.ConfigIndex = 1;
  535. link->irq.Handler = xirc2ps_interrupt;
  536. link->irq.Instance = dev;
  537. /* Fill in card specific entries */
  538. dev->netdev_ops = &netdev_ops;
  539. dev->ethtool_ops = &netdev_ethtool_ops;
  540. dev->watchdog_timeo = TX_TIMEOUT;
  541. INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
  542. return xirc2ps_config(link);
  543. } /* xirc2ps_attach */
  544. /****************
  545. * This deletes a driver "instance". The device is de-registered
  546. * with Card Services. If it has been released, all local data
  547. * structures are freed. Otherwise, the structures will be freed
  548. * when the device is released.
  549. */
  550. static void
  551. xirc2ps_detach(struct pcmcia_device *link)
  552. {
  553. struct net_device *dev = link->priv;
  554. DEBUG(0, "detach(0x%p)\n", link);
  555. if (link->dev_node)
  556. unregister_netdev(dev);
  557. xirc2ps_release(link);
  558. free_netdev(dev);
  559. } /* xirc2ps_detach */
  560. /****************
  561. * Detect the type of the card. s is the buffer with the data of tuple 0x20
  562. * Returns: 0 := not supported
  563. * mediaid=11 and prodid=47
  564. * Media-Id bits:
  565. * Ethernet 0x01
  566. * Tokenring 0x02
  567. * Arcnet 0x04
  568. * Wireless 0x08
  569. * Modem 0x10
  570. * GSM only 0x20
  571. * Prod-Id bits:
  572. * Pocket 0x10
  573. * External 0x20
  574. * Creditcard 0x40
  575. * Cardbus 0x80
  576. *
  577. */
  578. static int
  579. set_card_type(struct pcmcia_device *link, const void *s)
  580. {
  581. struct net_device *dev = link->priv;
  582. local_info_t *local = netdev_priv(dev);
  583. #ifdef PCMCIA_DEBUG
  584. unsigned cisrev = ((const unsigned char *)s)[2];
  585. #endif
  586. unsigned mediaid= ((const unsigned char *)s)[3];
  587. unsigned prodid = ((const unsigned char *)s)[4];
  588. DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n",
  589. cisrev, mediaid, prodid);
  590. local->mohawk = 0;
  591. local->dingo = 0;
  592. local->modem = 0;
  593. local->card_type = XIR_UNKNOWN;
  594. if (!(prodid & 0x40)) {
  595. printk(KNOT_XIRC "Ooops: Not a creditcard\n");
  596. return 0;
  597. }
  598. if (!(mediaid & 0x01)) {
  599. printk(KNOT_XIRC "Not an Ethernet card\n");
  600. return 0;
  601. }
  602. if (mediaid & 0x10) {
  603. local->modem = 1;
  604. switch(prodid & 15) {
  605. case 1: local->card_type = XIR_CEM ; break;
  606. case 2: local->card_type = XIR_CEM2 ; break;
  607. case 3: local->card_type = XIR_CEM3 ; break;
  608. case 4: local->card_type = XIR_CEM33 ; break;
  609. case 5: local->card_type = XIR_CEM56M;
  610. local->mohawk = 1;
  611. break;
  612. case 6:
  613. case 7: /* 7 is the RealPort 10/56 */
  614. local->card_type = XIR_CEM56 ;
  615. local->mohawk = 1;
  616. local->dingo = 1;
  617. break;
  618. }
  619. } else {
  620. switch(prodid & 15) {
  621. case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
  622. break;
  623. case 2: local->card_type = XIR_CE2; break;
  624. case 3: local->card_type = XIR_CE3;
  625. local->mohawk = 1;
  626. break;
  627. }
  628. }
  629. if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
  630. printk(KNOT_XIRC "Sorry, this is an old CE card\n");
  631. return 0;
  632. }
  633. if (local->card_type == XIR_UNKNOWN)
  634. printk(KNOT_XIRC "unknown card (mediaid=%02x prodid=%02x)\n",
  635. mediaid, prodid);
  636. return 1;
  637. }
  638. /****************
  639. * There are some CE2 cards out which claim to be a CE card.
  640. * This function looks for a "CE2" in the 3rd version field.
  641. * Returns: true if this is a CE2
  642. */
  643. static int
  644. has_ce2_string(struct pcmcia_device * p_dev)
  645. {
  646. if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
  647. return 1;
  648. return 0;
  649. }
  650. static int
  651. xirc2ps_config_modem(struct pcmcia_device *p_dev,
  652. cistpl_cftable_entry_t *cf,
  653. cistpl_cftable_entry_t *dflt,
  654. unsigned int vcc,
  655. void *priv_data)
  656. {
  657. unsigned int ioaddr;
  658. if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
  659. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  660. p_dev->io.BasePort2 = cf->io.win[0].base;
  661. p_dev->io.BasePort1 = ioaddr;
  662. if (!pcmcia_request_io(p_dev, &p_dev->io))
  663. return 0;
  664. }
  665. }
  666. return -ENODEV;
  667. }
  668. static int
  669. xirc2ps_config_check(struct pcmcia_device *p_dev,
  670. cistpl_cftable_entry_t *cf,
  671. cistpl_cftable_entry_t *dflt,
  672. unsigned int vcc,
  673. void *priv_data)
  674. {
  675. int *pass = priv_data;
  676. if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
  677. p_dev->io.BasePort2 = cf->io.win[0].base;
  678. p_dev->io.BasePort1 = p_dev->io.BasePort2
  679. + (*pass ? (cf->index & 0x20 ? -24:8)
  680. : (cf->index & 0x20 ? 8:-24));
  681. if (!pcmcia_request_io(p_dev, &p_dev->io))
  682. return 0;
  683. }
  684. return -ENODEV;
  685. }
  686. /****************
  687. * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
  688. * is received, to configure the PCMCIA socket, and to make the
  689. * ethernet device available to the system.
  690. */
  691. static int
  692. xirc2ps_config(struct pcmcia_device * link)
  693. {
  694. struct net_device *dev = link->priv;
  695. local_info_t *local = netdev_priv(dev);
  696. unsigned int ioaddr;
  697. tuple_t tuple;
  698. cisparse_t parse;
  699. int err, i;
  700. u_char buf[64];
  701. cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
  702. local->dingo_ccr = NULL;
  703. DEBUG(0, "config(0x%p)\n", link);
  704. /*
  705. * This reads the card's CONFIG tuple to find its configuration
  706. * registers.
  707. */
  708. tuple.Attributes = 0;
  709. tuple.TupleData = buf;
  710. tuple.TupleDataMax = 64;
  711. tuple.TupleOffset = 0;
  712. /* Is this a valid card */
  713. tuple.DesiredTuple = CISTPL_MANFID;
  714. if ((err=first_tuple(link, &tuple, &parse))) {
  715. printk(KNOT_XIRC "manfid not found in CIS\n");
  716. goto failure;
  717. }
  718. switch(parse.manfid.manf) {
  719. case MANFID_XIRCOM:
  720. local->manf_str = "Xircom";
  721. break;
  722. case MANFID_ACCTON:
  723. local->manf_str = "Accton";
  724. break;
  725. case MANFID_COMPAQ:
  726. case MANFID_COMPAQ2:
  727. local->manf_str = "Compaq";
  728. break;
  729. case MANFID_INTEL:
  730. local->manf_str = "Intel";
  731. break;
  732. case MANFID_TOSHIBA:
  733. local->manf_str = "Toshiba";
  734. break;
  735. default:
  736. printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
  737. (unsigned)parse.manfid.manf);
  738. goto failure;
  739. }
  740. DEBUG(0, "found %s card\n", local->manf_str);
  741. if (!set_card_type(link, buf)) {
  742. printk(KNOT_XIRC "this card is not supported\n");
  743. goto failure;
  744. }
  745. /* get the ethernet address from the CIS */
  746. tuple.DesiredTuple = CISTPL_FUNCE;
  747. for (err = first_tuple(link, &tuple, &parse); !err;
  748. err = next_tuple(link, &tuple, &parse)) {
  749. /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
  750. * the first one with a length of zero the second correct -
  751. * so I skip all entries with length 0 */
  752. if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID
  753. && ((cistpl_lan_node_id_t *)parse.funce.data)->nb)
  754. break;
  755. }
  756. if (err) { /* not found: try to get the node-id from tuple 0x89 */
  757. tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */
  758. if ((err = pcmcia_get_first_tuple(link, &tuple)) == 0 &&
  759. (err = pcmcia_get_tuple_data(link, &tuple)) == 0) {
  760. if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
  761. memcpy(&parse, buf, 8);
  762. else
  763. err = -1;
  764. }
  765. }
  766. if (err) { /* another try (James Lehmer's CE2 version 4.1)*/
  767. tuple.DesiredTuple = CISTPL_FUNCE;
  768. for (err = first_tuple(link, &tuple, &parse); !err;
  769. err = next_tuple(link, &tuple, &parse)) {
  770. if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
  771. && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
  772. buf[1] = 4;
  773. memcpy(&parse, buf+1, 8);
  774. break;
  775. }
  776. }
  777. }
  778. if (err) {
  779. printk(KNOT_XIRC "node-id not found in CIS\n");
  780. goto failure;
  781. }
  782. node_id = (cistpl_lan_node_id_t *)parse.funce.data;
  783. if (node_id->nb != 6) {
  784. printk(KNOT_XIRC "malformed node-id in CIS\n");
  785. goto failure;
  786. }
  787. for (i=0; i < 6; i++)
  788. dev->dev_addr[i] = node_id->id[i];
  789. link->io.IOAddrLines =10;
  790. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  791. link->irq.Attributes = IRQ_HANDLE_PRESENT;
  792. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  793. if (local->modem) {
  794. int pass;
  795. if (do_sound) {
  796. link->conf.Attributes |= CONF_ENABLE_SPKR;
  797. link->conf.Status |= CCSR_AUDIO_ENA;
  798. }
  799. link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED ;
  800. link->io.NumPorts2 = 8;
  801. link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
  802. if (local->dingo) {
  803. /* Take the Modem IO port from the CIS and scan for a free
  804. * Ethernet port */
  805. link->io.NumPorts1 = 16; /* no Mako stuff anymore */
  806. if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
  807. goto port_found;
  808. } else {
  809. link->io.NumPorts1 = 18;
  810. /* We do 2 passes here: The first one uses the regular mapping and
  811. * the second tries again, thereby considering that the 32 ports are
  812. * mirrored every 32 bytes. Actually we use a mirrored port for
  813. * the Mako if (on the first pass) the COR bit 5 is set.
  814. */
  815. for (pass=0; pass < 2; pass++)
  816. if (!pcmcia_loop_config(link, xirc2ps_config_check, &pass))
  817. goto port_found;
  818. /* if special option:
  819. * try to configure as Ethernet only.
  820. * .... */
  821. }
  822. printk(KNOT_XIRC "no ports available\n");
  823. } else {
  824. link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
  825. link->io.NumPorts1 = 16;
  826. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  827. link->io.BasePort1 = ioaddr;
  828. if (!(err=pcmcia_request_io(link, &link->io)))
  829. goto port_found;
  830. }
  831. link->io.BasePort1 = 0; /* let CS decide */
  832. if ((err=pcmcia_request_io(link, &link->io))) {
  833. cs_error(link, RequestIO, err);
  834. goto config_error;
  835. }
  836. }
  837. port_found:
  838. if (err)
  839. goto config_error;
  840. /****************
  841. * Now allocate an interrupt line. Note that this does not
  842. * actually assign a handler to the interrupt.
  843. */
  844. if ((err=pcmcia_request_irq(link, &link->irq))) {
  845. cs_error(link, RequestIRQ, err);
  846. goto config_error;
  847. }
  848. /****************
  849. * This actually configures the PCMCIA socket -- setting up
  850. * the I/O windows and the interrupt mapping.
  851. */
  852. if ((err=pcmcia_request_configuration(link, &link->conf))) {
  853. cs_error(link, RequestConfiguration, err);
  854. goto config_error;
  855. }
  856. if (local->dingo) {
  857. conf_reg_t reg;
  858. win_req_t req;
  859. memreq_t mem;
  860. /* Reset the modem's BAR to the correct value
  861. * This is necessary because in the RequestConfiguration call,
  862. * the base address of the ethernet port (BasePort1) is written
  863. * to the BAR registers of the modem.
  864. */
  865. reg.Action = CS_WRITE;
  866. reg.Offset = CISREG_IOBASE_0;
  867. reg.Value = link->io.BasePort2 & 0xff;
  868. if ((err = pcmcia_access_configuration_register(link, &reg))) {
  869. cs_error(link, AccessConfigurationRegister, err);
  870. goto config_error;
  871. }
  872. reg.Action = CS_WRITE;
  873. reg.Offset = CISREG_IOBASE_1;
  874. reg.Value = (link->io.BasePort2 >> 8) & 0xff;
  875. if ((err = pcmcia_access_configuration_register(link, &reg))) {
  876. cs_error(link, AccessConfigurationRegister, err);
  877. goto config_error;
  878. }
  879. /* There is no config entry for the Ethernet part which
  880. * is at 0x0800. So we allocate a window into the attribute
  881. * memory and write direct to the CIS registers
  882. */
  883. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  884. req.Base = req.Size = 0;
  885. req.AccessSpeed = 0;
  886. if ((err = pcmcia_request_window(&link, &req, &link->win))) {
  887. cs_error(link, RequestWindow, err);
  888. goto config_error;
  889. }
  890. local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
  891. mem.CardOffset = 0x0;
  892. mem.Page = 0;
  893. if ((err = pcmcia_map_mem_page(link->win, &mem))) {
  894. cs_error(link, MapMemPage, err);
  895. goto config_error;
  896. }
  897. /* Setup the CCRs; there are no infos in the CIS about the Ethernet
  898. * part.
  899. */
  900. writeb(0x47, local->dingo_ccr + CISREG_COR);
  901. ioaddr = link->io.BasePort1;
  902. writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
  903. writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
  904. #if 0
  905. {
  906. u_char tmp;
  907. printk(KERN_INFO "ECOR:");
  908. for (i=0; i < 7; i++) {
  909. tmp = readb(local->dingo_ccr + i*2);
  910. printk(" %02x", tmp);
  911. }
  912. printk("\n");
  913. printk(KERN_INFO "DCOR:");
  914. for (i=0; i < 4; i++) {
  915. tmp = readb(local->dingo_ccr + 0x20 + i*2);
  916. printk(" %02x", tmp);
  917. }
  918. printk("\n");
  919. printk(KERN_INFO "SCOR:");
  920. for (i=0; i < 10; i++) {
  921. tmp = readb(local->dingo_ccr + 0x40 + i*2);
  922. printk(" %02x", tmp);
  923. }
  924. printk("\n");
  925. }
  926. #endif
  927. writeb(0x01, local->dingo_ccr + 0x20);
  928. writeb(0x0c, local->dingo_ccr + 0x22);
  929. writeb(0x00, local->dingo_ccr + 0x24);
  930. writeb(0x00, local->dingo_ccr + 0x26);
  931. writeb(0x00, local->dingo_ccr + 0x28);
  932. }
  933. /* The if_port symbol can be set when the module is loaded */
  934. local->probe_port=0;
  935. if (!if_port) {
  936. local->probe_port = dev->if_port = 1;
  937. } else if ((if_port >= 1 && if_port <= 2) ||
  938. (local->mohawk && if_port==4))
  939. dev->if_port = if_port;
  940. else
  941. printk(KNOT_XIRC "invalid if_port requested\n");
  942. /* we can now register the device with the net subsystem */
  943. dev->irq = link->irq.AssignedIRQ;
  944. dev->base_addr = link->io.BasePort1;
  945. if (local->dingo)
  946. do_reset(dev, 1); /* a kludge to make the cem56 work */
  947. link->dev_node = &local->node;
  948. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  949. if ((err=register_netdev(dev))) {
  950. printk(KNOT_XIRC "register_netdev() failed\n");
  951. link->dev_node = NULL;
  952. goto config_error;
  953. }
  954. strcpy(local->node.dev_name, dev->name);
  955. /* give some infos about the hardware */
  956. printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr %pM\n",
  957. dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq,
  958. dev->dev_addr);
  959. return 0;
  960. config_error:
  961. xirc2ps_release(link);
  962. return -ENODEV;
  963. failure:
  964. return -ENODEV;
  965. } /* xirc2ps_config */
  966. /****************
  967. * After a card is removed, xirc2ps_release() will unregister the net
  968. * device, and release the PCMCIA configuration. If the device is
  969. * still open, this will be postponed until it is closed.
  970. */
  971. static void
  972. xirc2ps_release(struct pcmcia_device *link)
  973. {
  974. DEBUG(0, "release(0x%p)\n", link);
  975. if (link->win) {
  976. struct net_device *dev = link->priv;
  977. local_info_t *local = netdev_priv(dev);
  978. if (local->dingo)
  979. iounmap(local->dingo_ccr - 0x0800);
  980. }
  981. pcmcia_disable_device(link);
  982. } /* xirc2ps_release */
  983. /*====================================================================*/
  984. static int xirc2ps_suspend(struct pcmcia_device *link)
  985. {
  986. struct net_device *dev = link->priv;
  987. if (link->open) {
  988. netif_device_detach(dev);
  989. do_powerdown(dev);
  990. }
  991. return 0;
  992. }
  993. static int xirc2ps_resume(struct pcmcia_device *link)
  994. {
  995. struct net_device *dev = link->priv;
  996. if (link->open) {
  997. do_reset(dev,1);
  998. netif_device_attach(dev);
  999. }
  1000. return 0;
  1001. }
  1002. /*====================================================================*/
  1003. /****************
  1004. * This is the Interrupt service route.
  1005. */
  1006. static irqreturn_t
  1007. xirc2ps_interrupt(int irq, void *dev_id)
  1008. {
  1009. struct net_device *dev = (struct net_device *)dev_id;
  1010. local_info_t *lp = netdev_priv(dev);
  1011. unsigned int ioaddr;
  1012. u_char saved_page;
  1013. unsigned bytes_rcvd;
  1014. unsigned int_status, eth_status, rx_status, tx_status;
  1015. unsigned rsr, pktlen;
  1016. ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
  1017. * is this something to worry about?
  1018. * -- on a laptop?
  1019. */
  1020. if (!netif_device_present(dev))
  1021. return IRQ_HANDLED;
  1022. ioaddr = dev->base_addr;
  1023. if (lp->mohawk) { /* must disable the interrupt */
  1024. PutByte(XIRCREG_CR, 0);
  1025. }
  1026. DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
  1027. saved_page = GetByte(XIRCREG_PR);
  1028. /* Read the ISR to see whats the cause for the interrupt.
  1029. * This also clears the interrupt flags on CE2 cards
  1030. */
  1031. int_status = GetByte(XIRCREG_ISR);
  1032. bytes_rcvd = 0;
  1033. loop_entry:
  1034. if (int_status == 0xff) { /* card may be ejected */
  1035. DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq);
  1036. goto leave;
  1037. }
  1038. eth_status = GetByte(XIRCREG_ESR);
  1039. SelectPage(0x40);
  1040. rx_status = GetByte(XIRCREG40_RXST0);
  1041. PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
  1042. tx_status = GetByte(XIRCREG40_TXST0);
  1043. tx_status |= GetByte(XIRCREG40_TXST1) << 8;
  1044. PutByte(XIRCREG40_TXST0, 0);
  1045. PutByte(XIRCREG40_TXST1, 0);
  1046. DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
  1047. dev->name, int_status, eth_status, rx_status, tx_status);
  1048. /***** receive section ******/
  1049. SelectPage(0);
  1050. while (eth_status & FullPktRcvd) {
  1051. rsr = GetByte(XIRCREG0_RSR);
  1052. if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
  1053. /* too many bytes received during this int, drop the rest of the
  1054. * packets */
  1055. dev->stats.rx_dropped++;
  1056. DEBUG(2, "%s: RX drop, too much done\n", dev->name);
  1057. } else if (rsr & PktRxOk) {
  1058. struct sk_buff *skb;
  1059. pktlen = GetWord(XIRCREG0_RBC);
  1060. bytes_rcvd += pktlen;
  1061. DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen);
  1062. skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
  1063. if (!skb) {
  1064. printk(KNOT_XIRC "low memory, packet dropped (size=%u)\n",
  1065. pktlen);
  1066. dev->stats.rx_dropped++;
  1067. } else { /* okay get the packet */
  1068. skb_reserve(skb, 2);
  1069. if (lp->silicon == 0 ) { /* work around a hardware bug */
  1070. unsigned rhsa; /* receive start address */
  1071. SelectPage(5);
  1072. rhsa = GetWord(XIRCREG5_RHSA0);
  1073. SelectPage(0);
  1074. rhsa += 3; /* skip control infos */
  1075. if (rhsa >= 0x8000)
  1076. rhsa = 0;
  1077. if (rhsa + pktlen > 0x8000) {
  1078. unsigned i;
  1079. u_char *buf = skb_put(skb, pktlen);
  1080. for (i=0; i < pktlen ; i++, rhsa++) {
  1081. buf[i] = GetByte(XIRCREG_EDP);
  1082. if (rhsa == 0x8000) {
  1083. rhsa = 0;
  1084. i--;
  1085. }
  1086. }
  1087. } else {
  1088. insw(ioaddr+XIRCREG_EDP,
  1089. skb_put(skb, pktlen), (pktlen+1)>>1);
  1090. }
  1091. }
  1092. #if 0
  1093. else if (lp->mohawk) {
  1094. /* To use this 32 bit access we should use
  1095. * a manual optimized loop
  1096. * Also the words are swapped, we can get more
  1097. * performance by using 32 bit access and swapping
  1098. * the words in a register. Will need this for cardbus
  1099. *
  1100. * Note: don't forget to change the ALLOC_SKB to .. +3
  1101. */
  1102. unsigned i;
  1103. u_long *p = skb_put(skb, pktlen);
  1104. register u_long a;
  1105. unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
  1106. for (i=0; i < len ; i += 4, p++) {
  1107. a = inl(edpreg);
  1108. __asm__("rorl $16,%0\n\t"
  1109. :"=q" (a)
  1110. : "0" (a));
  1111. *p = a;
  1112. }
  1113. }
  1114. #endif
  1115. else {
  1116. insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
  1117. (pktlen+1)>>1);
  1118. }
  1119. skb->protocol = eth_type_trans(skb, dev);
  1120. netif_rx(skb);
  1121. dev->stats.rx_packets++;
  1122. dev->stats.rx_bytes += pktlen;
  1123. if (!(rsr & PhyPkt))
  1124. dev->stats.multicast++;
  1125. }
  1126. } else { /* bad packet */
  1127. DEBUG(5, "rsr=%#02x\n", rsr);
  1128. }
  1129. if (rsr & PktTooLong) {
  1130. dev->stats.rx_frame_errors++;
  1131. DEBUG(3, "%s: Packet too long\n", dev->name);
  1132. }
  1133. if (rsr & CRCErr) {
  1134. dev->stats.rx_crc_errors++;
  1135. DEBUG(3, "%s: CRC error\n", dev->name);
  1136. }
  1137. if (rsr & AlignErr) {
  1138. dev->stats.rx_fifo_errors++; /* okay ? */
  1139. DEBUG(3, "%s: Alignment error\n", dev->name);
  1140. }
  1141. /* clear the received/dropped/error packet */
  1142. PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
  1143. /* get the new ethernet status */
  1144. eth_status = GetByte(XIRCREG_ESR);
  1145. }
  1146. if (rx_status & 0x10) { /* Receive overrun */
  1147. dev->stats.rx_over_errors++;
  1148. PutByte(XIRCREG_CR, ClearRxOvrun);
  1149. DEBUG(3, "receive overrun cleared\n");
  1150. }
  1151. /***** transmit section ******/
  1152. if (int_status & PktTxed) {
  1153. unsigned n, nn;
  1154. n = lp->last_ptr_value;
  1155. nn = GetByte(XIRCREG0_PTR);
  1156. lp->last_ptr_value = nn;
  1157. if (nn < n) /* rollover */
  1158. dev->stats.tx_packets += 256 - n;
  1159. else if (n == nn) { /* happens sometimes - don't know why */
  1160. DEBUG(0, "PTR not changed?\n");
  1161. } else
  1162. dev->stats.tx_packets += lp->last_ptr_value - n;
  1163. netif_wake_queue(dev);
  1164. }
  1165. if (tx_status & 0x0002) { /* Execessive collissions */
  1166. DEBUG(0, "tx restarted due to execssive collissions\n");
  1167. PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
  1168. }
  1169. if (tx_status & 0x0040)
  1170. dev->stats.tx_aborted_errors++;
  1171. /* recalculate our work chunk so that we limit the duration of this
  1172. * ISR to about 1/10 of a second.
  1173. * Calculate only if we received a reasonable amount of bytes.
  1174. */
  1175. if (bytes_rcvd > 1000) {
  1176. u_long duration = jiffies - start_ticks;
  1177. if (duration >= HZ/10) { /* if more than about 1/10 second */
  1178. maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
  1179. if (maxrx_bytes < 2000)
  1180. maxrx_bytes = 2000;
  1181. else if (maxrx_bytes > 22000)
  1182. maxrx_bytes = 22000;
  1183. DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n",
  1184. maxrx_bytes, bytes_rcvd, duration);
  1185. } else if (!duration && maxrx_bytes < 22000) {
  1186. /* now much faster */
  1187. maxrx_bytes += 2000;
  1188. if (maxrx_bytes > 22000)
  1189. maxrx_bytes = 22000;
  1190. DEBUG(1, "set maxrx=%u\n", maxrx_bytes);
  1191. }
  1192. }
  1193. leave:
  1194. if (lockup_hack) {
  1195. if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
  1196. goto loop_entry;
  1197. }
  1198. SelectPage(saved_page);
  1199. PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */
  1200. /* Instead of dropping packets during a receive, we could
  1201. * force an interrupt with this command:
  1202. * PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
  1203. */
  1204. return IRQ_HANDLED;
  1205. } /* xirc2ps_interrupt */
  1206. /*====================================================================*/
  1207. static void
  1208. xirc2ps_tx_timeout_task(struct work_struct *work)
  1209. {
  1210. local_info_t *local =
  1211. container_of(work, local_info_t, tx_timeout_task);
  1212. struct net_device *dev = local->dev;
  1213. /* reset the card */
  1214. do_reset(dev,1);
  1215. dev->trans_start = jiffies;
  1216. netif_wake_queue(dev);
  1217. }
  1218. static void
  1219. xirc_tx_timeout(struct net_device *dev)
  1220. {
  1221. local_info_t *lp = netdev_priv(dev);
  1222. dev->stats.tx_errors++;
  1223. printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
  1224. schedule_work(&lp->tx_timeout_task);
  1225. }
  1226. static int
  1227. do_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1228. {
  1229. local_info_t *lp = netdev_priv(dev);
  1230. unsigned int ioaddr = dev->base_addr;
  1231. int okay;
  1232. unsigned freespace;
  1233. unsigned pktlen = skb->len;
  1234. DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n",
  1235. skb, dev, pktlen);
  1236. /* adjust the packet length to min. required
  1237. * and hope that the buffer is large enough
  1238. * to provide some random data.
  1239. * fixme: For Mohawk we can change this by sending
  1240. * a larger packetlen than we actually have; the chip will
  1241. * pad this in his buffer with random bytes
  1242. */
  1243. if (pktlen < ETH_ZLEN)
  1244. {
  1245. if (skb_padto(skb, ETH_ZLEN))
  1246. return 0;
  1247. pktlen = ETH_ZLEN;
  1248. }
  1249. netif_stop_queue(dev);
  1250. SelectPage(0);
  1251. PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
  1252. freespace = GetWord(XIRCREG0_TSO);
  1253. okay = freespace & 0x8000;
  1254. freespace &= 0x7fff;
  1255. /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
  1256. okay = pktlen +2 < freespace;
  1257. DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n",
  1258. dev->name, freespace, okay ? " (okay)":" (not enough)");
  1259. if (!okay) { /* not enough space */
  1260. return 1; /* upper layer may decide to requeue this packet */
  1261. }
  1262. /* send the packet */
  1263. PutWord(XIRCREG_EDP, (u_short)pktlen);
  1264. outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
  1265. if (pktlen & 1)
  1266. PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
  1267. if (lp->mohawk)
  1268. PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
  1269. dev_kfree_skb (skb);
  1270. dev->trans_start = jiffies;
  1271. dev->stats.tx_bytes += pktlen;
  1272. netif_start_queue(dev);
  1273. return 0;
  1274. }
  1275. /****************
  1276. * Set all addresses: This first one is the individual address,
  1277. * the next 9 addresses are taken from the multicast list and
  1278. * the rest is filled with the individual address.
  1279. */
  1280. static void
  1281. set_addresses(struct net_device *dev)
  1282. {
  1283. unsigned int ioaddr = dev->base_addr;
  1284. local_info_t *lp = netdev_priv(dev);
  1285. struct dev_mc_list *dmi = dev->mc_list;
  1286. unsigned char *addr;
  1287. int i,j,k,n;
  1288. SelectPage(k=0x50);
  1289. for (i=0,j=8,n=0; ; i++, j++) {
  1290. if (i > 5) {
  1291. if (++n > 9)
  1292. break;
  1293. i = 0;
  1294. if (n > 1 && n <= dev->mc_count && dmi) {
  1295. dmi = dmi->next;
  1296. }
  1297. }
  1298. if (j > 15) {
  1299. j = 8;
  1300. k++;
  1301. SelectPage(k);
  1302. }
  1303. if (n && n <= dev->mc_count && dmi)
  1304. addr = dmi->dmi_addr;
  1305. else
  1306. addr = dev->dev_addr;
  1307. if (lp->mohawk)
  1308. PutByte(j, addr[5-i]);
  1309. else
  1310. PutByte(j, addr[i]);
  1311. }
  1312. SelectPage(0);
  1313. }
  1314. /****************
  1315. * Set or clear the multicast filter for this adaptor.
  1316. * We can filter up to 9 addresses, if more are requested we set
  1317. * multicast promiscuous mode.
  1318. */
  1319. static void
  1320. set_multicast_list(struct net_device *dev)
  1321. {
  1322. unsigned int ioaddr = dev->base_addr;
  1323. unsigned value;
  1324. SelectPage(0x42);
  1325. value = GetByte(XIRCREG42_SWC1) & 0xC0;
  1326. if (dev->flags & IFF_PROMISC) { /* snoop */
  1327. PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */
  1328. } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
  1329. PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */
  1330. } else if (dev->mc_count) {
  1331. /* the chip can filter 9 addresses perfectly */
  1332. PutByte(XIRCREG42_SWC1, value | 0x01);
  1333. SelectPage(0x40);
  1334. PutByte(XIRCREG40_CMD0, Offline);
  1335. set_addresses(dev);
  1336. SelectPage(0x40);
  1337. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1338. } else { /* standard usage */
  1339. PutByte(XIRCREG42_SWC1, value | 0x00);
  1340. }
  1341. SelectPage(0);
  1342. }
  1343. static int
  1344. do_config(struct net_device *dev, struct ifmap *map)
  1345. {
  1346. local_info_t *local = netdev_priv(dev);
  1347. DEBUG(0, "do_config(%p)\n", dev);
  1348. if (map->port != 255 && map->port != dev->if_port) {
  1349. if (map->port > 4)
  1350. return -EINVAL;
  1351. if (!map->port) {
  1352. local->probe_port = 1;
  1353. dev->if_port = 1;
  1354. } else {
  1355. local->probe_port = 0;
  1356. dev->if_port = map->port;
  1357. }
  1358. printk(KERN_INFO "%s: switching to %s port\n",
  1359. dev->name, if_names[dev->if_port]);
  1360. do_reset(dev,1); /* not the fine way :-) */
  1361. }
  1362. return 0;
  1363. }
  1364. /****************
  1365. * Open the driver
  1366. */
  1367. static int
  1368. do_open(struct net_device *dev)
  1369. {
  1370. local_info_t *lp = netdev_priv(dev);
  1371. struct pcmcia_device *link = lp->p_dev;
  1372. DEBUG(0, "do_open(%p)\n", dev);
  1373. /* Check that the PCMCIA card is still here. */
  1374. /* Physical device present signature. */
  1375. if (!pcmcia_dev_present(link))
  1376. return -ENODEV;
  1377. /* okay */
  1378. link->open++;
  1379. netif_start_queue(dev);
  1380. do_reset(dev,1);
  1381. return 0;
  1382. }
  1383. static void netdev_get_drvinfo(struct net_device *dev,
  1384. struct ethtool_drvinfo *info)
  1385. {
  1386. strcpy(info->driver, "xirc2ps_cs");
  1387. sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
  1388. }
  1389. static const struct ethtool_ops netdev_ethtool_ops = {
  1390. .get_drvinfo = netdev_get_drvinfo,
  1391. };
  1392. static int
  1393. do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1394. {
  1395. local_info_t *local = netdev_priv(dev);
  1396. unsigned int ioaddr = dev->base_addr;
  1397. u16 *data = (u16 *)&rq->ifr_ifru;
  1398. DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
  1399. dev->name, rq->ifr_ifrn.ifrn_name, cmd,
  1400. data[0], data[1], data[2], data[3]);
  1401. if (!local->mohawk)
  1402. return -EOPNOTSUPP;
  1403. switch(cmd) {
  1404. case SIOCGMIIPHY: /* Get the address of the PHY in use. */
  1405. data[0] = 0; /* we have only this address */
  1406. /* fall through */
  1407. case SIOCGMIIREG: /* Read the specified MII register. */
  1408. data[3] = mii_rd(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
  1409. break;
  1410. case SIOCSMIIREG: /* Write the specified MII register */
  1411. if (!capable(CAP_NET_ADMIN))
  1412. return -EPERM;
  1413. mii_wr(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2], 16);
  1414. break;
  1415. default:
  1416. return -EOPNOTSUPP;
  1417. }
  1418. return 0;
  1419. }
  1420. static void
  1421. hardreset(struct net_device *dev)
  1422. {
  1423. local_info_t *local = netdev_priv(dev);
  1424. unsigned int ioaddr = dev->base_addr;
  1425. SelectPage(4);
  1426. udelay(1);
  1427. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1428. msleep(40); /* wait 40 msec */
  1429. if (local->mohawk)
  1430. PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */
  1431. else
  1432. PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */
  1433. msleep(20); /* wait 20 msec */
  1434. }
  1435. static void
  1436. do_reset(struct net_device *dev, int full)
  1437. {
  1438. local_info_t *local = netdev_priv(dev);
  1439. unsigned int ioaddr = dev->base_addr;
  1440. unsigned value;
  1441. DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
  1442. hardreset(dev);
  1443. PutByte(XIRCREG_CR, SoftReset); /* set */
  1444. msleep(20); /* wait 20 msec */
  1445. PutByte(XIRCREG_CR, 0); /* clear */
  1446. msleep(40); /* wait 40 msec */
  1447. if (local->mohawk) {
  1448. SelectPage(4);
  1449. /* set pin GP1 and GP2 to output (0x0c)
  1450. * set GP1 to low to power up the ML6692 (0x00)
  1451. * set GP2 to high to power up the 10Mhz chip (0x02)
  1452. */
  1453. PutByte(XIRCREG4_GPR0, 0x0e);
  1454. }
  1455. /* give the circuits some time to power up */
  1456. msleep(500); /* about 500ms */
  1457. local->last_ptr_value = 0;
  1458. local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
  1459. : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
  1460. if (local->probe_port) {
  1461. if (!local->mohawk) {
  1462. SelectPage(4);
  1463. PutByte(XIRCREG4_GPR0, 4);
  1464. local->probe_port = 0;
  1465. }
  1466. } else if (dev->if_port == 2) { /* enable 10Base2 */
  1467. SelectPage(0x42);
  1468. PutByte(XIRCREG42_SWC1, 0xC0);
  1469. } else { /* enable 10BaseT */
  1470. SelectPage(0x42);
  1471. PutByte(XIRCREG42_SWC1, 0x80);
  1472. }
  1473. msleep(40); /* wait 40 msec to let it complete */
  1474. #ifdef PCMCIA_DEBUG
  1475. if (pc_debug) {
  1476. SelectPage(0);
  1477. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1478. printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
  1479. }
  1480. #endif
  1481. /* setup the ECR */
  1482. SelectPage(1);
  1483. PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
  1484. PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */
  1485. value = GetByte(XIRCREG1_ECR);
  1486. #if 0
  1487. if (local->mohawk)
  1488. value |= DisableLinkPulse;
  1489. PutByte(XIRCREG1_ECR, value);
  1490. #endif
  1491. DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value);
  1492. SelectPage(0x42);
  1493. PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
  1494. if (local->silicon != 1) {
  1495. /* set the local memory dividing line.
  1496. * The comments in the sample code say that this is only
  1497. * settable with the scipper version 2 which is revision 0.
  1498. * Always for CE3 cards
  1499. */
  1500. SelectPage(2);
  1501. PutWord(XIRCREG2_RBS, 0x2000);
  1502. }
  1503. if (full)
  1504. set_addresses(dev);
  1505. /* Hardware workaround:
  1506. * The receive byte pointer after reset is off by 1 so we need
  1507. * to move the offset pointer back to 0.
  1508. */
  1509. SelectPage(0);
  1510. PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
  1511. /* setup MAC IMRs and clear status registers */
  1512. SelectPage(0x40); /* Bit 7 ... bit 0 */
  1513. PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
  1514. PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1515. PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
  1516. PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
  1517. PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1518. PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */
  1519. if (full && local->mohawk && init_mii(dev)) {
  1520. if (dev->if_port == 4 || local->dingo || local->new_mii) {
  1521. printk(KERN_INFO "%s: MII selected\n", dev->name);
  1522. SelectPage(2);
  1523. PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
  1524. msleep(20);
  1525. } else {
  1526. printk(KERN_INFO "%s: MII detected; using 10mbs\n",
  1527. dev->name);
  1528. SelectPage(0x42);
  1529. if (dev->if_port == 2) /* enable 10Base2 */
  1530. PutByte(XIRCREG42_SWC1, 0xC0);
  1531. else /* enable 10BaseT */
  1532. PutByte(XIRCREG42_SWC1, 0x80);
  1533. msleep(40); /* wait 40 msec to let it complete */
  1534. }
  1535. if (full_duplex)
  1536. PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
  1537. } else { /* No MII */
  1538. SelectPage(0);
  1539. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1540. dev->if_port = (value & MediaSelect) ? 1 : 2;
  1541. }
  1542. /* configure the LEDs */
  1543. SelectPage(2);
  1544. if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
  1545. PutByte(XIRCREG2_LED, 0x3b);
  1546. else /* Coax: Not-Collision and Activity */
  1547. PutByte(XIRCREG2_LED, 0x3a);
  1548. if (local->dingo)
  1549. PutByte(0x0b, 0x04); /* 100 Mbit LED */
  1550. /* enable receiver and put the mac online */
  1551. if (full) {
  1552. set_multicast_list(dev);
  1553. SelectPage(0x40);
  1554. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1555. }
  1556. /* setup Ethernet IMR and enable interrupts */
  1557. SelectPage(1);
  1558. PutByte(XIRCREG1_IMR0, 0xff);
  1559. udelay(1);
  1560. SelectPage(0);
  1561. PutByte(XIRCREG_CR, EnableIntr);
  1562. if (local->modem && !local->dingo) { /* do some magic */
  1563. if (!(GetByte(0x10) & 0x01))
  1564. PutByte(0x10, 0x11); /* unmask master-int bit */
  1565. }
  1566. if (full)
  1567. printk(KERN_INFO "%s: media %s, silicon revision %d\n",
  1568. dev->name, if_names[dev->if_port], local->silicon);
  1569. /* We should switch back to page 0 to avoid a bug in revision 0
  1570. * where regs with offset below 8 can't be read after an access
  1571. * to the MAC registers */
  1572. SelectPage(0);
  1573. }
  1574. /****************
  1575. * Initialize the Media-Independent-Interface
  1576. * Returns: True if we have a good MII
  1577. */
  1578. static int
  1579. init_mii(struct net_device *dev)
  1580. {
  1581. local_info_t *local = netdev_priv(dev);
  1582. unsigned int ioaddr = dev->base_addr;
  1583. unsigned control, status, linkpartner;
  1584. int i;
  1585. if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
  1586. dev->if_port = if_port;
  1587. local->probe_port = 0;
  1588. return 1;
  1589. }
  1590. status = mii_rd(ioaddr, 0, 1);
  1591. if ((status & 0xff00) != 0x7800)
  1592. return 0; /* No MII */
  1593. local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
  1594. if (local->probe_port)
  1595. control = 0x1000; /* auto neg */
  1596. else if (dev->if_port == 4)
  1597. control = 0x2000; /* no auto neg, 100mbs mode */
  1598. else
  1599. control = 0x0000; /* no auto neg, 10mbs mode */
  1600. mii_wr(ioaddr, 0, 0, control, 16);
  1601. udelay(100);
  1602. control = mii_rd(ioaddr, 0, 0);
  1603. if (control & 0x0400) {
  1604. printk(KERN_NOTICE "%s can't take PHY out of isolation mode\n",
  1605. dev->name);
  1606. local->probe_port = 0;
  1607. return 0;
  1608. }
  1609. if (local->probe_port) {
  1610. /* according to the DP83840A specs the auto negotiation process
  1611. * may take up to 3.5 sec, so we use this also for our ML6692
  1612. * Fixme: Better to use a timer here!
  1613. */
  1614. for (i=0; i < 35; i++) {
  1615. msleep(100); /* wait 100 msec */
  1616. status = mii_rd(ioaddr, 0, 1);
  1617. if ((status & 0x0020) && (status & 0x0004))
  1618. break;
  1619. }
  1620. if (!(status & 0x0020)) {
  1621. printk(KERN_INFO "%s: autonegotiation failed;"
  1622. " using 10mbs\n", dev->name);
  1623. if (!local->new_mii) {
  1624. control = 0x0000;
  1625. mii_wr(ioaddr, 0, 0, control, 16);
  1626. udelay(100);
  1627. SelectPage(0);
  1628. dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
  1629. }
  1630. } else {
  1631. linkpartner = mii_rd(ioaddr, 0, 5);
  1632. printk(KERN_INFO "%s: MII link partner: %04x\n",
  1633. dev->name, linkpartner);
  1634. if (linkpartner & 0x0080) {
  1635. dev->if_port = 4;
  1636. } else
  1637. dev->if_port = 1;
  1638. }
  1639. }
  1640. return 1;
  1641. }
  1642. static void
  1643. do_powerdown(struct net_device *dev)
  1644. {
  1645. unsigned int ioaddr = dev->base_addr;
  1646. DEBUG(0, "do_powerdown(%p)\n", dev);
  1647. SelectPage(4);
  1648. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1649. SelectPage(0);
  1650. }
  1651. static int
  1652. do_stop(struct net_device *dev)
  1653. {
  1654. unsigned int ioaddr = dev->base_addr;
  1655. local_info_t *lp = netdev_priv(dev);
  1656. struct pcmcia_device *link = lp->p_dev;
  1657. DEBUG(0, "do_stop(%p)\n", dev);
  1658. if (!link)
  1659. return -ENODEV;
  1660. netif_stop_queue(dev);
  1661. SelectPage(0);
  1662. PutByte(XIRCREG_CR, 0); /* disable interrupts */
  1663. SelectPage(0x01);
  1664. PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
  1665. SelectPage(4);
  1666. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1667. SelectPage(0);
  1668. link->open--;
  1669. return 0;
  1670. }
  1671. static struct pcmcia_device_id xirc2ps_ids[] = {
  1672. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
  1673. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
  1674. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
  1675. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
  1676. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
  1677. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
  1678. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
  1679. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
  1680. PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
  1681. PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
  1682. PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
  1683. PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
  1684. PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
  1685. PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
  1686. PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
  1687. PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
  1688. PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
  1689. PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
  1690. PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
  1691. /* also matches CFE-10 cards! */
  1692. /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
  1693. PCMCIA_DEVICE_NULL,
  1694. };
  1695. MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
  1696. static struct pcmcia_driver xirc2ps_cs_driver = {
  1697. .owner = THIS_MODULE,
  1698. .drv = {
  1699. .name = "xirc2ps_cs",
  1700. },
  1701. .probe = xirc2ps_probe,
  1702. .remove = xirc2ps_detach,
  1703. .id_table = xirc2ps_ids,
  1704. .suspend = xirc2ps_suspend,
  1705. .resume = xirc2ps_resume,
  1706. };
  1707. static int __init
  1708. init_xirc2ps_cs(void)
  1709. {
  1710. return pcmcia_register_driver(&xirc2ps_cs_driver);
  1711. }
  1712. static void __exit
  1713. exit_xirc2ps_cs(void)
  1714. {
  1715. pcmcia_unregister_driver(&xirc2ps_cs_driver);
  1716. }
  1717. module_init(init_xirc2ps_cs);
  1718. module_exit(exit_xirc2ps_cs);
  1719. #ifndef MODULE
  1720. static int __init setup_xirc2ps_cs(char *str)
  1721. {
  1722. /* if_port, full_duplex, do_sound, lockup_hack
  1723. */
  1724. int ints[10] = { -1 };
  1725. str = get_options(str, 9, ints);
  1726. #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
  1727. MAYBE_SET(if_port, 3);
  1728. MAYBE_SET(full_duplex, 4);
  1729. MAYBE_SET(do_sound, 5);
  1730. MAYBE_SET(lockup_hack, 6);
  1731. #undef MAYBE_SET
  1732. return 1;
  1733. }
  1734. __setup("xirc2ps_cs=", setup_xirc2ps_cs);
  1735. #endif