macsonic.c 19 KB

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