i40e_debugfs.c 58 KB

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