i40e_ethtool.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40e */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. struct i40e_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define I40E_STAT(_type, _name, _stat) { \
  35. .stat_string = _name, \
  36. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  37. .stat_offset = offsetof(_type, _stat) \
  38. }
  39. #define I40E_NETDEV_STAT(_net_stat) \
  40. I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
  41. #define I40E_PF_STAT(_name, _stat) \
  42. I40E_STAT(struct i40e_pf, _name, _stat)
  43. #define I40E_VSI_STAT(_name, _stat) \
  44. I40E_STAT(struct i40e_vsi, _name, _stat)
  45. #define I40E_VEB_STAT(_name, _stat) \
  46. I40E_STAT(struct i40e_veb, _name, _stat)
  47. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  48. I40E_NETDEV_STAT(rx_packets),
  49. I40E_NETDEV_STAT(tx_packets),
  50. I40E_NETDEV_STAT(rx_bytes),
  51. I40E_NETDEV_STAT(tx_bytes),
  52. I40E_NETDEV_STAT(rx_errors),
  53. I40E_NETDEV_STAT(tx_errors),
  54. I40E_NETDEV_STAT(rx_dropped),
  55. I40E_NETDEV_STAT(tx_dropped),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. static const struct i40e_stats i40e_gstrings_veb_stats[] = {
  61. I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
  62. I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
  63. I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
  64. I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
  65. I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
  66. I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
  67. I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
  68. I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
  69. I40E_VEB_STAT("rx_discards", stats.rx_discards),
  70. I40E_VEB_STAT("tx_discards", stats.tx_discards),
  71. I40E_VEB_STAT("tx_errors", stats.tx_errors),
  72. I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
  73. };
  74. static const struct i40e_stats i40e_gstrings_misc_stats[] = {
  75. I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  76. I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  77. I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  78. I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  79. I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  80. I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  81. I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  82. I40E_VSI_STAT("tx_linearize", tx_linearize),
  83. I40E_VSI_STAT("tx_force_wb", tx_force_wb),
  84. I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
  85. I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  86. I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  87. };
  88. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  89. * but they are separate. This device supports Virtualization, and
  90. * as such might have several netdevs supporting VMDq and FCoE going
  91. * through a single port. The NETDEV_STATs are for individual netdevs
  92. * seen at the top of the stack, and the PF_STATs are for the physical
  93. * function at the bottom of the stack hosting those netdevs.
  94. *
  95. * The PF_STATs are appended to the netdev stats only when ethtool -S
  96. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  97. */
  98. static const struct i40e_stats i40e_gstrings_stats[] = {
  99. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  100. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  101. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  102. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  103. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  104. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  105. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  106. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  107. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  108. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  109. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  110. I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
  111. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  112. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  113. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  114. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  115. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  116. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  117. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  118. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  119. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  120. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  121. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  122. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  123. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  124. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  125. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  126. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  127. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  128. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  129. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  130. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  131. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  132. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  133. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  134. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  135. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  136. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  137. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  138. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  139. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  140. I40E_PF_STAT("arq_overflows", arq_overflows),
  141. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  142. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  143. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  144. I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
  145. I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
  146. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  147. I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
  148. /* LPI stats */
  149. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  150. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  151. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  152. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  153. };
  154. #ifdef I40E_FCOE
  155. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  156. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  157. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  158. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  159. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  160. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  161. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  162. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  163. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  164. };
  165. #endif /* I40E_FCOE */
  166. #define I40E_QUEUE_STATS_LEN(n) \
  167. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  168. * 2 /* Tx and Rx together */ \
  169. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  170. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  171. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  172. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  173. #ifdef I40E_FCOE
  174. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  175. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  176. I40E_FCOE_STATS_LEN + \
  177. I40E_MISC_STATS_LEN + \
  178. I40E_QUEUE_STATS_LEN((n)))
  179. #else
  180. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  181. I40E_MISC_STATS_LEN + \
  182. I40E_QUEUE_STATS_LEN((n)))
  183. #endif /* I40E_FCOE */
  184. #define I40E_PFC_STATS_LEN ( \
  185. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  186. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  187. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  188. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  189. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  190. / sizeof(u64))
  191. #define I40E_VEB_TC_STATS_LEN ( \
  192. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  193. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  194. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  195. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  196. / sizeof(u64))
  197. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  198. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  199. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  200. I40E_PFC_STATS_LEN + \
  201. I40E_VSI_STATS_LEN((n)))
  202. enum i40e_ethtool_test_id {
  203. I40E_ETH_TEST_REG = 0,
  204. I40E_ETH_TEST_EEPROM,
  205. I40E_ETH_TEST_INTR,
  206. I40E_ETH_TEST_LINK,
  207. };
  208. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  209. "Register test (offline)",
  210. "Eeprom test (offline)",
  211. "Interrupt test (offline)",
  212. "Link test (on/offline)"
  213. };
  214. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  215. static const char i40e_priv_flags_strings_gl[][ETH_GSTRING_LEN] = {
  216. "MFP",
  217. "LinkPolling",
  218. "flow-director-atr",
  219. "veb-stats",
  220. "hw-atr-eviction",
  221. "vf-true-promisc-support",
  222. };
  223. #define I40E_PRIV_FLAGS_GL_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings_gl)
  224. static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
  225. "NPAR",
  226. "LinkPolling",
  227. "flow-director-atr",
  228. "veb-stats",
  229. "hw-atr-eviction",
  230. };
  231. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
  232. /**
  233. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  234. * @pf: the PF struct
  235. **/
  236. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  237. {
  238. dev_info(&pf->pdev->dev,
  239. "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
  240. }
  241. /**
  242. * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
  243. * @phy_types: PHY types to convert
  244. * @supported: pointer to the ethtool supported variable to fill in
  245. * @advertising: pointer to the ethtool advertising variable to fill in
  246. *
  247. **/
  248. static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
  249. u32 *advertising)
  250. {
  251. enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types;
  252. struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
  253. *supported = 0x0;
  254. *advertising = 0x0;
  255. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  256. *supported |= SUPPORTED_Autoneg |
  257. SUPPORTED_1000baseT_Full;
  258. *advertising |= ADVERTISED_Autoneg;
  259. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  260. *advertising |= ADVERTISED_1000baseT_Full;
  261. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  262. *supported |= SUPPORTED_100baseT_Full;
  263. *advertising |= ADVERTISED_100baseT_Full;
  264. }
  265. }
  266. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  267. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  268. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  269. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  270. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  271. *supported |= SUPPORTED_10000baseT_Full;
  272. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  273. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  274. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  275. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  276. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  277. *supported |= SUPPORTED_Autoneg |
  278. SUPPORTED_10000baseT_Full;
  279. *advertising |= ADVERTISED_Autoneg;
  280. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  281. *advertising |= ADVERTISED_10000baseT_Full;
  282. }
  283. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  284. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  285. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  286. *supported |= SUPPORTED_40000baseCR4_Full;
  287. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  288. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  289. *supported |= SUPPORTED_Autoneg |
  290. SUPPORTED_40000baseCR4_Full;
  291. *advertising |= ADVERTISED_Autoneg;
  292. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
  293. *advertising |= ADVERTISED_40000baseCR4_Full;
  294. }
  295. if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
  296. *supported |= SUPPORTED_Autoneg |
  297. SUPPORTED_100baseT_Full;
  298. *advertising |= ADVERTISED_Autoneg;
  299. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  300. *advertising |= ADVERTISED_100baseT_Full;
  301. }
  302. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  303. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  304. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  305. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  306. *supported |= SUPPORTED_Autoneg |
  307. SUPPORTED_1000baseT_Full;
  308. *advertising |= ADVERTISED_Autoneg;
  309. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  310. *advertising |= ADVERTISED_1000baseT_Full;
  311. }
  312. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  313. *supported |= SUPPORTED_40000baseSR4_Full;
  314. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  315. *supported |= SUPPORTED_40000baseLR4_Full;
  316. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  317. *supported |= SUPPORTED_40000baseKR4_Full |
  318. SUPPORTED_Autoneg;
  319. *advertising |= ADVERTISED_40000baseKR4_Full |
  320. ADVERTISED_Autoneg;
  321. }
  322. if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  323. *supported |= SUPPORTED_20000baseKR2_Full |
  324. SUPPORTED_Autoneg;
  325. *advertising |= ADVERTISED_Autoneg;
  326. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
  327. *advertising |= ADVERTISED_20000baseKR2_Full;
  328. }
  329. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  330. *supported |= SUPPORTED_10000baseKR_Full |
  331. SUPPORTED_Autoneg;
  332. *advertising |= ADVERTISED_Autoneg;
  333. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  334. *advertising |= ADVERTISED_10000baseKR_Full;
  335. }
  336. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  337. *supported |= SUPPORTED_10000baseKX4_Full |
  338. SUPPORTED_Autoneg;
  339. *advertising |= ADVERTISED_Autoneg;
  340. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  341. *advertising |= ADVERTISED_10000baseKX4_Full;
  342. }
  343. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  344. *supported |= SUPPORTED_1000baseKX_Full |
  345. SUPPORTED_Autoneg;
  346. *advertising |= ADVERTISED_Autoneg;
  347. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  348. *advertising |= ADVERTISED_1000baseKX_Full;
  349. }
  350. }
  351. /**
  352. * i40e_get_settings_link_up - Get the Link settings for when link is up
  353. * @hw: hw structure
  354. * @ecmd: ethtool command to fill in
  355. * @netdev: network interface device structure
  356. *
  357. **/
  358. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  359. struct ethtool_cmd *ecmd,
  360. struct net_device *netdev,
  361. struct i40e_pf *pf)
  362. {
  363. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  364. u32 link_speed = hw_link_info->link_speed;
  365. u32 e_advertising = 0x0;
  366. u32 e_supported = 0x0;
  367. /* Initialize supported and advertised settings based on phy settings */
  368. switch (hw_link_info->phy_type) {
  369. case I40E_PHY_TYPE_40GBASE_CR4:
  370. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  371. ecmd->supported = SUPPORTED_Autoneg |
  372. SUPPORTED_40000baseCR4_Full;
  373. ecmd->advertising = ADVERTISED_Autoneg |
  374. ADVERTISED_40000baseCR4_Full;
  375. break;
  376. case I40E_PHY_TYPE_XLAUI:
  377. case I40E_PHY_TYPE_XLPPI:
  378. case I40E_PHY_TYPE_40GBASE_AOC:
  379. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  380. break;
  381. case I40E_PHY_TYPE_40GBASE_SR4:
  382. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  383. break;
  384. case I40E_PHY_TYPE_40GBASE_LR4:
  385. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  386. break;
  387. case I40E_PHY_TYPE_10GBASE_SR:
  388. case I40E_PHY_TYPE_10GBASE_LR:
  389. case I40E_PHY_TYPE_1000BASE_SX:
  390. case I40E_PHY_TYPE_1000BASE_LX:
  391. ecmd->supported = SUPPORTED_10000baseT_Full;
  392. if (hw_link_info->module_type[2] &
  393. I40E_MODULE_TYPE_1000BASE_SX ||
  394. hw_link_info->module_type[2] &
  395. I40E_MODULE_TYPE_1000BASE_LX) {
  396. ecmd->supported |= SUPPORTED_1000baseT_Full;
  397. if (hw_link_info->requested_speeds &
  398. I40E_LINK_SPEED_1GB)
  399. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  400. }
  401. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  402. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  403. break;
  404. case I40E_PHY_TYPE_10GBASE_T:
  405. case I40E_PHY_TYPE_1000BASE_T:
  406. case I40E_PHY_TYPE_100BASE_TX:
  407. ecmd->supported = SUPPORTED_Autoneg |
  408. SUPPORTED_10000baseT_Full |
  409. SUPPORTED_1000baseT_Full |
  410. SUPPORTED_100baseT_Full;
  411. ecmd->advertising = ADVERTISED_Autoneg;
  412. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  413. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  414. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  415. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  416. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  417. ecmd->advertising |= ADVERTISED_100baseT_Full;
  418. break;
  419. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  420. ecmd->supported = SUPPORTED_Autoneg |
  421. SUPPORTED_1000baseT_Full;
  422. ecmd->advertising = ADVERTISED_Autoneg |
  423. ADVERTISED_1000baseT_Full;
  424. break;
  425. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  426. case I40E_PHY_TYPE_10GBASE_CR1:
  427. ecmd->supported = SUPPORTED_Autoneg |
  428. SUPPORTED_10000baseT_Full;
  429. ecmd->advertising = ADVERTISED_Autoneg |
  430. ADVERTISED_10000baseT_Full;
  431. break;
  432. case I40E_PHY_TYPE_XAUI:
  433. case I40E_PHY_TYPE_XFI:
  434. case I40E_PHY_TYPE_SFI:
  435. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  436. case I40E_PHY_TYPE_10GBASE_AOC:
  437. ecmd->supported = SUPPORTED_10000baseT_Full;
  438. ecmd->advertising = SUPPORTED_10000baseT_Full;
  439. break;
  440. case I40E_PHY_TYPE_SGMII:
  441. ecmd->supported = SUPPORTED_Autoneg |
  442. SUPPORTED_1000baseT_Full;
  443. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  444. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  445. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  446. ecmd->supported |= SUPPORTED_100baseT_Full;
  447. if (hw_link_info->requested_speeds &
  448. I40E_LINK_SPEED_100MB)
  449. ecmd->advertising |= ADVERTISED_100baseT_Full;
  450. }
  451. break;
  452. case I40E_PHY_TYPE_40GBASE_KR4:
  453. case I40E_PHY_TYPE_20GBASE_KR2:
  454. case I40E_PHY_TYPE_10GBASE_KR:
  455. case I40E_PHY_TYPE_10GBASE_KX4:
  456. case I40E_PHY_TYPE_1000BASE_KX:
  457. ecmd->supported |= SUPPORTED_40000baseKR4_Full |
  458. SUPPORTED_20000baseKR2_Full |
  459. SUPPORTED_10000baseKR_Full |
  460. SUPPORTED_10000baseKX4_Full |
  461. SUPPORTED_1000baseKX_Full |
  462. SUPPORTED_Autoneg;
  463. ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
  464. ADVERTISED_20000baseKR2_Full |
  465. ADVERTISED_10000baseKR_Full |
  466. ADVERTISED_10000baseKX4_Full |
  467. ADVERTISED_1000baseKX_Full |
  468. ADVERTISED_Autoneg;
  469. break;
  470. default:
  471. /* if we got here and link is up something bad is afoot */
  472. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  473. hw_link_info->phy_type);
  474. }
  475. /* Now that we've worked out everything that could be supported by the
  476. * current PHY type, get what is supported by the NVM and them to
  477. * get what is truly supported
  478. */
  479. i40e_phy_type_to_ethtool(pf, &e_supported,
  480. &e_advertising);
  481. ecmd->supported = ecmd->supported & e_supported;
  482. ecmd->advertising = ecmd->advertising & e_advertising;
  483. /* Set speed and duplex */
  484. switch (link_speed) {
  485. case I40E_LINK_SPEED_40GB:
  486. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  487. break;
  488. case I40E_LINK_SPEED_20GB:
  489. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  490. break;
  491. case I40E_LINK_SPEED_10GB:
  492. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  493. break;
  494. case I40E_LINK_SPEED_1GB:
  495. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  496. break;
  497. case I40E_LINK_SPEED_100MB:
  498. ethtool_cmd_speed_set(ecmd, SPEED_100);
  499. break;
  500. default:
  501. break;
  502. }
  503. ecmd->duplex = DUPLEX_FULL;
  504. }
  505. /**
  506. * i40e_get_settings_link_down - Get the Link settings for when link is down
  507. * @hw: hw structure
  508. * @ecmd: ethtool command to fill in
  509. *
  510. * Reports link settings that can be determined when link is down
  511. **/
  512. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  513. struct ethtool_cmd *ecmd,
  514. struct i40e_pf *pf)
  515. {
  516. /* link is down and the driver needs to fall back on
  517. * supported phy types to figure out what info to display
  518. */
  519. i40e_phy_type_to_ethtool(pf, &ecmd->supported,
  520. &ecmd->advertising);
  521. /* With no link speed and duplex are unknown */
  522. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  523. ecmd->duplex = DUPLEX_UNKNOWN;
  524. }
  525. /**
  526. * i40e_get_settings - Get Link Speed and Duplex settings
  527. * @netdev: network interface device structure
  528. * @ecmd: ethtool command
  529. *
  530. * Reports speed/duplex settings based on media_type
  531. **/
  532. static int i40e_get_settings(struct net_device *netdev,
  533. struct ethtool_cmd *ecmd)
  534. {
  535. struct i40e_netdev_priv *np = netdev_priv(netdev);
  536. struct i40e_pf *pf = np->vsi->back;
  537. struct i40e_hw *hw = &pf->hw;
  538. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  539. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  540. if (link_up)
  541. i40e_get_settings_link_up(hw, ecmd, netdev, pf);
  542. else
  543. i40e_get_settings_link_down(hw, ecmd, pf);
  544. /* Now set the settings that don't rely on link being up/down */
  545. /* Set autoneg settings */
  546. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  547. AUTONEG_ENABLE : AUTONEG_DISABLE);
  548. switch (hw->phy.media_type) {
  549. case I40E_MEDIA_TYPE_BACKPLANE:
  550. ecmd->supported |= SUPPORTED_Autoneg |
  551. SUPPORTED_Backplane;
  552. ecmd->advertising |= ADVERTISED_Autoneg |
  553. ADVERTISED_Backplane;
  554. ecmd->port = PORT_NONE;
  555. break;
  556. case I40E_MEDIA_TYPE_BASET:
  557. ecmd->supported |= SUPPORTED_TP;
  558. ecmd->advertising |= ADVERTISED_TP;
  559. ecmd->port = PORT_TP;
  560. break;
  561. case I40E_MEDIA_TYPE_DA:
  562. case I40E_MEDIA_TYPE_CX4:
  563. ecmd->supported |= SUPPORTED_FIBRE;
  564. ecmd->advertising |= ADVERTISED_FIBRE;
  565. ecmd->port = PORT_DA;
  566. break;
  567. case I40E_MEDIA_TYPE_FIBER:
  568. ecmd->supported |= SUPPORTED_FIBRE;
  569. ecmd->port = PORT_FIBRE;
  570. break;
  571. case I40E_MEDIA_TYPE_UNKNOWN:
  572. default:
  573. ecmd->port = PORT_OTHER;
  574. break;
  575. }
  576. /* Set transceiver */
  577. ecmd->transceiver = XCVR_EXTERNAL;
  578. /* Set flow control settings */
  579. ecmd->supported |= SUPPORTED_Pause;
  580. switch (hw->fc.requested_mode) {
  581. case I40E_FC_FULL:
  582. ecmd->advertising |= ADVERTISED_Pause;
  583. break;
  584. case I40E_FC_TX_PAUSE:
  585. ecmd->advertising |= ADVERTISED_Asym_Pause;
  586. break;
  587. case I40E_FC_RX_PAUSE:
  588. ecmd->advertising |= (ADVERTISED_Pause |
  589. ADVERTISED_Asym_Pause);
  590. break;
  591. default:
  592. ecmd->advertising &= ~(ADVERTISED_Pause |
  593. ADVERTISED_Asym_Pause);
  594. break;
  595. }
  596. return 0;
  597. }
  598. /**
  599. * i40e_set_settings - Set Speed and Duplex
  600. * @netdev: network interface device structure
  601. * @ecmd: ethtool command
  602. *
  603. * Set speed/duplex per media_types advertised/forced
  604. **/
  605. static int i40e_set_settings(struct net_device *netdev,
  606. struct ethtool_cmd *ecmd)
  607. {
  608. struct i40e_netdev_priv *np = netdev_priv(netdev);
  609. struct i40e_aq_get_phy_abilities_resp abilities;
  610. struct i40e_aq_set_phy_config config;
  611. struct i40e_pf *pf = np->vsi->back;
  612. struct i40e_vsi *vsi = np->vsi;
  613. struct i40e_hw *hw = &pf->hw;
  614. struct ethtool_cmd safe_ecmd;
  615. i40e_status status = 0;
  616. bool change = false;
  617. int err = 0;
  618. u8 autoneg;
  619. u32 advertise;
  620. /* Changing port settings is not supported if this isn't the
  621. * port's controlling PF
  622. */
  623. if (hw->partition_id != 1) {
  624. i40e_partition_setting_complaint(pf);
  625. return -EOPNOTSUPP;
  626. }
  627. if (vsi != pf->vsi[pf->lan_vsi])
  628. return -EOPNOTSUPP;
  629. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  630. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  631. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  632. hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
  633. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  634. return -EOPNOTSUPP;
  635. if (hw->device_id == I40E_DEV_ID_KX_B ||
  636. hw->device_id == I40E_DEV_ID_KX_C ||
  637. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  638. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  639. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  640. return -EOPNOTSUPP;
  641. }
  642. /* get our own copy of the bits to check against */
  643. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  644. i40e_get_settings(netdev, &safe_ecmd);
  645. /* save autoneg and speed out of ecmd */
  646. autoneg = ecmd->autoneg;
  647. advertise = ecmd->advertising;
  648. /* set autoneg and speed back to what they currently are */
  649. ecmd->autoneg = safe_ecmd.autoneg;
  650. ecmd->advertising = safe_ecmd.advertising;
  651. ecmd->cmd = safe_ecmd.cmd;
  652. /* If ecmd and safe_ecmd are not the same now, then they are
  653. * trying to set something that we do not support
  654. */
  655. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  656. return -EOPNOTSUPP;
  657. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  658. usleep_range(1000, 2000);
  659. /* Get the current phy config */
  660. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  661. NULL);
  662. if (status)
  663. return -EAGAIN;
  664. /* Copy abilities to config in case autoneg is not
  665. * set below
  666. */
  667. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  668. config.abilities = abilities.abilities;
  669. /* Check autoneg */
  670. if (autoneg == AUTONEG_ENABLE) {
  671. /* If autoneg was not already enabled */
  672. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  673. /* If autoneg is not supported, return error */
  674. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  675. netdev_info(netdev, "Autoneg not supported on this phy\n");
  676. return -EINVAL;
  677. }
  678. /* Autoneg is allowed to change */
  679. config.abilities = abilities.abilities |
  680. I40E_AQ_PHY_ENABLE_AN;
  681. change = true;
  682. }
  683. } else {
  684. /* If autoneg is currently enabled */
  685. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  686. /* If autoneg is supported 10GBASE_T is the only PHY
  687. * that can disable it, so otherwise return error
  688. */
  689. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  690. hw->phy.link_info.phy_type !=
  691. I40E_PHY_TYPE_10GBASE_T) {
  692. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  693. return -EINVAL;
  694. }
  695. /* Autoneg is allowed to change */
  696. config.abilities = abilities.abilities &
  697. ~I40E_AQ_PHY_ENABLE_AN;
  698. change = true;
  699. }
  700. }
  701. if (advertise & ~safe_ecmd.supported)
  702. return -EINVAL;
  703. if (advertise & ADVERTISED_100baseT_Full)
  704. config.link_speed |= I40E_LINK_SPEED_100MB;
  705. if (advertise & ADVERTISED_1000baseT_Full ||
  706. advertise & ADVERTISED_1000baseKX_Full)
  707. config.link_speed |= I40E_LINK_SPEED_1GB;
  708. if (advertise & ADVERTISED_10000baseT_Full ||
  709. advertise & ADVERTISED_10000baseKX4_Full ||
  710. advertise & ADVERTISED_10000baseKR_Full)
  711. config.link_speed |= I40E_LINK_SPEED_10GB;
  712. if (advertise & ADVERTISED_20000baseKR2_Full)
  713. config.link_speed |= I40E_LINK_SPEED_20GB;
  714. if (advertise & ADVERTISED_40000baseKR4_Full ||
  715. advertise & ADVERTISED_40000baseCR4_Full ||
  716. advertise & ADVERTISED_40000baseSR4_Full ||
  717. advertise & ADVERTISED_40000baseLR4_Full)
  718. config.link_speed |= I40E_LINK_SPEED_40GB;
  719. /* If speed didn't get set, set it to what it currently is.
  720. * This is needed because if advertise is 0 (as it is when autoneg
  721. * is disabled) then speed won't get set.
  722. */
  723. if (!config.link_speed)
  724. config.link_speed = abilities.link_speed;
  725. if (change || (abilities.link_speed != config.link_speed)) {
  726. /* copy over the rest of the abilities */
  727. config.phy_type = abilities.phy_type;
  728. config.eee_capability = abilities.eee_capability;
  729. config.eeer = abilities.eeer_val;
  730. config.low_power_ctrl = abilities.d3_lpan;
  731. /* save the requested speeds */
  732. hw->phy.link_info.requested_speeds = config.link_speed;
  733. /* set link and auto negotiation so changes take effect */
  734. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  735. /* If link is up put link down */
  736. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  737. /* Tell the OS link is going down, the link will go
  738. * back up when fw says it is ready asynchronously
  739. */
  740. i40e_print_link_message(vsi, false);
  741. netif_carrier_off(netdev);
  742. netif_tx_stop_all_queues(netdev);
  743. }
  744. /* make the aq call */
  745. status = i40e_aq_set_phy_config(hw, &config, NULL);
  746. if (status) {
  747. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  748. i40e_stat_str(hw, status),
  749. i40e_aq_str(hw, hw->aq.asq_last_status));
  750. return -EAGAIN;
  751. }
  752. status = i40e_update_link_info(hw);
  753. if (status)
  754. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  755. i40e_stat_str(hw, status),
  756. i40e_aq_str(hw, hw->aq.asq_last_status));
  757. } else {
  758. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  759. }
  760. return err;
  761. }
  762. static int i40e_nway_reset(struct net_device *netdev)
  763. {
  764. /* restart autonegotiation */
  765. struct i40e_netdev_priv *np = netdev_priv(netdev);
  766. struct i40e_pf *pf = np->vsi->back;
  767. struct i40e_hw *hw = &pf->hw;
  768. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  769. i40e_status ret = 0;
  770. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  771. if (ret) {
  772. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  773. i40e_stat_str(hw, ret),
  774. i40e_aq_str(hw, hw->aq.asq_last_status));
  775. return -EIO;
  776. }
  777. return 0;
  778. }
  779. /**
  780. * i40e_get_pauseparam - Get Flow Control status
  781. * Return tx/rx-pause status
  782. **/
  783. static void i40e_get_pauseparam(struct net_device *netdev,
  784. struct ethtool_pauseparam *pause)
  785. {
  786. struct i40e_netdev_priv *np = netdev_priv(netdev);
  787. struct i40e_pf *pf = np->vsi->back;
  788. struct i40e_hw *hw = &pf->hw;
  789. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  790. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  791. pause->autoneg =
  792. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  793. AUTONEG_ENABLE : AUTONEG_DISABLE);
  794. /* PFC enabled so report LFC as off */
  795. if (dcbx_cfg->pfc.pfcenable) {
  796. pause->rx_pause = 0;
  797. pause->tx_pause = 0;
  798. return;
  799. }
  800. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  801. pause->rx_pause = 1;
  802. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  803. pause->tx_pause = 1;
  804. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  805. pause->rx_pause = 1;
  806. pause->tx_pause = 1;
  807. }
  808. }
  809. /**
  810. * i40e_set_pauseparam - Set Flow Control parameter
  811. * @netdev: network interface device structure
  812. * @pause: return tx/rx flow control status
  813. **/
  814. static int i40e_set_pauseparam(struct net_device *netdev,
  815. struct ethtool_pauseparam *pause)
  816. {
  817. struct i40e_netdev_priv *np = netdev_priv(netdev);
  818. struct i40e_pf *pf = np->vsi->back;
  819. struct i40e_vsi *vsi = np->vsi;
  820. struct i40e_hw *hw = &pf->hw;
  821. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  822. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  823. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  824. i40e_status status;
  825. u8 aq_failures;
  826. int err = 0;
  827. /* Changing the port's flow control is not supported if this isn't the
  828. * port's controlling PF
  829. */
  830. if (hw->partition_id != 1) {
  831. i40e_partition_setting_complaint(pf);
  832. return -EOPNOTSUPP;
  833. }
  834. if (vsi != pf->vsi[pf->lan_vsi])
  835. return -EOPNOTSUPP;
  836. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  837. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  838. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  839. return -EOPNOTSUPP;
  840. }
  841. /* If we have link and don't have autoneg */
  842. if (!test_bit(__I40E_DOWN, &pf->state) &&
  843. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  844. /* Send message that it might not necessarily work*/
  845. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  846. }
  847. if (dcbx_cfg->pfc.pfcenable) {
  848. netdev_info(netdev,
  849. "Priority flow control enabled. Cannot set link flow control.\n");
  850. return -EOPNOTSUPP;
  851. }
  852. if (pause->rx_pause && pause->tx_pause)
  853. hw->fc.requested_mode = I40E_FC_FULL;
  854. else if (pause->rx_pause && !pause->tx_pause)
  855. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  856. else if (!pause->rx_pause && pause->tx_pause)
  857. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  858. else if (!pause->rx_pause && !pause->tx_pause)
  859. hw->fc.requested_mode = I40E_FC_NONE;
  860. else
  861. return -EINVAL;
  862. /* Tell the OS link is going down, the link will go back up when fw
  863. * says it is ready asynchronously
  864. */
  865. i40e_print_link_message(vsi, false);
  866. netif_carrier_off(netdev);
  867. netif_tx_stop_all_queues(netdev);
  868. /* Set the fc mode and only restart an if link is up*/
  869. status = i40e_set_fc(hw, &aq_failures, link_up);
  870. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  871. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  872. i40e_stat_str(hw, status),
  873. i40e_aq_str(hw, hw->aq.asq_last_status));
  874. err = -EAGAIN;
  875. }
  876. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  877. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  878. i40e_stat_str(hw, status),
  879. i40e_aq_str(hw, hw->aq.asq_last_status));
  880. err = -EAGAIN;
  881. }
  882. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  883. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  884. i40e_stat_str(hw, status),
  885. i40e_aq_str(hw, hw->aq.asq_last_status));
  886. err = -EAGAIN;
  887. }
  888. if (!test_bit(__I40E_DOWN, &pf->state)) {
  889. /* Give it a little more time to try to come back */
  890. msleep(75);
  891. if (!test_bit(__I40E_DOWN, &pf->state))
  892. return i40e_nway_reset(netdev);
  893. }
  894. return err;
  895. }
  896. static u32 i40e_get_msglevel(struct net_device *netdev)
  897. {
  898. struct i40e_netdev_priv *np = netdev_priv(netdev);
  899. struct i40e_pf *pf = np->vsi->back;
  900. u32 debug_mask = pf->hw.debug_mask;
  901. if (debug_mask)
  902. netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
  903. return pf->msg_enable;
  904. }
  905. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  906. {
  907. struct i40e_netdev_priv *np = netdev_priv(netdev);
  908. struct i40e_pf *pf = np->vsi->back;
  909. if (I40E_DEBUG_USER & data)
  910. pf->hw.debug_mask = data;
  911. else
  912. pf->msg_enable = data;
  913. }
  914. static int i40e_get_regs_len(struct net_device *netdev)
  915. {
  916. int reg_count = 0;
  917. int i;
  918. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  919. reg_count += i40e_reg_list[i].elements;
  920. return reg_count * sizeof(u32);
  921. }
  922. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  923. void *p)
  924. {
  925. struct i40e_netdev_priv *np = netdev_priv(netdev);
  926. struct i40e_pf *pf = np->vsi->back;
  927. struct i40e_hw *hw = &pf->hw;
  928. u32 *reg_buf = p;
  929. int i, j, ri;
  930. u32 reg;
  931. /* Tell ethtool which driver-version-specific regs output we have.
  932. *
  933. * At some point, if we have ethtool doing special formatting of
  934. * this data, it will rely on this version number to know how to
  935. * interpret things. Hence, this needs to be updated if/when the
  936. * diags register table is changed.
  937. */
  938. regs->version = 1;
  939. /* loop through the diags reg table for what to print */
  940. ri = 0;
  941. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  942. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  943. reg = i40e_reg_list[i].offset
  944. + (j * i40e_reg_list[i].stride);
  945. reg_buf[ri++] = rd32(hw, reg);
  946. }
  947. }
  948. }
  949. static int i40e_get_eeprom(struct net_device *netdev,
  950. struct ethtool_eeprom *eeprom, u8 *bytes)
  951. {
  952. struct i40e_netdev_priv *np = netdev_priv(netdev);
  953. struct i40e_hw *hw = &np->vsi->back->hw;
  954. struct i40e_pf *pf = np->vsi->back;
  955. int ret_val = 0, len, offset;
  956. u8 *eeprom_buff;
  957. u16 i, sectors;
  958. bool last;
  959. u32 magic;
  960. #define I40E_NVM_SECTOR_SIZE 4096
  961. if (eeprom->len == 0)
  962. return -EINVAL;
  963. /* check for NVMUpdate access method */
  964. magic = hw->vendor_id | (hw->device_id << 16);
  965. if (eeprom->magic && eeprom->magic != magic) {
  966. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  967. int errno = 0;
  968. /* make sure it is the right magic for NVMUpdate */
  969. if ((eeprom->magic >> 16) != hw->device_id)
  970. errno = -EINVAL;
  971. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  972. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  973. errno = -EBUSY;
  974. else
  975. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  976. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  977. dev_info(&pf->pdev->dev,
  978. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  979. ret_val, hw->aq.asq_last_status, errno,
  980. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  981. cmd->offset, cmd->data_size);
  982. return errno;
  983. }
  984. /* normal ethtool get_eeprom support */
  985. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  986. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  987. if (!eeprom_buff)
  988. return -ENOMEM;
  989. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  990. if (ret_val) {
  991. dev_info(&pf->pdev->dev,
  992. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  993. ret_val, hw->aq.asq_last_status);
  994. goto free_buff;
  995. }
  996. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  997. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  998. len = I40E_NVM_SECTOR_SIZE;
  999. last = false;
  1000. for (i = 0; i < sectors; i++) {
  1001. if (i == (sectors - 1)) {
  1002. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  1003. last = true;
  1004. }
  1005. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  1006. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  1007. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  1008. last, NULL);
  1009. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  1010. dev_info(&pf->pdev->dev,
  1011. "read NVM failed, invalid offset 0x%x\n",
  1012. offset);
  1013. break;
  1014. } else if (ret_val &&
  1015. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  1016. dev_info(&pf->pdev->dev,
  1017. "read NVM failed, access, offset 0x%x\n",
  1018. offset);
  1019. break;
  1020. } else if (ret_val) {
  1021. dev_info(&pf->pdev->dev,
  1022. "read NVM failed offset %d err=%d status=0x%x\n",
  1023. offset, ret_val, hw->aq.asq_last_status);
  1024. break;
  1025. }
  1026. }
  1027. i40e_release_nvm(hw);
  1028. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  1029. free_buff:
  1030. kfree(eeprom_buff);
  1031. return ret_val;
  1032. }
  1033. static int i40e_get_eeprom_len(struct net_device *netdev)
  1034. {
  1035. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1036. struct i40e_hw *hw = &np->vsi->back->hw;
  1037. u32 val;
  1038. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1039. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1040. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1041. /* register returns value in power of 2, 64Kbyte chunks. */
  1042. val = (64 * 1024) * BIT(val);
  1043. return val;
  1044. }
  1045. static int i40e_set_eeprom(struct net_device *netdev,
  1046. struct ethtool_eeprom *eeprom, u8 *bytes)
  1047. {
  1048. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1049. struct i40e_hw *hw = &np->vsi->back->hw;
  1050. struct i40e_pf *pf = np->vsi->back;
  1051. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1052. int ret_val = 0;
  1053. int errno = 0;
  1054. u32 magic;
  1055. /* normal ethtool set_eeprom is not supported */
  1056. magic = hw->vendor_id | (hw->device_id << 16);
  1057. if (eeprom->magic == magic)
  1058. errno = -EOPNOTSUPP;
  1059. /* check for NVMUpdate access method */
  1060. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1061. errno = -EINVAL;
  1062. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1063. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1064. errno = -EBUSY;
  1065. else
  1066. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1067. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1068. dev_info(&pf->pdev->dev,
  1069. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1070. ret_val, hw->aq.asq_last_status, errno,
  1071. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1072. cmd->offset, cmd->data_size);
  1073. return errno;
  1074. }
  1075. static void i40e_get_drvinfo(struct net_device *netdev,
  1076. struct ethtool_drvinfo *drvinfo)
  1077. {
  1078. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1079. struct i40e_vsi *vsi = np->vsi;
  1080. struct i40e_pf *pf = vsi->back;
  1081. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1082. strlcpy(drvinfo->version, i40e_driver_version_str,
  1083. sizeof(drvinfo->version));
  1084. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1085. sizeof(drvinfo->fw_version));
  1086. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1087. sizeof(drvinfo->bus_info));
  1088. if (pf->hw.pf_id == 0)
  1089. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
  1090. else
  1091. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  1092. }
  1093. static void i40e_get_ringparam(struct net_device *netdev,
  1094. struct ethtool_ringparam *ring)
  1095. {
  1096. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1097. struct i40e_pf *pf = np->vsi->back;
  1098. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1099. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1100. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1101. ring->rx_mini_max_pending = 0;
  1102. ring->rx_jumbo_max_pending = 0;
  1103. ring->rx_pending = vsi->rx_rings[0]->count;
  1104. ring->tx_pending = vsi->tx_rings[0]->count;
  1105. ring->rx_mini_pending = 0;
  1106. ring->rx_jumbo_pending = 0;
  1107. }
  1108. static int i40e_set_ringparam(struct net_device *netdev,
  1109. struct ethtool_ringparam *ring)
  1110. {
  1111. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1112. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1113. struct i40e_vsi *vsi = np->vsi;
  1114. struct i40e_pf *pf = vsi->back;
  1115. u32 new_rx_count, new_tx_count;
  1116. int i, err = 0;
  1117. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1118. return -EINVAL;
  1119. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1120. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1121. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1122. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1123. netdev_info(netdev,
  1124. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1125. ring->tx_pending, ring->rx_pending,
  1126. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1127. return -EINVAL;
  1128. }
  1129. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1130. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1131. /* if nothing to do return success */
  1132. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1133. (new_rx_count == vsi->rx_rings[0]->count))
  1134. return 0;
  1135. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1136. usleep_range(1000, 2000);
  1137. if (!netif_running(vsi->netdev)) {
  1138. /* simple case - set for the next time the netdev is started */
  1139. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1140. vsi->tx_rings[i]->count = new_tx_count;
  1141. vsi->rx_rings[i]->count = new_rx_count;
  1142. }
  1143. goto done;
  1144. }
  1145. /* We can't just free everything and then setup again,
  1146. * because the ISRs in MSI-X mode get passed pointers
  1147. * to the Tx and Rx ring structs.
  1148. */
  1149. /* alloc updated Tx resources */
  1150. if (new_tx_count != vsi->tx_rings[0]->count) {
  1151. netdev_info(netdev,
  1152. "Changing Tx descriptor count from %d to %d.\n",
  1153. vsi->tx_rings[0]->count, new_tx_count);
  1154. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1155. sizeof(struct i40e_ring), GFP_KERNEL);
  1156. if (!tx_rings) {
  1157. err = -ENOMEM;
  1158. goto done;
  1159. }
  1160. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1161. /* clone ring and setup updated count */
  1162. tx_rings[i] = *vsi->tx_rings[i];
  1163. tx_rings[i].count = new_tx_count;
  1164. /* the desc and bi pointers will be reallocated in the
  1165. * setup call
  1166. */
  1167. tx_rings[i].desc = NULL;
  1168. tx_rings[i].rx_bi = NULL;
  1169. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1170. if (err) {
  1171. while (i) {
  1172. i--;
  1173. i40e_free_tx_resources(&tx_rings[i]);
  1174. }
  1175. kfree(tx_rings);
  1176. tx_rings = NULL;
  1177. goto done;
  1178. }
  1179. }
  1180. }
  1181. /* alloc updated Rx resources */
  1182. if (new_rx_count != vsi->rx_rings[0]->count) {
  1183. netdev_info(netdev,
  1184. "Changing Rx descriptor count from %d to %d\n",
  1185. vsi->rx_rings[0]->count, new_rx_count);
  1186. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1187. sizeof(struct i40e_ring), GFP_KERNEL);
  1188. if (!rx_rings) {
  1189. err = -ENOMEM;
  1190. goto free_tx;
  1191. }
  1192. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1193. /* this is to allow wr32 to have something to write to
  1194. * during early allocation of Rx buffers
  1195. */
  1196. u32 __iomem faketail = 0;
  1197. struct i40e_ring *ring;
  1198. u16 unused;
  1199. /* clone ring and setup updated count */
  1200. rx_rings[i] = *vsi->rx_rings[i];
  1201. rx_rings[i].count = new_rx_count;
  1202. /* the desc and bi pointers will be reallocated in the
  1203. * setup call
  1204. */
  1205. rx_rings[i].desc = NULL;
  1206. rx_rings[i].rx_bi = NULL;
  1207. rx_rings[i].tail = (u8 __iomem *)&faketail;
  1208. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1209. if (err)
  1210. goto rx_unwind;
  1211. /* now allocate the Rx buffers to make sure the OS
  1212. * has enough memory, any failure here means abort
  1213. */
  1214. ring = &rx_rings[i];
  1215. unused = I40E_DESC_UNUSED(ring);
  1216. err = i40e_alloc_rx_buffers(ring, unused);
  1217. rx_unwind:
  1218. if (err) {
  1219. do {
  1220. i40e_free_rx_resources(&rx_rings[i]);
  1221. } while (i--);
  1222. kfree(rx_rings);
  1223. rx_rings = NULL;
  1224. goto free_tx;
  1225. }
  1226. }
  1227. }
  1228. /* Bring interface down, copy in the new ring info,
  1229. * then restore the interface
  1230. */
  1231. i40e_down(vsi);
  1232. if (tx_rings) {
  1233. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1234. i40e_free_tx_resources(vsi->tx_rings[i]);
  1235. *vsi->tx_rings[i] = tx_rings[i];
  1236. }
  1237. kfree(tx_rings);
  1238. tx_rings = NULL;
  1239. }
  1240. if (rx_rings) {
  1241. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1242. i40e_free_rx_resources(vsi->rx_rings[i]);
  1243. /* get the real tail offset */
  1244. rx_rings[i].tail = vsi->rx_rings[i]->tail;
  1245. /* this is to fake out the allocation routine
  1246. * into thinking it has to realloc everything
  1247. * but the recycling logic will let us re-use
  1248. * the buffers allocated above
  1249. */
  1250. rx_rings[i].next_to_use = 0;
  1251. rx_rings[i].next_to_clean = 0;
  1252. rx_rings[i].next_to_alloc = 0;
  1253. /* do a struct copy */
  1254. *vsi->rx_rings[i] = rx_rings[i];
  1255. }
  1256. kfree(rx_rings);
  1257. rx_rings = NULL;
  1258. }
  1259. i40e_up(vsi);
  1260. free_tx:
  1261. /* error cleanup if the Rx allocations failed after getting Tx */
  1262. if (tx_rings) {
  1263. for (i = 0; i < vsi->num_queue_pairs; i++)
  1264. i40e_free_tx_resources(&tx_rings[i]);
  1265. kfree(tx_rings);
  1266. tx_rings = NULL;
  1267. }
  1268. done:
  1269. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1270. return err;
  1271. }
  1272. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1273. {
  1274. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1275. struct i40e_vsi *vsi = np->vsi;
  1276. struct i40e_pf *pf = vsi->back;
  1277. switch (sset) {
  1278. case ETH_SS_TEST:
  1279. return I40E_TEST_LEN;
  1280. case ETH_SS_STATS:
  1281. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1282. int len = I40E_PF_STATS_LEN(netdev);
  1283. if ((pf->lan_veb != I40E_NO_VEB) &&
  1284. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1285. len += I40E_VEB_STATS_TOTAL;
  1286. return len;
  1287. } else {
  1288. return I40E_VSI_STATS_LEN(netdev);
  1289. }
  1290. case ETH_SS_PRIV_FLAGS:
  1291. if (pf->hw.pf_id == 0)
  1292. return I40E_PRIV_FLAGS_GL_STR_LEN;
  1293. else
  1294. return I40E_PRIV_FLAGS_STR_LEN;
  1295. default:
  1296. return -EOPNOTSUPP;
  1297. }
  1298. }
  1299. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1300. struct ethtool_stats *stats, u64 *data)
  1301. {
  1302. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1303. struct i40e_ring *tx_ring, *rx_ring;
  1304. struct i40e_vsi *vsi = np->vsi;
  1305. struct i40e_pf *pf = vsi->back;
  1306. int i = 0;
  1307. char *p;
  1308. int j;
  1309. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1310. unsigned int start;
  1311. i40e_update_stats(vsi);
  1312. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1313. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1314. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1315. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1316. }
  1317. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1318. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1319. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1320. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1321. }
  1322. #ifdef I40E_FCOE
  1323. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1324. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1325. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1326. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1327. }
  1328. #endif
  1329. rcu_read_lock();
  1330. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1331. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1332. if (!tx_ring)
  1333. continue;
  1334. /* process Tx ring statistics */
  1335. do {
  1336. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1337. data[i] = tx_ring->stats.packets;
  1338. data[i + 1] = tx_ring->stats.bytes;
  1339. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1340. i += 2;
  1341. /* Rx ring is the 2nd half of the queue pair */
  1342. rx_ring = &tx_ring[1];
  1343. do {
  1344. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1345. data[i] = rx_ring->stats.packets;
  1346. data[i + 1] = rx_ring->stats.bytes;
  1347. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1348. i += 2;
  1349. }
  1350. rcu_read_unlock();
  1351. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1352. return;
  1353. if ((pf->lan_veb != I40E_NO_VEB) &&
  1354. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1355. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1356. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1357. p = (char *)veb;
  1358. p += i40e_gstrings_veb_stats[j].stat_offset;
  1359. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1360. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1361. }
  1362. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1363. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1364. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1365. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1366. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1367. }
  1368. }
  1369. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1370. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1371. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1372. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1373. }
  1374. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1375. data[i++] = pf->stats.priority_xon_tx[j];
  1376. data[i++] = pf->stats.priority_xoff_tx[j];
  1377. }
  1378. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1379. data[i++] = pf->stats.priority_xon_rx[j];
  1380. data[i++] = pf->stats.priority_xoff_rx[j];
  1381. }
  1382. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1383. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1384. }
  1385. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1386. u8 *data)
  1387. {
  1388. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1389. struct i40e_vsi *vsi = np->vsi;
  1390. struct i40e_pf *pf = vsi->back;
  1391. char *p = (char *)data;
  1392. int i;
  1393. switch (stringset) {
  1394. case ETH_SS_TEST:
  1395. for (i = 0; i < I40E_TEST_LEN; i++) {
  1396. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1397. data += ETH_GSTRING_LEN;
  1398. }
  1399. break;
  1400. case ETH_SS_STATS:
  1401. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1402. snprintf(p, ETH_GSTRING_LEN, "%s",
  1403. i40e_gstrings_net_stats[i].stat_string);
  1404. p += ETH_GSTRING_LEN;
  1405. }
  1406. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1407. snprintf(p, ETH_GSTRING_LEN, "%s",
  1408. i40e_gstrings_misc_stats[i].stat_string);
  1409. p += ETH_GSTRING_LEN;
  1410. }
  1411. #ifdef I40E_FCOE
  1412. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1413. snprintf(p, ETH_GSTRING_LEN, "%s",
  1414. i40e_gstrings_fcoe_stats[i].stat_string);
  1415. p += ETH_GSTRING_LEN;
  1416. }
  1417. #endif
  1418. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1419. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
  1420. p += ETH_GSTRING_LEN;
  1421. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
  1422. p += ETH_GSTRING_LEN;
  1423. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
  1424. p += ETH_GSTRING_LEN;
  1425. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
  1426. p += ETH_GSTRING_LEN;
  1427. }
  1428. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1429. return;
  1430. if ((pf->lan_veb != I40E_NO_VEB) &&
  1431. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1432. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1433. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1434. i40e_gstrings_veb_stats[i].stat_string);
  1435. p += ETH_GSTRING_LEN;
  1436. }
  1437. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1438. snprintf(p, ETH_GSTRING_LEN,
  1439. "veb.tc_%d_tx_packets", i);
  1440. p += ETH_GSTRING_LEN;
  1441. snprintf(p, ETH_GSTRING_LEN,
  1442. "veb.tc_%d_tx_bytes", i);
  1443. p += ETH_GSTRING_LEN;
  1444. snprintf(p, ETH_GSTRING_LEN,
  1445. "veb.tc_%d_rx_packets", i);
  1446. p += ETH_GSTRING_LEN;
  1447. snprintf(p, ETH_GSTRING_LEN,
  1448. "veb.tc_%d_rx_bytes", i);
  1449. p += ETH_GSTRING_LEN;
  1450. }
  1451. }
  1452. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1453. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1454. i40e_gstrings_stats[i].stat_string);
  1455. p += ETH_GSTRING_LEN;
  1456. }
  1457. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1458. snprintf(p, ETH_GSTRING_LEN,
  1459. "port.tx_priority_%d_xon", i);
  1460. p += ETH_GSTRING_LEN;
  1461. snprintf(p, ETH_GSTRING_LEN,
  1462. "port.tx_priority_%d_xoff", i);
  1463. p += ETH_GSTRING_LEN;
  1464. }
  1465. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1466. snprintf(p, ETH_GSTRING_LEN,
  1467. "port.rx_priority_%d_xon", i);
  1468. p += ETH_GSTRING_LEN;
  1469. snprintf(p, ETH_GSTRING_LEN,
  1470. "port.rx_priority_%d_xoff", i);
  1471. p += ETH_GSTRING_LEN;
  1472. }
  1473. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1474. snprintf(p, ETH_GSTRING_LEN,
  1475. "port.rx_priority_%d_xon_2_xoff", i);
  1476. p += ETH_GSTRING_LEN;
  1477. }
  1478. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1479. break;
  1480. case ETH_SS_PRIV_FLAGS:
  1481. if (pf->hw.pf_id == 0) {
  1482. for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
  1483. memcpy(data, i40e_priv_flags_strings_gl[i],
  1484. ETH_GSTRING_LEN);
  1485. data += ETH_GSTRING_LEN;
  1486. }
  1487. } else {
  1488. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1489. memcpy(data, i40e_priv_flags_strings[i],
  1490. ETH_GSTRING_LEN);
  1491. data += ETH_GSTRING_LEN;
  1492. }
  1493. }
  1494. break;
  1495. default:
  1496. break;
  1497. }
  1498. }
  1499. static int i40e_get_ts_info(struct net_device *dev,
  1500. struct ethtool_ts_info *info)
  1501. {
  1502. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1503. /* only report HW timestamping if PTP is enabled */
  1504. if (!(pf->flags & I40E_FLAG_PTP))
  1505. return ethtool_op_get_ts_info(dev, info);
  1506. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1507. SOF_TIMESTAMPING_RX_SOFTWARE |
  1508. SOF_TIMESTAMPING_SOFTWARE |
  1509. SOF_TIMESTAMPING_TX_HARDWARE |
  1510. SOF_TIMESTAMPING_RX_HARDWARE |
  1511. SOF_TIMESTAMPING_RAW_HARDWARE;
  1512. if (pf->ptp_clock)
  1513. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1514. else
  1515. info->phc_index = -1;
  1516. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1517. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1518. BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  1519. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
  1520. return 0;
  1521. }
  1522. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1523. {
  1524. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1525. struct i40e_pf *pf = np->vsi->back;
  1526. i40e_status status;
  1527. bool link_up = false;
  1528. netif_info(pf, hw, netdev, "link test\n");
  1529. status = i40e_get_link_status(&pf->hw, &link_up);
  1530. if (status) {
  1531. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1532. *data = 1;
  1533. return *data;
  1534. }
  1535. if (link_up)
  1536. *data = 0;
  1537. else
  1538. *data = 1;
  1539. return *data;
  1540. }
  1541. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1542. {
  1543. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1544. struct i40e_pf *pf = np->vsi->back;
  1545. netif_info(pf, hw, netdev, "register test\n");
  1546. *data = i40e_diag_reg_test(&pf->hw);
  1547. return *data;
  1548. }
  1549. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1550. {
  1551. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1552. struct i40e_pf *pf = np->vsi->back;
  1553. netif_info(pf, hw, netdev, "eeprom test\n");
  1554. *data = i40e_diag_eeprom_test(&pf->hw);
  1555. /* forcebly clear the NVM Update state machine */
  1556. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1557. return *data;
  1558. }
  1559. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1560. {
  1561. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1562. struct i40e_pf *pf = np->vsi->back;
  1563. u16 swc_old = pf->sw_int_count;
  1564. netif_info(pf, hw, netdev, "interrupt test\n");
  1565. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1566. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1567. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1568. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1569. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1570. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1571. usleep_range(1000, 2000);
  1572. *data = (swc_old == pf->sw_int_count);
  1573. return *data;
  1574. }
  1575. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1576. {
  1577. struct i40e_vf *vfs = pf->vf;
  1578. int i;
  1579. for (i = 0; i < pf->num_alloc_vfs; i++)
  1580. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1581. return true;
  1582. return false;
  1583. }
  1584. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1585. {
  1586. return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
  1587. }
  1588. static void i40e_diag_test(struct net_device *netdev,
  1589. struct ethtool_test *eth_test, u64 *data)
  1590. {
  1591. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1592. bool if_running = netif_running(netdev);
  1593. struct i40e_pf *pf = np->vsi->back;
  1594. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1595. /* Offline tests */
  1596. netif_info(pf, drv, netdev, "offline testing starting\n");
  1597. set_bit(__I40E_TESTING, &pf->state);
  1598. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1599. dev_warn(&pf->pdev->dev,
  1600. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1601. data[I40E_ETH_TEST_REG] = 1;
  1602. data[I40E_ETH_TEST_EEPROM] = 1;
  1603. data[I40E_ETH_TEST_INTR] = 1;
  1604. data[I40E_ETH_TEST_LINK] = 1;
  1605. eth_test->flags |= ETH_TEST_FL_FAILED;
  1606. clear_bit(__I40E_TESTING, &pf->state);
  1607. goto skip_ol_tests;
  1608. }
  1609. /* If the device is online then take it offline */
  1610. if (if_running)
  1611. /* indicate we're in test mode */
  1612. i40e_close(netdev);
  1613. else
  1614. /* This reset does not affect link - if it is
  1615. * changed to a type of reset that does affect
  1616. * link then the following link test would have
  1617. * to be moved to before the reset
  1618. */
  1619. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1620. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1621. eth_test->flags |= ETH_TEST_FL_FAILED;
  1622. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1623. eth_test->flags |= ETH_TEST_FL_FAILED;
  1624. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1625. eth_test->flags |= ETH_TEST_FL_FAILED;
  1626. /* run reg test last, a reset is required after it */
  1627. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1628. eth_test->flags |= ETH_TEST_FL_FAILED;
  1629. clear_bit(__I40E_TESTING, &pf->state);
  1630. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1631. if (if_running)
  1632. i40e_open(netdev);
  1633. } else {
  1634. /* Online tests */
  1635. netif_info(pf, drv, netdev, "online testing starting\n");
  1636. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1637. eth_test->flags |= ETH_TEST_FL_FAILED;
  1638. /* Offline only tests, not run in online; pass by default */
  1639. data[I40E_ETH_TEST_REG] = 0;
  1640. data[I40E_ETH_TEST_EEPROM] = 0;
  1641. data[I40E_ETH_TEST_INTR] = 0;
  1642. }
  1643. skip_ol_tests:
  1644. netif_info(pf, drv, netdev, "testing finished\n");
  1645. }
  1646. static void i40e_get_wol(struct net_device *netdev,
  1647. struct ethtool_wolinfo *wol)
  1648. {
  1649. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1650. struct i40e_pf *pf = np->vsi->back;
  1651. struct i40e_hw *hw = &pf->hw;
  1652. u16 wol_nvm_bits;
  1653. /* NVM bit on means WoL disabled for the port */
  1654. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1655. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1656. wol->supported = 0;
  1657. wol->wolopts = 0;
  1658. } else {
  1659. wol->supported = WAKE_MAGIC;
  1660. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1661. }
  1662. }
  1663. /**
  1664. * i40e_set_wol - set the WakeOnLAN configuration
  1665. * @netdev: the netdev in question
  1666. * @wol: the ethtool WoL setting data
  1667. **/
  1668. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1669. {
  1670. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1671. struct i40e_pf *pf = np->vsi->back;
  1672. struct i40e_vsi *vsi = np->vsi;
  1673. struct i40e_hw *hw = &pf->hw;
  1674. u16 wol_nvm_bits;
  1675. /* WoL not supported if this isn't the controlling PF on the port */
  1676. if (hw->partition_id != 1) {
  1677. i40e_partition_setting_complaint(pf);
  1678. return -EOPNOTSUPP;
  1679. }
  1680. if (vsi != pf->vsi[pf->lan_vsi])
  1681. return -EOPNOTSUPP;
  1682. /* NVM bit on means WoL disabled for the port */
  1683. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1684. if (BIT(hw->port) & wol_nvm_bits)
  1685. return -EOPNOTSUPP;
  1686. /* only magic packet is supported */
  1687. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1688. return -EOPNOTSUPP;
  1689. /* is this a new value? */
  1690. if (pf->wol_en != !!wol->wolopts) {
  1691. pf->wol_en = !!wol->wolopts;
  1692. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1693. }
  1694. return 0;
  1695. }
  1696. static int i40e_set_phys_id(struct net_device *netdev,
  1697. enum ethtool_phys_id_state state)
  1698. {
  1699. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1700. i40e_status ret = 0;
  1701. struct i40e_pf *pf = np->vsi->back;
  1702. struct i40e_hw *hw = &pf->hw;
  1703. int blink_freq = 2;
  1704. u16 temp_status;
  1705. switch (state) {
  1706. case ETHTOOL_ID_ACTIVE:
  1707. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1708. pf->led_status = i40e_led_get(hw);
  1709. } else {
  1710. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
  1711. ret = i40e_led_get_phy(hw, &temp_status,
  1712. &pf->phy_led_val);
  1713. pf->led_status = temp_status;
  1714. }
  1715. return blink_freq;
  1716. case ETHTOOL_ID_ON:
  1717. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1718. i40e_led_set(hw, 0xf, false);
  1719. else
  1720. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1721. break;
  1722. case ETHTOOL_ID_OFF:
  1723. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1724. i40e_led_set(hw, 0x0, false);
  1725. else
  1726. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1727. break;
  1728. case ETHTOOL_ID_INACTIVE:
  1729. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1730. i40e_led_set(hw, false, pf->led_status);
  1731. } else {
  1732. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1733. (pf->phy_led_val |
  1734. I40E_PHY_LED_MODE_ORIG));
  1735. i40e_aq_set_phy_debug(hw, 0, NULL);
  1736. }
  1737. break;
  1738. default:
  1739. break;
  1740. }
  1741. if (ret)
  1742. return -ENOENT;
  1743. else
  1744. return 0;
  1745. }
  1746. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1747. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1748. * 125us (8000 interrupts per second) == ITR(62)
  1749. */
  1750. /**
  1751. * __i40e_get_coalesce - get per-queue coalesce settings
  1752. * @netdev: the netdev to check
  1753. * @ec: ethtool coalesce data structure
  1754. * @queue: which queue to pick
  1755. *
  1756. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  1757. * are per queue. If queue is <0 then we default to queue 0 as the
  1758. * representative value.
  1759. **/
  1760. static int __i40e_get_coalesce(struct net_device *netdev,
  1761. struct ethtool_coalesce *ec,
  1762. int queue)
  1763. {
  1764. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1765. struct i40e_ring *rx_ring, *tx_ring;
  1766. struct i40e_vsi *vsi = np->vsi;
  1767. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1768. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1769. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1770. * return queue 0's value to represent.
  1771. */
  1772. if (queue < 0) {
  1773. queue = 0;
  1774. } else if (queue >= vsi->num_queue_pairs) {
  1775. return -EINVAL;
  1776. }
  1777. rx_ring = vsi->rx_rings[queue];
  1778. tx_ring = vsi->tx_rings[queue];
  1779. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  1780. ec->use_adaptive_rx_coalesce = 1;
  1781. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  1782. ec->use_adaptive_tx_coalesce = 1;
  1783. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1784. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1785. /* we use the _usecs_high to store/set the interrupt rate limit
  1786. * that the hardware supports, that almost but not quite
  1787. * fits the original intent of the ethtool variable,
  1788. * the rx_coalesce_usecs_high limits total interrupts
  1789. * per second from both tx/rx sources.
  1790. */
  1791. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1792. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1793. return 0;
  1794. }
  1795. /**
  1796. * i40e_get_coalesce - get a netdev's coalesce settings
  1797. * @netdev: the netdev to check
  1798. * @ec: ethtool coalesce data structure
  1799. *
  1800. * Gets the coalesce settings for a particular netdev. Note that if user has
  1801. * modified per-queue settings, this only guarantees to represent queue 0. See
  1802. * __i40e_get_coalesce for more details.
  1803. **/
  1804. static int i40e_get_coalesce(struct net_device *netdev,
  1805. struct ethtool_coalesce *ec)
  1806. {
  1807. return __i40e_get_coalesce(netdev, ec, -1);
  1808. }
  1809. /**
  1810. * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
  1811. * @netdev: netdev structure
  1812. * @ec: ethtool's coalesce settings
  1813. * @queue: the particular queue to read
  1814. *
  1815. * Will read a specific queue's coalesce settings
  1816. **/
  1817. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1818. struct ethtool_coalesce *ec)
  1819. {
  1820. return __i40e_get_coalesce(netdev, ec, queue);
  1821. }
  1822. /**
  1823. * i40e_set_itr_per_queue - set ITR values for specific queue
  1824. * @vsi: the VSI to set values for
  1825. * @ec: coalesce settings from ethtool
  1826. * @queue: the queue to modify
  1827. *
  1828. * Change the ITR settings for a specific queue.
  1829. **/
  1830. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1831. struct ethtool_coalesce *ec,
  1832. int queue)
  1833. {
  1834. struct i40e_pf *pf = vsi->back;
  1835. struct i40e_hw *hw = &pf->hw;
  1836. struct i40e_q_vector *q_vector;
  1837. u16 vector, intrl;
  1838. intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
  1839. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1840. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1841. if (ec->use_adaptive_rx_coalesce)
  1842. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1843. else
  1844. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1845. if (ec->use_adaptive_tx_coalesce)
  1846. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1847. else
  1848. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1849. q_vector = vsi->rx_rings[queue]->q_vector;
  1850. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1851. vector = vsi->base_vector + q_vector->v_idx;
  1852. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1853. q_vector = vsi->tx_rings[queue]->q_vector;
  1854. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1855. vector = vsi->base_vector + q_vector->v_idx;
  1856. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1857. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1858. i40e_flush(hw);
  1859. }
  1860. /**
  1861. * __i40e_set_coalesce - set coalesce settings for particular queue
  1862. * @netdev: the netdev to change
  1863. * @ec: ethtool coalesce settings
  1864. * @queue: the queue to change
  1865. *
  1866. * Sets the coalesce settings for a particular queue.
  1867. **/
  1868. static int __i40e_set_coalesce(struct net_device *netdev,
  1869. struct ethtool_coalesce *ec,
  1870. int queue)
  1871. {
  1872. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1873. struct i40e_vsi *vsi = np->vsi;
  1874. struct i40e_pf *pf = vsi->back;
  1875. int i;
  1876. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1877. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1878. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1879. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1880. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1881. return -EINVAL;
  1882. }
  1883. if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1884. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
  1885. return -EINVAL;
  1886. }
  1887. if (ec->rx_coalesce_usecs == 0) {
  1888. if (ec->use_adaptive_rx_coalesce)
  1889. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1890. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1891. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1892. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1893. return -EINVAL;
  1894. }
  1895. vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
  1896. if (ec->tx_coalesce_usecs == 0) {
  1897. if (ec->use_adaptive_tx_coalesce)
  1898. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1899. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1900. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1901. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1902. return -EINVAL;
  1903. }
  1904. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1905. * apply to all queues.
  1906. */
  1907. if (queue < 0) {
  1908. for (i = 0; i < vsi->num_queue_pairs; i++)
  1909. i40e_set_itr_per_queue(vsi, ec, i);
  1910. } else if (queue < vsi->num_queue_pairs) {
  1911. i40e_set_itr_per_queue(vsi, ec, queue);
  1912. } else {
  1913. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1914. vsi->num_queue_pairs - 1);
  1915. return -EINVAL;
  1916. }
  1917. return 0;
  1918. }
  1919. /**
  1920. * i40e_set_coalesce - set coalesce settings for every queue on the netdev
  1921. * @netdev: the netdev to change
  1922. * @ec: ethtool coalesce settings
  1923. *
  1924. * This will set each queue to the same coalesce settings.
  1925. **/
  1926. static int i40e_set_coalesce(struct net_device *netdev,
  1927. struct ethtool_coalesce *ec)
  1928. {
  1929. return __i40e_set_coalesce(netdev, ec, -1);
  1930. }
  1931. /**
  1932. * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
  1933. * @netdev: the netdev to change
  1934. * @ec: ethtool's coalesce settings
  1935. * @queue: the queue to change
  1936. *
  1937. * Sets the specified queue's coalesce settings.
  1938. **/
  1939. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1940. struct ethtool_coalesce *ec)
  1941. {
  1942. return __i40e_set_coalesce(netdev, ec, queue);
  1943. }
  1944. /**
  1945. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1946. * @pf: pointer to the physical function struct
  1947. * @cmd: ethtool rxnfc command
  1948. *
  1949. * Returns Success if the flow is supported, else Invalid Input.
  1950. **/
  1951. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1952. {
  1953. struct i40e_hw *hw = &pf->hw;
  1954. u8 flow_pctype = 0;
  1955. u64 i_set = 0;
  1956. cmd->data = 0;
  1957. switch (cmd->flow_type) {
  1958. case TCP_V4_FLOW:
  1959. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  1960. break;
  1961. case UDP_V4_FLOW:
  1962. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  1963. break;
  1964. case TCP_V6_FLOW:
  1965. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  1966. break;
  1967. case UDP_V6_FLOW:
  1968. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  1969. break;
  1970. case SCTP_V4_FLOW:
  1971. case AH_ESP_V4_FLOW:
  1972. case AH_V4_FLOW:
  1973. case ESP_V4_FLOW:
  1974. case IPV4_FLOW:
  1975. case SCTP_V6_FLOW:
  1976. case AH_ESP_V6_FLOW:
  1977. case AH_V6_FLOW:
  1978. case ESP_V6_FLOW:
  1979. case IPV6_FLOW:
  1980. /* Default is src/dest for IP, no matter the L4 hashing */
  1981. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1982. break;
  1983. default:
  1984. return -EINVAL;
  1985. }
  1986. /* Read flow based hash input set register */
  1987. if (flow_pctype) {
  1988. i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  1989. flow_pctype)) |
  1990. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  1991. flow_pctype)) << 32);
  1992. }
  1993. /* Process bits of hash input set */
  1994. if (i_set) {
  1995. if (i_set & I40E_L4_SRC_MASK)
  1996. cmd->data |= RXH_L4_B_0_1;
  1997. if (i_set & I40E_L4_DST_MASK)
  1998. cmd->data |= RXH_L4_B_2_3;
  1999. if (cmd->flow_type == TCP_V4_FLOW ||
  2000. cmd->flow_type == UDP_V4_FLOW) {
  2001. if (i_set & I40E_L3_SRC_MASK)
  2002. cmd->data |= RXH_IP_SRC;
  2003. if (i_set & I40E_L3_DST_MASK)
  2004. cmd->data |= RXH_IP_DST;
  2005. } else if (cmd->flow_type == TCP_V6_FLOW ||
  2006. cmd->flow_type == UDP_V6_FLOW) {
  2007. if (i_set & I40E_L3_V6_SRC_MASK)
  2008. cmd->data |= RXH_IP_SRC;
  2009. if (i_set & I40E_L3_V6_DST_MASK)
  2010. cmd->data |= RXH_IP_DST;
  2011. }
  2012. }
  2013. return 0;
  2014. }
  2015. /**
  2016. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  2017. * @pf: Pointer to the physical function struct
  2018. * @cmd: The command to get or set Rx flow classification rules
  2019. * @rule_locs: Array of used rule locations
  2020. *
  2021. * This function populates both the total and actual rule count of
  2022. * the ethtool flow classification command
  2023. *
  2024. * Returns 0 on success or -EMSGSIZE if entry not found
  2025. **/
  2026. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  2027. struct ethtool_rxnfc *cmd,
  2028. u32 *rule_locs)
  2029. {
  2030. struct i40e_fdir_filter *rule;
  2031. struct hlist_node *node2;
  2032. int cnt = 0;
  2033. /* report total rule count */
  2034. cmd->data = i40e_get_fd_cnt_all(pf);
  2035. hlist_for_each_entry_safe(rule, node2,
  2036. &pf->fdir_filter_list, fdir_node) {
  2037. if (cnt == cmd->rule_cnt)
  2038. return -EMSGSIZE;
  2039. rule_locs[cnt] = rule->fd_id;
  2040. cnt++;
  2041. }
  2042. cmd->rule_cnt = cnt;
  2043. return 0;
  2044. }
  2045. /**
  2046. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  2047. * @pf: Pointer to the physical function struct
  2048. * @cmd: The command to get or set Rx flow classification rules
  2049. *
  2050. * This function looks up a filter based on the Rx flow classification
  2051. * command and fills the flow spec info for it if found
  2052. *
  2053. * Returns 0 on success or -EINVAL if filter not found
  2054. **/
  2055. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  2056. struct ethtool_rxnfc *cmd)
  2057. {
  2058. struct ethtool_rx_flow_spec *fsp =
  2059. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2060. struct i40e_fdir_filter *rule = NULL;
  2061. struct hlist_node *node2;
  2062. hlist_for_each_entry_safe(rule, node2,
  2063. &pf->fdir_filter_list, fdir_node) {
  2064. if (fsp->location <= rule->fd_id)
  2065. break;
  2066. }
  2067. if (!rule || fsp->location != rule->fd_id)
  2068. return -EINVAL;
  2069. fsp->flow_type = rule->flow_type;
  2070. if (fsp->flow_type == IP_USER_FLOW) {
  2071. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  2072. fsp->h_u.usr_ip4_spec.proto = 0;
  2073. fsp->m_u.usr_ip4_spec.proto = 0;
  2074. }
  2075. /* Reverse the src and dest notion, since the HW views them from
  2076. * Tx perspective where as the user expects it from Rx filter view.
  2077. */
  2078. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  2079. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  2080. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  2081. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  2082. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  2083. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  2084. else
  2085. fsp->ring_cookie = rule->q_index;
  2086. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  2087. struct i40e_vsi *vsi;
  2088. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  2089. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  2090. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  2091. fsp->m_ext.data[1] = htonl(0x1);
  2092. }
  2093. }
  2094. return 0;
  2095. }
  2096. /**
  2097. * i40e_get_rxnfc - command to get RX flow classification rules
  2098. * @netdev: network interface device structure
  2099. * @cmd: ethtool rxnfc command
  2100. *
  2101. * Returns Success if the command is supported.
  2102. **/
  2103. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  2104. u32 *rule_locs)
  2105. {
  2106. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2107. struct i40e_vsi *vsi = np->vsi;
  2108. struct i40e_pf *pf = vsi->back;
  2109. int ret = -EOPNOTSUPP;
  2110. switch (cmd->cmd) {
  2111. case ETHTOOL_GRXRINGS:
  2112. cmd->data = vsi->num_queue_pairs;
  2113. ret = 0;
  2114. break;
  2115. case ETHTOOL_GRXFH:
  2116. ret = i40e_get_rss_hash_opts(pf, cmd);
  2117. break;
  2118. case ETHTOOL_GRXCLSRLCNT:
  2119. cmd->rule_cnt = pf->fdir_pf_active_filters;
  2120. /* report total rule count */
  2121. cmd->data = i40e_get_fd_cnt_all(pf);
  2122. ret = 0;
  2123. break;
  2124. case ETHTOOL_GRXCLSRULE:
  2125. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  2126. break;
  2127. case ETHTOOL_GRXCLSRLALL:
  2128. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  2129. break;
  2130. default:
  2131. break;
  2132. }
  2133. return ret;
  2134. }
  2135. /**
  2136. * i40e_get_rss_hash_bits - Read RSS Hash bits from register
  2137. * @nfc: pointer to user request
  2138. * @i_setc bits currently set
  2139. *
  2140. * Returns value of bits to be set per user request
  2141. **/
  2142. static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
  2143. {
  2144. u64 i_set = i_setc;
  2145. u64 src_l3 = 0, dst_l3 = 0;
  2146. if (nfc->data & RXH_L4_B_0_1)
  2147. i_set |= I40E_L4_SRC_MASK;
  2148. else
  2149. i_set &= ~I40E_L4_SRC_MASK;
  2150. if (nfc->data & RXH_L4_B_2_3)
  2151. i_set |= I40E_L4_DST_MASK;
  2152. else
  2153. i_set &= ~I40E_L4_DST_MASK;
  2154. if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
  2155. src_l3 = I40E_L3_V6_SRC_MASK;
  2156. dst_l3 = I40E_L3_V6_DST_MASK;
  2157. } else if (nfc->flow_type == TCP_V4_FLOW ||
  2158. nfc->flow_type == UDP_V4_FLOW) {
  2159. src_l3 = I40E_L3_SRC_MASK;
  2160. dst_l3 = I40E_L3_DST_MASK;
  2161. } else {
  2162. /* Any other flow type are not supported here */
  2163. return i_set;
  2164. }
  2165. if (nfc->data & RXH_IP_SRC)
  2166. i_set |= src_l3;
  2167. else
  2168. i_set &= ~src_l3;
  2169. if (nfc->data & RXH_IP_DST)
  2170. i_set |= dst_l3;
  2171. else
  2172. i_set &= ~dst_l3;
  2173. return i_set;
  2174. }
  2175. /**
  2176. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  2177. * @pf: pointer to the physical function struct
  2178. * @cmd: ethtool rxnfc command
  2179. *
  2180. * Returns Success if the flow input set is supported.
  2181. **/
  2182. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2183. {
  2184. struct i40e_hw *hw = &pf->hw;
  2185. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2186. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2187. u8 flow_pctype = 0;
  2188. u64 i_set, i_setc;
  2189. /* RSS does not support anything other than hashing
  2190. * to queues on src and dst IPs and ports
  2191. */
  2192. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2193. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2194. return -EINVAL;
  2195. switch (nfc->flow_type) {
  2196. case TCP_V4_FLOW:
  2197. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2198. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2199. hena |=
  2200. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2201. break;
  2202. case TCP_V6_FLOW:
  2203. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2204. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2205. hena |=
  2206. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2207. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2208. hena |=
  2209. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2210. break;
  2211. case UDP_V4_FLOW:
  2212. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2213. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2214. hena |=
  2215. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2216. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2217. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2218. break;
  2219. case UDP_V6_FLOW:
  2220. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2221. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2222. hena |=
  2223. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2224. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2225. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2226. break;
  2227. case AH_ESP_V4_FLOW:
  2228. case AH_V4_FLOW:
  2229. case ESP_V4_FLOW:
  2230. case SCTP_V4_FLOW:
  2231. if ((nfc->data & RXH_L4_B_0_1) ||
  2232. (nfc->data & RXH_L4_B_2_3))
  2233. return -EINVAL;
  2234. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2235. break;
  2236. case AH_ESP_V6_FLOW:
  2237. case AH_V6_FLOW:
  2238. case ESP_V6_FLOW:
  2239. case SCTP_V6_FLOW:
  2240. if ((nfc->data & RXH_L4_B_0_1) ||
  2241. (nfc->data & RXH_L4_B_2_3))
  2242. return -EINVAL;
  2243. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2244. break;
  2245. case IPV4_FLOW:
  2246. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2247. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2248. break;
  2249. case IPV6_FLOW:
  2250. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2251. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2252. break;
  2253. default:
  2254. return -EINVAL;
  2255. }
  2256. if (flow_pctype) {
  2257. i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2258. flow_pctype)) |
  2259. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2260. flow_pctype)) << 32);
  2261. i_set = i40e_get_rss_hash_bits(nfc, i_setc);
  2262. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
  2263. (u32)i_set);
  2264. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
  2265. (u32)(i_set >> 32));
  2266. hena |= BIT_ULL(flow_pctype);
  2267. }
  2268. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2269. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2270. i40e_flush(hw);
  2271. return 0;
  2272. }
  2273. /**
  2274. * i40e_match_fdir_input_set - Match a new filter against an existing one
  2275. * @rule: The filter already added
  2276. * @input: The new filter to comapre against
  2277. *
  2278. * Returns true if the two input set match
  2279. **/
  2280. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  2281. struct i40e_fdir_filter *input)
  2282. {
  2283. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  2284. (rule->src_ip[0] != input->src_ip[0]) ||
  2285. (rule->dst_port != input->dst_port) ||
  2286. (rule->src_port != input->src_port))
  2287. return false;
  2288. return true;
  2289. }
  2290. /**
  2291. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2292. * @vsi: Pointer to the targeted VSI
  2293. * @input: The filter to update or NULL to indicate deletion
  2294. * @sw_idx: Software index to the filter
  2295. * @cmd: The command to get or set Rx flow classification rules
  2296. *
  2297. * This function updates (or deletes) a Flow Director entry from
  2298. * the hlist of the corresponding PF
  2299. *
  2300. * Returns 0 on success
  2301. **/
  2302. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2303. struct i40e_fdir_filter *input,
  2304. u16 sw_idx,
  2305. struct ethtool_rxnfc *cmd)
  2306. {
  2307. struct i40e_fdir_filter *rule, *parent;
  2308. struct i40e_pf *pf = vsi->back;
  2309. struct hlist_node *node2;
  2310. int err = -EINVAL;
  2311. parent = NULL;
  2312. rule = NULL;
  2313. hlist_for_each_entry_safe(rule, node2,
  2314. &pf->fdir_filter_list, fdir_node) {
  2315. /* hash found, or no matching entry */
  2316. if (rule->fd_id >= sw_idx)
  2317. break;
  2318. parent = rule;
  2319. }
  2320. /* if there is an old rule occupying our place remove it */
  2321. if (rule && (rule->fd_id == sw_idx)) {
  2322. if (input && !i40e_match_fdir_input_set(rule, input))
  2323. err = i40e_add_del_fdir(vsi, rule, false);
  2324. else if (!input)
  2325. err = i40e_add_del_fdir(vsi, rule, false);
  2326. hlist_del(&rule->fdir_node);
  2327. kfree(rule);
  2328. pf->fdir_pf_active_filters--;
  2329. }
  2330. /* If no input this was a delete, err should be 0 if a rule was
  2331. * successfully found and removed from the list else -EINVAL
  2332. */
  2333. if (!input)
  2334. return err;
  2335. /* initialize node and set software index */
  2336. INIT_HLIST_NODE(&input->fdir_node);
  2337. /* add filter to the list */
  2338. if (parent)
  2339. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2340. else
  2341. hlist_add_head(&input->fdir_node,
  2342. &pf->fdir_filter_list);
  2343. /* update counts */
  2344. pf->fdir_pf_active_filters++;
  2345. return 0;
  2346. }
  2347. /**
  2348. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2349. * @vsi: Pointer to the targeted VSI
  2350. * @cmd: The command to get or set Rx flow classification rules
  2351. *
  2352. * The function removes a Flow Director filter entry from the
  2353. * hlist of the corresponding PF
  2354. *
  2355. * Returns 0 on success
  2356. */
  2357. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2358. struct ethtool_rxnfc *cmd)
  2359. {
  2360. struct ethtool_rx_flow_spec *fsp =
  2361. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2362. struct i40e_pf *pf = vsi->back;
  2363. int ret = 0;
  2364. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2365. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2366. return -EBUSY;
  2367. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2368. return -EBUSY;
  2369. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2370. i40e_fdir_check_and_reenable(pf);
  2371. return ret;
  2372. }
  2373. /**
  2374. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  2375. * @vsi: pointer to the targeted VSI
  2376. * @cmd: command to get or set RX flow classification rules
  2377. *
  2378. * Add Flow Director filters for a specific flow spec based on their
  2379. * protocol. Returns 0 if the filters were successfully added.
  2380. **/
  2381. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  2382. struct ethtool_rxnfc *cmd)
  2383. {
  2384. struct ethtool_rx_flow_spec *fsp;
  2385. struct i40e_fdir_filter *input;
  2386. struct i40e_pf *pf;
  2387. int ret = -EINVAL;
  2388. u16 vf_id;
  2389. if (!vsi)
  2390. return -EINVAL;
  2391. pf = vsi->back;
  2392. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2393. return -EOPNOTSUPP;
  2394. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  2395. return -ENOSPC;
  2396. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2397. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2398. return -EBUSY;
  2399. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2400. return -EBUSY;
  2401. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  2402. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  2403. pf->hw.func_caps.fd_filters_guaranteed)) {
  2404. return -EINVAL;
  2405. }
  2406. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  2407. (fsp->ring_cookie >= vsi->num_queue_pairs))
  2408. return -EINVAL;
  2409. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2410. if (!input)
  2411. return -ENOMEM;
  2412. input->fd_id = fsp->location;
  2413. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  2414. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2415. else
  2416. input->dest_ctl =
  2417. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2418. input->q_index = fsp->ring_cookie;
  2419. input->flex_off = 0;
  2420. input->pctype = 0;
  2421. input->dest_vsi = vsi->id;
  2422. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2423. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  2424. input->flow_type = fsp->flow_type;
  2425. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2426. /* Reverse the src and dest notion, since the HW expects them to be from
  2427. * Tx perspective where as the input from user is from Rx filter view.
  2428. */
  2429. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2430. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2431. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2432. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2433. if (ntohl(fsp->m_ext.data[1])) {
  2434. vf_id = ntohl(fsp->h_ext.data[1]);
  2435. if (vf_id >= pf->num_alloc_vfs) {
  2436. netif_info(pf, drv, vsi->netdev,
  2437. "Invalid VF id %d\n", vf_id);
  2438. goto free_input;
  2439. }
  2440. /* Find vsi id from vf id and override dest vsi */
  2441. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2442. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2443. netif_info(pf, drv, vsi->netdev,
  2444. "Invalid queue id %d for VF %d\n",
  2445. input->q_index, vf_id);
  2446. goto free_input;
  2447. }
  2448. }
  2449. ret = i40e_add_del_fdir(vsi, input, true);
  2450. free_input:
  2451. if (ret)
  2452. kfree(input);
  2453. else
  2454. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2455. return ret;
  2456. }
  2457. /**
  2458. * i40e_set_rxnfc - command to set RX flow classification rules
  2459. * @netdev: network interface device structure
  2460. * @cmd: ethtool rxnfc command
  2461. *
  2462. * Returns Success if the command is supported.
  2463. **/
  2464. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2465. {
  2466. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2467. struct i40e_vsi *vsi = np->vsi;
  2468. struct i40e_pf *pf = vsi->back;
  2469. int ret = -EOPNOTSUPP;
  2470. switch (cmd->cmd) {
  2471. case ETHTOOL_SRXFH:
  2472. ret = i40e_set_rss_hash_opt(pf, cmd);
  2473. break;
  2474. case ETHTOOL_SRXCLSRLINS:
  2475. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2476. break;
  2477. case ETHTOOL_SRXCLSRLDEL:
  2478. ret = i40e_del_fdir_entry(vsi, cmd);
  2479. break;
  2480. default:
  2481. break;
  2482. }
  2483. return ret;
  2484. }
  2485. /**
  2486. * i40e_max_channels - get Max number of combined channels supported
  2487. * @vsi: vsi pointer
  2488. **/
  2489. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2490. {
  2491. /* TODO: This code assumes DCB and FD is disabled for now. */
  2492. return vsi->alloc_queue_pairs;
  2493. }
  2494. /**
  2495. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2496. * @netdev: network interface device structure
  2497. * @ch: ethtool channels structure
  2498. *
  2499. * We don't support separate tx and rx queues as channels. The other count
  2500. * represents how many queues are being used for control. max_combined counts
  2501. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2502. * q_vectors since we support a lot more queue pairs than q_vectors.
  2503. **/
  2504. static void i40e_get_channels(struct net_device *dev,
  2505. struct ethtool_channels *ch)
  2506. {
  2507. struct i40e_netdev_priv *np = netdev_priv(dev);
  2508. struct i40e_vsi *vsi = np->vsi;
  2509. struct i40e_pf *pf = vsi->back;
  2510. /* report maximum channels */
  2511. ch->max_combined = i40e_max_channels(vsi);
  2512. /* report info for other vector */
  2513. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2514. ch->max_other = ch->other_count;
  2515. /* Note: This code assumes DCB is disabled for now. */
  2516. ch->combined_count = vsi->num_queue_pairs;
  2517. }
  2518. /**
  2519. * i40e_set_channels - Set the new channels count.
  2520. * @netdev: network interface device structure
  2521. * @ch: ethtool channels structure
  2522. *
  2523. * The new channels count may not be the same as requested by the user
  2524. * since it gets rounded down to a power of 2 value.
  2525. **/
  2526. static int i40e_set_channels(struct net_device *dev,
  2527. struct ethtool_channels *ch)
  2528. {
  2529. const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2530. struct i40e_netdev_priv *np = netdev_priv(dev);
  2531. unsigned int count = ch->combined_count;
  2532. struct i40e_vsi *vsi = np->vsi;
  2533. struct i40e_pf *pf = vsi->back;
  2534. struct i40e_fdir_filter *rule;
  2535. struct hlist_node *node2;
  2536. int new_count;
  2537. int err = 0;
  2538. /* We do not support setting channels for any other VSI at present */
  2539. if (vsi->type != I40E_VSI_MAIN)
  2540. return -EINVAL;
  2541. /* verify they are not requesting separate vectors */
  2542. if (!count || ch->rx_count || ch->tx_count)
  2543. return -EINVAL;
  2544. /* verify other_count has not changed */
  2545. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2546. return -EINVAL;
  2547. /* verify the number of channels does not exceed hardware limits */
  2548. if (count > i40e_max_channels(vsi))
  2549. return -EINVAL;
  2550. /* verify that the number of channels does not invalidate any current
  2551. * flow director rules
  2552. */
  2553. hlist_for_each_entry_safe(rule, node2,
  2554. &pf->fdir_filter_list, fdir_node) {
  2555. if (rule->dest_ctl != drop && count <= rule->q_index) {
  2556. dev_warn(&pf->pdev->dev,
  2557. "Existing user defined filter %d assigns flow to queue %d\n",
  2558. rule->fd_id, rule->q_index);
  2559. err = -EINVAL;
  2560. }
  2561. }
  2562. if (err) {
  2563. dev_err(&pf->pdev->dev,
  2564. "Existing filter rules must be deleted to reduce combined channel count to %d\n",
  2565. count);
  2566. return err;
  2567. }
  2568. /* update feature limits from largest to smallest supported values */
  2569. /* TODO: Flow director limit, DCB etc */
  2570. /* use rss_reconfig to rebuild with new queue count and update traffic
  2571. * class queue mapping
  2572. */
  2573. new_count = i40e_reconfig_rss_queues(pf, count);
  2574. if (new_count > 0)
  2575. return 0;
  2576. else
  2577. return -EINVAL;
  2578. }
  2579. /**
  2580. * i40e_get_rxfh_key_size - get the RSS hash key size
  2581. * @netdev: network interface device structure
  2582. *
  2583. * Returns the table size.
  2584. **/
  2585. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2586. {
  2587. return I40E_HKEY_ARRAY_SIZE;
  2588. }
  2589. /**
  2590. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2591. * @netdev: network interface device structure
  2592. *
  2593. * Returns the table size.
  2594. **/
  2595. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2596. {
  2597. return I40E_HLUT_ARRAY_SIZE;
  2598. }
  2599. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2600. u8 *hfunc)
  2601. {
  2602. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2603. struct i40e_vsi *vsi = np->vsi;
  2604. u8 *lut, *seed = NULL;
  2605. int ret;
  2606. u16 i;
  2607. if (hfunc)
  2608. *hfunc = ETH_RSS_HASH_TOP;
  2609. if (!indir)
  2610. return 0;
  2611. seed = key;
  2612. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2613. if (!lut)
  2614. return -ENOMEM;
  2615. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  2616. if (ret)
  2617. goto out;
  2618. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2619. indir[i] = (u32)(lut[i]);
  2620. out:
  2621. kfree(lut);
  2622. return ret;
  2623. }
  2624. /**
  2625. * i40e_set_rxfh - set the rx flow hash indirection table
  2626. * @netdev: network interface device structure
  2627. * @indir: indirection table
  2628. * @key: hash key
  2629. *
  2630. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  2631. * returns 0 after programming the table.
  2632. **/
  2633. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2634. const u8 *key, const u8 hfunc)
  2635. {
  2636. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2637. struct i40e_vsi *vsi = np->vsi;
  2638. struct i40e_pf *pf = vsi->back;
  2639. u8 *seed = NULL;
  2640. u16 i;
  2641. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2642. return -EOPNOTSUPP;
  2643. if (key) {
  2644. if (!vsi->rss_hkey_user) {
  2645. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  2646. GFP_KERNEL);
  2647. if (!vsi->rss_hkey_user)
  2648. return -ENOMEM;
  2649. }
  2650. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  2651. seed = vsi->rss_hkey_user;
  2652. }
  2653. if (!vsi->rss_lut_user) {
  2654. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2655. if (!vsi->rss_lut_user)
  2656. return -ENOMEM;
  2657. }
  2658. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  2659. if (indir)
  2660. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2661. vsi->rss_lut_user[i] = (u8)(indir[i]);
  2662. else
  2663. i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
  2664. vsi->rss_size);
  2665. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  2666. I40E_HLUT_ARRAY_SIZE);
  2667. }
  2668. /**
  2669. * i40e_get_priv_flags - report device private flags
  2670. * @dev: network interface device structure
  2671. *
  2672. * The get string set count and the string set should be matched for each
  2673. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2674. * array.
  2675. *
  2676. * Returns a u32 bitmap of flags.
  2677. **/
  2678. static u32 i40e_get_priv_flags(struct net_device *dev)
  2679. {
  2680. struct i40e_netdev_priv *np = netdev_priv(dev);
  2681. struct i40e_vsi *vsi = np->vsi;
  2682. struct i40e_pf *pf = vsi->back;
  2683. u32 ret_flags = 0;
  2684. ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
  2685. I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
  2686. ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
  2687. I40E_PRIV_FLAGS_FD_ATR : 0;
  2688. ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
  2689. I40E_PRIV_FLAGS_VEB_STATS : 0;
  2690. ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
  2691. 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
  2692. if (pf->hw.pf_id == 0) {
  2693. ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
  2694. I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
  2695. }
  2696. return ret_flags;
  2697. }
  2698. /**
  2699. * i40e_set_priv_flags - set private flags
  2700. * @dev: network interface device structure
  2701. * @flags: bit flags to be set
  2702. **/
  2703. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  2704. {
  2705. struct i40e_netdev_priv *np = netdev_priv(dev);
  2706. struct i40e_vsi *vsi = np->vsi;
  2707. struct i40e_pf *pf = vsi->back;
  2708. u16 sw_flags = 0, valid_flags = 0;
  2709. bool reset_required = false;
  2710. bool promisc_change = false;
  2711. int ret;
  2712. /* NOTE: MFP is not settable */
  2713. if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
  2714. pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
  2715. else
  2716. pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
  2717. /* allow the user to control the state of the Flow
  2718. * Director ATR (Application Targeted Routing) feature
  2719. * of the driver
  2720. */
  2721. if (flags & I40E_PRIV_FLAGS_FD_ATR) {
  2722. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  2723. } else {
  2724. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  2725. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  2726. /* flush current ATR settings */
  2727. set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  2728. }
  2729. if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2730. !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2731. pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
  2732. reset_required = true;
  2733. } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2734. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2735. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  2736. reset_required = true;
  2737. }
  2738. if (pf->hw.pf_id == 0) {
  2739. if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2740. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2741. pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2742. promisc_change = true;
  2743. } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2744. (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2745. pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2746. promisc_change = true;
  2747. }
  2748. }
  2749. if (promisc_change) {
  2750. if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  2751. sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2752. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2753. ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
  2754. NULL);
  2755. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  2756. dev_info(&pf->pdev->dev,
  2757. "couldn't set switch config bits, err %s aq_err %s\n",
  2758. i40e_stat_str(&pf->hw, ret),
  2759. i40e_aq_str(&pf->hw,
  2760. pf->hw.aq.asq_last_status));
  2761. /* not a fatal problem, just keep going */
  2762. }
  2763. }
  2764. if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
  2765. (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
  2766. pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2767. else
  2768. pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2769. /* if needed, issue reset to cause things to take effect */
  2770. if (reset_required)
  2771. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  2772. return 0;
  2773. }
  2774. static const struct ethtool_ops i40e_ethtool_ops = {
  2775. .get_settings = i40e_get_settings,
  2776. .set_settings = i40e_set_settings,
  2777. .get_drvinfo = i40e_get_drvinfo,
  2778. .get_regs_len = i40e_get_regs_len,
  2779. .get_regs = i40e_get_regs,
  2780. .nway_reset = i40e_nway_reset,
  2781. .get_link = ethtool_op_get_link,
  2782. .get_wol = i40e_get_wol,
  2783. .set_wol = i40e_set_wol,
  2784. .set_eeprom = i40e_set_eeprom,
  2785. .get_eeprom_len = i40e_get_eeprom_len,
  2786. .get_eeprom = i40e_get_eeprom,
  2787. .get_ringparam = i40e_get_ringparam,
  2788. .set_ringparam = i40e_set_ringparam,
  2789. .get_pauseparam = i40e_get_pauseparam,
  2790. .set_pauseparam = i40e_set_pauseparam,
  2791. .get_msglevel = i40e_get_msglevel,
  2792. .set_msglevel = i40e_set_msglevel,
  2793. .get_rxnfc = i40e_get_rxnfc,
  2794. .set_rxnfc = i40e_set_rxnfc,
  2795. .self_test = i40e_diag_test,
  2796. .get_strings = i40e_get_strings,
  2797. .set_phys_id = i40e_set_phys_id,
  2798. .get_sset_count = i40e_get_sset_count,
  2799. .get_ethtool_stats = i40e_get_ethtool_stats,
  2800. .get_coalesce = i40e_get_coalesce,
  2801. .set_coalesce = i40e_set_coalesce,
  2802. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2803. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2804. .get_rxfh = i40e_get_rxfh,
  2805. .set_rxfh = i40e_set_rxfh,
  2806. .get_channels = i40e_get_channels,
  2807. .set_channels = i40e_set_channels,
  2808. .get_ts_info = i40e_get_ts_info,
  2809. .get_priv_flags = i40e_get_priv_flags,
  2810. .set_priv_flags = i40e_set_priv_flags,
  2811. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  2812. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  2813. };
  2814. void i40e_set_ethtool_ops(struct net_device *netdev)
  2815. {
  2816. netdev->ethtool_ops = &i40e_ethtool_ops;
  2817. }