igb_ethtool.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437
  1. /* Intel(R) Gigabit Ethernet Linux driver
  2. * Copyright(c) 2007-2014 Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  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. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * The full GNU General Public License is included in this distribution in
  17. * the file called "COPYING".
  18. *
  19. * Contact Information:
  20. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  21. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  22. */
  23. /* ethtool support for igb */
  24. #include <linux/vmalloc.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/pci.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/if_ether.h>
  30. #include <linux/ethtool.h>
  31. #include <linux/sched.h>
  32. #include <linux/slab.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/highmem.h>
  35. #include <linux/mdio.h>
  36. #include "igb.h"
  37. struct igb_stats {
  38. char stat_string[ETH_GSTRING_LEN];
  39. int sizeof_stat;
  40. int stat_offset;
  41. };
  42. #define IGB_STAT(_name, _stat) { \
  43. .stat_string = _name, \
  44. .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \
  45. .stat_offset = offsetof(struct igb_adapter, _stat) \
  46. }
  47. static const struct igb_stats igb_gstrings_stats[] = {
  48. IGB_STAT("rx_packets", stats.gprc),
  49. IGB_STAT("tx_packets", stats.gptc),
  50. IGB_STAT("rx_bytes", stats.gorc),
  51. IGB_STAT("tx_bytes", stats.gotc),
  52. IGB_STAT("rx_broadcast", stats.bprc),
  53. IGB_STAT("tx_broadcast", stats.bptc),
  54. IGB_STAT("rx_multicast", stats.mprc),
  55. IGB_STAT("tx_multicast", stats.mptc),
  56. IGB_STAT("multicast", stats.mprc),
  57. IGB_STAT("collisions", stats.colc),
  58. IGB_STAT("rx_crc_errors", stats.crcerrs),
  59. IGB_STAT("rx_no_buffer_count", stats.rnbc),
  60. IGB_STAT("rx_missed_errors", stats.mpc),
  61. IGB_STAT("tx_aborted_errors", stats.ecol),
  62. IGB_STAT("tx_carrier_errors", stats.tncrs),
  63. IGB_STAT("tx_window_errors", stats.latecol),
  64. IGB_STAT("tx_abort_late_coll", stats.latecol),
  65. IGB_STAT("tx_deferred_ok", stats.dc),
  66. IGB_STAT("tx_single_coll_ok", stats.scc),
  67. IGB_STAT("tx_multi_coll_ok", stats.mcc),
  68. IGB_STAT("tx_timeout_count", tx_timeout_count),
  69. IGB_STAT("rx_long_length_errors", stats.roc),
  70. IGB_STAT("rx_short_length_errors", stats.ruc),
  71. IGB_STAT("rx_align_errors", stats.algnerrc),
  72. IGB_STAT("tx_tcp_seg_good", stats.tsctc),
  73. IGB_STAT("tx_tcp_seg_failed", stats.tsctfc),
  74. IGB_STAT("rx_flow_control_xon", stats.xonrxc),
  75. IGB_STAT("rx_flow_control_xoff", stats.xoffrxc),
  76. IGB_STAT("tx_flow_control_xon", stats.xontxc),
  77. IGB_STAT("tx_flow_control_xoff", stats.xofftxc),
  78. IGB_STAT("rx_long_byte_count", stats.gorc),
  79. IGB_STAT("tx_dma_out_of_sync", stats.doosync),
  80. IGB_STAT("tx_smbus", stats.mgptc),
  81. IGB_STAT("rx_smbus", stats.mgprc),
  82. IGB_STAT("dropped_smbus", stats.mgpdc),
  83. IGB_STAT("os2bmc_rx_by_bmc", stats.o2bgptc),
  84. IGB_STAT("os2bmc_tx_by_bmc", stats.b2ospc),
  85. IGB_STAT("os2bmc_tx_by_host", stats.o2bspc),
  86. IGB_STAT("os2bmc_rx_by_host", stats.b2ogprc),
  87. IGB_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
  88. IGB_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  89. };
  90. #define IGB_NETDEV_STAT(_net_stat) { \
  91. .stat_string = __stringify(_net_stat), \
  92. .sizeof_stat = FIELD_SIZEOF(struct rtnl_link_stats64, _net_stat), \
  93. .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
  94. }
  95. static const struct igb_stats igb_gstrings_net_stats[] = {
  96. IGB_NETDEV_STAT(rx_errors),
  97. IGB_NETDEV_STAT(tx_errors),
  98. IGB_NETDEV_STAT(tx_dropped),
  99. IGB_NETDEV_STAT(rx_length_errors),
  100. IGB_NETDEV_STAT(rx_over_errors),
  101. IGB_NETDEV_STAT(rx_frame_errors),
  102. IGB_NETDEV_STAT(rx_fifo_errors),
  103. IGB_NETDEV_STAT(tx_fifo_errors),
  104. IGB_NETDEV_STAT(tx_heartbeat_errors)
  105. };
  106. #define IGB_GLOBAL_STATS_LEN \
  107. (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats))
  108. #define IGB_NETDEV_STATS_LEN \
  109. (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats))
  110. #define IGB_RX_QUEUE_STATS_LEN \
  111. (sizeof(struct igb_rx_queue_stats) / sizeof(u64))
  112. #define IGB_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */
  113. #define IGB_QUEUE_STATS_LEN \
  114. ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \
  115. IGB_RX_QUEUE_STATS_LEN) + \
  116. (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \
  117. IGB_TX_QUEUE_STATS_LEN))
  118. #define IGB_STATS_LEN \
  119. (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN)
  120. enum igb_diagnostics_results {
  121. TEST_REG = 0,
  122. TEST_EEP,
  123. TEST_IRQ,
  124. TEST_LOOP,
  125. TEST_LINK
  126. };
  127. static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
  128. [TEST_REG] = "Register test (offline)",
  129. [TEST_EEP] = "Eeprom test (offline)",
  130. [TEST_IRQ] = "Interrupt test (offline)",
  131. [TEST_LOOP] = "Loopback test (offline)",
  132. [TEST_LINK] = "Link test (on/offline)"
  133. };
  134. #define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
  135. static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  136. {
  137. struct igb_adapter *adapter = netdev_priv(netdev);
  138. struct e1000_hw *hw = &adapter->hw;
  139. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  140. struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
  141. u32 status;
  142. u32 speed;
  143. status = rd32(E1000_STATUS);
  144. if (hw->phy.media_type == e1000_media_type_copper) {
  145. ecmd->supported = (SUPPORTED_10baseT_Half |
  146. SUPPORTED_10baseT_Full |
  147. SUPPORTED_100baseT_Half |
  148. SUPPORTED_100baseT_Full |
  149. SUPPORTED_1000baseT_Full|
  150. SUPPORTED_Autoneg |
  151. SUPPORTED_TP |
  152. SUPPORTED_Pause);
  153. ecmd->advertising = ADVERTISED_TP;
  154. if (hw->mac.autoneg == 1) {
  155. ecmd->advertising |= ADVERTISED_Autoneg;
  156. /* the e1000 autoneg seems to match ethtool nicely */
  157. ecmd->advertising |= hw->phy.autoneg_advertised;
  158. }
  159. ecmd->port = PORT_TP;
  160. ecmd->phy_address = hw->phy.addr;
  161. ecmd->transceiver = XCVR_INTERNAL;
  162. } else {
  163. ecmd->supported = (SUPPORTED_FIBRE |
  164. SUPPORTED_1000baseKX_Full |
  165. SUPPORTED_Autoneg |
  166. SUPPORTED_Pause);
  167. ecmd->advertising = (ADVERTISED_FIBRE |
  168. ADVERTISED_1000baseKX_Full);
  169. if (hw->mac.type == e1000_i354) {
  170. if ((hw->device_id ==
  171. E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) &&
  172. !(status & E1000_STATUS_2P5_SKU_OVER)) {
  173. ecmd->supported |= SUPPORTED_2500baseX_Full;
  174. ecmd->supported &=
  175. ~SUPPORTED_1000baseKX_Full;
  176. ecmd->advertising |= ADVERTISED_2500baseX_Full;
  177. ecmd->advertising &=
  178. ~ADVERTISED_1000baseKX_Full;
  179. }
  180. }
  181. if (eth_flags->e100_base_fx) {
  182. ecmd->supported |= SUPPORTED_100baseT_Full;
  183. ecmd->advertising |= ADVERTISED_100baseT_Full;
  184. }
  185. if (hw->mac.autoneg == 1)
  186. ecmd->advertising |= ADVERTISED_Autoneg;
  187. ecmd->port = PORT_FIBRE;
  188. ecmd->transceiver = XCVR_EXTERNAL;
  189. }
  190. if (hw->mac.autoneg != 1)
  191. ecmd->advertising &= ~(ADVERTISED_Pause |
  192. ADVERTISED_Asym_Pause);
  193. switch (hw->fc.requested_mode) {
  194. case e1000_fc_full:
  195. ecmd->advertising |= ADVERTISED_Pause;
  196. break;
  197. case e1000_fc_rx_pause:
  198. ecmd->advertising |= (ADVERTISED_Pause |
  199. ADVERTISED_Asym_Pause);
  200. break;
  201. case e1000_fc_tx_pause:
  202. ecmd->advertising |= ADVERTISED_Asym_Pause;
  203. break;
  204. default:
  205. ecmd->advertising &= ~(ADVERTISED_Pause |
  206. ADVERTISED_Asym_Pause);
  207. }
  208. if (status & E1000_STATUS_LU) {
  209. if ((status & E1000_STATUS_2P5_SKU) &&
  210. !(status & E1000_STATUS_2P5_SKU_OVER)) {
  211. speed = SPEED_2500;
  212. } else if (status & E1000_STATUS_SPEED_1000) {
  213. speed = SPEED_1000;
  214. } else if (status & E1000_STATUS_SPEED_100) {
  215. speed = SPEED_100;
  216. } else {
  217. speed = SPEED_10;
  218. }
  219. if ((status & E1000_STATUS_FD) ||
  220. hw->phy.media_type != e1000_media_type_copper)
  221. ecmd->duplex = DUPLEX_FULL;
  222. else
  223. ecmd->duplex = DUPLEX_HALF;
  224. } else {
  225. speed = SPEED_UNKNOWN;
  226. ecmd->duplex = DUPLEX_UNKNOWN;
  227. }
  228. ethtool_cmd_speed_set(ecmd, speed);
  229. if ((hw->phy.media_type == e1000_media_type_fiber) ||
  230. hw->mac.autoneg)
  231. ecmd->autoneg = AUTONEG_ENABLE;
  232. else
  233. ecmd->autoneg = AUTONEG_DISABLE;
  234. /* MDI-X => 2; MDI =>1; Invalid =>0 */
  235. if (hw->phy.media_type == e1000_media_type_copper)
  236. ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
  237. ETH_TP_MDI;
  238. else
  239. ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
  240. if (hw->phy.mdix == AUTO_ALL_MODES)
  241. ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
  242. else
  243. ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
  244. return 0;
  245. }
  246. static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  247. {
  248. struct igb_adapter *adapter = netdev_priv(netdev);
  249. struct e1000_hw *hw = &adapter->hw;
  250. /* When SoL/IDER sessions are active, autoneg/speed/duplex
  251. * cannot be changed
  252. */
  253. if (igb_check_reset_block(hw)) {
  254. dev_err(&adapter->pdev->dev,
  255. "Cannot change link characteristics when SoL/IDER is active.\n");
  256. return -EINVAL;
  257. }
  258. /* MDI setting is only allowed when autoneg enabled because
  259. * some hardware doesn't allow MDI setting when speed or
  260. * duplex is forced.
  261. */
  262. if (ecmd->eth_tp_mdix_ctrl) {
  263. if (hw->phy.media_type != e1000_media_type_copper)
  264. return -EOPNOTSUPP;
  265. if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
  266. (ecmd->autoneg != AUTONEG_ENABLE)) {
  267. dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
  268. return -EINVAL;
  269. }
  270. }
  271. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  272. usleep_range(1000, 2000);
  273. if (ecmd->autoneg == AUTONEG_ENABLE) {
  274. hw->mac.autoneg = 1;
  275. if (hw->phy.media_type == e1000_media_type_fiber) {
  276. hw->phy.autoneg_advertised = ecmd->advertising |
  277. ADVERTISED_FIBRE |
  278. ADVERTISED_Autoneg;
  279. switch (adapter->link_speed) {
  280. case SPEED_2500:
  281. hw->phy.autoneg_advertised =
  282. ADVERTISED_2500baseX_Full;
  283. break;
  284. case SPEED_1000:
  285. hw->phy.autoneg_advertised =
  286. ADVERTISED_1000baseT_Full;
  287. break;
  288. case SPEED_100:
  289. hw->phy.autoneg_advertised =
  290. ADVERTISED_100baseT_Full;
  291. break;
  292. default:
  293. break;
  294. }
  295. } else {
  296. hw->phy.autoneg_advertised = ecmd->advertising |
  297. ADVERTISED_TP |
  298. ADVERTISED_Autoneg;
  299. }
  300. ecmd->advertising = hw->phy.autoneg_advertised;
  301. if (adapter->fc_autoneg)
  302. hw->fc.requested_mode = e1000_fc_default;
  303. } else {
  304. u32 speed = ethtool_cmd_speed(ecmd);
  305. /* calling this overrides forced MDI setting */
  306. if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) {
  307. clear_bit(__IGB_RESETTING, &adapter->state);
  308. return -EINVAL;
  309. }
  310. }
  311. /* MDI-X => 2; MDI => 1; Auto => 3 */
  312. if (ecmd->eth_tp_mdix_ctrl) {
  313. /* fix up the value for auto (3 => 0) as zero is mapped
  314. * internally to auto
  315. */
  316. if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
  317. hw->phy.mdix = AUTO_ALL_MODES;
  318. else
  319. hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
  320. }
  321. /* reset the link */
  322. if (netif_running(adapter->netdev)) {
  323. igb_down(adapter);
  324. igb_up(adapter);
  325. } else
  326. igb_reset(adapter);
  327. clear_bit(__IGB_RESETTING, &adapter->state);
  328. return 0;
  329. }
  330. static u32 igb_get_link(struct net_device *netdev)
  331. {
  332. struct igb_adapter *adapter = netdev_priv(netdev);
  333. struct e1000_mac_info *mac = &adapter->hw.mac;
  334. /* If the link is not reported up to netdev, interrupts are disabled,
  335. * and so the physical link state may have changed since we last
  336. * looked. Set get_link_status to make sure that the true link
  337. * state is interrogated, rather than pulling a cached and possibly
  338. * stale link state from the driver.
  339. */
  340. if (!netif_carrier_ok(netdev))
  341. mac->get_link_status = 1;
  342. return igb_has_link(adapter);
  343. }
  344. static void igb_get_pauseparam(struct net_device *netdev,
  345. struct ethtool_pauseparam *pause)
  346. {
  347. struct igb_adapter *adapter = netdev_priv(netdev);
  348. struct e1000_hw *hw = &adapter->hw;
  349. pause->autoneg =
  350. (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
  351. if (hw->fc.current_mode == e1000_fc_rx_pause)
  352. pause->rx_pause = 1;
  353. else if (hw->fc.current_mode == e1000_fc_tx_pause)
  354. pause->tx_pause = 1;
  355. else if (hw->fc.current_mode == e1000_fc_full) {
  356. pause->rx_pause = 1;
  357. pause->tx_pause = 1;
  358. }
  359. }
  360. static int igb_set_pauseparam(struct net_device *netdev,
  361. struct ethtool_pauseparam *pause)
  362. {
  363. struct igb_adapter *adapter = netdev_priv(netdev);
  364. struct e1000_hw *hw = &adapter->hw;
  365. int retval = 0;
  366. /* 100basefx does not support setting link flow control */
  367. if (hw->dev_spec._82575.eth_flags.e100_base_fx)
  368. return -EINVAL;
  369. adapter->fc_autoneg = pause->autoneg;
  370. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  371. usleep_range(1000, 2000);
  372. if (adapter->fc_autoneg == AUTONEG_ENABLE) {
  373. hw->fc.requested_mode = e1000_fc_default;
  374. if (netif_running(adapter->netdev)) {
  375. igb_down(adapter);
  376. igb_up(adapter);
  377. } else {
  378. igb_reset(adapter);
  379. }
  380. } else {
  381. if (pause->rx_pause && pause->tx_pause)
  382. hw->fc.requested_mode = e1000_fc_full;
  383. else if (pause->rx_pause && !pause->tx_pause)
  384. hw->fc.requested_mode = e1000_fc_rx_pause;
  385. else if (!pause->rx_pause && pause->tx_pause)
  386. hw->fc.requested_mode = e1000_fc_tx_pause;
  387. else if (!pause->rx_pause && !pause->tx_pause)
  388. hw->fc.requested_mode = e1000_fc_none;
  389. hw->fc.current_mode = hw->fc.requested_mode;
  390. retval = ((hw->phy.media_type == e1000_media_type_copper) ?
  391. igb_force_mac_fc(hw) : igb_setup_link(hw));
  392. }
  393. clear_bit(__IGB_RESETTING, &adapter->state);
  394. return retval;
  395. }
  396. static u32 igb_get_msglevel(struct net_device *netdev)
  397. {
  398. struct igb_adapter *adapter = netdev_priv(netdev);
  399. return adapter->msg_enable;
  400. }
  401. static void igb_set_msglevel(struct net_device *netdev, u32 data)
  402. {
  403. struct igb_adapter *adapter = netdev_priv(netdev);
  404. adapter->msg_enable = data;
  405. }
  406. static int igb_get_regs_len(struct net_device *netdev)
  407. {
  408. #define IGB_REGS_LEN 739
  409. return IGB_REGS_LEN * sizeof(u32);
  410. }
  411. static void igb_get_regs(struct net_device *netdev,
  412. struct ethtool_regs *regs, void *p)
  413. {
  414. struct igb_adapter *adapter = netdev_priv(netdev);
  415. struct e1000_hw *hw = &adapter->hw;
  416. u32 *regs_buff = p;
  417. u8 i;
  418. memset(p, 0, IGB_REGS_LEN * sizeof(u32));
  419. regs->version = (1u << 24) | (hw->revision_id << 16) | hw->device_id;
  420. /* General Registers */
  421. regs_buff[0] = rd32(E1000_CTRL);
  422. regs_buff[1] = rd32(E1000_STATUS);
  423. regs_buff[2] = rd32(E1000_CTRL_EXT);
  424. regs_buff[3] = rd32(E1000_MDIC);
  425. regs_buff[4] = rd32(E1000_SCTL);
  426. regs_buff[5] = rd32(E1000_CONNSW);
  427. regs_buff[6] = rd32(E1000_VET);
  428. regs_buff[7] = rd32(E1000_LEDCTL);
  429. regs_buff[8] = rd32(E1000_PBA);
  430. regs_buff[9] = rd32(E1000_PBS);
  431. regs_buff[10] = rd32(E1000_FRTIMER);
  432. regs_buff[11] = rd32(E1000_TCPTIMER);
  433. /* NVM Register */
  434. regs_buff[12] = rd32(E1000_EECD);
  435. /* Interrupt */
  436. /* Reading EICS for EICR because they read the
  437. * same but EICS does not clear on read
  438. */
  439. regs_buff[13] = rd32(E1000_EICS);
  440. regs_buff[14] = rd32(E1000_EICS);
  441. regs_buff[15] = rd32(E1000_EIMS);
  442. regs_buff[16] = rd32(E1000_EIMC);
  443. regs_buff[17] = rd32(E1000_EIAC);
  444. regs_buff[18] = rd32(E1000_EIAM);
  445. /* Reading ICS for ICR because they read the
  446. * same but ICS does not clear on read
  447. */
  448. regs_buff[19] = rd32(E1000_ICS);
  449. regs_buff[20] = rd32(E1000_ICS);
  450. regs_buff[21] = rd32(E1000_IMS);
  451. regs_buff[22] = rd32(E1000_IMC);
  452. regs_buff[23] = rd32(E1000_IAC);
  453. regs_buff[24] = rd32(E1000_IAM);
  454. regs_buff[25] = rd32(E1000_IMIRVP);
  455. /* Flow Control */
  456. regs_buff[26] = rd32(E1000_FCAL);
  457. regs_buff[27] = rd32(E1000_FCAH);
  458. regs_buff[28] = rd32(E1000_FCTTV);
  459. regs_buff[29] = rd32(E1000_FCRTL);
  460. regs_buff[30] = rd32(E1000_FCRTH);
  461. regs_buff[31] = rd32(E1000_FCRTV);
  462. /* Receive */
  463. regs_buff[32] = rd32(E1000_RCTL);
  464. regs_buff[33] = rd32(E1000_RXCSUM);
  465. regs_buff[34] = rd32(E1000_RLPML);
  466. regs_buff[35] = rd32(E1000_RFCTL);
  467. regs_buff[36] = rd32(E1000_MRQC);
  468. regs_buff[37] = rd32(E1000_VT_CTL);
  469. /* Transmit */
  470. regs_buff[38] = rd32(E1000_TCTL);
  471. regs_buff[39] = rd32(E1000_TCTL_EXT);
  472. regs_buff[40] = rd32(E1000_TIPG);
  473. regs_buff[41] = rd32(E1000_DTXCTL);
  474. /* Wake Up */
  475. regs_buff[42] = rd32(E1000_WUC);
  476. regs_buff[43] = rd32(E1000_WUFC);
  477. regs_buff[44] = rd32(E1000_WUS);
  478. regs_buff[45] = rd32(E1000_IPAV);
  479. regs_buff[46] = rd32(E1000_WUPL);
  480. /* MAC */
  481. regs_buff[47] = rd32(E1000_PCS_CFG0);
  482. regs_buff[48] = rd32(E1000_PCS_LCTL);
  483. regs_buff[49] = rd32(E1000_PCS_LSTAT);
  484. regs_buff[50] = rd32(E1000_PCS_ANADV);
  485. regs_buff[51] = rd32(E1000_PCS_LPAB);
  486. regs_buff[52] = rd32(E1000_PCS_NPTX);
  487. regs_buff[53] = rd32(E1000_PCS_LPABNP);
  488. /* Statistics */
  489. regs_buff[54] = adapter->stats.crcerrs;
  490. regs_buff[55] = adapter->stats.algnerrc;
  491. regs_buff[56] = adapter->stats.symerrs;
  492. regs_buff[57] = adapter->stats.rxerrc;
  493. regs_buff[58] = adapter->stats.mpc;
  494. regs_buff[59] = adapter->stats.scc;
  495. regs_buff[60] = adapter->stats.ecol;
  496. regs_buff[61] = adapter->stats.mcc;
  497. regs_buff[62] = adapter->stats.latecol;
  498. regs_buff[63] = adapter->stats.colc;
  499. regs_buff[64] = adapter->stats.dc;
  500. regs_buff[65] = adapter->stats.tncrs;
  501. regs_buff[66] = adapter->stats.sec;
  502. regs_buff[67] = adapter->stats.htdpmc;
  503. regs_buff[68] = adapter->stats.rlec;
  504. regs_buff[69] = adapter->stats.xonrxc;
  505. regs_buff[70] = adapter->stats.xontxc;
  506. regs_buff[71] = adapter->stats.xoffrxc;
  507. regs_buff[72] = adapter->stats.xofftxc;
  508. regs_buff[73] = adapter->stats.fcruc;
  509. regs_buff[74] = adapter->stats.prc64;
  510. regs_buff[75] = adapter->stats.prc127;
  511. regs_buff[76] = adapter->stats.prc255;
  512. regs_buff[77] = adapter->stats.prc511;
  513. regs_buff[78] = adapter->stats.prc1023;
  514. regs_buff[79] = adapter->stats.prc1522;
  515. regs_buff[80] = adapter->stats.gprc;
  516. regs_buff[81] = adapter->stats.bprc;
  517. regs_buff[82] = adapter->stats.mprc;
  518. regs_buff[83] = adapter->stats.gptc;
  519. regs_buff[84] = adapter->stats.gorc;
  520. regs_buff[86] = adapter->stats.gotc;
  521. regs_buff[88] = adapter->stats.rnbc;
  522. regs_buff[89] = adapter->stats.ruc;
  523. regs_buff[90] = adapter->stats.rfc;
  524. regs_buff[91] = adapter->stats.roc;
  525. regs_buff[92] = adapter->stats.rjc;
  526. regs_buff[93] = adapter->stats.mgprc;
  527. regs_buff[94] = adapter->stats.mgpdc;
  528. regs_buff[95] = adapter->stats.mgptc;
  529. regs_buff[96] = adapter->stats.tor;
  530. regs_buff[98] = adapter->stats.tot;
  531. regs_buff[100] = adapter->stats.tpr;
  532. regs_buff[101] = adapter->stats.tpt;
  533. regs_buff[102] = adapter->stats.ptc64;
  534. regs_buff[103] = adapter->stats.ptc127;
  535. regs_buff[104] = adapter->stats.ptc255;
  536. regs_buff[105] = adapter->stats.ptc511;
  537. regs_buff[106] = adapter->stats.ptc1023;
  538. regs_buff[107] = adapter->stats.ptc1522;
  539. regs_buff[108] = adapter->stats.mptc;
  540. regs_buff[109] = adapter->stats.bptc;
  541. regs_buff[110] = adapter->stats.tsctc;
  542. regs_buff[111] = adapter->stats.iac;
  543. regs_buff[112] = adapter->stats.rpthc;
  544. regs_buff[113] = adapter->stats.hgptc;
  545. regs_buff[114] = adapter->stats.hgorc;
  546. regs_buff[116] = adapter->stats.hgotc;
  547. regs_buff[118] = adapter->stats.lenerrs;
  548. regs_buff[119] = adapter->stats.scvpc;
  549. regs_buff[120] = adapter->stats.hrmpc;
  550. for (i = 0; i < 4; i++)
  551. regs_buff[121 + i] = rd32(E1000_SRRCTL(i));
  552. for (i = 0; i < 4; i++)
  553. regs_buff[125 + i] = rd32(E1000_PSRTYPE(i));
  554. for (i = 0; i < 4; i++)
  555. regs_buff[129 + i] = rd32(E1000_RDBAL(i));
  556. for (i = 0; i < 4; i++)
  557. regs_buff[133 + i] = rd32(E1000_RDBAH(i));
  558. for (i = 0; i < 4; i++)
  559. regs_buff[137 + i] = rd32(E1000_RDLEN(i));
  560. for (i = 0; i < 4; i++)
  561. regs_buff[141 + i] = rd32(E1000_RDH(i));
  562. for (i = 0; i < 4; i++)
  563. regs_buff[145 + i] = rd32(E1000_RDT(i));
  564. for (i = 0; i < 4; i++)
  565. regs_buff[149 + i] = rd32(E1000_RXDCTL(i));
  566. for (i = 0; i < 10; i++)
  567. regs_buff[153 + i] = rd32(E1000_EITR(i));
  568. for (i = 0; i < 8; i++)
  569. regs_buff[163 + i] = rd32(E1000_IMIR(i));
  570. for (i = 0; i < 8; i++)
  571. regs_buff[171 + i] = rd32(E1000_IMIREXT(i));
  572. for (i = 0; i < 16; i++)
  573. regs_buff[179 + i] = rd32(E1000_RAL(i));
  574. for (i = 0; i < 16; i++)
  575. regs_buff[195 + i] = rd32(E1000_RAH(i));
  576. for (i = 0; i < 4; i++)
  577. regs_buff[211 + i] = rd32(E1000_TDBAL(i));
  578. for (i = 0; i < 4; i++)
  579. regs_buff[215 + i] = rd32(E1000_TDBAH(i));
  580. for (i = 0; i < 4; i++)
  581. regs_buff[219 + i] = rd32(E1000_TDLEN(i));
  582. for (i = 0; i < 4; i++)
  583. regs_buff[223 + i] = rd32(E1000_TDH(i));
  584. for (i = 0; i < 4; i++)
  585. regs_buff[227 + i] = rd32(E1000_TDT(i));
  586. for (i = 0; i < 4; i++)
  587. regs_buff[231 + i] = rd32(E1000_TXDCTL(i));
  588. for (i = 0; i < 4; i++)
  589. regs_buff[235 + i] = rd32(E1000_TDWBAL(i));
  590. for (i = 0; i < 4; i++)
  591. regs_buff[239 + i] = rd32(E1000_TDWBAH(i));
  592. for (i = 0; i < 4; i++)
  593. regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i));
  594. for (i = 0; i < 4; i++)
  595. regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i));
  596. for (i = 0; i < 4; i++)
  597. regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i));
  598. for (i = 0; i < 32; i++)
  599. regs_buff[255 + i] = rd32(E1000_WUPM_REG(i));
  600. for (i = 0; i < 128; i++)
  601. regs_buff[287 + i] = rd32(E1000_FFMT_REG(i));
  602. for (i = 0; i < 128; i++)
  603. regs_buff[415 + i] = rd32(E1000_FFVT_REG(i));
  604. for (i = 0; i < 4; i++)
  605. regs_buff[543 + i] = rd32(E1000_FFLT_REG(i));
  606. regs_buff[547] = rd32(E1000_TDFH);
  607. regs_buff[548] = rd32(E1000_TDFT);
  608. regs_buff[549] = rd32(E1000_TDFHS);
  609. regs_buff[550] = rd32(E1000_TDFPC);
  610. if (hw->mac.type > e1000_82580) {
  611. regs_buff[551] = adapter->stats.o2bgptc;
  612. regs_buff[552] = adapter->stats.b2ospc;
  613. regs_buff[553] = adapter->stats.o2bspc;
  614. regs_buff[554] = adapter->stats.b2ogprc;
  615. }
  616. if (hw->mac.type != e1000_82576)
  617. return;
  618. for (i = 0; i < 12; i++)
  619. regs_buff[555 + i] = rd32(E1000_SRRCTL(i + 4));
  620. for (i = 0; i < 4; i++)
  621. regs_buff[567 + i] = rd32(E1000_PSRTYPE(i + 4));
  622. for (i = 0; i < 12; i++)
  623. regs_buff[571 + i] = rd32(E1000_RDBAL(i + 4));
  624. for (i = 0; i < 12; i++)
  625. regs_buff[583 + i] = rd32(E1000_RDBAH(i + 4));
  626. for (i = 0; i < 12; i++)
  627. regs_buff[595 + i] = rd32(E1000_RDLEN(i + 4));
  628. for (i = 0; i < 12; i++)
  629. regs_buff[607 + i] = rd32(E1000_RDH(i + 4));
  630. for (i = 0; i < 12; i++)
  631. regs_buff[619 + i] = rd32(E1000_RDT(i + 4));
  632. for (i = 0; i < 12; i++)
  633. regs_buff[631 + i] = rd32(E1000_RXDCTL(i + 4));
  634. for (i = 0; i < 12; i++)
  635. regs_buff[643 + i] = rd32(E1000_TDBAL(i + 4));
  636. for (i = 0; i < 12; i++)
  637. regs_buff[655 + i] = rd32(E1000_TDBAH(i + 4));
  638. for (i = 0; i < 12; i++)
  639. regs_buff[667 + i] = rd32(E1000_TDLEN(i + 4));
  640. for (i = 0; i < 12; i++)
  641. regs_buff[679 + i] = rd32(E1000_TDH(i + 4));
  642. for (i = 0; i < 12; i++)
  643. regs_buff[691 + i] = rd32(E1000_TDT(i + 4));
  644. for (i = 0; i < 12; i++)
  645. regs_buff[703 + i] = rd32(E1000_TXDCTL(i + 4));
  646. for (i = 0; i < 12; i++)
  647. regs_buff[715 + i] = rd32(E1000_TDWBAL(i + 4));
  648. for (i = 0; i < 12; i++)
  649. regs_buff[727 + i] = rd32(E1000_TDWBAH(i + 4));
  650. }
  651. static int igb_get_eeprom_len(struct net_device *netdev)
  652. {
  653. struct igb_adapter *adapter = netdev_priv(netdev);
  654. return adapter->hw.nvm.word_size * 2;
  655. }
  656. static int igb_get_eeprom(struct net_device *netdev,
  657. struct ethtool_eeprom *eeprom, u8 *bytes)
  658. {
  659. struct igb_adapter *adapter = netdev_priv(netdev);
  660. struct e1000_hw *hw = &adapter->hw;
  661. u16 *eeprom_buff;
  662. int first_word, last_word;
  663. int ret_val = 0;
  664. u16 i;
  665. if (eeprom->len == 0)
  666. return -EINVAL;
  667. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  668. first_word = eeprom->offset >> 1;
  669. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  670. eeprom_buff = kmalloc(sizeof(u16) *
  671. (last_word - first_word + 1), GFP_KERNEL);
  672. if (!eeprom_buff)
  673. return -ENOMEM;
  674. if (hw->nvm.type == e1000_nvm_eeprom_spi)
  675. ret_val = hw->nvm.ops.read(hw, first_word,
  676. last_word - first_word + 1,
  677. eeprom_buff);
  678. else {
  679. for (i = 0; i < last_word - first_word + 1; i++) {
  680. ret_val = hw->nvm.ops.read(hw, first_word + i, 1,
  681. &eeprom_buff[i]);
  682. if (ret_val)
  683. break;
  684. }
  685. }
  686. /* Device's eeprom is always little-endian, word addressable */
  687. for (i = 0; i < last_word - first_word + 1; i++)
  688. le16_to_cpus(&eeprom_buff[i]);
  689. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
  690. eeprom->len);
  691. kfree(eeprom_buff);
  692. return ret_val;
  693. }
  694. static int igb_set_eeprom(struct net_device *netdev,
  695. struct ethtool_eeprom *eeprom, u8 *bytes)
  696. {
  697. struct igb_adapter *adapter = netdev_priv(netdev);
  698. struct e1000_hw *hw = &adapter->hw;
  699. u16 *eeprom_buff;
  700. void *ptr;
  701. int max_len, first_word, last_word, ret_val = 0;
  702. u16 i;
  703. if (eeprom->len == 0)
  704. return -EOPNOTSUPP;
  705. if ((hw->mac.type >= e1000_i210) &&
  706. !igb_get_flash_presence_i210(hw)) {
  707. return -EOPNOTSUPP;
  708. }
  709. if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  710. return -EFAULT;
  711. max_len = hw->nvm.word_size * 2;
  712. first_word = eeprom->offset >> 1;
  713. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  714. eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  715. if (!eeprom_buff)
  716. return -ENOMEM;
  717. ptr = (void *)eeprom_buff;
  718. if (eeprom->offset & 1) {
  719. /* need read/modify/write of first changed EEPROM word
  720. * only the second byte of the word is being modified
  721. */
  722. ret_val = hw->nvm.ops.read(hw, first_word, 1,
  723. &eeprom_buff[0]);
  724. ptr++;
  725. }
  726. if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
  727. /* need read/modify/write of last changed EEPROM word
  728. * only the first byte of the word is being modified
  729. */
  730. ret_val = hw->nvm.ops.read(hw, last_word, 1,
  731. &eeprom_buff[last_word - first_word]);
  732. }
  733. /* Device's eeprom is always little-endian, word addressable */
  734. for (i = 0; i < last_word - first_word + 1; i++)
  735. le16_to_cpus(&eeprom_buff[i]);
  736. memcpy(ptr, bytes, eeprom->len);
  737. for (i = 0; i < last_word - first_word + 1; i++)
  738. eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
  739. ret_val = hw->nvm.ops.write(hw, first_word,
  740. last_word - first_word + 1, eeprom_buff);
  741. /* Update the checksum if nvm write succeeded */
  742. if (ret_val == 0)
  743. hw->nvm.ops.update(hw);
  744. igb_set_fw_version(adapter);
  745. kfree(eeprom_buff);
  746. return ret_val;
  747. }
  748. static void igb_get_drvinfo(struct net_device *netdev,
  749. struct ethtool_drvinfo *drvinfo)
  750. {
  751. struct igb_adapter *adapter = netdev_priv(netdev);
  752. strlcpy(drvinfo->driver, igb_driver_name, sizeof(drvinfo->driver));
  753. strlcpy(drvinfo->version, igb_driver_version, sizeof(drvinfo->version));
  754. /* EEPROM image version # is reported as firmware version # for
  755. * 82575 controllers
  756. */
  757. strlcpy(drvinfo->fw_version, adapter->fw_version,
  758. sizeof(drvinfo->fw_version));
  759. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  760. sizeof(drvinfo->bus_info));
  761. }
  762. static void igb_get_ringparam(struct net_device *netdev,
  763. struct ethtool_ringparam *ring)
  764. {
  765. struct igb_adapter *adapter = netdev_priv(netdev);
  766. ring->rx_max_pending = IGB_MAX_RXD;
  767. ring->tx_max_pending = IGB_MAX_TXD;
  768. ring->rx_pending = adapter->rx_ring_count;
  769. ring->tx_pending = adapter->tx_ring_count;
  770. }
  771. static int igb_set_ringparam(struct net_device *netdev,
  772. struct ethtool_ringparam *ring)
  773. {
  774. struct igb_adapter *adapter = netdev_priv(netdev);
  775. struct igb_ring *temp_ring;
  776. int i, err = 0;
  777. u16 new_rx_count, new_tx_count;
  778. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  779. return -EINVAL;
  780. new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD);
  781. new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD);
  782. new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
  783. new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD);
  784. new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD);
  785. new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
  786. if ((new_tx_count == adapter->tx_ring_count) &&
  787. (new_rx_count == adapter->rx_ring_count)) {
  788. /* nothing to do */
  789. return 0;
  790. }
  791. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  792. usleep_range(1000, 2000);
  793. if (!netif_running(adapter->netdev)) {
  794. for (i = 0; i < adapter->num_tx_queues; i++)
  795. adapter->tx_ring[i]->count = new_tx_count;
  796. for (i = 0; i < adapter->num_rx_queues; i++)
  797. adapter->rx_ring[i]->count = new_rx_count;
  798. adapter->tx_ring_count = new_tx_count;
  799. adapter->rx_ring_count = new_rx_count;
  800. goto clear_reset;
  801. }
  802. if (adapter->num_tx_queues > adapter->num_rx_queues)
  803. temp_ring = vmalloc(adapter->num_tx_queues *
  804. sizeof(struct igb_ring));
  805. else
  806. temp_ring = vmalloc(adapter->num_rx_queues *
  807. sizeof(struct igb_ring));
  808. if (!temp_ring) {
  809. err = -ENOMEM;
  810. goto clear_reset;
  811. }
  812. igb_down(adapter);
  813. /* We can't just free everything and then setup again,
  814. * because the ISRs in MSI-X mode get passed pointers
  815. * to the Tx and Rx ring structs.
  816. */
  817. if (new_tx_count != adapter->tx_ring_count) {
  818. for (i = 0; i < adapter->num_tx_queues; i++) {
  819. memcpy(&temp_ring[i], adapter->tx_ring[i],
  820. sizeof(struct igb_ring));
  821. temp_ring[i].count = new_tx_count;
  822. err = igb_setup_tx_resources(&temp_ring[i]);
  823. if (err) {
  824. while (i) {
  825. i--;
  826. igb_free_tx_resources(&temp_ring[i]);
  827. }
  828. goto err_setup;
  829. }
  830. }
  831. for (i = 0; i < adapter->num_tx_queues; i++) {
  832. igb_free_tx_resources(adapter->tx_ring[i]);
  833. memcpy(adapter->tx_ring[i], &temp_ring[i],
  834. sizeof(struct igb_ring));
  835. }
  836. adapter->tx_ring_count = new_tx_count;
  837. }
  838. if (new_rx_count != adapter->rx_ring_count) {
  839. for (i = 0; i < adapter->num_rx_queues; i++) {
  840. memcpy(&temp_ring[i], adapter->rx_ring[i],
  841. sizeof(struct igb_ring));
  842. temp_ring[i].count = new_rx_count;
  843. err = igb_setup_rx_resources(&temp_ring[i]);
  844. if (err) {
  845. while (i) {
  846. i--;
  847. igb_free_rx_resources(&temp_ring[i]);
  848. }
  849. goto err_setup;
  850. }
  851. }
  852. for (i = 0; i < adapter->num_rx_queues; i++) {
  853. igb_free_rx_resources(adapter->rx_ring[i]);
  854. memcpy(adapter->rx_ring[i], &temp_ring[i],
  855. sizeof(struct igb_ring));
  856. }
  857. adapter->rx_ring_count = new_rx_count;
  858. }
  859. err_setup:
  860. igb_up(adapter);
  861. vfree(temp_ring);
  862. clear_reset:
  863. clear_bit(__IGB_RESETTING, &adapter->state);
  864. return err;
  865. }
  866. /* ethtool register test data */
  867. struct igb_reg_test {
  868. u16 reg;
  869. u16 reg_offset;
  870. u16 array_len;
  871. u16 test_type;
  872. u32 mask;
  873. u32 write;
  874. };
  875. /* In the hardware, registers are laid out either singly, in arrays
  876. * spaced 0x100 bytes apart, or in contiguous tables. We assume
  877. * most tests take place on arrays or single registers (handled
  878. * as a single-element array) and special-case the tables.
  879. * Table tests are always pattern tests.
  880. *
  881. * We also make provision for some required setup steps by specifying
  882. * registers to be written without any read-back testing.
  883. */
  884. #define PATTERN_TEST 1
  885. #define SET_READ_TEST 2
  886. #define WRITE_NO_TEST 3
  887. #define TABLE32_TEST 4
  888. #define TABLE64_TEST_LO 5
  889. #define TABLE64_TEST_HI 6
  890. /* i210 reg test */
  891. static struct igb_reg_test reg_test_i210[] = {
  892. { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  893. { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  894. { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  895. { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  896. { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  897. { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  898. /* RDH is read-only for i210, only test RDT. */
  899. { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  900. { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
  901. { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  902. { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
  903. { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  904. { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  905. { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  906. { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  907. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  908. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
  909. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
  910. { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  911. { E1000_RA, 0, 16, TABLE64_TEST_LO,
  912. 0xFFFFFFFF, 0xFFFFFFFF },
  913. { E1000_RA, 0, 16, TABLE64_TEST_HI,
  914. 0x900FFFFF, 0xFFFFFFFF },
  915. { E1000_MTA, 0, 128, TABLE32_TEST,
  916. 0xFFFFFFFF, 0xFFFFFFFF },
  917. { 0, 0, 0, 0, 0 }
  918. };
  919. /* i350 reg test */
  920. static struct igb_reg_test reg_test_i350[] = {
  921. { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  922. { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  923. { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  924. { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFF0000, 0xFFFF0000 },
  925. { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  926. { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  927. { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  928. { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  929. { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  930. { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  931. /* RDH is read-only for i350, only test RDT. */
  932. { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  933. { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  934. { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
  935. { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  936. { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
  937. { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  938. { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  939. { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  940. { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  941. { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  942. { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  943. { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  944. { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  945. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  946. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
  947. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
  948. { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  949. { E1000_RA, 0, 16, TABLE64_TEST_LO,
  950. 0xFFFFFFFF, 0xFFFFFFFF },
  951. { E1000_RA, 0, 16, TABLE64_TEST_HI,
  952. 0xC3FFFFFF, 0xFFFFFFFF },
  953. { E1000_RA2, 0, 16, TABLE64_TEST_LO,
  954. 0xFFFFFFFF, 0xFFFFFFFF },
  955. { E1000_RA2, 0, 16, TABLE64_TEST_HI,
  956. 0xC3FFFFFF, 0xFFFFFFFF },
  957. { E1000_MTA, 0, 128, TABLE32_TEST,
  958. 0xFFFFFFFF, 0xFFFFFFFF },
  959. { 0, 0, 0, 0 }
  960. };
  961. /* 82580 reg test */
  962. static struct igb_reg_test reg_test_82580[] = {
  963. { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  964. { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  965. { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  966. { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  967. { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  968. { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  969. { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  970. { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  971. { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  972. { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  973. /* RDH is read-only for 82580, only test RDT. */
  974. { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  975. { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  976. { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
  977. { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  978. { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
  979. { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  980. { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  981. { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  982. { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  983. { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  984. { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  985. { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  986. { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  987. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  988. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
  989. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
  990. { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  991. { E1000_RA, 0, 16, TABLE64_TEST_LO,
  992. 0xFFFFFFFF, 0xFFFFFFFF },
  993. { E1000_RA, 0, 16, TABLE64_TEST_HI,
  994. 0x83FFFFFF, 0xFFFFFFFF },
  995. { E1000_RA2, 0, 8, TABLE64_TEST_LO,
  996. 0xFFFFFFFF, 0xFFFFFFFF },
  997. { E1000_RA2, 0, 8, TABLE64_TEST_HI,
  998. 0x83FFFFFF, 0xFFFFFFFF },
  999. { E1000_MTA, 0, 128, TABLE32_TEST,
  1000. 0xFFFFFFFF, 0xFFFFFFFF },
  1001. { 0, 0, 0, 0 }
  1002. };
  1003. /* 82576 reg test */
  1004. static struct igb_reg_test reg_test_82576[] = {
  1005. { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1006. { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  1007. { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  1008. { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1009. { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1010. { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1011. { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  1012. { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1013. { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1014. { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  1015. /* Enable all RX queues before testing. */
  1016. { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
  1017. E1000_RXDCTL_QUEUE_ENABLE },
  1018. { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0,
  1019. E1000_RXDCTL_QUEUE_ENABLE },
  1020. /* RDH is read-only for 82576, only test RDT. */
  1021. { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1022. { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1023. { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
  1024. { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 },
  1025. { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
  1026. { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1027. { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
  1028. { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1029. { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1030. { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  1031. { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1032. { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1033. { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF },
  1034. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  1035. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB },
  1036. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF },
  1037. { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  1038. { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
  1039. { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
  1040. { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
  1041. { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF },
  1042. { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1043. { 0, 0, 0, 0 }
  1044. };
  1045. /* 82575 register test */
  1046. static struct igb_reg_test reg_test_82575[] = {
  1047. { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1048. { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  1049. { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF },
  1050. { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1051. { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1052. { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1053. { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  1054. /* Enable all four RX queues before testing. */
  1055. { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0,
  1056. E1000_RXDCTL_QUEUE_ENABLE },
  1057. /* RDH is read-only for 82575, only test RDT. */
  1058. { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1059. { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 },
  1060. { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 },
  1061. { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1062. { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF },
  1063. { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1064. { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1065. { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  1066. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  1067. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB },
  1068. { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF },
  1069. { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 },
  1070. { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF },
  1071. { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
  1072. { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF },
  1073. { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1074. { 0, 0, 0, 0 }
  1075. };
  1076. static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data,
  1077. int reg, u32 mask, u32 write)
  1078. {
  1079. struct e1000_hw *hw = &adapter->hw;
  1080. u32 pat, val;
  1081. static const u32 _test[] = {
  1082. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
  1083. for (pat = 0; pat < ARRAY_SIZE(_test); pat++) {
  1084. wr32(reg, (_test[pat] & write));
  1085. val = rd32(reg) & mask;
  1086. if (val != (_test[pat] & write & mask)) {
  1087. dev_err(&adapter->pdev->dev,
  1088. "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
  1089. reg, val, (_test[pat] & write & mask));
  1090. *data = reg;
  1091. return true;
  1092. }
  1093. }
  1094. return false;
  1095. }
  1096. static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data,
  1097. int reg, u32 mask, u32 write)
  1098. {
  1099. struct e1000_hw *hw = &adapter->hw;
  1100. u32 val;
  1101. wr32(reg, write & mask);
  1102. val = rd32(reg);
  1103. if ((write & mask) != (val & mask)) {
  1104. dev_err(&adapter->pdev->dev,
  1105. "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
  1106. reg, (val & mask), (write & mask));
  1107. *data = reg;
  1108. return true;
  1109. }
  1110. return false;
  1111. }
  1112. #define REG_PATTERN_TEST(reg, mask, write) \
  1113. do { \
  1114. if (reg_pattern_test(adapter, data, reg, mask, write)) \
  1115. return 1; \
  1116. } while (0)
  1117. #define REG_SET_AND_CHECK(reg, mask, write) \
  1118. do { \
  1119. if (reg_set_and_check(adapter, data, reg, mask, write)) \
  1120. return 1; \
  1121. } while (0)
  1122. static int igb_reg_test(struct igb_adapter *adapter, u64 *data)
  1123. {
  1124. struct e1000_hw *hw = &adapter->hw;
  1125. struct igb_reg_test *test;
  1126. u32 value, before, after;
  1127. u32 i, toggle;
  1128. switch (adapter->hw.mac.type) {
  1129. case e1000_i350:
  1130. case e1000_i354:
  1131. test = reg_test_i350;
  1132. toggle = 0x7FEFF3FF;
  1133. break;
  1134. case e1000_i210:
  1135. case e1000_i211:
  1136. test = reg_test_i210;
  1137. toggle = 0x7FEFF3FF;
  1138. break;
  1139. case e1000_82580:
  1140. test = reg_test_82580;
  1141. toggle = 0x7FEFF3FF;
  1142. break;
  1143. case e1000_82576:
  1144. test = reg_test_82576;
  1145. toggle = 0x7FFFF3FF;
  1146. break;
  1147. default:
  1148. test = reg_test_82575;
  1149. toggle = 0x7FFFF3FF;
  1150. break;
  1151. }
  1152. /* Because the status register is such a special case,
  1153. * we handle it separately from the rest of the register
  1154. * tests. Some bits are read-only, some toggle, and some
  1155. * are writable on newer MACs.
  1156. */
  1157. before = rd32(E1000_STATUS);
  1158. value = (rd32(E1000_STATUS) & toggle);
  1159. wr32(E1000_STATUS, toggle);
  1160. after = rd32(E1000_STATUS) & toggle;
  1161. if (value != after) {
  1162. dev_err(&adapter->pdev->dev,
  1163. "failed STATUS register test got: 0x%08X expected: 0x%08X\n",
  1164. after, value);
  1165. *data = 1;
  1166. return 1;
  1167. }
  1168. /* restore previous status */
  1169. wr32(E1000_STATUS, before);
  1170. /* Perform the remainder of the register test, looping through
  1171. * the test table until we either fail or reach the null entry.
  1172. */
  1173. while (test->reg) {
  1174. for (i = 0; i < test->array_len; i++) {
  1175. switch (test->test_type) {
  1176. case PATTERN_TEST:
  1177. REG_PATTERN_TEST(test->reg +
  1178. (i * test->reg_offset),
  1179. test->mask,
  1180. test->write);
  1181. break;
  1182. case SET_READ_TEST:
  1183. REG_SET_AND_CHECK(test->reg +
  1184. (i * test->reg_offset),
  1185. test->mask,
  1186. test->write);
  1187. break;
  1188. case WRITE_NO_TEST:
  1189. writel(test->write,
  1190. (adapter->hw.hw_addr + test->reg)
  1191. + (i * test->reg_offset));
  1192. break;
  1193. case TABLE32_TEST:
  1194. REG_PATTERN_TEST(test->reg + (i * 4),
  1195. test->mask,
  1196. test->write);
  1197. break;
  1198. case TABLE64_TEST_LO:
  1199. REG_PATTERN_TEST(test->reg + (i * 8),
  1200. test->mask,
  1201. test->write);
  1202. break;
  1203. case TABLE64_TEST_HI:
  1204. REG_PATTERN_TEST((test->reg + 4) + (i * 8),
  1205. test->mask,
  1206. test->write);
  1207. break;
  1208. }
  1209. }
  1210. test++;
  1211. }
  1212. *data = 0;
  1213. return 0;
  1214. }
  1215. static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data)
  1216. {
  1217. struct e1000_hw *hw = &adapter->hw;
  1218. *data = 0;
  1219. /* Validate eeprom on all parts but flashless */
  1220. switch (hw->mac.type) {
  1221. case e1000_i210:
  1222. case e1000_i211:
  1223. if (igb_get_flash_presence_i210(hw)) {
  1224. if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
  1225. *data = 2;
  1226. }
  1227. break;
  1228. default:
  1229. if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0)
  1230. *data = 2;
  1231. break;
  1232. }
  1233. return *data;
  1234. }
  1235. static irqreturn_t igb_test_intr(int irq, void *data)
  1236. {
  1237. struct igb_adapter *adapter = (struct igb_adapter *) data;
  1238. struct e1000_hw *hw = &adapter->hw;
  1239. adapter->test_icr |= rd32(E1000_ICR);
  1240. return IRQ_HANDLED;
  1241. }
  1242. static int igb_intr_test(struct igb_adapter *adapter, u64 *data)
  1243. {
  1244. struct e1000_hw *hw = &adapter->hw;
  1245. struct net_device *netdev = adapter->netdev;
  1246. u32 mask, ics_mask, i = 0, shared_int = true;
  1247. u32 irq = adapter->pdev->irq;
  1248. *data = 0;
  1249. /* Hook up test interrupt handler just for this test */
  1250. if (adapter->flags & IGB_FLAG_HAS_MSIX) {
  1251. if (request_irq(adapter->msix_entries[0].vector,
  1252. igb_test_intr, 0, netdev->name, adapter)) {
  1253. *data = 1;
  1254. return -1;
  1255. }
  1256. } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
  1257. shared_int = false;
  1258. if (request_irq(irq,
  1259. igb_test_intr, 0, netdev->name, adapter)) {
  1260. *data = 1;
  1261. return -1;
  1262. }
  1263. } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED,
  1264. netdev->name, adapter)) {
  1265. shared_int = false;
  1266. } else if (request_irq(irq, igb_test_intr, IRQF_SHARED,
  1267. netdev->name, adapter)) {
  1268. *data = 1;
  1269. return -1;
  1270. }
  1271. dev_info(&adapter->pdev->dev, "testing %s interrupt\n",
  1272. (shared_int ? "shared" : "unshared"));
  1273. /* Disable all the interrupts */
  1274. wr32(E1000_IMC, ~0);
  1275. wrfl();
  1276. usleep_range(10000, 11000);
  1277. /* Define all writable bits for ICS */
  1278. switch (hw->mac.type) {
  1279. case e1000_82575:
  1280. ics_mask = 0x37F47EDD;
  1281. break;
  1282. case e1000_82576:
  1283. ics_mask = 0x77D4FBFD;
  1284. break;
  1285. case e1000_82580:
  1286. ics_mask = 0x77DCFED5;
  1287. break;
  1288. case e1000_i350:
  1289. case e1000_i354:
  1290. case e1000_i210:
  1291. case e1000_i211:
  1292. ics_mask = 0x77DCFED5;
  1293. break;
  1294. default:
  1295. ics_mask = 0x7FFFFFFF;
  1296. break;
  1297. }
  1298. /* Test each interrupt */
  1299. for (; i < 31; i++) {
  1300. /* Interrupt to test */
  1301. mask = BIT(i);
  1302. if (!(mask & ics_mask))
  1303. continue;
  1304. if (!shared_int) {
  1305. /* Disable the interrupt to be reported in
  1306. * the cause register and then force the same
  1307. * interrupt and see if one gets posted. If
  1308. * an interrupt was posted to the bus, the
  1309. * test failed.
  1310. */
  1311. adapter->test_icr = 0;
  1312. /* Flush any pending interrupts */
  1313. wr32(E1000_ICR, ~0);
  1314. wr32(E1000_IMC, mask);
  1315. wr32(E1000_ICS, mask);
  1316. wrfl();
  1317. usleep_range(10000, 11000);
  1318. if (adapter->test_icr & mask) {
  1319. *data = 3;
  1320. break;
  1321. }
  1322. }
  1323. /* Enable the interrupt to be reported in
  1324. * the cause register and then force the same
  1325. * interrupt and see if one gets posted. If
  1326. * an interrupt was not posted to the bus, the
  1327. * test failed.
  1328. */
  1329. adapter->test_icr = 0;
  1330. /* Flush any pending interrupts */
  1331. wr32(E1000_ICR, ~0);
  1332. wr32(E1000_IMS, mask);
  1333. wr32(E1000_ICS, mask);
  1334. wrfl();
  1335. usleep_range(10000, 11000);
  1336. if (!(adapter->test_icr & mask)) {
  1337. *data = 4;
  1338. break;
  1339. }
  1340. if (!shared_int) {
  1341. /* Disable the other interrupts to be reported in
  1342. * the cause register and then force the other
  1343. * interrupts and see if any get posted. If
  1344. * an interrupt was posted to the bus, the
  1345. * test failed.
  1346. */
  1347. adapter->test_icr = 0;
  1348. /* Flush any pending interrupts */
  1349. wr32(E1000_ICR, ~0);
  1350. wr32(E1000_IMC, ~mask);
  1351. wr32(E1000_ICS, ~mask);
  1352. wrfl();
  1353. usleep_range(10000, 11000);
  1354. if (adapter->test_icr & mask) {
  1355. *data = 5;
  1356. break;
  1357. }
  1358. }
  1359. }
  1360. /* Disable all the interrupts */
  1361. wr32(E1000_IMC, ~0);
  1362. wrfl();
  1363. usleep_range(10000, 11000);
  1364. /* Unhook test interrupt handler */
  1365. if (adapter->flags & IGB_FLAG_HAS_MSIX)
  1366. free_irq(adapter->msix_entries[0].vector, adapter);
  1367. else
  1368. free_irq(irq, adapter);
  1369. return *data;
  1370. }
  1371. static void igb_free_desc_rings(struct igb_adapter *adapter)
  1372. {
  1373. igb_free_tx_resources(&adapter->test_tx_ring);
  1374. igb_free_rx_resources(&adapter->test_rx_ring);
  1375. }
  1376. static int igb_setup_desc_rings(struct igb_adapter *adapter)
  1377. {
  1378. struct igb_ring *tx_ring = &adapter->test_tx_ring;
  1379. struct igb_ring *rx_ring = &adapter->test_rx_ring;
  1380. struct e1000_hw *hw = &adapter->hw;
  1381. int ret_val;
  1382. /* Setup Tx descriptor ring and Tx buffers */
  1383. tx_ring->count = IGB_DEFAULT_TXD;
  1384. tx_ring->dev = &adapter->pdev->dev;
  1385. tx_ring->netdev = adapter->netdev;
  1386. tx_ring->reg_idx = adapter->vfs_allocated_count;
  1387. if (igb_setup_tx_resources(tx_ring)) {
  1388. ret_val = 1;
  1389. goto err_nomem;
  1390. }
  1391. igb_setup_tctl(adapter);
  1392. igb_configure_tx_ring(adapter, tx_ring);
  1393. /* Setup Rx descriptor ring and Rx buffers */
  1394. rx_ring->count = IGB_DEFAULT_RXD;
  1395. rx_ring->dev = &adapter->pdev->dev;
  1396. rx_ring->netdev = adapter->netdev;
  1397. rx_ring->reg_idx = adapter->vfs_allocated_count;
  1398. if (igb_setup_rx_resources(rx_ring)) {
  1399. ret_val = 3;
  1400. goto err_nomem;
  1401. }
  1402. /* set the default queue to queue 0 of PF */
  1403. wr32(E1000_MRQC, adapter->vfs_allocated_count << 3);
  1404. /* enable receive ring */
  1405. igb_setup_rctl(adapter);
  1406. igb_configure_rx_ring(adapter, rx_ring);
  1407. igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
  1408. return 0;
  1409. err_nomem:
  1410. igb_free_desc_rings(adapter);
  1411. return ret_val;
  1412. }
  1413. static void igb_phy_disable_receiver(struct igb_adapter *adapter)
  1414. {
  1415. struct e1000_hw *hw = &adapter->hw;
  1416. /* Write out to PHY registers 29 and 30 to disable the Receiver. */
  1417. igb_write_phy_reg(hw, 29, 0x001F);
  1418. igb_write_phy_reg(hw, 30, 0x8FFC);
  1419. igb_write_phy_reg(hw, 29, 0x001A);
  1420. igb_write_phy_reg(hw, 30, 0x8FF0);
  1421. }
  1422. static int igb_integrated_phy_loopback(struct igb_adapter *adapter)
  1423. {
  1424. struct e1000_hw *hw = &adapter->hw;
  1425. u32 ctrl_reg = 0;
  1426. hw->mac.autoneg = false;
  1427. if (hw->phy.type == e1000_phy_m88) {
  1428. if (hw->phy.id != I210_I_PHY_ID) {
  1429. /* Auto-MDI/MDIX Off */
  1430. igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
  1431. /* reset to update Auto-MDI/MDIX */
  1432. igb_write_phy_reg(hw, PHY_CONTROL, 0x9140);
  1433. /* autoneg off */
  1434. igb_write_phy_reg(hw, PHY_CONTROL, 0x8140);
  1435. } else {
  1436. /* force 1000, set loopback */
  1437. igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0);
  1438. igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
  1439. }
  1440. } else if (hw->phy.type == e1000_phy_82580) {
  1441. /* enable MII loopback */
  1442. igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041);
  1443. }
  1444. /* add small delay to avoid loopback test failure */
  1445. msleep(50);
  1446. /* force 1000, set loopback */
  1447. igb_write_phy_reg(hw, PHY_CONTROL, 0x4140);
  1448. /* Now set up the MAC to the same speed/duplex as the PHY. */
  1449. ctrl_reg = rd32(E1000_CTRL);
  1450. ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
  1451. ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
  1452. E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
  1453. E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
  1454. E1000_CTRL_FD | /* Force Duplex to FULL */
  1455. E1000_CTRL_SLU); /* Set link up enable bit */
  1456. if (hw->phy.type == e1000_phy_m88)
  1457. ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
  1458. wr32(E1000_CTRL, ctrl_reg);
  1459. /* Disable the receiver on the PHY so when a cable is plugged in, the
  1460. * PHY does not begin to autoneg when a cable is reconnected to the NIC.
  1461. */
  1462. if (hw->phy.type == e1000_phy_m88)
  1463. igb_phy_disable_receiver(adapter);
  1464. mdelay(500);
  1465. return 0;
  1466. }
  1467. static int igb_set_phy_loopback(struct igb_adapter *adapter)
  1468. {
  1469. return igb_integrated_phy_loopback(adapter);
  1470. }
  1471. static int igb_setup_loopback_test(struct igb_adapter *adapter)
  1472. {
  1473. struct e1000_hw *hw = &adapter->hw;
  1474. u32 reg;
  1475. reg = rd32(E1000_CTRL_EXT);
  1476. /* use CTRL_EXT to identify link type as SGMII can appear as copper */
  1477. if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) {
  1478. if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
  1479. (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
  1480. (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
  1481. (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
  1482. (hw->device_id == E1000_DEV_ID_I354_SGMII) ||
  1483. (hw->device_id == E1000_DEV_ID_I354_BACKPLANE_2_5GBPS)) {
  1484. /* Enable DH89xxCC MPHY for near end loopback */
  1485. reg = rd32(E1000_MPHY_ADDR_CTL);
  1486. reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
  1487. E1000_MPHY_PCS_CLK_REG_OFFSET;
  1488. wr32(E1000_MPHY_ADDR_CTL, reg);
  1489. reg = rd32(E1000_MPHY_DATA);
  1490. reg |= E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
  1491. wr32(E1000_MPHY_DATA, reg);
  1492. }
  1493. reg = rd32(E1000_RCTL);
  1494. reg |= E1000_RCTL_LBM_TCVR;
  1495. wr32(E1000_RCTL, reg);
  1496. wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK);
  1497. reg = rd32(E1000_CTRL);
  1498. reg &= ~(E1000_CTRL_RFCE |
  1499. E1000_CTRL_TFCE |
  1500. E1000_CTRL_LRST);
  1501. reg |= E1000_CTRL_SLU |
  1502. E1000_CTRL_FD;
  1503. wr32(E1000_CTRL, reg);
  1504. /* Unset switch control to serdes energy detect */
  1505. reg = rd32(E1000_CONNSW);
  1506. reg &= ~E1000_CONNSW_ENRGSRC;
  1507. wr32(E1000_CONNSW, reg);
  1508. /* Unset sigdetect for SERDES loopback on
  1509. * 82580 and newer devices.
  1510. */
  1511. if (hw->mac.type >= e1000_82580) {
  1512. reg = rd32(E1000_PCS_CFG0);
  1513. reg |= E1000_PCS_CFG_IGN_SD;
  1514. wr32(E1000_PCS_CFG0, reg);
  1515. }
  1516. /* Set PCS register for forced speed */
  1517. reg = rd32(E1000_PCS_LCTL);
  1518. reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/
  1519. reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */
  1520. E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */
  1521. E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */
  1522. E1000_PCS_LCTL_FSD | /* Force Speed */
  1523. E1000_PCS_LCTL_FORCE_LINK; /* Force Link */
  1524. wr32(E1000_PCS_LCTL, reg);
  1525. return 0;
  1526. }
  1527. return igb_set_phy_loopback(adapter);
  1528. }
  1529. static void igb_loopback_cleanup(struct igb_adapter *adapter)
  1530. {
  1531. struct e1000_hw *hw = &adapter->hw;
  1532. u32 rctl;
  1533. u16 phy_reg;
  1534. if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) ||
  1535. (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) ||
  1536. (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) ||
  1537. (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP) ||
  1538. (hw->device_id == E1000_DEV_ID_I354_SGMII)) {
  1539. u32 reg;
  1540. /* Disable near end loopback on DH89xxCC */
  1541. reg = rd32(E1000_MPHY_ADDR_CTL);
  1542. reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) |
  1543. E1000_MPHY_PCS_CLK_REG_OFFSET;
  1544. wr32(E1000_MPHY_ADDR_CTL, reg);
  1545. reg = rd32(E1000_MPHY_DATA);
  1546. reg &= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN;
  1547. wr32(E1000_MPHY_DATA, reg);
  1548. }
  1549. rctl = rd32(E1000_RCTL);
  1550. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1551. wr32(E1000_RCTL, rctl);
  1552. hw->mac.autoneg = true;
  1553. igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg);
  1554. if (phy_reg & MII_CR_LOOPBACK) {
  1555. phy_reg &= ~MII_CR_LOOPBACK;
  1556. igb_write_phy_reg(hw, PHY_CONTROL, phy_reg);
  1557. igb_phy_sw_reset(hw);
  1558. }
  1559. }
  1560. static void igb_create_lbtest_frame(struct sk_buff *skb,
  1561. unsigned int frame_size)
  1562. {
  1563. memset(skb->data, 0xFF, frame_size);
  1564. frame_size /= 2;
  1565. memset(&skb->data[frame_size], 0xAA, frame_size - 1);
  1566. memset(&skb->data[frame_size + 10], 0xBE, 1);
  1567. memset(&skb->data[frame_size + 12], 0xAF, 1);
  1568. }
  1569. static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer,
  1570. unsigned int frame_size)
  1571. {
  1572. unsigned char *data;
  1573. bool match = true;
  1574. frame_size >>= 1;
  1575. data = kmap(rx_buffer->page);
  1576. if (data[3] != 0xFF ||
  1577. data[frame_size + 10] != 0xBE ||
  1578. data[frame_size + 12] != 0xAF)
  1579. match = false;
  1580. kunmap(rx_buffer->page);
  1581. return match;
  1582. }
  1583. static int igb_clean_test_rings(struct igb_ring *rx_ring,
  1584. struct igb_ring *tx_ring,
  1585. unsigned int size)
  1586. {
  1587. union e1000_adv_rx_desc *rx_desc;
  1588. struct igb_rx_buffer *rx_buffer_info;
  1589. struct igb_tx_buffer *tx_buffer_info;
  1590. u16 rx_ntc, tx_ntc, count = 0;
  1591. /* initialize next to clean and descriptor values */
  1592. rx_ntc = rx_ring->next_to_clean;
  1593. tx_ntc = tx_ring->next_to_clean;
  1594. rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
  1595. while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
  1596. /* check Rx buffer */
  1597. rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
  1598. /* sync Rx buffer for CPU read */
  1599. dma_sync_single_for_cpu(rx_ring->dev,
  1600. rx_buffer_info->dma,
  1601. IGB_RX_BUFSZ,
  1602. DMA_FROM_DEVICE);
  1603. /* verify contents of skb */
  1604. if (igb_check_lbtest_frame(rx_buffer_info, size))
  1605. count++;
  1606. /* sync Rx buffer for device write */
  1607. dma_sync_single_for_device(rx_ring->dev,
  1608. rx_buffer_info->dma,
  1609. IGB_RX_BUFSZ,
  1610. DMA_FROM_DEVICE);
  1611. /* unmap buffer on Tx side */
  1612. tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
  1613. igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  1614. /* increment Rx/Tx next to clean counters */
  1615. rx_ntc++;
  1616. if (rx_ntc == rx_ring->count)
  1617. rx_ntc = 0;
  1618. tx_ntc++;
  1619. if (tx_ntc == tx_ring->count)
  1620. tx_ntc = 0;
  1621. /* fetch next descriptor */
  1622. rx_desc = IGB_RX_DESC(rx_ring, rx_ntc);
  1623. }
  1624. netdev_tx_reset_queue(txring_txq(tx_ring));
  1625. /* re-map buffers to ring, store next to clean values */
  1626. igb_alloc_rx_buffers(rx_ring, count);
  1627. rx_ring->next_to_clean = rx_ntc;
  1628. tx_ring->next_to_clean = tx_ntc;
  1629. return count;
  1630. }
  1631. static int igb_run_loopback_test(struct igb_adapter *adapter)
  1632. {
  1633. struct igb_ring *tx_ring = &adapter->test_tx_ring;
  1634. struct igb_ring *rx_ring = &adapter->test_rx_ring;
  1635. u16 i, j, lc, good_cnt;
  1636. int ret_val = 0;
  1637. unsigned int size = IGB_RX_HDR_LEN;
  1638. netdev_tx_t tx_ret_val;
  1639. struct sk_buff *skb;
  1640. /* allocate test skb */
  1641. skb = alloc_skb(size, GFP_KERNEL);
  1642. if (!skb)
  1643. return 11;
  1644. /* place data into test skb */
  1645. igb_create_lbtest_frame(skb, size);
  1646. skb_put(skb, size);
  1647. /* Calculate the loop count based on the largest descriptor ring
  1648. * The idea is to wrap the largest ring a number of times using 64
  1649. * send/receive pairs during each loop
  1650. */
  1651. if (rx_ring->count <= tx_ring->count)
  1652. lc = ((tx_ring->count / 64) * 2) + 1;
  1653. else
  1654. lc = ((rx_ring->count / 64) * 2) + 1;
  1655. for (j = 0; j <= lc; j++) { /* loop count loop */
  1656. /* reset count of good packets */
  1657. good_cnt = 0;
  1658. /* place 64 packets on the transmit queue*/
  1659. for (i = 0; i < 64; i++) {
  1660. skb_get(skb);
  1661. tx_ret_val = igb_xmit_frame_ring(skb, tx_ring);
  1662. if (tx_ret_val == NETDEV_TX_OK)
  1663. good_cnt++;
  1664. }
  1665. if (good_cnt != 64) {
  1666. ret_val = 12;
  1667. break;
  1668. }
  1669. /* allow 200 milliseconds for packets to go from Tx to Rx */
  1670. msleep(200);
  1671. good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size);
  1672. if (good_cnt != 64) {
  1673. ret_val = 13;
  1674. break;
  1675. }
  1676. } /* end loop count loop */
  1677. /* free the original skb */
  1678. kfree_skb(skb);
  1679. return ret_val;
  1680. }
  1681. static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)
  1682. {
  1683. /* PHY loopback cannot be performed if SoL/IDER
  1684. * sessions are active
  1685. */
  1686. if (igb_check_reset_block(&adapter->hw)) {
  1687. dev_err(&adapter->pdev->dev,
  1688. "Cannot do PHY loopback test when SoL/IDER is active.\n");
  1689. *data = 0;
  1690. goto out;
  1691. }
  1692. if (adapter->hw.mac.type == e1000_i354) {
  1693. dev_info(&adapter->pdev->dev,
  1694. "Loopback test not supported on i354.\n");
  1695. *data = 0;
  1696. goto out;
  1697. }
  1698. *data = igb_setup_desc_rings(adapter);
  1699. if (*data)
  1700. goto out;
  1701. *data = igb_setup_loopback_test(adapter);
  1702. if (*data)
  1703. goto err_loopback;
  1704. *data = igb_run_loopback_test(adapter);
  1705. igb_loopback_cleanup(adapter);
  1706. err_loopback:
  1707. igb_free_desc_rings(adapter);
  1708. out:
  1709. return *data;
  1710. }
  1711. static int igb_link_test(struct igb_adapter *adapter, u64 *data)
  1712. {
  1713. struct e1000_hw *hw = &adapter->hw;
  1714. *data = 0;
  1715. if (hw->phy.media_type == e1000_media_type_internal_serdes) {
  1716. int i = 0;
  1717. hw->mac.serdes_has_link = false;
  1718. /* On some blade server designs, link establishment
  1719. * could take as long as 2-3 minutes
  1720. */
  1721. do {
  1722. hw->mac.ops.check_for_link(&adapter->hw);
  1723. if (hw->mac.serdes_has_link)
  1724. return *data;
  1725. msleep(20);
  1726. } while (i++ < 3750);
  1727. *data = 1;
  1728. } else {
  1729. hw->mac.ops.check_for_link(&adapter->hw);
  1730. if (hw->mac.autoneg)
  1731. msleep(5000);
  1732. if (!(rd32(E1000_STATUS) & E1000_STATUS_LU))
  1733. *data = 1;
  1734. }
  1735. return *data;
  1736. }
  1737. static void igb_diag_test(struct net_device *netdev,
  1738. struct ethtool_test *eth_test, u64 *data)
  1739. {
  1740. struct igb_adapter *adapter = netdev_priv(netdev);
  1741. u16 autoneg_advertised;
  1742. u8 forced_speed_duplex, autoneg;
  1743. bool if_running = netif_running(netdev);
  1744. set_bit(__IGB_TESTING, &adapter->state);
  1745. /* can't do offline tests on media switching devices */
  1746. if (adapter->hw.dev_spec._82575.mas_capable)
  1747. eth_test->flags &= ~ETH_TEST_FL_OFFLINE;
  1748. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1749. /* Offline tests */
  1750. /* save speed, duplex, autoneg settings */
  1751. autoneg_advertised = adapter->hw.phy.autoneg_advertised;
  1752. forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
  1753. autoneg = adapter->hw.mac.autoneg;
  1754. dev_info(&adapter->pdev->dev, "offline testing starting\n");
  1755. /* power up link for link test */
  1756. igb_power_up_link(adapter);
  1757. /* Link test performed before hardware reset so autoneg doesn't
  1758. * interfere with test result
  1759. */
  1760. if (igb_link_test(adapter, &data[TEST_LINK]))
  1761. eth_test->flags |= ETH_TEST_FL_FAILED;
  1762. if (if_running)
  1763. /* indicate we're in test mode */
  1764. igb_close(netdev);
  1765. else
  1766. igb_reset(adapter);
  1767. if (igb_reg_test(adapter, &data[TEST_REG]))
  1768. eth_test->flags |= ETH_TEST_FL_FAILED;
  1769. igb_reset(adapter);
  1770. if (igb_eeprom_test(adapter, &data[TEST_EEP]))
  1771. eth_test->flags |= ETH_TEST_FL_FAILED;
  1772. igb_reset(adapter);
  1773. if (igb_intr_test(adapter, &data[TEST_IRQ]))
  1774. eth_test->flags |= ETH_TEST_FL_FAILED;
  1775. igb_reset(adapter);
  1776. /* power up link for loopback test */
  1777. igb_power_up_link(adapter);
  1778. if (igb_loopback_test(adapter, &data[TEST_LOOP]))
  1779. eth_test->flags |= ETH_TEST_FL_FAILED;
  1780. /* restore speed, duplex, autoneg settings */
  1781. adapter->hw.phy.autoneg_advertised = autoneg_advertised;
  1782. adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
  1783. adapter->hw.mac.autoneg = autoneg;
  1784. /* force this routine to wait until autoneg complete/timeout */
  1785. adapter->hw.phy.autoneg_wait_to_complete = true;
  1786. igb_reset(adapter);
  1787. adapter->hw.phy.autoneg_wait_to_complete = false;
  1788. clear_bit(__IGB_TESTING, &adapter->state);
  1789. if (if_running)
  1790. igb_open(netdev);
  1791. } else {
  1792. dev_info(&adapter->pdev->dev, "online testing starting\n");
  1793. /* PHY is powered down when interface is down */
  1794. if (if_running && igb_link_test(adapter, &data[TEST_LINK]))
  1795. eth_test->flags |= ETH_TEST_FL_FAILED;
  1796. else
  1797. data[TEST_LINK] = 0;
  1798. /* Online tests aren't run; pass by default */
  1799. data[TEST_REG] = 0;
  1800. data[TEST_EEP] = 0;
  1801. data[TEST_IRQ] = 0;
  1802. data[TEST_LOOP] = 0;
  1803. clear_bit(__IGB_TESTING, &adapter->state);
  1804. }
  1805. msleep_interruptible(4 * 1000);
  1806. }
  1807. static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1808. {
  1809. struct igb_adapter *adapter = netdev_priv(netdev);
  1810. wol->wolopts = 0;
  1811. if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
  1812. return;
  1813. wol->supported = WAKE_UCAST | WAKE_MCAST |
  1814. WAKE_BCAST | WAKE_MAGIC |
  1815. WAKE_PHY;
  1816. /* apply any specific unsupported masks here */
  1817. switch (adapter->hw.device_id) {
  1818. default:
  1819. break;
  1820. }
  1821. if (adapter->wol & E1000_WUFC_EX)
  1822. wol->wolopts |= WAKE_UCAST;
  1823. if (adapter->wol & E1000_WUFC_MC)
  1824. wol->wolopts |= WAKE_MCAST;
  1825. if (adapter->wol & E1000_WUFC_BC)
  1826. wol->wolopts |= WAKE_BCAST;
  1827. if (adapter->wol & E1000_WUFC_MAG)
  1828. wol->wolopts |= WAKE_MAGIC;
  1829. if (adapter->wol & E1000_WUFC_LNKC)
  1830. wol->wolopts |= WAKE_PHY;
  1831. }
  1832. static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1833. {
  1834. struct igb_adapter *adapter = netdev_priv(netdev);
  1835. if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE))
  1836. return -EOPNOTSUPP;
  1837. if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED))
  1838. return wol->wolopts ? -EOPNOTSUPP : 0;
  1839. /* these settings will always override what we currently have */
  1840. adapter->wol = 0;
  1841. if (wol->wolopts & WAKE_UCAST)
  1842. adapter->wol |= E1000_WUFC_EX;
  1843. if (wol->wolopts & WAKE_MCAST)
  1844. adapter->wol |= E1000_WUFC_MC;
  1845. if (wol->wolopts & WAKE_BCAST)
  1846. adapter->wol |= E1000_WUFC_BC;
  1847. if (wol->wolopts & WAKE_MAGIC)
  1848. adapter->wol |= E1000_WUFC_MAG;
  1849. if (wol->wolopts & WAKE_PHY)
  1850. adapter->wol |= E1000_WUFC_LNKC;
  1851. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1852. return 0;
  1853. }
  1854. /* bit defines for adapter->led_status */
  1855. #define IGB_LED_ON 0
  1856. static int igb_set_phys_id(struct net_device *netdev,
  1857. enum ethtool_phys_id_state state)
  1858. {
  1859. struct igb_adapter *adapter = netdev_priv(netdev);
  1860. struct e1000_hw *hw = &adapter->hw;
  1861. switch (state) {
  1862. case ETHTOOL_ID_ACTIVE:
  1863. igb_blink_led(hw);
  1864. return 2;
  1865. case ETHTOOL_ID_ON:
  1866. igb_blink_led(hw);
  1867. break;
  1868. case ETHTOOL_ID_OFF:
  1869. igb_led_off(hw);
  1870. break;
  1871. case ETHTOOL_ID_INACTIVE:
  1872. igb_led_off(hw);
  1873. clear_bit(IGB_LED_ON, &adapter->led_status);
  1874. igb_cleanup_led(hw);
  1875. break;
  1876. }
  1877. return 0;
  1878. }
  1879. static int igb_set_coalesce(struct net_device *netdev,
  1880. struct ethtool_coalesce *ec)
  1881. {
  1882. struct igb_adapter *adapter = netdev_priv(netdev);
  1883. int i;
  1884. if (ec->rx_max_coalesced_frames ||
  1885. ec->rx_coalesce_usecs_irq ||
  1886. ec->rx_max_coalesced_frames_irq ||
  1887. ec->tx_max_coalesced_frames ||
  1888. ec->tx_coalesce_usecs_irq ||
  1889. ec->stats_block_coalesce_usecs ||
  1890. ec->use_adaptive_rx_coalesce ||
  1891. ec->use_adaptive_tx_coalesce ||
  1892. ec->pkt_rate_low ||
  1893. ec->rx_coalesce_usecs_low ||
  1894. ec->rx_max_coalesced_frames_low ||
  1895. ec->tx_coalesce_usecs_low ||
  1896. ec->tx_max_coalesced_frames_low ||
  1897. ec->pkt_rate_high ||
  1898. ec->rx_coalesce_usecs_high ||
  1899. ec->rx_max_coalesced_frames_high ||
  1900. ec->tx_coalesce_usecs_high ||
  1901. ec->tx_max_coalesced_frames_high ||
  1902. ec->rate_sample_interval)
  1903. return -ENOTSUPP;
  1904. if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
  1905. ((ec->rx_coalesce_usecs > 3) &&
  1906. (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
  1907. (ec->rx_coalesce_usecs == 2))
  1908. return -EINVAL;
  1909. if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) ||
  1910. ((ec->tx_coalesce_usecs > 3) &&
  1911. (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) ||
  1912. (ec->tx_coalesce_usecs == 2))
  1913. return -EINVAL;
  1914. if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs)
  1915. return -EINVAL;
  1916. /* If ITR is disabled, disable DMAC */
  1917. if (ec->rx_coalesce_usecs == 0) {
  1918. if (adapter->flags & IGB_FLAG_DMAC)
  1919. adapter->flags &= ~IGB_FLAG_DMAC;
  1920. }
  1921. /* convert to rate of irq's per second */
  1922. if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3)
  1923. adapter->rx_itr_setting = ec->rx_coalesce_usecs;
  1924. else
  1925. adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
  1926. /* convert to rate of irq's per second */
  1927. if (adapter->flags & IGB_FLAG_QUEUE_PAIRS)
  1928. adapter->tx_itr_setting = adapter->rx_itr_setting;
  1929. else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3)
  1930. adapter->tx_itr_setting = ec->tx_coalesce_usecs;
  1931. else
  1932. adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
  1933. for (i = 0; i < adapter->num_q_vectors; i++) {
  1934. struct igb_q_vector *q_vector = adapter->q_vector[i];
  1935. q_vector->tx.work_limit = adapter->tx_work_limit;
  1936. if (q_vector->rx.ring)
  1937. q_vector->itr_val = adapter->rx_itr_setting;
  1938. else
  1939. q_vector->itr_val = adapter->tx_itr_setting;
  1940. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1941. q_vector->itr_val = IGB_START_ITR;
  1942. q_vector->set_itr = 1;
  1943. }
  1944. return 0;
  1945. }
  1946. static int igb_get_coalesce(struct net_device *netdev,
  1947. struct ethtool_coalesce *ec)
  1948. {
  1949. struct igb_adapter *adapter = netdev_priv(netdev);
  1950. if (adapter->rx_itr_setting <= 3)
  1951. ec->rx_coalesce_usecs = adapter->rx_itr_setting;
  1952. else
  1953. ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
  1954. if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) {
  1955. if (adapter->tx_itr_setting <= 3)
  1956. ec->tx_coalesce_usecs = adapter->tx_itr_setting;
  1957. else
  1958. ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
  1959. }
  1960. return 0;
  1961. }
  1962. static int igb_nway_reset(struct net_device *netdev)
  1963. {
  1964. struct igb_adapter *adapter = netdev_priv(netdev);
  1965. if (netif_running(netdev))
  1966. igb_reinit_locked(adapter);
  1967. return 0;
  1968. }
  1969. static int igb_get_sset_count(struct net_device *netdev, int sset)
  1970. {
  1971. switch (sset) {
  1972. case ETH_SS_STATS:
  1973. return IGB_STATS_LEN;
  1974. case ETH_SS_TEST:
  1975. return IGB_TEST_LEN;
  1976. default:
  1977. return -ENOTSUPP;
  1978. }
  1979. }
  1980. static void igb_get_ethtool_stats(struct net_device *netdev,
  1981. struct ethtool_stats *stats, u64 *data)
  1982. {
  1983. struct igb_adapter *adapter = netdev_priv(netdev);
  1984. struct rtnl_link_stats64 *net_stats = &adapter->stats64;
  1985. unsigned int start;
  1986. struct igb_ring *ring;
  1987. int i, j;
  1988. char *p;
  1989. spin_lock(&adapter->stats64_lock);
  1990. igb_update_stats(adapter, net_stats);
  1991. for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
  1992. p = (char *)adapter + igb_gstrings_stats[i].stat_offset;
  1993. data[i] = (igb_gstrings_stats[i].sizeof_stat ==
  1994. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1995. }
  1996. for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) {
  1997. p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset;
  1998. data[i] = (igb_gstrings_net_stats[j].sizeof_stat ==
  1999. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  2000. }
  2001. for (j = 0; j < adapter->num_tx_queues; j++) {
  2002. u64 restart2;
  2003. ring = adapter->tx_ring[j];
  2004. do {
  2005. start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
  2006. data[i] = ring->tx_stats.packets;
  2007. data[i+1] = ring->tx_stats.bytes;
  2008. data[i+2] = ring->tx_stats.restart_queue;
  2009. } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
  2010. do {
  2011. start = u64_stats_fetch_begin_irq(&ring->tx_syncp2);
  2012. restart2 = ring->tx_stats.restart_queue2;
  2013. } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start));
  2014. data[i+2] += restart2;
  2015. i += IGB_TX_QUEUE_STATS_LEN;
  2016. }
  2017. for (j = 0; j < adapter->num_rx_queues; j++) {
  2018. ring = adapter->rx_ring[j];
  2019. do {
  2020. start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
  2021. data[i] = ring->rx_stats.packets;
  2022. data[i+1] = ring->rx_stats.bytes;
  2023. data[i+2] = ring->rx_stats.drops;
  2024. data[i+3] = ring->rx_stats.csum_err;
  2025. data[i+4] = ring->rx_stats.alloc_failed;
  2026. } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
  2027. i += IGB_RX_QUEUE_STATS_LEN;
  2028. }
  2029. spin_unlock(&adapter->stats64_lock);
  2030. }
  2031. static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  2032. {
  2033. struct igb_adapter *adapter = netdev_priv(netdev);
  2034. u8 *p = data;
  2035. int i;
  2036. switch (stringset) {
  2037. case ETH_SS_TEST:
  2038. memcpy(data, *igb_gstrings_test,
  2039. IGB_TEST_LEN*ETH_GSTRING_LEN);
  2040. break;
  2041. case ETH_SS_STATS:
  2042. for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) {
  2043. memcpy(p, igb_gstrings_stats[i].stat_string,
  2044. ETH_GSTRING_LEN);
  2045. p += ETH_GSTRING_LEN;
  2046. }
  2047. for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
  2048. memcpy(p, igb_gstrings_net_stats[i].stat_string,
  2049. ETH_GSTRING_LEN);
  2050. p += ETH_GSTRING_LEN;
  2051. }
  2052. for (i = 0; i < adapter->num_tx_queues; i++) {
  2053. sprintf(p, "tx_queue_%u_packets", i);
  2054. p += ETH_GSTRING_LEN;
  2055. sprintf(p, "tx_queue_%u_bytes", i);
  2056. p += ETH_GSTRING_LEN;
  2057. sprintf(p, "tx_queue_%u_restart", i);
  2058. p += ETH_GSTRING_LEN;
  2059. }
  2060. for (i = 0; i < adapter->num_rx_queues; i++) {
  2061. sprintf(p, "rx_queue_%u_packets", i);
  2062. p += ETH_GSTRING_LEN;
  2063. sprintf(p, "rx_queue_%u_bytes", i);
  2064. p += ETH_GSTRING_LEN;
  2065. sprintf(p, "rx_queue_%u_drops", i);
  2066. p += ETH_GSTRING_LEN;
  2067. sprintf(p, "rx_queue_%u_csum_err", i);
  2068. p += ETH_GSTRING_LEN;
  2069. sprintf(p, "rx_queue_%u_alloc_failed", i);
  2070. p += ETH_GSTRING_LEN;
  2071. }
  2072. /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
  2073. break;
  2074. }
  2075. }
  2076. static int igb_get_ts_info(struct net_device *dev,
  2077. struct ethtool_ts_info *info)
  2078. {
  2079. struct igb_adapter *adapter = netdev_priv(dev);
  2080. if (adapter->ptp_clock)
  2081. info->phc_index = ptp_clock_index(adapter->ptp_clock);
  2082. else
  2083. info->phc_index = -1;
  2084. switch (adapter->hw.mac.type) {
  2085. case e1000_82575:
  2086. info->so_timestamping =
  2087. SOF_TIMESTAMPING_TX_SOFTWARE |
  2088. SOF_TIMESTAMPING_RX_SOFTWARE |
  2089. SOF_TIMESTAMPING_SOFTWARE;
  2090. return 0;
  2091. case e1000_82576:
  2092. case e1000_82580:
  2093. case e1000_i350:
  2094. case e1000_i354:
  2095. case e1000_i210:
  2096. case e1000_i211:
  2097. info->so_timestamping =
  2098. SOF_TIMESTAMPING_TX_SOFTWARE |
  2099. SOF_TIMESTAMPING_RX_SOFTWARE |
  2100. SOF_TIMESTAMPING_SOFTWARE |
  2101. SOF_TIMESTAMPING_TX_HARDWARE |
  2102. SOF_TIMESTAMPING_RX_HARDWARE |
  2103. SOF_TIMESTAMPING_RAW_HARDWARE;
  2104. info->tx_types =
  2105. BIT(HWTSTAMP_TX_OFF) |
  2106. BIT(HWTSTAMP_TX_ON);
  2107. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
  2108. /* 82576 does not support timestamping all packets. */
  2109. if (adapter->hw.mac.type >= e1000_82580)
  2110. info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL);
  2111. else
  2112. info->rx_filters |=
  2113. BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  2114. BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  2115. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
  2116. return 0;
  2117. default:
  2118. return -EOPNOTSUPP;
  2119. }
  2120. }
  2121. #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
  2122. static int igb_get_ethtool_nfc_entry(struct igb_adapter *adapter,
  2123. struct ethtool_rxnfc *cmd)
  2124. {
  2125. struct ethtool_rx_flow_spec *fsp = &cmd->fs;
  2126. struct igb_nfc_filter *rule = NULL;
  2127. /* report total rule count */
  2128. cmd->data = IGB_MAX_RXNFC_FILTERS;
  2129. hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
  2130. if (fsp->location <= rule->sw_idx)
  2131. break;
  2132. }
  2133. if (!rule || fsp->location != rule->sw_idx)
  2134. return -EINVAL;
  2135. if (rule->filter.match_flags) {
  2136. fsp->flow_type = ETHER_FLOW;
  2137. fsp->ring_cookie = rule->action;
  2138. if (rule->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE) {
  2139. fsp->h_u.ether_spec.h_proto = rule->filter.etype;
  2140. fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK;
  2141. }
  2142. if (rule->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI) {
  2143. fsp->flow_type |= FLOW_EXT;
  2144. fsp->h_ext.vlan_tci = rule->filter.vlan_tci;
  2145. fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK);
  2146. }
  2147. return 0;
  2148. }
  2149. return -EINVAL;
  2150. }
  2151. static int igb_get_ethtool_nfc_all(struct igb_adapter *adapter,
  2152. struct ethtool_rxnfc *cmd,
  2153. u32 *rule_locs)
  2154. {
  2155. struct igb_nfc_filter *rule;
  2156. int cnt = 0;
  2157. /* report total rule count */
  2158. cmd->data = IGB_MAX_RXNFC_FILTERS;
  2159. hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
  2160. if (cnt == cmd->rule_cnt)
  2161. return -EMSGSIZE;
  2162. rule_locs[cnt] = rule->sw_idx;
  2163. cnt++;
  2164. }
  2165. cmd->rule_cnt = cnt;
  2166. return 0;
  2167. }
  2168. static int igb_get_rss_hash_opts(struct igb_adapter *adapter,
  2169. struct ethtool_rxnfc *cmd)
  2170. {
  2171. cmd->data = 0;
  2172. /* Report default options for RSS on igb */
  2173. switch (cmd->flow_type) {
  2174. case TCP_V4_FLOW:
  2175. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2176. /* Fall through */
  2177. case UDP_V4_FLOW:
  2178. if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
  2179. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2180. /* Fall through */
  2181. case SCTP_V4_FLOW:
  2182. case AH_ESP_V4_FLOW:
  2183. case AH_V4_FLOW:
  2184. case ESP_V4_FLOW:
  2185. case IPV4_FLOW:
  2186. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  2187. break;
  2188. case TCP_V6_FLOW:
  2189. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2190. /* Fall through */
  2191. case UDP_V6_FLOW:
  2192. if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
  2193. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2194. /* Fall through */
  2195. case SCTP_V6_FLOW:
  2196. case AH_ESP_V6_FLOW:
  2197. case AH_V6_FLOW:
  2198. case ESP_V6_FLOW:
  2199. case IPV6_FLOW:
  2200. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  2201. break;
  2202. default:
  2203. return -EINVAL;
  2204. }
  2205. return 0;
  2206. }
  2207. static int igb_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  2208. u32 *rule_locs)
  2209. {
  2210. struct igb_adapter *adapter = netdev_priv(dev);
  2211. int ret = -EOPNOTSUPP;
  2212. switch (cmd->cmd) {
  2213. case ETHTOOL_GRXRINGS:
  2214. cmd->data = adapter->num_rx_queues;
  2215. ret = 0;
  2216. break;
  2217. case ETHTOOL_GRXCLSRLCNT:
  2218. cmd->rule_cnt = adapter->nfc_filter_count;
  2219. ret = 0;
  2220. break;
  2221. case ETHTOOL_GRXCLSRULE:
  2222. ret = igb_get_ethtool_nfc_entry(adapter, cmd);
  2223. break;
  2224. case ETHTOOL_GRXCLSRLALL:
  2225. ret = igb_get_ethtool_nfc_all(adapter, cmd, rule_locs);
  2226. break;
  2227. case ETHTOOL_GRXFH:
  2228. ret = igb_get_rss_hash_opts(adapter, cmd);
  2229. break;
  2230. default:
  2231. break;
  2232. }
  2233. return ret;
  2234. }
  2235. #define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \
  2236. IGB_FLAG_RSS_FIELD_IPV6_UDP)
  2237. static int igb_set_rss_hash_opt(struct igb_adapter *adapter,
  2238. struct ethtool_rxnfc *nfc)
  2239. {
  2240. u32 flags = adapter->flags;
  2241. /* RSS does not support anything other than hashing
  2242. * to queues on src and dst IPs and ports
  2243. */
  2244. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2245. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2246. return -EINVAL;
  2247. switch (nfc->flow_type) {
  2248. case TCP_V4_FLOW:
  2249. case TCP_V6_FLOW:
  2250. if (!(nfc->data & RXH_IP_SRC) ||
  2251. !(nfc->data & RXH_IP_DST) ||
  2252. !(nfc->data & RXH_L4_B_0_1) ||
  2253. !(nfc->data & RXH_L4_B_2_3))
  2254. return -EINVAL;
  2255. break;
  2256. case UDP_V4_FLOW:
  2257. if (!(nfc->data & RXH_IP_SRC) ||
  2258. !(nfc->data & RXH_IP_DST))
  2259. return -EINVAL;
  2260. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2261. case 0:
  2262. flags &= ~IGB_FLAG_RSS_FIELD_IPV4_UDP;
  2263. break;
  2264. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2265. flags |= IGB_FLAG_RSS_FIELD_IPV4_UDP;
  2266. break;
  2267. default:
  2268. return -EINVAL;
  2269. }
  2270. break;
  2271. case UDP_V6_FLOW:
  2272. if (!(nfc->data & RXH_IP_SRC) ||
  2273. !(nfc->data & RXH_IP_DST))
  2274. return -EINVAL;
  2275. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2276. case 0:
  2277. flags &= ~IGB_FLAG_RSS_FIELD_IPV6_UDP;
  2278. break;
  2279. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2280. flags |= IGB_FLAG_RSS_FIELD_IPV6_UDP;
  2281. break;
  2282. default:
  2283. return -EINVAL;
  2284. }
  2285. break;
  2286. case AH_ESP_V4_FLOW:
  2287. case AH_V4_FLOW:
  2288. case ESP_V4_FLOW:
  2289. case SCTP_V4_FLOW:
  2290. case AH_ESP_V6_FLOW:
  2291. case AH_V6_FLOW:
  2292. case ESP_V6_FLOW:
  2293. case SCTP_V6_FLOW:
  2294. if (!(nfc->data & RXH_IP_SRC) ||
  2295. !(nfc->data & RXH_IP_DST) ||
  2296. (nfc->data & RXH_L4_B_0_1) ||
  2297. (nfc->data & RXH_L4_B_2_3))
  2298. return -EINVAL;
  2299. break;
  2300. default:
  2301. return -EINVAL;
  2302. }
  2303. /* if we changed something we need to update flags */
  2304. if (flags != adapter->flags) {
  2305. struct e1000_hw *hw = &adapter->hw;
  2306. u32 mrqc = rd32(E1000_MRQC);
  2307. if ((flags & UDP_RSS_FLAGS) &&
  2308. !(adapter->flags & UDP_RSS_FLAGS))
  2309. dev_err(&adapter->pdev->dev,
  2310. "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
  2311. adapter->flags = flags;
  2312. /* Perform hash on these packet types */
  2313. mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
  2314. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2315. E1000_MRQC_RSS_FIELD_IPV6 |
  2316. E1000_MRQC_RSS_FIELD_IPV6_TCP;
  2317. mrqc &= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP |
  2318. E1000_MRQC_RSS_FIELD_IPV6_UDP);
  2319. if (flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
  2320. mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
  2321. if (flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
  2322. mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
  2323. wr32(E1000_MRQC, mrqc);
  2324. }
  2325. return 0;
  2326. }
  2327. static int igb_rxnfc_write_etype_filter(struct igb_adapter *adapter,
  2328. struct igb_nfc_filter *input)
  2329. {
  2330. struct e1000_hw *hw = &adapter->hw;
  2331. u8 i;
  2332. u32 etqf;
  2333. u16 etype;
  2334. /* find an empty etype filter register */
  2335. for (i = 0; i < MAX_ETYPE_FILTER; ++i) {
  2336. if (!adapter->etype_bitmap[i])
  2337. break;
  2338. }
  2339. if (i == MAX_ETYPE_FILTER) {
  2340. dev_err(&adapter->pdev->dev, "ethtool -N: etype filters are all used.\n");
  2341. return -EINVAL;
  2342. }
  2343. adapter->etype_bitmap[i] = true;
  2344. etqf = rd32(E1000_ETQF(i));
  2345. etype = ntohs(input->filter.etype & ETHER_TYPE_FULL_MASK);
  2346. etqf |= E1000_ETQF_FILTER_ENABLE;
  2347. etqf &= ~E1000_ETQF_ETYPE_MASK;
  2348. etqf |= (etype & E1000_ETQF_ETYPE_MASK);
  2349. etqf &= ~E1000_ETQF_QUEUE_MASK;
  2350. etqf |= ((input->action << E1000_ETQF_QUEUE_SHIFT)
  2351. & E1000_ETQF_QUEUE_MASK);
  2352. etqf |= E1000_ETQF_QUEUE_ENABLE;
  2353. wr32(E1000_ETQF(i), etqf);
  2354. input->etype_reg_index = i;
  2355. return 0;
  2356. }
  2357. static int igb_rxnfc_write_vlan_prio_filter(struct igb_adapter *adapter,
  2358. struct igb_nfc_filter *input)
  2359. {
  2360. struct e1000_hw *hw = &adapter->hw;
  2361. u8 vlan_priority;
  2362. u16 queue_index;
  2363. u32 vlapqf;
  2364. vlapqf = rd32(E1000_VLAPQF);
  2365. vlan_priority = (ntohs(input->filter.vlan_tci) & VLAN_PRIO_MASK)
  2366. >> VLAN_PRIO_SHIFT;
  2367. queue_index = (vlapqf >> (vlan_priority * 4)) & E1000_VLAPQF_QUEUE_MASK;
  2368. /* check whether this vlan prio is already set */
  2369. if ((vlapqf & E1000_VLAPQF_P_VALID(vlan_priority)) &&
  2370. (queue_index != input->action)) {
  2371. dev_err(&adapter->pdev->dev, "ethtool rxnfc set vlan prio filter failed.\n");
  2372. return -EEXIST;
  2373. }
  2374. vlapqf |= E1000_VLAPQF_P_VALID(vlan_priority);
  2375. vlapqf |= E1000_VLAPQF_QUEUE_SEL(vlan_priority, input->action);
  2376. wr32(E1000_VLAPQF, vlapqf);
  2377. return 0;
  2378. }
  2379. int igb_add_filter(struct igb_adapter *adapter, struct igb_nfc_filter *input)
  2380. {
  2381. int err = -EINVAL;
  2382. if (input->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE) {
  2383. err = igb_rxnfc_write_etype_filter(adapter, input);
  2384. if (err)
  2385. return err;
  2386. }
  2387. if (input->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI)
  2388. err = igb_rxnfc_write_vlan_prio_filter(adapter, input);
  2389. return err;
  2390. }
  2391. static void igb_clear_etype_filter_regs(struct igb_adapter *adapter,
  2392. u16 reg_index)
  2393. {
  2394. struct e1000_hw *hw = &adapter->hw;
  2395. u32 etqf = rd32(E1000_ETQF(reg_index));
  2396. etqf &= ~E1000_ETQF_QUEUE_ENABLE;
  2397. etqf &= ~E1000_ETQF_QUEUE_MASK;
  2398. etqf &= ~E1000_ETQF_FILTER_ENABLE;
  2399. wr32(E1000_ETQF(reg_index), etqf);
  2400. adapter->etype_bitmap[reg_index] = false;
  2401. }
  2402. static void igb_clear_vlan_prio_filter(struct igb_adapter *adapter,
  2403. u16 vlan_tci)
  2404. {
  2405. struct e1000_hw *hw = &adapter->hw;
  2406. u8 vlan_priority;
  2407. u32 vlapqf;
  2408. vlan_priority = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  2409. vlapqf = rd32(E1000_VLAPQF);
  2410. vlapqf &= ~E1000_VLAPQF_P_VALID(vlan_priority);
  2411. vlapqf &= ~E1000_VLAPQF_QUEUE_SEL(vlan_priority,
  2412. E1000_VLAPQF_QUEUE_MASK);
  2413. wr32(E1000_VLAPQF, vlapqf);
  2414. }
  2415. int igb_erase_filter(struct igb_adapter *adapter, struct igb_nfc_filter *input)
  2416. {
  2417. if (input->filter.match_flags & IGB_FILTER_FLAG_ETHER_TYPE)
  2418. igb_clear_etype_filter_regs(adapter,
  2419. input->etype_reg_index);
  2420. if (input->filter.match_flags & IGB_FILTER_FLAG_VLAN_TCI)
  2421. igb_clear_vlan_prio_filter(adapter,
  2422. ntohs(input->filter.vlan_tci));
  2423. return 0;
  2424. }
  2425. static int igb_update_ethtool_nfc_entry(struct igb_adapter *adapter,
  2426. struct igb_nfc_filter *input,
  2427. u16 sw_idx)
  2428. {
  2429. struct igb_nfc_filter *rule, *parent;
  2430. int err = -EINVAL;
  2431. parent = NULL;
  2432. rule = NULL;
  2433. hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
  2434. /* hash found, or no matching entry */
  2435. if (rule->sw_idx >= sw_idx)
  2436. break;
  2437. parent = rule;
  2438. }
  2439. /* if there is an old rule occupying our place remove it */
  2440. if (rule && (rule->sw_idx == sw_idx)) {
  2441. if (!input)
  2442. err = igb_erase_filter(adapter, rule);
  2443. hlist_del(&rule->nfc_node);
  2444. kfree(rule);
  2445. adapter->nfc_filter_count--;
  2446. }
  2447. /* If no input this was a delete, err should be 0 if a rule was
  2448. * successfully found and removed from the list else -EINVAL
  2449. */
  2450. if (!input)
  2451. return err;
  2452. /* initialize node */
  2453. INIT_HLIST_NODE(&input->nfc_node);
  2454. /* add filter to the list */
  2455. if (parent)
  2456. hlist_add_behind(&parent->nfc_node, &input->nfc_node);
  2457. else
  2458. hlist_add_head(&input->nfc_node, &adapter->nfc_filter_list);
  2459. /* update counts */
  2460. adapter->nfc_filter_count++;
  2461. return 0;
  2462. }
  2463. static int igb_add_ethtool_nfc_entry(struct igb_adapter *adapter,
  2464. struct ethtool_rxnfc *cmd)
  2465. {
  2466. struct net_device *netdev = adapter->netdev;
  2467. struct ethtool_rx_flow_spec *fsp =
  2468. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2469. struct igb_nfc_filter *input, *rule;
  2470. int err = 0;
  2471. if (!(netdev->hw_features & NETIF_F_NTUPLE))
  2472. return -EOPNOTSUPP;
  2473. /* Don't allow programming if the action is a queue greater than
  2474. * the number of online Rx queues.
  2475. */
  2476. if ((fsp->ring_cookie == RX_CLS_FLOW_DISC) ||
  2477. (fsp->ring_cookie >= adapter->num_rx_queues)) {
  2478. dev_err(&adapter->pdev->dev, "ethtool -N: The specified action is invalid\n");
  2479. return -EINVAL;
  2480. }
  2481. /* Don't allow indexes to exist outside of available space */
  2482. if (fsp->location >= IGB_MAX_RXNFC_FILTERS) {
  2483. dev_err(&adapter->pdev->dev, "Location out of range\n");
  2484. return -EINVAL;
  2485. }
  2486. if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW)
  2487. return -EINVAL;
  2488. if (fsp->m_u.ether_spec.h_proto != ETHER_TYPE_FULL_MASK &&
  2489. fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK))
  2490. return -EINVAL;
  2491. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2492. if (!input)
  2493. return -ENOMEM;
  2494. if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) {
  2495. input->filter.etype = fsp->h_u.ether_spec.h_proto;
  2496. input->filter.match_flags = IGB_FILTER_FLAG_ETHER_TYPE;
  2497. }
  2498. if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) {
  2499. if (fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK)) {
  2500. err = -EINVAL;
  2501. goto err_out;
  2502. }
  2503. input->filter.vlan_tci = fsp->h_ext.vlan_tci;
  2504. input->filter.match_flags |= IGB_FILTER_FLAG_VLAN_TCI;
  2505. }
  2506. input->action = fsp->ring_cookie;
  2507. input->sw_idx = fsp->location;
  2508. spin_lock(&adapter->nfc_lock);
  2509. hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node) {
  2510. if (!memcmp(&input->filter, &rule->filter,
  2511. sizeof(input->filter))) {
  2512. err = -EEXIST;
  2513. dev_err(&adapter->pdev->dev,
  2514. "ethtool: this filter is already set\n");
  2515. goto err_out_w_lock;
  2516. }
  2517. }
  2518. err = igb_add_filter(adapter, input);
  2519. if (err)
  2520. goto err_out_w_lock;
  2521. igb_update_ethtool_nfc_entry(adapter, input, input->sw_idx);
  2522. spin_unlock(&adapter->nfc_lock);
  2523. return 0;
  2524. err_out_w_lock:
  2525. spin_unlock(&adapter->nfc_lock);
  2526. err_out:
  2527. kfree(input);
  2528. return err;
  2529. }
  2530. static int igb_del_ethtool_nfc_entry(struct igb_adapter *adapter,
  2531. struct ethtool_rxnfc *cmd)
  2532. {
  2533. struct ethtool_rx_flow_spec *fsp =
  2534. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2535. int err;
  2536. spin_lock(&adapter->nfc_lock);
  2537. err = igb_update_ethtool_nfc_entry(adapter, NULL, fsp->location);
  2538. spin_unlock(&adapter->nfc_lock);
  2539. return err;
  2540. }
  2541. static int igb_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  2542. {
  2543. struct igb_adapter *adapter = netdev_priv(dev);
  2544. int ret = -EOPNOTSUPP;
  2545. switch (cmd->cmd) {
  2546. case ETHTOOL_SRXFH:
  2547. ret = igb_set_rss_hash_opt(adapter, cmd);
  2548. break;
  2549. case ETHTOOL_SRXCLSRLINS:
  2550. ret = igb_add_ethtool_nfc_entry(adapter, cmd);
  2551. break;
  2552. case ETHTOOL_SRXCLSRLDEL:
  2553. ret = igb_del_ethtool_nfc_entry(adapter, cmd);
  2554. default:
  2555. break;
  2556. }
  2557. return ret;
  2558. }
  2559. static int igb_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
  2560. {
  2561. struct igb_adapter *adapter = netdev_priv(netdev);
  2562. struct e1000_hw *hw = &adapter->hw;
  2563. u32 ret_val;
  2564. u16 phy_data;
  2565. if ((hw->mac.type < e1000_i350) ||
  2566. (hw->phy.media_type != e1000_media_type_copper))
  2567. return -EOPNOTSUPP;
  2568. edata->supported = (SUPPORTED_1000baseT_Full |
  2569. SUPPORTED_100baseT_Full);
  2570. if (!hw->dev_spec._82575.eee_disable)
  2571. edata->advertised =
  2572. mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
  2573. /* The IPCNFG and EEER registers are not supported on I354. */
  2574. if (hw->mac.type == e1000_i354) {
  2575. igb_get_eee_status_i354(hw, (bool *)&edata->eee_active);
  2576. } else {
  2577. u32 eeer;
  2578. eeer = rd32(E1000_EEER);
  2579. /* EEE status on negotiated link */
  2580. if (eeer & E1000_EEER_EEE_NEG)
  2581. edata->eee_active = true;
  2582. if (eeer & E1000_EEER_TX_LPI_EN)
  2583. edata->tx_lpi_enabled = true;
  2584. }
  2585. /* EEE Link Partner Advertised */
  2586. switch (hw->mac.type) {
  2587. case e1000_i350:
  2588. ret_val = igb_read_emi_reg(hw, E1000_EEE_LP_ADV_ADDR_I350,
  2589. &phy_data);
  2590. if (ret_val)
  2591. return -ENODATA;
  2592. edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
  2593. break;
  2594. case e1000_i354:
  2595. case e1000_i210:
  2596. case e1000_i211:
  2597. ret_val = igb_read_xmdio_reg(hw, E1000_EEE_LP_ADV_ADDR_I210,
  2598. E1000_EEE_LP_ADV_DEV_I210,
  2599. &phy_data);
  2600. if (ret_val)
  2601. return -ENODATA;
  2602. edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
  2603. break;
  2604. default:
  2605. break;
  2606. }
  2607. edata->eee_enabled = !hw->dev_spec._82575.eee_disable;
  2608. if ((hw->mac.type == e1000_i354) &&
  2609. (edata->eee_enabled))
  2610. edata->tx_lpi_enabled = true;
  2611. /* Report correct negotiated EEE status for devices that
  2612. * wrongly report EEE at half-duplex
  2613. */
  2614. if (adapter->link_duplex == HALF_DUPLEX) {
  2615. edata->eee_enabled = false;
  2616. edata->eee_active = false;
  2617. edata->tx_lpi_enabled = false;
  2618. edata->advertised &= ~edata->advertised;
  2619. }
  2620. return 0;
  2621. }
  2622. static int igb_set_eee(struct net_device *netdev,
  2623. struct ethtool_eee *edata)
  2624. {
  2625. struct igb_adapter *adapter = netdev_priv(netdev);
  2626. struct e1000_hw *hw = &adapter->hw;
  2627. struct ethtool_eee eee_curr;
  2628. bool adv1g_eee = true, adv100m_eee = true;
  2629. s32 ret_val;
  2630. if ((hw->mac.type < e1000_i350) ||
  2631. (hw->phy.media_type != e1000_media_type_copper))
  2632. return -EOPNOTSUPP;
  2633. memset(&eee_curr, 0, sizeof(struct ethtool_eee));
  2634. ret_val = igb_get_eee(netdev, &eee_curr);
  2635. if (ret_val)
  2636. return ret_val;
  2637. if (eee_curr.eee_enabled) {
  2638. if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
  2639. dev_err(&adapter->pdev->dev,
  2640. "Setting EEE tx-lpi is not supported\n");
  2641. return -EINVAL;
  2642. }
  2643. /* Tx LPI timer is not implemented currently */
  2644. if (edata->tx_lpi_timer) {
  2645. dev_err(&adapter->pdev->dev,
  2646. "Setting EEE Tx LPI timer is not supported\n");
  2647. return -EINVAL;
  2648. }
  2649. if (!edata->advertised || (edata->advertised &
  2650. ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL))) {
  2651. dev_err(&adapter->pdev->dev,
  2652. "EEE Advertisement supports only 100Tx and/or 100T full duplex\n");
  2653. return -EINVAL;
  2654. }
  2655. adv100m_eee = !!(edata->advertised & ADVERTISE_100_FULL);
  2656. adv1g_eee = !!(edata->advertised & ADVERTISE_1000_FULL);
  2657. } else if (!edata->eee_enabled) {
  2658. dev_err(&adapter->pdev->dev,
  2659. "Setting EEE options are not supported with EEE disabled\n");
  2660. return -EINVAL;
  2661. }
  2662. adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
  2663. if (hw->dev_spec._82575.eee_disable != !edata->eee_enabled) {
  2664. hw->dev_spec._82575.eee_disable = !edata->eee_enabled;
  2665. adapter->flags |= IGB_FLAG_EEE;
  2666. /* reset link */
  2667. if (netif_running(netdev))
  2668. igb_reinit_locked(adapter);
  2669. else
  2670. igb_reset(adapter);
  2671. }
  2672. if (hw->mac.type == e1000_i354)
  2673. ret_val = igb_set_eee_i354(hw, adv1g_eee, adv100m_eee);
  2674. else
  2675. ret_val = igb_set_eee_i350(hw, adv1g_eee, adv100m_eee);
  2676. if (ret_val) {
  2677. dev_err(&adapter->pdev->dev,
  2678. "Problem setting EEE advertisement options\n");
  2679. return -EINVAL;
  2680. }
  2681. return 0;
  2682. }
  2683. static int igb_get_module_info(struct net_device *netdev,
  2684. struct ethtool_modinfo *modinfo)
  2685. {
  2686. struct igb_adapter *adapter = netdev_priv(netdev);
  2687. struct e1000_hw *hw = &adapter->hw;
  2688. u32 status = 0;
  2689. u16 sff8472_rev, addr_mode;
  2690. bool page_swap = false;
  2691. if ((hw->phy.media_type == e1000_media_type_copper) ||
  2692. (hw->phy.media_type == e1000_media_type_unknown))
  2693. return -EOPNOTSUPP;
  2694. /* Check whether we support SFF-8472 or not */
  2695. status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
  2696. if (status)
  2697. return -EIO;
  2698. /* addressing mode is not supported */
  2699. status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
  2700. if (status)
  2701. return -EIO;
  2702. /* addressing mode is not supported */
  2703. if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
  2704. hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
  2705. page_swap = true;
  2706. }
  2707. if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
  2708. /* We have an SFP, but it does not support SFF-8472 */
  2709. modinfo->type = ETH_MODULE_SFF_8079;
  2710. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  2711. } else {
  2712. /* We have an SFP which supports a revision of SFF-8472 */
  2713. modinfo->type = ETH_MODULE_SFF_8472;
  2714. modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
  2715. }
  2716. return 0;
  2717. }
  2718. static int igb_get_module_eeprom(struct net_device *netdev,
  2719. struct ethtool_eeprom *ee, u8 *data)
  2720. {
  2721. struct igb_adapter *adapter = netdev_priv(netdev);
  2722. struct e1000_hw *hw = &adapter->hw;
  2723. u32 status = 0;
  2724. u16 *dataword;
  2725. u16 first_word, last_word;
  2726. int i = 0;
  2727. if (ee->len == 0)
  2728. return -EINVAL;
  2729. first_word = ee->offset >> 1;
  2730. last_word = (ee->offset + ee->len - 1) >> 1;
  2731. dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  2732. GFP_KERNEL);
  2733. if (!dataword)
  2734. return -ENOMEM;
  2735. /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
  2736. for (i = 0; i < last_word - first_word + 1; i++) {
  2737. status = igb_read_phy_reg_i2c(hw, (first_word + i) * 2,
  2738. &dataword[i]);
  2739. if (status) {
  2740. /* Error occurred while reading module */
  2741. kfree(dataword);
  2742. return -EIO;
  2743. }
  2744. be16_to_cpus(&dataword[i]);
  2745. }
  2746. memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len);
  2747. kfree(dataword);
  2748. return 0;
  2749. }
  2750. static int igb_ethtool_begin(struct net_device *netdev)
  2751. {
  2752. struct igb_adapter *adapter = netdev_priv(netdev);
  2753. pm_runtime_get_sync(&adapter->pdev->dev);
  2754. return 0;
  2755. }
  2756. static void igb_ethtool_complete(struct net_device *netdev)
  2757. {
  2758. struct igb_adapter *adapter = netdev_priv(netdev);
  2759. pm_runtime_put(&adapter->pdev->dev);
  2760. }
  2761. static u32 igb_get_rxfh_indir_size(struct net_device *netdev)
  2762. {
  2763. return IGB_RETA_SIZE;
  2764. }
  2765. static int igb_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2766. u8 *hfunc)
  2767. {
  2768. struct igb_adapter *adapter = netdev_priv(netdev);
  2769. int i;
  2770. if (hfunc)
  2771. *hfunc = ETH_RSS_HASH_TOP;
  2772. if (!indir)
  2773. return 0;
  2774. for (i = 0; i < IGB_RETA_SIZE; i++)
  2775. indir[i] = adapter->rss_indir_tbl[i];
  2776. return 0;
  2777. }
  2778. void igb_write_rss_indir_tbl(struct igb_adapter *adapter)
  2779. {
  2780. struct e1000_hw *hw = &adapter->hw;
  2781. u32 reg = E1000_RETA(0);
  2782. u32 shift = 0;
  2783. int i = 0;
  2784. switch (hw->mac.type) {
  2785. case e1000_82575:
  2786. shift = 6;
  2787. break;
  2788. case e1000_82576:
  2789. /* 82576 supports 2 RSS queues for SR-IOV */
  2790. if (adapter->vfs_allocated_count)
  2791. shift = 3;
  2792. break;
  2793. default:
  2794. break;
  2795. }
  2796. while (i < IGB_RETA_SIZE) {
  2797. u32 val = 0;
  2798. int j;
  2799. for (j = 3; j >= 0; j--) {
  2800. val <<= 8;
  2801. val |= adapter->rss_indir_tbl[i + j];
  2802. }
  2803. wr32(reg, val << shift);
  2804. reg += 4;
  2805. i += 4;
  2806. }
  2807. }
  2808. static int igb_set_rxfh(struct net_device *netdev, const u32 *indir,
  2809. const u8 *key, const u8 hfunc)
  2810. {
  2811. struct igb_adapter *adapter = netdev_priv(netdev);
  2812. struct e1000_hw *hw = &adapter->hw;
  2813. int i;
  2814. u32 num_queues;
  2815. /* We do not allow change in unsupported parameters */
  2816. if (key ||
  2817. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  2818. return -EOPNOTSUPP;
  2819. if (!indir)
  2820. return 0;
  2821. num_queues = adapter->rss_queues;
  2822. switch (hw->mac.type) {
  2823. case e1000_82576:
  2824. /* 82576 supports 2 RSS queues for SR-IOV */
  2825. if (adapter->vfs_allocated_count)
  2826. num_queues = 2;
  2827. break;
  2828. default:
  2829. break;
  2830. }
  2831. /* Verify user input. */
  2832. for (i = 0; i < IGB_RETA_SIZE; i++)
  2833. if (indir[i] >= num_queues)
  2834. return -EINVAL;
  2835. for (i = 0; i < IGB_RETA_SIZE; i++)
  2836. adapter->rss_indir_tbl[i] = indir[i];
  2837. igb_write_rss_indir_tbl(adapter);
  2838. return 0;
  2839. }
  2840. static unsigned int igb_max_channels(struct igb_adapter *adapter)
  2841. {
  2842. struct e1000_hw *hw = &adapter->hw;
  2843. unsigned int max_combined = 0;
  2844. switch (hw->mac.type) {
  2845. case e1000_i211:
  2846. max_combined = IGB_MAX_RX_QUEUES_I211;
  2847. break;
  2848. case e1000_82575:
  2849. case e1000_i210:
  2850. max_combined = IGB_MAX_RX_QUEUES_82575;
  2851. break;
  2852. case e1000_i350:
  2853. if (!!adapter->vfs_allocated_count) {
  2854. max_combined = 1;
  2855. break;
  2856. }
  2857. /* fall through */
  2858. case e1000_82576:
  2859. if (!!adapter->vfs_allocated_count) {
  2860. max_combined = 2;
  2861. break;
  2862. }
  2863. /* fall through */
  2864. case e1000_82580:
  2865. case e1000_i354:
  2866. default:
  2867. max_combined = IGB_MAX_RX_QUEUES;
  2868. break;
  2869. }
  2870. return max_combined;
  2871. }
  2872. static void igb_get_channels(struct net_device *netdev,
  2873. struct ethtool_channels *ch)
  2874. {
  2875. struct igb_adapter *adapter = netdev_priv(netdev);
  2876. /* Report maximum channels */
  2877. ch->max_combined = igb_max_channels(adapter);
  2878. /* Report info for other vector */
  2879. if (adapter->flags & IGB_FLAG_HAS_MSIX) {
  2880. ch->max_other = NON_Q_VECTORS;
  2881. ch->other_count = NON_Q_VECTORS;
  2882. }
  2883. ch->combined_count = adapter->rss_queues;
  2884. }
  2885. static int igb_set_channels(struct net_device *netdev,
  2886. struct ethtool_channels *ch)
  2887. {
  2888. struct igb_adapter *adapter = netdev_priv(netdev);
  2889. unsigned int count = ch->combined_count;
  2890. unsigned int max_combined = 0;
  2891. /* Verify they are not requesting separate vectors */
  2892. if (!count || ch->rx_count || ch->tx_count)
  2893. return -EINVAL;
  2894. /* Verify other_count is valid and has not been changed */
  2895. if (ch->other_count != NON_Q_VECTORS)
  2896. return -EINVAL;
  2897. /* Verify the number of channels doesn't exceed hw limits */
  2898. max_combined = igb_max_channels(adapter);
  2899. if (count > max_combined)
  2900. return -EINVAL;
  2901. if (count != adapter->rss_queues) {
  2902. adapter->rss_queues = count;
  2903. igb_set_flag_queue_pairs(adapter, max_combined);
  2904. /* Hardware has to reinitialize queues and interrupts to
  2905. * match the new configuration.
  2906. */
  2907. return igb_reinit_queues(adapter);
  2908. }
  2909. return 0;
  2910. }
  2911. static const struct ethtool_ops igb_ethtool_ops = {
  2912. .get_settings = igb_get_settings,
  2913. .set_settings = igb_set_settings,
  2914. .get_drvinfo = igb_get_drvinfo,
  2915. .get_regs_len = igb_get_regs_len,
  2916. .get_regs = igb_get_regs,
  2917. .get_wol = igb_get_wol,
  2918. .set_wol = igb_set_wol,
  2919. .get_msglevel = igb_get_msglevel,
  2920. .set_msglevel = igb_set_msglevel,
  2921. .nway_reset = igb_nway_reset,
  2922. .get_link = igb_get_link,
  2923. .get_eeprom_len = igb_get_eeprom_len,
  2924. .get_eeprom = igb_get_eeprom,
  2925. .set_eeprom = igb_set_eeprom,
  2926. .get_ringparam = igb_get_ringparam,
  2927. .set_ringparam = igb_set_ringparam,
  2928. .get_pauseparam = igb_get_pauseparam,
  2929. .set_pauseparam = igb_set_pauseparam,
  2930. .self_test = igb_diag_test,
  2931. .get_strings = igb_get_strings,
  2932. .set_phys_id = igb_set_phys_id,
  2933. .get_sset_count = igb_get_sset_count,
  2934. .get_ethtool_stats = igb_get_ethtool_stats,
  2935. .get_coalesce = igb_get_coalesce,
  2936. .set_coalesce = igb_set_coalesce,
  2937. .get_ts_info = igb_get_ts_info,
  2938. .get_rxnfc = igb_get_rxnfc,
  2939. .set_rxnfc = igb_set_rxnfc,
  2940. .get_eee = igb_get_eee,
  2941. .set_eee = igb_set_eee,
  2942. .get_module_info = igb_get_module_info,
  2943. .get_module_eeprom = igb_get_module_eeprom,
  2944. .get_rxfh_indir_size = igb_get_rxfh_indir_size,
  2945. .get_rxfh = igb_get_rxfh,
  2946. .set_rxfh = igb_set_rxfh,
  2947. .get_channels = igb_get_channels,
  2948. .set_channels = igb_set_channels,
  2949. .begin = igb_ethtool_begin,
  2950. .complete = igb_ethtool_complete,
  2951. };
  2952. void igb_set_ethtool_ops(struct net_device *netdev)
  2953. {
  2954. netdev->ethtool_ops = &igb_ethtool_ops;
  2955. }