i40e_debugfs.c 59 KB

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