xenbus.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. * Xenbus code for netif backend
  3. *
  4. * Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
  5. * Copyright (C) 2005 XenSource Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "common.h"
  21. #include <linux/vmalloc.h>
  22. #include <linux/rtnetlink.h>
  23. struct backend_info {
  24. struct xenbus_device *dev;
  25. struct xenvif *vif;
  26. /* This is the state that will be reflected in xenstore when any
  27. * active hotplug script completes.
  28. */
  29. enum xenbus_state state;
  30. enum xenbus_state frontend_state;
  31. struct xenbus_watch hotplug_status_watch;
  32. u8 have_hotplug_status_watch:1;
  33. };
  34. static int connect_rings(struct backend_info *be, struct xenvif_queue *queue);
  35. static void connect(struct backend_info *be);
  36. static int read_xenbus_vif_flags(struct backend_info *be);
  37. static void backend_create_xenvif(struct backend_info *be);
  38. static void unregister_hotplug_status_watch(struct backend_info *be);
  39. static void set_backend_state(struct backend_info *be,
  40. enum xenbus_state state);
  41. static int netback_remove(struct xenbus_device *dev)
  42. {
  43. struct backend_info *be = dev_get_drvdata(&dev->dev);
  44. set_backend_state(be, XenbusStateClosed);
  45. unregister_hotplug_status_watch(be);
  46. if (be->vif) {
  47. kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
  48. xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
  49. xenvif_free(be->vif);
  50. be->vif = NULL;
  51. }
  52. kfree(be);
  53. dev_set_drvdata(&dev->dev, NULL);
  54. return 0;
  55. }
  56. /**
  57. * Entry point to this code when a new device is created. Allocate the basic
  58. * structures and switch to InitWait.
  59. */
  60. static int netback_probe(struct xenbus_device *dev,
  61. const struct xenbus_device_id *id)
  62. {
  63. const char *message;
  64. struct xenbus_transaction xbt;
  65. int err;
  66. int sg;
  67. struct backend_info *be = kzalloc(sizeof(struct backend_info),
  68. GFP_KERNEL);
  69. if (!be) {
  70. xenbus_dev_fatal(dev, -ENOMEM,
  71. "allocating backend structure");
  72. return -ENOMEM;
  73. }
  74. be->dev = dev;
  75. dev_set_drvdata(&dev->dev, be);
  76. sg = 1;
  77. do {
  78. err = xenbus_transaction_start(&xbt);
  79. if (err) {
  80. xenbus_dev_fatal(dev, err, "starting transaction");
  81. goto fail;
  82. }
  83. err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", sg);
  84. if (err) {
  85. message = "writing feature-sg";
  86. goto abort_transaction;
  87. }
  88. err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4",
  89. "%d", sg);
  90. if (err) {
  91. message = "writing feature-gso-tcpv4";
  92. goto abort_transaction;
  93. }
  94. err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6",
  95. "%d", sg);
  96. if (err) {
  97. message = "writing feature-gso-tcpv6";
  98. goto abort_transaction;
  99. }
  100. /* We support partial checksum setup for IPv6 packets */
  101. err = xenbus_printf(xbt, dev->nodename,
  102. "feature-ipv6-csum-offload",
  103. "%d", 1);
  104. if (err) {
  105. message = "writing feature-ipv6-csum-offload";
  106. goto abort_transaction;
  107. }
  108. /* We support rx-copy path. */
  109. err = xenbus_printf(xbt, dev->nodename,
  110. "feature-rx-copy", "%d", 1);
  111. if (err) {
  112. message = "writing feature-rx-copy";
  113. goto abort_transaction;
  114. }
  115. /*
  116. * We don't support rx-flip path (except old guests who don't
  117. * grok this feature flag).
  118. */
  119. err = xenbus_printf(xbt, dev->nodename,
  120. "feature-rx-flip", "%d", 0);
  121. if (err) {
  122. message = "writing feature-rx-flip";
  123. goto abort_transaction;
  124. }
  125. err = xenbus_transaction_end(xbt, 0);
  126. } while (err == -EAGAIN);
  127. if (err) {
  128. xenbus_dev_fatal(dev, err, "completing transaction");
  129. goto fail;
  130. }
  131. /*
  132. * Split event channels support, this is optional so it is not
  133. * put inside the above loop.
  134. */
  135. err = xenbus_printf(XBT_NIL, dev->nodename,
  136. "feature-split-event-channels",
  137. "%u", separate_tx_rx_irq);
  138. if (err)
  139. pr_debug("Error writing feature-split-event-channels\n");
  140. /* Multi-queue support: This is an optional feature. */
  141. err = xenbus_printf(XBT_NIL, dev->nodename,
  142. "multi-queue-max-queues", "%u", xenvif_max_queues);
  143. if (err)
  144. pr_debug("Error writing multi-queue-max-queues\n");
  145. err = xenbus_switch_state(dev, XenbusStateInitWait);
  146. if (err)
  147. goto fail;
  148. be->state = XenbusStateInitWait;
  149. /* This kicks hotplug scripts, so do it immediately. */
  150. backend_create_xenvif(be);
  151. return 0;
  152. abort_transaction:
  153. xenbus_transaction_end(xbt, 1);
  154. xenbus_dev_fatal(dev, err, "%s", message);
  155. fail:
  156. pr_debug("failed\n");
  157. netback_remove(dev);
  158. return err;
  159. }
  160. /*
  161. * Handle the creation of the hotplug script environment. We add the script
  162. * and vif variables to the environment, for the benefit of the vif-* hotplug
  163. * scripts.
  164. */
  165. static int netback_uevent(struct xenbus_device *xdev,
  166. struct kobj_uevent_env *env)
  167. {
  168. struct backend_info *be = dev_get_drvdata(&xdev->dev);
  169. char *val;
  170. val = xenbus_read(XBT_NIL, xdev->nodename, "script", NULL);
  171. if (IS_ERR(val)) {
  172. int err = PTR_ERR(val);
  173. xenbus_dev_fatal(xdev, err, "reading script");
  174. return err;
  175. } else {
  176. if (add_uevent_var(env, "script=%s", val)) {
  177. kfree(val);
  178. return -ENOMEM;
  179. }
  180. kfree(val);
  181. }
  182. if (!be || !be->vif)
  183. return 0;
  184. return add_uevent_var(env, "vif=%s", be->vif->dev->name);
  185. }
  186. static void backend_create_xenvif(struct backend_info *be)
  187. {
  188. int err;
  189. long handle;
  190. struct xenbus_device *dev = be->dev;
  191. if (be->vif != NULL)
  192. return;
  193. err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
  194. if (err != 1) {
  195. xenbus_dev_fatal(dev, err, "reading handle");
  196. return;
  197. }
  198. be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle);
  199. if (IS_ERR(be->vif)) {
  200. err = PTR_ERR(be->vif);
  201. be->vif = NULL;
  202. xenbus_dev_fatal(dev, err, "creating interface");
  203. return;
  204. }
  205. kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
  206. }
  207. static void backend_disconnect(struct backend_info *be)
  208. {
  209. if (be->vif)
  210. xenvif_disconnect(be->vif);
  211. }
  212. static void backend_connect(struct backend_info *be)
  213. {
  214. if (be->vif)
  215. connect(be);
  216. }
  217. static inline void backend_switch_state(struct backend_info *be,
  218. enum xenbus_state state)
  219. {
  220. struct xenbus_device *dev = be->dev;
  221. pr_debug("%s -> %s\n", dev->nodename, xenbus_strstate(state));
  222. be->state = state;
  223. /* If we are waiting for a hotplug script then defer the
  224. * actual xenbus state change.
  225. */
  226. if (!be->have_hotplug_status_watch)
  227. xenbus_switch_state(dev, state);
  228. }
  229. /* Handle backend state transitions:
  230. *
  231. * The backend state starts in InitWait and the following transitions are
  232. * allowed.
  233. *
  234. * InitWait -> Connected
  235. *
  236. * ^ \ |
  237. * | \ |
  238. * | \ |
  239. * | \ |
  240. * | \ |
  241. * | \ |
  242. * | V V
  243. *
  244. * Closed <-> Closing
  245. *
  246. * The state argument specifies the eventual state of the backend and the
  247. * function transitions to that state via the shortest path.
  248. */
  249. static void set_backend_state(struct backend_info *be,
  250. enum xenbus_state state)
  251. {
  252. while (be->state != state) {
  253. switch (be->state) {
  254. case XenbusStateClosed:
  255. switch (state) {
  256. case XenbusStateInitWait:
  257. case XenbusStateConnected:
  258. pr_info("%s: prepare for reconnect\n",
  259. be->dev->nodename);
  260. backend_switch_state(be, XenbusStateInitWait);
  261. break;
  262. case XenbusStateClosing:
  263. backend_switch_state(be, XenbusStateClosing);
  264. break;
  265. default:
  266. BUG();
  267. }
  268. break;
  269. case XenbusStateInitWait:
  270. switch (state) {
  271. case XenbusStateConnected:
  272. backend_connect(be);
  273. backend_switch_state(be, XenbusStateConnected);
  274. break;
  275. case XenbusStateClosing:
  276. case XenbusStateClosed:
  277. backend_switch_state(be, XenbusStateClosing);
  278. break;
  279. default:
  280. BUG();
  281. }
  282. break;
  283. case XenbusStateConnected:
  284. switch (state) {
  285. case XenbusStateInitWait:
  286. case XenbusStateClosing:
  287. case XenbusStateClosed:
  288. backend_disconnect(be);
  289. backend_switch_state(be, XenbusStateClosing);
  290. break;
  291. default:
  292. BUG();
  293. }
  294. break;
  295. case XenbusStateClosing:
  296. switch (state) {
  297. case XenbusStateInitWait:
  298. case XenbusStateConnected:
  299. case XenbusStateClosed:
  300. backend_switch_state(be, XenbusStateClosed);
  301. break;
  302. default:
  303. BUG();
  304. }
  305. break;
  306. default:
  307. BUG();
  308. }
  309. }
  310. }
  311. /**
  312. * Callback received when the frontend's state changes.
  313. */
  314. static void frontend_changed(struct xenbus_device *dev,
  315. enum xenbus_state frontend_state)
  316. {
  317. struct backend_info *be = dev_get_drvdata(&dev->dev);
  318. pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
  319. be->frontend_state = frontend_state;
  320. switch (frontend_state) {
  321. case XenbusStateInitialising:
  322. set_backend_state(be, XenbusStateInitWait);
  323. break;
  324. case XenbusStateInitialised:
  325. break;
  326. case XenbusStateConnected:
  327. set_backend_state(be, XenbusStateConnected);
  328. break;
  329. case XenbusStateClosing:
  330. set_backend_state(be, XenbusStateClosing);
  331. break;
  332. case XenbusStateClosed:
  333. set_backend_state(be, XenbusStateClosed);
  334. if (xenbus_dev_is_online(dev))
  335. break;
  336. /* fall through if not online */
  337. case XenbusStateUnknown:
  338. set_backend_state(be, XenbusStateClosed);
  339. device_unregister(&dev->dev);
  340. break;
  341. default:
  342. xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
  343. frontend_state);
  344. break;
  345. }
  346. }
  347. static void xen_net_read_rate(struct xenbus_device *dev,
  348. unsigned long *bytes, unsigned long *usec)
  349. {
  350. char *s, *e;
  351. unsigned long b, u;
  352. char *ratestr;
  353. /* Default to unlimited bandwidth. */
  354. *bytes = ~0UL;
  355. *usec = 0;
  356. ratestr = xenbus_read(XBT_NIL, dev->nodename, "rate", NULL);
  357. if (IS_ERR(ratestr))
  358. return;
  359. s = ratestr;
  360. b = simple_strtoul(s, &e, 10);
  361. if ((s == e) || (*e != ','))
  362. goto fail;
  363. s = e + 1;
  364. u = simple_strtoul(s, &e, 10);
  365. if ((s == e) || (*e != '\0'))
  366. goto fail;
  367. *bytes = b;
  368. *usec = u;
  369. kfree(ratestr);
  370. return;
  371. fail:
  372. pr_warn("Failed to parse network rate limit. Traffic unlimited.\n");
  373. kfree(ratestr);
  374. }
  375. static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
  376. {
  377. char *s, *e, *macstr;
  378. int i;
  379. macstr = s = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL);
  380. if (IS_ERR(macstr))
  381. return PTR_ERR(macstr);
  382. for (i = 0; i < ETH_ALEN; i++) {
  383. mac[i] = simple_strtoul(s, &e, 16);
  384. if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
  385. kfree(macstr);
  386. return -ENOENT;
  387. }
  388. s = e+1;
  389. }
  390. kfree(macstr);
  391. return 0;
  392. }
  393. static void unregister_hotplug_status_watch(struct backend_info *be)
  394. {
  395. if (be->have_hotplug_status_watch) {
  396. unregister_xenbus_watch(&be->hotplug_status_watch);
  397. kfree(be->hotplug_status_watch.node);
  398. }
  399. be->have_hotplug_status_watch = 0;
  400. }
  401. static void hotplug_status_changed(struct xenbus_watch *watch,
  402. const char **vec,
  403. unsigned int vec_size)
  404. {
  405. struct backend_info *be = container_of(watch,
  406. struct backend_info,
  407. hotplug_status_watch);
  408. char *str;
  409. unsigned int len;
  410. str = xenbus_read(XBT_NIL, be->dev->nodename, "hotplug-status", &len);
  411. if (IS_ERR(str))
  412. return;
  413. if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
  414. /* Complete any pending state change */
  415. xenbus_switch_state(be->dev, be->state);
  416. /* Not interested in this watch anymore. */
  417. unregister_hotplug_status_watch(be);
  418. }
  419. kfree(str);
  420. }
  421. static void connect(struct backend_info *be)
  422. {
  423. int err;
  424. struct xenbus_device *dev = be->dev;
  425. unsigned long credit_bytes, credit_usec;
  426. unsigned int queue_index;
  427. unsigned int requested_num_queues;
  428. struct xenvif_queue *queue;
  429. /* Check whether the frontend requested multiple queues
  430. * and read the number requested.
  431. */
  432. err = xenbus_scanf(XBT_NIL, dev->otherend,
  433. "multi-queue-num-queues",
  434. "%u", &requested_num_queues);
  435. if (err < 0) {
  436. requested_num_queues = 1; /* Fall back to single queue */
  437. } else if (requested_num_queues > xenvif_max_queues) {
  438. /* buggy or malicious guest */
  439. xenbus_dev_fatal(dev, err,
  440. "guest requested %u queues, exceeding the maximum of %u.",
  441. requested_num_queues, xenvif_max_queues);
  442. return;
  443. }
  444. err = xen_net_read_mac(dev, be->vif->fe_dev_addr);
  445. if (err) {
  446. xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);
  447. return;
  448. }
  449. xen_net_read_rate(dev, &credit_bytes, &credit_usec);
  450. read_xenbus_vif_flags(be);
  451. /* Use the number of queues requested by the frontend */
  452. be->vif->queues = vzalloc(requested_num_queues *
  453. sizeof(struct xenvif_queue));
  454. be->vif->num_queues = requested_num_queues;
  455. for (queue_index = 0; queue_index < requested_num_queues; ++queue_index) {
  456. queue = &be->vif->queues[queue_index];
  457. queue->vif = be->vif;
  458. queue->id = queue_index;
  459. snprintf(queue->name, sizeof(queue->name), "%s-q%u",
  460. be->vif->dev->name, queue->id);
  461. err = xenvif_init_queue(queue);
  462. if (err) {
  463. /* xenvif_init_queue() cleans up after itself on
  464. * failure, but we need to clean up any previously
  465. * initialised queues. Set num_queues to i so that
  466. * earlier queues can be destroyed using the regular
  467. * disconnect logic.
  468. */
  469. be->vif->num_queues = queue_index;
  470. goto err;
  471. }
  472. queue->remaining_credit = credit_bytes;
  473. err = connect_rings(be, queue);
  474. if (err) {
  475. /* connect_rings() cleans up after itself on failure,
  476. * but we need to clean up after xenvif_init_queue() here,
  477. * and also clean up any previously initialised queues.
  478. */
  479. xenvif_deinit_queue(queue);
  480. be->vif->num_queues = queue_index;
  481. goto err;
  482. }
  483. }
  484. /* Initialisation completed, tell core driver the number of
  485. * active queues.
  486. */
  487. rtnl_lock();
  488. netif_set_real_num_tx_queues(be->vif->dev, requested_num_queues);
  489. netif_set_real_num_rx_queues(be->vif->dev, requested_num_queues);
  490. rtnl_unlock();
  491. xenvif_carrier_on(be->vif);
  492. unregister_hotplug_status_watch(be);
  493. err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
  494. hotplug_status_changed,
  495. "%s/%s", dev->nodename, "hotplug-status");
  496. if (!err)
  497. be->have_hotplug_status_watch = 1;
  498. netif_tx_wake_all_queues(be->vif->dev);
  499. return;
  500. err:
  501. if (be->vif->num_queues > 0)
  502. xenvif_disconnect(be->vif); /* Clean up existing queues */
  503. vfree(be->vif->queues);
  504. be->vif->queues = NULL;
  505. be->vif->num_queues = 0;
  506. return;
  507. }
  508. static int connect_rings(struct backend_info *be, struct xenvif_queue *queue)
  509. {
  510. struct xenbus_device *dev = be->dev;
  511. unsigned int num_queues = queue->vif->num_queues;
  512. unsigned long tx_ring_ref, rx_ring_ref;
  513. unsigned int tx_evtchn, rx_evtchn;
  514. int err;
  515. char *xspath;
  516. size_t xspathsize;
  517. const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */
  518. /* If the frontend requested 1 queue, or we have fallen back
  519. * to single queue due to lack of frontend support for multi-
  520. * queue, expect the remaining XenStore keys in the toplevel
  521. * directory. Otherwise, expect them in a subdirectory called
  522. * queue-N.
  523. */
  524. if (num_queues == 1) {
  525. xspath = kzalloc(strlen(dev->otherend) + 1, GFP_KERNEL);
  526. if (!xspath) {
  527. xenbus_dev_fatal(dev, -ENOMEM,
  528. "reading ring references");
  529. return -ENOMEM;
  530. }
  531. strcpy(xspath, dev->otherend);
  532. } else {
  533. xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
  534. xspath = kzalloc(xspathsize, GFP_KERNEL);
  535. if (!xspath) {
  536. xenbus_dev_fatal(dev, -ENOMEM,
  537. "reading ring references");
  538. return -ENOMEM;
  539. }
  540. snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend,
  541. queue->id);
  542. }
  543. err = xenbus_gather(XBT_NIL, xspath,
  544. "tx-ring-ref", "%lu", &tx_ring_ref,
  545. "rx-ring-ref", "%lu", &rx_ring_ref, NULL);
  546. if (err) {
  547. xenbus_dev_fatal(dev, err,
  548. "reading %s/ring-ref",
  549. xspath);
  550. goto err;
  551. }
  552. /* Try split event channels first, then single event channel. */
  553. err = xenbus_gather(XBT_NIL, xspath,
  554. "event-channel-tx", "%u", &tx_evtchn,
  555. "event-channel-rx", "%u", &rx_evtchn, NULL);
  556. if (err < 0) {
  557. err = xenbus_scanf(XBT_NIL, xspath,
  558. "event-channel", "%u", &tx_evtchn);
  559. if (err < 0) {
  560. xenbus_dev_fatal(dev, err,
  561. "reading %s/event-channel(-tx/rx)",
  562. xspath);
  563. goto err;
  564. }
  565. rx_evtchn = tx_evtchn;
  566. }
  567. /* Map the shared frame, irq etc. */
  568. err = xenvif_connect(queue, tx_ring_ref, rx_ring_ref,
  569. tx_evtchn, rx_evtchn);
  570. if (err) {
  571. xenbus_dev_fatal(dev, err,
  572. "mapping shared-frames %lu/%lu port tx %u rx %u",
  573. tx_ring_ref, rx_ring_ref,
  574. tx_evtchn, rx_evtchn);
  575. goto err;
  576. }
  577. err = 0;
  578. err: /* Regular return falls through with err == 0 */
  579. kfree(xspath);
  580. return err;
  581. }
  582. static int read_xenbus_vif_flags(struct backend_info *be)
  583. {
  584. struct xenvif *vif = be->vif;
  585. struct xenbus_device *dev = be->dev;
  586. unsigned int rx_copy;
  587. int err, val;
  588. err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u",
  589. &rx_copy);
  590. if (err == -ENOENT) {
  591. err = 0;
  592. rx_copy = 0;
  593. }
  594. if (err < 0) {
  595. xenbus_dev_fatal(dev, err, "reading %s/request-rx-copy",
  596. dev->otherend);
  597. return err;
  598. }
  599. if (!rx_copy)
  600. return -EOPNOTSUPP;
  601. if (vif->dev->tx_queue_len != 0) {
  602. if (xenbus_scanf(XBT_NIL, dev->otherend,
  603. "feature-rx-notify", "%d", &val) < 0)
  604. val = 0;
  605. if (val)
  606. vif->can_queue = 1;
  607. else
  608. /* Must be non-zero for pfifo_fast to work. */
  609. vif->dev->tx_queue_len = 1;
  610. }
  611. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg",
  612. "%d", &val) < 0)
  613. val = 0;
  614. vif->can_sg = !!val;
  615. vif->gso_mask = 0;
  616. vif->gso_prefix_mask = 0;
  617. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4",
  618. "%d", &val) < 0)
  619. val = 0;
  620. if (val)
  621. vif->gso_mask |= GSO_BIT(TCPV4);
  622. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4-prefix",
  623. "%d", &val) < 0)
  624. val = 0;
  625. if (val)
  626. vif->gso_prefix_mask |= GSO_BIT(TCPV4);
  627. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6",
  628. "%d", &val) < 0)
  629. val = 0;
  630. if (val)
  631. vif->gso_mask |= GSO_BIT(TCPV6);
  632. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6-prefix",
  633. "%d", &val) < 0)
  634. val = 0;
  635. if (val)
  636. vif->gso_prefix_mask |= GSO_BIT(TCPV6);
  637. if (vif->gso_mask & vif->gso_prefix_mask) {
  638. xenbus_dev_fatal(dev, err,
  639. "%s: gso and gso prefix flags are not "
  640. "mutually exclusive",
  641. dev->otherend);
  642. return -EOPNOTSUPP;
  643. }
  644. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload",
  645. "%d", &val) < 0)
  646. val = 0;
  647. vif->ip_csum = !val;
  648. if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-ipv6-csum-offload",
  649. "%d", &val) < 0)
  650. val = 0;
  651. vif->ipv6_csum = !!val;
  652. return 0;
  653. }
  654. /* ** Driver Registration ** */
  655. static const struct xenbus_device_id netback_ids[] = {
  656. { "vif" },
  657. { "" }
  658. };
  659. static DEFINE_XENBUS_DRIVER(netback, ,
  660. .probe = netback_probe,
  661. .remove = netback_remove,
  662. .uevent = netback_uevent,
  663. .otherend_changed = frontend_changed,
  664. );
  665. int xenvif_xenbus_init(void)
  666. {
  667. return xenbus_register_backend(&netback_driver);
  668. }
  669. void xenvif_xenbus_fini(void)
  670. {
  671. return xenbus_unregister_driver(&netback_driver);
  672. }