i40e_ethtool.c 95 KB

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