macsonic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 (tsbogend@bigbug.franken.de)
  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 (andy@waldorf-gmbh.de)
  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 sammy@oh.verio.com: 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 <asm/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 irqreturn_t macsonic_interrupt(int irq, void *dev_id)
  103. {
  104. irqreturn_t result;
  105. unsigned long flags;
  106. local_irq_save(flags);
  107. result = sonic_interrupt(irq, dev_id);
  108. local_irq_restore(flags);
  109. return result;
  110. }
  111. static int macsonic_open(struct net_device* dev)
  112. {
  113. int retval;
  114. retval = request_irq(dev->irq, sonic_interrupt, 0, "sonic", dev);
  115. if (retval) {
  116. printk(KERN_ERR "%s: unable to get IRQ %d.\n",
  117. dev->name, dev->irq);
  118. goto err;
  119. }
  120. /* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes
  121. * in at priority level 3. However, we sometimes get the level 2 inter-
  122. * rupt as well, which must prevent re-entrance of the sonic handler.
  123. */
  124. if (dev->irq == IRQ_AUTO_3) {
  125. retval = request_irq(IRQ_NUBUS_9, macsonic_interrupt, 0,
  126. "sonic", dev);
  127. if (retval) {
  128. printk(KERN_ERR "%s: unable to get IRQ %d.\n",
  129. dev->name, IRQ_NUBUS_9);
  130. goto err_irq;
  131. }
  132. }
  133. retval = sonic_open(dev);
  134. if (retval)
  135. goto err_irq_nubus;
  136. return 0;
  137. err_irq_nubus:
  138. if (dev->irq == IRQ_AUTO_3)
  139. free_irq(IRQ_NUBUS_9, dev);
  140. err_irq:
  141. free_irq(dev->irq, dev);
  142. err:
  143. return retval;
  144. }
  145. static int macsonic_close(struct net_device* dev)
  146. {
  147. int err;
  148. err = sonic_close(dev);
  149. free_irq(dev->irq, dev);
  150. if (dev->irq == IRQ_AUTO_3)
  151. free_irq(IRQ_NUBUS_9, dev);
  152. return err;
  153. }
  154. static const struct net_device_ops macsonic_netdev_ops = {
  155. .ndo_open = macsonic_open,
  156. .ndo_stop = macsonic_close,
  157. .ndo_start_xmit = sonic_send_packet,
  158. .ndo_set_rx_mode = sonic_multicast_list,
  159. .ndo_tx_timeout = sonic_tx_timeout,
  160. .ndo_get_stats = sonic_get_stats,
  161. .ndo_validate_addr = eth_validate_addr,
  162. .ndo_set_mac_address = eth_mac_addr,
  163. };
  164. static int macsonic_init(struct net_device *dev)
  165. {
  166. struct sonic_local* lp = netdev_priv(dev);
  167. /* Allocate the entire chunk of memory for the descriptors.
  168. Note that this cannot cross a 64K boundary. */
  169. lp->descriptors = dma_alloc_coherent(lp->device,
  170. SIZEOF_SONIC_DESC *
  171. SONIC_BUS_SCALE(lp->dma_bitmode),
  172. &lp->descriptors_laddr,
  173. GFP_KERNEL);
  174. if (lp->descriptors == NULL)
  175. return -ENOMEM;
  176. /* Now set up the pointers to point to the appropriate places */
  177. lp->cda = lp->descriptors;
  178. lp->tda = lp->cda + (SIZEOF_SONIC_CDA
  179. * SONIC_BUS_SCALE(lp->dma_bitmode));
  180. lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  181. * SONIC_BUS_SCALE(lp->dma_bitmode));
  182. lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  183. * SONIC_BUS_SCALE(lp->dma_bitmode));
  184. lp->cda_laddr = lp->descriptors_laddr;
  185. lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
  186. * SONIC_BUS_SCALE(lp->dma_bitmode));
  187. lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  188. * SONIC_BUS_SCALE(lp->dma_bitmode));
  189. lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  190. * SONIC_BUS_SCALE(lp->dma_bitmode));
  191. dev->netdev_ops = &macsonic_netdev_ops;
  192. dev->watchdog_timeo = TX_TIMEOUT;
  193. /*
  194. * clear tally counter
  195. */
  196. SONIC_WRITE(SONIC_CRCT, 0xffff);
  197. SONIC_WRITE(SONIC_FAET, 0xffff);
  198. SONIC_WRITE(SONIC_MPT, 0xffff);
  199. return 0;
  200. }
  201. #define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
  202. memcmp(mac, "\x00\xA0\x40", 3) && \
  203. memcmp(mac, "\x00\x80\x19", 3) && \
  204. memcmp(mac, "\x00\x05\x02", 3))
  205. static void mac_onboard_sonic_ethernet_addr(struct net_device *dev)
  206. {
  207. struct sonic_local *lp = netdev_priv(dev);
  208. const int prom_addr = ONBOARD_SONIC_PROM_BASE;
  209. unsigned short val;
  210. /*
  211. * On NuBus boards we can sometimes look in the ROM resources.
  212. * No such luck for comm-slot/onboard.
  213. * On the PowerBook 520, the PROM base address is a mystery.
  214. */
  215. if (hwreg_present((void *)prom_addr)) {
  216. int i;
  217. for (i = 0; i < 6; i++)
  218. dev->dev_addr[i] = SONIC_READ_PROM(i);
  219. if (!INVALID_MAC(dev->dev_addr))
  220. return;
  221. /*
  222. * Most of the time, the address is bit-reversed. The NetBSD
  223. * source has a rather long and detailed historical account of
  224. * why this is so.
  225. */
  226. bit_reverse_addr(dev->dev_addr);
  227. if (!INVALID_MAC(dev->dev_addr))
  228. return;
  229. /*
  230. * If we still have what seems to be a bogus address, we'll
  231. * look in the CAM. The top entry should be ours.
  232. */
  233. printk(KERN_WARNING "macsonic: MAC address in PROM seems "
  234. "to be invalid, trying CAM\n");
  235. } else {
  236. printk(KERN_WARNING "macsonic: cannot read MAC address from "
  237. "PROM, trying CAM\n");
  238. }
  239. /* This only works if MacOS has already initialized the card. */
  240. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  241. SONIC_WRITE(SONIC_CEP, 15);
  242. val = SONIC_READ(SONIC_CAP2);
  243. dev->dev_addr[5] = val >> 8;
  244. dev->dev_addr[4] = val & 0xff;
  245. val = SONIC_READ(SONIC_CAP1);
  246. dev->dev_addr[3] = val >> 8;
  247. dev->dev_addr[2] = val & 0xff;
  248. val = SONIC_READ(SONIC_CAP0);
  249. dev->dev_addr[1] = val >> 8;
  250. dev->dev_addr[0] = val & 0xff;
  251. if (!INVALID_MAC(dev->dev_addr))
  252. return;
  253. /* Still nonsense ... messed up someplace! */
  254. printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
  255. "seems invalid, will use a random MAC\n");
  256. eth_hw_addr_random(dev);
  257. }
  258. static int mac_onboard_sonic_probe(struct net_device *dev)
  259. {
  260. struct sonic_local* lp = netdev_priv(dev);
  261. int sr;
  262. bool commslot = macintosh_config->expansion_type == MAC_EXP_PDS_COMM;
  263. /* Bogus probing, on the models which may or may not have
  264. Ethernet (BTW, the Ethernet *is* always at the same
  265. address, and nothing else lives there, at least if Apple's
  266. documentation is to be believed) */
  267. if (commslot || macintosh_config->ident == MAC_MODEL_C610) {
  268. int card_present;
  269. card_present = hwreg_present((void*)ONBOARD_SONIC_REGISTERS);
  270. if (!card_present) {
  271. pr_info("Onboard/comm-slot SONIC not found\n");
  272. return -ENODEV;
  273. }
  274. }
  275. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  276. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  277. dev->base_addr = ONBOARD_SONIC_REGISTERS;
  278. if (via_alt_mapping)
  279. dev->irq = IRQ_AUTO_3;
  280. else
  281. dev->irq = IRQ_NUBUS_9;
  282. /* The PowerBook's SONIC is 16 bit always. */
  283. if (macintosh_config->ident == MAC_MODEL_PB520) {
  284. lp->reg_offset = 0;
  285. lp->dma_bitmode = SONIC_BITMODE16;
  286. } else if (commslot) {
  287. /* Some of the comm-slot cards are 16 bit. But some
  288. of them are not. The 32-bit cards use offset 2 and
  289. have known revisions, we try reading the revision
  290. register at offset 2, if we don't get a known revision
  291. we assume 16 bit at offset 0. */
  292. lp->reg_offset = 2;
  293. lp->dma_bitmode = SONIC_BITMODE16;
  294. sr = SONIC_READ(SONIC_SR);
  295. if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101)
  296. /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */
  297. lp->dma_bitmode = SONIC_BITMODE32;
  298. else {
  299. lp->dma_bitmode = SONIC_BITMODE16;
  300. lp->reg_offset = 0;
  301. }
  302. } else {
  303. /* All onboard cards are at offset 2 with 32 bit DMA. */
  304. lp->reg_offset = 2;
  305. lp->dma_bitmode = SONIC_BITMODE32;
  306. }
  307. pr_info("Onboard/comm-slot SONIC, revision 0x%04x, %d bit DMA, register offset %d\n",
  308. SONIC_READ(SONIC_SR), lp->dma_bitmode ? 32 : 16,
  309. lp->reg_offset);
  310. /* This is sometimes useful to find out how MacOS configured the card */
  311. pr_debug("%s: DCR=0x%04x, DCR2=0x%04x\n", __func__,
  312. SONIC_READ(SONIC_DCR) & 0xffff,
  313. SONIC_READ(SONIC_DCR2) & 0xffff);
  314. /* Software reset, then initialize control registers. */
  315. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  316. SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS |
  317. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  318. (lp->dma_bitmode ? SONIC_DCR_DW : 0));
  319. /* This *must* be written back to in order to restore the
  320. * extended programmable output bits, as it may not have been
  321. * initialised since the hardware reset. */
  322. SONIC_WRITE(SONIC_DCR2, 0);
  323. /* Clear *and* disable interrupts to be on the safe side */
  324. SONIC_WRITE(SONIC_IMR, 0);
  325. SONIC_WRITE(SONIC_ISR, 0x7fff);
  326. /* Now look for the MAC address. */
  327. mac_onboard_sonic_ethernet_addr(dev);
  328. pr_info("SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
  329. dev->base_addr, dev->dev_addr, dev->irq);
  330. /* Shared init code */
  331. return macsonic_init(dev);
  332. }
  333. static int mac_sonic_nubus_ethernet_addr(struct net_device *dev,
  334. unsigned long prom_addr, int id)
  335. {
  336. int i;
  337. for(i = 0; i < 6; i++)
  338. dev->dev_addr[i] = SONIC_READ_PROM(i);
  339. /* Some of the addresses are bit-reversed */
  340. if (id != MACSONIC_DAYNA)
  341. bit_reverse_addr(dev->dev_addr);
  342. return 0;
  343. }
  344. static int macsonic_ident(struct nubus_rsrc *fres)
  345. {
  346. if (fres->dr_hw == NUBUS_DRHW_ASANTE_LC &&
  347. fres->dr_sw == NUBUS_DRSW_SONIC_LC)
  348. return MACSONIC_DAYNALINK;
  349. if (fres->dr_hw == NUBUS_DRHW_SONIC &&
  350. fres->dr_sw == NUBUS_DRSW_APPLE) {
  351. /* There has to be a better way to do this... */
  352. if (strstr(fres->board->name, "DuoDock"))
  353. return MACSONIC_DUODOCK;
  354. else
  355. return MACSONIC_APPLE;
  356. }
  357. if (fres->dr_hw == NUBUS_DRHW_SMC9194 &&
  358. fres->dr_sw == NUBUS_DRSW_DAYNA)
  359. return MACSONIC_DAYNA;
  360. if (fres->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
  361. fres->dr_sw == 0) { /* huh? */
  362. return MACSONIC_APPLE16;
  363. }
  364. return -1;
  365. }
  366. static int mac_sonic_nubus_probe_board(struct nubus_board *board, int id,
  367. struct net_device *dev)
  368. {
  369. struct sonic_local* lp = netdev_priv(dev);
  370. unsigned long base_addr, prom_addr;
  371. u16 sonic_dcr;
  372. int reg_offset, dma_bitmode;
  373. switch (id) {
  374. case MACSONIC_DUODOCK:
  375. base_addr = board->slot_addr + DUODOCK_SONIC_REGISTERS;
  376. prom_addr = board->slot_addr + DUODOCK_SONIC_PROM_BASE;
  377. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 |
  378. SONIC_DCR_TFT0;
  379. reg_offset = 2;
  380. dma_bitmode = SONIC_BITMODE32;
  381. break;
  382. case MACSONIC_APPLE:
  383. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  384. prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
  385. sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0;
  386. reg_offset = 0;
  387. dma_bitmode = SONIC_BITMODE32;
  388. break;
  389. case MACSONIC_APPLE16:
  390. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  391. prom_addr = board->slot_addr + APPLE_SONIC_PROM_BASE;
  392. sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  393. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  394. reg_offset = 0;
  395. dma_bitmode = SONIC_BITMODE16;
  396. break;
  397. case MACSONIC_DAYNALINK:
  398. base_addr = board->slot_addr + APPLE_SONIC_REGISTERS;
  399. prom_addr = board->slot_addr + DAYNALINK_PROM_BASE;
  400. sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 |
  401. SONIC_DCR_PO1 | SONIC_DCR_BMS;
  402. reg_offset = 0;
  403. dma_bitmode = SONIC_BITMODE16;
  404. break;
  405. case MACSONIC_DAYNA:
  406. base_addr = board->slot_addr + DAYNA_SONIC_REGISTERS;
  407. prom_addr = board->slot_addr + DAYNA_SONIC_MAC_ADDR;
  408. sonic_dcr = SONIC_DCR_BMS |
  409. SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1;
  410. reg_offset = 0;
  411. dma_bitmode = SONIC_BITMODE16;
  412. break;
  413. default:
  414. printk(KERN_ERR "macsonic: WTF, id is %d\n", id);
  415. return -ENODEV;
  416. }
  417. /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset
  418. * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */
  419. dev->base_addr = base_addr;
  420. lp->reg_offset = reg_offset;
  421. lp->dma_bitmode = dma_bitmode;
  422. dev->irq = SLOT2IRQ(board->slot);
  423. dev_info(&board->dev, "%s, revision 0x%04x, %d bit DMA, register offset %d\n",
  424. board->name, SONIC_READ(SONIC_SR),
  425. lp->dma_bitmode ? 32 : 16, lp->reg_offset);
  426. /* This is sometimes useful to find out how MacOS configured the card */
  427. dev_dbg(&board->dev, "%s: DCR=0x%04x, DCR2=0x%04x\n", __func__,
  428. SONIC_READ(SONIC_DCR) & 0xffff,
  429. SONIC_READ(SONIC_DCR2) & 0xffff);
  430. /* Software reset, then initialize control registers. */
  431. SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
  432. SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0));
  433. /* This *must* be written back to in order to restore the
  434. * extended programmable output bits, since it may not have been
  435. * initialised since the hardware reset. */
  436. SONIC_WRITE(SONIC_DCR2, 0);
  437. /* Clear *and* disable interrupts to be on the safe side */
  438. SONIC_WRITE(SONIC_IMR, 0);
  439. SONIC_WRITE(SONIC_ISR, 0x7fff);
  440. /* Now look for the MAC address. */
  441. if (mac_sonic_nubus_ethernet_addr(dev, prom_addr, id) != 0)
  442. return -ENODEV;
  443. dev_info(&board->dev, "SONIC ethernet @%08lx, MAC %pM, IRQ %d\n",
  444. dev->base_addr, dev->dev_addr, dev->irq);
  445. /* Shared init code */
  446. return macsonic_init(dev);
  447. }
  448. static int mac_sonic_platform_probe(struct platform_device *pdev)
  449. {
  450. struct net_device *dev;
  451. struct sonic_local *lp;
  452. int err;
  453. dev = alloc_etherdev(sizeof(struct sonic_local));
  454. if (!dev)
  455. return -ENOMEM;
  456. lp = netdev_priv(dev);
  457. lp->device = &pdev->dev;
  458. SET_NETDEV_DEV(dev, &pdev->dev);
  459. platform_set_drvdata(pdev, dev);
  460. err = mac_onboard_sonic_probe(dev);
  461. if (err)
  462. goto out;
  463. sonic_msg_init(dev);
  464. err = register_netdev(dev);
  465. if (err)
  466. goto out;
  467. return 0;
  468. out:
  469. free_netdev(dev);
  470. return err;
  471. }
  472. MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
  473. MODULE_ALIAS("platform:macsonic");
  474. #include "sonic.c"
  475. static int mac_sonic_platform_remove(struct platform_device *pdev)
  476. {
  477. struct net_device *dev = platform_get_drvdata(pdev);
  478. struct sonic_local* lp = netdev_priv(dev);
  479. unregister_netdev(dev);
  480. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  481. lp->descriptors, lp->descriptors_laddr);
  482. free_netdev(dev);
  483. return 0;
  484. }
  485. static struct platform_driver mac_sonic_platform_driver = {
  486. .probe = mac_sonic_platform_probe,
  487. .remove = mac_sonic_platform_remove,
  488. .driver = {
  489. .name = "macsonic",
  490. },
  491. };
  492. static int mac_sonic_nubus_probe(struct nubus_board *board)
  493. {
  494. struct net_device *ndev;
  495. struct sonic_local *lp;
  496. struct nubus_rsrc *fres;
  497. int id = -1;
  498. int err;
  499. /* The platform driver will handle a PDS or Comm Slot card (even if
  500. * it has a pseudoslot declaration ROM).
  501. */
  502. if (macintosh_config->expansion_type == MAC_EXP_PDS_COMM)
  503. return -ENODEV;
  504. for_each_board_func_rsrc(board, fres) {
  505. if (fres->category != NUBUS_CAT_NETWORK ||
  506. fres->type != NUBUS_TYPE_ETHERNET)
  507. continue;
  508. id = macsonic_ident(fres);
  509. if (id != -1)
  510. break;
  511. }
  512. if (!fres)
  513. return -ENODEV;
  514. ndev = alloc_etherdev(sizeof(struct sonic_local));
  515. if (!ndev)
  516. return -ENOMEM;
  517. lp = netdev_priv(ndev);
  518. lp->device = &board->dev;
  519. SET_NETDEV_DEV(ndev, &board->dev);
  520. err = mac_sonic_nubus_probe_board(board, id, ndev);
  521. if (err)
  522. goto out;
  523. sonic_msg_init(ndev);
  524. err = register_netdev(ndev);
  525. if (err)
  526. goto out;
  527. nubus_set_drvdata(board, ndev);
  528. return 0;
  529. out:
  530. free_netdev(ndev);
  531. return err;
  532. }
  533. static int mac_sonic_nubus_remove(struct nubus_board *board)
  534. {
  535. struct net_device *ndev = nubus_get_drvdata(board);
  536. struct sonic_local *lp = netdev_priv(ndev);
  537. unregister_netdev(ndev);
  538. dma_free_coherent(lp->device,
  539. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  540. lp->descriptors, lp->descriptors_laddr);
  541. free_netdev(ndev);
  542. return 0;
  543. }
  544. static struct nubus_driver mac_sonic_nubus_driver = {
  545. .probe = mac_sonic_nubus_probe,
  546. .remove = mac_sonic_nubus_remove,
  547. .driver = {
  548. .name = "macsonic-nubus",
  549. .owner = THIS_MODULE,
  550. },
  551. };
  552. static int perr, nerr;
  553. static int __init mac_sonic_init(void)
  554. {
  555. perr = platform_driver_register(&mac_sonic_platform_driver);
  556. nerr = nubus_driver_register(&mac_sonic_nubus_driver);
  557. return 0;
  558. }
  559. module_init(mac_sonic_init);
  560. static void __exit mac_sonic_exit(void)
  561. {
  562. if (!perr)
  563. platform_driver_unregister(&mac_sonic_platform_driver);
  564. if (!nerr)
  565. nubus_driver_unregister(&mac_sonic_nubus_driver);
  566. }
  567. module_exit(mac_sonic_exit);