macsonic.c 18 KB

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