i40e_debugfs.c 70 KB

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