macsonic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * macsonic.c
  3. *
  4. * (C) 2005 Finn Thain
  5. *
  6. * Converted to DMA API, converted to unified driver model, made it work as
  7. * a module again, and from the mac68k project, introduced more 32-bit cards
  8. * and dhd's support for 16-bit cards.
  9. *
  10. * (C) 1998 Alan Cox
  11. *
  12. * Debugging Andreas Ehliar, Michael Schmitz
  13. *
  14. * Based on code
  15. * (C) 1996 by Thomas Bogendoerfer (tsbogend@bigbug.franken.de)
  16. *
  17. * This driver is based on work from Andreas Busse, but most of
  18. * the code is rewritten.
  19. *
  20. * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
  21. *
  22. * A driver for the Mac onboard Sonic ethernet chip.
  23. *
  24. * 98/12/21 MSch: judged from tests on Q800, it's basically working,
  25. * but eating up both receive and transmit resources
  26. * and duplicating packets. Needs more testing.
  27. *
  28. * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed.
  29. *
  30. * 00/10/31 sammy@oh.verio.com: Updated driver for 2.4 kernels, fixed problems
  31. * on centris.
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/types.h>
  36. #include <linux/fcntl.h>
  37. #include <linux/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_change_mtu = eth_change_mtu,
  170. .ndo_set_mac_address = eth_mac_addr,
  171. };
  172. static int macsonic_init(struct net_device *dev)
  173. {
  174. struct sonic_local* lp = netdev_priv(dev);
  175. /* Allocate the entire chunk of memory for the descriptors.
  176. Note that this cannot cross a 64K boundary. */
  177. lp->descriptors = dma_alloc_coherent(lp->device,
  178. SIZEOF_SONIC_DESC *
  179. SONIC_BUS_SCALE(lp->dma_bitmode),
  180. &lp->descriptors_laddr,
  181. GFP_KERNEL);
  182. if (lp->descriptors == NULL)
  183. return -ENOMEM;
  184. /* Now set up the pointers to point to the appropriate places */
  185. lp->cda = lp->descriptors;
  186. lp->tda = lp->cda + (SIZEOF_SONIC_CDA
  187. * SONIC_BUS_SCALE(lp->dma_bitmode));
  188. lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  189. * SONIC_BUS_SCALE(lp->dma_bitmode));
  190. lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  191. * SONIC_BUS_SCALE(lp->dma_bitmode));
  192. lp->cda_laddr = lp->descriptors_laddr;
  193. lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
  194. * SONIC_BUS_SCALE(lp->dma_bitmode));
  195. lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  196. * SONIC_BUS_SCALE(lp->dma_bitmode));
  197. lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  198. * SONIC_BUS_SCALE(lp->dma_bitmode));
  199. dev->netdev_ops = &macsonic_netdev_ops;
  200. dev->watchdog_timeo = TX_TIMEOUT;
  201. /*
  202. * clear tally counter
  203. */
  204. SONIC_WRITE(SONIC_CRCT, 0xffff);
  205. SONIC_WRITE(SONIC_FAET, 0xffff);
  206. SONIC_WRITE(SONIC_MPT, 0xffff);
  207. return 0;
  208. }
  209. #define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
  210. memcmp(mac, "\x00\xA0\x40", 3) && \
  211. memcmp(mac, "\x00\x80\x19", 3) && \
  212. memcmp(mac, "\x00\x05\x02", 3))
  213. static void mac_onboard_sonic_ethernet_addr(struct net_device *dev)
  214. {
  215. struct sonic_local *lp = netdev_priv(dev);
  216. const int prom_addr = ONBOARD_SONIC_PROM_BASE;
  217. unsigned short val;
  218. /*
  219. * On NuBus boards we can sometimes look in the ROM resources.
  220. * No such luck for comm-slot/onboard.
  221. * On the PowerBook 520, the PROM base address is a mystery.
  222. */
  223. if (hwreg_present((void *)prom_addr)) {
  224. int i;
  225. for (i = 0; i < 6; i++)
  226. dev->dev_addr[i] = SONIC_READ_PROM(i);
  227. if (!INVALID_MAC(dev->dev_addr))
  228. return;
  229. /*
  230. * Most of the time, the address is bit-reversed. The NetBSD
  231. * source has a rather long and detailed historical account of
  232. * why this is so.
  233. */
  234. bit_reverse_addr(dev->dev_addr);
  235. if (!INVALID_MAC(dev->dev_addr))
  236. return;
  237. /*
  238. * If we still have what seems to be a bogus address, we'll
  239. * look in the CAM. The top entry should be ours.
  240. */
  241. printk(KERN_WARNING "macsonic: MAC address in PROM seems "
  242. "to be invalid, trying CAM\n");
  243. } else {
  244. printk(KERN_WARNING "macsonic: cannot read MAC address from "
  245. "PROM, trying CAM\n");
  246. }
  247. /* This only works if MacOS has already initialized the card. */
  248. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  249. SONIC_WRITE(SONIC_CEP, 15);
  250. val = SONIC_READ(SONIC_CAP2);
  251. dev->dev_addr[5] = val >> 8;
  252. dev->dev_addr[4] = val & 0xff;
  253. val = SONIC_READ(SONIC_CAP1);
  254. dev->dev_addr[3] = val >> 8;
  255. dev->dev_addr[2] = val & 0xff;
  256. val = SONIC_READ(SONIC_CAP0);
  257. dev->dev_addr[1] = val >> 8;
  258. dev->dev_addr[0] = val & 0xff;
  259. if (!INVALID_MAC(dev->dev_addr))
  260. return;
  261. /* Still nonsense ... messed up someplace! */
  262. printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
  263. "seems invalid, will use a random MAC\n");
  264. eth_hw_addr_random(dev);
  265. }
  266. static int mac_onboard_sonic_probe(struct net_device *dev)
  267. {
  268. struct sonic_local* lp = netdev_priv(dev);
  269. int sr;
  270. int commslot = 0;
  271. if (!MACH_IS_MAC)
  272. return -ENODEV;
  273. printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. ");
  274. /* Bogus probing, on the models which may or may not have
  275. Ethernet (BTW, the Ethernet *is* always at the same
  276. address, and nothing else lives there, at least if Apple's
  277. documentation is to be believed) */
  278. if (macintosh_config->ident == MAC_MODEL_Q630 ||
  279. macintosh_config->ident == MAC_MODEL_P588 ||
  280. macintosh_config->ident == MAC_MODEL_P575 ||
  281. macintosh_config->ident == MAC_MODEL_C610) {
  282. int card_present;
  283. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  284. if (!card_present) {
  285. printk("none.\n");
  286. return -ENODEV;
  287. }
  288. commslot = 1;
  289. }
  290. printk("yes\n");
  291. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  292. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  293. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  294. if (via_alt_mapping)
  295. dev->irq = IRQ_AUTO_3;
  296. else
  297. dev->irq = IRQ_NUBUS_9;
  298. if (!sonic_version_printed) {
  299. printk(KERN_INFO "%s", version);
  300. sonic_version_printed = 1;
  301. }
  302. printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
  303. dev_name(lp->device), dev->base_addr);
  304. /* The PowerBook's SONIC is 16 bit always. */
  305. if (macintosh_config->ident == MAC_MODEL_PB520) {
  306. lp->reg_offset = 0;
  307. lp->dma_bitmode = SONIC_BITMODE16;
  308. sr = SONIC_READ(SONIC_SR);
  309. } else if (commslot) {
  310. /* Some of the comm-slot cards are 16 bit. But some
  311. of them are not. The 32-bit cards use offset 2 and
  312. have known revisions, we try reading the revision
  313. register at offset 2, if we don't get a known revision
  314. we assume 16 bit at offset 0. */
  315. lp->reg_offset = 2;
  316. lp->dma_bitmode = SONIC_BITMODE16;
  317. sr = SONIC_READ(SONIC_SR);
  318. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  319. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  320. lp->dma_bitmode = SONIC_BITMODE32;
  321. else {
  322. lp->dma_bitmode = SONIC_BITMODE16;
  323. lp->reg_offset = 0;
  324. sr = SONIC_READ(SONIC_SR);
  325. }
  326. } else {
  327. /* All onboard cards are at offset 2 with 32 bit DMA. */
  328. lp->reg_offset = 2;
  329. lp->dma_bitmode = SONIC_BITMODE32;
  330. sr = SONIC_READ(SONIC_SR);
  331. }
  332. printk(KERN_INFO
  333. "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  334. dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
  335. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  336. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  337. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  338. #endif
  339. /* Software reset, then initialize control registers. */
  340. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  341. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  342. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  343. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  344. /* This *must* be written back to in order to restore the
  345. * extended programmable output bits, as it may not have been
  346. * initialised since the hardware reset. */
  347. SONIC_WRITE(SONIC_DCR2, 0);
  348. /* Clear *and* disable interrupts to be on the safe side */
  349. SONIC_WRITE(SONIC_IMR, 0);
  350. SONIC_WRITE(SONIC_ISR, 0x7fff);
  351. /* Now look for the MAC address. */
  352. mac_onboard_sonic_ethernet_addr(dev);
  353. /* Shared init code */
  354. return macsonic_init(dev);
  355. }
  356. static int mac_nubus_sonic_ethernet_addr(struct net_device *dev,
  357. unsigned long prom_addr, int id)
  358. {
  359. int i;
  360. for(i = 0; i < 6; i++)
  361. dev->dev_addr[i] = SONIC_READ_PROM(i);
  362. /* Some of the addresses are bit-reversed */
  363. if (id != MACSONIC_DAYNA)
  364. bit_reverse_addr(dev->dev_addr);
  365. return 0;
  366. }
  367. static int macsonic_ident(struct nubus_dev *ndev)
  368. {
  369. if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  370. ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
  371. return MACSONIC_DAYNALINK;
  372. if (ndev->dr_hw == NUBUS_DRHW_SONIC &&
  373. ndev->dr_sw == NUBUS_DRSW_APPLE) {
  374. /* There has to be a better way to do this... */
  375. if (strstr(ndev->board->name, "DuoDock"))
  376. return MACSONIC_DUODOCK;
  377. else
  378. return MACSONIC_APPLE;
  379. }
  380. if (ndev->dr_hw == NUBUS_DRHW_SMC9194 &&
  381. ndev->dr_sw == NUBUS_DRSW_DAYNA)
  382. return MACSONIC_DAYNA;
  383. if (ndev->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
  384. ndev->dr_sw == 0) { /* huh? */
  385. return MACSONIC_APPLE16;
  386. }
  387. return -1;
  388. }
  389. static int mac_nubus_sonic_probe(struct net_device *dev)
  390. {
  391. static int slots;
  392. struct nubus_dev* ndev = NULL;
  393. struct sonic_local* lp = netdev_priv(dev);
  394. unsigned long base_addr, prom_addr;
  395. u16 sonic_dcr;
  396. int id = -1;
  397. int reg_offset, dma_bitmode;
  398. /* Find the first SONIC that hasn't been initialized already */
  399. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
  400. NUBUS_TYPE_ETHERNET, ndev)) != NULL)
  401. {
  402. /* Have we seen it already? */
  403. if (slots & (1<<ndev->board->slot))
  404. continue;
  405. slots |= 1<<ndev->board->slot;
  406. /* Is it one of ours? */
  407. if ((id = macsonic_ident(ndev)) != -1)
  408. break;
  409. }
  410. if (ndev == NULL)
  411. return -ENODEV;
  412. switch (id) {
  413. case MACSONIC_DUODOCK:
  414. base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
  415. prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  416. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  417. SONIC_DCR_TFT0;
  418. reg_offset = 2;
  419. dma_bitmode = SONIC_BITMODE32;
  420. break;
  421. case MACSONIC_APPLE:
  422. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  423. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  424. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  425. reg_offset = 0;
  426. dma_bitmode = SONIC_BITMODE32;
  427. break;
  428. case MACSONIC_APPLE16:
  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_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  432. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  433. reg_offset = 0;
  434. dma_bitmode = SONIC_BITMODE16;
  435. break;
  436. case MACSONIC_DAYNALINK:
  437. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  438. prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
  439. sonic_dcr = 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_DAYNA:
  445. base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
  446. prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  447. sonic_dcr = SONIC_DCR_BMS |
  448. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  449. reg_offset = 0;
  450. dma_bitmode = SONIC_BITMODE16;
  451. break;
  452. default:
  453. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  454. return -ENODEV;
  455. }
  456. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  457. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  458. dev->base_addr = base_addr;
  459. lp->reg_offset = reg_offset;
  460. lp->dma_bitmode = dma_bitmode;
  461. dev->irq = SLOT2IRQ(ndev->board->slot);
  462. if (!sonic_version_printed) {
  463. printk(KERN_INFO "%s", version);
  464. sonic_version_printed = 1;
  465. }
  466. printk(KERN_INFO "%s: %s in slot %X\n",
  467. dev_name(lp->device), ndev->board->name, ndev->board->slot);
  468. printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  469. dev_name(lp->device), SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
  470. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  471. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  472. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  473. #endif
  474. /* Software reset, then initialize control registers. */
  475. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  476. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  477. /* This *must* be written back to in order to restore the
  478. * extended programmable output bits, since it may not have been
  479. * initialised since the hardware reset. */
  480. SONIC_WRITE(SONIC_DCR2, 0);
  481. /* Clear *and* disable interrupts to be on the safe side */
  482. SONIC_WRITE(SONIC_IMR, 0);
  483. SONIC_WRITE(SONIC_ISR, 0x7fff);
  484. /* Now look for the MAC address. */
  485. if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0)
  486. return -ENODEV;
  487. /* Shared init code */
  488. return macsonic_init(dev);
  489. }
  490. static int mac_sonic_probe(struct platform_device *pdev)
  491. {
  492. struct net_device *dev;
  493. struct sonic_local *lp;
  494. int err;
  495. dev = alloc_etherdev(sizeof(struct sonic_local));
  496. if (!dev)
  497. return -ENOMEM;
  498. lp = netdev_priv(dev);
  499. lp->device = &pdev->dev;
  500. SET_NETDEV_DEV(dev, &pdev->dev);
  501. platform_set_drvdata(pdev, dev);
  502. /* This will catch fatal stuff like -ENOMEM as well as success */
  503. err = mac_onboard_sonic_probe(dev);
  504. if (err == 0)
  505. goto found;
  506. if (err != -ENODEV)
  507. goto out;
  508. err = mac_nubus_sonic_probe(dev);
  509. if (err)
  510. goto out;
  511. found:
  512. err = register_netdev(dev);
  513. if (err)
  514. goto out;
  515. printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
  516. return 0;
  517. out:
  518. free_netdev(dev);
  519. return err;
  520. }
  521. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  522. module_param(sonic_debug, int, 0);
  523. MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
  524. MODULE_ALIAS("platform:macsonic");
  525. #include "sonic.c"
  526. static int mac_sonic_device_remove(struct platform_device *pdev)
  527. {
  528. struct net_device *dev = platform_get_drvdata(pdev);
  529. struct sonic_local* lp = netdev_priv(dev);
  530. unregister_netdev(dev);
  531. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  532. lp->descriptors, lp->descriptors_laddr);
  533. free_netdev(dev);
  534. return 0;
  535. }
  536. static struct platform_driver mac_sonic_driver = {
  537. .probe = mac_sonic_probe,
  538. .remove = mac_sonic_device_remove,
  539. .driver = {
  540. .name = mac_sonic_string,
  541. },
  542. };
  543. module_platform_driver(mac_sonic_driver);