ifdi_if.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #
  2. # Copyright (c) 2014, Matthew Macy (mmacy@mattmacy.io)
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright notice,
  9. # this list of conditions and the following disclaimer.
  10. #
  11. # 2. Neither the name of Matthew Macy nor the names of its
  12. # contributors may be used to endorse or promote products derived from
  13. # this software without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. # POSSIBILITY OF SUCH DAMAGE.
  26. #
  27. #
  28. #include <sys/types.h>
  29. #include <sys/systm.h>
  30. #include <sys/socket.h>
  31. #include <machine/bus.h>
  32. #include <sys/bus.h>
  33. #include <net/ethernet.h>
  34. #include <net/if.h>
  35. #include <net/if_var.h>
  36. #include <net/if_media.h>
  37. #include <net/iflib.h>
  38. #include <net/if_private.h>
  39. INTERFACE ifdi;
  40. CODE {
  41. static void
  42. null_void_op(if_ctx_t _ctx __unused)
  43. {
  44. }
  45. static void
  46. null_timer_op(if_ctx_t _ctx __unused, uint16_t _qsidx __unused)
  47. {
  48. }
  49. static int
  50. null_int_op(if_ctx_t _ctx __unused)
  51. {
  52. return (0);
  53. }
  54. static int
  55. null_queue_intr_enable(if_ctx_t _ctx __unused, uint16_t _qid __unused)
  56. {
  57. return (ENOTSUP);
  58. }
  59. static void
  60. null_led_func(if_ctx_t _ctx __unused, int _onoff __unused)
  61. {
  62. }
  63. static void
  64. null_vlan_register_op(if_ctx_t _ctx __unused, uint16_t vtag __unused)
  65. {
  66. }
  67. static int
  68. null_q_setup(if_ctx_t _ctx __unused, uint32_t _qid __unused)
  69. {
  70. return (0);
  71. }
  72. static int
  73. null_i2c_req(if_ctx_t _sctx __unused, struct ifi2creq *_i2c __unused)
  74. {
  75. return (ENOTSUP);
  76. }
  77. static int
  78. null_sysctl_int_delay(if_ctx_t _sctx __unused, if_int_delay_info_t _iidi __unused)
  79. {
  80. return (0);
  81. }
  82. static int
  83. null_iov_init(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
  84. {
  85. return (ENOTSUP);
  86. }
  87. static int
  88. null_vf_add(if_ctx_t _ctx __unused, uint16_t num_vfs __unused, const nvlist_t *params __unused)
  89. {
  90. return (ENOTSUP);
  91. }
  92. static int
  93. null_priv_ioctl(if_ctx_t _ctx __unused, u_long command, caddr_t *data __unused)
  94. {
  95. return (ENOTSUP);
  96. }
  97. static bool
  98. null_needs_restart(if_ctx_t _ctx __unused, enum iflib_restart_event _event __unused)
  99. {
  100. return (false);
  101. }
  102. };
  103. #
  104. # bus interfaces
  105. #
  106. METHOD int attach_pre {
  107. if_ctx_t _ctx;
  108. };
  109. METHOD int attach_post {
  110. if_ctx_t _ctx;
  111. };
  112. METHOD int reinit_pre {
  113. if_ctx_t _ctx;
  114. };
  115. METHOD int reinit_post {
  116. if_ctx_t _ctx;
  117. };
  118. METHOD int detach {
  119. if_ctx_t _ctx;
  120. };
  121. METHOD int suspend {
  122. if_ctx_t _ctx;
  123. } DEFAULT null_int_op;
  124. METHOD int shutdown {
  125. if_ctx_t _ctx;
  126. } DEFAULT null_int_op;
  127. METHOD int resume {
  128. if_ctx_t _ctx;
  129. } DEFAULT null_int_op;
  130. #
  131. # downcall to driver to allocate its
  132. # own queue state and tie it to the parent
  133. #
  134. METHOD int tx_queues_alloc {
  135. if_ctx_t _ctx;
  136. caddr_t *_vaddrs;
  137. uint64_t *_paddrs;
  138. int ntxqs;
  139. int ntxqsets;
  140. };
  141. METHOD int rx_queues_alloc {
  142. if_ctx_t _ctx;
  143. caddr_t *_vaddrs;
  144. uint64_t *_paddrs;
  145. int nrxqs;
  146. int nrxqsets;
  147. };
  148. METHOD void queues_free {
  149. if_ctx_t _ctx;
  150. };
  151. #
  152. # interface reset / stop
  153. #
  154. METHOD void init {
  155. if_ctx_t _ctx;
  156. };
  157. METHOD void stop {
  158. if_ctx_t _ctx;
  159. };
  160. #
  161. # interrupt setup and manipulation
  162. #
  163. METHOD int msix_intr_assign {
  164. if_ctx_t _sctx;
  165. int msix;
  166. };
  167. METHOD void intr_enable {
  168. if_ctx_t _ctx;
  169. };
  170. METHOD void intr_disable {
  171. if_ctx_t _ctx;
  172. };
  173. METHOD int rx_queue_intr_enable {
  174. if_ctx_t _ctx;
  175. uint16_t _qid;
  176. } DEFAULT null_queue_intr_enable;
  177. METHOD int tx_queue_intr_enable {
  178. if_ctx_t _ctx;
  179. uint16_t _qid;
  180. } DEFAULT null_queue_intr_enable;
  181. METHOD void link_intr_enable {
  182. if_ctx_t _ctx;
  183. } DEFAULT null_void_op;
  184. METHOD void admin_completion_handle {
  185. if_ctx_t _ctx;
  186. } DEFAULT null_void_op;
  187. #
  188. # interface configuration
  189. #
  190. METHOD void multi_set {
  191. if_ctx_t _ctx;
  192. };
  193. METHOD int mtu_set {
  194. if_ctx_t _ctx;
  195. uint32_t _mtu;
  196. };
  197. METHOD void media_set{
  198. if_ctx_t _ctx;
  199. } DEFAULT null_void_op;
  200. METHOD int promisc_set {
  201. if_ctx_t _ctx;
  202. int _flags;
  203. };
  204. METHOD void crcstrip_set {
  205. if_ctx_t _ctx;
  206. int _onoff;
  207. int _strip;
  208. };
  209. #
  210. # IOV handling
  211. #
  212. METHOD void vflr_handle {
  213. if_ctx_t _ctx;
  214. } DEFAULT null_void_op;
  215. METHOD int iov_init {
  216. if_ctx_t _ctx;
  217. uint16_t num_vfs;
  218. const nvlist_t * params;
  219. } DEFAULT null_iov_init;
  220. METHOD void iov_uninit {
  221. if_ctx_t _ctx;
  222. } DEFAULT null_void_op;
  223. METHOD int iov_vf_add {
  224. if_ctx_t _ctx;
  225. uint16_t num_vfs;
  226. const nvlist_t * params;
  227. } DEFAULT null_vf_add;
  228. #
  229. # Device status
  230. #
  231. METHOD void update_admin_status {
  232. if_ctx_t _ctx;
  233. };
  234. METHOD void media_status {
  235. if_ctx_t _ctx;
  236. struct ifmediareq *_ifm;
  237. };
  238. METHOD int media_change {
  239. if_ctx_t _ctx;
  240. };
  241. METHOD uint64_t get_counter {
  242. if_ctx_t _ctx;
  243. ift_counter cnt;
  244. };
  245. METHOD int priv_ioctl {
  246. if_ctx_t _ctx;
  247. u_long _cmd;
  248. caddr_t _data;
  249. } DEFAULT null_priv_ioctl;
  250. #
  251. # optional methods
  252. #
  253. METHOD int i2c_req {
  254. if_ctx_t _ctx;
  255. struct ifi2creq *_req;
  256. } DEFAULT null_i2c_req;
  257. METHOD int txq_setup {
  258. if_ctx_t _ctx;
  259. uint32_t _txqid;
  260. } DEFAULT null_q_setup;
  261. METHOD int rxq_setup {
  262. if_ctx_t _ctx;
  263. uint32_t _txqid;
  264. } DEFAULT null_q_setup;
  265. METHOD void timer {
  266. if_ctx_t _ctx;
  267. uint16_t _txqid;
  268. } DEFAULT null_timer_op;
  269. METHOD void watchdog_reset {
  270. if_ctx_t _ctx;
  271. } DEFAULT null_void_op;
  272. METHOD void led_func {
  273. if_ctx_t _ctx;
  274. int _onoff;
  275. } DEFAULT null_led_func;
  276. METHOD void vlan_register {
  277. if_ctx_t _ctx;
  278. uint16_t _vtag;
  279. } DEFAULT null_vlan_register_op;
  280. METHOD void vlan_unregister {
  281. if_ctx_t _ctx;
  282. uint16_t _vtag;
  283. } DEFAULT null_vlan_register_op;
  284. METHOD int sysctl_int_delay {
  285. if_ctx_t _sctx;
  286. if_int_delay_info_t _iidi;
  287. } DEFAULT null_sysctl_int_delay;
  288. METHOD void debug {
  289. if_ctx_t _ctx;
  290. } DEFAULT null_void_op;
  291. METHOD bool needs_restart {
  292. if_ctx_t _ctx;
  293. enum iflib_restart_event _event;
  294. } DEFAULT null_needs_restart;