xirc2ps_cs.c 55 KB

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