macsonic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * macsonic.c
  3. *
  4. * (C) 2005 Finn Thain
  5. *
  6. * Converted to DMA API, converted to unified driver model, made it work as
  7. * a module again, and from the mac68k project, introduced more 32-bit cards
  8. * and dhd's support for 16-bit cards.
  9. *
  10. * (C) 1998 Alan Cox
  11. *
  12. * Debugging Andreas Ehliar, Michael Schmitz
  13. *
  14. * Based on code
  15. * (C) 1996 by Thomas Bogendoerfer (tsbogend@bigbug.franken.de)
  16. *
  17. * This driver is based on work from Andreas Busse, but most of
  18. * the code is rewritten.
  19. *
  20. * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
  21. *
  22. * A driver for the Mac onboard Sonic ethernet chip.
  23. *
  24. * 98/12/21 MSch: judged from tests on Q800, it's basically working,
  25. * but eating up both receive and transmit resources
  26. * and duplicating packets. Needs more testing.
  27. *
  28. * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed.
  29. *
  30. * 00/10/31 sammy@oh.verio.com: Updated driver for 2.4 kernels, fixed problems
  31. * on centris.
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/types.h>
  36. #include <linux/fcntl.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/init.h>
  39. #include <linux/ioport.h>
  40. #include <linux/in.h>
  41. #include <linux/slab.h>
  42. #include <linux/string.h>
  43. #include <linux/delay.h>
  44. #include <linux/nubus.h>
  45. #include <linux/errno.h>
  46. #include <linux/netdevice.h>
  47. #include <linux/etherdevice.h>
  48. #include <linux/skbuff.h>
  49. #include <linux/platform_device.h>
  50. #include <linux/dma-mapping.h>
  51. #include <linux/bitrev.h>
  52. #include <asm/bootinfo.h>
  53. #include <asm/system.h>
  54. #include <asm/pgtable.h>
  55. #include <asm/io.h>
  56. #include <asm/hwtest.h>
  57. #include <asm/dma.h>
  58. #include <asm/macintosh.h>
  59. #include <asm/macints.h>
  60. #include <asm/mac_via.h>
  61. static char mac_sonic_string[] = "macsonic";
  62. #include "sonic.h"
  63. /* These should basically be bus-size and endian independent (since
  64. the SONIC is at least smart enough that it uses the same endianness
  65. as the host, unlike certain less enlightened Macintosh NICs) */
  66. #define SONIC_READ(reg) (nubus_readw(dev->base_addr + (reg * 4) \
  67. + lp->reg_offset))
  68. #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \
  69. + lp->reg_offset))
  70. /* use 0 for production, 1 for verification, >1 for debug */
  71. #ifdef SONIC_DEBUG
  72. static unsigned int sonic_debug = SONIC_DEBUG;
  73. #else
  74. static unsigned int sonic_debug = 1;
  75. #endif
  76. static int sonic_version_printed;
  77. /* For onboard SONIC */
  78. #define ONBOARD_SONIC_REGISTERS 0x50F0A000
  79. #define ONBOARD_SONIC_PROM_BASE 0x50f08000
  80. enum macsonic_type {
  81. MACSONIC_DUODOCK,
  82. MACSONIC_APPLE,
  83. MACSONIC_APPLE16,
  84. MACSONIC_DAYNA,
  85. MACSONIC_DAYNALINK
  86. };
  87. /* For the built-in SONIC in the Duo Dock */
  88. #define DUODOCK_SONIC_REGISTERS 0xe10000
  89. #define DUODOCK_SONIC_PROM_BASE 0xe12000
  90. /* For Apple-style NuBus SONIC */
  91. #define APPLE_SONIC_REGISTERS 0
  92. #define APPLE_SONIC_PROM_BASE 0x40000
  93. /* Daynalink LC SONIC */
  94. #define DAYNALINK_PROM_BASE 0x400000
  95. /* For Dayna-style NuBus SONIC (haven't seen one yet) */
  96. #define DAYNA_SONIC_REGISTERS 0x180000
  97. /* This is what OpenBSD says. However, this is definitely in NuBus
  98. ROM space so we should be able to get it by walking the NuBus
  99. resource directories */
  100. #define DAYNA_SONIC_MAC_ADDR 0xffe004
  101. #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr)
  102. /*
  103. * For reversing the PROM address
  104. */
  105. static inline void bit_reverse_addr(unsigned char addr[6])
  106. {
  107. int i;
  108. for(i = 0; i < 6; i++)
  109. addr[i] = bitrev8(addr[i]);
  110. }
  111. static irqreturn_t macsonic_interrupt(int irq, void *dev_id)
  112. {
  113. irqreturn_t result;
  114. unsigned long flags;
  115. local_irq_save(flags);
  116. result = sonic_interrupt(irq, dev_id);
  117. local_irq_restore(flags);
  118. return result;
  119. }
  120. static int macsonic_open(struct net_device* dev)
  121. {
  122. if (request_irq(dev->irq, sonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
  123. printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
  124. return -EAGAIN;
  125. }
  126. /* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes
  127. * in at priority level 3. However, we sometimes get the level 2 inter-
  128. * rupt as well, which must prevent re-entrance of the sonic handler.
  129. */
  130. if (dev->irq == IRQ_AUTO_3)
  131. if (request_irq(IRQ_NUBUS_9, macsonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
  132. printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, IRQ_NUBUS_9);
  133. free_irq(dev->irq, dev);
  134. return -EAGAIN;
  135. }
  136. return sonic_open(dev);
  137. }
  138. static int macsonic_close(struct net_device* dev)
  139. {
  140. int err;
  141. err = sonic_close(dev);
  142. free_irq(dev->irq, dev);
  143. if (dev->irq == IRQ_AUTO_3)
  144. free_irq(IRQ_NUBUS_9, dev);
  145. return err;
  146. }
  147. static const struct net_device_ops macsonic_netdev_ops = {
  148. .ndo_open = macsonic_open,
  149. .ndo_stop = macsonic_close,
  150. .ndo_start_xmit = sonic_send_packet,
  151. .ndo_set_multicast_list = sonic_multicast_list,
  152. .ndo_tx_timeout = sonic_tx_timeout,
  153. .ndo_get_stats = sonic_get_stats,
  154. .ndo_validate_addr = eth_validate_addr,
  155. .ndo_change_mtu = eth_change_mtu,
  156. .ndo_set_mac_address = eth_mac_addr,
  157. };
  158. static int __devinit macsonic_init(struct net_device *dev)
  159. {
  160. struct sonic_local* lp = netdev_priv(dev);
  161. /* Allocate the entire chunk of memory for the descriptors.
  162. Note that this cannot cross a 64K boundary. */
  163. if ((lp->descriptors = dma_alloc_coherent(lp->device,
  164. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  165. &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
  166. printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n",
  167. dev_name(lp->device));
  168. return -ENOMEM;
  169. }
  170. /* Now set up the pointers to point to the appropriate places */
  171. lp->cda = lp->descriptors;
  172. lp->tda = lp->cda + (SIZEOF_SONIC_CDA
  173. * SONIC_BUS_SCALE(lp->dma_bitmode));
  174. lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  175. * SONIC_BUS_SCALE(lp->dma_bitmode));
  176. lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  177. * SONIC_BUS_SCALE(lp->dma_bitmode));
  178. lp->cda_laddr = lp->descriptors_laddr;
  179. lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
  180. * SONIC_BUS_SCALE(lp->dma_bitmode));
  181. lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  182. * SONIC_BUS_SCALE(lp->dma_bitmode));
  183. lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  184. * SONIC_BUS_SCALE(lp->dma_bitmode));
  185. dev->netdev_ops = &macsonic_netdev_ops;
  186. dev->watchdog_timeo = TX_TIMEOUT;
  187. /*
  188. * clear tally counter
  189. */
  190. SONIC_WRITE(SONIC_CRCT, 0xffff);
  191. SONIC_WRITE(SONIC_FAET, 0xffff);
  192. SONIC_WRITE(SONIC_MPT, 0xffff);
  193. return 0;
  194. }
  195. #define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
  196. memcmp(mac, "\x00\xA0\x40", 3) && \
  197. memcmp(mac, "\x00\x80\x19", 3) && \
  198. memcmp(mac, "\x00\x05\x02", 3))
  199. static void __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev)
  200. {
  201. struct sonic_local *lp = netdev_priv(dev);
  202. const int prom_addr = ONBOARD_SONIC_PROM_BASE;
  203. unsigned short val;
  204. /*
  205. * On NuBus boards we can sometimes look in the ROM resources.
  206. * No such luck for comm-slot/onboard.
  207. * On the PowerBook 520, the PROM base address is a mystery.
  208. */
  209. if (hwreg_present((void *)prom_addr)) {
  210. int i;
  211. for (i = 0; i < 6; i++)
  212. dev->dev_addr[i] = SONIC_READ_PROM(i);
  213. if (!INVALID_MAC(dev->dev_addr))
  214. return;
  215. /*
  216. * Most of the time, the address is bit-reversed. The NetBSD
  217. * source has a rather long and detailed historical account of
  218. * why this is so.
  219. */
  220. bit_reverse_addr(dev->dev_addr);
  221. if (!INVALID_MAC(dev->dev_addr))
  222. return;
  223. /*
  224. * If we still have what seems to be a bogus address, we'll
  225. * look in the CAM. The top entry should be ours.
  226. */
  227. printk(KERN_WARNING "macsonic: MAC address in PROM seems "
  228. "to be invalid, trying CAM\n");
  229. } else {
  230. printk(KERN_WARNING "macsonic: cannot read MAC address from "
  231. "PROM, trying CAM\n");
  232. }
  233. /* This only works if MacOS has already initialized the card. */
  234. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  235. SONIC_WRITE(SONIC_CEP, 15);
  236. val = SONIC_READ(SONIC_CAP2);
  237. dev->dev_addr[5] = val >> 8;
  238. dev->dev_addr[4] = val & 0xff;
  239. val = SONIC_READ(SONIC_CAP1);
  240. dev->dev_addr[3] = val >> 8;
  241. dev->dev_addr[2] = val & 0xff;
  242. val = SONIC_READ(SONIC_CAP0);
  243. dev->dev_addr[1] = val >> 8;
  244. dev->dev_addr[0] = val & 0xff;
  245. if (!INVALID_MAC(dev->dev_addr))
  246. return;
  247. /* Still nonsense ... messed up someplace! */
  248. printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
  249. "seems invalid, will use a random MAC\n");
  250. random_ether_addr(dev->dev_addr);
  251. }
  252. static int __devinit mac_onboard_sonic_probe(struct net_device *dev)
  253. {
  254. /* Bwahahaha */
  255. static int once_is_more_than_enough;
  256. struct sonic_local* lp = netdev_priv(dev);
  257. int sr;
  258. int commslot = 0;
  259. if (once_is_more_than_enough)
  260. return -ENODEV;
  261. once_is_more_than_enough = 1;
  262. if (!MACH_IS_MAC)
  263. return -ENODEV;
  264. if (macintosh_config->ether_type != MAC_ETHER_SONIC)
  265. return -ENODEV;
  266. printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
  267. /* Bogus probing, on the models which may or may not have
  268. Ethernet (BTW, the Ethernet *is* always at the same
  269. address, and nothing else lives there, at least if Apple's
  270. documentation is to be believed) */
  271. if (macintosh_config->ident == MAC_MODEL_Q630 ||
  272. macintosh_config->ident == MAC_MODEL_P588 ||
  273. macintosh_config->ident == MAC_MODEL_P575 ||
  274. macintosh_config->ident == MAC_MODEL_C610) {
  275. unsigned long flags;
  276. int card_present;
  277. local_irq_save(flags);
  278. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  279. local_irq_restore(flags);
  280. if (!card_present) {
  281. printk("none.\n");
  282. return -ENODEV;
  283. }
  284. commslot = 1;
  285. }
  286. printk("yes\n");
  287. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  288. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  289. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  290. if (via_alt_mapping)
  291. dev->irq = IRQ_AUTO_3;
  292. else
  293. dev->irq = IRQ_NUBUS_9;
  294. if (!sonic_version_printed) {
  295. printk(KERN_INFO "%s", version);
  296. sonic_version_printed = 1;
  297. }
  298. printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
  299. dev_name(lp->device), dev->base_addr);
  300. /* The PowerBook's SONIC is 16 bit always. */
  301. if (macintosh_config->ident == MAC_MODEL_PB520) {
  302. lp->reg_offset = 0;
  303. lp->dma_bitmode = SONIC_BITMODE16;
  304. sr = SONIC_READ(SONIC_SR);
  305. } else if (commslot) {
  306. /* Some of the comm-slot cards are 16 bit. But some
  307. of them are not. The 32-bit cards use offset 2 and
  308. have known revisions, we try reading the revision
  309. register at offset 2, if we don't get a known revision
  310. we assume 16 bit at offset 0. */
  311. lp->reg_offset = 2;
  312. lp->dma_bitmode = SONIC_BITMODE16;
  313. sr = SONIC_READ(SONIC_SR);
  314. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  315. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  316. lp->dma_bitmode = SONIC_BITMODE32;
  317. else {
  318. lp->dma_bitmode = SONIC_BITMODE16;
  319. lp->reg_offset = 0;
  320. sr = SONIC_READ(SONIC_SR);
  321. }
  322. } else {
  323. /* All onboard cards are at offset 2 with 32 bit DMA. */
  324. lp->reg_offset = 2;
  325. lp->dma_bitmode = SONIC_BITMODE32;
  326. sr = SONIC_READ(SONIC_SR);
  327. }
  328. printk(KERN_INFO
  329. "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  330. dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
  331. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  332. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  333. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  334. #endif
  335. /* Software reset, then initialize control registers. */
  336. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  337. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  338. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  339. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  340. /* This *must* be written back to in order to restore the
  341. * extended programmable output bits, as it may not have been
  342. * initialised since the hardware reset. */
  343. SONIC_WRITE(SONIC_DCR2, 0);
  344. /* Clear *and* disable interrupts to be on the safe side */
  345. SONIC_WRITE(SONIC_IMR, 0);
  346. SONIC_WRITE(SONIC_ISR, 0x7fff);
  347. /* Now look for the MAC address. */
  348. mac_onboard_sonic_ethernet_addr(dev);
  349. /* Shared init code */
  350. return macsonic_init(dev);
  351. }
  352. static int __devinit mac_nubus_sonic_ethernet_addr(struct net_device *dev,
  353. unsigned long prom_addr,
  354. int id)
  355. {
  356. int i;
  357. for(i = 0; i < 6; i++)
  358. dev->dev_addr[i] = SONIC_READ_PROM(i);
  359. /* Some of the addresses are bit-reversed */
  360. if (id != MACSONIC_DAYNA)
  361. bit_reverse_addr(dev->dev_addr);
  362. return 0;
  363. }
  364. static int __devinit macsonic_ident(struct nubus_dev *ndev)
  365. {
  366. if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  367. ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
  368. return MACSONIC_DAYNALINK;
  369. if (ndev->dr_hw == NUBUS_DRHW_SONIC &&
  370. ndev->dr_sw == NUBUS_DRSW_APPLE) {
  371. /* There has to be a better way to do this... */
  372. if (strstr(ndev->board->name, "DuoDock"))
  373. return MACSONIC_DUODOCK;
  374. else
  375. return MACSONIC_APPLE;
  376. }
  377. if (ndev->dr_hw == NUBUS_DRHW_SMC9194 &&
  378. ndev->dr_sw == NUBUS_DRSW_DAYNA)
  379. return MACSONIC_DAYNA;
  380. if (ndev->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
  381. ndev->dr_sw == 0) { /* huh? */
  382. return MACSONIC_APPLE16;
  383. }
  384. return -1;
  385. }
  386. static int __devinit mac_nubus_sonic_probe(struct net_device *dev)
  387. {
  388. static int slots;
  389. struct nubus_dev* ndev = NULL;
  390. struct sonic_local* lp = netdev_priv(dev);
  391. unsigned long base_addr, prom_addr;
  392. u16 sonic_dcr;
  393. int id = -1;
  394. int reg_offset, dma_bitmode;
  395. /* Find the first SONIC that hasn't been initialized already */
  396. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
  397. NUBUS_TYPE_ETHERNET, ndev)) != NULL)
  398. {
  399. /* Have we seen it already? */
  400. if (slots & (1<<ndev->board->slot))
  401. continue;
  402. slots |= 1<<ndev->board->slot;
  403. /* Is it one of ours? */
  404. if ((id = macsonic_ident(ndev)) != -1)
  405. break;
  406. }
  407. if (ndev == NULL)
  408. return -ENODEV;
  409. switch (id) {
  410. case MACSONIC_DUODOCK:
  411. base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
  412. prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  413. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  414. SONIC_DCR_TFT0;
  415. reg_offset = 2;
  416. dma_bitmode = SONIC_BITMODE32;
  417. break;
  418. case MACSONIC_APPLE:
  419. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  420. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  421. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  422. reg_offset = 0;
  423. dma_bitmode = SONIC_BITMODE32;
  424. break;
  425. case MACSONIC_APPLE16:
  426. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  427. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  428. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  429. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  430. reg_offset = 0;
  431. dma_bitmode = SONIC_BITMODE16;
  432. break;
  433. case MACSONIC_DAYNALINK:
  434. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  435. prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
  436. sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  437. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  438. reg_offset = 0;
  439. dma_bitmode = SONIC_BITMODE16;
  440. break;
  441. case MACSONIC_DAYNA:
  442. base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
  443. prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  444. sonic_dcr = SONIC_DCR_BMS |
  445. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  446. reg_offset = 0;
  447. dma_bitmode = SONIC_BITMODE16;
  448. break;
  449. default:
  450. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  451. return -ENODEV;
  452. }
  453. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  454. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  455. dev->base_addr = base_addr;
  456. lp->reg_offset = reg_offset;
  457. lp->dma_bitmode = dma_bitmode;
  458. dev->irq = SLOT2IRQ(ndev->board->slot);
  459. if (!sonic_version_printed) {
  460. printk(KERN_INFO "%s", version);
  461. sonic_version_printed = 1;
  462. }
  463. printk(KERN_INFO "%s: %s in slot %X\n",
  464. dev_name(lp->device), ndev->board->name, ndev->board->slot);
  465. printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  466. dev_name(lp->device), SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
  467. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  468. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  469. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  470. #endif
  471. /* Software reset, then initialize control registers. */
  472. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  473. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  474. /* This *must* be written back to in order to restore the
  475. * extended programmable output bits, since it may not have been
  476. * initialised since the hardware reset. */
  477. SONIC_WRITE(SONIC_DCR2, 0);
  478. /* Clear *and* disable interrupts to be on the safe side */
  479. SONIC_WRITE(SONIC_IMR, 0);
  480. SONIC_WRITE(SONIC_ISR, 0x7fff);
  481. /* Now look for the MAC address. */
  482. if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0)
  483. return -ENODEV;
  484. /* Shared init code */
  485. return macsonic_init(dev);
  486. }
  487. static int __devinit mac_sonic_probe(struct platform_device *pdev)
  488. {
  489. struct net_device *dev;
  490. struct sonic_local *lp;
  491. int err;
  492. dev = alloc_etherdev(sizeof(struct sonic_local));
  493. if (!dev)
  494. return -ENOMEM;
  495. lp = netdev_priv(dev);
  496. lp->device = &pdev->dev;
  497. SET_NETDEV_DEV(dev, &pdev->dev);
  498. platform_set_drvdata(pdev, dev);
  499. /* This will catch fatal stuff like -ENOMEM as well as success */
  500. err = mac_onboard_sonic_probe(dev);
  501. if (err == 0)
  502. goto found;
  503. if (err != -ENODEV)
  504. goto out;
  505. err = mac_nubus_sonic_probe(dev);
  506. if (err)
  507. goto out;
  508. found:
  509. err = register_netdev(dev);
  510. if (err)
  511. goto out;
  512. printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
  513. return 0;
  514. out:
  515. free_netdev(dev);
  516. return err;
  517. }
  518. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  519. module_param(sonic_debug, int, 0);
  520. MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
  521. MODULE_ALIAS("platform:macsonic");
  522. #include "sonic.c"
  523. static int __devexit mac_sonic_device_remove (struct platform_device *pdev)
  524. {
  525. struct net_device *dev = platform_get_drvdata(pdev);
  526. struct sonic_local* lp = netdev_priv(dev);
  527. unregister_netdev(dev);
  528. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  529. lp->descriptors, lp->descriptors_laddr);
  530. free_netdev(dev);
  531. return 0;
  532. }
  533. static struct platform_driver mac_sonic_driver = {
  534. .probe = mac_sonic_probe,
  535. .remove = __devexit_p(mac_sonic_device_remove),
  536. .driver = {
  537. .name = mac_sonic_string,
  538. .owner = THIS_MODULE,
  539. },
  540. };
  541. static int __init mac_sonic_init_module(void)
  542. {
  543. return platform_driver_register(&mac_sonic_driver);
  544. }
  545. static void __exit mac_sonic_cleanup_module(void)
  546. {
  547. platform_driver_unregister(&mac_sonic_driver);
  548. }
  549. module_init(mac_sonic_init_module);
  550. module_exit(mac_sonic_cleanup_module);