macsonic.c 18 KB

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