netdev.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. static const struct net_device_ops wil_netdev_ops = {
  32. .ndo_open = wil_open,
  33. .ndo_stop = wil_stop,
  34. .ndo_start_xmit = wil_start_xmit,
  35. .ndo_set_mac_address = eth_mac_addr,
  36. .ndo_validate_addr = eth_validate_addr,
  37. };
  38. void *wil_if_alloc(struct device *dev, void __iomem *csr)
  39. {
  40. struct net_device *ndev;
  41. struct wireless_dev *wdev;
  42. struct wil6210_priv *wil;
  43. struct ieee80211_channel *ch;
  44. int rc = 0;
  45. wdev = wil_cfg80211_init(dev);
  46. if (IS_ERR(wdev)) {
  47. dev_err(dev, "wil_cfg80211_init failed\n");
  48. return wdev;
  49. }
  50. wil = wdev_to_wil(wdev);
  51. wil->csr = csr;
  52. wil->wdev = wdev;
  53. rc = wil_priv_init(wil);
  54. if (rc) {
  55. dev_err(dev, "wil_priv_init failed\n");
  56. goto out_wdev;
  57. }
  58. wdev->iftype = NL80211_IFTYPE_STATION; /* TODO */
  59. /* default monitor channel */
  60. ch = wdev->wiphy->bands[IEEE80211_BAND_60GHZ]->channels;
  61. cfg80211_chandef_create(&wdev->preset_chandef, ch, NL80211_CHAN_NO_HT);
  62. ndev = alloc_netdev(0, "wlan%d", ether_setup);
  63. if (!ndev) {
  64. dev_err(dev, "alloc_netdev_mqs failed\n");
  65. rc = -ENOMEM;
  66. goto out_priv;
  67. }
  68. ndev->netdev_ops = &wil_netdev_ops;
  69. ndev->ieee80211_ptr = wdev;
  70. SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
  71. wdev->netdev = ndev;
  72. wil_link_off(wil);
  73. return wil;
  74. out_priv:
  75. wil_priv_deinit(wil);
  76. out_wdev:
  77. wil_wdev_free(wil);
  78. return ERR_PTR(rc);
  79. }
  80. void wil_if_free(struct wil6210_priv *wil)
  81. {
  82. struct net_device *ndev = wil_to_ndev(wil);
  83. if (!ndev)
  84. return;
  85. free_netdev(ndev);
  86. wil_priv_deinit(wil);
  87. wil_wdev_free(wil);
  88. }
  89. int wil_if_add(struct wil6210_priv *wil)
  90. {
  91. struct net_device *ndev = wil_to_ndev(wil);
  92. int rc;
  93. rc = register_netdev(ndev);
  94. if (rc < 0) {
  95. dev_err(&ndev->dev, "Failed to register netdev: %d\n", rc);
  96. return rc;
  97. }
  98. wil_link_off(wil);
  99. return 0;
  100. }
  101. void wil_if_remove(struct wil6210_priv *wil)
  102. {
  103. struct net_device *ndev = wil_to_ndev(wil);
  104. unregister_netdev(ndev);
  105. }