en_netdev.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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/hash.h>
  39. #include <net/ip.h>
  40. #include <linux/mlx4/driver.h>
  41. #include <linux/mlx4/device.h>
  42. #include <linux/mlx4/cmd.h>
  43. #include <linux/mlx4/cq.h>
  44. #include "mlx4_en.h"
  45. #include "en_port.h"
  46. static int mlx4_en_setup_tc(struct net_device *dev, u8 up)
  47. {
  48. struct mlx4_en_priv *priv = netdev_priv(dev);
  49. int i;
  50. unsigned int q, offset = 0;
  51. if (up && up != MLX4_EN_NUM_UP)
  52. return -EINVAL;
  53. netdev_set_num_tc(dev, up);
  54. /* Partition Tx queues evenly amongst UP's */
  55. q = priv->tx_ring_num / up;
  56. for (i = 0; i < up; i++) {
  57. netdev_set_tc_queue(dev, i, q, offset);
  58. offset += q;
  59. }
  60. return 0;
  61. }
  62. #ifdef CONFIG_RFS_ACCEL
  63. struct mlx4_en_filter {
  64. struct list_head next;
  65. struct work_struct work;
  66. __be32 src_ip;
  67. __be32 dst_ip;
  68. __be16 src_port;
  69. __be16 dst_port;
  70. int rxq_index;
  71. struct mlx4_en_priv *priv;
  72. u32 flow_id; /* RFS infrastructure id */
  73. int id; /* mlx4_en driver id */
  74. u64 reg_id; /* Flow steering API id */
  75. u8 activated; /* Used to prevent expiry before filter
  76. * is attached
  77. */
  78. struct hlist_node filter_chain;
  79. };
  80. static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv);
  81. static void mlx4_en_filter_work(struct work_struct *work)
  82. {
  83. struct mlx4_en_filter *filter = container_of(work,
  84. struct mlx4_en_filter,
  85. work);
  86. struct mlx4_en_priv *priv = filter->priv;
  87. struct mlx4_spec_list spec_tcp = {
  88. .id = MLX4_NET_TRANS_RULE_ID_TCP,
  89. {
  90. .tcp_udp = {
  91. .dst_port = filter->dst_port,
  92. .dst_port_msk = (__force __be16)-1,
  93. .src_port = filter->src_port,
  94. .src_port_msk = (__force __be16)-1,
  95. },
  96. },
  97. };
  98. struct mlx4_spec_list spec_ip = {
  99. .id = MLX4_NET_TRANS_RULE_ID_IPV4,
  100. {
  101. .ipv4 = {
  102. .dst_ip = filter->dst_ip,
  103. .dst_ip_msk = (__force __be32)-1,
  104. .src_ip = filter->src_ip,
  105. .src_ip_msk = (__force __be32)-1,
  106. },
  107. },
  108. };
  109. struct mlx4_spec_list spec_eth = {
  110. .id = MLX4_NET_TRANS_RULE_ID_ETH,
  111. };
  112. struct mlx4_net_trans_rule rule = {
  113. .list = LIST_HEAD_INIT(rule.list),
  114. .queue_mode = MLX4_NET_TRANS_Q_LIFO,
  115. .exclusive = 1,
  116. .allow_loopback = 1,
  117. .promisc_mode = MLX4_FS_PROMISC_NONE,
  118. .port = priv->port,
  119. .priority = MLX4_DOMAIN_RFS,
  120. };
  121. int rc;
  122. __be64 mac;
  123. __be64 mac_mask = cpu_to_be64(MLX4_MAC_MASK << 16);
  124. list_add_tail(&spec_eth.list, &rule.list);
  125. list_add_tail(&spec_ip.list, &rule.list);
  126. list_add_tail(&spec_tcp.list, &rule.list);
  127. mac = cpu_to_be64((priv->mac & MLX4_MAC_MASK) << 16);
  128. rule.qpn = priv->rss_map.qps[filter->rxq_index].qpn;
  129. memcpy(spec_eth.eth.dst_mac, &mac, ETH_ALEN);
  130. memcpy(spec_eth.eth.dst_mac_msk, &mac_mask, ETH_ALEN);
  131. filter->activated = 0;
  132. if (filter->reg_id) {
  133. rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
  134. if (rc && rc != -ENOENT)
  135. en_err(priv, "Error detaching flow. rc = %d\n", rc);
  136. }
  137. rc = mlx4_flow_attach(priv->mdev->dev, &rule, &filter->reg_id);
  138. if (rc)
  139. en_err(priv, "Error attaching flow. err = %d\n", rc);
  140. mlx4_en_filter_rfs_expire(priv);
  141. filter->activated = 1;
  142. }
  143. static inline struct hlist_head *
  144. filter_hash_bucket(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
  145. __be16 src_port, __be16 dst_port)
  146. {
  147. unsigned long l;
  148. int bucket_idx;
  149. l = (__force unsigned long)src_port |
  150. ((__force unsigned long)dst_port << 2);
  151. l ^= (__force unsigned long)(src_ip ^ dst_ip);
  152. bucket_idx = hash_long(l, MLX4_EN_FILTER_HASH_SHIFT);
  153. return &priv->filter_hash[bucket_idx];
  154. }
  155. static struct mlx4_en_filter *
  156. mlx4_en_filter_alloc(struct mlx4_en_priv *priv, int rxq_index, __be32 src_ip,
  157. __be32 dst_ip, __be16 src_port, __be16 dst_port,
  158. u32 flow_id)
  159. {
  160. struct mlx4_en_filter *filter = NULL;
  161. filter = kzalloc(sizeof(struct mlx4_en_filter), GFP_ATOMIC);
  162. if (!filter)
  163. return NULL;
  164. filter->priv = priv;
  165. filter->rxq_index = rxq_index;
  166. INIT_WORK(&filter->work, mlx4_en_filter_work);
  167. filter->src_ip = src_ip;
  168. filter->dst_ip = dst_ip;
  169. filter->src_port = src_port;
  170. filter->dst_port = dst_port;
  171. filter->flow_id = flow_id;
  172. filter->id = priv->last_filter_id++ % RPS_NO_FILTER;
  173. list_add_tail(&filter->next, &priv->filters);
  174. hlist_add_head(&filter->filter_chain,
  175. filter_hash_bucket(priv, src_ip, dst_ip, src_port,
  176. dst_port));
  177. return filter;
  178. }
  179. static void mlx4_en_filter_free(struct mlx4_en_filter *filter)
  180. {
  181. struct mlx4_en_priv *priv = filter->priv;
  182. int rc;
  183. list_del(&filter->next);
  184. rc = mlx4_flow_detach(priv->mdev->dev, filter->reg_id);
  185. if (rc && rc != -ENOENT)
  186. en_err(priv, "Error detaching flow. rc = %d\n", rc);
  187. kfree(filter);
  188. }
  189. static inline struct mlx4_en_filter *
  190. mlx4_en_filter_find(struct mlx4_en_priv *priv, __be32 src_ip, __be32 dst_ip,
  191. __be16 src_port, __be16 dst_port)
  192. {
  193. struct hlist_node *elem;
  194. struct mlx4_en_filter *filter;
  195. struct mlx4_en_filter *ret = NULL;
  196. hlist_for_each_entry(filter, elem,
  197. filter_hash_bucket(priv, src_ip, dst_ip,
  198. src_port, dst_port),
  199. filter_chain) {
  200. if (filter->src_ip == src_ip &&
  201. filter->dst_ip == dst_ip &&
  202. filter->src_port == src_port &&
  203. filter->dst_port == dst_port) {
  204. ret = filter;
  205. break;
  206. }
  207. }
  208. return ret;
  209. }
  210. static int
  211. mlx4_en_filter_rfs(struct net_device *net_dev, const struct sk_buff *skb,
  212. u16 rxq_index, u32 flow_id)
  213. {
  214. struct mlx4_en_priv *priv = netdev_priv(net_dev);
  215. struct mlx4_en_filter *filter;
  216. const struct iphdr *ip;
  217. const __be16 *ports;
  218. __be32 src_ip;
  219. __be32 dst_ip;
  220. __be16 src_port;
  221. __be16 dst_port;
  222. int nhoff = skb_network_offset(skb);
  223. int ret = 0;
  224. if (skb->protocol != htons(ETH_P_IP))
  225. return -EPROTONOSUPPORT;
  226. ip = (const struct iphdr *)(skb->data + nhoff);
  227. if (ip_is_fragment(ip))
  228. return -EPROTONOSUPPORT;
  229. ports = (const __be16 *)(skb->data + nhoff + 4 * ip->ihl);
  230. src_ip = ip->saddr;
  231. dst_ip = ip->daddr;
  232. src_port = ports[0];
  233. dst_port = ports[1];
  234. if (ip->protocol != IPPROTO_TCP)
  235. return -EPROTONOSUPPORT;
  236. spin_lock_bh(&priv->filters_lock);
  237. filter = mlx4_en_filter_find(priv, src_ip, dst_ip, src_port, dst_port);
  238. if (filter) {
  239. if (filter->rxq_index == rxq_index)
  240. goto out;
  241. filter->rxq_index = rxq_index;
  242. } else {
  243. filter = mlx4_en_filter_alloc(priv, rxq_index,
  244. src_ip, dst_ip,
  245. src_port, dst_port, flow_id);
  246. if (!filter) {
  247. ret = -ENOMEM;
  248. goto err;
  249. }
  250. }
  251. queue_work(priv->mdev->workqueue, &filter->work);
  252. out:
  253. ret = filter->id;
  254. err:
  255. spin_unlock_bh(&priv->filters_lock);
  256. return ret;
  257. }
  258. void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv,
  259. struct mlx4_en_rx_ring *rx_ring)
  260. {
  261. struct mlx4_en_filter *filter, *tmp;
  262. LIST_HEAD(del_list);
  263. spin_lock_bh(&priv->filters_lock);
  264. list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
  265. list_move(&filter->next, &del_list);
  266. hlist_del(&filter->filter_chain);
  267. }
  268. spin_unlock_bh(&priv->filters_lock);
  269. list_for_each_entry_safe(filter, tmp, &del_list, next) {
  270. cancel_work_sync(&filter->work);
  271. mlx4_en_filter_free(filter);
  272. }
  273. }
  274. static void mlx4_en_filter_rfs_expire(struct mlx4_en_priv *priv)
  275. {
  276. struct mlx4_en_filter *filter = NULL, *tmp, *last_filter = NULL;
  277. LIST_HEAD(del_list);
  278. int i = 0;
  279. spin_lock_bh(&priv->filters_lock);
  280. list_for_each_entry_safe(filter, tmp, &priv->filters, next) {
  281. if (i > MLX4_EN_FILTER_EXPIRY_QUOTA)
  282. break;
  283. if (filter->activated &&
  284. !work_pending(&filter->work) &&
  285. rps_may_expire_flow(priv->dev,
  286. filter->rxq_index, filter->flow_id,
  287. filter->id)) {
  288. list_move(&filter->next, &del_list);
  289. hlist_del(&filter->filter_chain);
  290. } else
  291. last_filter = filter;
  292. i++;
  293. }
  294. if (last_filter && (&last_filter->next != priv->filters.next))
  295. list_move(&priv->filters, &last_filter->next);
  296. spin_unlock_bh(&priv->filters_lock);
  297. list_for_each_entry_safe(filter, tmp, &del_list, next)
  298. mlx4_en_filter_free(filter);
  299. }
  300. #endif
  301. static int mlx4_en_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  302. {
  303. struct mlx4_en_priv *priv = netdev_priv(dev);
  304. struct mlx4_en_dev *mdev = priv->mdev;
  305. int err;
  306. int idx;
  307. en_dbg(HW, priv, "adding VLAN:%d\n", vid);
  308. set_bit(vid, priv->active_vlans);
  309. /* Add VID to port VLAN filter */
  310. mutex_lock(&mdev->state_lock);
  311. if (mdev->device_up && priv->port_up) {
  312. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  313. if (err)
  314. en_err(priv, "Failed configuring VLAN filter\n");
  315. }
  316. if (mlx4_register_vlan(mdev->dev, priv->port, vid, &idx))
  317. en_err(priv, "failed adding vlan %d\n", vid);
  318. mutex_unlock(&mdev->state_lock);
  319. return 0;
  320. }
  321. static int mlx4_en_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  322. {
  323. struct mlx4_en_priv *priv = netdev_priv(dev);
  324. struct mlx4_en_dev *mdev = priv->mdev;
  325. int err;
  326. int idx;
  327. en_dbg(HW, priv, "Killing VID:%d\n", vid);
  328. clear_bit(vid, priv->active_vlans);
  329. /* Remove VID from port VLAN filter */
  330. mutex_lock(&mdev->state_lock);
  331. if (!mlx4_find_cached_vlan(mdev->dev, priv->port, vid, &idx))
  332. mlx4_unregister_vlan(mdev->dev, priv->port, idx);
  333. else
  334. en_err(priv, "could not find vid %d in cache\n", vid);
  335. if (mdev->device_up && priv->port_up) {
  336. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  337. if (err)
  338. en_err(priv, "Failed configuring VLAN filter\n");
  339. }
  340. mutex_unlock(&mdev->state_lock);
  341. return 0;
  342. }
  343. u64 mlx4_en_mac_to_u64(u8 *addr)
  344. {
  345. u64 mac = 0;
  346. int i;
  347. for (i = 0; i < ETH_ALEN; i++) {
  348. mac <<= 8;
  349. mac |= addr[i];
  350. }
  351. return mac;
  352. }
  353. static int mlx4_en_set_mac(struct net_device *dev, void *addr)
  354. {
  355. struct mlx4_en_priv *priv = netdev_priv(dev);
  356. struct mlx4_en_dev *mdev = priv->mdev;
  357. struct sockaddr *saddr = addr;
  358. if (!is_valid_ether_addr(saddr->sa_data))
  359. return -EADDRNOTAVAIL;
  360. memcpy(dev->dev_addr, saddr->sa_data, ETH_ALEN);
  361. priv->mac = mlx4_en_mac_to_u64(dev->dev_addr);
  362. queue_work(mdev->workqueue, &priv->mac_task);
  363. return 0;
  364. }
  365. static void mlx4_en_do_set_mac(struct work_struct *work)
  366. {
  367. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  368. mac_task);
  369. struct mlx4_en_dev *mdev = priv->mdev;
  370. int err = 0;
  371. mutex_lock(&mdev->state_lock);
  372. if (priv->port_up) {
  373. /* Remove old MAC and insert the new one */
  374. err = mlx4_replace_mac(mdev->dev, priv->port,
  375. priv->base_qpn, priv->mac);
  376. if (err)
  377. en_err(priv, "Failed changing HW MAC address\n");
  378. } else
  379. en_dbg(HW, priv, "Port is down while "
  380. "registering mac, exiting...\n");
  381. mutex_unlock(&mdev->state_lock);
  382. }
  383. static void mlx4_en_clear_list(struct net_device *dev)
  384. {
  385. struct mlx4_en_priv *priv = netdev_priv(dev);
  386. struct mlx4_en_mc_list *tmp, *mc_to_del;
  387. list_for_each_entry_safe(mc_to_del, tmp, &priv->mc_list, list) {
  388. list_del(&mc_to_del->list);
  389. kfree(mc_to_del);
  390. }
  391. }
  392. static void mlx4_en_cache_mclist(struct net_device *dev)
  393. {
  394. struct mlx4_en_priv *priv = netdev_priv(dev);
  395. struct netdev_hw_addr *ha;
  396. struct mlx4_en_mc_list *tmp;
  397. mlx4_en_clear_list(dev);
  398. netdev_for_each_mc_addr(ha, dev) {
  399. tmp = kzalloc(sizeof(struct mlx4_en_mc_list), GFP_ATOMIC);
  400. if (!tmp) {
  401. en_err(priv, "failed to allocate multicast list\n");
  402. mlx4_en_clear_list(dev);
  403. return;
  404. }
  405. memcpy(tmp->addr, ha->addr, ETH_ALEN);
  406. list_add_tail(&tmp->list, &priv->mc_list);
  407. }
  408. }
  409. static void update_mclist_flags(struct mlx4_en_priv *priv,
  410. struct list_head *dst,
  411. struct list_head *src)
  412. {
  413. struct mlx4_en_mc_list *dst_tmp, *src_tmp, *new_mc;
  414. bool found;
  415. /* Find all the entries that should be removed from dst,
  416. * These are the entries that are not found in src
  417. */
  418. list_for_each_entry(dst_tmp, dst, list) {
  419. found = false;
  420. list_for_each_entry(src_tmp, src, list) {
  421. if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
  422. found = true;
  423. break;
  424. }
  425. }
  426. if (!found)
  427. dst_tmp->action = MCLIST_REM;
  428. }
  429. /* Add entries that exist in src but not in dst
  430. * mark them as need to add
  431. */
  432. list_for_each_entry(src_tmp, src, list) {
  433. found = false;
  434. list_for_each_entry(dst_tmp, dst, list) {
  435. if (!memcmp(dst_tmp->addr, src_tmp->addr, ETH_ALEN)) {
  436. dst_tmp->action = MCLIST_NONE;
  437. found = true;
  438. break;
  439. }
  440. }
  441. if (!found) {
  442. new_mc = kmalloc(sizeof(struct mlx4_en_mc_list),
  443. GFP_KERNEL);
  444. if (!new_mc) {
  445. en_err(priv, "Failed to allocate current multicast list\n");
  446. return;
  447. }
  448. memcpy(new_mc, src_tmp,
  449. sizeof(struct mlx4_en_mc_list));
  450. new_mc->action = MCLIST_ADD;
  451. list_add_tail(&new_mc->list, dst);
  452. }
  453. }
  454. }
  455. static void mlx4_en_set_multicast(struct net_device *dev)
  456. {
  457. struct mlx4_en_priv *priv = netdev_priv(dev);
  458. if (!priv->port_up)
  459. return;
  460. queue_work(priv->mdev->workqueue, &priv->mcast_task);
  461. }
  462. static void mlx4_en_do_set_multicast(struct work_struct *work)
  463. {
  464. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  465. mcast_task);
  466. struct mlx4_en_dev *mdev = priv->mdev;
  467. struct net_device *dev = priv->dev;
  468. struct mlx4_en_mc_list *mclist, *tmp;
  469. u64 mcast_addr = 0;
  470. u8 mc_list[16] = {0};
  471. int err = 0;
  472. mutex_lock(&mdev->state_lock);
  473. if (!mdev->device_up) {
  474. en_dbg(HW, priv, "Card is not up, "
  475. "ignoring multicast change.\n");
  476. goto out;
  477. }
  478. if (!priv->port_up) {
  479. en_dbg(HW, priv, "Port is down, "
  480. "ignoring multicast change.\n");
  481. goto out;
  482. }
  483. if (!netif_carrier_ok(dev)) {
  484. if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
  485. if (priv->port_state.link_state) {
  486. priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
  487. netif_carrier_on(dev);
  488. en_dbg(LINK, priv, "Link Up\n");
  489. }
  490. }
  491. }
  492. /*
  493. * Promsicuous mode: disable all filters
  494. */
  495. if (dev->flags & IFF_PROMISC) {
  496. if (!(priv->flags & MLX4_EN_FLAG_PROMISC)) {
  497. if (netif_msg_rx_status(priv))
  498. en_warn(priv, "Entering promiscuous mode\n");
  499. priv->flags |= MLX4_EN_FLAG_PROMISC;
  500. /* Enable promiscouos mode */
  501. switch (mdev->dev->caps.steering_mode) {
  502. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  503. err = mlx4_flow_steer_promisc_add(mdev->dev,
  504. priv->port,
  505. priv->base_qpn,
  506. MLX4_FS_PROMISC_UPLINK);
  507. if (err)
  508. en_err(priv, "Failed enabling promiscuous mode\n");
  509. priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
  510. break;
  511. case MLX4_STEERING_MODE_B0:
  512. err = mlx4_unicast_promisc_add(mdev->dev,
  513. priv->base_qpn,
  514. priv->port);
  515. if (err)
  516. en_err(priv, "Failed enabling unicast promiscuous mode\n");
  517. /* Add the default qp number as multicast
  518. * promisc
  519. */
  520. if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
  521. err = mlx4_multicast_promisc_add(mdev->dev,
  522. priv->base_qpn,
  523. priv->port);
  524. if (err)
  525. en_err(priv, "Failed enabling multicast promiscuous mode\n");
  526. priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
  527. }
  528. break;
  529. case MLX4_STEERING_MODE_A0:
  530. err = mlx4_SET_PORT_qpn_calc(mdev->dev,
  531. priv->port,
  532. priv->base_qpn,
  533. 1);
  534. if (err)
  535. en_err(priv, "Failed enabling promiscuous mode\n");
  536. break;
  537. }
  538. /* Disable port multicast filter (unconditionally) */
  539. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  540. 0, MLX4_MCAST_DISABLE);
  541. if (err)
  542. en_err(priv, "Failed disabling "
  543. "multicast filter\n");
  544. /* Disable port VLAN filter */
  545. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  546. if (err)
  547. en_err(priv, "Failed disabling VLAN filter\n");
  548. }
  549. goto out;
  550. }
  551. /*
  552. * Not in promiscuous mode
  553. */
  554. if (priv->flags & MLX4_EN_FLAG_PROMISC) {
  555. if (netif_msg_rx_status(priv))
  556. en_warn(priv, "Leaving promiscuous mode\n");
  557. priv->flags &= ~MLX4_EN_FLAG_PROMISC;
  558. /* Disable promiscouos mode */
  559. switch (mdev->dev->caps.steering_mode) {
  560. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  561. err = mlx4_flow_steer_promisc_remove(mdev->dev,
  562. priv->port,
  563. MLX4_FS_PROMISC_UPLINK);
  564. if (err)
  565. en_err(priv, "Failed disabling promiscuous mode\n");
  566. priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
  567. break;
  568. case MLX4_STEERING_MODE_B0:
  569. err = mlx4_unicast_promisc_remove(mdev->dev,
  570. priv->base_qpn,
  571. priv->port);
  572. if (err)
  573. en_err(priv, "Failed disabling unicast promiscuous mode\n");
  574. /* Disable Multicast promisc */
  575. if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
  576. err = mlx4_multicast_promisc_remove(mdev->dev,
  577. priv->base_qpn,
  578. priv->port);
  579. if (err)
  580. en_err(priv, "Failed disabling multicast promiscuous mode\n");
  581. priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
  582. }
  583. break;
  584. case MLX4_STEERING_MODE_A0:
  585. err = mlx4_SET_PORT_qpn_calc(mdev->dev,
  586. priv->port,
  587. priv->base_qpn, 0);
  588. if (err)
  589. en_err(priv, "Failed disabling promiscuous mode\n");
  590. break;
  591. }
  592. /* Enable port VLAN filter */
  593. err = mlx4_SET_VLAN_FLTR(mdev->dev, priv);
  594. if (err)
  595. en_err(priv, "Failed enabling VLAN filter\n");
  596. }
  597. /* Enable/disable the multicast filter according to IFF_ALLMULTI */
  598. if (dev->flags & IFF_ALLMULTI) {
  599. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  600. 0, MLX4_MCAST_DISABLE);
  601. if (err)
  602. en_err(priv, "Failed disabling multicast filter\n");
  603. /* Add the default qp number as multicast promisc */
  604. if (!(priv->flags & MLX4_EN_FLAG_MC_PROMISC)) {
  605. switch (mdev->dev->caps.steering_mode) {
  606. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  607. err = mlx4_flow_steer_promisc_add(mdev->dev,
  608. priv->port,
  609. priv->base_qpn,
  610. MLX4_FS_PROMISC_ALL_MULTI);
  611. break;
  612. case MLX4_STEERING_MODE_B0:
  613. err = mlx4_multicast_promisc_add(mdev->dev,
  614. priv->base_qpn,
  615. priv->port);
  616. break;
  617. case MLX4_STEERING_MODE_A0:
  618. break;
  619. }
  620. if (err)
  621. en_err(priv, "Failed entering multicast promisc mode\n");
  622. priv->flags |= MLX4_EN_FLAG_MC_PROMISC;
  623. }
  624. } else {
  625. /* Disable Multicast promisc */
  626. if (priv->flags & MLX4_EN_FLAG_MC_PROMISC) {
  627. switch (mdev->dev->caps.steering_mode) {
  628. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  629. err = mlx4_flow_steer_promisc_remove(mdev->dev,
  630. priv->port,
  631. MLX4_FS_PROMISC_ALL_MULTI);
  632. break;
  633. case MLX4_STEERING_MODE_B0:
  634. err = mlx4_multicast_promisc_remove(mdev->dev,
  635. priv->base_qpn,
  636. priv->port);
  637. break;
  638. case MLX4_STEERING_MODE_A0:
  639. break;
  640. }
  641. if (err)
  642. en_err(priv, "Failed disabling multicast promiscuous mode\n");
  643. priv->flags &= ~MLX4_EN_FLAG_MC_PROMISC;
  644. }
  645. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  646. 0, MLX4_MCAST_DISABLE);
  647. if (err)
  648. en_err(priv, "Failed disabling multicast filter\n");
  649. /* Flush mcast filter and init it with broadcast address */
  650. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, ETH_BCAST,
  651. 1, MLX4_MCAST_CONFIG);
  652. /* Update multicast list - we cache all addresses so they won't
  653. * change while HW is updated holding the command semaphor */
  654. netif_tx_lock_bh(dev);
  655. mlx4_en_cache_mclist(dev);
  656. netif_tx_unlock_bh(dev);
  657. list_for_each_entry(mclist, &priv->mc_list, list) {
  658. mcast_addr = mlx4_en_mac_to_u64(mclist->addr);
  659. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port,
  660. mcast_addr, 0, MLX4_MCAST_CONFIG);
  661. }
  662. err = mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0,
  663. 0, MLX4_MCAST_ENABLE);
  664. if (err)
  665. en_err(priv, "Failed enabling multicast filter\n");
  666. update_mclist_flags(priv, &priv->curr_list, &priv->mc_list);
  667. list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
  668. if (mclist->action == MCLIST_REM) {
  669. /* detach this address and delete from list */
  670. memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
  671. mc_list[5] = priv->port;
  672. err = mlx4_multicast_detach(mdev->dev,
  673. &priv->rss_map.indir_qp,
  674. mc_list,
  675. MLX4_PROT_ETH,
  676. mclist->reg_id);
  677. if (err)
  678. en_err(priv, "Fail to detach multicast address\n");
  679. /* remove from list */
  680. list_del(&mclist->list);
  681. kfree(mclist);
  682. } else if (mclist->action == MCLIST_ADD) {
  683. /* attach the address */
  684. memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
  685. /* needed for B0 steering support */
  686. mc_list[5] = priv->port;
  687. err = mlx4_multicast_attach(mdev->dev,
  688. &priv->rss_map.indir_qp,
  689. mc_list,
  690. priv->port, 0,
  691. MLX4_PROT_ETH,
  692. &mclist->reg_id);
  693. if (err)
  694. en_err(priv, "Fail to attach multicast address\n");
  695. }
  696. }
  697. }
  698. out:
  699. mutex_unlock(&mdev->state_lock);
  700. }
  701. #ifdef CONFIG_NET_POLL_CONTROLLER
  702. static void mlx4_en_netpoll(struct net_device *dev)
  703. {
  704. struct mlx4_en_priv *priv = netdev_priv(dev);
  705. struct mlx4_en_cq *cq;
  706. unsigned long flags;
  707. int i;
  708. for (i = 0; i < priv->rx_ring_num; i++) {
  709. cq = &priv->rx_cq[i];
  710. spin_lock_irqsave(&cq->lock, flags);
  711. napi_synchronize(&cq->napi);
  712. mlx4_en_process_rx_cq(dev, cq, 0);
  713. spin_unlock_irqrestore(&cq->lock, flags);
  714. }
  715. }
  716. #endif
  717. static void mlx4_en_tx_timeout(struct net_device *dev)
  718. {
  719. struct mlx4_en_priv *priv = netdev_priv(dev);
  720. struct mlx4_en_dev *mdev = priv->mdev;
  721. if (netif_msg_timer(priv))
  722. en_warn(priv, "Tx timeout called on port:%d\n", priv->port);
  723. priv->port_stats.tx_timeout++;
  724. en_dbg(DRV, priv, "Scheduling watchdog\n");
  725. queue_work(mdev->workqueue, &priv->watchdog_task);
  726. }
  727. static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
  728. {
  729. struct mlx4_en_priv *priv = netdev_priv(dev);
  730. spin_lock_bh(&priv->stats_lock);
  731. memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
  732. spin_unlock_bh(&priv->stats_lock);
  733. return &priv->ret_stats;
  734. }
  735. static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
  736. {
  737. struct mlx4_en_cq *cq;
  738. int i;
  739. /* If we haven't received a specific coalescing setting
  740. * (module param), we set the moderation parameters as follows:
  741. * - moder_cnt is set to the number of mtu sized packets to
  742. * satisfy our coelsing target.
  743. * - moder_time is set to a fixed value.
  744. */
  745. priv->rx_frames = MLX4_EN_RX_COAL_TARGET;
  746. priv->rx_usecs = MLX4_EN_RX_COAL_TIME;
  747. priv->tx_frames = MLX4_EN_TX_COAL_PKTS;
  748. priv->tx_usecs = MLX4_EN_TX_COAL_TIME;
  749. en_dbg(INTR, priv, "Default coalesing params for mtu:%d - "
  750. "rx_frames:%d rx_usecs:%d\n",
  751. priv->dev->mtu, priv->rx_frames, priv->rx_usecs);
  752. /* Setup cq moderation params */
  753. for (i = 0; i < priv->rx_ring_num; i++) {
  754. cq = &priv->rx_cq[i];
  755. cq->moder_cnt = priv->rx_frames;
  756. cq->moder_time = priv->rx_usecs;
  757. priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
  758. priv->last_moder_packets[i] = 0;
  759. priv->last_moder_bytes[i] = 0;
  760. }
  761. for (i = 0; i < priv->tx_ring_num; i++) {
  762. cq = &priv->tx_cq[i];
  763. cq->moder_cnt = priv->tx_frames;
  764. cq->moder_time = priv->tx_usecs;
  765. }
  766. /* Reset auto-moderation params */
  767. priv->pkt_rate_low = MLX4_EN_RX_RATE_LOW;
  768. priv->rx_usecs_low = MLX4_EN_RX_COAL_TIME_LOW;
  769. priv->pkt_rate_high = MLX4_EN_RX_RATE_HIGH;
  770. priv->rx_usecs_high = MLX4_EN_RX_COAL_TIME_HIGH;
  771. priv->sample_interval = MLX4_EN_SAMPLE_INTERVAL;
  772. priv->adaptive_rx_coal = 1;
  773. priv->last_moder_jiffies = 0;
  774. priv->last_moder_tx_packets = 0;
  775. }
  776. static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
  777. {
  778. unsigned long period = (unsigned long) (jiffies - priv->last_moder_jiffies);
  779. struct mlx4_en_cq *cq;
  780. unsigned long packets;
  781. unsigned long rate;
  782. unsigned long avg_pkt_size;
  783. unsigned long rx_packets;
  784. unsigned long rx_bytes;
  785. unsigned long rx_pkt_diff;
  786. int moder_time;
  787. int ring, err;
  788. if (!priv->adaptive_rx_coal || period < priv->sample_interval * HZ)
  789. return;
  790. for (ring = 0; ring < priv->rx_ring_num; ring++) {
  791. spin_lock_bh(&priv->stats_lock);
  792. rx_packets = priv->rx_ring[ring].packets;
  793. rx_bytes = priv->rx_ring[ring].bytes;
  794. spin_unlock_bh(&priv->stats_lock);
  795. rx_pkt_diff = ((unsigned long) (rx_packets -
  796. priv->last_moder_packets[ring]));
  797. packets = rx_pkt_diff;
  798. rate = packets * HZ / period;
  799. avg_pkt_size = packets ? ((unsigned long) (rx_bytes -
  800. priv->last_moder_bytes[ring])) / packets : 0;
  801. /* Apply auto-moderation only when packet rate
  802. * exceeds a rate that it matters */
  803. if (rate > (MLX4_EN_RX_RATE_THRESH / priv->rx_ring_num) &&
  804. avg_pkt_size > MLX4_EN_AVG_PKT_SMALL) {
  805. if (rate < priv->pkt_rate_low)
  806. moder_time = priv->rx_usecs_low;
  807. else if (rate > priv->pkt_rate_high)
  808. moder_time = priv->rx_usecs_high;
  809. else
  810. moder_time = (rate - priv->pkt_rate_low) *
  811. (priv->rx_usecs_high - priv->rx_usecs_low) /
  812. (priv->pkt_rate_high - priv->pkt_rate_low) +
  813. priv->rx_usecs_low;
  814. } else {
  815. moder_time = priv->rx_usecs_low;
  816. }
  817. if (moder_time != priv->last_moder_time[ring]) {
  818. priv->last_moder_time[ring] = moder_time;
  819. cq = &priv->rx_cq[ring];
  820. cq->moder_time = moder_time;
  821. err = mlx4_en_set_cq_moder(priv, cq);
  822. if (err)
  823. en_err(priv, "Failed modifying moderation "
  824. "for cq:%d\n", ring);
  825. }
  826. priv->last_moder_packets[ring] = rx_packets;
  827. priv->last_moder_bytes[ring] = rx_bytes;
  828. }
  829. priv->last_moder_jiffies = jiffies;
  830. }
  831. static void mlx4_en_do_get_stats(struct work_struct *work)
  832. {
  833. struct delayed_work *delay = to_delayed_work(work);
  834. struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
  835. stats_task);
  836. struct mlx4_en_dev *mdev = priv->mdev;
  837. int err;
  838. err = mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 0);
  839. if (err)
  840. en_dbg(HW, priv, "Could not update stats\n");
  841. mutex_lock(&mdev->state_lock);
  842. if (mdev->device_up) {
  843. if (priv->port_up)
  844. mlx4_en_auto_moderation(priv);
  845. queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  846. }
  847. if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
  848. queue_work(mdev->workqueue, &priv->mac_task);
  849. mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
  850. }
  851. mutex_unlock(&mdev->state_lock);
  852. }
  853. static void mlx4_en_linkstate(struct work_struct *work)
  854. {
  855. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  856. linkstate_task);
  857. struct mlx4_en_dev *mdev = priv->mdev;
  858. int linkstate = priv->link_state;
  859. mutex_lock(&mdev->state_lock);
  860. /* If observable port state changed set carrier state and
  861. * report to system log */
  862. if (priv->last_link_state != linkstate) {
  863. if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
  864. en_info(priv, "Link Down\n");
  865. netif_carrier_off(priv->dev);
  866. } else {
  867. en_info(priv, "Link Up\n");
  868. netif_carrier_on(priv->dev);
  869. }
  870. }
  871. priv->last_link_state = linkstate;
  872. mutex_unlock(&mdev->state_lock);
  873. }
  874. int mlx4_en_start_port(struct net_device *dev)
  875. {
  876. struct mlx4_en_priv *priv = netdev_priv(dev);
  877. struct mlx4_en_dev *mdev = priv->mdev;
  878. struct mlx4_en_cq *cq;
  879. struct mlx4_en_tx_ring *tx_ring;
  880. int rx_index = 0;
  881. int tx_index = 0;
  882. int err = 0;
  883. int i;
  884. int j;
  885. u8 mc_list[16] = {0};
  886. if (priv->port_up) {
  887. en_dbg(DRV, priv, "start port called while port already up\n");
  888. return 0;
  889. }
  890. INIT_LIST_HEAD(&priv->mc_list);
  891. INIT_LIST_HEAD(&priv->curr_list);
  892. /* Calculate Rx buf size */
  893. dev->mtu = min(dev->mtu, priv->max_mtu);
  894. mlx4_en_calc_rx_buf(dev);
  895. en_dbg(DRV, priv, "Rx buf size:%d\n", priv->rx_skb_size);
  896. /* Configure rx cq's and rings */
  897. err = mlx4_en_activate_rx_rings(priv);
  898. if (err) {
  899. en_err(priv, "Failed to activate RX rings\n");
  900. return err;
  901. }
  902. for (i = 0; i < priv->rx_ring_num; i++) {
  903. cq = &priv->rx_cq[i];
  904. err = mlx4_en_activate_cq(priv, cq, i);
  905. if (err) {
  906. en_err(priv, "Failed activating Rx CQ\n");
  907. goto cq_err;
  908. }
  909. for (j = 0; j < cq->size; j++)
  910. cq->buf[j].owner_sr_opcode = MLX4_CQE_OWNER_MASK;
  911. err = mlx4_en_set_cq_moder(priv, cq);
  912. if (err) {
  913. en_err(priv, "Failed setting cq moderation parameters");
  914. mlx4_en_deactivate_cq(priv, cq);
  915. goto cq_err;
  916. }
  917. mlx4_en_arm_cq(priv, cq);
  918. priv->rx_ring[i].cqn = cq->mcq.cqn;
  919. ++rx_index;
  920. }
  921. /* Set qp number */
  922. en_dbg(DRV, priv, "Getting qp number for port %d\n", priv->port);
  923. err = mlx4_get_eth_qp(mdev->dev, priv->port,
  924. priv->mac, &priv->base_qpn);
  925. if (err) {
  926. en_err(priv, "Failed getting eth qp\n");
  927. goto cq_err;
  928. }
  929. mdev->mac_removed[priv->port] = 0;
  930. err = mlx4_en_config_rss_steer(priv);
  931. if (err) {
  932. en_err(priv, "Failed configuring rss steering\n");
  933. goto mac_err;
  934. }
  935. err = mlx4_en_create_drop_qp(priv);
  936. if (err)
  937. goto rss_err;
  938. /* Configure tx cq's and rings */
  939. for (i = 0; i < priv->tx_ring_num; i++) {
  940. /* Configure cq */
  941. cq = &priv->tx_cq[i];
  942. err = mlx4_en_activate_cq(priv, cq, i);
  943. if (err) {
  944. en_err(priv, "Failed allocating Tx CQ\n");
  945. goto tx_err;
  946. }
  947. err = mlx4_en_set_cq_moder(priv, cq);
  948. if (err) {
  949. en_err(priv, "Failed setting cq moderation parameters");
  950. mlx4_en_deactivate_cq(priv, cq);
  951. goto tx_err;
  952. }
  953. en_dbg(DRV, priv, "Resetting index of collapsed CQ:%d to -1\n", i);
  954. cq->buf->wqe_index = cpu_to_be16(0xffff);
  955. /* Configure ring */
  956. tx_ring = &priv->tx_ring[i];
  957. err = mlx4_en_activate_tx_ring(priv, tx_ring, cq->mcq.cqn,
  958. i / priv->mdev->profile.num_tx_rings_p_up);
  959. if (err) {
  960. en_err(priv, "Failed allocating Tx ring\n");
  961. mlx4_en_deactivate_cq(priv, cq);
  962. goto tx_err;
  963. }
  964. tx_ring->tx_queue = netdev_get_tx_queue(dev, i);
  965. /* Arm CQ for TX completions */
  966. mlx4_en_arm_cq(priv, cq);
  967. /* Set initial ownership of all Tx TXBBs to SW (1) */
  968. for (j = 0; j < tx_ring->buf_size; j += STAMP_STRIDE)
  969. *((u32 *) (tx_ring->buf + j)) = 0xffffffff;
  970. ++tx_index;
  971. }
  972. /* Configure port */
  973. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  974. priv->rx_skb_size + ETH_FCS_LEN,
  975. priv->prof->tx_pause,
  976. priv->prof->tx_ppp,
  977. priv->prof->rx_pause,
  978. priv->prof->rx_ppp);
  979. if (err) {
  980. en_err(priv, "Failed setting port general configurations "
  981. "for port %d, with error %d\n", priv->port, err);
  982. goto tx_err;
  983. }
  984. /* Set default qp number */
  985. err = mlx4_SET_PORT_qpn_calc(mdev->dev, priv->port, priv->base_qpn, 0);
  986. if (err) {
  987. en_err(priv, "Failed setting default qp numbers\n");
  988. goto tx_err;
  989. }
  990. /* Init port */
  991. en_dbg(HW, priv, "Initializing port\n");
  992. err = mlx4_INIT_PORT(mdev->dev, priv->port);
  993. if (err) {
  994. en_err(priv, "Failed Initializing port\n");
  995. goto tx_err;
  996. }
  997. /* Attach rx QP to bradcast address */
  998. memset(&mc_list[10], 0xff, ETH_ALEN);
  999. mc_list[5] = priv->port; /* needed for B0 steering support */
  1000. if (mlx4_multicast_attach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
  1001. priv->port, 0, MLX4_PROT_ETH,
  1002. &priv->broadcast_id))
  1003. mlx4_warn(mdev, "Failed Attaching Broadcast\n");
  1004. /* Must redo promiscuous mode setup. */
  1005. priv->flags &= ~(MLX4_EN_FLAG_PROMISC | MLX4_EN_FLAG_MC_PROMISC);
  1006. if (mdev->dev->caps.steering_mode ==
  1007. MLX4_STEERING_MODE_DEVICE_MANAGED) {
  1008. mlx4_flow_steer_promisc_remove(mdev->dev,
  1009. priv->port,
  1010. MLX4_FS_PROMISC_UPLINK);
  1011. mlx4_flow_steer_promisc_remove(mdev->dev,
  1012. priv->port,
  1013. MLX4_FS_PROMISC_ALL_MULTI);
  1014. }
  1015. /* Schedule multicast task to populate multicast list */
  1016. queue_work(mdev->workqueue, &priv->mcast_task);
  1017. mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
  1018. priv->port_up = true;
  1019. netif_tx_start_all_queues(dev);
  1020. return 0;
  1021. tx_err:
  1022. while (tx_index--) {
  1023. mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[tx_index]);
  1024. mlx4_en_deactivate_cq(priv, &priv->tx_cq[tx_index]);
  1025. }
  1026. mlx4_en_destroy_drop_qp(priv);
  1027. rss_err:
  1028. mlx4_en_release_rss_steer(priv);
  1029. mac_err:
  1030. mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
  1031. cq_err:
  1032. while (rx_index--)
  1033. mlx4_en_deactivate_cq(priv, &priv->rx_cq[rx_index]);
  1034. for (i = 0; i < priv->rx_ring_num; i++)
  1035. mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
  1036. return err; /* need to close devices */
  1037. }
  1038. void mlx4_en_stop_port(struct net_device *dev)
  1039. {
  1040. struct mlx4_en_priv *priv = netdev_priv(dev);
  1041. struct mlx4_en_dev *mdev = priv->mdev;
  1042. struct mlx4_en_mc_list *mclist, *tmp;
  1043. int i;
  1044. u8 mc_list[16] = {0};
  1045. if (!priv->port_up) {
  1046. en_dbg(DRV, priv, "stop port called while port already down\n");
  1047. return;
  1048. }
  1049. /* Synchronize with tx routine */
  1050. netif_tx_lock_bh(dev);
  1051. netif_tx_stop_all_queues(dev);
  1052. netif_tx_unlock_bh(dev);
  1053. /* Set port as not active */
  1054. priv->port_up = false;
  1055. /* Detach All multicasts */
  1056. memset(&mc_list[10], 0xff, ETH_ALEN);
  1057. mc_list[5] = priv->port; /* needed for B0 steering support */
  1058. mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, mc_list,
  1059. MLX4_PROT_ETH, priv->broadcast_id);
  1060. list_for_each_entry(mclist, &priv->curr_list, list) {
  1061. memcpy(&mc_list[10], mclist->addr, ETH_ALEN);
  1062. mc_list[5] = priv->port;
  1063. mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
  1064. mc_list, MLX4_PROT_ETH, mclist->reg_id);
  1065. }
  1066. mlx4_en_clear_list(dev);
  1067. list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
  1068. list_del(&mclist->list);
  1069. kfree(mclist);
  1070. }
  1071. /* Flush multicast filter */
  1072. mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
  1073. mlx4_en_destroy_drop_qp(priv);
  1074. /* Free TX Rings */
  1075. for (i = 0; i < priv->tx_ring_num; i++) {
  1076. mlx4_en_deactivate_tx_ring(priv, &priv->tx_ring[i]);
  1077. mlx4_en_deactivate_cq(priv, &priv->tx_cq[i]);
  1078. }
  1079. msleep(10);
  1080. for (i = 0; i < priv->tx_ring_num; i++)
  1081. mlx4_en_free_tx_buf(dev, &priv->tx_ring[i]);
  1082. /* Free RSS qps */
  1083. mlx4_en_release_rss_steer(priv);
  1084. /* Unregister Mac address for the port */
  1085. mlx4_put_eth_qp(mdev->dev, priv->port, priv->mac, priv->base_qpn);
  1086. mdev->mac_removed[priv->port] = 1;
  1087. /* Free RX Rings */
  1088. for (i = 0; i < priv->rx_ring_num; i++) {
  1089. mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
  1090. while (test_bit(NAPI_STATE_SCHED, &priv->rx_cq[i].napi.state))
  1091. msleep(1);
  1092. mlx4_en_deactivate_cq(priv, &priv->rx_cq[i]);
  1093. }
  1094. /* close port*/
  1095. mlx4_CLOSE_PORT(mdev->dev, priv->port);
  1096. }
  1097. static void mlx4_en_restart(struct work_struct *work)
  1098. {
  1099. struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
  1100. watchdog_task);
  1101. struct mlx4_en_dev *mdev = priv->mdev;
  1102. struct net_device *dev = priv->dev;
  1103. int i;
  1104. en_dbg(DRV, priv, "Watchdog task called for port %d\n", priv->port);
  1105. mutex_lock(&mdev->state_lock);
  1106. if (priv->port_up) {
  1107. mlx4_en_stop_port(dev);
  1108. for (i = 0; i < priv->tx_ring_num; i++)
  1109. netdev_tx_reset_queue(priv->tx_ring[i].tx_queue);
  1110. if (mlx4_en_start_port(dev))
  1111. en_err(priv, "Failed restarting port %d\n", priv->port);
  1112. }
  1113. mutex_unlock(&mdev->state_lock);
  1114. }
  1115. static void mlx4_en_clear_stats(struct net_device *dev)
  1116. {
  1117. struct mlx4_en_priv *priv = netdev_priv(dev);
  1118. struct mlx4_en_dev *mdev = priv->mdev;
  1119. int i;
  1120. if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
  1121. en_dbg(HW, priv, "Failed dumping statistics\n");
  1122. memset(&priv->stats, 0, sizeof(priv->stats));
  1123. memset(&priv->pstats, 0, sizeof(priv->pstats));
  1124. memset(&priv->pkstats, 0, sizeof(priv->pkstats));
  1125. memset(&priv->port_stats, 0, sizeof(priv->port_stats));
  1126. for (i = 0; i < priv->tx_ring_num; i++) {
  1127. priv->tx_ring[i].bytes = 0;
  1128. priv->tx_ring[i].packets = 0;
  1129. priv->tx_ring[i].tx_csum = 0;
  1130. }
  1131. for (i = 0; i < priv->rx_ring_num; i++) {
  1132. priv->rx_ring[i].bytes = 0;
  1133. priv->rx_ring[i].packets = 0;
  1134. priv->rx_ring[i].csum_ok = 0;
  1135. priv->rx_ring[i].csum_none = 0;
  1136. }
  1137. }
  1138. static int mlx4_en_open(struct net_device *dev)
  1139. {
  1140. struct mlx4_en_priv *priv = netdev_priv(dev);
  1141. struct mlx4_en_dev *mdev = priv->mdev;
  1142. int err = 0;
  1143. mutex_lock(&mdev->state_lock);
  1144. if (!mdev->device_up) {
  1145. en_err(priv, "Cannot open - device down/disabled\n");
  1146. err = -EBUSY;
  1147. goto out;
  1148. }
  1149. /* Reset HW statistics and SW counters */
  1150. mlx4_en_clear_stats(dev);
  1151. err = mlx4_en_start_port(dev);
  1152. if (err)
  1153. en_err(priv, "Failed starting port:%d\n", priv->port);
  1154. out:
  1155. mutex_unlock(&mdev->state_lock);
  1156. return err;
  1157. }
  1158. static int mlx4_en_close(struct net_device *dev)
  1159. {
  1160. struct mlx4_en_priv *priv = netdev_priv(dev);
  1161. struct mlx4_en_dev *mdev = priv->mdev;
  1162. en_dbg(IFDOWN, priv, "Close port called\n");
  1163. mutex_lock(&mdev->state_lock);
  1164. mlx4_en_stop_port(dev);
  1165. netif_carrier_off(dev);
  1166. mutex_unlock(&mdev->state_lock);
  1167. return 0;
  1168. }
  1169. void mlx4_en_free_resources(struct mlx4_en_priv *priv)
  1170. {
  1171. int i;
  1172. #ifdef CONFIG_RFS_ACCEL
  1173. free_irq_cpu_rmap(priv->dev->rx_cpu_rmap);
  1174. priv->dev->rx_cpu_rmap = NULL;
  1175. #endif
  1176. for (i = 0; i < priv->tx_ring_num; i++) {
  1177. if (priv->tx_ring[i].tx_info)
  1178. mlx4_en_destroy_tx_ring(priv, &priv->tx_ring[i]);
  1179. if (priv->tx_cq[i].buf)
  1180. mlx4_en_destroy_cq(priv, &priv->tx_cq[i]);
  1181. }
  1182. for (i = 0; i < priv->rx_ring_num; i++) {
  1183. if (priv->rx_ring[i].rx_info)
  1184. mlx4_en_destroy_rx_ring(priv, &priv->rx_ring[i],
  1185. priv->prof->rx_ring_size, priv->stride);
  1186. if (priv->rx_cq[i].buf)
  1187. mlx4_en_destroy_cq(priv, &priv->rx_cq[i]);
  1188. }
  1189. if (priv->base_tx_qpn) {
  1190. mlx4_qp_release_range(priv->mdev->dev, priv->base_tx_qpn, priv->tx_ring_num);
  1191. priv->base_tx_qpn = 0;
  1192. }
  1193. }
  1194. int mlx4_en_alloc_resources(struct mlx4_en_priv *priv)
  1195. {
  1196. struct mlx4_en_port_profile *prof = priv->prof;
  1197. int i;
  1198. int err;
  1199. err = mlx4_qp_reserve_range(priv->mdev->dev, priv->tx_ring_num, 256, &priv->base_tx_qpn);
  1200. if (err) {
  1201. en_err(priv, "failed reserving range for TX rings\n");
  1202. return err;
  1203. }
  1204. /* Create tx Rings */
  1205. for (i = 0; i < priv->tx_ring_num; i++) {
  1206. if (mlx4_en_create_cq(priv, &priv->tx_cq[i],
  1207. prof->tx_ring_size, i, TX))
  1208. goto err;
  1209. if (mlx4_en_create_tx_ring(priv, &priv->tx_ring[i], priv->base_tx_qpn + i,
  1210. prof->tx_ring_size, TXBB_SIZE))
  1211. goto err;
  1212. }
  1213. /* Create rx Rings */
  1214. for (i = 0; i < priv->rx_ring_num; i++) {
  1215. if (mlx4_en_create_cq(priv, &priv->rx_cq[i],
  1216. prof->rx_ring_size, i, RX))
  1217. goto err;
  1218. if (mlx4_en_create_rx_ring(priv, &priv->rx_ring[i],
  1219. prof->rx_ring_size, priv->stride))
  1220. goto err;
  1221. }
  1222. #ifdef CONFIG_RFS_ACCEL
  1223. priv->dev->rx_cpu_rmap = alloc_irq_cpu_rmap(priv->rx_ring_num);
  1224. if (!priv->dev->rx_cpu_rmap)
  1225. goto err;
  1226. INIT_LIST_HEAD(&priv->filters);
  1227. spin_lock_init(&priv->filters_lock);
  1228. #endif
  1229. return 0;
  1230. err:
  1231. en_err(priv, "Failed to allocate NIC resources\n");
  1232. return -ENOMEM;
  1233. }
  1234. void mlx4_en_destroy_netdev(struct net_device *dev)
  1235. {
  1236. struct mlx4_en_priv *priv = netdev_priv(dev);
  1237. struct mlx4_en_dev *mdev = priv->mdev;
  1238. en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
  1239. /* Unregister device - this will close the port if it was up */
  1240. if (priv->registered)
  1241. unregister_netdev(dev);
  1242. if (priv->allocated)
  1243. mlx4_free_hwq_res(mdev->dev, &priv->res, MLX4_EN_PAGE_SIZE);
  1244. cancel_delayed_work(&priv->stats_task);
  1245. /* flush any pending task for this netdev */
  1246. flush_workqueue(mdev->workqueue);
  1247. /* Detach the netdev so tasks would not attempt to access it */
  1248. mutex_lock(&mdev->state_lock);
  1249. mdev->pndev[priv->port] = NULL;
  1250. mutex_unlock(&mdev->state_lock);
  1251. mlx4_en_free_resources(priv);
  1252. kfree(priv->tx_ring);
  1253. kfree(priv->tx_cq);
  1254. free_netdev(dev);
  1255. }
  1256. static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
  1257. {
  1258. struct mlx4_en_priv *priv = netdev_priv(dev);
  1259. struct mlx4_en_dev *mdev = priv->mdev;
  1260. int err = 0;
  1261. en_dbg(DRV, priv, "Change MTU called - current:%d new:%d\n",
  1262. dev->mtu, new_mtu);
  1263. if ((new_mtu < MLX4_EN_MIN_MTU) || (new_mtu > priv->max_mtu)) {
  1264. en_err(priv, "Bad MTU size:%d.\n", new_mtu);
  1265. return -EPERM;
  1266. }
  1267. dev->mtu = new_mtu;
  1268. if (netif_running(dev)) {
  1269. mutex_lock(&mdev->state_lock);
  1270. if (!mdev->device_up) {
  1271. /* NIC is probably restarting - let watchdog task reset
  1272. * the port */
  1273. en_dbg(DRV, priv, "Change MTU called with card down!?\n");
  1274. } else {
  1275. mlx4_en_stop_port(dev);
  1276. err = mlx4_en_start_port(dev);
  1277. if (err) {
  1278. en_err(priv, "Failed restarting port:%d\n",
  1279. priv->port);
  1280. queue_work(mdev->workqueue, &priv->watchdog_task);
  1281. }
  1282. }
  1283. mutex_unlock(&mdev->state_lock);
  1284. }
  1285. return 0;
  1286. }
  1287. static int mlx4_en_set_features(struct net_device *netdev,
  1288. netdev_features_t features)
  1289. {
  1290. struct mlx4_en_priv *priv = netdev_priv(netdev);
  1291. if (features & NETIF_F_LOOPBACK)
  1292. priv->ctrl_flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
  1293. else
  1294. priv->ctrl_flags &=
  1295. cpu_to_be32(~MLX4_WQE_CTRL_FORCE_LOOPBACK);
  1296. return 0;
  1297. }
  1298. static const struct net_device_ops mlx4_netdev_ops = {
  1299. .ndo_open = mlx4_en_open,
  1300. .ndo_stop = mlx4_en_close,
  1301. .ndo_start_xmit = mlx4_en_xmit,
  1302. .ndo_select_queue = mlx4_en_select_queue,
  1303. .ndo_get_stats = mlx4_en_get_stats,
  1304. .ndo_set_rx_mode = mlx4_en_set_multicast,
  1305. .ndo_set_mac_address = mlx4_en_set_mac,
  1306. .ndo_validate_addr = eth_validate_addr,
  1307. .ndo_change_mtu = mlx4_en_change_mtu,
  1308. .ndo_tx_timeout = mlx4_en_tx_timeout,
  1309. .ndo_vlan_rx_add_vid = mlx4_en_vlan_rx_add_vid,
  1310. .ndo_vlan_rx_kill_vid = mlx4_en_vlan_rx_kill_vid,
  1311. #ifdef CONFIG_NET_POLL_CONTROLLER
  1312. .ndo_poll_controller = mlx4_en_netpoll,
  1313. #endif
  1314. .ndo_set_features = mlx4_en_set_features,
  1315. .ndo_setup_tc = mlx4_en_setup_tc,
  1316. #ifdef CONFIG_RFS_ACCEL
  1317. .ndo_rx_flow_steer = mlx4_en_filter_rfs,
  1318. #endif
  1319. };
  1320. int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
  1321. struct mlx4_en_port_profile *prof)
  1322. {
  1323. struct net_device *dev;
  1324. struct mlx4_en_priv *priv;
  1325. int i;
  1326. int err;
  1327. dev = alloc_etherdev_mqs(sizeof(struct mlx4_en_priv),
  1328. prof->tx_ring_num, prof->rx_ring_num);
  1329. if (dev == NULL)
  1330. return -ENOMEM;
  1331. SET_NETDEV_DEV(dev, &mdev->dev->pdev->dev);
  1332. dev->dev_id = port - 1;
  1333. /*
  1334. * Initialize driver private data
  1335. */
  1336. priv = netdev_priv(dev);
  1337. memset(priv, 0, sizeof(struct mlx4_en_priv));
  1338. priv->dev = dev;
  1339. priv->mdev = mdev;
  1340. priv->ddev = &mdev->pdev->dev;
  1341. priv->prof = prof;
  1342. priv->port = port;
  1343. priv->port_up = false;
  1344. priv->flags = prof->flags;
  1345. priv->ctrl_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
  1346. MLX4_WQE_CTRL_SOLICITED);
  1347. priv->tx_ring_num = prof->tx_ring_num;
  1348. priv->tx_ring = kzalloc(sizeof(struct mlx4_en_tx_ring) *
  1349. priv->tx_ring_num, GFP_KERNEL);
  1350. if (!priv->tx_ring) {
  1351. err = -ENOMEM;
  1352. goto out;
  1353. }
  1354. priv->tx_cq = kzalloc(sizeof(struct mlx4_en_cq) * priv->tx_ring_num,
  1355. GFP_KERNEL);
  1356. if (!priv->tx_cq) {
  1357. err = -ENOMEM;
  1358. goto out;
  1359. }
  1360. priv->rx_ring_num = prof->rx_ring_num;
  1361. priv->mac_index = -1;
  1362. priv->msg_enable = MLX4_EN_MSG_LEVEL;
  1363. spin_lock_init(&priv->stats_lock);
  1364. INIT_WORK(&priv->mcast_task, mlx4_en_do_set_multicast);
  1365. INIT_WORK(&priv->mac_task, mlx4_en_do_set_mac);
  1366. INIT_WORK(&priv->watchdog_task, mlx4_en_restart);
  1367. INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
  1368. INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
  1369. #ifdef CONFIG_MLX4_EN_DCB
  1370. if (!mlx4_is_slave(priv->mdev->dev))
  1371. dev->dcbnl_ops = &mlx4_en_dcbnl_ops;
  1372. #endif
  1373. /* Query for default mac and max mtu */
  1374. priv->max_mtu = mdev->dev->caps.eth_mtu_cap[priv->port];
  1375. priv->mac = mdev->dev->caps.def_mac[priv->port];
  1376. if (ILLEGAL_MAC(priv->mac)) {
  1377. en_err(priv, "Port: %d, invalid mac burned: 0x%llx, quiting\n",
  1378. priv->port, priv->mac);
  1379. err = -EINVAL;
  1380. goto out;
  1381. }
  1382. priv->stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) +
  1383. DS_SIZE * MLX4_EN_MAX_RX_FRAGS);
  1384. err = mlx4_en_alloc_resources(priv);
  1385. if (err)
  1386. goto out;
  1387. /* Allocate page for receive rings */
  1388. err = mlx4_alloc_hwq_res(mdev->dev, &priv->res,
  1389. MLX4_EN_PAGE_SIZE, MLX4_EN_PAGE_SIZE);
  1390. if (err) {
  1391. en_err(priv, "Failed to allocate page for rx qps\n");
  1392. goto out;
  1393. }
  1394. priv->allocated = 1;
  1395. /*
  1396. * Initialize netdev entry points
  1397. */
  1398. dev->netdev_ops = &mlx4_netdev_ops;
  1399. dev->watchdog_timeo = MLX4_EN_WATCHDOG_TIMEOUT;
  1400. netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
  1401. netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
  1402. SET_ETHTOOL_OPS(dev, &mlx4_en_ethtool_ops);
  1403. /* Set defualt MAC */
  1404. dev->addr_len = ETH_ALEN;
  1405. for (i = 0; i < ETH_ALEN; i++) {
  1406. dev->dev_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
  1407. dev->perm_addr[ETH_ALEN - 1 - i] = (u8) (priv->mac >> (8 * i));
  1408. }
  1409. /*
  1410. * Set driver features
  1411. */
  1412. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  1413. if (mdev->LSO_support)
  1414. dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
  1415. dev->vlan_features = dev->hw_features;
  1416. dev->hw_features |= NETIF_F_RXCSUM | NETIF_F_RXHASH;
  1417. dev->features = dev->hw_features | NETIF_F_HIGHDMA |
  1418. NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
  1419. NETIF_F_HW_VLAN_FILTER;
  1420. dev->hw_features |= NETIF_F_LOOPBACK;
  1421. if (mdev->dev->caps.steering_mode ==
  1422. MLX4_STEERING_MODE_DEVICE_MANAGED)
  1423. dev->hw_features |= NETIF_F_NTUPLE;
  1424. mdev->pndev[port] = dev;
  1425. netif_carrier_off(dev);
  1426. err = register_netdev(dev);
  1427. if (err) {
  1428. en_err(priv, "Netdev registration failed for port %d\n", port);
  1429. goto out;
  1430. }
  1431. priv->registered = 1;
  1432. en_warn(priv, "Using %d TX rings\n", prof->tx_ring_num);
  1433. en_warn(priv, "Using %d RX rings\n", prof->rx_ring_num);
  1434. /* Configure port */
  1435. mlx4_en_calc_rx_buf(dev);
  1436. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  1437. priv->rx_skb_size + ETH_FCS_LEN,
  1438. prof->tx_pause, prof->tx_ppp,
  1439. prof->rx_pause, prof->rx_ppp);
  1440. if (err) {
  1441. en_err(priv, "Failed setting port general configurations "
  1442. "for port %d, with error %d\n", priv->port, err);
  1443. goto out;
  1444. }
  1445. /* Init port */
  1446. en_warn(priv, "Initializing port\n");
  1447. err = mlx4_INIT_PORT(mdev->dev, priv->port);
  1448. if (err) {
  1449. en_err(priv, "Failed Initializing port\n");
  1450. goto out;
  1451. }
  1452. mlx4_en_set_default_moderation(priv);
  1453. queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  1454. return 0;
  1455. out:
  1456. mlx4_en_destroy_netdev(dev);
  1457. return err;
  1458. }