i40e_debugfs.c 71 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. (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. 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. (long unsigned 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. (long unsigned 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. /**
  879. * i40e_dbg_cmd_fd_ctrl - Enable/disable FD sideband/ATR
  880. * @pf: the PF that would be altered
  881. * @flag: flag that needs enabling or disabling
  882. * @enable: Enable/disable FD SD/ATR
  883. **/
  884. static void i40e_dbg_cmd_fd_ctrl(struct i40e_pf *pf, u64 flag, bool enable)
  885. {
  886. if (enable) {
  887. pf->flags |= flag;
  888. } else {
  889. pf->flags &= ~flag;
  890. pf->auto_disable_flags |= flag;
  891. }
  892. dev_info(&pf->pdev->dev, "requesting a PF reset\n");
  893. i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
  894. }
  895. #define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
  896. /**
  897. * i40e_dbg_command_write - write into command datum
  898. * @filp: the opened file
  899. * @buffer: where to find the user's data
  900. * @count: the length of the user's data
  901. * @ppos: file position offset
  902. **/
  903. static ssize_t i40e_dbg_command_write(struct file *filp,
  904. const char __user *buffer,
  905. size_t count, loff_t *ppos)
  906. {
  907. struct i40e_pf *pf = filp->private_data;
  908. char *cmd_buf, *cmd_buf_tmp;
  909. int bytes_not_copied;
  910. struct i40e_vsi *vsi;
  911. int vsi_seid;
  912. int veb_seid;
  913. int cnt;
  914. /* don't allow partial writes */
  915. if (*ppos != 0)
  916. return 0;
  917. cmd_buf = kzalloc(count + 1, GFP_KERNEL);
  918. if (!cmd_buf)
  919. return count;
  920. bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
  921. if (bytes_not_copied < 0) {
  922. kfree(cmd_buf);
  923. return bytes_not_copied;
  924. }
  925. if (bytes_not_copied > 0)
  926. count -= bytes_not_copied;
  927. cmd_buf[count] = '\0';
  928. cmd_buf_tmp = strchr(cmd_buf, '\n');
  929. if (cmd_buf_tmp) {
  930. *cmd_buf_tmp = '\0';
  931. count = cmd_buf_tmp - cmd_buf + 1;
  932. }
  933. if (strncmp(cmd_buf, "add vsi", 7) == 0) {
  934. vsi_seid = -1;
  935. cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
  936. if (cnt == 0) {
  937. /* default to PF VSI */
  938. vsi_seid = pf->vsi[pf->lan_vsi]->seid;
  939. } else if (vsi_seid < 0) {
  940. dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
  941. vsi_seid);
  942. goto command_write_done;
  943. }
  944. /* By default we are in VEPA mode, if this is the first VF/VMDq
  945. * VSI to be added switch to VEB mode.
  946. */
  947. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  948. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  949. i40e_do_reset_safe(pf,
  950. BIT_ULL(__I40E_PF_RESET_REQUESTED));
  951. }
  952. vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
  953. if (vsi)
  954. dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
  955. vsi->seid, vsi->uplink_seid);
  956. else
  957. dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
  958. } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
  959. sscanf(&cmd_buf[7], "%i", &vsi_seid);
  960. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  961. if (!vsi) {
  962. dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
  963. vsi_seid);
  964. goto command_write_done;
  965. }
  966. dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
  967. i40e_vsi_release(vsi);
  968. } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
  969. struct i40e_veb *veb;
  970. int uplink_seid, i;
  971. cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
  972. if (cnt != 2) {
  973. dev_info(&pf->pdev->dev,
  974. "add relay: bad command string, cnt=%d\n",
  975. cnt);
  976. goto command_write_done;
  977. } else if (uplink_seid < 0) {
  978. dev_info(&pf->pdev->dev,
  979. "add relay %d: bad uplink seid\n",
  980. uplink_seid);
  981. goto command_write_done;
  982. }
  983. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  984. if (!vsi) {
  985. dev_info(&pf->pdev->dev,
  986. "add relay: VSI %d not found\n", vsi_seid);
  987. goto command_write_done;
  988. }
  989. for (i = 0; i < I40E_MAX_VEB; i++)
  990. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
  991. break;
  992. if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
  993. uplink_seid != pf->mac_seid) {
  994. dev_info(&pf->pdev->dev,
  995. "add relay: relay uplink %d not found\n",
  996. uplink_seid);
  997. goto command_write_done;
  998. }
  999. veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
  1000. vsi->tc_config.enabled_tc);
  1001. if (veb)
  1002. dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
  1003. else
  1004. dev_info(&pf->pdev->dev, "add relay failed\n");
  1005. } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
  1006. int i;
  1007. cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
  1008. if (cnt != 1) {
  1009. dev_info(&pf->pdev->dev,
  1010. "del relay: bad command string, cnt=%d\n",
  1011. cnt);
  1012. goto command_write_done;
  1013. } else if (veb_seid < 0) {
  1014. dev_info(&pf->pdev->dev,
  1015. "del relay %d: bad relay seid\n", veb_seid);
  1016. goto command_write_done;
  1017. }
  1018. /* find the veb */
  1019. for (i = 0; i < I40E_MAX_VEB; i++)
  1020. if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
  1021. break;
  1022. if (i >= I40E_MAX_VEB) {
  1023. dev_info(&pf->pdev->dev,
  1024. "del relay: relay %d not found\n", veb_seid);
  1025. goto command_write_done;
  1026. }
  1027. dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
  1028. i40e_veb_release(pf->veb[i]);
  1029. } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
  1030. struct i40e_mac_filter *f;
  1031. int vlan = 0;
  1032. u8 ma[6];
  1033. int ret;
  1034. cnt = sscanf(&cmd_buf[11],
  1035. "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
  1036. &vsi_seid,
  1037. &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
  1038. &vlan);
  1039. if (cnt == 7) {
  1040. vlan = 0;
  1041. } else if (cnt != 8) {
  1042. dev_info(&pf->pdev->dev,
  1043. "add macaddr: bad command string, cnt=%d\n",
  1044. cnt);
  1045. goto command_write_done;
  1046. }
  1047. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1048. if (!vsi) {
  1049. dev_info(&pf->pdev->dev,
  1050. "add macaddr: VSI %d not found\n", vsi_seid);
  1051. goto command_write_done;
  1052. }
  1053. f = i40e_add_filter(vsi, ma, vlan, false, false);
  1054. ret = i40e_sync_vsi_filters(vsi);
  1055. if (f && !ret)
  1056. dev_info(&pf->pdev->dev,
  1057. "add macaddr: %pM vlan=%d added to VSI %d\n",
  1058. ma, vlan, vsi_seid);
  1059. else
  1060. dev_info(&pf->pdev->dev,
  1061. "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
  1062. ma, vlan, vsi_seid, f, ret);
  1063. } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
  1064. int vlan = 0;
  1065. u8 ma[6];
  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. "del 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. "del macaddr: VSI %d not found\n", vsi_seid);
  1084. goto command_write_done;
  1085. }
  1086. i40e_del_filter(vsi, ma, vlan, false, false);
  1087. ret = i40e_sync_vsi_filters(vsi);
  1088. if (!ret)
  1089. dev_info(&pf->pdev->dev,
  1090. "del macaddr: %pM vlan=%d removed from VSI %d\n",
  1091. ma, vlan, vsi_seid);
  1092. else
  1093. dev_info(&pf->pdev->dev,
  1094. "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
  1095. ma, vlan, vsi_seid, ret);
  1096. } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
  1097. i40e_status ret;
  1098. u16 vid;
  1099. unsigned int v;
  1100. cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
  1101. if (cnt != 2) {
  1102. dev_info(&pf->pdev->dev,
  1103. "add pvid: bad command string, cnt=%d\n", cnt);
  1104. goto command_write_done;
  1105. }
  1106. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1107. if (!vsi) {
  1108. dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
  1109. vsi_seid);
  1110. goto command_write_done;
  1111. }
  1112. vid = v;
  1113. ret = i40e_vsi_add_pvid(vsi, vid);
  1114. if (!ret)
  1115. dev_info(&pf->pdev->dev,
  1116. "add pvid: %d added to VSI %d\n",
  1117. vid, vsi_seid);
  1118. else
  1119. dev_info(&pf->pdev->dev,
  1120. "add pvid: %d to VSI %d failed, ret=%d\n",
  1121. vid, vsi_seid, ret);
  1122. } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
  1123. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1124. if (cnt != 1) {
  1125. dev_info(&pf->pdev->dev,
  1126. "del pvid: bad command string, cnt=%d\n",
  1127. cnt);
  1128. goto command_write_done;
  1129. }
  1130. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1131. if (!vsi) {
  1132. dev_info(&pf->pdev->dev,
  1133. "del pvid: VSI %d not found\n", vsi_seid);
  1134. goto command_write_done;
  1135. }
  1136. i40e_vsi_remove_pvid(vsi);
  1137. dev_info(&pf->pdev->dev,
  1138. "del pvid: removed from VSI %d\n", vsi_seid);
  1139. } else if (strncmp(cmd_buf, "dump", 4) == 0) {
  1140. if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
  1141. i40e_fetch_switch_configuration(pf, true);
  1142. } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
  1143. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1144. if (cnt > 0)
  1145. i40e_dbg_dump_vsi_seid(pf, vsi_seid);
  1146. else
  1147. i40e_dbg_dump_vsi_no_seid(pf);
  1148. } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
  1149. cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
  1150. if (cnt > 0)
  1151. i40e_dbg_dump_veb_seid(pf, vsi_seid);
  1152. else
  1153. i40e_dbg_dump_veb_all(pf);
  1154. } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
  1155. int ring_id, desc_n;
  1156. if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
  1157. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  1158. &vsi_seid, &ring_id, &desc_n);
  1159. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  1160. desc_n, pf, true);
  1161. } else if (strncmp(&cmd_buf[10], "tx", 2)
  1162. == 0) {
  1163. cnt = sscanf(&cmd_buf[12], "%i %i %i",
  1164. &vsi_seid, &ring_id, &desc_n);
  1165. i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
  1166. desc_n, pf, false);
  1167. } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
  1168. i40e_dbg_dump_aq_desc(pf);
  1169. } else {
  1170. dev_info(&pf->pdev->dev,
  1171. "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  1172. dev_info(&pf->pdev->dev,
  1173. "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  1174. dev_info(&pf->pdev->dev, "dump desc aq\n");
  1175. }
  1176. } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
  1177. dev_info(&pf->pdev->dev,
  1178. "core reset count: %d\n", pf->corer_count);
  1179. dev_info(&pf->pdev->dev,
  1180. "global reset count: %d\n", pf->globr_count);
  1181. dev_info(&pf->pdev->dev,
  1182. "emp reset count: %d\n", pf->empr_count);
  1183. dev_info(&pf->pdev->dev,
  1184. "pf reset count: %d\n", pf->pfr_count);
  1185. dev_info(&pf->pdev->dev,
  1186. "pf tx sluggish count: %d\n",
  1187. pf->tx_sluggish_count);
  1188. } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
  1189. struct i40e_aqc_query_port_ets_config_resp *bw_data;
  1190. struct i40e_dcbx_config *cfg =
  1191. &pf->hw.local_dcbx_config;
  1192. struct i40e_dcbx_config *r_cfg =
  1193. &pf->hw.remote_dcbx_config;
  1194. int i, ret;
  1195. bw_data = kzalloc(sizeof(
  1196. struct i40e_aqc_query_port_ets_config_resp),
  1197. GFP_KERNEL);
  1198. if (!bw_data) {
  1199. ret = -ENOMEM;
  1200. goto command_write_done;
  1201. }
  1202. ret = i40e_aq_query_port_ets_config(&pf->hw,
  1203. pf->mac_seid,
  1204. bw_data, NULL);
  1205. if (ret) {
  1206. dev_info(&pf->pdev->dev,
  1207. "Query Port ETS Config AQ command failed =0x%x\n",
  1208. pf->hw.aq.asq_last_status);
  1209. kfree(bw_data);
  1210. bw_data = NULL;
  1211. goto command_write_done;
  1212. }
  1213. dev_info(&pf->pdev->dev,
  1214. "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
  1215. bw_data->tc_valid_bits,
  1216. bw_data->tc_strict_priority_bits,
  1217. le16_to_cpu(bw_data->tc_bw_max[0]),
  1218. le16_to_cpu(bw_data->tc_bw_max[1]));
  1219. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1220. dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
  1221. bw_data->tc_bw_share_credits[i],
  1222. le16_to_cpu(bw_data->tc_bw_limits[i]));
  1223. }
  1224. kfree(bw_data);
  1225. bw_data = NULL;
  1226. dev_info(&pf->pdev->dev,
  1227. "port dcbx_mode=%d\n", cfg->dcbx_mode);
  1228. dev_info(&pf->pdev->dev,
  1229. "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  1230. cfg->etscfg.willing, cfg->etscfg.cbs,
  1231. cfg->etscfg.maxtcs);
  1232. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1233. dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1234. i, cfg->etscfg.prioritytable[i],
  1235. cfg->etscfg.tcbwtable[i],
  1236. cfg->etscfg.tsatable[i]);
  1237. }
  1238. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1239. dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1240. i, cfg->etsrec.prioritytable[i],
  1241. cfg->etsrec.tcbwtable[i],
  1242. cfg->etsrec.tsatable[i]);
  1243. }
  1244. dev_info(&pf->pdev->dev,
  1245. "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  1246. cfg->pfc.willing, cfg->pfc.mbc,
  1247. cfg->pfc.pfccap, cfg->pfc.pfcenable);
  1248. dev_info(&pf->pdev->dev,
  1249. "port app_table: num_apps=%d\n", cfg->numapps);
  1250. for (i = 0; i < cfg->numapps; i++) {
  1251. dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1252. i, cfg->app[i].priority,
  1253. cfg->app[i].selector,
  1254. cfg->app[i].protocolid);
  1255. }
  1256. /* Peer TLV DCBX data */
  1257. dev_info(&pf->pdev->dev,
  1258. "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
  1259. r_cfg->etscfg.willing,
  1260. r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
  1261. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1262. dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1263. i, r_cfg->etscfg.prioritytable[i],
  1264. r_cfg->etscfg.tcbwtable[i],
  1265. r_cfg->etscfg.tsatable[i]);
  1266. }
  1267. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1268. dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
  1269. i, r_cfg->etsrec.prioritytable[i],
  1270. r_cfg->etsrec.tcbwtable[i],
  1271. r_cfg->etsrec.tsatable[i]);
  1272. }
  1273. dev_info(&pf->pdev->dev,
  1274. "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
  1275. r_cfg->pfc.willing,
  1276. r_cfg->pfc.mbc,
  1277. r_cfg->pfc.pfccap,
  1278. r_cfg->pfc.pfcenable);
  1279. dev_info(&pf->pdev->dev,
  1280. "remote port app_table: num_apps=%d\n",
  1281. r_cfg->numapps);
  1282. for (i = 0; i < r_cfg->numapps; i++) {
  1283. dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
  1284. i, r_cfg->app[i].priority,
  1285. r_cfg->app[i].selector,
  1286. r_cfg->app[i].protocolid);
  1287. }
  1288. } else if (strncmp(&cmd_buf[5], "debug fwdata", 12) == 0) {
  1289. int cluster_id, table_id;
  1290. int index, ret;
  1291. u16 buff_len = 4096;
  1292. u32 next_index;
  1293. u8 next_table;
  1294. u8 *buff;
  1295. u16 rlen;
  1296. cnt = sscanf(&cmd_buf[18], "%i %i %i",
  1297. &cluster_id, &table_id, &index);
  1298. if (cnt != 3) {
  1299. dev_info(&pf->pdev->dev,
  1300. "dump debug fwdata <cluster_id> <table_id> <index>\n");
  1301. goto command_write_done;
  1302. }
  1303. dev_info(&pf->pdev->dev,
  1304. "AQ debug dump fwdata params %x %x %x %x\n",
  1305. cluster_id, table_id, index, buff_len);
  1306. buff = kzalloc(buff_len, GFP_KERNEL);
  1307. if (!buff)
  1308. goto command_write_done;
  1309. ret = i40e_aq_debug_dump(&pf->hw, cluster_id, table_id,
  1310. index, buff_len, buff, &rlen,
  1311. &next_table, &next_index,
  1312. NULL);
  1313. if (ret) {
  1314. dev_info(&pf->pdev->dev,
  1315. "debug dump fwdata AQ Failed %d 0x%x\n",
  1316. ret, pf->hw.aq.asq_last_status);
  1317. kfree(buff);
  1318. buff = NULL;
  1319. goto command_write_done;
  1320. }
  1321. dev_info(&pf->pdev->dev,
  1322. "AQ debug dump fwdata rlen=0x%x next_table=0x%x next_index=0x%x\n",
  1323. rlen, next_table, next_index);
  1324. print_hex_dump(KERN_INFO, "AQ buffer WB: ",
  1325. DUMP_PREFIX_OFFSET, 16, 1,
  1326. buff, rlen, true);
  1327. kfree(buff);
  1328. buff = NULL;
  1329. } else {
  1330. dev_info(&pf->pdev->dev,
  1331. "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
  1332. dev_info(&pf->pdev->dev, "dump switch\n");
  1333. dev_info(&pf->pdev->dev, "dump vsi [seid]\n");
  1334. dev_info(&pf->pdev->dev, "dump reset stats\n");
  1335. dev_info(&pf->pdev->dev, "dump port\n");
  1336. dev_info(&pf->pdev->dev,
  1337. "dump debug fwdata <cluster_id> <table_id> <index>\n");
  1338. }
  1339. } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
  1340. u32 level;
  1341. cnt = sscanf(&cmd_buf[10], "%i", &level);
  1342. if (cnt) {
  1343. if (I40E_DEBUG_USER & level) {
  1344. pf->hw.debug_mask = level;
  1345. dev_info(&pf->pdev->dev,
  1346. "set hw.debug_mask = 0x%08x\n",
  1347. pf->hw.debug_mask);
  1348. }
  1349. pf->msg_enable = level;
  1350. dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
  1351. pf->msg_enable);
  1352. } else {
  1353. dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
  1354. pf->msg_enable);
  1355. }
  1356. } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
  1357. dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n");
  1358. i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1359. } else if (strncmp(cmd_buf, "corer", 5) == 0) {
  1360. dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n");
  1361. i40e_do_reset_safe(pf, BIT(__I40E_CORE_RESET_REQUESTED));
  1362. } else if (strncmp(cmd_buf, "globr", 5) == 0) {
  1363. dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n");
  1364. i40e_do_reset_safe(pf, BIT(__I40E_GLOBAL_RESET_REQUESTED));
  1365. } else if (strncmp(cmd_buf, "empr", 4) == 0) {
  1366. dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n");
  1367. i40e_do_reset_safe(pf, BIT(__I40E_EMP_RESET_REQUESTED));
  1368. } else if (strncmp(cmd_buf, "read", 4) == 0) {
  1369. u32 address;
  1370. u32 value;
  1371. cnt = sscanf(&cmd_buf[4], "%i", &address);
  1372. if (cnt != 1) {
  1373. dev_info(&pf->pdev->dev, "read <reg>\n");
  1374. goto command_write_done;
  1375. }
  1376. /* check the range on address */
  1377. if (address >= I40E_MAX_REGISTER) {
  1378. dev_info(&pf->pdev->dev, "read reg address 0x%08x too large\n",
  1379. address);
  1380. goto command_write_done;
  1381. }
  1382. value = rd32(&pf->hw, address);
  1383. dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
  1384. address, value);
  1385. } else if (strncmp(cmd_buf, "write", 5) == 0) {
  1386. u32 address, value;
  1387. cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
  1388. if (cnt != 2) {
  1389. dev_info(&pf->pdev->dev, "write <reg> <value>\n");
  1390. goto command_write_done;
  1391. }
  1392. /* check the range on address */
  1393. if (address >= I40E_MAX_REGISTER) {
  1394. dev_info(&pf->pdev->dev, "write reg address 0x%08x too large\n",
  1395. address);
  1396. goto command_write_done;
  1397. }
  1398. wr32(&pf->hw, address, value);
  1399. value = rd32(&pf->hw, address);
  1400. dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
  1401. address, value);
  1402. } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
  1403. if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
  1404. cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
  1405. if (cnt == 0) {
  1406. int i;
  1407. for (i = 0; i < pf->num_alloc_vsi; i++)
  1408. i40e_vsi_reset_stats(pf->vsi[i]);
  1409. dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
  1410. } else if (cnt == 1) {
  1411. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1412. if (!vsi) {
  1413. dev_info(&pf->pdev->dev,
  1414. "clear_stats vsi: bad vsi %d\n",
  1415. vsi_seid);
  1416. goto command_write_done;
  1417. }
  1418. i40e_vsi_reset_stats(vsi);
  1419. dev_info(&pf->pdev->dev,
  1420. "vsi clear stats called for vsi %d\n",
  1421. vsi_seid);
  1422. } else {
  1423. dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
  1424. }
  1425. } else if (strncmp(&cmd_buf[12], "port", 4) == 0) {
  1426. if (pf->hw.partition_id == 1) {
  1427. i40e_pf_reset_stats(pf);
  1428. dev_info(&pf->pdev->dev, "port stats cleared\n");
  1429. } else {
  1430. dev_info(&pf->pdev->dev, "clear port stats not allowed on this port partition\n");
  1431. }
  1432. } else {
  1433. dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats port\n");
  1434. }
  1435. } else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) {
  1436. struct i40e_aq_desc *desc;
  1437. i40e_status ret;
  1438. desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
  1439. if (!desc)
  1440. goto command_write_done;
  1441. cnt = sscanf(&cmd_buf[11],
  1442. "%hi %hi %hi %hi %i %i %i %i %i %i",
  1443. &desc->flags,
  1444. &desc->opcode, &desc->datalen, &desc->retval,
  1445. &desc->cookie_high, &desc->cookie_low,
  1446. &desc->params.internal.param0,
  1447. &desc->params.internal.param1,
  1448. &desc->params.internal.param2,
  1449. &desc->params.internal.param3);
  1450. if (cnt != 10) {
  1451. dev_info(&pf->pdev->dev,
  1452. "send aq_cmd: bad command string, cnt=%d\n",
  1453. cnt);
  1454. kfree(desc);
  1455. desc = NULL;
  1456. goto command_write_done;
  1457. }
  1458. ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL);
  1459. if (!ret) {
  1460. dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
  1461. } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
  1462. dev_info(&pf->pdev->dev,
  1463. "AQ command send failed Opcode %x AQ Error: %d\n",
  1464. desc->opcode, pf->hw.aq.asq_last_status);
  1465. } else {
  1466. dev_info(&pf->pdev->dev,
  1467. "AQ command send failed Opcode %x Status: %d\n",
  1468. desc->opcode, ret);
  1469. }
  1470. dev_info(&pf->pdev->dev,
  1471. "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1472. desc->flags, desc->opcode, desc->datalen, desc->retval,
  1473. desc->cookie_high, desc->cookie_low,
  1474. desc->params.internal.param0,
  1475. desc->params.internal.param1,
  1476. desc->params.internal.param2,
  1477. desc->params.internal.param3);
  1478. kfree(desc);
  1479. desc = NULL;
  1480. } else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) {
  1481. struct i40e_aq_desc *desc;
  1482. i40e_status ret;
  1483. u16 buffer_len;
  1484. u8 *buff;
  1485. desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
  1486. if (!desc)
  1487. goto command_write_done;
  1488. cnt = sscanf(&cmd_buf[20],
  1489. "%hi %hi %hi %hi %i %i %i %i %i %i %hi",
  1490. &desc->flags,
  1491. &desc->opcode, &desc->datalen, &desc->retval,
  1492. &desc->cookie_high, &desc->cookie_low,
  1493. &desc->params.internal.param0,
  1494. &desc->params.internal.param1,
  1495. &desc->params.internal.param2,
  1496. &desc->params.internal.param3,
  1497. &buffer_len);
  1498. if (cnt != 11) {
  1499. dev_info(&pf->pdev->dev,
  1500. "send indirect aq_cmd: bad command string, cnt=%d\n",
  1501. cnt);
  1502. kfree(desc);
  1503. desc = NULL;
  1504. goto command_write_done;
  1505. }
  1506. /* Just stub a buffer big enough in case user messed up */
  1507. if (buffer_len == 0)
  1508. buffer_len = 1280;
  1509. buff = kzalloc(buffer_len, GFP_KERNEL);
  1510. if (!buff) {
  1511. kfree(desc);
  1512. desc = NULL;
  1513. goto command_write_done;
  1514. }
  1515. desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
  1516. ret = i40e_asq_send_command(&pf->hw, desc, buff,
  1517. buffer_len, NULL);
  1518. if (!ret) {
  1519. dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
  1520. } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
  1521. dev_info(&pf->pdev->dev,
  1522. "AQ command send failed Opcode %x AQ Error: %d\n",
  1523. desc->opcode, pf->hw.aq.asq_last_status);
  1524. } else {
  1525. dev_info(&pf->pdev->dev,
  1526. "AQ command send failed Opcode %x Status: %d\n",
  1527. desc->opcode, ret);
  1528. }
  1529. dev_info(&pf->pdev->dev,
  1530. "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1531. desc->flags, desc->opcode, desc->datalen, desc->retval,
  1532. desc->cookie_high, desc->cookie_low,
  1533. desc->params.internal.param0,
  1534. desc->params.internal.param1,
  1535. desc->params.internal.param2,
  1536. desc->params.internal.param3);
  1537. print_hex_dump(KERN_INFO, "AQ buffer WB: ",
  1538. DUMP_PREFIX_OFFSET, 16, 1,
  1539. buff, buffer_len, true);
  1540. kfree(buff);
  1541. buff = NULL;
  1542. kfree(desc);
  1543. desc = NULL;
  1544. } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
  1545. (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
  1546. struct i40e_fdir_filter fd_data;
  1547. u16 packet_len, i, j = 0;
  1548. char *asc_packet;
  1549. u8 *raw_packet;
  1550. bool add = false;
  1551. int ret;
  1552. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1553. goto command_write_done;
  1554. if (strncmp(cmd_buf, "add", 3) == 0)
  1555. add = true;
  1556. if (add && (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
  1557. goto command_write_done;
  1558. asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
  1559. GFP_KERNEL);
  1560. if (!asc_packet)
  1561. goto command_write_done;
  1562. raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
  1563. GFP_KERNEL);
  1564. if (!raw_packet) {
  1565. kfree(asc_packet);
  1566. asc_packet = NULL;
  1567. goto command_write_done;
  1568. }
  1569. cnt = sscanf(&cmd_buf[13],
  1570. "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %511s",
  1571. &fd_data.q_index,
  1572. &fd_data.flex_off, &fd_data.pctype,
  1573. &fd_data.dest_vsi, &fd_data.dest_ctl,
  1574. &fd_data.fd_status, &fd_data.cnt_index,
  1575. &fd_data.fd_id, &packet_len, asc_packet);
  1576. if (cnt != 10) {
  1577. dev_info(&pf->pdev->dev,
  1578. "program fd_filter: bad command string, cnt=%d\n",
  1579. cnt);
  1580. kfree(asc_packet);
  1581. asc_packet = NULL;
  1582. kfree(raw_packet);
  1583. goto command_write_done;
  1584. }
  1585. /* fix packet length if user entered 0 */
  1586. if (packet_len == 0)
  1587. packet_len = I40E_FDIR_MAX_RAW_PACKET_SIZE;
  1588. /* make sure to check the max as well */
  1589. packet_len = min_t(u16,
  1590. packet_len, I40E_FDIR_MAX_RAW_PACKET_SIZE);
  1591. for (i = 0; i < packet_len; i++) {
  1592. sscanf(&asc_packet[j], "%2hhx ",
  1593. &raw_packet[i]);
  1594. j += 3;
  1595. }
  1596. dev_info(&pf->pdev->dev, "FD raw packet dump\n");
  1597. print_hex_dump(KERN_INFO, "FD raw packet: ",
  1598. DUMP_PREFIX_OFFSET, 16, 1,
  1599. raw_packet, packet_len, true);
  1600. ret = i40e_program_fdir_filter(&fd_data, raw_packet, pf, add);
  1601. if (!ret) {
  1602. dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
  1603. } else {
  1604. dev_info(&pf->pdev->dev,
  1605. "Filter command send failed %d\n", ret);
  1606. }
  1607. kfree(raw_packet);
  1608. raw_packet = NULL;
  1609. kfree(asc_packet);
  1610. asc_packet = NULL;
  1611. } else if (strncmp(cmd_buf, "fd-atr off", 10) == 0) {
  1612. i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_ATR_ENABLED, false);
  1613. } else if (strncmp(cmd_buf, "fd-atr on", 9) == 0) {
  1614. i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_ATR_ENABLED, true);
  1615. } else if (strncmp(cmd_buf, "fd current cnt", 14) == 0) {
  1616. dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
  1617. i40e_get_current_fd_count(pf));
  1618. } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
  1619. if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
  1620. int ret;
  1621. ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
  1622. if (ret) {
  1623. dev_info(&pf->pdev->dev,
  1624. "Stop LLDP AQ command failed =0x%x\n",
  1625. pf->hw.aq.asq_last_status);
  1626. goto command_write_done;
  1627. }
  1628. ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
  1629. pf->hw.mac.addr,
  1630. I40E_ETH_P_LLDP, 0,
  1631. pf->vsi[pf->lan_vsi]->seid,
  1632. 0, true, NULL, NULL);
  1633. if (ret) {
  1634. dev_info(&pf->pdev->dev,
  1635. "%s: Add Control Packet Filter AQ command failed =0x%x\n",
  1636. __func__, pf->hw.aq.asq_last_status);
  1637. goto command_write_done;
  1638. }
  1639. #ifdef CONFIG_I40E_DCB
  1640. pf->dcbx_cap = DCB_CAP_DCBX_HOST |
  1641. DCB_CAP_DCBX_VER_IEEE;
  1642. #endif /* CONFIG_I40E_DCB */
  1643. } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
  1644. int ret;
  1645. ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
  1646. pf->hw.mac.addr,
  1647. I40E_ETH_P_LLDP, 0,
  1648. pf->vsi[pf->lan_vsi]->seid,
  1649. 0, false, NULL, NULL);
  1650. if (ret) {
  1651. dev_info(&pf->pdev->dev,
  1652. "%s: Remove Control Packet Filter AQ command failed =0x%x\n",
  1653. __func__, pf->hw.aq.asq_last_status);
  1654. /* Continue and start FW LLDP anyways */
  1655. }
  1656. ret = i40e_aq_start_lldp(&pf->hw, NULL);
  1657. if (ret) {
  1658. dev_info(&pf->pdev->dev,
  1659. "Start LLDP AQ command failed =0x%x\n",
  1660. pf->hw.aq.asq_last_status);
  1661. goto command_write_done;
  1662. }
  1663. #ifdef CONFIG_I40E_DCB
  1664. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  1665. DCB_CAP_DCBX_VER_IEEE;
  1666. #endif /* CONFIG_I40E_DCB */
  1667. } else if (strncmp(&cmd_buf[5],
  1668. "get local", 9) == 0) {
  1669. u16 llen, rlen;
  1670. int ret;
  1671. u8 *buff;
  1672. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1673. if (!buff)
  1674. goto command_write_done;
  1675. ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
  1676. I40E_AQ_LLDP_MIB_LOCAL,
  1677. buff, I40E_LLDPDU_SIZE,
  1678. &llen, &rlen, NULL);
  1679. if (ret) {
  1680. dev_info(&pf->pdev->dev,
  1681. "Get LLDP MIB (local) AQ command failed =0x%x\n",
  1682. pf->hw.aq.asq_last_status);
  1683. kfree(buff);
  1684. buff = NULL;
  1685. goto command_write_done;
  1686. }
  1687. dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
  1688. print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
  1689. DUMP_PREFIX_OFFSET, 16, 1,
  1690. buff, I40E_LLDPDU_SIZE, true);
  1691. kfree(buff);
  1692. buff = NULL;
  1693. } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
  1694. u16 llen, rlen;
  1695. int ret;
  1696. u8 *buff;
  1697. buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
  1698. if (!buff)
  1699. goto command_write_done;
  1700. ret = i40e_aq_get_lldp_mib(&pf->hw,
  1701. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  1702. I40E_AQ_LLDP_MIB_REMOTE,
  1703. buff, I40E_LLDPDU_SIZE,
  1704. &llen, &rlen, NULL);
  1705. if (ret) {
  1706. dev_info(&pf->pdev->dev,
  1707. "Get LLDP MIB (remote) AQ command failed =0x%x\n",
  1708. pf->hw.aq.asq_last_status);
  1709. kfree(buff);
  1710. buff = NULL;
  1711. goto command_write_done;
  1712. }
  1713. dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
  1714. print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
  1715. DUMP_PREFIX_OFFSET, 16, 1,
  1716. buff, I40E_LLDPDU_SIZE, true);
  1717. kfree(buff);
  1718. buff = NULL;
  1719. } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
  1720. int ret;
  1721. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1722. true, NULL);
  1723. if (ret) {
  1724. dev_info(&pf->pdev->dev,
  1725. "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
  1726. pf->hw.aq.asq_last_status);
  1727. goto command_write_done;
  1728. }
  1729. } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
  1730. int ret;
  1731. ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
  1732. false, NULL);
  1733. if (ret) {
  1734. dev_info(&pf->pdev->dev,
  1735. "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
  1736. pf->hw.aq.asq_last_status);
  1737. goto command_write_done;
  1738. }
  1739. }
  1740. } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
  1741. u16 buffer_len, bytes;
  1742. u16 module;
  1743. u32 offset;
  1744. u16 *buff;
  1745. int ret;
  1746. cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
  1747. &module, &offset, &buffer_len);
  1748. if (cnt == 0) {
  1749. module = 0;
  1750. offset = 0;
  1751. buffer_len = 0;
  1752. } else if (cnt == 1) {
  1753. offset = 0;
  1754. buffer_len = 0;
  1755. } else if (cnt == 2) {
  1756. buffer_len = 0;
  1757. } else if (cnt > 3) {
  1758. dev_info(&pf->pdev->dev,
  1759. "nvm read: bad command string, cnt=%d\n", cnt);
  1760. goto command_write_done;
  1761. }
  1762. /* set the max length */
  1763. buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
  1764. bytes = 2 * buffer_len;
  1765. /* read at least 1k bytes, no more than 4kB */
  1766. bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
  1767. buff = kzalloc(bytes, GFP_KERNEL);
  1768. if (!buff)
  1769. goto command_write_done;
  1770. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  1771. if (ret) {
  1772. dev_info(&pf->pdev->dev,
  1773. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1774. ret, pf->hw.aq.asq_last_status);
  1775. kfree(buff);
  1776. goto command_write_done;
  1777. }
  1778. ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
  1779. bytes, (u8 *)buff, true, NULL);
  1780. i40e_release_nvm(&pf->hw);
  1781. if (ret) {
  1782. dev_info(&pf->pdev->dev,
  1783. "Read NVM AQ failed err=%d status=0x%x\n",
  1784. ret, pf->hw.aq.asq_last_status);
  1785. } else {
  1786. dev_info(&pf->pdev->dev,
  1787. "Read NVM module=0x%x offset=0x%x words=%d\n",
  1788. module, offset, buffer_len);
  1789. if (bytes)
  1790. print_hex_dump(KERN_INFO, "NVM Dump: ",
  1791. DUMP_PREFIX_OFFSET, 16, 2,
  1792. buff, bytes, true);
  1793. }
  1794. kfree(buff);
  1795. buff = NULL;
  1796. } else {
  1797. dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
  1798. dev_info(&pf->pdev->dev, "available commands\n");
  1799. dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
  1800. dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
  1801. dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
  1802. dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
  1803. dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
  1804. dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
  1805. dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
  1806. dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
  1807. dev_info(&pf->pdev->dev, " dump switch\n");
  1808. dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
  1809. dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
  1810. dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
  1811. dev_info(&pf->pdev->dev, " dump desc aq\n");
  1812. dev_info(&pf->pdev->dev, " dump reset stats\n");
  1813. dev_info(&pf->pdev->dev, " dump debug fwdata <cluster_id> <table_id> <index>\n");
  1814. dev_info(&pf->pdev->dev, " msg_enable [level]\n");
  1815. dev_info(&pf->pdev->dev, " read <reg>\n");
  1816. dev_info(&pf->pdev->dev, " write <reg> <value>\n");
  1817. dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
  1818. dev_info(&pf->pdev->dev, " clear_stats port\n");
  1819. dev_info(&pf->pdev->dev, " pfr\n");
  1820. dev_info(&pf->pdev->dev, " corer\n");
  1821. dev_info(&pf->pdev->dev, " globr\n");
  1822. dev_info(&pf->pdev->dev, " send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n");
  1823. dev_info(&pf->pdev->dev, " send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n");
  1824. 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");
  1825. 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");
  1826. dev_info(&pf->pdev->dev, " fd-atr off\n");
  1827. dev_info(&pf->pdev->dev, " fd-atr on\n");
  1828. dev_info(&pf->pdev->dev, " fd current cnt");
  1829. dev_info(&pf->pdev->dev, " lldp start\n");
  1830. dev_info(&pf->pdev->dev, " lldp stop\n");
  1831. dev_info(&pf->pdev->dev, " lldp get local\n");
  1832. dev_info(&pf->pdev->dev, " lldp get remote\n");
  1833. dev_info(&pf->pdev->dev, " lldp event on\n");
  1834. dev_info(&pf->pdev->dev, " lldp event off\n");
  1835. dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
  1836. }
  1837. command_write_done:
  1838. kfree(cmd_buf);
  1839. cmd_buf = NULL;
  1840. return count;
  1841. }
  1842. static const struct file_operations i40e_dbg_command_fops = {
  1843. .owner = THIS_MODULE,
  1844. .open = simple_open,
  1845. .read = i40e_dbg_command_read,
  1846. .write = i40e_dbg_command_write,
  1847. };
  1848. /**************************************************************
  1849. * netdev_ops
  1850. * The netdev_ops entry in debugfs is for giving the driver commands
  1851. * to be executed from the netdev operations.
  1852. **************************************************************/
  1853. static char i40e_dbg_netdev_ops_buf[256] = "";
  1854. /**
  1855. * i40e_dbg_netdev_ops - read for netdev_ops datum
  1856. * @filp: the opened file
  1857. * @buffer: where to write the data for the user to read
  1858. * @count: the size of the user's buffer
  1859. * @ppos: file position offset
  1860. **/
  1861. static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
  1862. size_t count, loff_t *ppos)
  1863. {
  1864. struct i40e_pf *pf = filp->private_data;
  1865. int bytes_not_copied;
  1866. int buf_size = 256;
  1867. char *buf;
  1868. int len;
  1869. /* don't allow partal reads */
  1870. if (*ppos != 0)
  1871. return 0;
  1872. if (count < buf_size)
  1873. return -ENOSPC;
  1874. buf = kzalloc(buf_size, GFP_KERNEL);
  1875. if (!buf)
  1876. return -ENOSPC;
  1877. len = snprintf(buf, buf_size, "%s: %s\n",
  1878. pf->vsi[pf->lan_vsi]->netdev->name,
  1879. i40e_dbg_netdev_ops_buf);
  1880. bytes_not_copied = copy_to_user(buffer, buf, len);
  1881. kfree(buf);
  1882. if (bytes_not_copied < 0)
  1883. return bytes_not_copied;
  1884. *ppos = len;
  1885. return len;
  1886. }
  1887. /**
  1888. * i40e_dbg_netdev_ops_write - write into netdev_ops datum
  1889. * @filp: the opened file
  1890. * @buffer: where to find the user's data
  1891. * @count: the length of the user's data
  1892. * @ppos: file position offset
  1893. **/
  1894. static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
  1895. const char __user *buffer,
  1896. size_t count, loff_t *ppos)
  1897. {
  1898. struct i40e_pf *pf = filp->private_data;
  1899. int bytes_not_copied;
  1900. struct i40e_vsi *vsi;
  1901. char *buf_tmp;
  1902. int vsi_seid;
  1903. int i, cnt;
  1904. /* don't allow partial writes */
  1905. if (*ppos != 0)
  1906. return 0;
  1907. if (count >= sizeof(i40e_dbg_netdev_ops_buf))
  1908. return -ENOSPC;
  1909. memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
  1910. bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
  1911. buffer, count);
  1912. if (bytes_not_copied < 0)
  1913. return bytes_not_copied;
  1914. else if (bytes_not_copied > 0)
  1915. count -= bytes_not_copied;
  1916. i40e_dbg_netdev_ops_buf[count] = '\0';
  1917. buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
  1918. if (buf_tmp) {
  1919. *buf_tmp = '\0';
  1920. count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
  1921. }
  1922. if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
  1923. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1924. if (cnt != 1) {
  1925. dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
  1926. goto netdev_ops_write_done;
  1927. }
  1928. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1929. if (!vsi) {
  1930. dev_info(&pf->pdev->dev,
  1931. "tx_timeout: VSI %d not found\n", vsi_seid);
  1932. } else if (!vsi->netdev) {
  1933. dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n",
  1934. vsi_seid);
  1935. } else if (test_bit(__I40E_DOWN, &vsi->state)) {
  1936. dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n",
  1937. vsi_seid);
  1938. } else if (rtnl_trylock()) {
  1939. vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
  1940. rtnl_unlock();
  1941. dev_info(&pf->pdev->dev, "tx_timeout called\n");
  1942. } else {
  1943. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1944. }
  1945. } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
  1946. int mtu;
  1947. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
  1948. &vsi_seid, &mtu);
  1949. if (cnt != 2) {
  1950. dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
  1951. goto netdev_ops_write_done;
  1952. }
  1953. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1954. if (!vsi) {
  1955. dev_info(&pf->pdev->dev,
  1956. "change_mtu: VSI %d not found\n", vsi_seid);
  1957. } else if (!vsi->netdev) {
  1958. dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n",
  1959. vsi_seid);
  1960. } else if (rtnl_trylock()) {
  1961. vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
  1962. mtu);
  1963. rtnl_unlock();
  1964. dev_info(&pf->pdev->dev, "change_mtu called\n");
  1965. } else {
  1966. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1967. }
  1968. } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
  1969. cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
  1970. if (cnt != 1) {
  1971. dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
  1972. goto netdev_ops_write_done;
  1973. }
  1974. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1975. if (!vsi) {
  1976. dev_info(&pf->pdev->dev,
  1977. "set_rx_mode: VSI %d not found\n", vsi_seid);
  1978. } else if (!vsi->netdev) {
  1979. dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n",
  1980. vsi_seid);
  1981. } else if (rtnl_trylock()) {
  1982. vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
  1983. rtnl_unlock();
  1984. dev_info(&pf->pdev->dev, "set_rx_mode called\n");
  1985. } else {
  1986. dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
  1987. }
  1988. } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
  1989. cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
  1990. if (cnt != 1) {
  1991. dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
  1992. goto netdev_ops_write_done;
  1993. }
  1994. vsi = i40e_dbg_find_vsi(pf, vsi_seid);
  1995. if (!vsi) {
  1996. dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
  1997. vsi_seid);
  1998. } else if (!vsi->netdev) {
  1999. dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n",
  2000. vsi_seid);
  2001. } else {
  2002. for (i = 0; i < vsi->num_q_vectors; i++)
  2003. napi_schedule(&vsi->q_vectors[i]->napi);
  2004. dev_info(&pf->pdev->dev, "napi called\n");
  2005. }
  2006. } else {
  2007. dev_info(&pf->pdev->dev, "unknown command '%s'\n",
  2008. i40e_dbg_netdev_ops_buf);
  2009. dev_info(&pf->pdev->dev, "available commands\n");
  2010. dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
  2011. dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
  2012. dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
  2013. dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
  2014. }
  2015. netdev_ops_write_done:
  2016. return count;
  2017. }
  2018. static const struct file_operations i40e_dbg_netdev_ops_fops = {
  2019. .owner = THIS_MODULE,
  2020. .open = simple_open,
  2021. .read = i40e_dbg_netdev_ops_read,
  2022. .write = i40e_dbg_netdev_ops_write,
  2023. };
  2024. /**
  2025. * i40e_dbg_pf_init - setup the debugfs directory for the PF
  2026. * @pf: the PF that is starting up
  2027. **/
  2028. void i40e_dbg_pf_init(struct i40e_pf *pf)
  2029. {
  2030. struct dentry *pfile;
  2031. const char *name = pci_name(pf->pdev);
  2032. const struct device *dev = &pf->pdev->dev;
  2033. pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
  2034. if (!pf->i40e_dbg_pf)
  2035. return;
  2036. pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
  2037. &i40e_dbg_command_fops);
  2038. if (!pfile)
  2039. goto create_failed;
  2040. pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf,
  2041. &i40e_dbg_dump_fops);
  2042. if (!pfile)
  2043. goto create_failed;
  2044. pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
  2045. &i40e_dbg_netdev_ops_fops);
  2046. if (!pfile)
  2047. goto create_failed;
  2048. return;
  2049. create_failed:
  2050. dev_info(dev, "debugfs dir/file for %s failed\n", name);
  2051. debugfs_remove_recursive(pf->i40e_dbg_pf);
  2052. return;
  2053. }
  2054. /**
  2055. * i40e_dbg_pf_exit - clear out the PF's debugfs entries
  2056. * @pf: the PF that is stopping
  2057. **/
  2058. void i40e_dbg_pf_exit(struct i40e_pf *pf)
  2059. {
  2060. debugfs_remove_recursive(pf->i40e_dbg_pf);
  2061. pf->i40e_dbg_pf = NULL;
  2062. kfree(i40e_dbg_dump_buf);
  2063. i40e_dbg_dump_buf = NULL;
  2064. }
  2065. /**
  2066. * i40e_dbg_init - start up debugfs for the driver
  2067. **/
  2068. void i40e_dbg_init(void)
  2069. {
  2070. i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
  2071. if (!i40e_dbg_root)
  2072. pr_info("init of debugfs failed\n");
  2073. }
  2074. /**
  2075. * i40e_dbg_exit - clean out the driver's debugfs entries
  2076. **/
  2077. void i40e_dbg_exit(void)
  2078. {
  2079. debugfs_remove_recursive(i40e_dbg_root);
  2080. i40e_dbg_root = NULL;
  2081. }
  2082. #endif /* CONFIG_DEBUG_FS */