main.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  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/mlx4/device.h>
  44. #include <linux/mlx4/doorbell.h>
  45. #include "mlx4.h"
  46. #include "fw.h"
  47. #include "icm.h"
  48. MODULE_AUTHOR("Roland Dreier");
  49. MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
  50. MODULE_LICENSE("Dual BSD/GPL");
  51. MODULE_VERSION(DRV_VERSION);
  52. struct workqueue_struct *mlx4_wq;
  53. #ifdef CONFIG_MLX4_DEBUG
  54. int mlx4_debug_level = 0;
  55. module_param_named(debug_level, mlx4_debug_level, int, 0644);
  56. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
  57. #endif /* CONFIG_MLX4_DEBUG */
  58. #ifdef CONFIG_PCI_MSI
  59. static int msi_x = 1;
  60. module_param(msi_x, int, 0444);
  61. MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
  62. #else /* CONFIG_PCI_MSI */
  63. #define msi_x (0)
  64. #endif /* CONFIG_PCI_MSI */
  65. static int num_vfs;
  66. module_param(num_vfs, int, 0444);
  67. MODULE_PARM_DESC(num_vfs, "enable #num_vfs functions if num_vfs > 0");
  68. static int probe_vf;
  69. module_param(probe_vf, int, 0644);
  70. MODULE_PARM_DESC(probe_vf, "number of vfs to probe by pf driver (num_vfs > 0)");
  71. int mlx4_log_num_mgm_entry_size = 10;
  72. module_param_named(log_num_mgm_entry_size,
  73. mlx4_log_num_mgm_entry_size, int, 0444);
  74. MODULE_PARM_DESC(log_num_mgm_entry_size, "log mgm size, that defines the num"
  75. " of qp per mcg, for example:"
  76. " 10 gives 248.range: 9<="
  77. " log_num_mgm_entry_size <= 12");
  78. #define MLX4_VF (1 << 0)
  79. #define HCA_GLOBAL_CAP_MASK 0
  80. #define PF_CONTEXT_BEHAVIOUR_MASK 0
  81. static char mlx4_version[] __devinitdata =
  82. DRV_NAME ": Mellanox ConnectX core driver v"
  83. DRV_VERSION " (" DRV_RELDATE ")\n";
  84. static struct mlx4_profile default_profile = {
  85. .num_qp = 1 << 18,
  86. .num_srq = 1 << 16,
  87. .rdmarc_per_qp = 1 << 4,
  88. .num_cq = 1 << 16,
  89. .num_mcg = 1 << 13,
  90. .num_mpt = 1 << 19,
  91. .num_mtt = 1 << 20, /* It is really num mtt segements */
  92. };
  93. static int log_num_mac = 7;
  94. module_param_named(log_num_mac, log_num_mac, int, 0444);
  95. MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
  96. static int log_num_vlan;
  97. module_param_named(log_num_vlan, log_num_vlan, int, 0444);
  98. MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
  99. /* Log2 max number of VLANs per ETH port (0-7) */
  100. #define MLX4_LOG_NUM_VLANS 7
  101. static bool use_prio;
  102. module_param_named(use_prio, use_prio, bool, 0444);
  103. MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
  104. "(0/1, default 0)");
  105. int log_mtts_per_seg = ilog2(MLX4_MTT_ENTRY_PER_SEG);
  106. module_param_named(log_mtts_per_seg, log_mtts_per_seg, int, 0444);
  107. MODULE_PARM_DESC(log_mtts_per_seg, "Log2 number of MTT entries per segment (1-7)");
  108. static int port_type_array[2] = {MLX4_PORT_TYPE_NONE, MLX4_PORT_TYPE_NONE};
  109. static int arr_argc = 2;
  110. module_param_array(port_type_array, int, &arr_argc, 0444);
  111. MODULE_PARM_DESC(port_type_array, "Array of port types: HW_DEFAULT (0) is default "
  112. "1 for IB, 2 for Ethernet");
  113. struct mlx4_port_config {
  114. struct list_head list;
  115. enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
  116. struct pci_dev *pdev;
  117. };
  118. static inline int mlx4_master_get_num_eqs(struct mlx4_dev *dev)
  119. {
  120. return dev->caps.reserved_eqs +
  121. MLX4_MFUNC_EQ_NUM * (dev->num_slaves + 1);
  122. }
  123. int mlx4_check_port_params(struct mlx4_dev *dev,
  124. enum mlx4_port_type *port_type)
  125. {
  126. int i;
  127. for (i = 0; i < dev->caps.num_ports - 1; i++) {
  128. if (port_type[i] != port_type[i + 1]) {
  129. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
  130. mlx4_err(dev, "Only same port types supported "
  131. "on this HCA, aborting.\n");
  132. return -EINVAL;
  133. }
  134. if (port_type[i] == MLX4_PORT_TYPE_ETH &&
  135. port_type[i + 1] == MLX4_PORT_TYPE_IB)
  136. return -EINVAL;
  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. for (i = 1; i <= dev->caps.num_ports; ++i) {
  184. dev->caps.vl_cap[i] = dev_cap->max_vl[i];
  185. dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
  186. dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
  187. dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
  188. dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
  189. dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
  190. dev->caps.def_mac[i] = dev_cap->def_mac[i];
  191. dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
  192. dev->caps.suggested_type[i] = dev_cap->suggested_type[i];
  193. dev->caps.default_sense[i] = dev_cap->default_sense[i];
  194. dev->caps.trans_type[i] = dev_cap->trans_type[i];
  195. dev->caps.vendor_oui[i] = dev_cap->vendor_oui[i];
  196. dev->caps.wavelength[i] = dev_cap->wavelength[i];
  197. dev->caps.trans_code[i] = dev_cap->trans_code[i];
  198. }
  199. dev->caps.uar_page_size = PAGE_SIZE;
  200. dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
  201. dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
  202. dev->caps.bf_reg_size = dev_cap->bf_reg_size;
  203. dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
  204. dev->caps.max_sq_sg = dev_cap->max_sq_sg;
  205. dev->caps.max_rq_sg = dev_cap->max_rq_sg;
  206. dev->caps.max_wqes = dev_cap->max_qp_sz;
  207. dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
  208. dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
  209. dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
  210. dev->caps.reserved_srqs = dev_cap->reserved_srqs;
  211. dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
  212. dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
  213. dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev);
  214. /*
  215. * Subtract 1 from the limit because we need to allocate a
  216. * spare CQE so the HCA HW can tell the difference between an
  217. * empty CQ and a full CQ.
  218. */
  219. dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
  220. dev->caps.reserved_cqs = dev_cap->reserved_cqs;
  221. dev->caps.reserved_eqs = dev_cap->reserved_eqs;
  222. dev->caps.reserved_mtts = dev_cap->reserved_mtts;
  223. dev->caps.reserved_mrws = dev_cap->reserved_mrws;
  224. /* The first 128 UARs are used for EQ doorbells */
  225. dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars);
  226. dev->caps.reserved_pds = dev_cap->reserved_pds;
  227. dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  228. dev_cap->reserved_xrcds : 0;
  229. dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ?
  230. dev_cap->max_xrcds : 0;
  231. dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz;
  232. dev->caps.max_msg_sz = dev_cap->max_msg_sz;
  233. dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
  234. dev->caps.flags = dev_cap->flags;
  235. dev->caps.bmme_flags = dev_cap->bmme_flags;
  236. dev->caps.reserved_lkey = dev_cap->reserved_lkey;
  237. dev->caps.stat_rate_support = dev_cap->stat_rate_support;
  238. dev->caps.max_gso_sz = dev_cap->max_gso_sz;
  239. /* Sense port always allowed on supported devices for ConnectX1 and 2 */
  240. if (dev->pdev->device != 0x1003)
  241. dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT;
  242. dev->caps.log_num_macs = log_num_mac;
  243. dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS;
  244. dev->caps.log_num_prios = use_prio ? 3 : 0;
  245. for (i = 1; i <= dev->caps.num_ports; ++i) {
  246. dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE;
  247. if (dev->caps.supported_type[i]) {
  248. /* if only ETH is supported - assign ETH */
  249. if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH)
  250. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  251. /* if only IB is supported,
  252. * assign IB only if SRIOV is off*/
  253. else if (dev->caps.supported_type[i] ==
  254. MLX4_PORT_TYPE_IB) {
  255. if (dev->flags & MLX4_FLAG_SRIOV)
  256. dev->caps.port_type[i] =
  257. MLX4_PORT_TYPE_NONE;
  258. else
  259. dev->caps.port_type[i] =
  260. MLX4_PORT_TYPE_IB;
  261. /* if IB and ETH are supported,
  262. * first of all check if SRIOV is on */
  263. } else if (dev->flags & MLX4_FLAG_SRIOV)
  264. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  265. else {
  266. /* In non-SRIOV mode, we set the port type
  267. * according to user selection of port type,
  268. * if usere selected none, take the FW hint */
  269. if (port_type_array[i-1] == MLX4_PORT_TYPE_NONE)
  270. dev->caps.port_type[i] = dev->caps.suggested_type[i] ?
  271. MLX4_PORT_TYPE_ETH : MLX4_PORT_TYPE_IB;
  272. else
  273. dev->caps.port_type[i] = port_type_array[i-1];
  274. }
  275. }
  276. /*
  277. * Link sensing is allowed on the port if 3 conditions are true:
  278. * 1. Both protocols are supported on the port.
  279. * 2. Different types are supported on the port
  280. * 3. FW declared that it supports link sensing
  281. */
  282. mlx4_priv(dev)->sense.sense_allowed[i] =
  283. ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) &&
  284. (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  285. (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT));
  286. /*
  287. * If "default_sense" bit is set, we move the port to "AUTO" mode
  288. * and perform sense_port FW command to try and set the correct
  289. * port type from beginning
  290. */
  291. if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) {
  292. enum mlx4_port_type sensed_port = MLX4_PORT_TYPE_NONE;
  293. dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO;
  294. mlx4_SENSE_PORT(dev, i, &sensed_port);
  295. if (sensed_port != MLX4_PORT_TYPE_NONE)
  296. dev->caps.port_type[i] = sensed_port;
  297. } else {
  298. dev->caps.possible_type[i] = dev->caps.port_type[i];
  299. }
  300. if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) {
  301. dev->caps.log_num_macs = dev_cap->log_max_macs[i];
  302. mlx4_warn(dev, "Requested number of MACs is too much "
  303. "for port %d, reducing to %d.\n",
  304. i, 1 << dev->caps.log_num_macs);
  305. }
  306. if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) {
  307. dev->caps.log_num_vlans = dev_cap->log_max_vlans[i];
  308. mlx4_warn(dev, "Requested number of VLANs is too much "
  309. "for port %d, reducing to %d.\n",
  310. i, 1 << dev->caps.log_num_vlans);
  311. }
  312. }
  313. dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters);
  314. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps;
  315. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] =
  316. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] =
  317. (1 << dev->caps.log_num_macs) *
  318. (1 << dev->caps.log_num_vlans) *
  319. (1 << dev->caps.log_num_prios) *
  320. dev->caps.num_ports;
  321. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH;
  322. dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] +
  323. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] +
  324. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] +
  325. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH];
  326. return 0;
  327. }
  328. /*The function checks if there are live vf, return the num of them*/
  329. static int mlx4_how_many_lives_vf(struct mlx4_dev *dev)
  330. {
  331. struct mlx4_priv *priv = mlx4_priv(dev);
  332. struct mlx4_slave_state *s_state;
  333. int i;
  334. int ret = 0;
  335. for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) {
  336. s_state = &priv->mfunc.master.slave_state[i];
  337. if (s_state->active && s_state->last_cmd !=
  338. MLX4_COMM_CMD_RESET) {
  339. mlx4_warn(dev, "%s: slave: %d is still active\n",
  340. __func__, i);
  341. ret++;
  342. }
  343. }
  344. return ret;
  345. }
  346. int mlx4_is_slave_active(struct mlx4_dev *dev, int slave)
  347. {
  348. struct mlx4_priv *priv = mlx4_priv(dev);
  349. struct mlx4_slave_state *s_slave;
  350. if (!mlx4_is_master(dev))
  351. return 0;
  352. s_slave = &priv->mfunc.master.slave_state[slave];
  353. return !!s_slave->active;
  354. }
  355. EXPORT_SYMBOL(mlx4_is_slave_active);
  356. static int mlx4_slave_cap(struct mlx4_dev *dev)
  357. {
  358. int err;
  359. u32 page_size;
  360. struct mlx4_dev_cap dev_cap;
  361. struct mlx4_func_cap func_cap;
  362. struct mlx4_init_hca_param hca_param;
  363. int i;
  364. memset(&hca_param, 0, sizeof(hca_param));
  365. err = mlx4_QUERY_HCA(dev, &hca_param);
  366. if (err) {
  367. mlx4_err(dev, "QUERY_HCA command failed, aborting.\n");
  368. return err;
  369. }
  370. /*fail if the hca has an unknown capability */
  371. if ((hca_param.global_caps | HCA_GLOBAL_CAP_MASK) !=
  372. HCA_GLOBAL_CAP_MASK) {
  373. mlx4_err(dev, "Unknown hca global capabilities\n");
  374. return -ENOSYS;
  375. }
  376. mlx4_log_num_mgm_entry_size = hca_param.log_mc_entry_sz;
  377. memset(&dev_cap, 0, sizeof(dev_cap));
  378. err = mlx4_dev_cap(dev, &dev_cap);
  379. if (err) {
  380. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  381. return err;
  382. }
  383. page_size = ~dev->caps.page_size_cap + 1;
  384. mlx4_warn(dev, "HCA minimum page size:%d\n", page_size);
  385. if (page_size > PAGE_SIZE) {
  386. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  387. "kernel PAGE_SIZE of %ld, aborting.\n",
  388. page_size, PAGE_SIZE);
  389. return -ENODEV;
  390. }
  391. /* slave gets uar page size from QUERY_HCA fw command */
  392. dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12);
  393. /* TODO: relax this assumption */
  394. if (dev->caps.uar_page_size != PAGE_SIZE) {
  395. mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n",
  396. dev->caps.uar_page_size, PAGE_SIZE);
  397. return -ENODEV;
  398. }
  399. memset(&func_cap, 0, sizeof(func_cap));
  400. err = mlx4_QUERY_FUNC_CAP(dev, &func_cap);
  401. if (err) {
  402. mlx4_err(dev, "QUERY_FUNC_CAP command failed, aborting.\n");
  403. return err;
  404. }
  405. if ((func_cap.pf_context_behaviour | PF_CONTEXT_BEHAVIOUR_MASK) !=
  406. PF_CONTEXT_BEHAVIOUR_MASK) {
  407. mlx4_err(dev, "Unknown pf context behaviour\n");
  408. return -ENOSYS;
  409. }
  410. dev->caps.num_ports = func_cap.num_ports;
  411. dev->caps.num_qps = func_cap.qp_quota;
  412. dev->caps.num_srqs = func_cap.srq_quota;
  413. dev->caps.num_cqs = func_cap.cq_quota;
  414. dev->caps.num_eqs = func_cap.max_eq;
  415. dev->caps.reserved_eqs = func_cap.reserved_eq;
  416. dev->caps.num_mpts = func_cap.mpt_quota;
  417. dev->caps.num_mtts = func_cap.mtt_quota;
  418. dev->caps.num_pds = MLX4_NUM_PDS;
  419. dev->caps.num_mgms = 0;
  420. dev->caps.num_amgms = 0;
  421. for (i = 1; i <= dev->caps.num_ports; ++i)
  422. dev->caps.port_mask[i] = dev->caps.port_type[i];
  423. if (dev->caps.num_ports > MLX4_MAX_PORTS) {
  424. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  425. "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS);
  426. return -ENODEV;
  427. }
  428. if (dev->caps.uar_page_size * (dev->caps.num_uars -
  429. dev->caps.reserved_uars) >
  430. pci_resource_len(dev->pdev, 2)) {
  431. mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than "
  432. "PCI resource 2 size of 0x%llx, aborting.\n",
  433. dev->caps.uar_page_size * dev->caps.num_uars,
  434. (unsigned long long) pci_resource_len(dev->pdev, 2));
  435. return -ENODEV;
  436. }
  437. #if 0
  438. mlx4_warn(dev, "sqp_demux:%d\n", dev->caps.sqp_demux);
  439. mlx4_warn(dev, "num_uars:%d reserved_uars:%d uar region:0x%x bar2:0x%llx\n",
  440. dev->caps.num_uars, dev->caps.reserved_uars,
  441. dev->caps.uar_page_size * dev->caps.num_uars,
  442. pci_resource_len(dev->pdev, 2));
  443. mlx4_warn(dev, "num_eqs:%d reserved_eqs:%d\n", dev->caps.num_eqs,
  444. dev->caps.reserved_eqs);
  445. mlx4_warn(dev, "num_pds:%d reserved_pds:%d slave_pd_shift:%d pd_base:%d\n",
  446. dev->caps.num_pds, dev->caps.reserved_pds,
  447. dev->caps.slave_pd_shift, dev->caps.pd_base);
  448. #endif
  449. return 0;
  450. }
  451. /*
  452. * Change the port configuration of the device.
  453. * Every user of this function must hold the port mutex.
  454. */
  455. int mlx4_change_port_types(struct mlx4_dev *dev,
  456. enum mlx4_port_type *port_types)
  457. {
  458. int err = 0;
  459. int change = 0;
  460. int port;
  461. for (port = 0; port < dev->caps.num_ports; port++) {
  462. /* Change the port type only if the new type is different
  463. * from the current, and not set to Auto */
  464. if (port_types[port] != dev->caps.port_type[port + 1])
  465. change = 1;
  466. }
  467. if (change) {
  468. mlx4_unregister_device(dev);
  469. for (port = 1; port <= dev->caps.num_ports; port++) {
  470. mlx4_CLOSE_PORT(dev, port);
  471. dev->caps.port_type[port] = port_types[port - 1];
  472. err = mlx4_SET_PORT(dev, port);
  473. if (err) {
  474. mlx4_err(dev, "Failed to set port %d, "
  475. "aborting\n", port);
  476. goto out;
  477. }
  478. }
  479. mlx4_set_port_mask(dev);
  480. err = mlx4_register_device(dev);
  481. }
  482. out:
  483. return err;
  484. }
  485. static ssize_t show_port_type(struct device *dev,
  486. struct device_attribute *attr,
  487. char *buf)
  488. {
  489. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  490. port_attr);
  491. struct mlx4_dev *mdev = info->dev;
  492. char type[8];
  493. sprintf(type, "%s",
  494. (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB) ?
  495. "ib" : "eth");
  496. if (mdev->caps.possible_type[info->port] == MLX4_PORT_TYPE_AUTO)
  497. sprintf(buf, "auto (%s)\n", type);
  498. else
  499. sprintf(buf, "%s\n", type);
  500. return strlen(buf);
  501. }
  502. static ssize_t set_port_type(struct device *dev,
  503. struct device_attribute *attr,
  504. const char *buf, size_t count)
  505. {
  506. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  507. port_attr);
  508. struct mlx4_dev *mdev = info->dev;
  509. struct mlx4_priv *priv = mlx4_priv(mdev);
  510. enum mlx4_port_type types[MLX4_MAX_PORTS];
  511. enum mlx4_port_type new_types[MLX4_MAX_PORTS];
  512. int i;
  513. int err = 0;
  514. if (!strcmp(buf, "ib\n"))
  515. info->tmp_type = MLX4_PORT_TYPE_IB;
  516. else if (!strcmp(buf, "eth\n"))
  517. info->tmp_type = MLX4_PORT_TYPE_ETH;
  518. else if (!strcmp(buf, "auto\n"))
  519. info->tmp_type = MLX4_PORT_TYPE_AUTO;
  520. else {
  521. mlx4_err(mdev, "%s is not supported port type\n", buf);
  522. return -EINVAL;
  523. }
  524. mlx4_stop_sense(mdev);
  525. mutex_lock(&priv->port_mutex);
  526. /* Possible type is always the one that was delivered */
  527. mdev->caps.possible_type[info->port] = info->tmp_type;
  528. for (i = 0; i < mdev->caps.num_ports; i++) {
  529. types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type :
  530. mdev->caps.possible_type[i+1];
  531. if (types[i] == MLX4_PORT_TYPE_AUTO)
  532. types[i] = mdev->caps.port_type[i+1];
  533. }
  534. if (!(mdev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) &&
  535. !(mdev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)) {
  536. for (i = 1; i <= mdev->caps.num_ports; i++) {
  537. if (mdev->caps.possible_type[i] == MLX4_PORT_TYPE_AUTO) {
  538. mdev->caps.possible_type[i] = mdev->caps.port_type[i];
  539. err = -EINVAL;
  540. }
  541. }
  542. }
  543. if (err) {
  544. mlx4_err(mdev, "Auto sensing is not supported on this HCA. "
  545. "Set only 'eth' or 'ib' for both ports "
  546. "(should be the same)\n");
  547. goto out;
  548. }
  549. mlx4_do_sense_ports(mdev, new_types, types);
  550. err = mlx4_check_port_params(mdev, new_types);
  551. if (err)
  552. goto out;
  553. /* We are about to apply the changes after the configuration
  554. * was verified, no need to remember the temporary types
  555. * any more */
  556. for (i = 0; i < mdev->caps.num_ports; i++)
  557. priv->port[i + 1].tmp_type = 0;
  558. err = mlx4_change_port_types(mdev, new_types);
  559. out:
  560. mlx4_start_sense(mdev);
  561. mutex_unlock(&priv->port_mutex);
  562. return err ? err : count;
  563. }
  564. enum ibta_mtu {
  565. IB_MTU_256 = 1,
  566. IB_MTU_512 = 2,
  567. IB_MTU_1024 = 3,
  568. IB_MTU_2048 = 4,
  569. IB_MTU_4096 = 5
  570. };
  571. static inline int int_to_ibta_mtu(int mtu)
  572. {
  573. switch (mtu) {
  574. case 256: return IB_MTU_256;
  575. case 512: return IB_MTU_512;
  576. case 1024: return IB_MTU_1024;
  577. case 2048: return IB_MTU_2048;
  578. case 4096: return IB_MTU_4096;
  579. default: return -1;
  580. }
  581. }
  582. static inline int ibta_mtu_to_int(enum ibta_mtu mtu)
  583. {
  584. switch (mtu) {
  585. case IB_MTU_256: return 256;
  586. case IB_MTU_512: return 512;
  587. case IB_MTU_1024: return 1024;
  588. case IB_MTU_2048: return 2048;
  589. case IB_MTU_4096: return 4096;
  590. default: return -1;
  591. }
  592. }
  593. static ssize_t show_port_ib_mtu(struct device *dev,
  594. struct device_attribute *attr,
  595. char *buf)
  596. {
  597. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  598. port_mtu_attr);
  599. struct mlx4_dev *mdev = info->dev;
  600. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH)
  601. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  602. sprintf(buf, "%d\n",
  603. ibta_mtu_to_int(mdev->caps.port_ib_mtu[info->port]));
  604. return strlen(buf);
  605. }
  606. static ssize_t set_port_ib_mtu(struct device *dev,
  607. struct device_attribute *attr,
  608. const char *buf, size_t count)
  609. {
  610. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  611. port_mtu_attr);
  612. struct mlx4_dev *mdev = info->dev;
  613. struct mlx4_priv *priv = mlx4_priv(mdev);
  614. int err, port, mtu, ibta_mtu = -1;
  615. if (mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_ETH) {
  616. mlx4_warn(mdev, "port level mtu is only used for IB ports\n");
  617. return -EINVAL;
  618. }
  619. err = sscanf(buf, "%d", &mtu);
  620. if (err > 0)
  621. ibta_mtu = int_to_ibta_mtu(mtu);
  622. if (err <= 0 || ibta_mtu < 0) {
  623. mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
  624. return -EINVAL;
  625. }
  626. mdev->caps.port_ib_mtu[info->port] = ibta_mtu;
  627. mlx4_stop_sense(mdev);
  628. mutex_lock(&priv->port_mutex);
  629. mlx4_unregister_device(mdev);
  630. for (port = 1; port <= mdev->caps.num_ports; port++) {
  631. mlx4_CLOSE_PORT(mdev, port);
  632. err = mlx4_SET_PORT(mdev, port);
  633. if (err) {
  634. mlx4_err(mdev, "Failed to set port %d, "
  635. "aborting\n", port);
  636. goto err_set_port;
  637. }
  638. }
  639. err = mlx4_register_device(mdev);
  640. err_set_port:
  641. mutex_unlock(&priv->port_mutex);
  642. mlx4_start_sense(mdev);
  643. return err ? err : count;
  644. }
  645. static int mlx4_load_fw(struct mlx4_dev *dev)
  646. {
  647. struct mlx4_priv *priv = mlx4_priv(dev);
  648. int err;
  649. priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
  650. GFP_HIGHUSER | __GFP_NOWARN, 0);
  651. if (!priv->fw.fw_icm) {
  652. mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
  653. return -ENOMEM;
  654. }
  655. err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
  656. if (err) {
  657. mlx4_err(dev, "MAP_FA command failed, aborting.\n");
  658. goto err_free;
  659. }
  660. err = mlx4_RUN_FW(dev);
  661. if (err) {
  662. mlx4_err(dev, "RUN_FW command failed, aborting.\n");
  663. goto err_unmap_fa;
  664. }
  665. return 0;
  666. err_unmap_fa:
  667. mlx4_UNMAP_FA(dev);
  668. err_free:
  669. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  670. return err;
  671. }
  672. static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
  673. int cmpt_entry_sz)
  674. {
  675. struct mlx4_priv *priv = mlx4_priv(dev);
  676. int err;
  677. int num_eqs;
  678. err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
  679. cmpt_base +
  680. ((u64) (MLX4_CMPT_TYPE_QP *
  681. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  682. cmpt_entry_sz, dev->caps.num_qps,
  683. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  684. 0, 0);
  685. if (err)
  686. goto err;
  687. err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
  688. cmpt_base +
  689. ((u64) (MLX4_CMPT_TYPE_SRQ *
  690. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  691. cmpt_entry_sz, dev->caps.num_srqs,
  692. dev->caps.reserved_srqs, 0, 0);
  693. if (err)
  694. goto err_qp;
  695. err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
  696. cmpt_base +
  697. ((u64) (MLX4_CMPT_TYPE_CQ *
  698. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  699. cmpt_entry_sz, dev->caps.num_cqs,
  700. dev->caps.reserved_cqs, 0, 0);
  701. if (err)
  702. goto err_srq;
  703. num_eqs = (mlx4_is_master(dev)) ?
  704. roundup_pow_of_two(mlx4_master_get_num_eqs(dev)) :
  705. dev->caps.num_eqs;
  706. err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
  707. cmpt_base +
  708. ((u64) (MLX4_CMPT_TYPE_EQ *
  709. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  710. cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
  711. if (err)
  712. goto err_cq;
  713. return 0;
  714. err_cq:
  715. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  716. err_srq:
  717. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  718. err_qp:
  719. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  720. err:
  721. return err;
  722. }
  723. static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
  724. struct mlx4_init_hca_param *init_hca, u64 icm_size)
  725. {
  726. struct mlx4_priv *priv = mlx4_priv(dev);
  727. u64 aux_pages;
  728. int num_eqs;
  729. int err;
  730. err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
  731. if (err) {
  732. mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
  733. return err;
  734. }
  735. mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
  736. (unsigned long long) icm_size >> 10,
  737. (unsigned long long) aux_pages << 2);
  738. priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
  739. GFP_HIGHUSER | __GFP_NOWARN, 0);
  740. if (!priv->fw.aux_icm) {
  741. mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
  742. return -ENOMEM;
  743. }
  744. err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
  745. if (err) {
  746. mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
  747. goto err_free_aux;
  748. }
  749. err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
  750. if (err) {
  751. mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
  752. goto err_unmap_aux;
  753. }
  754. num_eqs = (mlx4_is_master(dev)) ?
  755. roundup_pow_of_two(mlx4_master_get_num_eqs(dev)) :
  756. dev->caps.num_eqs;
  757. err = mlx4_init_icm_table(dev, &priv->eq_table.table,
  758. init_hca->eqc_base, dev_cap->eqc_entry_sz,
  759. num_eqs, num_eqs, 0, 0);
  760. if (err) {
  761. mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
  762. goto err_unmap_cmpt;
  763. }
  764. /*
  765. * Reserved MTT entries must be aligned up to a cacheline
  766. * boundary, since the FW will write to them, while the driver
  767. * writes to all other MTT entries. (The variable
  768. * dev->caps.mtt_entry_sz below is really the MTT segment
  769. * size, not the raw entry size)
  770. */
  771. dev->caps.reserved_mtts =
  772. ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
  773. dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
  774. err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
  775. init_hca->mtt_base,
  776. dev->caps.mtt_entry_sz,
  777. dev->caps.num_mtts,
  778. dev->caps.reserved_mtts, 1, 0);
  779. if (err) {
  780. mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
  781. goto err_unmap_eq;
  782. }
  783. err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
  784. init_hca->dmpt_base,
  785. dev_cap->dmpt_entry_sz,
  786. dev->caps.num_mpts,
  787. dev->caps.reserved_mrws, 1, 1);
  788. if (err) {
  789. mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
  790. goto err_unmap_mtt;
  791. }
  792. err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
  793. init_hca->qpc_base,
  794. dev_cap->qpc_entry_sz,
  795. dev->caps.num_qps,
  796. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  797. 0, 0);
  798. if (err) {
  799. mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
  800. goto err_unmap_dmpt;
  801. }
  802. err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
  803. init_hca->auxc_base,
  804. dev_cap->aux_entry_sz,
  805. dev->caps.num_qps,
  806. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  807. 0, 0);
  808. if (err) {
  809. mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
  810. goto err_unmap_qp;
  811. }
  812. err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
  813. init_hca->altc_base,
  814. dev_cap->altc_entry_sz,
  815. dev->caps.num_qps,
  816. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  817. 0, 0);
  818. if (err) {
  819. mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
  820. goto err_unmap_auxc;
  821. }
  822. err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
  823. init_hca->rdmarc_base,
  824. dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
  825. dev->caps.num_qps,
  826. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  827. 0, 0);
  828. if (err) {
  829. mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
  830. goto err_unmap_altc;
  831. }
  832. err = mlx4_init_icm_table(dev, &priv->cq_table.table,
  833. init_hca->cqc_base,
  834. dev_cap->cqc_entry_sz,
  835. dev->caps.num_cqs,
  836. dev->caps.reserved_cqs, 0, 0);
  837. if (err) {
  838. mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
  839. goto err_unmap_rdmarc;
  840. }
  841. err = mlx4_init_icm_table(dev, &priv->srq_table.table,
  842. init_hca->srqc_base,
  843. dev_cap->srq_entry_sz,
  844. dev->caps.num_srqs,
  845. dev->caps.reserved_srqs, 0, 0);
  846. if (err) {
  847. mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
  848. goto err_unmap_cq;
  849. }
  850. /*
  851. * It's not strictly required, but for simplicity just map the
  852. * whole multicast group table now. The table isn't very big
  853. * and it's a lot easier than trying to track ref counts.
  854. */
  855. err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
  856. init_hca->mc_base,
  857. mlx4_get_mgm_entry_size(dev),
  858. dev->caps.num_mgms + dev->caps.num_amgms,
  859. dev->caps.num_mgms + dev->caps.num_amgms,
  860. 0, 0);
  861. if (err) {
  862. mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
  863. goto err_unmap_srq;
  864. }
  865. return 0;
  866. err_unmap_srq:
  867. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  868. err_unmap_cq:
  869. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  870. err_unmap_rdmarc:
  871. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  872. err_unmap_altc:
  873. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  874. err_unmap_auxc:
  875. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  876. err_unmap_qp:
  877. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  878. err_unmap_dmpt:
  879. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  880. err_unmap_mtt:
  881. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  882. err_unmap_eq:
  883. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  884. err_unmap_cmpt:
  885. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  886. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  887. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  888. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  889. err_unmap_aux:
  890. mlx4_UNMAP_ICM_AUX(dev);
  891. err_free_aux:
  892. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  893. return err;
  894. }
  895. static void mlx4_free_icms(struct mlx4_dev *dev)
  896. {
  897. struct mlx4_priv *priv = mlx4_priv(dev);
  898. mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
  899. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  900. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  901. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  902. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  903. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  904. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  905. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  906. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  907. mlx4_cleanup_icm_table(dev, &priv->eq_table.table);
  908. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  909. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  910. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  911. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  912. mlx4_UNMAP_ICM_AUX(dev);
  913. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  914. }
  915. static void mlx4_slave_exit(struct mlx4_dev *dev)
  916. {
  917. struct mlx4_priv *priv = mlx4_priv(dev);
  918. down(&priv->cmd.slave_sem);
  919. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_TIME))
  920. mlx4_warn(dev, "Failed to close slave function.\n");
  921. up(&priv->cmd.slave_sem);
  922. }
  923. static int map_bf_area(struct mlx4_dev *dev)
  924. {
  925. struct mlx4_priv *priv = mlx4_priv(dev);
  926. resource_size_t bf_start;
  927. resource_size_t bf_len;
  928. int err = 0;
  929. if (!dev->caps.bf_reg_size)
  930. return -ENXIO;
  931. bf_start = pci_resource_start(dev->pdev, 2) +
  932. (dev->caps.num_uars << PAGE_SHIFT);
  933. bf_len = pci_resource_len(dev->pdev, 2) -
  934. (dev->caps.num_uars << PAGE_SHIFT);
  935. priv->bf_mapping = io_mapping_create_wc(bf_start, bf_len);
  936. if (!priv->bf_mapping)
  937. err = -ENOMEM;
  938. return err;
  939. }
  940. static void unmap_bf_area(struct mlx4_dev *dev)
  941. {
  942. if (mlx4_priv(dev)->bf_mapping)
  943. io_mapping_free(mlx4_priv(dev)->bf_mapping);
  944. }
  945. static void mlx4_close_hca(struct mlx4_dev *dev)
  946. {
  947. unmap_bf_area(dev);
  948. if (mlx4_is_slave(dev))
  949. mlx4_slave_exit(dev);
  950. else {
  951. mlx4_CLOSE_HCA(dev, 0);
  952. mlx4_free_icms(dev);
  953. mlx4_UNMAP_FA(dev);
  954. mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
  955. }
  956. }
  957. static int mlx4_init_slave(struct mlx4_dev *dev)
  958. {
  959. struct mlx4_priv *priv = mlx4_priv(dev);
  960. u64 dma = (u64) priv->mfunc.vhcr_dma;
  961. int num_of_reset_retries = NUM_OF_RESET_RETRIES;
  962. int ret_from_reset = 0;
  963. u32 slave_read;
  964. u32 cmd_channel_ver;
  965. down(&priv->cmd.slave_sem);
  966. priv->cmd.max_cmds = 1;
  967. mlx4_warn(dev, "Sending reset\n");
  968. ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0,
  969. MLX4_COMM_TIME);
  970. /* if we are in the middle of flr the slave will try
  971. * NUM_OF_RESET_RETRIES times before leaving.*/
  972. if (ret_from_reset) {
  973. if (MLX4_DELAY_RESET_SLAVE == ret_from_reset) {
  974. msleep(SLEEP_TIME_IN_RESET);
  975. while (ret_from_reset && num_of_reset_retries) {
  976. mlx4_warn(dev, "slave is currently in the"
  977. "middle of FLR. retrying..."
  978. "(try num:%d)\n",
  979. (NUM_OF_RESET_RETRIES -
  980. num_of_reset_retries + 1));
  981. ret_from_reset =
  982. mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET,
  983. 0, MLX4_COMM_TIME);
  984. num_of_reset_retries = num_of_reset_retries - 1;
  985. }
  986. } else
  987. goto err;
  988. }
  989. /* check the driver version - the slave I/F revision
  990. * must match the master's */
  991. slave_read = swab32(readl(&priv->mfunc.comm->slave_read));
  992. cmd_channel_ver = mlx4_comm_get_version();
  993. if (MLX4_COMM_GET_IF_REV(cmd_channel_ver) !=
  994. MLX4_COMM_GET_IF_REV(slave_read)) {
  995. mlx4_err(dev, "slave driver version is not supported"
  996. " by the master\n");
  997. goto err;
  998. }
  999. mlx4_warn(dev, "Sending vhcr0\n");
  1000. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48,
  1001. MLX4_COMM_TIME))
  1002. goto err;
  1003. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32,
  1004. MLX4_COMM_TIME))
  1005. goto err;
  1006. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16,
  1007. MLX4_COMM_TIME))
  1008. goto err;
  1009. if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, MLX4_COMM_TIME))
  1010. goto err;
  1011. up(&priv->cmd.slave_sem);
  1012. return 0;
  1013. err:
  1014. mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, 0);
  1015. up(&priv->cmd.slave_sem);
  1016. return -EIO;
  1017. }
  1018. static int mlx4_init_hca(struct mlx4_dev *dev)
  1019. {
  1020. struct mlx4_priv *priv = mlx4_priv(dev);
  1021. struct mlx4_adapter adapter;
  1022. struct mlx4_dev_cap dev_cap;
  1023. struct mlx4_mod_stat_cfg mlx4_cfg;
  1024. struct mlx4_profile profile;
  1025. struct mlx4_init_hca_param init_hca;
  1026. u64 icm_size;
  1027. int err;
  1028. if (!mlx4_is_slave(dev)) {
  1029. err = mlx4_QUERY_FW(dev);
  1030. if (err) {
  1031. if (err == -EACCES)
  1032. mlx4_info(dev, "non-primary physical function, skipping.\n");
  1033. else
  1034. mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
  1035. goto unmap_bf;
  1036. }
  1037. err = mlx4_load_fw(dev);
  1038. if (err) {
  1039. mlx4_err(dev, "Failed to start FW, aborting.\n");
  1040. goto unmap_bf;
  1041. }
  1042. mlx4_cfg.log_pg_sz_m = 1;
  1043. mlx4_cfg.log_pg_sz = 0;
  1044. err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
  1045. if (err)
  1046. mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
  1047. err = mlx4_dev_cap(dev, &dev_cap);
  1048. if (err) {
  1049. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  1050. goto err_stop_fw;
  1051. }
  1052. profile = default_profile;
  1053. icm_size = mlx4_make_profile(dev, &profile, &dev_cap,
  1054. &init_hca);
  1055. if ((long long) icm_size < 0) {
  1056. err = icm_size;
  1057. goto err_stop_fw;
  1058. }
  1059. dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1;
  1060. init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
  1061. init_hca.uar_page_sz = PAGE_SHIFT - 12;
  1062. err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
  1063. if (err)
  1064. goto err_stop_fw;
  1065. err = mlx4_INIT_HCA(dev, &init_hca);
  1066. if (err) {
  1067. mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
  1068. goto err_free_icm;
  1069. }
  1070. } else {
  1071. err = mlx4_init_slave(dev);
  1072. if (err) {
  1073. mlx4_err(dev, "Failed to initialize slave\n");
  1074. goto unmap_bf;
  1075. }
  1076. err = mlx4_slave_cap(dev);
  1077. if (err) {
  1078. mlx4_err(dev, "Failed to obtain slave caps\n");
  1079. goto err_close;
  1080. }
  1081. }
  1082. if (map_bf_area(dev))
  1083. mlx4_dbg(dev, "Failed to map blue flame area\n");
  1084. /*Only the master set the ports, all the rest got it from it.*/
  1085. if (!mlx4_is_slave(dev))
  1086. mlx4_set_port_mask(dev);
  1087. err = mlx4_QUERY_ADAPTER(dev, &adapter);
  1088. if (err) {
  1089. mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
  1090. goto err_close;
  1091. }
  1092. priv->eq_table.inta_pin = adapter.inta_pin;
  1093. memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
  1094. return 0;
  1095. err_close:
  1096. mlx4_close_hca(dev);
  1097. err_free_icm:
  1098. if (!mlx4_is_slave(dev))
  1099. mlx4_free_icms(dev);
  1100. err_stop_fw:
  1101. if (!mlx4_is_slave(dev)) {
  1102. mlx4_UNMAP_FA(dev);
  1103. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  1104. }
  1105. unmap_bf:
  1106. unmap_bf_area(dev);
  1107. return err;
  1108. }
  1109. static int mlx4_init_counters_table(struct mlx4_dev *dev)
  1110. {
  1111. struct mlx4_priv *priv = mlx4_priv(dev);
  1112. int nent;
  1113. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1114. return -ENOENT;
  1115. nent = dev->caps.max_counters;
  1116. return mlx4_bitmap_init(&priv->counters_bitmap, nent, nent - 1, 0, 0);
  1117. }
  1118. static void mlx4_cleanup_counters_table(struct mlx4_dev *dev)
  1119. {
  1120. mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap);
  1121. }
  1122. int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx)
  1123. {
  1124. struct mlx4_priv *priv = mlx4_priv(dev);
  1125. if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS))
  1126. return -ENOENT;
  1127. *idx = mlx4_bitmap_alloc(&priv->counters_bitmap);
  1128. if (*idx == -1)
  1129. return -ENOMEM;
  1130. return 0;
  1131. }
  1132. EXPORT_SYMBOL_GPL(mlx4_counter_alloc);
  1133. void mlx4_counter_free(struct mlx4_dev *dev, u32 idx)
  1134. {
  1135. mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx);
  1136. return;
  1137. }
  1138. EXPORT_SYMBOL_GPL(mlx4_counter_free);
  1139. static int mlx4_setup_hca(struct mlx4_dev *dev)
  1140. {
  1141. struct mlx4_priv *priv = mlx4_priv(dev);
  1142. int err;
  1143. int port;
  1144. __be32 ib_port_default_caps;
  1145. err = mlx4_init_uar_table(dev);
  1146. if (err) {
  1147. mlx4_err(dev, "Failed to initialize "
  1148. "user access region table, aborting.\n");
  1149. return err;
  1150. }
  1151. err = mlx4_uar_alloc(dev, &priv->driver_uar);
  1152. if (err) {
  1153. mlx4_err(dev, "Failed to allocate driver access region, "
  1154. "aborting.\n");
  1155. goto err_uar_table_free;
  1156. }
  1157. priv->kar = ioremap((phys_addr_t) priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  1158. if (!priv->kar) {
  1159. mlx4_err(dev, "Couldn't map kernel access region, "
  1160. "aborting.\n");
  1161. err = -ENOMEM;
  1162. goto err_uar_free;
  1163. }
  1164. err = mlx4_init_pd_table(dev);
  1165. if (err) {
  1166. mlx4_err(dev, "Failed to initialize "
  1167. "protection domain table, aborting.\n");
  1168. goto err_kar_unmap;
  1169. }
  1170. err = mlx4_init_xrcd_table(dev);
  1171. if (err) {
  1172. mlx4_err(dev, "Failed to initialize "
  1173. "reliable connection domain table, aborting.\n");
  1174. goto err_pd_table_free;
  1175. }
  1176. err = mlx4_init_mr_table(dev);
  1177. if (err) {
  1178. mlx4_err(dev, "Failed to initialize "
  1179. "memory region table, aborting.\n");
  1180. goto err_xrcd_table_free;
  1181. }
  1182. err = mlx4_init_eq_table(dev);
  1183. if (err) {
  1184. mlx4_err(dev, "Failed to initialize "
  1185. "event queue table, aborting.\n");
  1186. goto err_mr_table_free;
  1187. }
  1188. err = mlx4_cmd_use_events(dev);
  1189. if (err) {
  1190. mlx4_err(dev, "Failed to switch to event-driven "
  1191. "firmware commands, aborting.\n");
  1192. goto err_eq_table_free;
  1193. }
  1194. err = mlx4_NOP(dev);
  1195. if (err) {
  1196. if (dev->flags & MLX4_FLAG_MSI_X) {
  1197. mlx4_warn(dev, "NOP command failed to generate MSI-X "
  1198. "interrupt IRQ %d).\n",
  1199. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1200. mlx4_warn(dev, "Trying again without MSI-X.\n");
  1201. } else {
  1202. mlx4_err(dev, "NOP command failed to generate interrupt "
  1203. "(IRQ %d), aborting.\n",
  1204. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  1205. mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
  1206. }
  1207. goto err_cmd_poll;
  1208. }
  1209. mlx4_dbg(dev, "NOP command IRQ test passed\n");
  1210. err = mlx4_init_cq_table(dev);
  1211. if (err) {
  1212. mlx4_err(dev, "Failed to initialize "
  1213. "completion queue table, aborting.\n");
  1214. goto err_cmd_poll;
  1215. }
  1216. err = mlx4_init_srq_table(dev);
  1217. if (err) {
  1218. mlx4_err(dev, "Failed to initialize "
  1219. "shared receive queue table, aborting.\n");
  1220. goto err_cq_table_free;
  1221. }
  1222. err = mlx4_init_qp_table(dev);
  1223. if (err) {
  1224. mlx4_err(dev, "Failed to initialize "
  1225. "queue pair table, aborting.\n");
  1226. goto err_srq_table_free;
  1227. }
  1228. if (!mlx4_is_slave(dev)) {
  1229. err = mlx4_init_mcg_table(dev);
  1230. if (err) {
  1231. mlx4_err(dev, "Failed to initialize "
  1232. "multicast group table, aborting.\n");
  1233. goto err_qp_table_free;
  1234. }
  1235. }
  1236. err = mlx4_init_counters_table(dev);
  1237. if (err && err != -ENOENT) {
  1238. mlx4_err(dev, "Failed to initialize counters table, aborting.\n");
  1239. goto err_mcg_table_free;
  1240. }
  1241. if (!mlx4_is_slave(dev)) {
  1242. for (port = 1; port <= dev->caps.num_ports; port++) {
  1243. ib_port_default_caps = 0;
  1244. err = mlx4_get_port_ib_caps(dev, port,
  1245. &ib_port_default_caps);
  1246. if (err)
  1247. mlx4_warn(dev, "failed to get port %d default "
  1248. "ib capabilities (%d). Continuing "
  1249. "with caps = 0\n", port, err);
  1250. dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
  1251. if (mlx4_is_mfunc(dev))
  1252. dev->caps.port_ib_mtu[port] = IB_MTU_2048;
  1253. else
  1254. dev->caps.port_ib_mtu[port] = IB_MTU_4096;
  1255. err = mlx4_SET_PORT(dev, port);
  1256. if (err) {
  1257. mlx4_err(dev, "Failed to set port %d, aborting\n",
  1258. port);
  1259. goto err_counters_table_free;
  1260. }
  1261. }
  1262. }
  1263. return 0;
  1264. err_counters_table_free:
  1265. mlx4_cleanup_counters_table(dev);
  1266. err_mcg_table_free:
  1267. mlx4_cleanup_mcg_table(dev);
  1268. err_qp_table_free:
  1269. mlx4_cleanup_qp_table(dev);
  1270. err_srq_table_free:
  1271. mlx4_cleanup_srq_table(dev);
  1272. err_cq_table_free:
  1273. mlx4_cleanup_cq_table(dev);
  1274. err_cmd_poll:
  1275. mlx4_cmd_use_polling(dev);
  1276. err_eq_table_free:
  1277. mlx4_cleanup_eq_table(dev);
  1278. err_mr_table_free:
  1279. mlx4_cleanup_mr_table(dev);
  1280. err_xrcd_table_free:
  1281. mlx4_cleanup_xrcd_table(dev);
  1282. err_pd_table_free:
  1283. mlx4_cleanup_pd_table(dev);
  1284. err_kar_unmap:
  1285. iounmap(priv->kar);
  1286. err_uar_free:
  1287. mlx4_uar_free(dev, &priv->driver_uar);
  1288. err_uar_table_free:
  1289. mlx4_cleanup_uar_table(dev);
  1290. return err;
  1291. }
  1292. static void mlx4_enable_msi_x(struct mlx4_dev *dev)
  1293. {
  1294. struct mlx4_priv *priv = mlx4_priv(dev);
  1295. struct msix_entry *entries;
  1296. int nreq = min_t(int, dev->caps.num_ports *
  1297. min_t(int, num_online_cpus() + 1, MAX_MSIX_P_PORT)
  1298. + MSIX_LEGACY_SZ, MAX_MSIX);
  1299. int err;
  1300. int i;
  1301. if (msi_x) {
  1302. /* In multifunction mode each function gets 2 msi-X vectors
  1303. * one for data path completions anf the other for asynch events
  1304. * or command completions */
  1305. if (mlx4_is_mfunc(dev)) {
  1306. nreq = 2;
  1307. } else {
  1308. nreq = min_t(int, dev->caps.num_eqs -
  1309. dev->caps.reserved_eqs, nreq);
  1310. }
  1311. entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
  1312. if (!entries)
  1313. goto no_msi;
  1314. for (i = 0; i < nreq; ++i)
  1315. entries[i].entry = i;
  1316. retry:
  1317. err = pci_enable_msix(dev->pdev, entries, nreq);
  1318. if (err) {
  1319. /* Try again if at least 2 vectors are available */
  1320. if (err > 1) {
  1321. mlx4_info(dev, "Requested %d vectors, "
  1322. "but only %d MSI-X vectors available, "
  1323. "trying again\n", nreq, err);
  1324. nreq = err;
  1325. goto retry;
  1326. }
  1327. kfree(entries);
  1328. goto no_msi;
  1329. }
  1330. if (nreq <
  1331. MSIX_LEGACY_SZ + dev->caps.num_ports * MIN_MSIX_P_PORT) {
  1332. /*Working in legacy mode , all EQ's shared*/
  1333. dev->caps.comp_pool = 0;
  1334. dev->caps.num_comp_vectors = nreq - 1;
  1335. } else {
  1336. dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ;
  1337. dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1;
  1338. }
  1339. for (i = 0; i < nreq; ++i)
  1340. priv->eq_table.eq[i].irq = entries[i].vector;
  1341. dev->flags |= MLX4_FLAG_MSI_X;
  1342. kfree(entries);
  1343. return;
  1344. }
  1345. no_msi:
  1346. dev->caps.num_comp_vectors = 1;
  1347. dev->caps.comp_pool = 0;
  1348. for (i = 0; i < 2; ++i)
  1349. priv->eq_table.eq[i].irq = dev->pdev->irq;
  1350. }
  1351. static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  1352. {
  1353. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  1354. int err = 0;
  1355. info->dev = dev;
  1356. info->port = port;
  1357. if (!mlx4_is_slave(dev)) {
  1358. INIT_RADIX_TREE(&info->mac_tree, GFP_KERNEL);
  1359. mlx4_init_mac_table(dev, &info->mac_table);
  1360. mlx4_init_vlan_table(dev, &info->vlan_table);
  1361. info->base_qpn =
  1362. dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
  1363. (port - 1) * (1 << log_num_mac);
  1364. }
  1365. sprintf(info->dev_name, "mlx4_port%d", port);
  1366. info->port_attr.attr.name = info->dev_name;
  1367. if (mlx4_is_mfunc(dev))
  1368. info->port_attr.attr.mode = S_IRUGO;
  1369. else {
  1370. info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
  1371. info->port_attr.store = set_port_type;
  1372. }
  1373. info->port_attr.show = show_port_type;
  1374. sysfs_attr_init(&info->port_attr.attr);
  1375. err = device_create_file(&dev->pdev->dev, &info->port_attr);
  1376. if (err) {
  1377. mlx4_err(dev, "Failed to create file for port %d\n", port);
  1378. info->port = -1;
  1379. }
  1380. sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
  1381. info->port_mtu_attr.attr.name = info->dev_mtu_name;
  1382. if (mlx4_is_mfunc(dev))
  1383. info->port_mtu_attr.attr.mode = S_IRUGO;
  1384. else {
  1385. info->port_mtu_attr.attr.mode = S_IRUGO | S_IWUSR;
  1386. info->port_mtu_attr.store = set_port_ib_mtu;
  1387. }
  1388. info->port_mtu_attr.show = show_port_ib_mtu;
  1389. sysfs_attr_init(&info->port_mtu_attr.attr);
  1390. err = device_create_file(&dev->pdev->dev, &info->port_mtu_attr);
  1391. if (err) {
  1392. mlx4_err(dev, "Failed to create mtu file for port %d\n", port);
  1393. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1394. info->port = -1;
  1395. }
  1396. return err;
  1397. }
  1398. static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
  1399. {
  1400. if (info->port < 0)
  1401. return;
  1402. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  1403. device_remove_file(&info->dev->pdev->dev, &info->port_mtu_attr);
  1404. }
  1405. static int mlx4_init_steering(struct mlx4_dev *dev)
  1406. {
  1407. struct mlx4_priv *priv = mlx4_priv(dev);
  1408. int num_entries = dev->caps.num_ports;
  1409. int i, j;
  1410. priv->steer = kzalloc(sizeof(struct mlx4_steer) * num_entries, GFP_KERNEL);
  1411. if (!priv->steer)
  1412. return -ENOMEM;
  1413. for (i = 0; i < num_entries; i++)
  1414. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1415. INIT_LIST_HEAD(&priv->steer[i].promisc_qps[j]);
  1416. INIT_LIST_HEAD(&priv->steer[i].steer_entries[j]);
  1417. }
  1418. return 0;
  1419. }
  1420. static void mlx4_clear_steering(struct mlx4_dev *dev)
  1421. {
  1422. struct mlx4_priv *priv = mlx4_priv(dev);
  1423. struct mlx4_steer_index *entry, *tmp_entry;
  1424. struct mlx4_promisc_qp *pqp, *tmp_pqp;
  1425. int num_entries = dev->caps.num_ports;
  1426. int i, j;
  1427. for (i = 0; i < num_entries; i++) {
  1428. for (j = 0; j < MLX4_NUM_STEERS; j++) {
  1429. list_for_each_entry_safe(pqp, tmp_pqp,
  1430. &priv->steer[i].promisc_qps[j],
  1431. list) {
  1432. list_del(&pqp->list);
  1433. kfree(pqp);
  1434. }
  1435. list_for_each_entry_safe(entry, tmp_entry,
  1436. &priv->steer[i].steer_entries[j],
  1437. list) {
  1438. list_del(&entry->list);
  1439. list_for_each_entry_safe(pqp, tmp_pqp,
  1440. &entry->duplicates,
  1441. list) {
  1442. list_del(&pqp->list);
  1443. kfree(pqp);
  1444. }
  1445. kfree(entry);
  1446. }
  1447. }
  1448. }
  1449. kfree(priv->steer);
  1450. }
  1451. static int extended_func_num(struct pci_dev *pdev)
  1452. {
  1453. return PCI_SLOT(pdev->devfn) * 8 + PCI_FUNC(pdev->devfn);
  1454. }
  1455. #define MLX4_OWNER_BASE 0x8069c
  1456. #define MLX4_OWNER_SIZE 4
  1457. static int mlx4_get_ownership(struct mlx4_dev *dev)
  1458. {
  1459. void __iomem *owner;
  1460. u32 ret;
  1461. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1462. MLX4_OWNER_SIZE);
  1463. if (!owner) {
  1464. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1465. return -ENOMEM;
  1466. }
  1467. ret = readl(owner);
  1468. iounmap(owner);
  1469. return (int) !!ret;
  1470. }
  1471. static void mlx4_free_ownership(struct mlx4_dev *dev)
  1472. {
  1473. void __iomem *owner;
  1474. owner = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_OWNER_BASE,
  1475. MLX4_OWNER_SIZE);
  1476. if (!owner) {
  1477. mlx4_err(dev, "Failed to obtain ownership bit\n");
  1478. return;
  1479. }
  1480. writel(0, owner);
  1481. msleep(1000);
  1482. iounmap(owner);
  1483. }
  1484. static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1485. {
  1486. struct mlx4_priv *priv;
  1487. struct mlx4_dev *dev;
  1488. int err;
  1489. int port;
  1490. pr_info(DRV_NAME ": Initializing %s\n", pci_name(pdev));
  1491. err = pci_enable_device(pdev);
  1492. if (err) {
  1493. dev_err(&pdev->dev, "Cannot enable PCI device, "
  1494. "aborting.\n");
  1495. return err;
  1496. }
  1497. if (num_vfs > MLX4_MAX_NUM_VF) {
  1498. printk(KERN_ERR "There are more VF's (%d) than allowed(%d)\n",
  1499. num_vfs, MLX4_MAX_NUM_VF);
  1500. return -EINVAL;
  1501. }
  1502. /*
  1503. * Check for BARs.
  1504. */
  1505. if (((id == NULL) || !(id->driver_data & MLX4_VF)) &&
  1506. !(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  1507. dev_err(&pdev->dev, "Missing DCS, aborting."
  1508. "(id == 0X%p, id->driver_data: 0x%lx,"
  1509. " pci_resource_flags(pdev, 0):0x%lx)\n", id,
  1510. id ? id->driver_data : 0, pci_resource_flags(pdev, 0));
  1511. err = -ENODEV;
  1512. goto err_disable_pdev;
  1513. }
  1514. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  1515. dev_err(&pdev->dev, "Missing UAR, aborting.\n");
  1516. err = -ENODEV;
  1517. goto err_disable_pdev;
  1518. }
  1519. err = pci_request_regions(pdev, DRV_NAME);
  1520. if (err) {
  1521. dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
  1522. goto err_disable_pdev;
  1523. }
  1524. pci_set_master(pdev);
  1525. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  1526. if (err) {
  1527. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
  1528. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1529. if (err) {
  1530. dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
  1531. goto err_release_regions;
  1532. }
  1533. }
  1534. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  1535. if (err) {
  1536. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
  1537. "consistent PCI DMA mask.\n");
  1538. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1539. if (err) {
  1540. dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
  1541. "aborting.\n");
  1542. goto err_release_regions;
  1543. }
  1544. }
  1545. /* Allow large DMA segments, up to the firmware limit of 1 GB */
  1546. dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024);
  1547. priv = kzalloc(sizeof *priv, GFP_KERNEL);
  1548. if (!priv) {
  1549. dev_err(&pdev->dev, "Device struct alloc failed, "
  1550. "aborting.\n");
  1551. err = -ENOMEM;
  1552. goto err_release_regions;
  1553. }
  1554. dev = &priv->dev;
  1555. dev->pdev = pdev;
  1556. INIT_LIST_HEAD(&priv->ctx_list);
  1557. spin_lock_init(&priv->ctx_lock);
  1558. mutex_init(&priv->port_mutex);
  1559. INIT_LIST_HEAD(&priv->pgdir_list);
  1560. mutex_init(&priv->pgdir_mutex);
  1561. INIT_LIST_HEAD(&priv->bf_list);
  1562. mutex_init(&priv->bf_mutex);
  1563. dev->rev_id = pdev->revision;
  1564. /* Detect if this device is a virtual function */
  1565. if (id && id->driver_data & MLX4_VF) {
  1566. /* When acting as pf, we normally skip vfs unless explicitly
  1567. * requested to probe them. */
  1568. if (num_vfs && extended_func_num(pdev) > probe_vf) {
  1569. mlx4_warn(dev, "Skipping virtual function:%d\n",
  1570. extended_func_num(pdev));
  1571. err = -ENODEV;
  1572. goto err_free_dev;
  1573. }
  1574. mlx4_warn(dev, "Detected virtual function - running in slave mode\n");
  1575. dev->flags |= MLX4_FLAG_SLAVE;
  1576. } else {
  1577. /* We reset the device and enable SRIOV only for physical
  1578. * devices. Try to claim ownership on the device;
  1579. * if already taken, skip -- do not allow multiple PFs */
  1580. err = mlx4_get_ownership(dev);
  1581. if (err) {
  1582. if (err < 0)
  1583. goto err_free_dev;
  1584. else {
  1585. mlx4_warn(dev, "Multiple PFs not yet supported."
  1586. " Skipping PF.\n");
  1587. err = -EINVAL;
  1588. goto err_free_dev;
  1589. }
  1590. }
  1591. if (num_vfs) {
  1592. mlx4_warn(dev, "Enabling sriov with:%d vfs\n", num_vfs);
  1593. err = pci_enable_sriov(pdev, num_vfs);
  1594. if (err) {
  1595. mlx4_err(dev, "Failed to enable sriov,"
  1596. "continuing without sriov enabled"
  1597. " (err = %d).\n", err);
  1598. num_vfs = 0;
  1599. err = 0;
  1600. } else {
  1601. mlx4_warn(dev, "Running in master mode\n");
  1602. dev->flags |= MLX4_FLAG_SRIOV |
  1603. MLX4_FLAG_MASTER;
  1604. dev->num_vfs = num_vfs;
  1605. }
  1606. }
  1607. /*
  1608. * Now reset the HCA before we touch the PCI capabilities or
  1609. * attempt a firmware command, since a boot ROM may have left
  1610. * the HCA in an undefined state.
  1611. */
  1612. err = mlx4_reset(dev);
  1613. if (err) {
  1614. mlx4_err(dev, "Failed to reset HCA, aborting.\n");
  1615. goto err_rel_own;
  1616. }
  1617. }
  1618. slave_start:
  1619. if (mlx4_cmd_init(dev)) {
  1620. mlx4_err(dev, "Failed to init command interface, aborting.\n");
  1621. goto err_sriov;
  1622. }
  1623. /* In slave functions, the communication channel must be initialized
  1624. * before posting commands. Also, init num_slaves before calling
  1625. * mlx4_init_hca */
  1626. if (mlx4_is_mfunc(dev)) {
  1627. if (mlx4_is_master(dev))
  1628. dev->num_slaves = MLX4_MAX_NUM_SLAVES;
  1629. else {
  1630. dev->num_slaves = 0;
  1631. if (mlx4_multi_func_init(dev)) {
  1632. mlx4_err(dev, "Failed to init slave mfunc"
  1633. " interface, aborting.\n");
  1634. goto err_cmd;
  1635. }
  1636. }
  1637. }
  1638. err = mlx4_init_hca(dev);
  1639. if (err) {
  1640. if (err == -EACCES) {
  1641. /* Not primary Physical function
  1642. * Running in slave mode */
  1643. mlx4_cmd_cleanup(dev);
  1644. dev->flags |= MLX4_FLAG_SLAVE;
  1645. dev->flags &= ~MLX4_FLAG_MASTER;
  1646. goto slave_start;
  1647. } else
  1648. goto err_mfunc;
  1649. }
  1650. /* In master functions, the communication channel must be initialized
  1651. * after obtaining its address from fw */
  1652. if (mlx4_is_master(dev)) {
  1653. if (mlx4_multi_func_init(dev)) {
  1654. mlx4_err(dev, "Failed to init master mfunc"
  1655. "interface, aborting.\n");
  1656. goto err_close;
  1657. }
  1658. }
  1659. err = mlx4_alloc_eq_table(dev);
  1660. if (err)
  1661. goto err_master_mfunc;
  1662. priv->msix_ctl.pool_bm = 0;
  1663. mutex_init(&priv->msix_ctl.pool_lock);
  1664. mlx4_enable_msi_x(dev);
  1665. if ((mlx4_is_mfunc(dev)) &&
  1666. !(dev->flags & MLX4_FLAG_MSI_X)) {
  1667. mlx4_err(dev, "INTx is not supported in multi-function mode."
  1668. " aborting.\n");
  1669. goto err_free_eq;
  1670. }
  1671. if (!mlx4_is_slave(dev)) {
  1672. err = mlx4_init_steering(dev);
  1673. if (err)
  1674. goto err_free_eq;
  1675. }
  1676. err = mlx4_setup_hca(dev);
  1677. if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) &&
  1678. !mlx4_is_mfunc(dev)) {
  1679. dev->flags &= ~MLX4_FLAG_MSI_X;
  1680. pci_disable_msix(pdev);
  1681. err = mlx4_setup_hca(dev);
  1682. }
  1683. if (err)
  1684. goto err_steer;
  1685. for (port = 1; port <= dev->caps.num_ports; port++) {
  1686. err = mlx4_init_port_info(dev, port);
  1687. if (err)
  1688. goto err_port;
  1689. }
  1690. err = mlx4_register_device(dev);
  1691. if (err)
  1692. goto err_port;
  1693. mlx4_sense_init(dev);
  1694. mlx4_start_sense(dev);
  1695. pci_set_drvdata(pdev, dev);
  1696. return 0;
  1697. err_port:
  1698. for (--port; port >= 1; --port)
  1699. mlx4_cleanup_port_info(&priv->port[port]);
  1700. mlx4_cleanup_counters_table(dev);
  1701. mlx4_cleanup_mcg_table(dev);
  1702. mlx4_cleanup_qp_table(dev);
  1703. mlx4_cleanup_srq_table(dev);
  1704. mlx4_cleanup_cq_table(dev);
  1705. mlx4_cmd_use_polling(dev);
  1706. mlx4_cleanup_eq_table(dev);
  1707. mlx4_cleanup_mr_table(dev);
  1708. mlx4_cleanup_xrcd_table(dev);
  1709. mlx4_cleanup_pd_table(dev);
  1710. mlx4_cleanup_uar_table(dev);
  1711. err_steer:
  1712. if (!mlx4_is_slave(dev))
  1713. mlx4_clear_steering(dev);
  1714. err_free_eq:
  1715. mlx4_free_eq_table(dev);
  1716. err_master_mfunc:
  1717. if (mlx4_is_master(dev))
  1718. mlx4_multi_func_cleanup(dev);
  1719. err_close:
  1720. if (dev->flags & MLX4_FLAG_MSI_X)
  1721. pci_disable_msix(pdev);
  1722. mlx4_close_hca(dev);
  1723. err_mfunc:
  1724. if (mlx4_is_slave(dev))
  1725. mlx4_multi_func_cleanup(dev);
  1726. err_cmd:
  1727. mlx4_cmd_cleanup(dev);
  1728. err_sriov:
  1729. if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV))
  1730. pci_disable_sriov(pdev);
  1731. err_rel_own:
  1732. if (!mlx4_is_slave(dev))
  1733. mlx4_free_ownership(dev);
  1734. err_free_dev:
  1735. kfree(priv);
  1736. err_release_regions:
  1737. pci_release_regions(pdev);
  1738. err_disable_pdev:
  1739. pci_disable_device(pdev);
  1740. pci_set_drvdata(pdev, NULL);
  1741. return err;
  1742. }
  1743. static int __devinit mlx4_init_one(struct pci_dev *pdev,
  1744. const struct pci_device_id *id)
  1745. {
  1746. printk_once(KERN_INFO "%s", mlx4_version);
  1747. return __mlx4_init_one(pdev, id);
  1748. }
  1749. static void mlx4_remove_one(struct pci_dev *pdev)
  1750. {
  1751. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  1752. struct mlx4_priv *priv = mlx4_priv(dev);
  1753. int p;
  1754. if (dev) {
  1755. /* in SRIOV it is not allowed to unload the pf's
  1756. * driver while there are alive vf's */
  1757. if (mlx4_is_master(dev)) {
  1758. if (mlx4_how_many_lives_vf(dev))
  1759. printk(KERN_ERR "Removing PF when there are assigned VF's !!!\n");
  1760. }
  1761. mlx4_stop_sense(dev);
  1762. mlx4_unregister_device(dev);
  1763. for (p = 1; p <= dev->caps.num_ports; p++) {
  1764. mlx4_cleanup_port_info(&priv->port[p]);
  1765. mlx4_CLOSE_PORT(dev, p);
  1766. }
  1767. mlx4_cleanup_counters_table(dev);
  1768. mlx4_cleanup_mcg_table(dev);
  1769. mlx4_cleanup_qp_table(dev);
  1770. mlx4_cleanup_srq_table(dev);
  1771. mlx4_cleanup_cq_table(dev);
  1772. mlx4_cmd_use_polling(dev);
  1773. mlx4_cleanup_eq_table(dev);
  1774. mlx4_cleanup_mr_table(dev);
  1775. mlx4_cleanup_xrcd_table(dev);
  1776. mlx4_cleanup_pd_table(dev);
  1777. if (mlx4_is_master(dev))
  1778. mlx4_free_resource_tracker(dev);
  1779. iounmap(priv->kar);
  1780. mlx4_uar_free(dev, &priv->driver_uar);
  1781. mlx4_cleanup_uar_table(dev);
  1782. if (!mlx4_is_slave(dev))
  1783. mlx4_clear_steering(dev);
  1784. mlx4_free_eq_table(dev);
  1785. if (mlx4_is_master(dev))
  1786. mlx4_multi_func_cleanup(dev);
  1787. mlx4_close_hca(dev);
  1788. if (mlx4_is_slave(dev))
  1789. mlx4_multi_func_cleanup(dev);
  1790. mlx4_cmd_cleanup(dev);
  1791. if (dev->flags & MLX4_FLAG_MSI_X)
  1792. pci_disable_msix(pdev);
  1793. if (num_vfs && (dev->flags & MLX4_FLAG_SRIOV)) {
  1794. mlx4_warn(dev, "Disabling sriov\n");
  1795. pci_disable_sriov(pdev);
  1796. }
  1797. if (!mlx4_is_slave(dev))
  1798. mlx4_free_ownership(dev);
  1799. kfree(priv);
  1800. pci_release_regions(pdev);
  1801. pci_disable_device(pdev);
  1802. pci_set_drvdata(pdev, NULL);
  1803. }
  1804. }
  1805. int mlx4_restart_one(struct pci_dev *pdev)
  1806. {
  1807. mlx4_remove_one(pdev);
  1808. return __mlx4_init_one(pdev, NULL);
  1809. }
  1810. static DEFINE_PCI_DEVICE_TABLE(mlx4_pci_table) = {
  1811. /* MT25408 "Hermon" SDR */
  1812. { PCI_VDEVICE(MELLANOX, 0x6340), 0 },
  1813. /* MT25408 "Hermon" DDR */
  1814. { PCI_VDEVICE(MELLANOX, 0x634a), 0 },
  1815. /* MT25408 "Hermon" QDR */
  1816. { PCI_VDEVICE(MELLANOX, 0x6354), 0 },
  1817. /* MT25408 "Hermon" DDR PCIe gen2 */
  1818. { PCI_VDEVICE(MELLANOX, 0x6732), 0 },
  1819. /* MT25408 "Hermon" QDR PCIe gen2 */
  1820. { PCI_VDEVICE(MELLANOX, 0x673c), 0 },
  1821. /* MT25408 "Hermon" EN 10GigE */
  1822. { PCI_VDEVICE(MELLANOX, 0x6368), 0 },
  1823. /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
  1824. { PCI_VDEVICE(MELLANOX, 0x6750), 0 },
  1825. /* MT25458 ConnectX EN 10GBASE-T 10GigE */
  1826. { PCI_VDEVICE(MELLANOX, 0x6372), 0 },
  1827. /* MT25458 ConnectX EN 10GBASE-T+Gen2 10GigE */
  1828. { PCI_VDEVICE(MELLANOX, 0x675a), 0 },
  1829. /* MT26468 ConnectX EN 10GigE PCIe gen2*/
  1830. { PCI_VDEVICE(MELLANOX, 0x6764), 0 },
  1831. /* MT26438 ConnectX EN 40GigE PCIe gen2 5GT/s */
  1832. { PCI_VDEVICE(MELLANOX, 0x6746), 0 },
  1833. /* MT26478 ConnectX2 40GigE PCIe gen2 */
  1834. { PCI_VDEVICE(MELLANOX, 0x676e), 0 },
  1835. /* MT25400 Family [ConnectX-2 Virtual Function] */
  1836. { PCI_VDEVICE(MELLANOX, 0x1002), MLX4_VF },
  1837. /* MT27500 Family [ConnectX-3] */
  1838. { PCI_VDEVICE(MELLANOX, 0x1003), 0 },
  1839. /* MT27500 Family [ConnectX-3 Virtual Function] */
  1840. { PCI_VDEVICE(MELLANOX, 0x1004), MLX4_VF },
  1841. { PCI_VDEVICE(MELLANOX, 0x1005), 0 }, /* MT27510 Family */
  1842. { PCI_VDEVICE(MELLANOX, 0x1006), 0 }, /* MT27511 Family */
  1843. { PCI_VDEVICE(MELLANOX, 0x1007), 0 }, /* MT27520 Family */
  1844. { PCI_VDEVICE(MELLANOX, 0x1008), 0 }, /* MT27521 Family */
  1845. { PCI_VDEVICE(MELLANOX, 0x1009), 0 }, /* MT27530 Family */
  1846. { PCI_VDEVICE(MELLANOX, 0x100a), 0 }, /* MT27531 Family */
  1847. { PCI_VDEVICE(MELLANOX, 0x100b), 0 }, /* MT27540 Family */
  1848. { PCI_VDEVICE(MELLANOX, 0x100c), 0 }, /* MT27541 Family */
  1849. { PCI_VDEVICE(MELLANOX, 0x100d), 0 }, /* MT27550 Family */
  1850. { PCI_VDEVICE(MELLANOX, 0x100e), 0 }, /* MT27551 Family */
  1851. { PCI_VDEVICE(MELLANOX, 0x100f), 0 }, /* MT27560 Family */
  1852. { PCI_VDEVICE(MELLANOX, 0x1010), 0 }, /* MT27561 Family */
  1853. { 0, }
  1854. };
  1855. MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
  1856. static struct pci_driver mlx4_driver = {
  1857. .name = DRV_NAME,
  1858. .id_table = mlx4_pci_table,
  1859. .probe = mlx4_init_one,
  1860. .remove = __devexit_p(mlx4_remove_one)
  1861. };
  1862. static int __init mlx4_verify_params(void)
  1863. {
  1864. if ((log_num_mac < 0) || (log_num_mac > 7)) {
  1865. pr_warning("mlx4_core: bad num_mac: %d\n", log_num_mac);
  1866. return -1;
  1867. }
  1868. if (log_num_vlan != 0)
  1869. pr_warning("mlx4_core: log_num_vlan - obsolete module param, using %d\n",
  1870. MLX4_LOG_NUM_VLANS);
  1871. if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
  1872. pr_warning("mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
  1873. return -1;
  1874. }
  1875. /* Check if module param for ports type has legal combination */
  1876. if (port_type_array[0] == false && port_type_array[1] == true) {
  1877. printk(KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n");
  1878. port_type_array[0] = true;
  1879. }
  1880. return 0;
  1881. }
  1882. static int __init mlx4_init(void)
  1883. {
  1884. int ret;
  1885. if (mlx4_verify_params())
  1886. return -EINVAL;
  1887. mlx4_catas_init();
  1888. mlx4_wq = create_singlethread_workqueue("mlx4");
  1889. if (!mlx4_wq)
  1890. return -ENOMEM;
  1891. ret = pci_register_driver(&mlx4_driver);
  1892. return ret < 0 ? ret : 0;
  1893. }
  1894. static void __exit mlx4_cleanup(void)
  1895. {
  1896. pci_unregister_driver(&mlx4_driver);
  1897. destroy_workqueue(mlx4_wq);
  1898. }
  1899. module_init(mlx4_init);
  1900. module_exit(mlx4_cleanup);