macsonic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 <asm/bootinfo.h>
  52. #include <asm/system.h>
  53. #include <asm/pgtable.h>
  54. #include <asm/io.h>
  55. #include <asm/hwtest.h>
  56. #include <asm/dma.h>
  57. #include <asm/macintosh.h>
  58. #include <asm/macints.h>
  59. #include <asm/mac_via.h>
  60. static char mac_sonic_string[] = "macsonic";
  61. static struct platform_device *mac_sonic_device;
  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. extern int mac_onboard_sonic_probe(struct net_device* dev);
  78. extern int mac_nubus_sonic_probe(struct net_device* dev);
  79. /* For onboard SONIC */
  80. #define ONBOARD_SONIC_REGISTERS 0x50F0A000
  81. #define ONBOARD_SONIC_PROM_BASE 0x50f08000
  82. enum macsonic_type {
  83. MACSONIC_DUODOCK,
  84. MACSONIC_APPLE,
  85. MACSONIC_APPLE16,
  86. MACSONIC_DAYNA,
  87. MACSONIC_DAYNALINK
  88. };
  89. /* For the built-in SONIC in the Duo Dock */
  90. #define DUODOCK_SONIC_REGISTERS 0xe10000
  91. #define DUODOCK_SONIC_PROM_BASE 0xe12000
  92. /* For Apple-style NuBus SONIC */
  93. #define APPLE_SONIC_REGISTERS 0
  94. #define APPLE_SONIC_PROM_BASE 0x40000
  95. /* Daynalink LC SONIC */
  96. #define DAYNALINK_PROM_BASE 0x400000
  97. /* For Dayna-style NuBus SONIC (haven't seen one yet) */
  98. #define DAYNA_SONIC_REGISTERS 0x180000
  99. /* This is what OpenBSD says. However, this is definitely in NuBus
  100. ROM space so we should be able to get it by walking the NuBus
  101. resource directories */
  102. #define DAYNA_SONIC_MAC_ADDR 0xffe004
  103. #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr)
  104. /*
  105. * For reversing the PROM address
  106. */
  107. static unsigned char nibbletab[] = {0, 8, 4, 12, 2, 10, 6, 14,
  108. 1, 9, 5, 13, 3, 11, 7, 15};
  109. static inline void bit_reverse_addr(unsigned char addr[6])
  110. {
  111. int i;
  112. for(i = 0; i < 6; i++)
  113. addr[i] = ((nibbletab[addr[i] & 0xf] << 4) |
  114. nibbletab[(addr[i] >> 4) &0xf]);
  115. }
  116. int __init macsonic_init(struct net_device* dev)
  117. {
  118. struct sonic_local* lp = netdev_priv(dev);
  119. /* Allocate the entire chunk of memory for the descriptors.
  120. Note that this cannot cross a 64K boundary. */
  121. if ((lp->descriptors = dma_alloc_coherent(lp->device,
  122. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  123. &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
  124. printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id);
  125. return -ENOMEM;
  126. }
  127. /* Now set up the pointers to point to the appropriate places */
  128. lp->cda = lp->descriptors;
  129. lp->tda = lp->cda + (SIZEOF_SONIC_CDA
  130. * SONIC_BUS_SCALE(lp->dma_bitmode));
  131. lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  132. * SONIC_BUS_SCALE(lp->dma_bitmode));
  133. lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  134. * SONIC_BUS_SCALE(lp->dma_bitmode));
  135. lp->cda_laddr = lp->descriptors_laddr;
  136. lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
  137. * SONIC_BUS_SCALE(lp->dma_bitmode));
  138. lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  139. * SONIC_BUS_SCALE(lp->dma_bitmode));
  140. lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  141. * SONIC_BUS_SCALE(lp->dma_bitmode));
  142. dev->open = sonic_open;
  143. dev->stop = sonic_close;
  144. dev->hard_start_xmit = sonic_send_packet;
  145. dev->get_stats = sonic_get_stats;
  146. dev->set_multicast_list = &sonic_multicast_list;
  147. dev->tx_timeout = sonic_tx_timeout;
  148. dev->watchdog_timeo = TX_TIMEOUT;
  149. /*
  150. * clear tally counter
  151. */
  152. SONIC_WRITE(SONIC_CRCT, 0xffff);
  153. SONIC_WRITE(SONIC_FAET, 0xffff);
  154. SONIC_WRITE(SONIC_MPT, 0xffff);
  155. return 0;
  156. }
  157. int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
  158. {
  159. struct sonic_local *lp = netdev_priv(dev);
  160. const int prom_addr = ONBOARD_SONIC_PROM_BASE;
  161. int i;
  162. /* On NuBus boards we can sometimes look in the ROM resources.
  163. No such luck for comm-slot/onboard. */
  164. for(i = 0; i < 6; i++)
  165. dev->dev_addr[i] = SONIC_READ_PROM(i);
  166. /* Most of the time, the address is bit-reversed. The NetBSD
  167. source has a rather long and detailed historical account of
  168. why this is so. */
  169. if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
  170. memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
  171. memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
  172. memcmp(dev->dev_addr, "\x00\x05\x02", 3))
  173. bit_reverse_addr(dev->dev_addr);
  174. else
  175. return 0;
  176. /* If we still have what seems to be a bogus address, we'll
  177. look in the CAM. The top entry should be ours. */
  178. /* Danger! This only works if MacOS has already initialized
  179. the card... */
  180. if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
  181. memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
  182. memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
  183. memcmp(dev->dev_addr, "\x00\x05\x02", 3))
  184. {
  185. unsigned short val;
  186. printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n");
  187. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  188. SONIC_WRITE(SONIC_CEP, 15);
  189. val = SONIC_READ(SONIC_CAP2);
  190. dev->dev_addr[5] = val >> 8;
  191. dev->dev_addr[4] = val & 0xff;
  192. val = SONIC_READ(SONIC_CAP1);
  193. dev->dev_addr[3] = val >> 8;
  194. dev->dev_addr[2] = val & 0xff;
  195. val = SONIC_READ(SONIC_CAP0);
  196. dev->dev_addr[1] = val >> 8;
  197. dev->dev_addr[0] = val & 0xff;
  198. printk(KERN_INFO "HW Address from CAM 15: ");
  199. for (i = 0; i < 6; i++) {
  200. printk("%2.2x", dev->dev_addr[i]);
  201. if (i < 5)
  202. printk(":");
  203. }
  204. printk("\n");
  205. } else return 0;
  206. if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
  207. memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
  208. memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
  209. memcmp(dev->dev_addr, "\x00\x05\x02", 3))
  210. {
  211. /*
  212. * Still nonsense ... messed up someplace!
  213. */
  214. printk(KERN_ERR "macsonic: ERROR (INVALID MAC)\n");
  215. return -EIO;
  216. } else return 0;
  217. }
  218. int __init mac_onboard_sonic_probe(struct net_device* dev)
  219. {
  220. /* Bwahahaha */
  221. static int once_is_more_than_enough;
  222. struct sonic_local* lp = netdev_priv(dev);
  223. int sr;
  224. int commslot = 0;
  225. if (once_is_more_than_enough)
  226. return -ENODEV;
  227. once_is_more_than_enough = 1;
  228. if (!MACH_IS_MAC)
  229. return -ENODEV;
  230. if (macintosh_config->ether_type != MAC_ETHER_SONIC)
  231. return -ENODEV;
  232. printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
  233. /* Bogus probing, on the models which may or may not have
  234. Ethernet (BTW, the Ethernet *is* always at the same
  235. address, and nothing else lives there, at least if Apple's
  236. documentation is to be believed) */
  237. if (macintosh_config->ident == MAC_MODEL_Q630 ||
  238. macintosh_config->ident == MAC_MODEL_P588 ||
  239. macintosh_config->ident == MAC_MODEL_P575 ||
  240. macintosh_config->ident == MAC_MODEL_C610) {
  241. unsigned long flags;
  242. int card_present;
  243. local_irq_save(flags);
  244. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  245. local_irq_restore(flags);
  246. if (!card_present) {
  247. printk("none.\n");
  248. return -ENODEV;
  249. }
  250. commslot = 1;
  251. }
  252. printk("yes\n");
  253. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  254. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  255. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  256. if (via_alt_mapping)
  257. dev->irq = IRQ_AUTO_3;
  258. else
  259. dev->irq = IRQ_NUBUS_9;
  260. if (!sonic_version_printed) {
  261. printk(KERN_INFO "%s", version);
  262. sonic_version_printed = 1;
  263. }
  264. printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
  265. lp->device->bus_id, dev->base_addr);
  266. /* The PowerBook's SONIC is 16 bit always. */
  267. if (macintosh_config->ident == MAC_MODEL_PB520) {
  268. lp->reg_offset = 0;
  269. lp->dma_bitmode = SONIC_BITMODE16;
  270. sr = SONIC_READ(SONIC_SR);
  271. } else if (commslot) {
  272. /* Some of the comm-slot cards are 16 bit. But some
  273. of them are not. The 32-bit cards use offset 2 and
  274. have known revisions, we try reading the revision
  275. register at offset 2, if we don't get a known revision
  276. we assume 16 bit at offset 0. */
  277. lp->reg_offset = 2;
  278. lp->dma_bitmode = SONIC_BITMODE16;
  279. sr = SONIC_READ(SONIC_SR);
  280. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  281. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  282. lp->dma_bitmode = SONIC_BITMODE32;
  283. else {
  284. lp->dma_bitmode = SONIC_BITMODE16;
  285. lp->reg_offset = 0;
  286. sr = SONIC_READ(SONIC_SR);
  287. }
  288. } else {
  289. /* All onboard cards are at offset 2 with 32 bit DMA. */
  290. lp->reg_offset = 2;
  291. lp->dma_bitmode = SONIC_BITMODE32;
  292. sr = SONIC_READ(SONIC_SR);
  293. }
  294. printk(KERN_INFO
  295. "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  296. lp->device->bus_id, sr, lp->dma_bitmode?32:16, lp->reg_offset);
  297. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  298. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id,
  299. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  300. #endif
  301. /* Software reset, then initialize control registers. */
  302. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  303. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  304. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  305. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  306. /* This *must* be written back to in order to restore the
  307. * extended programmable output bits, as it may not have been
  308. * initialised since the hardware reset. */
  309. SONIC_WRITE(SONIC_DCR2, 0);
  310. /* Clear *and* disable interrupts to be on the safe side */
  311. SONIC_WRITE(SONIC_IMR, 0);
  312. SONIC_WRITE(SONIC_ISR, 0x7fff);
  313. /* Now look for the MAC address. */
  314. if (mac_onboard_sonic_ethernet_addr(dev) != 0)
  315. return -ENODEV;
  316. /* Shared init code */
  317. return macsonic_init(dev);
  318. }
  319. int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev,
  320. unsigned long prom_addr,
  321. int id)
  322. {
  323. int i;
  324. for(i = 0; i < 6; i++)
  325. dev->dev_addr[i] = SONIC_READ_PROM(i);
  326. /* Some of the addresses are bit-reversed */
  327. if (id != MACSONIC_DAYNA)
  328. bit_reverse_addr(dev->dev_addr);
  329. return 0;
  330. }
  331. int __init macsonic_ident(struct nubus_dev* ndev)
  332. {
  333. if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  334. ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
  335. return MACSONIC_DAYNALINK;
  336. if (ndev->dr_hw == NUBUS_DRHW_SONIC &&
  337. ndev->dr_sw == NUBUS_DRSW_APPLE) {
  338. /* There has to be a better way to do this... */
  339. if (strstr(ndev->board->name, "DuoDock"))
  340. return MACSONIC_DUODOCK;
  341. else
  342. return MACSONIC_APPLE;
  343. }
  344. if (ndev->dr_hw == NUBUS_DRHW_SMC9194 &&
  345. ndev->dr_sw == NUBUS_DRSW_DAYNA)
  346. return MACSONIC_DAYNA;
  347. if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC &&
  348. ndev->dr_sw == 0) { /* huh? */
  349. return MACSONIC_APPLE16;
  350. }
  351. return -1;
  352. }
  353. int __init mac_nubus_sonic_probe(struct net_device* dev)
  354. {
  355. static int slots;
  356. struct nubus_dev* ndev = NULL;
  357. struct sonic_local* lp = netdev_priv(dev);
  358. unsigned long base_addr, prom_addr;
  359. u16 sonic_dcr;
  360. int id = -1;
  361. int reg_offset, dma_bitmode;
  362. /* Find the first SONIC that hasn't been initialized already */
  363. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
  364. NUBUS_TYPE_ETHERNET, ndev)) != NULL)
  365. {
  366. /* Have we seen it already? */
  367. if (slots & (1<<ndev->board->slot))
  368. continue;
  369. slots |= 1<<ndev->board->slot;
  370. /* Is it one of ours? */
  371. if ((id = macsonic_ident(ndev)) != -1)
  372. break;
  373. }
  374. if (ndev == NULL)
  375. return -ENODEV;
  376. switch (id) {
  377. case MACSONIC_DUODOCK:
  378. base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
  379. prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  380. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  381. SONIC_DCR_TFT0;
  382. reg_offset = 2;
  383. dma_bitmode = SONIC_BITMODE32;
  384. break;
  385. case MACSONIC_APPLE:
  386. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  387. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  388. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  389. reg_offset = 0;
  390. dma_bitmode = SONIC_BITMODE32;
  391. break;
  392. case MACSONIC_APPLE16:
  393. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  394. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  395. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  396. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  397. reg_offset = 0;
  398. dma_bitmode = SONIC_BITMODE16;
  399. break;
  400. case MACSONIC_DAYNALINK:
  401. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  402. prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
  403. sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  404. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  405. reg_offset = 0;
  406. dma_bitmode = SONIC_BITMODE16;
  407. break;
  408. case MACSONIC_DAYNA:
  409. base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
  410. prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  411. sonic_dcr = SONIC_DCR_BMS |
  412. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  413. reg_offset = 0;
  414. dma_bitmode = SONIC_BITMODE16;
  415. break;
  416. default:
  417. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  418. return -ENODEV;
  419. }
  420. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  421. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  422. dev->base_addr = base_addr;
  423. lp->reg_offset = reg_offset;
  424. lp->dma_bitmode = dma_bitmode;
  425. dev->irq = SLOT2IRQ(ndev->board->slot);
  426. if (!sonic_version_printed) {
  427. printk(KERN_INFO "%s", version);
  428. sonic_version_printed = 1;
  429. }
  430. printk(KERN_INFO "%s: %s in slot %X\n",
  431. lp->device->bus_id, ndev->board->name, ndev->board->slot);
  432. printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  433. lp->device->bus_id, SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
  434. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  435. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id,
  436. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  437. #endif
  438. /* Software reset, then initialize control registers. */
  439. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  440. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  441. /* This *must* be written back to in order to restore the
  442. * extended programmable output bits, since it may not have been
  443. * initialised since the hardware reset. */
  444. SONIC_WRITE(SONIC_DCR2, 0);
  445. /* Clear *and* disable interrupts to be on the safe side */
  446. SONIC_WRITE(SONIC_IMR, 0);
  447. SONIC_WRITE(SONIC_ISR, 0x7fff);
  448. /* Now look for the MAC address. */
  449. if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0)
  450. return -ENODEV;
  451. /* Shared init code */
  452. return macsonic_init(dev);
  453. }
  454. static int __init mac_sonic_probe(struct platform_device *device)
  455. {
  456. struct net_device *dev;
  457. struct sonic_local *lp;
  458. int err;
  459. int i;
  460. dev = alloc_etherdev(sizeof(struct sonic_local));
  461. if (!dev)
  462. return -ENOMEM;
  463. lp = netdev_priv(dev);
  464. lp->device = &device->dev;
  465. SET_NETDEV_DEV(dev, &device->dev);
  466. SET_MODULE_OWNER(dev);
  467. /* This will catch fatal stuff like -ENOMEM as well as success */
  468. err = mac_onboard_sonic_probe(dev);
  469. if (err == 0)
  470. goto found;
  471. if (err != -ENODEV)
  472. goto out;
  473. err = mac_nubus_sonic_probe(dev);
  474. if (err)
  475. goto out;
  476. found:
  477. err = register_netdev(dev);
  478. if (err)
  479. goto out;
  480. printk("%s: MAC ", dev->name);
  481. for (i = 0; i < 6; i++) {
  482. printk("%2.2x", dev->dev_addr[i]);
  483. if (i < 5)
  484. printk(":");
  485. }
  486. printk(" IRQ %d\n", dev->irq);
  487. return 0;
  488. out:
  489. free_netdev(dev);
  490. return err;
  491. }
  492. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  493. module_param(sonic_debug, int, 0);
  494. MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
  495. #define SONIC_IRQ_FLAG IRQ_FLG_FAST
  496. #include "sonic.c"
  497. static int __devexit mac_sonic_device_remove (struct platform_device *device)
  498. {
  499. struct net_device *dev = platform_get_drvdata(device);
  500. struct sonic_local* lp = netdev_priv(dev);
  501. unregister_netdev (dev);
  502. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  503. lp->descriptors, lp->descriptors_laddr);
  504. free_netdev (dev);
  505. return 0;
  506. }
  507. static struct platform_driver mac_sonic_driver = {
  508. .probe = mac_sonic_probe,
  509. .remove = __devexit_p(mac_sonic_device_remove),
  510. .driver = {
  511. .name = mac_sonic_string,
  512. },
  513. };
  514. static int __init mac_sonic_init_module(void)
  515. {
  516. int err;
  517. if ((err = platform_driver_register(&mac_sonic_driver))) {
  518. printk(KERN_ERR "Driver registration failed\n");
  519. return err;
  520. }
  521. mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
  522. if (!mac_sonic_device) {
  523. goto out_unregister;
  524. }
  525. if (platform_device_add(mac_sonic_device)) {
  526. platform_device_put(mac_sonic_device);
  527. mac_sonic_device = NULL;
  528. }
  529. return 0;
  530. out_unregister:
  531. platform_driver_unregister(&mac_sonic_driver);
  532. return -ENOMEM;
  533. }
  534. static void __exit mac_sonic_cleanup_module(void)
  535. {
  536. platform_driver_unregister(&mac_sonic_driver);
  537. if (mac_sonic_device) {
  538. platform_device_unregister(mac_sonic_device);
  539. mac_sonic_device = NULL;
  540. }
  541. }
  542. module_init(mac_sonic_init_module);
  543. module_exit(mac_sonic_cleanup_module);