enic_dev.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright 2011 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #include <linux/pci.h>
  19. #include <linux/etherdevice.h>
  20. #include "vnic_dev.h"
  21. #include "vnic_vic.h"
  22. #include "enic_res.h"
  23. #include "enic.h"
  24. #include "enic_dev.h"
  25. int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
  26. {
  27. int err;
  28. spin_lock_bh(&enic->devcmd_lock);
  29. err = vnic_dev_fw_info(enic->vdev, fw_info);
  30. spin_unlock_bh(&enic->devcmd_lock);
  31. return err;
  32. }
  33. int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
  34. {
  35. int err;
  36. spin_lock_bh(&enic->devcmd_lock);
  37. err = vnic_dev_stats_dump(enic->vdev, vstats);
  38. spin_unlock_bh(&enic->devcmd_lock);
  39. return err;
  40. }
  41. int enic_dev_add_station_addr(struct enic *enic)
  42. {
  43. int err;
  44. if (!is_valid_ether_addr(enic->netdev->dev_addr))
  45. return -EADDRNOTAVAIL;
  46. spin_lock_bh(&enic->devcmd_lock);
  47. err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
  48. spin_unlock_bh(&enic->devcmd_lock);
  49. return err;
  50. }
  51. int enic_dev_del_station_addr(struct enic *enic)
  52. {
  53. int err;
  54. if (!is_valid_ether_addr(enic->netdev->dev_addr))
  55. return -EADDRNOTAVAIL;
  56. spin_lock_bh(&enic->devcmd_lock);
  57. err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
  58. spin_unlock_bh(&enic->devcmd_lock);
  59. return err;
  60. }
  61. int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
  62. int broadcast, int promisc, int allmulti)
  63. {
  64. int err;
  65. spin_lock_bh(&enic->devcmd_lock);
  66. err = vnic_dev_packet_filter(enic->vdev, directed,
  67. multicast, broadcast, promisc, allmulti);
  68. spin_unlock_bh(&enic->devcmd_lock);
  69. return err;
  70. }
  71. int enic_dev_add_addr(struct enic *enic, const u8 *addr)
  72. {
  73. int err;
  74. spin_lock_bh(&enic->devcmd_lock);
  75. err = vnic_dev_add_addr(enic->vdev, addr);
  76. spin_unlock_bh(&enic->devcmd_lock);
  77. return err;
  78. }
  79. int enic_dev_del_addr(struct enic *enic, const u8 *addr)
  80. {
  81. int err;
  82. spin_lock_bh(&enic->devcmd_lock);
  83. err = vnic_dev_del_addr(enic->vdev, addr);
  84. spin_unlock_bh(&enic->devcmd_lock);
  85. return err;
  86. }
  87. int enic_dev_notify_unset(struct enic *enic)
  88. {
  89. int err;
  90. spin_lock_bh(&enic->devcmd_lock);
  91. err = vnic_dev_notify_unset(enic->vdev);
  92. spin_unlock_bh(&enic->devcmd_lock);
  93. return err;
  94. }
  95. int enic_dev_hang_notify(struct enic *enic)
  96. {
  97. int err;
  98. spin_lock_bh(&enic->devcmd_lock);
  99. err = vnic_dev_hang_notify(enic->vdev);
  100. spin_unlock_bh(&enic->devcmd_lock);
  101. return err;
  102. }
  103. int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
  104. {
  105. int err;
  106. spin_lock_bh(&enic->devcmd_lock);
  107. err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
  108. IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
  109. spin_unlock_bh(&enic->devcmd_lock);
  110. return err;
  111. }
  112. int enic_dev_enable(struct enic *enic)
  113. {
  114. int err;
  115. spin_lock_bh(&enic->devcmd_lock);
  116. err = vnic_dev_enable_wait(enic->vdev);
  117. spin_unlock_bh(&enic->devcmd_lock);
  118. return err;
  119. }
  120. int enic_dev_disable(struct enic *enic)
  121. {
  122. int err;
  123. spin_lock_bh(&enic->devcmd_lock);
  124. err = vnic_dev_disable(enic->vdev);
  125. spin_unlock_bh(&enic->devcmd_lock);
  126. return err;
  127. }
  128. int enic_dev_intr_coal_timer_info(struct enic *enic)
  129. {
  130. int err;
  131. spin_lock_bh(&enic->devcmd_lock);
  132. err = vnic_dev_intr_coal_timer_info(enic->vdev);
  133. spin_unlock_bh(&enic->devcmd_lock);
  134. return err;
  135. }
  136. /* rtnl lock is held */
  137. int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
  138. {
  139. struct enic *enic = netdev_priv(netdev);
  140. int err;
  141. spin_lock_bh(&enic->devcmd_lock);
  142. err = enic_add_vlan(enic, vid);
  143. spin_unlock_bh(&enic->devcmd_lock);
  144. return err;
  145. }
  146. /* rtnl lock is held */
  147. int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
  148. {
  149. struct enic *enic = netdev_priv(netdev);
  150. int err;
  151. spin_lock_bh(&enic->devcmd_lock);
  152. err = enic_del_vlan(enic, vid);
  153. spin_unlock_bh(&enic->devcmd_lock);
  154. return err;
  155. }
  156. int enic_dev_status_to_errno(int devcmd_status)
  157. {
  158. switch (devcmd_status) {
  159. case ERR_SUCCESS:
  160. return 0;
  161. case ERR_EINVAL:
  162. return -EINVAL;
  163. case ERR_EFAULT:
  164. return -EFAULT;
  165. case ERR_EPERM:
  166. return -EPERM;
  167. case ERR_EBUSY:
  168. return -EBUSY;
  169. case ERR_ECMDUNKNOWN:
  170. case ERR_ENOTSUPPORTED:
  171. return -EOPNOTSUPP;
  172. case ERR_EBADSTATE:
  173. return -EINVAL;
  174. case ERR_ENOMEM:
  175. return -ENOMEM;
  176. case ERR_ETIMEDOUT:
  177. return -ETIMEDOUT;
  178. case ERR_ELINKDOWN:
  179. return -ENETDOWN;
  180. case ERR_EINPROGRESS:
  181. return -EINPROGRESS;
  182. case ERR_EMAXRES:
  183. default:
  184. return (devcmd_status < 0) ? devcmd_status : -1;
  185. }
  186. }