en_netdev.c 31 KB

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