port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/errno.h>
  33. #include <linux/if_ether.h>
  34. #include <linux/export.h>
  35. #include <linux/mlx4/cmd.h>
  36. #include "mlx4.h"
  37. #define MLX4_MAC_VALID (1ull << 63)
  38. #define MLX4_VLAN_VALID (1u << 31)
  39. #define MLX4_VLAN_MASK 0xfff
  40. #define MLX4_STATS_TRAFFIC_COUNTERS_MASK 0xfULL
  41. #define MLX4_STATS_TRAFFIC_DROPS_MASK 0xc0ULL
  42. #define MLX4_STATS_ERROR_COUNTERS_MASK 0x1ffc30ULL
  43. #define MLX4_STATS_PORT_COUNTERS_MASK 0x1fe00000ULL
  44. void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table)
  45. {
  46. int i;
  47. mutex_init(&table->mutex);
  48. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  49. table->entries[i] = 0;
  50. table->refs[i] = 0;
  51. }
  52. table->max = 1 << dev->caps.log_num_macs;
  53. table->total = 0;
  54. }
  55. void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table)
  56. {
  57. int i;
  58. mutex_init(&table->mutex);
  59. for (i = 0; i < MLX4_MAX_VLAN_NUM; i++) {
  60. table->entries[i] = 0;
  61. table->refs[i] = 0;
  62. }
  63. table->max = (1 << dev->caps.log_num_vlans) - MLX4_VLAN_REGULAR;
  64. table->total = 0;
  65. }
  66. static int validate_index(struct mlx4_dev *dev,
  67. struct mlx4_mac_table *table, int index)
  68. {
  69. int err = 0;
  70. if (index < 0 || index >= table->max || !table->entries[index]) {
  71. mlx4_warn(dev, "No valid Mac entry for the given index\n");
  72. err = -EINVAL;
  73. }
  74. return err;
  75. }
  76. static int find_index(struct mlx4_dev *dev,
  77. struct mlx4_mac_table *table, u64 mac)
  78. {
  79. int i;
  80. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  81. if ((mac & MLX4_MAC_MASK) ==
  82. (MLX4_MAC_MASK & be64_to_cpu(table->entries[i])))
  83. return i;
  84. }
  85. /* Mac not found */
  86. return -EINVAL;
  87. }
  88. static int mlx4_set_port_mac_table(struct mlx4_dev *dev, u8 port,
  89. __be64 *entries)
  90. {
  91. struct mlx4_cmd_mailbox *mailbox;
  92. u32 in_mod;
  93. int err;
  94. mailbox = mlx4_alloc_cmd_mailbox(dev);
  95. if (IS_ERR(mailbox))
  96. return PTR_ERR(mailbox);
  97. memcpy(mailbox->buf, entries, MLX4_MAC_TABLE_SIZE);
  98. in_mod = MLX4_SET_PORT_MAC_TABLE << 8 | port;
  99. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  100. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  101. mlx4_free_cmd_mailbox(dev, mailbox);
  102. return err;
  103. }
  104. int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  105. {
  106. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  107. struct mlx4_mac_table *table = &info->mac_table;
  108. int i, err = 0;
  109. int free = -1;
  110. mlx4_dbg(dev, "Registering MAC: 0x%llx for port %d\n",
  111. (unsigned long long) mac, port);
  112. mutex_lock(&table->mutex);
  113. for (i = 0; i < MLX4_MAX_MAC_NUM; i++) {
  114. if (free < 0 && !table->entries[i]) {
  115. free = i;
  116. continue;
  117. }
  118. if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) {
  119. /* MAC already registered, Must not have duplicates */
  120. err = -EEXIST;
  121. goto out;
  122. }
  123. }
  124. mlx4_dbg(dev, "Free MAC index is %d\n", free);
  125. if (table->total == table->max) {
  126. /* No free mac entries */
  127. err = -ENOSPC;
  128. goto out;
  129. }
  130. /* Register new MAC */
  131. table->entries[free] = cpu_to_be64(mac | MLX4_MAC_VALID);
  132. err = mlx4_set_port_mac_table(dev, port, table->entries);
  133. if (unlikely(err)) {
  134. mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
  135. (unsigned long long) mac);
  136. table->entries[free] = 0;
  137. goto out;
  138. }
  139. err = free;
  140. ++table->total;
  141. out:
  142. mutex_unlock(&table->mutex);
  143. return err;
  144. }
  145. EXPORT_SYMBOL_GPL(__mlx4_register_mac);
  146. int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  147. {
  148. u64 out_param = 0;
  149. int err;
  150. if (mlx4_is_mfunc(dev)) {
  151. set_param_l(&out_param, port);
  152. err = mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
  153. RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
  154. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  155. if (err)
  156. return err;
  157. return get_param_l(&out_param);
  158. }
  159. return __mlx4_register_mac(dev, port, mac);
  160. }
  161. EXPORT_SYMBOL_GPL(mlx4_register_mac);
  162. int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port)
  163. {
  164. return dev->caps.reserved_qps_base[MLX4_QP_REGION_ETH_ADDR] +
  165. (port - 1) * (1 << dev->caps.log_num_macs);
  166. }
  167. EXPORT_SYMBOL_GPL(mlx4_get_base_qpn);
  168. void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  169. {
  170. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  171. struct mlx4_mac_table *table = &info->mac_table;
  172. int index;
  173. index = find_index(dev, table, mac);
  174. mutex_lock(&table->mutex);
  175. if (validate_index(dev, table, index))
  176. goto out;
  177. table->entries[index] = 0;
  178. mlx4_set_port_mac_table(dev, port, table->entries);
  179. --table->total;
  180. out:
  181. mutex_unlock(&table->mutex);
  182. }
  183. EXPORT_SYMBOL_GPL(__mlx4_unregister_mac);
  184. void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
  185. {
  186. u64 out_param = 0;
  187. if (mlx4_is_mfunc(dev)) {
  188. set_param_l(&out_param, port);
  189. (void) mlx4_cmd_imm(dev, mac, &out_param, RES_MAC,
  190. RES_OP_RESERVE_AND_MAP, MLX4_CMD_FREE_RES,
  191. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  192. return;
  193. }
  194. __mlx4_unregister_mac(dev, port, mac);
  195. return;
  196. }
  197. EXPORT_SYMBOL_GPL(mlx4_unregister_mac);
  198. int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac)
  199. {
  200. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  201. struct mlx4_mac_table *table = &info->mac_table;
  202. int index = qpn - info->base_qpn;
  203. int err = 0;
  204. /* CX1 doesn't support multi-functions */
  205. mutex_lock(&table->mutex);
  206. err = validate_index(dev, table, index);
  207. if (err)
  208. goto out;
  209. table->entries[index] = cpu_to_be64(new_mac | MLX4_MAC_VALID);
  210. err = mlx4_set_port_mac_table(dev, port, table->entries);
  211. if (unlikely(err)) {
  212. mlx4_err(dev, "Failed adding MAC: 0x%llx\n",
  213. (unsigned long long) new_mac);
  214. table->entries[index] = 0;
  215. }
  216. out:
  217. mutex_unlock(&table->mutex);
  218. return err;
  219. }
  220. EXPORT_SYMBOL_GPL(__mlx4_replace_mac);
  221. static int mlx4_set_port_vlan_table(struct mlx4_dev *dev, u8 port,
  222. __be32 *entries)
  223. {
  224. struct mlx4_cmd_mailbox *mailbox;
  225. u32 in_mod;
  226. int err;
  227. mailbox = mlx4_alloc_cmd_mailbox(dev);
  228. if (IS_ERR(mailbox))
  229. return PTR_ERR(mailbox);
  230. memcpy(mailbox->buf, entries, MLX4_VLAN_TABLE_SIZE);
  231. in_mod = MLX4_SET_PORT_VLAN_TABLE << 8 | port;
  232. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  233. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  234. mlx4_free_cmd_mailbox(dev, mailbox);
  235. return err;
  236. }
  237. int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx)
  238. {
  239. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  240. int i;
  241. for (i = 0; i < MLX4_MAX_VLAN_NUM; ++i) {
  242. if (table->refs[i] &&
  243. (vid == (MLX4_VLAN_MASK &
  244. be32_to_cpu(table->entries[i])))) {
  245. /* VLAN already registered, increase reference count */
  246. *idx = i;
  247. return 0;
  248. }
  249. }
  250. return -ENOENT;
  251. }
  252. EXPORT_SYMBOL_GPL(mlx4_find_cached_vlan);
  253. static int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan,
  254. int *index)
  255. {
  256. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  257. int i, err = 0;
  258. int free = -1;
  259. mutex_lock(&table->mutex);
  260. if (table->total == table->max) {
  261. /* No free vlan entries */
  262. err = -ENOSPC;
  263. goto out;
  264. }
  265. for (i = MLX4_VLAN_REGULAR; i < MLX4_MAX_VLAN_NUM; i++) {
  266. if (free < 0 && (table->refs[i] == 0)) {
  267. free = i;
  268. continue;
  269. }
  270. if (table->refs[i] &&
  271. (vlan == (MLX4_VLAN_MASK &
  272. be32_to_cpu(table->entries[i])))) {
  273. /* Vlan already registered, increase references count */
  274. *index = i;
  275. ++table->refs[i];
  276. goto out;
  277. }
  278. }
  279. if (free < 0) {
  280. err = -ENOMEM;
  281. goto out;
  282. }
  283. /* Register new VLAN */
  284. table->refs[free] = 1;
  285. table->entries[free] = cpu_to_be32(vlan | MLX4_VLAN_VALID);
  286. err = mlx4_set_port_vlan_table(dev, port, table->entries);
  287. if (unlikely(err)) {
  288. mlx4_warn(dev, "Failed adding vlan: %u\n", vlan);
  289. table->refs[free] = 0;
  290. table->entries[free] = 0;
  291. goto out;
  292. }
  293. *index = free;
  294. ++table->total;
  295. out:
  296. mutex_unlock(&table->mutex);
  297. return err;
  298. }
  299. int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
  300. {
  301. u64 out_param = 0;
  302. int err;
  303. if (mlx4_is_mfunc(dev)) {
  304. set_param_l(&out_param, port);
  305. err = mlx4_cmd_imm(dev, vlan, &out_param, RES_VLAN,
  306. RES_OP_RESERVE_AND_MAP, MLX4_CMD_ALLOC_RES,
  307. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  308. if (!err)
  309. *index = get_param_l(&out_param);
  310. return err;
  311. }
  312. return __mlx4_register_vlan(dev, port, vlan, index);
  313. }
  314. EXPORT_SYMBOL_GPL(mlx4_register_vlan);
  315. static void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
  316. {
  317. struct mlx4_vlan_table *table = &mlx4_priv(dev)->port[port].vlan_table;
  318. if (index < MLX4_VLAN_REGULAR) {
  319. mlx4_warn(dev, "Trying to free special vlan index %d\n", index);
  320. return;
  321. }
  322. mutex_lock(&table->mutex);
  323. if (!table->refs[index]) {
  324. mlx4_warn(dev, "No vlan entry for index %d\n", index);
  325. goto out;
  326. }
  327. if (--table->refs[index]) {
  328. mlx4_dbg(dev, "Have more references for index %d,"
  329. "no need to modify vlan table\n", index);
  330. goto out;
  331. }
  332. table->entries[index] = 0;
  333. mlx4_set_port_vlan_table(dev, port, table->entries);
  334. --table->total;
  335. out:
  336. mutex_unlock(&table->mutex);
  337. }
  338. void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index)
  339. {
  340. u64 in_param = 0;
  341. int err;
  342. if (mlx4_is_mfunc(dev)) {
  343. set_param_l(&in_param, port);
  344. err = mlx4_cmd(dev, in_param, RES_VLAN, RES_OP_RESERVE_AND_MAP,
  345. MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
  346. MLX4_CMD_WRAPPED);
  347. if (!err)
  348. mlx4_warn(dev, "Failed freeing vlan at index:%d\n",
  349. index);
  350. return;
  351. }
  352. __mlx4_unregister_vlan(dev, port, index);
  353. }
  354. EXPORT_SYMBOL_GPL(mlx4_unregister_vlan);
  355. int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps)
  356. {
  357. struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
  358. u8 *inbuf, *outbuf;
  359. int err;
  360. inmailbox = mlx4_alloc_cmd_mailbox(dev);
  361. if (IS_ERR(inmailbox))
  362. return PTR_ERR(inmailbox);
  363. outmailbox = mlx4_alloc_cmd_mailbox(dev);
  364. if (IS_ERR(outmailbox)) {
  365. mlx4_free_cmd_mailbox(dev, inmailbox);
  366. return PTR_ERR(outmailbox);
  367. }
  368. inbuf = inmailbox->buf;
  369. outbuf = outmailbox->buf;
  370. memset(inbuf, 0, 256);
  371. memset(outbuf, 0, 256);
  372. inbuf[0] = 1;
  373. inbuf[1] = 1;
  374. inbuf[2] = 1;
  375. inbuf[3] = 1;
  376. *(__be16 *) (&inbuf[16]) = cpu_to_be16(0x0015);
  377. *(__be32 *) (&inbuf[20]) = cpu_to_be32(port);
  378. err = mlx4_cmd_box(dev, inmailbox->dma, outmailbox->dma, port, 3,
  379. MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C,
  380. MLX4_CMD_NATIVE);
  381. if (!err)
  382. *caps = *(__be32 *) (outbuf + 84);
  383. mlx4_free_cmd_mailbox(dev, inmailbox);
  384. mlx4_free_cmd_mailbox(dev, outmailbox);
  385. return err;
  386. }
  387. static int mlx4_common_set_port(struct mlx4_dev *dev, int slave, u32 in_mod,
  388. u8 op_mod, struct mlx4_cmd_mailbox *inbox)
  389. {
  390. struct mlx4_priv *priv = mlx4_priv(dev);
  391. struct mlx4_port_info *port_info;
  392. struct mlx4_mfunc_master_ctx *master = &priv->mfunc.master;
  393. struct mlx4_slave_state *slave_st = &master->slave_state[slave];
  394. struct mlx4_set_port_rqp_calc_context *qpn_context;
  395. struct mlx4_set_port_general_context *gen_context;
  396. int reset_qkey_viols;
  397. int port;
  398. int is_eth;
  399. u32 in_modifier;
  400. u32 promisc;
  401. u16 mtu, prev_mtu;
  402. int err;
  403. int i;
  404. __be32 agg_cap_mask;
  405. __be32 slave_cap_mask;
  406. __be32 new_cap_mask;
  407. port = in_mod & 0xff;
  408. in_modifier = in_mod >> 8;
  409. is_eth = op_mod;
  410. port_info = &priv->port[port];
  411. /* Slaves cannot perform SET_PORT operations except changing MTU */
  412. if (is_eth) {
  413. if (slave != dev->caps.function &&
  414. in_modifier != MLX4_SET_PORT_GENERAL) {
  415. mlx4_warn(dev, "denying SET_PORT for slave:%d\n",
  416. slave);
  417. return -EINVAL;
  418. }
  419. switch (in_modifier) {
  420. case MLX4_SET_PORT_RQP_CALC:
  421. qpn_context = inbox->buf;
  422. qpn_context->base_qpn =
  423. cpu_to_be32(port_info->base_qpn);
  424. qpn_context->n_mac = 0x7;
  425. promisc = be32_to_cpu(qpn_context->promisc) >>
  426. SET_PORT_PROMISC_SHIFT;
  427. qpn_context->promisc = cpu_to_be32(
  428. promisc << SET_PORT_PROMISC_SHIFT |
  429. port_info->base_qpn);
  430. promisc = be32_to_cpu(qpn_context->mcast) >>
  431. SET_PORT_MC_PROMISC_SHIFT;
  432. qpn_context->mcast = cpu_to_be32(
  433. promisc << SET_PORT_MC_PROMISC_SHIFT |
  434. port_info->base_qpn);
  435. break;
  436. case MLX4_SET_PORT_GENERAL:
  437. gen_context = inbox->buf;
  438. /* Mtu is configured as the max MTU among all the
  439. * the functions on the port. */
  440. mtu = be16_to_cpu(gen_context->mtu);
  441. mtu = min_t(int, mtu, dev->caps.eth_mtu_cap[port]);
  442. prev_mtu = slave_st->mtu[port];
  443. slave_st->mtu[port] = mtu;
  444. if (mtu > master->max_mtu[port])
  445. master->max_mtu[port] = mtu;
  446. if (mtu < prev_mtu && prev_mtu ==
  447. master->max_mtu[port]) {
  448. slave_st->mtu[port] = mtu;
  449. master->max_mtu[port] = mtu;
  450. for (i = 0; i < dev->num_slaves; i++) {
  451. master->max_mtu[port] =
  452. max(master->max_mtu[port],
  453. master->slave_state[i].mtu[port]);
  454. }
  455. }
  456. gen_context->mtu = cpu_to_be16(master->max_mtu[port]);
  457. break;
  458. }
  459. return mlx4_cmd(dev, inbox->dma, in_mod, op_mod,
  460. MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B,
  461. MLX4_CMD_NATIVE);
  462. }
  463. /* For IB, we only consider:
  464. * - The capability mask, which is set to the aggregate of all
  465. * slave function capabilities
  466. * - The QKey violatin counter - reset according to each request.
  467. */
  468. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  469. reset_qkey_viols = (*(u8 *) inbox->buf) & 0x40;
  470. new_cap_mask = ((__be32 *) inbox->buf)[2];
  471. } else {
  472. reset_qkey_viols = ((u8 *) inbox->buf)[3] & 0x1;
  473. new_cap_mask = ((__be32 *) inbox->buf)[1];
  474. }
  475. /* slave may not set the IS_SM capability for the port */
  476. if (slave != mlx4_master_func_num(dev) &&
  477. (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_IS_SM))
  478. return -EINVAL;
  479. /* No DEV_MGMT in multifunc mode */
  480. if (mlx4_is_mfunc(dev) &&
  481. (be32_to_cpu(new_cap_mask) & MLX4_PORT_CAP_DEV_MGMT_SUP))
  482. return -EINVAL;
  483. agg_cap_mask = 0;
  484. slave_cap_mask =
  485. priv->mfunc.master.slave_state[slave].ib_cap_mask[port];
  486. priv->mfunc.master.slave_state[slave].ib_cap_mask[port] = new_cap_mask;
  487. for (i = 0; i < dev->num_slaves; i++)
  488. agg_cap_mask |=
  489. priv->mfunc.master.slave_state[i].ib_cap_mask[port];
  490. /* only clear mailbox for guests. Master may be setting
  491. * MTU or PKEY table size
  492. */
  493. if (slave != dev->caps.function)
  494. memset(inbox->buf, 0, 256);
  495. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  496. *(u8 *) inbox->buf |= !!reset_qkey_viols << 6;
  497. ((__be32 *) inbox->buf)[2] = agg_cap_mask;
  498. } else {
  499. ((u8 *) inbox->buf)[3] |= !!reset_qkey_viols;
  500. ((__be32 *) inbox->buf)[1] = agg_cap_mask;
  501. }
  502. err = mlx4_cmd(dev, inbox->dma, port, is_eth, MLX4_CMD_SET_PORT,
  503. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  504. if (err)
  505. priv->mfunc.master.slave_state[slave].ib_cap_mask[port] =
  506. slave_cap_mask;
  507. return err;
  508. }
  509. int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave,
  510. struct mlx4_vhcr *vhcr,
  511. struct mlx4_cmd_mailbox *inbox,
  512. struct mlx4_cmd_mailbox *outbox,
  513. struct mlx4_cmd_info *cmd)
  514. {
  515. return mlx4_common_set_port(dev, slave, vhcr->in_modifier,
  516. vhcr->op_modifier, inbox);
  517. }
  518. /* bit locations for set port command with zero op modifier */
  519. enum {
  520. MLX4_SET_PORT_VL_CAP = 4, /* bits 7:4 */
  521. MLX4_SET_PORT_MTU_CAP = 12, /* bits 15:12 */
  522. MLX4_CHANGE_PORT_PKEY_TBL_SZ = 20,
  523. MLX4_CHANGE_PORT_VL_CAP = 21,
  524. MLX4_CHANGE_PORT_MTU_CAP = 22,
  525. };
  526. int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz)
  527. {
  528. struct mlx4_cmd_mailbox *mailbox;
  529. int err, vl_cap, pkey_tbl_flag = 0;
  530. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
  531. return 0;
  532. mailbox = mlx4_alloc_cmd_mailbox(dev);
  533. if (IS_ERR(mailbox))
  534. return PTR_ERR(mailbox);
  535. memset(mailbox->buf, 0, 256);
  536. ((__be32 *) mailbox->buf)[1] = dev->caps.ib_port_def_cap[port];
  537. if (pkey_tbl_sz >= 0 && mlx4_is_master(dev)) {
  538. pkey_tbl_flag = 1;
  539. ((__be16 *) mailbox->buf)[20] = cpu_to_be16(pkey_tbl_sz);
  540. }
  541. /* IB VL CAP enum isn't used by the firmware, just numerical values */
  542. for (vl_cap = 8; vl_cap >= 1; vl_cap >>= 1) {
  543. ((__be32 *) mailbox->buf)[0] = cpu_to_be32(
  544. (1 << MLX4_CHANGE_PORT_MTU_CAP) |
  545. (1 << MLX4_CHANGE_PORT_VL_CAP) |
  546. (pkey_tbl_flag << MLX4_CHANGE_PORT_PKEY_TBL_SZ) |
  547. (dev->caps.port_ib_mtu[port] << MLX4_SET_PORT_MTU_CAP) |
  548. (vl_cap << MLX4_SET_PORT_VL_CAP));
  549. err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
  550. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  551. if (err != -ENOMEM)
  552. break;
  553. }
  554. mlx4_free_cmd_mailbox(dev, mailbox);
  555. return err;
  556. }
  557. int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
  558. u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx)
  559. {
  560. struct mlx4_cmd_mailbox *mailbox;
  561. struct mlx4_set_port_general_context *context;
  562. int err;
  563. u32 in_mod;
  564. mailbox = mlx4_alloc_cmd_mailbox(dev);
  565. if (IS_ERR(mailbox))
  566. return PTR_ERR(mailbox);
  567. context = mailbox->buf;
  568. memset(context, 0, sizeof *context);
  569. context->flags = SET_PORT_GEN_ALL_VALID;
  570. context->mtu = cpu_to_be16(mtu);
  571. context->pptx = (pptx * (!pfctx)) << 7;
  572. context->pfctx = pfctx;
  573. context->pprx = (pprx * (!pfcrx)) << 7;
  574. context->pfcrx = pfcrx;
  575. in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
  576. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  577. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  578. mlx4_free_cmd_mailbox(dev, mailbox);
  579. return err;
  580. }
  581. EXPORT_SYMBOL(mlx4_SET_PORT_general);
  582. int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
  583. u8 promisc)
  584. {
  585. struct mlx4_cmd_mailbox *mailbox;
  586. struct mlx4_set_port_rqp_calc_context *context;
  587. int err;
  588. u32 in_mod;
  589. u32 m_promisc = (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) ?
  590. MCAST_DIRECT : MCAST_DEFAULT;
  591. if (dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
  592. return 0;
  593. mailbox = mlx4_alloc_cmd_mailbox(dev);
  594. if (IS_ERR(mailbox))
  595. return PTR_ERR(mailbox);
  596. context = mailbox->buf;
  597. memset(context, 0, sizeof *context);
  598. context->base_qpn = cpu_to_be32(base_qpn);
  599. context->n_mac = dev->caps.log_num_macs;
  600. context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_SHIFT |
  601. base_qpn);
  602. context->mcast = cpu_to_be32(m_promisc << SET_PORT_MC_PROMISC_SHIFT |
  603. base_qpn);
  604. context->intra_no_vlan = 0;
  605. context->no_vlan = MLX4_NO_VLAN_IDX;
  606. context->intra_vlan_miss = 0;
  607. context->vlan_miss = MLX4_VLAN_MISS_IDX;
  608. in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port;
  609. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  610. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  611. mlx4_free_cmd_mailbox(dev, mailbox);
  612. return err;
  613. }
  614. EXPORT_SYMBOL(mlx4_SET_PORT_qpn_calc);
  615. int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc)
  616. {
  617. struct mlx4_cmd_mailbox *mailbox;
  618. struct mlx4_set_port_prio2tc_context *context;
  619. int err;
  620. u32 in_mod;
  621. int i;
  622. mailbox = mlx4_alloc_cmd_mailbox(dev);
  623. if (IS_ERR(mailbox))
  624. return PTR_ERR(mailbox);
  625. context = mailbox->buf;
  626. memset(context, 0, sizeof *context);
  627. for (i = 0; i < MLX4_NUM_UP; i += 2)
  628. context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
  629. in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port;
  630. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  631. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  632. mlx4_free_cmd_mailbox(dev, mailbox);
  633. return err;
  634. }
  635. EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC);
  636. int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
  637. u8 *pg, u16 *ratelimit)
  638. {
  639. struct mlx4_cmd_mailbox *mailbox;
  640. struct mlx4_set_port_scheduler_context *context;
  641. int err;
  642. u32 in_mod;
  643. int i;
  644. mailbox = mlx4_alloc_cmd_mailbox(dev);
  645. if (IS_ERR(mailbox))
  646. return PTR_ERR(mailbox);
  647. context = mailbox->buf;
  648. memset(context, 0, sizeof *context);
  649. for (i = 0; i < MLX4_NUM_TC; i++) {
  650. struct mlx4_port_scheduler_tc_cfg_be *tc = &context->tc[i];
  651. u16 r = ratelimit && ratelimit[i] ? ratelimit[i] :
  652. MLX4_RATELIMIT_DEFAULT;
  653. tc->pg = htons(pg[i]);
  654. tc->bw_precentage = htons(tc_tx_bw[i]);
  655. tc->max_bw_units = htons(MLX4_RATELIMIT_UNITS);
  656. tc->max_bw_value = htons(r);
  657. }
  658. in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port;
  659. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  660. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  661. mlx4_free_cmd_mailbox(dev, mailbox);
  662. return err;
  663. }
  664. EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER);
  665. int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  666. struct mlx4_vhcr *vhcr,
  667. struct mlx4_cmd_mailbox *inbox,
  668. struct mlx4_cmd_mailbox *outbox,
  669. struct mlx4_cmd_info *cmd)
  670. {
  671. int err = 0;
  672. return err;
  673. }
  674. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port,
  675. u64 mac, u64 clear, u8 mode)
  676. {
  677. return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
  678. MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B,
  679. MLX4_CMD_WRAPPED);
  680. }
  681. EXPORT_SYMBOL(mlx4_SET_MCAST_FLTR);
  682. int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  683. struct mlx4_vhcr *vhcr,
  684. struct mlx4_cmd_mailbox *inbox,
  685. struct mlx4_cmd_mailbox *outbox,
  686. struct mlx4_cmd_info *cmd)
  687. {
  688. int err = 0;
  689. return err;
  690. }
  691. int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave,
  692. u32 in_mod, struct mlx4_cmd_mailbox *outbox)
  693. {
  694. return mlx4_cmd_box(dev, 0, outbox->dma, in_mod, 0,
  695. MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
  696. MLX4_CMD_NATIVE);
  697. }
  698. int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
  699. struct mlx4_vhcr *vhcr,
  700. struct mlx4_cmd_mailbox *inbox,
  701. struct mlx4_cmd_mailbox *outbox,
  702. struct mlx4_cmd_info *cmd)
  703. {
  704. if (slave != dev->caps.function)
  705. return 0;
  706. return mlx4_common_dump_eth_stats(dev, slave,
  707. vhcr->in_modifier, outbox);
  708. }
  709. void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap)
  710. {
  711. if (!mlx4_is_mfunc(dev)) {
  712. *stats_bitmap = 0;
  713. return;
  714. }
  715. *stats_bitmap = (MLX4_STATS_TRAFFIC_COUNTERS_MASK |
  716. MLX4_STATS_TRAFFIC_DROPS_MASK |
  717. MLX4_STATS_PORT_COUNTERS_MASK);
  718. if (mlx4_is_master(dev))
  719. *stats_bitmap |= MLX4_STATS_ERROR_COUNTERS_MASK;
  720. }
  721. EXPORT_SYMBOL(mlx4_set_stats_bitmap);