xirc2ps_cs.c 52 KB

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