en_netdev.c 45 KB

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