smc91c92_cs.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  1. /*======================================================================
  2. A PCMCIA ethernet driver for SMC91c92-based cards.
  3. This driver supports Megahertz PCMCIA ethernet cards; and
  4. Megahertz, Motorola, Ositech, and Psion Dacom ethernet/modem
  5. multifunction cards.
  6. Copyright (C) 1999 David A. Hinds -- dahinds@users.sourceforge.net
  7. smc91c92_cs.c 1.122 2002/10/25 06:26:39
  8. This driver contains code written by Donald Becker
  9. (becker@scyld.com), Rowan Hughes (x-csrdh@jcu.edu.au),
  10. David Hinds (dahinds@users.sourceforge.net), and Erik Stahlman
  11. (erik@vt.edu). Donald wrote the SMC 91c92 code using parts of
  12. Erik's SMC 91c94 driver. Rowan wrote a similar driver, and I've
  13. incorporated some parts of his driver here. I (Dave) wrote most
  14. of the PCMCIA glue code, and the Ositech support code. Kelly
  15. Stephens (kstephen@holli.com) added support for the Motorola
  16. Mariner, with help from Allen Brost.
  17. This software may be used and distributed according to the terms of
  18. the GNU General Public License, incorporated herein by reference.
  19. ======================================================================*/
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/timer.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <linux/crc32.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/if_arp.h>
  33. #include <linux/ioport.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/mii.h>
  36. #include <linux/jiffies.h>
  37. #include <linux/firmware.h>
  38. #include <pcmcia/cistpl.h>
  39. #include <pcmcia/cisreg.h>
  40. #include <pcmcia/ciscode.h>
  41. #include <pcmcia/ds.h>
  42. #include <pcmcia/ss.h>
  43. #include <asm/io.h>
  44. #include <asm/uaccess.h>
  45. /*====================================================================*/
  46. static const char *if_names[] = { "auto", "10baseT", "10base2"};
  47. /* Firmware name */
  48. #define FIRMWARE_NAME "/*(DEBLOBBED)*/"
  49. /* Module parameters */
  50. MODULE_DESCRIPTION("SMC 91c92 series PCMCIA ethernet driver");
  51. MODULE_LICENSE("GPL");
  52. /*(DEBLOBBED)*/
  53. #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
  54. /*
  55. Transceiver/media type.
  56. 0 = auto
  57. 1 = 10baseT (and autoselect if #define AUTOSELECT),
  58. 2 = AUI/10base2,
  59. */
  60. INT_MODULE_PARM(if_port, 0);
  61. #define DRV_NAME "smc91c92_cs"
  62. #define DRV_VERSION "1.123"
  63. /*====================================================================*/
  64. /* Operational parameter that usually are not changed. */
  65. /* Time in jiffies before concluding Tx hung */
  66. #define TX_TIMEOUT ((400*HZ)/1000)
  67. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  68. #define INTR_WORK 4
  69. /* Times to check the check the chip before concluding that it doesn't
  70. currently have room for another Tx packet. */
  71. #define MEMORY_WAIT_TIME 8
  72. struct smc_private {
  73. struct pcmcia_device *p_dev;
  74. spinlock_t lock;
  75. u_short manfid;
  76. u_short cardid;
  77. struct sk_buff *saved_skb;
  78. int packets_waiting;
  79. void __iomem *base;
  80. u_short cfg;
  81. struct timer_list media;
  82. int watchdog, tx_err;
  83. u_short media_status;
  84. u_short fast_poll;
  85. u_short link_status;
  86. struct mii_if_info mii_if;
  87. int duplex;
  88. int rx_ovrn;
  89. };
  90. /* Special definitions for Megahertz multifunction cards */
  91. #define MEGAHERTZ_ISR 0x0380
  92. /* Special function registers for Motorola Mariner */
  93. #define MOT_LAN 0x0000
  94. #define MOT_UART 0x0020
  95. #define MOT_EEPROM 0x20
  96. #define MOT_NORMAL \
  97. (COR_LEVEL_REQ | COR_FUNC_ENA | COR_ADDR_DECODE | COR_IREQ_ENA)
  98. /* Special function registers for Ositech cards */
  99. #define OSITECH_AUI_CTL 0x0c
  100. #define OSITECH_PWRDOWN 0x0d
  101. #define OSITECH_RESET 0x0e
  102. #define OSITECH_ISR 0x0f
  103. #define OSITECH_AUI_PWR 0x0c
  104. #define OSITECH_RESET_ISR 0x0e
  105. #define OSI_AUI_PWR 0x40
  106. #define OSI_LAN_PWRDOWN 0x02
  107. #define OSI_MODEM_PWRDOWN 0x01
  108. #define OSI_LAN_RESET 0x02
  109. #define OSI_MODEM_RESET 0x01
  110. /* Symbolic constants for the SMC91c9* series chips, from Erik Stahlman. */
  111. #define BANK_SELECT 14 /* Window select register. */
  112. #define SMC_SELECT_BANK(x) { outw(x, ioaddr + BANK_SELECT); }
  113. /* Bank 0 registers. */
  114. #define TCR 0 /* transmit control register */
  115. #define TCR_CLEAR 0 /* do NOTHING */
  116. #define TCR_ENABLE 0x0001 /* if this is 1, we can transmit */
  117. #define TCR_PAD_EN 0x0080 /* pads short packets to 64 bytes */
  118. #define TCR_MONCSN 0x0400 /* Monitor Carrier. */
  119. #define TCR_FDUPLX 0x0800 /* Full duplex mode. */
  120. #define TCR_NORMAL TCR_ENABLE | TCR_PAD_EN
  121. #define EPH 2 /* Ethernet Protocol Handler report. */
  122. #define EPH_TX_SUC 0x0001
  123. #define EPH_SNGLCOL 0x0002
  124. #define EPH_MULCOL 0x0004
  125. #define EPH_LTX_MULT 0x0008
  126. #define EPH_16COL 0x0010
  127. #define EPH_SQET 0x0020
  128. #define EPH_LTX_BRD 0x0040
  129. #define EPH_TX_DEFR 0x0080
  130. #define EPH_LAT_COL 0x0200
  131. #define EPH_LOST_CAR 0x0400
  132. #define EPH_EXC_DEF 0x0800
  133. #define EPH_CTR_ROL 0x1000
  134. #define EPH_RX_OVRN 0x2000
  135. #define EPH_LINK_OK 0x4000
  136. #define EPH_TX_UNRN 0x8000
  137. #define MEMINFO 8 /* Memory Information Register */
  138. #define MEMCFG 10 /* Memory Configuration Register */
  139. /* Bank 1 registers. */
  140. #define CONFIG 0
  141. #define CFG_MII_SELECT 0x8000 /* 91C100 only */
  142. #define CFG_NO_WAIT 0x1000
  143. #define CFG_FULL_STEP 0x0400
  144. #define CFG_SET_SQLCH 0x0200
  145. #define CFG_AUI_SELECT 0x0100
  146. #define CFG_16BIT 0x0080
  147. #define CFG_DIS_LINK 0x0040
  148. #define CFG_STATIC 0x0030
  149. #define CFG_IRQ_SEL_1 0x0004
  150. #define CFG_IRQ_SEL_0 0x0002
  151. #define BASE_ADDR 2
  152. #define ADDR0 4
  153. #define GENERAL 10
  154. #define CONTROL 12
  155. #define CTL_STORE 0x0001
  156. #define CTL_RELOAD 0x0002
  157. #define CTL_EE_SELECT 0x0004
  158. #define CTL_TE_ENABLE 0x0020
  159. #define CTL_CR_ENABLE 0x0040
  160. #define CTL_LE_ENABLE 0x0080
  161. #define CTL_AUTO_RELEASE 0x0800
  162. #define CTL_POWERDOWN 0x2000
  163. /* Bank 2 registers. */
  164. #define MMU_CMD 0
  165. #define MC_ALLOC 0x20 /* or with number of 256 byte packets */
  166. #define MC_RESET 0x40
  167. #define MC_RELEASE 0x80 /* remove and release the current rx packet */
  168. #define MC_FREEPKT 0xA0 /* Release packet in PNR register */
  169. #define MC_ENQUEUE 0xC0 /* Enqueue the packet for transmit */
  170. #define PNR_ARR 2
  171. #define FIFO_PORTS 4
  172. #define FP_RXEMPTY 0x8000
  173. #define POINTER 6
  174. #define PTR_AUTO_INC 0x0040
  175. #define PTR_READ 0x2000
  176. #define PTR_AUTOINC 0x4000
  177. #define PTR_RCV 0x8000
  178. #define DATA_1 8
  179. #define INTERRUPT 12
  180. #define IM_RCV_INT 0x1
  181. #define IM_TX_INT 0x2
  182. #define IM_TX_EMPTY_INT 0x4
  183. #define IM_ALLOC_INT 0x8
  184. #define IM_RX_OVRN_INT 0x10
  185. #define IM_EPH_INT 0x20
  186. #define RCR 4
  187. enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
  188. RxEnable = 0x0100, RxStripCRC = 0x0200};
  189. #define RCR_SOFTRESET 0x8000 /* resets the chip */
  190. #define RCR_STRIP_CRC 0x200 /* strips CRC */
  191. #define RCR_ENABLE 0x100 /* IFF this is set, we can receive packets */
  192. #define RCR_ALMUL 0x4 /* receive all multicast packets */
  193. #define RCR_PROMISC 0x2 /* enable promiscuous mode */
  194. /* the normal settings for the RCR register : */
  195. #define RCR_NORMAL (RCR_STRIP_CRC | RCR_ENABLE)
  196. #define RCR_CLEAR 0x0 /* set it to a base state */
  197. #define COUNTER 6
  198. /* BANK 3 -- not the same values as in smc9194! */
  199. #define MULTICAST0 0
  200. #define MULTICAST2 2
  201. #define MULTICAST4 4
  202. #define MULTICAST6 6
  203. #define MGMT 8
  204. #define REVISION 0x0a
  205. /* Transmit status bits. */
  206. #define TS_SUCCESS 0x0001
  207. #define TS_16COL 0x0010
  208. #define TS_LATCOL 0x0200
  209. #define TS_LOSTCAR 0x0400
  210. /* Receive status bits. */
  211. #define RS_ALGNERR 0x8000
  212. #define RS_BADCRC 0x2000
  213. #define RS_ODDFRAME 0x1000
  214. #define RS_TOOLONG 0x0800
  215. #define RS_TOOSHORT 0x0400
  216. #define RS_MULTICAST 0x0001
  217. #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
  218. #define set_bits(v, p) outw(inw(p)|(v), (p))
  219. #define mask_bits(v, p) outw(inw(p)&(v), (p))
  220. /*====================================================================*/
  221. static void smc91c92_detach(struct pcmcia_device *p_dev);
  222. static int smc91c92_config(struct pcmcia_device *link);
  223. static void smc91c92_release(struct pcmcia_device *link);
  224. static int smc_open(struct net_device *dev);
  225. static int smc_close(struct net_device *dev);
  226. static int smc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  227. static void smc_tx_timeout(struct net_device *dev);
  228. static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
  229. struct net_device *dev);
  230. static irqreturn_t smc_interrupt(int irq, void *dev_id);
  231. static void smc_rx(struct net_device *dev);
  232. static void set_rx_mode(struct net_device *dev);
  233. static int s9k_config(struct net_device *dev, struct ifmap *map);
  234. static void smc_set_xcvr(struct net_device *dev, int if_port);
  235. static void smc_reset(struct net_device *dev);
  236. static void media_check(u_long arg);
  237. static void mdio_sync(unsigned int addr);
  238. static int mdio_read(struct net_device *dev, int phy_id, int loc);
  239. static void mdio_write(struct net_device *dev, int phy_id, int loc, int value);
  240. static int smc_link_ok(struct net_device *dev);
  241. static const struct ethtool_ops ethtool_ops;
  242. static const struct net_device_ops smc_netdev_ops = {
  243. .ndo_open = smc_open,
  244. .ndo_stop = smc_close,
  245. .ndo_start_xmit = smc_start_xmit,
  246. .ndo_tx_timeout = smc_tx_timeout,
  247. .ndo_set_config = s9k_config,
  248. .ndo_set_rx_mode = set_rx_mode,
  249. .ndo_do_ioctl = smc_ioctl,
  250. .ndo_change_mtu = eth_change_mtu,
  251. .ndo_set_mac_address = eth_mac_addr,
  252. .ndo_validate_addr = eth_validate_addr,
  253. };
  254. static int smc91c92_probe(struct pcmcia_device *link)
  255. {
  256. struct smc_private *smc;
  257. struct net_device *dev;
  258. dev_dbg(&link->dev, "smc91c92_attach()\n");
  259. /* Create new ethernet device */
  260. dev = alloc_etherdev(sizeof(struct smc_private));
  261. if (!dev)
  262. return -ENOMEM;
  263. smc = netdev_priv(dev);
  264. smc->p_dev = link;
  265. link->priv = dev;
  266. spin_lock_init(&smc->lock);
  267. /* The SMC91c92-specific entries in the device structure. */
  268. dev->netdev_ops = &smc_netdev_ops;
  269. dev->ethtool_ops = &ethtool_ops;
  270. dev->watchdog_timeo = TX_TIMEOUT;
  271. smc->mii_if.dev = dev;
  272. smc->mii_if.mdio_read = mdio_read;
  273. smc->mii_if.mdio_write = mdio_write;
  274. smc->mii_if.phy_id_mask = 0x1f;
  275. smc->mii_if.reg_num_mask = 0x1f;
  276. return smc91c92_config(link);
  277. } /* smc91c92_attach */
  278. static void smc91c92_detach(struct pcmcia_device *link)
  279. {
  280. struct net_device *dev = link->priv;
  281. dev_dbg(&link->dev, "smc91c92_detach\n");
  282. unregister_netdev(dev);
  283. smc91c92_release(link);
  284. free_netdev(dev);
  285. } /* smc91c92_detach */
  286. /*====================================================================*/
  287. static int cvt_ascii_address(struct net_device *dev, char *s)
  288. {
  289. int i, j, da, c;
  290. if (strlen(s) != 12)
  291. return -1;
  292. for (i = 0; i < 6; i++) {
  293. da = 0;
  294. for (j = 0; j < 2; j++) {
  295. c = *s++;
  296. da <<= 4;
  297. da += ((c >= '0') && (c <= '9')) ?
  298. (c - '0') : ((c & 0x0f) + 9);
  299. }
  300. dev->dev_addr[i] = da;
  301. }
  302. return 0;
  303. }
  304. /*====================================================================
  305. Configuration stuff for Megahertz cards
  306. mhz_3288_power() is used to power up a 3288's ethernet chip.
  307. mhz_mfc_config() handles socket setup for multifunction (1144
  308. and 3288) cards. mhz_setup() gets a card's hardware ethernet
  309. address.
  310. ======================================================================*/
  311. static int mhz_3288_power(struct pcmcia_device *link)
  312. {
  313. struct net_device *dev = link->priv;
  314. struct smc_private *smc = netdev_priv(dev);
  315. u_char tmp;
  316. /* Read the ISR twice... */
  317. readb(smc->base+MEGAHERTZ_ISR);
  318. udelay(5);
  319. readb(smc->base+MEGAHERTZ_ISR);
  320. /* Pause 200ms... */
  321. mdelay(200);
  322. /* Now read and write the COR... */
  323. tmp = readb(smc->base + link->config_base + CISREG_COR);
  324. udelay(5);
  325. writeb(tmp, smc->base + link->config_base + CISREG_COR);
  326. return 0;
  327. }
  328. static int mhz_mfc_config_check(struct pcmcia_device *p_dev, void *priv_data)
  329. {
  330. int k;
  331. p_dev->io_lines = 16;
  332. p_dev->resource[1]->start = p_dev->resource[0]->start;
  333. p_dev->resource[1]->end = 8;
  334. p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  335. p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  336. p_dev->resource[0]->end = 16;
  337. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  338. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  339. for (k = 0; k < 0x400; k += 0x10) {
  340. if (k & 0x80)
  341. continue;
  342. p_dev->resource[0]->start = k ^ 0x300;
  343. if (!pcmcia_request_io(p_dev))
  344. return 0;
  345. }
  346. return -ENODEV;
  347. }
  348. static int mhz_mfc_config(struct pcmcia_device *link)
  349. {
  350. struct net_device *dev = link->priv;
  351. struct smc_private *smc = netdev_priv(dev);
  352. unsigned int offset;
  353. int i;
  354. link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ |
  355. CONF_AUTO_SET_IO;
  356. /* The Megahertz combo cards have modem-like CIS entries, so
  357. we have to explicitly try a bunch of port combinations. */
  358. if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
  359. return -ENODEV;
  360. dev->base_addr = link->resource[0]->start;
  361. /* Allocate a memory window, for accessing the ISR */
  362. link->resource[2]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  363. link->resource[2]->start = link->resource[2]->end = 0;
  364. i = pcmcia_request_window(link, link->resource[2], 0);
  365. if (i != 0)
  366. return -ENODEV;
  367. smc->base = ioremap(link->resource[2]->start,
  368. resource_size(link->resource[2]));
  369. offset = (smc->manfid == MANFID_MOTOROLA) ? link->config_base : 0;
  370. i = pcmcia_map_mem_page(link, link->resource[2], offset);
  371. if ((i == 0) &&
  372. (smc->manfid == MANFID_MEGAHERTZ) &&
  373. (smc->cardid == PRODID_MEGAHERTZ_EM3288))
  374. mhz_3288_power(link);
  375. return 0;
  376. }
  377. static int pcmcia_get_versmac(struct pcmcia_device *p_dev,
  378. tuple_t *tuple,
  379. void *priv)
  380. {
  381. struct net_device *dev = priv;
  382. cisparse_t parse;
  383. u8 *buf;
  384. if (pcmcia_parse_tuple(tuple, &parse))
  385. return -EINVAL;
  386. buf = parse.version_1.str + parse.version_1.ofs[3];
  387. if ((parse.version_1.ns > 3) && (cvt_ascii_address(dev, buf) == 0))
  388. return 0;
  389. return -EINVAL;
  390. };
  391. static int mhz_setup(struct pcmcia_device *link)
  392. {
  393. struct net_device *dev = link->priv;
  394. size_t len;
  395. u8 *buf;
  396. int rc;
  397. /* Read the station address from the CIS. It is stored as the last
  398. (fourth) string in the Version 1 Version/ID tuple. */
  399. if ((link->prod_id[3]) &&
  400. (cvt_ascii_address(dev, link->prod_id[3]) == 0))
  401. return 0;
  402. /* Workarounds for broken cards start here. */
  403. /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
  404. if (!pcmcia_loop_tuple(link, CISTPL_VERS_1, pcmcia_get_versmac, dev))
  405. return 0;
  406. /* Another possibility: for the EM3288, in a special tuple */
  407. rc = -1;
  408. len = pcmcia_get_tuple(link, 0x81, &buf);
  409. if (buf && len >= 13) {
  410. buf[12] = '\0';
  411. if (cvt_ascii_address(dev, buf) == 0)
  412. rc = 0;
  413. }
  414. kfree(buf);
  415. return rc;
  416. };
  417. /*======================================================================
  418. Configuration stuff for the Motorola Mariner
  419. mot_config() writes directly to the Mariner configuration
  420. registers because the CIS is just bogus.
  421. ======================================================================*/
  422. static void mot_config(struct pcmcia_device *link)
  423. {
  424. struct net_device *dev = link->priv;
  425. struct smc_private *smc = netdev_priv(dev);
  426. unsigned int ioaddr = dev->base_addr;
  427. unsigned int iouart = link->resource[1]->start;
  428. /* Set UART base address and force map with COR bit 1 */
  429. writeb(iouart & 0xff, smc->base + MOT_UART + CISREG_IOBASE_0);
  430. writeb((iouart >> 8) & 0xff, smc->base + MOT_UART + CISREG_IOBASE_1);
  431. writeb(MOT_NORMAL, smc->base + MOT_UART + CISREG_COR);
  432. /* Set SMC base address and force map with COR bit 1 */
  433. writeb(ioaddr & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_0);
  434. writeb((ioaddr >> 8) & 0xff, smc->base + MOT_LAN + CISREG_IOBASE_1);
  435. writeb(MOT_NORMAL, smc->base + MOT_LAN + CISREG_COR);
  436. /* Wait for things to settle down */
  437. mdelay(100);
  438. }
  439. static int mot_setup(struct pcmcia_device *link)
  440. {
  441. struct net_device *dev = link->priv;
  442. unsigned int ioaddr = dev->base_addr;
  443. int i, wait, loop;
  444. u_int addr;
  445. /* Read Ethernet address from Serial EEPROM */
  446. for (i = 0; i < 3; i++) {
  447. SMC_SELECT_BANK(2);
  448. outw(MOT_EEPROM + i, ioaddr + POINTER);
  449. SMC_SELECT_BANK(1);
  450. outw((CTL_RELOAD | CTL_EE_SELECT), ioaddr + CONTROL);
  451. for (loop = wait = 0; loop < 200; loop++) {
  452. udelay(10);
  453. wait = ((CTL_RELOAD | CTL_STORE) & inw(ioaddr + CONTROL));
  454. if (wait == 0) break;
  455. }
  456. if (wait)
  457. return -1;
  458. addr = inw(ioaddr + GENERAL);
  459. dev->dev_addr[2*i] = addr & 0xff;
  460. dev->dev_addr[2*i+1] = (addr >> 8) & 0xff;
  461. }
  462. return 0;
  463. }
  464. /*====================================================================*/
  465. static int smc_configcheck(struct pcmcia_device *p_dev, void *priv_data)
  466. {
  467. p_dev->resource[0]->end = 16;
  468. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  469. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  470. return pcmcia_request_io(p_dev);
  471. }
  472. static int smc_config(struct pcmcia_device *link)
  473. {
  474. struct net_device *dev = link->priv;
  475. int i;
  476. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  477. i = pcmcia_loop_config(link, smc_configcheck, NULL);
  478. if (!i)
  479. dev->base_addr = link->resource[0]->start;
  480. return i;
  481. }
  482. static int smc_setup(struct pcmcia_device *link)
  483. {
  484. struct net_device *dev = link->priv;
  485. /* Check for a LAN function extension tuple */
  486. if (!pcmcia_get_mac_from_cis(link, dev))
  487. return 0;
  488. /* Try the third string in the Version 1 Version/ID tuple. */
  489. if (link->prod_id[2]) {
  490. if (cvt_ascii_address(dev, link->prod_id[2]) == 0)
  491. return 0;
  492. }
  493. return -1;
  494. }
  495. /*====================================================================*/
  496. static int osi_config(struct pcmcia_device *link)
  497. {
  498. struct net_device *dev = link->priv;
  499. static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
  500. int i, j;
  501. link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ;
  502. link->resource[0]->end = 64;
  503. link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
  504. link->resource[1]->end = 8;
  505. /* Enable Hard Decode, LAN, Modem */
  506. link->io_lines = 16;
  507. link->config_index = 0x23;
  508. for (i = j = 0; j < 4; j++) {
  509. link->resource[1]->start = com[j];
  510. i = pcmcia_request_io(link);
  511. if (i == 0)
  512. break;
  513. }
  514. if (i != 0) {
  515. /* Fallback: turn off hard decode */
  516. link->config_index = 0x03;
  517. link->resource[1]->end = 0;
  518. i = pcmcia_request_io(link);
  519. }
  520. dev->base_addr = link->resource[0]->start + 0x10;
  521. return i;
  522. }
  523. static int osi_load_firmware(struct pcmcia_device *link)
  524. {
  525. const struct firmware *fw;
  526. int i, err;
  527. err = reject_firmware(&fw, FIRMWARE_NAME, &link->dev);
  528. if (err) {
  529. pr_err("Failed to load firmware \"%s\"\n", FIRMWARE_NAME);
  530. return err;
  531. }
  532. /* Download the Seven of Diamonds firmware */
  533. for (i = 0; i < fw->size; i++) {
  534. outb(fw->data[i], link->resource[0]->start + 2);
  535. udelay(50);
  536. }
  537. release_firmware(fw);
  538. return err;
  539. }
  540. static int pcmcia_osi_mac(struct pcmcia_device *p_dev,
  541. tuple_t *tuple,
  542. void *priv)
  543. {
  544. struct net_device *dev = priv;
  545. int i;
  546. if (tuple->TupleDataLen < 8)
  547. return -EINVAL;
  548. if (tuple->TupleData[0] != 0x04)
  549. return -EINVAL;
  550. for (i = 0; i < 6; i++)
  551. dev->dev_addr[i] = tuple->TupleData[i+2];
  552. return 0;
  553. };
  554. static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
  555. {
  556. struct net_device *dev = link->priv;
  557. int rc;
  558. /* Read the station address from tuple 0x90, subtuple 0x04 */
  559. if (pcmcia_loop_tuple(link, 0x90, pcmcia_osi_mac, dev))
  560. return -1;
  561. if (((manfid == MANFID_OSITECH) &&
  562. (cardid == PRODID_OSITECH_SEVEN)) ||
  563. ((manfid == MANFID_PSION) &&
  564. (cardid == PRODID_PSION_NET100))) {
  565. rc = osi_load_firmware(link);
  566. if (rc)
  567. return rc;
  568. } else if (manfid == MANFID_OSITECH) {
  569. /* Make sure both functions are powered up */
  570. set_bits(0x300, link->resource[0]->start + OSITECH_AUI_PWR);
  571. /* Now, turn on the interrupt for both card functions */
  572. set_bits(0x300, link->resource[0]->start + OSITECH_RESET_ISR);
  573. dev_dbg(&link->dev, "AUI/PWR: %4.4x RESET/ISR: %4.4x\n",
  574. inw(link->resource[0]->start + OSITECH_AUI_PWR),
  575. inw(link->resource[0]->start + OSITECH_RESET_ISR));
  576. }
  577. return 0;
  578. }
  579. static int smc91c92_suspend(struct pcmcia_device *link)
  580. {
  581. struct net_device *dev = link->priv;
  582. if (link->open)
  583. netif_device_detach(dev);
  584. return 0;
  585. }
  586. static int smc91c92_resume(struct pcmcia_device *link)
  587. {
  588. struct net_device *dev = link->priv;
  589. struct smc_private *smc = netdev_priv(dev);
  590. int i;
  591. if ((smc->manfid == MANFID_MEGAHERTZ) &&
  592. (smc->cardid == PRODID_MEGAHERTZ_EM3288))
  593. mhz_3288_power(link);
  594. if (smc->manfid == MANFID_MOTOROLA)
  595. mot_config(link);
  596. if ((smc->manfid == MANFID_OSITECH) &&
  597. (smc->cardid != PRODID_OSITECH_SEVEN)) {
  598. /* Power up the card and enable interrupts */
  599. set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
  600. set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
  601. }
  602. if (((smc->manfid == MANFID_OSITECH) &&
  603. (smc->cardid == PRODID_OSITECH_SEVEN)) ||
  604. ((smc->manfid == MANFID_PSION) &&
  605. (smc->cardid == PRODID_PSION_NET100))) {
  606. i = osi_load_firmware(link);
  607. if (i) {
  608. netdev_err(dev, "Failed to load firmware\n");
  609. return i;
  610. }
  611. }
  612. if (link->open) {
  613. smc_reset(dev);
  614. netif_device_attach(dev);
  615. }
  616. return 0;
  617. }
  618. /*======================================================================
  619. This verifies that the chip is some SMC91cXX variant, and returns
  620. the revision code if successful. Otherwise, it returns -ENODEV.
  621. ======================================================================*/
  622. static int check_sig(struct pcmcia_device *link)
  623. {
  624. struct net_device *dev = link->priv;
  625. unsigned int ioaddr = dev->base_addr;
  626. int width;
  627. u_short s;
  628. SMC_SELECT_BANK(1);
  629. if (inw(ioaddr + BANK_SELECT) >> 8 != 0x33) {
  630. /* Try powering up the chip */
  631. outw(0, ioaddr + CONTROL);
  632. mdelay(55);
  633. }
  634. /* Try setting bus width */
  635. width = (link->resource[0]->flags == IO_DATA_PATH_WIDTH_AUTO);
  636. s = inb(ioaddr + CONFIG);
  637. if (width)
  638. s |= CFG_16BIT;
  639. else
  640. s &= ~CFG_16BIT;
  641. outb(s, ioaddr + CONFIG);
  642. /* Check Base Address Register to make sure bus width is OK */
  643. s = inw(ioaddr + BASE_ADDR);
  644. if ((inw(ioaddr + BANK_SELECT) >> 8 == 0x33) &&
  645. ((s >> 8) != (s & 0xff))) {
  646. SMC_SELECT_BANK(3);
  647. s = inw(ioaddr + REVISION);
  648. return s & 0xff;
  649. }
  650. if (width) {
  651. netdev_info(dev, "using 8-bit IO window\n");
  652. smc91c92_suspend(link);
  653. pcmcia_fixup_iowidth(link);
  654. smc91c92_resume(link);
  655. return check_sig(link);
  656. }
  657. return -ENODEV;
  658. }
  659. static int smc91c92_config(struct pcmcia_device *link)
  660. {
  661. struct net_device *dev = link->priv;
  662. struct smc_private *smc = netdev_priv(dev);
  663. char *name;
  664. int i, rev, j = 0;
  665. unsigned int ioaddr;
  666. u_long mir;
  667. dev_dbg(&link->dev, "smc91c92_config\n");
  668. smc->manfid = link->manf_id;
  669. smc->cardid = link->card_id;
  670. if ((smc->manfid == MANFID_OSITECH) &&
  671. (smc->cardid != PRODID_OSITECH_SEVEN)) {
  672. i = osi_config(link);
  673. } else if ((smc->manfid == MANFID_MOTOROLA) ||
  674. ((smc->manfid == MANFID_MEGAHERTZ) &&
  675. ((smc->cardid == PRODID_MEGAHERTZ_VARIOUS) ||
  676. (smc->cardid == PRODID_MEGAHERTZ_EM3288)))) {
  677. i = mhz_mfc_config(link);
  678. } else {
  679. i = smc_config(link);
  680. }
  681. if (i)
  682. goto config_failed;
  683. i = pcmcia_request_irq(link, smc_interrupt);
  684. if (i)
  685. goto config_failed;
  686. i = pcmcia_enable_device(link);
  687. if (i)
  688. goto config_failed;
  689. if (smc->manfid == MANFID_MOTOROLA)
  690. mot_config(link);
  691. dev->irq = link->irq;
  692. if ((if_port >= 0) && (if_port <= 2))
  693. dev->if_port = if_port;
  694. else
  695. dev_notice(&link->dev, "invalid if_port requested\n");
  696. switch (smc->manfid) {
  697. case MANFID_OSITECH:
  698. case MANFID_PSION:
  699. i = osi_setup(link, smc->manfid, smc->cardid); break;
  700. case MANFID_SMC:
  701. case MANFID_NEW_MEDIA:
  702. i = smc_setup(link); break;
  703. case 0x128: /* For broken Megahertz cards */
  704. case MANFID_MEGAHERTZ:
  705. i = mhz_setup(link); break;
  706. case MANFID_MOTOROLA:
  707. default: /* get the hw address from EEPROM */
  708. i = mot_setup(link); break;
  709. }
  710. if (i != 0) {
  711. dev_notice(&link->dev, "Unable to find hardware address.\n");
  712. goto config_failed;
  713. }
  714. smc->duplex = 0;
  715. smc->rx_ovrn = 0;
  716. rev = check_sig(link);
  717. name = "???";
  718. if (rev > 0)
  719. switch (rev >> 4) {
  720. case 3: name = "92"; break;
  721. case 4: name = ((rev & 15) >= 6) ? "96" : "94"; break;
  722. case 5: name = "95"; break;
  723. case 7: name = "100"; break;
  724. case 8: name = "100-FD"; break;
  725. case 9: name = "110"; break;
  726. }
  727. ioaddr = dev->base_addr;
  728. if (rev > 0) {
  729. u_long mcr;
  730. SMC_SELECT_BANK(0);
  731. mir = inw(ioaddr + MEMINFO) & 0xff;
  732. if (mir == 0xff) mir++;
  733. /* Get scale factor for memory size */
  734. mcr = ((rev >> 4) > 3) ? inw(ioaddr + MEMCFG) : 0x0200;
  735. mir *= 128 * (1<<((mcr >> 9) & 7));
  736. SMC_SELECT_BANK(1);
  737. smc->cfg = inw(ioaddr + CONFIG) & ~CFG_AUI_SELECT;
  738. smc->cfg |= CFG_NO_WAIT | CFG_16BIT | CFG_STATIC;
  739. if (smc->manfid == MANFID_OSITECH)
  740. smc->cfg |= CFG_IRQ_SEL_1 | CFG_IRQ_SEL_0;
  741. if ((rev >> 4) >= 7)
  742. smc->cfg |= CFG_MII_SELECT;
  743. } else
  744. mir = 0;
  745. if (smc->cfg & CFG_MII_SELECT) {
  746. SMC_SELECT_BANK(3);
  747. for (i = 0; i < 32; i++) {
  748. j = mdio_read(dev, i, 1);
  749. if ((j != 0) && (j != 0xffff)) break;
  750. }
  751. smc->mii_if.phy_id = (i < 32) ? i : -1;
  752. SMC_SELECT_BANK(0);
  753. }
  754. SET_NETDEV_DEV(dev, &link->dev);
  755. if (register_netdev(dev) != 0) {
  756. dev_err(&link->dev, "register_netdev() failed\n");
  757. goto config_undo;
  758. }
  759. netdev_info(dev, "smc91c%s rev %d: io %#3lx, irq %d, hw_addr %pM\n",
  760. name, (rev & 0x0f), dev->base_addr, dev->irq, dev->dev_addr);
  761. if (rev > 0) {
  762. if (mir & 0x3ff)
  763. netdev_info(dev, " %lu byte", mir);
  764. else
  765. netdev_info(dev, " %lu kb", mir>>10);
  766. pr_cont(" buffer, %s xcvr\n",
  767. (smc->cfg & CFG_MII_SELECT) ? "MII" : if_names[dev->if_port]);
  768. }
  769. if (smc->cfg & CFG_MII_SELECT) {
  770. if (smc->mii_if.phy_id != -1) {
  771. netdev_dbg(dev, " MII transceiver at index %d, status %x\n",
  772. smc->mii_if.phy_id, j);
  773. } else {
  774. netdev_notice(dev, " No MII transceivers found!\n");
  775. }
  776. }
  777. return 0;
  778. config_undo:
  779. unregister_netdev(dev);
  780. config_failed:
  781. smc91c92_release(link);
  782. free_netdev(dev);
  783. return -ENODEV;
  784. } /* smc91c92_config */
  785. static void smc91c92_release(struct pcmcia_device *link)
  786. {
  787. dev_dbg(&link->dev, "smc91c92_release\n");
  788. if (link->resource[2]->end) {
  789. struct net_device *dev = link->priv;
  790. struct smc_private *smc = netdev_priv(dev);
  791. iounmap(smc->base);
  792. }
  793. pcmcia_disable_device(link);
  794. }
  795. /*======================================================================
  796. MII interface support for SMC91cXX based cards
  797. ======================================================================*/
  798. #define MDIO_SHIFT_CLK 0x04
  799. #define MDIO_DATA_OUT 0x01
  800. #define MDIO_DIR_WRITE 0x08
  801. #define MDIO_DATA_WRITE0 (MDIO_DIR_WRITE)
  802. #define MDIO_DATA_WRITE1 (MDIO_DIR_WRITE | MDIO_DATA_OUT)
  803. #define MDIO_DATA_READ 0x02
  804. static void mdio_sync(unsigned int addr)
  805. {
  806. int bits;
  807. for (bits = 0; bits < 32; bits++) {
  808. outb(MDIO_DATA_WRITE1, addr);
  809. outb(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, addr);
  810. }
  811. }
  812. static int mdio_read(struct net_device *dev, int phy_id, int loc)
  813. {
  814. unsigned int addr = dev->base_addr + MGMT;
  815. u_int cmd = (0x06<<10)|(phy_id<<5)|loc;
  816. int i, retval = 0;
  817. mdio_sync(addr);
  818. for (i = 13; i >= 0; i--) {
  819. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  820. outb(dat, addr);
  821. outb(dat | MDIO_SHIFT_CLK, addr);
  822. }
  823. for (i = 19; i > 0; i--) {
  824. outb(0, addr);
  825. retval = (retval << 1) | ((inb(addr) & MDIO_DATA_READ) != 0);
  826. outb(MDIO_SHIFT_CLK, addr);
  827. }
  828. return (retval>>1) & 0xffff;
  829. }
  830. static void mdio_write(struct net_device *dev, int phy_id, int loc, int value)
  831. {
  832. unsigned int addr = dev->base_addr + MGMT;
  833. u_int cmd = (0x05<<28)|(phy_id<<23)|(loc<<18)|(1<<17)|value;
  834. int i;
  835. mdio_sync(addr);
  836. for (i = 31; i >= 0; i--) {
  837. int dat = (cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  838. outb(dat, addr);
  839. outb(dat | MDIO_SHIFT_CLK, addr);
  840. }
  841. for (i = 1; i >= 0; i--) {
  842. outb(0, addr);
  843. outb(MDIO_SHIFT_CLK, addr);
  844. }
  845. }
  846. /*======================================================================
  847. The driver core code, most of which should be common with a
  848. non-PCMCIA implementation.
  849. ======================================================================*/
  850. #ifdef PCMCIA_DEBUG
  851. static void smc_dump(struct net_device *dev)
  852. {
  853. unsigned int ioaddr = dev->base_addr;
  854. u_short i, w, save;
  855. save = inw(ioaddr + BANK_SELECT);
  856. for (w = 0; w < 4; w++) {
  857. SMC_SELECT_BANK(w);
  858. netdev_dbg(dev, "bank %d: ", w);
  859. for (i = 0; i < 14; i += 2)
  860. pr_cont(" %04x", inw(ioaddr + i));
  861. pr_cont("\n");
  862. }
  863. outw(save, ioaddr + BANK_SELECT);
  864. }
  865. #endif
  866. static int smc_open(struct net_device *dev)
  867. {
  868. struct smc_private *smc = netdev_priv(dev);
  869. struct pcmcia_device *link = smc->p_dev;
  870. dev_dbg(&link->dev, "%s: smc_open(%p), ID/Window %4.4x.\n",
  871. dev->name, dev, inw(dev->base_addr + BANK_SELECT));
  872. #ifdef PCMCIA_DEBUG
  873. smc_dump(dev);
  874. #endif
  875. /* Check that the PCMCIA card is still here. */
  876. if (!pcmcia_dev_present(link))
  877. return -ENODEV;
  878. /* Physical device present signature. */
  879. if (check_sig(link) < 0) {
  880. netdev_info(dev, "Yikes! Bad chip signature!\n");
  881. return -ENODEV;
  882. }
  883. link->open++;
  884. netif_start_queue(dev);
  885. smc->saved_skb = NULL;
  886. smc->packets_waiting = 0;
  887. smc_reset(dev);
  888. setup_timer(&smc->media, media_check, (u_long)dev);
  889. mod_timer(&smc->media, jiffies + HZ);
  890. return 0;
  891. } /* smc_open */
  892. /*====================================================================*/
  893. static int smc_close(struct net_device *dev)
  894. {
  895. struct smc_private *smc = netdev_priv(dev);
  896. struct pcmcia_device *link = smc->p_dev;
  897. unsigned int ioaddr = dev->base_addr;
  898. dev_dbg(&link->dev, "%s: smc_close(), status %4.4x.\n",
  899. dev->name, inw(ioaddr + BANK_SELECT));
  900. netif_stop_queue(dev);
  901. /* Shut off all interrupts, and turn off the Tx and Rx sections.
  902. Don't bother to check for chip present. */
  903. SMC_SELECT_BANK(2); /* Nominally paranoia, but do no assume... */
  904. outw(0, ioaddr + INTERRUPT);
  905. SMC_SELECT_BANK(0);
  906. mask_bits(0xff00, ioaddr + RCR);
  907. mask_bits(0xff00, ioaddr + TCR);
  908. /* Put the chip into power-down mode. */
  909. SMC_SELECT_BANK(1);
  910. outw(CTL_POWERDOWN, ioaddr + CONTROL );
  911. link->open--;
  912. del_timer_sync(&smc->media);
  913. return 0;
  914. } /* smc_close */
  915. /*======================================================================
  916. Transfer a packet to the hardware and trigger the packet send.
  917. This may be called at either from either the Tx queue code
  918. or the interrupt handler.
  919. ======================================================================*/
  920. static void smc_hardware_send_packet(struct net_device * dev)
  921. {
  922. struct smc_private *smc = netdev_priv(dev);
  923. struct sk_buff *skb = smc->saved_skb;
  924. unsigned int ioaddr = dev->base_addr;
  925. u_char packet_no;
  926. if (!skb) {
  927. netdev_err(dev, "In XMIT with no packet to send\n");
  928. return;
  929. }
  930. /* There should be a packet slot waiting. */
  931. packet_no = inw(ioaddr + PNR_ARR) >> 8;
  932. if (packet_no & 0x80) {
  933. /* If not, there is a hardware problem! Likely an ejected card. */
  934. netdev_warn(dev, "hardware Tx buffer allocation failed, status %#2.2x\n",
  935. packet_no);
  936. dev_kfree_skb_irq(skb);
  937. smc->saved_skb = NULL;
  938. netif_start_queue(dev);
  939. return;
  940. }
  941. dev->stats.tx_bytes += skb->len;
  942. /* The card should use the just-allocated buffer. */
  943. outw(packet_no, ioaddr + PNR_ARR);
  944. /* point to the beginning of the packet */
  945. outw(PTR_AUTOINC , ioaddr + POINTER);
  946. /* Send the packet length (+6 for status, length and ctl byte)
  947. and the status word (set to zeros). */
  948. {
  949. u_char *buf = skb->data;
  950. u_int length = skb->len; /* The chip will pad to ethernet min. */
  951. netdev_dbg(dev, "Trying to xmit packet of length %d\n", length);
  952. /* send the packet length: +6 for status word, length, and ctl */
  953. outw(0, ioaddr + DATA_1);
  954. outw(length + 6, ioaddr + DATA_1);
  955. outsw(ioaddr + DATA_1, buf, length >> 1);
  956. /* The odd last byte, if there is one, goes in the control word. */
  957. outw((length & 1) ? 0x2000 | buf[length-1] : 0, ioaddr + DATA_1);
  958. }
  959. /* Enable the Tx interrupts, both Tx (TxErr) and TxEmpty. */
  960. outw(((IM_TX_INT|IM_TX_EMPTY_INT)<<8) |
  961. (inw(ioaddr + INTERRUPT) & 0xff00),
  962. ioaddr + INTERRUPT);
  963. /* The chip does the rest of the work. */
  964. outw(MC_ENQUEUE , ioaddr + MMU_CMD);
  965. smc->saved_skb = NULL;
  966. dev_kfree_skb_irq(skb);
  967. netif_trans_update(dev);
  968. netif_start_queue(dev);
  969. }
  970. /*====================================================================*/
  971. static void smc_tx_timeout(struct net_device *dev)
  972. {
  973. struct smc_private *smc = netdev_priv(dev);
  974. unsigned int ioaddr = dev->base_addr;
  975. netdev_notice(dev, "transmit timed out, Tx_status %2.2x status %4.4x.\n",
  976. inw(ioaddr)&0xff, inw(ioaddr + 2));
  977. dev->stats.tx_errors++;
  978. smc_reset(dev);
  979. netif_trans_update(dev); /* prevent tx timeout */
  980. smc->saved_skb = NULL;
  981. netif_wake_queue(dev);
  982. }
  983. static netdev_tx_t smc_start_xmit(struct sk_buff *skb,
  984. struct net_device *dev)
  985. {
  986. struct smc_private *smc = netdev_priv(dev);
  987. unsigned int ioaddr = dev->base_addr;
  988. u_short num_pages;
  989. short time_out, ir;
  990. unsigned long flags;
  991. netif_stop_queue(dev);
  992. netdev_dbg(dev, "smc_start_xmit(length = %d) called, status %04x\n",
  993. skb->len, inw(ioaddr + 2));
  994. if (smc->saved_skb) {
  995. /* THIS SHOULD NEVER HAPPEN. */
  996. dev->stats.tx_aborted_errors++;
  997. netdev_dbg(dev, "Internal error -- sent packet while busy\n");
  998. return NETDEV_TX_BUSY;
  999. }
  1000. smc->saved_skb = skb;
  1001. num_pages = skb->len >> 8;
  1002. if (num_pages > 7) {
  1003. netdev_err(dev, "Far too big packet error: %d pages\n", num_pages);
  1004. dev_kfree_skb (skb);
  1005. smc->saved_skb = NULL;
  1006. dev->stats.tx_dropped++;
  1007. return NETDEV_TX_OK; /* Do not re-queue this packet. */
  1008. }
  1009. /* A packet is now waiting. */
  1010. smc->packets_waiting++;
  1011. spin_lock_irqsave(&smc->lock, flags);
  1012. SMC_SELECT_BANK(2); /* Paranoia, we should always be in window 2 */
  1013. /* need MC_RESET to keep the memory consistent. errata? */
  1014. if (smc->rx_ovrn) {
  1015. outw(MC_RESET, ioaddr + MMU_CMD);
  1016. smc->rx_ovrn = 0;
  1017. }
  1018. /* Allocate the memory; send the packet now if we win. */
  1019. outw(MC_ALLOC | num_pages, ioaddr + MMU_CMD);
  1020. for (time_out = MEMORY_WAIT_TIME; time_out >= 0; time_out--) {
  1021. ir = inw(ioaddr+INTERRUPT);
  1022. if (ir & IM_ALLOC_INT) {
  1023. /* Acknowledge the interrupt, send the packet. */
  1024. outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
  1025. smc_hardware_send_packet(dev); /* Send the packet now.. */
  1026. spin_unlock_irqrestore(&smc->lock, flags);
  1027. return NETDEV_TX_OK;
  1028. }
  1029. }
  1030. /* Otherwise defer until the Tx-space-allocated interrupt. */
  1031. netdev_dbg(dev, "memory allocation deferred.\n");
  1032. outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
  1033. spin_unlock_irqrestore(&smc->lock, flags);
  1034. return NETDEV_TX_OK;
  1035. }
  1036. /*======================================================================
  1037. Handle a Tx anomalous event. Entered while in Window 2.
  1038. ======================================================================*/
  1039. static void smc_tx_err(struct net_device * dev)
  1040. {
  1041. struct smc_private *smc = netdev_priv(dev);
  1042. unsigned int ioaddr = dev->base_addr;
  1043. int saved_packet = inw(ioaddr + PNR_ARR) & 0xff;
  1044. int packet_no = inw(ioaddr + FIFO_PORTS) & 0x7f;
  1045. int tx_status;
  1046. /* select this as the packet to read from */
  1047. outw(packet_no, ioaddr + PNR_ARR);
  1048. /* read the first word from this packet */
  1049. outw(PTR_AUTOINC | PTR_READ | 0, ioaddr + POINTER);
  1050. tx_status = inw(ioaddr + DATA_1);
  1051. dev->stats.tx_errors++;
  1052. if (tx_status & TS_LOSTCAR) dev->stats.tx_carrier_errors++;
  1053. if (tx_status & TS_LATCOL) dev->stats.tx_window_errors++;
  1054. if (tx_status & TS_16COL) {
  1055. dev->stats.tx_aborted_errors++;
  1056. smc->tx_err++;
  1057. }
  1058. if (tx_status & TS_SUCCESS) {
  1059. netdev_notice(dev, "Successful packet caused error interrupt?\n");
  1060. }
  1061. /* re-enable transmit */
  1062. SMC_SELECT_BANK(0);
  1063. outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
  1064. SMC_SELECT_BANK(2);
  1065. outw(MC_FREEPKT, ioaddr + MMU_CMD); /* Free the packet memory. */
  1066. /* one less packet waiting for me */
  1067. smc->packets_waiting--;
  1068. outw(saved_packet, ioaddr + PNR_ARR);
  1069. }
  1070. /*====================================================================*/
  1071. static void smc_eph_irq(struct net_device *dev)
  1072. {
  1073. struct smc_private *smc = netdev_priv(dev);
  1074. unsigned int ioaddr = dev->base_addr;
  1075. u_short card_stats, ephs;
  1076. SMC_SELECT_BANK(0);
  1077. ephs = inw(ioaddr + EPH);
  1078. netdev_dbg(dev, "Ethernet protocol handler interrupt, status %4.4x.\n",
  1079. ephs);
  1080. /* Could be a counter roll-over warning: update stats. */
  1081. card_stats = inw(ioaddr + COUNTER);
  1082. /* single collisions */
  1083. dev->stats.collisions += card_stats & 0xF;
  1084. card_stats >>= 4;
  1085. /* multiple collisions */
  1086. dev->stats.collisions += card_stats & 0xF;
  1087. #if 0 /* These are for when linux supports these statistics */
  1088. card_stats >>= 4; /* deferred */
  1089. card_stats >>= 4; /* excess deferred */
  1090. #endif
  1091. /* If we had a transmit error we must re-enable the transmitter. */
  1092. outw(inw(ioaddr + TCR) | TCR_ENABLE | smc->duplex, ioaddr + TCR);
  1093. /* Clear a link error interrupt. */
  1094. SMC_SELECT_BANK(1);
  1095. outw(CTL_AUTO_RELEASE | 0x0000, ioaddr + CONTROL);
  1096. outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
  1097. ioaddr + CONTROL);
  1098. SMC_SELECT_BANK(2);
  1099. }
  1100. /*====================================================================*/
  1101. static irqreturn_t smc_interrupt(int irq, void *dev_id)
  1102. {
  1103. struct net_device *dev = dev_id;
  1104. struct smc_private *smc = netdev_priv(dev);
  1105. unsigned int ioaddr;
  1106. u_short saved_bank, saved_pointer, mask, status;
  1107. unsigned int handled = 1;
  1108. char bogus_cnt = INTR_WORK; /* Work we are willing to do. */
  1109. if (!netif_device_present(dev))
  1110. return IRQ_NONE;
  1111. ioaddr = dev->base_addr;
  1112. netdev_dbg(dev, "SMC91c92 interrupt %d at %#x.\n",
  1113. irq, ioaddr);
  1114. spin_lock(&smc->lock);
  1115. smc->watchdog = 0;
  1116. saved_bank = inw(ioaddr + BANK_SELECT);
  1117. if ((saved_bank & 0xff00) != 0x3300) {
  1118. /* The device does not exist -- the card could be off-line, or
  1119. maybe it has been ejected. */
  1120. netdev_dbg(dev, "SMC91c92 interrupt %d for non-existent/ejected device.\n",
  1121. irq);
  1122. handled = 0;
  1123. goto irq_done;
  1124. }
  1125. SMC_SELECT_BANK(2);
  1126. saved_pointer = inw(ioaddr + POINTER);
  1127. mask = inw(ioaddr + INTERRUPT) >> 8;
  1128. /* clear all interrupts */
  1129. outw(0, ioaddr + INTERRUPT);
  1130. do { /* read the status flag, and mask it */
  1131. status = inw(ioaddr + INTERRUPT) & 0xff;
  1132. netdev_dbg(dev, "Status is %#2.2x (mask %#2.2x).\n",
  1133. status, mask);
  1134. if ((status & mask) == 0) {
  1135. if (bogus_cnt == INTR_WORK)
  1136. handled = 0;
  1137. break;
  1138. }
  1139. if (status & IM_RCV_INT) {
  1140. /* Got a packet(s). */
  1141. smc_rx(dev);
  1142. }
  1143. if (status & IM_TX_INT) {
  1144. smc_tx_err(dev);
  1145. outw(IM_TX_INT, ioaddr + INTERRUPT);
  1146. }
  1147. status &= mask;
  1148. if (status & IM_TX_EMPTY_INT) {
  1149. outw(IM_TX_EMPTY_INT, ioaddr + INTERRUPT);
  1150. mask &= ~IM_TX_EMPTY_INT;
  1151. dev->stats.tx_packets += smc->packets_waiting;
  1152. smc->packets_waiting = 0;
  1153. }
  1154. if (status & IM_ALLOC_INT) {
  1155. /* Clear this interrupt so it doesn't happen again */
  1156. mask &= ~IM_ALLOC_INT;
  1157. smc_hardware_send_packet(dev);
  1158. /* enable xmit interrupts based on this */
  1159. mask |= (IM_TX_EMPTY_INT | IM_TX_INT);
  1160. /* and let the card send more packets to me */
  1161. netif_wake_queue(dev);
  1162. }
  1163. if (status & IM_RX_OVRN_INT) {
  1164. dev->stats.rx_errors++;
  1165. dev->stats.rx_fifo_errors++;
  1166. if (smc->duplex)
  1167. smc->rx_ovrn = 1; /* need MC_RESET outside smc_interrupt */
  1168. outw(IM_RX_OVRN_INT, ioaddr + INTERRUPT);
  1169. }
  1170. if (status & IM_EPH_INT)
  1171. smc_eph_irq(dev);
  1172. } while (--bogus_cnt);
  1173. netdev_dbg(dev, " Restoring saved registers mask %2.2x bank %4.4x pointer %4.4x.\n",
  1174. mask, saved_bank, saved_pointer);
  1175. /* restore state register */
  1176. outw((mask<<8), ioaddr + INTERRUPT);
  1177. outw(saved_pointer, ioaddr + POINTER);
  1178. SMC_SELECT_BANK(saved_bank);
  1179. netdev_dbg(dev, "Exiting interrupt IRQ%d.\n", irq);
  1180. irq_done:
  1181. if ((smc->manfid == MANFID_OSITECH) &&
  1182. (smc->cardid != PRODID_OSITECH_SEVEN)) {
  1183. /* Retrigger interrupt if needed */
  1184. mask_bits(0x00ff, ioaddr-0x10+OSITECH_RESET_ISR);
  1185. set_bits(0x0300, ioaddr-0x10+OSITECH_RESET_ISR);
  1186. }
  1187. if (smc->manfid == MANFID_MOTOROLA) {
  1188. u_char cor;
  1189. cor = readb(smc->base + MOT_UART + CISREG_COR);
  1190. writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_UART + CISREG_COR);
  1191. writeb(cor, smc->base + MOT_UART + CISREG_COR);
  1192. cor = readb(smc->base + MOT_LAN + CISREG_COR);
  1193. writeb(cor & ~COR_IREQ_ENA, smc->base + MOT_LAN + CISREG_COR);
  1194. writeb(cor, smc->base + MOT_LAN + CISREG_COR);
  1195. }
  1196. if ((smc->base != NULL) && /* Megahertz MFC's */
  1197. (smc->manfid == MANFID_MEGAHERTZ) &&
  1198. (smc->cardid == PRODID_MEGAHERTZ_EM3288)) {
  1199. u_char tmp;
  1200. tmp = readb(smc->base+MEGAHERTZ_ISR);
  1201. tmp = readb(smc->base+MEGAHERTZ_ISR);
  1202. /* Retrigger interrupt if needed */
  1203. writeb(tmp, smc->base + MEGAHERTZ_ISR);
  1204. writeb(tmp, smc->base + MEGAHERTZ_ISR);
  1205. }
  1206. spin_unlock(&smc->lock);
  1207. return IRQ_RETVAL(handled);
  1208. }
  1209. /*====================================================================*/
  1210. static void smc_rx(struct net_device *dev)
  1211. {
  1212. unsigned int ioaddr = dev->base_addr;
  1213. int rx_status;
  1214. int packet_length; /* Caution: not frame length, rather words
  1215. to transfer from the chip. */
  1216. /* Assertion: we are in Window 2. */
  1217. if (inw(ioaddr + FIFO_PORTS) & FP_RXEMPTY) {
  1218. netdev_err(dev, "smc_rx() with nothing on Rx FIFO\n");
  1219. return;
  1220. }
  1221. /* Reset the read pointer, and read the status and packet length. */
  1222. outw(PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER);
  1223. rx_status = inw(ioaddr + DATA_1);
  1224. packet_length = inw(ioaddr + DATA_1) & 0x07ff;
  1225. netdev_dbg(dev, "Receive status %4.4x length %d.\n",
  1226. rx_status, packet_length);
  1227. if (!(rx_status & RS_ERRORS)) {
  1228. /* do stuff to make a new packet */
  1229. struct sk_buff *skb;
  1230. /* Note: packet_length adds 5 or 6 extra bytes here! */
  1231. skb = netdev_alloc_skb(dev, packet_length+2);
  1232. if (skb == NULL) {
  1233. netdev_dbg(dev, "Low memory, packet dropped.\n");
  1234. dev->stats.rx_dropped++;
  1235. outw(MC_RELEASE, ioaddr + MMU_CMD);
  1236. return;
  1237. }
  1238. packet_length -= (rx_status & RS_ODDFRAME ? 5 : 6);
  1239. skb_reserve(skb, 2);
  1240. insw(ioaddr+DATA_1, skb_put(skb, packet_length),
  1241. (packet_length+1)>>1);
  1242. skb->protocol = eth_type_trans(skb, dev);
  1243. netif_rx(skb);
  1244. dev->last_rx = jiffies;
  1245. dev->stats.rx_packets++;
  1246. dev->stats.rx_bytes += packet_length;
  1247. if (rx_status & RS_MULTICAST)
  1248. dev->stats.multicast++;
  1249. } else {
  1250. /* error ... */
  1251. dev->stats.rx_errors++;
  1252. if (rx_status & RS_ALGNERR) dev->stats.rx_frame_errors++;
  1253. if (rx_status & (RS_TOOSHORT | RS_TOOLONG))
  1254. dev->stats.rx_length_errors++;
  1255. if (rx_status & RS_BADCRC) dev->stats.rx_crc_errors++;
  1256. }
  1257. /* Let the MMU free the memory of this packet. */
  1258. outw(MC_RELEASE, ioaddr + MMU_CMD);
  1259. }
  1260. /*======================================================================
  1261. Set the receive mode.
  1262. This routine is used by both the protocol level to notify us of
  1263. promiscuous/multicast mode changes, and by the open/reset code to
  1264. initialize the Rx registers. We always set the multicast list and
  1265. leave the receiver running.
  1266. ======================================================================*/
  1267. static void set_rx_mode(struct net_device *dev)
  1268. {
  1269. unsigned int ioaddr = dev->base_addr;
  1270. struct smc_private *smc = netdev_priv(dev);
  1271. unsigned char multicast_table[8];
  1272. unsigned long flags;
  1273. u_short rx_cfg_setting;
  1274. int i;
  1275. memset(multicast_table, 0, sizeof(multicast_table));
  1276. if (dev->flags & IFF_PROMISC) {
  1277. rx_cfg_setting = RxStripCRC | RxEnable | RxPromisc | RxAllMulti;
  1278. } else if (dev->flags & IFF_ALLMULTI)
  1279. rx_cfg_setting = RxStripCRC | RxEnable | RxAllMulti;
  1280. else {
  1281. if (!netdev_mc_empty(dev)) {
  1282. struct netdev_hw_addr *ha;
  1283. netdev_for_each_mc_addr(ha, dev) {
  1284. u_int position = ether_crc(6, ha->addr);
  1285. multicast_table[position >> 29] |= 1 << ((position >> 26) & 7);
  1286. }
  1287. }
  1288. rx_cfg_setting = RxStripCRC | RxEnable;
  1289. }
  1290. /* Load MC table and Rx setting into the chip without interrupts. */
  1291. spin_lock_irqsave(&smc->lock, flags);
  1292. SMC_SELECT_BANK(3);
  1293. for (i = 0; i < 8; i++)
  1294. outb(multicast_table[i], ioaddr + MULTICAST0 + i);
  1295. SMC_SELECT_BANK(0);
  1296. outw(rx_cfg_setting, ioaddr + RCR);
  1297. SMC_SELECT_BANK(2);
  1298. spin_unlock_irqrestore(&smc->lock, flags);
  1299. }
  1300. /*======================================================================
  1301. Senses when a card's config changes. Here, it's coax or TP.
  1302. ======================================================================*/
  1303. static int s9k_config(struct net_device *dev, struct ifmap *map)
  1304. {
  1305. struct smc_private *smc = netdev_priv(dev);
  1306. if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
  1307. if (smc->cfg & CFG_MII_SELECT)
  1308. return -EOPNOTSUPP;
  1309. else if (map->port > 2)
  1310. return -EINVAL;
  1311. dev->if_port = map->port;
  1312. netdev_info(dev, "switched to %s port\n", if_names[dev->if_port]);
  1313. smc_reset(dev);
  1314. }
  1315. return 0;
  1316. }
  1317. /*======================================================================
  1318. Reset the chip, reloading every register that might be corrupted.
  1319. ======================================================================*/
  1320. /*
  1321. Set transceiver type, perhaps to something other than what the user
  1322. specified in dev->if_port.
  1323. */
  1324. static void smc_set_xcvr(struct net_device *dev, int if_port)
  1325. {
  1326. struct smc_private *smc = netdev_priv(dev);
  1327. unsigned int ioaddr = dev->base_addr;
  1328. u_short saved_bank;
  1329. saved_bank = inw(ioaddr + BANK_SELECT);
  1330. SMC_SELECT_BANK(1);
  1331. if (if_port == 2) {
  1332. outw(smc->cfg | CFG_AUI_SELECT, ioaddr + CONFIG);
  1333. if ((smc->manfid == MANFID_OSITECH) &&
  1334. (smc->cardid != PRODID_OSITECH_SEVEN))
  1335. set_bits(OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
  1336. smc->media_status = ((dev->if_port == 0) ? 0x0001 : 0x0002);
  1337. } else {
  1338. outw(smc->cfg, ioaddr + CONFIG);
  1339. if ((smc->manfid == MANFID_OSITECH) &&
  1340. (smc->cardid != PRODID_OSITECH_SEVEN))
  1341. mask_bits(~OSI_AUI_PWR, ioaddr - 0x10 + OSITECH_AUI_PWR);
  1342. smc->media_status = ((dev->if_port == 0) ? 0x0012 : 0x4001);
  1343. }
  1344. SMC_SELECT_BANK(saved_bank);
  1345. }
  1346. static void smc_reset(struct net_device *dev)
  1347. {
  1348. unsigned int ioaddr = dev->base_addr;
  1349. struct smc_private *smc = netdev_priv(dev);
  1350. int i;
  1351. netdev_dbg(dev, "smc91c92 reset called.\n");
  1352. /* The first interaction must be a write to bring the chip out
  1353. of sleep mode. */
  1354. SMC_SELECT_BANK(0);
  1355. /* Reset the chip. */
  1356. outw(RCR_SOFTRESET, ioaddr + RCR);
  1357. udelay(10);
  1358. /* Clear the transmit and receive configuration registers. */
  1359. outw(RCR_CLEAR, ioaddr + RCR);
  1360. outw(TCR_CLEAR, ioaddr + TCR);
  1361. /* Set the Window 1 control, configuration and station addr registers.
  1362. No point in writing the I/O base register ;-> */
  1363. SMC_SELECT_BANK(1);
  1364. /* Automatically release successfully transmitted packets,
  1365. Accept link errors, counter and Tx error interrupts. */
  1366. outw(CTL_AUTO_RELEASE | CTL_TE_ENABLE | CTL_CR_ENABLE,
  1367. ioaddr + CONTROL);
  1368. smc_set_xcvr(dev, dev->if_port);
  1369. if ((smc->manfid == MANFID_OSITECH) &&
  1370. (smc->cardid != PRODID_OSITECH_SEVEN))
  1371. outw((dev->if_port == 2 ? OSI_AUI_PWR : 0) |
  1372. (inw(ioaddr-0x10+OSITECH_AUI_PWR) & 0xff00),
  1373. ioaddr - 0x10 + OSITECH_AUI_PWR);
  1374. /* Fill in the physical address. The databook is wrong about the order! */
  1375. for (i = 0; i < 6; i += 2)
  1376. outw((dev->dev_addr[i+1]<<8)+dev->dev_addr[i],
  1377. ioaddr + ADDR0 + i);
  1378. /* Reset the MMU */
  1379. SMC_SELECT_BANK(2);
  1380. outw(MC_RESET, ioaddr + MMU_CMD);
  1381. outw(0, ioaddr + INTERRUPT);
  1382. /* Re-enable the chip. */
  1383. SMC_SELECT_BANK(0);
  1384. outw(((smc->cfg & CFG_MII_SELECT) ? 0 : TCR_MONCSN) |
  1385. TCR_ENABLE | TCR_PAD_EN | smc->duplex, ioaddr + TCR);
  1386. set_rx_mode(dev);
  1387. if (smc->cfg & CFG_MII_SELECT) {
  1388. SMC_SELECT_BANK(3);
  1389. /* Reset MII */
  1390. mdio_write(dev, smc->mii_if.phy_id, 0, 0x8000);
  1391. /* Advertise 100F, 100H, 10F, 10H */
  1392. mdio_write(dev, smc->mii_if.phy_id, 4, 0x01e1);
  1393. /* Restart MII autonegotiation */
  1394. mdio_write(dev, smc->mii_if.phy_id, 0, 0x0000);
  1395. mdio_write(dev, smc->mii_if.phy_id, 0, 0x1200);
  1396. }
  1397. /* Enable interrupts. */
  1398. SMC_SELECT_BANK(2);
  1399. outw((IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT) << 8,
  1400. ioaddr + INTERRUPT);
  1401. }
  1402. /*======================================================================
  1403. Media selection timer routine
  1404. ======================================================================*/
  1405. static void media_check(u_long arg)
  1406. {
  1407. struct net_device *dev = (struct net_device *) arg;
  1408. struct smc_private *smc = netdev_priv(dev);
  1409. unsigned int ioaddr = dev->base_addr;
  1410. u_short i, media, saved_bank;
  1411. u_short link;
  1412. unsigned long flags;
  1413. spin_lock_irqsave(&smc->lock, flags);
  1414. saved_bank = inw(ioaddr + BANK_SELECT);
  1415. if (!netif_device_present(dev))
  1416. goto reschedule;
  1417. SMC_SELECT_BANK(2);
  1418. /* need MC_RESET to keep the memory consistent. errata? */
  1419. if (smc->rx_ovrn) {
  1420. outw(MC_RESET, ioaddr + MMU_CMD);
  1421. smc->rx_ovrn = 0;
  1422. }
  1423. i = inw(ioaddr + INTERRUPT);
  1424. SMC_SELECT_BANK(0);
  1425. media = inw(ioaddr + EPH) & EPH_LINK_OK;
  1426. SMC_SELECT_BANK(1);
  1427. media |= (inw(ioaddr + CONFIG) & CFG_AUI_SELECT) ? 2 : 1;
  1428. SMC_SELECT_BANK(saved_bank);
  1429. spin_unlock_irqrestore(&smc->lock, flags);
  1430. /* Check for pending interrupt with watchdog flag set: with
  1431. this, we can limp along even if the interrupt is blocked */
  1432. if (smc->watchdog++ && ((i>>8) & i)) {
  1433. if (!smc->fast_poll)
  1434. netdev_info(dev, "interrupt(s) dropped!\n");
  1435. local_irq_save(flags);
  1436. smc_interrupt(dev->irq, dev);
  1437. local_irq_restore(flags);
  1438. smc->fast_poll = HZ;
  1439. }
  1440. if (smc->fast_poll) {
  1441. smc->fast_poll--;
  1442. smc->media.expires = jiffies + HZ/100;
  1443. add_timer(&smc->media);
  1444. return;
  1445. }
  1446. spin_lock_irqsave(&smc->lock, flags);
  1447. saved_bank = inw(ioaddr + BANK_SELECT);
  1448. if (smc->cfg & CFG_MII_SELECT) {
  1449. if (smc->mii_if.phy_id < 0)
  1450. goto reschedule;
  1451. SMC_SELECT_BANK(3);
  1452. link = mdio_read(dev, smc->mii_if.phy_id, 1);
  1453. if (!link || (link == 0xffff)) {
  1454. netdev_info(dev, "MII is missing!\n");
  1455. smc->mii_if.phy_id = -1;
  1456. goto reschedule;
  1457. }
  1458. link &= 0x0004;
  1459. if (link != smc->link_status) {
  1460. u_short p = mdio_read(dev, smc->mii_if.phy_id, 5);
  1461. netdev_info(dev, "%s link beat\n", link ? "found" : "lost");
  1462. smc->duplex = (((p & 0x0100) || ((p & 0x1c0) == 0x40))
  1463. ? TCR_FDUPLX : 0);
  1464. if (link) {
  1465. netdev_info(dev, "autonegotiation complete: "
  1466. "%dbaseT-%cD selected\n",
  1467. (p & 0x0180) ? 100 : 10, smc->duplex ? 'F' : 'H');
  1468. }
  1469. SMC_SELECT_BANK(0);
  1470. outw(inw(ioaddr + TCR) | smc->duplex, ioaddr + TCR);
  1471. smc->link_status = link;
  1472. }
  1473. goto reschedule;
  1474. }
  1475. /* Ignore collisions unless we've had no rx's recently */
  1476. if (time_after(jiffies, dev->last_rx + HZ)) {
  1477. if (smc->tx_err || (smc->media_status & EPH_16COL))
  1478. media |= EPH_16COL;
  1479. }
  1480. smc->tx_err = 0;
  1481. if (media != smc->media_status) {
  1482. if ((media & smc->media_status & 1) &&
  1483. ((smc->media_status ^ media) & EPH_LINK_OK))
  1484. netdev_info(dev, "%s link beat\n",
  1485. smc->media_status & EPH_LINK_OK ? "lost" : "found");
  1486. else if ((media & smc->media_status & 2) &&
  1487. ((smc->media_status ^ media) & EPH_16COL))
  1488. netdev_info(dev, "coax cable %s\n",
  1489. media & EPH_16COL ? "problem" : "ok");
  1490. if (dev->if_port == 0) {
  1491. if (media & 1) {
  1492. if (media & EPH_LINK_OK)
  1493. netdev_info(dev, "flipped to 10baseT\n");
  1494. else
  1495. smc_set_xcvr(dev, 2);
  1496. } else {
  1497. if (media & EPH_16COL)
  1498. smc_set_xcvr(dev, 1);
  1499. else
  1500. netdev_info(dev, "flipped to 10base2\n");
  1501. }
  1502. }
  1503. smc->media_status = media;
  1504. }
  1505. reschedule:
  1506. smc->media.expires = jiffies + HZ;
  1507. add_timer(&smc->media);
  1508. SMC_SELECT_BANK(saved_bank);
  1509. spin_unlock_irqrestore(&smc->lock, flags);
  1510. }
  1511. static int smc_link_ok(struct net_device *dev)
  1512. {
  1513. unsigned int ioaddr = dev->base_addr;
  1514. struct smc_private *smc = netdev_priv(dev);
  1515. if (smc->cfg & CFG_MII_SELECT) {
  1516. return mii_link_ok(&smc->mii_if);
  1517. } else {
  1518. SMC_SELECT_BANK(0);
  1519. return inw(ioaddr + EPH) & EPH_LINK_OK;
  1520. }
  1521. }
  1522. static int smc_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
  1523. {
  1524. u16 tmp;
  1525. unsigned int ioaddr = dev->base_addr;
  1526. ecmd->supported = (SUPPORTED_TP | SUPPORTED_AUI |
  1527. SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full);
  1528. SMC_SELECT_BANK(1);
  1529. tmp = inw(ioaddr + CONFIG);
  1530. ecmd->port = (tmp & CFG_AUI_SELECT) ? PORT_AUI : PORT_TP;
  1531. ecmd->transceiver = XCVR_INTERNAL;
  1532. ethtool_cmd_speed_set(ecmd, SPEED_10);
  1533. ecmd->phy_address = ioaddr + MGMT;
  1534. SMC_SELECT_BANK(0);
  1535. tmp = inw(ioaddr + TCR);
  1536. ecmd->duplex = (tmp & TCR_FDUPLX) ? DUPLEX_FULL : DUPLEX_HALF;
  1537. return 0;
  1538. }
  1539. static int smc_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
  1540. {
  1541. u16 tmp;
  1542. unsigned int ioaddr = dev->base_addr;
  1543. if (ethtool_cmd_speed(ecmd) != SPEED_10)
  1544. return -EINVAL;
  1545. if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
  1546. return -EINVAL;
  1547. if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI)
  1548. return -EINVAL;
  1549. if (ecmd->transceiver != XCVR_INTERNAL)
  1550. return -EINVAL;
  1551. if (ecmd->port == PORT_AUI)
  1552. smc_set_xcvr(dev, 1);
  1553. else
  1554. smc_set_xcvr(dev, 0);
  1555. SMC_SELECT_BANK(0);
  1556. tmp = inw(ioaddr + TCR);
  1557. if (ecmd->duplex == DUPLEX_FULL)
  1558. tmp |= TCR_FDUPLX;
  1559. else
  1560. tmp &= ~TCR_FDUPLX;
  1561. outw(tmp, ioaddr + TCR);
  1562. return 0;
  1563. }
  1564. static int check_if_running(struct net_device *dev)
  1565. {
  1566. if (!netif_running(dev))
  1567. return -EINVAL;
  1568. return 0;
  1569. }
  1570. static void smc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1571. {
  1572. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  1573. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1574. }
  1575. static int smc_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1576. {
  1577. struct smc_private *smc = netdev_priv(dev);
  1578. unsigned int ioaddr = dev->base_addr;
  1579. u16 saved_bank = inw(ioaddr + BANK_SELECT);
  1580. int ret;
  1581. unsigned long flags;
  1582. spin_lock_irqsave(&smc->lock, flags);
  1583. SMC_SELECT_BANK(3);
  1584. if (smc->cfg & CFG_MII_SELECT)
  1585. ret = mii_ethtool_gset(&smc->mii_if, ecmd);
  1586. else
  1587. ret = smc_netdev_get_ecmd(dev, ecmd);
  1588. SMC_SELECT_BANK(saved_bank);
  1589. spin_unlock_irqrestore(&smc->lock, flags);
  1590. return ret;
  1591. }
  1592. static int smc_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1593. {
  1594. struct smc_private *smc = netdev_priv(dev);
  1595. unsigned int ioaddr = dev->base_addr;
  1596. u16 saved_bank = inw(ioaddr + BANK_SELECT);
  1597. int ret;
  1598. unsigned long flags;
  1599. spin_lock_irqsave(&smc->lock, flags);
  1600. SMC_SELECT_BANK(3);
  1601. if (smc->cfg & CFG_MII_SELECT)
  1602. ret = mii_ethtool_sset(&smc->mii_if, ecmd);
  1603. else
  1604. ret = smc_netdev_set_ecmd(dev, ecmd);
  1605. SMC_SELECT_BANK(saved_bank);
  1606. spin_unlock_irqrestore(&smc->lock, flags);
  1607. return ret;
  1608. }
  1609. static u32 smc_get_link(struct net_device *dev)
  1610. {
  1611. struct smc_private *smc = netdev_priv(dev);
  1612. unsigned int ioaddr = dev->base_addr;
  1613. u16 saved_bank = inw(ioaddr + BANK_SELECT);
  1614. u32 ret;
  1615. unsigned long flags;
  1616. spin_lock_irqsave(&smc->lock, flags);
  1617. SMC_SELECT_BANK(3);
  1618. ret = smc_link_ok(dev);
  1619. SMC_SELECT_BANK(saved_bank);
  1620. spin_unlock_irqrestore(&smc->lock, flags);
  1621. return ret;
  1622. }
  1623. static int smc_nway_reset(struct net_device *dev)
  1624. {
  1625. struct smc_private *smc = netdev_priv(dev);
  1626. if (smc->cfg & CFG_MII_SELECT) {
  1627. unsigned int ioaddr = dev->base_addr;
  1628. u16 saved_bank = inw(ioaddr + BANK_SELECT);
  1629. int res;
  1630. SMC_SELECT_BANK(3);
  1631. res = mii_nway_restart(&smc->mii_if);
  1632. SMC_SELECT_BANK(saved_bank);
  1633. return res;
  1634. } else
  1635. return -EOPNOTSUPP;
  1636. }
  1637. static const struct ethtool_ops ethtool_ops = {
  1638. .begin = check_if_running,
  1639. .get_drvinfo = smc_get_drvinfo,
  1640. .get_settings = smc_get_settings,
  1641. .set_settings = smc_set_settings,
  1642. .get_link = smc_get_link,
  1643. .nway_reset = smc_nway_reset,
  1644. };
  1645. static int smc_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
  1646. {
  1647. struct smc_private *smc = netdev_priv(dev);
  1648. struct mii_ioctl_data *mii = if_mii(rq);
  1649. int rc = 0;
  1650. u16 saved_bank;
  1651. unsigned int ioaddr = dev->base_addr;
  1652. unsigned long flags;
  1653. if (!netif_running(dev))
  1654. return -EINVAL;
  1655. spin_lock_irqsave(&smc->lock, flags);
  1656. saved_bank = inw(ioaddr + BANK_SELECT);
  1657. SMC_SELECT_BANK(3);
  1658. rc = generic_mii_ioctl(&smc->mii_if, mii, cmd, NULL);
  1659. SMC_SELECT_BANK(saved_bank);
  1660. spin_unlock_irqrestore(&smc->lock, flags);
  1661. return rc;
  1662. }
  1663. static const struct pcmcia_device_id smc91c92_ids[] = {
  1664. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0109, 0x0501),
  1665. PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0140, 0x000a),
  1666. PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
  1667. PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
  1668. PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
  1669. PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
  1670. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
  1671. PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
  1672. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
  1673. PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
  1674. PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
  1675. PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
  1676. PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
  1677. PCMCIA_DEVICE_PROD_ID12("ARGOSY", "Fast Ethernet PCCard", 0x78f308dc, 0xdcea68bc),
  1678. PCMCIA_DEVICE_PROD_ID12("dit Co., Ltd.", "PC Card-10/100BTX", 0xe59365c8, 0x6a2161d1),
  1679. PCMCIA_DEVICE_PROD_ID12("DYNALINK", "L100C", 0x6a26d1cf, 0xc16ce9c5),
  1680. PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
  1681. PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
  1682. PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
  1683. PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
  1684. PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
  1685. PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
  1686. PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
  1687. PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
  1688. /* These conflict with other cards! */
  1689. /* PCMCIA_DEVICE_MANF_CARD(0x0186, 0x0100), */
  1690. /* PCMCIA_DEVICE_MANF_CARD(0x8a01, 0xc1ab), */
  1691. PCMCIA_DEVICE_NULL,
  1692. };
  1693. MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
  1694. static struct pcmcia_driver smc91c92_cs_driver = {
  1695. .owner = THIS_MODULE,
  1696. .name = "smc91c92_cs",
  1697. .probe = smc91c92_probe,
  1698. .remove = smc91c92_detach,
  1699. .id_table = smc91c92_ids,
  1700. .suspend = smc91c92_suspend,
  1701. .resume = smc91c92_resume,
  1702. };
  1703. module_pcmcia_driver(smc91c92_cs_driver);