i40e_debugfs.c 72 KB

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