i40e_ethtool.c 94 KB

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