i40e_ethtool.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 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. };
  83. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  84. struct ethtool_rxnfc *cmd);
  85. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  86. * but they are separate. This device supports Virtualization, and
  87. * as such might have several netdevs supporting VMDq and FCoE going
  88. * through a single port. The NETDEV_STATs are for individual netdevs
  89. * seen at the top of the stack, and the PF_STATs are for the physical
  90. * function at the bottom of the stack hosting those netdevs.
  91. *
  92. * The PF_STATs are appended to the netdev stats only when ethtool -S
  93. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  94. */
  95. static struct i40e_stats i40e_gstrings_stats[] = {
  96. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  97. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  98. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  99. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  100. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  101. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  102. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  103. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  104. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  105. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  106. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  107. I40E_PF_STAT("crc_errors", stats.crc_errors),
  108. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  109. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  110. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  111. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  112. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  113. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  114. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  115. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  116. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  117. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  118. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  119. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  120. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  121. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  122. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  123. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  124. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  125. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  126. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  127. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  128. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  129. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  130. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  131. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  132. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  133. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  134. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  135. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  136. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  137. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  138. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  139. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  140. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  141. /* LPI stats */
  142. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  143. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  144. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  145. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  146. };
  147. #ifdef I40E_FCOE
  148. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  149. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  150. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  151. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  152. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  153. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  154. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  155. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  156. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  157. };
  158. #endif /* I40E_FCOE */
  159. #define I40E_QUEUE_STATS_LEN(n) \
  160. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  161. * 2 /* Tx and Rx together */ \
  162. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  163. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  164. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  165. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  166. #ifdef I40E_FCOE
  167. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  168. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  169. I40E_FCOE_STATS_LEN + \
  170. I40E_MISC_STATS_LEN + \
  171. I40E_QUEUE_STATS_LEN((n)))
  172. #else
  173. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  174. I40E_MISC_STATS_LEN + \
  175. I40E_QUEUE_STATS_LEN((n)))
  176. #endif /* I40E_FCOE */
  177. #define I40E_PFC_STATS_LEN ( \
  178. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  179. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  180. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  181. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  182. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  183. / sizeof(u64))
  184. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  185. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  186. I40E_PFC_STATS_LEN + \
  187. I40E_VSI_STATS_LEN((n)))
  188. enum i40e_ethtool_test_id {
  189. I40E_ETH_TEST_REG = 0,
  190. I40E_ETH_TEST_EEPROM,
  191. I40E_ETH_TEST_INTR,
  192. I40E_ETH_TEST_LOOPBACK,
  193. I40E_ETH_TEST_LINK,
  194. };
  195. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  196. "Register test (offline)",
  197. "Eeprom test (offline)",
  198. "Interrupt test (offline)",
  199. "Loopback test (offline)",
  200. "Link test (on/offline)"
  201. };
  202. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  203. /**
  204. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  205. * @pf: the PF struct
  206. **/
  207. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  208. {
  209. dev_info(&pf->pdev->dev,
  210. "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");
  211. }
  212. /**
  213. * i40e_get_settings - Get Link Speed and Duplex settings
  214. * @netdev: network interface device structure
  215. * @ecmd: ethtool command
  216. *
  217. * Reports speed/duplex settings based on media_type
  218. **/
  219. static int i40e_get_settings(struct net_device *netdev,
  220. struct ethtool_cmd *ecmd)
  221. {
  222. struct i40e_netdev_priv *np = netdev_priv(netdev);
  223. struct i40e_pf *pf = np->vsi->back;
  224. struct i40e_hw *hw = &pf->hw;
  225. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  226. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  227. u32 link_speed = hw_link_info->link_speed;
  228. /* hardware is either in 40G mode or 10G mode
  229. * NOTE: this section initializes supported and advertising
  230. */
  231. if (!link_up) {
  232. /* link is down and the driver needs to fall back on
  233. * device ID to determine what kinds of info to display,
  234. * it's mostly a guess that may change when link is up
  235. */
  236. switch (hw->device_id) {
  237. case I40E_DEV_ID_QSFP_A:
  238. case I40E_DEV_ID_QSFP_B:
  239. case I40E_DEV_ID_QSFP_C:
  240. /* pluggable QSFP */
  241. ecmd->supported = SUPPORTED_40000baseSR4_Full |
  242. SUPPORTED_40000baseCR4_Full |
  243. SUPPORTED_40000baseLR4_Full;
  244. ecmd->advertising = ADVERTISED_40000baseSR4_Full |
  245. ADVERTISED_40000baseCR4_Full |
  246. ADVERTISED_40000baseLR4_Full;
  247. break;
  248. case I40E_DEV_ID_KX_B:
  249. /* backplane 40G */
  250. ecmd->supported = SUPPORTED_40000baseKR4_Full;
  251. ecmd->advertising = ADVERTISED_40000baseKR4_Full;
  252. break;
  253. case I40E_DEV_ID_KX_C:
  254. /* backplane 10G */
  255. ecmd->supported = SUPPORTED_10000baseKR_Full;
  256. ecmd->advertising = ADVERTISED_10000baseKR_Full;
  257. break;
  258. case I40E_DEV_ID_10G_BASE_T:
  259. ecmd->supported = SUPPORTED_10000baseT_Full |
  260. SUPPORTED_1000baseT_Full |
  261. SUPPORTED_100baseT_Full;
  262. ecmd->advertising = ADVERTISED_10000baseT_Full |
  263. ADVERTISED_1000baseT_Full |
  264. ADVERTISED_100baseT_Full;
  265. break;
  266. default:
  267. /* all the rest are 10G/1G */
  268. ecmd->supported = SUPPORTED_10000baseT_Full |
  269. SUPPORTED_1000baseT_Full;
  270. ecmd->advertising = ADVERTISED_10000baseT_Full |
  271. ADVERTISED_1000baseT_Full;
  272. break;
  273. }
  274. /* skip phy_type use as it is zero when link is down */
  275. goto no_valid_phy_type;
  276. }
  277. switch (hw_link_info->phy_type) {
  278. case I40E_PHY_TYPE_40GBASE_CR4:
  279. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  280. ecmd->supported = SUPPORTED_Autoneg |
  281. SUPPORTED_40000baseCR4_Full;
  282. ecmd->advertising = ADVERTISED_Autoneg |
  283. ADVERTISED_40000baseCR4_Full;
  284. break;
  285. case I40E_PHY_TYPE_40GBASE_KR4:
  286. ecmd->supported = SUPPORTED_Autoneg |
  287. SUPPORTED_40000baseKR4_Full;
  288. ecmd->advertising = ADVERTISED_Autoneg |
  289. ADVERTISED_40000baseKR4_Full;
  290. break;
  291. case I40E_PHY_TYPE_40GBASE_SR4:
  292. case I40E_PHY_TYPE_XLPPI:
  293. case I40E_PHY_TYPE_XLAUI:
  294. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  295. break;
  296. case I40E_PHY_TYPE_40GBASE_LR4:
  297. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  298. break;
  299. case I40E_PHY_TYPE_10GBASE_KX4:
  300. ecmd->supported = SUPPORTED_Autoneg |
  301. SUPPORTED_10000baseKX4_Full;
  302. ecmd->advertising = ADVERTISED_Autoneg |
  303. ADVERTISED_10000baseKX4_Full;
  304. break;
  305. case I40E_PHY_TYPE_10GBASE_KR:
  306. ecmd->supported = SUPPORTED_Autoneg |
  307. SUPPORTED_10000baseKR_Full;
  308. ecmd->advertising = ADVERTISED_Autoneg |
  309. ADVERTISED_10000baseKR_Full;
  310. break;
  311. case I40E_PHY_TYPE_10GBASE_SR:
  312. case I40E_PHY_TYPE_10GBASE_LR:
  313. case I40E_PHY_TYPE_1000BASE_SX:
  314. case I40E_PHY_TYPE_1000BASE_LX:
  315. ecmd->supported = SUPPORTED_10000baseT_Full;
  316. ecmd->supported |= SUPPORTED_1000baseT_Full;
  317. break;
  318. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  319. case I40E_PHY_TYPE_10GBASE_CR1:
  320. case I40E_PHY_TYPE_10GBASE_T:
  321. ecmd->supported = SUPPORTED_Autoneg |
  322. SUPPORTED_10000baseT_Full |
  323. SUPPORTED_1000baseT_Full |
  324. SUPPORTED_100baseT_Full;
  325. ecmd->advertising = ADVERTISED_Autoneg |
  326. ADVERTISED_10000baseT_Full |
  327. ADVERTISED_1000baseT_Full |
  328. ADVERTISED_100baseT_Full;
  329. break;
  330. case I40E_PHY_TYPE_XAUI:
  331. case I40E_PHY_TYPE_XFI:
  332. case I40E_PHY_TYPE_SFI:
  333. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  334. ecmd->supported = SUPPORTED_10000baseT_Full;
  335. break;
  336. case I40E_PHY_TYPE_1000BASE_KX:
  337. case I40E_PHY_TYPE_1000BASE_T:
  338. ecmd->supported = SUPPORTED_Autoneg |
  339. SUPPORTED_10000baseT_Full |
  340. SUPPORTED_1000baseT_Full |
  341. SUPPORTED_100baseT_Full;
  342. ecmd->advertising = ADVERTISED_Autoneg |
  343. ADVERTISED_10000baseT_Full |
  344. ADVERTISED_1000baseT_Full |
  345. ADVERTISED_100baseT_Full;
  346. break;
  347. case I40E_PHY_TYPE_100BASE_TX:
  348. ecmd->supported = SUPPORTED_Autoneg |
  349. SUPPORTED_10000baseT_Full |
  350. SUPPORTED_1000baseT_Full |
  351. SUPPORTED_100baseT_Full;
  352. ecmd->advertising = ADVERTISED_Autoneg |
  353. ADVERTISED_10000baseT_Full |
  354. ADVERTISED_1000baseT_Full |
  355. ADVERTISED_100baseT_Full;
  356. break;
  357. case I40E_PHY_TYPE_SGMII:
  358. ecmd->supported = SUPPORTED_Autoneg |
  359. SUPPORTED_1000baseT_Full |
  360. SUPPORTED_100baseT_Full;
  361. ecmd->advertising = ADVERTISED_Autoneg |
  362. ADVERTISED_1000baseT_Full |
  363. ADVERTISED_100baseT_Full;
  364. break;
  365. default:
  366. /* if we got here and link is up something bad is afoot */
  367. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  368. hw_link_info->phy_type);
  369. }
  370. no_valid_phy_type:
  371. /* this is if autoneg is enabled or disabled */
  372. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  373. AUTONEG_ENABLE : AUTONEG_DISABLE);
  374. switch (hw->phy.media_type) {
  375. case I40E_MEDIA_TYPE_BACKPLANE:
  376. ecmd->supported |= SUPPORTED_Autoneg |
  377. SUPPORTED_Backplane;
  378. ecmd->advertising |= ADVERTISED_Autoneg |
  379. ADVERTISED_Backplane;
  380. ecmd->port = PORT_NONE;
  381. break;
  382. case I40E_MEDIA_TYPE_BASET:
  383. ecmd->supported |= SUPPORTED_TP;
  384. ecmd->advertising |= ADVERTISED_TP;
  385. ecmd->port = PORT_TP;
  386. break;
  387. case I40E_MEDIA_TYPE_DA:
  388. case I40E_MEDIA_TYPE_CX4:
  389. ecmd->supported |= SUPPORTED_FIBRE;
  390. ecmd->advertising |= ADVERTISED_FIBRE;
  391. ecmd->port = PORT_DA;
  392. break;
  393. case I40E_MEDIA_TYPE_FIBER:
  394. ecmd->supported |= SUPPORTED_FIBRE;
  395. ecmd->port = PORT_FIBRE;
  396. break;
  397. case I40E_MEDIA_TYPE_UNKNOWN:
  398. default:
  399. ecmd->port = PORT_OTHER;
  400. break;
  401. }
  402. ecmd->transceiver = XCVR_EXTERNAL;
  403. ecmd->supported |= SUPPORTED_Pause;
  404. switch (hw->fc.current_mode) {
  405. case I40E_FC_FULL:
  406. ecmd->advertising |= ADVERTISED_Pause;
  407. break;
  408. case I40E_FC_TX_PAUSE:
  409. ecmd->advertising |= ADVERTISED_Asym_Pause;
  410. break;
  411. case I40E_FC_RX_PAUSE:
  412. ecmd->advertising |= (ADVERTISED_Pause |
  413. ADVERTISED_Asym_Pause);
  414. break;
  415. default:
  416. ecmd->advertising &= ~(ADVERTISED_Pause |
  417. ADVERTISED_Asym_Pause);
  418. break;
  419. }
  420. if (link_up) {
  421. switch (link_speed) {
  422. case I40E_LINK_SPEED_40GB:
  423. /* need a SPEED_40000 in ethtool.h */
  424. ethtool_cmd_speed_set(ecmd, 40000);
  425. break;
  426. case I40E_LINK_SPEED_10GB:
  427. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  428. break;
  429. case I40E_LINK_SPEED_1GB:
  430. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  431. break;
  432. case I40E_LINK_SPEED_100MB:
  433. ethtool_cmd_speed_set(ecmd, SPEED_100);
  434. break;
  435. default:
  436. break;
  437. }
  438. ecmd->duplex = DUPLEX_FULL;
  439. } else {
  440. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  441. ecmd->duplex = DUPLEX_UNKNOWN;
  442. }
  443. return 0;
  444. }
  445. /**
  446. * i40e_set_settings - Set Speed and Duplex
  447. * @netdev: network interface device structure
  448. * @ecmd: ethtool command
  449. *
  450. * Set speed/duplex per media_types advertised/forced
  451. **/
  452. static int i40e_set_settings(struct net_device *netdev,
  453. struct ethtool_cmd *ecmd)
  454. {
  455. struct i40e_netdev_priv *np = netdev_priv(netdev);
  456. struct i40e_aq_get_phy_abilities_resp abilities;
  457. struct i40e_aq_set_phy_config config;
  458. struct i40e_pf *pf = np->vsi->back;
  459. struct i40e_vsi *vsi = np->vsi;
  460. struct i40e_hw *hw = &pf->hw;
  461. struct ethtool_cmd safe_ecmd;
  462. i40e_status status = 0;
  463. bool change = false;
  464. int err = 0;
  465. u8 autoneg;
  466. u32 advertise;
  467. /* Changing port settings is not supported if this isn't the
  468. * port's controlling PF
  469. */
  470. if (hw->partition_id != 1) {
  471. i40e_partition_setting_complaint(pf);
  472. return -EOPNOTSUPP;
  473. }
  474. if (vsi != pf->vsi[pf->lan_vsi])
  475. return -EOPNOTSUPP;
  476. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  477. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  478. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  479. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  480. return -EOPNOTSUPP;
  481. /* get our own copy of the bits to check against */
  482. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  483. i40e_get_settings(netdev, &safe_ecmd);
  484. /* save autoneg and speed out of ecmd */
  485. autoneg = ecmd->autoneg;
  486. advertise = ecmd->advertising;
  487. /* set autoneg and speed back to what they currently are */
  488. ecmd->autoneg = safe_ecmd.autoneg;
  489. ecmd->advertising = safe_ecmd.advertising;
  490. ecmd->cmd = safe_ecmd.cmd;
  491. /* If ecmd and safe_ecmd are not the same now, then they are
  492. * trying to set something that we do not support
  493. */
  494. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  495. return -EOPNOTSUPP;
  496. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  497. usleep_range(1000, 2000);
  498. /* Get the current phy config */
  499. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  500. NULL);
  501. if (status)
  502. return -EAGAIN;
  503. /* Copy abilities to config in case autoneg is not
  504. * set below
  505. */
  506. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  507. config.abilities = abilities.abilities;
  508. /* Check autoneg */
  509. if (autoneg == AUTONEG_ENABLE) {
  510. /* If autoneg is not supported, return error */
  511. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  512. netdev_info(netdev, "Autoneg not supported on this phy\n");
  513. return -EINVAL;
  514. }
  515. /* If autoneg was not already enabled */
  516. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  517. config.abilities = abilities.abilities |
  518. I40E_AQ_PHY_ENABLE_AN;
  519. change = true;
  520. }
  521. } else {
  522. /* If autoneg is supported 10GBASE_T is the only phy that
  523. * can disable it, so otherwise return error
  524. */
  525. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  526. hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
  527. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  528. return -EINVAL;
  529. }
  530. /* If autoneg is currently enabled */
  531. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  532. config.abilities = abilities.abilities &
  533. ~I40E_AQ_PHY_ENABLE_AN;
  534. change = true;
  535. }
  536. }
  537. if (advertise & ~safe_ecmd.supported)
  538. return -EINVAL;
  539. if (advertise & ADVERTISED_100baseT_Full)
  540. config.link_speed |= I40E_LINK_SPEED_100MB;
  541. if (advertise & ADVERTISED_1000baseT_Full ||
  542. advertise & ADVERTISED_1000baseKX_Full)
  543. config.link_speed |= I40E_LINK_SPEED_1GB;
  544. if (advertise & ADVERTISED_10000baseT_Full ||
  545. advertise & ADVERTISED_10000baseKX4_Full ||
  546. advertise & ADVERTISED_10000baseKR_Full)
  547. config.link_speed |= I40E_LINK_SPEED_10GB;
  548. if (advertise & ADVERTISED_40000baseKR4_Full ||
  549. advertise & ADVERTISED_40000baseCR4_Full ||
  550. advertise & ADVERTISED_40000baseSR4_Full ||
  551. advertise & ADVERTISED_40000baseLR4_Full)
  552. config.link_speed |= I40E_LINK_SPEED_40GB;
  553. if (change || (abilities.link_speed != config.link_speed)) {
  554. /* copy over the rest of the abilities */
  555. config.phy_type = abilities.phy_type;
  556. config.eee_capability = abilities.eee_capability;
  557. config.eeer = abilities.eeer_val;
  558. config.low_power_ctrl = abilities.d3_lpan;
  559. /* set link and auto negotiation so changes take effect */
  560. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  561. /* If link is up put link down */
  562. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  563. /* Tell the OS link is going down, the link will go
  564. * back up when fw says it is ready asynchronously
  565. */
  566. netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
  567. netif_carrier_off(netdev);
  568. netif_tx_stop_all_queues(netdev);
  569. }
  570. /* make the aq call */
  571. status = i40e_aq_set_phy_config(hw, &config, NULL);
  572. if (status) {
  573. netdev_info(netdev, "Set phy config failed with error %d.\n",
  574. status);
  575. return -EAGAIN;
  576. }
  577. status = i40e_update_link_info(hw, true);
  578. if (status)
  579. netdev_info(netdev, "Updating link info failed with error %d\n",
  580. status);
  581. } else {
  582. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  583. }
  584. return err;
  585. }
  586. static int i40e_nway_reset(struct net_device *netdev)
  587. {
  588. /* restart autonegotiation */
  589. struct i40e_netdev_priv *np = netdev_priv(netdev);
  590. struct i40e_pf *pf = np->vsi->back;
  591. struct i40e_hw *hw = &pf->hw;
  592. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  593. i40e_status ret = 0;
  594. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  595. if (ret) {
  596. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  597. pf->hw.aq.asq_last_status);
  598. return -EIO;
  599. }
  600. return 0;
  601. }
  602. /**
  603. * i40e_get_pauseparam - Get Flow Control status
  604. * Return tx/rx-pause status
  605. **/
  606. static void i40e_get_pauseparam(struct net_device *netdev,
  607. struct ethtool_pauseparam *pause)
  608. {
  609. struct i40e_netdev_priv *np = netdev_priv(netdev);
  610. struct i40e_pf *pf = np->vsi->back;
  611. struct i40e_hw *hw = &pf->hw;
  612. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  613. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  614. pause->autoneg =
  615. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  616. AUTONEG_ENABLE : AUTONEG_DISABLE);
  617. /* PFC enabled so report LFC as off */
  618. if (dcbx_cfg->pfc.pfcenable) {
  619. pause->rx_pause = 0;
  620. pause->tx_pause = 0;
  621. return;
  622. }
  623. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  624. pause->rx_pause = 1;
  625. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  626. pause->tx_pause = 1;
  627. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  628. pause->rx_pause = 1;
  629. pause->tx_pause = 1;
  630. }
  631. }
  632. /**
  633. * i40e_set_pauseparam - Set Flow Control parameter
  634. * @netdev: network interface device structure
  635. * @pause: return tx/rx flow control status
  636. **/
  637. static int i40e_set_pauseparam(struct net_device *netdev,
  638. struct ethtool_pauseparam *pause)
  639. {
  640. struct i40e_netdev_priv *np = netdev_priv(netdev);
  641. struct i40e_pf *pf = np->vsi->back;
  642. struct i40e_vsi *vsi = np->vsi;
  643. struct i40e_hw *hw = &pf->hw;
  644. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  645. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  646. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  647. i40e_status status;
  648. u8 aq_failures;
  649. int err = 0;
  650. /* Changing the port's flow control is not supported if this isn't the
  651. * port's controlling PF
  652. */
  653. if (hw->partition_id != 1) {
  654. i40e_partition_setting_complaint(pf);
  655. return -EOPNOTSUPP;
  656. }
  657. if (vsi != pf->vsi[pf->lan_vsi])
  658. return -EOPNOTSUPP;
  659. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  660. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  661. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  662. return -EOPNOTSUPP;
  663. }
  664. /* If we have link and don't have autoneg */
  665. if (!test_bit(__I40E_DOWN, &pf->state) &&
  666. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  667. /* Send message that it might not necessarily work*/
  668. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  669. }
  670. if (dcbx_cfg->pfc.pfcenable) {
  671. netdev_info(netdev,
  672. "Priority flow control enabled. Cannot set link flow control.\n");
  673. return -EOPNOTSUPP;
  674. }
  675. if (pause->rx_pause && pause->tx_pause)
  676. hw->fc.requested_mode = I40E_FC_FULL;
  677. else if (pause->rx_pause && !pause->tx_pause)
  678. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  679. else if (!pause->rx_pause && pause->tx_pause)
  680. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  681. else if (!pause->rx_pause && !pause->tx_pause)
  682. hw->fc.requested_mode = I40E_FC_NONE;
  683. else
  684. return -EINVAL;
  685. /* Tell the OS link is going down, the link will go back up when fw
  686. * says it is ready asynchronously
  687. */
  688. netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
  689. netif_carrier_off(netdev);
  690. netif_tx_stop_all_queues(netdev);
  691. /* Set the fc mode and only restart an if link is up*/
  692. status = i40e_set_fc(hw, &aq_failures, link_up);
  693. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  694. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
  695. status, hw->aq.asq_last_status);
  696. err = -EAGAIN;
  697. }
  698. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  699. netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
  700. status, hw->aq.asq_last_status);
  701. err = -EAGAIN;
  702. }
  703. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  704. netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
  705. status, hw->aq.asq_last_status);
  706. err = -EAGAIN;
  707. }
  708. if (!test_bit(__I40E_DOWN, &pf->state)) {
  709. /* Give it a little more time to try to come back */
  710. msleep(75);
  711. if (!test_bit(__I40E_DOWN, &pf->state))
  712. return i40e_nway_reset(netdev);
  713. }
  714. return err;
  715. }
  716. static u32 i40e_get_msglevel(struct net_device *netdev)
  717. {
  718. struct i40e_netdev_priv *np = netdev_priv(netdev);
  719. struct i40e_pf *pf = np->vsi->back;
  720. return pf->msg_enable;
  721. }
  722. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  723. {
  724. struct i40e_netdev_priv *np = netdev_priv(netdev);
  725. struct i40e_pf *pf = np->vsi->back;
  726. if (I40E_DEBUG_USER & data)
  727. pf->hw.debug_mask = data;
  728. pf->msg_enable = data;
  729. }
  730. static int i40e_get_regs_len(struct net_device *netdev)
  731. {
  732. int reg_count = 0;
  733. int i;
  734. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  735. reg_count += i40e_reg_list[i].elements;
  736. return reg_count * sizeof(u32);
  737. }
  738. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  739. void *p)
  740. {
  741. struct i40e_netdev_priv *np = netdev_priv(netdev);
  742. struct i40e_pf *pf = np->vsi->back;
  743. struct i40e_hw *hw = &pf->hw;
  744. u32 *reg_buf = p;
  745. int i, j, ri;
  746. u32 reg;
  747. /* Tell ethtool which driver-version-specific regs output we have.
  748. *
  749. * At some point, if we have ethtool doing special formatting of
  750. * this data, it will rely on this version number to know how to
  751. * interpret things. Hence, this needs to be updated if/when the
  752. * diags register table is changed.
  753. */
  754. regs->version = 1;
  755. /* loop through the diags reg table for what to print */
  756. ri = 0;
  757. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  758. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  759. reg = i40e_reg_list[i].offset
  760. + (j * i40e_reg_list[i].stride);
  761. reg_buf[ri++] = rd32(hw, reg);
  762. }
  763. }
  764. }
  765. static int i40e_get_eeprom(struct net_device *netdev,
  766. struct ethtool_eeprom *eeprom, u8 *bytes)
  767. {
  768. struct i40e_netdev_priv *np = netdev_priv(netdev);
  769. struct i40e_hw *hw = &np->vsi->back->hw;
  770. struct i40e_pf *pf = np->vsi->back;
  771. int ret_val = 0, len, offset;
  772. u8 *eeprom_buff;
  773. u16 i, sectors;
  774. bool last;
  775. u32 magic;
  776. #define I40E_NVM_SECTOR_SIZE 4096
  777. if (eeprom->len == 0)
  778. return -EINVAL;
  779. /* check for NVMUpdate access method */
  780. magic = hw->vendor_id | (hw->device_id << 16);
  781. if (eeprom->magic && eeprom->magic != magic) {
  782. struct i40e_nvm_access *cmd;
  783. int errno;
  784. /* make sure it is the right magic for NVMUpdate */
  785. if ((eeprom->magic >> 16) != hw->device_id)
  786. return -EINVAL;
  787. cmd = (struct i40e_nvm_access *)eeprom;
  788. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  789. if (ret_val)
  790. dev_info(&pf->pdev->dev,
  791. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  792. ret_val, hw->aq.asq_last_status, errno,
  793. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  794. cmd->offset, cmd->data_size);
  795. return errno;
  796. }
  797. /* normal ethtool get_eeprom support */
  798. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  799. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  800. if (!eeprom_buff)
  801. return -ENOMEM;
  802. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  803. if (ret_val) {
  804. dev_info(&pf->pdev->dev,
  805. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  806. ret_val, hw->aq.asq_last_status);
  807. goto free_buff;
  808. }
  809. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  810. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  811. len = I40E_NVM_SECTOR_SIZE;
  812. last = false;
  813. for (i = 0; i < sectors; i++) {
  814. if (i == (sectors - 1)) {
  815. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  816. last = true;
  817. }
  818. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  819. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  820. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  821. last, NULL);
  822. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  823. dev_info(&pf->pdev->dev,
  824. "read NVM failed, invalid offset 0x%x\n",
  825. offset);
  826. break;
  827. } else if (ret_val &&
  828. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  829. dev_info(&pf->pdev->dev,
  830. "read NVM failed, access, offset 0x%x\n",
  831. offset);
  832. break;
  833. } else if (ret_val) {
  834. dev_info(&pf->pdev->dev,
  835. "read NVM failed offset %d err=%d status=0x%x\n",
  836. offset, ret_val, hw->aq.asq_last_status);
  837. break;
  838. }
  839. }
  840. i40e_release_nvm(hw);
  841. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  842. free_buff:
  843. kfree(eeprom_buff);
  844. return ret_val;
  845. }
  846. static int i40e_get_eeprom_len(struct net_device *netdev)
  847. {
  848. struct i40e_netdev_priv *np = netdev_priv(netdev);
  849. struct i40e_hw *hw = &np->vsi->back->hw;
  850. u32 val;
  851. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  852. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  853. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  854. /* register returns value in power of 2, 64Kbyte chunks. */
  855. val = (64 * 1024) * (1 << val);
  856. return val;
  857. }
  858. static int i40e_set_eeprom(struct net_device *netdev,
  859. struct ethtool_eeprom *eeprom, u8 *bytes)
  860. {
  861. struct i40e_netdev_priv *np = netdev_priv(netdev);
  862. struct i40e_hw *hw = &np->vsi->back->hw;
  863. struct i40e_pf *pf = np->vsi->back;
  864. struct i40e_nvm_access *cmd;
  865. int ret_val = 0;
  866. int errno;
  867. u32 magic;
  868. /* normal ethtool set_eeprom is not supported */
  869. magic = hw->vendor_id | (hw->device_id << 16);
  870. if (eeprom->magic == magic)
  871. return -EOPNOTSUPP;
  872. /* check for NVMUpdate access method */
  873. if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  874. return -EINVAL;
  875. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  876. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  877. return -EBUSY;
  878. cmd = (struct i40e_nvm_access *)eeprom;
  879. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  880. if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
  881. dev_info(&pf->pdev->dev,
  882. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  883. ret_val, hw->aq.asq_last_status, errno,
  884. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  885. cmd->offset, cmd->data_size);
  886. return errno;
  887. }
  888. static void i40e_get_drvinfo(struct net_device *netdev,
  889. struct ethtool_drvinfo *drvinfo)
  890. {
  891. struct i40e_netdev_priv *np = netdev_priv(netdev);
  892. struct i40e_vsi *vsi = np->vsi;
  893. struct i40e_pf *pf = vsi->back;
  894. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  895. strlcpy(drvinfo->version, i40e_driver_version_str,
  896. sizeof(drvinfo->version));
  897. strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
  898. sizeof(drvinfo->fw_version));
  899. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  900. sizeof(drvinfo->bus_info));
  901. }
  902. static void i40e_get_ringparam(struct net_device *netdev,
  903. struct ethtool_ringparam *ring)
  904. {
  905. struct i40e_netdev_priv *np = netdev_priv(netdev);
  906. struct i40e_pf *pf = np->vsi->back;
  907. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  908. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  909. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  910. ring->rx_mini_max_pending = 0;
  911. ring->rx_jumbo_max_pending = 0;
  912. ring->rx_pending = vsi->rx_rings[0]->count;
  913. ring->tx_pending = vsi->tx_rings[0]->count;
  914. ring->rx_mini_pending = 0;
  915. ring->rx_jumbo_pending = 0;
  916. }
  917. static int i40e_set_ringparam(struct net_device *netdev,
  918. struct ethtool_ringparam *ring)
  919. {
  920. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  921. struct i40e_netdev_priv *np = netdev_priv(netdev);
  922. struct i40e_vsi *vsi = np->vsi;
  923. struct i40e_pf *pf = vsi->back;
  924. u32 new_rx_count, new_tx_count;
  925. int i, err = 0;
  926. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  927. return -EINVAL;
  928. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  929. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  930. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  931. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  932. netdev_info(netdev,
  933. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  934. ring->tx_pending, ring->rx_pending,
  935. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  936. return -EINVAL;
  937. }
  938. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  939. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  940. /* if nothing to do return success */
  941. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  942. (new_rx_count == vsi->rx_rings[0]->count))
  943. return 0;
  944. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  945. usleep_range(1000, 2000);
  946. if (!netif_running(vsi->netdev)) {
  947. /* simple case - set for the next time the netdev is started */
  948. for (i = 0; i < vsi->num_queue_pairs; i++) {
  949. vsi->tx_rings[i]->count = new_tx_count;
  950. vsi->rx_rings[i]->count = new_rx_count;
  951. }
  952. goto done;
  953. }
  954. /* We can't just free everything and then setup again,
  955. * because the ISRs in MSI-X mode get passed pointers
  956. * to the Tx and Rx ring structs.
  957. */
  958. /* alloc updated Tx resources */
  959. if (new_tx_count != vsi->tx_rings[0]->count) {
  960. netdev_info(netdev,
  961. "Changing Tx descriptor count from %d to %d.\n",
  962. vsi->tx_rings[0]->count, new_tx_count);
  963. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  964. sizeof(struct i40e_ring), GFP_KERNEL);
  965. if (!tx_rings) {
  966. err = -ENOMEM;
  967. goto done;
  968. }
  969. for (i = 0; i < vsi->num_queue_pairs; i++) {
  970. /* clone ring and setup updated count */
  971. tx_rings[i] = *vsi->tx_rings[i];
  972. tx_rings[i].count = new_tx_count;
  973. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  974. if (err) {
  975. while (i) {
  976. i--;
  977. i40e_free_tx_resources(&tx_rings[i]);
  978. }
  979. kfree(tx_rings);
  980. tx_rings = NULL;
  981. goto done;
  982. }
  983. }
  984. }
  985. /* alloc updated Rx resources */
  986. if (new_rx_count != vsi->rx_rings[0]->count) {
  987. netdev_info(netdev,
  988. "Changing Rx descriptor count from %d to %d\n",
  989. vsi->rx_rings[0]->count, new_rx_count);
  990. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  991. sizeof(struct i40e_ring), GFP_KERNEL);
  992. if (!rx_rings) {
  993. err = -ENOMEM;
  994. goto free_tx;
  995. }
  996. for (i = 0; i < vsi->num_queue_pairs; i++) {
  997. /* clone ring and setup updated count */
  998. rx_rings[i] = *vsi->rx_rings[i];
  999. rx_rings[i].count = new_rx_count;
  1000. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1001. if (err) {
  1002. while (i) {
  1003. i--;
  1004. i40e_free_rx_resources(&rx_rings[i]);
  1005. }
  1006. kfree(rx_rings);
  1007. rx_rings = NULL;
  1008. goto free_tx;
  1009. }
  1010. }
  1011. }
  1012. /* Bring interface down, copy in the new ring info,
  1013. * then restore the interface
  1014. */
  1015. i40e_down(vsi);
  1016. if (tx_rings) {
  1017. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1018. i40e_free_tx_resources(vsi->tx_rings[i]);
  1019. *vsi->tx_rings[i] = tx_rings[i];
  1020. }
  1021. kfree(tx_rings);
  1022. tx_rings = NULL;
  1023. }
  1024. if (rx_rings) {
  1025. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1026. i40e_free_rx_resources(vsi->rx_rings[i]);
  1027. *vsi->rx_rings[i] = rx_rings[i];
  1028. }
  1029. kfree(rx_rings);
  1030. rx_rings = NULL;
  1031. }
  1032. i40e_up(vsi);
  1033. free_tx:
  1034. /* error cleanup if the Rx allocations failed after getting Tx */
  1035. if (tx_rings) {
  1036. for (i = 0; i < vsi->num_queue_pairs; i++)
  1037. i40e_free_tx_resources(&tx_rings[i]);
  1038. kfree(tx_rings);
  1039. tx_rings = NULL;
  1040. }
  1041. done:
  1042. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1043. return err;
  1044. }
  1045. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1046. {
  1047. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1048. struct i40e_vsi *vsi = np->vsi;
  1049. struct i40e_pf *pf = vsi->back;
  1050. switch (sset) {
  1051. case ETH_SS_TEST:
  1052. return I40E_TEST_LEN;
  1053. case ETH_SS_STATS:
  1054. if (vsi == pf->vsi[pf->lan_vsi]) {
  1055. int len = I40E_PF_STATS_LEN(netdev);
  1056. if (pf->lan_veb != I40E_NO_VEB)
  1057. len += I40E_VEB_STATS_LEN;
  1058. return len;
  1059. } else {
  1060. return I40E_VSI_STATS_LEN(netdev);
  1061. }
  1062. default:
  1063. return -EOPNOTSUPP;
  1064. }
  1065. }
  1066. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1067. struct ethtool_stats *stats, u64 *data)
  1068. {
  1069. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1070. struct i40e_ring *tx_ring, *rx_ring;
  1071. struct i40e_vsi *vsi = np->vsi;
  1072. struct i40e_pf *pf = vsi->back;
  1073. int i = 0;
  1074. char *p;
  1075. int j;
  1076. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1077. unsigned int start;
  1078. i40e_update_stats(vsi);
  1079. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1080. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1081. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1082. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1083. }
  1084. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1085. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1086. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1087. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1088. }
  1089. #ifdef I40E_FCOE
  1090. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1091. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1092. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1093. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1094. }
  1095. #endif
  1096. rcu_read_lock();
  1097. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1098. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1099. if (!tx_ring)
  1100. continue;
  1101. /* process Tx ring statistics */
  1102. do {
  1103. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1104. data[i] = tx_ring->stats.packets;
  1105. data[i + 1] = tx_ring->stats.bytes;
  1106. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1107. i += 2;
  1108. /* Rx ring is the 2nd half of the queue pair */
  1109. rx_ring = &tx_ring[1];
  1110. do {
  1111. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1112. data[i] = rx_ring->stats.packets;
  1113. data[i + 1] = rx_ring->stats.bytes;
  1114. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1115. i += 2;
  1116. }
  1117. rcu_read_unlock();
  1118. if (vsi != pf->vsi[pf->lan_vsi])
  1119. return;
  1120. if (pf->lan_veb != I40E_NO_VEB) {
  1121. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1122. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1123. p = (char *)veb;
  1124. p += i40e_gstrings_veb_stats[j].stat_offset;
  1125. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1126. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1127. }
  1128. }
  1129. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1130. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1131. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1132. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1133. }
  1134. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1135. data[i++] = pf->stats.priority_xon_tx[j];
  1136. data[i++] = pf->stats.priority_xoff_tx[j];
  1137. }
  1138. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1139. data[i++] = pf->stats.priority_xon_rx[j];
  1140. data[i++] = pf->stats.priority_xoff_rx[j];
  1141. }
  1142. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1143. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1144. }
  1145. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1146. u8 *data)
  1147. {
  1148. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1149. struct i40e_vsi *vsi = np->vsi;
  1150. struct i40e_pf *pf = vsi->back;
  1151. char *p = (char *)data;
  1152. int i;
  1153. switch (stringset) {
  1154. case ETH_SS_TEST:
  1155. for (i = 0; i < I40E_TEST_LEN; i++) {
  1156. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1157. data += ETH_GSTRING_LEN;
  1158. }
  1159. break;
  1160. case ETH_SS_STATS:
  1161. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1162. snprintf(p, ETH_GSTRING_LEN, "%s",
  1163. i40e_gstrings_net_stats[i].stat_string);
  1164. p += ETH_GSTRING_LEN;
  1165. }
  1166. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1167. snprintf(p, ETH_GSTRING_LEN, "%s",
  1168. i40e_gstrings_misc_stats[i].stat_string);
  1169. p += ETH_GSTRING_LEN;
  1170. }
  1171. #ifdef I40E_FCOE
  1172. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1173. snprintf(p, ETH_GSTRING_LEN, "%s",
  1174. i40e_gstrings_fcoe_stats[i].stat_string);
  1175. p += ETH_GSTRING_LEN;
  1176. }
  1177. #endif
  1178. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1179. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  1180. p += ETH_GSTRING_LEN;
  1181. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  1182. p += ETH_GSTRING_LEN;
  1183. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  1184. p += ETH_GSTRING_LEN;
  1185. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  1186. p += ETH_GSTRING_LEN;
  1187. }
  1188. if (vsi != pf->vsi[pf->lan_vsi])
  1189. return;
  1190. if (pf->lan_veb != I40E_NO_VEB) {
  1191. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1192. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1193. i40e_gstrings_veb_stats[i].stat_string);
  1194. p += ETH_GSTRING_LEN;
  1195. }
  1196. }
  1197. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1198. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1199. i40e_gstrings_stats[i].stat_string);
  1200. p += ETH_GSTRING_LEN;
  1201. }
  1202. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1203. snprintf(p, ETH_GSTRING_LEN,
  1204. "port.tx_priority_%u_xon", i);
  1205. p += ETH_GSTRING_LEN;
  1206. snprintf(p, ETH_GSTRING_LEN,
  1207. "port.tx_priority_%u_xoff", i);
  1208. p += ETH_GSTRING_LEN;
  1209. }
  1210. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1211. snprintf(p, ETH_GSTRING_LEN,
  1212. "port.rx_priority_%u_xon", i);
  1213. p += ETH_GSTRING_LEN;
  1214. snprintf(p, ETH_GSTRING_LEN,
  1215. "port.rx_priority_%u_xoff", i);
  1216. p += ETH_GSTRING_LEN;
  1217. }
  1218. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1219. snprintf(p, ETH_GSTRING_LEN,
  1220. "port.rx_priority_%u_xon_2_xoff", i);
  1221. p += ETH_GSTRING_LEN;
  1222. }
  1223. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1224. break;
  1225. }
  1226. }
  1227. static int i40e_get_ts_info(struct net_device *dev,
  1228. struct ethtool_ts_info *info)
  1229. {
  1230. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1231. /* only report HW timestamping if PTP is enabled */
  1232. if (!(pf->flags & I40E_FLAG_PTP))
  1233. return ethtool_op_get_ts_info(dev, info);
  1234. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1235. SOF_TIMESTAMPING_RX_SOFTWARE |
  1236. SOF_TIMESTAMPING_SOFTWARE |
  1237. SOF_TIMESTAMPING_TX_HARDWARE |
  1238. SOF_TIMESTAMPING_RX_HARDWARE |
  1239. SOF_TIMESTAMPING_RAW_HARDWARE;
  1240. if (pf->ptp_clock)
  1241. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1242. else
  1243. info->phc_index = -1;
  1244. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  1245. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  1246. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1247. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1248. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1249. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  1250. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1251. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1252. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1253. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1254. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1255. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  1256. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1257. return 0;
  1258. }
  1259. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1260. {
  1261. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1262. struct i40e_pf *pf = np->vsi->back;
  1263. netif_info(pf, hw, netdev, "link test\n");
  1264. if (i40e_get_link_status(&pf->hw))
  1265. *data = 0;
  1266. else
  1267. *data = 1;
  1268. return *data;
  1269. }
  1270. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1271. {
  1272. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1273. struct i40e_pf *pf = np->vsi->back;
  1274. netif_info(pf, hw, netdev, "register test\n");
  1275. *data = i40e_diag_reg_test(&pf->hw);
  1276. return *data;
  1277. }
  1278. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1279. {
  1280. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1281. struct i40e_pf *pf = np->vsi->back;
  1282. netif_info(pf, hw, netdev, "eeprom test\n");
  1283. *data = i40e_diag_eeprom_test(&pf->hw);
  1284. /* forcebly clear the NVM Update state machine */
  1285. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1286. return *data;
  1287. }
  1288. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1289. {
  1290. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1291. struct i40e_pf *pf = np->vsi->back;
  1292. u16 swc_old = pf->sw_int_count;
  1293. netif_info(pf, hw, netdev, "interrupt test\n");
  1294. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1295. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1296. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1297. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1298. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1299. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1300. usleep_range(1000, 2000);
  1301. *data = (swc_old == pf->sw_int_count);
  1302. return *data;
  1303. }
  1304. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1305. {
  1306. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1307. struct i40e_pf *pf = np->vsi->back;
  1308. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1309. *data = 0;
  1310. return *data;
  1311. }
  1312. static void i40e_diag_test(struct net_device *netdev,
  1313. struct ethtool_test *eth_test, u64 *data)
  1314. {
  1315. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1316. struct i40e_pf *pf = np->vsi->back;
  1317. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1318. /* Offline tests */
  1319. netif_info(pf, drv, netdev, "offline testing starting\n");
  1320. set_bit(__I40E_TESTING, &pf->state);
  1321. /* Link test performed before hardware reset
  1322. * so autoneg doesn't interfere with test result
  1323. */
  1324. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1325. eth_test->flags |= ETH_TEST_FL_FAILED;
  1326. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1327. eth_test->flags |= ETH_TEST_FL_FAILED;
  1328. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1329. eth_test->flags |= ETH_TEST_FL_FAILED;
  1330. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1331. eth_test->flags |= ETH_TEST_FL_FAILED;
  1332. /* run reg test last, a reset is required after it */
  1333. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1334. eth_test->flags |= ETH_TEST_FL_FAILED;
  1335. clear_bit(__I40E_TESTING, &pf->state);
  1336. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  1337. } else {
  1338. /* Online tests */
  1339. netif_info(pf, drv, netdev, "online testing starting\n");
  1340. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1341. eth_test->flags |= ETH_TEST_FL_FAILED;
  1342. /* Offline only tests, not run in online; pass by default */
  1343. data[I40E_ETH_TEST_REG] = 0;
  1344. data[I40E_ETH_TEST_EEPROM] = 0;
  1345. data[I40E_ETH_TEST_INTR] = 0;
  1346. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1347. }
  1348. netif_info(pf, drv, netdev, "testing finished\n");
  1349. }
  1350. static void i40e_get_wol(struct net_device *netdev,
  1351. struct ethtool_wolinfo *wol)
  1352. {
  1353. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1354. struct i40e_pf *pf = np->vsi->back;
  1355. struct i40e_hw *hw = &pf->hw;
  1356. u16 wol_nvm_bits;
  1357. /* NVM bit on means WoL disabled for the port */
  1358. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1359. if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
  1360. wol->supported = 0;
  1361. wol->wolopts = 0;
  1362. } else {
  1363. wol->supported = WAKE_MAGIC;
  1364. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1365. }
  1366. }
  1367. /**
  1368. * i40e_set_wol - set the WakeOnLAN configuration
  1369. * @netdev: the netdev in question
  1370. * @wol: the ethtool WoL setting data
  1371. **/
  1372. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1373. {
  1374. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1375. struct i40e_pf *pf = np->vsi->back;
  1376. struct i40e_vsi *vsi = np->vsi;
  1377. struct i40e_hw *hw = &pf->hw;
  1378. u16 wol_nvm_bits;
  1379. /* WoL not supported if this isn't the controlling PF on the port */
  1380. if (hw->partition_id != 1) {
  1381. i40e_partition_setting_complaint(pf);
  1382. return -EOPNOTSUPP;
  1383. }
  1384. if (vsi != pf->vsi[pf->lan_vsi])
  1385. return -EOPNOTSUPP;
  1386. /* NVM bit on means WoL disabled for the port */
  1387. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1388. if (((1 << hw->port) & wol_nvm_bits))
  1389. return -EOPNOTSUPP;
  1390. /* only magic packet is supported */
  1391. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1392. return -EOPNOTSUPP;
  1393. /* is this a new value? */
  1394. if (pf->wol_en != !!wol->wolopts) {
  1395. pf->wol_en = !!wol->wolopts;
  1396. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1397. }
  1398. return 0;
  1399. }
  1400. static int i40e_set_phys_id(struct net_device *netdev,
  1401. enum ethtool_phys_id_state state)
  1402. {
  1403. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1404. struct i40e_pf *pf = np->vsi->back;
  1405. struct i40e_hw *hw = &pf->hw;
  1406. int blink_freq = 2;
  1407. switch (state) {
  1408. case ETHTOOL_ID_ACTIVE:
  1409. pf->led_status = i40e_led_get(hw);
  1410. return blink_freq;
  1411. case ETHTOOL_ID_ON:
  1412. i40e_led_set(hw, 0xF, false);
  1413. break;
  1414. case ETHTOOL_ID_OFF:
  1415. i40e_led_set(hw, 0x0, false);
  1416. break;
  1417. case ETHTOOL_ID_INACTIVE:
  1418. i40e_led_set(hw, pf->led_status, false);
  1419. break;
  1420. }
  1421. return 0;
  1422. }
  1423. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1424. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1425. * 125us (8000 interrupts per second) == ITR(62)
  1426. */
  1427. static int i40e_get_coalesce(struct net_device *netdev,
  1428. struct ethtool_coalesce *ec)
  1429. {
  1430. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1431. struct i40e_vsi *vsi = np->vsi;
  1432. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1433. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1434. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  1435. ec->use_adaptive_rx_coalesce = 1;
  1436. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  1437. ec->use_adaptive_tx_coalesce = 1;
  1438. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1439. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1440. return 0;
  1441. }
  1442. static int i40e_set_coalesce(struct net_device *netdev,
  1443. struct ethtool_coalesce *ec)
  1444. {
  1445. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1446. struct i40e_q_vector *q_vector;
  1447. struct i40e_vsi *vsi = np->vsi;
  1448. struct i40e_pf *pf = vsi->back;
  1449. struct i40e_hw *hw = &pf->hw;
  1450. u16 vector;
  1451. int i;
  1452. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1453. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1454. vector = vsi->base_vector;
  1455. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1456. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1457. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1458. } else if (ec->rx_coalesce_usecs == 0) {
  1459. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1460. if (ec->use_adaptive_rx_coalesce)
  1461. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1462. } else {
  1463. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1464. return -EINVAL;
  1465. }
  1466. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1467. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1468. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1469. } else if (ec->tx_coalesce_usecs == 0) {
  1470. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1471. if (ec->use_adaptive_tx_coalesce)
  1472. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1473. } else {
  1474. netif_info(pf, drv, netdev,
  1475. "Invalid value, tx-usecs range is 0-8160\n");
  1476. return -EINVAL;
  1477. }
  1478. if (ec->use_adaptive_rx_coalesce)
  1479. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1480. else
  1481. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1482. if (ec->use_adaptive_tx_coalesce)
  1483. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1484. else
  1485. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1486. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  1487. q_vector = vsi->q_vectors[i];
  1488. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  1489. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  1490. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  1491. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  1492. i40e_flush(hw);
  1493. }
  1494. return 0;
  1495. }
  1496. /**
  1497. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1498. * @pf: pointer to the physical function struct
  1499. * @cmd: ethtool rxnfc command
  1500. *
  1501. * Returns Success if the flow is supported, else Invalid Input.
  1502. **/
  1503. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1504. {
  1505. cmd->data = 0;
  1506. /* Report default options for RSS on i40e */
  1507. switch (cmd->flow_type) {
  1508. case TCP_V4_FLOW:
  1509. case UDP_V4_FLOW:
  1510. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1511. /* fall through to add IP fields */
  1512. case SCTP_V4_FLOW:
  1513. case AH_ESP_V4_FLOW:
  1514. case AH_V4_FLOW:
  1515. case ESP_V4_FLOW:
  1516. case IPV4_FLOW:
  1517. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1518. break;
  1519. case TCP_V6_FLOW:
  1520. case UDP_V6_FLOW:
  1521. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1522. /* fall through to add IP fields */
  1523. case SCTP_V6_FLOW:
  1524. case AH_ESP_V6_FLOW:
  1525. case AH_V6_FLOW:
  1526. case ESP_V6_FLOW:
  1527. case IPV6_FLOW:
  1528. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1529. break;
  1530. default:
  1531. return -EINVAL;
  1532. }
  1533. return 0;
  1534. }
  1535. /**
  1536. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1537. * @pf: Pointer to the physical function struct
  1538. * @cmd: The command to get or set Rx flow classification rules
  1539. * @rule_locs: Array of used rule locations
  1540. *
  1541. * This function populates both the total and actual rule count of
  1542. * the ethtool flow classification command
  1543. *
  1544. * Returns 0 on success or -EMSGSIZE if entry not found
  1545. **/
  1546. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1547. struct ethtool_rxnfc *cmd,
  1548. u32 *rule_locs)
  1549. {
  1550. struct i40e_fdir_filter *rule;
  1551. struct hlist_node *node2;
  1552. int cnt = 0;
  1553. /* report total rule count */
  1554. cmd->data = i40e_get_fd_cnt_all(pf);
  1555. hlist_for_each_entry_safe(rule, node2,
  1556. &pf->fdir_filter_list, fdir_node) {
  1557. if (cnt == cmd->rule_cnt)
  1558. return -EMSGSIZE;
  1559. rule_locs[cnt] = rule->fd_id;
  1560. cnt++;
  1561. }
  1562. cmd->rule_cnt = cnt;
  1563. return 0;
  1564. }
  1565. /**
  1566. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1567. * @pf: Pointer to the physical function struct
  1568. * @cmd: The command to get or set Rx flow classification rules
  1569. *
  1570. * This function looks up a filter based on the Rx flow classification
  1571. * command and fills the flow spec info for it if found
  1572. *
  1573. * Returns 0 on success or -EINVAL if filter not found
  1574. **/
  1575. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1576. struct ethtool_rxnfc *cmd)
  1577. {
  1578. struct ethtool_rx_flow_spec *fsp =
  1579. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1580. struct i40e_fdir_filter *rule = NULL;
  1581. struct hlist_node *node2;
  1582. hlist_for_each_entry_safe(rule, node2,
  1583. &pf->fdir_filter_list, fdir_node) {
  1584. if (fsp->location <= rule->fd_id)
  1585. break;
  1586. }
  1587. if (!rule || fsp->location != rule->fd_id)
  1588. return -EINVAL;
  1589. fsp->flow_type = rule->flow_type;
  1590. if (fsp->flow_type == IP_USER_FLOW) {
  1591. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1592. fsp->h_u.usr_ip4_spec.proto = 0;
  1593. fsp->m_u.usr_ip4_spec.proto = 0;
  1594. }
  1595. /* Reverse the src and dest notion, since the HW views them from
  1596. * Tx perspective where as the user expects it from Rx filter view.
  1597. */
  1598. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  1599. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  1600. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  1601. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  1602. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  1603. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  1604. else
  1605. fsp->ring_cookie = rule->q_index;
  1606. return 0;
  1607. }
  1608. /**
  1609. * i40e_get_rxnfc - command to get RX flow classification rules
  1610. * @netdev: network interface device structure
  1611. * @cmd: ethtool rxnfc command
  1612. *
  1613. * Returns Success if the command is supported.
  1614. **/
  1615. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1616. u32 *rule_locs)
  1617. {
  1618. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1619. struct i40e_vsi *vsi = np->vsi;
  1620. struct i40e_pf *pf = vsi->back;
  1621. int ret = -EOPNOTSUPP;
  1622. switch (cmd->cmd) {
  1623. case ETHTOOL_GRXRINGS:
  1624. cmd->data = vsi->alloc_queue_pairs;
  1625. ret = 0;
  1626. break;
  1627. case ETHTOOL_GRXFH:
  1628. ret = i40e_get_rss_hash_opts(pf, cmd);
  1629. break;
  1630. case ETHTOOL_GRXCLSRLCNT:
  1631. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1632. /* report total rule count */
  1633. cmd->data = i40e_get_fd_cnt_all(pf);
  1634. ret = 0;
  1635. break;
  1636. case ETHTOOL_GRXCLSRULE:
  1637. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1638. break;
  1639. case ETHTOOL_GRXCLSRLALL:
  1640. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1641. break;
  1642. default:
  1643. break;
  1644. }
  1645. return ret;
  1646. }
  1647. /**
  1648. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1649. * @pf: pointer to the physical function struct
  1650. * @cmd: ethtool rxnfc command
  1651. *
  1652. * Returns Success if the flow input set is supported.
  1653. **/
  1654. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1655. {
  1656. struct i40e_hw *hw = &pf->hw;
  1657. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  1658. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  1659. /* RSS does not support anything other than hashing
  1660. * to queues on src and dst IPs and ports
  1661. */
  1662. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1663. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1664. return -EINVAL;
  1665. /* We need at least the IP SRC and DEST fields for hashing */
  1666. if (!(nfc->data & RXH_IP_SRC) ||
  1667. !(nfc->data & RXH_IP_DST))
  1668. return -EINVAL;
  1669. switch (nfc->flow_type) {
  1670. case TCP_V4_FLOW:
  1671. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1672. case 0:
  1673. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1674. break;
  1675. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1676. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1677. break;
  1678. default:
  1679. return -EINVAL;
  1680. }
  1681. break;
  1682. case TCP_V6_FLOW:
  1683. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1684. case 0:
  1685. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1686. break;
  1687. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1688. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1689. break;
  1690. default:
  1691. return -EINVAL;
  1692. }
  1693. break;
  1694. case UDP_V4_FLOW:
  1695. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1696. case 0:
  1697. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1698. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1699. break;
  1700. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1701. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1702. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1703. break;
  1704. default:
  1705. return -EINVAL;
  1706. }
  1707. break;
  1708. case UDP_V6_FLOW:
  1709. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1710. case 0:
  1711. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1712. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1713. break;
  1714. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1715. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1716. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1717. break;
  1718. default:
  1719. return -EINVAL;
  1720. }
  1721. break;
  1722. case AH_ESP_V4_FLOW:
  1723. case AH_V4_FLOW:
  1724. case ESP_V4_FLOW:
  1725. case SCTP_V4_FLOW:
  1726. if ((nfc->data & RXH_L4_B_0_1) ||
  1727. (nfc->data & RXH_L4_B_2_3))
  1728. return -EINVAL;
  1729. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  1730. break;
  1731. case AH_ESP_V6_FLOW:
  1732. case AH_V6_FLOW:
  1733. case ESP_V6_FLOW:
  1734. case SCTP_V6_FLOW:
  1735. if ((nfc->data & RXH_L4_B_0_1) ||
  1736. (nfc->data & RXH_L4_B_2_3))
  1737. return -EINVAL;
  1738. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  1739. break;
  1740. case IPV4_FLOW:
  1741. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  1742. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  1743. break;
  1744. case IPV6_FLOW:
  1745. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  1746. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  1747. break;
  1748. default:
  1749. return -EINVAL;
  1750. }
  1751. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  1752. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  1753. i40e_flush(hw);
  1754. return 0;
  1755. }
  1756. /**
  1757. * i40e_match_fdir_input_set - Match a new filter against an existing one
  1758. * @rule: The filter already added
  1759. * @input: The new filter to comapre against
  1760. *
  1761. * Returns true if the two input set match
  1762. **/
  1763. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  1764. struct i40e_fdir_filter *input)
  1765. {
  1766. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  1767. (rule->src_ip[0] != input->src_ip[0]) ||
  1768. (rule->dst_port != input->dst_port) ||
  1769. (rule->src_port != input->src_port))
  1770. return false;
  1771. return true;
  1772. }
  1773. /**
  1774. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  1775. * @vsi: Pointer to the targeted VSI
  1776. * @input: The filter to update or NULL to indicate deletion
  1777. * @sw_idx: Software index to the filter
  1778. * @cmd: The command to get or set Rx flow classification rules
  1779. *
  1780. * This function updates (or deletes) a Flow Director entry from
  1781. * the hlist of the corresponding PF
  1782. *
  1783. * Returns 0 on success
  1784. **/
  1785. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  1786. struct i40e_fdir_filter *input,
  1787. u16 sw_idx,
  1788. struct ethtool_rxnfc *cmd)
  1789. {
  1790. struct i40e_fdir_filter *rule, *parent;
  1791. struct i40e_pf *pf = vsi->back;
  1792. struct hlist_node *node2;
  1793. int err = -EINVAL;
  1794. parent = NULL;
  1795. rule = NULL;
  1796. hlist_for_each_entry_safe(rule, node2,
  1797. &pf->fdir_filter_list, fdir_node) {
  1798. /* hash found, or no matching entry */
  1799. if (rule->fd_id >= sw_idx)
  1800. break;
  1801. parent = rule;
  1802. }
  1803. /* if there is an old rule occupying our place remove it */
  1804. if (rule && (rule->fd_id == sw_idx)) {
  1805. if (input && !i40e_match_fdir_input_set(rule, input))
  1806. err = i40e_add_del_fdir(vsi, rule, false);
  1807. else if (!input)
  1808. err = i40e_add_del_fdir(vsi, rule, false);
  1809. hlist_del(&rule->fdir_node);
  1810. kfree(rule);
  1811. pf->fdir_pf_active_filters--;
  1812. }
  1813. /* If no input this was a delete, err should be 0 if a rule was
  1814. * successfully found and removed from the list else -EINVAL
  1815. */
  1816. if (!input)
  1817. return err;
  1818. /* initialize node and set software index */
  1819. INIT_HLIST_NODE(&input->fdir_node);
  1820. /* add filter to the list */
  1821. if (parent)
  1822. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  1823. else
  1824. hlist_add_head(&input->fdir_node,
  1825. &pf->fdir_filter_list);
  1826. /* update counts */
  1827. pf->fdir_pf_active_filters++;
  1828. return 0;
  1829. }
  1830. /**
  1831. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  1832. * @vsi: Pointer to the targeted VSI
  1833. * @cmd: The command to get or set Rx flow classification rules
  1834. *
  1835. * The function removes a Flow Director filter entry from the
  1836. * hlist of the corresponding PF
  1837. *
  1838. * Returns 0 on success
  1839. */
  1840. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  1841. struct ethtool_rxnfc *cmd)
  1842. {
  1843. struct ethtool_rx_flow_spec *fsp =
  1844. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1845. struct i40e_pf *pf = vsi->back;
  1846. int ret = 0;
  1847. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1848. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1849. return -EBUSY;
  1850. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  1851. return -EBUSY;
  1852. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  1853. i40e_fdir_check_and_reenable(pf);
  1854. return ret;
  1855. }
  1856. /**
  1857. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  1858. * @vsi: pointer to the targeted VSI
  1859. * @cmd: command to get or set RX flow classification rules
  1860. *
  1861. * Add Flow Director filters for a specific flow spec based on their
  1862. * protocol. Returns 0 if the filters were successfully added.
  1863. **/
  1864. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  1865. struct ethtool_rxnfc *cmd)
  1866. {
  1867. struct ethtool_rx_flow_spec *fsp;
  1868. struct i40e_fdir_filter *input;
  1869. struct i40e_pf *pf;
  1870. int ret = -EINVAL;
  1871. if (!vsi)
  1872. return -EINVAL;
  1873. pf = vsi->back;
  1874. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1875. return -EOPNOTSUPP;
  1876. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  1877. return -ENOSPC;
  1878. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1879. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1880. return -EBUSY;
  1881. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  1882. return -EBUSY;
  1883. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1884. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  1885. pf->hw.func_caps.fd_filters_guaranteed)) {
  1886. return -EINVAL;
  1887. }
  1888. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  1889. (fsp->ring_cookie >= vsi->num_queue_pairs))
  1890. return -EINVAL;
  1891. input = kzalloc(sizeof(*input), GFP_KERNEL);
  1892. if (!input)
  1893. return -ENOMEM;
  1894. input->fd_id = fsp->location;
  1895. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  1896. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  1897. else
  1898. input->dest_ctl =
  1899. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  1900. input->q_index = fsp->ring_cookie;
  1901. input->flex_off = 0;
  1902. input->pctype = 0;
  1903. input->dest_vsi = vsi->id;
  1904. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  1905. input->cnt_index = pf->fd_sb_cnt_idx;
  1906. input->flow_type = fsp->flow_type;
  1907. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  1908. /* Reverse the src and dest notion, since the HW expects them to be from
  1909. * Tx perspective where as the input from user is from Rx filter view.
  1910. */
  1911. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  1912. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  1913. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  1914. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  1915. ret = i40e_add_del_fdir(vsi, input, true);
  1916. if (ret)
  1917. kfree(input);
  1918. else
  1919. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  1920. return ret;
  1921. }
  1922. /**
  1923. * i40e_set_rxnfc - command to set RX flow classification rules
  1924. * @netdev: network interface device structure
  1925. * @cmd: ethtool rxnfc command
  1926. *
  1927. * Returns Success if the command is supported.
  1928. **/
  1929. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  1930. {
  1931. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1932. struct i40e_vsi *vsi = np->vsi;
  1933. struct i40e_pf *pf = vsi->back;
  1934. int ret = -EOPNOTSUPP;
  1935. switch (cmd->cmd) {
  1936. case ETHTOOL_SRXFH:
  1937. ret = i40e_set_rss_hash_opt(pf, cmd);
  1938. break;
  1939. case ETHTOOL_SRXCLSRLINS:
  1940. ret = i40e_add_fdir_ethtool(vsi, cmd);
  1941. break;
  1942. case ETHTOOL_SRXCLSRLDEL:
  1943. ret = i40e_del_fdir_entry(vsi, cmd);
  1944. break;
  1945. default:
  1946. break;
  1947. }
  1948. return ret;
  1949. }
  1950. /**
  1951. * i40e_max_channels - get Max number of combined channels supported
  1952. * @vsi: vsi pointer
  1953. **/
  1954. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  1955. {
  1956. /* TODO: This code assumes DCB and FD is disabled for now. */
  1957. return vsi->alloc_queue_pairs;
  1958. }
  1959. /**
  1960. * i40e_get_channels - Get the current channels enabled and max supported etc.
  1961. * @netdev: network interface device structure
  1962. * @ch: ethtool channels structure
  1963. *
  1964. * We don't support separate tx and rx queues as channels. The other count
  1965. * represents how many queues are being used for control. max_combined counts
  1966. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  1967. * q_vectors since we support a lot more queue pairs than q_vectors.
  1968. **/
  1969. static void i40e_get_channels(struct net_device *dev,
  1970. struct ethtool_channels *ch)
  1971. {
  1972. struct i40e_netdev_priv *np = netdev_priv(dev);
  1973. struct i40e_vsi *vsi = np->vsi;
  1974. struct i40e_pf *pf = vsi->back;
  1975. /* report maximum channels */
  1976. ch->max_combined = i40e_max_channels(vsi);
  1977. /* report info for other vector */
  1978. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  1979. ch->max_other = ch->other_count;
  1980. /* Note: This code assumes DCB is disabled for now. */
  1981. ch->combined_count = vsi->num_queue_pairs;
  1982. }
  1983. /**
  1984. * i40e_set_channels - Set the new channels count.
  1985. * @netdev: network interface device structure
  1986. * @ch: ethtool channels structure
  1987. *
  1988. * The new channels count may not be the same as requested by the user
  1989. * since it gets rounded down to a power of 2 value.
  1990. **/
  1991. static int i40e_set_channels(struct net_device *dev,
  1992. struct ethtool_channels *ch)
  1993. {
  1994. struct i40e_netdev_priv *np = netdev_priv(dev);
  1995. unsigned int count = ch->combined_count;
  1996. struct i40e_vsi *vsi = np->vsi;
  1997. struct i40e_pf *pf = vsi->back;
  1998. int new_count;
  1999. /* We do not support setting channels for any other VSI at present */
  2000. if (vsi->type != I40E_VSI_MAIN)
  2001. return -EINVAL;
  2002. /* verify they are not requesting separate vectors */
  2003. if (!count || ch->rx_count || ch->tx_count)
  2004. return -EINVAL;
  2005. /* verify other_count has not changed */
  2006. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2007. return -EINVAL;
  2008. /* verify the number of channels does not exceed hardware limits */
  2009. if (count > i40e_max_channels(vsi))
  2010. return -EINVAL;
  2011. /* update feature limits from largest to smallest supported values */
  2012. /* TODO: Flow director limit, DCB etc */
  2013. /* cap RSS limit */
  2014. if (count > pf->rss_size_max)
  2015. count = pf->rss_size_max;
  2016. /* use rss_reconfig to rebuild with new queue count and update traffic
  2017. * class queue mapping
  2018. */
  2019. new_count = i40e_reconfig_rss_queues(pf, count);
  2020. if (new_count > 0)
  2021. return 0;
  2022. else
  2023. return -EINVAL;
  2024. }
  2025. static const struct ethtool_ops i40e_ethtool_ops = {
  2026. .get_settings = i40e_get_settings,
  2027. .set_settings = i40e_set_settings,
  2028. .get_drvinfo = i40e_get_drvinfo,
  2029. .get_regs_len = i40e_get_regs_len,
  2030. .get_regs = i40e_get_regs,
  2031. .nway_reset = i40e_nway_reset,
  2032. .get_link = ethtool_op_get_link,
  2033. .get_wol = i40e_get_wol,
  2034. .set_wol = i40e_set_wol,
  2035. .set_eeprom = i40e_set_eeprom,
  2036. .get_eeprom_len = i40e_get_eeprom_len,
  2037. .get_eeprom = i40e_get_eeprom,
  2038. .get_ringparam = i40e_get_ringparam,
  2039. .set_ringparam = i40e_set_ringparam,
  2040. .get_pauseparam = i40e_get_pauseparam,
  2041. .set_pauseparam = i40e_set_pauseparam,
  2042. .get_msglevel = i40e_get_msglevel,
  2043. .set_msglevel = i40e_set_msglevel,
  2044. .get_rxnfc = i40e_get_rxnfc,
  2045. .set_rxnfc = i40e_set_rxnfc,
  2046. .self_test = i40e_diag_test,
  2047. .get_strings = i40e_get_strings,
  2048. .set_phys_id = i40e_set_phys_id,
  2049. .get_sset_count = i40e_get_sset_count,
  2050. .get_ethtool_stats = i40e_get_ethtool_stats,
  2051. .get_coalesce = i40e_get_coalesce,
  2052. .set_coalesce = i40e_set_coalesce,
  2053. .get_channels = i40e_get_channels,
  2054. .set_channels = i40e_set_channels,
  2055. .get_ts_info = i40e_get_ts_info,
  2056. };
  2057. void i40e_set_ethtool_ops(struct net_device *netdev)
  2058. {
  2059. netdev->ethtool_ops = &i40e_ethtool_ops;
  2060. }