i40e_ethtool.c 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118
  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. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1037. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1038. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1039. /* register returns value in power of 2, 64Kbyte chunks. */
  1040. val = (64 * 1024) * BIT(val);
  1041. return val;
  1042. }
  1043. static int i40e_set_eeprom(struct net_device *netdev,
  1044. struct ethtool_eeprom *eeprom, u8 *bytes)
  1045. {
  1046. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1047. struct i40e_hw *hw = &np->vsi->back->hw;
  1048. struct i40e_pf *pf = np->vsi->back;
  1049. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1050. int ret_val = 0;
  1051. int errno = 0;
  1052. u32 magic;
  1053. /* normal ethtool set_eeprom is not supported */
  1054. magic = hw->vendor_id | (hw->device_id << 16);
  1055. if (eeprom->magic == magic)
  1056. errno = -EOPNOTSUPP;
  1057. /* check for NVMUpdate access method */
  1058. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1059. errno = -EINVAL;
  1060. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1061. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1062. errno = -EBUSY;
  1063. else
  1064. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1065. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1066. dev_info(&pf->pdev->dev,
  1067. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1068. ret_val, hw->aq.asq_last_status, errno,
  1069. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1070. cmd->offset, cmd->data_size);
  1071. return errno;
  1072. }
  1073. static void i40e_get_drvinfo(struct net_device *netdev,
  1074. struct ethtool_drvinfo *drvinfo)
  1075. {
  1076. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1077. struct i40e_vsi *vsi = np->vsi;
  1078. struct i40e_pf *pf = vsi->back;
  1079. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1080. strlcpy(drvinfo->version, i40e_driver_version_str,
  1081. sizeof(drvinfo->version));
  1082. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1083. sizeof(drvinfo->fw_version));
  1084. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1085. sizeof(drvinfo->bus_info));
  1086. if (pf->hw.pf_id == 0)
  1087. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
  1088. else
  1089. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  1090. }
  1091. static void i40e_get_ringparam(struct net_device *netdev,
  1092. struct ethtool_ringparam *ring)
  1093. {
  1094. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1095. struct i40e_pf *pf = np->vsi->back;
  1096. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1097. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1098. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1099. ring->rx_mini_max_pending = 0;
  1100. ring->rx_jumbo_max_pending = 0;
  1101. ring->rx_pending = vsi->rx_rings[0]->count;
  1102. ring->tx_pending = vsi->tx_rings[0]->count;
  1103. ring->rx_mini_pending = 0;
  1104. ring->rx_jumbo_pending = 0;
  1105. }
  1106. static int i40e_set_ringparam(struct net_device *netdev,
  1107. struct ethtool_ringparam *ring)
  1108. {
  1109. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1110. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1111. struct i40e_vsi *vsi = np->vsi;
  1112. struct i40e_pf *pf = vsi->back;
  1113. u32 new_rx_count, new_tx_count;
  1114. int i, err = 0;
  1115. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1116. return -EINVAL;
  1117. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1118. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1119. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1120. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1121. netdev_info(netdev,
  1122. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1123. ring->tx_pending, ring->rx_pending,
  1124. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1125. return -EINVAL;
  1126. }
  1127. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1128. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1129. /* if nothing to do return success */
  1130. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1131. (new_rx_count == vsi->rx_rings[0]->count))
  1132. return 0;
  1133. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1134. usleep_range(1000, 2000);
  1135. if (!netif_running(vsi->netdev)) {
  1136. /* simple case - set for the next time the netdev is started */
  1137. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1138. vsi->tx_rings[i]->count = new_tx_count;
  1139. vsi->rx_rings[i]->count = new_rx_count;
  1140. }
  1141. goto done;
  1142. }
  1143. /* We can't just free everything and then setup again,
  1144. * because the ISRs in MSI-X mode get passed pointers
  1145. * to the Tx and Rx ring structs.
  1146. */
  1147. /* alloc updated Tx resources */
  1148. if (new_tx_count != vsi->tx_rings[0]->count) {
  1149. netdev_info(netdev,
  1150. "Changing Tx descriptor count from %d to %d.\n",
  1151. vsi->tx_rings[0]->count, new_tx_count);
  1152. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1153. sizeof(struct i40e_ring), GFP_KERNEL);
  1154. if (!tx_rings) {
  1155. err = -ENOMEM;
  1156. goto done;
  1157. }
  1158. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1159. /* clone ring and setup updated count */
  1160. tx_rings[i] = *vsi->tx_rings[i];
  1161. tx_rings[i].count = new_tx_count;
  1162. /* the desc and bi pointers will be reallocated in the
  1163. * setup call
  1164. */
  1165. tx_rings[i].desc = NULL;
  1166. tx_rings[i].rx_bi = NULL;
  1167. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1168. if (err) {
  1169. while (i) {
  1170. i--;
  1171. i40e_free_tx_resources(&tx_rings[i]);
  1172. }
  1173. kfree(tx_rings);
  1174. tx_rings = NULL;
  1175. goto done;
  1176. }
  1177. }
  1178. }
  1179. /* alloc updated Rx resources */
  1180. if (new_rx_count != vsi->rx_rings[0]->count) {
  1181. netdev_info(netdev,
  1182. "Changing Rx descriptor count from %d to %d\n",
  1183. vsi->rx_rings[0]->count, new_rx_count);
  1184. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1185. sizeof(struct i40e_ring), GFP_KERNEL);
  1186. if (!rx_rings) {
  1187. err = -ENOMEM;
  1188. goto free_tx;
  1189. }
  1190. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1191. /* this is to allow wr32 to have something to write to
  1192. * during early allocation of Rx buffers
  1193. */
  1194. u32 __iomem faketail = 0;
  1195. struct i40e_ring *ring;
  1196. u16 unused;
  1197. /* clone ring and setup updated count */
  1198. rx_rings[i] = *vsi->rx_rings[i];
  1199. rx_rings[i].count = new_rx_count;
  1200. /* the desc and bi pointers will be reallocated in the
  1201. * setup call
  1202. */
  1203. rx_rings[i].desc = NULL;
  1204. rx_rings[i].rx_bi = NULL;
  1205. rx_rings[i].tail = (u8 __iomem *)&faketail;
  1206. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1207. if (err)
  1208. goto rx_unwind;
  1209. /* now allocate the Rx buffers to make sure the OS
  1210. * has enough memory, any failure here means abort
  1211. */
  1212. ring = &rx_rings[i];
  1213. unused = I40E_DESC_UNUSED(ring);
  1214. err = i40e_alloc_rx_buffers(ring, unused);
  1215. rx_unwind:
  1216. if (err) {
  1217. do {
  1218. i40e_free_rx_resources(&rx_rings[i]);
  1219. } while (i--);
  1220. kfree(rx_rings);
  1221. rx_rings = NULL;
  1222. goto free_tx;
  1223. }
  1224. }
  1225. }
  1226. /* Bring interface down, copy in the new ring info,
  1227. * then restore the interface
  1228. */
  1229. i40e_down(vsi);
  1230. if (tx_rings) {
  1231. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1232. i40e_free_tx_resources(vsi->tx_rings[i]);
  1233. *vsi->tx_rings[i] = tx_rings[i];
  1234. }
  1235. kfree(tx_rings);
  1236. tx_rings = NULL;
  1237. }
  1238. if (rx_rings) {
  1239. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1240. i40e_free_rx_resources(vsi->rx_rings[i]);
  1241. /* get the real tail offset */
  1242. rx_rings[i].tail = vsi->rx_rings[i]->tail;
  1243. /* this is to fake out the allocation routine
  1244. * into thinking it has to realloc everything
  1245. * but the recycling logic will let us re-use
  1246. * the buffers allocated above
  1247. */
  1248. rx_rings[i].next_to_use = 0;
  1249. rx_rings[i].next_to_clean = 0;
  1250. rx_rings[i].next_to_alloc = 0;
  1251. /* do a struct copy */
  1252. *vsi->rx_rings[i] = rx_rings[i];
  1253. }
  1254. kfree(rx_rings);
  1255. rx_rings = NULL;
  1256. }
  1257. i40e_up(vsi);
  1258. free_tx:
  1259. /* error cleanup if the Rx allocations failed after getting Tx */
  1260. if (tx_rings) {
  1261. for (i = 0; i < vsi->num_queue_pairs; i++)
  1262. i40e_free_tx_resources(&tx_rings[i]);
  1263. kfree(tx_rings);
  1264. tx_rings = NULL;
  1265. }
  1266. done:
  1267. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1268. return err;
  1269. }
  1270. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1271. {
  1272. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1273. struct i40e_vsi *vsi = np->vsi;
  1274. struct i40e_pf *pf = vsi->back;
  1275. switch (sset) {
  1276. case ETH_SS_TEST:
  1277. return I40E_TEST_LEN;
  1278. case ETH_SS_STATS:
  1279. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1280. int len = I40E_PF_STATS_LEN(netdev);
  1281. if ((pf->lan_veb != I40E_NO_VEB) &&
  1282. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1283. len += I40E_VEB_STATS_TOTAL;
  1284. return len;
  1285. } else {
  1286. return I40E_VSI_STATS_LEN(netdev);
  1287. }
  1288. case ETH_SS_PRIV_FLAGS:
  1289. if (pf->hw.pf_id == 0)
  1290. return I40E_PRIV_FLAGS_GL_STR_LEN;
  1291. else
  1292. return I40E_PRIV_FLAGS_STR_LEN;
  1293. default:
  1294. return -EOPNOTSUPP;
  1295. }
  1296. }
  1297. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1298. struct ethtool_stats *stats, u64 *data)
  1299. {
  1300. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1301. struct i40e_ring *tx_ring, *rx_ring;
  1302. struct i40e_vsi *vsi = np->vsi;
  1303. struct i40e_pf *pf = vsi->back;
  1304. int i = 0;
  1305. char *p;
  1306. int j;
  1307. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1308. unsigned int start;
  1309. i40e_update_stats(vsi);
  1310. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1311. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1312. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1313. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1314. }
  1315. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1316. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1317. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1318. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1319. }
  1320. #ifdef I40E_FCOE
  1321. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1322. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1323. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1324. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1325. }
  1326. #endif
  1327. rcu_read_lock();
  1328. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1329. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1330. if (!tx_ring)
  1331. continue;
  1332. /* process Tx ring statistics */
  1333. do {
  1334. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1335. data[i] = tx_ring->stats.packets;
  1336. data[i + 1] = tx_ring->stats.bytes;
  1337. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1338. i += 2;
  1339. /* Rx ring is the 2nd half of the queue pair */
  1340. rx_ring = &tx_ring[1];
  1341. do {
  1342. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1343. data[i] = rx_ring->stats.packets;
  1344. data[i + 1] = rx_ring->stats.bytes;
  1345. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1346. i += 2;
  1347. }
  1348. rcu_read_unlock();
  1349. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1350. return;
  1351. if ((pf->lan_veb != I40E_NO_VEB) &&
  1352. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1353. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1354. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1355. p = (char *)veb;
  1356. p += i40e_gstrings_veb_stats[j].stat_offset;
  1357. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1358. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1359. }
  1360. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1361. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1362. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1363. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1364. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1365. }
  1366. }
  1367. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1368. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1369. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1370. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1371. }
  1372. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1373. data[i++] = pf->stats.priority_xon_tx[j];
  1374. data[i++] = pf->stats.priority_xoff_tx[j];
  1375. }
  1376. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1377. data[i++] = pf->stats.priority_xon_rx[j];
  1378. data[i++] = pf->stats.priority_xoff_rx[j];
  1379. }
  1380. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1381. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1382. }
  1383. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1384. u8 *data)
  1385. {
  1386. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1387. struct i40e_vsi *vsi = np->vsi;
  1388. struct i40e_pf *pf = vsi->back;
  1389. char *p = (char *)data;
  1390. int i;
  1391. switch (stringset) {
  1392. case ETH_SS_TEST:
  1393. for (i = 0; i < I40E_TEST_LEN; i++) {
  1394. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1395. data += ETH_GSTRING_LEN;
  1396. }
  1397. break;
  1398. case ETH_SS_STATS:
  1399. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1400. snprintf(p, ETH_GSTRING_LEN, "%s",
  1401. i40e_gstrings_net_stats[i].stat_string);
  1402. p += ETH_GSTRING_LEN;
  1403. }
  1404. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1405. snprintf(p, ETH_GSTRING_LEN, "%s",
  1406. i40e_gstrings_misc_stats[i].stat_string);
  1407. p += ETH_GSTRING_LEN;
  1408. }
  1409. #ifdef I40E_FCOE
  1410. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1411. snprintf(p, ETH_GSTRING_LEN, "%s",
  1412. i40e_gstrings_fcoe_stats[i].stat_string);
  1413. p += ETH_GSTRING_LEN;
  1414. }
  1415. #endif
  1416. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1417. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
  1418. p += ETH_GSTRING_LEN;
  1419. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
  1420. p += ETH_GSTRING_LEN;
  1421. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
  1422. p += ETH_GSTRING_LEN;
  1423. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
  1424. p += ETH_GSTRING_LEN;
  1425. }
  1426. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1427. return;
  1428. if ((pf->lan_veb != I40E_NO_VEB) &&
  1429. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1430. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1431. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1432. i40e_gstrings_veb_stats[i].stat_string);
  1433. p += ETH_GSTRING_LEN;
  1434. }
  1435. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1436. snprintf(p, ETH_GSTRING_LEN,
  1437. "veb.tc_%d_tx_packets", i);
  1438. p += ETH_GSTRING_LEN;
  1439. snprintf(p, ETH_GSTRING_LEN,
  1440. "veb.tc_%d_tx_bytes", i);
  1441. p += ETH_GSTRING_LEN;
  1442. snprintf(p, ETH_GSTRING_LEN,
  1443. "veb.tc_%d_rx_packets", i);
  1444. p += ETH_GSTRING_LEN;
  1445. snprintf(p, ETH_GSTRING_LEN,
  1446. "veb.tc_%d_rx_bytes", i);
  1447. p += ETH_GSTRING_LEN;
  1448. }
  1449. }
  1450. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1451. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1452. i40e_gstrings_stats[i].stat_string);
  1453. p += ETH_GSTRING_LEN;
  1454. }
  1455. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1456. snprintf(p, ETH_GSTRING_LEN,
  1457. "port.tx_priority_%d_xon", i);
  1458. p += ETH_GSTRING_LEN;
  1459. snprintf(p, ETH_GSTRING_LEN,
  1460. "port.tx_priority_%d_xoff", i);
  1461. p += ETH_GSTRING_LEN;
  1462. }
  1463. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1464. snprintf(p, ETH_GSTRING_LEN,
  1465. "port.rx_priority_%d_xon", i);
  1466. p += ETH_GSTRING_LEN;
  1467. snprintf(p, ETH_GSTRING_LEN,
  1468. "port.rx_priority_%d_xoff", i);
  1469. p += ETH_GSTRING_LEN;
  1470. }
  1471. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1472. snprintf(p, ETH_GSTRING_LEN,
  1473. "port.rx_priority_%d_xon_2_xoff", i);
  1474. p += ETH_GSTRING_LEN;
  1475. }
  1476. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1477. break;
  1478. case ETH_SS_PRIV_FLAGS:
  1479. if (pf->hw.pf_id == 0) {
  1480. for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
  1481. memcpy(data, i40e_priv_flags_strings_gl[i],
  1482. ETH_GSTRING_LEN);
  1483. data += ETH_GSTRING_LEN;
  1484. }
  1485. } else {
  1486. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1487. memcpy(data, i40e_priv_flags_strings[i],
  1488. ETH_GSTRING_LEN);
  1489. data += ETH_GSTRING_LEN;
  1490. }
  1491. }
  1492. break;
  1493. default:
  1494. break;
  1495. }
  1496. }
  1497. static int i40e_get_ts_info(struct net_device *dev,
  1498. struct ethtool_ts_info *info)
  1499. {
  1500. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1501. /* only report HW timestamping if PTP is enabled */
  1502. if (!(pf->flags & I40E_FLAG_PTP))
  1503. return ethtool_op_get_ts_info(dev, info);
  1504. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1505. SOF_TIMESTAMPING_RX_SOFTWARE |
  1506. SOF_TIMESTAMPING_SOFTWARE |
  1507. SOF_TIMESTAMPING_TX_HARDWARE |
  1508. SOF_TIMESTAMPING_RX_HARDWARE |
  1509. SOF_TIMESTAMPING_RAW_HARDWARE;
  1510. if (pf->ptp_clock)
  1511. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1512. else
  1513. info->phc_index = -1;
  1514. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1515. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1516. BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  1517. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
  1518. return 0;
  1519. }
  1520. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1521. {
  1522. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1523. struct i40e_pf *pf = np->vsi->back;
  1524. i40e_status status;
  1525. bool link_up = false;
  1526. netif_info(pf, hw, netdev, "link test\n");
  1527. status = i40e_get_link_status(&pf->hw, &link_up);
  1528. if (status) {
  1529. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1530. *data = 1;
  1531. return *data;
  1532. }
  1533. if (link_up)
  1534. *data = 0;
  1535. else
  1536. *data = 1;
  1537. return *data;
  1538. }
  1539. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1540. {
  1541. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1542. struct i40e_pf *pf = np->vsi->back;
  1543. netif_info(pf, hw, netdev, "register test\n");
  1544. *data = i40e_diag_reg_test(&pf->hw);
  1545. return *data;
  1546. }
  1547. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1548. {
  1549. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1550. struct i40e_pf *pf = np->vsi->back;
  1551. netif_info(pf, hw, netdev, "eeprom test\n");
  1552. *data = i40e_diag_eeprom_test(&pf->hw);
  1553. /* forcebly clear the NVM Update state machine */
  1554. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1555. return *data;
  1556. }
  1557. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1558. {
  1559. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1560. struct i40e_pf *pf = np->vsi->back;
  1561. u16 swc_old = pf->sw_int_count;
  1562. netif_info(pf, hw, netdev, "interrupt test\n");
  1563. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1564. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1565. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1566. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1567. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1568. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1569. usleep_range(1000, 2000);
  1570. *data = (swc_old == pf->sw_int_count);
  1571. return *data;
  1572. }
  1573. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1574. {
  1575. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1576. struct i40e_pf *pf = np->vsi->back;
  1577. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1578. *data = 0;
  1579. return *data;
  1580. }
  1581. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1582. {
  1583. struct i40e_vf *vfs = pf->vf;
  1584. int i;
  1585. for (i = 0; i < pf->num_alloc_vfs; i++)
  1586. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1587. return true;
  1588. return false;
  1589. }
  1590. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1591. {
  1592. struct i40e_vsi **vsi = pf->vsi;
  1593. int i;
  1594. for (i = 0; i < pf->num_alloc_vsi; i++) {
  1595. if (!vsi[i])
  1596. continue;
  1597. if (vsi[i]->type == I40E_VSI_VMDQ2)
  1598. return true;
  1599. }
  1600. return false;
  1601. }
  1602. static void i40e_diag_test(struct net_device *netdev,
  1603. struct ethtool_test *eth_test, u64 *data)
  1604. {
  1605. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1606. bool if_running = netif_running(netdev);
  1607. struct i40e_pf *pf = np->vsi->back;
  1608. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1609. /* Offline tests */
  1610. netif_info(pf, drv, netdev, "offline testing starting\n");
  1611. set_bit(__I40E_TESTING, &pf->state);
  1612. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1613. dev_warn(&pf->pdev->dev,
  1614. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1615. data[I40E_ETH_TEST_REG] = 1;
  1616. data[I40E_ETH_TEST_EEPROM] = 1;
  1617. data[I40E_ETH_TEST_INTR] = 1;
  1618. data[I40E_ETH_TEST_LOOPBACK] = 1;
  1619. data[I40E_ETH_TEST_LINK] = 1;
  1620. eth_test->flags |= ETH_TEST_FL_FAILED;
  1621. clear_bit(__I40E_TESTING, &pf->state);
  1622. goto skip_ol_tests;
  1623. }
  1624. /* If the device is online then take it offline */
  1625. if (if_running)
  1626. /* indicate we're in test mode */
  1627. i40e_close(netdev);
  1628. else
  1629. /* This reset does not affect link - if it is
  1630. * changed to a type of reset that does affect
  1631. * link then the following link test would have
  1632. * to be moved to before the reset
  1633. */
  1634. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1635. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1636. eth_test->flags |= ETH_TEST_FL_FAILED;
  1637. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1638. eth_test->flags |= ETH_TEST_FL_FAILED;
  1639. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1640. eth_test->flags |= ETH_TEST_FL_FAILED;
  1641. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1642. eth_test->flags |= ETH_TEST_FL_FAILED;
  1643. /* run reg test last, a reset is required after it */
  1644. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1645. eth_test->flags |= ETH_TEST_FL_FAILED;
  1646. clear_bit(__I40E_TESTING, &pf->state);
  1647. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1648. if (if_running)
  1649. i40e_open(netdev);
  1650. } else {
  1651. /* Online tests */
  1652. netif_info(pf, drv, netdev, "online testing starting\n");
  1653. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1654. eth_test->flags |= ETH_TEST_FL_FAILED;
  1655. /* Offline only tests, not run in online; pass by default */
  1656. data[I40E_ETH_TEST_REG] = 0;
  1657. data[I40E_ETH_TEST_EEPROM] = 0;
  1658. data[I40E_ETH_TEST_INTR] = 0;
  1659. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1660. }
  1661. skip_ol_tests:
  1662. netif_info(pf, drv, netdev, "testing finished\n");
  1663. }
  1664. static void i40e_get_wol(struct net_device *netdev,
  1665. struct ethtool_wolinfo *wol)
  1666. {
  1667. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1668. struct i40e_pf *pf = np->vsi->back;
  1669. struct i40e_hw *hw = &pf->hw;
  1670. u16 wol_nvm_bits;
  1671. /* NVM bit on means WoL disabled for the port */
  1672. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1673. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1674. wol->supported = 0;
  1675. wol->wolopts = 0;
  1676. } else {
  1677. wol->supported = WAKE_MAGIC;
  1678. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1679. }
  1680. }
  1681. /**
  1682. * i40e_set_wol - set the WakeOnLAN configuration
  1683. * @netdev: the netdev in question
  1684. * @wol: the ethtool WoL setting data
  1685. **/
  1686. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1687. {
  1688. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1689. struct i40e_pf *pf = np->vsi->back;
  1690. struct i40e_vsi *vsi = np->vsi;
  1691. struct i40e_hw *hw = &pf->hw;
  1692. u16 wol_nvm_bits;
  1693. /* WoL not supported if this isn't the controlling PF on the port */
  1694. if (hw->partition_id != 1) {
  1695. i40e_partition_setting_complaint(pf);
  1696. return -EOPNOTSUPP;
  1697. }
  1698. if (vsi != pf->vsi[pf->lan_vsi])
  1699. return -EOPNOTSUPP;
  1700. /* NVM bit on means WoL disabled for the port */
  1701. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1702. if (BIT(hw->port) & wol_nvm_bits)
  1703. return -EOPNOTSUPP;
  1704. /* only magic packet is supported */
  1705. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1706. return -EOPNOTSUPP;
  1707. /* is this a new value? */
  1708. if (pf->wol_en != !!wol->wolopts) {
  1709. pf->wol_en = !!wol->wolopts;
  1710. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1711. }
  1712. return 0;
  1713. }
  1714. static int i40e_set_phys_id(struct net_device *netdev,
  1715. enum ethtool_phys_id_state state)
  1716. {
  1717. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1718. i40e_status ret = 0;
  1719. struct i40e_pf *pf = np->vsi->back;
  1720. struct i40e_hw *hw = &pf->hw;
  1721. int blink_freq = 2;
  1722. u16 temp_status;
  1723. switch (state) {
  1724. case ETHTOOL_ID_ACTIVE:
  1725. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1726. pf->led_status = i40e_led_get(hw);
  1727. } else {
  1728. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
  1729. ret = i40e_led_get_phy(hw, &temp_status,
  1730. &pf->phy_led_val);
  1731. pf->led_status = temp_status;
  1732. }
  1733. return blink_freq;
  1734. case ETHTOOL_ID_ON:
  1735. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1736. i40e_led_set(hw, 0xf, false);
  1737. else
  1738. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1739. break;
  1740. case ETHTOOL_ID_OFF:
  1741. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1742. i40e_led_set(hw, 0x0, false);
  1743. else
  1744. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1745. break;
  1746. case ETHTOOL_ID_INACTIVE:
  1747. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1748. i40e_led_set(hw, false, pf->led_status);
  1749. } else {
  1750. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1751. (pf->phy_led_val |
  1752. I40E_PHY_LED_MODE_ORIG));
  1753. i40e_aq_set_phy_debug(hw, 0, NULL);
  1754. }
  1755. break;
  1756. default:
  1757. break;
  1758. }
  1759. if (ret)
  1760. return -ENOENT;
  1761. else
  1762. return 0;
  1763. }
  1764. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1765. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1766. * 125us (8000 interrupts per second) == ITR(62)
  1767. */
  1768. static int __i40e_get_coalesce(struct net_device *netdev,
  1769. struct ethtool_coalesce *ec,
  1770. int queue)
  1771. {
  1772. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1773. struct i40e_vsi *vsi = np->vsi;
  1774. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1775. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1776. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1777. * return queue 0's value to represent.
  1778. */
  1779. if (queue < 0) {
  1780. queue = 0;
  1781. } else if (queue >= vsi->num_queue_pairs) {
  1782. return -EINVAL;
  1783. }
  1784. if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
  1785. ec->use_adaptive_rx_coalesce = 1;
  1786. if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
  1787. ec->use_adaptive_tx_coalesce = 1;
  1788. ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1789. ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1790. /* we use the _usecs_high to store/set the interrupt rate limit
  1791. * that the hardware supports, that almost but not quite
  1792. * fits the original intent of the ethtool variable,
  1793. * the rx_coalesce_usecs_high limits total interrupts
  1794. * per second from both tx/rx sources.
  1795. */
  1796. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1797. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1798. return 0;
  1799. }
  1800. static int i40e_get_coalesce(struct net_device *netdev,
  1801. struct ethtool_coalesce *ec)
  1802. {
  1803. return __i40e_get_coalesce(netdev, ec, -1);
  1804. }
  1805. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1806. struct ethtool_coalesce *ec)
  1807. {
  1808. return __i40e_get_coalesce(netdev, ec, queue);
  1809. }
  1810. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1811. struct ethtool_coalesce *ec,
  1812. int queue)
  1813. {
  1814. struct i40e_pf *pf = vsi->back;
  1815. struct i40e_hw *hw = &pf->hw;
  1816. struct i40e_q_vector *q_vector;
  1817. u16 vector, intrl;
  1818. intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
  1819. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1820. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1821. if (ec->use_adaptive_rx_coalesce)
  1822. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1823. else
  1824. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1825. if (ec->use_adaptive_tx_coalesce)
  1826. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1827. else
  1828. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1829. q_vector = vsi->rx_rings[queue]->q_vector;
  1830. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1831. vector = vsi->base_vector + q_vector->v_idx;
  1832. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1833. q_vector = vsi->tx_rings[queue]->q_vector;
  1834. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1835. vector = vsi->base_vector + q_vector->v_idx;
  1836. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1837. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1838. i40e_flush(hw);
  1839. }
  1840. static int __i40e_set_coalesce(struct net_device *netdev,
  1841. struct ethtool_coalesce *ec,
  1842. int queue)
  1843. {
  1844. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1845. struct i40e_vsi *vsi = np->vsi;
  1846. struct i40e_pf *pf = vsi->back;
  1847. int i;
  1848. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1849. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1850. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1851. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1852. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1853. return -EINVAL;
  1854. }
  1855. if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1856. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
  1857. return -EINVAL;
  1858. }
  1859. if (ec->rx_coalesce_usecs == 0) {
  1860. if (ec->use_adaptive_rx_coalesce)
  1861. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1862. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1863. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1864. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1865. return -EINVAL;
  1866. }
  1867. vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
  1868. if (ec->tx_coalesce_usecs == 0) {
  1869. if (ec->use_adaptive_tx_coalesce)
  1870. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1871. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1872. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1873. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1874. return -EINVAL;
  1875. }
  1876. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1877. * apply to all queues.
  1878. */
  1879. if (queue < 0) {
  1880. for (i = 0; i < vsi->num_queue_pairs; i++)
  1881. i40e_set_itr_per_queue(vsi, ec, i);
  1882. } else if (queue < vsi->num_queue_pairs) {
  1883. i40e_set_itr_per_queue(vsi, ec, queue);
  1884. } else {
  1885. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1886. vsi->num_queue_pairs - 1);
  1887. return -EINVAL;
  1888. }
  1889. return 0;
  1890. }
  1891. static int i40e_set_coalesce(struct net_device *netdev,
  1892. struct ethtool_coalesce *ec)
  1893. {
  1894. return __i40e_set_coalesce(netdev, ec, -1);
  1895. }
  1896. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1897. struct ethtool_coalesce *ec)
  1898. {
  1899. return __i40e_set_coalesce(netdev, ec, queue);
  1900. }
  1901. /**
  1902. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1903. * @pf: pointer to the physical function struct
  1904. * @cmd: ethtool rxnfc command
  1905. *
  1906. * Returns Success if the flow is supported, else Invalid Input.
  1907. **/
  1908. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1909. {
  1910. struct i40e_hw *hw = &pf->hw;
  1911. u8 flow_pctype = 0;
  1912. u64 i_set = 0;
  1913. cmd->data = 0;
  1914. switch (cmd->flow_type) {
  1915. case TCP_V4_FLOW:
  1916. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  1917. break;
  1918. case UDP_V4_FLOW:
  1919. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  1920. break;
  1921. case TCP_V6_FLOW:
  1922. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  1923. break;
  1924. case UDP_V6_FLOW:
  1925. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  1926. break;
  1927. case SCTP_V4_FLOW:
  1928. case AH_ESP_V4_FLOW:
  1929. case AH_V4_FLOW:
  1930. case ESP_V4_FLOW:
  1931. case IPV4_FLOW:
  1932. case SCTP_V6_FLOW:
  1933. case AH_ESP_V6_FLOW:
  1934. case AH_V6_FLOW:
  1935. case ESP_V6_FLOW:
  1936. case IPV6_FLOW:
  1937. /* Default is src/dest for IP, no matter the L4 hashing */
  1938. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1939. break;
  1940. default:
  1941. return -EINVAL;
  1942. }
  1943. /* Read flow based hash input set register */
  1944. if (flow_pctype) {
  1945. i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  1946. flow_pctype)) |
  1947. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  1948. flow_pctype)) << 32);
  1949. }
  1950. /* Process bits of hash input set */
  1951. if (i_set) {
  1952. if (i_set & I40E_L4_SRC_MASK)
  1953. cmd->data |= RXH_L4_B_0_1;
  1954. if (i_set & I40E_L4_DST_MASK)
  1955. cmd->data |= RXH_L4_B_2_3;
  1956. if (cmd->flow_type == TCP_V4_FLOW ||
  1957. cmd->flow_type == UDP_V4_FLOW) {
  1958. if (i_set & I40E_L3_SRC_MASK)
  1959. cmd->data |= RXH_IP_SRC;
  1960. if (i_set & I40E_L3_DST_MASK)
  1961. cmd->data |= RXH_IP_DST;
  1962. } else if (cmd->flow_type == TCP_V6_FLOW ||
  1963. cmd->flow_type == UDP_V6_FLOW) {
  1964. if (i_set & I40E_L3_V6_SRC_MASK)
  1965. cmd->data |= RXH_IP_SRC;
  1966. if (i_set & I40E_L3_V6_DST_MASK)
  1967. cmd->data |= RXH_IP_DST;
  1968. }
  1969. }
  1970. return 0;
  1971. }
  1972. /**
  1973. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1974. * @pf: Pointer to the physical function struct
  1975. * @cmd: The command to get or set Rx flow classification rules
  1976. * @rule_locs: Array of used rule locations
  1977. *
  1978. * This function populates both the total and actual rule count of
  1979. * the ethtool flow classification command
  1980. *
  1981. * Returns 0 on success or -EMSGSIZE if entry not found
  1982. **/
  1983. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1984. struct ethtool_rxnfc *cmd,
  1985. u32 *rule_locs)
  1986. {
  1987. struct i40e_fdir_filter *rule;
  1988. struct hlist_node *node2;
  1989. int cnt = 0;
  1990. /* report total rule count */
  1991. cmd->data = i40e_get_fd_cnt_all(pf);
  1992. hlist_for_each_entry_safe(rule, node2,
  1993. &pf->fdir_filter_list, fdir_node) {
  1994. if (cnt == cmd->rule_cnt)
  1995. return -EMSGSIZE;
  1996. rule_locs[cnt] = rule->fd_id;
  1997. cnt++;
  1998. }
  1999. cmd->rule_cnt = cnt;
  2000. return 0;
  2001. }
  2002. /**
  2003. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  2004. * @pf: Pointer to the physical function struct
  2005. * @cmd: The command to get or set Rx flow classification rules
  2006. *
  2007. * This function looks up a filter based on the Rx flow classification
  2008. * command and fills the flow spec info for it if found
  2009. *
  2010. * Returns 0 on success or -EINVAL if filter not found
  2011. **/
  2012. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  2013. struct ethtool_rxnfc *cmd)
  2014. {
  2015. struct ethtool_rx_flow_spec *fsp =
  2016. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2017. struct i40e_fdir_filter *rule = NULL;
  2018. struct hlist_node *node2;
  2019. hlist_for_each_entry_safe(rule, node2,
  2020. &pf->fdir_filter_list, fdir_node) {
  2021. if (fsp->location <= rule->fd_id)
  2022. break;
  2023. }
  2024. if (!rule || fsp->location != rule->fd_id)
  2025. return -EINVAL;
  2026. fsp->flow_type = rule->flow_type;
  2027. if (fsp->flow_type == IP_USER_FLOW) {
  2028. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  2029. fsp->h_u.usr_ip4_spec.proto = 0;
  2030. fsp->m_u.usr_ip4_spec.proto = 0;
  2031. }
  2032. /* Reverse the src and dest notion, since the HW views them from
  2033. * Tx perspective where as the user expects it from Rx filter view.
  2034. */
  2035. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  2036. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  2037. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  2038. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  2039. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  2040. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  2041. else
  2042. fsp->ring_cookie = rule->q_index;
  2043. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  2044. struct i40e_vsi *vsi;
  2045. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  2046. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  2047. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  2048. fsp->m_ext.data[1] = htonl(0x1);
  2049. }
  2050. }
  2051. return 0;
  2052. }
  2053. /**
  2054. * i40e_get_rxnfc - command to get RX flow classification rules
  2055. * @netdev: network interface device structure
  2056. * @cmd: ethtool rxnfc command
  2057. *
  2058. * Returns Success if the command is supported.
  2059. **/
  2060. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  2061. u32 *rule_locs)
  2062. {
  2063. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2064. struct i40e_vsi *vsi = np->vsi;
  2065. struct i40e_pf *pf = vsi->back;
  2066. int ret = -EOPNOTSUPP;
  2067. switch (cmd->cmd) {
  2068. case ETHTOOL_GRXRINGS:
  2069. cmd->data = vsi->num_queue_pairs;
  2070. ret = 0;
  2071. break;
  2072. case ETHTOOL_GRXFH:
  2073. ret = i40e_get_rss_hash_opts(pf, cmd);
  2074. break;
  2075. case ETHTOOL_GRXCLSRLCNT:
  2076. cmd->rule_cnt = pf->fdir_pf_active_filters;
  2077. /* report total rule count */
  2078. cmd->data = i40e_get_fd_cnt_all(pf);
  2079. ret = 0;
  2080. break;
  2081. case ETHTOOL_GRXCLSRULE:
  2082. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  2083. break;
  2084. case ETHTOOL_GRXCLSRLALL:
  2085. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  2086. break;
  2087. default:
  2088. break;
  2089. }
  2090. return ret;
  2091. }
  2092. /**
  2093. * i40e_get_rss_hash_bits - Read RSS Hash bits from register
  2094. * @nfc: pointer to user request
  2095. * @i_setc bits currently set
  2096. *
  2097. * Returns value of bits to be set per user request
  2098. **/
  2099. static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
  2100. {
  2101. u64 i_set = i_setc;
  2102. u64 src_l3 = 0, dst_l3 = 0;
  2103. if (nfc->data & RXH_L4_B_0_1)
  2104. i_set |= I40E_L4_SRC_MASK;
  2105. else
  2106. i_set &= ~I40E_L4_SRC_MASK;
  2107. if (nfc->data & RXH_L4_B_2_3)
  2108. i_set |= I40E_L4_DST_MASK;
  2109. else
  2110. i_set &= ~I40E_L4_DST_MASK;
  2111. if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
  2112. src_l3 = I40E_L3_V6_SRC_MASK;
  2113. dst_l3 = I40E_L3_V6_DST_MASK;
  2114. } else if (nfc->flow_type == TCP_V4_FLOW ||
  2115. nfc->flow_type == UDP_V4_FLOW) {
  2116. src_l3 = I40E_L3_SRC_MASK;
  2117. dst_l3 = I40E_L3_DST_MASK;
  2118. } else {
  2119. /* Any other flow type are not supported here */
  2120. return i_set;
  2121. }
  2122. if (nfc->data & RXH_IP_SRC)
  2123. i_set |= src_l3;
  2124. else
  2125. i_set &= ~src_l3;
  2126. if (nfc->data & RXH_IP_DST)
  2127. i_set |= dst_l3;
  2128. else
  2129. i_set &= ~dst_l3;
  2130. return i_set;
  2131. }
  2132. /**
  2133. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  2134. * @pf: pointer to the physical function struct
  2135. * @cmd: ethtool rxnfc command
  2136. *
  2137. * Returns Success if the flow input set is supported.
  2138. **/
  2139. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2140. {
  2141. struct i40e_hw *hw = &pf->hw;
  2142. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2143. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2144. u8 flow_pctype = 0;
  2145. u64 i_set, i_setc;
  2146. /* RSS does not support anything other than hashing
  2147. * to queues on src and dst IPs and ports
  2148. */
  2149. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2150. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2151. return -EINVAL;
  2152. switch (nfc->flow_type) {
  2153. case TCP_V4_FLOW:
  2154. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2155. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2156. hena |=
  2157. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2158. break;
  2159. case TCP_V6_FLOW:
  2160. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2161. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2162. hena |=
  2163. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2164. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2165. hena |=
  2166. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2167. break;
  2168. case UDP_V4_FLOW:
  2169. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2170. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2171. hena |=
  2172. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2173. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2174. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2175. break;
  2176. case UDP_V6_FLOW:
  2177. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2178. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2179. hena |=
  2180. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2181. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2182. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2183. break;
  2184. case AH_ESP_V4_FLOW:
  2185. case AH_V4_FLOW:
  2186. case ESP_V4_FLOW:
  2187. case SCTP_V4_FLOW:
  2188. if ((nfc->data & RXH_L4_B_0_1) ||
  2189. (nfc->data & RXH_L4_B_2_3))
  2190. return -EINVAL;
  2191. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2192. break;
  2193. case AH_ESP_V6_FLOW:
  2194. case AH_V6_FLOW:
  2195. case ESP_V6_FLOW:
  2196. case SCTP_V6_FLOW:
  2197. if ((nfc->data & RXH_L4_B_0_1) ||
  2198. (nfc->data & RXH_L4_B_2_3))
  2199. return -EINVAL;
  2200. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2201. break;
  2202. case IPV4_FLOW:
  2203. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2204. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2205. break;
  2206. case IPV6_FLOW:
  2207. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2208. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2209. break;
  2210. default:
  2211. return -EINVAL;
  2212. }
  2213. if (flow_pctype) {
  2214. i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2215. flow_pctype)) |
  2216. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2217. flow_pctype)) << 32);
  2218. i_set = i40e_get_rss_hash_bits(nfc, i_setc);
  2219. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
  2220. (u32)i_set);
  2221. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
  2222. (u32)(i_set >> 32));
  2223. hena |= BIT_ULL(flow_pctype);
  2224. }
  2225. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2226. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2227. i40e_flush(hw);
  2228. return 0;
  2229. }
  2230. /**
  2231. * i40e_match_fdir_input_set - Match a new filter against an existing one
  2232. * @rule: The filter already added
  2233. * @input: The new filter to comapre against
  2234. *
  2235. * Returns true if the two input set match
  2236. **/
  2237. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  2238. struct i40e_fdir_filter *input)
  2239. {
  2240. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  2241. (rule->src_ip[0] != input->src_ip[0]) ||
  2242. (rule->dst_port != input->dst_port) ||
  2243. (rule->src_port != input->src_port))
  2244. return false;
  2245. return true;
  2246. }
  2247. /**
  2248. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2249. * @vsi: Pointer to the targeted VSI
  2250. * @input: The filter to update or NULL to indicate deletion
  2251. * @sw_idx: Software index to the filter
  2252. * @cmd: The command to get or set Rx flow classification rules
  2253. *
  2254. * This function updates (or deletes) a Flow Director entry from
  2255. * the hlist of the corresponding PF
  2256. *
  2257. * Returns 0 on success
  2258. **/
  2259. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2260. struct i40e_fdir_filter *input,
  2261. u16 sw_idx,
  2262. struct ethtool_rxnfc *cmd)
  2263. {
  2264. struct i40e_fdir_filter *rule, *parent;
  2265. struct i40e_pf *pf = vsi->back;
  2266. struct hlist_node *node2;
  2267. int err = -EINVAL;
  2268. parent = NULL;
  2269. rule = NULL;
  2270. hlist_for_each_entry_safe(rule, node2,
  2271. &pf->fdir_filter_list, fdir_node) {
  2272. /* hash found, or no matching entry */
  2273. if (rule->fd_id >= sw_idx)
  2274. break;
  2275. parent = rule;
  2276. }
  2277. /* if there is an old rule occupying our place remove it */
  2278. if (rule && (rule->fd_id == sw_idx)) {
  2279. if (input && !i40e_match_fdir_input_set(rule, input))
  2280. err = i40e_add_del_fdir(vsi, rule, false);
  2281. else if (!input)
  2282. err = i40e_add_del_fdir(vsi, rule, false);
  2283. hlist_del(&rule->fdir_node);
  2284. kfree(rule);
  2285. pf->fdir_pf_active_filters--;
  2286. }
  2287. /* If no input this was a delete, err should be 0 if a rule was
  2288. * successfully found and removed from the list else -EINVAL
  2289. */
  2290. if (!input)
  2291. return err;
  2292. /* initialize node and set software index */
  2293. INIT_HLIST_NODE(&input->fdir_node);
  2294. /* add filter to the list */
  2295. if (parent)
  2296. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2297. else
  2298. hlist_add_head(&input->fdir_node,
  2299. &pf->fdir_filter_list);
  2300. /* update counts */
  2301. pf->fdir_pf_active_filters++;
  2302. return 0;
  2303. }
  2304. /**
  2305. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2306. * @vsi: Pointer to the targeted VSI
  2307. * @cmd: The command to get or set Rx flow classification rules
  2308. *
  2309. * The function removes a Flow Director filter entry from the
  2310. * hlist of the corresponding PF
  2311. *
  2312. * Returns 0 on success
  2313. */
  2314. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2315. struct ethtool_rxnfc *cmd)
  2316. {
  2317. struct ethtool_rx_flow_spec *fsp =
  2318. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2319. struct i40e_pf *pf = vsi->back;
  2320. int ret = 0;
  2321. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2322. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2323. return -EBUSY;
  2324. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2325. return -EBUSY;
  2326. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2327. i40e_fdir_check_and_reenable(pf);
  2328. return ret;
  2329. }
  2330. /**
  2331. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  2332. * @vsi: pointer to the targeted VSI
  2333. * @cmd: command to get or set RX flow classification rules
  2334. *
  2335. * Add Flow Director filters for a specific flow spec based on their
  2336. * protocol. Returns 0 if the filters were successfully added.
  2337. **/
  2338. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  2339. struct ethtool_rxnfc *cmd)
  2340. {
  2341. struct ethtool_rx_flow_spec *fsp;
  2342. struct i40e_fdir_filter *input;
  2343. struct i40e_pf *pf;
  2344. int ret = -EINVAL;
  2345. u16 vf_id;
  2346. if (!vsi)
  2347. return -EINVAL;
  2348. pf = vsi->back;
  2349. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2350. return -EOPNOTSUPP;
  2351. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  2352. return -ENOSPC;
  2353. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2354. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2355. return -EBUSY;
  2356. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2357. return -EBUSY;
  2358. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  2359. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  2360. pf->hw.func_caps.fd_filters_guaranteed)) {
  2361. return -EINVAL;
  2362. }
  2363. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  2364. (fsp->ring_cookie >= vsi->num_queue_pairs))
  2365. return -EINVAL;
  2366. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2367. if (!input)
  2368. return -ENOMEM;
  2369. input->fd_id = fsp->location;
  2370. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  2371. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2372. else
  2373. input->dest_ctl =
  2374. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2375. input->q_index = fsp->ring_cookie;
  2376. input->flex_off = 0;
  2377. input->pctype = 0;
  2378. input->dest_vsi = vsi->id;
  2379. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2380. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  2381. input->flow_type = fsp->flow_type;
  2382. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2383. /* Reverse the src and dest notion, since the HW expects them to be from
  2384. * Tx perspective where as the input from user is from Rx filter view.
  2385. */
  2386. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2387. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2388. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2389. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2390. if (ntohl(fsp->m_ext.data[1])) {
  2391. vf_id = ntohl(fsp->h_ext.data[1]);
  2392. if (vf_id >= pf->num_alloc_vfs) {
  2393. netif_info(pf, drv, vsi->netdev,
  2394. "Invalid VF id %d\n", vf_id);
  2395. goto free_input;
  2396. }
  2397. /* Find vsi id from vf id and override dest vsi */
  2398. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2399. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2400. netif_info(pf, drv, vsi->netdev,
  2401. "Invalid queue id %d for VF %d\n",
  2402. input->q_index, vf_id);
  2403. goto free_input;
  2404. }
  2405. }
  2406. ret = i40e_add_del_fdir(vsi, input, true);
  2407. free_input:
  2408. if (ret)
  2409. kfree(input);
  2410. else
  2411. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2412. return ret;
  2413. }
  2414. /**
  2415. * i40e_set_rxnfc - command to set RX flow classification rules
  2416. * @netdev: network interface device structure
  2417. * @cmd: ethtool rxnfc command
  2418. *
  2419. * Returns Success if the command is supported.
  2420. **/
  2421. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2422. {
  2423. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2424. struct i40e_vsi *vsi = np->vsi;
  2425. struct i40e_pf *pf = vsi->back;
  2426. int ret = -EOPNOTSUPP;
  2427. switch (cmd->cmd) {
  2428. case ETHTOOL_SRXFH:
  2429. ret = i40e_set_rss_hash_opt(pf, cmd);
  2430. break;
  2431. case ETHTOOL_SRXCLSRLINS:
  2432. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2433. break;
  2434. case ETHTOOL_SRXCLSRLDEL:
  2435. ret = i40e_del_fdir_entry(vsi, cmd);
  2436. break;
  2437. default:
  2438. break;
  2439. }
  2440. return ret;
  2441. }
  2442. /**
  2443. * i40e_max_channels - get Max number of combined channels supported
  2444. * @vsi: vsi pointer
  2445. **/
  2446. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2447. {
  2448. /* TODO: This code assumes DCB and FD is disabled for now. */
  2449. return vsi->alloc_queue_pairs;
  2450. }
  2451. /**
  2452. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2453. * @netdev: network interface device structure
  2454. * @ch: ethtool channels structure
  2455. *
  2456. * We don't support separate tx and rx queues as channels. The other count
  2457. * represents how many queues are being used for control. max_combined counts
  2458. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2459. * q_vectors since we support a lot more queue pairs than q_vectors.
  2460. **/
  2461. static void i40e_get_channels(struct net_device *dev,
  2462. struct ethtool_channels *ch)
  2463. {
  2464. struct i40e_netdev_priv *np = netdev_priv(dev);
  2465. struct i40e_vsi *vsi = np->vsi;
  2466. struct i40e_pf *pf = vsi->back;
  2467. /* report maximum channels */
  2468. ch->max_combined = i40e_max_channels(vsi);
  2469. /* report info for other vector */
  2470. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2471. ch->max_other = ch->other_count;
  2472. /* Note: This code assumes DCB is disabled for now. */
  2473. ch->combined_count = vsi->num_queue_pairs;
  2474. }
  2475. /**
  2476. * i40e_set_channels - Set the new channels count.
  2477. * @netdev: network interface device structure
  2478. * @ch: ethtool channels structure
  2479. *
  2480. * The new channels count may not be the same as requested by the user
  2481. * since it gets rounded down to a power of 2 value.
  2482. **/
  2483. static int i40e_set_channels(struct net_device *dev,
  2484. struct ethtool_channels *ch)
  2485. {
  2486. const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2487. struct i40e_netdev_priv *np = netdev_priv(dev);
  2488. unsigned int count = ch->combined_count;
  2489. struct i40e_vsi *vsi = np->vsi;
  2490. struct i40e_pf *pf = vsi->back;
  2491. struct i40e_fdir_filter *rule;
  2492. struct hlist_node *node2;
  2493. int new_count;
  2494. int err = 0;
  2495. /* We do not support setting channels for any other VSI at present */
  2496. if (vsi->type != I40E_VSI_MAIN)
  2497. return -EINVAL;
  2498. /* verify they are not requesting separate vectors */
  2499. if (!count || ch->rx_count || ch->tx_count)
  2500. return -EINVAL;
  2501. /* verify other_count has not changed */
  2502. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2503. return -EINVAL;
  2504. /* verify the number of channels does not exceed hardware limits */
  2505. if (count > i40e_max_channels(vsi))
  2506. return -EINVAL;
  2507. /* verify that the number of channels does not invalidate any current
  2508. * flow director rules
  2509. */
  2510. hlist_for_each_entry_safe(rule, node2,
  2511. &pf->fdir_filter_list, fdir_node) {
  2512. if (rule->dest_ctl != drop && count <= rule->q_index) {
  2513. dev_warn(&pf->pdev->dev,
  2514. "Existing user defined filter %d assigns flow to queue %d\n",
  2515. rule->fd_id, rule->q_index);
  2516. err = -EINVAL;
  2517. }
  2518. }
  2519. if (err) {
  2520. dev_err(&pf->pdev->dev,
  2521. "Existing filter rules must be deleted to reduce combined channel count to %d\n",
  2522. count);
  2523. return err;
  2524. }
  2525. /* update feature limits from largest to smallest supported values */
  2526. /* TODO: Flow director limit, DCB etc */
  2527. /* use rss_reconfig to rebuild with new queue count and update traffic
  2528. * class queue mapping
  2529. */
  2530. new_count = i40e_reconfig_rss_queues(pf, count);
  2531. if (new_count > 0)
  2532. return 0;
  2533. else
  2534. return -EINVAL;
  2535. }
  2536. /**
  2537. * i40e_get_rxfh_key_size - get the RSS hash key size
  2538. * @netdev: network interface device structure
  2539. *
  2540. * Returns the table size.
  2541. **/
  2542. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2543. {
  2544. return I40E_HKEY_ARRAY_SIZE;
  2545. }
  2546. /**
  2547. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2548. * @netdev: network interface device structure
  2549. *
  2550. * Returns the table size.
  2551. **/
  2552. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2553. {
  2554. return I40E_HLUT_ARRAY_SIZE;
  2555. }
  2556. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2557. u8 *hfunc)
  2558. {
  2559. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2560. struct i40e_vsi *vsi = np->vsi;
  2561. u8 *lut, *seed = NULL;
  2562. int ret;
  2563. u16 i;
  2564. if (hfunc)
  2565. *hfunc = ETH_RSS_HASH_TOP;
  2566. if (!indir)
  2567. return 0;
  2568. seed = key;
  2569. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2570. if (!lut)
  2571. return -ENOMEM;
  2572. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  2573. if (ret)
  2574. goto out;
  2575. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2576. indir[i] = (u32)(lut[i]);
  2577. out:
  2578. kfree(lut);
  2579. return ret;
  2580. }
  2581. /**
  2582. * i40e_set_rxfh - set the rx flow hash indirection table
  2583. * @netdev: network interface device structure
  2584. * @indir: indirection table
  2585. * @key: hash key
  2586. *
  2587. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  2588. * returns 0 after programming the table.
  2589. **/
  2590. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2591. const u8 *key, const u8 hfunc)
  2592. {
  2593. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2594. struct i40e_vsi *vsi = np->vsi;
  2595. u8 *seed = NULL;
  2596. u16 i;
  2597. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2598. return -EOPNOTSUPP;
  2599. if (!indir)
  2600. return 0;
  2601. if (key) {
  2602. if (!vsi->rss_hkey_user) {
  2603. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  2604. GFP_KERNEL);
  2605. if (!vsi->rss_hkey_user)
  2606. return -ENOMEM;
  2607. }
  2608. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  2609. seed = vsi->rss_hkey_user;
  2610. }
  2611. if (!vsi->rss_lut_user) {
  2612. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2613. if (!vsi->rss_lut_user)
  2614. return -ENOMEM;
  2615. }
  2616. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  2617. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2618. vsi->rss_lut_user[i] = (u8)(indir[i]);
  2619. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  2620. I40E_HLUT_ARRAY_SIZE);
  2621. }
  2622. /**
  2623. * i40e_get_priv_flags - report device private flags
  2624. * @dev: network interface device structure
  2625. *
  2626. * The get string set count and the string set should be matched for each
  2627. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2628. * array.
  2629. *
  2630. * Returns a u32 bitmap of flags.
  2631. **/
  2632. static u32 i40e_get_priv_flags(struct net_device *dev)
  2633. {
  2634. struct i40e_netdev_priv *np = netdev_priv(dev);
  2635. struct i40e_vsi *vsi = np->vsi;
  2636. struct i40e_pf *pf = vsi->back;
  2637. u32 ret_flags = 0;
  2638. ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
  2639. I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
  2640. ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
  2641. I40E_PRIV_FLAGS_FD_ATR : 0;
  2642. ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
  2643. I40E_PRIV_FLAGS_VEB_STATS : 0;
  2644. ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
  2645. 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
  2646. if (pf->hw.pf_id == 0) {
  2647. ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
  2648. I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
  2649. }
  2650. return ret_flags;
  2651. }
  2652. /**
  2653. * i40e_set_priv_flags - set private flags
  2654. * @dev: network interface device structure
  2655. * @flags: bit flags to be set
  2656. **/
  2657. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  2658. {
  2659. struct i40e_netdev_priv *np = netdev_priv(dev);
  2660. struct i40e_vsi *vsi = np->vsi;
  2661. struct i40e_pf *pf = vsi->back;
  2662. u16 sw_flags = 0, valid_flags = 0;
  2663. bool reset_required = false;
  2664. bool promisc_change = false;
  2665. int ret;
  2666. /* NOTE: MFP is not settable */
  2667. if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
  2668. pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
  2669. else
  2670. pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
  2671. /* allow the user to control the state of the Flow
  2672. * Director ATR (Application Targeted Routing) feature
  2673. * of the driver
  2674. */
  2675. if (flags & I40E_PRIV_FLAGS_FD_ATR) {
  2676. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  2677. } else {
  2678. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  2679. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  2680. }
  2681. if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2682. !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2683. pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
  2684. reset_required = true;
  2685. } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2686. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2687. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  2688. reset_required = true;
  2689. }
  2690. if (pf->hw.pf_id == 0) {
  2691. if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2692. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2693. pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2694. promisc_change = true;
  2695. } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2696. (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2697. pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2698. promisc_change = true;
  2699. }
  2700. }
  2701. if (promisc_change) {
  2702. if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  2703. sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2704. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2705. ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
  2706. NULL);
  2707. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  2708. dev_info(&pf->pdev->dev,
  2709. "couldn't set switch config bits, err %s aq_err %s\n",
  2710. i40e_stat_str(&pf->hw, ret),
  2711. i40e_aq_str(&pf->hw,
  2712. pf->hw.aq.asq_last_status));
  2713. /* not a fatal problem, just keep going */
  2714. }
  2715. }
  2716. if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
  2717. (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
  2718. pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2719. else
  2720. pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2721. /* if needed, issue reset to cause things to take effect */
  2722. if (reset_required)
  2723. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  2724. return 0;
  2725. }
  2726. static const struct ethtool_ops i40e_ethtool_ops = {
  2727. .get_settings = i40e_get_settings,
  2728. .set_settings = i40e_set_settings,
  2729. .get_drvinfo = i40e_get_drvinfo,
  2730. .get_regs_len = i40e_get_regs_len,
  2731. .get_regs = i40e_get_regs,
  2732. .nway_reset = i40e_nway_reset,
  2733. .get_link = ethtool_op_get_link,
  2734. .get_wol = i40e_get_wol,
  2735. .set_wol = i40e_set_wol,
  2736. .set_eeprom = i40e_set_eeprom,
  2737. .get_eeprom_len = i40e_get_eeprom_len,
  2738. .get_eeprom = i40e_get_eeprom,
  2739. .get_ringparam = i40e_get_ringparam,
  2740. .set_ringparam = i40e_set_ringparam,
  2741. .get_pauseparam = i40e_get_pauseparam,
  2742. .set_pauseparam = i40e_set_pauseparam,
  2743. .get_msglevel = i40e_get_msglevel,
  2744. .set_msglevel = i40e_set_msglevel,
  2745. .get_rxnfc = i40e_get_rxnfc,
  2746. .set_rxnfc = i40e_set_rxnfc,
  2747. .self_test = i40e_diag_test,
  2748. .get_strings = i40e_get_strings,
  2749. .set_phys_id = i40e_set_phys_id,
  2750. .get_sset_count = i40e_get_sset_count,
  2751. .get_ethtool_stats = i40e_get_ethtool_stats,
  2752. .get_coalesce = i40e_get_coalesce,
  2753. .set_coalesce = i40e_set_coalesce,
  2754. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2755. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2756. .get_rxfh = i40e_get_rxfh,
  2757. .set_rxfh = i40e_set_rxfh,
  2758. .get_channels = i40e_get_channels,
  2759. .set_channels = i40e_set_channels,
  2760. .get_ts_info = i40e_get_ts_info,
  2761. .get_priv_flags = i40e_get_priv_flags,
  2762. .set_priv_flags = i40e_set_priv_flags,
  2763. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  2764. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  2765. };
  2766. void i40e_set_ethtool_ops(struct net_device *netdev)
  2767. {
  2768. netdev->ethtool_ops = &i40e_ethtool_ops;
  2769. }