bfin_mac.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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(void)
  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 = dev_alloc_skb(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. setup_mac_addr(dev->dev_addr);
  524. return 0;
  525. }
  526. #ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
  527. #define bfin_mac_hwtstamp_is_none(cfg) ((cfg) == HWTSTAMP_FILTER_NONE)
  528. static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
  529. struct ifreq *ifr, int cmd)
  530. {
  531. struct hwtstamp_config config;
  532. struct bfin_mac_local *lp = netdev_priv(netdev);
  533. u16 ptpctl;
  534. u32 ptpfv1, ptpfv2, ptpfv3, ptpfoff;
  535. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  536. return -EFAULT;
  537. pr_debug("%s config flag:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
  538. __func__, config.flags, config.tx_type, config.rx_filter);
  539. /* reserved for future extensions */
  540. if (config.flags)
  541. return -EINVAL;
  542. if ((config.tx_type != HWTSTAMP_TX_OFF) &&
  543. (config.tx_type != HWTSTAMP_TX_ON))
  544. return -ERANGE;
  545. ptpctl = bfin_read_EMAC_PTP_CTL();
  546. switch (config.rx_filter) {
  547. case HWTSTAMP_FILTER_NONE:
  548. /*
  549. * Dont allow any timestamping
  550. */
  551. ptpfv3 = 0xFFFFFFFF;
  552. bfin_write_EMAC_PTP_FV3(ptpfv3);
  553. break;
  554. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  555. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  556. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  557. /*
  558. * Clear the five comparison mask bits (bits[12:8]) in EMAC_PTP_CTL)
  559. * to enable all the field matches.
  560. */
  561. ptpctl &= ~0x1F00;
  562. bfin_write_EMAC_PTP_CTL(ptpctl);
  563. /*
  564. * Keep the default values of the EMAC_PTP_FOFF register.
  565. */
  566. ptpfoff = 0x4A24170C;
  567. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  568. /*
  569. * Keep the default values of the EMAC_PTP_FV1 and EMAC_PTP_FV2
  570. * registers.
  571. */
  572. ptpfv1 = 0x11040800;
  573. bfin_write_EMAC_PTP_FV1(ptpfv1);
  574. ptpfv2 = 0x0140013F;
  575. bfin_write_EMAC_PTP_FV2(ptpfv2);
  576. /*
  577. * The default value (0xFFFC) allows the timestamping of both
  578. * received Sync messages and Delay_Req messages.
  579. */
  580. ptpfv3 = 0xFFFFFFFC;
  581. bfin_write_EMAC_PTP_FV3(ptpfv3);
  582. config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  583. break;
  584. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  585. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  586. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  587. /* Clear all five comparison mask bits (bits[12:8]) in the
  588. * EMAC_PTP_CTL register to enable all the field matches.
  589. */
  590. ptpctl &= ~0x1F00;
  591. bfin_write_EMAC_PTP_CTL(ptpctl);
  592. /*
  593. * Keep the default values of the EMAC_PTP_FOFF register, except set
  594. * the PTPCOF field to 0x2A.
  595. */
  596. ptpfoff = 0x2A24170C;
  597. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  598. /*
  599. * Keep the default values of the EMAC_PTP_FV1 and EMAC_PTP_FV2
  600. * registers.
  601. */
  602. ptpfv1 = 0x11040800;
  603. bfin_write_EMAC_PTP_FV1(ptpfv1);
  604. ptpfv2 = 0x0140013F;
  605. bfin_write_EMAC_PTP_FV2(ptpfv2);
  606. /*
  607. * To allow the timestamping of Pdelay_Req and Pdelay_Resp, set
  608. * the value to 0xFFF0.
  609. */
  610. ptpfv3 = 0xFFFFFFF0;
  611. bfin_write_EMAC_PTP_FV3(ptpfv3);
  612. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  613. break;
  614. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  615. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  616. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  617. /*
  618. * Clear bits 8 and 12 of the EMAC_PTP_CTL register to enable only the
  619. * EFTM and PTPCM field comparison.
  620. */
  621. ptpctl &= ~0x1100;
  622. bfin_write_EMAC_PTP_CTL(ptpctl);
  623. /*
  624. * Keep the default values of all the fields of the EMAC_PTP_FOFF
  625. * register, except set the PTPCOF field to 0x0E.
  626. */
  627. ptpfoff = 0x0E24170C;
  628. bfin_write_EMAC_PTP_FOFF(ptpfoff);
  629. /*
  630. * Program bits [15:0] of the EMAC_PTP_FV1 register to 0x88F7, which
  631. * corresponds to PTP messages on the MAC layer.
  632. */
  633. ptpfv1 = 0x110488F7;
  634. bfin_write_EMAC_PTP_FV1(ptpfv1);
  635. ptpfv2 = 0x0140013F;
  636. bfin_write_EMAC_PTP_FV2(ptpfv2);
  637. /*
  638. * To allow the timestamping of Pdelay_Req and Pdelay_Resp
  639. * messages, set the value to 0xFFF0.
  640. */
  641. ptpfv3 = 0xFFFFFFF0;
  642. bfin_write_EMAC_PTP_FV3(ptpfv3);
  643. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  644. break;
  645. default:
  646. return -ERANGE;
  647. }
  648. if (config.tx_type == HWTSTAMP_TX_OFF &&
  649. bfin_mac_hwtstamp_is_none(config.rx_filter)) {
  650. ptpctl &= ~PTP_EN;
  651. bfin_write_EMAC_PTP_CTL(ptpctl);
  652. SSYNC();
  653. } else {
  654. ptpctl |= PTP_EN;
  655. bfin_write_EMAC_PTP_CTL(ptpctl);
  656. /*
  657. * clear any existing timestamp
  658. */
  659. bfin_read_EMAC_PTP_RXSNAPLO();
  660. bfin_read_EMAC_PTP_RXSNAPHI();
  661. bfin_read_EMAC_PTP_TXSNAPLO();
  662. bfin_read_EMAC_PTP_TXSNAPHI();
  663. /*
  664. * Set registers so that rollover occurs soon to test this.
  665. */
  666. bfin_write_EMAC_PTP_TIMELO(0x00000000);
  667. bfin_write_EMAC_PTP_TIMEHI(0xFF800000);
  668. SSYNC();
  669. lp->compare.last_update = 0;
  670. timecounter_init(&lp->clock,
  671. &lp->cycles,
  672. ktime_to_ns(ktime_get_real()));
  673. timecompare_update(&lp->compare, 0);
  674. }
  675. lp->stamp_cfg = config;
  676. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  677. -EFAULT : 0;
  678. }
  679. static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompare *cmp)
  680. {
  681. ktime_t sys = ktime_get_real();
  682. pr_debug("%s %s hardware:%d,%d transform system:%d,%d system:%d,%d, cmp:%lld, %lld\n",
  683. __func__, s, hw->tv.sec, hw->tv.nsec, ts->tv.sec, ts->tv.nsec, sys.tv.sec,
  684. sys.tv.nsec, cmp->offset, cmp->skew);
  685. }
  686. static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
  687. {
  688. struct bfin_mac_local *lp = netdev_priv(netdev);
  689. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
  690. int timeout_cnt = MAX_TIMEOUT_CNT;
  691. /* When doing time stamping, keep the connection to the socket
  692. * a while longer
  693. */
  694. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  695. /*
  696. * The timestamping is done at the EMAC module's MII/RMII interface
  697. * when the module sees the Start of Frame of an event message packet. This
  698. * interface is the closest possible place to the physical Ethernet transmission
  699. * medium, providing the best timing accuracy.
  700. */
  701. while ((!(bfin_read_EMAC_PTP_ISTAT() & TXTL)) && (--timeout_cnt))
  702. udelay(1);
  703. if (timeout_cnt == 0)
  704. netdev_err(netdev, "timestamp the TX packet failed\n");
  705. else {
  706. struct skb_shared_hwtstamps shhwtstamps;
  707. u64 ns;
  708. u64 regval;
  709. regval = bfin_read_EMAC_PTP_TXSNAPLO();
  710. regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
  711. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  712. ns = timecounter_cyc2time(&lp->clock,
  713. regval);
  714. timecompare_update(&lp->compare, ns);
  715. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  716. shhwtstamps.syststamp =
  717. timecompare_transform(&lp->compare, ns);
  718. skb_tstamp_tx(skb, &shhwtstamps);
  719. bfin_dump_hwtamp("TX", &shhwtstamps.hwtstamp, &shhwtstamps.syststamp, &lp->compare);
  720. }
  721. }
  722. }
  723. static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
  724. {
  725. struct bfin_mac_local *lp = netdev_priv(netdev);
  726. u32 valid;
  727. u64 regval, ns;
  728. struct skb_shared_hwtstamps *shhwtstamps;
  729. if (bfin_mac_hwtstamp_is_none(lp->stamp_cfg.rx_filter))
  730. return;
  731. valid = bfin_read_EMAC_PTP_ISTAT() & RXEL;
  732. if (!valid)
  733. return;
  734. shhwtstamps = skb_hwtstamps(skb);
  735. regval = bfin_read_EMAC_PTP_RXSNAPLO();
  736. regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
  737. ns = timecounter_cyc2time(&lp->clock, regval);
  738. timecompare_update(&lp->compare, ns);
  739. memset(shhwtstamps, 0, sizeof(*shhwtstamps));
  740. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  741. shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
  742. bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
  743. }
  744. /*
  745. * bfin_read_clock - read raw cycle counter (to be used by time counter)
  746. */
  747. static cycle_t bfin_read_clock(const struct cyclecounter *tc)
  748. {
  749. u64 stamp;
  750. stamp = bfin_read_EMAC_PTP_TIMELO();
  751. stamp |= (u64)bfin_read_EMAC_PTP_TIMEHI() << 32ULL;
  752. return stamp;
  753. }
  754. #define PTP_CLK 25000000
  755. static void bfin_mac_hwtstamp_init(struct net_device *netdev)
  756. {
  757. struct bfin_mac_local *lp = netdev_priv(netdev);
  758. u64 append;
  759. /* Initialize hardware timer */
  760. append = PTP_CLK * (1ULL << 32);
  761. do_div(append, get_sclk());
  762. bfin_write_EMAC_PTP_ADDEND((u32)append);
  763. memset(&lp->cycles, 0, sizeof(lp->cycles));
  764. lp->cycles.read = bfin_read_clock;
  765. lp->cycles.mask = CLOCKSOURCE_MASK(64);
  766. lp->cycles.mult = 1000000000 / PTP_CLK;
  767. lp->cycles.shift = 0;
  768. /* Synchronize our NIC clock against system wall clock */
  769. memset(&lp->compare, 0, sizeof(lp->compare));
  770. lp->compare.source = &lp->clock;
  771. lp->compare.target = ktime_get_real;
  772. lp->compare.num_samples = 10;
  773. /* Initialize hwstamp config */
  774. lp->stamp_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
  775. lp->stamp_cfg.tx_type = HWTSTAMP_TX_OFF;
  776. }
  777. #else
  778. # define bfin_mac_hwtstamp_is_none(cfg) 0
  779. # define bfin_mac_hwtstamp_init(dev)
  780. # define bfin_mac_hwtstamp_ioctl(dev, ifr, cmd) (-EOPNOTSUPP)
  781. # define bfin_rx_hwtstamp(dev, skb)
  782. # define bfin_tx_hwtstamp(dev, skb)
  783. #endif
  784. static inline void _tx_reclaim_skb(void)
  785. {
  786. do {
  787. tx_list_head->desc_a.config &= ~DMAEN;
  788. tx_list_head->status.status_word = 0;
  789. if (tx_list_head->skb) {
  790. dev_kfree_skb(tx_list_head->skb);
  791. tx_list_head->skb = NULL;
  792. }
  793. tx_list_head = tx_list_head->next;
  794. } while (tx_list_head->status.status_word != 0);
  795. }
  796. static void tx_reclaim_skb(struct bfin_mac_local *lp)
  797. {
  798. int timeout_cnt = MAX_TIMEOUT_CNT;
  799. if (tx_list_head->status.status_word != 0)
  800. _tx_reclaim_skb();
  801. if (current_tx_ptr->next == tx_list_head) {
  802. while (tx_list_head->status.status_word == 0) {
  803. /* slow down polling to avoid too many queue stop. */
  804. udelay(10);
  805. /* reclaim skb if DMA is not running. */
  806. if (!(bfin_read_DMA2_IRQ_STATUS() & DMA_RUN))
  807. break;
  808. if (timeout_cnt-- < 0)
  809. break;
  810. }
  811. if (timeout_cnt >= 0)
  812. _tx_reclaim_skb();
  813. else
  814. netif_stop_queue(lp->ndev);
  815. }
  816. if (current_tx_ptr->next != tx_list_head &&
  817. netif_queue_stopped(lp->ndev))
  818. netif_wake_queue(lp->ndev);
  819. if (tx_list_head != current_tx_ptr) {
  820. /* shorten the timer interval if tx queue is stopped */
  821. if (netif_queue_stopped(lp->ndev))
  822. lp->tx_reclaim_timer.expires =
  823. jiffies + (TX_RECLAIM_JIFFIES >> 4);
  824. else
  825. lp->tx_reclaim_timer.expires =
  826. jiffies + TX_RECLAIM_JIFFIES;
  827. mod_timer(&lp->tx_reclaim_timer,
  828. lp->tx_reclaim_timer.expires);
  829. }
  830. return;
  831. }
  832. static void tx_reclaim_skb_timeout(unsigned long lp)
  833. {
  834. tx_reclaim_skb((struct bfin_mac_local *)lp);
  835. }
  836. static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
  837. struct net_device *dev)
  838. {
  839. struct bfin_mac_local *lp = netdev_priv(dev);
  840. u16 *data;
  841. u32 data_align = (unsigned long)(skb->data) & 0x3;
  842. current_tx_ptr->skb = skb;
  843. if (data_align == 0x2) {
  844. /* move skb->data to current_tx_ptr payload */
  845. data = (u16 *)(skb->data) - 1;
  846. *data = (u16)(skb->len);
  847. /*
  848. * When transmitting an Ethernet packet, the PTP_TSYNC module requires
  849. * a DMA_Length_Word field associated with the packet. The lower 12 bits
  850. * of this field are the length of the packet payload in bytes and the higher
  851. * 4 bits are the timestamping enable field.
  852. */
  853. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
  854. *data |= 0x1000;
  855. current_tx_ptr->desc_a.start_addr = (u32)data;
  856. /* this is important! */
  857. blackfin_dcache_flush_range((u32)data,
  858. (u32)((u8 *)data + skb->len + 4));
  859. } else {
  860. *((u16 *)(current_tx_ptr->packet)) = (u16)(skb->len);
  861. /* enable timestamping for the sent packet */
  862. if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
  863. *((u16 *)(current_tx_ptr->packet)) |= 0x1000;
  864. memcpy((u8 *)(current_tx_ptr->packet + 2), skb->data,
  865. skb->len);
  866. current_tx_ptr->desc_a.start_addr =
  867. (u32)current_tx_ptr->packet;
  868. blackfin_dcache_flush_range(
  869. (u32)current_tx_ptr->packet,
  870. (u32)(current_tx_ptr->packet + skb->len + 2));
  871. }
  872. /* make sure the internal data buffers in the core are drained
  873. * so that the DMA descriptors are completely written when the
  874. * DMA engine goes to fetch them below
  875. */
  876. SSYNC();
  877. /* always clear status buffer before start tx dma */
  878. current_tx_ptr->status.status_word = 0;
  879. /* enable this packet's dma */
  880. current_tx_ptr->desc_a.config |= DMAEN;
  881. /* tx dma is running, just return */
  882. if (bfin_read_DMA2_IRQ_STATUS() & DMA_RUN)
  883. goto out;
  884. /* tx dma is not running */
  885. bfin_write_DMA2_NEXT_DESC_PTR(&(current_tx_ptr->desc_a));
  886. /* dma enabled, read from memory, size is 6 */
  887. bfin_write_DMA2_CONFIG(current_tx_ptr->desc_a.config);
  888. /* Turn on the EMAC tx */
  889. bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
  890. out:
  891. bfin_tx_hwtstamp(dev, skb);
  892. current_tx_ptr = current_tx_ptr->next;
  893. dev->stats.tx_packets++;
  894. dev->stats.tx_bytes += (skb->len);
  895. tx_reclaim_skb(lp);
  896. return NETDEV_TX_OK;
  897. }
  898. #define IP_HEADER_OFF 0
  899. #define RX_ERROR_MASK (RX_LONG | RX_ALIGN | RX_CRC | RX_LEN | \
  900. RX_FRAG | RX_ADDR | RX_DMAO | RX_PHY | RX_LATE | RX_RANGE)
  901. static void bfin_mac_rx(struct net_device *dev)
  902. {
  903. struct sk_buff *skb, *new_skb;
  904. unsigned short len;
  905. struct bfin_mac_local *lp __maybe_unused = netdev_priv(dev);
  906. #if defined(BFIN_MAC_CSUM_OFFLOAD)
  907. unsigned int i;
  908. unsigned char fcs[ETH_FCS_LEN + 1];
  909. #endif
  910. /* check if frame status word reports an error condition
  911. * we which case we simply drop the packet
  912. */
  913. if (current_rx_ptr->status.status_word & RX_ERROR_MASK) {
  914. netdev_notice(dev, "rx: receive error - packet dropped\n");
  915. dev->stats.rx_dropped++;
  916. goto out;
  917. }
  918. /* allocate a new skb for next time receive */
  919. skb = current_rx_ptr->skb;
  920. new_skb = dev_alloc_skb(PKT_BUF_SZ + NET_IP_ALIGN);
  921. if (!new_skb) {
  922. netdev_notice(dev, "rx: low on mem - packet dropped\n");
  923. dev->stats.rx_dropped++;
  924. goto out;
  925. }
  926. /* reserve 2 bytes for RXDWA padding */
  927. skb_reserve(new_skb, NET_IP_ALIGN);
  928. /* Invidate the data cache of skb->data range when it is write back
  929. * cache. It will prevent overwritting the new data from DMA
  930. */
  931. blackfin_dcache_invalidate_range((unsigned long)new_skb->head,
  932. (unsigned long)new_skb->end);
  933. current_rx_ptr->skb = new_skb;
  934. current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2;
  935. len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN);
  936. /* Deduce Ethernet FCS length from Ethernet payload length */
  937. len -= ETH_FCS_LEN;
  938. skb_put(skb, len);
  939. skb->protocol = eth_type_trans(skb, dev);
  940. bfin_rx_hwtstamp(dev, skb);
  941. #if defined(BFIN_MAC_CSUM_OFFLOAD)
  942. /* Checksum offloading only works for IPv4 packets with the standard IP header
  943. * length of 20 bytes, because the blackfin MAC checksum calculation is
  944. * based on that assumption. We must NOT use the calculated checksum if our
  945. * IP version or header break that assumption.
  946. */
  947. if (skb->data[IP_HEADER_OFF] == 0x45) {
  948. skb->csum = current_rx_ptr->status.ip_payload_csum;
  949. /*
  950. * Deduce Ethernet FCS from hardware generated IP payload checksum.
  951. * IP checksum is based on 16-bit one's complement algorithm.
  952. * To deduce a value from checksum is equal to add its inversion.
  953. * If the IP payload len is odd, the inversed FCS should also
  954. * begin from odd address and leave first byte zero.
  955. */
  956. if (skb->len % 2) {
  957. fcs[0] = 0;
  958. for (i = 0; i < ETH_FCS_LEN; i++)
  959. fcs[i + 1] = ~skb->data[skb->len + i];
  960. skb->csum = csum_partial(fcs, ETH_FCS_LEN + 1, skb->csum);
  961. } else {
  962. for (i = 0; i < ETH_FCS_LEN; i++)
  963. fcs[i] = ~skb->data[skb->len + i];
  964. skb->csum = csum_partial(fcs, ETH_FCS_LEN, skb->csum);
  965. }
  966. skb->ip_summed = CHECKSUM_COMPLETE;
  967. }
  968. #endif
  969. netif_rx(skb);
  970. dev->stats.rx_packets++;
  971. dev->stats.rx_bytes += len;
  972. out:
  973. current_rx_ptr->status.status_word = 0x00000000;
  974. current_rx_ptr = current_rx_ptr->next;
  975. }
  976. /* interrupt routine to handle rx and error signal */
  977. static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
  978. {
  979. struct net_device *dev = dev_id;
  980. int number = 0;
  981. get_one_packet:
  982. if (current_rx_ptr->status.status_word == 0) {
  983. /* no more new packet received */
  984. if (number == 0) {
  985. if (current_rx_ptr->next->status.status_word != 0) {
  986. current_rx_ptr = current_rx_ptr->next;
  987. goto real_rx;
  988. }
  989. }
  990. bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() |
  991. DMA_DONE | DMA_ERR);
  992. return IRQ_HANDLED;
  993. }
  994. real_rx:
  995. bfin_mac_rx(dev);
  996. number++;
  997. goto get_one_packet;
  998. }
  999. #ifdef CONFIG_NET_POLL_CONTROLLER
  1000. static void bfin_mac_poll(struct net_device *dev)
  1001. {
  1002. struct bfin_mac_local *lp = netdev_priv(dev);
  1003. disable_irq(IRQ_MAC_RX);
  1004. bfin_mac_interrupt(IRQ_MAC_RX, dev);
  1005. tx_reclaim_skb(lp);
  1006. enable_irq(IRQ_MAC_RX);
  1007. }
  1008. #endif /* CONFIG_NET_POLL_CONTROLLER */
  1009. static void bfin_mac_disable(void)
  1010. {
  1011. unsigned int opmode;
  1012. opmode = bfin_read_EMAC_OPMODE();
  1013. opmode &= (~RE);
  1014. opmode &= (~TE);
  1015. /* Turn off the EMAC */
  1016. bfin_write_EMAC_OPMODE(opmode);
  1017. }
  1018. /*
  1019. * Enable Interrupts, Receive, and Transmit
  1020. */
  1021. static int bfin_mac_enable(struct phy_device *phydev)
  1022. {
  1023. int ret;
  1024. u32 opmode;
  1025. pr_debug("%s\n", __func__);
  1026. /* Set RX DMA */
  1027. bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a));
  1028. bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config);
  1029. /* Wait MII done */
  1030. ret = bfin_mdio_poll();
  1031. if (ret)
  1032. return ret;
  1033. /* We enable only RX here */
  1034. /* ASTP : Enable Automatic Pad Stripping
  1035. PR : Promiscuous Mode for test
  1036. PSF : Receive frames with total length less than 64 bytes.
  1037. FDMODE : Full Duplex Mode
  1038. LB : Internal Loopback for test
  1039. RE : Receiver Enable */
  1040. opmode = bfin_read_EMAC_OPMODE();
  1041. if (opmode & FDMODE)
  1042. opmode |= PSF;
  1043. else
  1044. opmode |= DRO | DC | PSF;
  1045. opmode |= RE;
  1046. if (phydev->interface == PHY_INTERFACE_MODE_RMII) {
  1047. opmode |= RMII; /* For Now only 100MBit are supported */
  1048. #if defined(CONFIG_BF537) || defined(CONFIG_BF536)
  1049. if (__SILICON_REVISION__ < 3) {
  1050. /*
  1051. * This isn't publicly documented (fun times!), but in
  1052. * silicon <=0.2, the RX and TX pins are clocked together.
  1053. * So in order to recv, we must enable the transmit side
  1054. * as well. This will cause a spurious TX interrupt too,
  1055. * but we can easily consume that.
  1056. */
  1057. opmode |= TE;
  1058. }
  1059. #endif
  1060. }
  1061. /* Turn on the EMAC rx */
  1062. bfin_write_EMAC_OPMODE(opmode);
  1063. return 0;
  1064. }
  1065. /* Our watchdog timed out. Called by the networking layer */
  1066. static void bfin_mac_timeout(struct net_device *dev)
  1067. {
  1068. struct bfin_mac_local *lp = netdev_priv(dev);
  1069. pr_debug("%s: %s\n", dev->name, __func__);
  1070. bfin_mac_disable();
  1071. del_timer(&lp->tx_reclaim_timer);
  1072. /* reset tx queue and free skb */
  1073. while (tx_list_head != current_tx_ptr) {
  1074. tx_list_head->desc_a.config &= ~DMAEN;
  1075. tx_list_head->status.status_word = 0;
  1076. if (tx_list_head->skb) {
  1077. dev_kfree_skb(tx_list_head->skb);
  1078. tx_list_head->skb = NULL;
  1079. }
  1080. tx_list_head = tx_list_head->next;
  1081. }
  1082. if (netif_queue_stopped(lp->ndev))
  1083. netif_wake_queue(lp->ndev);
  1084. bfin_mac_enable(lp->phydev);
  1085. /* We can accept TX packets again */
  1086. dev->trans_start = jiffies; /* prevent tx timeout */
  1087. netif_wake_queue(dev);
  1088. }
  1089. static void bfin_mac_multicast_hash(struct net_device *dev)
  1090. {
  1091. u32 emac_hashhi, emac_hashlo;
  1092. struct netdev_hw_addr *ha;
  1093. u32 crc;
  1094. emac_hashhi = emac_hashlo = 0;
  1095. netdev_for_each_mc_addr(ha, dev) {
  1096. crc = ether_crc(ETH_ALEN, ha->addr);
  1097. crc >>= 26;
  1098. if (crc & 0x20)
  1099. emac_hashhi |= 1 << (crc & 0x1f);
  1100. else
  1101. emac_hashlo |= 1 << (crc & 0x1f);
  1102. }
  1103. bfin_write_EMAC_HASHHI(emac_hashhi);
  1104. bfin_write_EMAC_HASHLO(emac_hashlo);
  1105. }
  1106. /*
  1107. * This routine will, depending on the values passed to it,
  1108. * either make it accept multicast packets, go into
  1109. * promiscuous mode (for TCPDUMP and cousins) or accept
  1110. * a select set of multicast packets
  1111. */
  1112. static void bfin_mac_set_multicast_list(struct net_device *dev)
  1113. {
  1114. u32 sysctl;
  1115. if (dev->flags & IFF_PROMISC) {
  1116. netdev_info(dev, "set promisc mode\n");
  1117. sysctl = bfin_read_EMAC_OPMODE();
  1118. sysctl |= PR;
  1119. bfin_write_EMAC_OPMODE(sysctl);
  1120. } else if (dev->flags & IFF_ALLMULTI) {
  1121. /* accept all multicast */
  1122. sysctl = bfin_read_EMAC_OPMODE();
  1123. sysctl |= PAM;
  1124. bfin_write_EMAC_OPMODE(sysctl);
  1125. } else if (!netdev_mc_empty(dev)) {
  1126. /* set up multicast hash table */
  1127. sysctl = bfin_read_EMAC_OPMODE();
  1128. sysctl |= HM;
  1129. bfin_write_EMAC_OPMODE(sysctl);
  1130. bfin_mac_multicast_hash(dev);
  1131. } else {
  1132. /* clear promisc or multicast mode */
  1133. sysctl = bfin_read_EMAC_OPMODE();
  1134. sysctl &= ~(RAF | PAM);
  1135. bfin_write_EMAC_OPMODE(sysctl);
  1136. }
  1137. }
  1138. static int bfin_mac_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1139. {
  1140. struct bfin_mac_local *lp = netdev_priv(netdev);
  1141. if (!netif_running(netdev))
  1142. return -EINVAL;
  1143. switch (cmd) {
  1144. case SIOCSHWTSTAMP:
  1145. return bfin_mac_hwtstamp_ioctl(netdev, ifr, cmd);
  1146. default:
  1147. if (lp->phydev)
  1148. return phy_mii_ioctl(lp->phydev, ifr, cmd);
  1149. else
  1150. return -EOPNOTSUPP;
  1151. }
  1152. }
  1153. /*
  1154. * this puts the device in an inactive state
  1155. */
  1156. static void bfin_mac_shutdown(struct net_device *dev)
  1157. {
  1158. /* Turn off the EMAC */
  1159. bfin_write_EMAC_OPMODE(0x00000000);
  1160. /* Turn off the EMAC RX DMA */
  1161. bfin_write_DMA1_CONFIG(0x0000);
  1162. bfin_write_DMA2_CONFIG(0x0000);
  1163. }
  1164. /*
  1165. * Open and Initialize the interface
  1166. *
  1167. * Set up everything, reset the card, etc..
  1168. */
  1169. static int bfin_mac_open(struct net_device *dev)
  1170. {
  1171. struct bfin_mac_local *lp = netdev_priv(dev);
  1172. int ret;
  1173. pr_debug("%s: %s\n", dev->name, __func__);
  1174. /*
  1175. * Check that the address is valid. If its not, refuse
  1176. * to bring the device up. The user must specify an
  1177. * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
  1178. */
  1179. if (!is_valid_ether_addr(dev->dev_addr)) {
  1180. netdev_warn(dev, "no valid ethernet hw addr\n");
  1181. return -EINVAL;
  1182. }
  1183. /* initial rx and tx list */
  1184. ret = desc_list_init();
  1185. if (ret)
  1186. return ret;
  1187. phy_start(lp->phydev);
  1188. phy_write(lp->phydev, MII_BMCR, BMCR_RESET);
  1189. setup_system_regs(dev);
  1190. setup_mac_addr(dev->dev_addr);
  1191. bfin_mac_disable();
  1192. ret = bfin_mac_enable(lp->phydev);
  1193. if (ret)
  1194. return ret;
  1195. pr_debug("hardware init finished\n");
  1196. netif_start_queue(dev);
  1197. netif_carrier_on(dev);
  1198. return 0;
  1199. }
  1200. /*
  1201. * this makes the board clean up everything that it can
  1202. * and not talk to the outside world. Caused by
  1203. * an 'ifconfig ethX down'
  1204. */
  1205. static int bfin_mac_close(struct net_device *dev)
  1206. {
  1207. struct bfin_mac_local *lp = netdev_priv(dev);
  1208. pr_debug("%s: %s\n", dev->name, __func__);
  1209. netif_stop_queue(dev);
  1210. netif_carrier_off(dev);
  1211. phy_stop(lp->phydev);
  1212. phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN);
  1213. /* clear everything */
  1214. bfin_mac_shutdown(dev);
  1215. /* free the rx/tx buffers */
  1216. desc_list_free();
  1217. return 0;
  1218. }
  1219. static const struct net_device_ops bfin_mac_netdev_ops = {
  1220. .ndo_open = bfin_mac_open,
  1221. .ndo_stop = bfin_mac_close,
  1222. .ndo_start_xmit = bfin_mac_hard_start_xmit,
  1223. .ndo_set_mac_address = bfin_mac_set_mac_address,
  1224. .ndo_tx_timeout = bfin_mac_timeout,
  1225. .ndo_set_multicast_list = bfin_mac_set_multicast_list,
  1226. .ndo_do_ioctl = bfin_mac_ioctl,
  1227. .ndo_validate_addr = eth_validate_addr,
  1228. .ndo_change_mtu = eth_change_mtu,
  1229. #ifdef CONFIG_NET_POLL_CONTROLLER
  1230. .ndo_poll_controller = bfin_mac_poll,
  1231. #endif
  1232. };
  1233. static int __devinit bfin_mac_probe(struct platform_device *pdev)
  1234. {
  1235. struct net_device *ndev;
  1236. struct bfin_mac_local *lp;
  1237. struct platform_device *pd;
  1238. struct bfin_mii_bus_platform_data *mii_bus_data;
  1239. int rc;
  1240. ndev = alloc_etherdev(sizeof(struct bfin_mac_local));
  1241. if (!ndev) {
  1242. dev_err(&pdev->dev, "Cannot allocate net device!\n");
  1243. return -ENOMEM;
  1244. }
  1245. SET_NETDEV_DEV(ndev, &pdev->dev);
  1246. platform_set_drvdata(pdev, ndev);
  1247. lp = netdev_priv(ndev);
  1248. lp->ndev = ndev;
  1249. /* Grab the MAC address in the MAC */
  1250. *(__le32 *) (&(ndev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO());
  1251. *(__le16 *) (&(ndev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI());
  1252. /* probe mac */
  1253. /*todo: how to proble? which is revision_register */
  1254. bfin_write_EMAC_ADDRLO(0x12345678);
  1255. if (bfin_read_EMAC_ADDRLO() != 0x12345678) {
  1256. dev_err(&pdev->dev, "Cannot detect Blackfin on-chip ethernet MAC controller!\n");
  1257. rc = -ENODEV;
  1258. goto out_err_probe_mac;
  1259. }
  1260. /*
  1261. * Is it valid? (Did bootloader initialize it?)
  1262. * Grab the MAC from the board somehow
  1263. * this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c
  1264. */
  1265. if (!is_valid_ether_addr(ndev->dev_addr))
  1266. bfin_get_ether_addr(ndev->dev_addr);
  1267. /* If still not valid, get a random one */
  1268. if (!is_valid_ether_addr(ndev->dev_addr))
  1269. random_ether_addr(ndev->dev_addr);
  1270. setup_mac_addr(ndev->dev_addr);
  1271. if (!pdev->dev.platform_data) {
  1272. dev_err(&pdev->dev, "Cannot get platform device bfin_mii_bus!\n");
  1273. rc = -ENODEV;
  1274. goto out_err_probe_mac;
  1275. }
  1276. pd = pdev->dev.platform_data;
  1277. lp->mii_bus = platform_get_drvdata(pd);
  1278. if (!lp->mii_bus) {
  1279. dev_err(&pdev->dev, "Cannot get mii_bus!\n");
  1280. rc = -ENODEV;
  1281. goto out_err_probe_mac;
  1282. }
  1283. lp->mii_bus->priv = ndev;
  1284. mii_bus_data = pd->dev.platform_data;
  1285. rc = mii_probe(ndev, mii_bus_data->phy_mode);
  1286. if (rc) {
  1287. dev_err(&pdev->dev, "MII Probe failed!\n");
  1288. goto out_err_mii_probe;
  1289. }
  1290. lp->vlan1_mask = ETH_P_8021Q | mii_bus_data->vlan1_mask;
  1291. lp->vlan2_mask = ETH_P_8021Q | mii_bus_data->vlan2_mask;
  1292. /* Fill in the fields of the device structure with ethernet values. */
  1293. ether_setup(ndev);
  1294. ndev->netdev_ops = &bfin_mac_netdev_ops;
  1295. ndev->ethtool_ops = &bfin_mac_ethtool_ops;
  1296. init_timer(&lp->tx_reclaim_timer);
  1297. lp->tx_reclaim_timer.data = (unsigned long)lp;
  1298. lp->tx_reclaim_timer.function = tx_reclaim_skb_timeout;
  1299. spin_lock_init(&lp->lock);
  1300. /* now, enable interrupts */
  1301. /* register irq handler */
  1302. rc = request_irq(IRQ_MAC_RX, bfin_mac_interrupt,
  1303. IRQF_DISABLED, "EMAC_RX", ndev);
  1304. if (rc) {
  1305. dev_err(&pdev->dev, "Cannot request Blackfin MAC RX IRQ!\n");
  1306. rc = -EBUSY;
  1307. goto out_err_request_irq;
  1308. }
  1309. rc = register_netdev(ndev);
  1310. if (rc) {
  1311. dev_err(&pdev->dev, "Cannot register net device!\n");
  1312. goto out_err_reg_ndev;
  1313. }
  1314. bfin_mac_hwtstamp_init(ndev);
  1315. /* now, print out the card info, in a short format.. */
  1316. netdev_info(ndev, "%s, Version %s\n", DRV_DESC, DRV_VERSION);
  1317. return 0;
  1318. out_err_reg_ndev:
  1319. free_irq(IRQ_MAC_RX, ndev);
  1320. out_err_request_irq:
  1321. out_err_mii_probe:
  1322. mdiobus_unregister(lp->mii_bus);
  1323. mdiobus_free(lp->mii_bus);
  1324. out_err_probe_mac:
  1325. platform_set_drvdata(pdev, NULL);
  1326. free_netdev(ndev);
  1327. return rc;
  1328. }
  1329. static int __devexit bfin_mac_remove(struct platform_device *pdev)
  1330. {
  1331. struct net_device *ndev = platform_get_drvdata(pdev);
  1332. struct bfin_mac_local *lp = netdev_priv(ndev);
  1333. platform_set_drvdata(pdev, NULL);
  1334. lp->mii_bus->priv = NULL;
  1335. unregister_netdev(ndev);
  1336. free_irq(IRQ_MAC_RX, ndev);
  1337. free_netdev(ndev);
  1338. return 0;
  1339. }
  1340. #ifdef CONFIG_PM
  1341. static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg)
  1342. {
  1343. struct net_device *net_dev = platform_get_drvdata(pdev);
  1344. struct bfin_mac_local *lp = netdev_priv(net_dev);
  1345. if (lp->wol) {
  1346. bfin_write_EMAC_OPMODE((bfin_read_EMAC_OPMODE() & ~TE) | RE);
  1347. bfin_write_EMAC_WKUP_CTL(MPKE);
  1348. enable_irq_wake(IRQ_MAC_WAKEDET);
  1349. } else {
  1350. if (netif_running(net_dev))
  1351. bfin_mac_close(net_dev);
  1352. }
  1353. return 0;
  1354. }
  1355. static int bfin_mac_resume(struct platform_device *pdev)
  1356. {
  1357. struct net_device *net_dev = platform_get_drvdata(pdev);
  1358. struct bfin_mac_local *lp = netdev_priv(net_dev);
  1359. if (lp->wol) {
  1360. bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
  1361. bfin_write_EMAC_WKUP_CTL(0);
  1362. disable_irq_wake(IRQ_MAC_WAKEDET);
  1363. } else {
  1364. if (netif_running(net_dev))
  1365. bfin_mac_open(net_dev);
  1366. }
  1367. return 0;
  1368. }
  1369. #else
  1370. #define bfin_mac_suspend NULL
  1371. #define bfin_mac_resume NULL
  1372. #endif /* CONFIG_PM */
  1373. static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
  1374. {
  1375. struct mii_bus *miibus;
  1376. struct bfin_mii_bus_platform_data *mii_bus_pd;
  1377. const unsigned short *pin_req;
  1378. int rc, i;
  1379. mii_bus_pd = dev_get_platdata(&pdev->dev);
  1380. if (!mii_bus_pd) {
  1381. dev_err(&pdev->dev, "No peripherals in platform data!\n");
  1382. return -EINVAL;
  1383. }
  1384. /*
  1385. * We are setting up a network card,
  1386. * so set the GPIO pins to Ethernet mode
  1387. */
  1388. pin_req = mii_bus_pd->mac_peripherals;
  1389. rc = peripheral_request_list(pin_req, KBUILD_MODNAME);
  1390. if (rc) {
  1391. dev_err(&pdev->dev, "Requesting peripherals failed!\n");
  1392. return rc;
  1393. }
  1394. rc = -ENOMEM;
  1395. miibus = mdiobus_alloc();
  1396. if (miibus == NULL)
  1397. goto out_err_alloc;
  1398. miibus->read = bfin_mdiobus_read;
  1399. miibus->write = bfin_mdiobus_write;
  1400. miibus->reset = bfin_mdiobus_reset;
  1401. miibus->parent = &pdev->dev;
  1402. miibus->name = "bfin_mii_bus";
  1403. miibus->phy_mask = mii_bus_pd->phy_mask;
  1404. snprintf(miibus->id, MII_BUS_ID_SIZE, "0");
  1405. miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
  1406. if (!miibus->irq)
  1407. goto out_err_irq_alloc;
  1408. for (i = rc; i < PHY_MAX_ADDR; ++i)
  1409. miibus->irq[i] = PHY_POLL;
  1410. rc = clamp(mii_bus_pd->phydev_number, 0, PHY_MAX_ADDR);
  1411. if (rc != mii_bus_pd->phydev_number)
  1412. dev_err(&pdev->dev, "Invalid number (%i) of phydevs\n",
  1413. mii_bus_pd->phydev_number);
  1414. for (i = 0; i < rc; ++i) {
  1415. unsigned short phyaddr = mii_bus_pd->phydev_data[i].addr;
  1416. if (phyaddr < PHY_MAX_ADDR)
  1417. miibus->irq[phyaddr] = mii_bus_pd->phydev_data[i].irq;
  1418. else
  1419. dev_err(&pdev->dev,
  1420. "Invalid PHY address %i for phydev %i\n",
  1421. phyaddr, i);
  1422. }
  1423. rc = mdiobus_register(miibus);
  1424. if (rc) {
  1425. dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
  1426. goto out_err_mdiobus_register;
  1427. }
  1428. platform_set_drvdata(pdev, miibus);
  1429. return 0;
  1430. out_err_mdiobus_register:
  1431. kfree(miibus->irq);
  1432. out_err_irq_alloc:
  1433. mdiobus_free(miibus);
  1434. out_err_alloc:
  1435. peripheral_free_list(pin_req);
  1436. return rc;
  1437. }
  1438. static int __devexit bfin_mii_bus_remove(struct platform_device *pdev)
  1439. {
  1440. struct mii_bus *miibus = platform_get_drvdata(pdev);
  1441. struct bfin_mii_bus_platform_data *mii_bus_pd =
  1442. dev_get_platdata(&pdev->dev);
  1443. platform_set_drvdata(pdev, NULL);
  1444. mdiobus_unregister(miibus);
  1445. kfree(miibus->irq);
  1446. mdiobus_free(miibus);
  1447. peripheral_free_list(mii_bus_pd->mac_peripherals);
  1448. return 0;
  1449. }
  1450. static struct platform_driver bfin_mii_bus_driver = {
  1451. .probe = bfin_mii_bus_probe,
  1452. .remove = __devexit_p(bfin_mii_bus_remove),
  1453. .driver = {
  1454. .name = "bfin_mii_bus",
  1455. .owner = THIS_MODULE,
  1456. },
  1457. };
  1458. static struct platform_driver bfin_mac_driver = {
  1459. .probe = bfin_mac_probe,
  1460. .remove = __devexit_p(bfin_mac_remove),
  1461. .resume = bfin_mac_resume,
  1462. .suspend = bfin_mac_suspend,
  1463. .driver = {
  1464. .name = KBUILD_MODNAME,
  1465. .owner = THIS_MODULE,
  1466. },
  1467. };
  1468. static int __init bfin_mac_init(void)
  1469. {
  1470. int ret;
  1471. ret = platform_driver_register(&bfin_mii_bus_driver);
  1472. if (!ret)
  1473. return platform_driver_register(&bfin_mac_driver);
  1474. return -ENODEV;
  1475. }
  1476. module_init(bfin_mac_init);
  1477. static void __exit bfin_mac_cleanup(void)
  1478. {
  1479. platform_driver_unregister(&bfin_mac_driver);
  1480. platform_driver_unregister(&bfin_mii_bus_driver);
  1481. }
  1482. module_exit(bfin_mac_cleanup);