i40e_debugfs.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #ifdef CONFIG_DEBUG_FS
  28. #include <linux/fs.h>
  29. #include <linux/debugfs.h>
  30. #include "i40e.h"
  31. static struct dentry *i40e_dbg_root;
  32. /**
  33. * i40e_dbg_find_vsi - searches for the vsi with the given seid
  34. * @pf - the pf structure to search for the vsi
  35. * @seid - seid of the vsi it is searching for
  36. **/
  37. static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
  38. {
  39. int i;
  40. if (seid < 0)
  41. dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
  42. else
  43. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  44. if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
  45. return pf->vsi[i];
  46. return NULL;
  47. }
  48. /**
  49. * i40e_dbg_find_veb - searches for the veb with the given seid
  50. * @pf - the pf structure to search for the veb
  51. * @seid - seid of the veb it is searching for
  52. **/
  53. static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
  54. {
  55. int i;
  56. if ((seid < I40E_BASE_VEB_SEID) ||
  57. (seid > (I40E_BASE_VEB_SEID + I40E_MAX_VEB)))
  58. dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
  59. else
  60. for (i = 0; i < I40E_MAX_VEB; i++)
  61. if (pf->veb[i] && pf->veb[i]->seid == seid)
  62. return pf->veb[i];
  63. return NULL;
  64. }
  65. /**************************************************************
  66. * dump
  67. * The dump entry in debugfs is for getting a data snapshow of
  68. * the driver's current configuration and runtime details.
  69. * When the filesystem entry is written, a snapshot is taken.
  70. * When the entry is read, the most recent snapshot data is dumped.
  71. **************************************************************/
  72. static char *i40e_dbg_dump_buf;
  73. static ssize_t i40e_dbg_dump_data_len;
  74. static ssize_t i40e_dbg_dump_buffer_len;
  75. /**
  76. * i40e_dbg_dump_read - read the dump data
  77. * @filp: the opened file
  78. * @buffer: where to write the data for the user to read
  79. * @count: the size of the user's buffer
  80. * @ppos: file position offset
  81. **/
  82. static ssize_t i40e_dbg_dump_read(struct file *filp, char __user *buffer,
  83. size_t count, loff_t *ppos)
  84. {
  85. int bytes_not_copied;
  86. int len;
  87. /* is *ppos bigger than the available data? */
  88. if (*ppos >= i40e_dbg_dump_data_len || !i40e_dbg_dump_buf)
  89. return 0;
  90. /* be sure to not read beyond the end of available data */
  91. len = min_t(int, count, (i40e_dbg_dump_data_len - *ppos));
  92. bytes_not_copied = copy_to_user(buffer, &i40e_dbg_dump_buf[*ppos], len);
  93. if (bytes_not_copied < 0)
  94. return bytes_not_copied;
  95. *ppos += len;
  96. return len;
  97. }
  98. /**
  99. * i40e_dbg_prep_dump_buf
  100. * @pf: the pf we're working with
  101. * @buflen: the desired buffer length
  102. *
  103. * Return positive if success, 0 if failed
  104. **/
  105. static int i40e_dbg_prep_dump_buf(struct i40e_pf *pf, int buflen)
  106. {
  107. /* if not already big enough, prep for re alloc */
  108. if (i40e_dbg_dump_buffer_len && i40e_dbg_dump_buffer_len < buflen) {
  109. kfree(i40e_dbg_dump_buf);
  110. i40e_dbg_dump_buffer_len = 0;
  111. i40e_dbg_dump_buf = NULL;
  112. }
  113. /* get a new buffer if needed */
  114. if (!i40e_dbg_dump_buf) {
  115. i40e_dbg_dump_buf = kzalloc(buflen, GFP_KERNEL);
  116. if (i40e_dbg_dump_buf != NULL)
  117. i40e_dbg_dump_buffer_len = buflen;
  118. }
  119. return i40e_dbg_dump_buffer_len;
  120. }
  121. /**
  122. * i40e_dbg_dump_write - trigger a datadump snapshot
  123. * @filp: the opened file
  124. * @buffer: where to find the user's data
  125. * @count: the length of the user's data
  126. * @ppos: file position offset
  127. *
  128. * Any write clears the stats
  129. **/
  130. static ssize_t i40e_dbg_dump_write(struct file *filp,
  131. const char __user *buffer,
  132. size_t count, loff_t *ppos)
  133. {
  134. struct i40e_pf *pf = filp->private_data;
  135. char dump_request_buf[16];
  136. bool seid_found = false;
  137. int bytes_not_copied;
  138. long seid = -1;
  139. int buflen = 0;
  140. int i, ret;
  141. int len;
  142. u8 *p;
  143. /* don't allow partial writes */
  144. if (*ppos != 0)
  145. return 0;
  146. if (count >= sizeof(dump_request_buf))
  147. return -ENOSPC;
  148. bytes_not_copied = copy_from_user(dump_request_buf, buffer, count);
  149. if (bytes_not_copied < 0)
  150. return bytes_not_copied;
  151. if (bytes_not_copied > 0)
  152. count -= bytes_not_copied;
  153. dump_request_buf[count] = '\0';
  154. /* decode the SEID given to be dumped */
  155. ret = kstrtol(dump_request_buf, 0, &seid);
  156. if (ret < 0) {
  157. dev_info(&pf->pdev->dev, "bad seid value '%s'\n",
  158. dump_request_buf);
  159. } else if (seid == 0) {
  160. seid_found = true;
  161. kfree(i40e_dbg_dump_buf);
  162. i40e_dbg_dump_buffer_len = 0;
  163. i40e_dbg_dump_data_len = 0;
  164. i40e_dbg_dump_buf = NULL;
  165. dev_info(&pf->pdev->dev, "debug buffer freed\n");
  166. } else if (seid == pf->pf_seid || seid == 1) {
  167. seid_found = true;
  168. buflen = sizeof(struct i40e_pf);
  169. buflen += (sizeof(struct i40e_aq_desc)
  170. * (pf->hw.aq.num_arq_entries + pf->hw.aq.num_asq_entries));
  171. if (i40e_dbg_prep_dump_buf(pf, buflen)) {
  172. p = i40e_dbg_dump_buf;
  173. len = sizeof(struct i40e_pf);
  174. memcpy(p, pf, len);
  175. p += len;
  176. len = (sizeof(struct i40e_aq_desc)
  177. * pf->hw.aq.num_asq_entries);
  178. memcpy(p, pf->hw.aq.asq.desc, len);
  179. p += len;
  180. len = (sizeof(struct i40e_aq_desc)
  181. * pf->hw.aq.num_arq_entries);
  182. memcpy(p, pf->hw.aq.arq.desc, len);
  183. p += len;
  184. i40e_dbg_dump_data_len = buflen;
  185. dev_info(&pf->pdev->dev,
  186. "PF seid %ld dumped %d bytes\n",
  187. seid, (int)i40e_dbg_dump_data_len);
  188. }
  189. } else if (seid >= I40E_BASE_VSI_SEID) {
  190. struct i40e_vsi *vsi = NULL;
  191. struct i40e_mac_filter *f;
  192. int filter_count = 0;
  193. mutex_lock(&pf->switch_mutex);
  194. vsi = i40e_dbg_find_vsi(pf, seid);
  195. if (!vsi) {
  196. mutex_unlock(&pf->switch_mutex);
  197. goto write_exit;
  198. }
  199. buflen = sizeof(struct i40e_vsi);
  200. buflen += sizeof(struct i40e_q_vector) * vsi->num_q_vectors;
  201. buflen += sizeof(struct i40e_ring) * 2 * vsi->num_queue_pairs;
  202. buflen += sizeof(struct i40e_tx_buffer) * vsi->num_queue_pairs;
  203. buflen += sizeof(struct i40e_rx_buffer) * vsi->num_queue_pairs;
  204. list_for_each_entry(f, &vsi->mac_filter_list, list)
  205. filter_count++;
  206. buflen += sizeof(struct i40e_mac_filter) * filter_count;
  207. if (i40e_dbg_prep_dump_buf(pf, buflen)) {
  208. p = i40e_dbg_dump_buf;
  209. seid_found = true;
  210. len = sizeof(struct i40e_vsi);
  211. memcpy(p, vsi, len);
  212. p += len;
  213. len = (sizeof(struct i40e_q_vector)
  214. * vsi->num_q_vectors);
  215. memcpy(p, vsi->q_vectors, len);
  216. p += len;
  217. len = (sizeof(struct i40e_ring) * vsi->num_queue_pairs);
  218. memcpy(p, vsi->tx_rings, len);
  219. p += len;
  220. memcpy(p, vsi->rx_rings, len);
  221. p += len;
  222. for (i = 0; i < vsi->num_queue_pairs; i++) {
  223. len = sizeof(struct i40e_tx_buffer);
  224. memcpy(p, vsi->tx_rings[i].tx_bi, len);
  225. p += len;
  226. }
  227. for (i = 0; i < vsi->num_queue_pairs; i++) {
  228. len = sizeof(struct i40e_rx_buffer);
  229. memcpy(p, vsi->rx_rings[i].rx_bi, len);
  230. p += len;
  231. }
  232. /* macvlan filter list */
  233. len = sizeof(struct i40e_mac_filter);
  234. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  235. memcpy(p, f, len);
  236. p += len;
  237. }
  238. i40e_dbg_dump_data_len = buflen;
  239. dev_info(&pf->pdev->dev,
  240. "VSI seid %ld dumped %d bytes\n",
  241. seid, (int)i40e_dbg_dump_data_len);
  242. }
  243. mutex_unlock(&pf->switch_mutex);
  244. } else if (seid >= I40E_BASE_VEB_SEID) {
  245. struct i40e_veb *veb = NULL;
  246. mutex_lock(&pf->switch_mutex);
  247. veb = i40e_dbg_find_veb(pf, seid);
  248. if (!veb) {
  249. mutex_unlock(&pf->switch_mutex);
  250. goto write_exit;
  251. }
  252. buflen = sizeof(struct i40e_veb);
  253. if (i40e_dbg_prep_dump_buf(pf, buflen)) {
  254. seid_found = true;
  255. memcpy(i40e_dbg_dump_buf, veb, buflen);
  256. i40e_dbg_dump_data_len = buflen;
  257. dev_info(&pf->pdev->dev,
  258. "VEB seid %ld dumped %d bytes\n",
  259. seid, (int)i40e_dbg_dump_data_len);
  260. }
  261. mutex_unlock(&pf->switch_mutex);
  262. }
  263. write_exit:
  264. if (!seid_found)
  265. dev_info(&pf->pdev->dev, "unknown seid %ld\n", seid);
  266. return count;
  267. }
  268. static const struct file_operations i40e_dbg_dump_fops = {
  269. .owner = THIS_MODULE,
  270. .open = simple_open,
  271. .read = i40e_dbg_dump_read,
  272. .write = i40e_dbg_dump_write,
  273. };
  274. /**************************************************************
  275. * command
  276. * The command entry in debugfs is for giving the driver commands
  277. * to be executed - these may be for changing the internal switch
  278. * setup, adding or removing filters, or other things. Many of
  279. * these will be useful for some forms of unit testing.
  280. **************************************************************/
  281. static char i40e_dbg_command_buf[256] = "hello world";
  282. /**
  283. * i40e_dbg_command_read - read for command datum
  284. * @filp: the opened file
  285. * @buffer: where to write the data for the user to read
  286. * @count: the size of the user's buffer
  287. * @ppos: file position offset
  288. **/
  289. static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
  290. size_t count, loff_t *ppos)
  291. {
  292. struct i40e_pf *pf = filp->private_data;
  293. int bytes_not_copied;
  294. int buf_size = 256;
  295. char *buf;
  296. int len;
  297. /* don't allow partial reads */
  298. if (*ppos != 0)
  299. return 0;
  300. if (count < buf_size)
  301. return -ENOSPC;
  302. buf = kzalloc(buf_size, GFP_KERNEL);
  303. if (!buf)
  304. return -ENOSPC;
  305. len = snprintf(buf, buf_size, "%s: %s\n",
  306. pf->vsi[pf->lan_vsi]->netdev->name,
  307. i40e_dbg_command_buf);
  308. bytes_not_copied = copy_to_user(buffer, buf, len);
  309. kfree(buf);
  310. if (bytes_not_copied < 0)
  311. return bytes_not_copied;
  312. *ppos = len;
  313. return len;
  314. }
  315. /**
  316. * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into pokem datum
  317. * @pf: the i40e_pf created in command write
  318. * @seid: the seid the user put in
  319. **/
  320. static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
  321. {
  322. struct rtnl_link_stats64 *nstat;
  323. struct i40e_mac_filter *f;
  324. struct i40e_vsi *vsi;
  325. int i;
  326. vsi = i40e_dbg_find_vsi(pf, seid);
  327. if (!vsi) {
  328. dev_info(&pf->pdev->dev,
  329. "dump %d: seid not found\n", seid);
  330. return;
  331. }
  332. dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
  333. if (vsi->netdev)
  334. dev_info(&pf->pdev->dev,
  335. " netdev: name = %s\n",
  336. vsi->netdev->name);
  337. if (vsi->active_vlans)
  338. dev_info(&pf->pdev->dev,
  339. " vlgrp: & = %p\n", vsi->active_vlans);
  340. dev_info(&pf->pdev->dev,
  341. " netdev_registered = %i, current_netdev_flags = 0x%04x, state = %li flags = 0x%08lx\n",
  342. vsi->netdev_registered,
  343. vsi->current_netdev_flags, vsi->state, vsi->flags);
  344. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  345. dev_info(&pf->pdev->dev,
  346. " mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n",
  347. f->macaddr, f->vlan, f->is_netdev, f->is_vf,
  348. f->counter);
  349. }
  350. nstat = i40e_get_vsi_stats_struct(vsi);
  351. dev_info(&pf->pdev->dev,
  352. " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
  353. (long unsigned int)nstat->rx_packets,
  354. (long unsigned int)nstat->rx_bytes,
  355. (long unsigned int)nstat->rx_errors,
  356. (long unsigned int)nstat->rx_dropped);
  357. dev_info(&pf->pdev->dev,
  358. " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
  359. (long unsigned int)nstat->tx_packets,
  360. (long unsigned int)nstat->tx_bytes,
  361. (long unsigned int)nstat->tx_errors,
  362. (long unsigned int)nstat->tx_dropped);
  363. dev_info(&pf->pdev->dev,
  364. " net_stats: multicast = %lu, collisions = %lu\n",
  365. (long unsigned int)nstat->multicast,
  366. (long unsigned int)nstat->collisions);
  367. dev_info(&pf->pdev->dev,
  368. " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
  369. (long unsigned int)nstat->rx_length_errors,
  370. (long unsigned int)nstat->rx_over_errors,
  371. (long unsigned int)nstat->rx_crc_errors);
  372. dev_info(&pf->pdev->dev,
  373. " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
  374. (long unsigned int)nstat->rx_frame_errors,
  375. (long unsigned int)nstat->rx_fifo_errors,
  376. (long unsigned int)nstat->rx_missed_errors);
  377. dev_info(&pf->pdev->dev,
  378. " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
  379. (long unsigned int)nstat->tx_aborted_errors,
  380. (long unsigned int)nstat->tx_carrier_errors,
  381. (long unsigned int)nstat->tx_fifo_errors);
  382. dev_info(&pf->pdev->dev,
  383. " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
  384. (long unsigned int)nstat->tx_heartbeat_errors,
  385. (long unsigned int)nstat->tx_window_errors);
  386. dev_info(&pf->pdev->dev,
  387. " net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
  388. (long unsigned int)nstat->rx_compressed,
  389. (long unsigned int)nstat->tx_compressed);
  390. dev_info(&pf->pdev->dev,
  391. " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
  392. (long unsigned int)vsi->net_stats_offsets.rx_packets,
  393. (long unsigned int)vsi->net_stats_offsets.rx_bytes,
  394. (long unsigned int)vsi->net_stats_offsets.rx_errors,
  395. (long unsigned int)vsi->net_stats_offsets.rx_dropped);
  396. dev_info(&pf->pdev->dev,
  397. " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
  398. (long unsigned int)vsi->net_stats_offsets.tx_packets,
  399. (long unsigned int)vsi->net_stats_offsets.tx_bytes,
  400. (long unsigned int)vsi->net_stats_offsets.tx_errors,
  401. (long unsigned int)vsi->net_stats_offsets.tx_dropped);
  402. dev_info(&pf->pdev->dev,
  403. " net_stats_offsets: multicast = %lu, collisions = %lu\n",
  404. (long unsigned int)vsi->net_stats_offsets.multicast,
  405. (long unsigned int)vsi->net_stats_offsets.collisions);
  406. dev_info(&pf->pdev->dev,
  407. " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
  408. (long unsigned int)vsi->net_stats_offsets.rx_length_errors,
  409. (long unsigned int)vsi->net_stats_offsets.rx_over_errors,
  410. (long unsigned int)vsi->net_stats_offsets.rx_crc_errors);
  411. dev_info(&pf->pdev->dev,
  412. " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
  413. (long unsigned int)vsi->net_stats_offsets.rx_frame_errors,
  414. (long unsigned int)vsi->net_stats_offsets.rx_fifo_errors,
  415. (long unsigned int)vsi->net_stats_offsets.rx_missed_errors);
  416. dev_info(&pf->pdev->dev,
  417. " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
  418. (long unsigned int)vsi->net_stats_offsets.tx_aborted_errors,
  419. (long unsigned int)vsi->net_stats_offsets.tx_carrier_errors,
  420. (long unsigned int)vsi->net_stats_offsets.tx_fifo_errors);
  421. dev_info(&pf->pdev->dev,
  422. " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
  423. (long unsigned int)vsi->net_stats_offsets.tx_heartbeat_errors,
  424. (long unsigned int)vsi->net_stats_offsets.tx_window_errors);
  425. dev_info(&pf->pdev->dev,
  426. " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
  427. (long unsigned int)vsi->net_stats_offsets.rx_compressed,
  428. (long unsigned int)vsi->net_stats_offsets.tx_compressed);
  429. dev_info(&pf->pdev->dev,
  430. " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
  431. vsi->tx_restart, vsi->tx_busy,
  432. vsi->rx_buf_failed, vsi->rx_page_failed);
  433. if (vsi->rx_rings) {
  434. for (i = 0; i < vsi->num_queue_pairs; i++) {
  435. dev_info(&pf->pdev->dev,
  436. " rx_rings[%i]: desc = %p\n",
  437. i, vsi->rx_rings[i].desc);
  438. dev_info(&pf->pdev->dev,
  439. " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
  440. i, vsi->rx_rings[i].dev,
  441. vsi->rx_rings[i].netdev,
  442. vsi->rx_rings[i].rx_bi);
  443. dev_info(&pf->pdev->dev,
  444. " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
  445. i, vsi->rx_rings[i].state,
  446. vsi->rx_rings[i].queue_index,
  447. vsi->rx_rings[i].reg_idx);
  448. dev_info(&pf->pdev->dev,
  449. " rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n",
  450. i, vsi->rx_rings[i].rx_hdr_len,
  451. vsi->rx_rings[i].rx_buf_len,
  452. vsi->rx_rings[i].dtype);
  453. dev_info(&pf->pdev->dev,
  454. " rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
  455. i, vsi->rx_rings[i].hsplit,
  456. vsi->rx_rings[i].next_to_use,
  457. vsi->rx_rings[i].next_to_clean,
  458. vsi->rx_rings[i].ring_active);
  459. dev_info(&pf->pdev->dev,
  460. " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
  461. i, vsi->rx_rings[i].stats.packets,
  462. vsi->rx_rings[i].stats.bytes,
  463. vsi->rx_rings[i].rx_stats.non_eop_descs);
  464. dev_info(&pf->pdev->dev,
  465. " rx_rings[%i]: rx_stats: alloc_rx_page_failed = %lld, alloc_rx_buff_failed = %lld\n",
  466. i,
  467. vsi->rx_rings[i].rx_stats.alloc_rx_page_failed,
  468. vsi->rx_rings[i].rx_stats.alloc_rx_buff_failed);
  469. dev_info(&pf->pdev->dev,
  470. " rx_rings[%i]: size = %i, dma = 0x%08lx\n",
  471. i, vsi->rx_rings[i].size,
  472. (long unsigned int)vsi->rx_rings[i].dma);
  473. dev_info(&pf->pdev->dev,
  474. " rx_rings[%i]: vsi = %p, q_vector = %p\n",
  475. i, vsi->rx_rings[i].vsi,
  476. vsi->rx_rings[i].q_vector);
  477. }
  478. }
  479. if (vsi->tx_rings) {
  480. for (i = 0; i < vsi->num_queue_pairs; i++) {
  481. dev_info(&pf->pdev->dev,
  482. " tx_rings[%i]: desc = %p\n",
  483. i, vsi->tx_rings[i].desc);
  484. dev_info(&pf->pdev->dev,
  485. " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
  486. i, vsi->tx_rings[i].dev,
  487. vsi->tx_rings[i].netdev,
  488. vsi->tx_rings[i].tx_bi);
  489. dev_info(&pf->pdev->dev,
  490. " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
  491. i, vsi->tx_rings[i].state,
  492. vsi->tx_rings[i].queue_index,
  493. vsi->tx_rings[i].reg_idx);
  494. dev_info(&pf->pdev->dev,
  495. " tx_rings[%i]: dtype = %d\n",
  496. i, vsi->tx_rings[i].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, vsi->tx_rings[i].hsplit,
  500. vsi->tx_rings[i].next_to_use,
  501. vsi->tx_rings[i].next_to_clean,
  502. vsi->tx_rings[i].ring_active);
  503. dev_info(&pf->pdev->dev,
  504. " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
  505. i, vsi->tx_rings[i].stats.packets,
  506. vsi->tx_rings[i].stats.bytes,
  507. vsi->tx_rings[i].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. vsi->tx_rings[i].tx_stats.tx_busy,
  512. vsi->tx_rings[i].tx_stats.tx_done_old);
  513. dev_info(&pf->pdev->dev,
  514. " tx_rings[%i]: size = %i, dma = 0x%08lx\n",
  515. i, vsi->tx_rings[i].size,
  516. (long unsigned int)vsi->tx_rings[i].dma);
  517. dev_info(&pf->pdev->dev,
  518. " tx_rings[%i]: vsi = %p, q_vector = %p\n",
  519. i, vsi->tx_rings[i].vsi,
  520. vsi->tx_rings[i].q_vector);
  521. dev_info(&pf->pdev->dev,
  522. " tx_rings[%i]: DCB tc = %d\n",
  523. i, vsi->tx_rings[i].dcb_tc);
  524. }
  525. }
  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. int bytes_not_copied;
  951. struct i40e_vsi *vsi;
  952. u8 *print_buf_start;
  953. u8 *print_buf;
  954. char *cmd_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. print_buf_start = kzalloc(I40E_MAX_DEBUG_OUT_BUFFER, GFP_KERNEL);
  971. if (!print_buf_start)
  972. goto command_write_done;
  973. print_buf = print_buf_start;
  974. if (strncmp(cmd_buf, "add vsi", 7) == 0) {
  975. vsi_seid = -1;
  976. cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
  977. if (cnt == 0) {
  978. /* default to PF VSI */
  979. vsi_seid = pf->vsi[pf->lan_vsi]->seid;
  980. } else if (vsi_seid < 0) {
  981. dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
  982. vsi_seid);
  983. goto command_write_done;
  984. }
  985. vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
  986. if (vsi)
  987. dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
  988. vsi->seid, vsi->uplink_seid);
  989. else
  990. dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
  991. } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
  992. sscanf(&cmd_buf[7], "%i", &vsi_seid);
  993. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  994. if (!vsi) {
  995. dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
  996. vsi_seid);
  997. goto command_write_done;
  998. }
  999. dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
  1000. i40e_vsi_release(vsi);
  1001. } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
  1002. struct i40e_veb *veb;
  1003. int uplink_seid, i;
  1004. cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
  1005. if (cnt != 2) {
  1006. dev_info(&pf->pdev->dev,
  1007. "add relay: bad command string, cnt=%d\n",
  1008. cnt);
  1009. goto command_write_done;
  1010. } else if (uplink_seid < 0) {
  1011. dev_info(&pf->pdev->dev,
  1012. "add relay %d: bad uplink seid\n",
  1013. uplink_seid);
  1014. goto command_write_done;
  1015. }
  1016. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1017. if (!vsi) {
  1018. dev_info(&pf->pdev->dev,
  1019. "add relay: vsi VSI %d not found\n", vsi_seid);
  1020. goto command_write_done;
  1021. }
  1022. for (i = 0; i < I40E_MAX_VEB; i++)
  1023. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
  1024. break;
  1025. if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
  1026. uplink_seid != pf->mac_seid) {
  1027. dev_info(&pf->pdev->dev,
  1028. "add relay: relay uplink %d not found\n",
  1029. uplink_seid);
  1030. goto command_write_done;
  1031. }
  1032. veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
  1033. vsi->tc_config.enabled_tc);
  1034. if (veb)
  1035. dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
  1036. else
  1037. dev_info(&pf->pdev->dev, "add relay failed\n");
  1038. } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
  1039. int i;
  1040. cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
  1041. if (cnt != 1) {
  1042. dev_info(&pf->pdev->dev,
  1043. "del relay: bad command string, cnt=%d\n",
  1044. cnt);
  1045. goto command_write_done;
  1046. } else if (veb_seid < 0) {
  1047. dev_info(&pf->pdev->dev,
  1048. "del relay %d: bad relay seid\n", veb_seid);
  1049. goto command_write_done;
  1050. }
  1051. /* find the veb */
  1052. for (i = 0; i < I40E_MAX_VEB; i++)
  1053. if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
  1054. break;
  1055. if (i >= I40E_MAX_VEB) {
  1056. dev_info(&pf->pdev->dev,
  1057. "del relay: relay %d not found\n", veb_seid);
  1058. goto command_write_done;
  1059. }
  1060. dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
  1061. i40e_veb_release(pf->veb[i]);
  1062. } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
  1063. u8 ma[6];
  1064. int vlan = 0;
  1065. struct i40e_mac_filter *f;
  1066. int ret;
  1067. cnt = sscanf(&cmd_buf[11],
  1068. "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
  1069. &vsi_seid,
  1070. &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
  1071. &vlan);
  1072. if (cnt == 7) {
  1073. vlan = 0;
  1074. } else if (cnt != 8) {
  1075. dev_info(&pf->pdev->dev,
  1076. "add macaddr: bad command string, cnt=%d\n",
  1077. cnt);
  1078. goto command_write_done;
  1079. }
  1080. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1081. if (!vsi) {
  1082. dev_info(&pf->pdev->dev,
  1083. "add macaddr: VSI %d not found\n", vsi_seid);
  1084. goto command_write_done;
  1085. }
  1086. f = i40e_add_filter(vsi, ma, vlan, false, false);
  1087. ret = i40e_sync_vsi_filters(vsi);
  1088. if (f && !ret)
  1089. dev_info(&pf->pdev->dev,
  1090. "add macaddr: %pM vlan=%d added to VSI %d\n",
  1091. ma, vlan, vsi_seid);
  1092. else
  1093. dev_info(&pf->pdev->dev,
  1094. "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
  1095. ma, vlan, vsi_seid, f, ret);
  1096. } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
  1097. u8 ma[6];
  1098. int vlan = 0;
  1099. int ret;
  1100. cnt = sscanf(&cmd_buf[11],
  1101. "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
  1102. &vsi_seid,
  1103. &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
  1104. &vlan);
  1105. if (cnt == 7) {
  1106. vlan = 0;
  1107. } else if (cnt != 8) {
  1108. dev_info(&pf->pdev->dev,
  1109. "del macaddr: bad command string, cnt=%d\n",
  1110. cnt);
  1111. goto command_write_done;
  1112. }
  1113. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1114. if (!vsi) {
  1115. dev_info(&pf->pdev->dev,
  1116. "del macaddr: VSI %d not found\n", vsi_seid);
  1117. goto command_write_done;
  1118. }
  1119. i40e_del_filter(vsi, ma, vlan, false, false);
  1120. ret = i40e_sync_vsi_filters(vsi);
  1121. if (!ret)
  1122. dev_info(&pf->pdev->dev,
  1123. "del macaddr: %pM vlan=%d removed from VSI %d\n",
  1124. ma, vlan, vsi_seid);
  1125. else
  1126. dev_info(&pf->pdev->dev,
  1127. "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
  1128. ma, vlan, vsi_seid, ret);
  1129. } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
  1130. int v;
  1131. u16 vid;
  1132. i40e_status ret;
  1133. cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
  1134. if (cnt != 2) {
  1135. dev_info(&pf->pdev->dev,
  1136. "add pvid: bad command string, cnt=%d\n", cnt);
  1137. goto command_write_done;
  1138. }
  1139. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1140. if (!vsi) {
  1141. dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
  1142. vsi_seid);
  1143. goto command_write_done;
  1144. }
  1145. vid = (unsigned)v;
  1146. ret = i40e_vsi_add_pvid(vsi, vid);
  1147. if (!ret)
  1148. dev_info(&pf->pdev->dev,
  1149. "add pvid: %d added to VSI %d\n",
  1150. vid, vsi_seid);
  1151. else
  1152. dev_info(&pf->pdev->dev,
  1153. "add pvid: %d to VSI %d failed, ret=%d\n",
  1154. vid, vsi_seid, ret);
  1155. } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
  1156. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1157. if (cnt != 1) {
  1158. dev_info(&pf->pdev->dev,
  1159. "del pvid: bad command string, cnt=%d\n",
  1160. cnt);
  1161. goto command_write_done;
  1162. }
  1163. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1164. if (!vsi) {
  1165. dev_info(&pf->pdev->dev,
  1166. "del pvid: VSI %d not found\n", vsi_seid);
  1167. goto command_write_done;
  1168. }
  1169. i40e_vsi_remove_pvid(vsi);
  1170. dev_info(&pf->pdev->dev,
  1171. "del pvid: removed from VSI %d\n", vsi_seid);
  1172. } else if (strncmp(cmd_buf, "dump", 4) == 0) {
  1173. if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
  1174. i40e_fetch_switch_configuration(pf, true);
  1175. } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
  1176. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1177. if (cnt > 0)
  1178. i40e_dbg_dump_vsi_seid(pf, vsi_seid);
  1179. else
  1180. i40e_dbg_dump_vsi_no_seid(pf);
  1181. } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
  1182. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1183. if (cnt > 0)
  1184. i40e_dbg_dump_veb_seid(pf, vsi_seid);
  1185. else
  1186. i40e_dbg_dump_veb_all(pf);
  1187. } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
  1188. int ring_id, desc_n;
  1189. if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
  1190. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  1191. &vsi_seid, &ring_id, &desc_n);
  1192. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  1193. desc_n, pf, true);
  1194. } else if (strncmp(&cmd_buf[10], "tx", 2)
  1195. == 0) {
  1196. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  1197. &vsi_seid, &ring_id, &desc_n);
  1198. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  1199. desc_n, pf, false);
  1200. } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
  1201. i40e_dbg_dump_aq_desc(pf);
  1202. } else {
  1203. dev_info(&pf->pdev->dev,
  1204. "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  1205. dev_info(&pf->pdev->dev,
  1206. "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  1207. dev_info(&pf->pdev->dev, "dump desc aq\n");
  1208. }
  1209. } else if (strncmp(&cmd_buf[5], "stats", 5) == 0) {
  1210. dev_info(&pf->pdev->dev, "pf stats:\n");
  1211. i40e_dbg_dump_stats(pf, &pf->stats);
  1212. dev_info(&pf->pdev->dev, "pf stats_offsets:\n");
  1213. i40e_dbg_dump_stats(pf, &pf->stats_offsets);
  1214. } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
  1215. dev_info(&pf->pdev->dev,
  1216. "core reset count: %d\n", pf->corer_count);
  1217. dev_info(&pf->pdev->dev,
  1218. "global reset count: %d\n", pf->globr_count);
  1219. dev_info(&pf->pdev->dev,
  1220. "emp reset count: %d\n", pf->empr_count);
  1221. dev_info(&pf->pdev->dev,
  1222. "pf reset count: %d\n", pf->pfr_count);
  1223. } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
  1224. struct i40e_aqc_query_port_ets_config_resp *bw_data;
  1225. struct i40e_dcbx_config *cfg =
  1226. &pf->hw.local_dcbx_config;
  1227. struct i40e_dcbx_config *r_cfg =
  1228. &pf->hw.remote_dcbx_config;
  1229. int i, ret;
  1230. bw_data = kzalloc(sizeof(
  1231. struct i40e_aqc_query_port_ets_config_resp),
  1232. GFP_KERNEL);
  1233. if (!bw_data) {
  1234. ret = -ENOMEM;
  1235. goto command_write_done;
  1236. }
  1237. ret = i40e_aq_query_port_ets_config(&pf->hw,
  1238. pf->mac_seid,
  1239. bw_data, NULL);
  1240. if (ret) {
  1241. dev_info(&pf->pdev->dev,
  1242. "Query Port ETS Config AQ command failed =0x%x\n",
  1243. pf->hw.aq.asq_last_status);
  1244. kfree(bw_data);
  1245. bw_data = NULL;
  1246. goto command_write_done;
  1247. }
  1248. dev_info(&pf->pdev->dev,
  1249. "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
  1250. bw_data->tc_valid_bits,
  1251. bw_data->tc_strict_priority_bits,
  1252. le16_to_cpu(bw_data->tc_bw_max[0]),
  1253. le16_to_cpu(bw_data->tc_bw_max[1]));
  1254. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1255. dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
  1256. bw_data->tc_bw_share_credits[i],
  1257. le16_to_cpu(bw_data->tc_bw_limits[i]));
  1258. }
  1259. kfree(bw_data);
  1260. bw_data = NULL;
  1261. dev_info(&pf->pdev->dev,
  1262. "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  1263. cfg->etscfg.willing, cfg->etscfg.cbs,
  1264. cfg->etscfg.maxtcs);
  1265. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1266. dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1267. i, cfg->etscfg.prioritytable[i],
  1268. cfg->etscfg.tcbwtable[i],
  1269. cfg->etscfg.tsatable[i]);
  1270. }
  1271. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1272. dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1273. i, cfg->etsrec.prioritytable[i],
  1274. cfg->etsrec.tcbwtable[i],
  1275. cfg->etsrec.tsatable[i]);
  1276. }
  1277. dev_info(&pf->pdev->dev,
  1278. "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  1279. cfg->pfc.willing, cfg->pfc.mbc,
  1280. cfg->pfc.pfccap, cfg->pfc.pfcenable);
  1281. dev_info(&pf->pdev->dev,
  1282. "port app_table: num_apps=%d\n", cfg->numapps);
  1283. for (i = 0; i < cfg->numapps; i++) {
  1284. dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1285. i, cfg->app[i].priority,
  1286. cfg->app[i].selector,
  1287. cfg->app[i].protocolid);
  1288. }
  1289. /* Peer TLV DCBX data */
  1290. dev_info(&pf->pdev->dev,
  1291. "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  1292. r_cfg->etscfg.willing,
  1293. r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
  1294. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1295. dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1296. i, r_cfg->etscfg.prioritytable[i],
  1297. r_cfg->etscfg.tcbwtable[i],
  1298. r_cfg->etscfg.tsatable[i]);
  1299. }
  1300. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1301. dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1302. i, r_cfg->etsrec.prioritytable[i],
  1303. r_cfg->etsrec.tcbwtable[i],
  1304. r_cfg->etsrec.tsatable[i]);
  1305. }
  1306. dev_info(&pf->pdev->dev,
  1307. "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  1308. r_cfg->pfc.willing,
  1309. r_cfg->pfc.mbc,
  1310. r_cfg->pfc.pfccap,
  1311. r_cfg->pfc.pfcenable);
  1312. dev_info(&pf->pdev->dev,
  1313. "remote port app_table: num_apps=%d\n",
  1314. r_cfg->numapps);
  1315. for (i = 0; i < r_cfg->numapps; i++) {
  1316. dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1317. i, r_cfg->app[i].priority,
  1318. r_cfg->app[i].selector,
  1319. r_cfg->app[i].protocolid);
  1320. }
  1321. } else {
  1322. dev_info(&pf->pdev->dev,
  1323. "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
  1324. dev_info(&pf->pdev->dev, "dump switch, dump vsi [seid] or\n");
  1325. dev_info(&pf->pdev->dev, "dump stats\n");
  1326. dev_info(&pf->pdev->dev, "dump reset stats\n");
  1327. dev_info(&pf->pdev->dev, "dump port\n");
  1328. dev_info(&pf->pdev->dev,
  1329. "dump debug fwdata <cluster_id> <table_id> <index>\n");
  1330. }
  1331. } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
  1332. u32 level;
  1333. cnt = sscanf(&cmd_buf[10], "%i", &level);
  1334. if (cnt) {
  1335. if (I40E_DEBUG_USER & level) {
  1336. pf->hw.debug_mask = level;
  1337. dev_info(&pf->pdev->dev,
  1338. "set hw.debug_mask = 0x%08x\n",
  1339. pf->hw.debug_mask);
  1340. }
  1341. pf->msg_enable = level;
  1342. dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
  1343. pf->msg_enable);
  1344. } else {
  1345. dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
  1346. pf->msg_enable);
  1347. }
  1348. } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
  1349. dev_info(&pf->pdev->dev, "forcing PFR\n");
  1350. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  1351. } else if (strncmp(cmd_buf, "corer", 5) == 0) {
  1352. dev_info(&pf->pdev->dev, "forcing CoreR\n");
  1353. i40e_do_reset(pf, (1 << __I40E_CORE_RESET_REQUESTED));
  1354. } else if (strncmp(cmd_buf, "globr", 5) == 0) {
  1355. dev_info(&pf->pdev->dev, "forcing GlobR\n");
  1356. i40e_do_reset(pf, (1 << __I40E_GLOBAL_RESET_REQUESTED));
  1357. } else if (strncmp(cmd_buf, "read", 4) == 0) {
  1358. u32 address;
  1359. u32 value;
  1360. cnt = sscanf(&cmd_buf[4], "%x", &address);
  1361. if (cnt != 1) {
  1362. dev_info(&pf->pdev->dev, "read <reg>\n");
  1363. goto command_write_done;
  1364. }
  1365. /* check the range on address */
  1366. if (address >= I40E_MAX_REGISTER) {
  1367. dev_info(&pf->pdev->dev, "read reg address 0x%08x too large\n",
  1368. address);
  1369. goto command_write_done;
  1370. }
  1371. value = rd32(&pf->hw, address);
  1372. dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
  1373. address, value);
  1374. } else if (strncmp(cmd_buf, "write", 5) == 0) {
  1375. u32 address, value;
  1376. cnt = sscanf(&cmd_buf[5], "%x %x", &address, &value);
  1377. if (cnt != 2) {
  1378. dev_info(&pf->pdev->dev, "write <reg> <value>\n");
  1379. goto command_write_done;
  1380. }
  1381. /* check the range on address */
  1382. if (address >= I40E_MAX_REGISTER) {
  1383. dev_info(&pf->pdev->dev, "write reg address 0x%08x too large\n",
  1384. address);
  1385. goto command_write_done;
  1386. }
  1387. wr32(&pf->hw, address, value);
  1388. value = rd32(&pf->hw, address);
  1389. dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
  1390. address, value);
  1391. } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
  1392. if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
  1393. cnt = sscanf(&cmd_buf[15], "%d", &vsi_seid);
  1394. if (cnt == 0) {
  1395. int i;
  1396. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  1397. i40e_vsi_reset_stats(pf->vsi[i]);
  1398. dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
  1399. } else if (cnt == 1) {
  1400. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1401. if (!vsi) {
  1402. dev_info(&pf->pdev->dev,
  1403. "clear_stats vsi: bad vsi %d\n",
  1404. vsi_seid);
  1405. goto command_write_done;
  1406. }
  1407. i40e_vsi_reset_stats(vsi);
  1408. dev_info(&pf->pdev->dev,
  1409. "vsi clear stats called for vsi %d\n",
  1410. vsi_seid);
  1411. } else {
  1412. dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
  1413. }
  1414. } else if (strncmp(&cmd_buf[12], "pf", 2) == 0) {
  1415. i40e_pf_reset_stats(pf);
  1416. dev_info(&pf->pdev->dev, "pf clear stats called\n");
  1417. } else {
  1418. dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats pf\n");
  1419. }
  1420. } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
  1421. (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
  1422. struct i40e_fdir_data fd_data;
  1423. int ret;
  1424. u16 packet_len, i, j = 0;
  1425. char *asc_packet;
  1426. bool add = false;
  1427. asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
  1428. GFP_KERNEL);
  1429. if (!asc_packet)
  1430. goto command_write_done;
  1431. fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
  1432. GFP_KERNEL);
  1433. if (!fd_data.raw_packet) {
  1434. kfree(asc_packet);
  1435. asc_packet = NULL;
  1436. goto command_write_done;
  1437. }
  1438. if (strncmp(cmd_buf, "add", 3) == 0)
  1439. add = true;
  1440. cnt = sscanf(&cmd_buf[13],
  1441. "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %512s",
  1442. &fd_data.q_index,
  1443. &fd_data.flex_off, &fd_data.pctype,
  1444. &fd_data.dest_vsi, &fd_data.dest_ctl,
  1445. &fd_data.fd_status, &fd_data.cnt_index,
  1446. &fd_data.fd_id, &packet_len, asc_packet);
  1447. if (cnt != 10) {
  1448. dev_info(&pf->pdev->dev,
  1449. "program fd_filter: bad command string, cnt=%d\n",
  1450. cnt);
  1451. kfree(asc_packet);
  1452. asc_packet = NULL;
  1453. kfree(fd_data.raw_packet);
  1454. goto command_write_done;
  1455. }
  1456. /* fix packet length if user entered 0 */
  1457. if (packet_len == 0)
  1458. packet_len = I40E_FDIR_MAX_RAW_PACKET_LOOKUP;
  1459. /* make sure to check the max as well */
  1460. packet_len = min_t(u16,
  1461. packet_len, I40E_FDIR_MAX_RAW_PACKET_LOOKUP);
  1462. dev_info(&pf->pdev->dev, "FD raw packet:\n");
  1463. for (i = 0; i < packet_len; i++) {
  1464. sscanf(&asc_packet[j], "%2hhx ",
  1465. &fd_data.raw_packet[i]);
  1466. j += 3;
  1467. snprintf(print_buf, 3, "%02x ", fd_data.raw_packet[i]);
  1468. print_buf += 3;
  1469. if ((i % 16) == 15) {
  1470. snprintf(print_buf, 1, "\n");
  1471. print_buf++;
  1472. }
  1473. }
  1474. dev_info(&pf->pdev->dev, "%s\n", print_buf_start);
  1475. ret = i40e_program_fdir_filter(&fd_data, pf, add);
  1476. if (!ret) {
  1477. dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
  1478. } else {
  1479. dev_info(&pf->pdev->dev,
  1480. "Filter command send failed %d\n", ret);
  1481. }
  1482. kfree(fd_data.raw_packet);
  1483. fd_data.raw_packet = NULL;
  1484. kfree(asc_packet);
  1485. asc_packet = NULL;
  1486. } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
  1487. if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
  1488. int ret;
  1489. ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
  1490. if (ret) {
  1491. dev_info(&pf->pdev->dev,
  1492. "Stop LLDP AQ command failed =0x%x\n",
  1493. pf->hw.aq.asq_last_status);
  1494. goto command_write_done;
  1495. }
  1496. } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
  1497. int ret;
  1498. ret = i40e_aq_start_lldp(&pf->hw, NULL);
  1499. if (ret) {
  1500. dev_info(&pf->pdev->dev,
  1501. "Start LLDP AQ command failed =0x%x\n",
  1502. pf->hw.aq.asq_last_status);
  1503. goto command_write_done;
  1504. }
  1505. } else if (strncmp(&cmd_buf[5],
  1506. "get local", 9) == 0) {
  1507. int ret, i;
  1508. u8 *buff;
  1509. u16 llen, rlen;
  1510. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1511. if (!buff)
  1512. goto command_write_done;
  1513. ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
  1514. I40E_AQ_LLDP_MIB_LOCAL,
  1515. buff, I40E_LLDPDU_SIZE,
  1516. &llen, &rlen, NULL);
  1517. if (ret) {
  1518. dev_info(&pf->pdev->dev,
  1519. "Get LLDP MIB (local) AQ command failed =0x%x\n",
  1520. pf->hw.aq.asq_last_status);
  1521. kfree(buff);
  1522. buff = NULL;
  1523. goto command_write_done;
  1524. }
  1525. dev_info(&pf->pdev->dev,
  1526. "Get LLDP MIB (local) AQ buffer written back:\n");
  1527. for (i = 0; i < I40E_LLDPDU_SIZE; i++) {
  1528. snprintf(print_buf, 3, "%02x ", buff[i]);
  1529. print_buf += 3;
  1530. if ((i % 16) == 15) {
  1531. snprintf(print_buf, 1, "\n");
  1532. print_buf++;
  1533. }
  1534. }
  1535. dev_info(&pf->pdev->dev, "%s\n", print_buf_start);
  1536. kfree(buff);
  1537. buff = NULL;
  1538. } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
  1539. int ret, i;
  1540. u8 *buff;
  1541. u16 llen, rlen;
  1542. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1543. if (!buff)
  1544. goto command_write_done;
  1545. ret = i40e_aq_get_lldp_mib(&pf->hw,
  1546. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  1547. I40E_AQ_LLDP_MIB_LOCAL,
  1548. buff, I40E_LLDPDU_SIZE,
  1549. &llen, &rlen, NULL);
  1550. if (ret) {
  1551. dev_info(&pf->pdev->dev,
  1552. "Get LLDP MIB (remote) AQ command failed =0x%x\n",
  1553. pf->hw.aq.asq_last_status);
  1554. kfree(buff);
  1555. buff = NULL;
  1556. goto command_write_done;
  1557. }
  1558. dev_info(&pf->pdev->dev,
  1559. "Get LLDP MIB (remote) AQ buffer written back:\n");
  1560. for (i = 0; i < I40E_LLDPDU_SIZE; i++) {
  1561. snprintf(print_buf, 3, "%02x ", buff[i]);
  1562. print_buf += 3;
  1563. if ((i % 16) == 15) {
  1564. snprintf(print_buf, 1, "\n");
  1565. print_buf++;
  1566. }
  1567. }
  1568. dev_info(&pf->pdev->dev, "%s\n", print_buf_start);
  1569. kfree(buff);
  1570. buff = NULL;
  1571. } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
  1572. int ret;
  1573. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1574. true, NULL);
  1575. if (ret) {
  1576. dev_info(&pf->pdev->dev,
  1577. "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
  1578. pf->hw.aq.asq_last_status);
  1579. goto command_write_done;
  1580. }
  1581. } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
  1582. int ret;
  1583. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1584. false, NULL);
  1585. if (ret) {
  1586. dev_info(&pf->pdev->dev,
  1587. "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
  1588. pf->hw.aq.asq_last_status);
  1589. goto command_write_done;
  1590. }
  1591. }
  1592. } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
  1593. u16 buffer_len, i, bytes;
  1594. u16 module;
  1595. u32 offset;
  1596. u16 *buff;
  1597. int ret;
  1598. cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
  1599. &module, &offset, &buffer_len);
  1600. if (cnt == 0) {
  1601. module = 0;
  1602. offset = 0;
  1603. buffer_len = 0;
  1604. } else if (cnt == 1) {
  1605. offset = 0;
  1606. buffer_len = 0;
  1607. } else if (cnt == 2) {
  1608. buffer_len = 0;
  1609. } else if (cnt > 3) {
  1610. dev_info(&pf->pdev->dev,
  1611. "nvm read: bad command string, cnt=%d\n", cnt);
  1612. goto command_write_done;
  1613. }
  1614. /* Read at least 512 words */
  1615. if (buffer_len == 0)
  1616. buffer_len = 512;
  1617. bytes = 2 * buffer_len;
  1618. buff = kzalloc(bytes, GFP_KERNEL);
  1619. if (!buff)
  1620. goto command_write_done;
  1621. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  1622. if (ret) {
  1623. dev_info(&pf->pdev->dev,
  1624. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1625. ret, pf->hw.aq.asq_last_status);
  1626. kfree(buff);
  1627. goto command_write_done;
  1628. }
  1629. ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
  1630. bytes, (u8 *)buff, true, NULL);
  1631. i40e_release_nvm(&pf->hw);
  1632. if (ret) {
  1633. dev_info(&pf->pdev->dev,
  1634. "Read NVM AQ failed err=%d status=0x%x\n",
  1635. ret, pf->hw.aq.asq_last_status);
  1636. } else {
  1637. dev_info(&pf->pdev->dev,
  1638. "Read NVM module=0x%x offset=0x%x words=%d\n",
  1639. module, offset, buffer_len);
  1640. for (i = 0; i < buffer_len; i++) {
  1641. if ((i % 16) == 0) {
  1642. snprintf(print_buf, 11, "\n0x%08x: ",
  1643. offset + i);
  1644. print_buf += 11;
  1645. }
  1646. snprintf(print_buf, 5, "%04x ", buff[i]);
  1647. print_buf += 5;
  1648. }
  1649. dev_info(&pf->pdev->dev, "%s\n", print_buf_start);
  1650. }
  1651. kfree(buff);
  1652. buff = NULL;
  1653. } else {
  1654. dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
  1655. dev_info(&pf->pdev->dev, "available commands\n");
  1656. dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
  1657. dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
  1658. dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
  1659. dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
  1660. dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
  1661. dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
  1662. dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
  1663. dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
  1664. dev_info(&pf->pdev->dev, " dump switch\n");
  1665. dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
  1666. dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  1667. dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  1668. dev_info(&pf->pdev->dev, " dump desc aq\n");
  1669. dev_info(&pf->pdev->dev, " dump stats\n");
  1670. dev_info(&pf->pdev->dev, " dump reset stats\n");
  1671. dev_info(&pf->pdev->dev, " msg_enable [level]\n");
  1672. dev_info(&pf->pdev->dev, " read <reg>\n");
  1673. dev_info(&pf->pdev->dev, " write <reg> <value>\n");
  1674. dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
  1675. dev_info(&pf->pdev->dev, " clear_stats pf\n");
  1676. dev_info(&pf->pdev->dev, " pfr\n");
  1677. dev_info(&pf->pdev->dev, " corer\n");
  1678. dev_info(&pf->pdev->dev, " globr\n");
  1679. 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");
  1680. 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");
  1681. dev_info(&pf->pdev->dev, " lldp start\n");
  1682. dev_info(&pf->pdev->dev, " lldp stop\n");
  1683. dev_info(&pf->pdev->dev, " lldp get local\n");
  1684. dev_info(&pf->pdev->dev, " lldp get remote\n");
  1685. dev_info(&pf->pdev->dev, " lldp event on\n");
  1686. dev_info(&pf->pdev->dev, " lldp event off\n");
  1687. dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
  1688. }
  1689. command_write_done:
  1690. kfree(cmd_buf);
  1691. cmd_buf = NULL;
  1692. kfree(print_buf_start);
  1693. print_buf = NULL;
  1694. print_buf_start = NULL;
  1695. return count;
  1696. }
  1697. static const struct file_operations i40e_dbg_command_fops = {
  1698. .owner = THIS_MODULE,
  1699. .open = simple_open,
  1700. .read = i40e_dbg_command_read,
  1701. .write = i40e_dbg_command_write,
  1702. };
  1703. /**************************************************************
  1704. * netdev_ops
  1705. * The netdev_ops entry in debugfs is for giving the driver commands
  1706. * to be executed from the netdev operations.
  1707. **************************************************************/
  1708. static char i40e_dbg_netdev_ops_buf[256] = "hello world";
  1709. /**
  1710. * i40e_dbg_netdev_ops - read for netdev_ops datum
  1711. * @filp: the opened file
  1712. * @buffer: where to write the data for the user to read
  1713. * @count: the size of the user's buffer
  1714. * @ppos: file position offset
  1715. **/
  1716. static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
  1717. size_t count, loff_t *ppos)
  1718. {
  1719. struct i40e_pf *pf = filp->private_data;
  1720. int bytes_not_copied;
  1721. int buf_size = 256;
  1722. char *buf;
  1723. int len;
  1724. /* don't allow partal reads */
  1725. if (*ppos != 0)
  1726. return 0;
  1727. if (count < buf_size)
  1728. return -ENOSPC;
  1729. buf = kzalloc(buf_size, GFP_KERNEL);
  1730. if (!buf)
  1731. return -ENOSPC;
  1732. len = snprintf(buf, buf_size, "%s: %s\n",
  1733. pf->vsi[pf->lan_vsi]->netdev->name,
  1734. i40e_dbg_netdev_ops_buf);
  1735. bytes_not_copied = copy_to_user(buffer, buf, len);
  1736. kfree(buf);
  1737. if (bytes_not_copied < 0)
  1738. return bytes_not_copied;
  1739. *ppos = len;
  1740. return len;
  1741. }
  1742. /**
  1743. * i40e_dbg_netdev_ops_write - write into netdev_ops datum
  1744. * @filp: the opened file
  1745. * @buffer: where to find the user's data
  1746. * @count: the length of the user's data
  1747. * @ppos: file position offset
  1748. **/
  1749. static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
  1750. const char __user *buffer,
  1751. size_t count, loff_t *ppos)
  1752. {
  1753. struct i40e_pf *pf = filp->private_data;
  1754. int bytes_not_copied;
  1755. struct i40e_vsi *vsi;
  1756. int vsi_seid;
  1757. int i, cnt;
  1758. /* don't allow partial writes */
  1759. if (*ppos != 0)
  1760. return 0;
  1761. if (count >= sizeof(i40e_dbg_netdev_ops_buf))
  1762. return -ENOSPC;
  1763. memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
  1764. bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
  1765. buffer, count);
  1766. if (bytes_not_copied < 0)
  1767. return bytes_not_copied;
  1768. else if (bytes_not_copied > 0)
  1769. count -= bytes_not_copied;
  1770. i40e_dbg_netdev_ops_buf[count] = '\0';
  1771. if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
  1772. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1773. if (cnt != 1) {
  1774. dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
  1775. goto netdev_ops_write_done;
  1776. }
  1777. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1778. if (!vsi) {
  1779. dev_info(&pf->pdev->dev,
  1780. "tx_timeout: VSI %d not found\n", vsi_seid);
  1781. goto netdev_ops_write_done;
  1782. }
  1783. if (rtnl_trylock()) {
  1784. vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
  1785. rtnl_unlock();
  1786. dev_info(&pf->pdev->dev, "tx_timeout called\n");
  1787. } else {
  1788. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1789. }
  1790. } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
  1791. int mtu;
  1792. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
  1793. &vsi_seid, &mtu);
  1794. if (cnt != 2) {
  1795. dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
  1796. goto netdev_ops_write_done;
  1797. }
  1798. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1799. if (!vsi) {
  1800. dev_info(&pf->pdev->dev,
  1801. "change_mtu: VSI %d not found\n", vsi_seid);
  1802. goto netdev_ops_write_done;
  1803. }
  1804. if (rtnl_trylock()) {
  1805. vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
  1806. mtu);
  1807. rtnl_unlock();
  1808. dev_info(&pf->pdev->dev, "change_mtu called\n");
  1809. } else {
  1810. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1811. }
  1812. } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
  1813. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1814. if (cnt != 1) {
  1815. dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
  1816. goto netdev_ops_write_done;
  1817. }
  1818. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1819. if (!vsi) {
  1820. dev_info(&pf->pdev->dev,
  1821. "set_rx_mode: VSI %d not found\n", vsi_seid);
  1822. goto netdev_ops_write_done;
  1823. }
  1824. if (rtnl_trylock()) {
  1825. vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
  1826. rtnl_unlock();
  1827. dev_info(&pf->pdev->dev, "set_rx_mode called\n");
  1828. } else {
  1829. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1830. }
  1831. } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
  1832. cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
  1833. if (cnt != 1) {
  1834. dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
  1835. goto netdev_ops_write_done;
  1836. }
  1837. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1838. if (!vsi) {
  1839. dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
  1840. vsi_seid);
  1841. goto netdev_ops_write_done;
  1842. }
  1843. for (i = 0; i < vsi->num_q_vectors; i++)
  1844. napi_schedule(&vsi->q_vectors[i]->napi);
  1845. dev_info(&pf->pdev->dev, "napi called\n");
  1846. } else {
  1847. dev_info(&pf->pdev->dev, "unknown command '%s'\n",
  1848. i40e_dbg_netdev_ops_buf);
  1849. dev_info(&pf->pdev->dev, "available commands\n");
  1850. dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
  1851. dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
  1852. dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
  1853. dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
  1854. }
  1855. netdev_ops_write_done:
  1856. return count;
  1857. }
  1858. static const struct file_operations i40e_dbg_netdev_ops_fops = {
  1859. .owner = THIS_MODULE,
  1860. .open = simple_open,
  1861. .read = i40e_dbg_netdev_ops_read,
  1862. .write = i40e_dbg_netdev_ops_write,
  1863. };
  1864. /**
  1865. * i40e_dbg_pf_init - setup the debugfs directory for the pf
  1866. * @pf: the pf that is starting up
  1867. **/
  1868. void i40e_dbg_pf_init(struct i40e_pf *pf)
  1869. {
  1870. struct dentry *pfile __attribute__((unused));
  1871. const char *name = pci_name(pf->pdev);
  1872. pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
  1873. if (pf->i40e_dbg_pf) {
  1874. pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf,
  1875. pf, &i40e_dbg_command_fops);
  1876. pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf,
  1877. &i40e_dbg_dump_fops);
  1878. pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf,
  1879. pf, &i40e_dbg_netdev_ops_fops);
  1880. } else {
  1881. dev_info(&pf->pdev->dev,
  1882. "debugfs entry for %s failed\n", name);
  1883. }
  1884. }
  1885. /**
  1886. * i40e_dbg_pf_exit - clear out the pf's debugfs entries
  1887. * @pf: the pf that is stopping
  1888. **/
  1889. void i40e_dbg_pf_exit(struct i40e_pf *pf)
  1890. {
  1891. debugfs_remove_recursive(pf->i40e_dbg_pf);
  1892. pf->i40e_dbg_pf = NULL;
  1893. kfree(i40e_dbg_dump_buf);
  1894. i40e_dbg_dump_buf = NULL;
  1895. }
  1896. /**
  1897. * i40e_dbg_init - start up debugfs for the driver
  1898. **/
  1899. void i40e_dbg_init(void)
  1900. {
  1901. i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
  1902. if (!i40e_dbg_root)
  1903. pr_info("init of debugfs failed\n");
  1904. }
  1905. /**
  1906. * i40e_dbg_exit - clean out the driver's debugfs entries
  1907. **/
  1908. void i40e_dbg_exit(void)
  1909. {
  1910. debugfs_remove_recursive(i40e_dbg_root);
  1911. i40e_dbg_root = NULL;
  1912. }
  1913. #endif /* CONFIG_DEBUG_FS */