xirc2ps_cs.c 54 KB

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