macsonic.c 18 KB

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