xirc2ps_cs.c 52 KB

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