i40e_debugfs.c 66 KB

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