macsonic.c 18 KB

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