main.c 76 KB

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