netvsc_drv.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  1. /*
  2. * Copyright (c) 2009, Microsoft Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * Authors:
  17. * Haiyang Zhang <haiyangz@microsoft.com>
  18. * Hank Janssen <hjanssen@microsoft.com>
  19. */
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/init.h>
  22. #include <linux/atomic.h>
  23. #include <linux/module.h>
  24. #include <linux/highmem.h>
  25. #include <linux/device.h>
  26. #include <linux/io.h>
  27. #include <linux/delay.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/inetdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/pci.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/in.h>
  35. #include <linux/slab.h>
  36. #include <linux/rtnetlink.h>
  37. #include <linux/netpoll.h>
  38. #include <net/arp.h>
  39. #include <net/route.h>
  40. #include <net/sock.h>
  41. #include <net/pkt_sched.h>
  42. #include <net/checksum.h>
  43. #include <net/ip6_checksum.h>
  44. #include "hyperv_net.h"
  45. #define RING_SIZE_MIN 64
  46. #define RETRY_US_LO 5000
  47. #define RETRY_US_HI 10000
  48. #define RETRY_MAX 2000 /* >10 sec */
  49. #define LINKCHANGE_INT (2 * HZ)
  50. #define VF_TAKEOVER_INT (HZ / 10)
  51. static unsigned int ring_size __ro_after_init = 128;
  52. module_param(ring_size, uint, 0444);
  53. MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
  54. unsigned int netvsc_ring_bytes __ro_after_init;
  55. static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
  56. NETIF_MSG_LINK | NETIF_MSG_IFUP |
  57. NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
  58. NETIF_MSG_TX_ERR;
  59. static int debug = -1;
  60. module_param(debug, int, 0444);
  61. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  62. static LIST_HEAD(netvsc_dev_list);
  63. static void netvsc_change_rx_flags(struct net_device *net, int change)
  64. {
  65. struct net_device_context *ndev_ctx = netdev_priv(net);
  66. struct net_device *vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
  67. int inc;
  68. if (!vf_netdev)
  69. return;
  70. if (change & IFF_PROMISC) {
  71. inc = (net->flags & IFF_PROMISC) ? 1 : -1;
  72. dev_set_promiscuity(vf_netdev, inc);
  73. }
  74. if (change & IFF_ALLMULTI) {
  75. inc = (net->flags & IFF_ALLMULTI) ? 1 : -1;
  76. dev_set_allmulti(vf_netdev, inc);
  77. }
  78. }
  79. static void netvsc_set_rx_mode(struct net_device *net)
  80. {
  81. struct net_device_context *ndev_ctx = netdev_priv(net);
  82. struct net_device *vf_netdev;
  83. struct netvsc_device *nvdev;
  84. rcu_read_lock();
  85. vf_netdev = rcu_dereference(ndev_ctx->vf_netdev);
  86. if (vf_netdev) {
  87. dev_uc_sync(vf_netdev, net);
  88. dev_mc_sync(vf_netdev, net);
  89. }
  90. nvdev = rcu_dereference(ndev_ctx->nvdev);
  91. if (nvdev)
  92. rndis_filter_update(nvdev);
  93. rcu_read_unlock();
  94. }
  95. static int netvsc_open(struct net_device *net)
  96. {
  97. struct net_device_context *ndev_ctx = netdev_priv(net);
  98. struct net_device *vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
  99. struct netvsc_device *nvdev = rtnl_dereference(ndev_ctx->nvdev);
  100. struct rndis_device *rdev;
  101. int ret = 0;
  102. netif_carrier_off(net);
  103. /* Open up the device */
  104. ret = rndis_filter_open(nvdev);
  105. if (ret != 0) {
  106. netdev_err(net, "unable to open device (ret %d).\n", ret);
  107. return ret;
  108. }
  109. rdev = nvdev->extension;
  110. if (!rdev->link_state) {
  111. netif_carrier_on(net);
  112. netif_tx_wake_all_queues(net);
  113. }
  114. if (vf_netdev) {
  115. /* Setting synthetic device up transparently sets
  116. * slave as up. If open fails, then slave will be
  117. * still be offline (and not used).
  118. */
  119. ret = dev_open(vf_netdev);
  120. if (ret)
  121. netdev_warn(net,
  122. "unable to open slave: %s: %d\n",
  123. vf_netdev->name, ret);
  124. }
  125. return 0;
  126. }
  127. static int netvsc_wait_until_empty(struct netvsc_device *nvdev)
  128. {
  129. unsigned int retry = 0;
  130. int i;
  131. /* Ensure pending bytes in ring are read */
  132. for (;;) {
  133. u32 aread = 0;
  134. for (i = 0; i < nvdev->num_chn; i++) {
  135. struct vmbus_channel *chn
  136. = nvdev->chan_table[i].channel;
  137. if (!chn)
  138. continue;
  139. /* make sure receive not running now */
  140. napi_synchronize(&nvdev->chan_table[i].napi);
  141. aread = hv_get_bytes_to_read(&chn->inbound);
  142. if (aread)
  143. break;
  144. aread = hv_get_bytes_to_read(&chn->outbound);
  145. if (aread)
  146. break;
  147. }
  148. if (aread == 0)
  149. return 0;
  150. if (++retry > RETRY_MAX)
  151. return -ETIMEDOUT;
  152. usleep_range(RETRY_US_LO, RETRY_US_HI);
  153. }
  154. }
  155. static int netvsc_close(struct net_device *net)
  156. {
  157. struct net_device_context *net_device_ctx = netdev_priv(net);
  158. struct net_device *vf_netdev
  159. = rtnl_dereference(net_device_ctx->vf_netdev);
  160. struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
  161. int ret;
  162. netif_tx_disable(net);
  163. /* No need to close rndis filter if it is removed already */
  164. if (!nvdev)
  165. return 0;
  166. ret = rndis_filter_close(nvdev);
  167. if (ret != 0) {
  168. netdev_err(net, "unable to close device (ret %d).\n", ret);
  169. return ret;
  170. }
  171. ret = netvsc_wait_until_empty(nvdev);
  172. if (ret)
  173. netdev_err(net, "Ring buffer not empty after closing rndis\n");
  174. if (vf_netdev)
  175. dev_close(vf_netdev);
  176. return ret;
  177. }
  178. static inline void *init_ppi_data(struct rndis_message *msg,
  179. u32 ppi_size, u32 pkt_type)
  180. {
  181. struct rndis_packet *rndis_pkt = &msg->msg.pkt;
  182. struct rndis_per_packet_info *ppi;
  183. rndis_pkt->data_offset += ppi_size;
  184. ppi = (void *)rndis_pkt + rndis_pkt->per_pkt_info_offset
  185. + rndis_pkt->per_pkt_info_len;
  186. ppi->size = ppi_size;
  187. ppi->type = pkt_type;
  188. ppi->ppi_offset = sizeof(struct rndis_per_packet_info);
  189. rndis_pkt->per_pkt_info_len += ppi_size;
  190. return ppi + 1;
  191. }
  192. /* Azure hosts don't support non-TCP port numbers in hashing for fragmented
  193. * packets. We can use ethtool to change UDP hash level when necessary.
  194. */
  195. static inline u32 netvsc_get_hash(
  196. struct sk_buff *skb,
  197. const struct net_device_context *ndc)
  198. {
  199. struct flow_keys flow;
  200. u32 hash, pkt_proto = 0;
  201. static u32 hashrnd __read_mostly;
  202. net_get_random_once(&hashrnd, sizeof(hashrnd));
  203. if (!skb_flow_dissect_flow_keys(skb, &flow, 0))
  204. return 0;
  205. switch (flow.basic.ip_proto) {
  206. case IPPROTO_TCP:
  207. if (flow.basic.n_proto == htons(ETH_P_IP))
  208. pkt_proto = HV_TCP4_L4HASH;
  209. else if (flow.basic.n_proto == htons(ETH_P_IPV6))
  210. pkt_proto = HV_TCP6_L4HASH;
  211. break;
  212. case IPPROTO_UDP:
  213. if (flow.basic.n_proto == htons(ETH_P_IP))
  214. pkt_proto = HV_UDP4_L4HASH;
  215. else if (flow.basic.n_proto == htons(ETH_P_IPV6))
  216. pkt_proto = HV_UDP6_L4HASH;
  217. break;
  218. }
  219. if (pkt_proto & ndc->l4_hash) {
  220. return skb_get_hash(skb);
  221. } else {
  222. if (flow.basic.n_proto == htons(ETH_P_IP))
  223. hash = jhash2((u32 *)&flow.addrs.v4addrs, 2, hashrnd);
  224. else if (flow.basic.n_proto == htons(ETH_P_IPV6))
  225. hash = jhash2((u32 *)&flow.addrs.v6addrs, 8, hashrnd);
  226. else
  227. hash = 0;
  228. skb_set_hash(skb, hash, PKT_HASH_TYPE_L3);
  229. }
  230. return hash;
  231. }
  232. static inline int netvsc_get_tx_queue(struct net_device *ndev,
  233. struct sk_buff *skb, int old_idx)
  234. {
  235. const struct net_device_context *ndc = netdev_priv(ndev);
  236. struct sock *sk = skb->sk;
  237. int q_idx;
  238. q_idx = ndc->tx_table[netvsc_get_hash(skb, ndc) &
  239. (VRSS_SEND_TAB_SIZE - 1)];
  240. /* If queue index changed record the new value */
  241. if (q_idx != old_idx &&
  242. sk && sk_fullsock(sk) && rcu_access_pointer(sk->sk_dst_cache))
  243. sk_tx_queue_set(sk, q_idx);
  244. return q_idx;
  245. }
  246. /*
  247. * Select queue for transmit.
  248. *
  249. * If a valid queue has already been assigned, then use that.
  250. * Otherwise compute tx queue based on hash and the send table.
  251. *
  252. * This is basically similar to default (__netdev_pick_tx) with the added step
  253. * of using the host send_table when no other queue has been assigned.
  254. *
  255. * TODO support XPS - but get_xps_queue not exported
  256. */
  257. static u16 netvsc_pick_tx(struct net_device *ndev, struct sk_buff *skb)
  258. {
  259. int q_idx = sk_tx_queue_get(skb->sk);
  260. if (q_idx < 0 || skb->ooo_okay || q_idx >= ndev->real_num_tx_queues) {
  261. /* If forwarding a packet, we use the recorded queue when
  262. * available for better cache locality.
  263. */
  264. if (skb_rx_queue_recorded(skb))
  265. q_idx = skb_get_rx_queue(skb);
  266. else
  267. q_idx = netvsc_get_tx_queue(ndev, skb, q_idx);
  268. }
  269. return q_idx;
  270. }
  271. static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb,
  272. struct net_device *sb_dev,
  273. select_queue_fallback_t fallback)
  274. {
  275. struct net_device_context *ndc = netdev_priv(ndev);
  276. struct net_device *vf_netdev;
  277. u16 txq;
  278. rcu_read_lock();
  279. vf_netdev = rcu_dereference(ndc->vf_netdev);
  280. if (vf_netdev) {
  281. const struct net_device_ops *vf_ops = vf_netdev->netdev_ops;
  282. if (vf_ops->ndo_select_queue)
  283. txq = vf_ops->ndo_select_queue(vf_netdev, skb,
  284. sb_dev, fallback);
  285. else
  286. txq = fallback(vf_netdev, skb, NULL);
  287. /* Record the queue selected by VF so that it can be
  288. * used for common case where VF has more queues than
  289. * the synthetic device.
  290. */
  291. qdisc_skb_cb(skb)->slave_dev_queue_mapping = txq;
  292. } else {
  293. txq = netvsc_pick_tx(ndev, skb);
  294. }
  295. rcu_read_unlock();
  296. while (unlikely(txq >= ndev->real_num_tx_queues))
  297. txq -= ndev->real_num_tx_queues;
  298. return txq;
  299. }
  300. static u32 fill_pg_buf(struct page *page, u32 offset, u32 len,
  301. struct hv_page_buffer *pb)
  302. {
  303. int j = 0;
  304. /* Deal with compund pages by ignoring unused part
  305. * of the page.
  306. */
  307. page += (offset >> PAGE_SHIFT);
  308. offset &= ~PAGE_MASK;
  309. while (len > 0) {
  310. unsigned long bytes;
  311. bytes = PAGE_SIZE - offset;
  312. if (bytes > len)
  313. bytes = len;
  314. pb[j].pfn = page_to_pfn(page);
  315. pb[j].offset = offset;
  316. pb[j].len = bytes;
  317. offset += bytes;
  318. len -= bytes;
  319. if (offset == PAGE_SIZE && len) {
  320. page++;
  321. offset = 0;
  322. j++;
  323. }
  324. }
  325. return j + 1;
  326. }
  327. static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
  328. struct hv_netvsc_packet *packet,
  329. struct hv_page_buffer *pb)
  330. {
  331. u32 slots_used = 0;
  332. char *data = skb->data;
  333. int frags = skb_shinfo(skb)->nr_frags;
  334. int i;
  335. /* The packet is laid out thus:
  336. * 1. hdr: RNDIS header and PPI
  337. * 2. skb linear data
  338. * 3. skb fragment data
  339. */
  340. slots_used += fill_pg_buf(virt_to_page(hdr),
  341. offset_in_page(hdr),
  342. len, &pb[slots_used]);
  343. packet->rmsg_size = len;
  344. packet->rmsg_pgcnt = slots_used;
  345. slots_used += fill_pg_buf(virt_to_page(data),
  346. offset_in_page(data),
  347. skb_headlen(skb), &pb[slots_used]);
  348. for (i = 0; i < frags; i++) {
  349. skb_frag_t *frag = skb_shinfo(skb)->frags + i;
  350. slots_used += fill_pg_buf(skb_frag_page(frag),
  351. frag->page_offset,
  352. skb_frag_size(frag), &pb[slots_used]);
  353. }
  354. return slots_used;
  355. }
  356. static int count_skb_frag_slots(struct sk_buff *skb)
  357. {
  358. int i, frags = skb_shinfo(skb)->nr_frags;
  359. int pages = 0;
  360. for (i = 0; i < frags; i++) {
  361. skb_frag_t *frag = skb_shinfo(skb)->frags + i;
  362. unsigned long size = skb_frag_size(frag);
  363. unsigned long offset = frag->page_offset;
  364. /* Skip unused frames from start of page */
  365. offset &= ~PAGE_MASK;
  366. pages += PFN_UP(offset + size);
  367. }
  368. return pages;
  369. }
  370. static int netvsc_get_slots(struct sk_buff *skb)
  371. {
  372. char *data = skb->data;
  373. unsigned int offset = offset_in_page(data);
  374. unsigned int len = skb_headlen(skb);
  375. int slots;
  376. int frag_slots;
  377. slots = DIV_ROUND_UP(offset + len, PAGE_SIZE);
  378. frag_slots = count_skb_frag_slots(skb);
  379. return slots + frag_slots;
  380. }
  381. static u32 net_checksum_info(struct sk_buff *skb)
  382. {
  383. if (skb->protocol == htons(ETH_P_IP)) {
  384. struct iphdr *ip = ip_hdr(skb);
  385. if (ip->protocol == IPPROTO_TCP)
  386. return TRANSPORT_INFO_IPV4_TCP;
  387. else if (ip->protocol == IPPROTO_UDP)
  388. return TRANSPORT_INFO_IPV4_UDP;
  389. } else {
  390. struct ipv6hdr *ip6 = ipv6_hdr(skb);
  391. if (ip6->nexthdr == IPPROTO_TCP)
  392. return TRANSPORT_INFO_IPV6_TCP;
  393. else if (ip6->nexthdr == IPPROTO_UDP)
  394. return TRANSPORT_INFO_IPV6_UDP;
  395. }
  396. return TRANSPORT_INFO_NOT_IP;
  397. }
  398. /* Send skb on the slave VF device. */
  399. static int netvsc_vf_xmit(struct net_device *net, struct net_device *vf_netdev,
  400. struct sk_buff *skb)
  401. {
  402. struct net_device_context *ndev_ctx = netdev_priv(net);
  403. unsigned int len = skb->len;
  404. int rc;
  405. skb->dev = vf_netdev;
  406. skb->queue_mapping = qdisc_skb_cb(skb)->slave_dev_queue_mapping;
  407. rc = dev_queue_xmit(skb);
  408. if (likely(rc == NET_XMIT_SUCCESS || rc == NET_XMIT_CN)) {
  409. struct netvsc_vf_pcpu_stats *pcpu_stats
  410. = this_cpu_ptr(ndev_ctx->vf_stats);
  411. u64_stats_update_begin(&pcpu_stats->syncp);
  412. pcpu_stats->tx_packets++;
  413. pcpu_stats->tx_bytes += len;
  414. u64_stats_update_end(&pcpu_stats->syncp);
  415. } else {
  416. this_cpu_inc(ndev_ctx->vf_stats->tx_dropped);
  417. }
  418. return rc;
  419. }
  420. static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
  421. {
  422. struct net_device_context *net_device_ctx = netdev_priv(net);
  423. struct hv_netvsc_packet *packet = NULL;
  424. int ret;
  425. unsigned int num_data_pgs;
  426. struct rndis_message *rndis_msg;
  427. struct net_device *vf_netdev;
  428. u32 rndis_msg_size;
  429. u32 hash;
  430. struct hv_page_buffer pb[MAX_PAGE_BUFFER_COUNT];
  431. /* if VF is present and up then redirect packets
  432. * already called with rcu_read_lock_bh
  433. */
  434. vf_netdev = rcu_dereference_bh(net_device_ctx->vf_netdev);
  435. if (vf_netdev && netif_running(vf_netdev) &&
  436. !netpoll_tx_running(net))
  437. return netvsc_vf_xmit(net, vf_netdev, skb);
  438. /* We will atmost need two pages to describe the rndis
  439. * header. We can only transmit MAX_PAGE_BUFFER_COUNT number
  440. * of pages in a single packet. If skb is scattered around
  441. * more pages we try linearizing it.
  442. */
  443. num_data_pgs = netvsc_get_slots(skb) + 2;
  444. if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) {
  445. ++net_device_ctx->eth_stats.tx_scattered;
  446. if (skb_linearize(skb))
  447. goto no_memory;
  448. num_data_pgs = netvsc_get_slots(skb) + 2;
  449. if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) {
  450. ++net_device_ctx->eth_stats.tx_too_big;
  451. goto drop;
  452. }
  453. }
  454. /*
  455. * Place the rndis header in the skb head room and
  456. * the skb->cb will be used for hv_netvsc_packet
  457. * structure.
  458. */
  459. ret = skb_cow_head(skb, RNDIS_AND_PPI_SIZE);
  460. if (ret)
  461. goto no_memory;
  462. /* Use the skb control buffer for building up the packet */
  463. BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) >
  464. FIELD_SIZEOF(struct sk_buff, cb));
  465. packet = (struct hv_netvsc_packet *)skb->cb;
  466. packet->q_idx = skb_get_queue_mapping(skb);
  467. packet->total_data_buflen = skb->len;
  468. packet->total_bytes = skb->len;
  469. packet->total_packets = 1;
  470. rndis_msg = (struct rndis_message *)skb->head;
  471. /* Add the rndis header */
  472. rndis_msg->ndis_msg_type = RNDIS_MSG_PACKET;
  473. rndis_msg->msg_len = packet->total_data_buflen;
  474. rndis_msg->msg.pkt = (struct rndis_packet) {
  475. .data_offset = sizeof(struct rndis_packet),
  476. .data_len = packet->total_data_buflen,
  477. .per_pkt_info_offset = sizeof(struct rndis_packet),
  478. };
  479. rndis_msg_size = RNDIS_MESSAGE_SIZE(struct rndis_packet);
  480. hash = skb_get_hash_raw(skb);
  481. if (hash != 0 && net->real_num_tx_queues > 1) {
  482. u32 *hash_info;
  483. rndis_msg_size += NDIS_HASH_PPI_SIZE;
  484. hash_info = init_ppi_data(rndis_msg, NDIS_HASH_PPI_SIZE,
  485. NBL_HASH_VALUE);
  486. *hash_info = hash;
  487. }
  488. if (skb_vlan_tag_present(skb)) {
  489. struct ndis_pkt_8021q_info *vlan;
  490. rndis_msg_size += NDIS_VLAN_PPI_SIZE;
  491. vlan = init_ppi_data(rndis_msg, NDIS_VLAN_PPI_SIZE,
  492. IEEE_8021Q_INFO);
  493. vlan->value = 0;
  494. vlan->vlanid = skb->vlan_tci & VLAN_VID_MASK;
  495. vlan->pri = (skb->vlan_tci & VLAN_PRIO_MASK) >>
  496. VLAN_PRIO_SHIFT;
  497. }
  498. if (skb_is_gso(skb)) {
  499. struct ndis_tcp_lso_info *lso_info;
  500. rndis_msg_size += NDIS_LSO_PPI_SIZE;
  501. lso_info = init_ppi_data(rndis_msg, NDIS_LSO_PPI_SIZE,
  502. TCP_LARGESEND_PKTINFO);
  503. lso_info->value = 0;
  504. lso_info->lso_v2_transmit.type = NDIS_TCP_LARGE_SEND_OFFLOAD_V2_TYPE;
  505. if (skb->protocol == htons(ETH_P_IP)) {
  506. lso_info->lso_v2_transmit.ip_version =
  507. NDIS_TCP_LARGE_SEND_OFFLOAD_IPV4;
  508. ip_hdr(skb)->tot_len = 0;
  509. ip_hdr(skb)->check = 0;
  510. tcp_hdr(skb)->check =
  511. ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  512. ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  513. } else {
  514. lso_info->lso_v2_transmit.ip_version =
  515. NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6;
  516. ipv6_hdr(skb)->payload_len = 0;
  517. tcp_hdr(skb)->check =
  518. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  519. &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  520. }
  521. lso_info->lso_v2_transmit.tcp_header_offset = skb_transport_offset(skb);
  522. lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size;
  523. } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
  524. if (net_checksum_info(skb) & net_device_ctx->tx_checksum_mask) {
  525. struct ndis_tcp_ip_checksum_info *csum_info;
  526. rndis_msg_size += NDIS_CSUM_PPI_SIZE;
  527. csum_info = init_ppi_data(rndis_msg, NDIS_CSUM_PPI_SIZE,
  528. TCPIP_CHKSUM_PKTINFO);
  529. csum_info->value = 0;
  530. csum_info->transmit.tcp_header_offset = skb_transport_offset(skb);
  531. if (skb->protocol == htons(ETH_P_IP)) {
  532. csum_info->transmit.is_ipv4 = 1;
  533. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  534. csum_info->transmit.tcp_checksum = 1;
  535. else
  536. csum_info->transmit.udp_checksum = 1;
  537. } else {
  538. csum_info->transmit.is_ipv6 = 1;
  539. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  540. csum_info->transmit.tcp_checksum = 1;
  541. else
  542. csum_info->transmit.udp_checksum = 1;
  543. }
  544. } else {
  545. /* Can't do offload of this type of checksum */
  546. if (skb_checksum_help(skb))
  547. goto drop;
  548. }
  549. }
  550. /* Start filling in the page buffers with the rndis hdr */
  551. rndis_msg->msg_len += rndis_msg_size;
  552. packet->total_data_buflen = rndis_msg->msg_len;
  553. packet->page_buf_cnt = init_page_array(rndis_msg, rndis_msg_size,
  554. skb, packet, pb);
  555. /* timestamp packet in software */
  556. skb_tx_timestamp(skb);
  557. ret = netvsc_send(net, packet, rndis_msg, pb, skb);
  558. if (likely(ret == 0))
  559. return NETDEV_TX_OK;
  560. if (ret == -EAGAIN) {
  561. ++net_device_ctx->eth_stats.tx_busy;
  562. return NETDEV_TX_BUSY;
  563. }
  564. if (ret == -ENOSPC)
  565. ++net_device_ctx->eth_stats.tx_no_space;
  566. drop:
  567. dev_kfree_skb_any(skb);
  568. net->stats.tx_dropped++;
  569. return NETDEV_TX_OK;
  570. no_memory:
  571. ++net_device_ctx->eth_stats.tx_no_memory;
  572. goto drop;
  573. }
  574. /*
  575. * netvsc_linkstatus_callback - Link up/down notification
  576. */
  577. void netvsc_linkstatus_callback(struct net_device *net,
  578. struct rndis_message *resp)
  579. {
  580. struct rndis_indicate_status *indicate = &resp->msg.indicate_status;
  581. struct net_device_context *ndev_ctx = netdev_priv(net);
  582. struct netvsc_reconfig *event;
  583. unsigned long flags;
  584. /* Update the physical link speed when changing to another vSwitch */
  585. if (indicate->status == RNDIS_STATUS_LINK_SPEED_CHANGE) {
  586. u32 speed;
  587. speed = *(u32 *)((void *)indicate
  588. + indicate->status_buf_offset) / 10000;
  589. ndev_ctx->speed = speed;
  590. return;
  591. }
  592. /* Handle these link change statuses below */
  593. if (indicate->status != RNDIS_STATUS_NETWORK_CHANGE &&
  594. indicate->status != RNDIS_STATUS_MEDIA_CONNECT &&
  595. indicate->status != RNDIS_STATUS_MEDIA_DISCONNECT)
  596. return;
  597. if (net->reg_state != NETREG_REGISTERED)
  598. return;
  599. event = kzalloc(sizeof(*event), GFP_ATOMIC);
  600. if (!event)
  601. return;
  602. event->event = indicate->status;
  603. spin_lock_irqsave(&ndev_ctx->lock, flags);
  604. list_add_tail(&event->list, &ndev_ctx->reconfig_events);
  605. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  606. schedule_delayed_work(&ndev_ctx->dwork, 0);
  607. }
  608. static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
  609. struct napi_struct *napi,
  610. const struct ndis_tcp_ip_checksum_info *csum_info,
  611. const struct ndis_pkt_8021q_info *vlan,
  612. void *data, u32 buflen)
  613. {
  614. struct sk_buff *skb;
  615. skb = napi_alloc_skb(napi, buflen);
  616. if (!skb)
  617. return skb;
  618. /*
  619. * Copy to skb. This copy is needed here since the memory pointed by
  620. * hv_netvsc_packet cannot be deallocated
  621. */
  622. skb_put_data(skb, data, buflen);
  623. skb->protocol = eth_type_trans(skb, net);
  624. /* skb is already created with CHECKSUM_NONE */
  625. skb_checksum_none_assert(skb);
  626. /*
  627. * In Linux, the IP checksum is always checked.
  628. * Do L4 checksum offload if enabled and present.
  629. */
  630. if (csum_info && (net->features & NETIF_F_RXCSUM)) {
  631. if (csum_info->receive.tcp_checksum_succeeded ||
  632. csum_info->receive.udp_checksum_succeeded)
  633. skb->ip_summed = CHECKSUM_UNNECESSARY;
  634. }
  635. if (vlan) {
  636. u16 vlan_tci = vlan->vlanid | (vlan->pri << VLAN_PRIO_SHIFT);
  637. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  638. vlan_tci);
  639. }
  640. return skb;
  641. }
  642. /*
  643. * netvsc_recv_callback - Callback when we receive a packet from the
  644. * "wire" on the specified device.
  645. */
  646. int netvsc_recv_callback(struct net_device *net,
  647. struct netvsc_device *net_device,
  648. struct vmbus_channel *channel,
  649. void *data, u32 len,
  650. const struct ndis_tcp_ip_checksum_info *csum_info,
  651. const struct ndis_pkt_8021q_info *vlan)
  652. {
  653. struct net_device_context *net_device_ctx = netdev_priv(net);
  654. u16 q_idx = channel->offermsg.offer.sub_channel_index;
  655. struct netvsc_channel *nvchan = &net_device->chan_table[q_idx];
  656. struct sk_buff *skb;
  657. struct netvsc_stats *rx_stats;
  658. if (net->reg_state != NETREG_REGISTERED)
  659. return NVSP_STAT_FAIL;
  660. /* Allocate a skb - TODO direct I/O to pages? */
  661. skb = netvsc_alloc_recv_skb(net, &nvchan->napi,
  662. csum_info, vlan, data, len);
  663. if (unlikely(!skb)) {
  664. ++net_device_ctx->eth_stats.rx_no_memory;
  665. rcu_read_unlock();
  666. return NVSP_STAT_FAIL;
  667. }
  668. skb_record_rx_queue(skb, q_idx);
  669. /*
  670. * Even if injecting the packet, record the statistics
  671. * on the synthetic device because modifying the VF device
  672. * statistics will not work correctly.
  673. */
  674. rx_stats = &nvchan->rx_stats;
  675. u64_stats_update_begin(&rx_stats->syncp);
  676. rx_stats->packets++;
  677. rx_stats->bytes += len;
  678. if (skb->pkt_type == PACKET_BROADCAST)
  679. ++rx_stats->broadcast;
  680. else if (skb->pkt_type == PACKET_MULTICAST)
  681. ++rx_stats->multicast;
  682. u64_stats_update_end(&rx_stats->syncp);
  683. napi_gro_receive(&nvchan->napi, skb);
  684. return NVSP_STAT_SUCCESS;
  685. }
  686. static void netvsc_get_drvinfo(struct net_device *net,
  687. struct ethtool_drvinfo *info)
  688. {
  689. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  690. strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
  691. }
  692. static void netvsc_get_channels(struct net_device *net,
  693. struct ethtool_channels *channel)
  694. {
  695. struct net_device_context *net_device_ctx = netdev_priv(net);
  696. struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
  697. if (nvdev) {
  698. channel->max_combined = nvdev->max_chn;
  699. channel->combined_count = nvdev->num_chn;
  700. }
  701. }
  702. static int netvsc_detach(struct net_device *ndev,
  703. struct netvsc_device *nvdev)
  704. {
  705. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  706. struct hv_device *hdev = ndev_ctx->device_ctx;
  707. int ret;
  708. /* Don't try continuing to try and setup sub channels */
  709. if (cancel_work_sync(&nvdev->subchan_work))
  710. nvdev->num_chn = 1;
  711. /* If device was up (receiving) then shutdown */
  712. if (netif_running(ndev)) {
  713. netif_tx_disable(ndev);
  714. ret = rndis_filter_close(nvdev);
  715. if (ret) {
  716. netdev_err(ndev,
  717. "unable to close device (ret %d).\n", ret);
  718. return ret;
  719. }
  720. ret = netvsc_wait_until_empty(nvdev);
  721. if (ret) {
  722. netdev_err(ndev,
  723. "Ring buffer not empty after closing rndis\n");
  724. return ret;
  725. }
  726. }
  727. netif_device_detach(ndev);
  728. rndis_filter_device_remove(hdev, nvdev);
  729. return 0;
  730. }
  731. static int netvsc_attach(struct net_device *ndev,
  732. struct netvsc_device_info *dev_info)
  733. {
  734. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  735. struct hv_device *hdev = ndev_ctx->device_ctx;
  736. struct netvsc_device *nvdev;
  737. struct rndis_device *rdev;
  738. int ret;
  739. nvdev = rndis_filter_device_add(hdev, dev_info);
  740. if (IS_ERR(nvdev))
  741. return PTR_ERR(nvdev);
  742. if (nvdev->num_chn > 1) {
  743. ret = rndis_set_subchannel(ndev, nvdev);
  744. /* if unavailable, just proceed with one queue */
  745. if (ret) {
  746. nvdev->max_chn = 1;
  747. nvdev->num_chn = 1;
  748. }
  749. }
  750. /* In any case device is now ready */
  751. netif_device_attach(ndev);
  752. /* Note: enable and attach happen when sub-channels setup */
  753. netif_carrier_off(ndev);
  754. if (netif_running(ndev)) {
  755. ret = rndis_filter_open(nvdev);
  756. if (ret)
  757. return ret;
  758. rdev = nvdev->extension;
  759. if (!rdev->link_state)
  760. netif_carrier_on(ndev);
  761. }
  762. return 0;
  763. }
  764. static int netvsc_set_channels(struct net_device *net,
  765. struct ethtool_channels *channels)
  766. {
  767. struct net_device_context *net_device_ctx = netdev_priv(net);
  768. struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
  769. unsigned int orig, count = channels->combined_count;
  770. struct netvsc_device_info device_info;
  771. int ret;
  772. /* We do not support separate count for rx, tx, or other */
  773. if (count == 0 ||
  774. channels->rx_count || channels->tx_count || channels->other_count)
  775. return -EINVAL;
  776. if (!nvdev || nvdev->destroy)
  777. return -ENODEV;
  778. if (nvdev->nvsp_version < NVSP_PROTOCOL_VERSION_5)
  779. return -EINVAL;
  780. if (count > nvdev->max_chn)
  781. return -EINVAL;
  782. orig = nvdev->num_chn;
  783. memset(&device_info, 0, sizeof(device_info));
  784. device_info.num_chn = count;
  785. device_info.send_sections = nvdev->send_section_cnt;
  786. device_info.send_section_size = nvdev->send_section_size;
  787. device_info.recv_sections = nvdev->recv_section_cnt;
  788. device_info.recv_section_size = nvdev->recv_section_size;
  789. ret = netvsc_detach(net, nvdev);
  790. if (ret)
  791. return ret;
  792. ret = netvsc_attach(net, &device_info);
  793. if (ret) {
  794. device_info.num_chn = orig;
  795. if (netvsc_attach(net, &device_info))
  796. netdev_err(net, "restoring channel setting failed\n");
  797. }
  798. return ret;
  799. }
  800. static bool
  801. netvsc_validate_ethtool_ss_cmd(const struct ethtool_link_ksettings *cmd)
  802. {
  803. struct ethtool_link_ksettings diff1 = *cmd;
  804. struct ethtool_link_ksettings diff2 = {};
  805. diff1.base.speed = 0;
  806. diff1.base.duplex = 0;
  807. /* advertising and cmd are usually set */
  808. ethtool_link_ksettings_zero_link_mode(&diff1, advertising);
  809. diff1.base.cmd = 0;
  810. /* We set port to PORT_OTHER */
  811. diff2.base.port = PORT_OTHER;
  812. return !memcmp(&diff1, &diff2, sizeof(diff1));
  813. }
  814. static void netvsc_init_settings(struct net_device *dev)
  815. {
  816. struct net_device_context *ndc = netdev_priv(dev);
  817. ndc->l4_hash = HV_DEFAULT_L4HASH;
  818. ndc->speed = SPEED_UNKNOWN;
  819. ndc->duplex = DUPLEX_FULL;
  820. }
  821. static int netvsc_get_link_ksettings(struct net_device *dev,
  822. struct ethtool_link_ksettings *cmd)
  823. {
  824. struct net_device_context *ndc = netdev_priv(dev);
  825. cmd->base.speed = ndc->speed;
  826. cmd->base.duplex = ndc->duplex;
  827. cmd->base.port = PORT_OTHER;
  828. return 0;
  829. }
  830. static int netvsc_set_link_ksettings(struct net_device *dev,
  831. const struct ethtool_link_ksettings *cmd)
  832. {
  833. struct net_device_context *ndc = netdev_priv(dev);
  834. u32 speed;
  835. speed = cmd->base.speed;
  836. if (!ethtool_validate_speed(speed) ||
  837. !ethtool_validate_duplex(cmd->base.duplex) ||
  838. !netvsc_validate_ethtool_ss_cmd(cmd))
  839. return -EINVAL;
  840. ndc->speed = speed;
  841. ndc->duplex = cmd->base.duplex;
  842. return 0;
  843. }
  844. static int netvsc_change_mtu(struct net_device *ndev, int mtu)
  845. {
  846. struct net_device_context *ndevctx = netdev_priv(ndev);
  847. struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev);
  848. struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
  849. int orig_mtu = ndev->mtu;
  850. struct netvsc_device_info device_info;
  851. int ret = 0;
  852. if (!nvdev || nvdev->destroy)
  853. return -ENODEV;
  854. /* Change MTU of underlying VF netdev first. */
  855. if (vf_netdev) {
  856. ret = dev_set_mtu(vf_netdev, mtu);
  857. if (ret)
  858. return ret;
  859. }
  860. memset(&device_info, 0, sizeof(device_info));
  861. device_info.num_chn = nvdev->num_chn;
  862. device_info.send_sections = nvdev->send_section_cnt;
  863. device_info.send_section_size = nvdev->send_section_size;
  864. device_info.recv_sections = nvdev->recv_section_cnt;
  865. device_info.recv_section_size = nvdev->recv_section_size;
  866. ret = netvsc_detach(ndev, nvdev);
  867. if (ret)
  868. goto rollback_vf;
  869. ndev->mtu = mtu;
  870. ret = netvsc_attach(ndev, &device_info);
  871. if (ret)
  872. goto rollback;
  873. return 0;
  874. rollback:
  875. /* Attempt rollback to original MTU */
  876. ndev->mtu = orig_mtu;
  877. if (netvsc_attach(ndev, &device_info))
  878. netdev_err(ndev, "restoring mtu failed\n");
  879. rollback_vf:
  880. if (vf_netdev)
  881. dev_set_mtu(vf_netdev, orig_mtu);
  882. return ret;
  883. }
  884. static void netvsc_get_vf_stats(struct net_device *net,
  885. struct netvsc_vf_pcpu_stats *tot)
  886. {
  887. struct net_device_context *ndev_ctx = netdev_priv(net);
  888. int i;
  889. memset(tot, 0, sizeof(*tot));
  890. for_each_possible_cpu(i) {
  891. const struct netvsc_vf_pcpu_stats *stats
  892. = per_cpu_ptr(ndev_ctx->vf_stats, i);
  893. u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
  894. unsigned int start;
  895. do {
  896. start = u64_stats_fetch_begin_irq(&stats->syncp);
  897. rx_packets = stats->rx_packets;
  898. tx_packets = stats->tx_packets;
  899. rx_bytes = stats->rx_bytes;
  900. tx_bytes = stats->tx_bytes;
  901. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  902. tot->rx_packets += rx_packets;
  903. tot->tx_packets += tx_packets;
  904. tot->rx_bytes += rx_bytes;
  905. tot->tx_bytes += tx_bytes;
  906. tot->tx_dropped += stats->tx_dropped;
  907. }
  908. }
  909. static void netvsc_get_pcpu_stats(struct net_device *net,
  910. struct netvsc_ethtool_pcpu_stats *pcpu_tot)
  911. {
  912. struct net_device_context *ndev_ctx = netdev_priv(net);
  913. struct netvsc_device *nvdev = rcu_dereference_rtnl(ndev_ctx->nvdev);
  914. int i;
  915. /* fetch percpu stats of vf */
  916. for_each_possible_cpu(i) {
  917. const struct netvsc_vf_pcpu_stats *stats =
  918. per_cpu_ptr(ndev_ctx->vf_stats, i);
  919. struct netvsc_ethtool_pcpu_stats *this_tot = &pcpu_tot[i];
  920. unsigned int start;
  921. do {
  922. start = u64_stats_fetch_begin_irq(&stats->syncp);
  923. this_tot->vf_rx_packets = stats->rx_packets;
  924. this_tot->vf_tx_packets = stats->tx_packets;
  925. this_tot->vf_rx_bytes = stats->rx_bytes;
  926. this_tot->vf_tx_bytes = stats->tx_bytes;
  927. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  928. this_tot->rx_packets = this_tot->vf_rx_packets;
  929. this_tot->tx_packets = this_tot->vf_tx_packets;
  930. this_tot->rx_bytes = this_tot->vf_rx_bytes;
  931. this_tot->tx_bytes = this_tot->vf_tx_bytes;
  932. }
  933. /* fetch percpu stats of netvsc */
  934. for (i = 0; i < nvdev->num_chn; i++) {
  935. const struct netvsc_channel *nvchan = &nvdev->chan_table[i];
  936. const struct netvsc_stats *stats;
  937. struct netvsc_ethtool_pcpu_stats *this_tot =
  938. &pcpu_tot[nvchan->channel->target_cpu];
  939. u64 packets, bytes;
  940. unsigned int start;
  941. stats = &nvchan->tx_stats;
  942. do {
  943. start = u64_stats_fetch_begin_irq(&stats->syncp);
  944. packets = stats->packets;
  945. bytes = stats->bytes;
  946. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  947. this_tot->tx_bytes += bytes;
  948. this_tot->tx_packets += packets;
  949. stats = &nvchan->rx_stats;
  950. do {
  951. start = u64_stats_fetch_begin_irq(&stats->syncp);
  952. packets = stats->packets;
  953. bytes = stats->bytes;
  954. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  955. this_tot->rx_bytes += bytes;
  956. this_tot->rx_packets += packets;
  957. }
  958. }
  959. static void netvsc_get_stats64(struct net_device *net,
  960. struct rtnl_link_stats64 *t)
  961. {
  962. struct net_device_context *ndev_ctx = netdev_priv(net);
  963. struct netvsc_device *nvdev = rcu_dereference_rtnl(ndev_ctx->nvdev);
  964. struct netvsc_vf_pcpu_stats vf_tot;
  965. int i;
  966. if (!nvdev)
  967. return;
  968. netdev_stats_to_stats64(t, &net->stats);
  969. netvsc_get_vf_stats(net, &vf_tot);
  970. t->rx_packets += vf_tot.rx_packets;
  971. t->tx_packets += vf_tot.tx_packets;
  972. t->rx_bytes += vf_tot.rx_bytes;
  973. t->tx_bytes += vf_tot.tx_bytes;
  974. t->tx_dropped += vf_tot.tx_dropped;
  975. for (i = 0; i < nvdev->num_chn; i++) {
  976. const struct netvsc_channel *nvchan = &nvdev->chan_table[i];
  977. const struct netvsc_stats *stats;
  978. u64 packets, bytes, multicast;
  979. unsigned int start;
  980. stats = &nvchan->tx_stats;
  981. do {
  982. start = u64_stats_fetch_begin_irq(&stats->syncp);
  983. packets = stats->packets;
  984. bytes = stats->bytes;
  985. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  986. t->tx_bytes += bytes;
  987. t->tx_packets += packets;
  988. stats = &nvchan->rx_stats;
  989. do {
  990. start = u64_stats_fetch_begin_irq(&stats->syncp);
  991. packets = stats->packets;
  992. bytes = stats->bytes;
  993. multicast = stats->multicast + stats->broadcast;
  994. } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
  995. t->rx_bytes += bytes;
  996. t->rx_packets += packets;
  997. t->multicast += multicast;
  998. }
  999. }
  1000. static int netvsc_set_mac_addr(struct net_device *ndev, void *p)
  1001. {
  1002. struct net_device_context *ndc = netdev_priv(ndev);
  1003. struct net_device *vf_netdev = rtnl_dereference(ndc->vf_netdev);
  1004. struct netvsc_device *nvdev = rtnl_dereference(ndc->nvdev);
  1005. struct sockaddr *addr = p;
  1006. int err;
  1007. err = eth_prepare_mac_addr_change(ndev, p);
  1008. if (err)
  1009. return err;
  1010. if (!nvdev)
  1011. return -ENODEV;
  1012. if (vf_netdev) {
  1013. err = dev_set_mac_address(vf_netdev, addr);
  1014. if (err)
  1015. return err;
  1016. }
  1017. err = rndis_filter_set_device_mac(nvdev, addr->sa_data);
  1018. if (!err) {
  1019. eth_commit_mac_addr_change(ndev, p);
  1020. } else if (vf_netdev) {
  1021. /* rollback change on VF */
  1022. memcpy(addr->sa_data, ndev->dev_addr, ETH_ALEN);
  1023. dev_set_mac_address(vf_netdev, addr);
  1024. }
  1025. return err;
  1026. }
  1027. static const struct {
  1028. char name[ETH_GSTRING_LEN];
  1029. u16 offset;
  1030. } netvsc_stats[] = {
  1031. { "tx_scattered", offsetof(struct netvsc_ethtool_stats, tx_scattered) },
  1032. { "tx_no_memory", offsetof(struct netvsc_ethtool_stats, tx_no_memory) },
  1033. { "tx_no_space", offsetof(struct netvsc_ethtool_stats, tx_no_space) },
  1034. { "tx_too_big", offsetof(struct netvsc_ethtool_stats, tx_too_big) },
  1035. { "tx_busy", offsetof(struct netvsc_ethtool_stats, tx_busy) },
  1036. { "tx_send_full", offsetof(struct netvsc_ethtool_stats, tx_send_full) },
  1037. { "rx_comp_busy", offsetof(struct netvsc_ethtool_stats, rx_comp_busy) },
  1038. { "rx_no_memory", offsetof(struct netvsc_ethtool_stats, rx_no_memory) },
  1039. { "stop_queue", offsetof(struct netvsc_ethtool_stats, stop_queue) },
  1040. { "wake_queue", offsetof(struct netvsc_ethtool_stats, wake_queue) },
  1041. }, pcpu_stats[] = {
  1042. { "cpu%u_rx_packets",
  1043. offsetof(struct netvsc_ethtool_pcpu_stats, rx_packets) },
  1044. { "cpu%u_rx_bytes",
  1045. offsetof(struct netvsc_ethtool_pcpu_stats, rx_bytes) },
  1046. { "cpu%u_tx_packets",
  1047. offsetof(struct netvsc_ethtool_pcpu_stats, tx_packets) },
  1048. { "cpu%u_tx_bytes",
  1049. offsetof(struct netvsc_ethtool_pcpu_stats, tx_bytes) },
  1050. { "cpu%u_vf_rx_packets",
  1051. offsetof(struct netvsc_ethtool_pcpu_stats, vf_rx_packets) },
  1052. { "cpu%u_vf_rx_bytes",
  1053. offsetof(struct netvsc_ethtool_pcpu_stats, vf_rx_bytes) },
  1054. { "cpu%u_vf_tx_packets",
  1055. offsetof(struct netvsc_ethtool_pcpu_stats, vf_tx_packets) },
  1056. { "cpu%u_vf_tx_bytes",
  1057. offsetof(struct netvsc_ethtool_pcpu_stats, vf_tx_bytes) },
  1058. }, vf_stats[] = {
  1059. { "vf_rx_packets", offsetof(struct netvsc_vf_pcpu_stats, rx_packets) },
  1060. { "vf_rx_bytes", offsetof(struct netvsc_vf_pcpu_stats, rx_bytes) },
  1061. { "vf_tx_packets", offsetof(struct netvsc_vf_pcpu_stats, tx_packets) },
  1062. { "vf_tx_bytes", offsetof(struct netvsc_vf_pcpu_stats, tx_bytes) },
  1063. { "vf_tx_dropped", offsetof(struct netvsc_vf_pcpu_stats, tx_dropped) },
  1064. };
  1065. #define NETVSC_GLOBAL_STATS_LEN ARRAY_SIZE(netvsc_stats)
  1066. #define NETVSC_VF_STATS_LEN ARRAY_SIZE(vf_stats)
  1067. /* statistics per queue (rx/tx packets/bytes) */
  1068. #define NETVSC_PCPU_STATS_LEN (num_present_cpus() * ARRAY_SIZE(pcpu_stats))
  1069. /* 4 statistics per queue (rx/tx packets/bytes) */
  1070. #define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 4)
  1071. static int netvsc_get_sset_count(struct net_device *dev, int string_set)
  1072. {
  1073. struct net_device_context *ndc = netdev_priv(dev);
  1074. struct netvsc_device *nvdev = rtnl_dereference(ndc->nvdev);
  1075. if (!nvdev)
  1076. return -ENODEV;
  1077. switch (string_set) {
  1078. case ETH_SS_STATS:
  1079. return NETVSC_GLOBAL_STATS_LEN
  1080. + NETVSC_VF_STATS_LEN
  1081. + NETVSC_QUEUE_STATS_LEN(nvdev)
  1082. + NETVSC_PCPU_STATS_LEN;
  1083. default:
  1084. return -EINVAL;
  1085. }
  1086. }
  1087. static void netvsc_get_ethtool_stats(struct net_device *dev,
  1088. struct ethtool_stats *stats, u64 *data)
  1089. {
  1090. struct net_device_context *ndc = netdev_priv(dev);
  1091. struct netvsc_device *nvdev = rtnl_dereference(ndc->nvdev);
  1092. const void *nds = &ndc->eth_stats;
  1093. const struct netvsc_stats *qstats;
  1094. struct netvsc_vf_pcpu_stats sum;
  1095. struct netvsc_ethtool_pcpu_stats *pcpu_sum;
  1096. unsigned int start;
  1097. u64 packets, bytes;
  1098. int i, j, cpu;
  1099. if (!nvdev)
  1100. return;
  1101. for (i = 0; i < NETVSC_GLOBAL_STATS_LEN; i++)
  1102. data[i] = *(unsigned long *)(nds + netvsc_stats[i].offset);
  1103. netvsc_get_vf_stats(dev, &sum);
  1104. for (j = 0; j < NETVSC_VF_STATS_LEN; j++)
  1105. data[i++] = *(u64 *)((void *)&sum + vf_stats[j].offset);
  1106. for (j = 0; j < nvdev->num_chn; j++) {
  1107. qstats = &nvdev->chan_table[j].tx_stats;
  1108. do {
  1109. start = u64_stats_fetch_begin_irq(&qstats->syncp);
  1110. packets = qstats->packets;
  1111. bytes = qstats->bytes;
  1112. } while (u64_stats_fetch_retry_irq(&qstats->syncp, start));
  1113. data[i++] = packets;
  1114. data[i++] = bytes;
  1115. qstats = &nvdev->chan_table[j].rx_stats;
  1116. do {
  1117. start = u64_stats_fetch_begin_irq(&qstats->syncp);
  1118. packets = qstats->packets;
  1119. bytes = qstats->bytes;
  1120. } while (u64_stats_fetch_retry_irq(&qstats->syncp, start));
  1121. data[i++] = packets;
  1122. data[i++] = bytes;
  1123. }
  1124. pcpu_sum = kvmalloc_array(num_possible_cpus(),
  1125. sizeof(struct netvsc_ethtool_pcpu_stats),
  1126. GFP_KERNEL);
  1127. netvsc_get_pcpu_stats(dev, pcpu_sum);
  1128. for_each_present_cpu(cpu) {
  1129. struct netvsc_ethtool_pcpu_stats *this_sum = &pcpu_sum[cpu];
  1130. for (j = 0; j < ARRAY_SIZE(pcpu_stats); j++)
  1131. data[i++] = *(u64 *)((void *)this_sum
  1132. + pcpu_stats[j].offset);
  1133. }
  1134. kvfree(pcpu_sum);
  1135. }
  1136. static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  1137. {
  1138. struct net_device_context *ndc = netdev_priv(dev);
  1139. struct netvsc_device *nvdev = rtnl_dereference(ndc->nvdev);
  1140. u8 *p = data;
  1141. int i, cpu;
  1142. if (!nvdev)
  1143. return;
  1144. switch (stringset) {
  1145. case ETH_SS_STATS:
  1146. for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++) {
  1147. memcpy(p, netvsc_stats[i].name, ETH_GSTRING_LEN);
  1148. p += ETH_GSTRING_LEN;
  1149. }
  1150. for (i = 0; i < ARRAY_SIZE(vf_stats); i++) {
  1151. memcpy(p, vf_stats[i].name, ETH_GSTRING_LEN);
  1152. p += ETH_GSTRING_LEN;
  1153. }
  1154. for (i = 0; i < nvdev->num_chn; i++) {
  1155. sprintf(p, "tx_queue_%u_packets", i);
  1156. p += ETH_GSTRING_LEN;
  1157. sprintf(p, "tx_queue_%u_bytes", i);
  1158. p += ETH_GSTRING_LEN;
  1159. sprintf(p, "rx_queue_%u_packets", i);
  1160. p += ETH_GSTRING_LEN;
  1161. sprintf(p, "rx_queue_%u_bytes", i);
  1162. p += ETH_GSTRING_LEN;
  1163. }
  1164. for_each_present_cpu(cpu) {
  1165. for (i = 0; i < ARRAY_SIZE(pcpu_stats); i++) {
  1166. sprintf(p, pcpu_stats[i].name, cpu);
  1167. p += ETH_GSTRING_LEN;
  1168. }
  1169. }
  1170. break;
  1171. }
  1172. }
  1173. static int
  1174. netvsc_get_rss_hash_opts(struct net_device_context *ndc,
  1175. struct ethtool_rxnfc *info)
  1176. {
  1177. const u32 l4_flag = RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1178. info->data = RXH_IP_SRC | RXH_IP_DST;
  1179. switch (info->flow_type) {
  1180. case TCP_V4_FLOW:
  1181. if (ndc->l4_hash & HV_TCP4_L4HASH)
  1182. info->data |= l4_flag;
  1183. break;
  1184. case TCP_V6_FLOW:
  1185. if (ndc->l4_hash & HV_TCP6_L4HASH)
  1186. info->data |= l4_flag;
  1187. break;
  1188. case UDP_V4_FLOW:
  1189. if (ndc->l4_hash & HV_UDP4_L4HASH)
  1190. info->data |= l4_flag;
  1191. break;
  1192. case UDP_V6_FLOW:
  1193. if (ndc->l4_hash & HV_UDP6_L4HASH)
  1194. info->data |= l4_flag;
  1195. break;
  1196. case IPV4_FLOW:
  1197. case IPV6_FLOW:
  1198. break;
  1199. default:
  1200. info->data = 0;
  1201. break;
  1202. }
  1203. return 0;
  1204. }
  1205. static int
  1206. netvsc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1207. u32 *rules)
  1208. {
  1209. struct net_device_context *ndc = netdev_priv(dev);
  1210. struct netvsc_device *nvdev = rtnl_dereference(ndc->nvdev);
  1211. if (!nvdev)
  1212. return -ENODEV;
  1213. switch (info->cmd) {
  1214. case ETHTOOL_GRXRINGS:
  1215. info->data = nvdev->num_chn;
  1216. return 0;
  1217. case ETHTOOL_GRXFH:
  1218. return netvsc_get_rss_hash_opts(ndc, info);
  1219. }
  1220. return -EOPNOTSUPP;
  1221. }
  1222. static int netvsc_set_rss_hash_opts(struct net_device_context *ndc,
  1223. struct ethtool_rxnfc *info)
  1224. {
  1225. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  1226. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1227. switch (info->flow_type) {
  1228. case TCP_V4_FLOW:
  1229. ndc->l4_hash |= HV_TCP4_L4HASH;
  1230. break;
  1231. case TCP_V6_FLOW:
  1232. ndc->l4_hash |= HV_TCP6_L4HASH;
  1233. break;
  1234. case UDP_V4_FLOW:
  1235. ndc->l4_hash |= HV_UDP4_L4HASH;
  1236. break;
  1237. case UDP_V6_FLOW:
  1238. ndc->l4_hash |= HV_UDP6_L4HASH;
  1239. break;
  1240. default:
  1241. return -EOPNOTSUPP;
  1242. }
  1243. return 0;
  1244. }
  1245. if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
  1246. switch (info->flow_type) {
  1247. case TCP_V4_FLOW:
  1248. ndc->l4_hash &= ~HV_TCP4_L4HASH;
  1249. break;
  1250. case TCP_V6_FLOW:
  1251. ndc->l4_hash &= ~HV_TCP6_L4HASH;
  1252. break;
  1253. case UDP_V4_FLOW:
  1254. ndc->l4_hash &= ~HV_UDP4_L4HASH;
  1255. break;
  1256. case UDP_V6_FLOW:
  1257. ndc->l4_hash &= ~HV_UDP6_L4HASH;
  1258. break;
  1259. default:
  1260. return -EOPNOTSUPP;
  1261. }
  1262. return 0;
  1263. }
  1264. return -EOPNOTSUPP;
  1265. }
  1266. static int
  1267. netvsc_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info)
  1268. {
  1269. struct net_device_context *ndc = netdev_priv(ndev);
  1270. if (info->cmd == ETHTOOL_SRXFH)
  1271. return netvsc_set_rss_hash_opts(ndc, info);
  1272. return -EOPNOTSUPP;
  1273. }
  1274. #ifdef CONFIG_NET_POLL_CONTROLLER
  1275. static void netvsc_poll_controller(struct net_device *dev)
  1276. {
  1277. struct net_device_context *ndc = netdev_priv(dev);
  1278. struct netvsc_device *ndev;
  1279. int i;
  1280. rcu_read_lock();
  1281. ndev = rcu_dereference(ndc->nvdev);
  1282. if (ndev) {
  1283. for (i = 0; i < ndev->num_chn; i++) {
  1284. struct netvsc_channel *nvchan = &ndev->chan_table[i];
  1285. napi_schedule(&nvchan->napi);
  1286. }
  1287. }
  1288. rcu_read_unlock();
  1289. }
  1290. #endif
  1291. static u32 netvsc_get_rxfh_key_size(struct net_device *dev)
  1292. {
  1293. return NETVSC_HASH_KEYLEN;
  1294. }
  1295. static u32 netvsc_rss_indir_size(struct net_device *dev)
  1296. {
  1297. return ITAB_NUM;
  1298. }
  1299. static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
  1300. u8 *hfunc)
  1301. {
  1302. struct net_device_context *ndc = netdev_priv(dev);
  1303. struct netvsc_device *ndev = rtnl_dereference(ndc->nvdev);
  1304. struct rndis_device *rndis_dev;
  1305. int i;
  1306. if (!ndev)
  1307. return -ENODEV;
  1308. if (hfunc)
  1309. *hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */
  1310. rndis_dev = ndev->extension;
  1311. if (indir) {
  1312. for (i = 0; i < ITAB_NUM; i++)
  1313. indir[i] = rndis_dev->rx_table[i];
  1314. }
  1315. if (key)
  1316. memcpy(key, rndis_dev->rss_key, NETVSC_HASH_KEYLEN);
  1317. return 0;
  1318. }
  1319. static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir,
  1320. const u8 *key, const u8 hfunc)
  1321. {
  1322. struct net_device_context *ndc = netdev_priv(dev);
  1323. struct netvsc_device *ndev = rtnl_dereference(ndc->nvdev);
  1324. struct rndis_device *rndis_dev;
  1325. int i;
  1326. if (!ndev)
  1327. return -ENODEV;
  1328. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  1329. return -EOPNOTSUPP;
  1330. rndis_dev = ndev->extension;
  1331. if (indir) {
  1332. for (i = 0; i < ITAB_NUM; i++)
  1333. if (indir[i] >= ndev->num_chn)
  1334. return -EINVAL;
  1335. for (i = 0; i < ITAB_NUM; i++)
  1336. rndis_dev->rx_table[i] = indir[i];
  1337. }
  1338. if (!key) {
  1339. if (!indir)
  1340. return 0;
  1341. key = rndis_dev->rss_key;
  1342. }
  1343. return rndis_filter_set_rss_param(rndis_dev, key);
  1344. }
  1345. /* Hyper-V RNDIS protocol does not have ring in the HW sense.
  1346. * It does have pre-allocated receive area which is divided into sections.
  1347. */
  1348. static void __netvsc_get_ringparam(struct netvsc_device *nvdev,
  1349. struct ethtool_ringparam *ring)
  1350. {
  1351. u32 max_buf_size;
  1352. ring->rx_pending = nvdev->recv_section_cnt;
  1353. ring->tx_pending = nvdev->send_section_cnt;
  1354. if (nvdev->nvsp_version <= NVSP_PROTOCOL_VERSION_2)
  1355. max_buf_size = NETVSC_RECEIVE_BUFFER_SIZE_LEGACY;
  1356. else
  1357. max_buf_size = NETVSC_RECEIVE_BUFFER_SIZE;
  1358. ring->rx_max_pending = max_buf_size / nvdev->recv_section_size;
  1359. ring->tx_max_pending = NETVSC_SEND_BUFFER_SIZE
  1360. / nvdev->send_section_size;
  1361. }
  1362. static void netvsc_get_ringparam(struct net_device *ndev,
  1363. struct ethtool_ringparam *ring)
  1364. {
  1365. struct net_device_context *ndevctx = netdev_priv(ndev);
  1366. struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
  1367. if (!nvdev)
  1368. return;
  1369. __netvsc_get_ringparam(nvdev, ring);
  1370. }
  1371. static int netvsc_set_ringparam(struct net_device *ndev,
  1372. struct ethtool_ringparam *ring)
  1373. {
  1374. struct net_device_context *ndevctx = netdev_priv(ndev);
  1375. struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
  1376. struct netvsc_device_info device_info;
  1377. struct ethtool_ringparam orig;
  1378. u32 new_tx, new_rx;
  1379. int ret = 0;
  1380. if (!nvdev || nvdev->destroy)
  1381. return -ENODEV;
  1382. memset(&orig, 0, sizeof(orig));
  1383. __netvsc_get_ringparam(nvdev, &orig);
  1384. new_tx = clamp_t(u32, ring->tx_pending,
  1385. NETVSC_MIN_TX_SECTIONS, orig.tx_max_pending);
  1386. new_rx = clamp_t(u32, ring->rx_pending,
  1387. NETVSC_MIN_RX_SECTIONS, orig.rx_max_pending);
  1388. if (new_tx == orig.tx_pending &&
  1389. new_rx == orig.rx_pending)
  1390. return 0; /* no change */
  1391. memset(&device_info, 0, sizeof(device_info));
  1392. device_info.num_chn = nvdev->num_chn;
  1393. device_info.send_sections = new_tx;
  1394. device_info.send_section_size = nvdev->send_section_size;
  1395. device_info.recv_sections = new_rx;
  1396. device_info.recv_section_size = nvdev->recv_section_size;
  1397. ret = netvsc_detach(ndev, nvdev);
  1398. if (ret)
  1399. return ret;
  1400. ret = netvsc_attach(ndev, &device_info);
  1401. if (ret) {
  1402. device_info.send_sections = orig.tx_pending;
  1403. device_info.recv_sections = orig.rx_pending;
  1404. if (netvsc_attach(ndev, &device_info))
  1405. netdev_err(ndev, "restoring ringparam failed");
  1406. }
  1407. return ret;
  1408. }
  1409. static u32 netvsc_get_msglevel(struct net_device *ndev)
  1410. {
  1411. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  1412. return ndev_ctx->msg_enable;
  1413. }
  1414. static void netvsc_set_msglevel(struct net_device *ndev, u32 val)
  1415. {
  1416. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  1417. ndev_ctx->msg_enable = val;
  1418. }
  1419. static const struct ethtool_ops ethtool_ops = {
  1420. .get_drvinfo = netvsc_get_drvinfo,
  1421. .get_msglevel = netvsc_get_msglevel,
  1422. .set_msglevel = netvsc_set_msglevel,
  1423. .get_link = ethtool_op_get_link,
  1424. .get_ethtool_stats = netvsc_get_ethtool_stats,
  1425. .get_sset_count = netvsc_get_sset_count,
  1426. .get_strings = netvsc_get_strings,
  1427. .get_channels = netvsc_get_channels,
  1428. .set_channels = netvsc_set_channels,
  1429. .get_ts_info = ethtool_op_get_ts_info,
  1430. .get_rxnfc = netvsc_get_rxnfc,
  1431. .set_rxnfc = netvsc_set_rxnfc,
  1432. .get_rxfh_key_size = netvsc_get_rxfh_key_size,
  1433. .get_rxfh_indir_size = netvsc_rss_indir_size,
  1434. .get_rxfh = netvsc_get_rxfh,
  1435. .set_rxfh = netvsc_set_rxfh,
  1436. .get_link_ksettings = netvsc_get_link_ksettings,
  1437. .set_link_ksettings = netvsc_set_link_ksettings,
  1438. .get_ringparam = netvsc_get_ringparam,
  1439. .set_ringparam = netvsc_set_ringparam,
  1440. };
  1441. static const struct net_device_ops device_ops = {
  1442. .ndo_open = netvsc_open,
  1443. .ndo_stop = netvsc_close,
  1444. .ndo_start_xmit = netvsc_start_xmit,
  1445. .ndo_change_rx_flags = netvsc_change_rx_flags,
  1446. .ndo_set_rx_mode = netvsc_set_rx_mode,
  1447. .ndo_change_mtu = netvsc_change_mtu,
  1448. .ndo_validate_addr = eth_validate_addr,
  1449. .ndo_set_mac_address = netvsc_set_mac_addr,
  1450. .ndo_select_queue = netvsc_select_queue,
  1451. .ndo_get_stats64 = netvsc_get_stats64,
  1452. #ifdef CONFIG_NET_POLL_CONTROLLER
  1453. .ndo_poll_controller = netvsc_poll_controller,
  1454. #endif
  1455. };
  1456. /*
  1457. * Handle link status changes. For RNDIS_STATUS_NETWORK_CHANGE emulate link
  1458. * down/up sequence. In case of RNDIS_STATUS_MEDIA_CONNECT when carrier is
  1459. * present send GARP packet to network peers with netif_notify_peers().
  1460. */
  1461. static void netvsc_link_change(struct work_struct *w)
  1462. {
  1463. struct net_device_context *ndev_ctx =
  1464. container_of(w, struct net_device_context, dwork.work);
  1465. struct hv_device *device_obj = ndev_ctx->device_ctx;
  1466. struct net_device *net = hv_get_drvdata(device_obj);
  1467. struct netvsc_device *net_device;
  1468. struct rndis_device *rdev;
  1469. struct netvsc_reconfig *event = NULL;
  1470. bool notify = false, reschedule = false;
  1471. unsigned long flags, next_reconfig, delay;
  1472. /* if changes are happening, comeback later */
  1473. if (!rtnl_trylock()) {
  1474. schedule_delayed_work(&ndev_ctx->dwork, LINKCHANGE_INT);
  1475. return;
  1476. }
  1477. net_device = rtnl_dereference(ndev_ctx->nvdev);
  1478. if (!net_device)
  1479. goto out_unlock;
  1480. rdev = net_device->extension;
  1481. next_reconfig = ndev_ctx->last_reconfig + LINKCHANGE_INT;
  1482. if (time_is_after_jiffies(next_reconfig)) {
  1483. /* link_watch only sends one notification with current state
  1484. * per second, avoid doing reconfig more frequently. Handle
  1485. * wrap around.
  1486. */
  1487. delay = next_reconfig - jiffies;
  1488. delay = delay < LINKCHANGE_INT ? delay : LINKCHANGE_INT;
  1489. schedule_delayed_work(&ndev_ctx->dwork, delay);
  1490. goto out_unlock;
  1491. }
  1492. ndev_ctx->last_reconfig = jiffies;
  1493. spin_lock_irqsave(&ndev_ctx->lock, flags);
  1494. if (!list_empty(&ndev_ctx->reconfig_events)) {
  1495. event = list_first_entry(&ndev_ctx->reconfig_events,
  1496. struct netvsc_reconfig, list);
  1497. list_del(&event->list);
  1498. reschedule = !list_empty(&ndev_ctx->reconfig_events);
  1499. }
  1500. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  1501. if (!event)
  1502. goto out_unlock;
  1503. switch (event->event) {
  1504. /* Only the following events are possible due to the check in
  1505. * netvsc_linkstatus_callback()
  1506. */
  1507. case RNDIS_STATUS_MEDIA_CONNECT:
  1508. if (rdev->link_state) {
  1509. rdev->link_state = false;
  1510. netif_carrier_on(net);
  1511. netif_tx_wake_all_queues(net);
  1512. } else {
  1513. notify = true;
  1514. }
  1515. kfree(event);
  1516. break;
  1517. case RNDIS_STATUS_MEDIA_DISCONNECT:
  1518. if (!rdev->link_state) {
  1519. rdev->link_state = true;
  1520. netif_carrier_off(net);
  1521. netif_tx_stop_all_queues(net);
  1522. }
  1523. kfree(event);
  1524. break;
  1525. case RNDIS_STATUS_NETWORK_CHANGE:
  1526. /* Only makes sense if carrier is present */
  1527. if (!rdev->link_state) {
  1528. rdev->link_state = true;
  1529. netif_carrier_off(net);
  1530. netif_tx_stop_all_queues(net);
  1531. event->event = RNDIS_STATUS_MEDIA_CONNECT;
  1532. spin_lock_irqsave(&ndev_ctx->lock, flags);
  1533. list_add(&event->list, &ndev_ctx->reconfig_events);
  1534. spin_unlock_irqrestore(&ndev_ctx->lock, flags);
  1535. reschedule = true;
  1536. }
  1537. break;
  1538. }
  1539. rtnl_unlock();
  1540. if (notify)
  1541. netdev_notify_peers(net);
  1542. /* link_watch only sends one notification with current state per
  1543. * second, handle next reconfig event in 2 seconds.
  1544. */
  1545. if (reschedule)
  1546. schedule_delayed_work(&ndev_ctx->dwork, LINKCHANGE_INT);
  1547. return;
  1548. out_unlock:
  1549. rtnl_unlock();
  1550. }
  1551. static struct net_device *get_netvsc_bymac(const u8 *mac)
  1552. {
  1553. struct net_device_context *ndev_ctx;
  1554. list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) {
  1555. struct net_device *dev = hv_get_drvdata(ndev_ctx->device_ctx);
  1556. if (ether_addr_equal(mac, dev->perm_addr))
  1557. return dev;
  1558. }
  1559. return NULL;
  1560. }
  1561. static struct net_device *get_netvsc_byref(struct net_device *vf_netdev)
  1562. {
  1563. struct net_device_context *net_device_ctx;
  1564. struct net_device *dev;
  1565. dev = netdev_master_upper_dev_get(vf_netdev);
  1566. if (!dev || dev->netdev_ops != &device_ops)
  1567. return NULL; /* not a netvsc device */
  1568. net_device_ctx = netdev_priv(dev);
  1569. if (!rtnl_dereference(net_device_ctx->nvdev))
  1570. return NULL; /* device is removed */
  1571. return dev;
  1572. }
  1573. /* Called when VF is injecting data into network stack.
  1574. * Change the associated network device from VF to netvsc.
  1575. * note: already called with rcu_read_lock
  1576. */
  1577. static rx_handler_result_t netvsc_vf_handle_frame(struct sk_buff **pskb)
  1578. {
  1579. struct sk_buff *skb = *pskb;
  1580. struct net_device *ndev = rcu_dereference(skb->dev->rx_handler_data);
  1581. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  1582. struct netvsc_vf_pcpu_stats *pcpu_stats
  1583. = this_cpu_ptr(ndev_ctx->vf_stats);
  1584. skb->dev = ndev;
  1585. u64_stats_update_begin(&pcpu_stats->syncp);
  1586. pcpu_stats->rx_packets++;
  1587. pcpu_stats->rx_bytes += skb->len;
  1588. u64_stats_update_end(&pcpu_stats->syncp);
  1589. return RX_HANDLER_ANOTHER;
  1590. }
  1591. static int netvsc_vf_join(struct net_device *vf_netdev,
  1592. struct net_device *ndev)
  1593. {
  1594. struct net_device_context *ndev_ctx = netdev_priv(ndev);
  1595. int ret;
  1596. ret = netdev_rx_handler_register(vf_netdev,
  1597. netvsc_vf_handle_frame, ndev);
  1598. if (ret != 0) {
  1599. netdev_err(vf_netdev,
  1600. "can not register netvsc VF receive handler (err = %d)\n",
  1601. ret);
  1602. goto rx_handler_failed;
  1603. }
  1604. ret = netdev_master_upper_dev_link(vf_netdev, ndev,
  1605. NULL, NULL, NULL);
  1606. if (ret != 0) {
  1607. netdev_err(vf_netdev,
  1608. "can not set master device %s (err = %d)\n",
  1609. ndev->name, ret);
  1610. goto upper_link_failed;
  1611. }
  1612. /* set slave flag before open to prevent IPv6 addrconf */
  1613. vf_netdev->flags |= IFF_SLAVE;
  1614. schedule_delayed_work(&ndev_ctx->vf_takeover, VF_TAKEOVER_INT);
  1615. call_netdevice_notifiers(NETDEV_JOIN, vf_netdev);
  1616. netdev_info(vf_netdev, "joined to %s\n", ndev->name);
  1617. return 0;
  1618. upper_link_failed:
  1619. netdev_rx_handler_unregister(vf_netdev);
  1620. rx_handler_failed:
  1621. return ret;
  1622. }
  1623. static void __netvsc_vf_setup(struct net_device *ndev,
  1624. struct net_device *vf_netdev)
  1625. {
  1626. int ret;
  1627. /* Align MTU of VF with master */
  1628. ret = dev_set_mtu(vf_netdev, ndev->mtu);
  1629. if (ret)
  1630. netdev_warn(vf_netdev,
  1631. "unable to change mtu to %u\n", ndev->mtu);
  1632. /* set multicast etc flags on VF */
  1633. dev_change_flags(vf_netdev, ndev->flags | IFF_SLAVE);
  1634. /* sync address list from ndev to VF */
  1635. netif_addr_lock_bh(ndev);
  1636. dev_uc_sync(vf_netdev, ndev);
  1637. dev_mc_sync(vf_netdev, ndev);
  1638. netif_addr_unlock_bh(ndev);
  1639. if (netif_running(ndev)) {
  1640. ret = dev_open(vf_netdev);
  1641. if (ret)
  1642. netdev_warn(vf_netdev,
  1643. "unable to open: %d\n", ret);
  1644. }
  1645. }
  1646. /* Setup VF as slave of the synthetic device.
  1647. * Runs in workqueue to avoid recursion in netlink callbacks.
  1648. */
  1649. static void netvsc_vf_setup(struct work_struct *w)
  1650. {
  1651. struct net_device_context *ndev_ctx
  1652. = container_of(w, struct net_device_context, vf_takeover.work);
  1653. struct net_device *ndev = hv_get_drvdata(ndev_ctx->device_ctx);
  1654. struct net_device *vf_netdev;
  1655. if (!rtnl_trylock()) {
  1656. schedule_delayed_work(&ndev_ctx->vf_takeover, 0);
  1657. return;
  1658. }
  1659. vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
  1660. if (vf_netdev)
  1661. __netvsc_vf_setup(ndev, vf_netdev);
  1662. rtnl_unlock();
  1663. }
  1664. static int netvsc_register_vf(struct net_device *vf_netdev)
  1665. {
  1666. struct net_device *ndev;
  1667. struct net_device_context *net_device_ctx;
  1668. struct device *pdev = vf_netdev->dev.parent;
  1669. struct netvsc_device *netvsc_dev;
  1670. int ret;
  1671. if (vf_netdev->addr_len != ETH_ALEN)
  1672. return NOTIFY_DONE;
  1673. if (!pdev || !dev_is_pci(pdev) || dev_is_pf(pdev))
  1674. return NOTIFY_DONE;
  1675. /*
  1676. * We will use the MAC address to locate the synthetic interface to
  1677. * associate with the VF interface. If we don't find a matching
  1678. * synthetic interface, move on.
  1679. */
  1680. ndev = get_netvsc_bymac(vf_netdev->perm_addr);
  1681. if (!ndev)
  1682. return NOTIFY_DONE;
  1683. net_device_ctx = netdev_priv(ndev);
  1684. netvsc_dev = rtnl_dereference(net_device_ctx->nvdev);
  1685. if (!netvsc_dev || rtnl_dereference(net_device_ctx->vf_netdev))
  1686. return NOTIFY_DONE;
  1687. /* if syntihetic interface is a different namespace,
  1688. * then move the VF to that namespace; join will be
  1689. * done again in that context.
  1690. */
  1691. if (!net_eq(dev_net(ndev), dev_net(vf_netdev))) {
  1692. ret = dev_change_net_namespace(vf_netdev,
  1693. dev_net(ndev), "eth%d");
  1694. if (ret)
  1695. netdev_err(vf_netdev,
  1696. "could not move to same namespace as %s: %d\n",
  1697. ndev->name, ret);
  1698. else
  1699. netdev_info(vf_netdev,
  1700. "VF moved to namespace with: %s\n",
  1701. ndev->name);
  1702. return NOTIFY_DONE;
  1703. }
  1704. netdev_info(ndev, "VF registering: %s\n", vf_netdev->name);
  1705. if (netvsc_vf_join(vf_netdev, ndev) != 0)
  1706. return NOTIFY_DONE;
  1707. dev_hold(vf_netdev);
  1708. rcu_assign_pointer(net_device_ctx->vf_netdev, vf_netdev);
  1709. return NOTIFY_OK;
  1710. }
  1711. /* VF up/down change detected, schedule to change data path */
  1712. static int netvsc_vf_changed(struct net_device *vf_netdev)
  1713. {
  1714. struct net_device_context *net_device_ctx;
  1715. struct netvsc_device *netvsc_dev;
  1716. struct net_device *ndev;
  1717. bool vf_is_up = netif_running(vf_netdev);
  1718. ndev = get_netvsc_byref(vf_netdev);
  1719. if (!ndev)
  1720. return NOTIFY_DONE;
  1721. net_device_ctx = netdev_priv(ndev);
  1722. netvsc_dev = rtnl_dereference(net_device_ctx->nvdev);
  1723. if (!netvsc_dev)
  1724. return NOTIFY_DONE;
  1725. netvsc_switch_datapath(ndev, vf_is_up);
  1726. netdev_info(ndev, "Data path switched %s VF: %s\n",
  1727. vf_is_up ? "to" : "from", vf_netdev->name);
  1728. return NOTIFY_OK;
  1729. }
  1730. static int netvsc_unregister_vf(struct net_device *vf_netdev)
  1731. {
  1732. struct net_device *ndev;
  1733. struct net_device_context *net_device_ctx;
  1734. ndev = get_netvsc_byref(vf_netdev);
  1735. if (!ndev)
  1736. return NOTIFY_DONE;
  1737. net_device_ctx = netdev_priv(ndev);
  1738. cancel_delayed_work_sync(&net_device_ctx->vf_takeover);
  1739. netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name);
  1740. netdev_rx_handler_unregister(vf_netdev);
  1741. netdev_upper_dev_unlink(vf_netdev, ndev);
  1742. RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL);
  1743. dev_put(vf_netdev);
  1744. return NOTIFY_OK;
  1745. }
  1746. static int netvsc_probe(struct hv_device *dev,
  1747. const struct hv_vmbus_device_id *dev_id)
  1748. {
  1749. struct net_device *net = NULL;
  1750. struct net_device_context *net_device_ctx;
  1751. struct netvsc_device_info device_info;
  1752. struct netvsc_device *nvdev;
  1753. int ret = -ENOMEM;
  1754. net = alloc_etherdev_mq(sizeof(struct net_device_context),
  1755. VRSS_CHANNEL_MAX);
  1756. if (!net)
  1757. goto no_net;
  1758. netif_carrier_off(net);
  1759. netvsc_init_settings(net);
  1760. net_device_ctx = netdev_priv(net);
  1761. net_device_ctx->device_ctx = dev;
  1762. net_device_ctx->msg_enable = netif_msg_init(debug, default_msg);
  1763. if (netif_msg_probe(net_device_ctx))
  1764. netdev_dbg(net, "netvsc msg_enable: %d\n",
  1765. net_device_ctx->msg_enable);
  1766. hv_set_drvdata(dev, net);
  1767. INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
  1768. spin_lock_init(&net_device_ctx->lock);
  1769. INIT_LIST_HEAD(&net_device_ctx->reconfig_events);
  1770. INIT_DELAYED_WORK(&net_device_ctx->vf_takeover, netvsc_vf_setup);
  1771. net_device_ctx->vf_stats
  1772. = netdev_alloc_pcpu_stats(struct netvsc_vf_pcpu_stats);
  1773. if (!net_device_ctx->vf_stats)
  1774. goto no_stats;
  1775. net->netdev_ops = &device_ops;
  1776. net->ethtool_ops = &ethtool_ops;
  1777. SET_NETDEV_DEV(net, &dev->device);
  1778. /* We always need headroom for rndis header */
  1779. net->needed_headroom = RNDIS_AND_PPI_SIZE;
  1780. /* Initialize the number of queues to be 1, we may change it if more
  1781. * channels are offered later.
  1782. */
  1783. netif_set_real_num_tx_queues(net, 1);
  1784. netif_set_real_num_rx_queues(net, 1);
  1785. /* Notify the netvsc driver of the new device */
  1786. memset(&device_info, 0, sizeof(device_info));
  1787. device_info.num_chn = VRSS_CHANNEL_DEFAULT;
  1788. device_info.send_sections = NETVSC_DEFAULT_TX;
  1789. device_info.send_section_size = NETVSC_SEND_SECTION_SIZE;
  1790. device_info.recv_sections = NETVSC_DEFAULT_RX;
  1791. device_info.recv_section_size = NETVSC_RECV_SECTION_SIZE;
  1792. nvdev = rndis_filter_device_add(dev, &device_info);
  1793. if (IS_ERR(nvdev)) {
  1794. ret = PTR_ERR(nvdev);
  1795. netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
  1796. goto rndis_failed;
  1797. }
  1798. memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
  1799. if (nvdev->num_chn > 1)
  1800. schedule_work(&nvdev->subchan_work);
  1801. /* hw_features computed in rndis_netdev_set_hwcaps() */
  1802. net->features = net->hw_features |
  1803. NETIF_F_HIGHDMA | NETIF_F_SG |
  1804. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  1805. net->vlan_features = net->features;
  1806. netdev_lockdep_set_classes(net);
  1807. /* MTU range: 68 - 1500 or 65521 */
  1808. net->min_mtu = NETVSC_MTU_MIN;
  1809. if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
  1810. net->max_mtu = NETVSC_MTU - ETH_HLEN;
  1811. else
  1812. net->max_mtu = ETH_DATA_LEN;
  1813. rtnl_lock();
  1814. ret = register_netdevice(net);
  1815. if (ret != 0) {
  1816. pr_err("Unable to register netdev.\n");
  1817. goto register_failed;
  1818. }
  1819. list_add(&net_device_ctx->list, &netvsc_dev_list);
  1820. rtnl_unlock();
  1821. return 0;
  1822. register_failed:
  1823. rtnl_unlock();
  1824. rndis_filter_device_remove(dev, nvdev);
  1825. rndis_failed:
  1826. free_percpu(net_device_ctx->vf_stats);
  1827. no_stats:
  1828. hv_set_drvdata(dev, NULL);
  1829. free_netdev(net);
  1830. no_net:
  1831. return ret;
  1832. }
  1833. static int netvsc_remove(struct hv_device *dev)
  1834. {
  1835. struct net_device_context *ndev_ctx;
  1836. struct net_device *vf_netdev, *net;
  1837. struct netvsc_device *nvdev;
  1838. net = hv_get_drvdata(dev);
  1839. if (net == NULL) {
  1840. dev_err(&dev->device, "No net device to remove\n");
  1841. return 0;
  1842. }
  1843. ndev_ctx = netdev_priv(net);
  1844. cancel_delayed_work_sync(&ndev_ctx->dwork);
  1845. rcu_read_lock();
  1846. nvdev = rcu_dereference(ndev_ctx->nvdev);
  1847. if (nvdev)
  1848. cancel_work_sync(&nvdev->subchan_work);
  1849. /*
  1850. * Call to the vsc driver to let it know that the device is being
  1851. * removed. Also blocks mtu and channel changes.
  1852. */
  1853. rtnl_lock();
  1854. vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
  1855. if (vf_netdev)
  1856. netvsc_unregister_vf(vf_netdev);
  1857. if (nvdev)
  1858. rndis_filter_device_remove(dev, nvdev);
  1859. unregister_netdevice(net);
  1860. list_del(&ndev_ctx->list);
  1861. rtnl_unlock();
  1862. rcu_read_unlock();
  1863. hv_set_drvdata(dev, NULL);
  1864. free_percpu(ndev_ctx->vf_stats);
  1865. free_netdev(net);
  1866. return 0;
  1867. }
  1868. static const struct hv_vmbus_device_id id_table[] = {
  1869. /* Network guid */
  1870. { HV_NIC_GUID, },
  1871. { },
  1872. };
  1873. MODULE_DEVICE_TABLE(vmbus, id_table);
  1874. /* The one and only one */
  1875. static struct hv_driver netvsc_drv = {
  1876. .name = KBUILD_MODNAME,
  1877. .id_table = id_table,
  1878. .probe = netvsc_probe,
  1879. .remove = netvsc_remove,
  1880. .driver = {
  1881. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1882. },
  1883. };
  1884. /*
  1885. * On Hyper-V, every VF interface is matched with a corresponding
  1886. * synthetic interface. The synthetic interface is presented first
  1887. * to the guest. When the corresponding VF instance is registered,
  1888. * we will take care of switching the data path.
  1889. */
  1890. static int netvsc_netdev_event(struct notifier_block *this,
  1891. unsigned long event, void *ptr)
  1892. {
  1893. struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
  1894. /* Skip our own events */
  1895. if (event_dev->netdev_ops == &device_ops)
  1896. return NOTIFY_DONE;
  1897. /* Avoid non-Ethernet type devices */
  1898. if (event_dev->type != ARPHRD_ETHER)
  1899. return NOTIFY_DONE;
  1900. /* Avoid Vlan dev with same MAC registering as VF */
  1901. if (is_vlan_dev(event_dev))
  1902. return NOTIFY_DONE;
  1903. /* Avoid Bonding master dev with same MAC registering as VF */
  1904. if ((event_dev->priv_flags & IFF_BONDING) &&
  1905. (event_dev->flags & IFF_MASTER))
  1906. return NOTIFY_DONE;
  1907. switch (event) {
  1908. case NETDEV_REGISTER:
  1909. return netvsc_register_vf(event_dev);
  1910. case NETDEV_UNREGISTER:
  1911. return netvsc_unregister_vf(event_dev);
  1912. case NETDEV_UP:
  1913. case NETDEV_DOWN:
  1914. return netvsc_vf_changed(event_dev);
  1915. default:
  1916. return NOTIFY_DONE;
  1917. }
  1918. }
  1919. static struct notifier_block netvsc_netdev_notifier = {
  1920. .notifier_call = netvsc_netdev_event,
  1921. };
  1922. static void __exit netvsc_drv_exit(void)
  1923. {
  1924. unregister_netdevice_notifier(&netvsc_netdev_notifier);
  1925. vmbus_driver_unregister(&netvsc_drv);
  1926. }
  1927. static int __init netvsc_drv_init(void)
  1928. {
  1929. int ret;
  1930. if (ring_size < RING_SIZE_MIN) {
  1931. ring_size = RING_SIZE_MIN;
  1932. pr_info("Increased ring_size to %u (min allowed)\n",
  1933. ring_size);
  1934. }
  1935. netvsc_ring_bytes = ring_size * PAGE_SIZE;
  1936. ret = vmbus_driver_register(&netvsc_drv);
  1937. if (ret)
  1938. return ret;
  1939. register_netdevice_notifier(&netvsc_netdev_notifier);
  1940. return 0;
  1941. }
  1942. MODULE_LICENSE("GPL");
  1943. MODULE_DESCRIPTION("Microsoft Hyper-V network driver");
  1944. module_init(netvsc_drv_init);
  1945. module_exit(netvsc_drv_exit);