xirc2ps_cs.c 58 KB

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