enic_main.c 60 KB

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