nes_nic.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. /*
  2. * Copyright (c) 2006 - 2011 Intel Corporation. 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/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/ip.h>
  38. #include <linux/tcp.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/ethtool.h>
  42. #include <linux/slab.h>
  43. #include <net/tcp.h>
  44. #include <net/inet_common.h>
  45. #include <linux/inet.h>
  46. #include "nes.h"
  47. static struct nic_qp_map nic_qp_mapping_0[] = {
  48. {16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0},
  49. {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0},
  50. {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
  51. {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
  52. };
  53. static struct nic_qp_map nic_qp_mapping_1[] = {
  54. {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
  55. {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
  56. };
  57. static struct nic_qp_map nic_qp_mapping_2[] = {
  58. {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}
  59. };
  60. static struct nic_qp_map nic_qp_mapping_3[] = {
  61. {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
  62. };
  63. static struct nic_qp_map nic_qp_mapping_4[] = {
  64. {28,8,0,0},{32,12,0,0}
  65. };
  66. static struct nic_qp_map nic_qp_mapping_5[] = {
  67. {29,9,1,0},{33,13,1,0}
  68. };
  69. static struct nic_qp_map nic_qp_mapping_6[] = {
  70. {30,10,2,0},{34,14,2,0}
  71. };
  72. static struct nic_qp_map nic_qp_mapping_7[] = {
  73. {31,11,3,0},{35,15,3,0}
  74. };
  75. static struct nic_qp_map *nic_qp_mapping_per_function[] = {
  76. nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3,
  77. nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7
  78. };
  79. static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
  80. | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
  81. static int debug = -1;
  82. static int nics_per_function = 1;
  83. /**
  84. * nes_netdev_poll
  85. */
  86. static int nes_netdev_poll(struct napi_struct *napi, int budget)
  87. {
  88. struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
  89. struct nes_device *nesdev = nesvnic->nesdev;
  90. struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;
  91. nesvnic->budget = budget;
  92. nescq->cqes_pending = 0;
  93. nescq->rx_cqes_completed = 0;
  94. nescq->cqe_allocs_pending = 0;
  95. nescq->rx_pkts_indicated = 0;
  96. nes_nic_ce_handler(nesdev, nescq);
  97. if (nescq->cqes_pending == 0) {
  98. napi_complete(napi);
  99. /* clear out completed cqes and arm */
  100. nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
  101. nescq->cq_number | (nescq->cqe_allocs_pending << 16));
  102. nes_read32(nesdev->regs+NES_CQE_ALLOC);
  103. } else {
  104. /* clear out completed cqes but don't arm */
  105. nes_write32(nesdev->regs+NES_CQE_ALLOC,
  106. nescq->cq_number | (nescq->cqe_allocs_pending << 16));
  107. nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
  108. nesvnic->netdev->name);
  109. }
  110. return nescq->rx_pkts_indicated;
  111. }
  112. /**
  113. * nes_netdev_open - Activate the network interface; ifconfig
  114. * ethx up.
  115. */
  116. static int nes_netdev_open(struct net_device *netdev)
  117. {
  118. u32 macaddr_low;
  119. u16 macaddr_high;
  120. struct nes_vnic *nesvnic = netdev_priv(netdev);
  121. struct nes_device *nesdev = nesvnic->nesdev;
  122. int ret;
  123. int i;
  124. struct nes_vnic *first_nesvnic = NULL;
  125. u32 nic_active_bit;
  126. u32 nic_active;
  127. struct list_head *list_pos, *list_temp;
  128. unsigned long flags;
  129. assert(nesdev != NULL);
  130. if (nesvnic->netdev_open == 1)
  131. return 0;
  132. if (netif_msg_ifup(nesvnic))
  133. printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
  134. ret = nes_init_nic_qp(nesdev, netdev);
  135. if (ret) {
  136. return ret;
  137. }
  138. netif_carrier_off(netdev);
  139. netif_stop_queue(netdev);
  140. if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
  141. nesvnic->nesibdev = nes_init_ofa_device(netdev);
  142. if (nesvnic->nesibdev == NULL) {
  143. printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
  144. } else {
  145. nesvnic->nesibdev->nesvnic = nesvnic;
  146. ret = nes_register_ofa_device(nesvnic->nesibdev);
  147. if (ret) {
  148. printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
  149. netdev->name, ret);
  150. }
  151. }
  152. }
  153. /* Set packet filters */
  154. nic_active_bit = 1 << nesvnic->nic_index;
  155. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
  156. nic_active |= nic_active_bit;
  157. nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
  158. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
  159. nic_active |= nic_active_bit;
  160. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
  161. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
  162. nic_active |= nic_active_bit;
  163. nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
  164. macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
  165. macaddr_high += (u16)netdev->dev_addr[1];
  166. macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
  167. macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
  168. macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
  169. macaddr_low += (u32)netdev->dev_addr[5];
  170. /* Program the various MAC regs */
  171. for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
  172. if (nesvnic->qp_nic_index[i] == 0xf) {
  173. break;
  174. }
  175. nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
  176. " (Addr:%08X) = %08X, HIGH = %08X.\n",
  177. i, nesvnic->qp_nic_index[i],
  178. NES_IDX_PERFECT_FILTER_LOW+
  179. (nesvnic->qp_nic_index[i] * 8),
  180. macaddr_low,
  181. (u32)macaddr_high | NES_MAC_ADDR_VALID |
  182. ((((u32)nesvnic->nic_index) << 16)));
  183. nes_write_indexed(nesdev,
  184. NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
  185. macaddr_low);
  186. nes_write_indexed(nesdev,
  187. NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
  188. (u32)macaddr_high | NES_MAC_ADDR_VALID |
  189. ((((u32)nesvnic->nic_index) << 16)));
  190. }
  191. nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
  192. nesvnic->nic_cq.cq_number);
  193. nes_read32(nesdev->regs+NES_CQE_ALLOC);
  194. list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
  195. first_nesvnic = container_of(list_pos, struct nes_vnic, list);
  196. if (first_nesvnic->netdev_open == 1)
  197. break;
  198. }
  199. if (first_nesvnic->netdev_open == 0) {
  200. nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
  201. nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index),
  202. ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
  203. NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
  204. first_nesvnic = nesvnic;
  205. }
  206. if (first_nesvnic->linkup) {
  207. /* Enable network packets */
  208. nesvnic->linkup = 1;
  209. netif_start_queue(netdev);
  210. netif_carrier_on(netdev);
  211. }
  212. spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
  213. if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_SFP_D) {
  214. if (nesdev->link_recheck)
  215. cancel_delayed_work(&nesdev->work);
  216. nesdev->link_recheck = 1;
  217. schedule_delayed_work(&nesdev->work, NES_LINK_RECHECK_DELAY);
  218. }
  219. spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
  220. spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
  221. if (nesvnic->of_device_registered) {
  222. nesdev->nesadapter->send_term_ok = 1;
  223. if (nesvnic->linkup == 1) {
  224. if (nesdev->iw_status == 0) {
  225. nesdev->iw_status = 1;
  226. nes_port_ibevent(nesvnic);
  227. }
  228. } else {
  229. nesdev->iw_status = 0;
  230. }
  231. }
  232. spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);
  233. napi_enable(&nesvnic->napi);
  234. nesvnic->netdev_open = 1;
  235. return 0;
  236. }
  237. /**
  238. * nes_netdev_stop
  239. */
  240. static int nes_netdev_stop(struct net_device *netdev)
  241. {
  242. struct nes_vnic *nesvnic = netdev_priv(netdev);
  243. struct nes_device *nesdev = nesvnic->nesdev;
  244. u32 nic_active_mask;
  245. u32 nic_active;
  246. struct nes_vnic *first_nesvnic = NULL;
  247. struct list_head *list_pos, *list_temp;
  248. unsigned long flags;
  249. nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
  250. nesvnic, nesdev, netdev, netdev->name);
  251. if (nesvnic->netdev_open == 0)
  252. return 0;
  253. if (netif_msg_ifdown(nesvnic))
  254. printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
  255. netif_carrier_off(netdev);
  256. /* Disable network packets */
  257. napi_disable(&nesvnic->napi);
  258. netif_stop_queue(netdev);
  259. list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
  260. first_nesvnic = container_of(list_pos, struct nes_vnic, list);
  261. if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic))
  262. break;
  263. }
  264. if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic) &&
  265. (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) !=
  266. PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) {
  267. nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+
  268. (0x200*nesdev->mac_index), 0xffffffff);
  269. nes_write_indexed(first_nesvnic->nesdev,
  270. NES_IDX_MAC_INT_MASK+
  271. (0x200*first_nesvnic->nesdev->mac_index),
  272. ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
  273. NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
  274. } else {
  275. nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
  276. }
  277. nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
  278. nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
  279. (nesvnic->perfect_filter_index*8), 0);
  280. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
  281. nic_active &= nic_active_mask;
  282. nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
  283. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
  284. nic_active &= nic_active_mask;
  285. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
  286. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
  287. nic_active &= nic_active_mask;
  288. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
  289. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
  290. nic_active &= nic_active_mask;
  291. nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
  292. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
  293. nic_active &= nic_active_mask;
  294. nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
  295. spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
  296. if (nesvnic->of_device_registered) {
  297. nesdev->nesadapter->send_term_ok = 0;
  298. nesdev->iw_status = 0;
  299. if (nesvnic->linkup == 1)
  300. nes_port_ibevent(nesvnic);
  301. }
  302. del_timer_sync(&nesvnic->event_timer);
  303. nesvnic->event_timer.function = NULL;
  304. spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);
  305. nes_destroy_nic_qp(nesvnic);
  306. nesvnic->netdev_open = 0;
  307. return 0;
  308. }
  309. /**
  310. * nes_nic_send
  311. */
  312. static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
  313. {
  314. struct nes_vnic *nesvnic = netdev_priv(netdev);
  315. struct nes_device *nesdev = nesvnic->nesdev;
  316. struct nes_hw_nic *nesnic = &nesvnic->nic;
  317. struct nes_hw_nic_sq_wqe *nic_sqe;
  318. struct tcphdr *tcph;
  319. __le16 *wqe_fragment_length;
  320. u32 wqe_misc;
  321. u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
  322. u16 skb_fragment_index;
  323. dma_addr_t bus_address;
  324. nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
  325. wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
  326. /* setup the VLAN tag if present */
  327. if (vlan_tx_tag_present(skb)) {
  328. nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
  329. netdev->name, vlan_tx_tag_get(skb));
  330. wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
  331. wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
  332. } else
  333. wqe_misc = 0;
  334. /* bump past the vlan tag */
  335. wqe_fragment_length++;
  336. /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
  337. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  338. tcph = tcp_hdr(skb);
  339. if (1) {
  340. if (skb_is_gso(skb)) {
  341. /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
  342. netdev->name, skb_is_gso(skb)); */
  343. wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
  344. NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
  345. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
  346. ((u32)tcph->doff) |
  347. (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
  348. } else {
  349. wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
  350. }
  351. }
  352. } else { /* CHECKSUM_HW */
  353. wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
  354. }
  355. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
  356. skb->len);
  357. memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
  358. skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
  359. wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
  360. skb_headlen(skb)));
  361. wqe_fragment_length[1] = 0;
  362. if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
  363. if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
  364. nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
  365. netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
  366. kfree_skb(skb);
  367. nesvnic->tx_sw_dropped++;
  368. return NETDEV_TX_LOCKED;
  369. }
  370. set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
  371. bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
  372. skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
  373. wqe_fragment_length[wqe_fragment_index++] =
  374. cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
  375. wqe_fragment_length[wqe_fragment_index] = 0;
  376. set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
  377. ((u64)(bus_address)));
  378. nesnic->tx_skb[nesnic->sq_head] = skb;
  379. }
  380. if (skb_headlen(skb) == skb->len) {
  381. if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
  382. nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
  383. nesnic->tx_skb[nesnic->sq_head] = skb;
  384. }
  385. } else {
  386. /* Deal with Fragments */
  387. nesnic->tx_skb[nesnic->sq_head] = skb;
  388. for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
  389. skb_fragment_index++) {
  390. skb_frag_t *frag =
  391. &skb_shinfo(skb)->frags[skb_fragment_index];
  392. bus_address = skb_frag_dma_map(&nesdev->pcidev->dev,
  393. frag, 0, skb_frag_size(frag),
  394. DMA_TO_DEVICE);
  395. wqe_fragment_length[wqe_fragment_index] =
  396. cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[skb_fragment_index]));
  397. set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
  398. bus_address);
  399. wqe_fragment_index++;
  400. if (wqe_fragment_index < 5)
  401. wqe_fragment_length[wqe_fragment_index] = 0;
  402. }
  403. }
  404. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
  405. nesnic->sq_head++;
  406. nesnic->sq_head &= nesnic->sq_size - 1;
  407. return NETDEV_TX_OK;
  408. }
  409. /**
  410. * nes_netdev_start_xmit
  411. */
  412. static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
  413. {
  414. struct nes_vnic *nesvnic = netdev_priv(netdev);
  415. struct nes_device *nesdev = nesvnic->nesdev;
  416. struct nes_hw_nic *nesnic = &nesvnic->nic;
  417. struct nes_hw_nic_sq_wqe *nic_sqe;
  418. struct tcphdr *tcph;
  419. /* struct udphdr *udph; */
  420. #define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
  421. /* 64K segment plus overflow on each side */
  422. dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
  423. dma_addr_t bus_address;
  424. u32 tso_frag_index;
  425. u32 tso_frag_count;
  426. u32 tso_wqe_length;
  427. u32 curr_tcp_seq;
  428. u32 wqe_count=1;
  429. u32 send_rc;
  430. struct iphdr *iph;
  431. __le16 *wqe_fragment_length;
  432. u32 nr_frags;
  433. u32 original_first_length;
  434. /* u64 *wqe_fragment_address; */
  435. /* first fragment (0) is used by copy buffer */
  436. u16 wqe_fragment_index=1;
  437. u16 hoffset;
  438. u16 nhoffset;
  439. u16 wqes_needed;
  440. u16 wqes_available;
  441. u32 wqe_misc;
  442. /*
  443. * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
  444. * " (%u frags), tso_size=%u\n",
  445. * netdev->name, skb->len, skb_headlen(skb),
  446. * skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
  447. */
  448. if (!netif_carrier_ok(netdev))
  449. return NETDEV_TX_OK;
  450. if (netif_queue_stopped(netdev))
  451. return NETDEV_TX_BUSY;
  452. /* Check if SQ is full */
  453. if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
  454. if (!netif_queue_stopped(netdev)) {
  455. netif_stop_queue(netdev);
  456. barrier();
  457. if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
  458. netif_start_queue(netdev);
  459. goto sq_no_longer_full;
  460. }
  461. }
  462. nesvnic->sq_full++;
  463. return NETDEV_TX_BUSY;
  464. }
  465. sq_no_longer_full:
  466. nr_frags = skb_shinfo(skb)->nr_frags;
  467. if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
  468. nr_frags++;
  469. }
  470. /* Check if too many fragments */
  471. if (unlikely((nr_frags > 4))) {
  472. if (skb_is_gso(skb)) {
  473. nesvnic->segmented_tso_requests++;
  474. nesvnic->tso_requests++;
  475. /* Basically 4 fragments available per WQE with extended fragments */
  476. wqes_needed = nr_frags >> 2;
  477. wqes_needed += (nr_frags&3)?1:0;
  478. wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
  479. (nesnic->sq_size - 1);
  480. if (unlikely(wqes_needed > wqes_available)) {
  481. if (!netif_queue_stopped(netdev)) {
  482. netif_stop_queue(netdev);
  483. barrier();
  484. wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
  485. (nesnic->sq_size - 1);
  486. if (wqes_needed <= wqes_available) {
  487. netif_start_queue(netdev);
  488. goto tso_sq_no_longer_full;
  489. }
  490. }
  491. nesvnic->sq_full++;
  492. nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
  493. netdev->name);
  494. return NETDEV_TX_BUSY;
  495. }
  496. tso_sq_no_longer_full:
  497. /* Map all the buffers */
  498. for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
  499. tso_frag_count++) {
  500. skb_frag_t *frag =
  501. &skb_shinfo(skb)->frags[tso_frag_count];
  502. tso_bus_address[tso_frag_count] =
  503. skb_frag_dma_map(&nesdev->pcidev->dev,
  504. frag, 0, skb_frag_size(frag),
  505. DMA_TO_DEVICE);
  506. }
  507. tso_frag_index = 0;
  508. curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
  509. hoffset = skb_transport_header(skb) - skb->data;
  510. nhoffset = skb_network_header(skb) - skb->data;
  511. original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
  512. for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
  513. tso_wqe_length = 0;
  514. nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
  515. wqe_fragment_length =
  516. (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
  517. /* setup the VLAN tag if present */
  518. if (vlan_tx_tag_present(skb)) {
  519. nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
  520. netdev->name, vlan_tx_tag_get(skb) );
  521. wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
  522. wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
  523. } else
  524. wqe_misc = 0;
  525. /* bump past the vlan tag */
  526. wqe_fragment_length++;
  527. /* Assumes header totally fits in allocated buffer and is in first fragment */
  528. if (original_first_length > NES_FIRST_FRAG_SIZE) {
  529. nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
  530. original_first_length, NES_FIRST_FRAG_SIZE);
  531. nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
  532. " (%u frags), tso_size=%u\n",
  533. netdev->name,
  534. skb->len, skb_headlen(skb),
  535. skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
  536. }
  537. memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
  538. skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
  539. original_first_length));
  540. iph = (struct iphdr *)
  541. (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
  542. tcph = (struct tcphdr *)
  543. (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
  544. if ((wqe_count+1)!=(u32)wqes_needed) {
  545. tcph->fin = 0;
  546. tcph->psh = 0;
  547. tcph->rst = 0;
  548. tcph->urg = 0;
  549. }
  550. if (wqe_count) {
  551. tcph->syn = 0;
  552. }
  553. tcph->seq = htonl(curr_tcp_seq);
  554. wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
  555. original_first_length));
  556. wqe_fragment_index = 1;
  557. if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
  558. set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
  559. bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
  560. skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
  561. wqe_fragment_length[wqe_fragment_index++] =
  562. cpu_to_le16(skb_headlen(skb) - original_first_length);
  563. wqe_fragment_length[wqe_fragment_index] = 0;
  564. set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
  565. bus_address);
  566. tso_wqe_length += skb_headlen(skb) -
  567. original_first_length;
  568. }
  569. while (wqe_fragment_index < 5) {
  570. wqe_fragment_length[wqe_fragment_index] =
  571. cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index]));
  572. set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
  573. (u64)tso_bus_address[tso_frag_index]);
  574. wqe_fragment_index++;
  575. tso_wqe_length += skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index++]);
  576. if (wqe_fragment_index < 5)
  577. wqe_fragment_length[wqe_fragment_index] = 0;
  578. if (tso_frag_index == tso_frag_count)
  579. break;
  580. }
  581. if ((wqe_count+1) == (u32)wqes_needed) {
  582. nesnic->tx_skb[nesnic->sq_head] = skb;
  583. } else {
  584. nesnic->tx_skb[nesnic->sq_head] = NULL;
  585. }
  586. wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
  587. if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
  588. wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
  589. } else {
  590. iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
  591. }
  592. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
  593. wqe_misc);
  594. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
  595. ((u32)tcph->doff) | (((u32)hoffset) << 4));
  596. set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
  597. tso_wqe_length + original_first_length);
  598. curr_tcp_seq += tso_wqe_length;
  599. nesnic->sq_head++;
  600. nesnic->sq_head &= nesnic->sq_size-1;
  601. }
  602. } else {
  603. nesvnic->linearized_skbs++;
  604. hoffset = skb_transport_header(skb) - skb->data;
  605. nhoffset = skb_network_header(skb) - skb->data;
  606. skb_linearize(skb);
  607. skb_set_transport_header(skb, hoffset);
  608. skb_set_network_header(skb, nhoffset);
  609. send_rc = nes_nic_send(skb, netdev);
  610. if (send_rc != NETDEV_TX_OK)
  611. return NETDEV_TX_OK;
  612. }
  613. } else {
  614. send_rc = nes_nic_send(skb, netdev);
  615. if (send_rc != NETDEV_TX_OK)
  616. return NETDEV_TX_OK;
  617. }
  618. barrier();
  619. if (wqe_count)
  620. nes_write32(nesdev->regs+NES_WQE_ALLOC,
  621. (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
  622. netdev->trans_start = jiffies;
  623. return NETDEV_TX_OK;
  624. }
  625. /**
  626. * nes_netdev_get_stats
  627. */
  628. static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
  629. {
  630. struct nes_vnic *nesvnic = netdev_priv(netdev);
  631. struct nes_device *nesdev = nesvnic->nesdev;
  632. u64 u64temp;
  633. u32 u32temp;
  634. u32temp = nes_read_indexed(nesdev,
  635. NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
  636. nesvnic->netstats.rx_dropped += u32temp;
  637. nesvnic->endnode_nstat_rx_discard += u32temp;
  638. u64temp = (u64)nes_read_indexed(nesdev,
  639. NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200));
  640. u64temp += ((u64)nes_read_indexed(nesdev,
  641. NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
  642. nesvnic->endnode_nstat_rx_octets += u64temp;
  643. nesvnic->netstats.rx_bytes += u64temp;
  644. u64temp = (u64)nes_read_indexed(nesdev,
  645. NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200));
  646. u64temp += ((u64)nes_read_indexed(nesdev,
  647. NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
  648. nesvnic->endnode_nstat_rx_frames += u64temp;
  649. nesvnic->netstats.rx_packets += u64temp;
  650. u64temp = (u64)nes_read_indexed(nesdev,
  651. NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200));
  652. u64temp += ((u64)nes_read_indexed(nesdev,
  653. NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
  654. nesvnic->endnode_nstat_tx_octets += u64temp;
  655. nesvnic->netstats.tx_bytes += u64temp;
  656. u64temp = (u64)nes_read_indexed(nesdev,
  657. NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200));
  658. u64temp += ((u64)nes_read_indexed(nesdev,
  659. NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
  660. nesvnic->endnode_nstat_tx_frames += u64temp;
  661. nesvnic->netstats.tx_packets += u64temp;
  662. u32temp = nes_read_indexed(nesdev,
  663. NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  664. nesvnic->netstats.rx_dropped += u32temp;
  665. nesvnic->nesdev->mac_rx_errors += u32temp;
  666. nesvnic->nesdev->mac_rx_short_frames += u32temp;
  667. u32temp = nes_read_indexed(nesdev,
  668. NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  669. nesvnic->netstats.rx_dropped += u32temp;
  670. nesvnic->nesdev->mac_rx_errors += u32temp;
  671. nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
  672. u32temp = nes_read_indexed(nesdev,
  673. NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  674. nesvnic->netstats.rx_dropped += u32temp;
  675. nesvnic->nesdev->mac_rx_errors += u32temp;
  676. nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
  677. u32temp = nes_read_indexed(nesdev,
  678. NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  679. nesvnic->netstats.rx_dropped += u32temp;
  680. nesvnic->nesdev->mac_rx_errors += u32temp;
  681. nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
  682. u32temp = nes_read_indexed(nesdev,
  683. NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  684. nesvnic->netstats.rx_length_errors += u32temp;
  685. nesvnic->nesdev->mac_rx_errors += u32temp;
  686. u32temp = nes_read_indexed(nesdev,
  687. NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  688. nesvnic->nesdev->mac_rx_errors += u32temp;
  689. nesvnic->nesdev->mac_rx_crc_errors += u32temp;
  690. nesvnic->netstats.rx_crc_errors += u32temp;
  691. u32temp = nes_read_indexed(nesdev,
  692. NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
  693. nesvnic->nesdev->mac_tx_errors += u32temp;
  694. nesvnic->netstats.tx_errors += u32temp;
  695. return &nesvnic->netstats;
  696. }
  697. /**
  698. * nes_netdev_tx_timeout
  699. */
  700. static void nes_netdev_tx_timeout(struct net_device *netdev)
  701. {
  702. struct nes_vnic *nesvnic = netdev_priv(netdev);
  703. if (netif_msg_timer(nesvnic))
  704. nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
  705. }
  706. /**
  707. * nes_netdev_set_mac_address
  708. */
  709. static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
  710. {
  711. struct nes_vnic *nesvnic = netdev_priv(netdev);
  712. struct nes_device *nesdev = nesvnic->nesdev;
  713. struct sockaddr *mac_addr = p;
  714. int i;
  715. u32 macaddr_low;
  716. u16 macaddr_high;
  717. if (!is_valid_ether_addr(mac_addr->sa_data))
  718. return -EADDRNOTAVAIL;
  719. memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
  720. printk(PFX "%s: Address length = %d, Address = %pM\n",
  721. __func__, netdev->addr_len, mac_addr->sa_data);
  722. macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
  723. macaddr_high += (u16)netdev->dev_addr[1];
  724. macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
  725. macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
  726. macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
  727. macaddr_low += (u32)netdev->dev_addr[5];
  728. for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
  729. if (nesvnic->qp_nic_index[i] == 0xf) {
  730. break;
  731. }
  732. nes_write_indexed(nesdev,
  733. NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
  734. macaddr_low);
  735. nes_write_indexed(nesdev,
  736. NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
  737. (u32)macaddr_high | NES_MAC_ADDR_VALID |
  738. ((((u32)nesvnic->nic_index) << 16)));
  739. }
  740. return 0;
  741. }
  742. static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit)
  743. {
  744. u32 nic_active;
  745. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
  746. nic_active |= nic_active_bit;
  747. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
  748. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
  749. nic_active &= ~nic_active_bit;
  750. nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
  751. }
  752. #define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN)
  753. /**
  754. * nes_netdev_set_multicast_list
  755. */
  756. static void nes_netdev_set_multicast_list(struct net_device *netdev)
  757. {
  758. struct nes_vnic *nesvnic = netdev_priv(netdev);
  759. struct nes_device *nesdev = nesvnic->nesdev;
  760. struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
  761. u32 nic_active_bit;
  762. u32 nic_active;
  763. u32 perfect_filter_register_address;
  764. u32 macaddr_low;
  765. u16 macaddr_high;
  766. u8 mc_all_on = 0;
  767. u8 mc_index;
  768. int mc_nic_index = -1;
  769. u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count *
  770. nics_per_function, 4);
  771. u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated;
  772. unsigned long flags;
  773. int mc_count = netdev_mc_count(netdev);
  774. spin_lock_irqsave(&nesadapter->resource_lock, flags);
  775. nic_active_bit = 1 << nesvnic->nic_index;
  776. if (netdev->flags & IFF_PROMISC) {
  777. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
  778. nic_active |= nic_active_bit;
  779. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
  780. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
  781. nic_active |= nic_active_bit;
  782. nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
  783. mc_all_on = 1;
  784. } else if ((netdev->flags & IFF_ALLMULTI) ||
  785. (nesvnic->nic_index > 3)) {
  786. set_allmulti(nesdev, nic_active_bit);
  787. mc_all_on = 1;
  788. } else {
  789. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
  790. nic_active &= ~nic_active_bit;
  791. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
  792. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
  793. nic_active &= ~nic_active_bit;
  794. nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
  795. }
  796. nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscuous = %d, All Multicast = %d.\n",
  797. mc_count, !!(netdev->flags & IFF_PROMISC),
  798. !!(netdev->flags & IFF_ALLMULTI));
  799. if (!mc_all_on) {
  800. char *addrs;
  801. int i;
  802. struct netdev_hw_addr *ha;
  803. addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC);
  804. if (!addrs) {
  805. set_allmulti(nesdev, nic_active_bit);
  806. goto unlock;
  807. }
  808. i = 0;
  809. netdev_for_each_mc_addr(ha, netdev)
  810. memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN);
  811. perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW +
  812. pft_entries_preallocated * 0x8;
  813. for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable;
  814. mc_index++) {
  815. while (i < mc_count && nesvnic->mcrq_mcast_filter &&
  816. ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic,
  817. get_addr(addrs, i++))) == 0));
  818. if (mc_nic_index < 0)
  819. mc_nic_index = nesvnic->nic_index;
  820. while (nesadapter->pft_mcast_map[mc_index] < 16 &&
  821. nesadapter->pft_mcast_map[mc_index] !=
  822. nesvnic->nic_index &&
  823. mc_index < max_pft_entries_avaiable) {
  824. nes_debug(NES_DBG_NIC_RX,
  825. "mc_index=%d skipping nic_index=%d, "
  826. "used for=%d \n", mc_index,
  827. nesvnic->nic_index,
  828. nesadapter->pft_mcast_map[mc_index]);
  829. mc_index++;
  830. }
  831. if (mc_index >= max_pft_entries_avaiable)
  832. break;
  833. if (i < mc_count) {
  834. char *addr = get_addr(addrs, i++);
  835. nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n",
  836. addr,
  837. perfect_filter_register_address+(mc_index * 8),
  838. mc_nic_index);
  839. macaddr_high = ((u16) addr[0]) << 8;
  840. macaddr_high += (u16) addr[1];
  841. macaddr_low = ((u32) addr[2]) << 24;
  842. macaddr_low += ((u32) addr[3]) << 16;
  843. macaddr_low += ((u32) addr[4]) << 8;
  844. macaddr_low += (u32) addr[5];
  845. nes_write_indexed(nesdev,
  846. perfect_filter_register_address+(mc_index * 8),
  847. macaddr_low);
  848. nes_write_indexed(nesdev,
  849. perfect_filter_register_address+4+(mc_index * 8),
  850. (u32)macaddr_high | NES_MAC_ADDR_VALID |
  851. ((((u32)(1<<mc_nic_index)) << 16)));
  852. nesadapter->pft_mcast_map[mc_index] =
  853. nesvnic->nic_index;
  854. } else {
  855. nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
  856. perfect_filter_register_address+(mc_index * 8));
  857. nes_write_indexed(nesdev,
  858. perfect_filter_register_address+4+(mc_index * 8),
  859. 0);
  860. nesadapter->pft_mcast_map[mc_index] = 255;
  861. }
  862. }
  863. kfree(addrs);
  864. /* PFT is not large enough */
  865. if (i < mc_count)
  866. set_allmulti(nesdev, nic_active_bit);
  867. }
  868. unlock:
  869. spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
  870. }
  871. /**
  872. * nes_netdev_change_mtu
  873. */
  874. static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
  875. {
  876. struct nes_vnic *nesvnic = netdev_priv(netdev);
  877. struct nes_device *nesdev = nesvnic->nesdev;
  878. int ret = 0;
  879. u8 jumbomode = 0;
  880. u32 nic_active;
  881. u32 nic_active_bit;
  882. u32 uc_all_active;
  883. u32 mc_all_active;
  884. if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
  885. return -EINVAL;
  886. netdev->mtu = new_mtu;
  887. nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN;
  888. if (netdev->mtu > 1500) {
  889. jumbomode=1;
  890. }
  891. nes_nic_init_timer_defaults(nesdev, jumbomode);
  892. if (netif_running(netdev)) {
  893. nic_active_bit = 1 << nesvnic->nic_index;
  894. mc_all_active = nes_read_indexed(nesdev,
  895. NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit;
  896. uc_all_active = nes_read_indexed(nesdev,
  897. NES_IDX_NIC_UNICAST_ALL) & nic_active_bit;
  898. nes_netdev_stop(netdev);
  899. nes_netdev_open(netdev);
  900. nic_active = nes_read_indexed(nesdev,
  901. NES_IDX_NIC_MULTICAST_ALL);
  902. nic_active |= mc_all_active;
  903. nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL,
  904. nic_active);
  905. nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
  906. nic_active |= uc_all_active;
  907. nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
  908. }
  909. return ret;
  910. }
  911. static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
  912. "Link Change Interrupts",
  913. "Linearized SKBs",
  914. "T/GSO Requests",
  915. "Pause Frames Sent",
  916. "Pause Frames Received",
  917. "Internal Routing Errors",
  918. "SQ SW Dropped SKBs",
  919. "SQ Full",
  920. "Segmented TSO Requests",
  921. "Rx Symbol Errors",
  922. "Rx Jabber Errors",
  923. "Rx Oversized Frames",
  924. "Rx Short Frames",
  925. "Rx Length Errors",
  926. "Rx CRC Errors",
  927. "Rx Port Discard",
  928. "Endnode Rx Discards",
  929. "Endnode Rx Octets",
  930. "Endnode Rx Frames",
  931. "Endnode Tx Octets",
  932. "Endnode Tx Frames",
  933. "Tx Errors",
  934. "mh detected",
  935. "mh pauses",
  936. "Retransmission Count",
  937. "CM Connects",
  938. "CM Accepts",
  939. "Disconnects",
  940. "Connected Events",
  941. "Connect Requests",
  942. "CM Rejects",
  943. "ModifyQP Timeouts",
  944. "CreateQPs",
  945. "SW DestroyQPs",
  946. "DestroyQPs",
  947. "CM Closes",
  948. "CM Packets Sent",
  949. "CM Packets Bounced",
  950. "CM Packets Created",
  951. "CM Packets Rcvd",
  952. "CM Packets Dropped",
  953. "CM Packets Retrans",
  954. "CM Listens Created",
  955. "CM Listens Destroyed",
  956. "CM Backlog Drops",
  957. "CM Loopbacks",
  958. "CM Nodes Created",
  959. "CM Nodes Destroyed",
  960. "CM Accel Drops",
  961. "CM Resets Received",
  962. "Free 4Kpbls",
  963. "Free 256pbls",
  964. "Timer Inits",
  965. "LRO aggregated",
  966. "LRO flushed",
  967. "LRO no_desc",
  968. "PAU CreateQPs",
  969. "PAU DestroyQPs",
  970. };
  971. #define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset)
  972. /**
  973. * nes_netdev_get_sset_count
  974. */
  975. static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset)
  976. {
  977. if (stringset == ETH_SS_STATS)
  978. return NES_ETHTOOL_STAT_COUNT;
  979. else
  980. return -EINVAL;
  981. }
  982. /**
  983. * nes_netdev_get_strings
  984. */
  985. static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
  986. u8 *ethtool_strings)
  987. {
  988. if (stringset == ETH_SS_STATS)
  989. memcpy(ethtool_strings,
  990. &nes_ethtool_stringset,
  991. sizeof(nes_ethtool_stringset));
  992. }
  993. /**
  994. * nes_netdev_get_ethtool_stats
  995. */
  996. static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
  997. struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
  998. {
  999. u64 u64temp;
  1000. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1001. struct nes_device *nesdev = nesvnic->nesdev;
  1002. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1003. u32 nic_count;
  1004. u32 u32temp;
  1005. u32 index = 0;
  1006. target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
  1007. target_stat_values[index] = nesvnic->nesdev->link_status_interrupts;
  1008. target_stat_values[++index] = nesvnic->linearized_skbs;
  1009. target_stat_values[++index] = nesvnic->tso_requests;
  1010. u32temp = nes_read_indexed(nesdev,
  1011. NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1012. nesvnic->nesdev->mac_pause_frames_sent += u32temp;
  1013. target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent;
  1014. u32temp = nes_read_indexed(nesdev,
  1015. NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1016. nesvnic->nesdev->mac_pause_frames_received += u32temp;
  1017. u32temp = nes_read_indexed(nesdev,
  1018. NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
  1019. nesvnic->nesdev->port_rx_discards += u32temp;
  1020. nesvnic->netstats.rx_dropped += u32temp;
  1021. u32temp = nes_read_indexed(nesdev,
  1022. NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
  1023. nesvnic->nesdev->port_tx_discards += u32temp;
  1024. nesvnic->netstats.tx_dropped += u32temp;
  1025. u32temp = nes_read_indexed(nesdev,
  1026. NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1027. nesvnic->netstats.rx_dropped += u32temp;
  1028. nesvnic->nesdev->mac_rx_errors += u32temp;
  1029. nesvnic->nesdev->mac_rx_short_frames += u32temp;
  1030. u32temp = nes_read_indexed(nesdev,
  1031. NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1032. nesvnic->netstats.rx_dropped += u32temp;
  1033. nesvnic->nesdev->mac_rx_errors += u32temp;
  1034. nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
  1035. u32temp = nes_read_indexed(nesdev,
  1036. NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1037. nesvnic->netstats.rx_dropped += u32temp;
  1038. nesvnic->nesdev->mac_rx_errors += u32temp;
  1039. nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
  1040. u32temp = nes_read_indexed(nesdev,
  1041. NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1042. nesvnic->netstats.rx_dropped += u32temp;
  1043. nesvnic->nesdev->mac_rx_errors += u32temp;
  1044. nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
  1045. u32temp = nes_read_indexed(nesdev,
  1046. NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1047. nesvnic->netstats.rx_length_errors += u32temp;
  1048. nesvnic->nesdev->mac_rx_errors += u32temp;
  1049. u32temp = nes_read_indexed(nesdev,
  1050. NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
  1051. nesvnic->nesdev->mac_rx_errors += u32temp;
  1052. nesvnic->nesdev->mac_rx_crc_errors += u32temp;
  1053. nesvnic->netstats.rx_crc_errors += u32temp;
  1054. u32temp = nes_read_indexed(nesdev,
  1055. NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
  1056. nesvnic->nesdev->mac_tx_errors += u32temp;
  1057. nesvnic->netstats.tx_errors += u32temp;
  1058. for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
  1059. if (nesvnic->qp_nic_index[nic_count] == 0xf)
  1060. break;
  1061. u32temp = nes_read_indexed(nesdev,
  1062. NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
  1063. (nesvnic->qp_nic_index[nic_count]*0x200));
  1064. nesvnic->netstats.rx_dropped += u32temp;
  1065. nesvnic->endnode_nstat_rx_discard += u32temp;
  1066. u64temp = (u64)nes_read_indexed(nesdev,
  1067. NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
  1068. (nesvnic->qp_nic_index[nic_count]*0x200));
  1069. u64temp += ((u64)nes_read_indexed(nesdev,
  1070. NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
  1071. (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
  1072. nesvnic->endnode_nstat_rx_octets += u64temp;
  1073. nesvnic->netstats.rx_bytes += u64temp;
  1074. u64temp = (u64)nes_read_indexed(nesdev,
  1075. NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
  1076. (nesvnic->qp_nic_index[nic_count]*0x200));
  1077. u64temp += ((u64)nes_read_indexed(nesdev,
  1078. NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
  1079. (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
  1080. nesvnic->endnode_nstat_rx_frames += u64temp;
  1081. nesvnic->netstats.rx_packets += u64temp;
  1082. u64temp = (u64)nes_read_indexed(nesdev,
  1083. NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
  1084. (nesvnic->qp_nic_index[nic_count]*0x200));
  1085. u64temp += ((u64)nes_read_indexed(nesdev,
  1086. NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
  1087. (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
  1088. nesvnic->endnode_nstat_tx_octets += u64temp;
  1089. nesvnic->netstats.tx_bytes += u64temp;
  1090. u64temp = (u64)nes_read_indexed(nesdev,
  1091. NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
  1092. (nesvnic->qp_nic_index[nic_count]*0x200));
  1093. u64temp += ((u64)nes_read_indexed(nesdev,
  1094. NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
  1095. (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
  1096. nesvnic->endnode_nstat_tx_frames += u64temp;
  1097. nesvnic->netstats.tx_packets += u64temp;
  1098. u32temp = nes_read_indexed(nesdev,
  1099. NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
  1100. nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
  1101. }
  1102. target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received;
  1103. target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err;
  1104. target_stat_values[++index] = nesvnic->tx_sw_dropped;
  1105. target_stat_values[++index] = nesvnic->sq_full;
  1106. target_stat_values[++index] = nesvnic->segmented_tso_requests;
  1107. target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames;
  1108. target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames;
  1109. target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames;
  1110. target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames;
  1111. target_stat_values[++index] = nesvnic->netstats.rx_length_errors;
  1112. target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors;
  1113. target_stat_values[++index] = nesvnic->nesdev->port_rx_discards;
  1114. target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard;
  1115. target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets;
  1116. target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames;
  1117. target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets;
  1118. target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames;
  1119. target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors;
  1120. target_stat_values[++index] = mh_detected;
  1121. target_stat_values[++index] = mh_pauses_sent;
  1122. target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
  1123. target_stat_values[++index] = atomic_read(&cm_connects);
  1124. target_stat_values[++index] = atomic_read(&cm_accepts);
  1125. target_stat_values[++index] = atomic_read(&cm_disconnects);
  1126. target_stat_values[++index] = atomic_read(&cm_connecteds);
  1127. target_stat_values[++index] = atomic_read(&cm_connect_reqs);
  1128. target_stat_values[++index] = atomic_read(&cm_rejects);
  1129. target_stat_values[++index] = atomic_read(&mod_qp_timouts);
  1130. target_stat_values[++index] = atomic_read(&qps_created);
  1131. target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
  1132. target_stat_values[++index] = atomic_read(&qps_destroyed);
  1133. target_stat_values[++index] = atomic_read(&cm_closes);
  1134. target_stat_values[++index] = cm_packets_sent;
  1135. target_stat_values[++index] = cm_packets_bounced;
  1136. target_stat_values[++index] = cm_packets_created;
  1137. target_stat_values[++index] = cm_packets_received;
  1138. target_stat_values[++index] = cm_packets_dropped;
  1139. target_stat_values[++index] = cm_packets_retrans;
  1140. target_stat_values[++index] = atomic_read(&cm_listens_created);
  1141. target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
  1142. target_stat_values[++index] = cm_backlog_drops;
  1143. target_stat_values[++index] = atomic_read(&cm_loopbacks);
  1144. target_stat_values[++index] = atomic_read(&cm_nodes_created);
  1145. target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
  1146. target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
  1147. target_stat_values[++index] = atomic_read(&cm_resets_recvd);
  1148. target_stat_values[++index] = nesadapter->free_4kpbl;
  1149. target_stat_values[++index] = nesadapter->free_256pbl;
  1150. target_stat_values[++index] = int_mod_timer_init;
  1151. target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
  1152. target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
  1153. target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
  1154. target_stat_values[++index] = atomic_read(&pau_qps_created);
  1155. target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
  1156. }
  1157. /**
  1158. * nes_netdev_get_drvinfo
  1159. */
  1160. static void nes_netdev_get_drvinfo(struct net_device *netdev,
  1161. struct ethtool_drvinfo *drvinfo)
  1162. {
  1163. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1164. struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
  1165. strcpy(drvinfo->driver, DRV_NAME);
  1166. strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
  1167. sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16,
  1168. nesadapter->firmware_version & 0x000000ff);
  1169. strcpy(drvinfo->version, DRV_VERSION);
  1170. drvinfo->testinfo_len = 0;
  1171. drvinfo->eedump_len = 0;
  1172. drvinfo->regdump_len = 0;
  1173. }
  1174. /**
  1175. * nes_netdev_set_coalesce
  1176. */
  1177. static int nes_netdev_set_coalesce(struct net_device *netdev,
  1178. struct ethtool_coalesce *et_coalesce)
  1179. {
  1180. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1181. struct nes_device *nesdev = nesvnic->nesdev;
  1182. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1183. struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
  1184. unsigned long flags;
  1185. spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
  1186. if (et_coalesce->rx_max_coalesced_frames_low) {
  1187. shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
  1188. }
  1189. if (et_coalesce->rx_max_coalesced_frames_irq) {
  1190. shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
  1191. }
  1192. if (et_coalesce->rx_max_coalesced_frames_high) {
  1193. shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
  1194. }
  1195. if (et_coalesce->rx_coalesce_usecs_low) {
  1196. shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
  1197. }
  1198. if (et_coalesce->rx_coalesce_usecs_high) {
  1199. shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
  1200. }
  1201. spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
  1202. /* using this to drive total interrupt moderation */
  1203. nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
  1204. if (et_coalesce->use_adaptive_rx_coalesce) {
  1205. nesadapter->et_use_adaptive_rx_coalesce = 1;
  1206. nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
  1207. nesadapter->et_rx_coalesce_usecs_irq = 0;
  1208. if (et_coalesce->pkt_rate_low) {
  1209. nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
  1210. }
  1211. } else {
  1212. nesadapter->et_use_adaptive_rx_coalesce = 0;
  1213. nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
  1214. if (nesadapter->et_rx_coalesce_usecs_irq) {
  1215. nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
  1216. 0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
  1217. }
  1218. }
  1219. return 0;
  1220. }
  1221. /**
  1222. * nes_netdev_get_coalesce
  1223. */
  1224. static int nes_netdev_get_coalesce(struct net_device *netdev,
  1225. struct ethtool_coalesce *et_coalesce)
  1226. {
  1227. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1228. struct nes_device *nesdev = nesvnic->nesdev;
  1229. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1230. struct ethtool_coalesce temp_et_coalesce;
  1231. struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
  1232. unsigned long flags;
  1233. memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
  1234. temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
  1235. temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce;
  1236. temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
  1237. temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
  1238. spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
  1239. temp_et_coalesce.rx_max_coalesced_frames_low = shared_timer->threshold_low;
  1240. temp_et_coalesce.rx_max_coalesced_frames_irq = shared_timer->threshold_target;
  1241. temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
  1242. temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
  1243. temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
  1244. if (nesadapter->et_use_adaptive_rx_coalesce) {
  1245. temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
  1246. }
  1247. spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
  1248. memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
  1249. return 0;
  1250. }
  1251. /**
  1252. * nes_netdev_get_pauseparam
  1253. */
  1254. static void nes_netdev_get_pauseparam(struct net_device *netdev,
  1255. struct ethtool_pauseparam *et_pauseparam)
  1256. {
  1257. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1258. et_pauseparam->autoneg = 0;
  1259. et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
  1260. et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
  1261. }
  1262. /**
  1263. * nes_netdev_set_pauseparam
  1264. */
  1265. static int nes_netdev_set_pauseparam(struct net_device *netdev,
  1266. struct ethtool_pauseparam *et_pauseparam)
  1267. {
  1268. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1269. struct nes_device *nesdev = nesvnic->nesdev;
  1270. u32 u32temp;
  1271. if (et_pauseparam->autoneg) {
  1272. /* TODO: should return unsupported */
  1273. return 0;
  1274. }
  1275. if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
  1276. u32temp = nes_read_indexed(nesdev,
  1277. NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
  1278. u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
  1279. nes_write_indexed(nesdev,
  1280. NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
  1281. nesdev->disable_tx_flow_control = 0;
  1282. } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
  1283. u32temp = nes_read_indexed(nesdev,
  1284. NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
  1285. u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
  1286. nes_write_indexed(nesdev,
  1287. NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
  1288. nesdev->disable_tx_flow_control = 1;
  1289. }
  1290. if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
  1291. u32temp = nes_read_indexed(nesdev,
  1292. NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
  1293. u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
  1294. nes_write_indexed(nesdev,
  1295. NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
  1296. nesdev->disable_rx_flow_control = 0;
  1297. } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
  1298. u32temp = nes_read_indexed(nesdev,
  1299. NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
  1300. u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
  1301. nes_write_indexed(nesdev,
  1302. NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
  1303. nesdev->disable_rx_flow_control = 1;
  1304. }
  1305. return 0;
  1306. }
  1307. /**
  1308. * nes_netdev_get_settings
  1309. */
  1310. static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
  1311. {
  1312. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1313. struct nes_device *nesdev = nesvnic->nesdev;
  1314. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1315. u32 mac_index = nesdev->mac_index;
  1316. u8 phy_type = nesadapter->phy_type[mac_index];
  1317. u8 phy_index = nesadapter->phy_index[mac_index];
  1318. u16 phy_data;
  1319. et_cmd->duplex = DUPLEX_FULL;
  1320. et_cmd->port = PORT_MII;
  1321. et_cmd->maxtxpkt = 511;
  1322. et_cmd->maxrxpkt = 511;
  1323. if (nesadapter->OneG_Mode) {
  1324. ethtool_cmd_speed_set(et_cmd, SPEED_1000);
  1325. if (phy_type == NES_PHY_TYPE_PUMA_1G) {
  1326. et_cmd->supported = SUPPORTED_1000baseT_Full;
  1327. et_cmd->advertising = ADVERTISED_1000baseT_Full;
  1328. et_cmd->autoneg = AUTONEG_DISABLE;
  1329. et_cmd->transceiver = XCVR_INTERNAL;
  1330. et_cmd->phy_address = mac_index;
  1331. } else {
  1332. unsigned long flags;
  1333. et_cmd->supported = SUPPORTED_1000baseT_Full
  1334. | SUPPORTED_Autoneg;
  1335. et_cmd->advertising = ADVERTISED_1000baseT_Full
  1336. | ADVERTISED_Autoneg;
  1337. spin_lock_irqsave(&nesadapter->phy_lock, flags);
  1338. nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
  1339. spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
  1340. if (phy_data & 0x1000)
  1341. et_cmd->autoneg = AUTONEG_ENABLE;
  1342. else
  1343. et_cmd->autoneg = AUTONEG_DISABLE;
  1344. et_cmd->transceiver = XCVR_EXTERNAL;
  1345. et_cmd->phy_address = phy_index;
  1346. }
  1347. return 0;
  1348. }
  1349. if ((phy_type == NES_PHY_TYPE_ARGUS) ||
  1350. (phy_type == NES_PHY_TYPE_SFP_D) ||
  1351. (phy_type == NES_PHY_TYPE_KR)) {
  1352. et_cmd->transceiver = XCVR_EXTERNAL;
  1353. et_cmd->port = PORT_FIBRE;
  1354. et_cmd->supported = SUPPORTED_FIBRE;
  1355. et_cmd->advertising = ADVERTISED_FIBRE;
  1356. et_cmd->phy_address = phy_index;
  1357. } else {
  1358. et_cmd->transceiver = XCVR_INTERNAL;
  1359. et_cmd->supported = SUPPORTED_10000baseT_Full;
  1360. et_cmd->advertising = ADVERTISED_10000baseT_Full;
  1361. et_cmd->phy_address = mac_index;
  1362. }
  1363. ethtool_cmd_speed_set(et_cmd, SPEED_10000);
  1364. et_cmd->autoneg = AUTONEG_DISABLE;
  1365. return 0;
  1366. }
  1367. /**
  1368. * nes_netdev_set_settings
  1369. */
  1370. static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
  1371. {
  1372. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1373. struct nes_device *nesdev = nesvnic->nesdev;
  1374. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1375. if ((nesadapter->OneG_Mode) &&
  1376. (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
  1377. unsigned long flags;
  1378. u16 phy_data;
  1379. u8 phy_index = nesadapter->phy_index[nesdev->mac_index];
  1380. spin_lock_irqsave(&nesadapter->phy_lock, flags);
  1381. nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
  1382. if (et_cmd->autoneg) {
  1383. /* Turn on Full duplex, Autoneg, and restart autonegotiation */
  1384. phy_data |= 0x1300;
  1385. } else {
  1386. /* Turn off autoneg */
  1387. phy_data &= ~0x1000;
  1388. }
  1389. nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data);
  1390. spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
  1391. }
  1392. return 0;
  1393. }
  1394. static const struct ethtool_ops nes_ethtool_ops = {
  1395. .get_link = ethtool_op_get_link,
  1396. .get_settings = nes_netdev_get_settings,
  1397. .set_settings = nes_netdev_set_settings,
  1398. .get_strings = nes_netdev_get_strings,
  1399. .get_sset_count = nes_netdev_get_sset_count,
  1400. .get_ethtool_stats = nes_netdev_get_ethtool_stats,
  1401. .get_drvinfo = nes_netdev_get_drvinfo,
  1402. .get_coalesce = nes_netdev_get_coalesce,
  1403. .set_coalesce = nes_netdev_set_coalesce,
  1404. .get_pauseparam = nes_netdev_get_pauseparam,
  1405. .set_pauseparam = nes_netdev_set_pauseparam,
  1406. };
  1407. static void nes_vlan_mode(struct net_device *netdev, struct nes_device *nesdev, netdev_features_t features)
  1408. {
  1409. struct nes_adapter *nesadapter = nesdev->nesadapter;
  1410. u32 u32temp;
  1411. unsigned long flags;
  1412. spin_lock_irqsave(&nesadapter->phy_lock, flags);
  1413. nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name);
  1414. /* Enable/Disable VLAN Stripping */
  1415. u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
  1416. if (features & NETIF_F_HW_VLAN_RX)
  1417. u32temp &= 0xfdffffff;
  1418. else
  1419. u32temp |= 0x02000000;
  1420. nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
  1421. spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
  1422. }
  1423. static netdev_features_t nes_fix_features(struct net_device *netdev, netdev_features_t features)
  1424. {
  1425. /*
  1426. * Since there is no support for separate rx/tx vlan accel
  1427. * enable/disable make sure tx flag is always in same state as rx.
  1428. */
  1429. if (features & NETIF_F_HW_VLAN_RX)
  1430. features |= NETIF_F_HW_VLAN_TX;
  1431. else
  1432. features &= ~NETIF_F_HW_VLAN_TX;
  1433. return features;
  1434. }
  1435. static int nes_set_features(struct net_device *netdev, netdev_features_t features)
  1436. {
  1437. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1438. struct nes_device *nesdev = nesvnic->nesdev;
  1439. u32 changed = netdev->features ^ features;
  1440. if (changed & NETIF_F_HW_VLAN_RX)
  1441. nes_vlan_mode(netdev, nesdev, features);
  1442. return 0;
  1443. }
  1444. static const struct net_device_ops nes_netdev_ops = {
  1445. .ndo_open = nes_netdev_open,
  1446. .ndo_stop = nes_netdev_stop,
  1447. .ndo_start_xmit = nes_netdev_start_xmit,
  1448. .ndo_get_stats = nes_netdev_get_stats,
  1449. .ndo_tx_timeout = nes_netdev_tx_timeout,
  1450. .ndo_set_mac_address = nes_netdev_set_mac_address,
  1451. .ndo_set_rx_mode = nes_netdev_set_multicast_list,
  1452. .ndo_change_mtu = nes_netdev_change_mtu,
  1453. .ndo_validate_addr = eth_validate_addr,
  1454. .ndo_fix_features = nes_fix_features,
  1455. .ndo_set_features = nes_set_features,
  1456. };
  1457. /**
  1458. * nes_netdev_init - initialize network device
  1459. */
  1460. struct net_device *nes_netdev_init(struct nes_device *nesdev,
  1461. void __iomem *mmio_addr)
  1462. {
  1463. u64 u64temp;
  1464. struct nes_vnic *nesvnic;
  1465. struct net_device *netdev;
  1466. struct nic_qp_map *curr_qp_map;
  1467. u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index];
  1468. netdev = alloc_etherdev(sizeof(struct nes_vnic));
  1469. if (!netdev) {
  1470. printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
  1471. return NULL;
  1472. }
  1473. nesvnic = netdev_priv(netdev);
  1474. nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
  1475. SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
  1476. netdev->watchdog_timeo = NES_TX_TIMEOUT;
  1477. netdev->irq = nesdev->pcidev->irq;
  1478. netdev->mtu = ETH_DATA_LEN;
  1479. netdev->hard_header_len = ETH_HLEN;
  1480. netdev->addr_len = ETH_ALEN;
  1481. netdev->type = ARPHRD_ETHER;
  1482. netdev->features = NETIF_F_HIGHDMA;
  1483. netdev->netdev_ops = &nes_netdev_ops;
  1484. netdev->ethtool_ops = &nes_ethtool_ops;
  1485. netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
  1486. nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
  1487. netdev->features |= NETIF_F_HW_VLAN_TX;
  1488. /* Fill in the port structure */
  1489. nesvnic->netdev = netdev;
  1490. nesvnic->nesdev = nesdev;
  1491. nesvnic->msg_enable = netif_msg_init(debug, default_msg);
  1492. nesvnic->netdev_index = nesdev->netdev_count;
  1493. nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
  1494. nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
  1495. curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
  1496. nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
  1497. nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
  1498. nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
  1499. /* Setup the burned in MAC address */
  1500. u64temp = (u64)nesdev->nesadapter->mac_addr_low;
  1501. u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
  1502. u64temp += nesvnic->nic_index;
  1503. netdev->dev_addr[0] = (u8)(u64temp>>40);
  1504. netdev->dev_addr[1] = (u8)(u64temp>>32);
  1505. netdev->dev_addr[2] = (u8)(u64temp>>24);
  1506. netdev->dev_addr[3] = (u8)(u64temp>>16);
  1507. netdev->dev_addr[4] = (u8)(u64temp>>8);
  1508. netdev->dev_addr[5] = (u8)u64temp;
  1509. memcpy(netdev->perm_addr, netdev->dev_addr, 6);
  1510. netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_IP_CSUM |
  1511. NETIF_F_HW_VLAN_RX;
  1512. if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV))
  1513. netdev->hw_features |= NETIF_F_TSO;
  1514. netdev->features |= netdev->hw_features;
  1515. netdev->hw_features |= NETIF_F_LRO;
  1516. nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
  1517. " nic_index = %d, logical_port = %d, mac_index = %d.\n",
  1518. nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
  1519. nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index);
  1520. if (nesvnic->nesdev->nesadapter->port_count == 1 &&
  1521. nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) {
  1522. nesvnic->qp_nic_index[0] = nesvnic->nic_index;
  1523. nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
  1524. if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
  1525. nesvnic->qp_nic_index[2] = 0xf;
  1526. nesvnic->qp_nic_index[3] = 0xf;
  1527. } else {
  1528. nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
  1529. nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
  1530. }
  1531. } else {
  1532. if (nesvnic->nesdev->nesadapter->port_count == 2 ||
  1533. (nesvnic->nesdev->nesadapter->port_count == 1 &&
  1534. nesvnic->nesdev->nesadapter->adapter_fcn_count == 2)) {
  1535. nesvnic->qp_nic_index[0] = nesvnic->nic_index;
  1536. nesvnic->qp_nic_index[1] = nesvnic->nic_index
  1537. + 2;
  1538. nesvnic->qp_nic_index[2] = 0xf;
  1539. nesvnic->qp_nic_index[3] = 0xf;
  1540. } else {
  1541. nesvnic->qp_nic_index[0] = nesvnic->nic_index;
  1542. nesvnic->qp_nic_index[1] = 0xf;
  1543. nesvnic->qp_nic_index[2] = 0xf;
  1544. nesvnic->qp_nic_index[3] = 0xf;
  1545. }
  1546. }
  1547. nesvnic->next_qp_nic_index = 0;
  1548. if (nesdev->netdev_count == 0) {
  1549. nesvnic->rdma_enabled = 1;
  1550. } else {
  1551. nesvnic->rdma_enabled = 0;
  1552. }
  1553. nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
  1554. init_timer(&nesvnic->event_timer);
  1555. nesvnic->event_timer.function = NULL;
  1556. spin_lock_init(&nesvnic->tx_lock);
  1557. spin_lock_init(&nesvnic->port_ibevent_lock);
  1558. nesdev->netdev[nesdev->netdev_count] = netdev;
  1559. nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
  1560. nesvnic, nesdev->mac_index);
  1561. list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
  1562. if ((nesdev->netdev_count == 0) &&
  1563. ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) ||
  1564. ((phy_type == NES_PHY_TYPE_PUMA_1G) &&
  1565. (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) ||
  1566. ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) {
  1567. u32 u32temp;
  1568. u32 link_mask = 0;
  1569. u32 link_val = 0;
  1570. u16 temp_phy_data;
  1571. u16 phy_data = 0;
  1572. unsigned long flags;
  1573. u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
  1574. (0x200 * (nesdev->mac_index & 1)));
  1575. if (phy_type != NES_PHY_TYPE_PUMA_1G) {
  1576. u32temp |= 0x00200000;
  1577. nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
  1578. (0x200 * (nesdev->mac_index & 1)), u32temp);
  1579. }
  1580. /* Check and set linkup here. This is for back to back */
  1581. /* configuration where second port won't get link interrupt */
  1582. switch (phy_type) {
  1583. case NES_PHY_TYPE_PUMA_1G:
  1584. if (nesdev->mac_index < 2) {
  1585. link_mask = 0x01010000;
  1586. link_val = 0x01010000;
  1587. } else {
  1588. link_mask = 0x02020000;
  1589. link_val = 0x02020000;
  1590. }
  1591. break;
  1592. case NES_PHY_TYPE_SFP_D:
  1593. spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
  1594. nes_read_10G_phy_reg(nesdev,
  1595. nesdev->nesadapter->phy_index[nesdev->mac_index],
  1596. 1, 0x9003);
  1597. temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
  1598. nes_read_10G_phy_reg(nesdev,
  1599. nesdev->nesadapter->phy_index[nesdev->mac_index],
  1600. 3, 0x0021);
  1601. nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
  1602. nes_read_10G_phy_reg(nesdev,
  1603. nesdev->nesadapter->phy_index[nesdev->mac_index],
  1604. 3, 0x0021);
  1605. phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
  1606. spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
  1607. phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0;
  1608. break;
  1609. default:
  1610. link_mask = 0x0f1f0000;
  1611. link_val = 0x0f0f0000;
  1612. break;
  1613. }
  1614. u32temp = nes_read_indexed(nesdev,
  1615. NES_IDX_PHY_PCS_CONTROL_STATUS0 +
  1616. (0x200 * (nesdev->mac_index & 1)));
  1617. if (phy_type == NES_PHY_TYPE_SFP_D) {
  1618. if (phy_data & 0x0004)
  1619. nesvnic->linkup = 1;
  1620. } else {
  1621. if ((u32temp & link_mask) == link_val)
  1622. nesvnic->linkup = 1;
  1623. }
  1624. /* clear the MAC interrupt status, assumes direct logical to physical mapping */
  1625. u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
  1626. nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
  1627. nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
  1628. nes_init_phy(nesdev);
  1629. }
  1630. nes_vlan_mode(netdev, nesdev, netdev->features);
  1631. return netdev;
  1632. }
  1633. /**
  1634. * nes_netdev_destroy - destroy network device structure
  1635. */
  1636. void nes_netdev_destroy(struct net_device *netdev)
  1637. {
  1638. struct nes_vnic *nesvnic = netdev_priv(netdev);
  1639. /* make sure 'stop' method is called by Linux stack */
  1640. /* nes_netdev_stop(netdev); */
  1641. list_del(&nesvnic->list);
  1642. if (nesvnic->of_device_registered) {
  1643. nes_destroy_ofa_device(nesvnic->nesibdev);
  1644. }
  1645. free_netdev(netdev);
  1646. }
  1647. /**
  1648. * nes_nic_cm_xmit -- CM calls this to send out pkts
  1649. */
  1650. int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
  1651. {
  1652. int ret;
  1653. skb->dev = netdev;
  1654. ret = dev_queue_xmit(skb);
  1655. if (ret) {
  1656. nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
  1657. }
  1658. return ret;
  1659. }