en_netdev.c 31 KB

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