main.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/errno.h>
  38. #include <linux/pci.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/slab.h>
  41. #include <linux/io-mapping.h>
  42. #include <linux/delay.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/kmod.h>
  45. #include <linux/mlx4/device.h>
  46. #include <linux/mlx4/doorbell.h>
  47. #include "mlx4.h"
  48. #include "fw.h"
  49. #include "icm.h"
  50. MODULE_AUTHOR("Roland Dreier");
  51. MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
  52. MODULE_LICENSE("Dual BSD/GPL");
  53. MODULE_VERSION(DRV_VERSION);
  54. struct workqueue_struct *mlx4_wq;
  55. #ifdef CONFIG_MLX4_DEBUG
  56. int mlx4_debug_level = 0;
  57. module_param_named(debug_level, mlx4_debug_level, int, 0644);
  58. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
  59. #endif /* CONFIG_MLX4_DEBUG */
  60. #ifdef CONFIG_PCI_MSI
  61. static int msi_x = 1;
  62. module_param(msi_x, int, 0444);
  63. MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
  64. #else /* CONFIG_PCI_MSI */
  65. #define msi_x (0)
  66. #endif /* CONFIG_PCI_MSI */
  67. static int num_vfs;
  68. module_param(num_vfs, int, 0444);
  69. MODULE_PARM_DESC(num_vfs, "enable #num_vfs functions if num_vfs > 0");
  70. static int probe_vf;
  71. module_param(probe_vf, int, 0644);
  72. MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 0)");
  73. int mlx4_log_num_mgm_entry_size = MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE;
  74. module_param_named(log_num_mgm_entry_size,
  75. mlx4_log_num_mgm_entry_size, int, 0444);
  76. MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
  77. " of qp per mcg, for example:"
  78. " 10 gives 248.range: 7 <="
  79. " log_num_mgm_entry_size <= 12."
  80. " To activate device managed"
  81. " flow steering when available, set to -1");
  82. static bool enable_64b_cqe_eqe;
  83. module_param(enable_64b_cqe_eqe, bool, 0444);
  84. MODULE_PARM_DESC(enable_64b_cqe_eqe,
  85. "Enable 64 byte CQEs/EQEs when the FW supports this");
  86. #define HCA_GLOBAL_CAP_MASK 0
  87. #define PF_CONTEXT_BEHAVIOUR_MASK MLX4_FUNC_CAP_64B_EQE_CQE
  88. static char mlx4_version[] =
  89. DRV_NAME ": Mellanox ConnectX core driver v"
  90. DRV_VERSION " (" DRV_RELDATE ")\n";
  91. static struct mlx4_profile default_profile = {
  92. .num_qp = 1 << 18,
  93. .num_srq = 1 << 16,
  94. .rdmarc_per_qp = 1 << 4,
  95. .num_cq = 1 << 16,
  96. .num_mcg = 1 << 13,
  97. .num_mpt = 1 << 19,
  98. .num_mtt = 1 << 20, /* It is really num mtt segements */
  99. };
  100. static int log_num_mac = 7;
  101. module_param_named(log_num_mac, log_num_mac, int, 0444);
  102. MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
  103. static int log_num_vlan;
  104. module_param_named(log_num_vlan, log_num_vlan, int, 0444);
  105. MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
  106. /* Log2 max number of VLANs per ETH port (0-7) */
  107. #define MLX4_LOG_NUM_VLANS 7
  108. static bool use_prio;
  109. module_param_named(use_prio, use_prio, bool, 0444);
  110. MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
  111. "(0/1, default 0)");
  112. int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG);
  113. module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
  114. MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)");
  115. static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE};
  116. static int arr_argc = 2;
  117. module_param_array(port_type_array, int, &arr_argc, 0444);
  118. MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default "
  119. "1 for IB, 2 for Ethernet");
  120. struct mlx4_port_config {
  121. struct list_head list;
  122. enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
  123. struct pci_dev *pdev;
  124. };
  125. int mlx4_check_port_params(struct mlx4_dev *dev,
  126. enum mlx4_port_type *port_type)
  127. {
  128. int i;
  129. for (i = 0; i < dev->caps.num_ports - 1; i++) {
  130. if (port_type[i] != port_type[i + 1]) {
  131. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
  132. mlx4_err(dev, "Only same port types supported "
  133. "on this HCA, aborting.\n");
  134. return -EINVAL;
  135. }
  136. }
  137. }
  138. for (i = 0; i < dev->caps.num_ports; i++) {
  139. if (!(port_type[i] & dev->caps.supported_type[i+1])) {
  140. mlx4_err(dev, "Requested port type for port %d is not "
  141. "supported on this HCA\n", i + 1);
  142. return -EINVAL;
  143. }
  144. }
  145. return 0;
  146. }
  147. static void mlx4_set_port_mask(struct mlx4_dev *dev)
  148. {
  149. int i;
  150. for (i = 1; i <= dev->caps.num_ports; ++i)
  151. dev->caps.port_mask[i] = dev->caps.port_type[i];
  152. }
  153. static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
  154. {
  155. int err;
  156. int i;
  157. err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
  158. if (err) {
  159. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  160. return err;
  161. }
  162. if (dev_cap->min_page_sz > PAGE_SIZE) {
  163. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  164. "kernel PAGE_SIZE of %ld, aborting.\n",
  165. dev_cap->min_page_sz, PAGE_SIZE);
  166. return -ENODEV;
  167. }
  168. if (dev_cap->num_ports > MLX4_MAX_PORTS) {
  169. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  170. "aborting.\n",
  171. dev_cap->num_ports, MLX4_MAX_PORTS);
  172. return -ENODEV;
  173. }
  174. if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
  175. mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
  176. "PCI resource 2 size of 0x%llx, aborting.\n",
  177. dev_cap->uar_size,
  178. (unsigned long long) pci_resource_len(dev->pdev, 2));
  179. return -ENODEV;
  180. }
  181. dev->caps.num_ports = dev_cap->num_ports;
  182. dev->phys_caps.num_phys_eqs = MLX4_MAX_EQ_NUM;
  183. for (i = 1; i <= dev->caps.num_ports; ++i) {
  184. dev->caps.vl_cap[i] = dev_cap->max_vl[i];
  185. dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
  186. dev->phys_caps.gid_phys_table_len[i] = dev_cap->max_gids[i];
  187. dev->phys_caps.pkey_phys_table_len[i] = dev_cap->max_pkeys[i];
  188. /* set gid and pkey table operating lengths by default
  189. * to non-sriov values */
  190. dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
  191. dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
  192. dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
  193. dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
  194. dev->caps.def_mac[i] = dev_cap->def_mac[i];
  195. dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
  196. dev->caps.suggested_type[i] = dev_cap->suggested_type[i];
  197. dev->caps.default_sense[i] = dev_cap->default_sense[i];
  198. dev->caps.trans_type[i] = dev_cap->trans_type[i];
  199. dev->caps.vendor_oui[i] = dev_cap->vendor_oui[i];
  200. dev->caps.wavelength[i] = dev_cap->wavelength[i];
  201. dev->caps.trans_code[i] = dev_cap->trans_code[i];
  202. }
  203. dev->caps.uar_page_size = PAGE_SIZE;
  204. dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
  205. dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
  206. dev->caps.bf_reg_size = dev_cap->bf_reg_size;
  207. dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
  208. dev->caps.max_sq_sg = dev_cap->max_sq_sg;
  209. dev->caps.max_rq_sg = dev_cap->max_rq_sg;
  210. dev->caps.max_wqes = dev_cap->max_qp_sz;
  211. dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
  212. dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
  213. dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
  214. dev->caps.reserved_srqs = dev_cap->reserved_srqs;
  215. dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
  216. dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
  217. /*
  218. * Subtract 1 from the limit because we need to allocate a
  219. * spare CQE so the HCA HW can tell the difference between an
  220. * empty CQ and a full CQ.
  221. */
  222. dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
  223. dev->caps.reserved_cqs = dev_cap->reserved_cqs;
  224. dev->caps.reserved_eqs = dev_cap->reserved_eqs;
  225. dev->caps.reserved_mtts = dev_cap->reserved_mtts;
  226. dev->caps.reserved_mrws = dev_cap->reserved_mrws;
  227. /* The first 128 UARs are used for EQ doorbells */
  228. dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars);
  229. dev->caps.reserved_pds = dev_cap->reserved_pds;
  230. dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  231. dev_cap->reserved_xrcds : 0;
  232. dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  233. dev_cap->max_xrcds : 0;
  234. dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz;
  235. dev->caps.max_msg_sz = dev_cap->max_msg_sz;
  236. dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
  237. dev->caps.flags = dev_cap->flags;
  238. dev->caps.flags2 = dev_cap->flags2;
  239. dev->caps.bmme_flags = dev_cap->bmme_flags;
  240. dev->caps.reserved_lkey = dev_cap->reserved_lkey;
  241. dev->caps.stat_rate_support = dev_cap->stat_rate_support;
  242. dev->caps.max_gso_sz = dev_cap->max_gso_sz;
  243. dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz;
  244. /* Sense port always allowed on supported devices for ConnectX-1 and -2 */
  245. if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT)
  246. dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
  247. /* Don't do sense port on multifunction devices (for now at least) */
  248. if (mlx4_is_mfunc(dev))
  249. dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
  250. dev->caps.log_num_macs = log_num_mac;
  251. dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
  252. dev->caps.log_num_prios = use_prio ? 3 : 0;
  253. for (i = 1; i <= dev->caps.num_ports; ++i) {
  254. dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE;
  255. if (dev->caps.supported_type[i]) {
  256. /* if only ETH is supported - assign ETH */
  257. if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH)
  258. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  259. /* if only IB is supported, assign IB */
  260. else if (dev->caps.supported_type[i] ==
  261. MLX4_PORT_TYPE_IB)
  262. dev->caps.port_type[i] = MLX4_PORT_TYPE_IB;
  263. else {
  264. /* if IB and ETH are supported, we set the port
  265. * type according to user selection of port type;
  266. * if user selected none, take the FW hint */
  267. if (port_type_array[i - 1] == MLX4_PORT_TYPE_NONE)
  268. dev->caps.port_type[i] = dev->caps.suggested_type[i] ?
  269. MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB;
  270. else
  271. dev->caps.port_type[i] = port_type_array[i - 1];
  272. }
  273. }
  274. /*
  275. * Link sensing is allowed on the port if 3 conditions are true:
  276. * 1. Both protocols are supported on the port.
  277. * 2. Different types are supported on the port
  278. * 3. FW declared that it supports link sensing
  279. */
  280. mlx4_priv(dev)->sense.sense_allowed[i] =
  281. ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) &&
  282. (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  283. (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT));
  284. /*
  285. * If "default_sense" bit is set, we move the port to "AUTO" mode
  286. * and perform sense_port FW command to try and set the correct
  287. * port type from beginning
  288. */
  289. if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) {
  290. enum mlx4_port_type sensed_port = MLX4_PORT_TYPE_NONE;
  291. dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO;
  292. mlx4_SENSE_PORT(dev, i, &sensed_port);
  293. if (sensed_port != MLX4_PORT_TYPE_NONE)
  294. dev->caps.port_type[i] = sensed_port;
  295. } else {
  296. dev->caps.possible_type[i] = dev->caps.port_type[i];
  297. }
  298. if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) {
  299. dev->caps.log_num_macs = dev_cap->log_max_macs[i];
  300. mlx4_warn(dev, "Requested number of MACs is too much "
  301. "for port %d, reducing to %d.\n",
  302. i, 1 << dev->caps.log_num_macs);
  303. }
  304. if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) {
  305. dev->caps.log_num_vlans = dev_cap->log_max_vlans[i];
  306. mlx4_warn(dev, "Requested number of VLANs is too much "
  307. "for port %d, reducing to %d.\n",
  308. i, 1 << dev->caps.log_num_vlans);
  309. }
  310. }
  311. dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters);
  312. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps;
  313. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] =
  314. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] =
  315. (1 << dev->caps.log_num_macs) *
  316. (1 << dev->caps.log_num_vlans) *
  317. (1 << dev->caps.log_num_prios) *
  318. dev->caps.num_ports;
  319. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH;
  320. dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] +
  321. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] +
  322. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] +
  323. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH];
  324. dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0;
  325. if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) {
  326. if (dev_cap->flags &
  327. (MLX4_DEV_CAP_FLAG_64B_CQE | MLX4_DEV_CAP_FLAG_64B_EQE)) {
  328. mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n");
  329. dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE;
  330. dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE;
  331. }
  332. }
  333. if ((dev->caps.flags &
  334. (MLX4_DEV_CAP_FLAG_64B_CQE | MLX4_DEV_CAP_FLAG_64B_EQE)) &&
  335. mlx4_is_master(dev))
  336. dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE;
  337. return 0;
  338. }
  339. /*The function checks if there are live vf, return the num of them*/
  340. static int mlx4_how_many_lives_vf(struct mlx4_dev *dev)
  341. {
  342. struct mlx4_priv *priv = mlx4_priv(dev);
  343. struct mlx4_slave_state *s_state;
  344. int i;
  345. int ret = 0;
  346. for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) {
  347. s_state = &priv->mfunc.master.slave_state[i];
  348. if (s_state->active && s_state->last_cmd !=
  349. MLX4_COMM_CMD_RESET) {
  350. mlx4_warn(dev, "%s: slave: %d is still active\n",
  351. __func__, i);
  352. ret++;
  353. }
  354. }
  355. return ret;
  356. }
  357. int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey)
  358. {
  359. u32 qk = MLX4_RESERVED_QKEY_BASE;
  360. if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX ||
  361. qpn < dev->phys_caps.base_proxy_sqpn)
  362. return -EINVAL;
  363. if (qpn >= dev->phys_caps.base_tunnel_sqpn)
  364. /* tunnel qp */
  365. qk += qpn - dev->phys_caps.base_tunnel_sqpn;
  366. else
  367. qk += qpn - dev->phys_caps.base_proxy_sqpn;
  368. *qkey = qk;
  369. return 0;
  370. }
  371. EXPORT_SYMBOL(mlx4_get_parav_qkey);
  372. void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val)
  373. {
  374. struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev);
  375. if (!mlx4_is_master(dev))
  376. return;
  377. priv->virt2phys_pkey[slave][port - 1][i] = val;
  378. }
  379. EXPORT_SYMBOL(mlx4_sync_pkey_table);
  380. void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid)
  381. {
  382. struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev);
  383. if (!mlx4_is_master(dev))
  384. return;
  385. priv->slave_node_guids[slave] = guid;
  386. }
  387. EXPORT_SYMBOL(mlx4_put_slave_node_guid);
  388. __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave)
  389. {
  390. struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev);
  391. if (!mlx4_is_master(dev))
  392. return 0;
  393. return priv->slave_node_guids[slave];
  394. }
  395. EXPORT_SYMBOL(mlx4_get_slave_node_guid);
  396. int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
  397. {
  398. struct mlx4_priv *priv = mlx4_priv(dev);
  399. struct mlx4_slave_state *s_slave;
  400. if (!mlx4_is_master(dev))
  401. return 0;
  402. s_slave = &priv->mfunc.master.slave_state[slave];
  403. return !!s_slave->active;
  404. }
  405. EXPORT_SYMBOL(mlx4_is_slave_active);
  406. static void slave_adjust_steering_mode(struct mlx4_dev *dev,
  407. struct mlx4_dev_cap *dev_cap,
  408. struct mlx4_init_hca_param *hca_param)
  409. {
  410. dev->caps.steering_mode = hca_param->steering_mode;
  411. if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) {
  412. dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry;
  413. dev->caps.fs_log_max_ucast_qp_range_size =
  414. dev_cap->fs_log_max_ucast_qp_range_size;
  415. } else
  416. dev->caps.num_qp_per_mgm =
  417. 4 * ((1 << hca_param->log_mc_entry_sz)/16 - 2);
  418. mlx4_dbg(dev, "Steering mode is: %s\n",
  419. mlx4_steering_mode_str(dev->caps.steering_mode));
  420. }
  421. static int mlx4_slave_cap(struct mlx4_dev *dev)
  422. {
  423. int err;
  424. u32 page_size;
  425. struct mlx4_dev_cap dev_cap;
  426. struct mlx4_func_cap func_cap;
  427. struct mlx4_init_hca_param hca_param;
  428. int i;
  429. memset(&hca_param, 0, sizeof(hca_param));
  430. err = mlx4_QUERY_HCA(dev, &hca_param);
  431. if (err) {
  432. mlx4_err(dev, "QUERY_HCA command failed, aborting.\n");
  433. return err;
  434. }
  435. /*fail if the hca has an unknown capability */
  436. if ((hca_param.global_caps | HCA_GLOBAL_CAP_MASK) !=
  437. HCA_GLOBAL_CAP_MASK) {
  438. mlx4_err(dev, "Unknown hca global capabilities\n");
  439. return -ENOSYS;
  440. }
  441. mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz;
  442. dev->caps.hca_core_clock = hca_param.hca_core_clock;
  443. memset(&dev_cap, 0, sizeof(dev_cap));
  444. dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp;
  445. err = mlx4_dev_cap(dev, &dev_cap);
  446. if (err) {
  447. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  448. return err;
  449. }
  450. err = mlx4_QUERY_FW(dev);
  451. if (err)
  452. mlx4_err(dev, "QUERY_FW command failed: could not get FW version.\n");
  453. page_size = ~dev->caps.page_size_cap + 1;
  454. mlx4_warn(dev, "HCA minimum page size:%d\n", page_size);
  455. if (page_size > PAGE_SIZE) {
  456. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  457. "kernel PAGE_SIZE of %ld, aborting.\n",
  458. page_size, PAGE_SIZE);
  459. return -ENODEV;
  460. }
  461. /* slave gets uar page size from QUERY_HCA fw command */
  462. dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12);
  463. /* TODO: relax this assumption */
  464. if (dev->caps.uar_page_size != PAGE_SIZE) {
  465. mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n",
  466. dev->caps.uar_page_size, PAGE_SIZE);
  467. return -ENODEV;
  468. }
  469. memset(&func_cap, 0, sizeof(func_cap));
  470. err = mlx4_QUERY_FUNC_CAP(dev, 0, &func_cap);
  471. if (err) {
  472. mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d).\n",
  473. err);
  474. return err;
  475. }
  476. if ((func_cap.pf_context_behaviour | PF_CONTEXT_BEHAVIOUR_MASK) !=
  477. PF_CONTEXT_BEHAVIOUR_MASK) {
  478. mlx4_err(dev, "Unknown pf context behaviour\n");
  479. return -ENOSYS;
  480. }
  481. dev->caps.num_ports = func_cap.num_ports;
  482. dev->quotas.qp = func_cap.qp_quota;
  483. dev->quotas.srq = func_cap.srq_quota;
  484. dev->quotas.cq = func_cap.cq_quota;
  485. dev->quotas.mpt = func_cap.mpt_quota;
  486. dev->quotas.mtt = func_cap.mtt_quota;
  487. dev->caps.num_qps = 1 << hca_param.log_num_qps;
  488. dev->caps.num_srqs = 1 << hca_param.log_num_srqs;
  489. dev->caps.num_cqs = 1 << hca_param.log_num_cqs;
  490. dev->caps.num_mpts = 1 << hca_param.log_mpt_sz;
  491. dev->caps.num_eqs = func_cap.max_eq;
  492. dev->caps.reserved_eqs = func_cap.reserved_eq;
  493. dev->caps.num_pds = MLX4_NUM_PDS;
  494. dev->caps.num_mgms = 0;
  495. dev->caps.num_amgms = 0;
  496. if (dev->caps.num_ports > MLX4_MAX_PORTS) {
  497. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  498. "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS);
  499. return -ENODEV;
  500. }
  501. dev->caps.qp0_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL);
  502. dev->caps.qp0_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL);
  503. dev->caps.qp1_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL);
  504. dev->caps.qp1_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL);
  505. if (!dev->caps.qp0_tunnel || !dev->caps.qp0_proxy ||
  506. !dev->caps.qp1_tunnel || !dev->caps.qp1_proxy) {
  507. err = -ENOMEM;
  508. goto err_mem;
  509. }
  510. for (i = 1; i <= dev->caps.num_ports; ++i) {
  511. err = mlx4_QUERY_FUNC_CAP(dev, (u32) i, &func_cap);
  512. if (err) {
  513. mlx4_err(dev, "QUERY_FUNC_CAP port command failed for"
  514. " port %d, aborting (%d).\n", i, err);
  515. goto err_mem;
  516. }
  517. dev->caps.qp0_tunnel[i - 1] = func_cap.qp0_tunnel_qpn;
  518. dev->caps.qp0_proxy[i - 1] = func_cap.qp0_proxy_qpn;
  519. dev->caps.qp1_tunnel[i - 1] = func_cap.qp1_tunnel_qpn;
  520. dev->caps.qp1_proxy[i - 1] = func_cap.qp1_proxy_qpn;
  521. dev->caps.port_mask[i] = dev->caps.port_type[i];
  522. if (mlx4_get_slave_pkey_gid_tbl_len(dev, i,
  523. &dev->caps.gid_table_len[i],
  524. &dev->caps.pkey_table_len[i]))
  525. goto err_mem;
  526. }
  527. if (dev->caps.uar_page_size * (dev->caps.num_uars -
  528. dev->caps.reserved_uars) >
  529. pci_resource_len(dev->pdev, 2)) {
  530. mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than "
  531. "PCI resource 2 size of 0x%llx, aborting.\n",
  532. dev->caps.uar_page_size * dev->caps.num_uars,
  533. (unsigned long long) pci_resource_len(dev->pdev, 2));
  534. goto err_mem;
  535. }
  536. if (hca_param.dev_cap_enabled & MLX4_DEV_CAP_64B_EQE_ENABLED) {
  537. dev->caps.eqe_size = 64;
  538. dev->caps.eqe_factor = 1;
  539. } else {
  540. dev->caps.eqe_size = 32;
  541. dev->caps.eqe_factor = 0;
  542. }
  543. if (hca_param.dev_cap_enabled & MLX4_DEV_CAP_64B_CQE_ENABLED) {
  544. dev->caps.cqe_size = 64;
  545. dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_64B_CQE;
  546. } else {
  547. dev->caps.cqe_size = 32;
  548. }
  549. dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS;
  550. mlx4_warn(dev, "Timestamping is not supported in slave mode.\n");
  551. slave_adjust_steering_mode(dev, &dev_cap, &hca_param);
  552. return 0;
  553. err_mem:
  554. kfree(dev->caps.qp0_tunnel);
  555. kfree(dev->caps.qp0_proxy);
  556. kfree(dev->caps.qp1_tunnel);
  557. kfree(dev->caps.qp1_proxy);
  558. dev->caps.qp0_tunnel = dev->caps.qp0_proxy =
  559. dev->caps.qp1_tunnel = dev->caps.qp1_proxy = NULL;
  560. return err;
  561. }
  562. static void mlx4_request_modules(struct mlx4_dev *dev)
  563. {
  564. int port;
  565. int has_ib_port = false;
  566. int has_eth_port = false;
  567. #define EN_DRV_NAME "mlx4_en"
  568. #define IB_DRV_NAME "mlx4_ib"
  569. for (port = 1; port <= dev->caps.num_ports; port++) {
  570. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_IB)
  571. has_ib_port = true;
  572. else if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
  573. has_eth_port = true;
  574. }
  575. if (has_ib_port)
  576. request_module_nowait(IB_DRV_NAME);
  577. if (has_eth_port)
  578. request_module_nowait(EN_DRV_NAME);
  579. }
  580. /*
  581. * Change the port configuration of the device.
  582. * Every user of this function must hold the port mutex.
  583. */
  584. int mlx4_change_port_types(struct mlx4_dev *dev,
  585. enum mlx4_port_type *port_types)
  586. {
  587. int err = 0;
  588. int change = 0;
  589. int port;
  590. for (port = 0; port < dev->caps.num_ports; port++) {
  591. /* Change the port type only if the new type is different
  592. * from the current, and not set to Auto */
  593. if (port_types[port] != dev->caps.port_type[port + 1])
  594. change = 1;
  595. }
  596. if (change) {
  597. mlx4_unregister_device(dev);
  598. for (port = 1; port <= dev->caps.num_ports; port++) {
  599. mlx4_CLOSE_PORT(dev, port);
  600. dev->caps.port_type[port] = port_types[port - 1];
  601. err = mlx4_SET_PORT(dev, port, -1);
  602. if (err) {
  603. mlx4_err(dev, "Failed to set port %d, "
  604. "aborting\n", port);
  605. goto out;
  606. }
  607. }
  608. mlx4_set_port_mask(dev);
  609. err = mlx4_register_device(dev);
  610. if (err) {
  611. mlx4_err(dev, "Failed to register device\n");
  612. goto out;
  613. }
  614. mlx4_request_modules(dev);
  615. }
  616. out:
  617. return err;
  618. }
  619. static ssize_t show_port_type(struct device *dev,
  620. struct device_attribute *attr,
  621. char *buf)
  622. {
  623. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  624. port_attr);
  625. struct mlx4_dev *mdev = info->dev;
  626. char type[8];
  627. sprintf(type, "%s",
  628. (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
  629. "ib" : "eth");
  630. if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO)
  631. sprintf(buf, "auto (%s)\n", type);
  632. else
  633. sprintf(buf, "%s\n", type);
  634. return strlen(buf);
  635. }
  636. static ssize_t set_port_type(struct device *dev,
  637. struct device_attribute *attr,
  638. const char *buf, size_t count)
  639. {
  640. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  641. port_attr);
  642. struct mlx4_dev *mdev = info->dev;
  643. struct mlx4_priv *priv = mlx4_priv(mdev);
  644. enum mlx4_port_type types[MLX4_MAX_PORTS];
  645. enum mlx4_port_type new_types[MLX4_MAX_PORTS];
  646. int i;
  647. int err = 0;
  648. if (!strcmp(buf, "ib\n"))
  649. info->tmp_type = MLX4_PORT_TYPE_IB;
  650. else if (!strcmp(buf, "eth\n"))
  651. info->tmp_type = MLX4_PORT_TYPE_ETH;
  652. else if (!strcmp(buf, "auto\n"))
  653. info->tmp_type = MLX4_PORT_TYPE_AUTO;
  654. else {
  655. mlx4_err(mdev, "%s is not supported port type\n", buf);
  656. return -EINVAL;
  657. }
  658. mlx4_stop_sense(mdev);
  659. mutex_lock(&priv->port_mutex);
  660. /* Possible type is always the one that was delivered */
  661. mdev->caps.possible_type[info->port] = info->tmp_type;
  662. for (i = 0; i < mdev->caps.num_ports; i++) {
  663. types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type :
  664. mdev->caps.possible_type[i+1];
  665. if (types[i] == MLX4_PORT_TYPE_AUTO)
  666. types[i] = mdev->caps.port_type[i+1];
  667. }
  668. if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  669. !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) {
  670. for (i = 1; i <= mdev->caps.num_ports; i++) {
  671. if (mdev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
  672. mdev->caps.possible_type[i] = mdev->caps.port_type[i];
  673. err = -EINVAL;
  674. }
  675. }
  676. }
  677. if (err) {
  678. mlx4_err(mdev, "Auto sensing is not supported on this HCA. "
  679. "Set only 'eth' or 'ib' for both ports "
  680. "(should be the same)\n");
  681. goto out;
  682. }
  683. mlx4_do_sense_ports(mdev, new_types, types);
  684. err = mlx4_check_port_params(mdev, new_types);
  685. if (err)
  686. goto out;
  687. /* We are about to apply the changes after the configuration
  688. * was verified, no need to remember the temporary types
  689. * any more */
  690. for (i = 0; i < mdev->caps.num_ports; i++)
  691. priv->port[i + 1].tmp_type = 0;
  692. err = mlx4_change_port_types(mdev, new_types);
  693. out:
  694. mlx4_start_sense(mdev);
  695. mutex_unlock(&priv->port_mutex);
  696. return err ? err : count;
  697. }
  698. enum ibta_mtu {
  699. IB_MTU_256 = 1,
  700. IB_MTU_512 = 2,
  701. IB_MTU_1024 = 3,
  702. IB_MTU_2048 = 4,
  703. IB_MTU_4096 = 5
  704. };
  705. static inline int int_to_ibta_mtu(int mtu)
  706. {
  707. switch (mtu) {
  708. case 256: return IB_MTU_256;
  709. case 512: return IB_MTU_512;
  710. case 1024: return IB_MTU_1024;
  711. case 2048: return IB_MTU_2048;
  712. case 4096: return IB_MTU_4096;
  713. default: return -1;
  714. }
  715. }
  716. static inline int ibta_mtu_to_int(enum ibta_mtu mtu)
  717. {
  718. switch (mtu) {
  719. case IB_MTU_256: return 256;
  720. case IB_MTU_512: return 512;
  721. case IB_MTU_1024: return 1024;
  722. case IB_MTU_2048: return 2048;
  723. case IB_MTU_4096: return 4096;
  724. default: return -1;
  725. }
  726. }
  727. static ssize_t show_port_ib_mtu(struct device *dev,
  728. struct device_attribute *attr,
  729. char *buf)
  730. {
  731. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  732. port_mtu_attr);
  733. struct mlx4_dev *mdev = info->dev;
  734. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH)
  735. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  736. sprintf(buf, "%d\n",
  737. ibta_mtu_to_int(mdev->caps.port_ib_mtu[info->port]));
  738. return strlen(buf);
  739. }
  740. static ssize_t set_port_ib_mtu(struct device *dev,
  741. struct device_attribute *attr,
  742. const char *buf, size_t count)
  743. {
  744. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  745. port_mtu_attr);
  746. struct mlx4_dev *mdev = info->dev;
  747. struct mlx4_priv *priv = mlx4_priv(mdev);
  748. int err, port, mtu, ibta_mtu = -1;
  749. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) {
  750. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  751. return -EINVAL;
  752. }
  753. err = kstrtoint(buf, 0, &mtu);
  754. if (!err)
  755. ibta_mtu = int_to_ibta_mtu(mtu);
  756. if (err || ibta_mtu < 0) {
  757. mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
  758. return -EINVAL;
  759. }
  760. mdev->caps.port_ib_mtu[info->port] = ibta_mtu;
  761. mlx4_stop_sense(mdev);
  762. mutex_lock(&priv->port_mutex);
  763. mlx4_unregister_device(mdev);
  764. for (port = 1; port <= mdev->caps.num_ports; port++) {
  765. mlx4_CLOSE_PORT(mdev, port);
  766. err = mlx4_SET_PORT(mdev, port, -1);
  767. if (err) {
  768. mlx4_err(mdev, "Failed to set port %d, "
  769. "aborting\n", port);
  770. goto err_set_port;
  771. }
  772. }
  773. err = mlx4_register_device(mdev);
  774. err_set_port:
  775. mutex_unlock(&priv->port_mutex);
  776. mlx4_start_sense(mdev);
  777. return err ? err : count;
  778. }
  779. static int mlx4_load_fw(struct mlx4_dev *dev)
  780. {
  781. struct mlx4_priv *priv = mlx4_priv(dev);
  782. int err;
  783. priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
  784. GFP_HIGHUSER | __GFP_NOWARN, 0);
  785. if (!priv->fw.fw_icm) {
  786. mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
  787. return -ENOMEM;
  788. }
  789. err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
  790. if (err) {
  791. mlx4_err(dev, "MAP_FA command failed, aborting.\n");
  792. goto err_free;
  793. }
  794. err = mlx4_RUN_FW(dev);
  795. if (err) {
  796. mlx4_err(dev, "RUN_FW command failed, aborting.\n");
  797. goto err_unmap_fa;
  798. }
  799. return 0;
  800. err_unmap_fa:
  801. mlx4_UNMAP_FA(dev);
  802. err_free:
  803. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  804. return err;
  805. }
  806. static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
  807. int cmpt_entry_sz)
  808. {
  809. struct mlx4_priv *priv = mlx4_priv(dev);
  810. int err;
  811. int num_eqs;
  812. err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
  813. cmpt_base +
  814. ((u64) (MLX4_CMPT_TYPE_QP *
  815. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  816. cmpt_entry_sz, dev->caps.num_qps,
  817. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  818. 0, 0);
  819. if (err)
  820. goto err;
  821. err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
  822. cmpt_base +
  823. ((u64) (MLX4_CMPT_TYPE_SRQ *
  824. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  825. cmpt_entry_sz, dev->caps.num_srqs,
  826. dev->caps.reserved_srqs, 0, 0);
  827. if (err)
  828. goto err_qp;
  829. err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
  830. cmpt_base +
  831. ((u64) (MLX4_CMPT_TYPE_CQ *
  832. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  833. cmpt_entry_sz, dev->caps.num_cqs,
  834. dev->caps.reserved_cqs, 0, 0);
  835. if (err)
  836. goto err_srq;
  837. num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
  838. dev->caps.num_eqs;
  839. err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
  840. cmpt_base +
  841. ((u64) (MLX4_CMPT_TYPE_EQ *
  842. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  843. cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
  844. if (err)
  845. goto err_cq;
  846. return 0;
  847. err_cq:
  848. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  849. err_srq:
  850. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  851. err_qp:
  852. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  853. err:
  854. return err;
  855. }
  856. static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
  857. struct mlx4_init_hca_param *init_hca, u64 icm_size)
  858. {
  859. struct mlx4_priv *priv = mlx4_priv(dev);
  860. u64 aux_pages;
  861. int num_eqs;
  862. int err;
  863. err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
  864. if (err) {
  865. mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
  866. return err;
  867. }
  868. mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
  869. (unsigned long long) icm_size >> 10,
  870. (unsigned long long) aux_pages << 2);
  871. priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
  872. GFP_HIGHUSER | __GFP_NOWARN, 0);
  873. if (!priv->fw.aux_icm) {
  874. mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
  875. return -ENOMEM;
  876. }
  877. err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
  878. if (err) {
  879. mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
  880. goto err_free_aux;
  881. }
  882. err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
  883. if (err) {
  884. mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
  885. goto err_unmap_aux;
  886. }
  887. num_eqs = (mlx4_is_master(dev)) ? dev->phys_caps.num_phys_eqs :
  888. dev->caps.num_eqs;
  889. err = mlx4_init_icm_table(dev, &priv->eq_table.table,
  890. init_hca->eqc_base, dev_cap->eqc_entry_sz,
  891. num_eqs, num_eqs, 0, 0);
  892. if (err) {
  893. mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
  894. goto err_unmap_cmpt;
  895. }
  896. /*
  897. * Reserved MTT entries must be aligned up to a cacheline
  898. * boundary, since the FW will write to them, while the driver
  899. * writes to all other MTT entries. (The variable
  900. * dev->caps.mtt_entry_sz below is really the MTT segment
  901. * size, not the raw entry size)
  902. */
  903. dev->caps.reserved_mtts =
  904. ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
  905. dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
  906. err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
  907. init_hca->mtt_base,
  908. dev->caps.mtt_entry_sz,
  909. dev->caps.num_mtts,
  910. dev->caps.reserved_mtts, 1, 0);
  911. if (err) {
  912. mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
  913. goto err_unmap_eq;
  914. }
  915. err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
  916. init_hca->dmpt_base,
  917. dev_cap->dmpt_entry_sz,
  918. dev->caps.num_mpts,
  919. dev->caps.reserved_mrws, 1, 1);
  920. if (err) {
  921. mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
  922. goto err_unmap_mtt;
  923. }
  924. err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
  925. init_hca->qpc_base,
  926. dev_cap->qpc_entry_sz,
  927. dev->caps.num_qps,
  928. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  929. 0, 0);
  930. if (err) {
  931. mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
  932. goto err_unmap_dmpt;
  933. }
  934. err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
  935. init_hca->auxc_base,
  936. dev_cap->aux_entry_sz,
  937. dev->caps.num_qps,
  938. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  939. 0, 0);
  940. if (err) {
  941. mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
  942. goto err_unmap_qp;
  943. }
  944. err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
  945. init_hca->altc_base,
  946. dev_cap->altc_entry_sz,
  947. dev->caps.num_qps,
  948. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  949. 0, 0);
  950. if (err) {
  951. mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
  952. goto err_unmap_auxc;
  953. }
  954. err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
  955. init_hca->rdmarc_base,
  956. dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
  957. dev->caps.num_qps,
  958. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  959. 0, 0);
  960. if (err) {
  961. mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
  962. goto err_unmap_altc;
  963. }
  964. err = mlx4_init_icm_table(dev, &priv->cq_table.table,
  965. init_hca->cqc_base,
  966. dev_cap->cqc_entry_sz,
  967. dev->caps.num_cqs,
  968. dev->caps.reserved_cqs, 0, 0);
  969. if (err) {
  970. mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
  971. goto err_unmap_rdmarc;
  972. }
  973. err = mlx4_init_icm_table(dev, &priv->srq_table.table,
  974. init_hca->srqc_base,
  975. dev_cap->srq_entry_sz,
  976. dev->caps.num_srqs,
  977. dev->caps.reserved_srqs, 0, 0);
  978. if (err) {
  979. mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
  980. goto err_unmap_cq;
  981. }
  982. /*
  983. * For flow steering device managed mode it is required to use
  984. * mlx4_init_icm_table. For B0 steering mode it's not strictly
  985. * required, but for simplicity just map the whole multicast
  986. * group table now. The table isn't very big and it's a lot
  987. * easier than trying to track ref counts.
  988. */
  989. err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
  990. init_hca->mc_base,
  991. mlx4_get_mgm_entry_size(dev),
  992. dev->caps.num_mgms + dev->caps.num_amgms,
  993. dev->caps.num_mgms + dev->caps.num_amgms,
  994. 0, 0);
  995. if (err) {
  996. mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
  997. goto err_unmap_srq;
  998. }
  999. return 0;
  1000. err_unmap_srq:
  1001. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  1002. err_unmap_cq:
  1003. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  1004. err_unmap_rdmarc:
  1005. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  1006. err_unmap_altc:
  1007. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  1008. err_unmap_auxc:
  1009. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  1010. err_unmap_qp:
  1011. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  1012. err_unmap_dmpt:
  1013. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  1014. err_unmap_mtt:
  1015. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  1016. err_unmap_eq:
  1017. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  1018. err_unmap_cmpt:
  1019. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  1020. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  1021. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  1022. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  1023. err_unmap_aux:
  1024. mlx4_UNMAP_ICM_AUX(dev);
  1025. err_free_aux:
  1026. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  1027. return err;
  1028. }
  1029. static void mlx4_free_icms(struct mlx4_dev *dev)
  1030. {
  1031. struct mlx4_priv *priv = mlx4_priv(dev);
  1032. mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
  1033. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  1034. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  1035. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  1036. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  1037. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  1038. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  1039. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  1040. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  1041. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  1042. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  1043. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  1044. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  1045. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  1046. mlx4_UNMAP_ICM_AUX(dev);
  1047. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  1048. }
  1049. static void mlx4_slave_exit(struct mlx4_dev *dev)
  1050. {
  1051. struct mlx4_priv *priv = mlx4_priv(dev);
  1052. mutex_lock(&priv->cmd.slave_cmd_mutex);
  1053. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME))
  1054. mlx4_warn(dev, "Failed to close slave function.\n");
  1055. mutex_unlock(&priv->cmd.slave_cmd_mutex);
  1056. }
  1057. static int map_bf_area(struct mlx4_dev *dev)
  1058. {
  1059. struct mlx4_priv *priv = mlx4_priv(dev);
  1060. resource_size_t bf_start;
  1061. resource_size_t bf_len;
  1062. int err = 0;
  1063. if (!dev->caps.bf_reg_size)
  1064. return -ENXIO;
  1065. bf_start = pci_resource_start(dev->pdev, 2) +
  1066. (dev->caps.num_uars << PAGE_SHIFT);
  1067. bf_len = pci_resource_len(dev->pdev, 2) -
  1068. (dev->caps.num_uars << PAGE_SHIFT);
  1069. priv->bf_mapping = io_mapping_create_wc(bf_start, bf_len);
  1070. if (!priv->bf_mapping)
  1071. err = -ENOMEM;
  1072. return err;
  1073. }
  1074. static void unmap_bf_area(struct mlx4_dev *dev)
  1075. {
  1076. if (mlx4_priv(dev)->bf_mapping)
  1077. io_mapping_free(mlx4_priv(dev)->bf_mapping);
  1078. }
  1079. cycle_t mlx4_read_clock(struct mlx4_dev *dev)
  1080. {
  1081. u32 clockhi, clocklo, clockhi1;
  1082. cycle_t cycles;
  1083. int i;
  1084. struct mlx4_priv *priv = mlx4_priv(dev);
  1085. for (i = 0; i < 10; i++) {
  1086. clockhi = swab32(readl(priv->clock_mapping));
  1087. clocklo = swab32(readl(priv->clock_mapping + 4));
  1088. clockhi1 = swab32(readl(priv->clock_mapping));
  1089. if (clockhi == clockhi1)
  1090. break;
  1091. }
  1092. cycles = (u64) clockhi << 32 | (u64) clocklo;
  1093. return cycles;
  1094. }
  1095. EXPORT_SYMBOL_GPL(mlx4_read_clock);
  1096. static int map_internal_clock(struct mlx4_dev *dev)
  1097. {
  1098. struct mlx4_priv *priv = mlx4_priv(dev);
  1099. priv->clock_mapping =
  1100. ioremap(pci_resource_start(dev->pdev, priv->fw.clock_bar) +
  1101. priv->fw.clock_offset, MLX4_CLOCK_SIZE);
  1102. if (!priv->clock_mapping)
  1103. return -ENOMEM;
  1104. return 0;
  1105. }
  1106. static void unmap_internal_clock(struct mlx4_dev *dev)
  1107. {
  1108. struct mlx4_priv *priv = mlx4_priv(dev);
  1109. if (priv->clock_mapping)
  1110. iounmap(priv->clock_mapping);
  1111. }
  1112. static void mlx4_close_hca(struct mlx4_dev *dev)
  1113. {
  1114. unmap_internal_clock(dev);
  1115. unmap_bf_area(dev);
  1116. if (mlx4_is_slave(dev))
  1117. mlx4_slave_exit(dev);
  1118. else {
  1119. mlx4_CLOSE_HCA(dev, 0);
  1120. mlx4_free_icms(dev);
  1121. mlx4_UNMAP_FA(dev);
  1122. mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
  1123. }
  1124. }
  1125. static int mlx4_init_slave(struct mlx4_dev *dev)
  1126. {
  1127. struct mlx4_priv *priv = mlx4_priv(dev);
  1128. u64 dma = (u64) priv->mfunc.vhcr_dma;
  1129. int ret_from_reset = 0;
  1130. u32 slave_read;
  1131. u32 cmd_channel_ver;
  1132. mutex_lock(&priv->cmd.slave_cmd_mutex);
  1133. priv->cmd.max_cmds = 1;
  1134. mlx4_warn(dev, "Sending reset\n");
  1135. ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0,
  1136. MLX4_COMM_TIME);
  1137. /* if we are in the middle of flr the slave will try
  1138. * NUM_OF_RESET_RETRIES times before leaving.*/
  1139. if (ret_from_reset) {
  1140. if (MLX4_DELAY_RESET_SLAVE == ret_from_reset) {
  1141. mlx4_warn(dev, "slave is currently in the "
  1142. "middle of FLR. Deferring probe.\n");
  1143. mutex_unlock(&priv->cmd.slave_cmd_mutex);
  1144. return -EPROBE_DEFER;
  1145. } else
  1146. goto err;
  1147. }
  1148. /* check the driver version - the slave I/F revision
  1149. * must match the master's */
  1150. slave_read = swab32(readl(&priv->mfunc.comm->slave_read));
  1151. cmd_channel_ver = mlx4_comm_get_version();
  1152. if (MLX4_COMM_GET_IF_REV(cmd_channel_ver) !=
  1153. MLX4_COMM_GET_IF_REV(slave_read)) {
  1154. mlx4_err(dev, "slave driver version is not supported"
  1155. " by the master\n");
  1156. goto err;
  1157. }
  1158. mlx4_warn(dev, "Sending vhcr0\n");
  1159. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48,
  1160. MLX4_COMM_TIME))
  1161. goto err;
  1162. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32,
  1163. MLX4_COMM_TIME))
  1164. goto err;
  1165. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16,
  1166. MLX4_COMM_TIME))
  1167. goto err;
  1168. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, MLX4_COMM_TIME))
  1169. goto err;
  1170. mutex_unlock(&priv->cmd.slave_cmd_mutex);
  1171. return 0;
  1172. err:
  1173. mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0);
  1174. mutex_unlock(&priv->cmd.slave_cmd_mutex);
  1175. return -EIO;
  1176. }
  1177. static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev)
  1178. {
  1179. int i;
  1180. for (i = 1; i <= dev->caps.num_ports; i++) {
  1181. dev->caps.gid_table_len[i] = 1;
  1182. dev->caps.pkey_table_len[i] =
  1183. dev->phys_caps.pkey_phys_table_len[i] - 1;
  1184. }
  1185. }
  1186. static int choose_log_fs_mgm_entry_size(int qp_per_entry)
  1187. {
  1188. int i = MLX4_MIN_MGM_LOG_ENTRY_SIZE;
  1189. for (i = MLX4_MIN_MGM_LOG_ENTRY_SIZE; i <= MLX4_MAX_MGM_LOG_ENTRY_SIZE;
  1190. i++) {
  1191. if (qp_per_entry <= 4 * ((1 << i) / 16 - 2))
  1192. break;
  1193. }
  1194. return (i <= MLX4_MAX_MGM_LOG_ENTRY_SIZE) ? i : -1;
  1195. }
  1196. static void choose_steering_mode(struct mlx4_dev *dev,
  1197. struct mlx4_dev_cap *dev_cap)
  1198. {
  1199. if (mlx4_log_num_mgm_entry_size == -1 &&
  1200. dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_FS_EN &&
  1201. (!mlx4_is_mfunc(dev) ||
  1202. (dev_cap->fs_max_num_qp_per_entry >= (num_vfs + 1))) &&
  1203. choose_log_fs_mgm_entry_size(dev_cap->fs_max_num_qp_per_entry) >=
  1204. MLX4_MIN_MGM_LOG_ENTRY_SIZE) {
  1205. dev->oper_log_mgm_entry_size =
  1206. choose_log_fs_mgm_entry_size(dev_cap->fs_max_num_qp_per_entry);
  1207. dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED;
  1208. dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry;
  1209. dev->caps.fs_log_max_ucast_qp_range_size =
  1210. dev_cap->fs_log_max_ucast_qp_range_size;
  1211. } else {
  1212. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER &&
  1213. dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER)
  1214. dev->caps.steering_mode = MLX4_STEERING_MODE_B0;
  1215. else {
  1216. dev->caps.steering_mode = MLX4_STEERING_MODE_A0;
  1217. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER ||
  1218. dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER)
  1219. mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags "
  1220. "set to use B0 steering. Falling back to A0 steering mode.\n");
  1221. }
  1222. dev->oper_log_mgm_entry_size =
  1223. mlx4_log_num_mgm_entry_size > 0 ?
  1224. mlx4_log_num_mgm_entry_size :
  1225. MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE;
  1226. dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev);
  1227. }
  1228. mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, "
  1229. "modparam log_num_mgm_entry_size = %d\n",
  1230. mlx4_steering_mode_str(dev->caps.steering_mode),
  1231. dev->oper_log_mgm_entry_size,
  1232. mlx4_log_num_mgm_entry_size);
  1233. }
  1234. static int mlx4_init_hca(struct mlx4_dev *dev)
  1235. {
  1236. struct mlx4_priv *priv = mlx4_priv(dev);
  1237. struct mlx4_adapter adapter;
  1238. struct mlx4_dev_cap dev_cap;
  1239. struct mlx4_mod_stat_cfg mlx4_cfg;
  1240. struct mlx4_profile profile;
  1241. struct mlx4_init_hca_param init_hca;
  1242. u64 icm_size;
  1243. int err;
  1244. if (!mlx4_is_slave(dev)) {
  1245. err = mlx4_QUERY_FW(dev);
  1246. if (err) {
  1247. if (err == -EACCES)
  1248. mlx4_info(dev, "non-primary physical function, skipping.\n");
  1249. else
  1250. mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
  1251. return err;
  1252. }
  1253. err = mlx4_load_fw(dev);
  1254. if (err) {
  1255. mlx4_err(dev, "Failed to start FW, aborting.\n");
  1256. return err;
  1257. }
  1258. mlx4_cfg.log_pg_sz_m = 1;
  1259. mlx4_cfg.log_pg_sz = 0;
  1260. err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
  1261. if (err)
  1262. mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
  1263. err = mlx4_dev_cap(dev, &dev_cap);
  1264. if (err) {
  1265. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  1266. goto err_stop_fw;
  1267. }
  1268. choose_steering_mode(dev, &dev_cap);
  1269. if (mlx4_is_master(dev))
  1270. mlx4_parav_master_pf_caps(dev);
  1271. profile = default_profile;
  1272. if (dev->caps.steering_mode ==
  1273. MLX4_STEERING_MODE_DEVICE_MANAGED)
  1274. profile.num_mcg = MLX4_FS_NUM_MCG;
  1275. icm_size = mlx4_make_profile(dev, &profile, &dev_cap,
  1276. &init_hca);
  1277. if ((long long) icm_size < 0) {
  1278. err = icm_size;
  1279. goto err_stop_fw;
  1280. }
  1281. dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
  1282. init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
  1283. init_hca.uar_page_sz = PAGE_SHIFT - 12;
  1284. init_hca.mw_enabled = 0;
  1285. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW ||
  1286. dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN)
  1287. init_hca.mw_enabled = INIT_HCA_TPT_MW_ENABLE;
  1288. err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
  1289. if (err)
  1290. goto err_stop_fw;
  1291. err = mlx4_INIT_HCA(dev, &init_hca);
  1292. if (err) {
  1293. mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
  1294. goto err_free_icm;
  1295. }
  1296. /*
  1297. * If TS is supported by FW
  1298. * read HCA frequency by QUERY_HCA command
  1299. */
  1300. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) {
  1301. memset(&init_hca, 0, sizeof(init_hca));
  1302. err = mlx4_QUERY_HCA(dev, &init_hca);
  1303. if (err) {
  1304. mlx4_err(dev, "QUERY_HCA command failed, disable timestamp.\n");
  1305. dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS;
  1306. } else {
  1307. dev->caps.hca_core_clock =
  1308. init_hca.hca_core_clock;
  1309. }
  1310. /* In case we got HCA frequency 0 - disable timestamping
  1311. * to avoid dividing by zero
  1312. */
  1313. if (!dev->caps.hca_core_clock) {
  1314. dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS;
  1315. mlx4_err(dev,
  1316. "HCA frequency is 0. Timestamping is not supported.");
  1317. } else if (map_internal_clock(dev)) {
  1318. /*
  1319. * Map internal clock,
  1320. * in case of failure disable timestamping
  1321. */
  1322. dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS;
  1323. mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported.\n");
  1324. }
  1325. }
  1326. } else {
  1327. err = mlx4_init_slave(dev);
  1328. if (err) {
  1329. if (err != -EPROBE_DEFER)
  1330. mlx4_err(dev, "Failed to initialize slave\n");
  1331. return err;
  1332. }
  1333. err = mlx4_slave_cap(dev);
  1334. if (err) {
  1335. mlx4_err(dev, "Failed to obtain slave caps\n");
  1336. goto err_close;
  1337. }
  1338. }
  1339. if (map_bf_area(dev))
  1340. mlx4_dbg(dev, "Failed to map blue flame area\n");
  1341. /*Only the master set the ports, all the rest got it from it.*/
  1342. if (!mlx4_is_slave(dev))
  1343. mlx4_set_port_mask(dev);
  1344. err = mlx4_QUERY_ADAPTER(dev, &adapter);
  1345. if (err) {
  1346. mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
  1347. goto unmap_bf;
  1348. }
  1349. priv->eq_table.inta_pin = adapter.inta_pin;
  1350. memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
  1351. return 0;
  1352. unmap_bf:
  1353. unmap_internal_clock(dev);
  1354. unmap_bf_area(dev);
  1355. err_close:
  1356. if (mlx4_is_slave(dev))
  1357. mlx4_slave_exit(dev);
  1358. else
  1359. mlx4_CLOSE_HCA(dev, 0);
  1360. err_free_icm:
  1361. if (!mlx4_is_slave(dev))
  1362. mlx4_free_icms(dev);
  1363. err_stop_fw:
  1364. if (!mlx4_is_slave(dev)) {
  1365. mlx4_UNMAP_FA(dev);
  1366. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  1367. }
  1368. return err;
  1369. }
  1370. static int mlx4_init_counters_table(struct mlx4_dev *dev)
  1371. {
  1372. struct mlx4_priv *priv = mlx4_priv(dev);
  1373. int nent;
  1374. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1375. return -ENOENT;
  1376. nent = dev->caps.max_counters;
  1377. return mlx4_bitmap_init(&priv->counters_bitmap, nent, nent - 1, 0, 0);
  1378. }
  1379. static void mlx4_cleanup_counters_table(struct mlx4_dev *dev)
  1380. {
  1381. mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap);
  1382. }
  1383. int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
  1384. {
  1385. struct mlx4_priv *priv = mlx4_priv(dev);
  1386. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1387. return -ENOENT;
  1388. *idx = mlx4_bitmap_alloc(&priv->counters_bitmap);
  1389. if (*idx == -1)
  1390. return -ENOMEM;
  1391. return 0;
  1392. }
  1393. int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
  1394. {
  1395. u64 out_param;
  1396. int err;
  1397. if (mlx4_is_mfunc(dev)) {
  1398. err = mlx4_cmd_imm(dev, 0, &out_param, RES_COUNTER,
  1399. RES_OP_RESERVE, MLX4_CMD_ALLOC_RES,
  1400. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  1401. if (!err)
  1402. *idx = get_param_l(&out_param);
  1403. return err;
  1404. }
  1405. return __mlx4_counter_alloc(dev, idx);
  1406. }
  1407. EXPORT_SYMBOL_GPL(mlx4_counter_alloc);
  1408. void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
  1409. {
  1410. mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx);
  1411. return;
  1412. }
  1413. void mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
  1414. {
  1415. u64 in_param = 0;
  1416. if (mlx4_is_mfunc(dev)) {
  1417. set_param_l(&in_param, idx);
  1418. mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE,
  1419. MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
  1420. MLX4_CMD_WRAPPED);
  1421. return;
  1422. }
  1423. __mlx4_counter_free(dev, idx);
  1424. }
  1425. EXPORT_SYMBOL_GPL(mlx4_counter_free);
  1426. static int mlx4_setup_hca(struct mlx4_dev *dev)
  1427. {
  1428. struct mlx4_priv *priv = mlx4_priv(dev);
  1429. int err;
  1430. int port;
  1431. __be32 ib_port_default_caps;
  1432. err = mlx4_init_uar_table(dev);
  1433. if (err) {
  1434. mlx4_err(dev, "Failed to initialize "
  1435. "user access region table, aborting.\n");
  1436. return err;
  1437. }
  1438. err = mlx4_uar_alloc(dev, &priv->driver_uar);
  1439. if (err) {
  1440. mlx4_err(dev, "Failed to allocate driver access region, "
  1441. "aborting.\n");
  1442. goto err_uar_table_free;
  1443. }
  1444. priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  1445. if (!priv->kar) {
  1446. mlx4_err(dev, "Couldn't map kernel access region, "
  1447. "aborting.\n");
  1448. err = -ENOMEM;
  1449. goto err_uar_free;
  1450. }
  1451. err = mlx4_init_pd_table(dev);
  1452. if (err) {
  1453. mlx4_err(dev, "Failed to initialize "
  1454. "protection domain table, aborting.\n");
  1455. goto err_kar_unmap;
  1456. }
  1457. err = mlx4_init_xrcd_table(dev);
  1458. if (err) {
  1459. mlx4_err(dev, "Failed to initialize "
  1460. "reliable connection domain table, aborting.\n");
  1461. goto err_pd_table_free;
  1462. }
  1463. err = mlx4_init_mr_table(dev);
  1464. if (err) {
  1465. mlx4_err(dev, "Failed to initialize "
  1466. "memory region table, aborting.\n");
  1467. goto err_xrcd_table_free;
  1468. }
  1469. if (!mlx4_is_slave(dev)) {
  1470. err = mlx4_init_mcg_table(dev);
  1471. if (err) {
  1472. mlx4_err(dev, "Failed to initialize multicast group table, aborting.\n");
  1473. goto err_mr_table_free;
  1474. }
  1475. }
  1476. err = mlx4_init_eq_table(dev);
  1477. if (err) {
  1478. mlx4_err(dev, "Failed to initialize "
  1479. "event queue table, aborting.\n");
  1480. goto err_mcg_table_free;
  1481. }
  1482. err = mlx4_cmd_use_events(dev);
  1483. if (err) {
  1484. mlx4_err(dev, "Failed to switch to event-driven "
  1485. "firmware commands, aborting.\n");
  1486. goto err_eq_table_free;
  1487. }
  1488. err = mlx4_NOP(dev);
  1489. if (err) {
  1490. if (dev->flags & MLX4_FLAG_MSI_X) {
  1491. mlx4_warn(dev, "NOP command failed to generate MSI-X "
  1492. "interrupt IRQ %d).\n",
  1493. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1494. mlx4_warn(dev, "Trying again without MSI-X.\n");
  1495. } else {
  1496. mlx4_err(dev, "NOP command failed to generate interrupt "
  1497. "(IRQ %d), aborting.\n",
  1498. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1499. mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
  1500. }
  1501. goto err_cmd_poll;
  1502. }
  1503. mlx4_dbg(dev, "NOP command IRQ test passed\n");
  1504. err = mlx4_init_cq_table(dev);
  1505. if (err) {
  1506. mlx4_err(dev, "Failed to initialize "
  1507. "completion queue table, aborting.\n");
  1508. goto err_cmd_poll;
  1509. }
  1510. err = mlx4_init_srq_table(dev);
  1511. if (err) {
  1512. mlx4_err(dev, "Failed to initialize "
  1513. "shared receive queue table, aborting.\n");
  1514. goto err_cq_table_free;
  1515. }
  1516. err = mlx4_init_qp_table(dev);
  1517. if (err) {
  1518. mlx4_err(dev, "Failed to initialize "
  1519. "queue pair table, aborting.\n");
  1520. goto err_srq_table_free;
  1521. }
  1522. err = mlx4_init_counters_table(dev);
  1523. if (err && err != -ENOENT) {
  1524. mlx4_err(dev, "Failed to initialize counters table, aborting.\n");
  1525. goto err_qp_table_free;
  1526. }
  1527. if (!mlx4_is_slave(dev)) {
  1528. for (port = 1; port <= dev->caps.num_ports; port++) {
  1529. ib_port_default_caps = 0;
  1530. err = mlx4_get_port_ib_caps(dev, port,
  1531. &ib_port_default_caps);
  1532. if (err)
  1533. mlx4_warn(dev, "failed to get port %d default "
  1534. "ib capabilities (%d). Continuing "
  1535. "with caps = 0\n", port, err);
  1536. dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
  1537. /* initialize per-slave default ib port capabilities */
  1538. if (mlx4_is_master(dev)) {
  1539. int i;
  1540. for (i = 0; i < dev->num_slaves; i++) {
  1541. if (i == mlx4_master_func_num(dev))
  1542. continue;
  1543. priv->mfunc.master.slave_state[i].ib_cap_mask[port] =
  1544. ib_port_default_caps;
  1545. }
  1546. }
  1547. if (mlx4_is_mfunc(dev))
  1548. dev->caps.port_ib_mtu[port] = IB_MTU_2048;
  1549. else
  1550. dev->caps.port_ib_mtu[port] = IB_MTU_4096;
  1551. err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ?
  1552. dev->caps.pkey_table_len[port] : -1);
  1553. if (err) {
  1554. mlx4_err(dev, "Failed to set port %d, aborting\n",
  1555. port);
  1556. goto err_counters_table_free;
  1557. }
  1558. }
  1559. }
  1560. return 0;
  1561. err_counters_table_free:
  1562. mlx4_cleanup_counters_table(dev);
  1563. err_qp_table_free:
  1564. mlx4_cleanup_qp_table(dev);
  1565. err_srq_table_free:
  1566. mlx4_cleanup_srq_table(dev);
  1567. err_cq_table_free:
  1568. mlx4_cleanup_cq_table(dev);
  1569. err_cmd_poll:
  1570. mlx4_cmd_use_polling(dev);
  1571. err_eq_table_free:
  1572. mlx4_cleanup_eq_table(dev);
  1573. err_mcg_table_free:
  1574. if (!mlx4_is_slave(dev))
  1575. mlx4_cleanup_mcg_table(dev);
  1576. err_mr_table_free:
  1577. mlx4_cleanup_mr_table(dev);
  1578. err_xrcd_table_free:
  1579. mlx4_cleanup_xrcd_table(dev);
  1580. err_pd_table_free:
  1581. mlx4_cleanup_pd_table(dev);
  1582. err_kar_unmap:
  1583. iounmap(priv->kar);
  1584. err_uar_free:
  1585. mlx4_uar_free(dev, &priv->driver_uar);
  1586. err_uar_table_free:
  1587. mlx4_cleanup_uar_table(dev);
  1588. return err;
  1589. }
  1590. static void mlx4_enable_msi_x(struct mlx4_dev *dev)
  1591. {
  1592. struct mlx4_priv *priv = mlx4_priv(dev);
  1593. struct msix_entry *entries;
  1594. int nreq = min_t(int, dev->caps.num_ports *
  1595. min_t(int, netif_get_num_default_rss_queues() + 1,
  1596. MAX_MSIX_P_PORT) + MSIX_LEGACY_SZ, MAX_MSIX);
  1597. int err;
  1598. int i;
  1599. if (msi_x) {
  1600. nreq = min_t(int, dev->caps.num_eqs - dev->caps.reserved_eqs,
  1601. nreq);
  1602. entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
  1603. if (!entries)
  1604. goto no_msi;
  1605. for (i = 0; i < nreq; ++i)
  1606. entries[i].entry = i;
  1607. retry:
  1608. err = pci_enable_msix(dev->pdev, entries, nreq);
  1609. if (err) {
  1610. /* Try again if at least 2 vectors are available */
  1611. if (err > 1) {
  1612. mlx4_info(dev, "Requested %d vectors, "
  1613. "but only %d MSI-X vectors available, "
  1614. "trying again\n", nreq, err);
  1615. nreq = err;
  1616. goto retry;
  1617. }
  1618. kfree(entries);
  1619. goto no_msi;
  1620. }
  1621. if (nreq <
  1622. MSIX_LEGACY_SZ + dev->caps.num_ports * MIN_MSIX_P_PORT) {
  1623. /*Working in legacy mode , all EQ's shared*/
  1624. dev->caps.comp_pool = 0;
  1625. dev->caps.num_comp_vectors = nreq - 1;
  1626. } else {
  1627. dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ;
  1628. dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1;
  1629. }
  1630. for (i = 0; i < nreq; ++i)
  1631. priv->eq_table.eq[i].irq = entries[i].vector;
  1632. dev->flags |= MLX4_FLAG_MSI_X;
  1633. kfree(entries);
  1634. return;
  1635. }
  1636. no_msi:
  1637. dev->caps.num_comp_vectors = 1;
  1638. dev->caps.comp_pool = 0;
  1639. for (i = 0; i < 2; ++i)
  1640. priv->eq_table.eq[i].irq = dev->pdev->irq;
  1641. }
  1642. static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  1643. {
  1644. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  1645. int err = 0;
  1646. info->dev = dev;
  1647. info->port = port;
  1648. if (!mlx4_is_slave(dev)) {
  1649. mlx4_init_mac_table(dev, &info->mac_table);
  1650. mlx4_init_vlan_table(dev, &info->vlan_table);
  1651. info->base_qpn = mlx4_get_base_qpn(dev, port);
  1652. }
  1653. sprintf(info->dev_name, "mlx4_port%d", port);
  1654. info->port_attr.attr.name = info->dev_name;
  1655. if (mlx4_is_mfunc(dev))
  1656. info->port_attr.attr.mode = S_IRUGO;
  1657. else {
  1658. info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
  1659. info->port_attr.store = set_port_type;
  1660. }
  1661. info->port_attr.show = show_port_type;
  1662. sysfs_attr_init(&info->port_attr.attr);
  1663. err = device_create_file(&dev->pdev->dev, &info->port_attr);
  1664. if (err) {
  1665. mlx4_err(dev, "Failed to create file for port %d\n", port);
  1666. info->port = -1;
  1667. }
  1668. sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
  1669. info->port_mtu_attr.attr.name = info->dev_mtu_name;
  1670. if (mlx4_is_mfunc(dev))
  1671. info->port_mtu_attr.attr.mode = S_IRUGO;
  1672. else {
  1673. info->port_mtu_attr.attr.mode = S_IRUGO | S_IWUSR;
  1674. info->port_mtu_attr.store = set_port_ib_mtu;
  1675. }
  1676. info->port_mtu_attr.show = show_port_ib_mtu;
  1677. sysfs_attr_init(&info->port_mtu_attr.attr);
  1678. err = device_create_file(&dev->pdev->dev, &info->port_mtu_attr);
  1679. if (err) {
  1680. mlx4_err(dev, "Failed to create mtu file for port %d\n", port);
  1681. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1682. info->port = -1;
  1683. }
  1684. return err;
  1685. }
  1686. static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
  1687. {
  1688. if (info->port < 0)
  1689. return;
  1690. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1691. device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr);
  1692. }
  1693. static int mlx4_init_steering(struct mlx4_dev *dev)
  1694. {
  1695. struct mlx4_priv *priv = mlx4_priv(dev);
  1696. int num_entries = dev->caps.num_ports;
  1697. int i, j;
  1698. priv->steer = kzalloc(sizeof(struct mlx4_steer) * num_entries, GFP_KERNEL);
  1699. if (!priv->steer)
  1700. return -ENOMEM;
  1701. for (i = 0; i < num_entries; i++)
  1702. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1703. INIT_LIST_HEAD(&priv->steer[i].promisc_qps[j]);
  1704. INIT_LIST_HEAD(&priv->steer[i].steer_entries[j]);
  1705. }
  1706. return 0;
  1707. }
  1708. static void mlx4_clear_steering(struct mlx4_dev *dev)
  1709. {
  1710. struct mlx4_priv *priv = mlx4_priv(dev);
  1711. struct mlx4_steer_index *entry, *tmp_entry;
  1712. struct mlx4_promisc_qp *pqp, *tmp_pqp;
  1713. int num_entries = dev->caps.num_ports;
  1714. int i, j;
  1715. for (i = 0; i < num_entries; i++) {
  1716. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1717. list_for_each_entry_safe(pqp, tmp_pqp,
  1718. &priv->steer[i].promisc_qps[j],
  1719. list) {
  1720. list_del(&pqp->list);
  1721. kfree(pqp);
  1722. }
  1723. list_for_each_entry_safe(entry, tmp_entry,
  1724. &priv->steer[i].steer_entries[j],
  1725. list) {
  1726. list_del(&entry->list);
  1727. list_for_each_entry_safe(pqp, tmp_pqp,
  1728. &entry->duplicates,
  1729. list) {
  1730. list_del(&pqp->list);
  1731. kfree(pqp);
  1732. }
  1733. kfree(entry);
  1734. }
  1735. }
  1736. }
  1737. kfree(priv->steer);
  1738. }
  1739. static int extended_func_num(struct pci_dev *pdev)
  1740. {
  1741. return PCI_SLOT(pdev->devfn) * 8 + PCI_FUNC(pdev->devfn);
  1742. }
  1743. #define MLX4_OWNER_BASE 0x8069c
  1744. #define MLX4_OWNER_SIZE 4
  1745. static int mlx4_get_ownership(struct mlx4_dev *dev)
  1746. {
  1747. void __iomem *owner;
  1748. u32 ret;
  1749. if (pci_channel_offline(dev->pdev))
  1750. return -EIO;
  1751. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1752. MLX4_OWNER_SIZE);
  1753. if (!owner) {
  1754. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1755. return -ENOMEM;
  1756. }
  1757. ret = readl(owner);
  1758. iounmap(owner);
  1759. return (int) !!ret;
  1760. }
  1761. static void mlx4_free_ownership(struct mlx4_dev *dev)
  1762. {
  1763. void __iomem *owner;
  1764. if (pci_channel_offline(dev->pdev))
  1765. return;
  1766. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1767. MLX4_OWNER_SIZE);
  1768. if (!owner) {
  1769. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1770. return;
  1771. }
  1772. writel(0, owner);
  1773. msleep(1000);
  1774. iounmap(owner);
  1775. }
  1776. static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
  1777. {
  1778. struct mlx4_priv *priv;
  1779. struct mlx4_dev *dev;
  1780. int err;
  1781. int port;
  1782. pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev));
  1783. err = pci_enable_device(pdev);
  1784. if (err) {
  1785. dev_err(&pdev->dev, "Cannot enable PCI device, "
  1786. "aborting.\n");
  1787. return err;
  1788. }
  1789. /* Due to requirement that all VFs and the PF are *guaranteed* 2 MACS
  1790. * per port, we must limit the number of VFs to 63 (since their are
  1791. * 128 MACs)
  1792. */
  1793. if (num_vfs >= MLX4_MAX_NUM_VF) {
  1794. dev_err(&pdev->dev,
  1795. "Requested more VF's (%d) than allowed (%d)\n",
  1796. num_vfs, MLX4_MAX_NUM_VF - 1);
  1797. return -EINVAL;
  1798. }
  1799. if (num_vfs < 0) {
  1800. pr_err("num_vfs module parameter cannot be negative\n");
  1801. return -EINVAL;
  1802. }
  1803. /*
  1804. * Check for BARs.
  1805. */
  1806. if (!(pci_dev_data & MLX4_PCI_DEV_IS_VF) &&
  1807. !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  1808. dev_err(&pdev->dev, "Missing DCS, aborting."
  1809. "(driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\n",
  1810. pci_dev_data, pci_resource_flags(pdev, 0));
  1811. err = -ENODEV;
  1812. goto err_disable_pdev;
  1813. }
  1814. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  1815. dev_err(&pdev->dev, "Missing UAR, aborting.\n");
  1816. err = -ENODEV;
  1817. goto err_disable_pdev;
  1818. }
  1819. err = pci_request_regions(pdev, DRV_NAME);
  1820. if (err) {
  1821. dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
  1822. goto err_disable_pdev;
  1823. }
  1824. pci_set_master(pdev);
  1825. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  1826. if (err) {
  1827. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
  1828. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1829. if (err) {
  1830. dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
  1831. goto err_release_regions;
  1832. }
  1833. }
  1834. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  1835. if (err) {
  1836. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
  1837. "consistent PCI DMA mask.\n");
  1838. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1839. if (err) {
  1840. dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
  1841. "aborting.\n");
  1842. goto err_release_regions;
  1843. }
  1844. }
  1845. /* Allow large DMA segments, up to the firmware limit of 1 GB */
  1846. dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
  1847. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  1848. if (!priv) {
  1849. err = -ENOMEM;
  1850. goto err_release_regions;
  1851. }
  1852. dev = &priv->dev;
  1853. dev->pdev = pdev;
  1854. INIT_LIST_HEAD(&priv->ctx_list);
  1855. spin_lock_init(&priv->ctx_lock);
  1856. mutex_init(&priv->port_mutex);
  1857. INIT_LIST_HEAD(&priv->pgdir_list);
  1858. mutex_init(&priv->pgdir_mutex);
  1859. INIT_LIST_HEAD(&priv->bf_list);
  1860. mutex_init(&priv->bf_mutex);
  1861. dev->rev_id = pdev->revision;
  1862. /* Detect if this device is a virtual function */
  1863. if (pci_dev_data & MLX4_PCI_DEV_IS_VF) {
  1864. /* When acting as pf, we normally skip vfs unless explicitly
  1865. * requested to probe them. */
  1866. if (num_vfs && extended_func_num(pdev) > probe_vf) {
  1867. mlx4_warn(dev, "Skipping virtual function:%d\n",
  1868. extended_func_num(pdev));
  1869. err = -ENODEV;
  1870. goto err_free_dev;
  1871. }
  1872. mlx4_warn(dev, "Detected virtual function - running in slave mode\n");
  1873. dev->flags |= MLX4_FLAG_SLAVE;
  1874. } else {
  1875. /* We reset the device and enable SRIOV only for physical
  1876. * devices. Try to claim ownership on the device;
  1877. * if already taken, skip -- do not allow multiple PFs */
  1878. err = mlx4_get_ownership(dev);
  1879. if (err) {
  1880. if (err < 0)
  1881. goto err_free_dev;
  1882. else {
  1883. mlx4_warn(dev, "Multiple PFs not yet supported."
  1884. " Skipping PF.\n");
  1885. err = -EINVAL;
  1886. goto err_free_dev;
  1887. }
  1888. }
  1889. if (num_vfs) {
  1890. mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs);
  1891. err = pci_enable_sriov(pdev, num_vfs);
  1892. if (err) {
  1893. mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
  1894. err);
  1895. err = 0;
  1896. } else {
  1897. mlx4_warn(dev, "Running in master mode\n");
  1898. dev->flags |= MLX4_FLAG_SRIOV |
  1899. MLX4_FLAG_MASTER;
  1900. dev->num_vfs = num_vfs;
  1901. }
  1902. }
  1903. atomic_set(&priv->opreq_count, 0);
  1904. INIT_WORK(&priv->opreq_task, mlx4_opreq_action);
  1905. /*
  1906. * Now reset the HCA before we touch the PCI capabilities or
  1907. * attempt a firmware command, since a boot ROM may have left
  1908. * the HCA in an undefined state.
  1909. */
  1910. err = mlx4_reset(dev);
  1911. if (err) {
  1912. mlx4_err(dev, "Failed to reset HCA, aborting.\n");
  1913. goto err_rel_own;
  1914. }
  1915. }
  1916. slave_start:
  1917. err = mlx4_cmd_init(dev);
  1918. if (err) {
  1919. mlx4_err(dev, "Failed to init command interface, aborting.\n");
  1920. goto err_sriov;
  1921. }
  1922. /* In slave functions, the communication channel must be initialized
  1923. * before posting commands. Also, init num_slaves before calling
  1924. * mlx4_init_hca */
  1925. if (mlx4_is_mfunc(dev)) {
  1926. if (mlx4_is_master(dev))
  1927. dev->num_slaves = MLX4_MAX_NUM_SLAVES;
  1928. else {
  1929. dev->num_slaves = 0;
  1930. err = mlx4_multi_func_init(dev);
  1931. if (err) {
  1932. mlx4_err(dev, "Failed to init slave mfunc"
  1933. " interface, aborting.\n");
  1934. goto err_cmd;
  1935. }
  1936. }
  1937. }
  1938. err = mlx4_init_hca(dev);
  1939. if (err) {
  1940. if (err == -EACCES) {
  1941. /* Not primary Physical function
  1942. * Running in slave mode */
  1943. mlx4_cmd_cleanup(dev);
  1944. dev->flags |= MLX4_FLAG_SLAVE;
  1945. dev->flags &= ~MLX4_FLAG_MASTER;
  1946. goto slave_start;
  1947. } else
  1948. goto err_mfunc;
  1949. }
  1950. /* In master functions, the communication channel must be initialized
  1951. * after obtaining its address from fw */
  1952. if (mlx4_is_master(dev)) {
  1953. err = mlx4_multi_func_init(dev);
  1954. if (err) {
  1955. mlx4_err(dev, "Failed to init master mfunc"
  1956. "interface, aborting.\n");
  1957. goto err_close;
  1958. }
  1959. }
  1960. err = mlx4_alloc_eq_table(dev);
  1961. if (err)
  1962. goto err_master_mfunc;
  1963. priv->msix_ctl.pool_bm = 0;
  1964. mutex_init(&priv->msix_ctl.pool_lock);
  1965. mlx4_enable_msi_x(dev);
  1966. if ((mlx4_is_mfunc(dev)) &&
  1967. !(dev->flags & MLX4_FLAG_MSI_X)) {
  1968. err = -ENOSYS;
  1969. mlx4_err(dev, "INTx is not supported in multi-function mode."
  1970. " aborting.\n");
  1971. goto err_free_eq;
  1972. }
  1973. if (!mlx4_is_slave(dev)) {
  1974. err = mlx4_init_steering(dev);
  1975. if (err)
  1976. goto err_free_eq;
  1977. }
  1978. err = mlx4_setup_hca(dev);
  1979. if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) &&
  1980. !mlx4_is_mfunc(dev)) {
  1981. dev->flags &= ~MLX4_FLAG_MSI_X;
  1982. dev->caps.num_comp_vectors = 1;
  1983. dev->caps.comp_pool = 0;
  1984. pci_disable_msix(pdev);
  1985. err = mlx4_setup_hca(dev);
  1986. }
  1987. if (err)
  1988. goto err_steer;
  1989. mlx4_init_quotas(dev);
  1990. for (port = 1; port <= dev->caps.num_ports; port++) {
  1991. err = mlx4_init_port_info(dev, port);
  1992. if (err)
  1993. goto err_port;
  1994. }
  1995. err = mlx4_register_device(dev);
  1996. if (err)
  1997. goto err_port;
  1998. mlx4_request_modules(dev);
  1999. mlx4_sense_init(dev);
  2000. mlx4_start_sense(dev);
  2001. priv->pci_dev_data = pci_dev_data;
  2002. pci_set_drvdata(pdev, dev);
  2003. return 0;
  2004. err_port:
  2005. for (--port; port >= 1; --port)
  2006. mlx4_cleanup_port_info(&priv->port[port]);
  2007. mlx4_cleanup_counters_table(dev);
  2008. mlx4_cleanup_qp_table(dev);
  2009. mlx4_cleanup_srq_table(dev);
  2010. mlx4_cleanup_cq_table(dev);
  2011. mlx4_cmd_use_polling(dev);
  2012. mlx4_cleanup_eq_table(dev);
  2013. mlx4_cleanup_mcg_table(dev);
  2014. mlx4_cleanup_mr_table(dev);
  2015. mlx4_cleanup_xrcd_table(dev);
  2016. mlx4_cleanup_pd_table(dev);
  2017. mlx4_cleanup_uar_table(dev);
  2018. err_steer:
  2019. if (!mlx4_is_slave(dev))
  2020. mlx4_clear_steering(dev);
  2021. err_free_eq:
  2022. mlx4_free_eq_table(dev);
  2023. err_master_mfunc:
  2024. if (mlx4_is_master(dev))
  2025. mlx4_multi_func_cleanup(dev);
  2026. err_close:
  2027. if (dev->flags & MLX4_FLAG_MSI_X)
  2028. pci_disable_msix(pdev);
  2029. mlx4_close_hca(dev);
  2030. err_mfunc:
  2031. if (mlx4_is_slave(dev))
  2032. mlx4_multi_func_cleanup(dev);
  2033. err_cmd:
  2034. mlx4_cmd_cleanup(dev);
  2035. err_sriov:
  2036. if (dev->flags & MLX4_FLAG_SRIOV)
  2037. pci_disable_sriov(pdev);
  2038. err_rel_own:
  2039. if (!mlx4_is_slave(dev))
  2040. mlx4_free_ownership(dev);
  2041. err_free_dev:
  2042. kfree(priv);
  2043. err_release_regions:
  2044. pci_release_regions(pdev);
  2045. err_disable_pdev:
  2046. pci_disable_device(pdev);
  2047. pci_set_drvdata(pdev, NULL);
  2048. return err;
  2049. }
  2050. static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2051. {
  2052. printk_once(KERN_INFO "%s", mlx4_version);
  2053. return __mlx4_init_one(pdev, id->driver_data);
  2054. }
  2055. static void mlx4_remove_one(struct pci_dev *pdev)
  2056. {
  2057. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  2058. struct mlx4_priv *priv = mlx4_priv(dev);
  2059. int p;
  2060. if (dev) {
  2061. /* in SRIOV it is not allowed to unload the pf's
  2062. * driver while there are alive vf's */
  2063. if (mlx4_is_master(dev)) {
  2064. if (mlx4_how_many_lives_vf(dev))
  2065. printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
  2066. }
  2067. mlx4_stop_sense(dev);
  2068. mlx4_unregister_device(dev);
  2069. for (p = 1; p <= dev->caps.num_ports; p++) {
  2070. mlx4_cleanup_port_info(&priv->port[p]);
  2071. mlx4_CLOSE_PORT(dev, p);
  2072. }
  2073. if (mlx4_is_master(dev))
  2074. mlx4_free_resource_tracker(dev,
  2075. RES_TR_FREE_SLAVES_ONLY);
  2076. mlx4_cleanup_counters_table(dev);
  2077. mlx4_cleanup_qp_table(dev);
  2078. mlx4_cleanup_srq_table(dev);
  2079. mlx4_cleanup_cq_table(dev);
  2080. mlx4_cmd_use_polling(dev);
  2081. mlx4_cleanup_eq_table(dev);
  2082. mlx4_cleanup_mcg_table(dev);
  2083. mlx4_cleanup_mr_table(dev);
  2084. mlx4_cleanup_xrcd_table(dev);
  2085. mlx4_cleanup_pd_table(dev);
  2086. if (mlx4_is_master(dev))
  2087. mlx4_free_resource_tracker(dev,
  2088. RES_TR_FREE_STRUCTS_ONLY);
  2089. iounmap(priv->kar);
  2090. mlx4_uar_free(dev, &priv->driver_uar);
  2091. mlx4_cleanup_uar_table(dev);
  2092. if (!mlx4_is_slave(dev))
  2093. mlx4_clear_steering(dev);
  2094. mlx4_free_eq_table(dev);
  2095. if (mlx4_is_master(dev))
  2096. mlx4_multi_func_cleanup(dev);
  2097. mlx4_close_hca(dev);
  2098. if (mlx4_is_slave(dev))
  2099. mlx4_multi_func_cleanup(dev);
  2100. mlx4_cmd_cleanup(dev);
  2101. if (dev->flags & MLX4_FLAG_MSI_X)
  2102. pci_disable_msix(pdev);
  2103. if (dev->flags & MLX4_FLAG_SRIOV) {
  2104. mlx4_warn(dev, "Disabling SR-IOV\n");
  2105. pci_disable_sriov(pdev);
  2106. }
  2107. if (!mlx4_is_slave(dev))
  2108. mlx4_free_ownership(dev);
  2109. kfree(dev->caps.qp0_tunnel);
  2110. kfree(dev->caps.qp0_proxy);
  2111. kfree(dev->caps.qp1_tunnel);
  2112. kfree(dev->caps.qp1_proxy);
  2113. kfree(priv);
  2114. pci_release_regions(pdev);
  2115. pci_disable_device(pdev);
  2116. pci_set_drvdata(pdev, NULL);
  2117. }
  2118. }
  2119. int mlx4_restart_one(struct pci_dev *pdev)
  2120. {
  2121. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  2122. struct mlx4_priv *priv = mlx4_priv(dev);
  2123. int pci_dev_data;
  2124. pci_dev_data = priv->pci_dev_data;
  2125. mlx4_remove_one(pdev);
  2126. return __mlx4_init_one(pdev, pci_dev_data);
  2127. }
  2128. static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
  2129. /* MT25408 "Hermon" SDR */
  2130. { PCI_VDEVICE(MELLANOX, 0x6340), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2131. /* MT25408 "Hermon" DDR */
  2132. { PCI_VDEVICE(MELLANOX, 0x634a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2133. /* MT25408 "Hermon" QDR */
  2134. { PCI_VDEVICE(MELLANOX, 0x6354), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2135. /* MT25408 "Hermon" DDR PCIe gen2 */
  2136. { PCI_VDEVICE(MELLANOX, 0x6732), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2137. /* MT25408 "Hermon" QDR PCIe gen2 */
  2138. { PCI_VDEVICE(MELLANOX, 0x673c), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2139. /* MT25408 "Hermon" EN 10GigE */
  2140. { PCI_VDEVICE(MELLANOX, 0x6368), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2141. /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
  2142. { PCI_VDEVICE(MELLANOX, 0x6750), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2143. /* MT25458 ConnectX EN 10GBASE-T 10GigE */
  2144. { PCI_VDEVICE(MELLANOX, 0x6372), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2145. /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
  2146. { PCI_VDEVICE(MELLANOX, 0x675a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2147. /* MT26468 ConnectX EN 10GigE PCIe gen2*/
  2148. { PCI_VDEVICE(MELLANOX, 0x6764), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2149. /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
  2150. { PCI_VDEVICE(MELLANOX, 0x6746), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2151. /* MT26478 ConnectX2 40GigE PCIe gen2 */
  2152. { PCI_VDEVICE(MELLANOX, 0x676e), MLX4_PCI_DEV_FORCE_SENSE_PORT },
  2153. /* MT25400 Family [ConnectX-2 Virtual Function] */
  2154. { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_PCI_DEV_IS_VF },
  2155. /* MT27500 Family [ConnectX-3] */
  2156. { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
  2157. /* MT27500 Family [ConnectX-3 Virtual Function] */
  2158. { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_PCI_DEV_IS_VF },
  2159. { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */
  2160. { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */
  2161. { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */
  2162. { PCI_VDEVICE(MELLANOX, 0x1008), 0 }, /* MT27521 Family */
  2163. { PCI_VDEVICE(MELLANOX, 0x1009), 0 }, /* MT27530 Family */
  2164. { PCI_VDEVICE(MELLANOX, 0x100a), 0 }, /* MT27531 Family */
  2165. { PCI_VDEVICE(MELLANOX, 0x100b), 0 }, /* MT27540 Family */
  2166. { PCI_VDEVICE(MELLANOX, 0x100c), 0 }, /* MT27541 Family */
  2167. { PCI_VDEVICE(MELLANOX, 0x100d), 0 }, /* MT27550 Family */
  2168. { PCI_VDEVICE(MELLANOX, 0x100e), 0 }, /* MT27551 Family */
  2169. { PCI_VDEVICE(MELLANOX, 0x100f), 0 }, /* MT27560 Family */
  2170. { PCI_VDEVICE(MELLANOX, 0x1010), 0 }, /* MT27561 Family */
  2171. { 0, }
  2172. };
  2173. MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
  2174. static pci_ers_result_t mlx4_pci_err_detected(struct pci_dev *pdev,
  2175. pci_channel_state_t state)
  2176. {
  2177. mlx4_remove_one(pdev);
  2178. return state == pci_channel_io_perm_failure ?
  2179. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  2180. }
  2181. static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev)
  2182. {
  2183. int ret = __mlx4_init_one(pdev, 0);
  2184. return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
  2185. }
  2186. static const struct pci_error_handlers mlx4_err_handler = {
  2187. .error_detected = mlx4_pci_err_detected,
  2188. .slot_reset = mlx4_pci_slot_reset,
  2189. };
  2190. static struct pci_driver mlx4_driver = {
  2191. .name = DRV_NAME,
  2192. .id_table = mlx4_pci_table,
  2193. .probe = mlx4_init_one,
  2194. .remove = mlx4_remove_one,
  2195. .err_handler = &mlx4_err_handler,
  2196. };
  2197. static int __init mlx4_verify_params(void)
  2198. {
  2199. if ((log_num_mac < 0) || (log_num_mac > 7)) {
  2200. pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac);
  2201. return -1;
  2202. }
  2203. if (log_num_vlan != 0)
  2204. pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n",
  2205. MLX4_LOG_NUM_VLANS);
  2206. if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
  2207. pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
  2208. return -1;
  2209. }
  2210. /* Check if module param for ports type has legal combination */
  2211. if (port_type_array[0] == false && port_type_array[1] == true) {
  2212. printk(KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n");
  2213. port_type_array[0] = true;
  2214. }
  2215. if (mlx4_log_num_mgm_entry_size != -1 &&
  2216. (mlx4_log_num_mgm_entry_size < MLX4_MIN_MGM_LOG_ENTRY_SIZE ||
  2217. mlx4_log_num_mgm_entry_size > MLX4_MAX_MGM_LOG_ENTRY_SIZE)) {
  2218. pr_warning("mlx4_core: mlx4_log_num_mgm_entry_size (%d) not "
  2219. "in legal range (-1 or %d..%d)\n",
  2220. mlx4_log_num_mgm_entry_size,
  2221. MLX4_MIN_MGM_LOG_ENTRY_SIZE,
  2222. MLX4_MAX_MGM_LOG_ENTRY_SIZE);
  2223. return -1;
  2224. }
  2225. return 0;
  2226. }
  2227. static int __init mlx4_init(void)
  2228. {
  2229. int ret;
  2230. if (mlx4_verify_params())
  2231. return -EINVAL;
  2232. mlx4_catas_init();
  2233. mlx4_wq = create_singlethread_workqueue("mlx4");
  2234. if (!mlx4_wq)
  2235. return -ENOMEM;
  2236. ret = pci_register_driver(&mlx4_driver);
  2237. return ret < 0 ? ret : 0;
  2238. }
  2239. static void __exit mlx4_cleanup(void)
  2240. {
  2241. pci_unregister_driver(&mlx4_driver);
  2242. destroy_workqueue(mlx4_wq);
  2243. }
  2244. module_init(mlx4_init);
  2245. module_exit(mlx4_cleanup);