i40e_debugfs.c 66 KB

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