xirc2ps_cs.c 54 KB

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