enic_main.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/string.h>
  22. #include <linux/errno.h>
  23. #include <linux/types.h>
  24. #include <linux/init.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/pci.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/if_ether.h>
  30. #include <linux/if_vlan.h>
  31. #include <linux/if_link.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/in.h>
  34. #include <linux/ip.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/tcp.h>
  37. #include <net/ip6_checksum.h>
  38. #include "cq_enet_desc.h"
  39. #include "vnic_dev.h"
  40. #include "vnic_intr.h"
  41. #include "vnic_stats.h"
  42. #include "vnic_vic.h"
  43. #include "enic_res.h"
  44. #include "enic.h"
  45. #define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
  46. #define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS)
  47. #define MAX_TSO (1 << 16)
  48. #define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1)
  49. #define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */
  50. #define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */
  51. /* Supported devices */
  52. static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = {
  53. { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) },
  54. { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) },
  55. { 0, } /* end of table */
  56. };
  57. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  58. MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
  59. MODULE_LICENSE("GPL");
  60. MODULE_VERSION(DRV_VERSION);
  61. MODULE_DEVICE_TABLE(pci, enic_id_table);
  62. struct enic_stat {
  63. char name[ETH_GSTRING_LEN];
  64. unsigned int offset;
  65. };
  66. #define ENIC_TX_STAT(stat) \
  67. { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
  68. #define ENIC_RX_STAT(stat) \
  69. { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
  70. static const struct enic_stat enic_tx_stats[] = {
  71. ENIC_TX_STAT(tx_frames_ok),
  72. ENIC_TX_STAT(tx_unicast_frames_ok),
  73. ENIC_TX_STAT(tx_multicast_frames_ok),
  74. ENIC_TX_STAT(tx_broadcast_frames_ok),
  75. ENIC_TX_STAT(tx_bytes_ok),
  76. ENIC_TX_STAT(tx_unicast_bytes_ok),
  77. ENIC_TX_STAT(tx_multicast_bytes_ok),
  78. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  79. ENIC_TX_STAT(tx_drops),
  80. ENIC_TX_STAT(tx_errors),
  81. ENIC_TX_STAT(tx_tso),
  82. };
  83. static const struct enic_stat enic_rx_stats[] = {
  84. ENIC_RX_STAT(rx_frames_ok),
  85. ENIC_RX_STAT(rx_frames_total),
  86. ENIC_RX_STAT(rx_unicast_frames_ok),
  87. ENIC_RX_STAT(rx_multicast_frames_ok),
  88. ENIC_RX_STAT(rx_broadcast_frames_ok),
  89. ENIC_RX_STAT(rx_bytes_ok),
  90. ENIC_RX_STAT(rx_unicast_bytes_ok),
  91. ENIC_RX_STAT(rx_multicast_bytes_ok),
  92. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  93. ENIC_RX_STAT(rx_drop),
  94. ENIC_RX_STAT(rx_no_bufs),
  95. ENIC_RX_STAT(rx_errors),
  96. ENIC_RX_STAT(rx_rss),
  97. ENIC_RX_STAT(rx_crc_errors),
  98. ENIC_RX_STAT(rx_frames_64),
  99. ENIC_RX_STAT(rx_frames_127),
  100. ENIC_RX_STAT(rx_frames_255),
  101. ENIC_RX_STAT(rx_frames_511),
  102. ENIC_RX_STAT(rx_frames_1023),
  103. ENIC_RX_STAT(rx_frames_1518),
  104. ENIC_RX_STAT(rx_frames_to_max),
  105. };
  106. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  107. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  108. static int enic_is_dynamic(struct enic *enic)
  109. {
  110. return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN;
  111. }
  112. static int enic_get_settings(struct net_device *netdev,
  113. struct ethtool_cmd *ecmd)
  114. {
  115. struct enic *enic = netdev_priv(netdev);
  116. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  117. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  118. ecmd->port = PORT_FIBRE;
  119. ecmd->transceiver = XCVR_EXTERNAL;
  120. if (netif_carrier_ok(netdev)) {
  121. ecmd->speed = vnic_dev_port_speed(enic->vdev);
  122. ecmd->duplex = DUPLEX_FULL;
  123. } else {
  124. ecmd->speed = -1;
  125. ecmd->duplex = -1;
  126. }
  127. ecmd->autoneg = AUTONEG_DISABLE;
  128. return 0;
  129. }
  130. static void enic_get_drvinfo(struct net_device *netdev,
  131. struct ethtool_drvinfo *drvinfo)
  132. {
  133. struct enic *enic = netdev_priv(netdev);
  134. struct vnic_devcmd_fw_info *fw_info;
  135. spin_lock(&enic->devcmd_lock);
  136. vnic_dev_fw_info(enic->vdev, &fw_info);
  137. spin_unlock(&enic->devcmd_lock);
  138. strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  139. strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  140. strncpy(drvinfo->fw_version, fw_info->fw_version,
  141. sizeof(drvinfo->fw_version));
  142. strncpy(drvinfo->bus_info, pci_name(enic->pdev),
  143. sizeof(drvinfo->bus_info));
  144. }
  145. static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  146. {
  147. unsigned int i;
  148. switch (stringset) {
  149. case ETH_SS_STATS:
  150. for (i = 0; i < enic_n_tx_stats; i++) {
  151. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  152. data += ETH_GSTRING_LEN;
  153. }
  154. for (i = 0; i < enic_n_rx_stats; i++) {
  155. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  156. data += ETH_GSTRING_LEN;
  157. }
  158. break;
  159. }
  160. }
  161. static int enic_get_sset_count(struct net_device *netdev, int sset)
  162. {
  163. switch (sset) {
  164. case ETH_SS_STATS:
  165. return enic_n_tx_stats + enic_n_rx_stats;
  166. default:
  167. return -EOPNOTSUPP;
  168. }
  169. }
  170. static void enic_get_ethtool_stats(struct net_device *netdev,
  171. struct ethtool_stats *stats, u64 *data)
  172. {
  173. struct enic *enic = netdev_priv(netdev);
  174. struct vnic_stats *vstats;
  175. unsigned int i;
  176. spin_lock(&enic->devcmd_lock);
  177. vnic_dev_stats_dump(enic->vdev, &vstats);
  178. spin_unlock(&enic->devcmd_lock);
  179. for (i = 0; i < enic_n_tx_stats; i++)
  180. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
  181. for (i = 0; i < enic_n_rx_stats; i++)
  182. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
  183. }
  184. static u32 enic_get_rx_csum(struct net_device *netdev)
  185. {
  186. struct enic *enic = netdev_priv(netdev);
  187. return enic->csum_rx_enabled;
  188. }
  189. static int enic_set_rx_csum(struct net_device *netdev, u32 data)
  190. {
  191. struct enic *enic = netdev_priv(netdev);
  192. if (data && !ENIC_SETTING(enic, RXCSUM))
  193. return -EINVAL;
  194. enic->csum_rx_enabled = !!data;
  195. return 0;
  196. }
  197. static int enic_set_tx_csum(struct net_device *netdev, u32 data)
  198. {
  199. struct enic *enic = netdev_priv(netdev);
  200. if (data && !ENIC_SETTING(enic, TXCSUM))
  201. return -EINVAL;
  202. if (data)
  203. netdev->features |= NETIF_F_HW_CSUM;
  204. else
  205. netdev->features &= ~NETIF_F_HW_CSUM;
  206. return 0;
  207. }
  208. static int enic_set_tso(struct net_device *netdev, u32 data)
  209. {
  210. struct enic *enic = netdev_priv(netdev);
  211. if (data && !ENIC_SETTING(enic, TSO))
  212. return -EINVAL;
  213. if (data)
  214. netdev->features |=
  215. NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  216. else
  217. netdev->features &=
  218. ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
  219. return 0;
  220. }
  221. static u32 enic_get_msglevel(struct net_device *netdev)
  222. {
  223. struct enic *enic = netdev_priv(netdev);
  224. return enic->msg_enable;
  225. }
  226. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  227. {
  228. struct enic *enic = netdev_priv(netdev);
  229. enic->msg_enable = value;
  230. }
  231. static int enic_get_coalesce(struct net_device *netdev,
  232. struct ethtool_coalesce *ecmd)
  233. {
  234. struct enic *enic = netdev_priv(netdev);
  235. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  236. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  237. return 0;
  238. }
  239. static int enic_set_coalesce(struct net_device *netdev,
  240. struct ethtool_coalesce *ecmd)
  241. {
  242. struct enic *enic = netdev_priv(netdev);
  243. u32 tx_coalesce_usecs;
  244. u32 rx_coalesce_usecs;
  245. tx_coalesce_usecs = min_t(u32,
  246. INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
  247. ecmd->tx_coalesce_usecs);
  248. rx_coalesce_usecs = min_t(u32,
  249. INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
  250. ecmd->rx_coalesce_usecs);
  251. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  252. case VNIC_DEV_INTR_MODE_INTX:
  253. if (tx_coalesce_usecs != rx_coalesce_usecs)
  254. return -EINVAL;
  255. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_INTX_WQ_RQ],
  256. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  257. break;
  258. case VNIC_DEV_INTR_MODE_MSI:
  259. if (tx_coalesce_usecs != rx_coalesce_usecs)
  260. return -EINVAL;
  261. vnic_intr_coalescing_timer_set(&enic->intr[0],
  262. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  263. break;
  264. case VNIC_DEV_INTR_MODE_MSIX:
  265. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_WQ],
  266. INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
  267. vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_RQ],
  268. INTR_COALESCE_USEC_TO_HW(rx_coalesce_usecs));
  269. break;
  270. default:
  271. break;
  272. }
  273. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  274. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  275. return 0;
  276. }
  277. static const struct ethtool_ops enic_ethtool_ops = {
  278. .get_settings = enic_get_settings,
  279. .get_drvinfo = enic_get_drvinfo,
  280. .get_msglevel = enic_get_msglevel,
  281. .set_msglevel = enic_set_msglevel,
  282. .get_link = ethtool_op_get_link,
  283. .get_strings = enic_get_strings,
  284. .get_sset_count = enic_get_sset_count,
  285. .get_ethtool_stats = enic_get_ethtool_stats,
  286. .get_rx_csum = enic_get_rx_csum,
  287. .set_rx_csum = enic_set_rx_csum,
  288. .get_tx_csum = ethtool_op_get_tx_csum,
  289. .set_tx_csum = enic_set_tx_csum,
  290. .get_sg = ethtool_op_get_sg,
  291. .set_sg = ethtool_op_set_sg,
  292. .get_tso = ethtool_op_get_tso,
  293. .set_tso = enic_set_tso,
  294. .get_coalesce = enic_get_coalesce,
  295. .set_coalesce = enic_set_coalesce,
  296. .get_flags = ethtool_op_get_flags,
  297. .set_flags = ethtool_op_set_flags,
  298. };
  299. static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
  300. {
  301. struct enic *enic = vnic_dev_priv(wq->vdev);
  302. if (buf->sop)
  303. pci_unmap_single(enic->pdev, buf->dma_addr,
  304. buf->len, PCI_DMA_TODEVICE);
  305. else
  306. pci_unmap_page(enic->pdev, buf->dma_addr,
  307. buf->len, PCI_DMA_TODEVICE);
  308. if (buf->os_buf)
  309. dev_kfree_skb_any(buf->os_buf);
  310. }
  311. static void enic_wq_free_buf(struct vnic_wq *wq,
  312. struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
  313. {
  314. enic_free_wq_buf(wq, buf);
  315. }
  316. static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  317. u8 type, u16 q_number, u16 completed_index, void *opaque)
  318. {
  319. struct enic *enic = vnic_dev_priv(vdev);
  320. spin_lock(&enic->wq_lock[q_number]);
  321. vnic_wq_service(&enic->wq[q_number], cq_desc,
  322. completed_index, enic_wq_free_buf,
  323. opaque);
  324. if (netif_queue_stopped(enic->netdev) &&
  325. vnic_wq_desc_avail(&enic->wq[q_number]) >=
  326. (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
  327. netif_wake_queue(enic->netdev);
  328. spin_unlock(&enic->wq_lock[q_number]);
  329. return 0;
  330. }
  331. static void enic_log_q_error(struct enic *enic)
  332. {
  333. unsigned int i;
  334. u32 error_status;
  335. for (i = 0; i < enic->wq_count; i++) {
  336. error_status = vnic_wq_error_status(&enic->wq[i]);
  337. if (error_status)
  338. printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n",
  339. enic->netdev->name, i, error_status);
  340. }
  341. for (i = 0; i < enic->rq_count; i++) {
  342. error_status = vnic_rq_error_status(&enic->rq[i]);
  343. if (error_status)
  344. printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n",
  345. enic->netdev->name, i, error_status);
  346. }
  347. }
  348. static void enic_link_check(struct enic *enic)
  349. {
  350. int link_status = vnic_dev_link_status(enic->vdev);
  351. int carrier_ok = netif_carrier_ok(enic->netdev);
  352. if (link_status && !carrier_ok) {
  353. printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name);
  354. netif_carrier_on(enic->netdev);
  355. } else if (!link_status && carrier_ok) {
  356. printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name);
  357. netif_carrier_off(enic->netdev);
  358. }
  359. }
  360. static void enic_mtu_check(struct enic *enic)
  361. {
  362. u32 mtu = vnic_dev_mtu(enic->vdev);
  363. if (mtu && mtu != enic->port_mtu) {
  364. enic->port_mtu = mtu;
  365. if (mtu < enic->netdev->mtu)
  366. printk(KERN_WARNING PFX
  367. "%s: interface MTU (%d) set higher "
  368. "than switch port MTU (%d)\n",
  369. enic->netdev->name, enic->netdev->mtu, mtu);
  370. }
  371. }
  372. static void enic_msglvl_check(struct enic *enic)
  373. {
  374. u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
  375. if (msg_enable != enic->msg_enable) {
  376. printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n",
  377. enic->netdev->name, enic->msg_enable, msg_enable);
  378. enic->msg_enable = msg_enable;
  379. }
  380. }
  381. static void enic_notify_check(struct enic *enic)
  382. {
  383. enic_msglvl_check(enic);
  384. enic_mtu_check(enic);
  385. enic_link_check(enic);
  386. }
  387. #define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
  388. static irqreturn_t enic_isr_legacy(int irq, void *data)
  389. {
  390. struct net_device *netdev = data;
  391. struct enic *enic = netdev_priv(netdev);
  392. u32 pba;
  393. vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
  394. pba = vnic_intr_legacy_pba(enic->legacy_pba);
  395. if (!pba) {
  396. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  397. return IRQ_NONE; /* not our interrupt */
  398. }
  399. if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY)) {
  400. vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_NOTIFY]);
  401. enic_notify_check(enic);
  402. }
  403. if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
  404. vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_ERR]);
  405. enic_log_q_error(enic);
  406. /* schedule recovery from WQ/RQ error */
  407. schedule_work(&enic->reset);
  408. return IRQ_HANDLED;
  409. }
  410. if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
  411. if (napi_schedule_prep(&enic->napi))
  412. __napi_schedule(&enic->napi);
  413. } else {
  414. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  415. }
  416. return IRQ_HANDLED;
  417. }
  418. static irqreturn_t enic_isr_msi(int irq, void *data)
  419. {
  420. struct enic *enic = data;
  421. /* With MSI, there is no sharing of interrupts, so this is
  422. * our interrupt and there is no need to ack it. The device
  423. * is not providing per-vector masking, so the OS will not
  424. * write to PCI config space to mask/unmask the interrupt.
  425. * We're using mask_on_assertion for MSI, so the device
  426. * automatically masks the interrupt when the interrupt is
  427. * generated. Later, when exiting polling, the interrupt
  428. * will be unmasked (see enic_poll).
  429. *
  430. * Also, the device uses the same PCIe Traffic Class (TC)
  431. * for Memory Write data and MSI, so there are no ordering
  432. * issues; the MSI will always arrive at the Root Complex
  433. * _after_ corresponding Memory Writes (i.e. descriptor
  434. * writes).
  435. */
  436. napi_schedule(&enic->napi);
  437. return IRQ_HANDLED;
  438. }
  439. static irqreturn_t enic_isr_msix_rq(int irq, void *data)
  440. {
  441. struct enic *enic = data;
  442. /* schedule NAPI polling for RQ cleanup */
  443. napi_schedule(&enic->napi);
  444. return IRQ_HANDLED;
  445. }
  446. static irqreturn_t enic_isr_msix_wq(int irq, void *data)
  447. {
  448. struct enic *enic = data;
  449. unsigned int wq_work_to_do = -1; /* no limit */
  450. unsigned int wq_work_done;
  451. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  452. wq_work_to_do, enic_wq_service, NULL);
  453. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
  454. wq_work_done,
  455. 1 /* unmask intr */,
  456. 1 /* reset intr timer */);
  457. return IRQ_HANDLED;
  458. }
  459. static irqreturn_t enic_isr_msix_err(int irq, void *data)
  460. {
  461. struct enic *enic = data;
  462. vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_ERR]);
  463. enic_log_q_error(enic);
  464. /* schedule recovery from WQ/RQ error */
  465. schedule_work(&enic->reset);
  466. return IRQ_HANDLED;
  467. }
  468. static irqreturn_t enic_isr_msix_notify(int irq, void *data)
  469. {
  470. struct enic *enic = data;
  471. vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_NOTIFY]);
  472. enic_notify_check(enic);
  473. return IRQ_HANDLED;
  474. }
  475. static inline void enic_queue_wq_skb_cont(struct enic *enic,
  476. struct vnic_wq *wq, struct sk_buff *skb,
  477. unsigned int len_left)
  478. {
  479. skb_frag_t *frag;
  480. /* Queue additional data fragments */
  481. for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
  482. len_left -= frag->size;
  483. enic_queue_wq_desc_cont(wq, skb,
  484. pci_map_page(enic->pdev, frag->page,
  485. frag->page_offset, frag->size,
  486. PCI_DMA_TODEVICE),
  487. frag->size,
  488. (len_left == 0)); /* EOP? */
  489. }
  490. }
  491. static inline void enic_queue_wq_skb_vlan(struct enic *enic,
  492. struct vnic_wq *wq, struct sk_buff *skb,
  493. int vlan_tag_insert, unsigned int vlan_tag)
  494. {
  495. unsigned int head_len = skb_headlen(skb);
  496. unsigned int len_left = skb->len - head_len;
  497. int eop = (len_left == 0);
  498. /* Queue the main skb fragment. The fragments are no larger
  499. * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
  500. * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
  501. * per fragment is queued.
  502. */
  503. enic_queue_wq_desc(wq, skb,
  504. pci_map_single(enic->pdev, skb->data,
  505. head_len, PCI_DMA_TODEVICE),
  506. head_len,
  507. vlan_tag_insert, vlan_tag,
  508. eop);
  509. if (!eop)
  510. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  511. }
  512. static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
  513. struct vnic_wq *wq, struct sk_buff *skb,
  514. int vlan_tag_insert, unsigned int vlan_tag)
  515. {
  516. unsigned int head_len = skb_headlen(skb);
  517. unsigned int len_left = skb->len - head_len;
  518. unsigned int hdr_len = skb_transport_offset(skb);
  519. unsigned int csum_offset = hdr_len + skb->csum_offset;
  520. int eop = (len_left == 0);
  521. /* Queue the main skb fragment. The fragments are no larger
  522. * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
  523. * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
  524. * per fragment is queued.
  525. */
  526. enic_queue_wq_desc_csum_l4(wq, skb,
  527. pci_map_single(enic->pdev, skb->data,
  528. head_len, PCI_DMA_TODEVICE),
  529. head_len,
  530. csum_offset,
  531. hdr_len,
  532. vlan_tag_insert, vlan_tag,
  533. eop);
  534. if (!eop)
  535. enic_queue_wq_skb_cont(enic, wq, skb, len_left);
  536. }
  537. static inline void enic_queue_wq_skb_tso(struct enic *enic,
  538. struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
  539. int vlan_tag_insert, unsigned int vlan_tag)
  540. {
  541. unsigned int frag_len_left = skb_headlen(skb);
  542. unsigned int len_left = skb->len - frag_len_left;
  543. unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  544. int eop = (len_left == 0);
  545. unsigned int len;
  546. dma_addr_t dma_addr;
  547. unsigned int offset = 0;
  548. skb_frag_t *frag;
  549. /* Preload TCP csum field with IP pseudo hdr calculated
  550. * with IP length set to zero. HW will later add in length
  551. * to each TCP segment resulting from the TSO.
  552. */
  553. if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
  554. ip_hdr(skb)->check = 0;
  555. tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  556. ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  557. } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
  558. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  559. &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
  560. }
  561. /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
  562. * for the main skb fragment
  563. */
  564. while (frag_len_left) {
  565. len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
  566. dma_addr = pci_map_single(enic->pdev, skb->data + offset,
  567. len, PCI_DMA_TODEVICE);
  568. enic_queue_wq_desc_tso(wq, skb,
  569. dma_addr,
  570. len,
  571. mss, hdr_len,
  572. vlan_tag_insert, vlan_tag,
  573. eop && (len == frag_len_left));
  574. frag_len_left -= len;
  575. offset += len;
  576. }
  577. if (eop)
  578. return;
  579. /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
  580. * for additional data fragments
  581. */
  582. for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
  583. len_left -= frag->size;
  584. frag_len_left = frag->size;
  585. offset = frag->page_offset;
  586. while (frag_len_left) {
  587. len = min(frag_len_left,
  588. (unsigned int)WQ_ENET_MAX_DESC_LEN);
  589. dma_addr = pci_map_page(enic->pdev, frag->page,
  590. offset, len,
  591. PCI_DMA_TODEVICE);
  592. enic_queue_wq_desc_cont(wq, skb,
  593. dma_addr,
  594. len,
  595. (len_left == 0) &&
  596. (len == frag_len_left)); /* EOP? */
  597. frag_len_left -= len;
  598. offset += len;
  599. }
  600. }
  601. }
  602. static inline void enic_queue_wq_skb(struct enic *enic,
  603. struct vnic_wq *wq, struct sk_buff *skb)
  604. {
  605. unsigned int mss = skb_shinfo(skb)->gso_size;
  606. unsigned int vlan_tag = 0;
  607. int vlan_tag_insert = 0;
  608. if (enic->vlan_group && vlan_tx_tag_present(skb)) {
  609. /* VLAN tag from trunking driver */
  610. vlan_tag_insert = 1;
  611. vlan_tag = vlan_tx_tag_get(skb);
  612. }
  613. if (mss)
  614. enic_queue_wq_skb_tso(enic, wq, skb, mss,
  615. vlan_tag_insert, vlan_tag);
  616. else if (skb->ip_summed == CHECKSUM_PARTIAL)
  617. enic_queue_wq_skb_csum_l4(enic, wq, skb,
  618. vlan_tag_insert, vlan_tag);
  619. else
  620. enic_queue_wq_skb_vlan(enic, wq, skb,
  621. vlan_tag_insert, vlan_tag);
  622. }
  623. /* netif_tx_lock held, process context with BHs disabled, or BH */
  624. static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
  625. struct net_device *netdev)
  626. {
  627. struct enic *enic = netdev_priv(netdev);
  628. struct vnic_wq *wq = &enic->wq[0];
  629. unsigned long flags;
  630. if (skb->len <= 0) {
  631. dev_kfree_skb(skb);
  632. return NETDEV_TX_OK;
  633. }
  634. /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
  635. * which is very likely. In the off chance it's going to take
  636. * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
  637. */
  638. if (skb_shinfo(skb)->gso_size == 0 &&
  639. skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
  640. skb_linearize(skb)) {
  641. dev_kfree_skb(skb);
  642. return NETDEV_TX_OK;
  643. }
  644. spin_lock_irqsave(&enic->wq_lock[0], flags);
  645. if (vnic_wq_desc_avail(wq) <
  646. skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
  647. netif_stop_queue(netdev);
  648. /* This is a hard error, log it */
  649. printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
  650. "queue awake!\n", netdev->name);
  651. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  652. return NETDEV_TX_BUSY;
  653. }
  654. enic_queue_wq_skb(enic, wq, skb);
  655. if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
  656. netif_stop_queue(netdev);
  657. spin_unlock_irqrestore(&enic->wq_lock[0], flags);
  658. return NETDEV_TX_OK;
  659. }
  660. /* dev_base_lock rwlock held, nominally process context */
  661. static struct net_device_stats *enic_get_stats(struct net_device *netdev)
  662. {
  663. struct enic *enic = netdev_priv(netdev);
  664. struct net_device_stats *net_stats = &netdev->stats;
  665. struct vnic_stats *stats;
  666. spin_lock(&enic->devcmd_lock);
  667. vnic_dev_stats_dump(enic->vdev, &stats);
  668. spin_unlock(&enic->devcmd_lock);
  669. net_stats->tx_packets = stats->tx.tx_frames_ok;
  670. net_stats->tx_bytes = stats->tx.tx_bytes_ok;
  671. net_stats->tx_errors = stats->tx.tx_errors;
  672. net_stats->tx_dropped = stats->tx.tx_drops;
  673. net_stats->rx_packets = stats->rx.rx_frames_ok;
  674. net_stats->rx_bytes = stats->rx.rx_bytes_ok;
  675. net_stats->rx_errors = stats->rx.rx_errors;
  676. net_stats->multicast = stats->rx.rx_multicast_frames_ok;
  677. net_stats->rx_over_errors = enic->rq_truncated_pkts;
  678. net_stats->rx_crc_errors = enic->rq_bad_fcs;
  679. net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
  680. return net_stats;
  681. }
  682. static void enic_reset_mcaddrs(struct enic *enic)
  683. {
  684. enic->mc_count = 0;
  685. }
  686. static int enic_set_mac_addr(struct net_device *netdev, char *addr)
  687. {
  688. struct enic *enic = netdev_priv(netdev);
  689. if (enic_is_dynamic(enic)) {
  690. if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
  691. return -EADDRNOTAVAIL;
  692. } else {
  693. if (!is_valid_ether_addr(addr))
  694. return -EADDRNOTAVAIL;
  695. }
  696. memcpy(netdev->dev_addr, addr, netdev->addr_len);
  697. return 0;
  698. }
  699. static int enic_dev_add_station_addr(struct enic *enic)
  700. {
  701. int err = 0;
  702. if (is_valid_ether_addr(enic->netdev->dev_addr)) {
  703. spin_lock(&enic->devcmd_lock);
  704. err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
  705. spin_unlock(&enic->devcmd_lock);
  706. }
  707. return err;
  708. }
  709. static int enic_dev_del_station_addr(struct enic *enic)
  710. {
  711. int err = 0;
  712. if (is_valid_ether_addr(enic->netdev->dev_addr)) {
  713. spin_lock(&enic->devcmd_lock);
  714. err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
  715. spin_unlock(&enic->devcmd_lock);
  716. }
  717. return err;
  718. }
  719. static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
  720. {
  721. struct enic *enic = netdev_priv(netdev);
  722. struct sockaddr *saddr = p;
  723. char *addr = saddr->sa_data;
  724. int err;
  725. if (netif_running(enic->netdev)) {
  726. err = enic_dev_del_station_addr(enic);
  727. if (err)
  728. return err;
  729. }
  730. err = enic_set_mac_addr(netdev, addr);
  731. if (err)
  732. return err;
  733. if (netif_running(enic->netdev)) {
  734. err = enic_dev_add_station_addr(enic);
  735. if (err)
  736. return err;
  737. }
  738. return err;
  739. }
  740. static int enic_set_mac_address(struct net_device *netdev, void *p)
  741. {
  742. return -EOPNOTSUPP;
  743. }
  744. /* netif_tx_lock held, BHs disabled */
  745. static void enic_set_multicast_list(struct net_device *netdev)
  746. {
  747. struct enic *enic = netdev_priv(netdev);
  748. struct netdev_hw_addr *ha;
  749. int directed = 1;
  750. int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
  751. int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
  752. int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
  753. unsigned int mc_count = netdev_mc_count(netdev);
  754. int allmulti = (netdev->flags & IFF_ALLMULTI) ||
  755. mc_count > ENIC_MULTICAST_PERFECT_FILTERS;
  756. unsigned int flags = netdev->flags | (allmulti ? IFF_ALLMULTI : 0);
  757. u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
  758. unsigned int i, j;
  759. if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
  760. mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
  761. spin_lock(&enic->devcmd_lock);
  762. if (enic->flags != flags) {
  763. enic->flags = flags;
  764. vnic_dev_packet_filter(enic->vdev, directed,
  765. multicast, broadcast, promisc, allmulti);
  766. }
  767. /* Is there an easier way? Trying to minimize to
  768. * calls to add/del multicast addrs. We keep the
  769. * addrs from the last call in enic->mc_addr and
  770. * look for changes to add/del.
  771. */
  772. i = 0;
  773. netdev_for_each_mc_addr(ha, netdev) {
  774. if (i == mc_count)
  775. break;
  776. memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
  777. }
  778. for (i = 0; i < enic->mc_count; i++) {
  779. for (j = 0; j < mc_count; j++)
  780. if (compare_ether_addr(enic->mc_addr[i],
  781. mc_addr[j]) == 0)
  782. break;
  783. if (j == mc_count)
  784. enic_del_multicast_addr(enic, enic->mc_addr[i]);
  785. }
  786. for (i = 0; i < mc_count; i++) {
  787. for (j = 0; j < enic->mc_count; j++)
  788. if (compare_ether_addr(mc_addr[i],
  789. enic->mc_addr[j]) == 0)
  790. break;
  791. if (j == enic->mc_count)
  792. enic_add_multicast_addr(enic, mc_addr[i]);
  793. }
  794. /* Save the list to compare against next time
  795. */
  796. for (i = 0; i < mc_count; i++)
  797. memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
  798. enic->mc_count = mc_count;
  799. spin_unlock(&enic->devcmd_lock);
  800. }
  801. /* rtnl lock is held */
  802. static void enic_vlan_rx_register(struct net_device *netdev,
  803. struct vlan_group *vlan_group)
  804. {
  805. struct enic *enic = netdev_priv(netdev);
  806. enic->vlan_group = vlan_group;
  807. }
  808. /* rtnl lock is held */
  809. static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  810. {
  811. struct enic *enic = netdev_priv(netdev);
  812. spin_lock(&enic->devcmd_lock);
  813. enic_add_vlan(enic, vid);
  814. spin_unlock(&enic->devcmd_lock);
  815. }
  816. /* rtnl lock is held */
  817. static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  818. {
  819. struct enic *enic = netdev_priv(netdev);
  820. spin_lock(&enic->devcmd_lock);
  821. enic_del_vlan(enic, vid);
  822. spin_unlock(&enic->devcmd_lock);
  823. }
  824. /* netif_tx_lock held, BHs disabled */
  825. static void enic_tx_timeout(struct net_device *netdev)
  826. {
  827. struct enic *enic = netdev_priv(netdev);
  828. schedule_work(&enic->reset);
  829. }
  830. static int enic_vnic_dev_deinit(struct enic *enic)
  831. {
  832. int err;
  833. spin_lock(&enic->devcmd_lock);
  834. err = vnic_dev_deinit(enic->vdev);
  835. spin_unlock(&enic->devcmd_lock);
  836. return err;
  837. }
  838. static int enic_dev_init_prov(struct enic *enic, struct vic_provinfo *vp)
  839. {
  840. int err;
  841. spin_lock(&enic->devcmd_lock);
  842. err = vnic_dev_init_prov(enic->vdev,
  843. (u8 *)vp, vic_provinfo_size(vp));
  844. spin_unlock(&enic->devcmd_lock);
  845. return err;
  846. }
  847. static int enic_dev_init_done(struct enic *enic, int *done, int *error)
  848. {
  849. int err;
  850. spin_lock(&enic->devcmd_lock);
  851. err = vnic_dev_init_done(enic->vdev, done, error);
  852. spin_unlock(&enic->devcmd_lock);
  853. return err;
  854. }
  855. static int enic_set_port_profile(struct enic *enic, u8 request, u8 *mac,
  856. char *name, u8 *instance_uuid, u8 *host_uuid)
  857. {
  858. struct vic_provinfo *vp;
  859. u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
  860. u8 *uuid;
  861. char uuid_str[38];
  862. static char *uuid_fmt = "%02X%02X%02X%02X-%02X%02X-%02X%02X-"
  863. "%02X%02X-%02X%02X%02X%02X%0X%02X";
  864. int err;
  865. if (!name)
  866. return -EINVAL;
  867. if (!is_valid_ether_addr(mac))
  868. return -EADDRNOTAVAIL;
  869. vp = vic_provinfo_alloc(GFP_KERNEL, oui, VIC_PROVINFO_LINUX_TYPE);
  870. if (!vp)
  871. return -ENOMEM;
  872. vic_provinfo_add_tlv(vp,
  873. VIC_LINUX_PROV_TLV_PORT_PROFILE_NAME_STR,
  874. strlen(name) + 1, name);
  875. vic_provinfo_add_tlv(vp,
  876. VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
  877. ETH_ALEN, mac);
  878. if (instance_uuid) {
  879. uuid = instance_uuid;
  880. sprintf(uuid_str, uuid_fmt,
  881. uuid[0], uuid[1], uuid[2], uuid[3],
  882. uuid[4], uuid[5], uuid[6], uuid[7],
  883. uuid[8], uuid[9], uuid[10], uuid[11],
  884. uuid[12], uuid[13], uuid[14], uuid[15]);
  885. vic_provinfo_add_tlv(vp,
  886. VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
  887. sizeof(uuid_str), uuid_str);
  888. }
  889. if (host_uuid) {
  890. uuid = host_uuid;
  891. sprintf(uuid_str, uuid_fmt,
  892. uuid[0], uuid[1], uuid[2], uuid[3],
  893. uuid[4], uuid[5], uuid[6], uuid[7],
  894. uuid[8], uuid[9], uuid[10], uuid[11],
  895. uuid[12], uuid[13], uuid[14], uuid[15]);
  896. vic_provinfo_add_tlv(vp,
  897. VIC_LINUX_PROV_TLV_HOST_UUID_STR,
  898. sizeof(uuid_str), uuid_str);
  899. }
  900. err = enic_vnic_dev_deinit(enic);
  901. if (err)
  902. goto err_out;
  903. memset(&enic->pp, 0, sizeof(enic->pp));
  904. err = enic_dev_init_prov(enic, vp);
  905. if (err)
  906. goto err_out;
  907. enic->pp.request = request;
  908. memcpy(enic->pp.name, name, PORT_PROFILE_MAX);
  909. if (instance_uuid)
  910. memcpy(enic->pp.instance_uuid,
  911. instance_uuid, PORT_UUID_MAX);
  912. if (host_uuid)
  913. memcpy(enic->pp.host_uuid,
  914. host_uuid, PORT_UUID_MAX);
  915. err_out:
  916. vic_provinfo_free(vp);
  917. return err;
  918. }
  919. static int enic_unset_port_profile(struct enic *enic)
  920. {
  921. memset(&enic->pp, 0, sizeof(enic->pp));
  922. return enic_vnic_dev_deinit(enic);
  923. }
  924. static int enic_set_vf_port(struct net_device *netdev, int vf,
  925. struct nlattr *port[])
  926. {
  927. struct enic *enic = netdev_priv(netdev);
  928. char *name = NULL;
  929. u8 *instance_uuid = NULL;
  930. u8 *host_uuid = NULL;
  931. u8 request = PORT_REQUEST_DISASSOCIATE;
  932. /* don't support VFs, yet */
  933. if (vf != PORT_SELF_VF)
  934. return -EOPNOTSUPP;
  935. if (port[IFLA_PORT_REQUEST])
  936. request = nla_get_u8(port[IFLA_PORT_REQUEST]);
  937. switch (request) {
  938. case PORT_REQUEST_ASSOCIATE:
  939. if (port[IFLA_PORT_PROFILE])
  940. name = nla_data(port[IFLA_PORT_PROFILE]);
  941. if (port[IFLA_PORT_INSTANCE_UUID])
  942. instance_uuid =
  943. nla_data(port[IFLA_PORT_INSTANCE_UUID]);
  944. if (port[IFLA_PORT_HOST_UUID])
  945. host_uuid = nla_data(port[IFLA_PORT_HOST_UUID]);
  946. return enic_set_port_profile(enic, request,
  947. netdev->dev_addr, name,
  948. instance_uuid, host_uuid);
  949. case PORT_REQUEST_DISASSOCIATE:
  950. return enic_unset_port_profile(enic);
  951. default:
  952. break;
  953. }
  954. return -EOPNOTSUPP;
  955. }
  956. static int enic_get_vf_port(struct net_device *netdev, int vf,
  957. struct sk_buff *skb)
  958. {
  959. struct enic *enic = netdev_priv(netdev);
  960. int err, error, done;
  961. u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
  962. /* don't support VFs, yet */
  963. if (vf != PORT_SELF_VF)
  964. return -EOPNOTSUPP;
  965. err = enic_dev_init_done(enic, &done, &error);
  966. if (err)
  967. return err;
  968. switch (error) {
  969. case ERR_SUCCESS:
  970. if (!done)
  971. response = PORT_PROFILE_RESPONSE_INPROGRESS;
  972. break;
  973. case ERR_EINVAL:
  974. response = PORT_PROFILE_RESPONSE_INVALID;
  975. break;
  976. case ERR_EBADSTATE:
  977. response = PORT_PROFILE_RESPONSE_BADSTATE;
  978. break;
  979. case ERR_ENOMEM:
  980. response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
  981. break;
  982. default:
  983. response = PORT_PROFILE_RESPONSE_ERROR;
  984. break;
  985. }
  986. NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request);
  987. NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response);
  988. NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX,
  989. enic->pp.name);
  990. NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
  991. enic->pp.instance_uuid);
  992. NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX,
  993. enic->pp.host_uuid);
  994. return 0;
  995. nla_put_failure:
  996. return -EMSGSIZE;
  997. }
  998. static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
  999. {
  1000. struct enic *enic = vnic_dev_priv(rq->vdev);
  1001. if (!buf->os_buf)
  1002. return;
  1003. pci_unmap_single(enic->pdev, buf->dma_addr,
  1004. buf->len, PCI_DMA_FROMDEVICE);
  1005. dev_kfree_skb_any(buf->os_buf);
  1006. }
  1007. static int enic_rq_alloc_buf(struct vnic_rq *rq)
  1008. {
  1009. struct enic *enic = vnic_dev_priv(rq->vdev);
  1010. struct net_device *netdev = enic->netdev;
  1011. struct sk_buff *skb;
  1012. unsigned int len = netdev->mtu + ETH_HLEN;
  1013. unsigned int os_buf_index = 0;
  1014. dma_addr_t dma_addr;
  1015. skb = netdev_alloc_skb_ip_align(netdev, len);
  1016. if (!skb)
  1017. return -ENOMEM;
  1018. dma_addr = pci_map_single(enic->pdev, skb->data,
  1019. len, PCI_DMA_FROMDEVICE);
  1020. enic_queue_rq_desc(rq, skb, os_buf_index,
  1021. dma_addr, len);
  1022. return 0;
  1023. }
  1024. static int enic_rq_alloc_buf_a1(struct vnic_rq *rq)
  1025. {
  1026. struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
  1027. if (vnic_rq_posting_soon(rq)) {
  1028. /* SW workaround for A0 HW erratum: if we're just about
  1029. * to write posted_index, insert a dummy desc
  1030. * of type resvd
  1031. */
  1032. rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0);
  1033. vnic_rq_post(rq, 0, 0, 0, 0);
  1034. } else {
  1035. return enic_rq_alloc_buf(rq);
  1036. }
  1037. return 0;
  1038. }
  1039. static int enic_set_rq_alloc_buf(struct enic *enic)
  1040. {
  1041. enum vnic_dev_hw_version hw_ver;
  1042. int err;
  1043. err = vnic_dev_hw_version(enic->vdev, &hw_ver);
  1044. if (err)
  1045. return err;
  1046. switch (hw_ver) {
  1047. case VNIC_DEV_HW_VER_A1:
  1048. enic->rq_alloc_buf = enic_rq_alloc_buf_a1;
  1049. break;
  1050. case VNIC_DEV_HW_VER_A2:
  1051. case VNIC_DEV_HW_VER_UNKNOWN:
  1052. enic->rq_alloc_buf = enic_rq_alloc_buf;
  1053. break;
  1054. default:
  1055. return -ENODEV;
  1056. }
  1057. return 0;
  1058. }
  1059. static int enic_get_skb_header(struct sk_buff *skb, void **iphdr,
  1060. void **tcph, u64 *hdr_flags, void *priv)
  1061. {
  1062. struct cq_enet_rq_desc *cq_desc = priv;
  1063. unsigned int ip_len;
  1064. struct iphdr *iph;
  1065. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  1066. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  1067. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  1068. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  1069. u8 packet_error;
  1070. u16 q_number, completed_index, bytes_written, vlan, checksum;
  1071. u32 rss_hash;
  1072. cq_enet_rq_desc_dec(cq_desc,
  1073. &type, &color, &q_number, &completed_index,
  1074. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  1075. &csum_not_calc, &rss_hash, &bytes_written,
  1076. &packet_error, &vlan_stripped, &vlan, &checksum,
  1077. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  1078. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  1079. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  1080. &fcs_ok);
  1081. if (!(ipv4 && tcp && !ipv4_fragment))
  1082. return -1;
  1083. skb_reset_network_header(skb);
  1084. iph = ip_hdr(skb);
  1085. ip_len = ip_hdrlen(skb);
  1086. skb_set_transport_header(skb, ip_len);
  1087. /* check if ip header and tcp header are complete */
  1088. if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
  1089. return -1;
  1090. *hdr_flags = LRO_IPV4 | LRO_TCP;
  1091. *tcph = tcp_hdr(skb);
  1092. *iphdr = iph;
  1093. return 0;
  1094. }
  1095. static void enic_rq_indicate_buf(struct vnic_rq *rq,
  1096. struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
  1097. int skipped, void *opaque)
  1098. {
  1099. struct enic *enic = vnic_dev_priv(rq->vdev);
  1100. struct net_device *netdev = enic->netdev;
  1101. struct sk_buff *skb;
  1102. u8 type, color, eop, sop, ingress_port, vlan_stripped;
  1103. u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
  1104. u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
  1105. u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
  1106. u8 packet_error;
  1107. u16 q_number, completed_index, bytes_written, vlan, checksum;
  1108. u32 rss_hash;
  1109. if (skipped)
  1110. return;
  1111. skb = buf->os_buf;
  1112. prefetch(skb->data - NET_IP_ALIGN);
  1113. pci_unmap_single(enic->pdev, buf->dma_addr,
  1114. buf->len, PCI_DMA_FROMDEVICE);
  1115. cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
  1116. &type, &color, &q_number, &completed_index,
  1117. &ingress_port, &fcoe, &eop, &sop, &rss_type,
  1118. &csum_not_calc, &rss_hash, &bytes_written,
  1119. &packet_error, &vlan_stripped, &vlan, &checksum,
  1120. &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
  1121. &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
  1122. &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
  1123. &fcs_ok);
  1124. if (packet_error) {
  1125. if (!fcs_ok) {
  1126. if (bytes_written > 0)
  1127. enic->rq_bad_fcs++;
  1128. else if (bytes_written == 0)
  1129. enic->rq_truncated_pkts++;
  1130. }
  1131. dev_kfree_skb_any(skb);
  1132. return;
  1133. }
  1134. if (eop && bytes_written > 0) {
  1135. /* Good receive
  1136. */
  1137. skb_put(skb, bytes_written);
  1138. skb->protocol = eth_type_trans(skb, netdev);
  1139. if (enic->csum_rx_enabled && !csum_not_calc) {
  1140. skb->csum = htons(checksum);
  1141. skb->ip_summed = CHECKSUM_COMPLETE;
  1142. }
  1143. skb->dev = netdev;
  1144. if (enic->vlan_group && vlan_stripped) {
  1145. if ((netdev->features & NETIF_F_LRO) && ipv4)
  1146. lro_vlan_hwaccel_receive_skb(&enic->lro_mgr,
  1147. skb, enic->vlan_group,
  1148. vlan, cq_desc);
  1149. else
  1150. vlan_hwaccel_receive_skb(skb,
  1151. enic->vlan_group, vlan);
  1152. } else {
  1153. if ((netdev->features & NETIF_F_LRO) && ipv4)
  1154. lro_receive_skb(&enic->lro_mgr, skb, cq_desc);
  1155. else
  1156. netif_receive_skb(skb);
  1157. }
  1158. } else {
  1159. /* Buffer overflow
  1160. */
  1161. dev_kfree_skb_any(skb);
  1162. }
  1163. }
  1164. static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  1165. u8 type, u16 q_number, u16 completed_index, void *opaque)
  1166. {
  1167. struct enic *enic = vnic_dev_priv(vdev);
  1168. vnic_rq_service(&enic->rq[q_number], cq_desc,
  1169. completed_index, VNIC_RQ_RETURN_DESC,
  1170. enic_rq_indicate_buf, opaque);
  1171. return 0;
  1172. }
  1173. static int enic_poll(struct napi_struct *napi, int budget)
  1174. {
  1175. struct enic *enic = container_of(napi, struct enic, napi);
  1176. struct net_device *netdev = enic->netdev;
  1177. unsigned int rq_work_to_do = budget;
  1178. unsigned int wq_work_to_do = -1; /* no limit */
  1179. unsigned int work_done, rq_work_done, wq_work_done;
  1180. int err;
  1181. /* Service RQ (first) and WQ
  1182. */
  1183. rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  1184. rq_work_to_do, enic_rq_service, NULL);
  1185. wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
  1186. wq_work_to_do, enic_wq_service, NULL);
  1187. /* Accumulate intr event credits for this polling
  1188. * cycle. An intr event is the completion of a
  1189. * a WQ or RQ packet.
  1190. */
  1191. work_done = rq_work_done + wq_work_done;
  1192. if (work_done > 0)
  1193. vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
  1194. work_done,
  1195. 0 /* don't unmask intr */,
  1196. 0 /* don't reset intr timer */);
  1197. err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
  1198. /* Buffer allocation failed. Stay in polling
  1199. * mode so we can try to fill the ring again.
  1200. */
  1201. if (err)
  1202. rq_work_done = rq_work_to_do;
  1203. if (rq_work_done < rq_work_to_do) {
  1204. /* Some work done, but not enough to stay in polling,
  1205. * flush all LROs and exit polling
  1206. */
  1207. if (netdev->features & NETIF_F_LRO)
  1208. lro_flush_all(&enic->lro_mgr);
  1209. napi_complete(napi);
  1210. vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
  1211. }
  1212. return rq_work_done;
  1213. }
  1214. static int enic_poll_msix(struct napi_struct *napi, int budget)
  1215. {
  1216. struct enic *enic = container_of(napi, struct enic, napi);
  1217. struct net_device *netdev = enic->netdev;
  1218. unsigned int work_to_do = budget;
  1219. unsigned int work_done;
  1220. int err;
  1221. /* Service RQ
  1222. */
  1223. work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
  1224. work_to_do, enic_rq_service, NULL);
  1225. /* Return intr event credits for this polling
  1226. * cycle. An intr event is the completion of a
  1227. * RQ packet.
  1228. */
  1229. if (work_done > 0)
  1230. vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
  1231. work_done,
  1232. 0 /* don't unmask intr */,
  1233. 0 /* don't reset intr timer */);
  1234. err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
  1235. /* Buffer allocation failed. Stay in polling mode
  1236. * so we can try to fill the ring again.
  1237. */
  1238. if (err)
  1239. work_done = work_to_do;
  1240. if (work_done < work_to_do) {
  1241. /* Some work done, but not enough to stay in polling,
  1242. * flush all LROs and exit polling
  1243. */
  1244. if (netdev->features & NETIF_F_LRO)
  1245. lro_flush_all(&enic->lro_mgr);
  1246. napi_complete(napi);
  1247. vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
  1248. }
  1249. return work_done;
  1250. }
  1251. static void enic_notify_timer(unsigned long data)
  1252. {
  1253. struct enic *enic = (struct enic *)data;
  1254. enic_notify_check(enic);
  1255. mod_timer(&enic->notify_timer,
  1256. round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
  1257. }
  1258. static void enic_free_intr(struct enic *enic)
  1259. {
  1260. struct net_device *netdev = enic->netdev;
  1261. unsigned int i;
  1262. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1263. case VNIC_DEV_INTR_MODE_INTX:
  1264. free_irq(enic->pdev->irq, netdev);
  1265. break;
  1266. case VNIC_DEV_INTR_MODE_MSI:
  1267. free_irq(enic->pdev->irq, enic);
  1268. break;
  1269. case VNIC_DEV_INTR_MODE_MSIX:
  1270. for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
  1271. if (enic->msix[i].requested)
  1272. free_irq(enic->msix_entry[i].vector,
  1273. enic->msix[i].devid);
  1274. break;
  1275. default:
  1276. break;
  1277. }
  1278. }
  1279. static int enic_request_intr(struct enic *enic)
  1280. {
  1281. struct net_device *netdev = enic->netdev;
  1282. unsigned int i;
  1283. int err = 0;
  1284. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1285. case VNIC_DEV_INTR_MODE_INTX:
  1286. err = request_irq(enic->pdev->irq, enic_isr_legacy,
  1287. IRQF_SHARED, netdev->name, netdev);
  1288. break;
  1289. case VNIC_DEV_INTR_MODE_MSI:
  1290. err = request_irq(enic->pdev->irq, enic_isr_msi,
  1291. 0, netdev->name, enic);
  1292. break;
  1293. case VNIC_DEV_INTR_MODE_MSIX:
  1294. sprintf(enic->msix[ENIC_MSIX_RQ].devname,
  1295. "%.11s-rx-0", netdev->name);
  1296. enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
  1297. enic->msix[ENIC_MSIX_RQ].devid = enic;
  1298. sprintf(enic->msix[ENIC_MSIX_WQ].devname,
  1299. "%.11s-tx-0", netdev->name);
  1300. enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
  1301. enic->msix[ENIC_MSIX_WQ].devid = enic;
  1302. sprintf(enic->msix[ENIC_MSIX_ERR].devname,
  1303. "%.11s-err", netdev->name);
  1304. enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
  1305. enic->msix[ENIC_MSIX_ERR].devid = enic;
  1306. sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
  1307. "%.11s-notify", netdev->name);
  1308. enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
  1309. enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
  1310. for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
  1311. err = request_irq(enic->msix_entry[i].vector,
  1312. enic->msix[i].isr, 0,
  1313. enic->msix[i].devname,
  1314. enic->msix[i].devid);
  1315. if (err) {
  1316. enic_free_intr(enic);
  1317. break;
  1318. }
  1319. enic->msix[i].requested = 1;
  1320. }
  1321. break;
  1322. default:
  1323. break;
  1324. }
  1325. return err;
  1326. }
  1327. static void enic_synchronize_irqs(struct enic *enic)
  1328. {
  1329. unsigned int i;
  1330. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1331. case VNIC_DEV_INTR_MODE_INTX:
  1332. case VNIC_DEV_INTR_MODE_MSI:
  1333. synchronize_irq(enic->pdev->irq);
  1334. break;
  1335. case VNIC_DEV_INTR_MODE_MSIX:
  1336. for (i = 0; i < enic->intr_count; i++)
  1337. synchronize_irq(enic->msix_entry[i].vector);
  1338. break;
  1339. default:
  1340. break;
  1341. }
  1342. }
  1343. static int enic_notify_set(struct enic *enic)
  1344. {
  1345. int err;
  1346. spin_lock(&enic->devcmd_lock);
  1347. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1348. case VNIC_DEV_INTR_MODE_INTX:
  1349. err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
  1350. break;
  1351. case VNIC_DEV_INTR_MODE_MSIX:
  1352. err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
  1353. break;
  1354. default:
  1355. err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
  1356. break;
  1357. }
  1358. spin_unlock(&enic->devcmd_lock);
  1359. return err;
  1360. }
  1361. static void enic_notify_timer_start(struct enic *enic)
  1362. {
  1363. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1364. case VNIC_DEV_INTR_MODE_MSI:
  1365. mod_timer(&enic->notify_timer, jiffies);
  1366. break;
  1367. default:
  1368. /* Using intr for notification for INTx/MSI-X */
  1369. break;
  1370. };
  1371. }
  1372. /* rtnl lock is held, process context */
  1373. static int enic_open(struct net_device *netdev)
  1374. {
  1375. struct enic *enic = netdev_priv(netdev);
  1376. unsigned int i;
  1377. int err;
  1378. err = enic_request_intr(enic);
  1379. if (err) {
  1380. printk(KERN_ERR PFX "%s: Unable to request irq.\n",
  1381. netdev->name);
  1382. return err;
  1383. }
  1384. err = enic_notify_set(enic);
  1385. if (err) {
  1386. printk(KERN_ERR PFX
  1387. "%s: Failed to alloc notify buffer, aborting.\n",
  1388. netdev->name);
  1389. goto err_out_free_intr;
  1390. }
  1391. for (i = 0; i < enic->rq_count; i++) {
  1392. vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf);
  1393. /* Need at least one buffer on ring to get going */
  1394. if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
  1395. printk(KERN_ERR PFX
  1396. "%s: Unable to alloc receive buffers.\n",
  1397. netdev->name);
  1398. err = -ENOMEM;
  1399. goto err_out_notify_unset;
  1400. }
  1401. }
  1402. for (i = 0; i < enic->wq_count; i++)
  1403. vnic_wq_enable(&enic->wq[i]);
  1404. for (i = 0; i < enic->rq_count; i++)
  1405. vnic_rq_enable(&enic->rq[i]);
  1406. enic_dev_add_station_addr(enic);
  1407. enic_set_multicast_list(netdev);
  1408. netif_wake_queue(netdev);
  1409. napi_enable(&enic->napi);
  1410. spin_lock(&enic->devcmd_lock);
  1411. vnic_dev_enable(enic->vdev);
  1412. spin_unlock(&enic->devcmd_lock);
  1413. for (i = 0; i < enic->intr_count; i++)
  1414. vnic_intr_unmask(&enic->intr[i]);
  1415. enic_notify_timer_start(enic);
  1416. return 0;
  1417. err_out_notify_unset:
  1418. spin_lock(&enic->devcmd_lock);
  1419. vnic_dev_notify_unset(enic->vdev);
  1420. spin_unlock(&enic->devcmd_lock);
  1421. err_out_free_intr:
  1422. enic_free_intr(enic);
  1423. return err;
  1424. }
  1425. /* rtnl lock is held, process context */
  1426. static int enic_stop(struct net_device *netdev)
  1427. {
  1428. struct enic *enic = netdev_priv(netdev);
  1429. unsigned int i;
  1430. int err;
  1431. for (i = 0; i < enic->intr_count; i++)
  1432. vnic_intr_mask(&enic->intr[i]);
  1433. enic_synchronize_irqs(enic);
  1434. del_timer_sync(&enic->notify_timer);
  1435. spin_lock(&enic->devcmd_lock);
  1436. vnic_dev_disable(enic->vdev);
  1437. spin_unlock(&enic->devcmd_lock);
  1438. napi_disable(&enic->napi);
  1439. netif_carrier_off(netdev);
  1440. netif_tx_disable(netdev);
  1441. enic_dev_del_station_addr(enic);
  1442. for (i = 0; i < enic->wq_count; i++) {
  1443. err = vnic_wq_disable(&enic->wq[i]);
  1444. if (err)
  1445. return err;
  1446. }
  1447. for (i = 0; i < enic->rq_count; i++) {
  1448. err = vnic_rq_disable(&enic->rq[i]);
  1449. if (err)
  1450. return err;
  1451. }
  1452. spin_lock(&enic->devcmd_lock);
  1453. vnic_dev_notify_unset(enic->vdev);
  1454. spin_unlock(&enic->devcmd_lock);
  1455. enic_free_intr(enic);
  1456. for (i = 0; i < enic->wq_count; i++)
  1457. vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
  1458. for (i = 0; i < enic->rq_count; i++)
  1459. vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
  1460. for (i = 0; i < enic->cq_count; i++)
  1461. vnic_cq_clean(&enic->cq[i]);
  1462. for (i = 0; i < enic->intr_count; i++)
  1463. vnic_intr_clean(&enic->intr[i]);
  1464. return 0;
  1465. }
  1466. static int enic_change_mtu(struct net_device *netdev, int new_mtu)
  1467. {
  1468. struct enic *enic = netdev_priv(netdev);
  1469. int running = netif_running(netdev);
  1470. if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
  1471. return -EINVAL;
  1472. if (running)
  1473. enic_stop(netdev);
  1474. netdev->mtu = new_mtu;
  1475. if (netdev->mtu > enic->port_mtu)
  1476. printk(KERN_WARNING PFX
  1477. "%s: interface MTU (%d) set higher "
  1478. "than port MTU (%d)\n",
  1479. netdev->name, netdev->mtu, enic->port_mtu);
  1480. if (running)
  1481. enic_open(netdev);
  1482. return 0;
  1483. }
  1484. #ifdef CONFIG_NET_POLL_CONTROLLER
  1485. static void enic_poll_controller(struct net_device *netdev)
  1486. {
  1487. struct enic *enic = netdev_priv(netdev);
  1488. struct vnic_dev *vdev = enic->vdev;
  1489. switch (vnic_dev_get_intr_mode(vdev)) {
  1490. case VNIC_DEV_INTR_MODE_MSIX:
  1491. enic_isr_msix_rq(enic->pdev->irq, enic);
  1492. enic_isr_msix_wq(enic->pdev->irq, enic);
  1493. break;
  1494. case VNIC_DEV_INTR_MODE_MSI:
  1495. enic_isr_msi(enic->pdev->irq, enic);
  1496. break;
  1497. case VNIC_DEV_INTR_MODE_INTX:
  1498. enic_isr_legacy(enic->pdev->irq, netdev);
  1499. break;
  1500. default:
  1501. break;
  1502. }
  1503. }
  1504. #endif
  1505. static int enic_dev_wait(struct vnic_dev *vdev,
  1506. int (*start)(struct vnic_dev *, int),
  1507. int (*finished)(struct vnic_dev *, int *),
  1508. int arg)
  1509. {
  1510. unsigned long time;
  1511. int done;
  1512. int err;
  1513. BUG_ON(in_interrupt());
  1514. err = start(vdev, arg);
  1515. if (err)
  1516. return err;
  1517. /* Wait for func to complete...2 seconds max
  1518. */
  1519. time = jiffies + (HZ * 2);
  1520. do {
  1521. err = finished(vdev, &done);
  1522. if (err)
  1523. return err;
  1524. if (done)
  1525. return 0;
  1526. schedule_timeout_uninterruptible(HZ / 10);
  1527. } while (time_after(time, jiffies));
  1528. return -ETIMEDOUT;
  1529. }
  1530. static int enic_dev_open(struct enic *enic)
  1531. {
  1532. int err;
  1533. err = enic_dev_wait(enic->vdev, vnic_dev_open,
  1534. vnic_dev_open_done, 0);
  1535. if (err)
  1536. printk(KERN_ERR PFX
  1537. "vNIC device open failed, err %d.\n", err);
  1538. return err;
  1539. }
  1540. static int enic_dev_soft_reset(struct enic *enic)
  1541. {
  1542. int err;
  1543. err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
  1544. vnic_dev_soft_reset_done, 0);
  1545. if (err)
  1546. printk(KERN_ERR PFX
  1547. "vNIC soft reset failed, err %d.\n", err);
  1548. return err;
  1549. }
  1550. static int enic_set_niccfg(struct enic *enic)
  1551. {
  1552. const u8 rss_default_cpu = 0;
  1553. const u8 rss_hash_type = 0;
  1554. const u8 rss_hash_bits = 0;
  1555. const u8 rss_base_cpu = 0;
  1556. const u8 rss_enable = 0;
  1557. const u8 tso_ipid_split_en = 0;
  1558. const u8 ig_vlan_strip_en = 1;
  1559. /* Enable VLAN tag stripping. RSS not enabled (yet).
  1560. */
  1561. return enic_set_nic_cfg(enic,
  1562. rss_default_cpu, rss_hash_type,
  1563. rss_hash_bits, rss_base_cpu,
  1564. rss_enable, tso_ipid_split_en,
  1565. ig_vlan_strip_en);
  1566. }
  1567. static void enic_reset(struct work_struct *work)
  1568. {
  1569. struct enic *enic = container_of(work, struct enic, reset);
  1570. if (!netif_running(enic->netdev))
  1571. return;
  1572. rtnl_lock();
  1573. spin_lock(&enic->devcmd_lock);
  1574. vnic_dev_hang_notify(enic->vdev);
  1575. spin_unlock(&enic->devcmd_lock);
  1576. enic_stop(enic->netdev);
  1577. enic_dev_soft_reset(enic);
  1578. vnic_dev_init(enic->vdev, 0);
  1579. enic_reset_mcaddrs(enic);
  1580. enic_init_vnic_resources(enic);
  1581. enic_set_niccfg(enic);
  1582. enic_open(enic->netdev);
  1583. rtnl_unlock();
  1584. }
  1585. static int enic_set_intr_mode(struct enic *enic)
  1586. {
  1587. unsigned int n = 1;
  1588. unsigned int m = 1;
  1589. unsigned int i;
  1590. /* Set interrupt mode (INTx, MSI, MSI-X) depending
  1591. * system capabilities.
  1592. *
  1593. * Try MSI-X first
  1594. *
  1595. * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
  1596. * (the second to last INTR is used for WQ/RQ errors)
  1597. * (the last INTR is used for notifications)
  1598. */
  1599. BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
  1600. for (i = 0; i < n + m + 2; i++)
  1601. enic->msix_entry[i].entry = i;
  1602. if (enic->config.intr_mode < 1 &&
  1603. enic->rq_count >= n &&
  1604. enic->wq_count >= m &&
  1605. enic->cq_count >= n + m &&
  1606. enic->intr_count >= n + m + 2 &&
  1607. !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
  1608. enic->rq_count = n;
  1609. enic->wq_count = m;
  1610. enic->cq_count = n + m;
  1611. enic->intr_count = n + m + 2;
  1612. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
  1613. return 0;
  1614. }
  1615. /* Next try MSI
  1616. *
  1617. * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
  1618. */
  1619. if (enic->config.intr_mode < 2 &&
  1620. enic->rq_count >= 1 &&
  1621. enic->wq_count >= 1 &&
  1622. enic->cq_count >= 2 &&
  1623. enic->intr_count >= 1 &&
  1624. !pci_enable_msi(enic->pdev)) {
  1625. enic->rq_count = 1;
  1626. enic->wq_count = 1;
  1627. enic->cq_count = 2;
  1628. enic->intr_count = 1;
  1629. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
  1630. return 0;
  1631. }
  1632. /* Next try INTx
  1633. *
  1634. * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
  1635. * (the first INTR is used for WQ/RQ)
  1636. * (the second INTR is used for WQ/RQ errors)
  1637. * (the last INTR is used for notifications)
  1638. */
  1639. if (enic->config.intr_mode < 3 &&
  1640. enic->rq_count >= 1 &&
  1641. enic->wq_count >= 1 &&
  1642. enic->cq_count >= 2 &&
  1643. enic->intr_count >= 3) {
  1644. enic->rq_count = 1;
  1645. enic->wq_count = 1;
  1646. enic->cq_count = 2;
  1647. enic->intr_count = 3;
  1648. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
  1649. return 0;
  1650. }
  1651. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1652. return -EINVAL;
  1653. }
  1654. static void enic_clear_intr_mode(struct enic *enic)
  1655. {
  1656. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1657. case VNIC_DEV_INTR_MODE_MSIX:
  1658. pci_disable_msix(enic->pdev);
  1659. break;
  1660. case VNIC_DEV_INTR_MODE_MSI:
  1661. pci_disable_msi(enic->pdev);
  1662. break;
  1663. default:
  1664. break;
  1665. }
  1666. vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
  1667. }
  1668. static const struct net_device_ops enic_netdev_dynamic_ops = {
  1669. .ndo_open = enic_open,
  1670. .ndo_stop = enic_stop,
  1671. .ndo_start_xmit = enic_hard_start_xmit,
  1672. .ndo_get_stats = enic_get_stats,
  1673. .ndo_validate_addr = eth_validate_addr,
  1674. .ndo_set_multicast_list = enic_set_multicast_list,
  1675. .ndo_set_mac_address = enic_set_mac_address_dynamic,
  1676. .ndo_change_mtu = enic_change_mtu,
  1677. .ndo_vlan_rx_register = enic_vlan_rx_register,
  1678. .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
  1679. .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
  1680. .ndo_tx_timeout = enic_tx_timeout,
  1681. .ndo_set_vf_port = enic_set_vf_port,
  1682. .ndo_get_vf_port = enic_get_vf_port,
  1683. #ifdef CONFIG_NET_POLL_CONTROLLER
  1684. .ndo_poll_controller = enic_poll_controller,
  1685. #endif
  1686. };
  1687. static const struct net_device_ops enic_netdev_ops = {
  1688. .ndo_open = enic_open,
  1689. .ndo_stop = enic_stop,
  1690. .ndo_start_xmit = enic_hard_start_xmit,
  1691. .ndo_get_stats = enic_get_stats,
  1692. .ndo_validate_addr = eth_validate_addr,
  1693. .ndo_set_multicast_list = enic_set_multicast_list,
  1694. .ndo_set_mac_address = enic_set_mac_address,
  1695. .ndo_change_mtu = enic_change_mtu,
  1696. .ndo_vlan_rx_register = enic_vlan_rx_register,
  1697. .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
  1698. .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
  1699. .ndo_tx_timeout = enic_tx_timeout,
  1700. #ifdef CONFIG_NET_POLL_CONTROLLER
  1701. .ndo_poll_controller = enic_poll_controller,
  1702. #endif
  1703. };
  1704. void enic_dev_deinit(struct enic *enic)
  1705. {
  1706. netif_napi_del(&enic->napi);
  1707. enic_free_vnic_resources(enic);
  1708. enic_clear_intr_mode(enic);
  1709. }
  1710. int enic_dev_init(struct enic *enic)
  1711. {
  1712. struct net_device *netdev = enic->netdev;
  1713. int err;
  1714. /* Get vNIC configuration
  1715. */
  1716. err = enic_get_vnic_config(enic);
  1717. if (err) {
  1718. printk(KERN_ERR PFX
  1719. "Get vNIC configuration failed, aborting.\n");
  1720. return err;
  1721. }
  1722. /* Get available resource counts
  1723. */
  1724. enic_get_res_counts(enic);
  1725. /* Set interrupt mode based on resource counts and system
  1726. * capabilities
  1727. */
  1728. err = enic_set_intr_mode(enic);
  1729. if (err) {
  1730. printk(KERN_ERR PFX
  1731. "Failed to set intr mode based on resource "
  1732. "counts and system capabilities, aborting.\n");
  1733. return err;
  1734. }
  1735. /* Allocate and configure vNIC resources
  1736. */
  1737. err = enic_alloc_vnic_resources(enic);
  1738. if (err) {
  1739. printk(KERN_ERR PFX
  1740. "Failed to alloc vNIC resources, aborting.\n");
  1741. goto err_out_free_vnic_resources;
  1742. }
  1743. enic_init_vnic_resources(enic);
  1744. err = enic_set_rq_alloc_buf(enic);
  1745. if (err) {
  1746. printk(KERN_ERR PFX
  1747. "Failed to set RQ buffer allocator, aborting.\n");
  1748. goto err_out_free_vnic_resources;
  1749. }
  1750. err = enic_set_niccfg(enic);
  1751. if (err) {
  1752. printk(KERN_ERR PFX
  1753. "Failed to config nic, aborting.\n");
  1754. goto err_out_free_vnic_resources;
  1755. }
  1756. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  1757. default:
  1758. netif_napi_add(netdev, &enic->napi, enic_poll, 64);
  1759. break;
  1760. case VNIC_DEV_INTR_MODE_MSIX:
  1761. netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
  1762. break;
  1763. }
  1764. return 0;
  1765. err_out_free_vnic_resources:
  1766. enic_clear_intr_mode(enic);
  1767. enic_free_vnic_resources(enic);
  1768. return err;
  1769. }
  1770. static void enic_iounmap(struct enic *enic)
  1771. {
  1772. unsigned int i;
  1773. for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
  1774. if (enic->bar[i].vaddr)
  1775. iounmap(enic->bar[i].vaddr);
  1776. }
  1777. static int __devinit enic_probe(struct pci_dev *pdev,
  1778. const struct pci_device_id *ent)
  1779. {
  1780. struct net_device *netdev;
  1781. struct enic *enic;
  1782. int using_dac = 0;
  1783. unsigned int i;
  1784. int err;
  1785. /* Allocate net device structure and initialize. Private
  1786. * instance data is initialized to zero.
  1787. */
  1788. netdev = alloc_etherdev(sizeof(struct enic));
  1789. if (!netdev) {
  1790. printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
  1791. return -ENOMEM;
  1792. }
  1793. pci_set_drvdata(pdev, netdev);
  1794. SET_NETDEV_DEV(netdev, &pdev->dev);
  1795. enic = netdev_priv(netdev);
  1796. enic->netdev = netdev;
  1797. enic->pdev = pdev;
  1798. /* Setup PCI resources
  1799. */
  1800. err = pci_enable_device(pdev);
  1801. if (err) {
  1802. printk(KERN_ERR PFX
  1803. "Cannot enable PCI device, aborting.\n");
  1804. goto err_out_free_netdev;
  1805. }
  1806. err = pci_request_regions(pdev, DRV_NAME);
  1807. if (err) {
  1808. printk(KERN_ERR PFX
  1809. "Cannot request PCI regions, aborting.\n");
  1810. goto err_out_disable_device;
  1811. }
  1812. pci_set_master(pdev);
  1813. /* Query PCI controller on system for DMA addressing
  1814. * limitation for the device. Try 40-bit first, and
  1815. * fail to 32-bit.
  1816. */
  1817. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
  1818. if (err) {
  1819. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1820. if (err) {
  1821. printk(KERN_ERR PFX
  1822. "No usable DMA configuration, aborting.\n");
  1823. goto err_out_release_regions;
  1824. }
  1825. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1826. if (err) {
  1827. printk(KERN_ERR PFX
  1828. "Unable to obtain 32-bit DMA "
  1829. "for consistent allocations, aborting.\n");
  1830. goto err_out_release_regions;
  1831. }
  1832. } else {
  1833. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
  1834. if (err) {
  1835. printk(KERN_ERR PFX
  1836. "Unable to obtain 40-bit DMA "
  1837. "for consistent allocations, aborting.\n");
  1838. goto err_out_release_regions;
  1839. }
  1840. using_dac = 1;
  1841. }
  1842. /* Map vNIC resources from BAR0-5
  1843. */
  1844. for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
  1845. if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
  1846. continue;
  1847. enic->bar[i].len = pci_resource_len(pdev, i);
  1848. enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
  1849. if (!enic->bar[i].vaddr) {
  1850. printk(KERN_ERR PFX
  1851. "Cannot memory-map BAR %d, aborting.\n", i);
  1852. err = -ENODEV;
  1853. goto err_out_iounmap;
  1854. }
  1855. enic->bar[i].bus_addr = pci_resource_start(pdev, i);
  1856. }
  1857. /* Register vNIC device
  1858. */
  1859. enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
  1860. ARRAY_SIZE(enic->bar));
  1861. if (!enic->vdev) {
  1862. printk(KERN_ERR PFX
  1863. "vNIC registration failed, aborting.\n");
  1864. err = -ENODEV;
  1865. goto err_out_iounmap;
  1866. }
  1867. /* Issue device open to get device in known state
  1868. */
  1869. err = enic_dev_open(enic);
  1870. if (err) {
  1871. printk(KERN_ERR PFX
  1872. "vNIC dev open failed, aborting.\n");
  1873. goto err_out_vnic_unregister;
  1874. }
  1875. /* Issue device init to initialize the vnic-to-switch link.
  1876. * We'll start with carrier off and wait for link UP
  1877. * notification later to turn on carrier. We don't need
  1878. * to wait here for the vnic-to-switch link initialization
  1879. * to complete; link UP notification is the indication that
  1880. * the process is complete.
  1881. */
  1882. netif_carrier_off(netdev);
  1883. if (!enic_is_dynamic(enic)) {
  1884. err = vnic_dev_init(enic->vdev, 0);
  1885. if (err) {
  1886. printk(KERN_ERR PFX
  1887. "vNIC dev init failed, aborting.\n");
  1888. goto err_out_dev_close;
  1889. }
  1890. }
  1891. err = enic_dev_init(enic);
  1892. if (err) {
  1893. printk(KERN_ERR PFX
  1894. "Device initialization failed, aborting.\n");
  1895. goto err_out_dev_close;
  1896. }
  1897. /* Setup notification timer, HW reset task, and locks
  1898. */
  1899. init_timer(&enic->notify_timer);
  1900. enic->notify_timer.function = enic_notify_timer;
  1901. enic->notify_timer.data = (unsigned long)enic;
  1902. INIT_WORK(&enic->reset, enic_reset);
  1903. for (i = 0; i < enic->wq_count; i++)
  1904. spin_lock_init(&enic->wq_lock[i]);
  1905. spin_lock_init(&enic->devcmd_lock);
  1906. /* Register net device
  1907. */
  1908. enic->port_mtu = enic->config.mtu;
  1909. (void)enic_change_mtu(netdev, enic->port_mtu);
  1910. err = enic_set_mac_addr(netdev, enic->mac_addr);
  1911. if (err) {
  1912. printk(KERN_ERR PFX
  1913. "Invalid MAC address, aborting.\n");
  1914. goto err_out_dev_deinit;
  1915. }
  1916. enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
  1917. enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
  1918. if (enic_is_dynamic(enic))
  1919. netdev->netdev_ops = &enic_netdev_dynamic_ops;
  1920. else
  1921. netdev->netdev_ops = &enic_netdev_ops;
  1922. netdev->watchdog_timeo = 2 * HZ;
  1923. netdev->ethtool_ops = &enic_ethtool_ops;
  1924. netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  1925. if (ENIC_SETTING(enic, TXCSUM))
  1926. netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
  1927. if (ENIC_SETTING(enic, TSO))
  1928. netdev->features |= NETIF_F_TSO |
  1929. NETIF_F_TSO6 | NETIF_F_TSO_ECN;
  1930. if (ENIC_SETTING(enic, LRO))
  1931. netdev->features |= NETIF_F_LRO;
  1932. if (using_dac)
  1933. netdev->features |= NETIF_F_HIGHDMA;
  1934. enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
  1935. enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR;
  1936. enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC;
  1937. enic->lro_mgr.lro_arr = enic->lro_desc;
  1938. enic->lro_mgr.get_skb_header = enic_get_skb_header;
  1939. enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
  1940. enic->lro_mgr.dev = netdev;
  1941. enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE;
  1942. enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
  1943. err = register_netdev(netdev);
  1944. if (err) {
  1945. printk(KERN_ERR PFX
  1946. "Cannot register net device, aborting.\n");
  1947. goto err_out_dev_deinit;
  1948. }
  1949. return 0;
  1950. err_out_dev_deinit:
  1951. enic_dev_deinit(enic);
  1952. err_out_dev_close:
  1953. vnic_dev_close(enic->vdev);
  1954. err_out_vnic_unregister:
  1955. vnic_dev_unregister(enic->vdev);
  1956. err_out_iounmap:
  1957. enic_iounmap(enic);
  1958. err_out_release_regions:
  1959. pci_release_regions(pdev);
  1960. err_out_disable_device:
  1961. pci_disable_device(pdev);
  1962. err_out_free_netdev:
  1963. pci_set_drvdata(pdev, NULL);
  1964. free_netdev(netdev);
  1965. return err;
  1966. }
  1967. static void __devexit enic_remove(struct pci_dev *pdev)
  1968. {
  1969. struct net_device *netdev = pci_get_drvdata(pdev);
  1970. if (netdev) {
  1971. struct enic *enic = netdev_priv(netdev);
  1972. flush_scheduled_work();
  1973. unregister_netdev(netdev);
  1974. enic_dev_deinit(enic);
  1975. vnic_dev_close(enic->vdev);
  1976. vnic_dev_unregister(enic->vdev);
  1977. enic_iounmap(enic);
  1978. pci_release_regions(pdev);
  1979. pci_disable_device(pdev);
  1980. pci_set_drvdata(pdev, NULL);
  1981. free_netdev(netdev);
  1982. }
  1983. }
  1984. static struct pci_driver enic_driver = {
  1985. .name = DRV_NAME,
  1986. .id_table = enic_id_table,
  1987. .probe = enic_probe,
  1988. .remove = __devexit_p(enic_remove),
  1989. };
  1990. static int __init enic_init_module(void)
  1991. {
  1992. printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
  1993. return pci_register_driver(&enic_driver);
  1994. }
  1995. static void __exit enic_cleanup_module(void)
  1996. {
  1997. pci_unregister_driver(&enic_driver);
  1998. }
  1999. module_init(enic_init_module);
  2000. module_exit(enic_cleanup_module);