i40e_debugfs.c 66 KB

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