i40e_debugfs.c 58 KB

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