en_netdev.c 32 KB

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