bfin_mac.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. /*
  2. * Blackfin On-Chip MAC Driver
  3. *
  4. * Copyright 2004-2010 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #define DRV_VERSION "1.1"
  11. #define DRV_DESC "Blackfin on-chip Ethernet MAC driver"
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h>
  17. #include <linux/slab.h>
  18. #include <linux/delay.h>
  19. #include <linux/timer.h>
  20. #include <linux/errno.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #include <linux/ioport.h>
  24. #include <linux/crc32.h>
  25. #include <linux/device.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/mii.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/platform_device.h>
  33. #include <asm/dma.h>
  34. #include <linux/dma-mapping.h>
  35. #include <asm/div64.h>
  36. #include <asm/dpmc.h>
  37. #include <asm/blackfin.h>
  38. #include <asm/cacheflush.h>
  39. #include <asm/portmux.h>
  40. #include <mach/pll.h>
  41. #include "bfin_mac.h"
  42. MODULE_AUTHOR("Bryan Wu, Luke Yang");
  43. MODULE_LICENSE("GPL");
  44. MODULE_DESCRIPTION(DRV_DESC);
  45. MODULE_ALIAS("platform:bfin_mac");
  46. #if defined(CONFIG_BFIN_MAC_USE_L1)
  47. # define bfin_mac_alloc(dma_handle, size, num) l1_data_sram_zalloc(size*num)
  48. # define bfin_mac_free(dma_handle, ptr, num) l1_data_sram_free(ptr)
  49. #else
  50. # define bfin_mac_alloc(dma_handle, size, num) \
  51. dma_alloc_coherent(NULL, size*num, dma_handle, GFP_KERNEL)
  52. # define bfin_mac_free(dma_handle, ptr, num) \
  53. dma_free_coherent(NULL, sizeof(*ptr)*num, ptr, dma_handle)
  54. #endif
  55. #define PKT_BUF_SZ 1580
  56. #define MAX_TIMEOUT_CNT 500
  57. /* pointers to maintain transmit list */
  58. static struct net_dma_desc_tx *tx_list_head;
  59. static struct net_dma_desc_tx *tx_list_tail;
  60. static struct net_dma_desc_rx *rx_list_head;
  61. static struct net_dma_desc_rx *rx_list_tail;
  62. static struct net_dma_desc_rx *current_rx_ptr;
  63. static struct net_dma_desc_tx *current_tx_ptr;
  64. static struct net_dma_desc_tx *tx_desc;
  65. static struct net_dma_desc_rx *rx_desc;
  66. static void desc_list_free(void)
  67. {
  68. struct net_dma_desc_rx *r;
  69. struct net_dma_desc_tx *t;
  70. int i;
  71. #if !defined(CONFIG_BFIN_MAC_USE_L1)
  72. dma_addr_t dma_handle = 0;
  73. #endif
  74. if (tx_desc) {
  75. t = tx_list_head;
  76. for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) {
  77. if (t) {
  78. if (t->skb) {
  79. dev_kfree_skb(t->skb);
  80. t->skb = NULL;
  81. }
  82. t = t->next;
  83. }
  84. }
  85. bfin_mac_free(dma_handle, tx_desc, CONFIG_BFIN_TX_DESC_NUM);
  86. }
  87. if (rx_desc) {
  88. r = rx_list_head;
  89. for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) {
  90. if (r) {
  91. if (r->skb) {
  92. dev_kfree_skb(r->skb);
  93. r->skb = NULL;
  94. }
  95. r = r->next;
  96. }
  97. }
  98. bfin_mac_free(dma_handle, rx_desc, CONFIG_BFIN_RX_DESC_NUM);
  99. }
  100. }
  101. static int desc_list_init(struct net_device *dev)
  102. {
  103. int i;
  104. struct sk_buff *new_skb;
  105. #if !defined(CONFIG_BFIN_MAC_USE_L1)
  106. /*
  107. * This dma_handle is useless in Blackfin dma_alloc_coherent().
  108. * The real dma handler is the return value of dma_alloc_coherent().
  109. */
  110. dma_addr_t dma_handle;
  111. #endif
  112. tx_desc = bfin_mac_alloc(&dma_handle,
  113. sizeof(struct net_dma_desc_tx),
  114. CONFIG_BFIN_TX_DESC_NUM);
  115. if (tx_desc == NULL)
  116. goto init_error;
  117. rx_desc = bfin_mac_alloc(&dma_handle,
  118. sizeof(struct net_dma_desc_rx),
  119. CONFIG_BFIN_RX_DESC_NUM);
  120. if (rx_desc == NULL)
  121. goto init_error;
  122. /* init tx_list */
  123. tx_list_head = tx_list_tail = tx_desc;
  124. for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) {
  125. struct net_dma_desc_tx *t = tx_desc + i;
  126. struct dma_descriptor *a = &(t->desc_a);
  127. struct dma_descriptor *b = &(t->desc_b);
  128. /*
  129. * disable DMA
  130. * read from memory WNR = 0
  131. * wordsize is 32 bits
  132. * 6 half words is desc size
  133. * large desc flow
  134. */
  135. a->config = WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
  136. a->start_addr = (unsigned long)t->packet;
  137. a->x_count = 0;
  138. a->next_dma_desc = b;
  139. /*
  140. * enabled DMA
  141. * write to memory WNR = 1
  142. * wordsize is 32 bits
  143. * disable interrupt
  144. * 6 half words is desc size
  145. * large desc flow
  146. */
  147. b->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
  148. b->start_addr = (unsigned long)(&(t->status));
  149. b->x_count = 0;
  150. t->skb = NULL;
  151. tx_list_tail->desc_b.next_dma_desc = a;
  152. tx_list_tail->next = t;
  153. tx_list_tail = t;
  154. }
  155. tx_list_tail->next = tx_list_head; /* tx_list is a circle */
  156. tx_list_tail->desc_b.next_dma_desc = &(tx_list_head->desc_a);
  157. current_tx_ptr = tx_list_head;
  158. /* init rx_list */
  159. rx_list_head = rx_list_tail = rx_desc;
  160. for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) {
  161. struct net_dma_desc_rx *r = rx_desc + i;
  162. struct dma_descriptor *a = &(r->desc_a);
  163. struct dma_descriptor *b = &(r->desc_b);
  164. /* allocate a new skb for next time receive */
  165. new_skb = netdev_alloc_skb(dev, PKT_BUF_SZ + NET_IP_ALIGN);
  166. if (!new_skb) {
  167. pr_notice("init: low on mem - packet dropped\n");
  168. goto init_error;
  169. }
  170. skb_reserve(new_skb, NET_IP_ALIGN);
  171. /* Invidate the data cache of skb->data range when it is write back
  172. * cache. It will prevent overwritting the new data from DMA
  173. */
  174. blackfin_dcache_invalidate_range((unsigned long)new_skb->head,
  175. (unsigned long)new_skb->end);
  176. r->skb = new_skb;
  177. /*
  178. * enabled DMA
  179. * write to memory WNR = 1
  180. * wordsize is 32 bits
  181. * disable interrupt
  182. * 6 half words is desc size
  183. * large desc flow
  184. */
  185. a->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE;
  186. /* since RXDWA is enabled */
  187. a->start_addr = (unsigned long)new_skb->data - 2;
  188. a->x_count = 0;
  189. a->next_dma_desc = b;
  190. /*
  191. * enabled DMA
  192. * write to memory WNR = 1
  193. * wordsize is 32 bits
  194. * enable interrupt
  195. * 6 half words is desc size
  196. * large desc flow
  197. */
  198. b->config = DMAEN | WNR | WDSIZE_32 | DI_EN |
  199. NDSIZE_6 | DMAFLOW_LARGE;
  200. b->start_addr = (unsigned long)(&(r->status));
  201. b->x_count = 0;
  202. rx_list_tail->desc_b.next_dma_desc = a;
  203. rx_list_tail->next = r;
  204. rx_list_tail = r;
  205. }
  206. rx_list_tail->next = rx_list_head; /* rx_list is a circle */
  207. rx_list_tail->desc_b.next_dma_desc = &(rx_list_head->desc_a);
  208. current_rx_ptr = rx_list_head;
  209. return 0;
  210. init_error:
  211. desc_list_free();
  212. pr_err("kmalloc failed\n");
  213. return -ENOMEM;
  214. }
  215. /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
  216. /*
  217. * MII operations
  218. */
  219. /* Wait until the previous MDC/MDIO transaction has completed */
  220. static int bfin_mdio_poll(void)
  221. {
  222. int timeout_cnt = MAX_TIMEOUT_CNT;
  223. /* poll the STABUSY bit */
  224. while ((bfin_read_EMAC_STAADD()) & STABUSY) {
  225. udelay(1);
  226. if (timeout_cnt-- < 0) {
  227. pr_err("wait MDC/MDIO transaction to complete timeout\n");
  228. return -ETIMEDOUT;
  229. }
  230. }
  231. return 0;
  232. }
  233. /* Read an off-chip register in a PHY through the MDC/MDIO port */
  234. static int bfin_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
  235. {
  236. int ret;
  237. ret = bfin_mdio_poll();
  238. if (ret)
  239. return ret;
  240. /* read mode */
  241. bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) |
  242. SET_REGAD((u16) regnum) |
  243. STABUSY);
  244. ret = bfin_mdio_poll();
  245. if (ret)
  246. return ret;
  247. return (int) bfin_read_EMAC_STADAT();
  248. }
  249. /* Write an off-chip register in a PHY through the MDC/MDIO port */
  250. static int bfin_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
  251. u16 value)
  252. {
  253. int ret;
  254. ret = bfin_mdio_poll();
  255. if (ret)
  256. return ret;
  257. bfin_write_EMAC_STADAT((u32) value);
  258. /* write mode */
  259. bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) |
  260. SET_REGAD((u16) regnum) |
  261. STAOP |
  262. STABUSY);
  263. return bfin_mdio_poll();
  264. }
  265. static int bfin_mdiobus_reset(struct mii_bus *bus)
  266. {
  267. return 0;
  268. }
  269. static void bfin_mac_adjust_link(struct net_device *dev)
  270. {
  271. struct bfin_mac_local *lp = netdev_priv(dev);
  272. struct phy_device *phydev = lp->phydev;
  273. unsigned long flags;
  274. int new_state = 0;
  275. spin_lock_irqsave(&lp->lock, flags);
  276. if (phydev->link) {
  277. /* Now we make sure that we can be in full duplex mode.
  278. * If not, we operate in half-duplex mode. */
  279. if (phydev->duplex != lp->old_duplex) {
  280. u32 opmode = bfin_read_EMAC_OPMODE();
  281. new_state = 1;
  282. if (phydev->duplex)
  283. opmode |= FDMODE;
  284. else
  285. opmode &= ~(FDMODE);
  286. bfin_write_EMAC_OPMODE(opmode);
  287. lp->old_duplex = phydev->duplex;
  288. }
  289. if (phydev->speed != lp->old_speed) {
  290. if (phydev->interface == PHY_INTERFACE_MODE_RMII) {
  291. u32 opmode = bfin_read_EMAC_OPMODE();
  292. switch (phydev->speed) {
  293. case 10:
  294. opmode |= RMII_10;
  295. break;
  296. case 100:
  297. opmode &= ~RMII_10;
  298. break;
  299. default:
  300. netdev_warn(dev,
  301. "Ack! Speed (%d) is not 10/100!\n",
  302. phydev->speed);
  303. break;
  304. }
  305. bfin_write_EMAC_OPMODE(opmode);
  306. }
  307. new_state = 1;
  308. lp->old_speed = phydev->speed;
  309. }
  310. if (!lp->old_link) {
  311. new_state = 1;
  312. lp->old_link = 1;
  313. }
  314. } else if (lp->old_link) {
  315. new_state = 1;
  316. lp->old_link = 0;
  317. lp->old_speed = 0;
  318. lp->old_duplex = -1;
  319. }
  320. if (new_state) {
  321. u32 opmode = bfin_read_EMAC_OPMODE();
  322. phy_print_status(phydev);
  323. pr_debug("EMAC_OPMODE = 0x%08x\n", opmode);
  324. }
  325. spin_unlock_irqrestore(&lp->lock, flags);
  326. }
  327. /* MDC = 2.5 MHz */
  328. #define MDC_CLK 2500000
  329. static int mii_probe(struct net_device *dev, int phy_mode)
  330. {
  331. struct bfin_mac_local *lp = netdev_priv(dev);
  332. struct phy_device *phydev = NULL;
  333. unsigned short sysctl;
  334. int i;
  335. u32 sclk, mdc_div;
  336. /* Enable PHY output early */
  337. if (!(bfin_read_VR_CTL() & CLKBUFOE))
  338. bfin_write_VR_CTL(bfin_read_VR_CTL() | CLKBUFOE);
  339. sclk = get_sclk();
  340. mdc_div = ((sclk / MDC_CLK) / 2) - 1;
  341. sysctl = bfin_read_EMAC_SYSCTL();
  342. sysctl = (sysctl & ~MDCDIV) | SET_MDCDIV(mdc_div);
  343. bfin_write_EMAC_SYSCTL(sysctl);
  344. /* search for connected PHY device */
  345. for (i = 0; i < PHY_MAX_ADDR; ++i) {
  346. struct phy_device *const tmp_phydev = lp->mii_bus->phy_map[i];
  347. if (!tmp_phydev)
  348. continue; /* no PHY here... */
  349. phydev = tmp_phydev;
  350. break; /* found it */
  351. }
  352. /* now we are supposed to have a proper phydev, to attach to... */
  353. if (!phydev) {
  354. netdev_err(dev, "no phy device found\n");
  355. return -ENODEV;
  356. }
  357. if (phy_mode != PHY_INTERFACE_MODE_RMII &&
  358. phy_mode != PHY_INTERFACE_MODE_MII) {
  359. netdev_err(dev, "invalid phy interface mode\n");
  360. return -EINVAL;
  361. }
  362. phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link,
  363. 0, phy_mode);
  364. if (IS_ERR(phydev)) {
  365. netdev_err(dev, "could not attach PHY\n");
  366. return PTR_ERR(phydev);
  367. }
  368. /* mask with MAC supported features */
  369. phydev->supported &= (SUPPORTED_10baseT_Half
  370. | SUPPORTED_10baseT_Full
  371. | SUPPORTED_100baseT_Half
  372. | SUPPORTED_100baseT_Full
  373. | SUPPORTED_Autoneg
  374. | SUPPORTED_Pause | SUPPORTED_Asym_Pause
  375. | SUPPORTED_MII
  376. | SUPPORTED_TP);
  377. phydev->advertising = phydev->supported;
  378. lp->old_link = 0;
  379. lp->old_speed = 0;
  380. lp->old_duplex = -1;
  381. lp->phydev = phydev;
  382. pr_info("attached PHY driver [%s] "
  383. "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)@sclk=%dMHz)\n",
  384. phydev->drv->name, dev_name(&phydev->dev), phydev->irq,
  385. MDC_CLK, mdc_div, sclk/1000000);
  386. return 0;
  387. }
  388. /*
  389. * Ethtool support
  390. */
  391. /*
  392. * interrupt routine for magic packet wakeup
  393. */
  394. static irqreturn_t bfin_mac_wake_interrupt(int irq, void *dev_id)
  395. {
  396. return IRQ_HANDLED;
  397. }
  398. static int
  399. bfin_mac_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  400. {
  401. struct bfin_mac_local *lp = netdev_priv(dev);
  402. if (lp->phydev)
  403. return phy_ethtool_gset(lp->phydev, cmd);
  404. return -EINVAL;
  405. }
  406. static int
  407. bfin_mac_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  408. {
  409. struct bfin_mac_local *lp = netdev_priv(dev);
  410. if (!capable(CAP_NET_ADMIN))
  411. return -EPERM;
  412. if (lp->phydev)
  413. return phy_ethtool_sset(lp->phydev, cmd);
  414. return -EINVAL;
  415. }
  416. static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev,
  417. struct ethtool_drvinfo *info)
  418. {
  419. strcpy(info->driver, KBUILD_MODNAME);
  420. strcpy(info->version, DRV_VERSION);
  421. strcpy(info->fw_version, "N/A");
  422. strcpy(info->bus_info, dev_name(&dev->dev));
  423. }
  424. static void bfin_mac_ethtool_getwol(struct net_device *dev,
  425. struct ethtool_wolinfo *wolinfo)
  426. {
  427. struct bfin_mac_local *lp = netdev_priv(dev);
  428. wolinfo->supported = WAKE_MAGIC;
  429. wolinfo->wolopts = lp->wol;
  430. }
  431. static int bfin_mac_ethtool_setwol(struct net_device *dev,
  432. struct ethtool_wolinfo *wolinfo)
  433. {
  434. struct bfin_mac_local *lp = netdev_priv(dev);
  435. int rc;
  436. if (wolinfo->wolopts & (WAKE_MAGICSECURE |
  437. WAKE_UCAST |
  438. WAKE_MCAST |
  439. WAKE_BCAST |
  440. WAKE_ARP))
  441. return -EOPNOTSUPP;
  442. lp->wol = wolinfo->wolopts;
  443. if (lp->wol && !lp->irq_wake_requested) {
  444. /* register wake irq handler */
  445. rc = request_irq(IRQ_MAC_WAKEDET, bfin_mac_wake_interrupt,
  446. IRQF_DISABLED, "EMAC_WAKE", dev);
  447. if (rc)
  448. return rc;
  449. lp->irq_wake_requested = true;
  450. }
  451. if (!lp->wol && lp->irq_wake_requested) {
  452. free_irq(IRQ_MAC_WAKEDET, dev);
  453. lp->irq_wake_requested = false;
  454. }
  455. /* Make sure the PHY driver doesn't suspend */
  456. device_init_wakeup(&dev->dev, lp->wol);
  457. return 0;
  458. }
  459. static const struct ethtool_ops bfin_mac_ethtool_ops = {
  460. .get_settings = bfin_mac_ethtool_getsettings,
  461. .set_settings = bfin_mac_ethtool_setsettings,
  462. .get_link = ethtool_op_get_link,
  463. .get_drvinfo = bfin_mac_ethtool_getdrvinfo,
  464. .get_wol = bfin_mac_ethtool_getwol,
  465. .set_wol = bfin_mac_ethtool_setwol,
  466. };
  467. /**************************************************************************/
  468. static void setup_system_regs(struct net_device *dev)
  469. {
  470. struct bfin_mac_local *lp = netdev_priv(dev);
  471. int i;
  472. unsigned short sysctl;
  473. /*
  474. * Odd word alignment for Receive Frame DMA word
  475. * Configure checksum support and rcve frame word alignment
  476. */
  477. sysctl = bfin_read_EMAC_SYSCTL();
  478. /*
  479. * check if interrupt is requested for any PHY,
  480. * enable PHY interrupt only if needed
  481. */
  482. for (i = 0; i < PHY_MAX_ADDR; ++i)
  483. if (lp->mii_bus->irq[i] != PHY_POLL)
  484. break;
  485. if (i < PHY_MAX_ADDR)
  486. sysctl |= PHYIE;
  487. sysctl |= RXDWA;
  488. #if defined(BFIN_MAC_CSUM_OFFLOAD)
  489. sysctl |= RXCKS;
  490. #else
  491. sysctl &= ~RXCKS;
  492. #endif
  493. bfin_write_EMAC_SYSCTL(sysctl);
  494. bfin_write_EMAC_MMC_CTL(RSTC | CROLL);
  495. /* Set vlan regs to let 1522 bytes long packets pass through */
  496. bfin_write_EMAC_VLAN1(lp->vlan1_mask);
  497. bfin_write_EMAC_VLAN2(lp->vlan2_mask);
  498. /* Initialize the TX DMA channel registers */
  499. bfin_write_DMA2_X_COUNT(0);
  500. bfin_write_DMA2_X_MODIFY(4);
  501. bfin_write_DMA2_Y_COUNT(0);
  502. bfin_write_DMA2_Y_MODIFY(0);
  503. /* Initialize the RX DMA channel registers */
  504. bfin_write_DMA1_X_COUNT(0);
  505. bfin_write_DMA1_X_MODIFY(4);
  506. bfin_write_DMA1_Y_COUNT(0);
  507. bfin_write_DMA1_Y_MODIFY(0);
  508. }
  509. static void setup_mac_addr(u8 *mac_addr)
  510. {
  511. u32 addr_low = le32_to_cpu(*(__le32 *) & mac_addr[0]);
  512. u16 addr_hi = le16_to_cpu(*(__le16 *) & mac_addr[4]);
  513. /* this depends on a little-endian machine */
  514. bfin_write_EMAC_ADDRLO(addr_low);
  515. bfin_write_EMAC_ADDRHI(addr_hi);
  516. }
  517. static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
  518. {
  519. struct sockaddr *addr = p;
  520. if (netif_running(dev))
  521. return -EBUSY;
  522. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  523. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  524. setup_mac_addr(dev->dev_addr);
  525. return 0;
  526. }
  527. #ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
  528. #define bfin_mac_hwtstamp_is_none(cfg) ((cfg) == HWTSTAMP_FILTER_NONE)
  529. static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
  530. struct ifreq *ifr, int cmd)
  531. {
  532. struct hwtstamp_config config;
  533. struct bfin_mac_local *lp = netdev_priv(netdev);
  534. u16 ptpctl;
  535. u32 ptpfv1, ptpfv2, ptpfv3, ptpfoff;
  536. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  537. return -EFAULT;
  538. pr_debug("%s config flag:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
  539. __func__, config.flags, config.tx_type, config.rx_filter);
  540. /* reserved for future extensions */
  541. if (config.flags)
  542. return -EINVAL;
  543. if ((config.tx_type != HWTSTAMP_TX_OFF) &&
  544. (config.tx_type != HWTSTAMP_TX_ON))
  545. return -ERANGE;
  546. ptpctl = bfin_read_EMAC_PTP_CTL();
  547. switch (config.rx_filter) {
  548. case HWTSTAMP_FILTER_NONE:
  549. /*
  550. * Dont allow any timestamping
  551. */
  552. ptpfv3 = 0xFFFFFFFF;
  553. bfin_write_EMAC_PTP_FV3(ptpfv3);
  554. break;
  555. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  556. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  557. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  558. /*
  559. * Clear the five comparison mask bits (bits[12:8]) in EMAC_PTP_CTL)
  560. * to enable all the field matches.
  561. */
  562. ptpctl &= ~0x1F00;
  563. bfin_write_EMAC_PTP_CTL(ptpctl);
  564. /*
  565. * Keep the default values of the EMAC_PTP_FOFF register.
  566. */
  567. ptpfoff = 0x4A24170C;
  568. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  569. /*
  570. * Keep the default values of the EMAC_PTP_FV1 and EMAC_PTP_FV2
  571. * registers.
  572. */
  573. ptpfv1 = 0x11040800;
  574. bfin_write_EMAC_PTP_FV1(ptpfv1);
  575. ptpfv2 = 0x0140013F;
  576. bfin_write_EMAC_PTP_FV2(ptpfv2);
  577. /*
  578. * The default value (0xFFFC) allows the timestamping of both
  579. * received Sync messages and Delay_Req messages.
  580. */
  581. ptpfv3 = 0xFFFFFFFC;
  582. bfin_write_EMAC_PTP_FV3(ptpfv3);
  583. config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  584. break;
  585. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  586. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  587. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  588. /* Clear all five comparison mask bits (bits[12:8]) in the
  589. * EMAC_PTP_CTL register to enable all the field matches.
  590. */
  591. ptpctl &= ~0x1F00;
  592. bfin_write_EMAC_PTP_CTL(ptpctl);
  593. /*
  594. * Keep the default values of the EMAC_PTP_FOFF register, except set
  595. * the PTPCOF field to 0x2A.
  596. */
  597. ptpfoff = 0x2A24170C;
  598. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  599. /*
  600. * Keep the default values of the EMAC_PTP_FV1 and EMAC_PTP_FV2
  601. * registers.
  602. */
  603. ptpfv1 = 0x11040800;
  604. bfin_write_EMAC_PTP_FV1(ptpfv1);
  605. ptpfv2 = 0x0140013F;
  606. bfin_write_EMAC_PTP_FV2(ptpfv2);
  607. /*
  608. * To allow the timestamping of Pdelay_Req and Pdelay_Resp, set
  609. * the value to 0xFFF0.
  610. */
  611. ptpfv3 = 0xFFFFFFF0;
  612. bfin_write_EMAC_PTP_FV3(ptpfv3);
  613. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  614. break;
  615. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  616. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  617. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  618. /*
  619. * Clear bits 8 and 12 of the EMAC_PTP_CTL register to enable only the
  620. * EFTM and PTPCM field comparison.
  621. */
  622. ptpctl &= ~0x1100;
  623. bfin_write_EMAC_PTP_CTL(ptpctl);
  624. /*
  625. * Keep the default values of all the fields of the EMAC_PTP_FOFF
  626. * register, except set the PTPCOF field to 0x0E.
  627. */
  628. ptpfoff = 0x0E24170C;
  629. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  630. /*
  631. * Program bits [15:0] of the EMAC_PTP_FV1 register to 0x88F7, which
  632. * corresponds to PTP messages on the MAC layer.
  633. */
  634. ptpfv1 = 0x110488F7;
  635. bfin_write_EMAC_PTP_FV1(ptpfv1);
  636. ptpfv2 = 0x0140013F;
  637. bfin_write_EMAC_PTP_FV2(ptpfv2);
  638. /*
  639. * To allow the timestamping of Pdelay_Req and Pdelay_Resp
  640. * messages, set the value to 0xFFF0.
  641. */
  642. ptpfv3 = 0xFFFFFFF0;
  643. bfin_write_EMAC_PTP_FV3(ptpfv3);
  644. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  645. break;
  646. default:
  647. return -ERANGE;
  648. }
  649. if (config.tx_type == HWTSTAMP_TX_OFF &&
  650. bfin_mac_hwtstamp_is_none(config.rx_filter)) {
  651. ptpctl &= ~PTP_EN;
  652. bfin_write_EMAC_PTP_CTL(ptpctl);
  653. SSYNC();
  654. } else {
  655. ptpctl |= PTP_EN;
  656. bfin_write_EMAC_PTP_CTL(ptpctl);
  657. /*
  658. * clear any existing timestamp
  659. */
  660. bfin_read_EMAC_PTP_RXSNAPLO();
  661. bfin_read_EMAC_PTP_RXSNAPHI();
  662. bfin_read_EMAC_PTP_TXSNAPLO();
  663. bfin_read_EMAC_PTP_TXSNAPHI();
  664. /*
  665. * Set registers so that rollover occurs soon to test this.
  666. */
  667. bfin_write_EMAC_PTP_TIMELO(0x00000000);
  668. bfin_write_EMAC_PTP_TIMEHI(0xFF800000);
  669. SSYNC();
  670. lp->compare.last_update = 0;
  671. timecounter_init(&lp->clock,
  672. &lp->cycles,
  673. ktime_to_ns(ktime_get_real()));
  674. timecompare_update(&lp->compare, 0);
  675. }
  676. lp->stamp_cfg = config;
  677. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  678. -EFAULT : 0;
  679. }
  680. static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompare *cmp)
  681. {
  682. ktime_t sys = ktime_get_real();
  683. pr_debug("%s %s hardware:%d,%d transform system:%d,%d system:%d,%d, cmp:%lld, %lld\n",
  684. __func__, s, hw->tv.sec, hw->tv.nsec, ts->tv.sec, ts->tv.nsec, sys.tv.sec,
  685. sys.tv.nsec, cmp->offset, cmp->skew);
  686. }
  687. static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
  688. {
  689. struct bfin_mac_local *lp = netdev_priv(netdev);
  690. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
  691. int timeout_cnt = MAX_TIMEOUT_CNT;
  692. /* When doing time stamping, keep the connection to the socket
  693. * a while longer
  694. */
  695. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  696. /*
  697. * The timestamping is done at the EMAC module's MII/RMII interface
  698. * when the module sees the Start of Frame of an event message packet. This
  699. * interface is the closest possible place to the physical Ethernet transmission
  700. * medium, providing the best timing accuracy.
  701. */
  702. while ((!(bfin_read_EMAC_PTP_ISTAT() & TXTL)) && (--timeout_cnt))
  703. udelay(1);
  704. if (timeout_cnt == 0)
  705. netdev_err(netdev, "timestamp the TX packet failed\n");
  706. else {
  707. struct skb_shared_hwtstamps shhwtstamps;
  708. u64 ns;
  709. u64 regval;
  710. regval = bfin_read_EMAC_PTP_TXSNAPLO();
  711. regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
  712. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  713. ns = timecounter_cyc2time(&lp->clock,
  714. regval);
  715. timecompare_update(&lp->compare, ns);
  716. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  717. shhwtstamps.syststamp =
  718. timecompare_transform(&lp->compare, ns);
  719. skb_tstamp_tx(skb, &shhwtstamps);
  720. bfin_dump_hwtamp("TX", &shhwtstamps.hwtstamp, &shhwtstamps.syststamp, &lp->compare);
  721. }
  722. }
  723. }
  724. static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
  725. {
  726. struct bfin_mac_local *lp = netdev_priv(netdev);
  727. u32 valid;
  728. u64 regval, ns;
  729. struct skb_shared_hwtstamps *shhwtstamps;
  730. if (bfin_mac_hwtstamp_is_none(lp->stamp_cfg.rx_filter))
  731. return;
  732. valid = bfin_read_EMAC_PTP_ISTAT() & RXEL;
  733. if (!valid)
  734. return;
  735. shhwtstamps = skb_hwtstamps(skb);
  736. regval = bfin_read_EMAC_PTP_RXSNAPLO();
  737. regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
  738. ns = timecounter_cyc2time(&lp->clock, regval);
  739. timecompare_update(&lp->compare, ns);
  740. memset(shhwtstamps, 0, sizeof(*shhwtstamps));
  741. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  742. shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
  743. bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
  744. }
  745. /*
  746. * bfin_read_clock - read raw cycle counter (to be used by time counter)
  747. */
  748. static cycle_t bfin_read_clock(const struct cyclecounter *tc)
  749. {
  750. u64 stamp;
  751. stamp = bfin_read_EMAC_PTP_TIMELO();
  752. stamp |= (u64)bfin_read_EMAC_PTP_TIMEHI() << 32ULL;
  753. return stamp;
  754. }
  755. #define PTP_CLK 25000000
  756. static void bfin_mac_hwtstamp_init(struct net_device *netdev)
  757. {
  758. struct bfin_mac_local *lp = netdev_priv(netdev);
  759. u64 append;
  760. /* Initialize hardware timer */
  761. append = PTP_CLK * (1ULL << 32);
  762. do_div(append, get_sclk());
  763. bfin_write_EMAC_PTP_ADDEND((u32)append);
  764. memset(&lp->cycles, 0, sizeof(lp->cycles));
  765. lp->cycles.read = bfin_read_clock;
  766. lp->cycles.mask = CLOCKSOURCE_MASK(64);
  767. lp->cycles.mult = 1000000000 / PTP_CLK;
  768. lp->cycles.shift = 0;
  769. /* Synchronize our NIC clock against system wall clock */
  770. memset(&lp->compare, 0, sizeof(lp->compare));
  771. lp->compare.source = &lp->clock;
  772. lp->compare.target = ktime_get_real;
  773. lp->compare.num_samples = 10;
  774. /* Initialize hwstamp config */
  775. lp->stamp_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
  776. lp->stamp_cfg.tx_type = HWTSTAMP_TX_OFF;
  777. }
  778. #else
  779. # define bfin_mac_hwtstamp_is_none(cfg) 0
  780. # define bfin_mac_hwtstamp_init(dev)
  781. # define bfin_mac_hwtstamp_ioctl(dev, ifr, cmd) (-EOPNOTSUPP)
  782. # define bfin_rx_hwtstamp(dev, skb)
  783. # define bfin_tx_hwtstamp(dev, skb)
  784. #endif
  785. static inline void _tx_reclaim_skb(void)
  786. {
  787. do {
  788. tx_list_head->desc_a.config &= ~DMAEN;
  789. tx_list_head->status.status_word = 0;
  790. if (tx_list_head->skb) {
  791. dev_kfree_skb(tx_list_head->skb);
  792. tx_list_head->skb = NULL;
  793. }
  794. tx_list_head = tx_list_head->next;
  795. } while (tx_list_head->status.status_word != 0);
  796. }
  797. static void tx_reclaim_skb(struct bfin_mac_local *lp)
  798. {
  799. int timeout_cnt = MAX_TIMEOUT_CNT;
  800. if (tx_list_head->status.status_word != 0)
  801. _tx_reclaim_skb();
  802. if (current_tx_ptr->next == tx_list_head) {
  803. while (tx_list_head->status.status_word == 0) {
  804. /* slow down polling to avoid too many queue stop. */
  805. udelay(10);
  806. /* reclaim skb if DMA is not running. */
  807. if (!(bfin_read_DMA2_IRQ_STATUS() & DMA_RUN))
  808. break;
  809. if (timeout_cnt-- < 0)
  810. break;
  811. }
  812. if (timeout_cnt >= 0)
  813. _tx_reclaim_skb();
  814. else
  815. netif_stop_queue(lp->ndev);
  816. }
  817. if (current_tx_ptr->next != tx_list_head &&
  818. netif_queue_stopped(lp->ndev))
  819. netif_wake_queue(lp->ndev);
  820. if (tx_list_head != current_tx_ptr) {
  821. /* shorten the timer interval if tx queue is stopped */
  822. if (netif_queue_stopped(lp->ndev))
  823. lp->tx_reclaim_timer.expires =
  824. jiffies + (TX_RECLAIM_JIFFIES >> 4);
  825. else
  826. lp->tx_reclaim_timer.expires =
  827. jiffies + TX_RECLAIM_JIFFIES;
  828. mod_timer(&lp->tx_reclaim_timer,
  829. lp->tx_reclaim_timer.expires);
  830. }
  831. return;
  832. }
  833. static void tx_reclaim_skb_timeout(unsigned long lp)
  834. {
  835. tx_reclaim_skb((struct bfin_mac_local *)lp);
  836. }
  837. static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
  838. struct net_device *dev)
  839. {
  840. struct bfin_mac_local *lp = netdev_priv(dev);
  841. u16 *data;
  842. u32 data_align = (unsigned long)(skb->data) & 0x3;
  843. current_tx_ptr->skb = skb;
  844. if (data_align == 0x2) {
  845. /* move skb->data to current_tx_ptr payload */
  846. data = (u16 *)(skb->data) - 1;
  847. *data = (u16)(skb->len);
  848. /*
  849. * When transmitting an Ethernet packet, the PTP_TSYNC module requires
  850. * a DMA_Length_Word field associated with the packet. The lower 12 bits
  851. * of this field are the length of the packet payload in bytes and the higher
  852. * 4 bits are the timestamping enable field.
  853. */
  854. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
  855. *data |= 0x1000;
  856. current_tx_ptr->desc_a.start_addr = (u32)data;
  857. /* this is important! */
  858. blackfin_dcache_flush_range((u32)data,
  859. (u32)((u8 *)data + skb->len + 4));
  860. } else {
  861. *((u16 *)(current_tx_ptr->packet)) = (u16)(skb->len);
  862. /* enable timestamping for the sent packet */
  863. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
  864. *((u16 *)(current_tx_ptr->packet)) |= 0x1000;
  865. memcpy((u8 *)(current_tx_ptr->packet + 2), skb->data,
  866. skb->len);
  867. current_tx_ptr->desc_a.start_addr =
  868. (u32)current_tx_ptr->packet;
  869. blackfin_dcache_flush_range(
  870. (u32)current_tx_ptr->packet,
  871. (u32)(current_tx_ptr->packet + skb->len + 2));
  872. }
  873. /* make sure the internal data buffers in the core are drained
  874. * so that the DMA descriptors are completely written when the
  875. * DMA engine goes to fetch them below
  876. */
  877. SSYNC();
  878. /* always clear status buffer before start tx dma */
  879. current_tx_ptr->status.status_word = 0;
  880. /* enable this packet's dma */
  881. current_tx_ptr->desc_a.config |= DMAEN;
  882. /* tx dma is running, just return */
  883. if (bfin_read_DMA2_IRQ_STATUS() & DMA_RUN)
  884. goto out;
  885. /* tx dma is not running */
  886. bfin_write_DMA2_NEXT_DESC_PTR(&(current_tx_ptr->desc_a));
  887. /* dma enabled, read from memory, size is 6 */
  888. bfin_write_DMA2_CONFIG(current_tx_ptr->desc_a.config);
  889. /* Turn on the EMAC tx */
  890. bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
  891. out:
  892. bfin_tx_hwtstamp(dev, skb);
  893. current_tx_ptr = current_tx_ptr->next;
  894. dev->stats.tx_packets++;
  895. dev->stats.tx_bytes += (skb->len);
  896. tx_reclaim_skb(lp);
  897. return NETDEV_TX_OK;
  898. }
  899. #define IP_HEADER_OFF 0
  900. #define RX_ERROR_MASK (RX_LONG | RX_ALIGN | RX_CRC | RX_LEN | \
  901. RX_FRAG | RX_ADDR | RX_DMAO | RX_PHY | RX_LATE | RX_RANGE)
  902. static void bfin_mac_rx(struct net_device *dev)
  903. {
  904. struct sk_buff *skb, *new_skb;
  905. unsigned short len;
  906. struct bfin_mac_local *lp __maybe_unused = netdev_priv(dev);
  907. #if defined(BFIN_MAC_CSUM_OFFLOAD)
  908. unsigned int i;
  909. unsigned char fcs[ETH_FCS_LEN + 1];
  910. #endif
  911. /* check if frame status word reports an error condition
  912. * we which case we simply drop the packet
  913. */
  914. if (current_rx_ptr->status.status_word & RX_ERROR_MASK) {
  915. netdev_notice(dev, "rx: receive error - packet dropped\n");
  916. dev->stats.rx_dropped++;
  917. goto out;
  918. }
  919. /* allocate a new skb for next time receive */
  920. skb = current_rx_ptr->skb;
  921. new_skb = netdev_alloc_skb(dev, PKT_BUF_SZ + NET_IP_ALIGN);
  922. if (!new_skb) {
  923. netdev_notice(dev, "rx: low on mem - packet dropped\n");
  924. dev->stats.rx_dropped++;
  925. goto out;
  926. }
  927. /* reserve 2 bytes for RXDWA padding */
  928. skb_reserve(new_skb, NET_IP_ALIGN);
  929. /* Invidate the data cache of skb->data range when it is write back
  930. * cache. It will prevent overwritting the new data from DMA
  931. */
  932. blackfin_dcache_invalidate_range((unsigned long)new_skb->head,
  933. (unsigned long)new_skb->end);
  934. current_rx_ptr->skb = new_skb;
  935. current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
  936. len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
  937. /* Deduce Ethernet FCS length from Ethernet payload length */
  938. len -= ETH_FCS_LEN;
  939. skb_put(skb, len);
  940. skb->protocol = eth_type_trans(skb, dev);
  941. bfin_rx_hwtstamp(dev, skb);
  942. #if defined(BFIN_MAC_CSUM_OFFLOAD)
  943. /* Checksum offloading only works for IPv4 packets with the standard IP header
  944. * length of 20 bytes, because the blackfin MAC checksum calculation is
  945. * based on that assumption. We must NOT use the calculated checksum if our
  946. * IP version or header break that assumption.
  947. */
  948. if (skb->data[IP_HEADER_OFF] == 0x45) {
  949. skb->csum = current_rx_ptr->status.ip_payload_csum;
  950. /*
  951. * Deduce Ethernet FCS from hardware generated IP payload checksum.
  952. * IP checksum is based on 16-bit one's complement algorithm.
  953. * To deduce a value from checksum is equal to add its inversion.
  954. * If the IP payload len is odd, the inversed FCS should also
  955. * begin from odd address and leave first byte zero.
  956. */
  957. if (skb->len % 2) {
  958. fcs[0] = 0;
  959. for (i = 0; i < ETH_FCS_LEN; i++)
  960. fcs[i + 1] = ~skb->data[skb->len + i];
  961. skb->csum = csum_partial(fcs, ETH_FCS_LEN + 1, skb->csum);
  962. } else {
  963. for (i = 0; i < ETH_FCS_LEN; i++)
  964. fcs[i] = ~skb->data[skb->len + i];
  965. skb->csum = csum_partial(fcs, ETH_FCS_LEN, skb->csum);
  966. }
  967. skb->ip_summed = CHECKSUM_COMPLETE;
  968. }
  969. #endif
  970. netif_rx(skb);
  971. dev->stats.rx_packets++;
  972. dev->stats.rx_bytes += len;
  973. out:
  974. current_rx_ptr->status.status_word = 0x00000000;
  975. current_rx_ptr = current_rx_ptr->next;
  976. }
  977. /* interrupt routine to handle rx and error signal */
  978. static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
  979. {
  980. struct net_device *dev = dev_id;
  981. int number = 0;
  982. get_one_packet:
  983. if (current_rx_ptr->status.status_word == 0) {
  984. /* no more new packet received */
  985. if (number == 0) {
  986. if (current_rx_ptr->next->status.status_word != 0) {
  987. current_rx_ptr = current_rx_ptr->next;
  988. goto real_rx;
  989. }
  990. }
  991. bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() |
  992. DMA_DONE | DMA_ERR);
  993. return IRQ_HANDLED;
  994. }
  995. real_rx:
  996. bfin_mac_rx(dev);
  997. number++;
  998. goto get_one_packet;
  999. }
  1000. #ifdef CONFIG_NET_POLL_CONTROLLER
  1001. static void bfin_mac_poll(struct net_device *dev)
  1002. {
  1003. struct bfin_mac_local *lp = netdev_priv(dev);
  1004. disable_irq(IRQ_MAC_RX);
  1005. bfin_mac_interrupt(IRQ_MAC_RX, dev);
  1006. tx_reclaim_skb(lp);
  1007. enable_irq(IRQ_MAC_RX);
  1008. }
  1009. #endif /* CONFIG_NET_POLL_CONTROLLER */
  1010. static void bfin_mac_disable(void)
  1011. {
  1012. unsigned int opmode;
  1013. opmode = bfin_read_EMAC_OPMODE();
  1014. opmode &= (~RE);
  1015. opmode &= (~TE);
  1016. /* Turn off the EMAC */
  1017. bfin_write_EMAC_OPMODE(opmode);
  1018. }
  1019. /*
  1020. * Enable Interrupts, Receive, and Transmit
  1021. */
  1022. static int bfin_mac_enable(struct phy_device *phydev)
  1023. {
  1024. int ret;
  1025. u32 opmode;
  1026. pr_debug("%s\n", __func__);
  1027. /* Set RX DMA */
  1028. bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a));
  1029. bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config);
  1030. /* Wait MII done */
  1031. ret = bfin_mdio_poll();
  1032. if (ret)
  1033. return ret;
  1034. /* We enable only RX here */
  1035. /* ASTP : Enable Automatic Pad Stripping
  1036. PR : Promiscuous Mode for test
  1037. PSF : Receive frames with total length less than 64 bytes.
  1038. FDMODE : Full Duplex Mode
  1039. LB : Internal Loopback for test
  1040. RE : Receiver Enable */
  1041. opmode = bfin_read_EMAC_OPMODE();
  1042. if (opmode & FDMODE)
  1043. opmode |= PSF;
  1044. else
  1045. opmode |= DRO | DC | PSF;
  1046. opmode |= RE;
  1047. if (phydev->interface == PHY_INTERFACE_MODE_RMII) {
  1048. opmode |= RMII; /* For Now only 100MBit are supported */
  1049. #if defined(CONFIG_BF537) || defined(CONFIG_BF536)
  1050. if (__SILICON_REVISION__ < 3) {
  1051. /*
  1052. * This isn't publicly documented (fun times!), but in
  1053. * silicon <=0.2, the RX and TX pins are clocked together.
  1054. * So in order to recv, we must enable the transmit side
  1055. * as well. This will cause a spurious TX interrupt too,
  1056. * but we can easily consume that.
  1057. */
  1058. opmode |= TE;
  1059. }
  1060. #endif
  1061. }
  1062. /* Turn on the EMAC rx */
  1063. bfin_write_EMAC_OPMODE(opmode);
  1064. return 0;
  1065. }
  1066. /* Our watchdog timed out. Called by the networking layer */
  1067. static void bfin_mac_timeout(struct net_device *dev)
  1068. {
  1069. struct bfin_mac_local *lp = netdev_priv(dev);
  1070. pr_debug("%s: %s\n", dev->name, __func__);
  1071. bfin_mac_disable();
  1072. del_timer(&lp->tx_reclaim_timer);
  1073. /* reset tx queue and free skb */
  1074. while (tx_list_head != current_tx_ptr) {
  1075. tx_list_head->desc_a.config &= ~DMAEN;
  1076. tx_list_head->status.status_word = 0;
  1077. if (tx_list_head->skb) {
  1078. dev_kfree_skb(tx_list_head->skb);
  1079. tx_list_head->skb = NULL;
  1080. }
  1081. tx_list_head = tx_list_head->next;
  1082. }
  1083. if (netif_queue_stopped(lp->ndev))
  1084. netif_wake_queue(lp->ndev);
  1085. bfin_mac_enable(lp->phydev);
  1086. /* We can accept TX packets again */
  1087. dev->trans_start = jiffies; /* prevent tx timeout */
  1088. netif_wake_queue(dev);
  1089. }
  1090. static void bfin_mac_multicast_hash(struct net_device *dev)
  1091. {
  1092. u32 emac_hashhi, emac_hashlo;
  1093. struct netdev_hw_addr *ha;
  1094. u32 crc;
  1095. emac_hashhi = emac_hashlo = 0;
  1096. netdev_for_each_mc_addr(ha, dev) {
  1097. crc = ether_crc(ETH_ALEN, ha->addr);
  1098. crc >>= 26;
  1099. if (crc & 0x20)
  1100. emac_hashhi |= 1 << (crc & 0x1f);
  1101. else
  1102. emac_hashlo |= 1 << (crc & 0x1f);
  1103. }
  1104. bfin_write_EMAC_HASHHI(emac_hashhi);
  1105. bfin_write_EMAC_HASHLO(emac_hashlo);
  1106. }
  1107. /*
  1108. * This routine will, depending on the values passed to it,
  1109. * either make it accept multicast packets, go into
  1110. * promiscuous mode (for TCPDUMP and cousins) or accept
  1111. * a select set of multicast packets
  1112. */
  1113. static void bfin_mac_set_multicast_list(struct net_device *dev)
  1114. {
  1115. u32 sysctl;
  1116. if (dev->flags & IFF_PROMISC) {
  1117. netdev_info(dev, "set promisc mode\n");
  1118. sysctl = bfin_read_EMAC_OPMODE();
  1119. sysctl |= PR;
  1120. bfin_write_EMAC_OPMODE(sysctl);
  1121. } else if (dev->flags & IFF_ALLMULTI) {
  1122. /* accept all multicast */
  1123. sysctl = bfin_read_EMAC_OPMODE();
  1124. sysctl |= PAM;
  1125. bfin_write_EMAC_OPMODE(sysctl);
  1126. } else if (!netdev_mc_empty(dev)) {
  1127. /* set up multicast hash table */
  1128. sysctl = bfin_read_EMAC_OPMODE();
  1129. sysctl |= HM;
  1130. bfin_write_EMAC_OPMODE(sysctl);
  1131. bfin_mac_multicast_hash(dev);
  1132. } else {
  1133. /* clear promisc or multicast mode */
  1134. sysctl = bfin_read_EMAC_OPMODE();
  1135. sysctl &= ~(RAF | PAM);
  1136. bfin_write_EMAC_OPMODE(sysctl);
  1137. }
  1138. }
  1139. static int bfin_mac_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1140. {
  1141. struct bfin_mac_local *lp = netdev_priv(netdev);
  1142. if (!netif_running(netdev))
  1143. return -EINVAL;
  1144. switch (cmd) {
  1145. case SIOCSHWTSTAMP:
  1146. return bfin_mac_hwtstamp_ioctl(netdev, ifr, cmd);
  1147. default:
  1148. if (lp->phydev)
  1149. return phy_mii_ioctl(lp->phydev, ifr, cmd);
  1150. else
  1151. return -EOPNOTSUPP;
  1152. }
  1153. }
  1154. /*
  1155. * this puts the device in an inactive state
  1156. */
  1157. static void bfin_mac_shutdown(struct net_device *dev)
  1158. {
  1159. /* Turn off the EMAC */
  1160. bfin_write_EMAC_OPMODE(0x00000000);
  1161. /* Turn off the EMAC RX DMA */
  1162. bfin_write_DMA1_CONFIG(0x0000);
  1163. bfin_write_DMA2_CONFIG(0x0000);
  1164. }
  1165. /*
  1166. * Open and Initialize the interface
  1167. *
  1168. * Set up everything, reset the card, etc..
  1169. */
  1170. static int bfin_mac_open(struct net_device *dev)
  1171. {
  1172. struct bfin_mac_local *lp = netdev_priv(dev);
  1173. int ret;
  1174. pr_debug("%s: %s\n", dev->name, __func__);
  1175. /*
  1176. * Check that the address is valid. If its not, refuse
  1177. * to bring the device up. The user must specify an
  1178. * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
  1179. */
  1180. if (!is_valid_ether_addr(dev->dev_addr)) {
  1181. netdev_warn(dev, "no valid ethernet hw addr\n");
  1182. return -EINVAL;
  1183. }
  1184. /* initial rx and tx list */
  1185. ret = desc_list_init(dev);
  1186. if (ret)
  1187. return ret;
  1188. phy_start(lp->phydev);
  1189. phy_write(lp->phydev, MII_BMCR, BMCR_RESET);
  1190. setup_system_regs(dev);
  1191. setup_mac_addr(dev->dev_addr);
  1192. bfin_mac_disable();
  1193. ret = bfin_mac_enable(lp->phydev);
  1194. if (ret)
  1195. return ret;
  1196. pr_debug("hardware init finished\n");
  1197. netif_start_queue(dev);
  1198. netif_carrier_on(dev);
  1199. return 0;
  1200. }
  1201. /*
  1202. * this makes the board clean up everything that it can
  1203. * and not talk to the outside world. Caused by
  1204. * an 'ifconfig ethX down'
  1205. */
  1206. static int bfin_mac_close(struct net_device *dev)
  1207. {
  1208. struct bfin_mac_local *lp = netdev_priv(dev);
  1209. pr_debug("%s: %s\n", dev->name, __func__);
  1210. netif_stop_queue(dev);
  1211. netif_carrier_off(dev);
  1212. phy_stop(lp->phydev);
  1213. phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN);
  1214. /* clear everything */
  1215. bfin_mac_shutdown(dev);
  1216. /* free the rx/tx buffers */
  1217. desc_list_free();
  1218. return 0;
  1219. }
  1220. static const struct net_device_ops bfin_mac_netdev_ops = {
  1221. .ndo_open = bfin_mac_open,
  1222. .ndo_stop = bfin_mac_close,
  1223. .ndo_start_xmit = bfin_mac_hard_start_xmit,
  1224. .ndo_set_mac_address = bfin_mac_set_mac_address,
  1225. .ndo_tx_timeout = bfin_mac_timeout,
  1226. .ndo_set_rx_mode = bfin_mac_set_multicast_list,
  1227. .ndo_do_ioctl = bfin_mac_ioctl,
  1228. .ndo_validate_addr = eth_validate_addr,
  1229. .ndo_change_mtu = eth_change_mtu,
  1230. #ifdef CONFIG_NET_POLL_CONTROLLER
  1231. .ndo_poll_controller = bfin_mac_poll,
  1232. #endif
  1233. };
  1234. static int __devinit bfin_mac_probe(struct platform_device *pdev)
  1235. {
  1236. struct net_device *ndev;
  1237. struct bfin_mac_local *lp;
  1238. struct platform_device *pd;
  1239. struct bfin_mii_bus_platform_data *mii_bus_data;
  1240. int rc;
  1241. ndev = alloc_etherdev(sizeof(struct bfin_mac_local));
  1242. if (!ndev)
  1243. return -ENOMEM;
  1244. SET_NETDEV_DEV(ndev, &pdev->dev);
  1245. platform_set_drvdata(pdev, ndev);
  1246. lp = netdev_priv(ndev);
  1247. lp->ndev = ndev;
  1248. /* Grab the MAC address in the MAC */
  1249. *(__le32 *) (&(ndev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO());
  1250. *(__le16 *) (&(ndev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI());
  1251. /* probe mac */
  1252. /*todo: how to proble? which is revision_register */
  1253. bfin_write_EMAC_ADDRLO(0x12345678);
  1254. if (bfin_read_EMAC_ADDRLO() != 0x12345678) {
  1255. dev_err(&pdev->dev, "Cannot detect Blackfin on-chip ethernet MAC controller!\n");
  1256. rc = -ENODEV;
  1257. goto out_err_probe_mac;
  1258. }
  1259. /*
  1260. * Is it valid? (Did bootloader initialize it?)
  1261. * Grab the MAC from the board somehow
  1262. * this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c
  1263. */
  1264. if (!is_valid_ether_addr(ndev->dev_addr)) {
  1265. if (bfin_get_ether_addr(ndev->dev_addr) ||
  1266. !is_valid_ether_addr(ndev->dev_addr)) {
  1267. /* Still not valid, get a random one */
  1268. netdev_warn(ndev, "Setting Ethernet MAC to a random one\n");
  1269. eth_hw_addr_random(ndev);
  1270. }
  1271. }
  1272. setup_mac_addr(ndev->dev_addr);
  1273. if (!pdev->dev.platform_data) {
  1274. dev_err(&pdev->dev, "Cannot get platform device bfin_mii_bus!\n");
  1275. rc = -ENODEV;
  1276. goto out_err_probe_mac;
  1277. }
  1278. pd = pdev->dev.platform_data;
  1279. lp->mii_bus = platform_get_drvdata(pd);
  1280. if (!lp->mii_bus) {
  1281. dev_err(&pdev->dev, "Cannot get mii_bus!\n");
  1282. rc = -ENODEV;
  1283. goto out_err_probe_mac;
  1284. }
  1285. lp->mii_bus->priv = ndev;
  1286. mii_bus_data = pd->dev.platform_data;
  1287. rc = mii_probe(ndev, mii_bus_data->phy_mode);
  1288. if (rc) {
  1289. dev_err(&pdev->dev, "MII Probe failed!\n");
  1290. goto out_err_mii_probe;
  1291. }
  1292. lp->vlan1_mask = ETH_P_8021Q | mii_bus_data->vlan1_mask;
  1293. lp->vlan2_mask = ETH_P_8021Q | mii_bus_data->vlan2_mask;
  1294. /* Fill in the fields of the device structure with ethernet values. */
  1295. ether_setup(ndev);
  1296. ndev->netdev_ops = &bfin_mac_netdev_ops;
  1297. ndev->ethtool_ops = &bfin_mac_ethtool_ops;
  1298. init_timer(&lp->tx_reclaim_timer);
  1299. lp->tx_reclaim_timer.data = (unsigned long)lp;
  1300. lp->tx_reclaim_timer.function = tx_reclaim_skb_timeout;
  1301. spin_lock_init(&lp->lock);
  1302. /* now, enable interrupts */
  1303. /* register irq handler */
  1304. rc = request_irq(IRQ_MAC_RX, bfin_mac_interrupt,
  1305. IRQF_DISABLED, "EMAC_RX", ndev);
  1306. if (rc) {
  1307. dev_err(&pdev->dev, "Cannot request Blackfin MAC RX IRQ!\n");
  1308. rc = -EBUSY;
  1309. goto out_err_request_irq;
  1310. }
  1311. rc = register_netdev(ndev);
  1312. if (rc) {
  1313. dev_err(&pdev->dev, "Cannot register net device!\n");
  1314. goto out_err_reg_ndev;
  1315. }
  1316. bfin_mac_hwtstamp_init(ndev);
  1317. /* now, print out the card info, in a short format.. */
  1318. netdev_info(ndev, "%s, Version %s\n", DRV_DESC, DRV_VERSION);
  1319. return 0;
  1320. out_err_reg_ndev:
  1321. free_irq(IRQ_MAC_RX, ndev);
  1322. out_err_request_irq:
  1323. out_err_mii_probe:
  1324. mdiobus_unregister(lp->mii_bus);
  1325. mdiobus_free(lp->mii_bus);
  1326. out_err_probe_mac:
  1327. platform_set_drvdata(pdev, NULL);
  1328. free_netdev(ndev);
  1329. return rc;
  1330. }
  1331. static int __devexit bfin_mac_remove(struct platform_device *pdev)
  1332. {
  1333. struct net_device *ndev = platform_get_drvdata(pdev);
  1334. struct bfin_mac_local *lp = netdev_priv(ndev);
  1335. platform_set_drvdata(pdev, NULL);
  1336. lp->mii_bus->priv = NULL;
  1337. unregister_netdev(ndev);
  1338. free_irq(IRQ_MAC_RX, ndev);
  1339. free_netdev(ndev);
  1340. return 0;
  1341. }
  1342. #ifdef CONFIG_PM
  1343. static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg)
  1344. {
  1345. struct net_device *net_dev = platform_get_drvdata(pdev);
  1346. struct bfin_mac_local *lp = netdev_priv(net_dev);
  1347. if (lp->wol) {
  1348. bfin_write_EMAC_OPMODE((bfin_read_EMAC_OPMODE() & ~TE) | RE);
  1349. bfin_write_EMAC_WKUP_CTL(MPKE);
  1350. enable_irq_wake(IRQ_MAC_WAKEDET);
  1351. } else {
  1352. if (netif_running(net_dev))
  1353. bfin_mac_close(net_dev);
  1354. }
  1355. return 0;
  1356. }
  1357. static int bfin_mac_resume(struct platform_device *pdev)
  1358. {
  1359. struct net_device *net_dev = platform_get_drvdata(pdev);
  1360. struct bfin_mac_local *lp = netdev_priv(net_dev);
  1361. if (lp->wol) {
  1362. bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
  1363. bfin_write_EMAC_WKUP_CTL(0);
  1364. disable_irq_wake(IRQ_MAC_WAKEDET);
  1365. } else {
  1366. if (netif_running(net_dev))
  1367. bfin_mac_open(net_dev);
  1368. }
  1369. return 0;
  1370. }
  1371. #else
  1372. #define bfin_mac_suspend NULL
  1373. #define bfin_mac_resume NULL
  1374. #endif /* CONFIG_PM */
  1375. static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
  1376. {
  1377. struct mii_bus *miibus;
  1378. struct bfin_mii_bus_platform_data *mii_bus_pd;
  1379. const unsigned short *pin_req;
  1380. int rc, i;
  1381. mii_bus_pd = dev_get_platdata(&pdev->dev);
  1382. if (!mii_bus_pd) {
  1383. dev_err(&pdev->dev, "No peripherals in platform data!\n");
  1384. return -EINVAL;
  1385. }
  1386. /*
  1387. * We are setting up a network card,
  1388. * so set the GPIO pins to Ethernet mode
  1389. */
  1390. pin_req = mii_bus_pd->mac_peripherals;
  1391. rc = peripheral_request_list(pin_req, KBUILD_MODNAME);
  1392. if (rc) {
  1393. dev_err(&pdev->dev, "Requesting peripherals failed!\n");
  1394. return rc;
  1395. }
  1396. rc = -ENOMEM;
  1397. miibus = mdiobus_alloc();
  1398. if (miibus == NULL)
  1399. goto out_err_alloc;
  1400. miibus->read = bfin_mdiobus_read;
  1401. miibus->write = bfin_mdiobus_write;
  1402. miibus->reset = bfin_mdiobus_reset;
  1403. miibus->parent = &pdev->dev;
  1404. miibus->name = "bfin_mii_bus";
  1405. miibus->phy_mask = mii_bus_pd->phy_mask;
  1406. snprintf(miibus->id, MII_BUS_ID_SIZE, "%s-%x",
  1407. pdev->name, pdev->id);
  1408. miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
  1409. if (!miibus->irq)
  1410. goto out_err_irq_alloc;
  1411. for (i = rc; i < PHY_MAX_ADDR; ++i)
  1412. miibus->irq[i] = PHY_POLL;
  1413. rc = clamp(mii_bus_pd->phydev_number, 0, PHY_MAX_ADDR);
  1414. if (rc != mii_bus_pd->phydev_number)
  1415. dev_err(&pdev->dev, "Invalid number (%i) of phydevs\n",
  1416. mii_bus_pd->phydev_number);
  1417. for (i = 0; i < rc; ++i) {
  1418. unsigned short phyaddr = mii_bus_pd->phydev_data[i].addr;
  1419. if (phyaddr < PHY_MAX_ADDR)
  1420. miibus->irq[phyaddr] = mii_bus_pd->phydev_data[i].irq;
  1421. else
  1422. dev_err(&pdev->dev,
  1423. "Invalid PHY address %i for phydev %i\n",
  1424. phyaddr, i);
  1425. }
  1426. rc = mdiobus_register(miibus);
  1427. if (rc) {
  1428. dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
  1429. goto out_err_mdiobus_register;
  1430. }
  1431. platform_set_drvdata(pdev, miibus);
  1432. return 0;
  1433. out_err_mdiobus_register:
  1434. kfree(miibus->irq);
  1435. out_err_irq_alloc:
  1436. mdiobus_free(miibus);
  1437. out_err_alloc:
  1438. peripheral_free_list(pin_req);
  1439. return rc;
  1440. }
  1441. static int __devexit bfin_mii_bus_remove(struct platform_device *pdev)
  1442. {
  1443. struct mii_bus *miibus = platform_get_drvdata(pdev);
  1444. struct bfin_mii_bus_platform_data *mii_bus_pd =
  1445. dev_get_platdata(&pdev->dev);
  1446. platform_set_drvdata(pdev, NULL);
  1447. mdiobus_unregister(miibus);
  1448. kfree(miibus->irq);
  1449. mdiobus_free(miibus);
  1450. peripheral_free_list(mii_bus_pd->mac_peripherals);
  1451. return 0;
  1452. }
  1453. static struct platform_driver bfin_mii_bus_driver = {
  1454. .probe = bfin_mii_bus_probe,
  1455. .remove = __devexit_p(bfin_mii_bus_remove),
  1456. .driver = {
  1457. .name = "bfin_mii_bus",
  1458. .owner = THIS_MODULE,
  1459. },
  1460. };
  1461. static struct platform_driver bfin_mac_driver = {
  1462. .probe = bfin_mac_probe,
  1463. .remove = __devexit_p(bfin_mac_remove),
  1464. .resume = bfin_mac_resume,
  1465. .suspend = bfin_mac_suspend,
  1466. .driver = {
  1467. .name = KBUILD_MODNAME,
  1468. .owner = THIS_MODULE,
  1469. },
  1470. };
  1471. static int __init bfin_mac_init(void)
  1472. {
  1473. int ret;
  1474. ret = platform_driver_register(&bfin_mii_bus_driver);
  1475. if (!ret)
  1476. return platform_driver_register(&bfin_mac_driver);
  1477. return -ENODEV;
  1478. }
  1479. module_init(bfin_mac_init);
  1480. static void __exit bfin_mac_cleanup(void)
  1481. {
  1482. platform_driver_unregister(&bfin_mac_driver);
  1483. platform_driver_unregister(&bfin_mii_bus_driver);
  1484. }
  1485. module_exit(bfin_mac_cleanup);