macsonic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * macsonic.c
  4. *
  5. * (C) 2005 Finn Thain
  6. *
  7. * Converted to DMA API, converted to unified driver model, made it work as
  8. * a module again, and from the mac68k project, introduced more 32-bit cards
  9. * and dhd's support for 16-bit cards.
  10. *
  11. * (C) 1998 Alan Cox
  12. *
  13. * Debugging Andreas Ehliar, Michael Schmitz
  14. *
  15. * Based on code
  16. * (C) 1996 by Thomas Bogendoerfer ([email protected])
  17. *
  18. * This driver is based on work from Andreas Busse, but most of
  19. * the code is rewritten.
  20. *
  21. * (C) 1995 by Andreas Busse ([email protected])
  22. *
  23. * A driver for the Mac onboard Sonic ethernet chip.
  24. *
  25. * 98/12/21 MSch: judged from tests on Q800, it's basically working,
  26. * but eating up both receive and transmit resources
  27. * and duplicating packets. Needs more testing.
  28. *
  29. * 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed.
  30. *
  31. * 00/10/31 [email protected]: Updated driver for 2.4 kernels, fixed problems
  32. * on centris.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/types.h>
  37. #include <linux/fcntl.h>
  38. #include <linux/gfp.h>
  39. #include <linux/interrupt.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 <linux/pgtable.h>
  54. #include <asm/io.h>
  55. #include <asm/hwtest.h>
  56. #include <asm/dma.h>
  57. #include <asm/macintosh.h>
  58. #include <asm/macints.h>
  59. #include <asm/mac_via.h>
  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. /* For onboard SONIC */
  69. #define ONBOARD_SONIC_REGISTERS 0x50F0A000
  70. #define ONBOARD_SONIC_PROM_BASE 0x50f08000
  71. enum macsonic_type {
  72. MACSONIC_DUODOCK,
  73. MACSONIC_APPLE,
  74. MACSONIC_APPLE16,
  75. MACSONIC_DAYNA,
  76. MACSONIC_DAYNALINK
  77. };
  78. /* For the built-in SONIC in the Duo Dock */
  79. #define DUODOCK_SONIC_REGISTERS 0xe10000
  80. #define DUODOCK_SONIC_PROM_BASE 0xe12000
  81. /* For Apple-style NuBus SONIC */
  82. #define APPLE_SONIC_REGISTERS 0
  83. #define APPLE_SONIC_PROM_BASE 0x40000
  84. /* Daynalink LC SONIC */
  85. #define DAYNALINK_PROM_BASE 0x400000
  86. /* For Dayna-style NuBus SONIC (haven't seen one yet) */
  87. #define DAYNA_SONIC_REGISTERS 0x180000
  88. /* This is what OpenBSD says. However, this is definitely in NuBus
  89. ROM space so we should be able to get it by walking the NuBus
  90. resource directories */
  91. #define DAYNA_SONIC_MAC_ADDR 0xffe004
  92. #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr)
  93. /*
  94. * For reversing the PROM address
  95. */
  96. static inline void bit_reverse_addr(unsigned char addr[6])
  97. {
  98. int i;
  99. for(i = 0; i < 6; i++)
  100. addr[i] = bitrev8(addr[i]);
  101. }
  102. static int macsonic_open(struct net_device* dev)
  103. {
  104. int retval;
  105. retval = request_irq(dev->irq, sonic_interrupt, 0, "sonic", dev);
  106. if (retval) {
  107. printk(KERN_ERR "%s: unable to get IRQ %d.\n",
  108. dev->name, dev->irq);
  109. goto err;
  110. }
  111. /* Under the A/UX interrupt scheme, the onboard SONIC interrupt gets
  112. * moved from level 2 to level 3. Unfortunately we still get some
  113. * level 2 interrupts so register the handler for both.
  114. */
  115. if (dev->irq == IRQ_AUTO_3) {
  116. retval = request_irq(IRQ_NUBUS_9, sonic_interrupt, 0,
  117. "sonic", dev);
  118. if (retval) {
  119. printk(KERN_ERR "%s: unable to get IRQ %d.\n",
  120. dev->name, IRQ_NUBUS_9);
  121. goto err_irq;
  122. }
  123. }
  124. retval = sonic_open(dev);
  125. if (retval)
  126. goto err_irq_nubus;
  127. return 0;
  128. err_irq_nubus:
  129. if (dev->irq == IRQ_AUTO_3)
  130. free_irq(IRQ_NUBUS_9, dev);
  131. err_irq:
  132. free_irq(dev->irq, dev);
  133. err:
  134. return retval;
  135. }
  136. static int macsonic_close(struct net_device* dev)
  137. {
  138. int err;
  139. err = sonic_close(dev);
  140. free_irq(dev->irq, dev);
  141. if (dev->irq == IRQ_AUTO_3)
  142. free_irq(IRQ_NUBUS_9, dev);
  143. return err;
  144. }
  145. static const struct net_device_ops macsonic_netdev_ops = {
  146. .ndo_open = macsonic_open,
  147. .ndo_stop = macsonic_close,
  148. .ndo_start_xmit = sonic_send_packet,
  149. .ndo_set_rx_mode = sonic_multicast_list,
  150. .ndo_tx_timeout = sonic_tx_timeout,
  151. .ndo_get_stats = sonic_get_stats,
  152. .ndo_validate_addr = eth_validate_addr,
  153. .ndo_set_mac_address = eth_mac_addr,
  154. };
  155. static int macsonic_init(struct net_device *dev)
  156. {
  157. struct sonic_local* lp = netdev_priv(dev);
  158. int err = sonic_alloc_descriptors(dev);
  159. if (err)
  160. return err;
  161. dev->netdev_ops = &macsonic_netdev_ops;
  162. dev->watchdog_timeo = TX_TIMEOUT;
  163. /*
  164. * clear tally counter
  165. */
  166. SONIC_WRITE(SONIC_CRCT, 0xffff);
  167. SONIC_WRITE(SONIC_FAET, 0xffff);
  168. SONIC_WRITE(SONIC_MPT, 0xffff);
  169. return 0;
  170. }
  171. #define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
  172. memcmp(mac, "\x00\xA0\x40", 3) && \
  173. memcmp(mac, "\x00\x80\x19", 3) && \
  174. memcmp(mac, "\x00\x05\x02", 3))
  175. static void mac_onboard_sonic_ethernet_addr(struct net_device *dev)
  176. {
  177. struct sonic_local *lp = netdev_priv(dev);
  178. const int prom_addr = ONBOARD_SONIC_PROM_BASE;
  179. unsigned short val;
  180. u8 addr[ETH_ALEN];
  181. /*
  182. * On NuBus boards we can sometimes look in the ROM resources.
  183. * No such luck for comm-slot/onboard.
  184. * On the PowerBook 520, the PROM base address is a mystery.
  185. */
  186. if (hwreg_present((void *)prom_addr)) {
  187. int i;
  188. for (i = 0; i < 6; i++)
  189. addr[i] = SONIC_READ_PROM(i);
  190. eth_hw_addr_set(dev, addr);
  191. if (!INVALID_MAC(dev->dev_addr))
  192. return;
  193. /*
  194. * Most of the time, the address is bit-reversed. The NetBSD
  195. * source has a rather long and detailed historical account of
  196. * why this is so.
  197. */
  198. bit_reverse_addr(addr);
  199. eth_hw_addr_set(dev, addr);
  200. if (!INVALID_MAC(dev->dev_addr))
  201. return;
  202. /*
  203. * If we still have what seems to be a bogus address, we'll
  204. * look in the CAM. The top entry should be ours.
  205. */
  206. printk(KERN_WARNING "macsonic: MAC address in PROM seems "
  207. "to be invalid, trying CAM\n");
  208. } else {
  209. printk(KERN_WARNING "macsonic: cannot read MAC address from "
  210. "PROM, trying CAM\n");
  211. }
  212. /* This only works if MacOS has already initialized the card. */
  213. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  214. SONIC_WRITE(SONIC_CEP, 15);
  215. val = SONIC_READ(SONIC_CAP2);
  216. addr[5] = val >> 8;
  217. addr[4] = val & 0xff;
  218. val = SONIC_READ(SONIC_CAP1);
  219. addr[3] = val >> 8;
  220. addr[2] = val & 0xff;
  221. val = SONIC_READ(SONIC_CAP0);
  222. addr[1] = val >> 8;
  223. addr[0] = val & 0xff;
  224. eth_hw_addr_set(dev, addr);
  225. if (!INVALID_MAC(dev->dev_addr))
  226. return;
  227. /* Still nonsense ... messed up someplace! */
  228. printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
  229. "seems invalid, will use a random MAC\n");
  230. eth_hw_addr_random(dev);
  231. }
  232. static int mac_onboard_sonic_probe(struct net_device *dev)
  233. {
  234. struct sonic_local* lp = netdev_priv(dev);
  235. int sr;
  236. bool commslot = macintosh_config->expansion_type == MAC_EXP_PDS_COMM;
  237. /* Bogus probing, on the models which may or may not have
  238. Ethernet (BTW, the Ethernet *is* always at the same
  239. address, and nothing else lives there, at least if Apple's
  240. documentation is to be believed) */
  241. if (commslot || macintosh_config->ident == MAC_MODEL_C610) {
  242. int card_present;
  243. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  244. if (!card_present) {
  245. pr_info("Onboard/comm-slot SONIC not found\n");
  246. return -ENODEV;
  247. }
  248. }
  249. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  250. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  251. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  252. if (via_alt_mapping)
  253. dev->irq = IRQ_AUTO_3;
  254. else
  255. dev->irq = IRQ_NUBUS_9;
  256. /* The PowerBook's SONIC is 16 bit always. */
  257. if (macintosh_config->ident == MAC_MODEL_PB520) {
  258. lp->reg_offset = 0;
  259. lp->dma_bitmode = SONIC_BITMODE16;
  260. } else if (commslot) {
  261. /* Some of the comm-slot cards are 16 bit. But some
  262. of them are not. The 32-bit cards use offset 2 and
  263. have known revisions, we try reading the revision
  264. register at offset 2, if we don't get a known revision
  265. we assume 16 bit at offset 0. */
  266. lp->reg_offset = 2;
  267. lp->dma_bitmode = SONIC_BITMODE16;
  268. sr = SONIC_READ(SONIC_SR);
  269. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  270. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  271. lp->dma_bitmode = SONIC_BITMODE32;
  272. else {
  273. lp->dma_bitmode = SONIC_BITMODE16;
  274. lp->reg_offset = 0;
  275. }
  276. } else {
  277. /* All onboard cards are at offset 2 with 32 bit DMA. */
  278. lp->reg_offset = 2;
  279. lp->dma_bitmode = SONIC_BITMODE32;
  280. }
  281. pr_info("Onboard/comm-slot SONIC, revision 0x%04x, %d bit DMA, register offset %d\n",
  282. SONIC_READ(SONIC_SR), lp->dma_bitmode ? 32 : 16,
  283. lp->reg_offset);
  284. /* This is sometimes useful to find out how MacOS configured the card */
  285. pr_debug("%s: DCR=0x%04x, DCR2=0x%04x\n", __func__,
  286. SONIC_READ(SONIC_DCR) & 0xffff,
  287. SONIC_READ(SONIC_DCR2) & 0xffff);
  288. /* Software reset, then initialize control registers. */
  289. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  290. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  291. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  292. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  293. /* This *must* be written back to in order to restore the
  294. * extended programmable output bits, as it may not have been
  295. * initialised since the hardware reset. */
  296. SONIC_WRITE(SONIC_DCR2, 0);
  297. /* Clear *and* disable interrupts to be on the safe side */
  298. SONIC_WRITE(SONIC_IMR, 0);
  299. SONIC_WRITE(SONIC_ISR, 0x7fff);
  300. /* Now look for the MAC address. */
  301. mac_onboard_sonic_ethernet_addr(dev);
  302. pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
  303. dev->base_addr, dev->dev_addr, dev->irq);
  304. /* Shared init code */
  305. return macsonic_init(dev);
  306. }
  307. static int mac_sonic_nubus_ethernet_addr(struct net_device *dev,
  308. unsigned long prom_addr, int id)
  309. {
  310. u8 addr[ETH_ALEN];
  311. int i;
  312. for(i = 0; i < 6; i++)
  313. addr[i] = SONIC_READ_PROM(i);
  314. /* Some of the addresses are bit-reversed */
  315. if (id != MACSONIC_DAYNA)
  316. bit_reverse_addr(addr);
  317. eth_hw_addr_set(dev, addr);
  318. return 0;
  319. }
  320. static int macsonic_ident(struct nubus_rsrc *fres)
  321. {
  322. if (fres->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  323. fres->dr_sw == NUBUS_DRSW_SONIC_LC)
  324. return MACSONIC_DAYNALINK;
  325. if (fres->dr_hw == NUBUS_DRHW_SONIC &&
  326. fres->dr_sw == NUBUS_DRSW_APPLE) {
  327. /* There has to be a better way to do this... */
  328. if (strstr(fres->board->name, "DuoDock"))
  329. return MACSONIC_DUODOCK;
  330. else
  331. return MACSONIC_APPLE;
  332. }
  333. if (fres->dr_hw == NUBUS_DRHW_SMC9194 &&
  334. fres->dr_sw == NUBUS_DRSW_DAYNA)
  335. return MACSONIC_DAYNA;
  336. if (fres->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
  337. fres->dr_sw == 0) { /* huh? */
  338. return MACSONIC_APPLE16;
  339. }
  340. return -1;
  341. }
  342. static int mac_sonic_nubus_probe_board(struct nubus_board *board, int id,
  343. struct net_device *dev)
  344. {
  345. struct sonic_local* lp = netdev_priv(dev);
  346. unsigned long base_addr, prom_addr;
  347. u16 sonic_dcr;
  348. int reg_offset, dma_bitmode;
  349. switch (id) {
  350. case MACSONIC_DUODOCK:
  351. base_addr = board->slot_addr + DUODOCK_SONIC_REGISTERS;
  352. prom_addr = board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  353. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  354. SONIC_DCR_TFT0;
  355. reg_offset = 2;
  356. dma_bitmode = SONIC_BITMODE32;
  357. break;
  358. case MACSONIC_APPLE:
  359. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  360. prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
  361. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  362. reg_offset = 0;
  363. dma_bitmode = SONIC_BITMODE32;
  364. break;
  365. case MACSONIC_APPLE16:
  366. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  367. prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
  368. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  369. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  370. reg_offset = 0;
  371. dma_bitmode = SONIC_BITMODE16;
  372. break;
  373. case MACSONIC_DAYNALINK:
  374. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  375. prom_addr = board->slot_addr + DAYNALINK_PROM_BASE;
  376. sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  377. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  378. reg_offset = 0;
  379. dma_bitmode = SONIC_BITMODE16;
  380. break;
  381. case MACSONIC_DAYNA:
  382. base_addr = board->slot_addr + DAYNA_SONIC_REGISTERS;
  383. prom_addr = board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  384. sonic_dcr = SONIC_DCR_BMS |
  385. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  386. reg_offset = 0;
  387. dma_bitmode = SONIC_BITMODE16;
  388. break;
  389. default:
  390. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  391. return -ENODEV;
  392. }
  393. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  394. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  395. dev->base_addr = base_addr;
  396. lp->reg_offset = reg_offset;
  397. lp->dma_bitmode = dma_bitmode;
  398. dev->irq = SLOT2IRQ(board->slot);
  399. dev_info(&board->dev, "%s, revision 0x%04x, %d bit DMA, register offset %d\n",
  400. board->name, SONIC_READ(SONIC_SR),
  401. lp->dma_bitmode ? 32 : 16, lp->reg_offset);
  402. /* This is sometimes useful to find out how MacOS configured the card */
  403. dev_dbg(&board->dev, "%s: DCR=0x%04x, DCR2=0x%04x\n", __func__,
  404. SONIC_READ(SONIC_DCR) & 0xffff,
  405. SONIC_READ(SONIC_DCR2) & 0xffff);
  406. /* Software reset, then initialize control registers. */
  407. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  408. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  409. /* This *must* be written back to in order to restore the
  410. * extended programmable output bits, since it may not have been
  411. * initialised since the hardware reset. */
  412. SONIC_WRITE(SONIC_DCR2, 0);
  413. /* Clear *and* disable interrupts to be on the safe side */
  414. SONIC_WRITE(SONIC_IMR, 0);
  415. SONIC_WRITE(SONIC_ISR, 0x7fff);
  416. /* Now look for the MAC address. */
  417. if (mac_sonic_nubus_ethernet_addr(dev, prom_addr, id) != 0)
  418. return -ENODEV;
  419. dev_info(&board->dev, "SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
  420. dev->base_addr, dev->dev_addr, dev->irq);
  421. /* Shared init code */
  422. return macsonic_init(dev);
  423. }
  424. static int mac_sonic_platform_probe(struct platform_device *pdev)
  425. {
  426. struct net_device *dev;
  427. struct sonic_local *lp;
  428. int err;
  429. dev = alloc_etherdev(sizeof(struct sonic_local));
  430. if (!dev)
  431. return -ENOMEM;
  432. lp = netdev_priv(dev);
  433. lp->device = &pdev->dev;
  434. SET_NETDEV_DEV(dev, &pdev->dev);
  435. platform_set_drvdata(pdev, dev);
  436. err = mac_onboard_sonic_probe(dev);
  437. if (err)
  438. goto out;
  439. sonic_msg_init(dev);
  440. err = register_netdev(dev);
  441. if (err)
  442. goto undo_probe;
  443. return 0;
  444. undo_probe:
  445. dma_free_coherent(lp->device,
  446. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  447. lp->descriptors, lp->descriptors_laddr);
  448. out:
  449. free_netdev(dev);
  450. return err;
  451. }
  452. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  453. MODULE_ALIAS("platform:macsonic");
  454. #include "sonic.c"
  455. static int mac_sonic_platform_remove(struct platform_device *pdev)
  456. {
  457. struct net_device *dev = platform_get_drvdata(pdev);
  458. struct sonic_local* lp = netdev_priv(dev);
  459. unregister_netdev(dev);
  460. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  461. lp->descriptors, lp->descriptors_laddr);
  462. free_netdev(dev);
  463. return 0;
  464. }
  465. static struct platform_driver mac_sonic_platform_driver = {
  466. .probe = mac_sonic_platform_probe,
  467. .remove = mac_sonic_platform_remove,
  468. .driver = {
  469. .name = "macsonic",
  470. },
  471. };
  472. static int mac_sonic_nubus_probe(struct nubus_board *board)
  473. {
  474. struct net_device *ndev;
  475. struct sonic_local *lp;
  476. struct nubus_rsrc *fres;
  477. int id = -1;
  478. int err;
  479. /* The platform driver will handle a PDS or Comm Slot card (even if
  480. * it has a pseudoslot declaration ROM).
  481. */
  482. if (macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
  483. return -ENODEV;
  484. for_each_board_func_rsrc(board, fres) {
  485. if (fres->category != NUBUS_CAT_NETWORK ||
  486. fres->type != NUBUS_TYPE_ETHERNET)
  487. continue;
  488. id = macsonic_ident(fres);
  489. if (id != -1)
  490. break;
  491. }
  492. if (!fres)
  493. return -ENODEV;
  494. ndev = alloc_etherdev(sizeof(struct sonic_local));
  495. if (!ndev)
  496. return -ENOMEM;
  497. lp = netdev_priv(ndev);
  498. lp->device = &board->dev;
  499. SET_NETDEV_DEV(ndev, &board->dev);
  500. err = mac_sonic_nubus_probe_board(board, id, ndev);
  501. if (err)
  502. goto out;
  503. sonic_msg_init(ndev);
  504. err = register_netdev(ndev);
  505. if (err)
  506. goto undo_probe;
  507. nubus_set_drvdata(board, ndev);
  508. return 0;
  509. undo_probe:
  510. dma_free_coherent(lp->device,
  511. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  512. lp->descriptors, lp->descriptors_laddr);
  513. out:
  514. free_netdev(ndev);
  515. return err;
  516. }
  517. static void mac_sonic_nubus_remove(struct nubus_board *board)
  518. {
  519. struct net_device *ndev = nubus_get_drvdata(board);
  520. struct sonic_local *lp = netdev_priv(ndev);
  521. unregister_netdev(ndev);
  522. dma_free_coherent(lp->device,
  523. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  524. lp->descriptors, lp->descriptors_laddr);
  525. free_netdev(ndev);
  526. }
  527. static struct nubus_driver mac_sonic_nubus_driver = {
  528. .probe = mac_sonic_nubus_probe,
  529. .remove = mac_sonic_nubus_remove,
  530. .driver = {
  531. .name = "macsonic-nubus",
  532. .owner = THIS_MODULE,
  533. },
  534. };
  535. static int perr, nerr;
  536. static int __init mac_sonic_init(void)
  537. {
  538. perr = platform_driver_register(&mac_sonic_platform_driver);
  539. nerr = nubus_driver_register(&mac_sonic_nubus_driver);
  540. return 0;
  541. }
  542. module_init(mac_sonic_init);
  543. static void __exit mac_sonic_exit(void)
  544. {
  545. if (!perr)
  546. platform_driver_unregister(&mac_sonic_platform_driver);
  547. if (!nerr)
  548. nubus_driver_unregister(&mac_sonic_nubus_driver);
  549. }
  550. module_exit(mac_sonic_exit);