xirc2ps_cs.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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 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(kio_addr_t ioaddr);
  257. static void mii_putbit(kio_addr_t ioaddr, unsigned data);
  258. static int mii_getbit(kio_addr_t ioaddr);
  259. static void mii_wbits(kio_addr_t ioaddr, unsigned data, int len);
  260. static unsigned mii_rd(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg);
  261. static void mii_wr(kio_addr_t 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(dev_link_t * link);
  271. static void xirc2ps_config(dev_link_t * link);
  272. static void xirc2ps_release(dev_link_t * link);
  273. static int xirc2ps_event(event_t event, int priority,
  274. event_callback_args_t * args);
  275. /****************
  276. * The attach() and detach() entry points are used to create and destroy
  277. * "instances" of the driver, where each instance represents everything
  278. * needed to manage one actual PCMCIA card.
  279. */
  280. static dev_link_t *xirc2ps_attach(void);
  281. static void xirc2ps_detach(struct pcmcia_device *p_dev);
  282. /****************
  283. * You'll also need to prototype all the functions that will actually
  284. * be used to talk to your device. See 'pcmem_cs' for a good example
  285. * of a fully self-sufficient driver; the other drivers rely more or
  286. * less on other parts of the kernel.
  287. */
  288. static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  289. /*
  290. * The dev_info variable is the "key" that is used to match up this
  291. * device driver with appropriate cards, through the card configuration
  292. * database.
  293. */
  294. static dev_info_t dev_info = "xirc2ps_cs";
  295. /****************
  296. * A linked list of "instances" of the device. Each actual
  297. * PCMCIA card corresponds to one device instance, and is described
  298. * by one dev_link_t structure (defined in ds.h).
  299. *
  300. * You may not want to use a linked list for this -- for example, the
  301. * memory card driver uses an array of dev_link_t pointers, where minor
  302. * device numbers are used to derive the corresponding array index.
  303. */
  304. static dev_link_t *dev_list;
  305. /****************
  306. * A dev_link_t structure has fields for most things that are needed
  307. * to keep track of a socket, but there will usually be some device
  308. * specific information that also needs to be kept track of. The
  309. * 'priv' pointer in a dev_link_t structure can be used to point to
  310. * a device-specific private data structure, like this.
  311. *
  312. * A driver needs to provide a dev_node_t structure for each device
  313. * on a card. In some cases, there is only one device per card (for
  314. * example, ethernet cards, modems). In other cases, there may be
  315. * many actual or logical devices (SCSI adapters, memory cards with
  316. * multiple partitions). The dev_node_t structures need to be kept
  317. * in a linked list starting at the 'dev' field of a dev_link_t
  318. * structure. We allocate them in the card's private data structure,
  319. * because they generally can't be allocated dynamically.
  320. */
  321. typedef struct local_info_t {
  322. dev_link_t link;
  323. dev_node_t node;
  324. struct net_device_stats stats;
  325. int card_type;
  326. int probe_port;
  327. int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
  328. int mohawk; /* a CE3 type card */
  329. int dingo; /* a CEM56 type card */
  330. int new_mii; /* has full 10baseT/100baseT MII */
  331. int modem; /* is a multi function card (i.e with a modem) */
  332. void __iomem *dingo_ccr; /* only used for CEM56 cards */
  333. unsigned last_ptr_value; /* last packets transmitted value */
  334. const char *manf_str;
  335. } local_info_t;
  336. /****************
  337. * Some more prototypes
  338. */
  339. static int do_start_xmit(struct sk_buff *skb, struct net_device *dev);
  340. static void do_tx_timeout(struct net_device *dev);
  341. static struct net_device_stats *do_get_stats(struct net_device *dev);
  342. static void set_addresses(struct net_device *dev);
  343. static void set_multicast_list(struct net_device *dev);
  344. static int set_card_type(dev_link_t *link, const void *s);
  345. static int do_config(struct net_device *dev, struct ifmap *map);
  346. static int do_open(struct net_device *dev);
  347. static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  348. static struct ethtool_ops netdev_ethtool_ops;
  349. static void hardreset(struct net_device *dev);
  350. static void do_reset(struct net_device *dev, int full);
  351. static int init_mii(struct net_device *dev);
  352. static void do_powerdown(struct net_device *dev);
  353. static int do_stop(struct net_device *dev);
  354. /*=============== Helper functions =========================*/
  355. static int
  356. first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
  357. {
  358. int err;
  359. if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
  360. (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
  361. err = pcmcia_parse_tuple(handle, tuple, parse);
  362. return err;
  363. }
  364. static int
  365. next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
  366. {
  367. int err;
  368. if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
  369. (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
  370. err = pcmcia_parse_tuple(handle, tuple, parse);
  371. return err;
  372. }
  373. #define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR)
  374. #define GetByte(reg) ((unsigned)inb(ioaddr + (reg)))
  375. #define GetWord(reg) ((unsigned)inw(ioaddr + (reg)))
  376. #define PutByte(reg,value) outb((value), ioaddr+(reg))
  377. #define PutWord(reg,value) outw((value), ioaddr+(reg))
  378. /*====== Functions used for debugging =================================*/
  379. #if defined(PCMCIA_DEBUG) && 0 /* reading regs may change system status */
  380. static void
  381. PrintRegisters(struct net_device *dev)
  382. {
  383. kio_addr_t ioaddr = dev->base_addr;
  384. if (pc_debug > 1) {
  385. int i, page;
  386. printk(KDBG_XIRC "Register common: ");
  387. for (i = 0; i < 8; i++)
  388. printk(" %2.2x", GetByte(i));
  389. printk("\n");
  390. for (page = 0; page <= 8; page++) {
  391. printk(KDBG_XIRC "Register page %2x: ", page);
  392. SelectPage(page);
  393. for (i = 8; i < 16; i++)
  394. printk(" %2.2x", GetByte(i));
  395. printk("\n");
  396. }
  397. for (page=0x40 ; page <= 0x5f; page++) {
  398. if (page == 0x43 || (page >= 0x46 && page <= 0x4f)
  399. || (page >= 0x51 && page <=0x5e))
  400. continue;
  401. printk(KDBG_XIRC "Register page %2x: ", page);
  402. SelectPage(page);
  403. for (i = 8; i < 16; i++)
  404. printk(" %2.2x", GetByte(i));
  405. printk("\n");
  406. }
  407. }
  408. }
  409. #endif /* PCMCIA_DEBUG */
  410. /*============== MII Management functions ===============*/
  411. /****************
  412. * Turn around for read
  413. */
  414. static void
  415. mii_idle(kio_addr_t ioaddr)
  416. {
  417. PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
  418. udelay(1);
  419. PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
  420. udelay(1);
  421. }
  422. /****************
  423. * Write a bit to MDI/O
  424. */
  425. static void
  426. mii_putbit(kio_addr_t ioaddr, unsigned data)
  427. {
  428. #if 1
  429. if (data) {
  430. PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
  431. udelay(1);
  432. PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
  433. udelay(1);
  434. } else {
  435. PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
  436. udelay(1);
  437. PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
  438. udelay(1);
  439. }
  440. #else
  441. if (data) {
  442. PutWord(XIRCREG2_GPR2-1, 0x0e0e);
  443. udelay(1);
  444. PutWord(XIRCREG2_GPR2-1, 0x0f0f);
  445. udelay(1);
  446. } else {
  447. PutWord(XIRCREG2_GPR2-1, 0x0c0c);
  448. udelay(1);
  449. PutWord(XIRCREG2_GPR2-1, 0x0d0d);
  450. udelay(1);
  451. }
  452. #endif
  453. }
  454. /****************
  455. * Get a bit from MDI/O
  456. */
  457. static int
  458. mii_getbit(kio_addr_t ioaddr)
  459. {
  460. unsigned d;
  461. PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
  462. udelay(1);
  463. d = GetByte(XIRCREG2_GPR2); /* read MDIO */
  464. PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
  465. udelay(1);
  466. return d & 0x20; /* read MDIO */
  467. }
  468. static void
  469. mii_wbits(kio_addr_t ioaddr, unsigned data, int len)
  470. {
  471. unsigned m = 1 << (len-1);
  472. for (; m; m >>= 1)
  473. mii_putbit(ioaddr, data & m);
  474. }
  475. static unsigned
  476. mii_rd(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg)
  477. {
  478. int i;
  479. unsigned data=0, m;
  480. SelectPage(2);
  481. for (i=0; i < 32; i++) /* 32 bit preamble */
  482. mii_putbit(ioaddr, 1);
  483. mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */
  484. mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
  485. mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */
  486. mii_idle(ioaddr); /* turn around */
  487. mii_getbit(ioaddr);
  488. for (m = 1<<15; m; m >>= 1)
  489. if (mii_getbit(ioaddr))
  490. data |= m;
  491. mii_idle(ioaddr);
  492. return data;
  493. }
  494. static void
  495. mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
  496. {
  497. int i;
  498. SelectPage(2);
  499. for (i=0; i < 32; i++) /* 32 bit preamble */
  500. mii_putbit(ioaddr, 1);
  501. mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */
  502. mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */
  503. mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */
  504. mii_putbit(ioaddr, 1); /* turn around */
  505. mii_putbit(ioaddr, 0);
  506. mii_wbits(ioaddr, data, len); /* And write the data */
  507. mii_idle(ioaddr);
  508. }
  509. /*============= Main bulk of functions =========================*/
  510. /****************
  511. * xirc2ps_attach() creates an "instance" of the driver, allocating
  512. * local data structures for one device. The device is registered
  513. * with Card Services.
  514. *
  515. * The dev_link structure is initialized, but we don't actually
  516. * configure the card at this point -- we wait until we receive a
  517. * card insertion event.
  518. */
  519. static dev_link_t *
  520. xirc2ps_attach(void)
  521. {
  522. client_reg_t client_reg;
  523. dev_link_t *link;
  524. struct net_device *dev;
  525. local_info_t *local;
  526. int err;
  527. DEBUG(0, "attach()\n");
  528. /* Allocate the device structure */
  529. dev = alloc_etherdev(sizeof(local_info_t));
  530. if (!dev)
  531. return NULL;
  532. local = netdev_priv(dev);
  533. link = &local->link;
  534. link->priv = dev;
  535. /* General socket configuration */
  536. link->conf.Attributes = CONF_ENABLE_IRQ;
  537. link->conf.Vcc = 50;
  538. link->conf.IntType = INT_MEMORY_AND_IO;
  539. link->conf.ConfigIndex = 1;
  540. link->conf.Present = PRESENT_OPTION;
  541. link->irq.Handler = xirc2ps_interrupt;
  542. link->irq.Instance = dev;
  543. /* Fill in card specific entries */
  544. SET_MODULE_OWNER(dev);
  545. dev->hard_start_xmit = &do_start_xmit;
  546. dev->set_config = &do_config;
  547. dev->get_stats = &do_get_stats;
  548. dev->do_ioctl = &do_ioctl;
  549. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  550. dev->set_multicast_list = &set_multicast_list;
  551. dev->open = &do_open;
  552. dev->stop = &do_stop;
  553. #ifdef HAVE_TX_TIMEOUT
  554. dev->tx_timeout = do_tx_timeout;
  555. dev->watchdog_timeo = TX_TIMEOUT;
  556. #endif
  557. /* Register with Card Services */
  558. link->next = dev_list;
  559. dev_list = link;
  560. client_reg.dev_info = &dev_info;
  561. client_reg.Version = 0x0210;
  562. client_reg.event_callback_args.client_data = link;
  563. if ((err = pcmcia_register_client(&link->handle, &client_reg))) {
  564. cs_error(link->handle, RegisterClient, err);
  565. xirc2ps_detach(link->handle);
  566. return NULL;
  567. }
  568. return link;
  569. } /* xirc2ps_attach */
  570. /****************
  571. * This deletes a driver "instance". The device is de-registered
  572. * with Card Services. If it has been released, all local data
  573. * structures are freed. Otherwise, the structures will be freed
  574. * when the device is released.
  575. */
  576. static void
  577. xirc2ps_detach(struct pcmcia_device *p_dev)
  578. {
  579. dev_link_t *link = dev_to_instance(p_dev);
  580. struct net_device *dev = link->priv;
  581. dev_link_t **linkp;
  582. DEBUG(0, "detach(0x%p)\n", link);
  583. /* Locate device structure */
  584. for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  585. if (*linkp == link)
  586. break;
  587. if (!*linkp) {
  588. DEBUG(0, "detach(0x%p): dev_link lost\n", link);
  589. return;
  590. }
  591. if (link->dev)
  592. unregister_netdev(dev);
  593. if (link->state & DEV_CONFIG)
  594. xirc2ps_release(link);
  595. /* Unlink device structure, free it */
  596. *linkp = link->next;
  597. free_netdev(dev);
  598. } /* xirc2ps_detach */
  599. /****************
  600. * Detect the type of the card. s is the buffer with the data of tuple 0x20
  601. * Returns: 0 := not supported
  602. * mediaid=11 and prodid=47
  603. * Media-Id bits:
  604. * Ethernet 0x01
  605. * Tokenring 0x02
  606. * Arcnet 0x04
  607. * Wireless 0x08
  608. * Modem 0x10
  609. * GSM only 0x20
  610. * Prod-Id bits:
  611. * Pocket 0x10
  612. * External 0x20
  613. * Creditcard 0x40
  614. * Cardbus 0x80
  615. *
  616. */
  617. static int
  618. set_card_type(dev_link_t *link, const void *s)
  619. {
  620. struct net_device *dev = link->priv;
  621. local_info_t *local = netdev_priv(dev);
  622. #ifdef PCMCIA_DEBUG
  623. unsigned cisrev = ((const unsigned char *)s)[2];
  624. #endif
  625. unsigned mediaid= ((const unsigned char *)s)[3];
  626. unsigned prodid = ((const unsigned char *)s)[4];
  627. DEBUG(0, "cisrev=%02x mediaid=%02x prodid=%02x\n",
  628. cisrev, mediaid, prodid);
  629. local->mohawk = 0;
  630. local->dingo = 0;
  631. local->modem = 0;
  632. local->card_type = XIR_UNKNOWN;
  633. if (!(prodid & 0x40)) {
  634. printk(KNOT_XIRC "Ooops: Not a creditcard\n");
  635. return 0;
  636. }
  637. if (!(mediaid & 0x01)) {
  638. printk(KNOT_XIRC "Not an Ethernet card\n");
  639. return 0;
  640. }
  641. if (mediaid & 0x10) {
  642. local->modem = 1;
  643. switch(prodid & 15) {
  644. case 1: local->card_type = XIR_CEM ; break;
  645. case 2: local->card_type = XIR_CEM2 ; break;
  646. case 3: local->card_type = XIR_CEM3 ; break;
  647. case 4: local->card_type = XIR_CEM33 ; break;
  648. case 5: local->card_type = XIR_CEM56M;
  649. local->mohawk = 1;
  650. break;
  651. case 6:
  652. case 7: /* 7 is the RealPort 10/56 */
  653. local->card_type = XIR_CEM56 ;
  654. local->mohawk = 1;
  655. local->dingo = 1;
  656. break;
  657. }
  658. } else {
  659. switch(prodid & 15) {
  660. case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
  661. break;
  662. case 2: local->card_type = XIR_CE2; break;
  663. case 3: local->card_type = XIR_CE3;
  664. local->mohawk = 1;
  665. break;
  666. }
  667. }
  668. if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
  669. printk(KNOT_XIRC "Sorry, this is an old CE card\n");
  670. return 0;
  671. }
  672. if (local->card_type == XIR_UNKNOWN)
  673. printk(KNOT_XIRC "unknown card (mediaid=%02x prodid=%02x)\n",
  674. mediaid, prodid);
  675. return 1;
  676. }
  677. /****************
  678. * There are some CE2 cards out which claim to be a CE card.
  679. * This function looks for a "CE2" in the 3rd version field.
  680. * Returns: true if this is a CE2
  681. */
  682. static int
  683. has_ce2_string(dev_link_t * link)
  684. {
  685. client_handle_t handle = link->handle;
  686. tuple_t tuple;
  687. cisparse_t parse;
  688. u_char buf[256];
  689. tuple.Attributes = 0;
  690. tuple.TupleData = buf;
  691. tuple.TupleDataMax = 254;
  692. tuple.TupleOffset = 0;
  693. tuple.DesiredTuple = CISTPL_VERS_1;
  694. if (!first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 2) {
  695. if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2"))
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. /****************
  701. * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
  702. * is received, to configure the PCMCIA socket, and to make the
  703. * ethernet device available to the system.
  704. */
  705. static void
  706. xirc2ps_config(dev_link_t * link)
  707. {
  708. client_handle_t handle = link->handle;
  709. struct net_device *dev = link->priv;
  710. local_info_t *local = netdev_priv(dev);
  711. tuple_t tuple;
  712. cisparse_t parse;
  713. kio_addr_t ioaddr;
  714. int err, i;
  715. u_char buf[64];
  716. cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
  717. cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  718. local->dingo_ccr = NULL;
  719. DEBUG(0, "config(0x%p)\n", link);
  720. /*
  721. * This reads the card's CONFIG tuple to find its configuration
  722. * registers.
  723. */
  724. tuple.Attributes = 0;
  725. tuple.TupleData = buf;
  726. tuple.TupleDataMax = 64;
  727. tuple.TupleOffset = 0;
  728. /* Is this a valid card */
  729. tuple.DesiredTuple = CISTPL_MANFID;
  730. if ((err=first_tuple(handle, &tuple, &parse))) {
  731. printk(KNOT_XIRC "manfid not found in CIS\n");
  732. goto failure;
  733. }
  734. switch(parse.manfid.manf) {
  735. case MANFID_XIRCOM:
  736. local->manf_str = "Xircom";
  737. break;
  738. case MANFID_ACCTON:
  739. local->manf_str = "Accton";
  740. break;
  741. case MANFID_COMPAQ:
  742. case MANFID_COMPAQ2:
  743. local->manf_str = "Compaq";
  744. break;
  745. case MANFID_INTEL:
  746. local->manf_str = "Intel";
  747. break;
  748. case MANFID_TOSHIBA:
  749. local->manf_str = "Toshiba";
  750. break;
  751. default:
  752. printk(KNOT_XIRC "Unknown Card Manufacturer ID: 0x%04x\n",
  753. (unsigned)parse.manfid.manf);
  754. goto failure;
  755. }
  756. DEBUG(0, "found %s card\n", local->manf_str);
  757. if (!set_card_type(link, buf)) {
  758. printk(KNOT_XIRC "this card is not supported\n");
  759. goto failure;
  760. }
  761. /* get configuration stuff */
  762. tuple.DesiredTuple = CISTPL_CONFIG;
  763. if ((err=first_tuple(handle, &tuple, &parse)))
  764. goto cis_error;
  765. link->conf.ConfigBase = parse.config.base;
  766. link->conf.Present = parse.config.rmask[0];
  767. /* get the ethernet address from the CIS */
  768. tuple.DesiredTuple = CISTPL_FUNCE;
  769. for (err = first_tuple(handle, &tuple, &parse); !err;
  770. err = next_tuple(handle, &tuple, &parse)) {
  771. /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
  772. * the first one with a length of zero the second correct -
  773. * so I skip all entries with length 0 */
  774. if (parse.funce.type == CISTPL_FUNCE_LAN_NODE_ID
  775. && ((cistpl_lan_node_id_t *)parse.funce.data)->nb)
  776. break;
  777. }
  778. if (err) { /* not found: try to get the node-id from tuple 0x89 */
  779. tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */
  780. if ((err = pcmcia_get_first_tuple(handle, &tuple)) == 0 &&
  781. (err = pcmcia_get_tuple_data(handle, &tuple)) == 0) {
  782. if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
  783. memcpy(&parse, buf, 8);
  784. else
  785. err = -1;
  786. }
  787. }
  788. if (err) { /* another try (James Lehmer's CE2 version 4.1)*/
  789. tuple.DesiredTuple = CISTPL_FUNCE;
  790. for (err = first_tuple(handle, &tuple, &parse); !err;
  791. err = next_tuple(handle, &tuple, &parse)) {
  792. if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
  793. && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
  794. buf[1] = 4;
  795. memcpy(&parse, buf+1, 8);
  796. break;
  797. }
  798. }
  799. }
  800. if (err) {
  801. printk(KNOT_XIRC "node-id not found in CIS\n");
  802. goto failure;
  803. }
  804. node_id = (cistpl_lan_node_id_t *)parse.funce.data;
  805. if (node_id->nb != 6) {
  806. printk(KNOT_XIRC "malformed node-id in CIS\n");
  807. goto failure;
  808. }
  809. for (i=0; i < 6; i++)
  810. dev->dev_addr[i] = node_id->id[i];
  811. /* Configure card */
  812. link->state |= DEV_CONFIG;
  813. link->io.IOAddrLines =10;
  814. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  815. link->irq.Attributes = IRQ_HANDLE_PRESENT;
  816. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  817. if (local->modem) {
  818. int pass;
  819. if (do_sound) {
  820. link->conf.Attributes |= CONF_ENABLE_SPKR;
  821. link->conf.Status |= CCSR_AUDIO_ENA;
  822. }
  823. link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED ;
  824. link->io.NumPorts2 = 8;
  825. link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
  826. if (local->dingo) {
  827. /* Take the Modem IO port from the CIS and scan for a free
  828. * Ethernet port */
  829. link->io.NumPorts1 = 16; /* no Mako stuff anymore */
  830. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  831. for (err = first_tuple(handle, &tuple, &parse); !err;
  832. err = next_tuple(handle, &tuple, &parse)) {
  833. if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
  834. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  835. link->conf.ConfigIndex = cf->index ;
  836. link->io.BasePort2 = cf->io.win[0].base;
  837. link->io.BasePort1 = ioaddr;
  838. if (!(err=pcmcia_request_io(link->handle, &link->io)))
  839. goto port_found;
  840. }
  841. }
  842. }
  843. } else {
  844. link->io.NumPorts1 = 18;
  845. /* We do 2 passes here: The first one uses the regular mapping and
  846. * the second tries again, thereby considering that the 32 ports are
  847. * mirrored every 32 bytes. Actually we use a mirrored port for
  848. * the Mako if (on the first pass) the COR bit 5 is set.
  849. */
  850. for (pass=0; pass < 2; pass++) {
  851. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  852. for (err = first_tuple(handle, &tuple, &parse); !err;
  853. err = next_tuple(handle, &tuple, &parse)){
  854. if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
  855. link->conf.ConfigIndex = cf->index ;
  856. link->io.BasePort2 = cf->io.win[0].base;
  857. link->io.BasePort1 = link->io.BasePort2
  858. + (pass ? (cf->index & 0x20 ? -24:8)
  859. : (cf->index & 0x20 ? 8:-24));
  860. if (!(err=pcmcia_request_io(link->handle, &link->io)))
  861. goto port_found;
  862. }
  863. }
  864. }
  865. /* if special option:
  866. * try to configure as Ethernet only.
  867. * .... */
  868. }
  869. printk(KNOT_XIRC "no ports available\n");
  870. } else {
  871. link->irq.Attributes |= IRQ_TYPE_EXCLUSIVE;
  872. link->io.NumPorts1 = 16;
  873. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  874. link->io.BasePort1 = ioaddr;
  875. if (!(err=pcmcia_request_io(link->handle, &link->io)))
  876. goto port_found;
  877. }
  878. link->io.BasePort1 = 0; /* let CS decide */
  879. if ((err=pcmcia_request_io(link->handle, &link->io))) {
  880. cs_error(link->handle, RequestIO, err);
  881. goto config_error;
  882. }
  883. }
  884. port_found:
  885. if (err)
  886. goto config_error;
  887. /****************
  888. * Now allocate an interrupt line. Note that this does not
  889. * actually assign a handler to the interrupt.
  890. */
  891. if ((err=pcmcia_request_irq(link->handle, &link->irq))) {
  892. cs_error(link->handle, RequestIRQ, err);
  893. goto config_error;
  894. }
  895. /****************
  896. * This actually configures the PCMCIA socket -- setting up
  897. * the I/O windows and the interrupt mapping.
  898. */
  899. if ((err=pcmcia_request_configuration(link->handle, &link->conf))) {
  900. cs_error(link->handle, RequestConfiguration, err);
  901. goto config_error;
  902. }
  903. if (local->dingo) {
  904. conf_reg_t reg;
  905. win_req_t req;
  906. memreq_t mem;
  907. /* Reset the modem's BAR to the correct value
  908. * This is necessary because in the RequestConfiguration call,
  909. * the base address of the ethernet port (BasePort1) is written
  910. * to the BAR registers of the modem.
  911. */
  912. reg.Action = CS_WRITE;
  913. reg.Offset = CISREG_IOBASE_0;
  914. reg.Value = link->io.BasePort2 & 0xff;
  915. if ((err = pcmcia_access_configuration_register(link->handle, &reg))) {
  916. cs_error(link->handle, AccessConfigurationRegister, err);
  917. goto config_error;
  918. }
  919. reg.Action = CS_WRITE;
  920. reg.Offset = CISREG_IOBASE_1;
  921. reg.Value = (link->io.BasePort2 >> 8) & 0xff;
  922. if ((err = pcmcia_access_configuration_register(link->handle, &reg))) {
  923. cs_error(link->handle, AccessConfigurationRegister, err);
  924. goto config_error;
  925. }
  926. /* There is no config entry for the Ethernet part which
  927. * is at 0x0800. So we allocate a window into the attribute
  928. * memory and write direct to the CIS registers
  929. */
  930. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  931. req.Base = req.Size = 0;
  932. req.AccessSpeed = 0;
  933. if ((err = pcmcia_request_window(&link->handle, &req, &link->win))) {
  934. cs_error(link->handle, RequestWindow, err);
  935. goto config_error;
  936. }
  937. local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
  938. mem.CardOffset = 0x0;
  939. mem.Page = 0;
  940. if ((err = pcmcia_map_mem_page(link->win, &mem))) {
  941. cs_error(link->handle, MapMemPage, err);
  942. goto config_error;
  943. }
  944. /* Setup the CCRs; there are no infos in the CIS about the Ethernet
  945. * part.
  946. */
  947. writeb(0x47, local->dingo_ccr + CISREG_COR);
  948. ioaddr = link->io.BasePort1;
  949. writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
  950. writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
  951. #if 0
  952. {
  953. u_char tmp;
  954. printk(KERN_INFO "ECOR:");
  955. for (i=0; i < 7; i++) {
  956. tmp = readb(local->dingo_ccr + i*2);
  957. printk(" %02x", tmp);
  958. }
  959. printk("\n");
  960. printk(KERN_INFO "DCOR:");
  961. for (i=0; i < 4; i++) {
  962. tmp = readb(local->dingo_ccr + 0x20 + i*2);
  963. printk(" %02x", tmp);
  964. }
  965. printk("\n");
  966. printk(KERN_INFO "SCOR:");
  967. for (i=0; i < 10; i++) {
  968. tmp = readb(local->dingo_ccr + 0x40 + i*2);
  969. printk(" %02x", tmp);
  970. }
  971. printk("\n");
  972. }
  973. #endif
  974. writeb(0x01, local->dingo_ccr + 0x20);
  975. writeb(0x0c, local->dingo_ccr + 0x22);
  976. writeb(0x00, local->dingo_ccr + 0x24);
  977. writeb(0x00, local->dingo_ccr + 0x26);
  978. writeb(0x00, local->dingo_ccr + 0x28);
  979. }
  980. /* The if_port symbol can be set when the module is loaded */
  981. local->probe_port=0;
  982. if (!if_port) {
  983. local->probe_port = dev->if_port = 1;
  984. } else if ((if_port >= 1 && if_port <= 2) ||
  985. (local->mohawk && if_port==4))
  986. dev->if_port = if_port;
  987. else
  988. printk(KNOT_XIRC "invalid if_port requested\n");
  989. /* we can now register the device with the net subsystem */
  990. dev->irq = link->irq.AssignedIRQ;
  991. dev->base_addr = link->io.BasePort1;
  992. if (local->dingo)
  993. do_reset(dev, 1); /* a kludge to make the cem56 work */
  994. link->dev = &local->node;
  995. link->state &= ~DEV_CONFIG_PENDING;
  996. SET_NETDEV_DEV(dev, &handle_to_dev(handle));
  997. if ((err=register_netdev(dev))) {
  998. printk(KNOT_XIRC "register_netdev() failed\n");
  999. link->dev = NULL;
  1000. goto config_error;
  1001. }
  1002. strcpy(local->node.dev_name, dev->name);
  1003. /* give some infos about the hardware */
  1004. printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr",
  1005. dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq);
  1006. for (i = 0; i < 6; i++)
  1007. printk("%c%02X", i?':':' ', dev->dev_addr[i]);
  1008. printk("\n");
  1009. return;
  1010. config_error:
  1011. link->state &= ~DEV_CONFIG_PENDING;
  1012. xirc2ps_release(link);
  1013. return;
  1014. cis_error:
  1015. printk(KNOT_XIRC "unable to parse CIS\n");
  1016. failure:
  1017. link->state &= ~DEV_CONFIG_PENDING;
  1018. } /* xirc2ps_config */
  1019. /****************
  1020. * After a card is removed, xirc2ps_release() will unregister the net
  1021. * device, and release the PCMCIA configuration. If the device is
  1022. * still open, this will be postponed until it is closed.
  1023. */
  1024. static void
  1025. xirc2ps_release(dev_link_t *link)
  1026. {
  1027. DEBUG(0, "release(0x%p)\n", link);
  1028. if (link->win) {
  1029. struct net_device *dev = link->priv;
  1030. local_info_t *local = netdev_priv(dev);
  1031. if (local->dingo)
  1032. iounmap(local->dingo_ccr - 0x0800);
  1033. pcmcia_release_window(link->win);
  1034. }
  1035. pcmcia_release_configuration(link->handle);
  1036. pcmcia_release_io(link->handle, &link->io);
  1037. pcmcia_release_irq(link->handle, &link->irq);
  1038. link->state &= ~DEV_CONFIG;
  1039. } /* xirc2ps_release */
  1040. /*====================================================================*/
  1041. static int xirc2ps_suspend(struct pcmcia_device *p_dev)
  1042. {
  1043. dev_link_t *link = dev_to_instance(p_dev);
  1044. struct net_device *dev = link->priv;
  1045. link->state |= DEV_SUSPEND;
  1046. if (link->state & DEV_CONFIG) {
  1047. if (link->open) {
  1048. netif_device_detach(dev);
  1049. do_powerdown(dev);
  1050. }
  1051. pcmcia_release_configuration(link->handle);
  1052. }
  1053. return 0;
  1054. }
  1055. static int xirc2ps_resume(struct pcmcia_device *p_dev)
  1056. {
  1057. dev_link_t *link = dev_to_instance(p_dev);
  1058. struct net_device *dev = link->priv;
  1059. link->state &= ~DEV_SUSPEND;
  1060. if (link->state & DEV_CONFIG) {
  1061. pcmcia_request_configuration(link->handle, &link->conf);
  1062. if (link->open) {
  1063. do_reset(dev,1);
  1064. netif_device_attach(dev);
  1065. }
  1066. }
  1067. return 0;
  1068. }
  1069. /****************
  1070. * The card status event handler. Mostly, this schedules other
  1071. * stuff to run after an event is received. A CARD_REMOVAL event
  1072. * also sets some flags to discourage the net drivers from trying
  1073. * to talk to the card any more.
  1074. *
  1075. * When a CARD_REMOVAL event is received, we immediately set a flag
  1076. * to block future accesses to this device. All the functions that
  1077. * actually access the device should check this flag to make sure
  1078. * the card is still present.
  1079. */
  1080. static int
  1081. xirc2ps_event(event_t event, int priority,
  1082. event_callback_args_t * args)
  1083. {
  1084. dev_link_t *link = args->client_data;
  1085. DEBUG(0, "event(%d)\n", (int)event);
  1086. switch (event) {
  1087. case CS_EVENT_CARD_INSERTION:
  1088. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  1089. xirc2ps_config(link);
  1090. break;
  1091. }
  1092. return 0;
  1093. } /* xirc2ps_event */
  1094. /*====================================================================*/
  1095. /****************
  1096. * This is the Interrupt service route.
  1097. */
  1098. static irqreturn_t
  1099. xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1100. {
  1101. struct net_device *dev = (struct net_device *)dev_id;
  1102. local_info_t *lp = netdev_priv(dev);
  1103. kio_addr_t ioaddr;
  1104. u_char saved_page;
  1105. unsigned bytes_rcvd;
  1106. unsigned int_status, eth_status, rx_status, tx_status;
  1107. unsigned rsr, pktlen;
  1108. ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
  1109. * is this something to worry about?
  1110. * -- on a laptop?
  1111. */
  1112. if (!netif_device_present(dev))
  1113. return IRQ_HANDLED;
  1114. ioaddr = dev->base_addr;
  1115. if (lp->mohawk) { /* must disable the interrupt */
  1116. PutByte(XIRCREG_CR, 0);
  1117. }
  1118. DEBUG(6, "%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
  1119. saved_page = GetByte(XIRCREG_PR);
  1120. /* Read the ISR to see whats the cause for the interrupt.
  1121. * This also clears the interrupt flags on CE2 cards
  1122. */
  1123. int_status = GetByte(XIRCREG_ISR);
  1124. bytes_rcvd = 0;
  1125. loop_entry:
  1126. if (int_status == 0xff) { /* card may be ejected */
  1127. DEBUG(3, "%s: interrupt %d for dead card\n", dev->name, irq);
  1128. goto leave;
  1129. }
  1130. eth_status = GetByte(XIRCREG_ESR);
  1131. SelectPage(0x40);
  1132. rx_status = GetByte(XIRCREG40_RXST0);
  1133. PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
  1134. tx_status = GetByte(XIRCREG40_TXST0);
  1135. tx_status |= GetByte(XIRCREG40_TXST1) << 8;
  1136. PutByte(XIRCREG40_TXST0, 0);
  1137. PutByte(XIRCREG40_TXST1, 0);
  1138. DEBUG(3, "%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
  1139. dev->name, int_status, eth_status, rx_status, tx_status);
  1140. /***** receive section ******/
  1141. SelectPage(0);
  1142. while (eth_status & FullPktRcvd) {
  1143. rsr = GetByte(XIRCREG0_RSR);
  1144. if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
  1145. /* too many bytes received during this int, drop the rest of the
  1146. * packets */
  1147. lp->stats.rx_dropped++;
  1148. DEBUG(2, "%s: RX drop, too much done\n", dev->name);
  1149. } else if (rsr & PktRxOk) {
  1150. struct sk_buff *skb;
  1151. pktlen = GetWord(XIRCREG0_RBC);
  1152. bytes_rcvd += pktlen;
  1153. DEBUG(5, "rsr=%#02x packet_length=%u\n", rsr, pktlen);
  1154. skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */
  1155. if (!skb) {
  1156. printk(KNOT_XIRC "low memory, packet dropped (size=%u)\n",
  1157. pktlen);
  1158. lp->stats.rx_dropped++;
  1159. } else { /* okay get the packet */
  1160. skb_reserve(skb, 2);
  1161. if (lp->silicon == 0 ) { /* work around a hardware bug */
  1162. unsigned rhsa; /* receive start address */
  1163. SelectPage(5);
  1164. rhsa = GetWord(XIRCREG5_RHSA0);
  1165. SelectPage(0);
  1166. rhsa += 3; /* skip control infos */
  1167. if (rhsa >= 0x8000)
  1168. rhsa = 0;
  1169. if (rhsa + pktlen > 0x8000) {
  1170. unsigned i;
  1171. u_char *buf = skb_put(skb, pktlen);
  1172. for (i=0; i < pktlen ; i++, rhsa++) {
  1173. buf[i] = GetByte(XIRCREG_EDP);
  1174. if (rhsa == 0x8000) {
  1175. rhsa = 0;
  1176. i--;
  1177. }
  1178. }
  1179. } else {
  1180. insw(ioaddr+XIRCREG_EDP,
  1181. skb_put(skb, pktlen), (pktlen+1)>>1);
  1182. }
  1183. }
  1184. #if 0
  1185. else if (lp->mohawk) {
  1186. /* To use this 32 bit access we should use
  1187. * a manual optimized loop
  1188. * Also the words are swapped, we can get more
  1189. * performance by using 32 bit access and swapping
  1190. * the words in a register. Will need this for cardbus
  1191. *
  1192. * Note: don't forget to change the ALLOC_SKB to .. +3
  1193. */
  1194. unsigned i;
  1195. u_long *p = skb_put(skb, pktlen);
  1196. register u_long a;
  1197. kio_addr_t edpreg = ioaddr+XIRCREG_EDP-2;
  1198. for (i=0; i < len ; i += 4, p++) {
  1199. a = inl(edpreg);
  1200. __asm__("rorl $16,%0\n\t"
  1201. :"=q" (a)
  1202. : "0" (a));
  1203. *p = a;
  1204. }
  1205. }
  1206. #endif
  1207. else {
  1208. insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
  1209. (pktlen+1)>>1);
  1210. }
  1211. skb->protocol = eth_type_trans(skb, dev);
  1212. skb->dev = dev;
  1213. netif_rx(skb);
  1214. dev->last_rx = jiffies;
  1215. lp->stats.rx_packets++;
  1216. lp->stats.rx_bytes += pktlen;
  1217. if (!(rsr & PhyPkt))
  1218. lp->stats.multicast++;
  1219. }
  1220. } else { /* bad packet */
  1221. DEBUG(5, "rsr=%#02x\n", rsr);
  1222. }
  1223. if (rsr & PktTooLong) {
  1224. lp->stats.rx_frame_errors++;
  1225. DEBUG(3, "%s: Packet too long\n", dev->name);
  1226. }
  1227. if (rsr & CRCErr) {
  1228. lp->stats.rx_crc_errors++;
  1229. DEBUG(3, "%s: CRC error\n", dev->name);
  1230. }
  1231. if (rsr & AlignErr) {
  1232. lp->stats.rx_fifo_errors++; /* okay ? */
  1233. DEBUG(3, "%s: Alignment error\n", dev->name);
  1234. }
  1235. /* clear the received/dropped/error packet */
  1236. PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
  1237. /* get the new ethernet status */
  1238. eth_status = GetByte(XIRCREG_ESR);
  1239. }
  1240. if (rx_status & 0x10) { /* Receive overrun */
  1241. lp->stats.rx_over_errors++;
  1242. PutByte(XIRCREG_CR, ClearRxOvrun);
  1243. DEBUG(3, "receive overrun cleared\n");
  1244. }
  1245. /***** transmit section ******/
  1246. if (int_status & PktTxed) {
  1247. unsigned n, nn;
  1248. n = lp->last_ptr_value;
  1249. nn = GetByte(XIRCREG0_PTR);
  1250. lp->last_ptr_value = nn;
  1251. if (nn < n) /* rollover */
  1252. lp->stats.tx_packets += 256 - n;
  1253. else if (n == nn) { /* happens sometimes - don't know why */
  1254. DEBUG(0, "PTR not changed?\n");
  1255. } else
  1256. lp->stats.tx_packets += lp->last_ptr_value - n;
  1257. netif_wake_queue(dev);
  1258. }
  1259. if (tx_status & 0x0002) { /* Execessive collissions */
  1260. DEBUG(0, "tx restarted due to execssive collissions\n");
  1261. PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
  1262. }
  1263. if (tx_status & 0x0040)
  1264. lp->stats.tx_aborted_errors++;
  1265. /* recalculate our work chunk so that we limit the duration of this
  1266. * ISR to about 1/10 of a second.
  1267. * Calculate only if we received a reasonable amount of bytes.
  1268. */
  1269. if (bytes_rcvd > 1000) {
  1270. u_long duration = jiffies - start_ticks;
  1271. if (duration >= HZ/10) { /* if more than about 1/10 second */
  1272. maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
  1273. if (maxrx_bytes < 2000)
  1274. maxrx_bytes = 2000;
  1275. else if (maxrx_bytes > 22000)
  1276. maxrx_bytes = 22000;
  1277. DEBUG(1, "set maxrx=%u (rcvd=%u ticks=%lu)\n",
  1278. maxrx_bytes, bytes_rcvd, duration);
  1279. } else if (!duration && maxrx_bytes < 22000) {
  1280. /* now much faster */
  1281. maxrx_bytes += 2000;
  1282. if (maxrx_bytes > 22000)
  1283. maxrx_bytes = 22000;
  1284. DEBUG(1, "set maxrx=%u\n", maxrx_bytes);
  1285. }
  1286. }
  1287. leave:
  1288. if (lockup_hack) {
  1289. if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
  1290. goto loop_entry;
  1291. }
  1292. SelectPage(saved_page);
  1293. PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */
  1294. /* Instead of dropping packets during a receive, we could
  1295. * force an interrupt with this command:
  1296. * PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
  1297. */
  1298. return IRQ_HANDLED;
  1299. } /* xirc2ps_interrupt */
  1300. /*====================================================================*/
  1301. static void
  1302. do_tx_timeout(struct net_device *dev)
  1303. {
  1304. local_info_t *lp = netdev_priv(dev);
  1305. printk(KERN_NOTICE "%s: transmit timed out\n", dev->name);
  1306. lp->stats.tx_errors++;
  1307. /* reset the card */
  1308. do_reset(dev,1);
  1309. dev->trans_start = jiffies;
  1310. netif_wake_queue(dev);
  1311. }
  1312. static int
  1313. do_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1314. {
  1315. local_info_t *lp = netdev_priv(dev);
  1316. kio_addr_t ioaddr = dev->base_addr;
  1317. int okay;
  1318. unsigned freespace;
  1319. unsigned pktlen = skb? skb->len : 0;
  1320. DEBUG(1, "do_start_xmit(skb=%p, dev=%p) len=%u\n",
  1321. skb, dev, pktlen);
  1322. /* adjust the packet length to min. required
  1323. * and hope that the buffer is large enough
  1324. * to provide some random data.
  1325. * fixme: For Mohawk we can change this by sending
  1326. * a larger packetlen than we actually have; the chip will
  1327. * pad this in his buffer with random bytes
  1328. */
  1329. if (pktlen < ETH_ZLEN)
  1330. {
  1331. skb = skb_padto(skb, ETH_ZLEN);
  1332. if (skb == NULL)
  1333. return 0;
  1334. pktlen = ETH_ZLEN;
  1335. }
  1336. netif_stop_queue(dev);
  1337. SelectPage(0);
  1338. PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
  1339. freespace = GetWord(XIRCREG0_TSO);
  1340. okay = freespace & 0x8000;
  1341. freespace &= 0x7fff;
  1342. /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
  1343. okay = pktlen +2 < freespace;
  1344. DEBUG(2 + (okay ? 2 : 0), "%s: avail. tx space=%u%s\n",
  1345. dev->name, freespace, okay ? " (okay)":" (not enough)");
  1346. if (!okay) { /* not enough space */
  1347. return 1; /* upper layer may decide to requeue this packet */
  1348. }
  1349. /* send the packet */
  1350. PutWord(XIRCREG_EDP, (u_short)pktlen);
  1351. outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
  1352. if (pktlen & 1)
  1353. PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
  1354. if (lp->mohawk)
  1355. PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
  1356. dev_kfree_skb (skb);
  1357. dev->trans_start = jiffies;
  1358. lp->stats.tx_bytes += pktlen;
  1359. netif_start_queue(dev);
  1360. return 0;
  1361. }
  1362. static struct net_device_stats *
  1363. do_get_stats(struct net_device *dev)
  1364. {
  1365. local_info_t *lp = netdev_priv(dev);
  1366. /* lp->stats.rx_missed_errors = GetByte(?) */
  1367. return &lp->stats;
  1368. }
  1369. /****************
  1370. * Set all addresses: This first one is the individual address,
  1371. * the next 9 addresses are taken from the multicast list and
  1372. * the rest is filled with the individual address.
  1373. */
  1374. static void
  1375. set_addresses(struct net_device *dev)
  1376. {
  1377. kio_addr_t ioaddr = dev->base_addr;
  1378. local_info_t *lp = netdev_priv(dev);
  1379. struct dev_mc_list *dmi = dev->mc_list;
  1380. char *addr;
  1381. int i,j,k,n;
  1382. SelectPage(k=0x50);
  1383. for (i=0,j=8,n=0; ; i++, j++) {
  1384. if (i > 5) {
  1385. if (++n > 9)
  1386. break;
  1387. i = 0;
  1388. }
  1389. if (j > 15) {
  1390. j = 8;
  1391. k++;
  1392. SelectPage(k);
  1393. }
  1394. if (n && n <= dev->mc_count && dmi) {
  1395. addr = dmi->dmi_addr;
  1396. dmi = dmi->next;
  1397. } else
  1398. addr = dev->dev_addr;
  1399. if (lp->mohawk)
  1400. PutByte(j, addr[5-i]);
  1401. else
  1402. PutByte(j, addr[i]);
  1403. }
  1404. SelectPage(0);
  1405. }
  1406. /****************
  1407. * Set or clear the multicast filter for this adaptor.
  1408. * We can filter up to 9 addresses, if more are requested we set
  1409. * multicast promiscuous mode.
  1410. */
  1411. static void
  1412. set_multicast_list(struct net_device *dev)
  1413. {
  1414. kio_addr_t ioaddr = dev->base_addr;
  1415. SelectPage(0x42);
  1416. if (dev->flags & IFF_PROMISC) { /* snoop */
  1417. PutByte(XIRCREG42_SWC1, 0x06); /* set MPE and PME */
  1418. } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
  1419. PutByte(XIRCREG42_SWC1, 0x06); /* set MPE */
  1420. } else if (dev->mc_count) {
  1421. /* the chip can filter 9 addresses perfectly */
  1422. PutByte(XIRCREG42_SWC1, 0x00);
  1423. SelectPage(0x40);
  1424. PutByte(XIRCREG40_CMD0, Offline);
  1425. set_addresses(dev);
  1426. SelectPage(0x40);
  1427. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1428. } else { /* standard usage */
  1429. PutByte(XIRCREG42_SWC1, 0x00);
  1430. }
  1431. SelectPage(0);
  1432. }
  1433. static int
  1434. do_config(struct net_device *dev, struct ifmap *map)
  1435. {
  1436. local_info_t *local = netdev_priv(dev);
  1437. DEBUG(0, "do_config(%p)\n", dev);
  1438. if (map->port != 255 && map->port != dev->if_port) {
  1439. if (map->port > 4)
  1440. return -EINVAL;
  1441. if (!map->port) {
  1442. local->probe_port = 1;
  1443. dev->if_port = 1;
  1444. } else {
  1445. local->probe_port = 0;
  1446. dev->if_port = map->port;
  1447. }
  1448. printk(KERN_INFO "%s: switching to %s port\n",
  1449. dev->name, if_names[dev->if_port]);
  1450. do_reset(dev,1); /* not the fine way :-) */
  1451. }
  1452. return 0;
  1453. }
  1454. /****************
  1455. * Open the driver
  1456. */
  1457. static int
  1458. do_open(struct net_device *dev)
  1459. {
  1460. local_info_t *lp = netdev_priv(dev);
  1461. dev_link_t *link = &lp->link;
  1462. DEBUG(0, "do_open(%p)\n", dev);
  1463. /* Check that the PCMCIA card is still here. */
  1464. /* Physical device present signature. */
  1465. if (!DEV_OK(link))
  1466. return -ENODEV;
  1467. /* okay */
  1468. link->open++;
  1469. netif_start_queue(dev);
  1470. do_reset(dev,1);
  1471. return 0;
  1472. }
  1473. static void netdev_get_drvinfo(struct net_device *dev,
  1474. struct ethtool_drvinfo *info)
  1475. {
  1476. strcpy(info->driver, "xirc2ps_cs");
  1477. sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
  1478. }
  1479. static struct ethtool_ops netdev_ethtool_ops = {
  1480. .get_drvinfo = netdev_get_drvinfo,
  1481. };
  1482. static int
  1483. do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1484. {
  1485. local_info_t *local = netdev_priv(dev);
  1486. kio_addr_t ioaddr = dev->base_addr;
  1487. u16 *data = (u16 *)&rq->ifr_ifru;
  1488. DEBUG(1, "%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
  1489. dev->name, rq->ifr_ifrn.ifrn_name, cmd,
  1490. data[0], data[1], data[2], data[3]);
  1491. if (!local->mohawk)
  1492. return -EOPNOTSUPP;
  1493. switch(cmd) {
  1494. case SIOCGMIIPHY: /* Get the address of the PHY in use. */
  1495. data[0] = 0; /* we have only this address */
  1496. /* fall trough */
  1497. case SIOCGMIIREG: /* Read the specified MII register. */
  1498. data[3] = mii_rd(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
  1499. break;
  1500. case SIOCSMIIREG: /* Write the specified MII register */
  1501. if (!capable(CAP_NET_ADMIN))
  1502. return -EPERM;
  1503. mii_wr(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2], 16);
  1504. break;
  1505. default:
  1506. return -EOPNOTSUPP;
  1507. }
  1508. return 0;
  1509. }
  1510. static void
  1511. hardreset(struct net_device *dev)
  1512. {
  1513. local_info_t *local = netdev_priv(dev);
  1514. kio_addr_t ioaddr = dev->base_addr;
  1515. SelectPage(4);
  1516. udelay(1);
  1517. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1518. msleep(40); /* wait 40 msec */
  1519. if (local->mohawk)
  1520. PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */
  1521. else
  1522. PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */
  1523. msleep(20); /* wait 20 msec */
  1524. }
  1525. static void
  1526. do_reset(struct net_device *dev, int full)
  1527. {
  1528. local_info_t *local = netdev_priv(dev);
  1529. kio_addr_t ioaddr = dev->base_addr;
  1530. unsigned value;
  1531. DEBUG(0, "%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
  1532. hardreset(dev);
  1533. PutByte(XIRCREG_CR, SoftReset); /* set */
  1534. msleep(20); /* wait 20 msec */
  1535. PutByte(XIRCREG_CR, 0); /* clear */
  1536. msleep(40); /* wait 40 msec */
  1537. if (local->mohawk) {
  1538. SelectPage(4);
  1539. /* set pin GP1 and GP2 to output (0x0c)
  1540. * set GP1 to low to power up the ML6692 (0x00)
  1541. * set GP2 to high to power up the 10Mhz chip (0x02)
  1542. */
  1543. PutByte(XIRCREG4_GPR0, 0x0e);
  1544. }
  1545. /* give the circuits some time to power up */
  1546. msleep(500); /* about 500ms */
  1547. local->last_ptr_value = 0;
  1548. local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
  1549. : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
  1550. if (local->probe_port) {
  1551. if (!local->mohawk) {
  1552. SelectPage(4);
  1553. PutByte(XIRCREG4_GPR0, 4);
  1554. local->probe_port = 0;
  1555. }
  1556. } else if (dev->if_port == 2) { /* enable 10Base2 */
  1557. SelectPage(0x42);
  1558. PutByte(XIRCREG42_SWC1, 0xC0);
  1559. } else { /* enable 10BaseT */
  1560. SelectPage(0x42);
  1561. PutByte(XIRCREG42_SWC1, 0x80);
  1562. }
  1563. msleep(40); /* wait 40 msec to let it complete */
  1564. #ifdef PCMCIA_DEBUG
  1565. if (pc_debug) {
  1566. SelectPage(0);
  1567. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1568. printk(KERN_DEBUG "%s: ESR is: %#02x\n", dev->name, value);
  1569. }
  1570. #endif
  1571. /* setup the ECR */
  1572. SelectPage(1);
  1573. PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
  1574. PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */
  1575. value = GetByte(XIRCREG1_ECR);
  1576. #if 0
  1577. if (local->mohawk)
  1578. value |= DisableLinkPulse;
  1579. PutByte(XIRCREG1_ECR, value);
  1580. #endif
  1581. DEBUG(0, "%s: ECR is: %#02x\n", dev->name, value);
  1582. SelectPage(0x42);
  1583. PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
  1584. if (local->silicon != 1) {
  1585. /* set the local memory dividing line.
  1586. * The comments in the sample code say that this is only
  1587. * settable with the scipper version 2 which is revision 0.
  1588. * Always for CE3 cards
  1589. */
  1590. SelectPage(2);
  1591. PutWord(XIRCREG2_RBS, 0x2000);
  1592. }
  1593. if (full)
  1594. set_addresses(dev);
  1595. /* Hardware workaround:
  1596. * The receive byte pointer after reset is off by 1 so we need
  1597. * to move the offset pointer back to 0.
  1598. */
  1599. SelectPage(0);
  1600. PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
  1601. /* setup MAC IMRs and clear status registers */
  1602. SelectPage(0x40); /* Bit 7 ... bit 0 */
  1603. PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
  1604. PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1605. PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
  1606. PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
  1607. PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1608. PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */
  1609. if (full && local->mohawk && init_mii(dev)) {
  1610. if (dev->if_port == 4 || local->dingo || local->new_mii) {
  1611. printk(KERN_INFO "%s: MII selected\n", dev->name);
  1612. SelectPage(2);
  1613. PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
  1614. msleep(20);
  1615. } else {
  1616. printk(KERN_INFO "%s: MII detected; using 10mbs\n",
  1617. dev->name);
  1618. SelectPage(0x42);
  1619. if (dev->if_port == 2) /* enable 10Base2 */
  1620. PutByte(XIRCREG42_SWC1, 0xC0);
  1621. else /* enable 10BaseT */
  1622. PutByte(XIRCREG42_SWC1, 0x80);
  1623. msleep(40); /* wait 40 msec to let it complete */
  1624. }
  1625. if (full_duplex)
  1626. PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
  1627. } else { /* No MII */
  1628. SelectPage(0);
  1629. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1630. dev->if_port = (value & MediaSelect) ? 1 : 2;
  1631. }
  1632. /* configure the LEDs */
  1633. SelectPage(2);
  1634. if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
  1635. PutByte(XIRCREG2_LED, 0x3b);
  1636. else /* Coax: Not-Collision and Activity */
  1637. PutByte(XIRCREG2_LED, 0x3a);
  1638. if (local->dingo)
  1639. PutByte(0x0b, 0x04); /* 100 Mbit LED */
  1640. /* enable receiver and put the mac online */
  1641. if (full) {
  1642. SelectPage(0x40);
  1643. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1644. }
  1645. /* setup Ethernet IMR and enable interrupts */
  1646. SelectPage(1);
  1647. PutByte(XIRCREG1_IMR0, 0xff);
  1648. udelay(1);
  1649. SelectPage(0);
  1650. PutByte(XIRCREG_CR, EnableIntr);
  1651. if (local->modem && !local->dingo) { /* do some magic */
  1652. if (!(GetByte(0x10) & 0x01))
  1653. PutByte(0x10, 0x11); /* unmask master-int bit */
  1654. }
  1655. if (full)
  1656. printk(KERN_INFO "%s: media %s, silicon revision %d\n",
  1657. dev->name, if_names[dev->if_port], local->silicon);
  1658. /* We should switch back to page 0 to avoid a bug in revision 0
  1659. * where regs with offset below 8 can't be read after an access
  1660. * to the MAC registers */
  1661. SelectPage(0);
  1662. }
  1663. /****************
  1664. * Initialize the Media-Independent-Interface
  1665. * Returns: True if we have a good MII
  1666. */
  1667. static int
  1668. init_mii(struct net_device *dev)
  1669. {
  1670. local_info_t *local = netdev_priv(dev);
  1671. kio_addr_t ioaddr = dev->base_addr;
  1672. unsigned control, status, linkpartner;
  1673. int i;
  1674. if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
  1675. dev->if_port = if_port;
  1676. local->probe_port = 0;
  1677. return 1;
  1678. }
  1679. status = mii_rd(ioaddr, 0, 1);
  1680. if ((status & 0xff00) != 0x7800)
  1681. return 0; /* No MII */
  1682. local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
  1683. if (local->probe_port)
  1684. control = 0x1000; /* auto neg */
  1685. else if (dev->if_port == 4)
  1686. control = 0x2000; /* no auto neg, 100mbs mode */
  1687. else
  1688. control = 0x0000; /* no auto neg, 10mbs mode */
  1689. mii_wr(ioaddr, 0, 0, control, 16);
  1690. udelay(100);
  1691. control = mii_rd(ioaddr, 0, 0);
  1692. if (control & 0x0400) {
  1693. printk(KERN_NOTICE "%s can't take PHY out of isolation mode\n",
  1694. dev->name);
  1695. local->probe_port = 0;
  1696. return 0;
  1697. }
  1698. if (local->probe_port) {
  1699. /* according to the DP83840A specs the auto negotiation process
  1700. * may take up to 3.5 sec, so we use this also for our ML6692
  1701. * Fixme: Better to use a timer here!
  1702. */
  1703. for (i=0; i < 35; i++) {
  1704. msleep(100); /* wait 100 msec */
  1705. status = mii_rd(ioaddr, 0, 1);
  1706. if ((status & 0x0020) && (status & 0x0004))
  1707. break;
  1708. }
  1709. if (!(status & 0x0020)) {
  1710. printk(KERN_INFO "%s: autonegotiation failed;"
  1711. " using 10mbs\n", dev->name);
  1712. if (!local->new_mii) {
  1713. control = 0x0000;
  1714. mii_wr(ioaddr, 0, 0, control, 16);
  1715. udelay(100);
  1716. SelectPage(0);
  1717. dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
  1718. }
  1719. } else {
  1720. linkpartner = mii_rd(ioaddr, 0, 5);
  1721. printk(KERN_INFO "%s: MII link partner: %04x\n",
  1722. dev->name, linkpartner);
  1723. if (linkpartner & 0x0080) {
  1724. dev->if_port = 4;
  1725. } else
  1726. dev->if_port = 1;
  1727. }
  1728. }
  1729. return 1;
  1730. }
  1731. static void
  1732. do_powerdown(struct net_device *dev)
  1733. {
  1734. kio_addr_t ioaddr = dev->base_addr;
  1735. DEBUG(0, "do_powerdown(%p)\n", dev);
  1736. SelectPage(4);
  1737. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1738. SelectPage(0);
  1739. }
  1740. static int
  1741. do_stop(struct net_device *dev)
  1742. {
  1743. kio_addr_t ioaddr = dev->base_addr;
  1744. local_info_t *lp = netdev_priv(dev);
  1745. dev_link_t *link = &lp->link;
  1746. DEBUG(0, "do_stop(%p)\n", dev);
  1747. if (!link)
  1748. return -ENODEV;
  1749. netif_stop_queue(dev);
  1750. SelectPage(0);
  1751. PutByte(XIRCREG_CR, 0); /* disable interrupts */
  1752. SelectPage(0x01);
  1753. PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
  1754. SelectPage(4);
  1755. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1756. SelectPage(0);
  1757. link->open--;
  1758. return 0;
  1759. }
  1760. static struct pcmcia_device_id xirc2ps_ids[] = {
  1761. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
  1762. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
  1763. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
  1764. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
  1765. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
  1766. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
  1767. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
  1768. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
  1769. PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
  1770. PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
  1771. PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
  1772. PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
  1773. PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
  1774. PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
  1775. PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
  1776. PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
  1777. PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
  1778. PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
  1779. PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
  1780. /* also matches CFE-10 cards! */
  1781. /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
  1782. PCMCIA_DEVICE_NULL,
  1783. };
  1784. MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
  1785. static struct pcmcia_driver xirc2ps_cs_driver = {
  1786. .owner = THIS_MODULE,
  1787. .drv = {
  1788. .name = "xirc2ps_cs",
  1789. },
  1790. .attach = xirc2ps_attach,
  1791. .event = xirc2ps_event,
  1792. .remove = xirc2ps_detach,
  1793. .id_table = xirc2ps_ids,
  1794. .suspend = xirc2ps_suspend,
  1795. .resume = xirc2ps_resume,
  1796. };
  1797. static int __init
  1798. init_xirc2ps_cs(void)
  1799. {
  1800. return pcmcia_register_driver(&xirc2ps_cs_driver);
  1801. }
  1802. static void __exit
  1803. exit_xirc2ps_cs(void)
  1804. {
  1805. pcmcia_unregister_driver(&xirc2ps_cs_driver);
  1806. BUG_ON(dev_list != NULL);
  1807. }
  1808. module_init(init_xirc2ps_cs);
  1809. module_exit(exit_xirc2ps_cs);
  1810. #ifndef MODULE
  1811. static int __init setup_xirc2ps_cs(char *str)
  1812. {
  1813. /* if_port, full_duplex, do_sound, lockup_hack
  1814. */
  1815. int ints[10] = { -1 };
  1816. str = get_options(str, 9, ints);
  1817. #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
  1818. MAYBE_SET(if_port, 3);
  1819. MAYBE_SET(full_duplex, 4);
  1820. MAYBE_SET(do_sound, 5);
  1821. MAYBE_SET(lockup_hack, 6);
  1822. #undef MAYBE_SET
  1823. return 0;
  1824. }
  1825. __setup("xirc2ps_cs=", setup_xirc2ps_cs);
  1826. #endif