enic_main.c 60 KB

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