en_netdev.c 32 KB

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