i40e_debugfs.c 70 KB

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