macsonic.c 18 KB

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