stmmac_main.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  1. /*******************************************************************************
  2. This is the driver for the ST MAC 10/100/1000 on-chip Ethernet controllers.
  3. ST Ethernet IPs are built around a Synopsys IP Core.
  4. Copyright(C) 2007-2011 STMicroelectronics Ltd
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms and conditions of the GNU General Public License,
  7. version 2, as published by the Free Software Foundation.
  8. This program is distributed in the hope it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. You should have received a copy of the GNU General Public License along with
  13. this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  15. The full GNU General Public License is included in this distribution in
  16. the file called "COPYING".
  17. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  18. Documentation available at:
  19. http://www.stlinux.com
  20. Support available at:
  21. https://bugzilla.stlinux.com/
  22. *******************************************************************************/
  23. #include <linux/kernel.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/ip.h>
  26. #include <linux/tcp.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/ethtool.h>
  29. #include <linux/if_ether.h>
  30. #include <linux/crc32.h>
  31. #include <linux/mii.h>
  32. #include <linux/if.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/slab.h>
  36. #include <linux/prefetch.h>
  37. #ifdef CONFIG_STMMAC_DEBUG_FS
  38. #include <linux/debugfs.h>
  39. #include <linux/seq_file.h>
  40. #endif
  41. #include "stmmac.h"
  42. #undef STMMAC_DEBUG
  43. /*#define STMMAC_DEBUG*/
  44. #ifdef STMMAC_DEBUG
  45. #define DBG(nlevel, klevel, fmt, args...) \
  46. ((void)(netif_msg_##nlevel(priv) && \
  47. printk(KERN_##klevel fmt, ## args)))
  48. #else
  49. #define DBG(nlevel, klevel, fmt, args...) do { } while (0)
  50. #endif
  51. #undef STMMAC_RX_DEBUG
  52. /*#define STMMAC_RX_DEBUG*/
  53. #ifdef STMMAC_RX_DEBUG
  54. #define RX_DBG(fmt, args...) printk(fmt, ## args)
  55. #else
  56. #define RX_DBG(fmt, args...) do { } while (0)
  57. #endif
  58. #undef STMMAC_XMIT_DEBUG
  59. /*#define STMMAC_XMIT_DEBUG*/
  60. #ifdef STMMAC_TX_DEBUG
  61. #define TX_DBG(fmt, args...) printk(fmt, ## args)
  62. #else
  63. #define TX_DBG(fmt, args...) do { } while (0)
  64. #endif
  65. #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
  66. #define JUMBO_LEN 9000
  67. /* Module parameters */
  68. #define TX_TIMEO 5000 /* default 5 seconds */
  69. static int watchdog = TX_TIMEO;
  70. module_param(watchdog, int, S_IRUGO | S_IWUSR);
  71. MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
  72. static int debug = -1; /* -1: default, 0: no output, 16: all */
  73. module_param(debug, int, S_IRUGO | S_IWUSR);
  74. MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
  75. int phyaddr = -1;
  76. module_param(phyaddr, int, S_IRUGO);
  77. MODULE_PARM_DESC(phyaddr, "Physical device address");
  78. #define DMA_TX_SIZE 256
  79. static int dma_txsize = DMA_TX_SIZE;
  80. module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
  81. MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
  82. #define DMA_RX_SIZE 256
  83. static int dma_rxsize = DMA_RX_SIZE;
  84. module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
  85. MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
  86. static int flow_ctrl = FLOW_OFF;
  87. module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
  88. MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
  89. static int pause = PAUSE_TIME;
  90. module_param(pause, int, S_IRUGO | S_IWUSR);
  91. MODULE_PARM_DESC(pause, "Flow Control Pause Time");
  92. #define TC_DEFAULT 64
  93. static int tc = TC_DEFAULT;
  94. module_param(tc, int, S_IRUGO | S_IWUSR);
  95. MODULE_PARM_DESC(tc, "DMA threshold control value");
  96. /* Pay attention to tune this parameter; take care of both
  97. * hardware capability and network stabitily/performance impact.
  98. * Many tests showed that ~4ms latency seems to be good enough. */
  99. #ifdef CONFIG_STMMAC_TIMER
  100. #define DEFAULT_PERIODIC_RATE 256
  101. static int tmrate = DEFAULT_PERIODIC_RATE;
  102. module_param(tmrate, int, S_IRUGO | S_IWUSR);
  103. MODULE_PARM_DESC(tmrate, "External timer freq. (default: 256Hz)");
  104. #endif
  105. #define DMA_BUFFER_SIZE BUF_SIZE_2KiB
  106. static int buf_sz = DMA_BUFFER_SIZE;
  107. module_param(buf_sz, int, S_IRUGO | S_IWUSR);
  108. MODULE_PARM_DESC(buf_sz, "DMA buffer size");
  109. static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  110. NETIF_MSG_LINK | NETIF_MSG_IFUP |
  111. NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
  112. #define STMMAC_DEFAULT_LPI_TIMER 1000
  113. static int eee_timer = STMMAC_DEFAULT_LPI_TIMER;
  114. module_param(eee_timer, int, S_IRUGO | S_IWUSR);
  115. MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec");
  116. #define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x))
  117. static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
  118. #ifdef CONFIG_STMMAC_DEBUG_FS
  119. static int stmmac_init_fs(struct net_device *dev);
  120. static void stmmac_exit_fs(void);
  121. #endif
  122. /**
  123. * stmmac_verify_args - verify the driver parameters.
  124. * Description: it verifies if some wrong parameter is passed to the driver.
  125. * Note that wrong parameters are replaced with the default values.
  126. */
  127. static void stmmac_verify_args(void)
  128. {
  129. if (unlikely(watchdog < 0))
  130. watchdog = TX_TIMEO;
  131. if (unlikely(dma_rxsize < 0))
  132. dma_rxsize = DMA_RX_SIZE;
  133. if (unlikely(dma_txsize < 0))
  134. dma_txsize = DMA_TX_SIZE;
  135. if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
  136. buf_sz = DMA_BUFFER_SIZE;
  137. if (unlikely(flow_ctrl > 1))
  138. flow_ctrl = FLOW_AUTO;
  139. else if (likely(flow_ctrl < 0))
  140. flow_ctrl = FLOW_OFF;
  141. if (unlikely((pause < 0) || (pause > 0xffff)))
  142. pause = PAUSE_TIME;
  143. if (eee_timer < 0)
  144. eee_timer = STMMAC_DEFAULT_LPI_TIMER;
  145. }
  146. static void stmmac_clk_csr_set(struct stmmac_priv *priv)
  147. {
  148. #ifdef CONFIG_HAVE_CLK
  149. u32 clk_rate;
  150. if (IS_ERR(priv->stmmac_clk))
  151. return;
  152. clk_rate = clk_get_rate(priv->stmmac_clk);
  153. /* Platform provided default clk_csr would be assumed valid
  154. * for all other cases except for the below mentioned ones. */
  155. if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) {
  156. if (clk_rate < CSR_F_35M)
  157. priv->clk_csr = STMMAC_CSR_20_35M;
  158. else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M))
  159. priv->clk_csr = STMMAC_CSR_35_60M;
  160. else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M))
  161. priv->clk_csr = STMMAC_CSR_60_100M;
  162. else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M))
  163. priv->clk_csr = STMMAC_CSR_100_150M;
  164. else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M))
  165. priv->clk_csr = STMMAC_CSR_150_250M;
  166. else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M))
  167. priv->clk_csr = STMMAC_CSR_250_300M;
  168. } /* For values higher than the IEEE 802.3 specified frequency
  169. * we can not estimate the proper divider as it is not known
  170. * the frequency of clk_csr_i. So we do not change the default
  171. * divider. */
  172. #endif
  173. }
  174. #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
  175. static void print_pkt(unsigned char *buf, int len)
  176. {
  177. int j;
  178. pr_info("len = %d byte, buf addr: 0x%p", len, buf);
  179. for (j = 0; j < len; j++) {
  180. if ((j % 16) == 0)
  181. pr_info("\n %03x:", j);
  182. pr_info(" %02x", buf[j]);
  183. }
  184. pr_info("\n");
  185. }
  186. #endif
  187. /* minimum number of free TX descriptors required to wake up TX process */
  188. #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
  189. static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
  190. {
  191. return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
  192. }
  193. /* On some ST platforms, some HW system configuraton registers have to be
  194. * set according to the link speed negotiated.
  195. */
  196. static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
  197. {
  198. struct phy_device *phydev = priv->phydev;
  199. if (likely(priv->plat->fix_mac_speed))
  200. priv->plat->fix_mac_speed(priv->plat->bsp_priv,
  201. phydev->speed);
  202. }
  203. static void stmmac_enable_eee_mode(struct stmmac_priv *priv)
  204. {
  205. /* Check and enter in LPI mode */
  206. if ((priv->dirty_tx == priv->cur_tx) &&
  207. (priv->tx_path_in_lpi_mode == false))
  208. priv->hw->mac->set_eee_mode(priv->ioaddr);
  209. }
  210. void stmmac_disable_eee_mode(struct stmmac_priv *priv)
  211. {
  212. /* Exit and disable EEE in case of we are are in LPI state. */
  213. priv->hw->mac->reset_eee_mode(priv->ioaddr);
  214. del_timer_sync(&priv->eee_ctrl_timer);
  215. priv->tx_path_in_lpi_mode = false;
  216. }
  217. /**
  218. * stmmac_eee_ctrl_timer
  219. * @arg : data hook
  220. * Description:
  221. * If there is no data transfer and if we are not in LPI state,
  222. * then MAC Transmitter can be moved to LPI state.
  223. */
  224. static void stmmac_eee_ctrl_timer(unsigned long arg)
  225. {
  226. struct stmmac_priv *priv = (struct stmmac_priv *)arg;
  227. stmmac_enable_eee_mode(priv);
  228. mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
  229. }
  230. /**
  231. * stmmac_eee_init
  232. * @priv: private device pointer
  233. * Description:
  234. * If the EEE support has been enabled while configuring the driver,
  235. * if the GMAC actually supports the EEE (from the HW cap reg) and the
  236. * phy can also manage EEE, so enable the LPI state and start the timer
  237. * to verify if the tx path can enter in LPI state.
  238. */
  239. bool stmmac_eee_init(struct stmmac_priv *priv)
  240. {
  241. bool ret = false;
  242. /* MAC core supports the EEE feature. */
  243. if (priv->dma_cap.eee) {
  244. /* Check if the PHY supports EEE */
  245. if (phy_init_eee(priv->phydev, 1))
  246. goto out;
  247. priv->eee_active = 1;
  248. init_timer(&priv->eee_ctrl_timer);
  249. priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer;
  250. priv->eee_ctrl_timer.data = (unsigned long)priv;
  251. priv->eee_ctrl_timer.expires = STMMAC_LPI_TIMER(eee_timer);
  252. add_timer(&priv->eee_ctrl_timer);
  253. priv->hw->mac->set_eee_timer(priv->ioaddr,
  254. STMMAC_DEFAULT_LIT_LS_TIMER,
  255. priv->tx_lpi_timer);
  256. pr_info("stmmac: Energy-Efficient Ethernet initialized\n");
  257. ret = true;
  258. }
  259. out:
  260. return ret;
  261. }
  262. static void stmmac_eee_adjust(struct stmmac_priv *priv)
  263. {
  264. /* When the EEE has been already initialised we have to
  265. * modify the PLS bit in the LPI ctrl & status reg according
  266. * to the PHY link status. For this reason.
  267. */
  268. if (priv->eee_enabled)
  269. priv->hw->mac->set_eee_pls(priv->ioaddr, priv->phydev->link);
  270. }
  271. /**
  272. * stmmac_adjust_link
  273. * @dev: net device structure
  274. * Description: it adjusts the link parameters.
  275. */
  276. static void stmmac_adjust_link(struct net_device *dev)
  277. {
  278. struct stmmac_priv *priv = netdev_priv(dev);
  279. struct phy_device *phydev = priv->phydev;
  280. unsigned long flags;
  281. int new_state = 0;
  282. unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
  283. if (phydev == NULL)
  284. return;
  285. DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
  286. phydev->addr, phydev->link);
  287. spin_lock_irqsave(&priv->lock, flags);
  288. if (phydev->link) {
  289. u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
  290. /* Now we make sure that we can be in full duplex mode.
  291. * If not, we operate in half-duplex mode. */
  292. if (phydev->duplex != priv->oldduplex) {
  293. new_state = 1;
  294. if (!(phydev->duplex))
  295. ctrl &= ~priv->hw->link.duplex;
  296. else
  297. ctrl |= priv->hw->link.duplex;
  298. priv->oldduplex = phydev->duplex;
  299. }
  300. /* Flow Control operation */
  301. if (phydev->pause)
  302. priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex,
  303. fc, pause_time);
  304. if (phydev->speed != priv->speed) {
  305. new_state = 1;
  306. switch (phydev->speed) {
  307. case 1000:
  308. if (likely(priv->plat->has_gmac))
  309. ctrl &= ~priv->hw->link.port;
  310. stmmac_hw_fix_mac_speed(priv);
  311. break;
  312. case 100:
  313. case 10:
  314. if (priv->plat->has_gmac) {
  315. ctrl |= priv->hw->link.port;
  316. if (phydev->speed == SPEED_100) {
  317. ctrl |= priv->hw->link.speed;
  318. } else {
  319. ctrl &= ~(priv->hw->link.speed);
  320. }
  321. } else {
  322. ctrl &= ~priv->hw->link.port;
  323. }
  324. stmmac_hw_fix_mac_speed(priv);
  325. break;
  326. default:
  327. if (netif_msg_link(priv))
  328. pr_warning("%s: Speed (%d) is not 10"
  329. " or 100!\n", dev->name, phydev->speed);
  330. break;
  331. }
  332. priv->speed = phydev->speed;
  333. }
  334. writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
  335. if (!priv->oldlink) {
  336. new_state = 1;
  337. priv->oldlink = 1;
  338. }
  339. } else if (priv->oldlink) {
  340. new_state = 1;
  341. priv->oldlink = 0;
  342. priv->speed = 0;
  343. priv->oldduplex = -1;
  344. }
  345. if (new_state && netif_msg_link(priv))
  346. phy_print_status(phydev);
  347. stmmac_eee_adjust(priv);
  348. spin_unlock_irqrestore(&priv->lock, flags);
  349. DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
  350. }
  351. /**
  352. * stmmac_init_phy - PHY initialization
  353. * @dev: net device structure
  354. * Description: it initializes the driver's PHY state, and attaches the PHY
  355. * to the mac driver.
  356. * Return value:
  357. * 0 on success
  358. */
  359. static int stmmac_init_phy(struct net_device *dev)
  360. {
  361. struct stmmac_priv *priv = netdev_priv(dev);
  362. struct phy_device *phydev;
  363. char phy_id_fmt[MII_BUS_ID_SIZE + 3];
  364. char bus_id[MII_BUS_ID_SIZE];
  365. int interface = priv->plat->interface;
  366. priv->oldlink = 0;
  367. priv->speed = 0;
  368. priv->oldduplex = -1;
  369. if (priv->plat->phy_bus_name)
  370. snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
  371. priv->plat->phy_bus_name, priv->plat->bus_id);
  372. else
  373. snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
  374. priv->plat->bus_id);
  375. snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
  376. priv->plat->phy_addr);
  377. pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
  378. phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, 0,
  379. interface);
  380. if (IS_ERR(phydev)) {
  381. pr_err("%s: Could not attach to PHY\n", dev->name);
  382. return PTR_ERR(phydev);
  383. }
  384. /* Stop Advertising 1000BASE Capability if interface is not GMII */
  385. if ((interface == PHY_INTERFACE_MODE_MII) ||
  386. (interface == PHY_INTERFACE_MODE_RMII))
  387. phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
  388. SUPPORTED_1000baseT_Full);
  389. /*
  390. * Broken HW is sometimes missing the pull-up resistor on the
  391. * MDIO line, which results in reads to non-existent devices returning
  392. * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
  393. * device as well.
  394. * Note: phydev->phy_id is the result of reading the UID PHY registers.
  395. */
  396. if (phydev->phy_id == 0) {
  397. phy_disconnect(phydev);
  398. return -ENODEV;
  399. }
  400. pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
  401. " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
  402. priv->phydev = phydev;
  403. return 0;
  404. }
  405. /**
  406. * display_ring
  407. * @p: pointer to the ring.
  408. * @size: size of the ring.
  409. * Description: display all the descriptors within the ring.
  410. */
  411. static void display_ring(struct dma_desc *p, int size)
  412. {
  413. struct tmp_s {
  414. u64 a;
  415. unsigned int b;
  416. unsigned int c;
  417. };
  418. int i;
  419. for (i = 0; i < size; i++) {
  420. struct tmp_s *x = (struct tmp_s *)(p + i);
  421. pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
  422. i, (unsigned int)virt_to_phys(&p[i]),
  423. (unsigned int)(x->a), (unsigned int)((x->a) >> 32),
  424. x->b, x->c);
  425. pr_info("\n");
  426. }
  427. }
  428. static int stmmac_set_bfsize(int mtu, int bufsize)
  429. {
  430. int ret = bufsize;
  431. if (mtu >= BUF_SIZE_4KiB)
  432. ret = BUF_SIZE_8KiB;
  433. else if (mtu >= BUF_SIZE_2KiB)
  434. ret = BUF_SIZE_4KiB;
  435. else if (mtu >= DMA_BUFFER_SIZE)
  436. ret = BUF_SIZE_2KiB;
  437. else
  438. ret = DMA_BUFFER_SIZE;
  439. return ret;
  440. }
  441. /**
  442. * init_dma_desc_rings - init the RX/TX descriptor rings
  443. * @dev: net device structure
  444. * Description: this function initializes the DMA RX/TX descriptors
  445. * and allocates the socket buffers. It suppors the chained and ring
  446. * modes.
  447. */
  448. static void init_dma_desc_rings(struct net_device *dev)
  449. {
  450. int i;
  451. struct stmmac_priv *priv = netdev_priv(dev);
  452. struct sk_buff *skb;
  453. unsigned int txsize = priv->dma_tx_size;
  454. unsigned int rxsize = priv->dma_rx_size;
  455. unsigned int bfsize;
  456. int dis_ic = 0;
  457. int des3_as_data_buf = 0;
  458. /* Set the max buffer size according to the DESC mode
  459. * and the MTU. Note that RING mode allows 16KiB bsize. */
  460. bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
  461. if (bfsize == BUF_SIZE_16KiB)
  462. des3_as_data_buf = 1;
  463. else
  464. bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
  465. #ifdef CONFIG_STMMAC_TIMER
  466. /* Disable interrupts on completion for the reception if timer is on */
  467. if (likely(priv->tm->enable))
  468. dis_ic = 1;
  469. #endif
  470. DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
  471. txsize, rxsize, bfsize);
  472. priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL);
  473. priv->rx_skbuff =
  474. kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL);
  475. priv->dma_rx =
  476. (struct dma_desc *)dma_alloc_coherent(priv->device,
  477. rxsize *
  478. sizeof(struct dma_desc),
  479. &priv->dma_rx_phy,
  480. GFP_KERNEL);
  481. priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize,
  482. GFP_KERNEL);
  483. priv->dma_tx =
  484. (struct dma_desc *)dma_alloc_coherent(priv->device,
  485. txsize *
  486. sizeof(struct dma_desc),
  487. &priv->dma_tx_phy,
  488. GFP_KERNEL);
  489. if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) {
  490. pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__);
  491. return;
  492. }
  493. DBG(probe, INFO, "stmmac (%s) DMA desc: virt addr (Rx %p, "
  494. "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
  495. dev->name, priv->dma_rx, priv->dma_tx,
  496. (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy);
  497. /* RX INITIALIZATION */
  498. DBG(probe, INFO, "stmmac: SKB addresses:\n"
  499. "skb\t\tskb data\tdma data\n");
  500. for (i = 0; i < rxsize; i++) {
  501. struct dma_desc *p = priv->dma_rx + i;
  502. skb = __netdev_alloc_skb(dev, bfsize + NET_IP_ALIGN,
  503. GFP_KERNEL);
  504. if (unlikely(skb == NULL)) {
  505. pr_err("%s: Rx init fails; skb is NULL\n", __func__);
  506. break;
  507. }
  508. skb_reserve(skb, NET_IP_ALIGN);
  509. priv->rx_skbuff[i] = skb;
  510. priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
  511. bfsize, DMA_FROM_DEVICE);
  512. p->des2 = priv->rx_skbuff_dma[i];
  513. priv->hw->ring->init_desc3(des3_as_data_buf, p);
  514. DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
  515. priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
  516. }
  517. priv->cur_rx = 0;
  518. priv->dirty_rx = (unsigned int)(i - rxsize);
  519. priv->dma_buf_sz = bfsize;
  520. buf_sz = bfsize;
  521. /* TX INITIALIZATION */
  522. for (i = 0; i < txsize; i++) {
  523. priv->tx_skbuff[i] = NULL;
  524. priv->dma_tx[i].des2 = 0;
  525. }
  526. /* In case of Chained mode this sets the des3 to the next
  527. * element in the chain */
  528. priv->hw->ring->init_dma_chain(priv->dma_rx, priv->dma_rx_phy, rxsize);
  529. priv->hw->ring->init_dma_chain(priv->dma_tx, priv->dma_tx_phy, txsize);
  530. priv->dirty_tx = 0;
  531. priv->cur_tx = 0;
  532. /* Clear the Rx/Tx descriptors */
  533. priv->hw->desc->init_rx_desc(priv->dma_rx, rxsize, dis_ic);
  534. priv->hw->desc->init_tx_desc(priv->dma_tx, txsize);
  535. if (netif_msg_hw(priv)) {
  536. pr_info("RX descriptor ring:\n");
  537. display_ring(priv->dma_rx, rxsize);
  538. pr_info("TX descriptor ring:\n");
  539. display_ring(priv->dma_tx, txsize);
  540. }
  541. }
  542. static void dma_free_rx_skbufs(struct stmmac_priv *priv)
  543. {
  544. int i;
  545. for (i = 0; i < priv->dma_rx_size; i++) {
  546. if (priv->rx_skbuff[i]) {
  547. dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
  548. priv->dma_buf_sz, DMA_FROM_DEVICE);
  549. dev_kfree_skb_any(priv->rx_skbuff[i]);
  550. }
  551. priv->rx_skbuff[i] = NULL;
  552. }
  553. }
  554. static void dma_free_tx_skbufs(struct stmmac_priv *priv)
  555. {
  556. int i;
  557. for (i = 0; i < priv->dma_tx_size; i++) {
  558. if (priv->tx_skbuff[i] != NULL) {
  559. struct dma_desc *p = priv->dma_tx + i;
  560. if (p->des2)
  561. dma_unmap_single(priv->device, p->des2,
  562. priv->hw->desc->get_tx_len(p),
  563. DMA_TO_DEVICE);
  564. dev_kfree_skb_any(priv->tx_skbuff[i]);
  565. priv->tx_skbuff[i] = NULL;
  566. }
  567. }
  568. }
  569. static void free_dma_desc_resources(struct stmmac_priv *priv)
  570. {
  571. /* Release the DMA TX/RX socket buffers */
  572. dma_free_rx_skbufs(priv);
  573. dma_free_tx_skbufs(priv);
  574. /* Free the region of consistent memory previously allocated for
  575. * the DMA */
  576. dma_free_coherent(priv->device,
  577. priv->dma_tx_size * sizeof(struct dma_desc),
  578. priv->dma_tx, priv->dma_tx_phy);
  579. dma_free_coherent(priv->device,
  580. priv->dma_rx_size * sizeof(struct dma_desc),
  581. priv->dma_rx, priv->dma_rx_phy);
  582. kfree(priv->rx_skbuff_dma);
  583. kfree(priv->rx_skbuff);
  584. kfree(priv->tx_skbuff);
  585. }
  586. /**
  587. * stmmac_dma_operation_mode - HW DMA operation mode
  588. * @priv : pointer to the private device structure.
  589. * Description: it sets the DMA operation mode: tx/rx DMA thresholds
  590. * or Store-And-Forward capability.
  591. */
  592. static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
  593. {
  594. if (likely(priv->plat->force_sf_dma_mode ||
  595. ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) {
  596. /*
  597. * In case of GMAC, SF mode can be enabled
  598. * to perform the TX COE in HW. This depends on:
  599. * 1) TX COE if actually supported
  600. * 2) There is no bugged Jumbo frame support
  601. * that needs to not insert csum in the TDES.
  602. */
  603. priv->hw->dma->dma_mode(priv->ioaddr,
  604. SF_DMA_MODE, SF_DMA_MODE);
  605. tc = SF_DMA_MODE;
  606. } else
  607. priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
  608. }
  609. /**
  610. * stmmac_tx:
  611. * @priv: private driver structure
  612. * Description: it reclaims resources after transmission completes.
  613. */
  614. static void stmmac_tx(struct stmmac_priv *priv)
  615. {
  616. unsigned int txsize = priv->dma_tx_size;
  617. spin_lock(&priv->tx_lock);
  618. while (priv->dirty_tx != priv->cur_tx) {
  619. int last;
  620. unsigned int entry = priv->dirty_tx % txsize;
  621. struct sk_buff *skb = priv->tx_skbuff[entry];
  622. struct dma_desc *p = priv->dma_tx + entry;
  623. /* Check if the descriptor is owned by the DMA. */
  624. if (priv->hw->desc->get_tx_owner(p))
  625. break;
  626. /* Verify tx error by looking at the last segment */
  627. last = priv->hw->desc->get_tx_ls(p);
  628. if (likely(last)) {
  629. int tx_error =
  630. priv->hw->desc->tx_status(&priv->dev->stats,
  631. &priv->xstats, p,
  632. priv->ioaddr);
  633. if (likely(tx_error == 0)) {
  634. priv->dev->stats.tx_packets++;
  635. priv->xstats.tx_pkt_n++;
  636. } else
  637. priv->dev->stats.tx_errors++;
  638. }
  639. TX_DBG("%s: curr %d, dirty %d\n", __func__,
  640. priv->cur_tx, priv->dirty_tx);
  641. if (likely(p->des2))
  642. dma_unmap_single(priv->device, p->des2,
  643. priv->hw->desc->get_tx_len(p),
  644. DMA_TO_DEVICE);
  645. priv->hw->ring->clean_desc3(p);
  646. if (likely(skb != NULL)) {
  647. /*
  648. * If there's room in the queue (limit it to size)
  649. * we add this skb back into the pool,
  650. * if it's the right size.
  651. */
  652. if ((skb_queue_len(&priv->rx_recycle) <
  653. priv->dma_rx_size) &&
  654. skb_recycle_check(skb, priv->dma_buf_sz))
  655. __skb_queue_head(&priv->rx_recycle, skb);
  656. else
  657. dev_kfree_skb(skb);
  658. priv->tx_skbuff[entry] = NULL;
  659. }
  660. priv->hw->desc->release_tx_desc(p);
  661. priv->dirty_tx++;
  662. }
  663. if (unlikely(netif_queue_stopped(priv->dev) &&
  664. stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
  665. netif_tx_lock(priv->dev);
  666. if (netif_queue_stopped(priv->dev) &&
  667. stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
  668. TX_DBG("%s: restart transmit\n", __func__);
  669. netif_wake_queue(priv->dev);
  670. }
  671. netif_tx_unlock(priv->dev);
  672. }
  673. if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) {
  674. stmmac_enable_eee_mode(priv);
  675. mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
  676. }
  677. spin_unlock(&priv->tx_lock);
  678. }
  679. static inline void stmmac_enable_irq(struct stmmac_priv *priv)
  680. {
  681. #ifdef CONFIG_STMMAC_TIMER
  682. if (likely(priv->tm->enable))
  683. priv->tm->timer_start(tmrate);
  684. else
  685. #endif
  686. priv->hw->dma->enable_dma_irq(priv->ioaddr);
  687. }
  688. static inline void stmmac_disable_irq(struct stmmac_priv *priv)
  689. {
  690. #ifdef CONFIG_STMMAC_TIMER
  691. if (likely(priv->tm->enable))
  692. priv->tm->timer_stop();
  693. else
  694. #endif
  695. priv->hw->dma->disable_dma_irq(priv->ioaddr);
  696. }
  697. static int stmmac_has_work(struct stmmac_priv *priv)
  698. {
  699. unsigned int has_work = 0;
  700. int rxret, tx_work = 0;
  701. rxret = priv->hw->desc->get_rx_owner(priv->dma_rx +
  702. (priv->cur_rx % priv->dma_rx_size));
  703. if (priv->dirty_tx != priv->cur_tx)
  704. tx_work = 1;
  705. if (likely(!rxret || tx_work))
  706. has_work = 1;
  707. return has_work;
  708. }
  709. static inline void _stmmac_schedule(struct stmmac_priv *priv)
  710. {
  711. if (likely(stmmac_has_work(priv))) {
  712. stmmac_disable_irq(priv);
  713. napi_schedule(&priv->napi);
  714. }
  715. }
  716. #ifdef CONFIG_STMMAC_TIMER
  717. void stmmac_schedule(struct net_device *dev)
  718. {
  719. struct stmmac_priv *priv = netdev_priv(dev);
  720. priv->xstats.sched_timer_n++;
  721. _stmmac_schedule(priv);
  722. }
  723. static void stmmac_no_timer_started(unsigned int x)
  724. {;
  725. };
  726. static void stmmac_no_timer_stopped(void)
  727. {;
  728. };
  729. #endif
  730. /**
  731. * stmmac_tx_err:
  732. * @priv: pointer to the private device structure
  733. * Description: it cleans the descriptors and restarts the transmission
  734. * in case of errors.
  735. */
  736. static void stmmac_tx_err(struct stmmac_priv *priv)
  737. {
  738. netif_stop_queue(priv->dev);
  739. priv->hw->dma->stop_tx(priv->ioaddr);
  740. dma_free_tx_skbufs(priv);
  741. priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
  742. priv->dirty_tx = 0;
  743. priv->cur_tx = 0;
  744. priv->hw->dma->start_tx(priv->ioaddr);
  745. priv->dev->stats.tx_errors++;
  746. netif_wake_queue(priv->dev);
  747. }
  748. static void stmmac_dma_interrupt(struct stmmac_priv *priv)
  749. {
  750. int status;
  751. status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
  752. if (likely(status == handle_tx_rx))
  753. _stmmac_schedule(priv);
  754. else if (unlikely(status == tx_hard_error_bump_tc)) {
  755. /* Try to bump up the dma threshold on this failure */
  756. if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
  757. tc += 64;
  758. priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
  759. priv->xstats.threshold = tc;
  760. }
  761. } else if (unlikely(status == tx_hard_error))
  762. stmmac_tx_err(priv);
  763. }
  764. static void stmmac_mmc_setup(struct stmmac_priv *priv)
  765. {
  766. unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
  767. MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
  768. /* Mask MMC irq, counters are managed in SW and registers
  769. * are cleared on each READ eventually. */
  770. dwmac_mmc_intr_all_mask(priv->ioaddr);
  771. if (priv->dma_cap.rmon) {
  772. dwmac_mmc_ctrl(priv->ioaddr, mode);
  773. memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
  774. } else
  775. pr_info(" No MAC Management Counters available\n");
  776. }
  777. static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
  778. {
  779. u32 hwid = priv->hw->synopsys_uid;
  780. /* Only check valid Synopsys Id because old MAC chips
  781. * have no HW registers where get the ID */
  782. if (likely(hwid)) {
  783. u32 uid = ((hwid & 0x0000ff00) >> 8);
  784. u32 synid = (hwid & 0x000000ff);
  785. pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
  786. uid, synid);
  787. return synid;
  788. }
  789. return 0;
  790. }
  791. /**
  792. * stmmac_selec_desc_mode
  793. * @priv : private structure
  794. * Description: select the Enhanced/Alternate or Normal descriptors
  795. */
  796. static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
  797. {
  798. if (priv->plat->enh_desc) {
  799. pr_info(" Enhanced/Alternate descriptors\n");
  800. priv->hw->desc = &enh_desc_ops;
  801. } else {
  802. pr_info(" Normal descriptors\n");
  803. priv->hw->desc = &ndesc_ops;
  804. }
  805. }
  806. /**
  807. * stmmac_get_hw_features
  808. * @priv : private device pointer
  809. * Description:
  810. * new GMAC chip generations have a new register to indicate the
  811. * presence of the optional feature/functions.
  812. * This can be also used to override the value passed through the
  813. * platform and necessary for old MAC10/100 and GMAC chips.
  814. */
  815. static int stmmac_get_hw_features(struct stmmac_priv *priv)
  816. {
  817. u32 hw_cap = 0;
  818. if (priv->hw->dma->get_hw_feature) {
  819. hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
  820. priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
  821. priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
  822. priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
  823. priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
  824. priv->dma_cap.multi_addr =
  825. (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5;
  826. priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
  827. priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
  828. priv->dma_cap.pmt_remote_wake_up =
  829. (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
  830. priv->dma_cap.pmt_magic_frame =
  831. (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
  832. /* MMC */
  833. priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
  834. /* IEEE 1588-2002*/
  835. priv->dma_cap.time_stamp =
  836. (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
  837. /* IEEE 1588-2008*/
  838. priv->dma_cap.atime_stamp =
  839. (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
  840. /* 802.3az - Energy-Efficient Ethernet (EEE) */
  841. priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
  842. priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
  843. /* TX and RX csum */
  844. priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
  845. priv->dma_cap.rx_coe_type1 =
  846. (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
  847. priv->dma_cap.rx_coe_type2 =
  848. (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
  849. priv->dma_cap.rxfifo_over_2048 =
  850. (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
  851. /* TX and RX number of channels */
  852. priv->dma_cap.number_rx_channel =
  853. (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
  854. priv->dma_cap.number_tx_channel =
  855. (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
  856. /* Alternate (enhanced) DESC mode*/
  857. priv->dma_cap.enh_desc =
  858. (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
  859. }
  860. return hw_cap;
  861. }
  862. static void stmmac_check_ether_addr(struct stmmac_priv *priv)
  863. {
  864. /* verify if the MAC address is valid, in case of failures it
  865. * generates a random MAC address */
  866. if (!is_valid_ether_addr(priv->dev->dev_addr)) {
  867. priv->hw->mac->get_umac_addr((void __iomem *)
  868. priv->dev->base_addr,
  869. priv->dev->dev_addr, 0);
  870. if (!is_valid_ether_addr(priv->dev->dev_addr))
  871. eth_hw_addr_random(priv->dev);
  872. }
  873. pr_warning("%s: device MAC address %pM\n", priv->dev->name,
  874. priv->dev->dev_addr);
  875. }
  876. static int stmmac_init_dma_engine(struct stmmac_priv *priv)
  877. {
  878. int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_len = 0;
  879. int mixed_burst = 0;
  880. /* Some DMA parameters can be passed from the platform;
  881. * in case of these are not passed we keep a default
  882. * (good for all the chips) and init the DMA! */
  883. if (priv->plat->dma_cfg) {
  884. pbl = priv->plat->dma_cfg->pbl;
  885. fixed_burst = priv->plat->dma_cfg->fixed_burst;
  886. mixed_burst = priv->plat->dma_cfg->mixed_burst;
  887. burst_len = priv->plat->dma_cfg->burst_len;
  888. }
  889. return priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst,
  890. burst_len, priv->dma_tx_phy,
  891. priv->dma_rx_phy);
  892. }
  893. /**
  894. * stmmac_open - open entry point of the driver
  895. * @dev : pointer to the device structure.
  896. * Description:
  897. * This function is the open entry point of the driver.
  898. * Return value:
  899. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  900. * file on failure.
  901. */
  902. static int stmmac_open(struct net_device *dev)
  903. {
  904. struct stmmac_priv *priv = netdev_priv(dev);
  905. int ret;
  906. #ifdef CONFIG_STMMAC_TIMER
  907. priv->tm = kzalloc(sizeof(struct stmmac_timer *), GFP_KERNEL);
  908. if (unlikely(priv->tm == NULL))
  909. return -ENOMEM;
  910. priv->tm->freq = tmrate;
  911. /* Test if the external timer can be actually used.
  912. * In case of failure continue without timer. */
  913. if (unlikely((stmmac_open_ext_timer(dev, priv->tm)) < 0)) {
  914. pr_warning("stmmaceth: cannot attach the external timer.\n");
  915. priv->tm->freq = 0;
  916. priv->tm->timer_start = stmmac_no_timer_started;
  917. priv->tm->timer_stop = stmmac_no_timer_stopped;
  918. } else
  919. priv->tm->enable = 1;
  920. #endif
  921. stmmac_clk_enable(priv);
  922. stmmac_check_ether_addr(priv);
  923. ret = stmmac_init_phy(dev);
  924. if (unlikely(ret)) {
  925. pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
  926. goto open_error;
  927. }
  928. /* Create and initialize the TX/RX descriptors chains. */
  929. priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
  930. priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
  931. priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
  932. init_dma_desc_rings(dev);
  933. /* DMA initialization and SW reset */
  934. ret = stmmac_init_dma_engine(priv);
  935. if (ret < 0) {
  936. pr_err("%s: DMA initialization failed\n", __func__);
  937. goto open_error;
  938. }
  939. /* Copy the MAC addr into the HW */
  940. priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
  941. /* If required, perform hw setup of the bus. */
  942. if (priv->plat->bus_setup)
  943. priv->plat->bus_setup(priv->ioaddr);
  944. /* Initialize the MAC Core */
  945. priv->hw->mac->core_init(priv->ioaddr);
  946. /* Request the IRQ lines */
  947. ret = request_irq(dev->irq, stmmac_interrupt,
  948. IRQF_SHARED, dev->name, dev);
  949. if (unlikely(ret < 0)) {
  950. pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
  951. __func__, dev->irq, ret);
  952. goto open_error;
  953. }
  954. /* Request the Wake IRQ in case of another line is used for WoL */
  955. if (priv->wol_irq != dev->irq) {
  956. ret = request_irq(priv->wol_irq, stmmac_interrupt,
  957. IRQF_SHARED, dev->name, dev);
  958. if (unlikely(ret < 0)) {
  959. pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
  960. "(error: %d)\n", __func__, priv->wol_irq, ret);
  961. goto open_error_wolirq;
  962. }
  963. }
  964. /* Request the IRQ lines */
  965. if (priv->lpi_irq != -ENXIO) {
  966. ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED,
  967. dev->name, dev);
  968. if (unlikely(ret < 0)) {
  969. pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n",
  970. __func__, priv->lpi_irq, ret);
  971. goto open_error_lpiirq;
  972. }
  973. }
  974. /* Enable the MAC Rx/Tx */
  975. stmmac_set_mac(priv->ioaddr, true);
  976. /* Set the HW DMA mode and the COE */
  977. stmmac_dma_operation_mode(priv);
  978. /* Extra statistics */
  979. memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
  980. priv->xstats.threshold = tc;
  981. stmmac_mmc_setup(priv);
  982. #ifdef CONFIG_STMMAC_DEBUG_FS
  983. ret = stmmac_init_fs(dev);
  984. if (ret < 0)
  985. pr_warning("%s: failed debugFS registration\n", __func__);
  986. #endif
  987. /* Start the ball rolling... */
  988. DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
  989. priv->hw->dma->start_tx(priv->ioaddr);
  990. priv->hw->dma->start_rx(priv->ioaddr);
  991. #ifdef CONFIG_STMMAC_TIMER
  992. priv->tm->timer_start(tmrate);
  993. #endif
  994. /* Dump DMA/MAC registers */
  995. if (netif_msg_hw(priv)) {
  996. priv->hw->mac->dump_regs(priv->ioaddr);
  997. priv->hw->dma->dump_regs(priv->ioaddr);
  998. }
  999. if (priv->phydev)
  1000. phy_start(priv->phydev);
  1001. priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS_TIMER;
  1002. priv->eee_enabled = stmmac_eee_init(priv);
  1003. napi_enable(&priv->napi);
  1004. skb_queue_head_init(&priv->rx_recycle);
  1005. netif_start_queue(dev);
  1006. return 0;
  1007. open_error_lpiirq:
  1008. if (priv->wol_irq != dev->irq)
  1009. free_irq(priv->wol_irq, dev);
  1010. open_error_wolirq:
  1011. free_irq(dev->irq, dev);
  1012. open_error:
  1013. #ifdef CONFIG_STMMAC_TIMER
  1014. kfree(priv->tm);
  1015. #endif
  1016. if (priv->phydev)
  1017. phy_disconnect(priv->phydev);
  1018. stmmac_clk_disable(priv);
  1019. return ret;
  1020. }
  1021. /**
  1022. * stmmac_release - close entry point of the driver
  1023. * @dev : device pointer.
  1024. * Description:
  1025. * This is the stop entry point of the driver.
  1026. */
  1027. static int stmmac_release(struct net_device *dev)
  1028. {
  1029. struct stmmac_priv *priv = netdev_priv(dev);
  1030. if (priv->eee_enabled)
  1031. del_timer_sync(&priv->eee_ctrl_timer);
  1032. /* Stop and disconnect the PHY */
  1033. if (priv->phydev) {
  1034. phy_stop(priv->phydev);
  1035. phy_disconnect(priv->phydev);
  1036. priv->phydev = NULL;
  1037. }
  1038. netif_stop_queue(dev);
  1039. #ifdef CONFIG_STMMAC_TIMER
  1040. /* Stop and release the timer */
  1041. stmmac_close_ext_timer();
  1042. if (priv->tm != NULL)
  1043. kfree(priv->tm);
  1044. #endif
  1045. napi_disable(&priv->napi);
  1046. skb_queue_purge(&priv->rx_recycle);
  1047. /* Free the IRQ lines */
  1048. free_irq(dev->irq, dev);
  1049. if (priv->wol_irq != dev->irq)
  1050. free_irq(priv->wol_irq, dev);
  1051. if (priv->lpi_irq != -ENXIO)
  1052. free_irq(priv->lpi_irq, dev);
  1053. /* Stop TX/RX DMA and clear the descriptors */
  1054. priv->hw->dma->stop_tx(priv->ioaddr);
  1055. priv->hw->dma->stop_rx(priv->ioaddr);
  1056. /* Release and free the Rx/Tx resources */
  1057. free_dma_desc_resources(priv);
  1058. /* Disable the MAC Rx/Tx */
  1059. stmmac_set_mac(priv->ioaddr, false);
  1060. netif_carrier_off(dev);
  1061. #ifdef CONFIG_STMMAC_DEBUG_FS
  1062. stmmac_exit_fs();
  1063. #endif
  1064. stmmac_clk_disable(priv);
  1065. return 0;
  1066. }
  1067. /**
  1068. * stmmac_xmit:
  1069. * @skb : the socket buffer
  1070. * @dev : device pointer
  1071. * Description : Tx entry point of the driver.
  1072. */
  1073. static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
  1074. {
  1075. struct stmmac_priv *priv = netdev_priv(dev);
  1076. unsigned int txsize = priv->dma_tx_size;
  1077. unsigned int entry;
  1078. int i, csum_insertion = 0;
  1079. int nfrags = skb_shinfo(skb)->nr_frags;
  1080. struct dma_desc *desc, *first;
  1081. unsigned int nopaged_len = skb_headlen(skb);
  1082. if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
  1083. if (!netif_queue_stopped(dev)) {
  1084. netif_stop_queue(dev);
  1085. /* This is a hard error, log it. */
  1086. pr_err("%s: BUG! Tx Ring full when queue awake\n",
  1087. __func__);
  1088. }
  1089. return NETDEV_TX_BUSY;
  1090. }
  1091. spin_lock(&priv->tx_lock);
  1092. if (priv->tx_path_in_lpi_mode)
  1093. stmmac_disable_eee_mode(priv);
  1094. entry = priv->cur_tx % txsize;
  1095. #ifdef STMMAC_XMIT_DEBUG
  1096. if ((skb->len > ETH_FRAME_LEN) || nfrags)
  1097. pr_info("stmmac xmit:\n"
  1098. "\tskb addr %p - len: %d - nopaged_len: %d\n"
  1099. "\tn_frags: %d - ip_summed: %d - %s gso\n",
  1100. skb, skb->len, nopaged_len, nfrags, skb->ip_summed,
  1101. !skb_is_gso(skb) ? "isn't" : "is");
  1102. #endif
  1103. csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
  1104. desc = priv->dma_tx + entry;
  1105. first = desc;
  1106. #ifdef STMMAC_XMIT_DEBUG
  1107. if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
  1108. pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n"
  1109. "\t\tn_frags: %d, ip_summed: %d\n",
  1110. skb->len, nopaged_len, nfrags, skb->ip_summed);
  1111. #endif
  1112. priv->tx_skbuff[entry] = skb;
  1113. if (priv->hw->ring->is_jumbo_frm(skb->len, priv->plat->enh_desc)) {
  1114. entry = priv->hw->ring->jumbo_frm(priv, skb, csum_insertion);
  1115. desc = priv->dma_tx + entry;
  1116. } else {
  1117. desc->des2 = dma_map_single(priv->device, skb->data,
  1118. nopaged_len, DMA_TO_DEVICE);
  1119. priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
  1120. csum_insertion);
  1121. }
  1122. for (i = 0; i < nfrags; i++) {
  1123. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1124. int len = skb_frag_size(frag);
  1125. entry = (++priv->cur_tx) % txsize;
  1126. desc = priv->dma_tx + entry;
  1127. TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
  1128. desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
  1129. DMA_TO_DEVICE);
  1130. priv->tx_skbuff[entry] = NULL;
  1131. priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion);
  1132. wmb();
  1133. priv->hw->desc->set_tx_owner(desc);
  1134. wmb();
  1135. }
  1136. /* Interrupt on completition only for the latest segment */
  1137. priv->hw->desc->close_tx_desc(desc);
  1138. #ifdef CONFIG_STMMAC_TIMER
  1139. /* Clean IC while using timer */
  1140. if (likely(priv->tm->enable))
  1141. priv->hw->desc->clear_tx_ic(desc);
  1142. #endif
  1143. wmb();
  1144. /* To avoid raise condition */
  1145. priv->hw->desc->set_tx_owner(first);
  1146. wmb();
  1147. priv->cur_tx++;
  1148. #ifdef STMMAC_XMIT_DEBUG
  1149. if (netif_msg_pktdata(priv)) {
  1150. pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
  1151. "first=%p, nfrags=%d\n",
  1152. (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
  1153. entry, first, nfrags);
  1154. display_ring(priv->dma_tx, txsize);
  1155. pr_info(">>> frame to be transmitted: ");
  1156. print_pkt(skb->data, skb->len);
  1157. }
  1158. #endif
  1159. if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
  1160. TX_DBG("%s: stop transmitted packets\n", __func__);
  1161. netif_stop_queue(dev);
  1162. }
  1163. dev->stats.tx_bytes += skb->len;
  1164. skb_tx_timestamp(skb);
  1165. priv->hw->dma->enable_dma_transmission(priv->ioaddr);
  1166. spin_unlock(&priv->tx_lock);
  1167. return NETDEV_TX_OK;
  1168. }
  1169. static inline void stmmac_rx_refill(struct stmmac_priv *priv)
  1170. {
  1171. unsigned int rxsize = priv->dma_rx_size;
  1172. int bfsize = priv->dma_buf_sz;
  1173. struct dma_desc *p = priv->dma_rx;
  1174. for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
  1175. unsigned int entry = priv->dirty_rx % rxsize;
  1176. if (likely(priv->rx_skbuff[entry] == NULL)) {
  1177. struct sk_buff *skb;
  1178. skb = __skb_dequeue(&priv->rx_recycle);
  1179. if (skb == NULL)
  1180. skb = netdev_alloc_skb_ip_align(priv->dev,
  1181. bfsize);
  1182. if (unlikely(skb == NULL))
  1183. break;
  1184. priv->rx_skbuff[entry] = skb;
  1185. priv->rx_skbuff_dma[entry] =
  1186. dma_map_single(priv->device, skb->data, bfsize,
  1187. DMA_FROM_DEVICE);
  1188. (p + entry)->des2 = priv->rx_skbuff_dma[entry];
  1189. if (unlikely(priv->plat->has_gmac))
  1190. priv->hw->ring->refill_desc3(bfsize, p + entry);
  1191. RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
  1192. }
  1193. wmb();
  1194. priv->hw->desc->set_rx_owner(p + entry);
  1195. wmb();
  1196. }
  1197. }
  1198. static int stmmac_rx(struct stmmac_priv *priv, int limit)
  1199. {
  1200. unsigned int rxsize = priv->dma_rx_size;
  1201. unsigned int entry = priv->cur_rx % rxsize;
  1202. unsigned int next_entry;
  1203. unsigned int count = 0;
  1204. struct dma_desc *p = priv->dma_rx + entry;
  1205. struct dma_desc *p_next;
  1206. #ifdef STMMAC_RX_DEBUG
  1207. if (netif_msg_hw(priv)) {
  1208. pr_debug(">>> stmmac_rx: descriptor ring:\n");
  1209. display_ring(priv->dma_rx, rxsize);
  1210. }
  1211. #endif
  1212. while (!priv->hw->desc->get_rx_owner(p)) {
  1213. int status;
  1214. if (count >= limit)
  1215. break;
  1216. count++;
  1217. next_entry = (++priv->cur_rx) % rxsize;
  1218. p_next = priv->dma_rx + next_entry;
  1219. prefetch(p_next);
  1220. /* read the status of the incoming frame */
  1221. status = (priv->hw->desc->rx_status(&priv->dev->stats,
  1222. &priv->xstats, p));
  1223. if (unlikely(status == discard_frame))
  1224. priv->dev->stats.rx_errors++;
  1225. else {
  1226. struct sk_buff *skb;
  1227. int frame_len;
  1228. frame_len = priv->hw->desc->get_rx_frame_len(p,
  1229. priv->plat->rx_coe);
  1230. /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
  1231. * Type frames (LLC/LLC-SNAP) */
  1232. if (unlikely(status != llc_snap))
  1233. frame_len -= ETH_FCS_LEN;
  1234. #ifdef STMMAC_RX_DEBUG
  1235. if (frame_len > ETH_FRAME_LEN)
  1236. pr_debug("\tRX frame size %d, COE status: %d\n",
  1237. frame_len, status);
  1238. if (netif_msg_hw(priv))
  1239. pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
  1240. p, entry, p->des2);
  1241. #endif
  1242. skb = priv->rx_skbuff[entry];
  1243. if (unlikely(!skb)) {
  1244. pr_err("%s: Inconsistent Rx descriptor chain\n",
  1245. priv->dev->name);
  1246. priv->dev->stats.rx_dropped++;
  1247. break;
  1248. }
  1249. prefetch(skb->data - NET_IP_ALIGN);
  1250. priv->rx_skbuff[entry] = NULL;
  1251. skb_put(skb, frame_len);
  1252. dma_unmap_single(priv->device,
  1253. priv->rx_skbuff_dma[entry],
  1254. priv->dma_buf_sz, DMA_FROM_DEVICE);
  1255. #ifdef STMMAC_RX_DEBUG
  1256. if (netif_msg_pktdata(priv)) {
  1257. pr_info(" frame received (%dbytes)", frame_len);
  1258. print_pkt(skb->data, frame_len);
  1259. }
  1260. #endif
  1261. skb->protocol = eth_type_trans(skb, priv->dev);
  1262. if (unlikely(!priv->plat->rx_coe)) {
  1263. /* No RX COE for old mac10/100 devices */
  1264. skb_checksum_none_assert(skb);
  1265. netif_receive_skb(skb);
  1266. } else {
  1267. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1268. napi_gro_receive(&priv->napi, skb);
  1269. }
  1270. priv->dev->stats.rx_packets++;
  1271. priv->dev->stats.rx_bytes += frame_len;
  1272. }
  1273. entry = next_entry;
  1274. p = p_next; /* use prefetched values */
  1275. }
  1276. stmmac_rx_refill(priv);
  1277. priv->xstats.rx_pkt_n += count;
  1278. return count;
  1279. }
  1280. /**
  1281. * stmmac_poll - stmmac poll method (NAPI)
  1282. * @napi : pointer to the napi structure.
  1283. * @budget : maximum number of packets that the current CPU can receive from
  1284. * all interfaces.
  1285. * Description :
  1286. * This function implements the the reception process.
  1287. * Also it runs the TX completion thread
  1288. */
  1289. static int stmmac_poll(struct napi_struct *napi, int budget)
  1290. {
  1291. struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
  1292. int work_done = 0;
  1293. priv->xstats.poll_n++;
  1294. stmmac_tx(priv);
  1295. work_done = stmmac_rx(priv, budget);
  1296. if (work_done < budget) {
  1297. napi_complete(napi);
  1298. stmmac_enable_irq(priv);
  1299. }
  1300. return work_done;
  1301. }
  1302. /**
  1303. * stmmac_tx_timeout
  1304. * @dev : Pointer to net device structure
  1305. * Description: this function is called when a packet transmission fails to
  1306. * complete within a reasonable tmrate. The driver will mark the error in the
  1307. * netdev structure and arrange for the device to be reset to a sane state
  1308. * in order to transmit a new packet.
  1309. */
  1310. static void stmmac_tx_timeout(struct net_device *dev)
  1311. {
  1312. struct stmmac_priv *priv = netdev_priv(dev);
  1313. /* Clear Tx resources and restart transmitting again */
  1314. stmmac_tx_err(priv);
  1315. }
  1316. /* Configuration changes (passed on by ifconfig) */
  1317. static int stmmac_config(struct net_device *dev, struct ifmap *map)
  1318. {
  1319. if (dev->flags & IFF_UP) /* can't act on a running interface */
  1320. return -EBUSY;
  1321. /* Don't allow changing the I/O address */
  1322. if (map->base_addr != dev->base_addr) {
  1323. pr_warning("%s: can't change I/O address\n", dev->name);
  1324. return -EOPNOTSUPP;
  1325. }
  1326. /* Don't allow changing the IRQ */
  1327. if (map->irq != dev->irq) {
  1328. pr_warning("%s: can't change IRQ number %d\n",
  1329. dev->name, dev->irq);
  1330. return -EOPNOTSUPP;
  1331. }
  1332. /* ignore other fields */
  1333. return 0;
  1334. }
  1335. /**
  1336. * stmmac_set_rx_mode - entry point for multicast addressing
  1337. * @dev : pointer to the device structure
  1338. * Description:
  1339. * This function is a driver entry point which gets called by the kernel
  1340. * whenever multicast addresses must be enabled/disabled.
  1341. * Return value:
  1342. * void.
  1343. */
  1344. static void stmmac_set_rx_mode(struct net_device *dev)
  1345. {
  1346. struct stmmac_priv *priv = netdev_priv(dev);
  1347. spin_lock(&priv->lock);
  1348. priv->hw->mac->set_filter(dev, priv->synopsys_id);
  1349. spin_unlock(&priv->lock);
  1350. }
  1351. /**
  1352. * stmmac_change_mtu - entry point to change MTU size for the device.
  1353. * @dev : device pointer.
  1354. * @new_mtu : the new MTU size for the device.
  1355. * Description: the Maximum Transfer Unit (MTU) is used by the network layer
  1356. * to drive packet transmission. Ethernet has an MTU of 1500 octets
  1357. * (ETH_DATA_LEN). This value can be changed with ifconfig.
  1358. * Return value:
  1359. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  1360. * file on failure.
  1361. */
  1362. static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
  1363. {
  1364. struct stmmac_priv *priv = netdev_priv(dev);
  1365. int max_mtu;
  1366. if (netif_running(dev)) {
  1367. pr_err("%s: must be stopped to change its MTU\n", dev->name);
  1368. return -EBUSY;
  1369. }
  1370. if (priv->plat->enh_desc)
  1371. max_mtu = JUMBO_LEN;
  1372. else
  1373. max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
  1374. if ((new_mtu < 46) || (new_mtu > max_mtu)) {
  1375. pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
  1376. return -EINVAL;
  1377. }
  1378. dev->mtu = new_mtu;
  1379. netdev_update_features(dev);
  1380. return 0;
  1381. }
  1382. static netdev_features_t stmmac_fix_features(struct net_device *dev,
  1383. netdev_features_t features)
  1384. {
  1385. struct stmmac_priv *priv = netdev_priv(dev);
  1386. if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
  1387. features &= ~NETIF_F_RXCSUM;
  1388. else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
  1389. features &= ~NETIF_F_IPV6_CSUM;
  1390. if (!priv->plat->tx_coe)
  1391. features &= ~NETIF_F_ALL_CSUM;
  1392. /* Some GMAC devices have a bugged Jumbo frame support that
  1393. * needs to have the Tx COE disabled for oversized frames
  1394. * (due to limited buffer sizes). In this case we disable
  1395. * the TX csum insertionin the TDES and not use SF. */
  1396. if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
  1397. features &= ~NETIF_F_ALL_CSUM;
  1398. return features;
  1399. }
  1400. static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
  1401. {
  1402. struct net_device *dev = (struct net_device *)dev_id;
  1403. struct stmmac_priv *priv = netdev_priv(dev);
  1404. if (unlikely(!dev)) {
  1405. pr_err("%s: invalid dev pointer\n", __func__);
  1406. return IRQ_NONE;
  1407. }
  1408. /* To handle GMAC own interrupts */
  1409. if (priv->plat->has_gmac) {
  1410. int status = priv->hw->mac->host_irq_status((void __iomem *)
  1411. dev->base_addr);
  1412. if (unlikely(status)) {
  1413. if (status & core_mmc_tx_irq)
  1414. priv->xstats.mmc_tx_irq_n++;
  1415. if (status & core_mmc_rx_irq)
  1416. priv->xstats.mmc_rx_irq_n++;
  1417. if (status & core_mmc_rx_csum_offload_irq)
  1418. priv->xstats.mmc_rx_csum_offload_irq_n++;
  1419. if (status & core_irq_receive_pmt_irq)
  1420. priv->xstats.irq_receive_pmt_irq_n++;
  1421. /* For LPI we need to save the tx status */
  1422. if (status & core_irq_tx_path_in_lpi_mode) {
  1423. priv->xstats.irq_tx_path_in_lpi_mode_n++;
  1424. priv->tx_path_in_lpi_mode = true;
  1425. }
  1426. if (status & core_irq_tx_path_exit_lpi_mode) {
  1427. priv->xstats.irq_tx_path_exit_lpi_mode_n++;
  1428. priv->tx_path_in_lpi_mode = false;
  1429. }
  1430. if (status & core_irq_rx_path_in_lpi_mode)
  1431. priv->xstats.irq_rx_path_in_lpi_mode_n++;
  1432. if (status & core_irq_rx_path_exit_lpi_mode)
  1433. priv->xstats.irq_rx_path_exit_lpi_mode_n++;
  1434. }
  1435. }
  1436. /* To handle DMA interrupts */
  1437. stmmac_dma_interrupt(priv);
  1438. return IRQ_HANDLED;
  1439. }
  1440. #ifdef CONFIG_NET_POLL_CONTROLLER
  1441. /* Polling receive - used by NETCONSOLE and other diagnostic tools
  1442. * to allow network I/O with interrupts disabled. */
  1443. static void stmmac_poll_controller(struct net_device *dev)
  1444. {
  1445. disable_irq(dev->irq);
  1446. stmmac_interrupt(dev->irq, dev);
  1447. enable_irq(dev->irq);
  1448. }
  1449. #endif
  1450. /**
  1451. * stmmac_ioctl - Entry point for the Ioctl
  1452. * @dev: Device pointer.
  1453. * @rq: An IOCTL specefic structure, that can contain a pointer to
  1454. * a proprietary structure used to pass information to the driver.
  1455. * @cmd: IOCTL command
  1456. * Description:
  1457. * Currently there are no special functionality supported in IOCTL, just the
  1458. * phy_mii_ioctl(...) can be invoked.
  1459. */
  1460. static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1461. {
  1462. struct stmmac_priv *priv = netdev_priv(dev);
  1463. int ret;
  1464. if (!netif_running(dev))
  1465. return -EINVAL;
  1466. if (!priv->phydev)
  1467. return -EINVAL;
  1468. ret = phy_mii_ioctl(priv->phydev, rq, cmd);
  1469. return ret;
  1470. }
  1471. #ifdef CONFIG_STMMAC_DEBUG_FS
  1472. static struct dentry *stmmac_fs_dir;
  1473. static struct dentry *stmmac_rings_status;
  1474. static struct dentry *stmmac_dma_cap;
  1475. static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
  1476. {
  1477. struct tmp_s {
  1478. u64 a;
  1479. unsigned int b;
  1480. unsigned int c;
  1481. };
  1482. int i;
  1483. struct net_device *dev = seq->private;
  1484. struct stmmac_priv *priv = netdev_priv(dev);
  1485. seq_printf(seq, "=======================\n");
  1486. seq_printf(seq, " RX descriptor ring\n");
  1487. seq_printf(seq, "=======================\n");
  1488. for (i = 0; i < priv->dma_rx_size; i++) {
  1489. struct tmp_s *x = (struct tmp_s *)(priv->dma_rx + i);
  1490. seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
  1491. i, (unsigned int)(x->a),
  1492. (unsigned int)((x->a) >> 32), x->b, x->c);
  1493. seq_printf(seq, "\n");
  1494. }
  1495. seq_printf(seq, "\n");
  1496. seq_printf(seq, "=======================\n");
  1497. seq_printf(seq, " TX descriptor ring\n");
  1498. seq_printf(seq, "=======================\n");
  1499. for (i = 0; i < priv->dma_tx_size; i++) {
  1500. struct tmp_s *x = (struct tmp_s *)(priv->dma_tx + i);
  1501. seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
  1502. i, (unsigned int)(x->a),
  1503. (unsigned int)((x->a) >> 32), x->b, x->c);
  1504. seq_printf(seq, "\n");
  1505. }
  1506. return 0;
  1507. }
  1508. static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file)
  1509. {
  1510. return single_open(file, stmmac_sysfs_ring_read, inode->i_private);
  1511. }
  1512. static const struct file_operations stmmac_rings_status_fops = {
  1513. .owner = THIS_MODULE,
  1514. .open = stmmac_sysfs_ring_open,
  1515. .read = seq_read,
  1516. .llseek = seq_lseek,
  1517. .release = single_release,
  1518. };
  1519. static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
  1520. {
  1521. struct net_device *dev = seq->private;
  1522. struct stmmac_priv *priv = netdev_priv(dev);
  1523. if (!priv->hw_cap_support) {
  1524. seq_printf(seq, "DMA HW features not supported\n");
  1525. return 0;
  1526. }
  1527. seq_printf(seq, "==============================\n");
  1528. seq_printf(seq, "\tDMA HW features\n");
  1529. seq_printf(seq, "==============================\n");
  1530. seq_printf(seq, "\t10/100 Mbps %s\n",
  1531. (priv->dma_cap.mbps_10_100) ? "Y" : "N");
  1532. seq_printf(seq, "\t1000 Mbps %s\n",
  1533. (priv->dma_cap.mbps_1000) ? "Y" : "N");
  1534. seq_printf(seq, "\tHalf duple %s\n",
  1535. (priv->dma_cap.half_duplex) ? "Y" : "N");
  1536. seq_printf(seq, "\tHash Filter: %s\n",
  1537. (priv->dma_cap.hash_filter) ? "Y" : "N");
  1538. seq_printf(seq, "\tMultiple MAC address registers: %s\n",
  1539. (priv->dma_cap.multi_addr) ? "Y" : "N");
  1540. seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
  1541. (priv->dma_cap.pcs) ? "Y" : "N");
  1542. seq_printf(seq, "\tSMA (MDIO) Interface: %s\n",
  1543. (priv->dma_cap.sma_mdio) ? "Y" : "N");
  1544. seq_printf(seq, "\tPMT Remote wake up: %s\n",
  1545. (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N");
  1546. seq_printf(seq, "\tPMT Magic Frame: %s\n",
  1547. (priv->dma_cap.pmt_magic_frame) ? "Y" : "N");
  1548. seq_printf(seq, "\tRMON module: %s\n",
  1549. (priv->dma_cap.rmon) ? "Y" : "N");
  1550. seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n",
  1551. (priv->dma_cap.time_stamp) ? "Y" : "N");
  1552. seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
  1553. (priv->dma_cap.atime_stamp) ? "Y" : "N");
  1554. seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
  1555. (priv->dma_cap.eee) ? "Y" : "N");
  1556. seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N");
  1557. seq_printf(seq, "\tChecksum Offload in TX: %s\n",
  1558. (priv->dma_cap.tx_coe) ? "Y" : "N");
  1559. seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n",
  1560. (priv->dma_cap.rx_coe_type1) ? "Y" : "N");
  1561. seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n",
  1562. (priv->dma_cap.rx_coe_type2) ? "Y" : "N");
  1563. seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n",
  1564. (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N");
  1565. seq_printf(seq, "\tNumber of Additional RX channel: %d\n",
  1566. priv->dma_cap.number_rx_channel);
  1567. seq_printf(seq, "\tNumber of Additional TX channel: %d\n",
  1568. priv->dma_cap.number_tx_channel);
  1569. seq_printf(seq, "\tEnhanced descriptors: %s\n",
  1570. (priv->dma_cap.enh_desc) ? "Y" : "N");
  1571. return 0;
  1572. }
  1573. static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file)
  1574. {
  1575. return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private);
  1576. }
  1577. static const struct file_operations stmmac_dma_cap_fops = {
  1578. .owner = THIS_MODULE,
  1579. .open = stmmac_sysfs_dma_cap_open,
  1580. .read = seq_read,
  1581. .llseek = seq_lseek,
  1582. .release = single_release,
  1583. };
  1584. static int stmmac_init_fs(struct net_device *dev)
  1585. {
  1586. /* Create debugfs entries */
  1587. stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
  1588. if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
  1589. pr_err("ERROR %s, debugfs create directory failed\n",
  1590. STMMAC_RESOURCE_NAME);
  1591. return -ENOMEM;
  1592. }
  1593. /* Entry to report DMA RX/TX rings */
  1594. stmmac_rings_status = debugfs_create_file("descriptors_status",
  1595. S_IRUGO, stmmac_fs_dir, dev,
  1596. &stmmac_rings_status_fops);
  1597. if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
  1598. pr_info("ERROR creating stmmac ring debugfs file\n");
  1599. debugfs_remove(stmmac_fs_dir);
  1600. return -ENOMEM;
  1601. }
  1602. /* Entry to report the DMA HW features */
  1603. stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
  1604. dev, &stmmac_dma_cap_fops);
  1605. if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
  1606. pr_info("ERROR creating stmmac MMC debugfs file\n");
  1607. debugfs_remove(stmmac_rings_status);
  1608. debugfs_remove(stmmac_fs_dir);
  1609. return -ENOMEM;
  1610. }
  1611. return 0;
  1612. }
  1613. static void stmmac_exit_fs(void)
  1614. {
  1615. debugfs_remove(stmmac_rings_status);
  1616. debugfs_remove(stmmac_dma_cap);
  1617. debugfs_remove(stmmac_fs_dir);
  1618. }
  1619. #endif /* CONFIG_STMMAC_DEBUG_FS */
  1620. static const struct net_device_ops stmmac_netdev_ops = {
  1621. .ndo_open = stmmac_open,
  1622. .ndo_start_xmit = stmmac_xmit,
  1623. .ndo_stop = stmmac_release,
  1624. .ndo_change_mtu = stmmac_change_mtu,
  1625. .ndo_fix_features = stmmac_fix_features,
  1626. .ndo_set_rx_mode = stmmac_set_rx_mode,
  1627. .ndo_tx_timeout = stmmac_tx_timeout,
  1628. .ndo_do_ioctl = stmmac_ioctl,
  1629. .ndo_set_config = stmmac_config,
  1630. #ifdef CONFIG_NET_POLL_CONTROLLER
  1631. .ndo_poll_controller = stmmac_poll_controller,
  1632. #endif
  1633. .ndo_set_mac_address = eth_mac_addr,
  1634. };
  1635. /**
  1636. * stmmac_hw_init - Init the MAC device
  1637. * @priv : pointer to the private device structure.
  1638. * Description: this function detects which MAC device
  1639. * (GMAC/MAC10-100) has to attached, checks the HW capability
  1640. * (if supported) and sets the driver's features (for example
  1641. * to use the ring or chaine mode or support the normal/enh
  1642. * descriptor structure).
  1643. */
  1644. static int stmmac_hw_init(struct stmmac_priv *priv)
  1645. {
  1646. int ret = 0;
  1647. struct mac_device_info *mac;
  1648. /* Identify the MAC HW device */
  1649. if (priv->plat->has_gmac) {
  1650. priv->dev->priv_flags |= IFF_UNICAST_FLT;
  1651. mac = dwmac1000_setup(priv->ioaddr);
  1652. } else {
  1653. mac = dwmac100_setup(priv->ioaddr);
  1654. }
  1655. if (!mac)
  1656. return -ENOMEM;
  1657. priv->hw = mac;
  1658. /* To use the chained or ring mode */
  1659. priv->hw->ring = &ring_mode_ops;
  1660. /* Get and dump the chip ID */
  1661. priv->synopsys_id = stmmac_get_synopsys_id(priv);
  1662. /* Get the HW capability (new GMAC newer than 3.50a) */
  1663. priv->hw_cap_support = stmmac_get_hw_features(priv);
  1664. if (priv->hw_cap_support) {
  1665. pr_info(" DMA HW capability register supported");
  1666. /* We can override some gmac/dma configuration fields: e.g.
  1667. * enh_desc, tx_coe (e.g. that are passed through the
  1668. * platform) with the values from the HW capability
  1669. * register (if supported).
  1670. */
  1671. priv->plat->enh_desc = priv->dma_cap.enh_desc;
  1672. priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
  1673. priv->plat->tx_coe = priv->dma_cap.tx_coe;
  1674. if (priv->dma_cap.rx_coe_type2)
  1675. priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
  1676. else if (priv->dma_cap.rx_coe_type1)
  1677. priv->plat->rx_coe = STMMAC_RX_COE_TYPE1;
  1678. } else
  1679. pr_info(" No HW DMA feature register supported");
  1680. /* Select the enhnaced/normal descriptor structures */
  1681. stmmac_selec_desc_mode(priv);
  1682. /* Enable the IPC (Checksum Offload) and check if the feature has been
  1683. * enabled during the core configuration. */
  1684. ret = priv->hw->mac->rx_ipc(priv->ioaddr);
  1685. if (!ret) {
  1686. pr_warning(" RX IPC Checksum Offload not configured.\n");
  1687. priv->plat->rx_coe = STMMAC_RX_COE_NONE;
  1688. }
  1689. if (priv->plat->rx_coe)
  1690. pr_info(" RX Checksum Offload Engine supported (type %d)\n",
  1691. priv->plat->rx_coe);
  1692. if (priv->plat->tx_coe)
  1693. pr_info(" TX Checksum insertion supported\n");
  1694. if (priv->plat->pmt) {
  1695. pr_info(" Wake-Up On Lan supported\n");
  1696. device_set_wakeup_capable(priv->device, 1);
  1697. }
  1698. return ret;
  1699. }
  1700. /**
  1701. * stmmac_dvr_probe
  1702. * @device: device pointer
  1703. * @plat_dat: platform data pointer
  1704. * @addr: iobase memory address
  1705. * Description: this is the main probe function used to
  1706. * call the alloc_etherdev, allocate the priv structure.
  1707. */
  1708. struct stmmac_priv *stmmac_dvr_probe(struct device *device,
  1709. struct plat_stmmacenet_data *plat_dat,
  1710. void __iomem *addr)
  1711. {
  1712. int ret = 0;
  1713. struct net_device *ndev = NULL;
  1714. struct stmmac_priv *priv;
  1715. ndev = alloc_etherdev(sizeof(struct stmmac_priv));
  1716. if (!ndev)
  1717. return NULL;
  1718. SET_NETDEV_DEV(ndev, device);
  1719. priv = netdev_priv(ndev);
  1720. priv->device = device;
  1721. priv->dev = ndev;
  1722. ether_setup(ndev);
  1723. stmmac_set_ethtool_ops(ndev);
  1724. priv->pause = pause;
  1725. priv->plat = plat_dat;
  1726. priv->ioaddr = addr;
  1727. priv->dev->base_addr = (unsigned long)addr;
  1728. /* Verify driver arguments */
  1729. stmmac_verify_args();
  1730. /* Override with kernel parameters if supplied XXX CRS XXX
  1731. * this needs to have multiple instances */
  1732. if ((phyaddr >= 0) && (phyaddr <= 31))
  1733. priv->plat->phy_addr = phyaddr;
  1734. /* Init MAC and get the capabilities */
  1735. stmmac_hw_init(priv);
  1736. ndev->netdev_ops = &stmmac_netdev_ops;
  1737. ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  1738. NETIF_F_RXCSUM;
  1739. ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
  1740. ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
  1741. #ifdef STMMAC_VLAN_TAG_USED
  1742. /* Both mac100 and gmac support receive VLAN tag detection */
  1743. ndev->features |= NETIF_F_HW_VLAN_RX;
  1744. #endif
  1745. priv->msg_enable = netif_msg_init(debug, default_msg_level);
  1746. if (flow_ctrl)
  1747. priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
  1748. netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
  1749. spin_lock_init(&priv->lock);
  1750. spin_lock_init(&priv->tx_lock);
  1751. ret = register_netdev(ndev);
  1752. if (ret) {
  1753. pr_err("%s: ERROR %i registering the device\n", __func__, ret);
  1754. goto error;
  1755. }
  1756. if (stmmac_clk_get(priv))
  1757. pr_warning("%s: warning: cannot get CSR clock\n", __func__);
  1758. /* If a specific clk_csr value is passed from the platform
  1759. * this means that the CSR Clock Range selection cannot be
  1760. * changed at run-time and it is fixed. Viceversa the driver'll try to
  1761. * set the MDC clock dynamically according to the csr actual
  1762. * clock input.
  1763. */
  1764. if (!priv->plat->clk_csr)
  1765. stmmac_clk_csr_set(priv);
  1766. else
  1767. priv->clk_csr = priv->plat->clk_csr;
  1768. /* MDIO bus Registration */
  1769. ret = stmmac_mdio_register(ndev);
  1770. if (ret < 0) {
  1771. pr_debug("%s: MDIO bus (id: %d) registration failed",
  1772. __func__, priv->plat->bus_id);
  1773. goto error;
  1774. }
  1775. return priv;
  1776. error:
  1777. netif_napi_del(&priv->napi);
  1778. unregister_netdev(ndev);
  1779. free_netdev(ndev);
  1780. return NULL;
  1781. }
  1782. /**
  1783. * stmmac_dvr_remove
  1784. * @ndev: net device pointer
  1785. * Description: this function resets the TX/RX processes, disables the MAC RX/TX
  1786. * changes the link status, releases the DMA descriptor rings.
  1787. */
  1788. int stmmac_dvr_remove(struct net_device *ndev)
  1789. {
  1790. struct stmmac_priv *priv = netdev_priv(ndev);
  1791. pr_info("%s:\n\tremoving driver", __func__);
  1792. priv->hw->dma->stop_rx(priv->ioaddr);
  1793. priv->hw->dma->stop_tx(priv->ioaddr);
  1794. stmmac_set_mac(priv->ioaddr, false);
  1795. stmmac_mdio_unregister(ndev);
  1796. netif_carrier_off(ndev);
  1797. unregister_netdev(ndev);
  1798. free_netdev(ndev);
  1799. return 0;
  1800. }
  1801. #ifdef CONFIG_PM
  1802. int stmmac_suspend(struct net_device *ndev)
  1803. {
  1804. struct stmmac_priv *priv = netdev_priv(ndev);
  1805. int dis_ic = 0;
  1806. unsigned long flags;
  1807. if (!ndev || !netif_running(ndev))
  1808. return 0;
  1809. if (priv->phydev)
  1810. phy_stop(priv->phydev);
  1811. spin_lock_irqsave(&priv->lock, flags);
  1812. netif_device_detach(ndev);
  1813. netif_stop_queue(ndev);
  1814. #ifdef CONFIG_STMMAC_TIMER
  1815. priv->tm->timer_stop();
  1816. if (likely(priv->tm->enable))
  1817. dis_ic = 1;
  1818. #endif
  1819. napi_disable(&priv->napi);
  1820. /* Stop TX/RX DMA */
  1821. priv->hw->dma->stop_tx(priv->ioaddr);
  1822. priv->hw->dma->stop_rx(priv->ioaddr);
  1823. /* Clear the Rx/Tx descriptors */
  1824. priv->hw->desc->init_rx_desc(priv->dma_rx, priv->dma_rx_size,
  1825. dis_ic);
  1826. priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
  1827. /* Enable Power down mode by programming the PMT regs */
  1828. if (device_may_wakeup(priv->device))
  1829. priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
  1830. else {
  1831. stmmac_set_mac(priv->ioaddr, false);
  1832. /* Disable clock in case of PWM is off */
  1833. stmmac_clk_disable(priv);
  1834. }
  1835. spin_unlock_irqrestore(&priv->lock, flags);
  1836. return 0;
  1837. }
  1838. int stmmac_resume(struct net_device *ndev)
  1839. {
  1840. struct stmmac_priv *priv = netdev_priv(ndev);
  1841. unsigned long flags;
  1842. if (!netif_running(ndev))
  1843. return 0;
  1844. spin_lock_irqsave(&priv->lock, flags);
  1845. /* Power Down bit, into the PM register, is cleared
  1846. * automatically as soon as a magic packet or a Wake-up frame
  1847. * is received. Anyway, it's better to manually clear
  1848. * this bit because it can generate problems while resuming
  1849. * from another devices (e.g. serial console). */
  1850. if (device_may_wakeup(priv->device))
  1851. priv->hw->mac->pmt(priv->ioaddr, 0);
  1852. else
  1853. /* enable the clk prevously disabled */
  1854. stmmac_clk_enable(priv);
  1855. netif_device_attach(ndev);
  1856. /* Enable the MAC and DMA */
  1857. stmmac_set_mac(priv->ioaddr, true);
  1858. priv->hw->dma->start_tx(priv->ioaddr);
  1859. priv->hw->dma->start_rx(priv->ioaddr);
  1860. #ifdef CONFIG_STMMAC_TIMER
  1861. if (likely(priv->tm->enable))
  1862. priv->tm->timer_start(tmrate);
  1863. #endif
  1864. napi_enable(&priv->napi);
  1865. netif_start_queue(ndev);
  1866. spin_unlock_irqrestore(&priv->lock, flags);
  1867. if (priv->phydev)
  1868. phy_start(priv->phydev);
  1869. return 0;
  1870. }
  1871. int stmmac_freeze(struct net_device *ndev)
  1872. {
  1873. if (!ndev || !netif_running(ndev))
  1874. return 0;
  1875. return stmmac_release(ndev);
  1876. }
  1877. int stmmac_restore(struct net_device *ndev)
  1878. {
  1879. if (!ndev || !netif_running(ndev))
  1880. return 0;
  1881. return stmmac_open(ndev);
  1882. }
  1883. #endif /* CONFIG_PM */
  1884. /* Driver can be configured w/ and w/ both PCI and Platf drivers
  1885. * depending on the configuration selected.
  1886. */
  1887. static int __init stmmac_init(void)
  1888. {
  1889. int err_plt = 0;
  1890. int err_pci = 0;
  1891. err_plt = stmmac_register_platform();
  1892. err_pci = stmmac_register_pci();
  1893. if ((err_pci) && (err_plt)) {
  1894. pr_err("stmmac: driver registration failed\n");
  1895. return -EINVAL;
  1896. }
  1897. return 0;
  1898. }
  1899. static void __exit stmmac_exit(void)
  1900. {
  1901. stmmac_unregister_platform();
  1902. stmmac_unregister_pci();
  1903. }
  1904. module_init(stmmac_init);
  1905. module_exit(stmmac_exit);
  1906. #ifndef MODULE
  1907. static int __init stmmac_cmdline_opt(char *str)
  1908. {
  1909. char *opt;
  1910. if (!str || !*str)
  1911. return -EINVAL;
  1912. while ((opt = strsep(&str, ",")) != NULL) {
  1913. if (!strncmp(opt, "debug:", 6)) {
  1914. if (kstrtoint(opt + 6, 0, &debug))
  1915. goto err;
  1916. } else if (!strncmp(opt, "phyaddr:", 8)) {
  1917. if (kstrtoint(opt + 8, 0, &phyaddr))
  1918. goto err;
  1919. } else if (!strncmp(opt, "dma_txsize:", 11)) {
  1920. if (kstrtoint(opt + 11, 0, &dma_txsize))
  1921. goto err;
  1922. } else if (!strncmp(opt, "dma_rxsize:", 11)) {
  1923. if (kstrtoint(opt + 11, 0, &dma_rxsize))
  1924. goto err;
  1925. } else if (!strncmp(opt, "buf_sz:", 7)) {
  1926. if (kstrtoint(opt + 7, 0, &buf_sz))
  1927. goto err;
  1928. } else if (!strncmp(opt, "tc:", 3)) {
  1929. if (kstrtoint(opt + 3, 0, &tc))
  1930. goto err;
  1931. } else if (!strncmp(opt, "watchdog:", 9)) {
  1932. if (kstrtoint(opt + 9, 0, &watchdog))
  1933. goto err;
  1934. } else if (!strncmp(opt, "flow_ctrl:", 10)) {
  1935. if (kstrtoint(opt + 10, 0, &flow_ctrl))
  1936. goto err;
  1937. } else if (!strncmp(opt, "pause:", 6)) {
  1938. if (kstrtoint(opt + 6, 0, &pause))
  1939. goto err;
  1940. } else if (!strncmp(opt, "eee_timer:", 6)) {
  1941. if (kstrtoint(opt + 10, 0, &eee_timer))
  1942. goto err;
  1943. #ifdef CONFIG_STMMAC_TIMER
  1944. } else if (!strncmp(opt, "tmrate:", 7)) {
  1945. if (kstrtoint(opt + 7, 0, &tmrate))
  1946. goto err;
  1947. #endif
  1948. }
  1949. }
  1950. return 0;
  1951. err:
  1952. pr_err("%s: ERROR broken module parameter conversion", __func__);
  1953. return -EINVAL;
  1954. }
  1955. __setup("stmmaceth=", stmmac_cmdline_opt);
  1956. #endif
  1957. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
  1958. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  1959. MODULE_LICENSE("GPL");