qede_ethtool.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  1. /* QLogic qede NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/version.h>
  33. #include <linux/types.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/etherdevice.h>
  36. #include <linux/ethtool.h>
  37. #include <linux/string.h>
  38. #include <linux/pci.h>
  39. #include <linux/capability.h>
  40. #include <linux/vmalloc.h>
  41. #include "qede.h"
  42. #include "qede_ptp.h"
  43. #define QEDE_RQSTAT_OFFSET(stat_name) \
  44. (offsetof(struct qede_rx_queue, stat_name))
  45. #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
  46. #define QEDE_RQSTAT(stat_name) \
  47. {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
  48. #define QEDE_SELFTEST_POLL_COUNT 100
  49. static const struct {
  50. u64 offset;
  51. char string[ETH_GSTRING_LEN];
  52. } qede_rqstats_arr[] = {
  53. QEDE_RQSTAT(rcv_pkts),
  54. QEDE_RQSTAT(rx_hw_errors),
  55. QEDE_RQSTAT(rx_alloc_errors),
  56. QEDE_RQSTAT(rx_ip_frags),
  57. QEDE_RQSTAT(xdp_no_pass),
  58. };
  59. #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
  60. #define QEDE_TQSTAT_OFFSET(stat_name) \
  61. (offsetof(struct qede_tx_queue, stat_name))
  62. #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
  63. #define QEDE_TQSTAT(stat_name) \
  64. {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
  65. #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
  66. static const struct {
  67. u64 offset;
  68. char string[ETH_GSTRING_LEN];
  69. } qede_tqstats_arr[] = {
  70. QEDE_TQSTAT(xmit_pkts),
  71. QEDE_TQSTAT(stopped_cnt),
  72. };
  73. #define QEDE_STAT_OFFSET(stat_name, type, base) \
  74. (offsetof(type, stat_name) + (base))
  75. #define QEDE_STAT_STRING(stat_name) (#stat_name)
  76. #define _QEDE_STAT(stat_name, type, base, attr) \
  77. {QEDE_STAT_OFFSET(stat_name, type, base), \
  78. QEDE_STAT_STRING(stat_name), \
  79. attr}
  80. #define QEDE_STAT(stat_name) \
  81. _QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0)
  82. #define QEDE_PF_STAT(stat_name) \
  83. _QEDE_STAT(stat_name, struct qede_stats_common, 0, \
  84. BIT(QEDE_STAT_PF_ONLY))
  85. #define QEDE_PF_BB_STAT(stat_name) \
  86. _QEDE_STAT(stat_name, struct qede_stats_bb, \
  87. offsetof(struct qede_stats, bb), \
  88. BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY))
  89. #define QEDE_PF_AH_STAT(stat_name) \
  90. _QEDE_STAT(stat_name, struct qede_stats_ah, \
  91. offsetof(struct qede_stats, ah), \
  92. BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY))
  93. static const struct {
  94. u64 offset;
  95. char string[ETH_GSTRING_LEN];
  96. unsigned long attr;
  97. #define QEDE_STAT_PF_ONLY 0
  98. #define QEDE_STAT_BB_ONLY 1
  99. #define QEDE_STAT_AH_ONLY 2
  100. } qede_stats_arr[] = {
  101. QEDE_STAT(rx_ucast_bytes),
  102. QEDE_STAT(rx_mcast_bytes),
  103. QEDE_STAT(rx_bcast_bytes),
  104. QEDE_STAT(rx_ucast_pkts),
  105. QEDE_STAT(rx_mcast_pkts),
  106. QEDE_STAT(rx_bcast_pkts),
  107. QEDE_STAT(tx_ucast_bytes),
  108. QEDE_STAT(tx_mcast_bytes),
  109. QEDE_STAT(tx_bcast_bytes),
  110. QEDE_STAT(tx_ucast_pkts),
  111. QEDE_STAT(tx_mcast_pkts),
  112. QEDE_STAT(tx_bcast_pkts),
  113. QEDE_PF_STAT(rx_64_byte_packets),
  114. QEDE_PF_STAT(rx_65_to_127_byte_packets),
  115. QEDE_PF_STAT(rx_128_to_255_byte_packets),
  116. QEDE_PF_STAT(rx_256_to_511_byte_packets),
  117. QEDE_PF_STAT(rx_512_to_1023_byte_packets),
  118. QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
  119. QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets),
  120. QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets),
  121. QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets),
  122. QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets),
  123. QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets),
  124. QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets),
  125. QEDE_PF_STAT(tx_64_byte_packets),
  126. QEDE_PF_STAT(tx_65_to_127_byte_packets),
  127. QEDE_PF_STAT(tx_128_to_255_byte_packets),
  128. QEDE_PF_STAT(tx_256_to_511_byte_packets),
  129. QEDE_PF_STAT(tx_512_to_1023_byte_packets),
  130. QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
  131. QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets),
  132. QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets),
  133. QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets),
  134. QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets),
  135. QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets),
  136. QEDE_PF_STAT(rx_mac_crtl_frames),
  137. QEDE_PF_STAT(tx_mac_ctrl_frames),
  138. QEDE_PF_STAT(rx_pause_frames),
  139. QEDE_PF_STAT(tx_pause_frames),
  140. QEDE_PF_STAT(rx_pfc_frames),
  141. QEDE_PF_STAT(tx_pfc_frames),
  142. QEDE_PF_STAT(rx_crc_errors),
  143. QEDE_PF_STAT(rx_align_errors),
  144. QEDE_PF_STAT(rx_carrier_errors),
  145. QEDE_PF_STAT(rx_oversize_packets),
  146. QEDE_PF_STAT(rx_jabbers),
  147. QEDE_PF_STAT(rx_undersize_packets),
  148. QEDE_PF_STAT(rx_fragments),
  149. QEDE_PF_BB_STAT(tx_lpi_entry_count),
  150. QEDE_PF_BB_STAT(tx_total_collisions),
  151. QEDE_PF_STAT(brb_truncates),
  152. QEDE_PF_STAT(brb_discards),
  153. QEDE_STAT(no_buff_discards),
  154. QEDE_PF_STAT(mftag_filter_discards),
  155. QEDE_PF_STAT(mac_filter_discards),
  156. QEDE_STAT(tx_err_drop_pkts),
  157. QEDE_STAT(ttl0_discard),
  158. QEDE_STAT(packet_too_big_discard),
  159. QEDE_STAT(coalesced_pkts),
  160. QEDE_STAT(coalesced_events),
  161. QEDE_STAT(coalesced_aborts_num),
  162. QEDE_STAT(non_coalesced_pkts),
  163. QEDE_STAT(coalesced_bytes),
  164. };
  165. #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
  166. #define QEDE_STAT_IS_PF_ONLY(i) \
  167. test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
  168. #define QEDE_STAT_IS_BB_ONLY(i) \
  169. test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
  170. #define QEDE_STAT_IS_AH_ONLY(i) \
  171. test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
  172. enum {
  173. QEDE_PRI_FLAG_CMT,
  174. QEDE_PRI_FLAG_LEN,
  175. };
  176. static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
  177. "Coupled-Function",
  178. };
  179. enum qede_ethtool_tests {
  180. QEDE_ETHTOOL_INT_LOOPBACK,
  181. QEDE_ETHTOOL_INTERRUPT_TEST,
  182. QEDE_ETHTOOL_MEMORY_TEST,
  183. QEDE_ETHTOOL_REGISTER_TEST,
  184. QEDE_ETHTOOL_CLOCK_TEST,
  185. QEDE_ETHTOOL_NVRAM_TEST,
  186. QEDE_ETHTOOL_TEST_MAX
  187. };
  188. static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
  189. "Internal loopback (offline)",
  190. "Interrupt (online)\t",
  191. "Memory (online)\t\t",
  192. "Register (online)\t",
  193. "Clock (online)\t\t",
  194. "Nvram (online)\t\t",
  195. };
  196. static void qede_get_strings_stats_txq(struct qede_dev *edev,
  197. struct qede_tx_queue *txq, u8 **buf)
  198. {
  199. int i;
  200. for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
  201. if (txq->is_xdp)
  202. sprintf(*buf, "%d [XDP]: %s",
  203. QEDE_TXQ_XDP_TO_IDX(edev, txq),
  204. qede_tqstats_arr[i].string);
  205. else
  206. sprintf(*buf, "%d: %s", txq->index,
  207. qede_tqstats_arr[i].string);
  208. *buf += ETH_GSTRING_LEN;
  209. }
  210. }
  211. static void qede_get_strings_stats_rxq(struct qede_dev *edev,
  212. struct qede_rx_queue *rxq, u8 **buf)
  213. {
  214. int i;
  215. for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
  216. sprintf(*buf, "%d: %s", rxq->rxq_id,
  217. qede_rqstats_arr[i].string);
  218. *buf += ETH_GSTRING_LEN;
  219. }
  220. }
  221. static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
  222. {
  223. return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
  224. (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
  225. (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
  226. }
  227. static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
  228. {
  229. struct qede_fastpath *fp;
  230. int i;
  231. /* Account for queue statistics */
  232. for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
  233. fp = &edev->fp_array[i];
  234. if (fp->type & QEDE_FASTPATH_RX)
  235. qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
  236. if (fp->type & QEDE_FASTPATH_XDP)
  237. qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
  238. if (fp->type & QEDE_FASTPATH_TX)
  239. qede_get_strings_stats_txq(edev, fp->txq, &buf);
  240. }
  241. /* Account for non-queue statistics */
  242. for (i = 0; i < QEDE_NUM_STATS; i++) {
  243. if (qede_is_irrelevant_stat(edev, i))
  244. continue;
  245. strcpy(buf, qede_stats_arr[i].string);
  246. buf += ETH_GSTRING_LEN;
  247. }
  248. }
  249. static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  250. {
  251. struct qede_dev *edev = netdev_priv(dev);
  252. switch (stringset) {
  253. case ETH_SS_STATS:
  254. qede_get_strings_stats(edev, buf);
  255. break;
  256. case ETH_SS_PRIV_FLAGS:
  257. memcpy(buf, qede_private_arr,
  258. ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
  259. break;
  260. case ETH_SS_TEST:
  261. memcpy(buf, qede_tests_str_arr,
  262. ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
  263. break;
  264. default:
  265. DP_VERBOSE(edev, QED_MSG_DEBUG,
  266. "Unsupported stringset 0x%08x\n", stringset);
  267. }
  268. }
  269. static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
  270. {
  271. int i;
  272. for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
  273. **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
  274. (*buf)++;
  275. }
  276. }
  277. static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
  278. {
  279. int i;
  280. for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
  281. **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
  282. (*buf)++;
  283. }
  284. }
  285. static void qede_get_ethtool_stats(struct net_device *dev,
  286. struct ethtool_stats *stats, u64 *buf)
  287. {
  288. struct qede_dev *edev = netdev_priv(dev);
  289. struct qede_fastpath *fp;
  290. int i;
  291. qede_fill_by_demand_stats(edev);
  292. /* Need to protect the access to the fastpath array */
  293. __qede_lock(edev);
  294. for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
  295. fp = &edev->fp_array[i];
  296. if (fp->type & QEDE_FASTPATH_RX)
  297. qede_get_ethtool_stats_rxq(fp->rxq, &buf);
  298. if (fp->type & QEDE_FASTPATH_XDP)
  299. qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
  300. if (fp->type & QEDE_FASTPATH_TX)
  301. qede_get_ethtool_stats_txq(fp->txq, &buf);
  302. }
  303. for (i = 0; i < QEDE_NUM_STATS; i++) {
  304. if (qede_is_irrelevant_stat(edev, i))
  305. continue;
  306. *buf = *((u64 *)(((void *)&edev->stats) +
  307. qede_stats_arr[i].offset));
  308. buf++;
  309. }
  310. __qede_unlock(edev);
  311. }
  312. static int qede_get_sset_count(struct net_device *dev, int stringset)
  313. {
  314. struct qede_dev *edev = netdev_priv(dev);
  315. int num_stats = QEDE_NUM_STATS, i;
  316. switch (stringset) {
  317. case ETH_SS_STATS:
  318. for (i = 0; i < QEDE_NUM_STATS; i++)
  319. if (qede_is_irrelevant_stat(edev, i))
  320. num_stats--;
  321. /* Account for the Regular Tx statistics */
  322. num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
  323. /* Account for the Regular Rx statistics */
  324. num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
  325. /* Account for XDP statistics [if needed] */
  326. if (edev->xdp_prog)
  327. num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
  328. return num_stats;
  329. case ETH_SS_PRIV_FLAGS:
  330. return QEDE_PRI_FLAG_LEN;
  331. case ETH_SS_TEST:
  332. if (!IS_VF(edev))
  333. return QEDE_ETHTOOL_TEST_MAX;
  334. else
  335. return 0;
  336. default:
  337. DP_VERBOSE(edev, QED_MSG_DEBUG,
  338. "Unsupported stringset 0x%08x\n", stringset);
  339. return -EINVAL;
  340. }
  341. }
  342. static u32 qede_get_priv_flags(struct net_device *dev)
  343. {
  344. struct qede_dev *edev = netdev_priv(dev);
  345. return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
  346. }
  347. struct qede_link_mode_mapping {
  348. u32 qed_link_mode;
  349. u32 ethtool_link_mode;
  350. };
  351. static const struct qede_link_mode_mapping qed_lm_map[] = {
  352. {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
  353. {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
  354. {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
  355. {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
  356. {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
  357. {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
  358. {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
  359. {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
  360. {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
  361. {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
  362. {QED_LM_100000baseKR4_Full_BIT,
  363. ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
  364. };
  365. #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
  366. { \
  367. int i; \
  368. \
  369. for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
  370. if ((caps) & (qed_lm_map[i].qed_link_mode)) \
  371. __set_bit(qed_lm_map[i].ethtool_link_mode,\
  372. lk_ksettings->link_modes.name); \
  373. } \
  374. }
  375. #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
  376. { \
  377. int i; \
  378. \
  379. for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
  380. if (test_bit(qed_lm_map[i].ethtool_link_mode, \
  381. lk_ksettings->link_modes.name)) \
  382. caps |= qed_lm_map[i].qed_link_mode; \
  383. } \
  384. }
  385. static int qede_get_link_ksettings(struct net_device *dev,
  386. struct ethtool_link_ksettings *cmd)
  387. {
  388. struct ethtool_link_settings *base = &cmd->base;
  389. struct qede_dev *edev = netdev_priv(dev);
  390. struct qed_link_output current_link;
  391. __qede_lock(edev);
  392. memset(&current_link, 0, sizeof(current_link));
  393. edev->ops->common->get_link(edev->cdev, &current_link);
  394. ethtool_link_ksettings_zero_link_mode(cmd, supported);
  395. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
  396. ethtool_link_ksettings_zero_link_mode(cmd, advertising);
  397. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
  398. ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
  399. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
  400. if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
  401. base->speed = current_link.speed;
  402. base->duplex = current_link.duplex;
  403. } else {
  404. base->speed = SPEED_UNKNOWN;
  405. base->duplex = DUPLEX_UNKNOWN;
  406. }
  407. __qede_unlock(edev);
  408. base->port = current_link.port;
  409. base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
  410. AUTONEG_DISABLE;
  411. return 0;
  412. }
  413. static int qede_set_link_ksettings(struct net_device *dev,
  414. const struct ethtool_link_ksettings *cmd)
  415. {
  416. const struct ethtool_link_settings *base = &cmd->base;
  417. struct qede_dev *edev = netdev_priv(dev);
  418. struct qed_link_output current_link;
  419. struct qed_link_params params;
  420. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  421. DP_INFO(edev, "Link settings are not allowed to be changed\n");
  422. return -EOPNOTSUPP;
  423. }
  424. memset(&current_link, 0, sizeof(current_link));
  425. memset(&params, 0, sizeof(params));
  426. edev->ops->common->get_link(edev->cdev, &current_link);
  427. params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
  428. params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
  429. if (base->autoneg == AUTONEG_ENABLE) {
  430. if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
  431. DP_INFO(edev, "Auto negotiation is not supported\n");
  432. return -EOPNOTSUPP;
  433. }
  434. params.autoneg = true;
  435. params.forced_speed = 0;
  436. QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
  437. } else { /* forced speed */
  438. params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
  439. params.autoneg = false;
  440. params.forced_speed = base->speed;
  441. switch (base->speed) {
  442. case SPEED_1000:
  443. if (!(current_link.supported_caps &
  444. QED_LM_1000baseT_Full_BIT)) {
  445. DP_INFO(edev, "1G speed not supported\n");
  446. return -EINVAL;
  447. }
  448. params.adv_speeds = QED_LM_1000baseT_Full_BIT;
  449. break;
  450. case SPEED_10000:
  451. if (!(current_link.supported_caps &
  452. QED_LM_10000baseKR_Full_BIT)) {
  453. DP_INFO(edev, "10G speed not supported\n");
  454. return -EINVAL;
  455. }
  456. params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
  457. break;
  458. case SPEED_25000:
  459. if (!(current_link.supported_caps &
  460. QED_LM_25000baseKR_Full_BIT)) {
  461. DP_INFO(edev, "25G speed not supported\n");
  462. return -EINVAL;
  463. }
  464. params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
  465. break;
  466. case SPEED_40000:
  467. if (!(current_link.supported_caps &
  468. QED_LM_40000baseLR4_Full_BIT)) {
  469. DP_INFO(edev, "40G speed not supported\n");
  470. return -EINVAL;
  471. }
  472. params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
  473. break;
  474. case SPEED_50000:
  475. if (!(current_link.supported_caps &
  476. QED_LM_50000baseKR2_Full_BIT)) {
  477. DP_INFO(edev, "50G speed not supported\n");
  478. return -EINVAL;
  479. }
  480. params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
  481. break;
  482. case SPEED_100000:
  483. if (!(current_link.supported_caps &
  484. QED_LM_100000baseKR4_Full_BIT)) {
  485. DP_INFO(edev, "100G speed not supported\n");
  486. return -EINVAL;
  487. }
  488. params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
  489. break;
  490. default:
  491. DP_INFO(edev, "Unsupported speed %u\n", base->speed);
  492. return -EINVAL;
  493. }
  494. }
  495. params.link_up = true;
  496. edev->ops->common->set_link(edev->cdev, &params);
  497. return 0;
  498. }
  499. static void qede_get_drvinfo(struct net_device *ndev,
  500. struct ethtool_drvinfo *info)
  501. {
  502. char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
  503. struct qede_dev *edev = netdev_priv(ndev);
  504. strlcpy(info->driver, "qede", sizeof(info->driver));
  505. strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
  506. snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
  507. edev->dev_info.common.fw_major,
  508. edev->dev_info.common.fw_minor,
  509. edev->dev_info.common.fw_rev,
  510. edev->dev_info.common.fw_eng);
  511. snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
  512. (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
  513. (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
  514. (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
  515. edev->dev_info.common.mfw_rev & 0xFF);
  516. if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
  517. sizeof(info->fw_version)) {
  518. snprintf(info->fw_version, sizeof(info->fw_version),
  519. "mfw %s storm %s", mfw, storm);
  520. } else {
  521. snprintf(info->fw_version, sizeof(info->fw_version),
  522. "%s %s", mfw, storm);
  523. }
  524. strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
  525. }
  526. static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  527. {
  528. struct qede_dev *edev = netdev_priv(ndev);
  529. if (edev->dev_info.common.wol_support) {
  530. wol->supported = WAKE_MAGIC;
  531. wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
  532. }
  533. }
  534. static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  535. {
  536. struct qede_dev *edev = netdev_priv(ndev);
  537. bool wol_requested;
  538. int rc;
  539. if (wol->wolopts & ~WAKE_MAGIC) {
  540. DP_INFO(edev,
  541. "Can't support WoL options other than magic-packet\n");
  542. return -EINVAL;
  543. }
  544. wol_requested = !!(wol->wolopts & WAKE_MAGIC);
  545. if (wol_requested == edev->wol_enabled)
  546. return 0;
  547. /* Need to actually change configuration */
  548. if (!edev->dev_info.common.wol_support) {
  549. DP_INFO(edev, "Device doesn't support WoL\n");
  550. return -EINVAL;
  551. }
  552. rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
  553. if (!rc)
  554. edev->wol_enabled = wol_requested;
  555. return rc;
  556. }
  557. static u32 qede_get_msglevel(struct net_device *ndev)
  558. {
  559. struct qede_dev *edev = netdev_priv(ndev);
  560. return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
  561. }
  562. static void qede_set_msglevel(struct net_device *ndev, u32 level)
  563. {
  564. struct qede_dev *edev = netdev_priv(ndev);
  565. u32 dp_module = 0;
  566. u8 dp_level = 0;
  567. qede_config_debug(level, &dp_module, &dp_level);
  568. edev->dp_level = dp_level;
  569. edev->dp_module = dp_module;
  570. edev->ops->common->update_msglvl(edev->cdev,
  571. dp_module, dp_level);
  572. }
  573. static int qede_nway_reset(struct net_device *dev)
  574. {
  575. struct qede_dev *edev = netdev_priv(dev);
  576. struct qed_link_output current_link;
  577. struct qed_link_params link_params;
  578. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  579. DP_INFO(edev, "Link settings are not allowed to be changed\n");
  580. return -EOPNOTSUPP;
  581. }
  582. if (!netif_running(dev))
  583. return 0;
  584. memset(&current_link, 0, sizeof(current_link));
  585. edev->ops->common->get_link(edev->cdev, &current_link);
  586. if (!current_link.link_up)
  587. return 0;
  588. /* Toggle the link */
  589. memset(&link_params, 0, sizeof(link_params));
  590. link_params.link_up = false;
  591. edev->ops->common->set_link(edev->cdev, &link_params);
  592. link_params.link_up = true;
  593. edev->ops->common->set_link(edev->cdev, &link_params);
  594. return 0;
  595. }
  596. static u32 qede_get_link(struct net_device *dev)
  597. {
  598. struct qede_dev *edev = netdev_priv(dev);
  599. struct qed_link_output current_link;
  600. memset(&current_link, 0, sizeof(current_link));
  601. edev->ops->common->get_link(edev->cdev, &current_link);
  602. return current_link.link_up;
  603. }
  604. static int qede_flash_device(struct net_device *dev,
  605. struct ethtool_flash *flash)
  606. {
  607. struct qede_dev *edev = netdev_priv(dev);
  608. return edev->ops->common->nvm_flash(edev->cdev, flash->data);
  609. }
  610. static int qede_get_coalesce(struct net_device *dev,
  611. struct ethtool_coalesce *coal)
  612. {
  613. void *rx_handle = NULL, *tx_handle = NULL;
  614. struct qede_dev *edev = netdev_priv(dev);
  615. u16 rx_coal, tx_coal, i, rc = 0;
  616. struct qede_fastpath *fp;
  617. rx_coal = QED_DEFAULT_RX_USECS;
  618. tx_coal = QED_DEFAULT_TX_USECS;
  619. memset(coal, 0, sizeof(struct ethtool_coalesce));
  620. __qede_lock(edev);
  621. if (edev->state == QEDE_STATE_OPEN) {
  622. for_each_queue(i) {
  623. fp = &edev->fp_array[i];
  624. if (fp->type & QEDE_FASTPATH_RX) {
  625. rx_handle = fp->rxq->handle;
  626. break;
  627. }
  628. }
  629. rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
  630. if (rc) {
  631. DP_INFO(edev, "Read Rx coalesce error\n");
  632. goto out;
  633. }
  634. for_each_queue(i) {
  635. fp = &edev->fp_array[i];
  636. if (fp->type & QEDE_FASTPATH_TX) {
  637. tx_handle = fp->txq->handle;
  638. break;
  639. }
  640. }
  641. rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
  642. if (rc)
  643. DP_INFO(edev, "Read Tx coalesce error\n");
  644. }
  645. out:
  646. __qede_unlock(edev);
  647. coal->rx_coalesce_usecs = rx_coal;
  648. coal->tx_coalesce_usecs = tx_coal;
  649. return rc;
  650. }
  651. static int qede_set_coalesce(struct net_device *dev,
  652. struct ethtool_coalesce *coal)
  653. {
  654. struct qede_dev *edev = netdev_priv(dev);
  655. struct qede_fastpath *fp;
  656. int i, rc = 0;
  657. u16 rxc, txc;
  658. if (!netif_running(dev)) {
  659. DP_INFO(edev, "Interface is down\n");
  660. return -EINVAL;
  661. }
  662. if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
  663. coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
  664. DP_INFO(edev,
  665. "Can't support requested %s coalesce value [max supported value %d]\n",
  666. coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
  667. "tx", QED_COALESCE_MAX);
  668. return -EINVAL;
  669. }
  670. rxc = (u16)coal->rx_coalesce_usecs;
  671. txc = (u16)coal->tx_coalesce_usecs;
  672. for_each_queue(i) {
  673. fp = &edev->fp_array[i];
  674. if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
  675. rc = edev->ops->common->set_coalesce(edev->cdev,
  676. rxc, 0,
  677. fp->rxq->handle);
  678. if (rc) {
  679. DP_INFO(edev,
  680. "Set RX coalesce error, rc = %d\n", rc);
  681. return rc;
  682. }
  683. }
  684. if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
  685. rc = edev->ops->common->set_coalesce(edev->cdev,
  686. 0, txc,
  687. fp->txq->handle);
  688. if (rc) {
  689. DP_INFO(edev,
  690. "Set TX coalesce error, rc = %d\n", rc);
  691. return rc;
  692. }
  693. }
  694. }
  695. return rc;
  696. }
  697. static void qede_get_ringparam(struct net_device *dev,
  698. struct ethtool_ringparam *ering)
  699. {
  700. struct qede_dev *edev = netdev_priv(dev);
  701. ering->rx_max_pending = NUM_RX_BDS_MAX;
  702. ering->rx_pending = edev->q_num_rx_buffers;
  703. ering->tx_max_pending = NUM_TX_BDS_MAX;
  704. ering->tx_pending = edev->q_num_tx_buffers;
  705. }
  706. static int qede_set_ringparam(struct net_device *dev,
  707. struct ethtool_ringparam *ering)
  708. {
  709. struct qede_dev *edev = netdev_priv(dev);
  710. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  711. "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
  712. ering->rx_pending, ering->tx_pending);
  713. /* Validate legality of configuration */
  714. if (ering->rx_pending > NUM_RX_BDS_MAX ||
  715. ering->rx_pending < NUM_RX_BDS_MIN ||
  716. ering->tx_pending > NUM_TX_BDS_MAX ||
  717. ering->tx_pending < NUM_TX_BDS_MIN) {
  718. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  719. "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
  720. NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
  721. NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
  722. return -EINVAL;
  723. }
  724. /* Change ring size and re-load */
  725. edev->q_num_rx_buffers = ering->rx_pending;
  726. edev->q_num_tx_buffers = ering->tx_pending;
  727. qede_reload(edev, NULL, false);
  728. return 0;
  729. }
  730. static void qede_get_pauseparam(struct net_device *dev,
  731. struct ethtool_pauseparam *epause)
  732. {
  733. struct qede_dev *edev = netdev_priv(dev);
  734. struct qed_link_output current_link;
  735. memset(&current_link, 0, sizeof(current_link));
  736. edev->ops->common->get_link(edev->cdev, &current_link);
  737. if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
  738. epause->autoneg = true;
  739. if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
  740. epause->rx_pause = true;
  741. if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
  742. epause->tx_pause = true;
  743. DP_VERBOSE(edev, QED_MSG_DEBUG,
  744. "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
  745. epause->cmd, epause->autoneg, epause->rx_pause,
  746. epause->tx_pause);
  747. }
  748. static int qede_set_pauseparam(struct net_device *dev,
  749. struct ethtool_pauseparam *epause)
  750. {
  751. struct qede_dev *edev = netdev_priv(dev);
  752. struct qed_link_params params;
  753. struct qed_link_output current_link;
  754. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  755. DP_INFO(edev,
  756. "Pause settings are not allowed to be changed\n");
  757. return -EOPNOTSUPP;
  758. }
  759. memset(&current_link, 0, sizeof(current_link));
  760. edev->ops->common->get_link(edev->cdev, &current_link);
  761. memset(&params, 0, sizeof(params));
  762. params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
  763. if (epause->autoneg) {
  764. if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
  765. DP_INFO(edev, "autoneg not supported\n");
  766. return -EINVAL;
  767. }
  768. params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
  769. }
  770. if (epause->rx_pause)
  771. params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
  772. if (epause->tx_pause)
  773. params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
  774. params.link_up = true;
  775. edev->ops->common->set_link(edev->cdev, &params);
  776. return 0;
  777. }
  778. static void qede_get_regs(struct net_device *ndev,
  779. struct ethtool_regs *regs, void *buffer)
  780. {
  781. struct qede_dev *edev = netdev_priv(ndev);
  782. regs->version = 0;
  783. memset(buffer, 0, regs->len);
  784. if (edev->ops && edev->ops->common)
  785. edev->ops->common->dbg_all_data(edev->cdev, buffer);
  786. }
  787. static int qede_get_regs_len(struct net_device *ndev)
  788. {
  789. struct qede_dev *edev = netdev_priv(ndev);
  790. if (edev->ops && edev->ops->common)
  791. return edev->ops->common->dbg_all_data_size(edev->cdev);
  792. else
  793. return -EINVAL;
  794. }
  795. static void qede_update_mtu(struct qede_dev *edev,
  796. struct qede_reload_args *args)
  797. {
  798. edev->ndev->mtu = args->u.mtu;
  799. }
  800. /* Netdevice NDOs */
  801. int qede_change_mtu(struct net_device *ndev, int new_mtu)
  802. {
  803. struct qede_dev *edev = netdev_priv(ndev);
  804. struct qede_reload_args args;
  805. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  806. "Configuring MTU size of %d\n", new_mtu);
  807. if (new_mtu > PAGE_SIZE)
  808. ndev->features &= ~NETIF_F_GRO_HW;
  809. /* Set the mtu field and re-start the interface if needed */
  810. args.u.mtu = new_mtu;
  811. args.func = &qede_update_mtu;
  812. qede_reload(edev, &args, false);
  813. edev->ops->common->update_mtu(edev->cdev, new_mtu);
  814. return 0;
  815. }
  816. static void qede_get_channels(struct net_device *dev,
  817. struct ethtool_channels *channels)
  818. {
  819. struct qede_dev *edev = netdev_priv(dev);
  820. channels->max_combined = QEDE_MAX_RSS_CNT(edev);
  821. channels->max_rx = QEDE_MAX_RSS_CNT(edev);
  822. channels->max_tx = QEDE_MAX_RSS_CNT(edev);
  823. channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
  824. edev->fp_num_rx;
  825. channels->tx_count = edev->fp_num_tx;
  826. channels->rx_count = edev->fp_num_rx;
  827. }
  828. static int qede_set_channels(struct net_device *dev,
  829. struct ethtool_channels *channels)
  830. {
  831. struct qede_dev *edev = netdev_priv(dev);
  832. u32 count;
  833. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  834. "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
  835. channels->rx_count, channels->tx_count,
  836. channels->other_count, channels->combined_count);
  837. count = channels->rx_count + channels->tx_count +
  838. channels->combined_count;
  839. /* We don't support `other' channels */
  840. if (channels->other_count) {
  841. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  842. "command parameters not supported\n");
  843. return -EINVAL;
  844. }
  845. if (!(channels->combined_count || (channels->rx_count &&
  846. channels->tx_count))) {
  847. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  848. "need to request at least one transmit and one receive channel\n");
  849. return -EINVAL;
  850. }
  851. if (count > QEDE_MAX_RSS_CNT(edev)) {
  852. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  853. "requested channels = %d max supported channels = %d\n",
  854. count, QEDE_MAX_RSS_CNT(edev));
  855. return -EINVAL;
  856. }
  857. /* Check if there was a change in the active parameters */
  858. if ((count == QEDE_QUEUE_CNT(edev)) &&
  859. (channels->tx_count == edev->fp_num_tx) &&
  860. (channels->rx_count == edev->fp_num_rx)) {
  861. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  862. "No change in active parameters\n");
  863. return 0;
  864. }
  865. /* We need the number of queues to be divisible between the hwfns */
  866. if ((count % edev->dev_info.common.num_hwfns) ||
  867. (channels->tx_count % edev->dev_info.common.num_hwfns) ||
  868. (channels->rx_count % edev->dev_info.common.num_hwfns)) {
  869. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  870. "Number of channels must be divisible by %04x\n",
  871. edev->dev_info.common.num_hwfns);
  872. return -EINVAL;
  873. }
  874. /* Set number of queues and reload if necessary */
  875. edev->req_queues = count;
  876. edev->req_num_tx = channels->tx_count;
  877. edev->req_num_rx = channels->rx_count;
  878. /* Reset the indirection table if rx queue count is updated */
  879. if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
  880. edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
  881. memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
  882. }
  883. qede_reload(edev, NULL, false);
  884. return 0;
  885. }
  886. static int qede_get_ts_info(struct net_device *dev,
  887. struct ethtool_ts_info *info)
  888. {
  889. struct qede_dev *edev = netdev_priv(dev);
  890. return qede_ptp_get_ts_info(edev, info);
  891. }
  892. static int qede_set_phys_id(struct net_device *dev,
  893. enum ethtool_phys_id_state state)
  894. {
  895. struct qede_dev *edev = netdev_priv(dev);
  896. u8 led_state = 0;
  897. switch (state) {
  898. case ETHTOOL_ID_ACTIVE:
  899. return 1; /* cycle on/off once per second */
  900. case ETHTOOL_ID_ON:
  901. led_state = QED_LED_MODE_ON;
  902. break;
  903. case ETHTOOL_ID_OFF:
  904. led_state = QED_LED_MODE_OFF;
  905. break;
  906. case ETHTOOL_ID_INACTIVE:
  907. led_state = QED_LED_MODE_RESTORE;
  908. break;
  909. }
  910. edev->ops->common->set_led(edev->cdev, led_state);
  911. return 0;
  912. }
  913. static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
  914. {
  915. info->data = RXH_IP_SRC | RXH_IP_DST;
  916. switch (info->flow_type) {
  917. case TCP_V4_FLOW:
  918. case TCP_V6_FLOW:
  919. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  920. break;
  921. case UDP_V4_FLOW:
  922. if (edev->rss_caps & QED_RSS_IPV4_UDP)
  923. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  924. break;
  925. case UDP_V6_FLOW:
  926. if (edev->rss_caps & QED_RSS_IPV6_UDP)
  927. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  928. break;
  929. case IPV4_FLOW:
  930. case IPV6_FLOW:
  931. break;
  932. default:
  933. info->data = 0;
  934. break;
  935. }
  936. return 0;
  937. }
  938. static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  939. u32 *rule_locs)
  940. {
  941. struct qede_dev *edev = netdev_priv(dev);
  942. int rc = 0;
  943. switch (info->cmd) {
  944. case ETHTOOL_GRXRINGS:
  945. info->data = QEDE_RSS_COUNT(edev);
  946. break;
  947. case ETHTOOL_GRXFH:
  948. rc = qede_get_rss_flags(edev, info);
  949. break;
  950. case ETHTOOL_GRXCLSRLCNT:
  951. info->rule_cnt = qede_get_arfs_filter_count(edev);
  952. info->data = QEDE_RFS_MAX_FLTR;
  953. break;
  954. case ETHTOOL_GRXCLSRULE:
  955. rc = qede_get_cls_rule_entry(edev, info);
  956. break;
  957. case ETHTOOL_GRXCLSRLALL:
  958. rc = qede_get_cls_rule_all(edev, info, rule_locs);
  959. break;
  960. default:
  961. DP_ERR(edev, "Command parameters not supported\n");
  962. rc = -EOPNOTSUPP;
  963. }
  964. return rc;
  965. }
  966. static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
  967. {
  968. struct qed_update_vport_params *vport_update_params;
  969. u8 set_caps = 0, clr_caps = 0;
  970. int rc = 0;
  971. DP_VERBOSE(edev, QED_MSG_DEBUG,
  972. "Set rss flags command parameters: flow type = %d, data = %llu\n",
  973. info->flow_type, info->data);
  974. switch (info->flow_type) {
  975. case TCP_V4_FLOW:
  976. case TCP_V6_FLOW:
  977. /* For TCP only 4-tuple hash is supported */
  978. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
  979. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  980. DP_INFO(edev, "Command parameters not supported\n");
  981. return -EINVAL;
  982. }
  983. return 0;
  984. case UDP_V4_FLOW:
  985. /* For UDP either 2-tuple hash or 4-tuple hash is supported */
  986. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  987. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  988. set_caps = QED_RSS_IPV4_UDP;
  989. DP_VERBOSE(edev, QED_MSG_DEBUG,
  990. "UDP 4-tuple enabled\n");
  991. } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
  992. clr_caps = QED_RSS_IPV4_UDP;
  993. DP_VERBOSE(edev, QED_MSG_DEBUG,
  994. "UDP 4-tuple disabled\n");
  995. } else {
  996. return -EINVAL;
  997. }
  998. break;
  999. case UDP_V6_FLOW:
  1000. /* For UDP either 2-tuple hash or 4-tuple hash is supported */
  1001. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  1002. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1003. set_caps = QED_RSS_IPV6_UDP;
  1004. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1005. "UDP 4-tuple enabled\n");
  1006. } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
  1007. clr_caps = QED_RSS_IPV6_UDP;
  1008. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1009. "UDP 4-tuple disabled\n");
  1010. } else {
  1011. return -EINVAL;
  1012. }
  1013. break;
  1014. case IPV4_FLOW:
  1015. case IPV6_FLOW:
  1016. /* For IP only 2-tuple hash is supported */
  1017. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
  1018. DP_INFO(edev, "Command parameters not supported\n");
  1019. return -EINVAL;
  1020. }
  1021. return 0;
  1022. case SCTP_V4_FLOW:
  1023. case AH_ESP_V4_FLOW:
  1024. case AH_V4_FLOW:
  1025. case ESP_V4_FLOW:
  1026. case SCTP_V6_FLOW:
  1027. case AH_ESP_V6_FLOW:
  1028. case AH_V6_FLOW:
  1029. case ESP_V6_FLOW:
  1030. case IP_USER_FLOW:
  1031. case ETHER_FLOW:
  1032. /* RSS is not supported for these protocols */
  1033. if (info->data) {
  1034. DP_INFO(edev, "Command parameters not supported\n");
  1035. return -EINVAL;
  1036. }
  1037. return 0;
  1038. default:
  1039. return -EINVAL;
  1040. }
  1041. /* No action is needed if there is no change in the rss capability */
  1042. if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
  1043. return 0;
  1044. /* Update internal configuration */
  1045. edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
  1046. edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
  1047. /* Re-configure if possible */
  1048. __qede_lock(edev);
  1049. if (edev->state == QEDE_STATE_OPEN) {
  1050. vport_update_params = vzalloc(sizeof(*vport_update_params));
  1051. if (!vport_update_params) {
  1052. __qede_unlock(edev);
  1053. return -ENOMEM;
  1054. }
  1055. qede_fill_rss_params(edev, &vport_update_params->rss_params,
  1056. &vport_update_params->update_rss_flg);
  1057. rc = edev->ops->vport_update(edev->cdev, vport_update_params);
  1058. vfree(vport_update_params);
  1059. }
  1060. __qede_unlock(edev);
  1061. return rc;
  1062. }
  1063. static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  1064. {
  1065. struct qede_dev *edev = netdev_priv(dev);
  1066. int rc;
  1067. switch (info->cmd) {
  1068. case ETHTOOL_SRXFH:
  1069. rc = qede_set_rss_flags(edev, info);
  1070. break;
  1071. case ETHTOOL_SRXCLSRLINS:
  1072. rc = qede_add_cls_rule(edev, info);
  1073. break;
  1074. case ETHTOOL_SRXCLSRLDEL:
  1075. rc = qede_del_cls_rule(edev, info);
  1076. break;
  1077. default:
  1078. DP_INFO(edev, "Command parameters not supported\n");
  1079. rc = -EOPNOTSUPP;
  1080. }
  1081. return rc;
  1082. }
  1083. static u32 qede_get_rxfh_indir_size(struct net_device *dev)
  1084. {
  1085. return QED_RSS_IND_TABLE_SIZE;
  1086. }
  1087. static u32 qede_get_rxfh_key_size(struct net_device *dev)
  1088. {
  1089. struct qede_dev *edev = netdev_priv(dev);
  1090. return sizeof(edev->rss_key);
  1091. }
  1092. static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
  1093. {
  1094. struct qede_dev *edev = netdev_priv(dev);
  1095. int i;
  1096. if (hfunc)
  1097. *hfunc = ETH_RSS_HASH_TOP;
  1098. if (!indir)
  1099. return 0;
  1100. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
  1101. indir[i] = edev->rss_ind_table[i];
  1102. if (key)
  1103. memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
  1104. return 0;
  1105. }
  1106. static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
  1107. const u8 *key, const u8 hfunc)
  1108. {
  1109. struct qed_update_vport_params *vport_update_params;
  1110. struct qede_dev *edev = netdev_priv(dev);
  1111. int i, rc = 0;
  1112. if (edev->dev_info.common.num_hwfns > 1) {
  1113. DP_INFO(edev,
  1114. "RSS configuration is not supported for 100G devices\n");
  1115. return -EOPNOTSUPP;
  1116. }
  1117. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  1118. return -EOPNOTSUPP;
  1119. if (!indir && !key)
  1120. return 0;
  1121. if (indir) {
  1122. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
  1123. edev->rss_ind_table[i] = indir[i];
  1124. edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
  1125. }
  1126. if (key) {
  1127. memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
  1128. edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
  1129. }
  1130. __qede_lock(edev);
  1131. if (edev->state == QEDE_STATE_OPEN) {
  1132. vport_update_params = vzalloc(sizeof(*vport_update_params));
  1133. if (!vport_update_params) {
  1134. __qede_unlock(edev);
  1135. return -ENOMEM;
  1136. }
  1137. qede_fill_rss_params(edev, &vport_update_params->rss_params,
  1138. &vport_update_params->update_rss_flg);
  1139. rc = edev->ops->vport_update(edev->cdev, vport_update_params);
  1140. vfree(vport_update_params);
  1141. }
  1142. __qede_unlock(edev);
  1143. return rc;
  1144. }
  1145. /* This function enables the interrupt generation and the NAPI on the device */
  1146. static void qede_netif_start(struct qede_dev *edev)
  1147. {
  1148. int i;
  1149. if (!netif_running(edev->ndev))
  1150. return;
  1151. for_each_queue(i) {
  1152. /* Update and reenable interrupts */
  1153. qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
  1154. napi_enable(&edev->fp_array[i].napi);
  1155. }
  1156. }
  1157. /* This function disables the NAPI and the interrupt generation on the device */
  1158. static void qede_netif_stop(struct qede_dev *edev)
  1159. {
  1160. int i;
  1161. for_each_queue(i) {
  1162. napi_disable(&edev->fp_array[i].napi);
  1163. /* Disable interrupts */
  1164. qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
  1165. }
  1166. }
  1167. static int qede_selftest_transmit_traffic(struct qede_dev *edev,
  1168. struct sk_buff *skb)
  1169. {
  1170. struct qede_tx_queue *txq = NULL;
  1171. struct eth_tx_1st_bd *first_bd;
  1172. dma_addr_t mapping;
  1173. int i, idx;
  1174. u16 val;
  1175. for_each_queue(i) {
  1176. if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
  1177. txq = edev->fp_array[i].txq;
  1178. break;
  1179. }
  1180. }
  1181. if (!txq) {
  1182. DP_NOTICE(edev, "Tx path is not available\n");
  1183. return -1;
  1184. }
  1185. /* Fill the entry in the SW ring and the BDs in the FW ring */
  1186. idx = txq->sw_tx_prod;
  1187. txq->sw_tx_ring.skbs[idx].skb = skb;
  1188. first_bd = qed_chain_produce(&txq->tx_pbl);
  1189. memset(first_bd, 0, sizeof(*first_bd));
  1190. val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
  1191. first_bd->data.bd_flags.bitfields = val;
  1192. val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
  1193. val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
  1194. first_bd->data.bitfields |= cpu_to_le16(val);
  1195. /* Map skb linear data for DMA and set in the first BD */
  1196. mapping = dma_map_single(&edev->pdev->dev, skb->data,
  1197. skb_headlen(skb), DMA_TO_DEVICE);
  1198. if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
  1199. DP_NOTICE(edev, "SKB mapping failed\n");
  1200. return -ENOMEM;
  1201. }
  1202. BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
  1203. /* update the first BD with the actual num BDs */
  1204. first_bd->data.nbds = 1;
  1205. txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
  1206. /* 'next page' entries are counted in the producer value */
  1207. val = qed_chain_get_prod_idx(&txq->tx_pbl);
  1208. txq->tx_db.data.bd_prod = cpu_to_le16(val);
  1209. /* wmb makes sure that the BDs data is updated before updating the
  1210. * producer, otherwise FW may read old data from the BDs.
  1211. */
  1212. wmb();
  1213. barrier();
  1214. writel(txq->tx_db.raw, txq->doorbell_addr);
  1215. /* mmiowb is needed to synchronize doorbell writes from more than one
  1216. * processor. It guarantees that the write arrives to the device before
  1217. * the queue lock is released and another start_xmit is called (possibly
  1218. * on another CPU). Without this barrier, the next doorbell can bypass
  1219. * this doorbell. This is applicable to IA64/Altix systems.
  1220. */
  1221. mmiowb();
  1222. for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
  1223. if (qede_txq_has_work(txq))
  1224. break;
  1225. usleep_range(100, 200);
  1226. }
  1227. if (!qede_txq_has_work(txq)) {
  1228. DP_NOTICE(edev, "Tx completion didn't happen\n");
  1229. return -1;
  1230. }
  1231. first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
  1232. dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
  1233. BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
  1234. txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
  1235. txq->sw_tx_ring.skbs[idx].skb = NULL;
  1236. return 0;
  1237. }
  1238. static int qede_selftest_receive_traffic(struct qede_dev *edev)
  1239. {
  1240. u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
  1241. struct eth_fast_path_rx_reg_cqe *fp_cqe;
  1242. struct qede_rx_queue *rxq = NULL;
  1243. struct sw_rx_data *sw_rx_data;
  1244. union eth_rx_cqe *cqe;
  1245. int i, iter, rc = 0;
  1246. u8 *data_ptr;
  1247. for_each_queue(i) {
  1248. if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
  1249. rxq = edev->fp_array[i].rxq;
  1250. break;
  1251. }
  1252. }
  1253. if (!rxq) {
  1254. DP_NOTICE(edev, "Rx path is not available\n");
  1255. return -1;
  1256. }
  1257. /* The packet is expected to receive on rx-queue 0 even though RSS is
  1258. * enabled. This is because the queue 0 is configured as the default
  1259. * queue and that the loopback traffic is not IP.
  1260. */
  1261. for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
  1262. if (!qede_has_rx_work(rxq)) {
  1263. usleep_range(100, 200);
  1264. continue;
  1265. }
  1266. hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
  1267. sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
  1268. /* Memory barrier to prevent the CPU from doing speculative
  1269. * reads of CQE/BD before reading hw_comp_cons. If the CQE is
  1270. * read before it is written by FW, then FW writes CQE and SB,
  1271. * and then the CPU reads the hw_comp_cons, it will use an old
  1272. * CQE.
  1273. */
  1274. rmb();
  1275. /* Get the CQE from the completion ring */
  1276. cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
  1277. /* Get the data from the SW ring */
  1278. sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
  1279. sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
  1280. fp_cqe = &cqe->fast_path_regular;
  1281. len = le16_to_cpu(fp_cqe->len_on_first_bd);
  1282. data_ptr = (u8 *)(page_address(sw_rx_data->data) +
  1283. fp_cqe->placement_offset +
  1284. sw_rx_data->page_offset);
  1285. if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
  1286. ether_addr_equal(data_ptr + ETH_ALEN,
  1287. edev->ndev->dev_addr)) {
  1288. for (i = ETH_HLEN; i < len; i++)
  1289. if (data_ptr[i] != (unsigned char)(i & 0xff)) {
  1290. rc = -1;
  1291. break;
  1292. }
  1293. qede_recycle_rx_bd_ring(rxq, 1);
  1294. qed_chain_recycle_consumed(&rxq->rx_comp_ring);
  1295. break;
  1296. }
  1297. DP_INFO(edev, "Not the transmitted packet\n");
  1298. qede_recycle_rx_bd_ring(rxq, 1);
  1299. qed_chain_recycle_consumed(&rxq->rx_comp_ring);
  1300. }
  1301. if (iter == QEDE_SELFTEST_POLL_COUNT) {
  1302. DP_NOTICE(edev, "Failed to receive the traffic\n");
  1303. return -1;
  1304. }
  1305. qede_update_rx_prod(edev, rxq);
  1306. return rc;
  1307. }
  1308. static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
  1309. {
  1310. struct qed_link_params link_params;
  1311. struct sk_buff *skb = NULL;
  1312. int rc = 0, i;
  1313. u32 pkt_size;
  1314. u8 *packet;
  1315. if (!netif_running(edev->ndev)) {
  1316. DP_NOTICE(edev, "Interface is down\n");
  1317. return -EINVAL;
  1318. }
  1319. qede_netif_stop(edev);
  1320. /* Bring up the link in Loopback mode */
  1321. memset(&link_params, 0, sizeof(link_params));
  1322. link_params.link_up = true;
  1323. link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
  1324. link_params.loopback_mode = loopback_mode;
  1325. edev->ops->common->set_link(edev->cdev, &link_params);
  1326. /* Wait for loopback configuration to apply */
  1327. msleep_interruptible(500);
  1328. /* prepare the loopback packet */
  1329. pkt_size = edev->ndev->mtu + ETH_HLEN;
  1330. skb = netdev_alloc_skb(edev->ndev, pkt_size);
  1331. if (!skb) {
  1332. DP_INFO(edev, "Can't allocate skb\n");
  1333. rc = -ENOMEM;
  1334. goto test_loopback_exit;
  1335. }
  1336. packet = skb_put(skb, pkt_size);
  1337. ether_addr_copy(packet, edev->ndev->dev_addr);
  1338. ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
  1339. memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
  1340. for (i = ETH_HLEN; i < pkt_size; i++)
  1341. packet[i] = (unsigned char)(i & 0xff);
  1342. rc = qede_selftest_transmit_traffic(edev, skb);
  1343. if (rc)
  1344. goto test_loopback_exit;
  1345. rc = qede_selftest_receive_traffic(edev);
  1346. if (rc)
  1347. goto test_loopback_exit;
  1348. DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
  1349. test_loopback_exit:
  1350. dev_kfree_skb(skb);
  1351. /* Bring up the link in Normal mode */
  1352. memset(&link_params, 0, sizeof(link_params));
  1353. link_params.link_up = true;
  1354. link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
  1355. link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
  1356. edev->ops->common->set_link(edev->cdev, &link_params);
  1357. /* Wait for loopback configuration to apply */
  1358. msleep_interruptible(500);
  1359. qede_netif_start(edev);
  1360. return rc;
  1361. }
  1362. static void qede_self_test(struct net_device *dev,
  1363. struct ethtool_test *etest, u64 *buf)
  1364. {
  1365. struct qede_dev *edev = netdev_priv(dev);
  1366. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1367. "Self-test command parameters: offline = %d, external_lb = %d\n",
  1368. (etest->flags & ETH_TEST_FL_OFFLINE),
  1369. (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
  1370. memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
  1371. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1372. if (qede_selftest_run_loopback(edev,
  1373. QED_LINK_LOOPBACK_INT_PHY)) {
  1374. buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
  1375. etest->flags |= ETH_TEST_FL_FAILED;
  1376. }
  1377. }
  1378. if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
  1379. buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
  1380. etest->flags |= ETH_TEST_FL_FAILED;
  1381. }
  1382. if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
  1383. buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
  1384. etest->flags |= ETH_TEST_FL_FAILED;
  1385. }
  1386. if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
  1387. buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
  1388. etest->flags |= ETH_TEST_FL_FAILED;
  1389. }
  1390. if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
  1391. buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
  1392. etest->flags |= ETH_TEST_FL_FAILED;
  1393. }
  1394. if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
  1395. buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
  1396. etest->flags |= ETH_TEST_FL_FAILED;
  1397. }
  1398. }
  1399. static int qede_set_tunable(struct net_device *dev,
  1400. const struct ethtool_tunable *tuna,
  1401. const void *data)
  1402. {
  1403. struct qede_dev *edev = netdev_priv(dev);
  1404. u32 val;
  1405. switch (tuna->id) {
  1406. case ETHTOOL_RX_COPYBREAK:
  1407. val = *(u32 *)data;
  1408. if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
  1409. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1410. "Invalid rx copy break value, range is [%u, %u]",
  1411. QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
  1412. return -EINVAL;
  1413. }
  1414. edev->rx_copybreak = *(u32 *)data;
  1415. break;
  1416. default:
  1417. return -EOPNOTSUPP;
  1418. }
  1419. return 0;
  1420. }
  1421. static int qede_get_tunable(struct net_device *dev,
  1422. const struct ethtool_tunable *tuna, void *data)
  1423. {
  1424. struct qede_dev *edev = netdev_priv(dev);
  1425. switch (tuna->id) {
  1426. case ETHTOOL_RX_COPYBREAK:
  1427. *(u32 *)data = edev->rx_copybreak;
  1428. break;
  1429. default:
  1430. return -EOPNOTSUPP;
  1431. }
  1432. return 0;
  1433. }
  1434. static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
  1435. {
  1436. struct qede_dev *edev = netdev_priv(dev);
  1437. struct qed_link_output current_link;
  1438. memset(&current_link, 0, sizeof(current_link));
  1439. edev->ops->common->get_link(edev->cdev, &current_link);
  1440. if (!current_link.eee_supported) {
  1441. DP_INFO(edev, "EEE is not supported\n");
  1442. return -EOPNOTSUPP;
  1443. }
  1444. if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
  1445. edata->advertised = ADVERTISED_1000baseT_Full;
  1446. if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
  1447. edata->advertised |= ADVERTISED_10000baseT_Full;
  1448. if (current_link.sup_caps & QED_EEE_1G_ADV)
  1449. edata->supported = ADVERTISED_1000baseT_Full;
  1450. if (current_link.sup_caps & QED_EEE_10G_ADV)
  1451. edata->supported |= ADVERTISED_10000baseT_Full;
  1452. if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
  1453. edata->lp_advertised = ADVERTISED_1000baseT_Full;
  1454. if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
  1455. edata->lp_advertised |= ADVERTISED_10000baseT_Full;
  1456. edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
  1457. edata->eee_enabled = current_link.eee.enable;
  1458. edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
  1459. edata->eee_active = current_link.eee_active;
  1460. return 0;
  1461. }
  1462. static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
  1463. {
  1464. struct qede_dev *edev = netdev_priv(dev);
  1465. struct qed_link_output current_link;
  1466. struct qed_link_params params;
  1467. if (!edev->ops->common->can_link_change(edev->cdev)) {
  1468. DP_INFO(edev, "Link settings are not allowed to be changed\n");
  1469. return -EOPNOTSUPP;
  1470. }
  1471. memset(&current_link, 0, sizeof(current_link));
  1472. edev->ops->common->get_link(edev->cdev, &current_link);
  1473. if (!current_link.eee_supported) {
  1474. DP_INFO(edev, "EEE is not supported\n");
  1475. return -EOPNOTSUPP;
  1476. }
  1477. memset(&params, 0, sizeof(params));
  1478. params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
  1479. if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
  1480. ADVERTISED_10000baseT_Full)) ||
  1481. ((edata->advertised & (ADVERTISED_1000baseT_Full |
  1482. ADVERTISED_10000baseT_Full)) !=
  1483. edata->advertised)) {
  1484. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1485. "Invalid advertised capabilities %d\n",
  1486. edata->advertised);
  1487. return -EINVAL;
  1488. }
  1489. if (edata->advertised & ADVERTISED_1000baseT_Full)
  1490. params.eee.adv_caps = QED_EEE_1G_ADV;
  1491. if (edata->advertised & ADVERTISED_10000baseT_Full)
  1492. params.eee.adv_caps |= QED_EEE_10G_ADV;
  1493. params.eee.enable = edata->eee_enabled;
  1494. params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
  1495. params.eee.tx_lpi_timer = edata->tx_lpi_timer;
  1496. params.link_up = true;
  1497. edev->ops->common->set_link(edev->cdev, &params);
  1498. return 0;
  1499. }
  1500. static const struct ethtool_ops qede_ethtool_ops = {
  1501. .get_link_ksettings = qede_get_link_ksettings,
  1502. .set_link_ksettings = qede_set_link_ksettings,
  1503. .get_drvinfo = qede_get_drvinfo,
  1504. .get_regs_len = qede_get_regs_len,
  1505. .get_regs = qede_get_regs,
  1506. .get_wol = qede_get_wol,
  1507. .set_wol = qede_set_wol,
  1508. .get_msglevel = qede_get_msglevel,
  1509. .set_msglevel = qede_set_msglevel,
  1510. .nway_reset = qede_nway_reset,
  1511. .get_link = qede_get_link,
  1512. .get_coalesce = qede_get_coalesce,
  1513. .set_coalesce = qede_set_coalesce,
  1514. .get_ringparam = qede_get_ringparam,
  1515. .set_ringparam = qede_set_ringparam,
  1516. .get_pauseparam = qede_get_pauseparam,
  1517. .set_pauseparam = qede_set_pauseparam,
  1518. .get_strings = qede_get_strings,
  1519. .set_phys_id = qede_set_phys_id,
  1520. .get_ethtool_stats = qede_get_ethtool_stats,
  1521. .get_priv_flags = qede_get_priv_flags,
  1522. .get_sset_count = qede_get_sset_count,
  1523. .get_rxnfc = qede_get_rxnfc,
  1524. .set_rxnfc = qede_set_rxnfc,
  1525. .get_rxfh_indir_size = qede_get_rxfh_indir_size,
  1526. .get_rxfh_key_size = qede_get_rxfh_key_size,
  1527. .get_rxfh = qede_get_rxfh,
  1528. .set_rxfh = qede_set_rxfh,
  1529. .get_ts_info = qede_get_ts_info,
  1530. .get_channels = qede_get_channels,
  1531. .set_channels = qede_set_channels,
  1532. .self_test = qede_self_test,
  1533. .get_eee = qede_get_eee,
  1534. .set_eee = qede_set_eee,
  1535. .get_tunable = qede_get_tunable,
  1536. .set_tunable = qede_set_tunable,
  1537. .flash_device = qede_flash_device,
  1538. };
  1539. static const struct ethtool_ops qede_vf_ethtool_ops = {
  1540. .get_link_ksettings = qede_get_link_ksettings,
  1541. .get_drvinfo = qede_get_drvinfo,
  1542. .get_msglevel = qede_get_msglevel,
  1543. .set_msglevel = qede_set_msglevel,
  1544. .get_link = qede_get_link,
  1545. .get_coalesce = qede_get_coalesce,
  1546. .set_coalesce = qede_set_coalesce,
  1547. .get_ringparam = qede_get_ringparam,
  1548. .set_ringparam = qede_set_ringparam,
  1549. .get_strings = qede_get_strings,
  1550. .get_ethtool_stats = qede_get_ethtool_stats,
  1551. .get_priv_flags = qede_get_priv_flags,
  1552. .get_sset_count = qede_get_sset_count,
  1553. .get_rxnfc = qede_get_rxnfc,
  1554. .set_rxnfc = qede_set_rxnfc,
  1555. .get_rxfh_indir_size = qede_get_rxfh_indir_size,
  1556. .get_rxfh_key_size = qede_get_rxfh_key_size,
  1557. .get_rxfh = qede_get_rxfh,
  1558. .set_rxfh = qede_set_rxfh,
  1559. .get_channels = qede_get_channels,
  1560. .set_channels = qede_set_channels,
  1561. .get_tunable = qede_get_tunable,
  1562. .set_tunable = qede_set_tunable,
  1563. };
  1564. void qede_set_ethtool_ops(struct net_device *dev)
  1565. {
  1566. struct qede_dev *edev = netdev_priv(dev);
  1567. if (IS_VF(edev))
  1568. dev->ethtool_ops = &qede_vf_ethtool_ops;
  1569. else
  1570. dev->ethtool_ops = &qede_ethtool_ops;
  1571. }