i40e_debugfs.c 59 KB

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