opa_vnic_vema_iface.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * Copyright(c) 2017 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. /*
  48. * This file contains OPA VNIC EMA Interface functions.
  49. */
  50. #include "opa_vnic_internal.h"
  51. /**
  52. * opa_vnic_vema_report_event - sent trap to report the specified event
  53. * @adapter: vnic port adapter
  54. * @event: event to be reported
  55. *
  56. * This function calls vema api to sent a trap for the given event.
  57. */
  58. void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event)
  59. {
  60. struct __opa_veswport_info *info = &adapter->info;
  61. struct __opa_veswport_trap trap_data;
  62. trap_data.fabric_id = info->vesw.fabric_id;
  63. trap_data.veswid = info->vesw.vesw_id;
  64. trap_data.veswportnum = info->vport.port_num;
  65. trap_data.opaportnum = adapter->port_num;
  66. trap_data.veswportindex = adapter->vport_num;
  67. trap_data.opcode = event;
  68. opa_vnic_vema_send_trap(adapter, &trap_data, info->vport.encap_slid);
  69. }
  70. /**
  71. * opa_vnic_get_error_counters - get summary counters
  72. * @adapter: vnic port adapter
  73. * @cntrs: pointer to destination summary counters structure
  74. *
  75. * This function populates the summary counters that is maintained by the
  76. * given adapter to destination address provided.
  77. */
  78. void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
  79. struct opa_veswport_summary_counters *cntrs)
  80. {
  81. struct opa_vnic_stats vstats;
  82. __be64 *dst;
  83. u64 *src;
  84. memset(&vstats, 0, sizeof(vstats));
  85. mutex_lock(&adapter->stats_lock);
  86. adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
  87. mutex_unlock(&adapter->stats_lock);
  88. cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
  89. cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
  90. cntrs->veswport_num = cpu_to_be32(adapter->port_num);
  91. cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
  92. cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
  93. cntrs->tx_packets = cpu_to_be64(vstats.netstats.tx_packets);
  94. cntrs->rx_packets = cpu_to_be64(vstats.netstats.rx_packets);
  95. cntrs->tx_bytes = cpu_to_be64(vstats.netstats.tx_bytes);
  96. cntrs->rx_bytes = cpu_to_be64(vstats.netstats.rx_bytes);
  97. /*
  98. * This loop depends on layout of
  99. * opa_veswport_summary_counters opa_vnic_stats structures.
  100. */
  101. for (dst = &cntrs->tx_unicast, src = &vstats.tx_grp.unicast;
  102. dst < &cntrs->reserved[0]; dst++, src++) {
  103. *dst = cpu_to_be64(*src);
  104. }
  105. }
  106. /**
  107. * opa_vnic_get_error_counters - get error counters
  108. * @adapter: vnic port adapter
  109. * @cntrs: pointer to destination error counters structure
  110. *
  111. * This function populates the error counters that is maintained by the
  112. * given adapter to destination address provided.
  113. */
  114. void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
  115. struct opa_veswport_error_counters *cntrs)
  116. {
  117. struct opa_vnic_stats vstats;
  118. memset(&vstats, 0, sizeof(vstats));
  119. mutex_lock(&adapter->stats_lock);
  120. adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
  121. mutex_unlock(&adapter->stats_lock);
  122. cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
  123. cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
  124. cntrs->veswport_num = cpu_to_be32(adapter->port_num);
  125. cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
  126. cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
  127. cntrs->tx_dlid_zero = cpu_to_be64(vstats.tx_dlid_zero);
  128. cntrs->tx_drop_state = cpu_to_be64(vstats.tx_drop_state);
  129. cntrs->tx_logic = cpu_to_be64(vstats.netstats.tx_fifo_errors +
  130. vstats.netstats.tx_carrier_errors);
  131. cntrs->rx_bad_veswid = cpu_to_be64(vstats.netstats.rx_nohandler);
  132. cntrs->rx_runt = cpu_to_be64(vstats.rx_runt);
  133. cntrs->rx_oversize = cpu_to_be64(vstats.rx_oversize);
  134. cntrs->rx_drop_state = cpu_to_be64(vstats.rx_drop_state);
  135. cntrs->rx_logic = cpu_to_be64(vstats.netstats.rx_fifo_errors);
  136. }
  137. /**
  138. * opa_vnic_get_vesw_info -- Get the vesw information
  139. * @adapter: vnic port adapter
  140. * @info: pointer to destination vesw info structure
  141. *
  142. * This function copies the vesw info that is maintained by the
  143. * given adapter to destination address provided.
  144. */
  145. void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
  146. struct opa_vesw_info *info)
  147. {
  148. struct __opa_vesw_info *src = &adapter->info.vesw;
  149. int i;
  150. info->fabric_id = cpu_to_be16(src->fabric_id);
  151. info->vesw_id = cpu_to_be16(src->vesw_id);
  152. memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
  153. info->def_port_mask = cpu_to_be16(src->def_port_mask);
  154. memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
  155. info->pkey = cpu_to_be16(src->pkey);
  156. memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
  157. info->u_mcast_dlid = cpu_to_be32(src->u_mcast_dlid);
  158. for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
  159. info->u_ucast_dlid[i] = cpu_to_be32(src->u_ucast_dlid[i]);
  160. memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
  161. for (i = 0; i < OPA_VNIC_MAX_NUM_PCP; i++)
  162. info->eth_mtu[i] = cpu_to_be16(src->eth_mtu[i]);
  163. info->eth_mtu_non_vlan = cpu_to_be16(src->eth_mtu_non_vlan);
  164. memcpy(info->rsvd4, src->rsvd4, ARRAY_SIZE(src->rsvd4));
  165. }
  166. /**
  167. * opa_vnic_set_vesw_info -- Set the vesw information
  168. * @adapter: vnic port adapter
  169. * @info: pointer to vesw info structure
  170. *
  171. * This function updates the vesw info that is maintained by the
  172. * given adapter with vesw info provided. Reserved fields are stored
  173. * and returned back to EM as is.
  174. */
  175. void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
  176. struct opa_vesw_info *info)
  177. {
  178. struct __opa_vesw_info *dst = &adapter->info.vesw;
  179. int i;
  180. dst->fabric_id = be16_to_cpu(info->fabric_id);
  181. dst->vesw_id = be16_to_cpu(info->vesw_id);
  182. memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
  183. dst->def_port_mask = be16_to_cpu(info->def_port_mask);
  184. memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
  185. dst->pkey = be16_to_cpu(info->pkey);
  186. memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
  187. dst->u_mcast_dlid = be32_to_cpu(info->u_mcast_dlid);
  188. for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
  189. dst->u_ucast_dlid[i] = be32_to_cpu(info->u_ucast_dlid[i]);
  190. memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
  191. for (i = 0; i < OPA_VNIC_MAX_NUM_PCP; i++)
  192. dst->eth_mtu[i] = be16_to_cpu(info->eth_mtu[i]);
  193. dst->eth_mtu_non_vlan = be16_to_cpu(info->eth_mtu_non_vlan);
  194. memcpy(dst->rsvd4, info->rsvd4, ARRAY_SIZE(info->rsvd4));
  195. }
  196. /**
  197. * opa_vnic_get_per_veswport_info -- Get the vesw per port information
  198. * @adapter: vnic port adapter
  199. * @info: pointer to destination vport info structure
  200. *
  201. * This function copies the vesw per port info that is maintained by the
  202. * given adapter to destination address provided.
  203. * Note that the read only fields are not copied.
  204. */
  205. void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
  206. struct opa_per_veswport_info *info)
  207. {
  208. struct __opa_per_veswport_info *src = &adapter->info.vport;
  209. info->port_num = cpu_to_be32(src->port_num);
  210. info->eth_link_status = src->eth_link_status;
  211. memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
  212. memcpy(info->base_mac_addr, src->base_mac_addr,
  213. ARRAY_SIZE(info->base_mac_addr));
  214. info->config_state = src->config_state;
  215. info->oper_state = src->oper_state;
  216. info->max_mac_tbl_ent = cpu_to_be16(src->max_mac_tbl_ent);
  217. info->max_smac_ent = cpu_to_be16(src->max_smac_ent);
  218. info->mac_tbl_digest = cpu_to_be32(src->mac_tbl_digest);
  219. memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
  220. info->encap_slid = cpu_to_be32(src->encap_slid);
  221. memcpy(info->pcp_to_sc_uc, src->pcp_to_sc_uc,
  222. ARRAY_SIZE(info->pcp_to_sc_uc));
  223. memcpy(info->pcp_to_vl_uc, src->pcp_to_vl_uc,
  224. ARRAY_SIZE(info->pcp_to_vl_uc));
  225. memcpy(info->pcp_to_sc_mc, src->pcp_to_sc_mc,
  226. ARRAY_SIZE(info->pcp_to_sc_mc));
  227. memcpy(info->pcp_to_vl_mc, src->pcp_to_vl_mc,
  228. ARRAY_SIZE(info->pcp_to_vl_mc));
  229. info->non_vlan_sc_uc = src->non_vlan_sc_uc;
  230. info->non_vlan_vl_uc = src->non_vlan_vl_uc;
  231. info->non_vlan_sc_mc = src->non_vlan_sc_mc;
  232. info->non_vlan_vl_mc = src->non_vlan_vl_mc;
  233. memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
  234. info->uc_macs_gen_count = cpu_to_be16(src->uc_macs_gen_count);
  235. info->mc_macs_gen_count = cpu_to_be16(src->mc_macs_gen_count);
  236. memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
  237. }
  238. /**
  239. * opa_vnic_set_per_veswport_info -- Set vesw per port information
  240. * @adapter: vnic port adapter
  241. * @info: pointer to vport info structure
  242. *
  243. * This function updates the vesw per port info that is maintained by the
  244. * given adapter with vesw per port info provided. Reserved fields are
  245. * stored and returned back to EM as is.
  246. */
  247. void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
  248. struct opa_per_veswport_info *info)
  249. {
  250. struct __opa_per_veswport_info *dst = &adapter->info.vport;
  251. dst->port_num = be32_to_cpu(info->port_num);
  252. memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
  253. memcpy(dst->base_mac_addr, info->base_mac_addr,
  254. ARRAY_SIZE(dst->base_mac_addr));
  255. dst->config_state = info->config_state;
  256. memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
  257. dst->encap_slid = be32_to_cpu(info->encap_slid);
  258. memcpy(dst->pcp_to_sc_uc, info->pcp_to_sc_uc,
  259. ARRAY_SIZE(dst->pcp_to_sc_uc));
  260. memcpy(dst->pcp_to_vl_uc, info->pcp_to_vl_uc,
  261. ARRAY_SIZE(dst->pcp_to_vl_uc));
  262. memcpy(dst->pcp_to_sc_mc, info->pcp_to_sc_mc,
  263. ARRAY_SIZE(dst->pcp_to_sc_mc));
  264. memcpy(dst->pcp_to_vl_mc, info->pcp_to_vl_mc,
  265. ARRAY_SIZE(dst->pcp_to_vl_mc));
  266. dst->non_vlan_sc_uc = info->non_vlan_sc_uc;
  267. dst->non_vlan_vl_uc = info->non_vlan_vl_uc;
  268. dst->non_vlan_sc_mc = info->non_vlan_sc_mc;
  269. dst->non_vlan_vl_mc = info->non_vlan_vl_mc;
  270. memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
  271. memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
  272. }
  273. /**
  274. * opa_vnic_query_mcast_macs - query multicast mac list
  275. * @adapter: vnic port adapter
  276. * @macs: pointer mac list
  277. *
  278. * This function populates the provided mac list with the configured
  279. * multicast addresses in the adapter.
  280. */
  281. void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
  282. struct opa_veswport_iface_macs *macs)
  283. {
  284. u16 start_idx, num_macs, idx = 0, count = 0;
  285. struct netdev_hw_addr *ha;
  286. start_idx = be16_to_cpu(macs->start_idx);
  287. num_macs = be16_to_cpu(macs->num_macs_in_msg);
  288. netdev_for_each_mc_addr(ha, adapter->netdev) {
  289. struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
  290. if (start_idx > idx++)
  291. continue;
  292. else if (num_macs == count)
  293. break;
  294. memcpy(entry, ha->addr, sizeof(*entry));
  295. count++;
  296. }
  297. macs->tot_macs_in_lst = cpu_to_be16(netdev_mc_count(adapter->netdev));
  298. macs->num_macs_in_msg = cpu_to_be16(count);
  299. macs->gen_count = cpu_to_be16(adapter->info.vport.mc_macs_gen_count);
  300. }
  301. /**
  302. * opa_vnic_query_ucast_macs - query unicast mac list
  303. * @adapter: vnic port adapter
  304. * @macs: pointer mac list
  305. *
  306. * This function populates the provided mac list with the configured
  307. * unicast addresses in the adapter.
  308. */
  309. void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
  310. struct opa_veswport_iface_macs *macs)
  311. {
  312. u16 start_idx, tot_macs, num_macs, idx = 0, count = 0;
  313. struct netdev_hw_addr *ha;
  314. start_idx = be16_to_cpu(macs->start_idx);
  315. num_macs = be16_to_cpu(macs->num_macs_in_msg);
  316. /* loop through dev_addrs list first */
  317. for_each_dev_addr(adapter->netdev, ha) {
  318. struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
  319. /* Do not include EM specified MAC address */
  320. if (!memcmp(adapter->info.vport.base_mac_addr, ha->addr,
  321. ARRAY_SIZE(adapter->info.vport.base_mac_addr)))
  322. continue;
  323. if (start_idx > idx++)
  324. continue;
  325. else if (num_macs == count)
  326. break;
  327. memcpy(entry, ha->addr, sizeof(*entry));
  328. count++;
  329. }
  330. /* loop through uc list */
  331. netdev_for_each_uc_addr(ha, adapter->netdev) {
  332. struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
  333. if (start_idx > idx++)
  334. continue;
  335. else if (num_macs == count)
  336. break;
  337. memcpy(entry, ha->addr, sizeof(*entry));
  338. count++;
  339. }
  340. tot_macs = netdev_hw_addr_list_count(&adapter->netdev->dev_addrs) +
  341. netdev_uc_count(adapter->netdev);
  342. macs->tot_macs_in_lst = cpu_to_be16(tot_macs);
  343. macs->num_macs_in_msg = cpu_to_be16(count);
  344. macs->gen_count = cpu_to_be16(adapter->info.vport.uc_macs_gen_count);
  345. }