i40e_debugfs.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #ifdef CONFIG_DEBUG_FS
  27. #include <linux/fs.h>
  28. #include <linux/debugfs.h>
  29. #include "i40e.h"
  30. static struct dentry *i40e_dbg_root;
  31. /**
  32. * i40e_dbg_find_vsi - searches for the vsi with the given seid
  33. * @pf - the PF structure to search for the vsi
  34. * @seid - seid of the vsi it is searching for
  35. **/
  36. static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
  37. {
  38. int i;
  39. if (seid < 0)
  40. dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
  41. else
  42. for (i = 0; i < pf->num_alloc_vsi; i++)
  43. if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
  44. return pf->vsi[i];
  45. return NULL;
  46. }
  47. /**
  48. * i40e_dbg_find_veb - searches for the veb with the given seid
  49. * @pf - the PF structure to search for the veb
  50. * @seid - seid of the veb it is searching for
  51. **/
  52. static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
  53. {
  54. int i;
  55. for (i = 0; i < I40E_MAX_VEB; i++)
  56. if (pf->veb[i] && pf->veb[i]->seid == seid)
  57. return pf->veb[i];
  58. return NULL;
  59. }
  60. /**************************************************************
  61. * command
  62. * The command entry in debugfs is for giving the driver commands
  63. * to be executed - these may be for changing the internal switch
  64. * setup, adding or removing filters, or other things. Many of
  65. * these will be useful for some forms of unit testing.
  66. **************************************************************/
  67. static char i40e_dbg_command_buf[256] = "";
  68. /**
  69. * i40e_dbg_command_read - read for command datum
  70. * @filp: the opened file
  71. * @buffer: where to write the data for the user to read
  72. * @count: the size of the user's buffer
  73. * @ppos: file position offset
  74. **/
  75. static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
  76. size_t count, loff_t *ppos)
  77. {
  78. struct i40e_pf *pf = filp->private_data;
  79. int bytes_not_copied;
  80. int buf_size = 256;
  81. char *buf;
  82. int len;
  83. /* don't allow partial reads */
  84. if (*ppos != 0)
  85. return 0;
  86. if (count < buf_size)
  87. return -ENOSPC;
  88. buf = kzalloc(buf_size, GFP_KERNEL);
  89. if (!buf)
  90. return -ENOSPC;
  91. len = snprintf(buf, buf_size, "%s: %s\n",
  92. pf->vsi[pf->lan_vsi]->netdev->name,
  93. i40e_dbg_command_buf);
  94. bytes_not_copied = copy_to_user(buffer, buf, len);
  95. kfree(buf);
  96. if (bytes_not_copied)
  97. return -EFAULT;
  98. *ppos = len;
  99. return len;
  100. }
  101. static char *i40e_filter_state_string[] = {
  102. "INVALID",
  103. "NEW",
  104. "ACTIVE",
  105. "FAILED",
  106. "REMOVE",
  107. };
  108. /**
  109. * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into command datum
  110. * @pf: the i40e_pf created in command write
  111. * @seid: the seid the user put in
  112. **/
  113. static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
  114. {
  115. struct rtnl_link_stats64 *nstat;
  116. struct i40e_mac_filter *f;
  117. struct i40e_vsi *vsi;
  118. int i, bkt;
  119. vsi = i40e_dbg_find_vsi(pf, seid);
  120. if (!vsi) {
  121. dev_info(&pf->pdev->dev,
  122. "dump %d: seid not found\n", seid);
  123. return;
  124. }
  125. dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
  126. if (vsi->netdev) {
  127. struct net_device *nd = vsi->netdev;
  128. dev_info(&pf->pdev->dev, " netdev: name = %s, state = %lu, flags = 0x%08x\n",
  129. nd->name, nd->state, nd->flags);
  130. dev_info(&pf->pdev->dev, " features = 0x%08lx\n",
  131. (unsigned long int)nd->features);
  132. dev_info(&pf->pdev->dev, " hw_features = 0x%08lx\n",
  133. (unsigned long int)nd->hw_features);
  134. dev_info(&pf->pdev->dev, " vlan_features = 0x%08lx\n",
  135. (unsigned long int)nd->vlan_features);
  136. }
  137. dev_info(&pf->pdev->dev,
  138. " vlgrp: & = %p\n", vsi->active_vlans);
  139. dev_info(&pf->pdev->dev,
  140. " flags = 0x%08lx, netdev_registered = %i, current_netdev_flags = 0x%04x\n",
  141. vsi->flags, vsi->netdev_registered, vsi->current_netdev_flags);
  142. for (i = 0; i < BITS_TO_LONGS(__I40E_VSI_STATE_SIZE__); i++)
  143. dev_info(&pf->pdev->dev,
  144. " state[%d] = %08lx\n",
  145. i, vsi->state[i]);
  146. if (vsi == pf->vsi[pf->lan_vsi])
  147. dev_info(&pf->pdev->dev, " MAC address: %pM SAN MAC: %pM Port MAC: %pM\n",
  148. pf->hw.mac.addr,
  149. pf->hw.mac.san_addr,
  150. pf->hw.mac.port_addr);
  151. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  152. dev_info(&pf->pdev->dev,
  153. " mac_filter_hash: %pM vid=%d, state %s\n",
  154. f->macaddr, f->vlan,
  155. i40e_filter_state_string[f->state]);
  156. }
  157. dev_info(&pf->pdev->dev, " active_filters %u, promisc_threshold %u, overflow promisc %s\n",
  158. vsi->active_filters, vsi->promisc_threshold,
  159. (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) ?
  160. "ON" : "OFF"));
  161. nstat = i40e_get_vsi_stats_struct(vsi);
  162. dev_info(&pf->pdev->dev,
  163. " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
  164. (unsigned long int)nstat->rx_packets,
  165. (unsigned long int)nstat->rx_bytes,
  166. (unsigned long int)nstat->rx_errors,
  167. (unsigned long int)nstat->rx_dropped);
  168. dev_info(&pf->pdev->dev,
  169. " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
  170. (unsigned long int)nstat->tx_packets,
  171. (unsigned long int)nstat->tx_bytes,
  172. (unsigned long int)nstat->tx_errors,
  173. (unsigned long int)nstat->tx_dropped);
  174. dev_info(&pf->pdev->dev,
  175. " net_stats: multicast = %lu, collisions = %lu\n",
  176. (unsigned long int)nstat->multicast,
  177. (unsigned long int)nstat->collisions);
  178. dev_info(&pf->pdev->dev,
  179. " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
  180. (unsigned long int)nstat->rx_length_errors,
  181. (unsigned long int)nstat->rx_over_errors,
  182. (unsigned long int)nstat->rx_crc_errors);
  183. dev_info(&pf->pdev->dev,
  184. " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
  185. (unsigned long int)nstat->rx_frame_errors,
  186. (unsigned long int)nstat->rx_fifo_errors,
  187. (unsigned long int)nstat->rx_missed_errors);
  188. dev_info(&pf->pdev->dev,
  189. " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
  190. (unsigned long int)nstat->tx_aborted_errors,
  191. (unsigned long int)nstat->tx_carrier_errors,
  192. (unsigned long int)nstat->tx_fifo_errors);
  193. dev_info(&pf->pdev->dev,
  194. " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
  195. (unsigned long int)nstat->tx_heartbeat_errors,
  196. (unsigned long int)nstat->tx_window_errors);
  197. dev_info(&pf->pdev->dev,
  198. " net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
  199. (unsigned long int)nstat->rx_compressed,
  200. (unsigned long int)nstat->tx_compressed);
  201. dev_info(&pf->pdev->dev,
  202. " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
  203. (unsigned long int)vsi->net_stats_offsets.rx_packets,
  204. (unsigned long int)vsi->net_stats_offsets.rx_bytes,
  205. (unsigned long int)vsi->net_stats_offsets.rx_errors,
  206. (unsigned long int)vsi->net_stats_offsets.rx_dropped);
  207. dev_info(&pf->pdev->dev,
  208. " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
  209. (unsigned long int)vsi->net_stats_offsets.tx_packets,
  210. (unsigned long int)vsi->net_stats_offsets.tx_bytes,
  211. (unsigned long int)vsi->net_stats_offsets.tx_errors,
  212. (unsigned long int)vsi->net_stats_offsets.tx_dropped);
  213. dev_info(&pf->pdev->dev,
  214. " net_stats_offsets: multicast = %lu, collisions = %lu\n",
  215. (unsigned long int)vsi->net_stats_offsets.multicast,
  216. (unsigned long int)vsi->net_stats_offsets.collisions);
  217. dev_info(&pf->pdev->dev,
  218. " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
  219. (unsigned long int)vsi->net_stats_offsets.rx_length_errors,
  220. (unsigned long int)vsi->net_stats_offsets.rx_over_errors,
  221. (unsigned long int)vsi->net_stats_offsets.rx_crc_errors);
  222. dev_info(&pf->pdev->dev,
  223. " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
  224. (unsigned long int)vsi->net_stats_offsets.rx_frame_errors,
  225. (unsigned long int)vsi->net_stats_offsets.rx_fifo_errors,
  226. (unsigned long int)vsi->net_stats_offsets.rx_missed_errors);
  227. dev_info(&pf->pdev->dev,
  228. " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
  229. (unsigned long int)vsi->net_stats_offsets.tx_aborted_errors,
  230. (unsigned long int)vsi->net_stats_offsets.tx_carrier_errors,
  231. (unsigned long int)vsi->net_stats_offsets.tx_fifo_errors);
  232. dev_info(&pf->pdev->dev,
  233. " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
  234. (unsigned long int)vsi->net_stats_offsets.tx_heartbeat_errors,
  235. (unsigned long int)vsi->net_stats_offsets.tx_window_errors);
  236. dev_info(&pf->pdev->dev,
  237. " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
  238. (unsigned long int)vsi->net_stats_offsets.rx_compressed,
  239. (unsigned long int)vsi->net_stats_offsets.tx_compressed);
  240. dev_info(&pf->pdev->dev,
  241. " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
  242. vsi->tx_restart, vsi->tx_busy,
  243. vsi->rx_buf_failed, vsi->rx_page_failed);
  244. rcu_read_lock();
  245. for (i = 0; i < vsi->num_queue_pairs; i++) {
  246. struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
  247. if (!rx_ring)
  248. continue;
  249. dev_info(&pf->pdev->dev,
  250. " rx_rings[%i]: desc = %p\n",
  251. i, rx_ring->desc);
  252. dev_info(&pf->pdev->dev,
  253. " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
  254. i, rx_ring->dev,
  255. rx_ring->netdev,
  256. rx_ring->rx_bi);
  257. dev_info(&pf->pdev->dev,
  258. " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
  259. i, rx_ring->state,
  260. rx_ring->queue_index,
  261. rx_ring->reg_idx);
  262. dev_info(&pf->pdev->dev,
  263. " rx_rings[%i]: rx_buf_len = %d\n",
  264. i, rx_ring->rx_buf_len);
  265. dev_info(&pf->pdev->dev,
  266. " rx_rings[%i]: next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
  267. i,
  268. rx_ring->next_to_use,
  269. rx_ring->next_to_clean,
  270. rx_ring->ring_active);
  271. dev_info(&pf->pdev->dev,
  272. " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
  273. i, rx_ring->stats.packets,
  274. rx_ring->stats.bytes,
  275. rx_ring->rx_stats.non_eop_descs);
  276. dev_info(&pf->pdev->dev,
  277. " rx_rings[%i]: rx_stats: alloc_page_failed = %lld, alloc_buff_failed = %lld\n",
  278. i,
  279. rx_ring->rx_stats.alloc_page_failed,
  280. rx_ring->rx_stats.alloc_buff_failed);
  281. dev_info(&pf->pdev->dev,
  282. " rx_rings[%i]: rx_stats: realloc_count = %lld, page_reuse_count = %lld\n",
  283. i,
  284. rx_ring->rx_stats.realloc_count,
  285. rx_ring->rx_stats.page_reuse_count);
  286. dev_info(&pf->pdev->dev,
  287. " rx_rings[%i]: size = %i, dma = 0x%08lx\n",
  288. i, rx_ring->size,
  289. (unsigned long int)rx_ring->dma);
  290. dev_info(&pf->pdev->dev,
  291. " rx_rings[%i]: vsi = %p, q_vector = %p\n",
  292. i, rx_ring->vsi,
  293. rx_ring->q_vector);
  294. dev_info(&pf->pdev->dev,
  295. " rx_rings[%i]: rx_itr_setting = %d (%s)\n",
  296. i, rx_ring->rx_itr_setting,
  297. ITR_IS_DYNAMIC(rx_ring->rx_itr_setting) ? "dynamic" : "fixed");
  298. }
  299. for (i = 0; i < vsi->num_queue_pairs; i++) {
  300. struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  301. if (!tx_ring)
  302. continue;
  303. dev_info(&pf->pdev->dev,
  304. " tx_rings[%i]: desc = %p\n",
  305. i, tx_ring->desc);
  306. dev_info(&pf->pdev->dev,
  307. " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
  308. i, tx_ring->dev,
  309. tx_ring->netdev,
  310. tx_ring->tx_bi);
  311. dev_info(&pf->pdev->dev,
  312. " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
  313. i, tx_ring->state,
  314. tx_ring->queue_index,
  315. tx_ring->reg_idx);
  316. dev_info(&pf->pdev->dev,
  317. " tx_rings[%i]: next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
  318. i,
  319. tx_ring->next_to_use,
  320. tx_ring->next_to_clean,
  321. tx_ring->ring_active);
  322. dev_info(&pf->pdev->dev,
  323. " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
  324. i, tx_ring->stats.packets,
  325. tx_ring->stats.bytes,
  326. tx_ring->tx_stats.restart_queue);
  327. dev_info(&pf->pdev->dev,
  328. " tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n",
  329. i,
  330. tx_ring->tx_stats.tx_busy,
  331. tx_ring->tx_stats.tx_done_old);
  332. dev_info(&pf->pdev->dev,
  333. " tx_rings[%i]: size = %i, dma = 0x%08lx\n",
  334. i, tx_ring->size,
  335. (unsigned long int)tx_ring->dma);
  336. dev_info(&pf->pdev->dev,
  337. " tx_rings[%i]: vsi = %p, q_vector = %p\n",
  338. i, tx_ring->vsi,
  339. tx_ring->q_vector);
  340. dev_info(&pf->pdev->dev,
  341. " tx_rings[%i]: DCB tc = %d\n",
  342. i, tx_ring->dcb_tc);
  343. dev_info(&pf->pdev->dev,
  344. " tx_rings[%i]: tx_itr_setting = %d (%s)\n",
  345. i, tx_ring->tx_itr_setting,
  346. ITR_IS_DYNAMIC(tx_ring->tx_itr_setting) ? "dynamic" : "fixed");
  347. }
  348. rcu_read_unlock();
  349. dev_info(&pf->pdev->dev,
  350. " work_limit = %d\n",
  351. vsi->work_limit);
  352. dev_info(&pf->pdev->dev,
  353. " max_frame = %d, rx_buf_len = %d dtype = %d\n",
  354. vsi->max_frame, vsi->rx_buf_len, 0);
  355. dev_info(&pf->pdev->dev,
  356. " num_q_vectors = %i, base_vector = %i\n",
  357. vsi->num_q_vectors, vsi->base_vector);
  358. dev_info(&pf->pdev->dev,
  359. " seid = %d, id = %d, uplink_seid = %d\n",
  360. vsi->seid, vsi->id, vsi->uplink_seid);
  361. dev_info(&pf->pdev->dev,
  362. " base_queue = %d, num_queue_pairs = %d, num_desc = %d\n",
  363. vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc);
  364. dev_info(&pf->pdev->dev, " type = %i\n", vsi->type);
  365. if (vsi->type == I40E_VSI_SRIOV)
  366. dev_info(&pf->pdev->dev, " VF ID = %i\n", vsi->vf_id);
  367. dev_info(&pf->pdev->dev,
  368. " info: valid_sections = 0x%04x, switch_id = 0x%04x\n",
  369. vsi->info.valid_sections, vsi->info.switch_id);
  370. dev_info(&pf->pdev->dev,
  371. " info: sw_reserved[] = 0x%02x 0x%02x\n",
  372. vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]);
  373. dev_info(&pf->pdev->dev,
  374. " info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n",
  375. vsi->info.sec_flags, vsi->info.sec_reserved);
  376. dev_info(&pf->pdev->dev,
  377. " info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n",
  378. vsi->info.pvid, vsi->info.fcoe_pvid,
  379. vsi->info.port_vlan_flags);
  380. dev_info(&pf->pdev->dev,
  381. " info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n",
  382. vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1],
  383. vsi->info.pvlan_reserved[2]);
  384. dev_info(&pf->pdev->dev,
  385. " info: ingress_table = 0x%08x, egress_table = 0x%08x\n",
  386. vsi->info.ingress_table, vsi->info.egress_table);
  387. dev_info(&pf->pdev->dev,
  388. " info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n",
  389. vsi->info.cas_pv_tag, vsi->info.cas_pv_flags,
  390. vsi->info.cas_pv_reserved);
  391. dev_info(&pf->pdev->dev,
  392. " info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
  393. vsi->info.queue_mapping[0], vsi->info.queue_mapping[1],
  394. vsi->info.queue_mapping[2], vsi->info.queue_mapping[3],
  395. vsi->info.queue_mapping[4], vsi->info.queue_mapping[5],
  396. vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]);
  397. dev_info(&pf->pdev->dev,
  398. " info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
  399. vsi->info.queue_mapping[8], vsi->info.queue_mapping[9],
  400. vsi->info.queue_mapping[10], vsi->info.queue_mapping[11],
  401. vsi->info.queue_mapping[12], vsi->info.queue_mapping[13],
  402. vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]);
  403. dev_info(&pf->pdev->dev,
  404. " info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
  405. vsi->info.tc_mapping[0], vsi->info.tc_mapping[1],
  406. vsi->info.tc_mapping[2], vsi->info.tc_mapping[3],
  407. vsi->info.tc_mapping[4], vsi->info.tc_mapping[5],
  408. vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]);
  409. dev_info(&pf->pdev->dev,
  410. " info: queueing_opt_flags = 0x%02x queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n",
  411. vsi->info.queueing_opt_flags,
  412. vsi->info.queueing_opt_reserved[0],
  413. vsi->info.queueing_opt_reserved[1],
  414. vsi->info.queueing_opt_reserved[2]);
  415. dev_info(&pf->pdev->dev,
  416. " info: up_enable_bits = 0x%02x\n",
  417. vsi->info.up_enable_bits);
  418. dev_info(&pf->pdev->dev,
  419. " info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n",
  420. vsi->info.sched_reserved, vsi->info.outer_up_table);
  421. dev_info(&pf->pdev->dev,
  422. " info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n",
  423. vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1],
  424. vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3],
  425. vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5],
  426. vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]);
  427. dev_info(&pf->pdev->dev,
  428. " info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
  429. vsi->info.qs_handle[0], vsi->info.qs_handle[1],
  430. vsi->info.qs_handle[2], vsi->info.qs_handle[3],
  431. vsi->info.qs_handle[4], vsi->info.qs_handle[5],
  432. vsi->info.qs_handle[6], vsi->info.qs_handle[7]);
  433. dev_info(&pf->pdev->dev,
  434. " info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n",
  435. vsi->info.stat_counter_idx, vsi->info.sched_id);
  436. dev_info(&pf->pdev->dev,
  437. " info: resp_reserved[] = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
  438. vsi->info.resp_reserved[0], vsi->info.resp_reserved[1],
  439. vsi->info.resp_reserved[2], vsi->info.resp_reserved[3],
  440. vsi->info.resp_reserved[4], vsi->info.resp_reserved[5],
  441. vsi->info.resp_reserved[6], vsi->info.resp_reserved[7],
  442. vsi->info.resp_reserved[8], vsi->info.resp_reserved[9],
  443. vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]);
  444. if (vsi->back)
  445. dev_info(&pf->pdev->dev, " PF = %p\n", vsi->back);
  446. dev_info(&pf->pdev->dev, " idx = %d\n", vsi->idx);
  447. dev_info(&pf->pdev->dev,
  448. " tc_config: numtc = %d, enabled_tc = 0x%x\n",
  449. vsi->tc_config.numtc, vsi->tc_config.enabled_tc);
  450. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  451. dev_info(&pf->pdev->dev,
  452. " tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n",
  453. i, vsi->tc_config.tc_info[i].qoffset,
  454. vsi->tc_config.tc_info[i].qcount,
  455. vsi->tc_config.tc_info[i].netdev_tc);
  456. }
  457. dev_info(&pf->pdev->dev,
  458. " bw: bw_limit = %d, bw_max_quanta = %d\n",
  459. vsi->bw_limit, vsi->bw_max_quanta);
  460. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  461. dev_info(&pf->pdev->dev,
  462. " bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n",
  463. i, vsi->bw_ets_share_credits[i],
  464. vsi->bw_ets_limit_credits[i],
  465. vsi->bw_ets_max_quanta[i]);
  466. }
  467. }
  468. /**
  469. * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum
  470. * @pf: the i40e_pf created in command write
  471. **/
  472. static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf)
  473. {
  474. struct i40e_adminq_ring *ring;
  475. struct i40e_hw *hw = &pf->hw;
  476. char hdr[32];
  477. int i;
  478. snprintf(hdr, sizeof(hdr), "%s %s: ",
  479. dev_driver_string(&pf->pdev->dev),
  480. dev_name(&pf->pdev->dev));
  481. /* first the send (command) ring, then the receive (event) ring */
  482. dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n");
  483. ring = &(hw->aq.asq);
  484. for (i = 0; i < ring->count; i++) {
  485. struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
  486. dev_info(&pf->pdev->dev,
  487. " at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
  488. i, d->flags, d->opcode, d->datalen, d->retval,
  489. d->cookie_high, d->cookie_low);
  490. print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
  491. 16, 1, d->params.raw, 16, 0);
  492. }
  493. dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n");
  494. ring = &(hw->aq.arq);
  495. for (i = 0; i < ring->count; i++) {
  496. struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
  497. dev_info(&pf->pdev->dev,
  498. " ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
  499. i, d->flags, d->opcode, d->datalen, d->retval,
  500. d->cookie_high, d->cookie_low);
  501. print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
  502. 16, 1, d->params.raw, 16, 0);
  503. }
  504. }
  505. /**
  506. * i40e_dbg_dump_desc - handles dump desc write into command datum
  507. * @cnt: number of arguments that the user supplied
  508. * @vsi_seid: vsi id entered by user
  509. * @ring_id: ring id entered by user
  510. * @desc_n: descriptor number entered by user
  511. * @pf: the i40e_pf created in command write
  512. * @is_rx_ring: true if rx, false if tx
  513. **/
  514. static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
  515. struct i40e_pf *pf, bool is_rx_ring)
  516. {
  517. struct i40e_tx_desc *txd;
  518. union i40e_rx_desc *rxd;
  519. struct i40e_ring *ring;
  520. struct i40e_vsi *vsi;
  521. int i;
  522. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  523. if (!vsi) {
  524. dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid);
  525. return;
  526. }
  527. if (ring_id >= vsi->num_queue_pairs || ring_id < 0) {
  528. dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id);
  529. return;
  530. }
  531. if (!vsi->tx_rings || !vsi->tx_rings[0]->desc) {
  532. dev_info(&pf->pdev->dev,
  533. "descriptor rings have not been allocated for vsi %d\n",
  534. vsi_seid);
  535. return;
  536. }
  537. ring = kmemdup(is_rx_ring
  538. ? vsi->rx_rings[ring_id] : vsi->tx_rings[ring_id],
  539. sizeof(*ring), GFP_KERNEL);
  540. if (!ring)
  541. return;
  542. if (cnt == 2) {
  543. dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n",
  544. vsi_seid, is_rx_ring ? "rx" : "tx", ring_id);
  545. for (i = 0; i < ring->count; i++) {
  546. if (!is_rx_ring) {
  547. txd = I40E_TX_DESC(ring, i);
  548. dev_info(&pf->pdev->dev,
  549. " d[%03x] = 0x%016llx 0x%016llx\n",
  550. i, txd->buffer_addr,
  551. txd->cmd_type_offset_bsz);
  552. } else {
  553. rxd = I40E_RX_DESC(ring, i);
  554. dev_info(&pf->pdev->dev,
  555. " d[%03x] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
  556. i, rxd->read.pkt_addr,
  557. rxd->read.hdr_addr,
  558. rxd->read.rsvd1, rxd->read.rsvd2);
  559. }
  560. }
  561. } else if (cnt == 3) {
  562. if (desc_n >= ring->count || desc_n < 0) {
  563. dev_info(&pf->pdev->dev,
  564. "descriptor %d not found\n", desc_n);
  565. goto out;
  566. }
  567. if (!is_rx_ring) {
  568. txd = I40E_TX_DESC(ring, desc_n);
  569. dev_info(&pf->pdev->dev,
  570. "vsi = %02i tx ring = %02i d[%03x] = 0x%016llx 0x%016llx\n",
  571. vsi_seid, ring_id, desc_n,
  572. txd->buffer_addr, txd->cmd_type_offset_bsz);
  573. } else {
  574. rxd = I40E_RX_DESC(ring, desc_n);
  575. dev_info(&pf->pdev->dev,
  576. "vsi = %02i rx ring = %02i d[%03x] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
  577. vsi_seid, ring_id, desc_n,
  578. rxd->read.pkt_addr, rxd->read.hdr_addr,
  579. rxd->read.rsvd1, rxd->read.rsvd2);
  580. }
  581. } else {
  582. dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
  583. }
  584. out:
  585. kfree(ring);
  586. }
  587. /**
  588. * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum
  589. * @pf: the i40e_pf created in command write
  590. **/
  591. static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
  592. {
  593. int i;
  594. for (i = 0; i < pf->num_alloc_vsi; i++)
  595. if (pf->vsi[i])
  596. dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
  597. i, pf->vsi[i]->seid);
  598. }
  599. /**
  600. * i40e_dbg_dump_stats - handles dump stats write into command datum
  601. * @pf: the i40e_pf created in command write
  602. * @estats: the eth stats structure to be dumped
  603. **/
  604. static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf,
  605. struct i40e_eth_stats *estats)
  606. {
  607. dev_info(&pf->pdev->dev, " ethstats:\n");
  608. dev_info(&pf->pdev->dev,
  609. " rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n",
  610. estats->rx_bytes, estats->rx_unicast, estats->rx_multicast);
  611. dev_info(&pf->pdev->dev,
  612. " rx_broadcast = \t%lld \trx_discards = \t\t%lld\n",
  613. estats->rx_broadcast, estats->rx_discards);
  614. dev_info(&pf->pdev->dev,
  615. " rx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n",
  616. estats->rx_unknown_protocol, estats->tx_bytes);
  617. dev_info(&pf->pdev->dev,
  618. " tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n",
  619. estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast);
  620. dev_info(&pf->pdev->dev,
  621. " tx_discards = \t%lld \ttx_errors = \t\t%lld\n",
  622. estats->tx_discards, estats->tx_errors);
  623. }
  624. /**
  625. * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb
  626. * @pf: the i40e_pf created in command write
  627. * @seid: the seid the user put in
  628. **/
  629. static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid)
  630. {
  631. struct i40e_veb *veb;
  632. veb = i40e_dbg_find_veb(pf, seid);
  633. if (!veb) {
  634. dev_info(&pf->pdev->dev, "can't find veb %d\n", seid);
  635. return;
  636. }
  637. dev_info(&pf->pdev->dev,
  638. "veb idx=%d,%d stats_ic=%d seid=%d uplink=%d mode=%s\n",
  639. veb->idx, veb->veb_idx, veb->stats_idx, veb->seid,
  640. veb->uplink_seid,
  641. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  642. i40e_dbg_dump_eth_stats(pf, &veb->stats);
  643. }
  644. /**
  645. * i40e_dbg_dump_veb_all - dumps all known veb's stats
  646. * @pf: the i40e_pf created in command write
  647. **/
  648. static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
  649. {
  650. struct i40e_veb *veb;
  651. int i;
  652. for (i = 0; i < I40E_MAX_VEB; i++) {
  653. veb = pf->veb[i];
  654. if (veb)
  655. i40e_dbg_dump_veb_seid(pf, veb->seid);
  656. }
  657. }
  658. /**
  659. * i40e_dbg_dump_vf - dump VF info
  660. * @pf: the i40e_pf created in command write
  661. * @vf_id: the vf_id from the user
  662. **/
  663. static void i40e_dbg_dump_vf(struct i40e_pf *pf, int vf_id)
  664. {
  665. struct i40e_vf *vf;
  666. struct i40e_vsi *vsi;
  667. if (!pf->num_alloc_vfs) {
  668. dev_info(&pf->pdev->dev, "no VFs allocated\n");
  669. } else if ((vf_id >= 0) && (vf_id < pf->num_alloc_vfs)) {
  670. vf = &pf->vf[vf_id];
  671. vsi = pf->vsi[vf->lan_vsi_idx];
  672. dev_info(&pf->pdev->dev, "vf %2d: VSI id=%d, seid=%d, qps=%d\n",
  673. vf_id, vf->lan_vsi_id, vsi->seid, vf->num_queue_pairs);
  674. dev_info(&pf->pdev->dev, " num MDD=%lld, invalid msg=%lld, valid msg=%lld\n",
  675. vf->num_mdd_events,
  676. vf->num_invalid_msgs,
  677. vf->num_valid_msgs);
  678. } else {
  679. dev_info(&pf->pdev->dev, "invalid VF id %d\n", vf_id);
  680. }
  681. }
  682. /**
  683. * i40e_dbg_dump_vf_all - dump VF info for all VFs
  684. * @pf: the i40e_pf created in command write
  685. **/
  686. static void i40e_dbg_dump_vf_all(struct i40e_pf *pf)
  687. {
  688. int i;
  689. if (!pf->num_alloc_vfs)
  690. dev_info(&pf->pdev->dev, "no VFs enabled!\n");
  691. else
  692. for (i = 0; i < pf->num_alloc_vfs; i++)
  693. i40e_dbg_dump_vf(pf, i);
  694. }
  695. #define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
  696. /**
  697. * i40e_dbg_command_write - write into command datum
  698. * @filp: the opened file
  699. * @buffer: where to find the user's data
  700. * @count: the length of the user's data
  701. * @ppos: file position offset
  702. **/
  703. static ssize_t i40e_dbg_command_write(struct file *filp,
  704. const char __user *buffer,
  705. size_t count, loff_t *ppos)
  706. {
  707. struct i40e_pf *pf = filp->private_data;
  708. char *cmd_buf, *cmd_buf_tmp;
  709. int bytes_not_copied;
  710. struct i40e_vsi *vsi;
  711. int vsi_seid;
  712. int veb_seid;
  713. int vf_id;
  714. int cnt;
  715. /* don't allow partial writes */
  716. if (*ppos != 0)
  717. return 0;
  718. cmd_buf = kzalloc(count + 1, GFP_KERNEL);
  719. if (!cmd_buf)
  720. return count;
  721. bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
  722. if (bytes_not_copied) {
  723. kfree(cmd_buf);
  724. return -EFAULT;
  725. }
  726. cmd_buf[count] = '\0';
  727. cmd_buf_tmp = strchr(cmd_buf, '\n');
  728. if (cmd_buf_tmp) {
  729. *cmd_buf_tmp = '\0';
  730. count = cmd_buf_tmp - cmd_buf + 1;
  731. }
  732. if (strncmp(cmd_buf, "add vsi", 7) == 0) {
  733. vsi_seid = -1;
  734. cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
  735. if (cnt == 0) {
  736. /* default to PF VSI */
  737. vsi_seid = pf->vsi[pf->lan_vsi]->seid;
  738. } else if (vsi_seid < 0) {
  739. dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
  740. vsi_seid);
  741. goto command_write_done;
  742. }
  743. /* By default we are in VEPA mode, if this is the first VF/VMDq
  744. * VSI to be added switch to VEB mode.
  745. */
  746. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  747. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  748. i40e_do_reset_safe(pf,
  749. BIT_ULL(__I40E_PF_RESET_REQUESTED));
  750. }
  751. vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
  752. if (vsi)
  753. dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
  754. vsi->seid, vsi->uplink_seid);
  755. else
  756. dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
  757. } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
  758. cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
  759. if (cnt != 1) {
  760. dev_info(&pf->pdev->dev,
  761. "del vsi: bad command string, cnt=%d\n",
  762. cnt);
  763. goto command_write_done;
  764. }
  765. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  766. if (!vsi) {
  767. dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
  768. vsi_seid);
  769. goto command_write_done;
  770. }
  771. dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
  772. i40e_vsi_release(vsi);
  773. } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
  774. struct i40e_veb *veb;
  775. int uplink_seid, i;
  776. cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
  777. if (cnt != 2) {
  778. dev_info(&pf->pdev->dev,
  779. "add relay: bad command string, cnt=%d\n",
  780. cnt);
  781. goto command_write_done;
  782. } else if (uplink_seid < 0) {
  783. dev_info(&pf->pdev->dev,
  784. "add relay %d: bad uplink seid\n",
  785. uplink_seid);
  786. goto command_write_done;
  787. }
  788. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  789. if (!vsi) {
  790. dev_info(&pf->pdev->dev,
  791. "add relay: VSI %d not found\n", vsi_seid);
  792. goto command_write_done;
  793. }
  794. for (i = 0; i < I40E_MAX_VEB; i++)
  795. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
  796. break;
  797. if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
  798. uplink_seid != pf->mac_seid) {
  799. dev_info(&pf->pdev->dev,
  800. "add relay: relay uplink %d not found\n",
  801. uplink_seid);
  802. goto command_write_done;
  803. }
  804. veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
  805. vsi->tc_config.enabled_tc);
  806. if (veb)
  807. dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
  808. else
  809. dev_info(&pf->pdev->dev, "add relay failed\n");
  810. } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
  811. int i;
  812. cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
  813. if (cnt != 1) {
  814. dev_info(&pf->pdev->dev,
  815. "del relay: bad command string, cnt=%d\n",
  816. cnt);
  817. goto command_write_done;
  818. } else if (veb_seid < 0) {
  819. dev_info(&pf->pdev->dev,
  820. "del relay %d: bad relay seid\n", veb_seid);
  821. goto command_write_done;
  822. }
  823. /* find the veb */
  824. for (i = 0; i < I40E_MAX_VEB; i++)
  825. if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
  826. break;
  827. if (i >= I40E_MAX_VEB) {
  828. dev_info(&pf->pdev->dev,
  829. "del relay: relay %d not found\n", veb_seid);
  830. goto command_write_done;
  831. }
  832. dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
  833. i40e_veb_release(pf->veb[i]);
  834. } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
  835. i40e_status ret;
  836. u16 vid;
  837. unsigned int v;
  838. cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
  839. if (cnt != 2) {
  840. dev_info(&pf->pdev->dev,
  841. "add pvid: bad command string, cnt=%d\n", cnt);
  842. goto command_write_done;
  843. }
  844. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  845. if (!vsi) {
  846. dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
  847. vsi_seid);
  848. goto command_write_done;
  849. }
  850. vid = v;
  851. ret = i40e_vsi_add_pvid(vsi, vid);
  852. if (!ret)
  853. dev_info(&pf->pdev->dev,
  854. "add pvid: %d added to VSI %d\n",
  855. vid, vsi_seid);
  856. else
  857. dev_info(&pf->pdev->dev,
  858. "add pvid: %d to VSI %d failed, ret=%d\n",
  859. vid, vsi_seid, ret);
  860. } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
  861. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  862. if (cnt != 1) {
  863. dev_info(&pf->pdev->dev,
  864. "del pvid: bad command string, cnt=%d\n",
  865. cnt);
  866. goto command_write_done;
  867. }
  868. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  869. if (!vsi) {
  870. dev_info(&pf->pdev->dev,
  871. "del pvid: VSI %d not found\n", vsi_seid);
  872. goto command_write_done;
  873. }
  874. i40e_vsi_remove_pvid(vsi);
  875. dev_info(&pf->pdev->dev,
  876. "del pvid: removed from VSI %d\n", vsi_seid);
  877. } else if (strncmp(cmd_buf, "dump", 4) == 0) {
  878. if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
  879. i40e_fetch_switch_configuration(pf, true);
  880. } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
  881. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  882. if (cnt > 0)
  883. i40e_dbg_dump_vsi_seid(pf, vsi_seid);
  884. else
  885. i40e_dbg_dump_vsi_no_seid(pf);
  886. } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
  887. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  888. if (cnt > 0)
  889. i40e_dbg_dump_veb_seid(pf, vsi_seid);
  890. else
  891. i40e_dbg_dump_veb_all(pf);
  892. } else if (strncmp(&cmd_buf[5], "vf", 2) == 0) {
  893. cnt = sscanf(&cmd_buf[7], "%i", &vf_id);
  894. if (cnt > 0)
  895. i40e_dbg_dump_vf(pf, vf_id);
  896. else
  897. i40e_dbg_dump_vf_all(pf);
  898. } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
  899. int ring_id, desc_n;
  900. if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
  901. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  902. &vsi_seid, &ring_id, &desc_n);
  903. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  904. desc_n, pf, true);
  905. } else if (strncmp(&cmd_buf[10], "tx", 2)
  906. == 0) {
  907. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  908. &vsi_seid, &ring_id, &desc_n);
  909. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  910. desc_n, pf, false);
  911. } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
  912. i40e_dbg_dump_aq_desc(pf);
  913. } else {
  914. dev_info(&pf->pdev->dev,
  915. "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  916. dev_info(&pf->pdev->dev,
  917. "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  918. dev_info(&pf->pdev->dev, "dump desc aq\n");
  919. }
  920. } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
  921. dev_info(&pf->pdev->dev,
  922. "core reset count: %d\n", pf->corer_count);
  923. dev_info(&pf->pdev->dev,
  924. "global reset count: %d\n", pf->globr_count);
  925. dev_info(&pf->pdev->dev,
  926. "emp reset count: %d\n", pf->empr_count);
  927. dev_info(&pf->pdev->dev,
  928. "pf reset count: %d\n", pf->pfr_count);
  929. dev_info(&pf->pdev->dev,
  930. "pf tx sluggish count: %d\n",
  931. pf->tx_sluggish_count);
  932. } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
  933. struct i40e_aqc_query_port_ets_config_resp *bw_data;
  934. struct i40e_dcbx_config *cfg =
  935. &pf->hw.local_dcbx_config;
  936. struct i40e_dcbx_config *r_cfg =
  937. &pf->hw.remote_dcbx_config;
  938. int i, ret;
  939. u16 switch_id;
  940. bw_data = kzalloc(sizeof(
  941. struct i40e_aqc_query_port_ets_config_resp),
  942. GFP_KERNEL);
  943. if (!bw_data) {
  944. ret = -ENOMEM;
  945. goto command_write_done;
  946. }
  947. vsi = pf->vsi[pf->lan_vsi];
  948. switch_id =
  949. le16_to_cpu(vsi->info.switch_id) &
  950. I40E_AQ_VSI_SW_ID_MASK;
  951. ret = i40e_aq_query_port_ets_config(&pf->hw,
  952. switch_id,
  953. bw_data, NULL);
  954. if (ret) {
  955. dev_info(&pf->pdev->dev,
  956. "Query Port ETS Config AQ command failed =0x%x\n",
  957. pf->hw.aq.asq_last_status);
  958. kfree(bw_data);
  959. bw_data = NULL;
  960. goto command_write_done;
  961. }
  962. dev_info(&pf->pdev->dev,
  963. "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
  964. bw_data->tc_valid_bits,
  965. bw_data->tc_strict_priority_bits,
  966. le16_to_cpu(bw_data->tc_bw_max[0]),
  967. le16_to_cpu(bw_data->tc_bw_max[1]));
  968. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  969. dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
  970. bw_data->tc_bw_share_credits[i],
  971. le16_to_cpu(bw_data->tc_bw_limits[i]));
  972. }
  973. kfree(bw_data);
  974. bw_data = NULL;
  975. dev_info(&pf->pdev->dev,
  976. "port dcbx_mode=%d\n", cfg->dcbx_mode);
  977. dev_info(&pf->pdev->dev,
  978. "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  979. cfg->etscfg.willing, cfg->etscfg.cbs,
  980. cfg->etscfg.maxtcs);
  981. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  982. dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  983. i, cfg->etscfg.prioritytable[i],
  984. cfg->etscfg.tcbwtable[i],
  985. cfg->etscfg.tsatable[i]);
  986. }
  987. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  988. dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  989. i, cfg->etsrec.prioritytable[i],
  990. cfg->etsrec.tcbwtable[i],
  991. cfg->etsrec.tsatable[i]);
  992. }
  993. dev_info(&pf->pdev->dev,
  994. "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  995. cfg->pfc.willing, cfg->pfc.mbc,
  996. cfg->pfc.pfccap, cfg->pfc.pfcenable);
  997. dev_info(&pf->pdev->dev,
  998. "port app_table: num_apps=%d\n", cfg->numapps);
  999. for (i = 0; i < cfg->numapps; i++) {
  1000. dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1001. i, cfg->app[i].priority,
  1002. cfg->app[i].selector,
  1003. cfg->app[i].protocolid);
  1004. }
  1005. /* Peer TLV DCBX data */
  1006. dev_info(&pf->pdev->dev,
  1007. "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  1008. r_cfg->etscfg.willing,
  1009. r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
  1010. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1011. dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1012. i, r_cfg->etscfg.prioritytable[i],
  1013. r_cfg->etscfg.tcbwtable[i],
  1014. r_cfg->etscfg.tsatable[i]);
  1015. }
  1016. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1017. dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1018. i, r_cfg->etsrec.prioritytable[i],
  1019. r_cfg->etsrec.tcbwtable[i],
  1020. r_cfg->etsrec.tsatable[i]);
  1021. }
  1022. dev_info(&pf->pdev->dev,
  1023. "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  1024. r_cfg->pfc.willing,
  1025. r_cfg->pfc.mbc,
  1026. r_cfg->pfc.pfccap,
  1027. r_cfg->pfc.pfcenable);
  1028. dev_info(&pf->pdev->dev,
  1029. "remote port app_table: num_apps=%d\n",
  1030. r_cfg->numapps);
  1031. for (i = 0; i < r_cfg->numapps; i++) {
  1032. dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1033. i, r_cfg->app[i].priority,
  1034. r_cfg->app[i].selector,
  1035. r_cfg->app[i].protocolid);
  1036. }
  1037. } else if (strncmp(&cmd_buf[5], "debug fwdata", 12) == 0) {
  1038. int cluster_id, table_id;
  1039. int index, ret;
  1040. u16 buff_len = 4096;
  1041. u32 next_index;
  1042. u8 next_table;
  1043. u8 *buff;
  1044. u16 rlen;
  1045. cnt = sscanf(&cmd_buf[18], "%i %i %i",
  1046. &cluster_id, &table_id, &index);
  1047. if (cnt != 3) {
  1048. dev_info(&pf->pdev->dev,
  1049. "dump debug fwdata <cluster_id> <table_id> <index>\n");
  1050. goto command_write_done;
  1051. }
  1052. dev_info(&pf->pdev->dev,
  1053. "AQ debug dump fwdata params %x %x %x %x\n",
  1054. cluster_id, table_id, index, buff_len);
  1055. buff = kzalloc(buff_len, GFP_KERNEL);
  1056. if (!buff)
  1057. goto command_write_done;
  1058. ret = i40e_aq_debug_dump(&pf->hw, cluster_id, table_id,
  1059. index, buff_len, buff, &rlen,
  1060. &next_table, &next_index,
  1061. NULL);
  1062. if (ret) {
  1063. dev_info(&pf->pdev->dev,
  1064. "debug dump fwdata AQ Failed %d 0x%x\n",
  1065. ret, pf->hw.aq.asq_last_status);
  1066. kfree(buff);
  1067. buff = NULL;
  1068. goto command_write_done;
  1069. }
  1070. dev_info(&pf->pdev->dev,
  1071. "AQ debug dump fwdata rlen=0x%x next_table=0x%x next_index=0x%x\n",
  1072. rlen, next_table, next_index);
  1073. print_hex_dump(KERN_INFO, "AQ buffer WB: ",
  1074. DUMP_PREFIX_OFFSET, 16, 1,
  1075. buff, rlen, true);
  1076. kfree(buff);
  1077. buff = NULL;
  1078. } else {
  1079. dev_info(&pf->pdev->dev,
  1080. "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
  1081. dev_info(&pf->pdev->dev, "dump switch\n");
  1082. dev_info(&pf->pdev->dev, "dump vsi [seid]\n");
  1083. dev_info(&pf->pdev->dev, "dump reset stats\n");
  1084. dev_info(&pf->pdev->dev, "dump port\n");
  1085. dev_info(&pf->pdev->dev, "dump vf [vf_id]\n");
  1086. dev_info(&pf->pdev->dev,
  1087. "dump debug fwdata <cluster_id> <table_id> <index>\n");
  1088. }
  1089. } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
  1090. dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n");
  1091. i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1092. } else if (strncmp(cmd_buf, "corer", 5) == 0) {
  1093. dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n");
  1094. i40e_do_reset_safe(pf, BIT(__I40E_CORE_RESET_REQUESTED));
  1095. } else if (strncmp(cmd_buf, "globr", 5) == 0) {
  1096. dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n");
  1097. i40e_do_reset_safe(pf, BIT(__I40E_GLOBAL_RESET_REQUESTED));
  1098. } else if (strncmp(cmd_buf, "empr", 4) == 0) {
  1099. dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n");
  1100. i40e_do_reset_safe(pf, BIT(__I40E_EMP_RESET_REQUESTED));
  1101. } else if (strncmp(cmd_buf, "read", 4) == 0) {
  1102. u32 address;
  1103. u32 value;
  1104. cnt = sscanf(&cmd_buf[4], "%i", &address);
  1105. if (cnt != 1) {
  1106. dev_info(&pf->pdev->dev, "read <reg>\n");
  1107. goto command_write_done;
  1108. }
  1109. /* check the range on address */
  1110. if (address > (pf->ioremap_len - sizeof(u32))) {
  1111. dev_info(&pf->pdev->dev, "read reg address 0x%08x too large, max=0x%08lx\n",
  1112. address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
  1113. goto command_write_done;
  1114. }
  1115. value = rd32(&pf->hw, address);
  1116. dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
  1117. address, value);
  1118. } else if (strncmp(cmd_buf, "write", 5) == 0) {
  1119. u32 address, value;
  1120. cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
  1121. if (cnt != 2) {
  1122. dev_info(&pf->pdev->dev, "write <reg> <value>\n");
  1123. goto command_write_done;
  1124. }
  1125. /* check the range on address */
  1126. if (address > (pf->ioremap_len - sizeof(u32))) {
  1127. dev_info(&pf->pdev->dev, "write reg address 0x%08x too large, max=0x%08lx\n",
  1128. address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
  1129. goto command_write_done;
  1130. }
  1131. wr32(&pf->hw, address, value);
  1132. value = rd32(&pf->hw, address);
  1133. dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
  1134. address, value);
  1135. } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
  1136. if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
  1137. cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
  1138. if (cnt == 0) {
  1139. int i;
  1140. for (i = 0; i < pf->num_alloc_vsi; i++)
  1141. i40e_vsi_reset_stats(pf->vsi[i]);
  1142. dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
  1143. } else if (cnt == 1) {
  1144. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1145. if (!vsi) {
  1146. dev_info(&pf->pdev->dev,
  1147. "clear_stats vsi: bad vsi %d\n",
  1148. vsi_seid);
  1149. goto command_write_done;
  1150. }
  1151. i40e_vsi_reset_stats(vsi);
  1152. dev_info(&pf->pdev->dev,
  1153. "vsi clear stats called for vsi %d\n",
  1154. vsi_seid);
  1155. } else {
  1156. dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
  1157. }
  1158. } else if (strncmp(&cmd_buf[12], "port", 4) == 0) {
  1159. if (pf->hw.partition_id == 1) {
  1160. i40e_pf_reset_stats(pf);
  1161. dev_info(&pf->pdev->dev, "port stats cleared\n");
  1162. } else {
  1163. dev_info(&pf->pdev->dev, "clear port stats not allowed on this port partition\n");
  1164. }
  1165. } else {
  1166. dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats port\n");
  1167. }
  1168. } else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) {
  1169. struct i40e_aq_desc *desc;
  1170. i40e_status ret;
  1171. desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
  1172. if (!desc)
  1173. goto command_write_done;
  1174. cnt = sscanf(&cmd_buf[11],
  1175. "%hi %hi %hi %hi %i %i %i %i %i %i",
  1176. &desc->flags,
  1177. &desc->opcode, &desc->datalen, &desc->retval,
  1178. &desc->cookie_high, &desc->cookie_low,
  1179. &desc->params.internal.param0,
  1180. &desc->params.internal.param1,
  1181. &desc->params.internal.param2,
  1182. &desc->params.internal.param3);
  1183. if (cnt != 10) {
  1184. dev_info(&pf->pdev->dev,
  1185. "send aq_cmd: bad command string, cnt=%d\n",
  1186. cnt);
  1187. kfree(desc);
  1188. desc = NULL;
  1189. goto command_write_done;
  1190. }
  1191. ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL);
  1192. if (!ret) {
  1193. dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
  1194. } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
  1195. dev_info(&pf->pdev->dev,
  1196. "AQ command send failed Opcode %x AQ Error: %d\n",
  1197. desc->opcode, pf->hw.aq.asq_last_status);
  1198. } else {
  1199. dev_info(&pf->pdev->dev,
  1200. "AQ command send failed Opcode %x Status: %d\n",
  1201. desc->opcode, ret);
  1202. }
  1203. dev_info(&pf->pdev->dev,
  1204. "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1205. desc->flags, desc->opcode, desc->datalen, desc->retval,
  1206. desc->cookie_high, desc->cookie_low,
  1207. desc->params.internal.param0,
  1208. desc->params.internal.param1,
  1209. desc->params.internal.param2,
  1210. desc->params.internal.param3);
  1211. kfree(desc);
  1212. desc = NULL;
  1213. } else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) {
  1214. struct i40e_aq_desc *desc;
  1215. i40e_status ret;
  1216. u16 buffer_len;
  1217. u8 *buff;
  1218. desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
  1219. if (!desc)
  1220. goto command_write_done;
  1221. cnt = sscanf(&cmd_buf[20],
  1222. "%hi %hi %hi %hi %i %i %i %i %i %i %hi",
  1223. &desc->flags,
  1224. &desc->opcode, &desc->datalen, &desc->retval,
  1225. &desc->cookie_high, &desc->cookie_low,
  1226. &desc->params.internal.param0,
  1227. &desc->params.internal.param1,
  1228. &desc->params.internal.param2,
  1229. &desc->params.internal.param3,
  1230. &buffer_len);
  1231. if (cnt != 11) {
  1232. dev_info(&pf->pdev->dev,
  1233. "send indirect aq_cmd: bad command string, cnt=%d\n",
  1234. cnt);
  1235. kfree(desc);
  1236. desc = NULL;
  1237. goto command_write_done;
  1238. }
  1239. /* Just stub a buffer big enough in case user messed up */
  1240. if (buffer_len == 0)
  1241. buffer_len = 1280;
  1242. buff = kzalloc(buffer_len, GFP_KERNEL);
  1243. if (!buff) {
  1244. kfree(desc);
  1245. desc = NULL;
  1246. goto command_write_done;
  1247. }
  1248. desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1249. ret = i40e_asq_send_command(&pf->hw, desc, buff,
  1250. buffer_len, NULL);
  1251. if (!ret) {
  1252. dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
  1253. } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
  1254. dev_info(&pf->pdev->dev,
  1255. "AQ command send failed Opcode %x AQ Error: %d\n",
  1256. desc->opcode, pf->hw.aq.asq_last_status);
  1257. } else {
  1258. dev_info(&pf->pdev->dev,
  1259. "AQ command send failed Opcode %x Status: %d\n",
  1260. desc->opcode, ret);
  1261. }
  1262. dev_info(&pf->pdev->dev,
  1263. "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1264. desc->flags, desc->opcode, desc->datalen, desc->retval,
  1265. desc->cookie_high, desc->cookie_low,
  1266. desc->params.internal.param0,
  1267. desc->params.internal.param1,
  1268. desc->params.internal.param2,
  1269. desc->params.internal.param3);
  1270. print_hex_dump(KERN_INFO, "AQ buffer WB: ",
  1271. DUMP_PREFIX_OFFSET, 16, 1,
  1272. buff, buffer_len, true);
  1273. kfree(buff);
  1274. buff = NULL;
  1275. kfree(desc);
  1276. desc = NULL;
  1277. } else if (strncmp(cmd_buf, "fd current cnt", 14) == 0) {
  1278. dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
  1279. i40e_get_current_fd_count(pf));
  1280. } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
  1281. if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
  1282. int ret;
  1283. ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
  1284. if (ret) {
  1285. dev_info(&pf->pdev->dev,
  1286. "Stop LLDP AQ command failed =0x%x\n",
  1287. pf->hw.aq.asq_last_status);
  1288. goto command_write_done;
  1289. }
  1290. ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
  1291. pf->hw.mac.addr,
  1292. I40E_ETH_P_LLDP, 0,
  1293. pf->vsi[pf->lan_vsi]->seid,
  1294. 0, true, NULL, NULL);
  1295. if (ret) {
  1296. dev_info(&pf->pdev->dev,
  1297. "%s: Add Control Packet Filter AQ command failed =0x%x\n",
  1298. __func__, pf->hw.aq.asq_last_status);
  1299. goto command_write_done;
  1300. }
  1301. #ifdef CONFIG_I40E_DCB
  1302. pf->dcbx_cap = DCB_CAP_DCBX_HOST |
  1303. DCB_CAP_DCBX_VER_IEEE;
  1304. #endif /* CONFIG_I40E_DCB */
  1305. } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
  1306. int ret;
  1307. ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
  1308. pf->hw.mac.addr,
  1309. I40E_ETH_P_LLDP, 0,
  1310. pf->vsi[pf->lan_vsi]->seid,
  1311. 0, false, NULL, NULL);
  1312. if (ret) {
  1313. dev_info(&pf->pdev->dev,
  1314. "%s: Remove Control Packet Filter AQ command failed =0x%x\n",
  1315. __func__, pf->hw.aq.asq_last_status);
  1316. /* Continue and start FW LLDP anyways */
  1317. }
  1318. ret = i40e_aq_start_lldp(&pf->hw, NULL);
  1319. if (ret) {
  1320. dev_info(&pf->pdev->dev,
  1321. "Start LLDP AQ command failed =0x%x\n",
  1322. pf->hw.aq.asq_last_status);
  1323. goto command_write_done;
  1324. }
  1325. #ifdef CONFIG_I40E_DCB
  1326. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  1327. DCB_CAP_DCBX_VER_IEEE;
  1328. #endif /* CONFIG_I40E_DCB */
  1329. } else if (strncmp(&cmd_buf[5],
  1330. "get local", 9) == 0) {
  1331. u16 llen, rlen;
  1332. int ret;
  1333. u8 *buff;
  1334. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1335. if (!buff)
  1336. goto command_write_done;
  1337. ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
  1338. I40E_AQ_LLDP_MIB_LOCAL,
  1339. buff, I40E_LLDPDU_SIZE,
  1340. &llen, &rlen, NULL);
  1341. if (ret) {
  1342. dev_info(&pf->pdev->dev,
  1343. "Get LLDP MIB (local) AQ command failed =0x%x\n",
  1344. pf->hw.aq.asq_last_status);
  1345. kfree(buff);
  1346. buff = NULL;
  1347. goto command_write_done;
  1348. }
  1349. dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
  1350. print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
  1351. DUMP_PREFIX_OFFSET, 16, 1,
  1352. buff, I40E_LLDPDU_SIZE, true);
  1353. kfree(buff);
  1354. buff = NULL;
  1355. } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
  1356. u16 llen, rlen;
  1357. int ret;
  1358. u8 *buff;
  1359. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1360. if (!buff)
  1361. goto command_write_done;
  1362. ret = i40e_aq_get_lldp_mib(&pf->hw,
  1363. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  1364. I40E_AQ_LLDP_MIB_REMOTE,
  1365. buff, I40E_LLDPDU_SIZE,
  1366. &llen, &rlen, NULL);
  1367. if (ret) {
  1368. dev_info(&pf->pdev->dev,
  1369. "Get LLDP MIB (remote) AQ command failed =0x%x\n",
  1370. pf->hw.aq.asq_last_status);
  1371. kfree(buff);
  1372. buff = NULL;
  1373. goto command_write_done;
  1374. }
  1375. dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
  1376. print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
  1377. DUMP_PREFIX_OFFSET, 16, 1,
  1378. buff, I40E_LLDPDU_SIZE, true);
  1379. kfree(buff);
  1380. buff = NULL;
  1381. } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
  1382. int ret;
  1383. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1384. true, NULL);
  1385. if (ret) {
  1386. dev_info(&pf->pdev->dev,
  1387. "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
  1388. pf->hw.aq.asq_last_status);
  1389. goto command_write_done;
  1390. }
  1391. } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
  1392. int ret;
  1393. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1394. false, NULL);
  1395. if (ret) {
  1396. dev_info(&pf->pdev->dev,
  1397. "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
  1398. pf->hw.aq.asq_last_status);
  1399. goto command_write_done;
  1400. }
  1401. }
  1402. } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
  1403. u16 buffer_len, bytes;
  1404. u16 module;
  1405. u32 offset;
  1406. u16 *buff;
  1407. int ret;
  1408. cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
  1409. &module, &offset, &buffer_len);
  1410. if (cnt == 0) {
  1411. module = 0;
  1412. offset = 0;
  1413. buffer_len = 0;
  1414. } else if (cnt == 1) {
  1415. offset = 0;
  1416. buffer_len = 0;
  1417. } else if (cnt == 2) {
  1418. buffer_len = 0;
  1419. } else if (cnt > 3) {
  1420. dev_info(&pf->pdev->dev,
  1421. "nvm read: bad command string, cnt=%d\n", cnt);
  1422. goto command_write_done;
  1423. }
  1424. /* set the max length */
  1425. buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
  1426. bytes = 2 * buffer_len;
  1427. /* read at least 1k bytes, no more than 4kB */
  1428. bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
  1429. buff = kzalloc(bytes, GFP_KERNEL);
  1430. if (!buff)
  1431. goto command_write_done;
  1432. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  1433. if (ret) {
  1434. dev_info(&pf->pdev->dev,
  1435. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1436. ret, pf->hw.aq.asq_last_status);
  1437. kfree(buff);
  1438. goto command_write_done;
  1439. }
  1440. ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
  1441. bytes, (u8 *)buff, true, NULL);
  1442. i40e_release_nvm(&pf->hw);
  1443. if (ret) {
  1444. dev_info(&pf->pdev->dev,
  1445. "Read NVM AQ failed err=%d status=0x%x\n",
  1446. ret, pf->hw.aq.asq_last_status);
  1447. } else {
  1448. dev_info(&pf->pdev->dev,
  1449. "Read NVM module=0x%x offset=0x%x words=%d\n",
  1450. module, offset, buffer_len);
  1451. if (bytes)
  1452. print_hex_dump(KERN_INFO, "NVM Dump: ",
  1453. DUMP_PREFIX_OFFSET, 16, 2,
  1454. buff, bytes, true);
  1455. }
  1456. kfree(buff);
  1457. buff = NULL;
  1458. } else {
  1459. dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
  1460. dev_info(&pf->pdev->dev, "available commands\n");
  1461. dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
  1462. dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
  1463. dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
  1464. dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
  1465. dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
  1466. dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
  1467. dev_info(&pf->pdev->dev, " dump switch\n");
  1468. dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
  1469. dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  1470. dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  1471. dev_info(&pf->pdev->dev, " dump desc aq\n");
  1472. dev_info(&pf->pdev->dev, " dump reset stats\n");
  1473. dev_info(&pf->pdev->dev, " dump debug fwdata <cluster_id> <table_id> <index>\n");
  1474. dev_info(&pf->pdev->dev, " read <reg>\n");
  1475. dev_info(&pf->pdev->dev, " write <reg> <value>\n");
  1476. dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
  1477. dev_info(&pf->pdev->dev, " clear_stats port\n");
  1478. dev_info(&pf->pdev->dev, " pfr\n");
  1479. dev_info(&pf->pdev->dev, " corer\n");
  1480. dev_info(&pf->pdev->dev, " globr\n");
  1481. dev_info(&pf->pdev->dev, " send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n");
  1482. dev_info(&pf->pdev->dev, " send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n");
  1483. dev_info(&pf->pdev->dev, " fd current cnt");
  1484. dev_info(&pf->pdev->dev, " lldp start\n");
  1485. dev_info(&pf->pdev->dev, " lldp stop\n");
  1486. dev_info(&pf->pdev->dev, " lldp get local\n");
  1487. dev_info(&pf->pdev->dev, " lldp get remote\n");
  1488. dev_info(&pf->pdev->dev, " lldp event on\n");
  1489. dev_info(&pf->pdev->dev, " lldp event off\n");
  1490. dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
  1491. }
  1492. command_write_done:
  1493. kfree(cmd_buf);
  1494. cmd_buf = NULL;
  1495. return count;
  1496. }
  1497. static const struct file_operations i40e_dbg_command_fops = {
  1498. .owner = THIS_MODULE,
  1499. .open = simple_open,
  1500. .read = i40e_dbg_command_read,
  1501. .write = i40e_dbg_command_write,
  1502. };
  1503. /**************************************************************
  1504. * netdev_ops
  1505. * The netdev_ops entry in debugfs is for giving the driver commands
  1506. * to be executed from the netdev operations.
  1507. **************************************************************/
  1508. static char i40e_dbg_netdev_ops_buf[256] = "";
  1509. /**
  1510. * i40e_dbg_netdev_ops - read for netdev_ops datum
  1511. * @filp: the opened file
  1512. * @buffer: where to write the data for the user to read
  1513. * @count: the size of the user's buffer
  1514. * @ppos: file position offset
  1515. **/
  1516. static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
  1517. size_t count, loff_t *ppos)
  1518. {
  1519. struct i40e_pf *pf = filp->private_data;
  1520. int bytes_not_copied;
  1521. int buf_size = 256;
  1522. char *buf;
  1523. int len;
  1524. /* don't allow partal reads */
  1525. if (*ppos != 0)
  1526. return 0;
  1527. if (count < buf_size)
  1528. return -ENOSPC;
  1529. buf = kzalloc(buf_size, GFP_KERNEL);
  1530. if (!buf)
  1531. return -ENOSPC;
  1532. len = snprintf(buf, buf_size, "%s: %s\n",
  1533. pf->vsi[pf->lan_vsi]->netdev->name,
  1534. i40e_dbg_netdev_ops_buf);
  1535. bytes_not_copied = copy_to_user(buffer, buf, len);
  1536. kfree(buf);
  1537. if (bytes_not_copied)
  1538. return -EFAULT;
  1539. *ppos = len;
  1540. return len;
  1541. }
  1542. /**
  1543. * i40e_dbg_netdev_ops_write - write into netdev_ops datum
  1544. * @filp: the opened file
  1545. * @buffer: where to find the user's data
  1546. * @count: the length of the user's data
  1547. * @ppos: file position offset
  1548. **/
  1549. static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
  1550. const char __user *buffer,
  1551. size_t count, loff_t *ppos)
  1552. {
  1553. struct i40e_pf *pf = filp->private_data;
  1554. int bytes_not_copied;
  1555. struct i40e_vsi *vsi;
  1556. char *buf_tmp;
  1557. int vsi_seid;
  1558. int i, cnt;
  1559. /* don't allow partial writes */
  1560. if (*ppos != 0)
  1561. return 0;
  1562. if (count >= sizeof(i40e_dbg_netdev_ops_buf))
  1563. return -ENOSPC;
  1564. memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
  1565. bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
  1566. buffer, count);
  1567. if (bytes_not_copied)
  1568. return -EFAULT;
  1569. i40e_dbg_netdev_ops_buf[count] = '\0';
  1570. buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
  1571. if (buf_tmp) {
  1572. *buf_tmp = '\0';
  1573. count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
  1574. }
  1575. if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
  1576. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1577. if (cnt != 1) {
  1578. dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
  1579. goto netdev_ops_write_done;
  1580. }
  1581. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1582. if (!vsi) {
  1583. dev_info(&pf->pdev->dev,
  1584. "tx_timeout: VSI %d not found\n", vsi_seid);
  1585. } else if (!vsi->netdev) {
  1586. dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n",
  1587. vsi_seid);
  1588. } else if (test_bit(__I40E_VSI_DOWN, vsi->state)) {
  1589. dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n",
  1590. vsi_seid);
  1591. } else if (rtnl_trylock()) {
  1592. vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
  1593. rtnl_unlock();
  1594. dev_info(&pf->pdev->dev, "tx_timeout called\n");
  1595. } else {
  1596. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1597. }
  1598. } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
  1599. int mtu;
  1600. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
  1601. &vsi_seid, &mtu);
  1602. if (cnt != 2) {
  1603. dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
  1604. goto netdev_ops_write_done;
  1605. }
  1606. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1607. if (!vsi) {
  1608. dev_info(&pf->pdev->dev,
  1609. "change_mtu: VSI %d not found\n", vsi_seid);
  1610. } else if (!vsi->netdev) {
  1611. dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n",
  1612. vsi_seid);
  1613. } else if (rtnl_trylock()) {
  1614. vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
  1615. mtu);
  1616. rtnl_unlock();
  1617. dev_info(&pf->pdev->dev, "change_mtu called\n");
  1618. } else {
  1619. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1620. }
  1621. } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
  1622. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1623. if (cnt != 1) {
  1624. dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
  1625. goto netdev_ops_write_done;
  1626. }
  1627. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1628. if (!vsi) {
  1629. dev_info(&pf->pdev->dev,
  1630. "set_rx_mode: VSI %d not found\n", vsi_seid);
  1631. } else if (!vsi->netdev) {
  1632. dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n",
  1633. vsi_seid);
  1634. } else if (rtnl_trylock()) {
  1635. vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
  1636. rtnl_unlock();
  1637. dev_info(&pf->pdev->dev, "set_rx_mode called\n");
  1638. } else {
  1639. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1640. }
  1641. } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
  1642. cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
  1643. if (cnt != 1) {
  1644. dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
  1645. goto netdev_ops_write_done;
  1646. }
  1647. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1648. if (!vsi) {
  1649. dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
  1650. vsi_seid);
  1651. } else if (!vsi->netdev) {
  1652. dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n",
  1653. vsi_seid);
  1654. } else {
  1655. for (i = 0; i < vsi->num_q_vectors; i++)
  1656. napi_schedule(&vsi->q_vectors[i]->napi);
  1657. dev_info(&pf->pdev->dev, "napi called\n");
  1658. }
  1659. } else {
  1660. dev_info(&pf->pdev->dev, "unknown command '%s'\n",
  1661. i40e_dbg_netdev_ops_buf);
  1662. dev_info(&pf->pdev->dev, "available commands\n");
  1663. dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
  1664. dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
  1665. dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
  1666. dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
  1667. }
  1668. netdev_ops_write_done:
  1669. return count;
  1670. }
  1671. static const struct file_operations i40e_dbg_netdev_ops_fops = {
  1672. .owner = THIS_MODULE,
  1673. .open = simple_open,
  1674. .read = i40e_dbg_netdev_ops_read,
  1675. .write = i40e_dbg_netdev_ops_write,
  1676. };
  1677. /**
  1678. * i40e_dbg_pf_init - setup the debugfs directory for the PF
  1679. * @pf: the PF that is starting up
  1680. **/
  1681. void i40e_dbg_pf_init(struct i40e_pf *pf)
  1682. {
  1683. struct dentry *pfile;
  1684. const char *name = pci_name(pf->pdev);
  1685. const struct device *dev = &pf->pdev->dev;
  1686. pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
  1687. if (!pf->i40e_dbg_pf)
  1688. return;
  1689. pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
  1690. &i40e_dbg_command_fops);
  1691. if (!pfile)
  1692. goto create_failed;
  1693. pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
  1694. &i40e_dbg_netdev_ops_fops);
  1695. if (!pfile)
  1696. goto create_failed;
  1697. return;
  1698. create_failed:
  1699. dev_info(dev, "debugfs dir/file for %s failed\n", name);
  1700. debugfs_remove_recursive(pf->i40e_dbg_pf);
  1701. }
  1702. /**
  1703. * i40e_dbg_pf_exit - clear out the PF's debugfs entries
  1704. * @pf: the PF that is stopping
  1705. **/
  1706. void i40e_dbg_pf_exit(struct i40e_pf *pf)
  1707. {
  1708. debugfs_remove_recursive(pf->i40e_dbg_pf);
  1709. pf->i40e_dbg_pf = NULL;
  1710. }
  1711. /**
  1712. * i40e_dbg_init - start up debugfs for the driver
  1713. **/
  1714. void i40e_dbg_init(void)
  1715. {
  1716. i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
  1717. if (!i40e_dbg_root)
  1718. pr_info("init of debugfs failed\n");
  1719. }
  1720. /**
  1721. * i40e_dbg_exit - clean out the driver's debugfs entries
  1722. **/
  1723. void i40e_dbg_exit(void)
  1724. {
  1725. debugfs_remove_recursive(i40e_dbg_root);
  1726. i40e_dbg_root = NULL;
  1727. }
  1728. #endif /* CONFIG_DEBUG_FS */