i40e_debugfs.c 64 KB

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