xirc2ps_cs.c 52 KB

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