i40e_debugfs.c 67 KB

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