en_netdev.c 31 KB

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