netdev.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2012 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/slab.h>
  20. #include "wil6210.h"
  21. static int wil_open(struct net_device *ndev)
  22. {
  23. struct wil6210_priv *wil = ndev_to_wil(ndev);
  24. return wil_up(wil);
  25. }
  26. static int wil_stop(struct net_device *ndev)
  27. {
  28. struct wil6210_priv *wil = ndev_to_wil(ndev);
  29. return wil_down(wil);
  30. }
  31. /*
  32. * AC to queue mapping
  33. *
  34. * AC_VO -> queue 3
  35. * AC_VI -> queue 2
  36. * AC_BE -> queue 1
  37. * AC_BK -> queue 0
  38. */
  39. static u16 wil_select_queue(struct net_device *ndev, struct sk_buff *skb)
  40. {
  41. static const u16 wil_1d_to_queue[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
  42. struct wil6210_priv *wil = ndev_to_wil(ndev);
  43. u16 rc;
  44. skb->priority = cfg80211_classify8021d(skb);
  45. rc = wil_1d_to_queue[skb->priority];
  46. wil_dbg_TXRX(wil, "%s() %d -> %d\n", __func__, (int)skb->priority,
  47. (int)rc);
  48. return rc;
  49. }
  50. static const struct net_device_ops wil_netdev_ops = {
  51. .ndo_open = wil_open,
  52. .ndo_stop = wil_stop,
  53. .ndo_start_xmit = wil_start_xmit,
  54. .ndo_select_queue = wil_select_queue,
  55. .ndo_set_mac_address = eth_mac_addr,
  56. .ndo_validate_addr = eth_validate_addr,
  57. };
  58. void *wil_if_alloc(struct device *dev, void __iomem *csr)
  59. {
  60. struct net_device *ndev;
  61. struct wireless_dev *wdev;
  62. struct wil6210_priv *wil;
  63. struct ieee80211_channel *ch;
  64. int rc = 0;
  65. wdev = wil_cfg80211_init(dev);
  66. if (IS_ERR(wdev)) {
  67. dev_err(dev, "wil_cfg80211_init failed\n");
  68. return wdev;
  69. }
  70. wil = wdev_to_wil(wdev);
  71. wil->csr = csr;
  72. wil->wdev = wdev;
  73. rc = wil_priv_init(wil);
  74. if (rc) {
  75. dev_err(dev, "wil_priv_init failed\n");
  76. goto out_wdev;
  77. }
  78. wdev->iftype = NL80211_IFTYPE_STATION; /* TODO */
  79. /* default monitor channel */
  80. ch = wdev->wiphy->bands[IEEE80211_BAND_60GHZ]->channels;
  81. cfg80211_chandef_create(&wdev->preset_chandef, ch, NL80211_CHAN_NO_HT);
  82. ndev = alloc_netdev_mqs(0, "wlan%d", ether_setup, WIL6210_TX_QUEUES, 1);
  83. if (!ndev) {
  84. dev_err(dev, "alloc_netdev_mqs failed\n");
  85. rc = -ENOMEM;
  86. goto out_priv;
  87. }
  88. ndev->netdev_ops = &wil_netdev_ops;
  89. ndev->ieee80211_ptr = wdev;
  90. SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
  91. wdev->netdev = ndev;
  92. wil_link_off(wil);
  93. return wil;
  94. out_priv:
  95. wil_priv_deinit(wil);
  96. out_wdev:
  97. wil_wdev_free(wil);
  98. return ERR_PTR(rc);
  99. }
  100. void wil_if_free(struct wil6210_priv *wil)
  101. {
  102. struct net_device *ndev = wil_to_ndev(wil);
  103. if (!ndev)
  104. return;
  105. free_netdev(ndev);
  106. wil_priv_deinit(wil);
  107. wil_wdev_free(wil);
  108. }
  109. int wil_if_add(struct wil6210_priv *wil)
  110. {
  111. struct net_device *ndev = wil_to_ndev(wil);
  112. int rc;
  113. rc = register_netdev(ndev);
  114. if (rc < 0) {
  115. dev_err(&ndev->dev, "Failed to register netdev: %d\n", rc);
  116. return rc;
  117. }
  118. wil_link_off(wil);
  119. return 0;
  120. }
  121. void wil_if_remove(struct wil6210_priv *wil)
  122. {
  123. struct net_device *ndev = wil_to_ndev(wil);
  124. unregister_netdev(ndev);
  125. }