stmmac_main.c 63 KB

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