i40e_ethtool.c 67 KB

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