xirc2ps_cs.c 54 KB

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