xirc2ps_cs.c 61 KB

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