en_netdev.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/etherdevice.h>
  34. #include <linux/tcp.h>
  35. #include <linux/if_vlan.h>
  36. #include <linux/delay.h>
  37. #include <linux/slab.h>
  38. #include <linux/mlx4/driver.h>
  39. #include <linux/mlx4/device.h>
  40. #include <linux/mlx4/cmd.h>
  41. #include <linux/mlx4/cq.h>
  42. #include "mlx4_en.h"
  43. #include "en_port.h"
  44. static void mlx4_en_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  45. {
  46. struct mlx4_en_priv *priv = netdev_priv(dev);
  47. struct mlx4_en_dev *mdev = priv->mdev;
  48. int err;
  49. int idx;
  50. en_dbg(HW, priv, "adding VLAN:%d\n", vid);
  51. set_bit(vid, priv->active_vlans);
  52. /* Add VID to port VLAN filter */
  53. mutex_lock(&mdev->state_lock);
  54. if (mdev->device_up && priv->port_up) {
  55. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  56. if (err)
  57. en_err(priv, "Failed configuring VLAN filter\n");
  58. }
  59. if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
  60. en_err(priv, "failed adding vlan %d\n", vid);
  61. mutex_unlock(&mdev->state_lock);
  62. }
  63. static void mlx4_en_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  64. {
  65. struct mlx4_en_priv *priv = netdev_priv(dev);
  66. struct mlx4_en_dev *mdev = priv->mdev;
  67. int err;
  68. int idx;
  69. en_dbg(HW, priv, "Killing VID:%d\n", vid);
  70. clear_bit(vid, priv->active_vlans);
  71. /* Remove VID from port VLAN filter */
  72. mutex_lock(&mdev->state_lock);
  73. if (!mlx4_find_cached_vlan(mdev->dev, priv->port, vid, &idx))
  74. mlx4_unregister_vlan(mdev->dev, priv->port, idx);
  75. else
  76. en_err(priv, "could not find vid %d in cache\n", vid);
  77. if (mdev->device_up && priv->port_up) {
  78. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  79. if (err)
  80. en_err(priv, "Failed configuring VLAN filter\n");
  81. }
  82. mutex_unlock(&mdev->state_lock);
  83. }
  84. u64 mlx4_en_mac_to_u64(u8 *addr)
  85. {
  86. u64 mac = 0;
  87. int i;
  88. for (i = 0; i < ETH_ALEN; i++) {
  89. mac <<= 8;
  90. mac |= addr[i];
  91. }
  92. return mac;
  93. }
  94. static int mlx4_en_set_mac(struct net_device *dev, void *addr)
  95. {
  96. struct mlx4_en_priv *priv = netdev_priv(dev);
  97. struct mlx4_en_dev *mdev = priv->mdev;
  98. struct sockaddr *saddr = addr;
  99. if (!is_valid_ether_addr(saddr->sa_data))
  100. return -EADDRNOTAVAIL;
  101. memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
  102. priv->mac = mlx4_en_mac_to_u64(dev->dev_addr);
  103. queue_work(mdev->workqueue, &priv->mac_task);
  104. return 0;
  105. }
  106. static void mlx4_en_do_set_mac(struct work_struct *work)
  107. {
  108. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  109. mac_task);
  110. struct mlx4_en_dev *mdev = priv->mdev;
  111. int err = 0;
  112. mutex_lock(&mdev->state_lock);
  113. if (priv->port_up) {
  114. /* Remove old MAC and insert the new one */
  115. err = mlx4_replace_mac(mdev->dev, priv->port,
  116. priv->base_qpn, priv->mac, 0);
  117. if (err)
  118. en_err(priv, "Failed changing HW MAC address\n");
  119. } else
  120. en_dbg(HW, priv, "Port is down while "
  121. "registering mac, exiting...\n");
  122. mutex_unlock(&mdev->state_lock);
  123. }
  124. static void mlx4_en_clear_list(struct net_device *dev)
  125. {
  126. struct mlx4_en_priv *priv = netdev_priv(dev);
  127. kfree(priv->mc_addrs);
  128. priv->mc_addrs_cnt = 0;
  129. }
  130. static void mlx4_en_cache_mclist(struct net_device *dev)
  131. {
  132. struct mlx4_en_priv *priv = netdev_priv(dev);
  133. struct netdev_hw_addr *ha;
  134. char *mc_addrs;
  135. int mc_addrs_cnt = netdev_mc_count(dev);
  136. int i;
  137. mc_addrs = kmalloc(mc_addrs_cnt * ETH_ALEN, GFP_ATOMIC);
  138. if (!mc_addrs) {
  139. en_err(priv, "failed to allocate multicast list\n");
  140. return;
  141. }
  142. i = 0;
  143. netdev_for_each_mc_addr(ha, dev)
  144. memcpy(mc_addrs + i++ * ETH_ALEN, ha->addr, ETH_ALEN);
  145. priv->mc_addrs = mc_addrs;
  146. priv->mc_addrs_cnt = mc_addrs_cnt;
  147. }
  148. static void mlx4_en_set_multicast(struct net_device *dev)
  149. {
  150. struct mlx4_en_priv *priv = netdev_priv(dev);
  151. if (!priv->port_up)
  152. return;
  153. queue_work(priv->mdev->workqueue, &priv->mcast_task);
  154. }
  155. static void mlx4_en_do_set_multicast(struct work_struct *work)
  156. {
  157. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  158. mcast_task);
  159. struct mlx4_en_dev *mdev = priv->mdev;
  160. struct net_device *dev = priv->dev;
  161. u64 mcast_addr = 0;
  162. u8 mc_list[16] = {0};
  163. int err;
  164. mutex_lock(&mdev->state_lock);
  165. if (!mdev->device_up) {
  166. en_dbg(HW, priv, "Card is not up, "
  167. "ignoring multicast change.\n");
  168. goto out;
  169. }
  170. if (!priv->port_up) {
  171. en_dbg(HW, priv, "Port is down, "
  172. "ignoring multicast change.\n");
  173. goto out;
  174. }
  175. /*
  176. * Promsicuous mode: disable all filters
  177. */
  178. if (dev->flags & IFF_PROMISC) {
  179. if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
  180. if (netif_msg_rx_status(priv))
  181. en_warn(priv, "Entering promiscuous mode\n");
  182. priv->flags |= MLX4_EN_FLAG_PROMISC;
  183. /* Enable promiscouos mode */
  184. if (!(mdev->dev->caps.flags &
  185. MLX4_DEV_CAP_FLAG_VEP_UC_STEER))
  186. err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port,
  187. priv->base_qpn, 1);
  188. else
  189. err = mlx4_unicast_promisc_add(mdev->dev, priv->base_qpn,
  190. priv->port);
  191. if (err)
  192. en_err(priv, "Failed enabling "
  193. "promiscuous mode\n");
  194. /* Disable port multicast filter (unconditionally) */
  195. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  196. 0, MLX4_MCAST_DISABLE);
  197. if (err)
  198. en_err(priv, "Failed disabling "
  199. "multicast filter\n");
  200. /* Add the default qp number as multicast promisc */
  201. if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
  202. err = mlx4_multicast_promisc_add(mdev->dev, priv->base_qpn,
  203. priv->port);
  204. if (err)
  205. en_err(priv, "Failed entering multicast promisc mode\n");
  206. priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
  207. }
  208. /* Disable port VLAN filter */
  209. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  210. if (err)
  211. en_err(priv, "Failed disabling VLAN filter\n");
  212. }
  213. goto out;
  214. }
  215. /*
  216. * Not in promiscuous mode
  217. */
  218. if (priv->flags & MLX4_EN_FLAG_PROMISC) {
  219. if (netif_msg_rx_status(priv))
  220. en_warn(priv, "Leaving promiscuous mode\n");
  221. priv->flags &= ~MLX4_EN_FLAG_PROMISC;
  222. /* Disable promiscouos mode */
  223. if (!(mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER))
  224. err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port,
  225. priv->base_qpn, 0);
  226. else
  227. err = mlx4_unicast_promisc_remove(mdev->dev, priv->base_qpn,
  228. priv->port);
  229. if (err)
  230. en_err(priv, "Failed disabling promiscuous mode\n");
  231. /* Disable Multicast promisc */
  232. if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
  233. err = mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
  234. priv->port);
  235. if (err)
  236. en_err(priv, "Failed disabling multicast promiscuous mode\n");
  237. priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
  238. }
  239. /* Enable port VLAN filter */
  240. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  241. if (err)
  242. en_err(priv, "Failed enabling VLAN filter\n");
  243. }
  244. /* Enable/disable the multicast filter according to IFF_ALLMULTI */
  245. if (dev->flags & IFF_ALLMULTI) {
  246. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  247. 0, MLX4_MCAST_DISABLE);
  248. if (err)
  249. en_err(priv, "Failed disabling multicast filter\n");
  250. /* Add the default qp number as multicast promisc */
  251. if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
  252. err = mlx4_multicast_promisc_add(mdev->dev, priv->base_qpn,
  253. priv->port);
  254. if (err)
  255. en_err(priv, "Failed entering multicast promisc mode\n");
  256. priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
  257. }
  258. } else {
  259. int i;
  260. /* Disable Multicast promisc */
  261. if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
  262. err = mlx4_multicast_promisc_remove(mdev->dev, priv->base_qpn,
  263. priv->port);
  264. if (err)
  265. en_err(priv, "Failed disabling multicast promiscuous mode\n");
  266. priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
  267. }
  268. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  269. 0, MLX4_MCAST_DISABLE);
  270. if (err)
  271. en_err(priv, "Failed disabling multicast filter\n");
  272. /* Detach our qp from all the multicast addresses */
  273. for (i = 0; i < priv->mc_addrs_cnt; i++) {
  274. memcpy(&mc_list[10], priv->mc_addrs + i * ETH_ALEN, ETH_ALEN);
  275. mc_list[5] = priv->port;
  276. mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
  277. mc_list, MLX4_PROT_ETH);
  278. }
  279. /* Flush mcast filter and init it with broadcast address */
  280. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
  281. 1, MLX4_MCAST_CONFIG);
  282. /* Update multicast list - we cache all addresses so they won't
  283. * change while HW is updated holding the command semaphor */
  284. netif_tx_lock_bh(dev);
  285. mlx4_en_cache_mclist(dev);
  286. netif_tx_unlock_bh(dev);
  287. for (i = 0; i < priv->mc_addrs_cnt; i++) {
  288. mcast_addr =
  289. mlx4_en_mac_to_u64(priv->mc_addrs + i * ETH_ALEN);
  290. memcpy(&mc_list[10], priv->mc_addrs + i * ETH_ALEN, ETH_ALEN);
  291. mc_list[5] = priv->port;
  292. mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp,
  293. mc_list, 0, MLX4_PROT_ETH);
  294. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
  295. mcast_addr, 0, MLX4_MCAST_CONFIG);
  296. }
  297. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  298. 0, MLX4_MCAST_ENABLE);
  299. if (err)
  300. en_err(priv, "Failed enabling multicast filter\n");
  301. }
  302. out:
  303. mutex_unlock(&mdev->state_lock);
  304. }
  305. #ifdef CONFIG_NET_POLL_CONTROLLER
  306. static void mlx4_en_netpoll(struct net_device *dev)
  307. {
  308. struct mlx4_en_priv *priv = netdev_priv(dev);
  309. struct mlx4_en_cq *cq;
  310. unsigned long flags;
  311. int i;
  312. for (i = 0; i < priv->rx_ring_num; i++) {
  313. cq = &priv->rx_cq[i];
  314. spin_lock_irqsave(&cq->lock, flags);
  315. napi_synchronize(&cq->napi);
  316. mlx4_en_process_rx_cq(dev, cq, 0);
  317. spin_unlock_irqrestore(&cq->lock, flags);
  318. }
  319. }
  320. #endif
  321. static void mlx4_en_tx_timeout(struct net_device *dev)
  322. {
  323. struct mlx4_en_priv *priv = netdev_priv(dev);
  324. struct mlx4_en_dev *mdev = priv->mdev;
  325. if (netif_msg_timer(priv))
  326. en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
  327. priv->port_stats.tx_timeout++;
  328. en_dbg(DRV, priv, "Scheduling watchdog\n");
  329. queue_work(mdev->workqueue, &priv->watchdog_task);
  330. }
  331. static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
  332. {
  333. struct mlx4_en_priv *priv = netdev_priv(dev);
  334. spin_lock_bh(&priv->stats_lock);
  335. memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
  336. spin_unlock_bh(&priv->stats_lock);
  337. return &priv->ret_stats;
  338. }
  339. static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
  340. {
  341. struct mlx4_en_cq *cq;
  342. int i;
  343. /* If we haven't received a specific coalescing setting
  344. * (module param), we set the moderation parameters as follows:
  345. * - moder_cnt is set to the number of mtu sized packets to
  346. * satisfy our coelsing target.
  347. * - moder_time is set to a fixed value.
  348. */
  349. priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
  350. priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
  351. en_dbg(INTR, priv, "Default coalesing params for mtu:%d - "
  352. "rx_frames:%d rx_usecs:%d\n",
  353. priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
  354. /* Setup cq moderation params */
  355. for (i = 0; i < priv->rx_ring_num; i++) {
  356. cq = &priv->rx_cq[i];
  357. cq->moder_cnt = priv->rx_frames;
  358. cq->moder_time = priv->rx_usecs;
  359. priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
  360. priv->last_moder_packets[i] = 0;
  361. priv->last_moder_bytes[i] = 0;
  362. }
  363. for (i = 0; i < priv->tx_ring_num; i++) {
  364. cq = &priv->tx_cq[i];
  365. cq->moder_cnt = MLX4_EN_TX_COAL_PKTS;
  366. cq->moder_time = MLX4_EN_TX_COAL_TIME;
  367. }
  368. /* Reset auto-moderation params */
  369. priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
  370. priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
  371. priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
  372. priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
  373. priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
  374. priv->adaptive_rx_coal = 1;
  375. priv->last_moder_jiffies = 0;
  376. priv->last_moder_tx_packets = 0;
  377. }
  378. static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
  379. {
  380. unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
  381. struct mlx4_en_cq *cq;
  382. unsigned long packets;
  383. unsigned long rate;
  384. unsigned long avg_pkt_size;
  385. unsigned long rx_packets;
  386. unsigned long rx_bytes;
  387. unsigned long rx_pkt_diff;
  388. int moder_time;
  389. int ring, err;
  390. if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
  391. return;
  392. for (ring = 0; ring < priv->rx_ring_num; ring++) {
  393. spin_lock_bh(&priv->stats_lock);
  394. rx_packets = priv->rx_ring[ring].packets;
  395. rx_bytes = priv->rx_ring[ring].bytes;
  396. spin_unlock_bh(&priv->stats_lock);
  397. rx_pkt_diff = ((unsigned long) (rx_packets -
  398. priv->last_moder_packets[ring]));
  399. packets = rx_pkt_diff;
  400. rate = packets * HZ / period;
  401. avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
  402. priv->last_moder_bytes[ring])) / packets : 0;
  403. /* Apply auto-moderation only when packet rate
  404. * exceeds a rate that it matters */
  405. if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
  406. avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
  407. if (rate < priv->pkt_rate_low)
  408. moder_time = priv->rx_usecs_low;
  409. else if (rate > priv->pkt_rate_high)
  410. moder_time = priv->rx_usecs_high;
  411. else
  412. moder_time = (rate - priv->pkt_rate_low) *
  413. (priv->rx_usecs_high - priv->rx_usecs_low) /
  414. (priv->pkt_rate_high - priv->pkt_rate_low) +
  415. priv->rx_usecs_low;
  416. } else {
  417. moder_time = priv->rx_usecs_low;
  418. }
  419. if (moder_time != priv->last_moder_time[ring]) {
  420. priv->last_moder_time[ring] = moder_time;
  421. cq = &priv->rx_cq[ring];
  422. cq->moder_time = moder_time;
  423. err = mlx4_en_set_cq_moder(priv, cq);
  424. if (err)
  425. en_err(priv, "Failed modifying moderation "
  426. "for cq:%d\n", ring);
  427. }
  428. priv->last_moder_packets[ring] = rx_packets;
  429. priv->last_moder_bytes[ring] = rx_bytes;
  430. }
  431. priv->last_moder_jiffies = jiffies;
  432. }
  433. static void mlx4_en_do_get_stats(struct work_struct *work)
  434. {
  435. struct delayed_work *delay = to_delayed_work(work);
  436. struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
  437. stats_task);
  438. struct mlx4_en_dev *mdev = priv->mdev;
  439. int err;
  440. err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
  441. if (err)
  442. en_dbg(HW, priv, "Could not update stats\n");
  443. mutex_lock(&mdev->state_lock);
  444. if (mdev->device_up) {
  445. if (priv->port_up)
  446. mlx4_en_auto_moderation(priv);
  447. queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  448. }
  449. if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
  450. queue_work(mdev->workqueue, &priv->mac_task);
  451. mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
  452. }
  453. mutex_unlock(&mdev->state_lock);
  454. }
  455. static void mlx4_en_linkstate(struct work_struct *work)
  456. {
  457. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  458. linkstate_task);
  459. struct mlx4_en_dev *mdev = priv->mdev;
  460. int linkstate = priv->link_state;
  461. mutex_lock(&mdev->state_lock);
  462. /* If observable port state changed set carrier state and
  463. * report to system log */
  464. if (priv->last_link_state != linkstate) {
  465. if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
  466. en_info(priv, "Link Down\n");
  467. netif_carrier_off(priv->dev);
  468. } else {
  469. en_info(priv, "Link Up\n");
  470. netif_carrier_on(priv->dev);
  471. }
  472. }
  473. priv->last_link_state = linkstate;
  474. mutex_unlock(&mdev->state_lock);
  475. }
  476. int mlx4_en_start_port(struct net_device *dev)
  477. {
  478. struct mlx4_en_priv *priv = netdev_priv(dev);
  479. struct mlx4_en_dev *mdev = priv->mdev;
  480. struct mlx4_en_cq *cq;
  481. struct mlx4_en_tx_ring *tx_ring;
  482. int rx_index = 0;
  483. int tx_index = 0;
  484. int err = 0;
  485. int i;
  486. int j;
  487. u8 mc_list[16] = {0};
  488. if (priv->port_up) {
  489. en_dbg(DRV, priv, "start port called while port already up\n");
  490. return 0;
  491. }
  492. /* Calculate Rx buf size */
  493. dev->mtu = min(dev->mtu, priv->max_mtu);
  494. mlx4_en_calc_rx_buf(dev);
  495. en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
  496. /* Configure rx cq's and rings */
  497. err = mlx4_en_activate_rx_rings(priv);
  498. if (err) {
  499. en_err(priv, "Failed to activate RX rings\n");
  500. return err;
  501. }
  502. for (i = 0; i < priv->rx_ring_num; i++) {
  503. cq = &priv->rx_cq[i];
  504. err = mlx4_en_activate_cq(priv, cq, i);
  505. if (err) {
  506. en_err(priv, "Failed activating Rx CQ\n");
  507. goto cq_err;
  508. }
  509. for (j = 0; j < cq->size; j++)
  510. cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
  511. err = mlx4_en_set_cq_moder(priv, cq);
  512. if (err) {
  513. en_err(priv, "Failed setting cq moderation parameters");
  514. mlx4_en_deactivate_cq(priv, cq);
  515. goto cq_err;
  516. }
  517. mlx4_en_arm_cq(priv, cq);
  518. priv->rx_ring[i].cqn = cq->mcq.cqn;
  519. ++rx_index;
  520. }
  521. /* Set port mac number */
  522. en_dbg(DRV, priv, "Setting mac for port %d\n", priv->port);
  523. err = mlx4_register_mac(mdev->dev, priv->port,
  524. priv->mac, &priv->base_qpn, 0);
  525. if (err) {
  526. en_err(priv, "Failed setting port mac\n");
  527. goto cq_err;
  528. }
  529. mdev->mac_removed[priv->port] = 0;
  530. err = mlx4_en_config_rss_steer(priv);
  531. if (err) {
  532. en_err(priv, "Failed configuring rss steering\n");
  533. goto mac_err;
  534. }
  535. /* Configure tx cq's and rings */
  536. for (i = 0; i < priv->tx_ring_num; i++) {
  537. /* Configure cq */
  538. cq = &priv->tx_cq[i];
  539. err = mlx4_en_activate_cq(priv, cq, i);
  540. if (err) {
  541. en_err(priv, "Failed allocating Tx CQ\n");
  542. goto tx_err;
  543. }
  544. err = mlx4_en_set_cq_moder(priv, cq);
  545. if (err) {
  546. en_err(priv, "Failed setting cq moderation parameters");
  547. mlx4_en_deactivate_cq(priv, cq);
  548. goto tx_err;
  549. }
  550. en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
  551. cq->buf->wqe_index = cpu_to_be16(0xffff);
  552. /* Configure ring */
  553. tx_ring = &priv->tx_ring[i];
  554. err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn);
  555. if (err) {
  556. en_err(priv, "Failed allocating Tx ring\n");
  557. mlx4_en_deactivate_cq(priv, cq);
  558. goto tx_err;
  559. }
  560. /* Set initial ownership of all Tx TXBBs to SW (1) */
  561. for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
  562. *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
  563. ++tx_index;
  564. }
  565. /* Configure port */
  566. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  567. priv->rx_skb_size + ETH_FCS_LEN,
  568. priv->prof->tx_pause,
  569. priv->prof->tx_ppp,
  570. priv->prof->rx_pause,
  571. priv->prof->rx_ppp);
  572. if (err) {
  573. en_err(priv, "Failed setting port general configurations "
  574. "for port %d, with error %d\n", priv->port, err);
  575. goto tx_err;
  576. }
  577. /* Set default qp number */
  578. err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
  579. if (err) {
  580. en_err(priv, "Failed setting default qp numbers\n");
  581. goto tx_err;
  582. }
  583. /* Init port */
  584. en_dbg(HW, priv, "Initializing port\n");
  585. err = mlx4_INIT_PORT(mdev->dev, priv->port);
  586. if (err) {
  587. en_err(priv, "Failed Initializing port\n");
  588. goto tx_err;
  589. }
  590. /* Attach rx QP to bradcast address */
  591. memset(&mc_list[10], 0xff, ETH_ALEN);
  592. mc_list[5] = priv->port;
  593. if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
  594. 0, MLX4_PROT_ETH))
  595. mlx4_warn(mdev, "Failed Attaching Broadcast\n");
  596. /* Must redo promiscuous mode setup. */
  597. priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
  598. /* Schedule multicast task to populate multicast list */
  599. queue_work(mdev->workqueue, &priv->mcast_task);
  600. priv->port_up = true;
  601. netif_tx_start_all_queues(dev);
  602. return 0;
  603. tx_err:
  604. while (tx_index--) {
  605. mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]);
  606. mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]);
  607. }
  608. mlx4_en_release_rss_steer(priv);
  609. mac_err:
  610. mlx4_unregister_mac(mdev->dev, priv->port, priv->base_qpn);
  611. cq_err:
  612. while (rx_index--)
  613. mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]);
  614. for (i = 0; i < priv->rx_ring_num; i++)
  615. mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
  616. return err; /* need to close devices */
  617. }
  618. void mlx4_en_stop_port(struct net_device *dev)
  619. {
  620. struct mlx4_en_priv *priv = netdev_priv(dev);
  621. struct mlx4_en_dev *mdev = priv->mdev;
  622. int i;
  623. u8 mc_list[16] = {0};
  624. if (!priv->port_up) {
  625. en_dbg(DRV, priv, "stop port called while port already down\n");
  626. return;
  627. }
  628. /* Synchronize with tx routine */
  629. netif_tx_lock_bh(dev);
  630. netif_tx_stop_all_queues(dev);
  631. netif_tx_unlock_bh(dev);
  632. /* Set port as not active */
  633. priv->port_up = false;
  634. /* Detach All multicasts */
  635. memset(&mc_list[10], 0xff, ETH_ALEN);
  636. mc_list[5] = priv->port;
  637. mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
  638. MLX4_PROT_ETH);
  639. for (i = 0; i < priv->mc_addrs_cnt; i++) {
  640. memcpy(&mc_list[10], priv->mc_addrs + i * ETH_ALEN, ETH_ALEN);
  641. mc_list[5] = priv->port;
  642. mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
  643. mc_list, MLX4_PROT_ETH);
  644. }
  645. mlx4_en_clear_list(dev);
  646. /* Flush multicast filter */
  647. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
  648. /* Unregister Mac address for the port */
  649. mlx4_unregister_mac(mdev->dev, priv->port, priv->base_qpn);
  650. mdev->mac_removed[priv->port] = 1;
  651. /* Free TX Rings */
  652. for (i = 0; i < priv->tx_ring_num; i++) {
  653. mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]);
  654. mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]);
  655. }
  656. msleep(10);
  657. for (i = 0; i < priv->tx_ring_num; i++)
  658. mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]);
  659. /* Free RSS qps */
  660. mlx4_en_release_rss_steer(priv);
  661. /* Free RX Rings */
  662. for (i = 0; i < priv->rx_ring_num; i++) {
  663. mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
  664. while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state))
  665. msleep(1);
  666. mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]);
  667. }
  668. /* close port*/
  669. mlx4_CLOSE_PORT(mdev->dev, priv->port);
  670. }
  671. static void mlx4_en_restart(struct work_struct *work)
  672. {
  673. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  674. watchdog_task);
  675. struct mlx4_en_dev *mdev = priv->mdev;
  676. struct net_device *dev = priv->dev;
  677. en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
  678. mutex_lock(&mdev->state_lock);
  679. if (priv->port_up) {
  680. mlx4_en_stop_port(dev);
  681. if (mlx4_en_start_port(dev))
  682. en_err(priv, "Failed restarting port %d\n", priv->port);
  683. }
  684. mutex_unlock(&mdev->state_lock);
  685. }
  686. static int mlx4_en_open(struct net_device *dev)
  687. {
  688. struct mlx4_en_priv *priv = netdev_priv(dev);
  689. struct mlx4_en_dev *mdev = priv->mdev;
  690. int i;
  691. int err = 0;
  692. mutex_lock(&mdev->state_lock);
  693. if (!mdev->device_up) {
  694. en_err(priv, "Cannot open - device down/disabled\n");
  695. err = -EBUSY;
  696. goto out;
  697. }
  698. /* Reset HW statistics and performance counters */
  699. if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
  700. en_dbg(HW, priv, "Failed dumping statistics\n");
  701. memset(&priv->stats, 0, sizeof(priv->stats));
  702. memset(&priv->pstats, 0, sizeof(priv->pstats));
  703. for (i = 0; i < priv->tx_ring_num; i++) {
  704. priv->tx_ring[i].bytes = 0;
  705. priv->tx_ring[i].packets = 0;
  706. }
  707. for (i = 0; i < priv->rx_ring_num; i++) {
  708. priv->rx_ring[i].bytes = 0;
  709. priv->rx_ring[i].packets = 0;
  710. }
  711. err = mlx4_en_start_port(dev);
  712. if (err)
  713. en_err(priv, "Failed starting port:%d\n", priv->port);
  714. out:
  715. mutex_unlock(&mdev->state_lock);
  716. return err;
  717. }
  718. static int mlx4_en_close(struct net_device *dev)
  719. {
  720. struct mlx4_en_priv *priv = netdev_priv(dev);
  721. struct mlx4_en_dev *mdev = priv->mdev;
  722. en_dbg(IFDOWN, priv, "Close port called\n");
  723. mutex_lock(&mdev->state_lock);
  724. mlx4_en_stop_port(dev);
  725. netif_carrier_off(dev);
  726. mutex_unlock(&mdev->state_lock);
  727. return 0;
  728. }
  729. void mlx4_en_free_resources(struct mlx4_en_priv *priv)
  730. {
  731. int i;
  732. for (i = 0; i < priv->tx_ring_num; i++) {
  733. if (priv->tx_ring[i].tx_info)
  734. mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
  735. if (priv->tx_cq[i].buf)
  736. mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
  737. }
  738. for (i = 0; i < priv->rx_ring_num; i++) {
  739. if (priv->rx_ring[i].rx_info)
  740. mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i]);
  741. if (priv->rx_cq[i].buf)
  742. mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
  743. }
  744. }
  745. int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
  746. {
  747. struct mlx4_en_port_profile *prof = priv->prof;
  748. int i;
  749. int base_tx_qpn, err;
  750. err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &base_tx_qpn);
  751. if (err) {
  752. en_err(priv, "failed reserving range for TX rings\n");
  753. return err;
  754. }
  755. /* Create tx Rings */
  756. for (i = 0; i < priv->tx_ring_num; i++) {
  757. if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
  758. prof->tx_ring_size, i, TX))
  759. goto err;
  760. if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], base_tx_qpn + i,
  761. prof->tx_ring_size, TXBB_SIZE))
  762. goto err;
  763. }
  764. /* Create rx Rings */
  765. for (i = 0; i < priv->rx_ring_num; i++) {
  766. if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
  767. prof->rx_ring_size, i, RX))
  768. goto err;
  769. if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
  770. prof->rx_ring_size, priv->stride))
  771. goto err;
  772. }
  773. return 0;
  774. err:
  775. en_err(priv, "Failed to allocate NIC resources\n");
  776. mlx4_qp_release_range(priv->mdev->dev, base_tx_qpn, priv->tx_ring_num);
  777. return -ENOMEM;
  778. }
  779. void mlx4_en_destroy_netdev(struct net_device *dev)
  780. {
  781. struct mlx4_en_priv *priv = netdev_priv(dev);
  782. struct mlx4_en_dev *mdev = priv->mdev;
  783. en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
  784. /* Unregister device - this will close the port if it was up */
  785. if (priv->registered)
  786. unregister_netdev(dev);
  787. if (priv->allocated)
  788. mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
  789. cancel_delayed_work(&priv->stats_task);
  790. /* flush any pending task for this netdev */
  791. flush_workqueue(mdev->workqueue);
  792. /* Detach the netdev so tasks would not attempt to access it */
  793. mutex_lock(&mdev->state_lock);
  794. mdev->pndev[priv->port] = NULL;
  795. mutex_unlock(&mdev->state_lock);
  796. mlx4_en_free_resources(priv);
  797. free_netdev(dev);
  798. }
  799. static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
  800. {
  801. struct mlx4_en_priv *priv = netdev_priv(dev);
  802. struct mlx4_en_dev *mdev = priv->mdev;
  803. int err = 0;
  804. en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
  805. dev->mtu, new_mtu);
  806. if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
  807. en_err(priv, "Bad MTU size:%d.\n", new_mtu);
  808. return -EPERM;
  809. }
  810. dev->mtu = new_mtu;
  811. if (netif_running(dev)) {
  812. mutex_lock(&mdev->state_lock);
  813. if (!mdev->device_up) {
  814. /* NIC is probably restarting - let watchdog task reset
  815. * the port */
  816. en_dbg(DRV, priv, "Change MTU called with card down!?\n");
  817. } else {
  818. mlx4_en_stop_port(dev);
  819. err = mlx4_en_start_port(dev);
  820. if (err) {
  821. en_err(priv, "Failed restarting port:%d\n",
  822. priv->port);
  823. queue_work(mdev->workqueue, &priv->watchdog_task);
  824. }
  825. }
  826. mutex_unlock(&mdev->state_lock);
  827. }
  828. return 0;
  829. }
  830. static const struct net_device_ops mlx4_netdev_ops = {
  831. .ndo_open = mlx4_en_open,
  832. .ndo_stop = mlx4_en_close,
  833. .ndo_start_xmit = mlx4_en_xmit,
  834. .ndo_select_queue = mlx4_en_select_queue,
  835. .ndo_get_stats = mlx4_en_get_stats,
  836. .ndo_set_rx_mode = mlx4_en_set_multicast,
  837. .ndo_set_mac_address = mlx4_en_set_mac,
  838. .ndo_validate_addr = eth_validate_addr,
  839. .ndo_change_mtu = mlx4_en_change_mtu,
  840. .ndo_tx_timeout = mlx4_en_tx_timeout,
  841. .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
  842. .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
  843. #ifdef CONFIG_NET_POLL_CONTROLLER
  844. .ndo_poll_controller = mlx4_en_netpoll,
  845. #endif
  846. };
  847. int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
  848. struct mlx4_en_port_profile *prof)
  849. {
  850. struct net_device *dev;
  851. struct mlx4_en_priv *priv;
  852. int i;
  853. int err;
  854. dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
  855. prof->tx_ring_num, prof->rx_ring_num);
  856. if (dev == NULL) {
  857. mlx4_err(mdev, "Net device allocation failed\n");
  858. return -ENOMEM;
  859. }
  860. SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
  861. dev->dev_id = port - 1;
  862. /*
  863. * Initialize driver private data
  864. */
  865. priv = netdev_priv(dev);
  866. memset(priv, 0, sizeof(struct mlx4_en_priv));
  867. priv->dev = dev;
  868. priv->mdev = mdev;
  869. priv->prof = prof;
  870. priv->port = port;
  871. priv->port_up = false;
  872. priv->flags = prof->flags;
  873. priv->tx_ring_num = prof->tx_ring_num;
  874. priv->rx_ring_num = prof->rx_ring_num;
  875. priv->mac_index = -1;
  876. priv->msg_enable = MLX4_EN_MSG_LEVEL;
  877. spin_lock_init(&priv->stats_lock);
  878. INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast);
  879. INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac);
  880. INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
  881. INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
  882. INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
  883. /* Query for default mac and max mtu */
  884. priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
  885. priv->mac = mdev->dev->caps.def_mac[priv->port];
  886. if (ILLEGAL_MAC(priv->mac)) {
  887. en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n",
  888. priv->port, priv->mac);
  889. err = -EINVAL;
  890. goto out;
  891. }
  892. priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
  893. DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
  894. err = mlx4_en_alloc_resources(priv);
  895. if (err)
  896. goto out;
  897. /* Allocate page for receive rings */
  898. err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
  899. MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
  900. if (err) {
  901. en_err(priv, "Failed to allocate page for rx qps\n");
  902. goto out;
  903. }
  904. priv->allocated = 1;
  905. /*
  906. * Initialize netdev entry points
  907. */
  908. dev->netdev_ops = &mlx4_netdev_ops;
  909. dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
  910. netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
  911. netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
  912. SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops);
  913. /* Set defualt MAC */
  914. dev->addr_len = ETH_ALEN;
  915. for (i = 0; i < ETH_ALEN; i++) {
  916. dev->dev_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
  917. dev->perm_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
  918. }
  919. /*
  920. * Set driver features
  921. */
  922. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  923. if (mdev->LSO_support)
  924. dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
  925. dev->vlan_features = dev->hw_features;
  926. dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
  927. dev->features = dev->hw_features | NETIF_F_HIGHDMA |
  928. NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
  929. NETIF_F_HW_VLAN_FILTER;
  930. mdev->pndev[port] = dev;
  931. netif_carrier_off(dev);
  932. err = register_netdev(dev);
  933. if (err) {
  934. en_err(priv, "Netdev registration failed for port %d\n", port);
  935. goto out;
  936. }
  937. priv->registered = 1;
  938. en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
  939. en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
  940. /* Configure port */
  941. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  942. MLX4_EN_MIN_MTU,
  943. 0, 0, 0, 0);
  944. if (err) {
  945. en_err(priv, "Failed setting port general configurations "
  946. "for port %d, with error %d\n", priv->port, err);
  947. goto out;
  948. }
  949. /* Init port */
  950. en_warn(priv, "Initializing port\n");
  951. err = mlx4_INIT_PORT(mdev->dev, priv->port);
  952. if (err) {
  953. en_err(priv, "Failed Initializing port\n");
  954. goto out;
  955. }
  956. mlx4_en_set_default_moderation(priv);
  957. queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  958. return 0;
  959. out:
  960. mlx4_en_destroy_netdev(dev);
  961. return err;
  962. }