ixgbe_ethtool.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2011 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* ethtool support for ixgbe */
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/uaccess.h>
  29. #include "ixgbe.h"
  30. #define IXGBE_ALL_RAR_ENTRIES 16
  31. enum {NETDEV_STATS, IXGBE_STATS};
  32. struct ixgbe_stats {
  33. char stat_string[ETH_GSTRING_LEN];
  34. int type;
  35. int sizeof_stat;
  36. int stat_offset;
  37. };
  38. #define IXGBE_STAT(m) IXGBE_STATS, \
  39. sizeof(((struct ixgbe_adapter *)0)->m), \
  40. offsetof(struct ixgbe_adapter, m)
  41. #define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \
  42. sizeof(((struct rtnl_link_stats64 *)0)->m), \
  43. offsetof(struct rtnl_link_stats64, m)
  44. static struct ixgbe_stats ixgbe_gstrings_stats[] = {
  45. {"rx_packets", IXGBE_NETDEV_STAT(rx_packets)},
  46. {"tx_packets", IXGBE_NETDEV_STAT(tx_packets)},
  47. {"rx_bytes", IXGBE_NETDEV_STAT(rx_bytes)},
  48. {"tx_bytes", IXGBE_NETDEV_STAT(tx_bytes)},
  49. {"rx_pkts_nic", IXGBE_STAT(stats.gprc)},
  50. {"tx_pkts_nic", IXGBE_STAT(stats.gptc)},
  51. {"rx_bytes_nic", IXGBE_STAT(stats.gorc)},
  52. {"tx_bytes_nic", IXGBE_STAT(stats.gotc)},
  53. {"lsc_int", IXGBE_STAT(lsc_int)},
  54. {"tx_busy", IXGBE_STAT(tx_busy)},
  55. {"non_eop_descs", IXGBE_STAT(non_eop_descs)},
  56. {"rx_errors", IXGBE_NETDEV_STAT(rx_errors)},
  57. {"tx_errors", IXGBE_NETDEV_STAT(tx_errors)},
  58. {"rx_dropped", IXGBE_NETDEV_STAT(rx_dropped)},
  59. {"tx_dropped", IXGBE_NETDEV_STAT(tx_dropped)},
  60. {"multicast", IXGBE_NETDEV_STAT(multicast)},
  61. {"broadcast", IXGBE_STAT(stats.bprc)},
  62. {"rx_no_buffer_count", IXGBE_STAT(stats.rnbc[0]) },
  63. {"collisions", IXGBE_NETDEV_STAT(collisions)},
  64. {"rx_over_errors", IXGBE_NETDEV_STAT(rx_over_errors)},
  65. {"rx_crc_errors", IXGBE_NETDEV_STAT(rx_crc_errors)},
  66. {"rx_frame_errors", IXGBE_NETDEV_STAT(rx_frame_errors)},
  67. {"hw_rsc_aggregated", IXGBE_STAT(rsc_total_count)},
  68. {"hw_rsc_flushed", IXGBE_STAT(rsc_total_flush)},
  69. {"fdir_match", IXGBE_STAT(stats.fdirmatch)},
  70. {"fdir_miss", IXGBE_STAT(stats.fdirmiss)},
  71. {"fdir_overflow", IXGBE_STAT(fdir_overflow)},
  72. {"rx_fifo_errors", IXGBE_NETDEV_STAT(rx_fifo_errors)},
  73. {"rx_missed_errors", IXGBE_NETDEV_STAT(rx_missed_errors)},
  74. {"tx_aborted_errors", IXGBE_NETDEV_STAT(tx_aborted_errors)},
  75. {"tx_carrier_errors", IXGBE_NETDEV_STAT(tx_carrier_errors)},
  76. {"tx_fifo_errors", IXGBE_NETDEV_STAT(tx_fifo_errors)},
  77. {"tx_heartbeat_errors", IXGBE_NETDEV_STAT(tx_heartbeat_errors)},
  78. {"tx_timeout_count", IXGBE_STAT(tx_timeout_count)},
  79. {"tx_restart_queue", IXGBE_STAT(restart_queue)},
  80. {"rx_long_length_errors", IXGBE_STAT(stats.roc)},
  81. {"rx_short_length_errors", IXGBE_STAT(stats.ruc)},
  82. {"tx_flow_control_xon", IXGBE_STAT(stats.lxontxc)},
  83. {"rx_flow_control_xon", IXGBE_STAT(stats.lxonrxc)},
  84. {"tx_flow_control_xoff", IXGBE_STAT(stats.lxofftxc)},
  85. {"rx_flow_control_xoff", IXGBE_STAT(stats.lxoffrxc)},
  86. {"rx_csum_offload_errors", IXGBE_STAT(hw_csum_rx_error)},
  87. {"alloc_rx_page_failed", IXGBE_STAT(alloc_rx_page_failed)},
  88. {"alloc_rx_buff_failed", IXGBE_STAT(alloc_rx_buff_failed)},
  89. {"rx_no_dma_resources", IXGBE_STAT(hw_rx_no_dma_resources)},
  90. {"os2bmc_rx_by_bmc", IXGBE_STAT(stats.o2bgptc)},
  91. {"os2bmc_tx_by_bmc", IXGBE_STAT(stats.b2ospc)},
  92. {"os2bmc_tx_by_host", IXGBE_STAT(stats.o2bspc)},
  93. {"os2bmc_rx_by_host", IXGBE_STAT(stats.b2ogprc)},
  94. #ifdef IXGBE_FCOE
  95. {"fcoe_bad_fccrc", IXGBE_STAT(stats.fccrc)},
  96. {"rx_fcoe_dropped", IXGBE_STAT(stats.fcoerpdc)},
  97. {"rx_fcoe_packets", IXGBE_STAT(stats.fcoeprc)},
  98. {"rx_fcoe_dwords", IXGBE_STAT(stats.fcoedwrc)},
  99. {"tx_fcoe_packets", IXGBE_STAT(stats.fcoeptc)},
  100. {"tx_fcoe_dwords", IXGBE_STAT(stats.fcoedwtc)},
  101. #endif /* IXGBE_FCOE */
  102. };
  103. #define IXGBE_QUEUE_STATS_LEN \
  104. ((((struct ixgbe_adapter *)netdev_priv(netdev))->num_tx_queues + \
  105. ((struct ixgbe_adapter *)netdev_priv(netdev))->num_rx_queues) * \
  106. (sizeof(struct ixgbe_queue_stats) / sizeof(u64)))
  107. #define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats)
  108. #define IXGBE_PB_STATS_LEN ( \
  109. (((struct ixgbe_adapter *)netdev_priv(netdev))->flags & \
  110. IXGBE_FLAG_DCB_ENABLED) ? \
  111. (sizeof(((struct ixgbe_adapter *)0)->stats.pxonrxc) + \
  112. sizeof(((struct ixgbe_adapter *)0)->stats.pxontxc) + \
  113. sizeof(((struct ixgbe_adapter *)0)->stats.pxoffrxc) + \
  114. sizeof(((struct ixgbe_adapter *)0)->stats.pxofftxc)) \
  115. / sizeof(u64) : 0)
  116. #define IXGBE_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + \
  117. IXGBE_PB_STATS_LEN + \
  118. IXGBE_QUEUE_STATS_LEN)
  119. static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
  120. "Register test (offline)", "Eeprom test (offline)",
  121. "Interrupt test (offline)", "Loopback test (offline)",
  122. "Link test (on/offline)"
  123. };
  124. #define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN
  125. static int ixgbe_get_settings(struct net_device *netdev,
  126. struct ethtool_cmd *ecmd)
  127. {
  128. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  129. struct ixgbe_hw *hw = &adapter->hw;
  130. u32 link_speed = 0;
  131. bool link_up;
  132. ecmd->supported = SUPPORTED_10000baseT_Full;
  133. ecmd->autoneg = AUTONEG_ENABLE;
  134. ecmd->transceiver = XCVR_EXTERNAL;
  135. if ((hw->phy.media_type == ixgbe_media_type_copper) ||
  136. (hw->phy.multispeed_fiber)) {
  137. ecmd->supported |= (SUPPORTED_1000baseT_Full |
  138. SUPPORTED_Autoneg);
  139. switch (hw->mac.type) {
  140. case ixgbe_mac_X540:
  141. ecmd->supported |= SUPPORTED_100baseT_Full;
  142. break;
  143. default:
  144. break;
  145. }
  146. ecmd->advertising = ADVERTISED_Autoneg;
  147. if (hw->phy.autoneg_advertised) {
  148. if (hw->phy.autoneg_advertised &
  149. IXGBE_LINK_SPEED_100_FULL)
  150. ecmd->advertising |= ADVERTISED_100baseT_Full;
  151. if (hw->phy.autoneg_advertised &
  152. IXGBE_LINK_SPEED_10GB_FULL)
  153. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  154. if (hw->phy.autoneg_advertised &
  155. IXGBE_LINK_SPEED_1GB_FULL)
  156. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  157. } else {
  158. /*
  159. * Default advertised modes in case
  160. * phy.autoneg_advertised isn't set.
  161. */
  162. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  163. ADVERTISED_1000baseT_Full);
  164. if (hw->mac.type == ixgbe_mac_X540)
  165. ecmd->advertising |= ADVERTISED_100baseT_Full;
  166. }
  167. if (hw->phy.media_type == ixgbe_media_type_copper) {
  168. ecmd->supported |= SUPPORTED_TP;
  169. ecmd->advertising |= ADVERTISED_TP;
  170. ecmd->port = PORT_TP;
  171. } else {
  172. ecmd->supported |= SUPPORTED_FIBRE;
  173. ecmd->advertising |= ADVERTISED_FIBRE;
  174. ecmd->port = PORT_FIBRE;
  175. }
  176. } else if (hw->phy.media_type == ixgbe_media_type_backplane) {
  177. /* Set as FIBRE until SERDES defined in kernel */
  178. if (hw->device_id == IXGBE_DEV_ID_82598_BX) {
  179. ecmd->supported = (SUPPORTED_1000baseT_Full |
  180. SUPPORTED_FIBRE);
  181. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  182. ADVERTISED_FIBRE);
  183. ecmd->port = PORT_FIBRE;
  184. ecmd->autoneg = AUTONEG_DISABLE;
  185. } else if ((hw->device_id == IXGBE_DEV_ID_82599_COMBO_BACKPLANE) ||
  186. (hw->device_id == IXGBE_DEV_ID_82599_KX4_MEZZ)) {
  187. ecmd->supported |= (SUPPORTED_1000baseT_Full |
  188. SUPPORTED_Autoneg |
  189. SUPPORTED_FIBRE);
  190. ecmd->advertising = (ADVERTISED_10000baseT_Full |
  191. ADVERTISED_1000baseT_Full |
  192. ADVERTISED_Autoneg |
  193. ADVERTISED_FIBRE);
  194. ecmd->port = PORT_FIBRE;
  195. } else {
  196. ecmd->supported |= (SUPPORTED_1000baseT_Full |
  197. SUPPORTED_FIBRE);
  198. ecmd->advertising = (ADVERTISED_10000baseT_Full |
  199. ADVERTISED_1000baseT_Full |
  200. ADVERTISED_FIBRE);
  201. ecmd->port = PORT_FIBRE;
  202. }
  203. } else {
  204. ecmd->supported |= SUPPORTED_FIBRE;
  205. ecmd->advertising = (ADVERTISED_10000baseT_Full |
  206. ADVERTISED_FIBRE);
  207. ecmd->port = PORT_FIBRE;
  208. ecmd->autoneg = AUTONEG_DISABLE;
  209. }
  210. /* Get PHY type */
  211. switch (adapter->hw.phy.type) {
  212. case ixgbe_phy_tn:
  213. case ixgbe_phy_aq:
  214. case ixgbe_phy_cu_unknown:
  215. /* Copper 10G-BASET */
  216. ecmd->port = PORT_TP;
  217. break;
  218. case ixgbe_phy_qt:
  219. ecmd->port = PORT_FIBRE;
  220. break;
  221. case ixgbe_phy_nl:
  222. case ixgbe_phy_sfp_passive_tyco:
  223. case ixgbe_phy_sfp_passive_unknown:
  224. case ixgbe_phy_sfp_ftl:
  225. case ixgbe_phy_sfp_avago:
  226. case ixgbe_phy_sfp_intel:
  227. case ixgbe_phy_sfp_unknown:
  228. switch (adapter->hw.phy.sfp_type) {
  229. /* SFP+ devices, further checking needed */
  230. case ixgbe_sfp_type_da_cu:
  231. case ixgbe_sfp_type_da_cu_core0:
  232. case ixgbe_sfp_type_da_cu_core1:
  233. ecmd->port = PORT_DA;
  234. break;
  235. case ixgbe_sfp_type_sr:
  236. case ixgbe_sfp_type_lr:
  237. case ixgbe_sfp_type_srlr_core0:
  238. case ixgbe_sfp_type_srlr_core1:
  239. ecmd->port = PORT_FIBRE;
  240. break;
  241. case ixgbe_sfp_type_not_present:
  242. ecmd->port = PORT_NONE;
  243. break;
  244. case ixgbe_sfp_type_1g_cu_core0:
  245. case ixgbe_sfp_type_1g_cu_core1:
  246. ecmd->port = PORT_TP;
  247. ecmd->supported = SUPPORTED_TP;
  248. ecmd->advertising = (ADVERTISED_1000baseT_Full |
  249. ADVERTISED_TP);
  250. break;
  251. case ixgbe_sfp_type_unknown:
  252. default:
  253. ecmd->port = PORT_OTHER;
  254. break;
  255. }
  256. break;
  257. case ixgbe_phy_xaui:
  258. ecmd->port = PORT_NONE;
  259. break;
  260. case ixgbe_phy_unknown:
  261. case ixgbe_phy_generic:
  262. case ixgbe_phy_sfp_unsupported:
  263. default:
  264. ecmd->port = PORT_OTHER;
  265. break;
  266. }
  267. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  268. if (link_up) {
  269. switch (link_speed) {
  270. case IXGBE_LINK_SPEED_10GB_FULL:
  271. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  272. break;
  273. case IXGBE_LINK_SPEED_1GB_FULL:
  274. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  275. break;
  276. case IXGBE_LINK_SPEED_100_FULL:
  277. ethtool_cmd_speed_set(ecmd, SPEED_100);
  278. break;
  279. default:
  280. break;
  281. }
  282. ecmd->duplex = DUPLEX_FULL;
  283. } else {
  284. ethtool_cmd_speed_set(ecmd, -1);
  285. ecmd->duplex = -1;
  286. }
  287. return 0;
  288. }
  289. static int ixgbe_set_settings(struct net_device *netdev,
  290. struct ethtool_cmd *ecmd)
  291. {
  292. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  293. struct ixgbe_hw *hw = &adapter->hw;
  294. u32 advertised, old;
  295. s32 err = 0;
  296. if ((hw->phy.media_type == ixgbe_media_type_copper) ||
  297. (hw->phy.multispeed_fiber)) {
  298. /* 10000/copper and 1000/copper must autoneg
  299. * this function does not support any duplex forcing, but can
  300. * limit the advertising of the adapter to only 10000 or 1000 */
  301. if (ecmd->autoneg == AUTONEG_DISABLE)
  302. return -EINVAL;
  303. old = hw->phy.autoneg_advertised;
  304. advertised = 0;
  305. if (ecmd->advertising & ADVERTISED_10000baseT_Full)
  306. advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  307. if (ecmd->advertising & ADVERTISED_1000baseT_Full)
  308. advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  309. if (ecmd->advertising & ADVERTISED_100baseT_Full)
  310. advertised |= IXGBE_LINK_SPEED_100_FULL;
  311. if (old == advertised)
  312. return err;
  313. /* this sets the link speed and restarts auto-neg */
  314. hw->mac.autotry_restart = true;
  315. err = hw->mac.ops.setup_link(hw, advertised, true, true);
  316. if (err) {
  317. e_info(probe, "setup link failed with code %d\n", err);
  318. hw->mac.ops.setup_link(hw, old, true, true);
  319. }
  320. } else {
  321. /* in this case we currently only support 10Gb/FULL */
  322. u32 speed = ethtool_cmd_speed(ecmd);
  323. if ((ecmd->autoneg == AUTONEG_ENABLE) ||
  324. (ecmd->advertising != ADVERTISED_10000baseT_Full) ||
  325. (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL))
  326. return -EINVAL;
  327. }
  328. return err;
  329. }
  330. static void ixgbe_get_pauseparam(struct net_device *netdev,
  331. struct ethtool_pauseparam *pause)
  332. {
  333. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  334. struct ixgbe_hw *hw = &adapter->hw;
  335. /*
  336. * Flow Control Autoneg isn't on if
  337. * - we didn't ask for it OR
  338. * - it failed, we know this by tx & rx being off
  339. */
  340. if (hw->fc.disable_fc_autoneg ||
  341. (hw->fc.current_mode == ixgbe_fc_none))
  342. pause->autoneg = 0;
  343. else
  344. pause->autoneg = 1;
  345. if (hw->fc.current_mode == ixgbe_fc_rx_pause) {
  346. pause->rx_pause = 1;
  347. } else if (hw->fc.current_mode == ixgbe_fc_tx_pause) {
  348. pause->tx_pause = 1;
  349. } else if (hw->fc.current_mode == ixgbe_fc_full) {
  350. pause->rx_pause = 1;
  351. pause->tx_pause = 1;
  352. #ifdef CONFIG_DCB
  353. } else if (hw->fc.current_mode == ixgbe_fc_pfc) {
  354. pause->rx_pause = 0;
  355. pause->tx_pause = 0;
  356. #endif
  357. }
  358. }
  359. static int ixgbe_set_pauseparam(struct net_device *netdev,
  360. struct ethtool_pauseparam *pause)
  361. {
  362. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  363. struct ixgbe_hw *hw = &adapter->hw;
  364. struct ixgbe_fc_info fc;
  365. #ifdef CONFIG_DCB
  366. if (adapter->dcb_cfg.pfc_mode_enable ||
  367. ((hw->mac.type == ixgbe_mac_82598EB) &&
  368. (adapter->flags & IXGBE_FLAG_DCB_ENABLED)))
  369. return -EINVAL;
  370. #endif
  371. fc = hw->fc;
  372. if (pause->autoneg != AUTONEG_ENABLE)
  373. fc.disable_fc_autoneg = true;
  374. else
  375. fc.disable_fc_autoneg = false;
  376. if ((pause->rx_pause && pause->tx_pause) || pause->autoneg)
  377. fc.requested_mode = ixgbe_fc_full;
  378. else if (pause->rx_pause && !pause->tx_pause)
  379. fc.requested_mode = ixgbe_fc_rx_pause;
  380. else if (!pause->rx_pause && pause->tx_pause)
  381. fc.requested_mode = ixgbe_fc_tx_pause;
  382. else if (!pause->rx_pause && !pause->tx_pause)
  383. fc.requested_mode = ixgbe_fc_none;
  384. else
  385. return -EINVAL;
  386. #ifdef CONFIG_DCB
  387. adapter->last_lfc_mode = fc.requested_mode;
  388. #endif
  389. /* if the thing changed then we'll update and use new autoneg */
  390. if (memcmp(&fc, &hw->fc, sizeof(struct ixgbe_fc_info))) {
  391. hw->fc = fc;
  392. if (netif_running(netdev))
  393. ixgbe_reinit_locked(adapter);
  394. else
  395. ixgbe_reset(adapter);
  396. }
  397. return 0;
  398. }
  399. static u32 ixgbe_get_rx_csum(struct net_device *netdev)
  400. {
  401. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  402. return adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED;
  403. }
  404. static int ixgbe_set_rx_csum(struct net_device *netdev, u32 data)
  405. {
  406. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  407. if (data)
  408. adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
  409. else
  410. adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
  411. return 0;
  412. }
  413. static u32 ixgbe_get_tx_csum(struct net_device *netdev)
  414. {
  415. return (netdev->features & NETIF_F_IP_CSUM) != 0;
  416. }
  417. static int ixgbe_set_tx_csum(struct net_device *netdev, u32 data)
  418. {
  419. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  420. u32 feature_list;
  421. feature_list = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
  422. switch (adapter->hw.mac.type) {
  423. case ixgbe_mac_82599EB:
  424. case ixgbe_mac_X540:
  425. feature_list |= NETIF_F_SCTP_CSUM;
  426. break;
  427. default:
  428. break;
  429. }
  430. if (data)
  431. netdev->features |= feature_list;
  432. else
  433. netdev->features &= ~feature_list;
  434. return 0;
  435. }
  436. static int ixgbe_set_tso(struct net_device *netdev, u32 data)
  437. {
  438. if (data) {
  439. netdev->features |= NETIF_F_TSO;
  440. netdev->features |= NETIF_F_TSO6;
  441. } else {
  442. netdev->features &= ~NETIF_F_TSO;
  443. netdev->features &= ~NETIF_F_TSO6;
  444. }
  445. return 0;
  446. }
  447. static u32 ixgbe_get_msglevel(struct net_device *netdev)
  448. {
  449. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  450. return adapter->msg_enable;
  451. }
  452. static void ixgbe_set_msglevel(struct net_device *netdev, u32 data)
  453. {
  454. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  455. adapter->msg_enable = data;
  456. }
  457. static int ixgbe_get_regs_len(struct net_device *netdev)
  458. {
  459. #define IXGBE_REGS_LEN 1128
  460. return IXGBE_REGS_LEN * sizeof(u32);
  461. }
  462. #define IXGBE_GET_STAT(_A_, _R_) _A_->stats._R_
  463. static void ixgbe_get_regs(struct net_device *netdev,
  464. struct ethtool_regs *regs, void *p)
  465. {
  466. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  467. struct ixgbe_hw *hw = &adapter->hw;
  468. u32 *regs_buff = p;
  469. u8 i;
  470. memset(p, 0, IXGBE_REGS_LEN * sizeof(u32));
  471. regs->version = (1 << 24) | hw->revision_id << 16 | hw->device_id;
  472. /* General Registers */
  473. regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_CTRL);
  474. regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_STATUS);
  475. regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  476. regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_ESDP);
  477. regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_EODSDP);
  478. regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  479. regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_FRTIMER);
  480. regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_TCPTIMER);
  481. /* NVM Register */
  482. regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_EEC);
  483. regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_EERD);
  484. regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_FLA);
  485. regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_EEMNGCTL);
  486. regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_EEMNGDATA);
  487. regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_FLMNGCTL);
  488. regs_buff[14] = IXGBE_READ_REG(hw, IXGBE_FLMNGDATA);
  489. regs_buff[15] = IXGBE_READ_REG(hw, IXGBE_FLMNGCNT);
  490. regs_buff[16] = IXGBE_READ_REG(hw, IXGBE_FLOP);
  491. regs_buff[17] = IXGBE_READ_REG(hw, IXGBE_GRC);
  492. /* Interrupt */
  493. /* don't read EICR because it can clear interrupt causes, instead
  494. * read EICS which is a shadow but doesn't clear EICR */
  495. regs_buff[18] = IXGBE_READ_REG(hw, IXGBE_EICS);
  496. regs_buff[19] = IXGBE_READ_REG(hw, IXGBE_EICS);
  497. regs_buff[20] = IXGBE_READ_REG(hw, IXGBE_EIMS);
  498. regs_buff[21] = IXGBE_READ_REG(hw, IXGBE_EIMC);
  499. regs_buff[22] = IXGBE_READ_REG(hw, IXGBE_EIAC);
  500. regs_buff[23] = IXGBE_READ_REG(hw, IXGBE_EIAM);
  501. regs_buff[24] = IXGBE_READ_REG(hw, IXGBE_EITR(0));
  502. regs_buff[25] = IXGBE_READ_REG(hw, IXGBE_IVAR(0));
  503. regs_buff[26] = IXGBE_READ_REG(hw, IXGBE_MSIXT);
  504. regs_buff[27] = IXGBE_READ_REG(hw, IXGBE_MSIXPBA);
  505. regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_PBACL(0));
  506. regs_buff[29] = IXGBE_READ_REG(hw, IXGBE_GPIE);
  507. /* Flow Control */
  508. regs_buff[30] = IXGBE_READ_REG(hw, IXGBE_PFCTOP);
  509. regs_buff[31] = IXGBE_READ_REG(hw, IXGBE_FCTTV(0));
  510. regs_buff[32] = IXGBE_READ_REG(hw, IXGBE_FCTTV(1));
  511. regs_buff[33] = IXGBE_READ_REG(hw, IXGBE_FCTTV(2));
  512. regs_buff[34] = IXGBE_READ_REG(hw, IXGBE_FCTTV(3));
  513. for (i = 0; i < 8; i++) {
  514. switch (hw->mac.type) {
  515. case ixgbe_mac_82598EB:
  516. regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL(i));
  517. regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH(i));
  518. break;
  519. case ixgbe_mac_82599EB:
  520. regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL_82599(i));
  521. regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. regs_buff[51] = IXGBE_READ_REG(hw, IXGBE_FCRTV);
  528. regs_buff[52] = IXGBE_READ_REG(hw, IXGBE_TFCS);
  529. /* Receive DMA */
  530. for (i = 0; i < 64; i++)
  531. regs_buff[53 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  532. for (i = 0; i < 64; i++)
  533. regs_buff[117 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  534. for (i = 0; i < 64; i++)
  535. regs_buff[181 + i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  536. for (i = 0; i < 64; i++)
  537. regs_buff[245 + i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  538. for (i = 0; i < 64; i++)
  539. regs_buff[309 + i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  540. for (i = 0; i < 64; i++)
  541. regs_buff[373 + i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  542. for (i = 0; i < 16; i++)
  543. regs_buff[437 + i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  544. for (i = 0; i < 16; i++)
  545. regs_buff[453 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  546. regs_buff[469] = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  547. for (i = 0; i < 8; i++)
  548. regs_buff[470 + i] = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
  549. regs_buff[478] = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  550. regs_buff[479] = IXGBE_READ_REG(hw, IXGBE_DROPEN);
  551. /* Receive */
  552. regs_buff[480] = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  553. regs_buff[481] = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  554. for (i = 0; i < 16; i++)
  555. regs_buff[482 + i] = IXGBE_READ_REG(hw, IXGBE_RAL(i));
  556. for (i = 0; i < 16; i++)
  557. regs_buff[498 + i] = IXGBE_READ_REG(hw, IXGBE_RAH(i));
  558. regs_buff[514] = IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0));
  559. regs_buff[515] = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  560. regs_buff[516] = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  561. regs_buff[517] = IXGBE_READ_REG(hw, IXGBE_MCSTCTRL);
  562. regs_buff[518] = IXGBE_READ_REG(hw, IXGBE_MRQC);
  563. regs_buff[519] = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  564. for (i = 0; i < 8; i++)
  565. regs_buff[520 + i] = IXGBE_READ_REG(hw, IXGBE_IMIR(i));
  566. for (i = 0; i < 8; i++)
  567. regs_buff[528 + i] = IXGBE_READ_REG(hw, IXGBE_IMIREXT(i));
  568. regs_buff[536] = IXGBE_READ_REG(hw, IXGBE_IMIRVP);
  569. /* Transmit */
  570. for (i = 0; i < 32; i++)
  571. regs_buff[537 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  572. for (i = 0; i < 32; i++)
  573. regs_buff[569 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  574. for (i = 0; i < 32; i++)
  575. regs_buff[601 + i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  576. for (i = 0; i < 32; i++)
  577. regs_buff[633 + i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  578. for (i = 0; i < 32; i++)
  579. regs_buff[665 + i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  580. for (i = 0; i < 32; i++)
  581. regs_buff[697 + i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  582. for (i = 0; i < 32; i++)
  583. regs_buff[729 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAL(i));
  584. for (i = 0; i < 32; i++)
  585. regs_buff[761 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAH(i));
  586. regs_buff[793] = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
  587. for (i = 0; i < 16; i++)
  588. regs_buff[794 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
  589. regs_buff[810] = IXGBE_READ_REG(hw, IXGBE_TIPG);
  590. for (i = 0; i < 8; i++)
  591. regs_buff[811 + i] = IXGBE_READ_REG(hw, IXGBE_TXPBSIZE(i));
  592. regs_buff[819] = IXGBE_READ_REG(hw, IXGBE_MNGTXMAP);
  593. /* Wake Up */
  594. regs_buff[820] = IXGBE_READ_REG(hw, IXGBE_WUC);
  595. regs_buff[821] = IXGBE_READ_REG(hw, IXGBE_WUFC);
  596. regs_buff[822] = IXGBE_READ_REG(hw, IXGBE_WUS);
  597. regs_buff[823] = IXGBE_READ_REG(hw, IXGBE_IPAV);
  598. regs_buff[824] = IXGBE_READ_REG(hw, IXGBE_IP4AT);
  599. regs_buff[825] = IXGBE_READ_REG(hw, IXGBE_IP6AT);
  600. regs_buff[826] = IXGBE_READ_REG(hw, IXGBE_WUPL);
  601. regs_buff[827] = IXGBE_READ_REG(hw, IXGBE_WUPM);
  602. regs_buff[828] = IXGBE_READ_REG(hw, IXGBE_FHFT(0));
  603. /* DCB */
  604. regs_buff[829] = IXGBE_READ_REG(hw, IXGBE_RMCS);
  605. regs_buff[830] = IXGBE_READ_REG(hw, IXGBE_DPMCS);
  606. regs_buff[831] = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
  607. regs_buff[832] = IXGBE_READ_REG(hw, IXGBE_RUPPBMR);
  608. for (i = 0; i < 8; i++)
  609. regs_buff[833 + i] = IXGBE_READ_REG(hw, IXGBE_RT2CR(i));
  610. for (i = 0; i < 8; i++)
  611. regs_buff[841 + i] = IXGBE_READ_REG(hw, IXGBE_RT2SR(i));
  612. for (i = 0; i < 8; i++)
  613. regs_buff[849 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCCR(i));
  614. for (i = 0; i < 8; i++)
  615. regs_buff[857 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCSR(i));
  616. for (i = 0; i < 8; i++)
  617. regs_buff[865 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCCR(i));
  618. for (i = 0; i < 8; i++)
  619. regs_buff[873 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCSR(i));
  620. /* Statistics */
  621. regs_buff[881] = IXGBE_GET_STAT(adapter, crcerrs);
  622. regs_buff[882] = IXGBE_GET_STAT(adapter, illerrc);
  623. regs_buff[883] = IXGBE_GET_STAT(adapter, errbc);
  624. regs_buff[884] = IXGBE_GET_STAT(adapter, mspdc);
  625. for (i = 0; i < 8; i++)
  626. regs_buff[885 + i] = IXGBE_GET_STAT(adapter, mpc[i]);
  627. regs_buff[893] = IXGBE_GET_STAT(adapter, mlfc);
  628. regs_buff[894] = IXGBE_GET_STAT(adapter, mrfc);
  629. regs_buff[895] = IXGBE_GET_STAT(adapter, rlec);
  630. regs_buff[896] = IXGBE_GET_STAT(adapter, lxontxc);
  631. regs_buff[897] = IXGBE_GET_STAT(adapter, lxonrxc);
  632. regs_buff[898] = IXGBE_GET_STAT(adapter, lxofftxc);
  633. regs_buff[899] = IXGBE_GET_STAT(adapter, lxoffrxc);
  634. for (i = 0; i < 8; i++)
  635. regs_buff[900 + i] = IXGBE_GET_STAT(adapter, pxontxc[i]);
  636. for (i = 0; i < 8; i++)
  637. regs_buff[908 + i] = IXGBE_GET_STAT(adapter, pxonrxc[i]);
  638. for (i = 0; i < 8; i++)
  639. regs_buff[916 + i] = IXGBE_GET_STAT(adapter, pxofftxc[i]);
  640. for (i = 0; i < 8; i++)
  641. regs_buff[924 + i] = IXGBE_GET_STAT(adapter, pxoffrxc[i]);
  642. regs_buff[932] = IXGBE_GET_STAT(adapter, prc64);
  643. regs_buff[933] = IXGBE_GET_STAT(adapter, prc127);
  644. regs_buff[934] = IXGBE_GET_STAT(adapter, prc255);
  645. regs_buff[935] = IXGBE_GET_STAT(adapter, prc511);
  646. regs_buff[936] = IXGBE_GET_STAT(adapter, prc1023);
  647. regs_buff[937] = IXGBE_GET_STAT(adapter, prc1522);
  648. regs_buff[938] = IXGBE_GET_STAT(adapter, gprc);
  649. regs_buff[939] = IXGBE_GET_STAT(adapter, bprc);
  650. regs_buff[940] = IXGBE_GET_STAT(adapter, mprc);
  651. regs_buff[941] = IXGBE_GET_STAT(adapter, gptc);
  652. regs_buff[942] = IXGBE_GET_STAT(adapter, gorc);
  653. regs_buff[944] = IXGBE_GET_STAT(adapter, gotc);
  654. for (i = 0; i < 8; i++)
  655. regs_buff[946 + i] = IXGBE_GET_STAT(adapter, rnbc[i]);
  656. regs_buff[954] = IXGBE_GET_STAT(adapter, ruc);
  657. regs_buff[955] = IXGBE_GET_STAT(adapter, rfc);
  658. regs_buff[956] = IXGBE_GET_STAT(adapter, roc);
  659. regs_buff[957] = IXGBE_GET_STAT(adapter, rjc);
  660. regs_buff[958] = IXGBE_GET_STAT(adapter, mngprc);
  661. regs_buff[959] = IXGBE_GET_STAT(adapter, mngpdc);
  662. regs_buff[960] = IXGBE_GET_STAT(adapter, mngptc);
  663. regs_buff[961] = IXGBE_GET_STAT(adapter, tor);
  664. regs_buff[963] = IXGBE_GET_STAT(adapter, tpr);
  665. regs_buff[964] = IXGBE_GET_STAT(adapter, tpt);
  666. regs_buff[965] = IXGBE_GET_STAT(adapter, ptc64);
  667. regs_buff[966] = IXGBE_GET_STAT(adapter, ptc127);
  668. regs_buff[967] = IXGBE_GET_STAT(adapter, ptc255);
  669. regs_buff[968] = IXGBE_GET_STAT(adapter, ptc511);
  670. regs_buff[969] = IXGBE_GET_STAT(adapter, ptc1023);
  671. regs_buff[970] = IXGBE_GET_STAT(adapter, ptc1522);
  672. regs_buff[971] = IXGBE_GET_STAT(adapter, mptc);
  673. regs_buff[972] = IXGBE_GET_STAT(adapter, bptc);
  674. regs_buff[973] = IXGBE_GET_STAT(adapter, xec);
  675. for (i = 0; i < 16; i++)
  676. regs_buff[974 + i] = IXGBE_GET_STAT(adapter, qprc[i]);
  677. for (i = 0; i < 16; i++)
  678. regs_buff[990 + i] = IXGBE_GET_STAT(adapter, qptc[i]);
  679. for (i = 0; i < 16; i++)
  680. regs_buff[1006 + i] = IXGBE_GET_STAT(adapter, qbrc[i]);
  681. for (i = 0; i < 16; i++)
  682. regs_buff[1022 + i] = IXGBE_GET_STAT(adapter, qbtc[i]);
  683. /* MAC */
  684. regs_buff[1038] = IXGBE_READ_REG(hw, IXGBE_PCS1GCFIG);
  685. regs_buff[1039] = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  686. regs_buff[1040] = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  687. regs_buff[1041] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG0);
  688. regs_buff[1042] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG1);
  689. regs_buff[1043] = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  690. regs_buff[1044] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  691. regs_buff[1045] = IXGBE_READ_REG(hw, IXGBE_PCS1GANNP);
  692. regs_buff[1046] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLPNP);
  693. regs_buff[1047] = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  694. regs_buff[1048] = IXGBE_READ_REG(hw, IXGBE_HLREG1);
  695. regs_buff[1049] = IXGBE_READ_REG(hw, IXGBE_PAP);
  696. regs_buff[1050] = IXGBE_READ_REG(hw, IXGBE_MACA);
  697. regs_buff[1051] = IXGBE_READ_REG(hw, IXGBE_APAE);
  698. regs_buff[1052] = IXGBE_READ_REG(hw, IXGBE_ARD);
  699. regs_buff[1053] = IXGBE_READ_REG(hw, IXGBE_AIS);
  700. regs_buff[1054] = IXGBE_READ_REG(hw, IXGBE_MSCA);
  701. regs_buff[1055] = IXGBE_READ_REG(hw, IXGBE_MSRWD);
  702. regs_buff[1056] = IXGBE_READ_REG(hw, IXGBE_MLADD);
  703. regs_buff[1057] = IXGBE_READ_REG(hw, IXGBE_MHADD);
  704. regs_buff[1058] = IXGBE_READ_REG(hw, IXGBE_TREG);
  705. regs_buff[1059] = IXGBE_READ_REG(hw, IXGBE_PCSS1);
  706. regs_buff[1060] = IXGBE_READ_REG(hw, IXGBE_PCSS2);
  707. regs_buff[1061] = IXGBE_READ_REG(hw, IXGBE_XPCSS);
  708. regs_buff[1062] = IXGBE_READ_REG(hw, IXGBE_SERDESC);
  709. regs_buff[1063] = IXGBE_READ_REG(hw, IXGBE_MACS);
  710. regs_buff[1064] = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  711. regs_buff[1065] = IXGBE_READ_REG(hw, IXGBE_LINKS);
  712. regs_buff[1066] = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  713. regs_buff[1067] = IXGBE_READ_REG(hw, IXGBE_AUTOC3);
  714. regs_buff[1068] = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  715. regs_buff[1069] = IXGBE_READ_REG(hw, IXGBE_ANLP2);
  716. regs_buff[1070] = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
  717. /* Diagnostic */
  718. regs_buff[1071] = IXGBE_READ_REG(hw, IXGBE_RDSTATCTL);
  719. for (i = 0; i < 8; i++)
  720. regs_buff[1072 + i] = IXGBE_READ_REG(hw, IXGBE_RDSTAT(i));
  721. regs_buff[1080] = IXGBE_READ_REG(hw, IXGBE_RDHMPN);
  722. for (i = 0; i < 4; i++)
  723. regs_buff[1081 + i] = IXGBE_READ_REG(hw, IXGBE_RIC_DW(i));
  724. regs_buff[1085] = IXGBE_READ_REG(hw, IXGBE_RDPROBE);
  725. regs_buff[1086] = IXGBE_READ_REG(hw, IXGBE_TDSTATCTL);
  726. for (i = 0; i < 8; i++)
  727. regs_buff[1087 + i] = IXGBE_READ_REG(hw, IXGBE_TDSTAT(i));
  728. regs_buff[1095] = IXGBE_READ_REG(hw, IXGBE_TDHMPN);
  729. for (i = 0; i < 4; i++)
  730. regs_buff[1096 + i] = IXGBE_READ_REG(hw, IXGBE_TIC_DW(i));
  731. regs_buff[1100] = IXGBE_READ_REG(hw, IXGBE_TDPROBE);
  732. regs_buff[1101] = IXGBE_READ_REG(hw, IXGBE_TXBUFCTRL);
  733. regs_buff[1102] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA0);
  734. regs_buff[1103] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA1);
  735. regs_buff[1104] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA2);
  736. regs_buff[1105] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA3);
  737. regs_buff[1106] = IXGBE_READ_REG(hw, IXGBE_RXBUFCTRL);
  738. regs_buff[1107] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA0);
  739. regs_buff[1108] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA1);
  740. regs_buff[1109] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA2);
  741. regs_buff[1110] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA3);
  742. for (i = 0; i < 8; i++)
  743. regs_buff[1111 + i] = IXGBE_READ_REG(hw, IXGBE_PCIE_DIAG(i));
  744. regs_buff[1119] = IXGBE_READ_REG(hw, IXGBE_RFVAL);
  745. regs_buff[1120] = IXGBE_READ_REG(hw, IXGBE_MDFTC1);
  746. regs_buff[1121] = IXGBE_READ_REG(hw, IXGBE_MDFTC2);
  747. regs_buff[1122] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO1);
  748. regs_buff[1123] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO2);
  749. regs_buff[1124] = IXGBE_READ_REG(hw, IXGBE_MDFTS);
  750. regs_buff[1125] = IXGBE_READ_REG(hw, IXGBE_PCIEECCCTL);
  751. regs_buff[1126] = IXGBE_READ_REG(hw, IXGBE_PBTXECC);
  752. regs_buff[1127] = IXGBE_READ_REG(hw, IXGBE_PBRXECC);
  753. }
  754. static int ixgbe_get_eeprom_len(struct net_device *netdev)
  755. {
  756. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  757. return adapter->hw.eeprom.word_size * 2;
  758. }
  759. static int ixgbe_get_eeprom(struct net_device *netdev,
  760. struct ethtool_eeprom *eeprom, u8 *bytes)
  761. {
  762. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  763. struct ixgbe_hw *hw = &adapter->hw;
  764. u16 *eeprom_buff;
  765. int first_word, last_word, eeprom_len;
  766. int ret_val = 0;
  767. u16 i;
  768. if (eeprom->len == 0)
  769. return -EINVAL;
  770. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  771. first_word = eeprom->offset >> 1;
  772. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  773. eeprom_len = last_word - first_word + 1;
  774. eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
  775. if (!eeprom_buff)
  776. return -ENOMEM;
  777. ret_val = hw->eeprom.ops.read_buffer(hw, first_word, eeprom_len,
  778. eeprom_buff);
  779. /* Device's eeprom is always little-endian, word addressable */
  780. for (i = 0; i < eeprom_len; i++)
  781. le16_to_cpus(&eeprom_buff[i]);
  782. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  783. kfree(eeprom_buff);
  784. return ret_val;
  785. }
  786. static void ixgbe_get_drvinfo(struct net_device *netdev,
  787. struct ethtool_drvinfo *drvinfo)
  788. {
  789. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  790. char firmware_version[32];
  791. strncpy(drvinfo->driver, ixgbe_driver_name,
  792. sizeof(drvinfo->driver) - 1);
  793. strncpy(drvinfo->version, ixgbe_driver_version,
  794. sizeof(drvinfo->version) - 1);
  795. snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
  796. (adapter->eeprom_version & 0xF000) >> 12,
  797. (adapter->eeprom_version & 0x0FF0) >> 4,
  798. adapter->eeprom_version & 0x000F);
  799. strncpy(drvinfo->fw_version, firmware_version,
  800. sizeof(drvinfo->fw_version));
  801. strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
  802. sizeof(drvinfo->bus_info));
  803. drvinfo->n_stats = IXGBE_STATS_LEN;
  804. drvinfo->testinfo_len = IXGBE_TEST_LEN;
  805. drvinfo->regdump_len = ixgbe_get_regs_len(netdev);
  806. }
  807. static void ixgbe_get_ringparam(struct net_device *netdev,
  808. struct ethtool_ringparam *ring)
  809. {
  810. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  811. struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
  812. struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
  813. ring->rx_max_pending = IXGBE_MAX_RXD;
  814. ring->tx_max_pending = IXGBE_MAX_TXD;
  815. ring->rx_mini_max_pending = 0;
  816. ring->rx_jumbo_max_pending = 0;
  817. ring->rx_pending = rx_ring->count;
  818. ring->tx_pending = tx_ring->count;
  819. ring->rx_mini_pending = 0;
  820. ring->rx_jumbo_pending = 0;
  821. }
  822. static int ixgbe_set_ringparam(struct net_device *netdev,
  823. struct ethtool_ringparam *ring)
  824. {
  825. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  826. struct ixgbe_ring *temp_tx_ring, *temp_rx_ring;
  827. int i, err = 0;
  828. u32 new_rx_count, new_tx_count;
  829. bool need_update = false;
  830. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  831. return -EINVAL;
  832. new_rx_count = max(ring->rx_pending, (u32)IXGBE_MIN_RXD);
  833. new_rx_count = min(new_rx_count, (u32)IXGBE_MAX_RXD);
  834. new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE);
  835. new_tx_count = max(ring->tx_pending, (u32)IXGBE_MIN_TXD);
  836. new_tx_count = min(new_tx_count, (u32)IXGBE_MAX_TXD);
  837. new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE);
  838. if ((new_tx_count == adapter->tx_ring[0]->count) &&
  839. (new_rx_count == adapter->rx_ring[0]->count)) {
  840. /* nothing to do */
  841. return 0;
  842. }
  843. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  844. usleep_range(1000, 2000);
  845. if (!netif_running(adapter->netdev)) {
  846. for (i = 0; i < adapter->num_tx_queues; i++)
  847. adapter->tx_ring[i]->count = new_tx_count;
  848. for (i = 0; i < adapter->num_rx_queues; i++)
  849. adapter->rx_ring[i]->count = new_rx_count;
  850. adapter->tx_ring_count = new_tx_count;
  851. adapter->rx_ring_count = new_rx_count;
  852. goto clear_reset;
  853. }
  854. temp_tx_ring = vmalloc(adapter->num_tx_queues * sizeof(struct ixgbe_ring));
  855. if (!temp_tx_ring) {
  856. err = -ENOMEM;
  857. goto clear_reset;
  858. }
  859. if (new_tx_count != adapter->tx_ring_count) {
  860. for (i = 0; i < adapter->num_tx_queues; i++) {
  861. memcpy(&temp_tx_ring[i], adapter->tx_ring[i],
  862. sizeof(struct ixgbe_ring));
  863. temp_tx_ring[i].count = new_tx_count;
  864. err = ixgbe_setup_tx_resources(&temp_tx_ring[i]);
  865. if (err) {
  866. while (i) {
  867. i--;
  868. ixgbe_free_tx_resources(&temp_tx_ring[i]);
  869. }
  870. goto clear_reset;
  871. }
  872. }
  873. need_update = true;
  874. }
  875. temp_rx_ring = vmalloc(adapter->num_rx_queues * sizeof(struct ixgbe_ring));
  876. if (!temp_rx_ring) {
  877. err = -ENOMEM;
  878. goto err_setup;
  879. }
  880. if (new_rx_count != adapter->rx_ring_count) {
  881. for (i = 0; i < adapter->num_rx_queues; i++) {
  882. memcpy(&temp_rx_ring[i], adapter->rx_ring[i],
  883. sizeof(struct ixgbe_ring));
  884. temp_rx_ring[i].count = new_rx_count;
  885. err = ixgbe_setup_rx_resources(&temp_rx_ring[i]);
  886. if (err) {
  887. while (i) {
  888. i--;
  889. ixgbe_free_rx_resources(&temp_rx_ring[i]);
  890. }
  891. goto err_setup;
  892. }
  893. }
  894. need_update = true;
  895. }
  896. /* if rings need to be updated, here's the place to do it in one shot */
  897. if (need_update) {
  898. ixgbe_down(adapter);
  899. /* tx */
  900. if (new_tx_count != adapter->tx_ring_count) {
  901. for (i = 0; i < adapter->num_tx_queues; i++) {
  902. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  903. memcpy(adapter->tx_ring[i], &temp_tx_ring[i],
  904. sizeof(struct ixgbe_ring));
  905. }
  906. adapter->tx_ring_count = new_tx_count;
  907. }
  908. /* rx */
  909. if (new_rx_count != adapter->rx_ring_count) {
  910. for (i = 0; i < adapter->num_rx_queues; i++) {
  911. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  912. memcpy(adapter->rx_ring[i], &temp_rx_ring[i],
  913. sizeof(struct ixgbe_ring));
  914. }
  915. adapter->rx_ring_count = new_rx_count;
  916. }
  917. ixgbe_up(adapter);
  918. }
  919. vfree(temp_rx_ring);
  920. err_setup:
  921. vfree(temp_tx_ring);
  922. clear_reset:
  923. clear_bit(__IXGBE_RESETTING, &adapter->state);
  924. return err;
  925. }
  926. static int ixgbe_get_sset_count(struct net_device *netdev, int sset)
  927. {
  928. switch (sset) {
  929. case ETH_SS_TEST:
  930. return IXGBE_TEST_LEN;
  931. case ETH_SS_STATS:
  932. return IXGBE_STATS_LEN;
  933. default:
  934. return -EOPNOTSUPP;
  935. }
  936. }
  937. static void ixgbe_get_ethtool_stats(struct net_device *netdev,
  938. struct ethtool_stats *stats, u64 *data)
  939. {
  940. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  941. struct rtnl_link_stats64 temp;
  942. const struct rtnl_link_stats64 *net_stats;
  943. unsigned int start;
  944. struct ixgbe_ring *ring;
  945. int i, j;
  946. char *p = NULL;
  947. ixgbe_update_stats(adapter);
  948. net_stats = dev_get_stats(netdev, &temp);
  949. for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
  950. switch (ixgbe_gstrings_stats[i].type) {
  951. case NETDEV_STATS:
  952. p = (char *) net_stats +
  953. ixgbe_gstrings_stats[i].stat_offset;
  954. break;
  955. case IXGBE_STATS:
  956. p = (char *) adapter +
  957. ixgbe_gstrings_stats[i].stat_offset;
  958. break;
  959. }
  960. data[i] = (ixgbe_gstrings_stats[i].sizeof_stat ==
  961. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  962. }
  963. for (j = 0; j < adapter->num_tx_queues; j++) {
  964. ring = adapter->tx_ring[j];
  965. do {
  966. start = u64_stats_fetch_begin_bh(&ring->syncp);
  967. data[i] = ring->stats.packets;
  968. data[i+1] = ring->stats.bytes;
  969. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  970. i += 2;
  971. }
  972. for (j = 0; j < adapter->num_rx_queues; j++) {
  973. ring = adapter->rx_ring[j];
  974. do {
  975. start = u64_stats_fetch_begin_bh(&ring->syncp);
  976. data[i] = ring->stats.packets;
  977. data[i+1] = ring->stats.bytes;
  978. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  979. i += 2;
  980. }
  981. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  982. for (j = 0; j < MAX_TX_PACKET_BUFFERS; j++) {
  983. data[i++] = adapter->stats.pxontxc[j];
  984. data[i++] = adapter->stats.pxofftxc[j];
  985. }
  986. for (j = 0; j < MAX_RX_PACKET_BUFFERS; j++) {
  987. data[i++] = adapter->stats.pxonrxc[j];
  988. data[i++] = adapter->stats.pxoffrxc[j];
  989. }
  990. }
  991. }
  992. static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
  993. u8 *data)
  994. {
  995. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  996. char *p = (char *)data;
  997. int i;
  998. switch (stringset) {
  999. case ETH_SS_TEST:
  1000. memcpy(data, *ixgbe_gstrings_test,
  1001. IXGBE_TEST_LEN * ETH_GSTRING_LEN);
  1002. break;
  1003. case ETH_SS_STATS:
  1004. for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
  1005. memcpy(p, ixgbe_gstrings_stats[i].stat_string,
  1006. ETH_GSTRING_LEN);
  1007. p += ETH_GSTRING_LEN;
  1008. }
  1009. for (i = 0; i < adapter->num_tx_queues; i++) {
  1010. sprintf(p, "tx_queue_%u_packets", i);
  1011. p += ETH_GSTRING_LEN;
  1012. sprintf(p, "tx_queue_%u_bytes", i);
  1013. p += ETH_GSTRING_LEN;
  1014. }
  1015. for (i = 0; i < adapter->num_rx_queues; i++) {
  1016. sprintf(p, "rx_queue_%u_packets", i);
  1017. p += ETH_GSTRING_LEN;
  1018. sprintf(p, "rx_queue_%u_bytes", i);
  1019. p += ETH_GSTRING_LEN;
  1020. }
  1021. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  1022. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  1023. sprintf(p, "tx_pb_%u_pxon", i);
  1024. p += ETH_GSTRING_LEN;
  1025. sprintf(p, "tx_pb_%u_pxoff", i);
  1026. p += ETH_GSTRING_LEN;
  1027. }
  1028. for (i = 0; i < MAX_RX_PACKET_BUFFERS; i++) {
  1029. sprintf(p, "rx_pb_%u_pxon", i);
  1030. p += ETH_GSTRING_LEN;
  1031. sprintf(p, "rx_pb_%u_pxoff", i);
  1032. p += ETH_GSTRING_LEN;
  1033. }
  1034. }
  1035. /* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */
  1036. break;
  1037. }
  1038. }
  1039. static int ixgbe_link_test(struct ixgbe_adapter *adapter, u64 *data)
  1040. {
  1041. struct ixgbe_hw *hw = &adapter->hw;
  1042. bool link_up;
  1043. u32 link_speed = 0;
  1044. *data = 0;
  1045. hw->mac.ops.check_link(hw, &link_speed, &link_up, true);
  1046. if (link_up)
  1047. return *data;
  1048. else
  1049. *data = 1;
  1050. return *data;
  1051. }
  1052. /* ethtool register test data */
  1053. struct ixgbe_reg_test {
  1054. u16 reg;
  1055. u8 array_len;
  1056. u8 test_type;
  1057. u32 mask;
  1058. u32 write;
  1059. };
  1060. /* In the hardware, registers are laid out either singly, in arrays
  1061. * spaced 0x40 bytes apart, or in contiguous tables. We assume
  1062. * most tests take place on arrays or single registers (handled
  1063. * as a single-element array) and special-case the tables.
  1064. * Table tests are always pattern tests.
  1065. *
  1066. * We also make provision for some required setup steps by specifying
  1067. * registers to be written without any read-back testing.
  1068. */
  1069. #define PATTERN_TEST 1
  1070. #define SET_READ_TEST 2
  1071. #define WRITE_NO_TEST 3
  1072. #define TABLE32_TEST 4
  1073. #define TABLE64_TEST_LO 5
  1074. #define TABLE64_TEST_HI 6
  1075. /* default 82599 register test */
  1076. static const struct ixgbe_reg_test reg_test_82599[] = {
  1077. { IXGBE_FCRTL_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1078. { IXGBE_FCRTH_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1079. { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1080. { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 },
  1081. { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 },
  1082. { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1083. { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  1084. { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
  1085. { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1086. { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 },
  1087. { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1088. { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1089. { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1090. { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1091. { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFF80 },
  1092. { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000001, 0x00000001 },
  1093. { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
  1094. { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x8001FFFF, 0x800CFFFF },
  1095. { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1096. { 0, 0, 0, 0 }
  1097. };
  1098. /* default 82598 register test */
  1099. static const struct ixgbe_reg_test reg_test_82598[] = {
  1100. { IXGBE_FCRTL(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1101. { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1102. { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1103. { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 },
  1104. { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1105. { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1106. { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  1107. /* Enable all four RX queues before testing. */
  1108. { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
  1109. /* RDH is read-only for 82598, only test RDT. */
  1110. { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  1111. { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 },
  1112. { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
  1113. { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1114. { IXGBE_TIPG, 1, PATTERN_TEST, 0x000000FF, 0x000000FF },
  1115. { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  1116. { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1117. { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  1118. { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000003, 0x00000003 },
  1119. { IXGBE_DTXCTL, 1, SET_READ_TEST, 0x00000005, 0x00000005 },
  1120. { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
  1121. { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x800CFFFF, 0x800CFFFF },
  1122. { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  1123. { 0, 0, 0, 0 }
  1124. };
  1125. static bool reg_pattern_test(struct ixgbe_adapter *adapter, u64 *data, int reg,
  1126. u32 mask, u32 write)
  1127. {
  1128. u32 pat, val, before;
  1129. static const u32 test_pattern[] = {
  1130. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
  1131. for (pat = 0; pat < ARRAY_SIZE(test_pattern); pat++) {
  1132. before = readl(adapter->hw.hw_addr + reg);
  1133. writel((test_pattern[pat] & write),
  1134. (adapter->hw.hw_addr + reg));
  1135. val = readl(adapter->hw.hw_addr + reg);
  1136. if (val != (test_pattern[pat] & write & mask)) {
  1137. e_err(drv, "pattern test reg %04X failed: got "
  1138. "0x%08X expected 0x%08X\n",
  1139. reg, val, (test_pattern[pat] & write & mask));
  1140. *data = reg;
  1141. writel(before, adapter->hw.hw_addr + reg);
  1142. return 1;
  1143. }
  1144. writel(before, adapter->hw.hw_addr + reg);
  1145. }
  1146. return 0;
  1147. }
  1148. static bool reg_set_and_check(struct ixgbe_adapter *adapter, u64 *data, int reg,
  1149. u32 mask, u32 write)
  1150. {
  1151. u32 val, before;
  1152. before = readl(adapter->hw.hw_addr + reg);
  1153. writel((write & mask), (adapter->hw.hw_addr + reg));
  1154. val = readl(adapter->hw.hw_addr + reg);
  1155. if ((write & mask) != (val & mask)) {
  1156. e_err(drv, "set/check reg %04X test failed: got 0x%08X "
  1157. "expected 0x%08X\n", reg, (val & mask), (write & mask));
  1158. *data = reg;
  1159. writel(before, (adapter->hw.hw_addr + reg));
  1160. return 1;
  1161. }
  1162. writel(before, (adapter->hw.hw_addr + reg));
  1163. return 0;
  1164. }
  1165. #define REG_PATTERN_TEST(reg, mask, write) \
  1166. do { \
  1167. if (reg_pattern_test(adapter, data, reg, mask, write)) \
  1168. return 1; \
  1169. } while (0) \
  1170. #define REG_SET_AND_CHECK(reg, mask, write) \
  1171. do { \
  1172. if (reg_set_and_check(adapter, data, reg, mask, write)) \
  1173. return 1; \
  1174. } while (0) \
  1175. static int ixgbe_reg_test(struct ixgbe_adapter *adapter, u64 *data)
  1176. {
  1177. const struct ixgbe_reg_test *test;
  1178. u32 value, before, after;
  1179. u32 i, toggle;
  1180. switch (adapter->hw.mac.type) {
  1181. case ixgbe_mac_82598EB:
  1182. toggle = 0x7FFFF3FF;
  1183. test = reg_test_82598;
  1184. break;
  1185. case ixgbe_mac_82599EB:
  1186. case ixgbe_mac_X540:
  1187. toggle = 0x7FFFF30F;
  1188. test = reg_test_82599;
  1189. break;
  1190. default:
  1191. *data = 1;
  1192. return 1;
  1193. break;
  1194. }
  1195. /*
  1196. * Because the status register is such a special case,
  1197. * we handle it separately from the rest of the register
  1198. * tests. Some bits are read-only, some toggle, and some
  1199. * are writeable on newer MACs.
  1200. */
  1201. before = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS);
  1202. value = (IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle);
  1203. IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, toggle);
  1204. after = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle;
  1205. if (value != after) {
  1206. e_err(drv, "failed STATUS register test got: 0x%08X "
  1207. "expected: 0x%08X\n", after, value);
  1208. *data = 1;
  1209. return 1;
  1210. }
  1211. /* restore previous status */
  1212. IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, before);
  1213. /*
  1214. * Perform the remainder of the register test, looping through
  1215. * the test table until we either fail or reach the null entry.
  1216. */
  1217. while (test->reg) {
  1218. for (i = 0; i < test->array_len; i++) {
  1219. switch (test->test_type) {
  1220. case PATTERN_TEST:
  1221. REG_PATTERN_TEST(test->reg + (i * 0x40),
  1222. test->mask,
  1223. test->write);
  1224. break;
  1225. case SET_READ_TEST:
  1226. REG_SET_AND_CHECK(test->reg + (i * 0x40),
  1227. test->mask,
  1228. test->write);
  1229. break;
  1230. case WRITE_NO_TEST:
  1231. writel(test->write,
  1232. (adapter->hw.hw_addr + test->reg)
  1233. + (i * 0x40));
  1234. break;
  1235. case TABLE32_TEST:
  1236. REG_PATTERN_TEST(test->reg + (i * 4),
  1237. test->mask,
  1238. test->write);
  1239. break;
  1240. case TABLE64_TEST_LO:
  1241. REG_PATTERN_TEST(test->reg + (i * 8),
  1242. test->mask,
  1243. test->write);
  1244. break;
  1245. case TABLE64_TEST_HI:
  1246. REG_PATTERN_TEST((test->reg + 4) + (i * 8),
  1247. test->mask,
  1248. test->write);
  1249. break;
  1250. }
  1251. }
  1252. test++;
  1253. }
  1254. *data = 0;
  1255. return 0;
  1256. }
  1257. static int ixgbe_eeprom_test(struct ixgbe_adapter *adapter, u64 *data)
  1258. {
  1259. struct ixgbe_hw *hw = &adapter->hw;
  1260. if (hw->eeprom.ops.validate_checksum(hw, NULL))
  1261. *data = 1;
  1262. else
  1263. *data = 0;
  1264. return *data;
  1265. }
  1266. static irqreturn_t ixgbe_test_intr(int irq, void *data)
  1267. {
  1268. struct net_device *netdev = (struct net_device *) data;
  1269. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1270. adapter->test_icr |= IXGBE_READ_REG(&adapter->hw, IXGBE_EICR);
  1271. return IRQ_HANDLED;
  1272. }
  1273. static int ixgbe_intr_test(struct ixgbe_adapter *adapter, u64 *data)
  1274. {
  1275. struct net_device *netdev = adapter->netdev;
  1276. u32 mask, i = 0, shared_int = true;
  1277. u32 irq = adapter->pdev->irq;
  1278. *data = 0;
  1279. /* Hook up test interrupt handler just for this test */
  1280. if (adapter->msix_entries) {
  1281. /* NOTE: we don't test MSI-X interrupts here, yet */
  1282. return 0;
  1283. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  1284. shared_int = false;
  1285. if (request_irq(irq, ixgbe_test_intr, 0, netdev->name,
  1286. netdev)) {
  1287. *data = 1;
  1288. return -1;
  1289. }
  1290. } else if (!request_irq(irq, ixgbe_test_intr, IRQF_PROBE_SHARED,
  1291. netdev->name, netdev)) {
  1292. shared_int = false;
  1293. } else if (request_irq(irq, ixgbe_test_intr, IRQF_SHARED,
  1294. netdev->name, netdev)) {
  1295. *data = 1;
  1296. return -1;
  1297. }
  1298. e_info(hw, "testing %s interrupt\n", shared_int ?
  1299. "shared" : "unshared");
  1300. /* Disable all the interrupts */
  1301. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF);
  1302. usleep_range(10000, 20000);
  1303. /* Test each interrupt */
  1304. for (; i < 10; i++) {
  1305. /* Interrupt to test */
  1306. mask = 1 << i;
  1307. if (!shared_int) {
  1308. /*
  1309. * Disable the interrupts to be reported in
  1310. * the cause register and then force the same
  1311. * interrupt and see if one gets posted. If
  1312. * an interrupt was posted to the bus, the
  1313. * test failed.
  1314. */
  1315. adapter->test_icr = 0;
  1316. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  1317. ~mask & 0x00007FFF);
  1318. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
  1319. ~mask & 0x00007FFF);
  1320. usleep_range(10000, 20000);
  1321. if (adapter->test_icr & mask) {
  1322. *data = 3;
  1323. break;
  1324. }
  1325. }
  1326. /*
  1327. * Enable the interrupt to be reported in the cause
  1328. * register and then force the same interrupt and see
  1329. * if one gets posted. If an interrupt was not posted
  1330. * to the bus, the test failed.
  1331. */
  1332. adapter->test_icr = 0;
  1333. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1334. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  1335. usleep_range(10000, 20000);
  1336. if (!(adapter->test_icr &mask)) {
  1337. *data = 4;
  1338. break;
  1339. }
  1340. if (!shared_int) {
  1341. /*
  1342. * Disable the other interrupts to be reported in
  1343. * the cause register and then force the other
  1344. * interrupts and see if any get posted. If
  1345. * an interrupt was posted to the bus, the
  1346. * test failed.
  1347. */
  1348. adapter->test_icr = 0;
  1349. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  1350. ~mask & 0x00007FFF);
  1351. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
  1352. ~mask & 0x00007FFF);
  1353. usleep_range(10000, 20000);
  1354. if (adapter->test_icr) {
  1355. *data = 5;
  1356. break;
  1357. }
  1358. }
  1359. }
  1360. /* Disable all the interrupts */
  1361. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF);
  1362. usleep_range(10000, 20000);
  1363. /* Unhook test interrupt handler */
  1364. free_irq(irq, netdev);
  1365. return *data;
  1366. }
  1367. static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter)
  1368. {
  1369. struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
  1370. struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
  1371. struct ixgbe_hw *hw = &adapter->hw;
  1372. u32 reg_ctl;
  1373. /* shut down the DMA engines now so they can be reinitialized later */
  1374. /* first Rx */
  1375. reg_ctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  1376. reg_ctl &= ~IXGBE_RXCTRL_RXEN;
  1377. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_ctl);
  1378. ixgbe_disable_rx_queue(adapter, rx_ring);
  1379. /* now Tx */
  1380. reg_ctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx));
  1381. reg_ctl &= ~IXGBE_TXDCTL_ENABLE;
  1382. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx), reg_ctl);
  1383. switch (hw->mac.type) {
  1384. case ixgbe_mac_82599EB:
  1385. case ixgbe_mac_X540:
  1386. reg_ctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  1387. reg_ctl &= ~IXGBE_DMATXCTL_TE;
  1388. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_ctl);
  1389. break;
  1390. default:
  1391. break;
  1392. }
  1393. ixgbe_reset(adapter);
  1394. ixgbe_free_tx_resources(&adapter->test_tx_ring);
  1395. ixgbe_free_rx_resources(&adapter->test_rx_ring);
  1396. }
  1397. static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter)
  1398. {
  1399. struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
  1400. struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
  1401. u32 rctl, reg_data;
  1402. int ret_val;
  1403. int err;
  1404. /* Setup Tx descriptor ring and Tx buffers */
  1405. tx_ring->count = IXGBE_DEFAULT_TXD;
  1406. tx_ring->queue_index = 0;
  1407. tx_ring->dev = &adapter->pdev->dev;
  1408. tx_ring->netdev = adapter->netdev;
  1409. tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx;
  1410. tx_ring->numa_node = adapter->node;
  1411. err = ixgbe_setup_tx_resources(tx_ring);
  1412. if (err)
  1413. return 1;
  1414. switch (adapter->hw.mac.type) {
  1415. case ixgbe_mac_82599EB:
  1416. case ixgbe_mac_X540:
  1417. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_DMATXCTL);
  1418. reg_data |= IXGBE_DMATXCTL_TE;
  1419. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DMATXCTL, reg_data);
  1420. break;
  1421. default:
  1422. break;
  1423. }
  1424. ixgbe_configure_tx_ring(adapter, tx_ring);
  1425. /* Setup Rx Descriptor ring and Rx buffers */
  1426. rx_ring->count = IXGBE_DEFAULT_RXD;
  1427. rx_ring->queue_index = 0;
  1428. rx_ring->dev = &adapter->pdev->dev;
  1429. rx_ring->netdev = adapter->netdev;
  1430. rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx;
  1431. rx_ring->rx_buf_len = IXGBE_RXBUFFER_2048;
  1432. rx_ring->numa_node = adapter->node;
  1433. err = ixgbe_setup_rx_resources(rx_ring);
  1434. if (err) {
  1435. ret_val = 4;
  1436. goto err_nomem;
  1437. }
  1438. rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXCTRL);
  1439. IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl & ~IXGBE_RXCTRL_RXEN);
  1440. ixgbe_configure_rx_ring(adapter, rx_ring);
  1441. rctl |= IXGBE_RXCTRL_RXEN | IXGBE_RXCTRL_DMBYPS;
  1442. IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl);
  1443. return 0;
  1444. err_nomem:
  1445. ixgbe_free_desc_rings(adapter);
  1446. return ret_val;
  1447. }
  1448. static int ixgbe_setup_loopback_test(struct ixgbe_adapter *adapter)
  1449. {
  1450. struct ixgbe_hw *hw = &adapter->hw;
  1451. u32 reg_data;
  1452. /* X540 needs to set the MACC.FLU bit to force link up */
  1453. if (adapter->hw.mac.type == ixgbe_mac_X540) {
  1454. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_MACC);
  1455. reg_data |= IXGBE_MACC_FLU;
  1456. IXGBE_WRITE_REG(&adapter->hw, IXGBE_MACC, reg_data);
  1457. }
  1458. /* right now we only support MAC loopback in the driver */
  1459. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
  1460. /* Setup MAC loopback */
  1461. reg_data |= IXGBE_HLREG0_LPBK;
  1462. IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
  1463. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
  1464. reg_data |= IXGBE_FCTRL_BAM | IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE;
  1465. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_data);
  1466. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_AUTOC);
  1467. reg_data &= ~IXGBE_AUTOC_LMS_MASK;
  1468. reg_data |= IXGBE_AUTOC_LMS_10G_LINK_NO_AN | IXGBE_AUTOC_FLU;
  1469. IXGBE_WRITE_REG(&adapter->hw, IXGBE_AUTOC, reg_data);
  1470. IXGBE_WRITE_FLUSH(&adapter->hw);
  1471. usleep_range(10000, 20000);
  1472. /* Disable Atlas Tx lanes; re-enabled in reset path */
  1473. if (hw->mac.type == ixgbe_mac_82598EB) {
  1474. u8 atlas;
  1475. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &atlas);
  1476. atlas |= IXGBE_ATLAS_PDN_TX_REG_EN;
  1477. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, atlas);
  1478. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &atlas);
  1479. atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  1480. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, atlas);
  1481. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &atlas);
  1482. atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  1483. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, atlas);
  1484. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &atlas);
  1485. atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  1486. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, atlas);
  1487. }
  1488. return 0;
  1489. }
  1490. static void ixgbe_loopback_cleanup(struct ixgbe_adapter *adapter)
  1491. {
  1492. u32 reg_data;
  1493. reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
  1494. reg_data &= ~IXGBE_HLREG0_LPBK;
  1495. IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
  1496. }
  1497. static void ixgbe_create_lbtest_frame(struct sk_buff *skb,
  1498. unsigned int frame_size)
  1499. {
  1500. memset(skb->data, 0xFF, frame_size);
  1501. frame_size &= ~1;
  1502. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  1503. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  1504. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  1505. }
  1506. static int ixgbe_check_lbtest_frame(struct sk_buff *skb,
  1507. unsigned int frame_size)
  1508. {
  1509. frame_size &= ~1;
  1510. if (*(skb->data + 3) == 0xFF) {
  1511. if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
  1512. (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
  1513. return 0;
  1514. }
  1515. }
  1516. return 13;
  1517. }
  1518. static u16 ixgbe_clean_test_rings(struct ixgbe_ring *rx_ring,
  1519. struct ixgbe_ring *tx_ring,
  1520. unsigned int size)
  1521. {
  1522. union ixgbe_adv_rx_desc *rx_desc;
  1523. struct ixgbe_rx_buffer *rx_buffer_info;
  1524. struct ixgbe_tx_buffer *tx_buffer_info;
  1525. const int bufsz = rx_ring->rx_buf_len;
  1526. u32 staterr;
  1527. u16 rx_ntc, tx_ntc, count = 0;
  1528. /* initialize next to clean and descriptor values */
  1529. rx_ntc = rx_ring->next_to_clean;
  1530. tx_ntc = tx_ring->next_to_clean;
  1531. rx_desc = IXGBE_RX_DESC_ADV(rx_ring, rx_ntc);
  1532. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1533. while (staterr & IXGBE_RXD_STAT_DD) {
  1534. /* check Rx buffer */
  1535. rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
  1536. /* unmap Rx buffer, will be remapped by alloc_rx_buffers */
  1537. dma_unmap_single(rx_ring->dev,
  1538. rx_buffer_info->dma,
  1539. bufsz,
  1540. DMA_FROM_DEVICE);
  1541. rx_buffer_info->dma = 0;
  1542. /* verify contents of skb */
  1543. if (!ixgbe_check_lbtest_frame(rx_buffer_info->skb, size))
  1544. count++;
  1545. /* unmap buffer on Tx side */
  1546. tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
  1547. ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  1548. /* increment Rx/Tx next to clean counters */
  1549. rx_ntc++;
  1550. if (rx_ntc == rx_ring->count)
  1551. rx_ntc = 0;
  1552. tx_ntc++;
  1553. if (tx_ntc == tx_ring->count)
  1554. tx_ntc = 0;
  1555. /* fetch next descriptor */
  1556. rx_desc = IXGBE_RX_DESC_ADV(rx_ring, rx_ntc);
  1557. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1558. }
  1559. /* re-map buffers to ring, store next to clean values */
  1560. ixgbe_alloc_rx_buffers(rx_ring, count);
  1561. rx_ring->next_to_clean = rx_ntc;
  1562. tx_ring->next_to_clean = tx_ntc;
  1563. return count;
  1564. }
  1565. static int ixgbe_run_loopback_test(struct ixgbe_adapter *adapter)
  1566. {
  1567. struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
  1568. struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
  1569. int i, j, lc, good_cnt, ret_val = 0;
  1570. unsigned int size = 1024;
  1571. netdev_tx_t tx_ret_val;
  1572. struct sk_buff *skb;
  1573. /* allocate test skb */
  1574. skb = alloc_skb(size, GFP_KERNEL);
  1575. if (!skb)
  1576. return 11;
  1577. /* place data into test skb */
  1578. ixgbe_create_lbtest_frame(skb, size);
  1579. skb_put(skb, size);
  1580. /*
  1581. * Calculate the loop count based on the largest descriptor ring
  1582. * The idea is to wrap the largest ring a number of times using 64
  1583. * send/receive pairs during each loop
  1584. */
  1585. if (rx_ring->count <= tx_ring->count)
  1586. lc = ((tx_ring->count / 64) * 2) + 1;
  1587. else
  1588. lc = ((rx_ring->count / 64) * 2) + 1;
  1589. for (j = 0; j <= lc; j++) {
  1590. /* reset count of good packets */
  1591. good_cnt = 0;
  1592. /* place 64 packets on the transmit queue*/
  1593. for (i = 0; i < 64; i++) {
  1594. skb_get(skb);
  1595. tx_ret_val = ixgbe_xmit_frame_ring(skb,
  1596. adapter,
  1597. tx_ring);
  1598. if (tx_ret_val == NETDEV_TX_OK)
  1599. good_cnt++;
  1600. }
  1601. if (good_cnt != 64) {
  1602. ret_val = 12;
  1603. break;
  1604. }
  1605. /* allow 200 milliseconds for packets to go from Tx to Rx */
  1606. msleep(200);
  1607. good_cnt = ixgbe_clean_test_rings(rx_ring, tx_ring, size);
  1608. if (good_cnt != 64) {
  1609. ret_val = 13;
  1610. break;
  1611. }
  1612. }
  1613. /* free the original skb */
  1614. kfree_skb(skb);
  1615. return ret_val;
  1616. }
  1617. static int ixgbe_loopback_test(struct ixgbe_adapter *adapter, u64 *data)
  1618. {
  1619. *data = ixgbe_setup_desc_rings(adapter);
  1620. if (*data)
  1621. goto out;
  1622. *data = ixgbe_setup_loopback_test(adapter);
  1623. if (*data)
  1624. goto err_loopback;
  1625. *data = ixgbe_run_loopback_test(adapter);
  1626. ixgbe_loopback_cleanup(adapter);
  1627. err_loopback:
  1628. ixgbe_free_desc_rings(adapter);
  1629. out:
  1630. return *data;
  1631. }
  1632. static void ixgbe_diag_test(struct net_device *netdev,
  1633. struct ethtool_test *eth_test, u64 *data)
  1634. {
  1635. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1636. bool if_running = netif_running(netdev);
  1637. set_bit(__IXGBE_TESTING, &adapter->state);
  1638. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1639. /* Offline tests */
  1640. e_info(hw, "offline testing starting\n");
  1641. /* Link test performed before hardware reset so autoneg doesn't
  1642. * interfere with test result */
  1643. if (ixgbe_link_test(adapter, &data[4]))
  1644. eth_test->flags |= ETH_TEST_FL_FAILED;
  1645. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  1646. int i;
  1647. for (i = 0; i < adapter->num_vfs; i++) {
  1648. if (adapter->vfinfo[i].clear_to_send) {
  1649. netdev_warn(netdev, "%s",
  1650. "offline diagnostic is not "
  1651. "supported when VFs are "
  1652. "present\n");
  1653. data[0] = 1;
  1654. data[1] = 1;
  1655. data[2] = 1;
  1656. data[3] = 1;
  1657. eth_test->flags |= ETH_TEST_FL_FAILED;
  1658. clear_bit(__IXGBE_TESTING,
  1659. &adapter->state);
  1660. goto skip_ol_tests;
  1661. }
  1662. }
  1663. }
  1664. if (if_running)
  1665. /* indicate we're in test mode */
  1666. dev_close(netdev);
  1667. else
  1668. ixgbe_reset(adapter);
  1669. e_info(hw, "register testing starting\n");
  1670. if (ixgbe_reg_test(adapter, &data[0]))
  1671. eth_test->flags |= ETH_TEST_FL_FAILED;
  1672. ixgbe_reset(adapter);
  1673. e_info(hw, "eeprom testing starting\n");
  1674. if (ixgbe_eeprom_test(adapter, &data[1]))
  1675. eth_test->flags |= ETH_TEST_FL_FAILED;
  1676. ixgbe_reset(adapter);
  1677. e_info(hw, "interrupt testing starting\n");
  1678. if (ixgbe_intr_test(adapter, &data[2]))
  1679. eth_test->flags |= ETH_TEST_FL_FAILED;
  1680. /* If SRIOV or VMDq is enabled then skip MAC
  1681. * loopback diagnostic. */
  1682. if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
  1683. IXGBE_FLAG_VMDQ_ENABLED)) {
  1684. e_info(hw, "Skip MAC loopback diagnostic in VT "
  1685. "mode\n");
  1686. data[3] = 0;
  1687. goto skip_loopback;
  1688. }
  1689. ixgbe_reset(adapter);
  1690. e_info(hw, "loopback testing starting\n");
  1691. if (ixgbe_loopback_test(adapter, &data[3]))
  1692. eth_test->flags |= ETH_TEST_FL_FAILED;
  1693. skip_loopback:
  1694. ixgbe_reset(adapter);
  1695. clear_bit(__IXGBE_TESTING, &adapter->state);
  1696. if (if_running)
  1697. dev_open(netdev);
  1698. } else {
  1699. e_info(hw, "online testing starting\n");
  1700. /* Online tests */
  1701. if (ixgbe_link_test(adapter, &data[4]))
  1702. eth_test->flags |= ETH_TEST_FL_FAILED;
  1703. /* Online tests aren't run; pass by default */
  1704. data[0] = 0;
  1705. data[1] = 0;
  1706. data[2] = 0;
  1707. data[3] = 0;
  1708. clear_bit(__IXGBE_TESTING, &adapter->state);
  1709. }
  1710. skip_ol_tests:
  1711. msleep_interruptible(4 * 1000);
  1712. }
  1713. static int ixgbe_wol_exclusion(struct ixgbe_adapter *adapter,
  1714. struct ethtool_wolinfo *wol)
  1715. {
  1716. struct ixgbe_hw *hw = &adapter->hw;
  1717. int retval = 1;
  1718. /* WOL not supported except for the following */
  1719. switch(hw->device_id) {
  1720. case IXGBE_DEV_ID_82599_SFP:
  1721. /* Only this subdevice supports WOL */
  1722. if (hw->subsystem_device_id != IXGBE_SUBDEV_ID_82599_SFP) {
  1723. wol->supported = 0;
  1724. break;
  1725. }
  1726. retval = 0;
  1727. break;
  1728. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  1729. /* All except this subdevice support WOL */
  1730. if (hw->subsystem_device_id ==
  1731. IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) {
  1732. wol->supported = 0;
  1733. break;
  1734. }
  1735. retval = 0;
  1736. break;
  1737. case IXGBE_DEV_ID_82599_KX4:
  1738. retval = 0;
  1739. break;
  1740. default:
  1741. wol->supported = 0;
  1742. }
  1743. return retval;
  1744. }
  1745. static void ixgbe_get_wol(struct net_device *netdev,
  1746. struct ethtool_wolinfo *wol)
  1747. {
  1748. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1749. wol->supported = WAKE_UCAST | WAKE_MCAST |
  1750. WAKE_BCAST | WAKE_MAGIC;
  1751. wol->wolopts = 0;
  1752. if (ixgbe_wol_exclusion(adapter, wol) ||
  1753. !device_can_wakeup(&adapter->pdev->dev))
  1754. return;
  1755. if (adapter->wol & IXGBE_WUFC_EX)
  1756. wol->wolopts |= WAKE_UCAST;
  1757. if (adapter->wol & IXGBE_WUFC_MC)
  1758. wol->wolopts |= WAKE_MCAST;
  1759. if (adapter->wol & IXGBE_WUFC_BC)
  1760. wol->wolopts |= WAKE_BCAST;
  1761. if (adapter->wol & IXGBE_WUFC_MAG)
  1762. wol->wolopts |= WAKE_MAGIC;
  1763. }
  1764. static int ixgbe_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1765. {
  1766. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1767. if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
  1768. return -EOPNOTSUPP;
  1769. if (ixgbe_wol_exclusion(adapter, wol))
  1770. return wol->wolopts ? -EOPNOTSUPP : 0;
  1771. adapter->wol = 0;
  1772. if (wol->wolopts & WAKE_UCAST)
  1773. adapter->wol |= IXGBE_WUFC_EX;
  1774. if (wol->wolopts & WAKE_MCAST)
  1775. adapter->wol |= IXGBE_WUFC_MC;
  1776. if (wol->wolopts & WAKE_BCAST)
  1777. adapter->wol |= IXGBE_WUFC_BC;
  1778. if (wol->wolopts & WAKE_MAGIC)
  1779. adapter->wol |= IXGBE_WUFC_MAG;
  1780. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1781. return 0;
  1782. }
  1783. static int ixgbe_nway_reset(struct net_device *netdev)
  1784. {
  1785. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1786. if (netif_running(netdev))
  1787. ixgbe_reinit_locked(adapter);
  1788. return 0;
  1789. }
  1790. static int ixgbe_set_phys_id(struct net_device *netdev,
  1791. enum ethtool_phys_id_state state)
  1792. {
  1793. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1794. struct ixgbe_hw *hw = &adapter->hw;
  1795. switch (state) {
  1796. case ETHTOOL_ID_ACTIVE:
  1797. adapter->led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1798. return 2;
  1799. case ETHTOOL_ID_ON:
  1800. hw->mac.ops.led_on(hw, IXGBE_LED_ON);
  1801. break;
  1802. case ETHTOOL_ID_OFF:
  1803. hw->mac.ops.led_off(hw, IXGBE_LED_ON);
  1804. break;
  1805. case ETHTOOL_ID_INACTIVE:
  1806. /* Restore LED settings */
  1807. IXGBE_WRITE_REG(&adapter->hw, IXGBE_LEDCTL, adapter->led_reg);
  1808. break;
  1809. }
  1810. return 0;
  1811. }
  1812. static int ixgbe_get_coalesce(struct net_device *netdev,
  1813. struct ethtool_coalesce *ec)
  1814. {
  1815. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1816. ec->tx_max_coalesced_frames_irq = adapter->tx_ring[0]->work_limit;
  1817. /* only valid if in constant ITR mode */
  1818. switch (adapter->rx_itr_setting) {
  1819. case 0:
  1820. /* throttling disabled */
  1821. ec->rx_coalesce_usecs = 0;
  1822. break;
  1823. case 1:
  1824. /* dynamic ITR mode */
  1825. ec->rx_coalesce_usecs = 1;
  1826. break;
  1827. default:
  1828. /* fixed interrupt rate mode */
  1829. ec->rx_coalesce_usecs = 1000000/adapter->rx_eitr_param;
  1830. break;
  1831. }
  1832. /* if in mixed tx/rx queues per vector mode, report only rx settings */
  1833. if (adapter->q_vector[0]->txr_count && adapter->q_vector[0]->rxr_count)
  1834. return 0;
  1835. /* only valid if in constant ITR mode */
  1836. switch (adapter->tx_itr_setting) {
  1837. case 0:
  1838. /* throttling disabled */
  1839. ec->tx_coalesce_usecs = 0;
  1840. break;
  1841. case 1:
  1842. /* dynamic ITR mode */
  1843. ec->tx_coalesce_usecs = 1;
  1844. break;
  1845. default:
  1846. ec->tx_coalesce_usecs = 1000000/adapter->tx_eitr_param;
  1847. break;
  1848. }
  1849. return 0;
  1850. }
  1851. /*
  1852. * this function must be called before setting the new value of
  1853. * rx_itr_setting
  1854. */
  1855. static bool ixgbe_update_rsc(struct ixgbe_adapter *adapter,
  1856. struct ethtool_coalesce *ec)
  1857. {
  1858. struct net_device *netdev = adapter->netdev;
  1859. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  1860. return false;
  1861. /* if interrupt rate is too high then disable RSC */
  1862. if (ec->rx_coalesce_usecs != 1 &&
  1863. ec->rx_coalesce_usecs <= 1000000/IXGBE_MAX_RSC_INT_RATE) {
  1864. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  1865. e_info(probe, "rx-usecs set too low, "
  1866. "disabling RSC\n");
  1867. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  1868. return true;
  1869. }
  1870. } else {
  1871. /* check the feature flag value and enable RSC if necessary */
  1872. if ((netdev->features & NETIF_F_LRO) &&
  1873. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  1874. e_info(probe, "rx-usecs set to %d, "
  1875. "re-enabling RSC\n",
  1876. ec->rx_coalesce_usecs);
  1877. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  1878. return true;
  1879. }
  1880. }
  1881. return false;
  1882. }
  1883. static int ixgbe_set_coalesce(struct net_device *netdev,
  1884. struct ethtool_coalesce *ec)
  1885. {
  1886. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1887. struct ixgbe_q_vector *q_vector;
  1888. int i;
  1889. bool need_reset = false;
  1890. /* don't accept tx specific changes if we've got mixed RxTx vectors */
  1891. if (adapter->q_vector[0]->txr_count && adapter->q_vector[0]->rxr_count
  1892. && ec->tx_coalesce_usecs)
  1893. return -EINVAL;
  1894. if (ec->tx_max_coalesced_frames_irq)
  1895. adapter->tx_ring[0]->work_limit = ec->tx_max_coalesced_frames_irq;
  1896. if (ec->rx_coalesce_usecs > 1) {
  1897. /* check the limits */
  1898. if ((1000000/ec->rx_coalesce_usecs > IXGBE_MAX_INT_RATE) ||
  1899. (1000000/ec->rx_coalesce_usecs < IXGBE_MIN_INT_RATE))
  1900. return -EINVAL;
  1901. /* check the old value and enable RSC if necessary */
  1902. need_reset = ixgbe_update_rsc(adapter, ec);
  1903. /* store the value in ints/second */
  1904. adapter->rx_eitr_param = 1000000/ec->rx_coalesce_usecs;
  1905. /* static value of interrupt rate */
  1906. adapter->rx_itr_setting = adapter->rx_eitr_param;
  1907. /* clear the lower bit as its used for dynamic state */
  1908. adapter->rx_itr_setting &= ~1;
  1909. } else if (ec->rx_coalesce_usecs == 1) {
  1910. /* check the old value and enable RSC if necessary */
  1911. need_reset = ixgbe_update_rsc(adapter, ec);
  1912. /* 1 means dynamic mode */
  1913. adapter->rx_eitr_param = 20000;
  1914. adapter->rx_itr_setting = 1;
  1915. } else {
  1916. /* check the old value and enable RSC if necessary */
  1917. need_reset = ixgbe_update_rsc(adapter, ec);
  1918. /*
  1919. * any other value means disable eitr, which is best
  1920. * served by setting the interrupt rate very high
  1921. */
  1922. adapter->rx_eitr_param = IXGBE_MAX_INT_RATE;
  1923. adapter->rx_itr_setting = 0;
  1924. }
  1925. if (ec->tx_coalesce_usecs > 1) {
  1926. /*
  1927. * don't have to worry about max_int as above because
  1928. * tx vectors don't do hardware RSC (an rx function)
  1929. */
  1930. /* check the limits */
  1931. if ((1000000/ec->tx_coalesce_usecs > IXGBE_MAX_INT_RATE) ||
  1932. (1000000/ec->tx_coalesce_usecs < IXGBE_MIN_INT_RATE))
  1933. return -EINVAL;
  1934. /* store the value in ints/second */
  1935. adapter->tx_eitr_param = 1000000/ec->tx_coalesce_usecs;
  1936. /* static value of interrupt rate */
  1937. adapter->tx_itr_setting = adapter->tx_eitr_param;
  1938. /* clear the lower bit as its used for dynamic state */
  1939. adapter->tx_itr_setting &= ~1;
  1940. } else if (ec->tx_coalesce_usecs == 1) {
  1941. /* 1 means dynamic mode */
  1942. adapter->tx_eitr_param = 10000;
  1943. adapter->tx_itr_setting = 1;
  1944. } else {
  1945. adapter->tx_eitr_param = IXGBE_MAX_INT_RATE;
  1946. adapter->tx_itr_setting = 0;
  1947. }
  1948. /* MSI/MSIx Interrupt Mode */
  1949. if (adapter->flags &
  1950. (IXGBE_FLAG_MSIX_ENABLED | IXGBE_FLAG_MSI_ENABLED)) {
  1951. int num_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1952. for (i = 0; i < num_vectors; i++) {
  1953. q_vector = adapter->q_vector[i];
  1954. if (q_vector->txr_count && !q_vector->rxr_count)
  1955. /* tx only */
  1956. q_vector->eitr = adapter->tx_eitr_param;
  1957. else
  1958. /* rx only or mixed */
  1959. q_vector->eitr = adapter->rx_eitr_param;
  1960. ixgbe_write_eitr(q_vector);
  1961. }
  1962. /* Legacy Interrupt Mode */
  1963. } else {
  1964. q_vector = adapter->q_vector[0];
  1965. q_vector->eitr = adapter->rx_eitr_param;
  1966. ixgbe_write_eitr(q_vector);
  1967. }
  1968. /*
  1969. * do reset here at the end to make sure EITR==0 case is handled
  1970. * correctly w.r.t stopping tx, and changing TXDCTL.WTHRESH settings
  1971. * also locks in RSC enable/disable which requires reset
  1972. */
  1973. if (need_reset) {
  1974. if (netif_running(netdev))
  1975. ixgbe_reinit_locked(adapter);
  1976. else
  1977. ixgbe_reset(adapter);
  1978. }
  1979. return 0;
  1980. }
  1981. static int ixgbe_set_flags(struct net_device *netdev, u32 data)
  1982. {
  1983. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1984. bool need_reset = false;
  1985. int rc;
  1986. #ifdef CONFIG_IXGBE_DCB
  1987. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  1988. !(data & ETH_FLAG_RXVLAN))
  1989. return -EINVAL;
  1990. #endif
  1991. need_reset = (data & ETH_FLAG_RXVLAN) !=
  1992. (netdev->features & NETIF_F_HW_VLAN_RX);
  1993. if ((data & ETH_FLAG_RXHASH) &&
  1994. !(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
  1995. return -EOPNOTSUPP;
  1996. rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_LRO | ETH_FLAG_NTUPLE |
  1997. ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN |
  1998. ETH_FLAG_RXHASH);
  1999. if (rc)
  2000. return rc;
  2001. /* if state changes we need to update adapter->flags and reset */
  2002. if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  2003. (!!(data & ETH_FLAG_LRO) !=
  2004. !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))) {
  2005. if ((data & ETH_FLAG_LRO) &&
  2006. (!adapter->rx_itr_setting ||
  2007. (adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE))) {
  2008. e_info(probe, "rx-usecs set too low, "
  2009. "not enabling RSC.\n");
  2010. } else {
  2011. adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
  2012. switch (adapter->hw.mac.type) {
  2013. case ixgbe_mac_82599EB:
  2014. need_reset = true;
  2015. break;
  2016. case ixgbe_mac_X540: {
  2017. int i;
  2018. for (i = 0; i < adapter->num_rx_queues; i++) {
  2019. struct ixgbe_ring *ring =
  2020. adapter->rx_ring[i];
  2021. if (adapter->flags2 &
  2022. IXGBE_FLAG2_RSC_ENABLED) {
  2023. ixgbe_configure_rscctl(adapter,
  2024. ring);
  2025. } else {
  2026. ixgbe_clear_rscctl(adapter,
  2027. ring);
  2028. }
  2029. }
  2030. }
  2031. break;
  2032. default:
  2033. break;
  2034. }
  2035. }
  2036. }
  2037. /*
  2038. * Check if Flow Director n-tuple support was enabled or disabled. If
  2039. * the state changed, we need to reset.
  2040. */
  2041. if ((adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) &&
  2042. (!(data & ETH_FLAG_NTUPLE))) {
  2043. /* turn off Flow Director perfect, set hash and reset */
  2044. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  2045. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  2046. need_reset = true;
  2047. } else if ((!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) &&
  2048. (data & ETH_FLAG_NTUPLE)) {
  2049. /* turn off Flow Director hash, enable perfect and reset */
  2050. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  2051. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  2052. need_reset = true;
  2053. } else {
  2054. /* no state change */
  2055. }
  2056. if (need_reset) {
  2057. if (netif_running(netdev))
  2058. ixgbe_reinit_locked(adapter);
  2059. else
  2060. ixgbe_reset(adapter);
  2061. }
  2062. return 0;
  2063. }
  2064. static int ixgbe_set_rx_ntuple(struct net_device *dev,
  2065. struct ethtool_rx_ntuple *cmd)
  2066. {
  2067. struct ixgbe_adapter *adapter = netdev_priv(dev);
  2068. struct ethtool_rx_ntuple_flow_spec *fs = &cmd->fs;
  2069. union ixgbe_atr_input input_struct;
  2070. struct ixgbe_atr_input_masks input_masks;
  2071. int target_queue;
  2072. int err;
  2073. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  2074. return -EOPNOTSUPP;
  2075. /*
  2076. * Don't allow programming if the action is a queue greater than
  2077. * the number of online Tx queues.
  2078. */
  2079. if ((fs->action >= adapter->num_tx_queues) ||
  2080. (fs->action < ETHTOOL_RXNTUPLE_ACTION_DROP))
  2081. return -EINVAL;
  2082. memset(&input_struct, 0, sizeof(union ixgbe_atr_input));
  2083. memset(&input_masks, 0, sizeof(struct ixgbe_atr_input_masks));
  2084. /* record flow type */
  2085. switch (fs->flow_type) {
  2086. case IPV4_FLOW:
  2087. input_struct.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_IPV4;
  2088. break;
  2089. case TCP_V4_FLOW:
  2090. input_struct.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  2091. break;
  2092. case UDP_V4_FLOW:
  2093. input_struct.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4;
  2094. break;
  2095. case SCTP_V4_FLOW:
  2096. input_struct.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4;
  2097. break;
  2098. default:
  2099. return -1;
  2100. }
  2101. /* copy vlan tag minus the CFI bit */
  2102. if ((fs->vlan_tag & 0xEFFF) || (~fs->vlan_tag_mask & 0xEFFF)) {
  2103. input_struct.formatted.vlan_id = htons(fs->vlan_tag & 0xEFFF);
  2104. if (!fs->vlan_tag_mask) {
  2105. input_masks.vlan_id_mask = htons(0xEFFF);
  2106. } else {
  2107. switch (~fs->vlan_tag_mask & 0xEFFF) {
  2108. /* all of these are valid vlan-mask values */
  2109. case 0xEFFF:
  2110. case 0xE000:
  2111. case 0x0FFF:
  2112. case 0x0000:
  2113. input_masks.vlan_id_mask =
  2114. htons(~fs->vlan_tag_mask);
  2115. break;
  2116. /* exit with error if vlan-mask is invalid */
  2117. default:
  2118. e_err(drv, "Partial VLAN ID or "
  2119. "priority mask in vlan-mask is not "
  2120. "supported by hardware\n");
  2121. return -1;
  2122. }
  2123. }
  2124. }
  2125. /* make sure we only use the first 2 bytes of user data */
  2126. if ((fs->data & 0xFFFF) || (~fs->data_mask & 0xFFFF)) {
  2127. input_struct.formatted.flex_bytes = htons(fs->data & 0xFFFF);
  2128. if (!(fs->data_mask & 0xFFFF)) {
  2129. input_masks.flex_mask = 0xFFFF;
  2130. } else if (~fs->data_mask & 0xFFFF) {
  2131. e_err(drv, "Partial user-def-mask is not "
  2132. "supported by hardware\n");
  2133. return -1;
  2134. }
  2135. }
  2136. /*
  2137. * Copy input into formatted structures
  2138. *
  2139. * These assignments are based on the following logic
  2140. * If neither input or mask are set assume value is masked out.
  2141. * If input is set, but mask is not mask should default to accept all.
  2142. * If input is not set, but mask is set then mask likely results in 0.
  2143. * If input is set and mask is set then assign both.
  2144. */
  2145. if (fs->h_u.tcp_ip4_spec.ip4src || ~fs->m_u.tcp_ip4_spec.ip4src) {
  2146. input_struct.formatted.src_ip[0] = fs->h_u.tcp_ip4_spec.ip4src;
  2147. if (!fs->m_u.tcp_ip4_spec.ip4src)
  2148. input_masks.src_ip_mask[0] = 0xFFFFFFFF;
  2149. else
  2150. input_masks.src_ip_mask[0] =
  2151. ~fs->m_u.tcp_ip4_spec.ip4src;
  2152. }
  2153. if (fs->h_u.tcp_ip4_spec.ip4dst || ~fs->m_u.tcp_ip4_spec.ip4dst) {
  2154. input_struct.formatted.dst_ip[0] = fs->h_u.tcp_ip4_spec.ip4dst;
  2155. if (!fs->m_u.tcp_ip4_spec.ip4dst)
  2156. input_masks.dst_ip_mask[0] = 0xFFFFFFFF;
  2157. else
  2158. input_masks.dst_ip_mask[0] =
  2159. ~fs->m_u.tcp_ip4_spec.ip4dst;
  2160. }
  2161. if (fs->h_u.tcp_ip4_spec.psrc || ~fs->m_u.tcp_ip4_spec.psrc) {
  2162. input_struct.formatted.src_port = fs->h_u.tcp_ip4_spec.psrc;
  2163. if (!fs->m_u.tcp_ip4_spec.psrc)
  2164. input_masks.src_port_mask = 0xFFFF;
  2165. else
  2166. input_masks.src_port_mask = ~fs->m_u.tcp_ip4_spec.psrc;
  2167. }
  2168. if (fs->h_u.tcp_ip4_spec.pdst || ~fs->m_u.tcp_ip4_spec.pdst) {
  2169. input_struct.formatted.dst_port = fs->h_u.tcp_ip4_spec.pdst;
  2170. if (!fs->m_u.tcp_ip4_spec.pdst)
  2171. input_masks.dst_port_mask = 0xFFFF;
  2172. else
  2173. input_masks.dst_port_mask = ~fs->m_u.tcp_ip4_spec.pdst;
  2174. }
  2175. /* determine if we need to drop or route the packet */
  2176. if (fs->action == ETHTOOL_RXNTUPLE_ACTION_DROP)
  2177. target_queue = MAX_RX_QUEUES - 1;
  2178. else
  2179. target_queue = fs->action;
  2180. spin_lock(&adapter->fdir_perfect_lock);
  2181. err = ixgbe_fdir_add_perfect_filter_82599(&adapter->hw,
  2182. &input_struct,
  2183. &input_masks, 0,
  2184. target_queue);
  2185. spin_unlock(&adapter->fdir_perfect_lock);
  2186. return err ? -1 : 0;
  2187. }
  2188. static const struct ethtool_ops ixgbe_ethtool_ops = {
  2189. .get_settings = ixgbe_get_settings,
  2190. .set_settings = ixgbe_set_settings,
  2191. .get_drvinfo = ixgbe_get_drvinfo,
  2192. .get_regs_len = ixgbe_get_regs_len,
  2193. .get_regs = ixgbe_get_regs,
  2194. .get_wol = ixgbe_get_wol,
  2195. .set_wol = ixgbe_set_wol,
  2196. .nway_reset = ixgbe_nway_reset,
  2197. .get_link = ethtool_op_get_link,
  2198. .get_eeprom_len = ixgbe_get_eeprom_len,
  2199. .get_eeprom = ixgbe_get_eeprom,
  2200. .get_ringparam = ixgbe_get_ringparam,
  2201. .set_ringparam = ixgbe_set_ringparam,
  2202. .get_pauseparam = ixgbe_get_pauseparam,
  2203. .set_pauseparam = ixgbe_set_pauseparam,
  2204. .get_rx_csum = ixgbe_get_rx_csum,
  2205. .set_rx_csum = ixgbe_set_rx_csum,
  2206. .get_tx_csum = ixgbe_get_tx_csum,
  2207. .set_tx_csum = ixgbe_set_tx_csum,
  2208. .get_sg = ethtool_op_get_sg,
  2209. .set_sg = ethtool_op_set_sg,
  2210. .get_msglevel = ixgbe_get_msglevel,
  2211. .set_msglevel = ixgbe_set_msglevel,
  2212. .get_tso = ethtool_op_get_tso,
  2213. .set_tso = ixgbe_set_tso,
  2214. .self_test = ixgbe_diag_test,
  2215. .get_strings = ixgbe_get_strings,
  2216. .set_phys_id = ixgbe_set_phys_id,
  2217. .get_sset_count = ixgbe_get_sset_count,
  2218. .get_ethtool_stats = ixgbe_get_ethtool_stats,
  2219. .get_coalesce = ixgbe_get_coalesce,
  2220. .set_coalesce = ixgbe_set_coalesce,
  2221. .get_flags = ethtool_op_get_flags,
  2222. .set_flags = ixgbe_set_flags,
  2223. .set_rx_ntuple = ixgbe_set_rx_ntuple,
  2224. };
  2225. void ixgbe_set_ethtool_ops(struct net_device *netdev)
  2226. {
  2227. SET_ETHTOOL_OPS(netdev, &ixgbe_ethtool_ops);
  2228. }