i40e_debugfs.c 57 KB

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