macsonic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. unsigned long flags;
  283. int card_present;
  284. local_irq_save(flags);
  285. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  286. local_irq_restore(flags);
  287. if (!card_present) {
  288. printk("none.\n");
  289. return -ENODEV;
  290. }
  291. commslot = 1;
  292. }
  293. printk("yes\n");
  294. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  295. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  296. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  297. if (via_alt_mapping)
  298. dev->irq = IRQ_AUTO_3;
  299. else
  300. dev->irq = IRQ_NUBUS_9;
  301. if (!sonic_version_printed) {
  302. printk(KERN_INFO "%s", version);
  303. sonic_version_printed = 1;
  304. }
  305. printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
  306. dev_name(lp->device), dev->base_addr);
  307. /* The PowerBook's SONIC is 16 bit always. */
  308. if (macintosh_config->ident == MAC_MODEL_PB520) {
  309. lp->reg_offset = 0;
  310. lp->dma_bitmode = SONIC_BITMODE16;
  311. sr = SONIC_READ(SONIC_SR);
  312. } else if (commslot) {
  313. /* Some of the comm-slot cards are 16 bit. But some
  314. of them are not. The 32-bit cards use offset 2 and
  315. have known revisions, we try reading the revision
  316. register at offset 2, if we don't get a known revision
  317. we assume 16 bit at offset 0. */
  318. lp->reg_offset = 2;
  319. lp->dma_bitmode = SONIC_BITMODE16;
  320. sr = SONIC_READ(SONIC_SR);
  321. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  322. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  323. lp->dma_bitmode = SONIC_BITMODE32;
  324. else {
  325. lp->dma_bitmode = SONIC_BITMODE16;
  326. lp->reg_offset = 0;
  327. sr = SONIC_READ(SONIC_SR);
  328. }
  329. } else {
  330. /* All onboard cards are at offset 2 with 32 bit DMA. */
  331. lp->reg_offset = 2;
  332. lp->dma_bitmode = SONIC_BITMODE32;
  333. sr = SONIC_READ(SONIC_SR);
  334. }
  335. printk(KERN_INFO
  336. "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  337. dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
  338. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  339. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  340. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  341. #endif
  342. /* Software reset, then initialize control registers. */
  343. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  344. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  345. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  346. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  347. /* This *must* be written back to in order to restore the
  348. * extended programmable output bits, as it may not have been
  349. * initialised since the hardware reset. */
  350. SONIC_WRITE(SONIC_DCR2, 0);
  351. /* Clear *and* disable interrupts to be on the safe side */
  352. SONIC_WRITE(SONIC_IMR, 0);
  353. SONIC_WRITE(SONIC_ISR, 0x7fff);
  354. /* Now look for the MAC address. */
  355. mac_onboard_sonic_ethernet_addr(dev);
  356. /* Shared init code */
  357. return macsonic_init(dev);
  358. }
  359. static int mac_nubus_sonic_ethernet_addr(struct net_device *dev,
  360. unsigned long prom_addr, int id)
  361. {
  362. int i;
  363. for(i = 0; i < 6; i++)
  364. dev->dev_addr[i] = SONIC_READ_PROM(i);
  365. /* Some of the addresses are bit-reversed */
  366. if (id != MACSONIC_DAYNA)
  367. bit_reverse_addr(dev->dev_addr);
  368. return 0;
  369. }
  370. static int macsonic_ident(struct nubus_dev *ndev)
  371. {
  372. if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  373. ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
  374. return MACSONIC_DAYNALINK;
  375. if (ndev->dr_hw == NUBUS_DRHW_SONIC &&
  376. ndev->dr_sw == NUBUS_DRSW_APPLE) {
  377. /* There has to be a better way to do this... */
  378. if (strstr(ndev->board->name, "DuoDock"))
  379. return MACSONIC_DUODOCK;
  380. else
  381. return MACSONIC_APPLE;
  382. }
  383. if (ndev->dr_hw == NUBUS_DRHW_SMC9194 &&
  384. ndev->dr_sw == NUBUS_DRSW_DAYNA)
  385. return MACSONIC_DAYNA;
  386. if (ndev->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
  387. ndev->dr_sw == 0) { /* huh? */
  388. return MACSONIC_APPLE16;
  389. }
  390. return -1;
  391. }
  392. static int mac_nubus_sonic_probe(struct net_device *dev)
  393. {
  394. static int slots;
  395. struct nubus_dev* ndev = NULL;
  396. struct sonic_local* lp = netdev_priv(dev);
  397. unsigned long base_addr, prom_addr;
  398. u16 sonic_dcr;
  399. int id = -1;
  400. int reg_offset, dma_bitmode;
  401. /* Find the first SONIC that hasn't been initialized already */
  402. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
  403. NUBUS_TYPE_ETHERNET, ndev)) != NULL)
  404. {
  405. /* Have we seen it already? */
  406. if (slots & (1<<ndev->board->slot))
  407. continue;
  408. slots |= 1<<ndev->board->slot;
  409. /* Is it one of ours? */
  410. if ((id = macsonic_ident(ndev)) != -1)
  411. break;
  412. }
  413. if (ndev == NULL)
  414. return -ENODEV;
  415. switch (id) {
  416. case MACSONIC_DUODOCK:
  417. base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS;
  418. prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  419. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  420. SONIC_DCR_TFT0;
  421. reg_offset = 2;
  422. dma_bitmode = SONIC_BITMODE32;
  423. break;
  424. case MACSONIC_APPLE:
  425. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  426. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  427. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  428. reg_offset = 0;
  429. dma_bitmode = SONIC_BITMODE32;
  430. break;
  431. case MACSONIC_APPLE16:
  432. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  433. prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE;
  434. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  435. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  436. reg_offset = 0;
  437. dma_bitmode = SONIC_BITMODE16;
  438. break;
  439. case MACSONIC_DAYNALINK:
  440. base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS;
  441. prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE;
  442. sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  443. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  444. reg_offset = 0;
  445. dma_bitmode = SONIC_BITMODE16;
  446. break;
  447. case MACSONIC_DAYNA:
  448. base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS;
  449. prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  450. sonic_dcr = SONIC_DCR_BMS |
  451. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  452. reg_offset = 0;
  453. dma_bitmode = SONIC_BITMODE16;
  454. break;
  455. default:
  456. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  457. return -ENODEV;
  458. }
  459. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  460. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  461. dev->base_addr = base_addr;
  462. lp->reg_offset = reg_offset;
  463. lp->dma_bitmode = dma_bitmode;
  464. dev->irq = SLOT2IRQ(ndev->board->slot);
  465. if (!sonic_version_printed) {
  466. printk(KERN_INFO "%s", version);
  467. sonic_version_printed = 1;
  468. }
  469. printk(KERN_INFO "%s: %s in slot %X\n",
  470. dev_name(lp->device), ndev->board->name, ndev->board->slot);
  471. printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
  472. dev_name(lp->device), SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
  473. #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
  474. printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
  475. SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
  476. #endif
  477. /* Software reset, then initialize control registers. */
  478. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  479. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  480. /* This *must* be written back to in order to restore the
  481. * extended programmable output bits, since it may not have been
  482. * initialised since the hardware reset. */
  483. SONIC_WRITE(SONIC_DCR2, 0);
  484. /* Clear *and* disable interrupts to be on the safe side */
  485. SONIC_WRITE(SONIC_IMR, 0);
  486. SONIC_WRITE(SONIC_ISR, 0x7fff);
  487. /* Now look for the MAC address. */
  488. if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0)
  489. return -ENODEV;
  490. /* Shared init code */
  491. return macsonic_init(dev);
  492. }
  493. static int mac_sonic_probe(struct platform_device *pdev)
  494. {
  495. struct net_device *dev;
  496. struct sonic_local *lp;
  497. int err;
  498. dev = alloc_etherdev(sizeof(struct sonic_local));
  499. if (!dev)
  500. return -ENOMEM;
  501. lp = netdev_priv(dev);
  502. lp->device = &pdev->dev;
  503. SET_NETDEV_DEV(dev, &pdev->dev);
  504. platform_set_drvdata(pdev, dev);
  505. /* This will catch fatal stuff like -ENOMEM as well as success */
  506. err = mac_onboard_sonic_probe(dev);
  507. if (err == 0)
  508. goto found;
  509. if (err != -ENODEV)
  510. goto out;
  511. err = mac_nubus_sonic_probe(dev);
  512. if (err)
  513. goto out;
  514. found:
  515. err = register_netdev(dev);
  516. if (err)
  517. goto out;
  518. printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
  519. return 0;
  520. out:
  521. free_netdev(dev);
  522. return err;
  523. }
  524. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  525. module_param(sonic_debug, int, 0);
  526. MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
  527. MODULE_ALIAS("platform:macsonic");
  528. #include "sonic.c"
  529. static int mac_sonic_device_remove(struct platform_device *pdev)
  530. {
  531. struct net_device *dev = platform_get_drvdata(pdev);
  532. struct sonic_local* lp = netdev_priv(dev);
  533. unregister_netdev(dev);
  534. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  535. lp->descriptors, lp->descriptors_laddr);
  536. free_netdev(dev);
  537. return 0;
  538. }
  539. static struct platform_driver mac_sonic_driver = {
  540. .probe = mac_sonic_probe,
  541. .remove = mac_sonic_device_remove,
  542. .driver = {
  543. .name = mac_sonic_string,
  544. .owner = THIS_MODULE,
  545. },
  546. };
  547. module_platform_driver(mac_sonic_driver);