xirc2ps_cs.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  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 <asm/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);
  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_do_ioctl = do_ioctl,
  427. .ndo_set_rx_mode = set_multicast_list,
  428. .ndo_change_mtu = eth_change_mtu,
  429. .ndo_set_mac_address = eth_mac_addr,
  430. .ndo_validate_addr = eth_validate_addr,
  431. };
  432. static int
  433. xirc2ps_probe(struct pcmcia_device *link)
  434. {
  435. struct net_device *dev;
  436. struct local_info *local;
  437. dev_dbg(&link->dev, "attach()\n");
  438. /* Allocate the device structure */
  439. dev = alloc_etherdev(sizeof(struct local_info));
  440. if (!dev)
  441. return -ENOMEM;
  442. local = netdev_priv(dev);
  443. local->dev = dev;
  444. local->p_dev = link;
  445. link->priv = dev;
  446. /* General socket configuration */
  447. link->config_index = 1;
  448. /* Fill in card specific entries */
  449. dev->netdev_ops = &netdev_ops;
  450. dev->ethtool_ops = &netdev_ethtool_ops;
  451. dev->watchdog_timeo = TX_TIMEOUT;
  452. INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
  453. return xirc2ps_config(link);
  454. } /* xirc2ps_attach */
  455. static void
  456. xirc2ps_detach(struct pcmcia_device *link)
  457. {
  458. struct net_device *dev = link->priv;
  459. dev_dbg(&link->dev, "detach\n");
  460. unregister_netdev(dev);
  461. xirc2ps_release(link);
  462. free_netdev(dev);
  463. } /* xirc2ps_detach */
  464. /****************
  465. * Detect the type of the card. s is the buffer with the data of tuple 0x20
  466. * Returns: 0 := not supported
  467. * mediaid=11 and prodid=47
  468. * Media-Id bits:
  469. * Ethernet 0x01
  470. * Tokenring 0x02
  471. * Arcnet 0x04
  472. * Wireless 0x08
  473. * Modem 0x10
  474. * GSM only 0x20
  475. * Prod-Id bits:
  476. * Pocket 0x10
  477. * External 0x20
  478. * Creditcard 0x40
  479. * Cardbus 0x80
  480. *
  481. */
  482. static int
  483. set_card_type(struct pcmcia_device *link)
  484. {
  485. struct net_device *dev = link->priv;
  486. struct local_info *local = netdev_priv(dev);
  487. u8 *buf;
  488. unsigned int cisrev, mediaid, prodid;
  489. size_t len;
  490. len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
  491. if (len < 5) {
  492. dev_err(&link->dev, "invalid CIS -- sorry\n");
  493. return 0;
  494. }
  495. cisrev = buf[2];
  496. mediaid = buf[3];
  497. prodid = buf[4];
  498. dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
  499. cisrev, mediaid, prodid);
  500. local->mohawk = 0;
  501. local->dingo = 0;
  502. local->modem = 0;
  503. local->card_type = XIR_UNKNOWN;
  504. if (!(prodid & 0x40)) {
  505. pr_notice("Oops: Not a creditcard\n");
  506. return 0;
  507. }
  508. if (!(mediaid & 0x01)) {
  509. pr_notice("Not an Ethernet card\n");
  510. return 0;
  511. }
  512. if (mediaid & 0x10) {
  513. local->modem = 1;
  514. switch(prodid & 15) {
  515. case 1: local->card_type = XIR_CEM ; break;
  516. case 2: local->card_type = XIR_CEM2 ; break;
  517. case 3: local->card_type = XIR_CEM3 ; break;
  518. case 4: local->card_type = XIR_CEM33 ; break;
  519. case 5: local->card_type = XIR_CEM56M;
  520. local->mohawk = 1;
  521. break;
  522. case 6:
  523. case 7: /* 7 is the RealPort 10/56 */
  524. local->card_type = XIR_CEM56 ;
  525. local->mohawk = 1;
  526. local->dingo = 1;
  527. break;
  528. }
  529. } else {
  530. switch(prodid & 15) {
  531. case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
  532. break;
  533. case 2: local->card_type = XIR_CE2; break;
  534. case 3: local->card_type = XIR_CE3;
  535. local->mohawk = 1;
  536. break;
  537. }
  538. }
  539. if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
  540. pr_notice("Sorry, this is an old CE card\n");
  541. return 0;
  542. }
  543. if (local->card_type == XIR_UNKNOWN)
  544. pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
  545. return 1;
  546. }
  547. /****************
  548. * There are some CE2 cards out which claim to be a CE card.
  549. * This function looks for a "CE2" in the 3rd version field.
  550. * Returns: true if this is a CE2
  551. */
  552. static int
  553. has_ce2_string(struct pcmcia_device * p_dev)
  554. {
  555. if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
  556. return 1;
  557. return 0;
  558. }
  559. static int
  560. xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
  561. {
  562. unsigned int ioaddr;
  563. if ((p_dev->resource[0]->start & 0xf) == 8)
  564. return -ENODEV;
  565. p_dev->resource[0]->end = 16;
  566. p_dev->resource[1]->end = 8;
  567. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  568. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
  569. p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  570. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  571. p_dev->io_lines = 10;
  572. p_dev->resource[1]->start = p_dev->resource[0]->start;
  573. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  574. p_dev->resource[0]->start = ioaddr;
  575. if (!pcmcia_request_io(p_dev))
  576. return 0;
  577. }
  578. return -ENODEV;
  579. }
  580. static int
  581. xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
  582. {
  583. int *pass = priv_data;
  584. resource_size_t tmp = p_dev->resource[1]->start;
  585. tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
  586. : (p_dev->config_index & 0x20 ? 8 : -24));
  587. if ((p_dev->resource[0]->start & 0xf) == 8)
  588. return -ENODEV;
  589. p_dev->resource[0]->end = 18;
  590. p_dev->resource[1]->end = 8;
  591. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  592. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
  593. p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  594. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  595. p_dev->io_lines = 10;
  596. p_dev->resource[1]->start = p_dev->resource[0]->start;
  597. p_dev->resource[0]->start = tmp;
  598. return pcmcia_request_io(p_dev);
  599. }
  600. static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
  601. tuple_t *tuple,
  602. void *priv)
  603. {
  604. struct net_device *dev = priv;
  605. int i;
  606. if (tuple->TupleDataLen != 13)
  607. return -EINVAL;
  608. if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
  609. (tuple->TupleData[2] != 6))
  610. return -EINVAL;
  611. /* another try (James Lehmer's CE2 version 4.1)*/
  612. for (i = 2; i < 6; i++)
  613. dev->dev_addr[i] = tuple->TupleData[i+2];
  614. return 0;
  615. };
  616. static int
  617. xirc2ps_config(struct pcmcia_device * link)
  618. {
  619. struct net_device *dev = link->priv;
  620. struct local_info *local = netdev_priv(dev);
  621. unsigned int ioaddr;
  622. int err;
  623. u8 *buf;
  624. size_t len;
  625. local->dingo_ccr = NULL;
  626. dev_dbg(&link->dev, "config\n");
  627. /* Is this a valid card */
  628. if (link->has_manf_id == 0) {
  629. pr_notice("manfid not found in CIS\n");
  630. goto failure;
  631. }
  632. switch (link->manf_id) {
  633. case MANFID_XIRCOM:
  634. local->manf_str = "Xircom";
  635. break;
  636. case MANFID_ACCTON:
  637. local->manf_str = "Accton";
  638. break;
  639. case MANFID_COMPAQ:
  640. case MANFID_COMPAQ2:
  641. local->manf_str = "Compaq";
  642. break;
  643. case MANFID_INTEL:
  644. local->manf_str = "Intel";
  645. break;
  646. case MANFID_TOSHIBA:
  647. local->manf_str = "Toshiba";
  648. break;
  649. default:
  650. pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
  651. (unsigned)link->manf_id);
  652. goto failure;
  653. }
  654. dev_dbg(&link->dev, "found %s card\n", local->manf_str);
  655. if (!set_card_type(link)) {
  656. pr_notice("this card is not supported\n");
  657. goto failure;
  658. }
  659. /* get the ethernet address from the CIS */
  660. err = pcmcia_get_mac_from_cis(link, dev);
  661. /* not found: try to get the node-id from tuple 0x89 */
  662. if (err) {
  663. len = pcmcia_get_tuple(link, 0x89, &buf);
  664. /* data layout looks like tuple 0x22 */
  665. if (buf && len == 8) {
  666. if (*buf == CISTPL_FUNCE_LAN_NODE_ID) {
  667. int i;
  668. for (i = 2; i < 6; i++)
  669. dev->dev_addr[i] = buf[i+2];
  670. } else
  671. err = -1;
  672. }
  673. kfree(buf);
  674. }
  675. if (err)
  676. err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
  677. if (err) {
  678. pr_notice("node-id not found in CIS\n");
  679. goto failure;
  680. }
  681. if (local->modem) {
  682. int pass;
  683. link->config_flags |= CONF_AUTO_SET_IO;
  684. if (local->dingo) {
  685. /* Take the Modem IO port from the CIS and scan for a free
  686. * Ethernet port */
  687. if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
  688. goto port_found;
  689. } else {
  690. /* We do 2 passes here: The first one uses the regular mapping and
  691. * the second tries again, thereby considering that the 32 ports are
  692. * mirrored every 32 bytes. Actually we use a mirrored port for
  693. * the Mako if (on the first pass) the COR bit 5 is set.
  694. */
  695. for (pass=0; pass < 2; pass++)
  696. if (!pcmcia_loop_config(link, xirc2ps_config_check,
  697. &pass))
  698. goto port_found;
  699. /* if special option:
  700. * try to configure as Ethernet only.
  701. * .... */
  702. }
  703. pr_notice("no ports available\n");
  704. } else {
  705. link->io_lines = 10;
  706. link->resource[0]->end = 16;
  707. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
  708. for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
  709. link->resource[0]->start = ioaddr;
  710. if (!(err = pcmcia_request_io(link)))
  711. goto port_found;
  712. }
  713. link->resource[0]->start = 0; /* let CS decide */
  714. if ((err = pcmcia_request_io(link)))
  715. goto config_error;
  716. }
  717. port_found:
  718. if (err)
  719. goto config_error;
  720. /****************
  721. * Now allocate an interrupt line. Note that this does not
  722. * actually assign a handler to the interrupt.
  723. */
  724. if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
  725. goto config_error;
  726. link->config_flags |= CONF_ENABLE_IRQ;
  727. if (do_sound)
  728. link->config_flags |= CONF_ENABLE_SPKR;
  729. if ((err = pcmcia_enable_device(link)))
  730. goto config_error;
  731. if (local->dingo) {
  732. /* Reset the modem's BAR to the correct value
  733. * This is necessary because in the RequestConfiguration call,
  734. * the base address of the ethernet port (BasePort1) is written
  735. * to the BAR registers of the modem.
  736. */
  737. err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
  738. link->resource[1]->start & 0xff);
  739. if (err)
  740. goto config_error;
  741. err = pcmcia_write_config_byte(link, CISREG_IOBASE_1,
  742. (link->resource[1]->start >> 8) & 0xff);
  743. if (err)
  744. goto config_error;
  745. /* There is no config entry for the Ethernet part which
  746. * is at 0x0800. So we allocate a window into the attribute
  747. * memory and write direct to the CIS registers
  748. */
  749. link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
  750. WIN_ENABLE;
  751. link->resource[2]->start = link->resource[2]->end = 0;
  752. if ((err = pcmcia_request_window(link, link->resource[2], 0)))
  753. goto config_error;
  754. local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
  755. if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
  756. goto config_error;
  757. /* Setup the CCRs; there are no infos in the CIS about the Ethernet
  758. * part.
  759. */
  760. writeb(0x47, local->dingo_ccr + CISREG_COR);
  761. ioaddr = link->resource[0]->start;
  762. writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0);
  763. writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
  764. #if 0
  765. {
  766. u_char tmp;
  767. pr_info("ECOR:");
  768. for (i=0; i < 7; i++) {
  769. tmp = readb(local->dingo_ccr + i*2);
  770. pr_cont(" %02x", tmp);
  771. }
  772. pr_cont("\n");
  773. pr_info("DCOR:");
  774. for (i=0; i < 4; i++) {
  775. tmp = readb(local->dingo_ccr + 0x20 + i*2);
  776. pr_cont(" %02x", tmp);
  777. }
  778. pr_cont("\n");
  779. pr_info("SCOR:");
  780. for (i=0; i < 10; i++) {
  781. tmp = readb(local->dingo_ccr + 0x40 + i*2);
  782. pr_cont(" %02x", tmp);
  783. }
  784. pr_cont("\n");
  785. }
  786. #endif
  787. writeb(0x01, local->dingo_ccr + 0x20);
  788. writeb(0x0c, local->dingo_ccr + 0x22);
  789. writeb(0x00, local->dingo_ccr + 0x24);
  790. writeb(0x00, local->dingo_ccr + 0x26);
  791. writeb(0x00, local->dingo_ccr + 0x28);
  792. }
  793. /* The if_port symbol can be set when the module is loaded */
  794. local->probe_port=0;
  795. if (!if_port) {
  796. local->probe_port = dev->if_port = 1;
  797. } else if ((if_port >= 1 && if_port <= 2) ||
  798. (local->mohawk && if_port==4))
  799. dev->if_port = if_port;
  800. else
  801. pr_notice("invalid if_port requested\n");
  802. /* we can now register the device with the net subsystem */
  803. dev->irq = link->irq;
  804. dev->base_addr = link->resource[0]->start;
  805. if (local->dingo)
  806. do_reset(dev, 1); /* a kludge to make the cem56 work */
  807. SET_NETDEV_DEV(dev, &link->dev);
  808. if ((err=register_netdev(dev))) {
  809. pr_notice("register_netdev() failed\n");
  810. goto config_error;
  811. }
  812. /* give some infos about the hardware */
  813. netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
  814. local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
  815. dev->dev_addr);
  816. return 0;
  817. config_error:
  818. xirc2ps_release(link);
  819. return -ENODEV;
  820. failure:
  821. return -ENODEV;
  822. } /* xirc2ps_config */
  823. static void
  824. xirc2ps_release(struct pcmcia_device *link)
  825. {
  826. dev_dbg(&link->dev, "release\n");
  827. if (link->resource[2]->end) {
  828. struct net_device *dev = link->priv;
  829. struct local_info *local = netdev_priv(dev);
  830. if (local->dingo)
  831. iounmap(local->dingo_ccr - 0x0800);
  832. }
  833. pcmcia_disable_device(link);
  834. } /* xirc2ps_release */
  835. /*====================================================================*/
  836. static int xirc2ps_suspend(struct pcmcia_device *link)
  837. {
  838. struct net_device *dev = link->priv;
  839. if (link->open) {
  840. netif_device_detach(dev);
  841. do_powerdown(dev);
  842. }
  843. return 0;
  844. }
  845. static int xirc2ps_resume(struct pcmcia_device *link)
  846. {
  847. struct net_device *dev = link->priv;
  848. if (link->open) {
  849. do_reset(dev,1);
  850. netif_device_attach(dev);
  851. }
  852. return 0;
  853. }
  854. /*====================================================================*/
  855. /****************
  856. * This is the Interrupt service route.
  857. */
  858. static irqreturn_t
  859. xirc2ps_interrupt(int irq, void *dev_id)
  860. {
  861. struct net_device *dev = (struct net_device *)dev_id;
  862. struct local_info *lp = netdev_priv(dev);
  863. unsigned int ioaddr;
  864. u_char saved_page;
  865. unsigned bytes_rcvd;
  866. unsigned int_status, eth_status, rx_status, tx_status;
  867. unsigned rsr, pktlen;
  868. ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
  869. * is this something to worry about?
  870. * -- on a laptop?
  871. */
  872. if (!netif_device_present(dev))
  873. return IRQ_HANDLED;
  874. ioaddr = dev->base_addr;
  875. if (lp->mohawk) { /* must disable the interrupt */
  876. PutByte(XIRCREG_CR, 0);
  877. }
  878. pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
  879. saved_page = GetByte(XIRCREG_PR);
  880. /* Read the ISR to see whats the cause for the interrupt.
  881. * This also clears the interrupt flags on CE2 cards
  882. */
  883. int_status = GetByte(XIRCREG_ISR);
  884. bytes_rcvd = 0;
  885. loop_entry:
  886. if (int_status == 0xff) { /* card may be ejected */
  887. pr_debug("%s: interrupt %d for dead card\n", dev->name, irq);
  888. goto leave;
  889. }
  890. eth_status = GetByte(XIRCREG_ESR);
  891. SelectPage(0x40);
  892. rx_status = GetByte(XIRCREG40_RXST0);
  893. PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
  894. tx_status = GetByte(XIRCREG40_TXST0);
  895. tx_status |= GetByte(XIRCREG40_TXST1) << 8;
  896. PutByte(XIRCREG40_TXST0, 0);
  897. PutByte(XIRCREG40_TXST1, 0);
  898. pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
  899. dev->name, int_status, eth_status, rx_status, tx_status);
  900. /***** receive section ******/
  901. SelectPage(0);
  902. while (eth_status & FullPktRcvd) {
  903. rsr = GetByte(XIRCREG0_RSR);
  904. if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
  905. /* too many bytes received during this int, drop the rest of the
  906. * packets */
  907. dev->stats.rx_dropped++;
  908. pr_debug("%s: RX drop, too much done\n", dev->name);
  909. } else if (rsr & PktRxOk) {
  910. struct sk_buff *skb;
  911. pktlen = GetWord(XIRCREG0_RBC);
  912. bytes_rcvd += pktlen;
  913. pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen);
  914. /* 1 extra so we can use insw */
  915. skb = netdev_alloc_skb(dev, pktlen + 3);
  916. if (!skb) {
  917. dev->stats.rx_dropped++;
  918. } else { /* okay get the packet */
  919. skb_reserve(skb, 2);
  920. if (lp->silicon == 0 ) { /* work around a hardware bug */
  921. unsigned rhsa; /* receive start address */
  922. SelectPage(5);
  923. rhsa = GetWord(XIRCREG5_RHSA0);
  924. SelectPage(0);
  925. rhsa += 3; /* skip control infos */
  926. if (rhsa >= 0x8000)
  927. rhsa = 0;
  928. if (rhsa + pktlen > 0x8000) {
  929. unsigned i;
  930. u_char *buf = skb_put(skb, pktlen);
  931. for (i=0; i < pktlen ; i++, rhsa++) {
  932. buf[i] = GetByte(XIRCREG_EDP);
  933. if (rhsa == 0x8000) {
  934. rhsa = 0;
  935. i--;
  936. }
  937. }
  938. } else {
  939. insw(ioaddr+XIRCREG_EDP,
  940. skb_put(skb, pktlen), (pktlen+1)>>1);
  941. }
  942. }
  943. #if 0
  944. else if (lp->mohawk) {
  945. /* To use this 32 bit access we should use
  946. * a manual optimized loop
  947. * Also the words are swapped, we can get more
  948. * performance by using 32 bit access and swapping
  949. * the words in a register. Will need this for cardbus
  950. *
  951. * Note: don't forget to change the ALLOC_SKB to .. +3
  952. */
  953. unsigned i;
  954. u_long *p = skb_put(skb, pktlen);
  955. register u_long a;
  956. unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
  957. for (i=0; i < len ; i += 4, p++) {
  958. a = inl(edpreg);
  959. __asm__("rorl $16,%0\n\t"
  960. :"=q" (a)
  961. : "0" (a));
  962. *p = a;
  963. }
  964. }
  965. #endif
  966. else {
  967. insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
  968. (pktlen+1)>>1);
  969. }
  970. skb->protocol = eth_type_trans(skb, dev);
  971. netif_rx(skb);
  972. dev->stats.rx_packets++;
  973. dev->stats.rx_bytes += pktlen;
  974. if (!(rsr & PhyPkt))
  975. dev->stats.multicast++;
  976. }
  977. } else { /* bad packet */
  978. pr_debug("rsr=%#02x\n", rsr);
  979. }
  980. if (rsr & PktTooLong) {
  981. dev->stats.rx_frame_errors++;
  982. pr_debug("%s: Packet too long\n", dev->name);
  983. }
  984. if (rsr & CRCErr) {
  985. dev->stats.rx_crc_errors++;
  986. pr_debug("%s: CRC error\n", dev->name);
  987. }
  988. if (rsr & AlignErr) {
  989. dev->stats.rx_fifo_errors++; /* okay ? */
  990. pr_debug("%s: Alignment error\n", dev->name);
  991. }
  992. /* clear the received/dropped/error packet */
  993. PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
  994. /* get the new ethernet status */
  995. eth_status = GetByte(XIRCREG_ESR);
  996. }
  997. if (rx_status & 0x10) { /* Receive overrun */
  998. dev->stats.rx_over_errors++;
  999. PutByte(XIRCREG_CR, ClearRxOvrun);
  1000. pr_debug("receive overrun cleared\n");
  1001. }
  1002. /***** transmit section ******/
  1003. if (int_status & PktTxed) {
  1004. unsigned n, nn;
  1005. n = lp->last_ptr_value;
  1006. nn = GetByte(XIRCREG0_PTR);
  1007. lp->last_ptr_value = nn;
  1008. if (nn < n) /* rollover */
  1009. dev->stats.tx_packets += 256 - n;
  1010. else if (n == nn) { /* happens sometimes - don't know why */
  1011. pr_debug("PTR not changed?\n");
  1012. } else
  1013. dev->stats.tx_packets += lp->last_ptr_value - n;
  1014. netif_wake_queue(dev);
  1015. }
  1016. if (tx_status & 0x0002) { /* Execessive collissions */
  1017. pr_debug("tx restarted due to execssive collissions\n");
  1018. PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */
  1019. }
  1020. if (tx_status & 0x0040)
  1021. dev->stats.tx_aborted_errors++;
  1022. /* recalculate our work chunk so that we limit the duration of this
  1023. * ISR to about 1/10 of a second.
  1024. * Calculate only if we received a reasonable amount of bytes.
  1025. */
  1026. if (bytes_rcvd > 1000) {
  1027. u_long duration = jiffies - start_ticks;
  1028. if (duration >= HZ/10) { /* if more than about 1/10 second */
  1029. maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
  1030. if (maxrx_bytes < 2000)
  1031. maxrx_bytes = 2000;
  1032. else if (maxrx_bytes > 22000)
  1033. maxrx_bytes = 22000;
  1034. pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
  1035. maxrx_bytes, bytes_rcvd, duration);
  1036. } else if (!duration && maxrx_bytes < 22000) {
  1037. /* now much faster */
  1038. maxrx_bytes += 2000;
  1039. if (maxrx_bytes > 22000)
  1040. maxrx_bytes = 22000;
  1041. pr_debug("set maxrx=%u\n", maxrx_bytes);
  1042. }
  1043. }
  1044. leave:
  1045. if (lockup_hack) {
  1046. if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
  1047. goto loop_entry;
  1048. }
  1049. SelectPage(saved_page);
  1050. PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */
  1051. /* Instead of dropping packets during a receive, we could
  1052. * force an interrupt with this command:
  1053. * PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
  1054. */
  1055. return IRQ_HANDLED;
  1056. } /* xirc2ps_interrupt */
  1057. /*====================================================================*/
  1058. static void
  1059. xirc2ps_tx_timeout_task(struct work_struct *work)
  1060. {
  1061. struct local_info *local =
  1062. container_of(work, struct local_info, tx_timeout_task);
  1063. struct net_device *dev = local->dev;
  1064. /* reset the card */
  1065. do_reset(dev,1);
  1066. dev->trans_start = jiffies; /* prevent tx timeout */
  1067. netif_wake_queue(dev);
  1068. }
  1069. static void
  1070. xirc_tx_timeout(struct net_device *dev)
  1071. {
  1072. struct local_info *lp = netdev_priv(dev);
  1073. dev->stats.tx_errors++;
  1074. netdev_notice(dev, "transmit timed out\n");
  1075. schedule_work(&lp->tx_timeout_task);
  1076. }
  1077. static netdev_tx_t
  1078. do_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1079. {
  1080. struct local_info *lp = netdev_priv(dev);
  1081. unsigned int ioaddr = dev->base_addr;
  1082. int okay;
  1083. unsigned freespace;
  1084. unsigned pktlen = skb->len;
  1085. pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n",
  1086. skb, dev, pktlen);
  1087. /* adjust the packet length to min. required
  1088. * and hope that the buffer is large enough
  1089. * to provide some random data.
  1090. * fixme: For Mohawk we can change this by sending
  1091. * a larger packetlen than we actually have; the chip will
  1092. * pad this in his buffer with random bytes
  1093. */
  1094. if (pktlen < ETH_ZLEN)
  1095. {
  1096. if (skb_padto(skb, ETH_ZLEN))
  1097. return NETDEV_TX_OK;
  1098. pktlen = ETH_ZLEN;
  1099. }
  1100. netif_stop_queue(dev);
  1101. SelectPage(0);
  1102. PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
  1103. freespace = GetWord(XIRCREG0_TSO);
  1104. okay = freespace & 0x8000;
  1105. freespace &= 0x7fff;
  1106. /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
  1107. okay = pktlen +2 < freespace;
  1108. pr_debug("%s: avail. tx space=%u%s\n",
  1109. dev->name, freespace, okay ? " (okay)":" (not enough)");
  1110. if (!okay) { /* not enough space */
  1111. return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */
  1112. }
  1113. /* send the packet */
  1114. PutWord(XIRCREG_EDP, (u_short)pktlen);
  1115. outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
  1116. if (pktlen & 1)
  1117. PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
  1118. if (lp->mohawk)
  1119. PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
  1120. dev_kfree_skb (skb);
  1121. dev->stats.tx_bytes += pktlen;
  1122. netif_start_queue(dev);
  1123. return NETDEV_TX_OK;
  1124. }
  1125. struct set_address_info {
  1126. int reg_nr;
  1127. int page_nr;
  1128. int mohawk;
  1129. unsigned int ioaddr;
  1130. };
  1131. static void set_address(struct set_address_info *sa_info, char *addr)
  1132. {
  1133. unsigned int ioaddr = sa_info->ioaddr;
  1134. int i;
  1135. for (i = 0; i < 6; i++) {
  1136. if (sa_info->reg_nr > 15) {
  1137. sa_info->reg_nr = 8;
  1138. sa_info->page_nr++;
  1139. SelectPage(sa_info->page_nr);
  1140. }
  1141. if (sa_info->mohawk)
  1142. PutByte(sa_info->reg_nr++, addr[5 - i]);
  1143. else
  1144. PutByte(sa_info->reg_nr++, addr[i]);
  1145. }
  1146. }
  1147. /****************
  1148. * Set all addresses: This first one is the individual address,
  1149. * the next 9 addresses are taken from the multicast list and
  1150. * the rest is filled with the individual address.
  1151. */
  1152. static void set_addresses(struct net_device *dev)
  1153. {
  1154. unsigned int ioaddr = dev->base_addr;
  1155. struct local_info *lp = netdev_priv(dev);
  1156. struct netdev_hw_addr *ha;
  1157. struct set_address_info sa_info;
  1158. int i;
  1159. /*
  1160. * Setup the info structure so that by first set_address call it will do
  1161. * SelectPage with the right page number. Hence these ones here.
  1162. */
  1163. sa_info.reg_nr = 15 + 1;
  1164. sa_info.page_nr = 0x50 - 1;
  1165. sa_info.mohawk = lp->mohawk;
  1166. sa_info.ioaddr = ioaddr;
  1167. set_address(&sa_info, dev->dev_addr);
  1168. i = 0;
  1169. netdev_for_each_mc_addr(ha, dev) {
  1170. if (i++ == 9)
  1171. break;
  1172. set_address(&sa_info, ha->addr);
  1173. }
  1174. while (i++ < 9)
  1175. set_address(&sa_info, dev->dev_addr);
  1176. SelectPage(0);
  1177. }
  1178. /****************
  1179. * Set or clear the multicast filter for this adaptor.
  1180. * We can filter up to 9 addresses, if more are requested we set
  1181. * multicast promiscuous mode.
  1182. */
  1183. static void
  1184. set_multicast_list(struct net_device *dev)
  1185. {
  1186. unsigned int ioaddr = dev->base_addr;
  1187. unsigned value;
  1188. SelectPage(0x42);
  1189. value = GetByte(XIRCREG42_SWC1) & 0xC0;
  1190. if (dev->flags & IFF_PROMISC) { /* snoop */
  1191. PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */
  1192. } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) {
  1193. PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */
  1194. } else if (!netdev_mc_empty(dev)) {
  1195. /* the chip can filter 9 addresses perfectly */
  1196. PutByte(XIRCREG42_SWC1, value | 0x01);
  1197. SelectPage(0x40);
  1198. PutByte(XIRCREG40_CMD0, Offline);
  1199. set_addresses(dev);
  1200. SelectPage(0x40);
  1201. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1202. } else { /* standard usage */
  1203. PutByte(XIRCREG42_SWC1, value | 0x00);
  1204. }
  1205. SelectPage(0);
  1206. }
  1207. static int
  1208. do_config(struct net_device *dev, struct ifmap *map)
  1209. {
  1210. struct local_info *local = netdev_priv(dev);
  1211. pr_debug("do_config(%p)\n", dev);
  1212. if (map->port != 255 && map->port != dev->if_port) {
  1213. if (map->port > 4)
  1214. return -EINVAL;
  1215. if (!map->port) {
  1216. local->probe_port = 1;
  1217. dev->if_port = 1;
  1218. } else {
  1219. local->probe_port = 0;
  1220. dev->if_port = map->port;
  1221. }
  1222. netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]);
  1223. do_reset(dev,1); /* not the fine way :-) */
  1224. }
  1225. return 0;
  1226. }
  1227. /****************
  1228. * Open the driver
  1229. */
  1230. static int
  1231. do_open(struct net_device *dev)
  1232. {
  1233. struct local_info *lp = netdev_priv(dev);
  1234. struct pcmcia_device *link = lp->p_dev;
  1235. dev_dbg(&link->dev, "do_open(%p)\n", dev);
  1236. /* Check that the PCMCIA card is still here. */
  1237. /* Physical device present signature. */
  1238. if (!pcmcia_dev_present(link))
  1239. return -ENODEV;
  1240. /* okay */
  1241. link->open++;
  1242. netif_start_queue(dev);
  1243. do_reset(dev,1);
  1244. return 0;
  1245. }
  1246. static void netdev_get_drvinfo(struct net_device *dev,
  1247. struct ethtool_drvinfo *info)
  1248. {
  1249. strlcpy(info->driver, "xirc2ps_cs", sizeof(info->driver));
  1250. snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx",
  1251. dev->base_addr);
  1252. }
  1253. static const struct ethtool_ops netdev_ethtool_ops = {
  1254. .get_drvinfo = netdev_get_drvinfo,
  1255. };
  1256. static int
  1257. do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1258. {
  1259. struct local_info *local = netdev_priv(dev);
  1260. unsigned int ioaddr = dev->base_addr;
  1261. struct mii_ioctl_data *data = if_mii(rq);
  1262. pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
  1263. dev->name, rq->ifr_ifrn.ifrn_name, cmd,
  1264. data->phy_id, data->reg_num, data->val_in, data->val_out);
  1265. if (!local->mohawk)
  1266. return -EOPNOTSUPP;
  1267. switch(cmd) {
  1268. case SIOCGMIIPHY: /* Get the address of the PHY in use. */
  1269. data->phy_id = 0; /* we have only this address */
  1270. /* fall through */
  1271. case SIOCGMIIREG: /* Read the specified MII register. */
  1272. data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f,
  1273. data->reg_num & 0x1f);
  1274. break;
  1275. case SIOCSMIIREG: /* Write the specified MII register */
  1276. mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in,
  1277. 16);
  1278. break;
  1279. default:
  1280. return -EOPNOTSUPP;
  1281. }
  1282. return 0;
  1283. }
  1284. static void
  1285. hardreset(struct net_device *dev)
  1286. {
  1287. struct local_info *local = netdev_priv(dev);
  1288. unsigned int ioaddr = dev->base_addr;
  1289. SelectPage(4);
  1290. udelay(1);
  1291. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1292. msleep(40); /* wait 40 msec */
  1293. if (local->mohawk)
  1294. PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */
  1295. else
  1296. PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */
  1297. msleep(20); /* wait 20 msec */
  1298. }
  1299. static void
  1300. do_reset(struct net_device *dev, int full)
  1301. {
  1302. struct local_info *local = netdev_priv(dev);
  1303. unsigned int ioaddr = dev->base_addr;
  1304. unsigned value;
  1305. pr_debug("%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full);
  1306. hardreset(dev);
  1307. PutByte(XIRCREG_CR, SoftReset); /* set */
  1308. msleep(20); /* wait 20 msec */
  1309. PutByte(XIRCREG_CR, 0); /* clear */
  1310. msleep(40); /* wait 40 msec */
  1311. if (local->mohawk) {
  1312. SelectPage(4);
  1313. /* set pin GP1 and GP2 to output (0x0c)
  1314. * set GP1 to low to power up the ML6692 (0x00)
  1315. * set GP2 to high to power up the 10Mhz chip (0x02)
  1316. */
  1317. PutByte(XIRCREG4_GPR0, 0x0e);
  1318. }
  1319. /* give the circuits some time to power up */
  1320. msleep(500); /* about 500ms */
  1321. local->last_ptr_value = 0;
  1322. local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
  1323. : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
  1324. if (local->probe_port) {
  1325. if (!local->mohawk) {
  1326. SelectPage(4);
  1327. PutByte(XIRCREG4_GPR0, 4);
  1328. local->probe_port = 0;
  1329. }
  1330. } else if (dev->if_port == 2) { /* enable 10Base2 */
  1331. SelectPage(0x42);
  1332. PutByte(XIRCREG42_SWC1, 0xC0);
  1333. } else { /* enable 10BaseT */
  1334. SelectPage(0x42);
  1335. PutByte(XIRCREG42_SWC1, 0x80);
  1336. }
  1337. msleep(40); /* wait 40 msec to let it complete */
  1338. #if 0
  1339. {
  1340. SelectPage(0);
  1341. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1342. pr_debug("%s: ESR is: %#02x\n", dev->name, value);
  1343. }
  1344. #endif
  1345. /* setup the ECR */
  1346. SelectPage(1);
  1347. PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
  1348. PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */
  1349. value = GetByte(XIRCREG1_ECR);
  1350. #if 0
  1351. if (local->mohawk)
  1352. value |= DisableLinkPulse;
  1353. PutByte(XIRCREG1_ECR, value);
  1354. #endif
  1355. pr_debug("%s: ECR is: %#02x\n", dev->name, value);
  1356. SelectPage(0x42);
  1357. PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
  1358. if (local->silicon != 1) {
  1359. /* set the local memory dividing line.
  1360. * The comments in the sample code say that this is only
  1361. * settable with the scipper version 2 which is revision 0.
  1362. * Always for CE3 cards
  1363. */
  1364. SelectPage(2);
  1365. PutWord(XIRCREG2_RBS, 0x2000);
  1366. }
  1367. if (full)
  1368. set_addresses(dev);
  1369. /* Hardware workaround:
  1370. * The receive byte pointer after reset is off by 1 so we need
  1371. * to move the offset pointer back to 0.
  1372. */
  1373. SelectPage(0);
  1374. PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
  1375. /* setup MAC IMRs and clear status registers */
  1376. SelectPage(0x40); /* Bit 7 ... bit 0 */
  1377. PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
  1378. PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1379. PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
  1380. PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
  1381. PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
  1382. PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */
  1383. if (full && local->mohawk && init_mii(dev)) {
  1384. if (dev->if_port == 4 || local->dingo || local->new_mii) {
  1385. netdev_info(dev, "MII selected\n");
  1386. SelectPage(2);
  1387. PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
  1388. msleep(20);
  1389. } else {
  1390. netdev_info(dev, "MII detected; using 10mbs\n");
  1391. SelectPage(0x42);
  1392. if (dev->if_port == 2) /* enable 10Base2 */
  1393. PutByte(XIRCREG42_SWC1, 0xC0);
  1394. else /* enable 10BaseT */
  1395. PutByte(XIRCREG42_SWC1, 0x80);
  1396. msleep(40); /* wait 40 msec to let it complete */
  1397. }
  1398. if (full_duplex)
  1399. PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
  1400. } else { /* No MII */
  1401. SelectPage(0);
  1402. value = GetByte(XIRCREG_ESR); /* read the ESR */
  1403. dev->if_port = (value & MediaSelect) ? 1 : 2;
  1404. }
  1405. /* configure the LEDs */
  1406. SelectPage(2);
  1407. if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
  1408. PutByte(XIRCREG2_LED, 0x3b);
  1409. else /* Coax: Not-Collision and Activity */
  1410. PutByte(XIRCREG2_LED, 0x3a);
  1411. if (local->dingo)
  1412. PutByte(0x0b, 0x04); /* 100 Mbit LED */
  1413. /* enable receiver and put the mac online */
  1414. if (full) {
  1415. set_multicast_list(dev);
  1416. SelectPage(0x40);
  1417. PutByte(XIRCREG40_CMD0, EnableRecv | Online);
  1418. }
  1419. /* setup Ethernet IMR and enable interrupts */
  1420. SelectPage(1);
  1421. PutByte(XIRCREG1_IMR0, 0xff);
  1422. udelay(1);
  1423. SelectPage(0);
  1424. PutByte(XIRCREG_CR, EnableIntr);
  1425. if (local->modem && !local->dingo) { /* do some magic */
  1426. if (!(GetByte(0x10) & 0x01))
  1427. PutByte(0x10, 0x11); /* unmask master-int bit */
  1428. }
  1429. if (full)
  1430. netdev_info(dev, "media %s, silicon revision %d\n",
  1431. if_names[dev->if_port], local->silicon);
  1432. /* We should switch back to page 0 to avoid a bug in revision 0
  1433. * where regs with offset below 8 can't be read after an access
  1434. * to the MAC registers */
  1435. SelectPage(0);
  1436. }
  1437. /****************
  1438. * Initialize the Media-Independent-Interface
  1439. * Returns: True if we have a good MII
  1440. */
  1441. static int
  1442. init_mii(struct net_device *dev)
  1443. {
  1444. struct local_info *local = netdev_priv(dev);
  1445. unsigned int ioaddr = dev->base_addr;
  1446. unsigned control, status, linkpartner;
  1447. int i;
  1448. if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
  1449. dev->if_port = if_port;
  1450. local->probe_port = 0;
  1451. return 1;
  1452. }
  1453. status = mii_rd(ioaddr, 0, 1);
  1454. if ((status & 0xff00) != 0x7800)
  1455. return 0; /* No MII */
  1456. local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
  1457. if (local->probe_port)
  1458. control = 0x1000; /* auto neg */
  1459. else if (dev->if_port == 4)
  1460. control = 0x2000; /* no auto neg, 100mbs mode */
  1461. else
  1462. control = 0x0000; /* no auto neg, 10mbs mode */
  1463. mii_wr(ioaddr, 0, 0, control, 16);
  1464. udelay(100);
  1465. control = mii_rd(ioaddr, 0, 0);
  1466. if (control & 0x0400) {
  1467. netdev_notice(dev, "can't take PHY out of isolation mode\n");
  1468. local->probe_port = 0;
  1469. return 0;
  1470. }
  1471. if (local->probe_port) {
  1472. /* according to the DP83840A specs the auto negotiation process
  1473. * may take up to 3.5 sec, so we use this also for our ML6692
  1474. * Fixme: Better to use a timer here!
  1475. */
  1476. for (i=0; i < 35; i++) {
  1477. msleep(100); /* wait 100 msec */
  1478. status = mii_rd(ioaddr, 0, 1);
  1479. if ((status & 0x0020) && (status & 0x0004))
  1480. break;
  1481. }
  1482. if (!(status & 0x0020)) {
  1483. netdev_info(dev, "autonegotiation failed; using 10mbs\n");
  1484. if (!local->new_mii) {
  1485. control = 0x0000;
  1486. mii_wr(ioaddr, 0, 0, control, 16);
  1487. udelay(100);
  1488. SelectPage(0);
  1489. dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
  1490. }
  1491. } else {
  1492. linkpartner = mii_rd(ioaddr, 0, 5);
  1493. netdev_info(dev, "MII link partner: %04x\n", linkpartner);
  1494. if (linkpartner & 0x0080) {
  1495. dev->if_port = 4;
  1496. } else
  1497. dev->if_port = 1;
  1498. }
  1499. }
  1500. return 1;
  1501. }
  1502. static void
  1503. do_powerdown(struct net_device *dev)
  1504. {
  1505. unsigned int ioaddr = dev->base_addr;
  1506. pr_debug("do_powerdown(%p)\n", dev);
  1507. SelectPage(4);
  1508. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1509. SelectPage(0);
  1510. }
  1511. static int
  1512. do_stop(struct net_device *dev)
  1513. {
  1514. unsigned int ioaddr = dev->base_addr;
  1515. struct local_info *lp = netdev_priv(dev);
  1516. struct pcmcia_device *link = lp->p_dev;
  1517. dev_dbg(&link->dev, "do_stop(%p)\n", dev);
  1518. if (!link)
  1519. return -ENODEV;
  1520. netif_stop_queue(dev);
  1521. SelectPage(0);
  1522. PutByte(XIRCREG_CR, 0); /* disable interrupts */
  1523. SelectPage(0x01);
  1524. PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
  1525. SelectPage(4);
  1526. PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */
  1527. SelectPage(0);
  1528. link->open--;
  1529. return 0;
  1530. }
  1531. static const struct pcmcia_device_id xirc2ps_ids[] = {
  1532. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
  1533. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
  1534. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
  1535. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
  1536. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
  1537. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
  1538. PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
  1539. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
  1540. PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
  1541. PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
  1542. PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
  1543. PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
  1544. PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
  1545. PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
  1546. PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
  1547. PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
  1548. PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
  1549. PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
  1550. PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
  1551. /* also matches CFE-10 cards! */
  1552. /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
  1553. PCMCIA_DEVICE_NULL,
  1554. };
  1555. MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
  1556. static struct pcmcia_driver xirc2ps_cs_driver = {
  1557. .owner = THIS_MODULE,
  1558. .name = "xirc2ps_cs",
  1559. .probe = xirc2ps_probe,
  1560. .remove = xirc2ps_detach,
  1561. .id_table = xirc2ps_ids,
  1562. .suspend = xirc2ps_suspend,
  1563. .resume = xirc2ps_resume,
  1564. };
  1565. module_pcmcia_driver(xirc2ps_cs_driver);
  1566. #ifndef MODULE
  1567. static int __init setup_xirc2ps_cs(char *str)
  1568. {
  1569. /* if_port, full_duplex, do_sound, lockup_hack
  1570. */
  1571. int ints[10] = { -1 };
  1572. str = get_options(str, 9, ints);
  1573. #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
  1574. MAYBE_SET(if_port, 3);
  1575. MAYBE_SET(full_duplex, 4);
  1576. MAYBE_SET(do_sound, 5);
  1577. MAYBE_SET(lockup_hack, 6);
  1578. #undef MAYBE_SET
  1579. return 1;
  1580. }
  1581. __setup("xirc2ps_cs=", setup_xirc2ps_cs);
  1582. #endif