xirc2ps_cs.c 61 KB

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