stmmac_main.c 62 KB

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