lio_core.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more details.
  17. ***********************************************************************/
  18. #include <linux/pci.h>
  19. #include <linux/if_vlan.h>
  20. #include "liquidio_common.h"
  21. #include "octeon_droq.h"
  22. #include "octeon_iq.h"
  23. #include "response_manager.h"
  24. #include "octeon_device.h"
  25. #include "octeon_nic.h"
  26. #include "octeon_main.h"
  27. #include "octeon_network.h"
  28. int liquidio_set_feature(struct net_device *netdev, int cmd, u16 param1)
  29. {
  30. struct lio *lio = GET_LIO(netdev);
  31. struct octeon_device *oct = lio->oct_dev;
  32. struct octnic_ctrl_pkt nctrl;
  33. int ret = 0;
  34. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  35. nctrl.ncmd.u64 = 0;
  36. nctrl.ncmd.s.cmd = cmd;
  37. nctrl.ncmd.s.param1 = param1;
  38. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  39. nctrl.wait_time = 100;
  40. nctrl.netpndev = (u64)netdev;
  41. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  42. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  43. if (ret < 0) {
  44. dev_err(&oct->pci_dev->dev, "Feature change failed in core (ret: 0x%x)\n",
  45. ret);
  46. }
  47. return ret;
  48. }
  49. void octeon_report_tx_completion_to_bql(void *txq, unsigned int pkts_compl,
  50. unsigned int bytes_compl)
  51. {
  52. struct netdev_queue *netdev_queue = txq;
  53. netdev_tx_completed_queue(netdev_queue, pkts_compl, bytes_compl);
  54. }
  55. void octeon_update_tx_completion_counters(void *buf, int reqtype,
  56. unsigned int *pkts_compl,
  57. unsigned int *bytes_compl)
  58. {
  59. struct octnet_buf_free_info *finfo;
  60. struct sk_buff *skb = NULL;
  61. struct octeon_soft_command *sc;
  62. switch (reqtype) {
  63. case REQTYPE_NORESP_NET:
  64. case REQTYPE_NORESP_NET_SG:
  65. finfo = buf;
  66. skb = finfo->skb;
  67. break;
  68. case REQTYPE_RESP_NET_SG:
  69. case REQTYPE_RESP_NET:
  70. sc = buf;
  71. skb = sc->callback_arg;
  72. break;
  73. default:
  74. return;
  75. }
  76. (*pkts_compl)++;
  77. *bytes_compl += skb->len;
  78. }
  79. void octeon_report_sent_bytes_to_bql(void *buf, int reqtype)
  80. {
  81. struct octnet_buf_free_info *finfo;
  82. struct sk_buff *skb;
  83. struct octeon_soft_command *sc;
  84. struct netdev_queue *txq;
  85. switch (reqtype) {
  86. case REQTYPE_NORESP_NET:
  87. case REQTYPE_NORESP_NET_SG:
  88. finfo = buf;
  89. skb = finfo->skb;
  90. break;
  91. case REQTYPE_RESP_NET_SG:
  92. case REQTYPE_RESP_NET:
  93. sc = buf;
  94. skb = sc->callback_arg;
  95. break;
  96. default:
  97. return;
  98. }
  99. txq = netdev_get_tx_queue(skb->dev, skb_get_queue_mapping(skb));
  100. netdev_tx_sent_queue(txq, skb->len);
  101. }
  102. void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
  103. {
  104. struct octnic_ctrl_pkt *nctrl = (struct octnic_ctrl_pkt *)nctrl_ptr;
  105. struct net_device *netdev = (struct net_device *)nctrl->netpndev;
  106. struct lio *lio = GET_LIO(netdev);
  107. struct octeon_device *oct = lio->oct_dev;
  108. u8 *mac;
  109. switch (nctrl->ncmd.s.cmd) {
  110. case OCTNET_CMD_CHANGE_DEVFLAGS:
  111. case OCTNET_CMD_SET_MULTI_LIST:
  112. break;
  113. case OCTNET_CMD_CHANGE_MACADDR:
  114. mac = ((u8 *)&nctrl->udd[0]) + 2;
  115. netif_info(lio, probe, lio->netdev,
  116. "MACAddr changed to %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
  117. mac[0], mac[1],
  118. mac[2], mac[3],
  119. mac[4], mac[5]);
  120. break;
  121. case OCTNET_CMD_CHANGE_MTU:
  122. /* If command is successful, change the MTU. */
  123. netif_info(lio, probe, lio->netdev, "MTU Changed from %d to %d\n",
  124. netdev->mtu, nctrl->ncmd.s.param1);
  125. dev_info(&oct->pci_dev->dev, "%s MTU Changed from %d to %d\n",
  126. netdev->name, netdev->mtu,
  127. nctrl->ncmd.s.param1);
  128. netdev->mtu = nctrl->ncmd.s.param1;
  129. queue_delayed_work(lio->link_status_wq.wq,
  130. &lio->link_status_wq.wk.work, 0);
  131. break;
  132. case OCTNET_CMD_GPIO_ACCESS:
  133. netif_info(lio, probe, lio->netdev, "LED Flashing visual identification\n");
  134. break;
  135. case OCTNET_CMD_ID_ACTIVE:
  136. netif_info(lio, probe, lio->netdev, "LED Flashing visual identification\n");
  137. break;
  138. case OCTNET_CMD_LRO_ENABLE:
  139. dev_info(&oct->pci_dev->dev, "%s LRO Enabled\n", netdev->name);
  140. break;
  141. case OCTNET_CMD_LRO_DISABLE:
  142. dev_info(&oct->pci_dev->dev, "%s LRO Disabled\n",
  143. netdev->name);
  144. break;
  145. case OCTNET_CMD_VERBOSE_ENABLE:
  146. dev_info(&oct->pci_dev->dev, "%s Firmware debug enabled\n",
  147. netdev->name);
  148. break;
  149. case OCTNET_CMD_VERBOSE_DISABLE:
  150. dev_info(&oct->pci_dev->dev, "%s Firmware debug disabled\n",
  151. netdev->name);
  152. break;
  153. case OCTNET_CMD_ENABLE_VLAN_FILTER:
  154. dev_info(&oct->pci_dev->dev, "%s VLAN filter enabled\n",
  155. netdev->name);
  156. break;
  157. case OCTNET_CMD_ADD_VLAN_FILTER:
  158. dev_info(&oct->pci_dev->dev, "%s VLAN filter %d added\n",
  159. netdev->name, nctrl->ncmd.s.param1);
  160. break;
  161. case OCTNET_CMD_DEL_VLAN_FILTER:
  162. dev_info(&oct->pci_dev->dev, "%s VLAN filter %d removed\n",
  163. netdev->name, nctrl->ncmd.s.param1);
  164. break;
  165. case OCTNET_CMD_SET_SETTINGS:
  166. dev_info(&oct->pci_dev->dev, "%s settings changed\n",
  167. netdev->name);
  168. break;
  169. /* Case to handle "OCTNET_CMD_TNL_RX_CSUM_CTL"
  170. * Command passed by NIC driver
  171. */
  172. case OCTNET_CMD_TNL_RX_CSUM_CTL:
  173. if (nctrl->ncmd.s.param1 == OCTNET_CMD_RXCSUM_ENABLE) {
  174. netif_info(lio, probe, lio->netdev,
  175. "RX Checksum Offload Enabled\n");
  176. } else if (nctrl->ncmd.s.param1 ==
  177. OCTNET_CMD_RXCSUM_DISABLE) {
  178. netif_info(lio, probe, lio->netdev,
  179. "RX Checksum Offload Disabled\n");
  180. }
  181. break;
  182. /* Case to handle "OCTNET_CMD_TNL_TX_CSUM_CTL"
  183. * Command passed by NIC driver
  184. */
  185. case OCTNET_CMD_TNL_TX_CSUM_CTL:
  186. if (nctrl->ncmd.s.param1 == OCTNET_CMD_TXCSUM_ENABLE) {
  187. netif_info(lio, probe, lio->netdev,
  188. "TX Checksum Offload Enabled\n");
  189. } else if (nctrl->ncmd.s.param1 ==
  190. OCTNET_CMD_TXCSUM_DISABLE) {
  191. netif_info(lio, probe, lio->netdev,
  192. "TX Checksum Offload Disabled\n");
  193. }
  194. break;
  195. /* Case to handle "OCTNET_CMD_VXLAN_PORT_CONFIG"
  196. * Command passed by NIC driver
  197. */
  198. case OCTNET_CMD_VXLAN_PORT_CONFIG:
  199. if (nctrl->ncmd.s.more == OCTNET_CMD_VXLAN_PORT_ADD) {
  200. netif_info(lio, probe, lio->netdev,
  201. "VxLAN Destination UDP PORT:%d ADDED\n",
  202. nctrl->ncmd.s.param1);
  203. } else if (nctrl->ncmd.s.more ==
  204. OCTNET_CMD_VXLAN_PORT_DEL) {
  205. netif_info(lio, probe, lio->netdev,
  206. "VxLAN Destination UDP PORT:%d DELETED\n",
  207. nctrl->ncmd.s.param1);
  208. }
  209. break;
  210. case OCTNET_CMD_SET_FLOW_CTL:
  211. netif_info(lio, probe, lio->netdev, "Set RX/TX flow control parameters\n");
  212. break;
  213. default:
  214. dev_err(&oct->pci_dev->dev, "%s Unknown cmd %d\n", __func__,
  215. nctrl->ncmd.s.cmd);
  216. }
  217. }
  218. void octeon_pf_changed_vf_macaddr(struct octeon_device *oct, u8 *mac)
  219. {
  220. bool macaddr_changed = false;
  221. struct net_device *netdev;
  222. struct lio *lio;
  223. rtnl_lock();
  224. netdev = oct->props[0].netdev;
  225. lio = GET_LIO(netdev);
  226. lio->linfo.macaddr_is_admin_asgnd = true;
  227. if (!ether_addr_equal(netdev->dev_addr, mac)) {
  228. macaddr_changed = true;
  229. ether_addr_copy(netdev->dev_addr, mac);
  230. ether_addr_copy(((u8 *)&lio->linfo.hw_addr) + 2, mac);
  231. call_netdevice_notifiers(NETDEV_CHANGEADDR, netdev);
  232. }
  233. rtnl_unlock();
  234. if (macaddr_changed)
  235. dev_info(&oct->pci_dev->dev,
  236. "PF changed VF's MAC address to %pM\n", mac);
  237. /* no need to notify the firmware of the macaddr change because
  238. * the PF did that already
  239. */
  240. }