PageRenderTime 31ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c

http://github.com/mirrors/linux
C | 2262 lines | 1327 code | 238 blank | 697 comment | 204 complexity | 638b39b71cc52c53b7f654232a29b1c6 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*
  2. * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
  3. * driver for Linux.
  4. *
  5. * Copyright (c) 2009-2010 Chelsio Communications, 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/pci.h>
  36. #include "t4vf_common.h"
  37. #include "t4vf_defs.h"
  38. #include "../cxgb4/t4_regs.h"
  39. #include "../cxgb4/t4_values.h"
  40. #include "../cxgb4/t4fw_api.h"
  41. /*
  42. * Wait for the device to become ready (signified by our "who am I" register
  43. * returning a value other than all 1's). Return an error if it doesn't
  44. * become ready ...
  45. */
  46. int t4vf_wait_dev_ready(struct adapter *adapter)
  47. {
  48. const u32 whoami = T4VF_PL_BASE_ADDR + PL_VF_WHOAMI;
  49. const u32 notready1 = 0xffffffff;
  50. const u32 notready2 = 0xeeeeeeee;
  51. u32 val;
  52. val = t4_read_reg(adapter, whoami);
  53. if (val != notready1 && val != notready2)
  54. return 0;
  55. msleep(500);
  56. val = t4_read_reg(adapter, whoami);
  57. if (val != notready1 && val != notready2)
  58. return 0;
  59. else
  60. return -EIO;
  61. }
  62. /*
  63. * Get the reply to a mailbox command and store it in @rpl in big-endian order
  64. * (since the firmware data structures are specified in a big-endian layout).
  65. */
  66. static void get_mbox_rpl(struct adapter *adapter, __be64 *rpl, int size,
  67. u32 mbox_data)
  68. {
  69. for ( ; size; size -= 8, mbox_data += 8)
  70. *rpl++ = cpu_to_be64(t4_read_reg64(adapter, mbox_data));
  71. }
  72. /**
  73. * t4vf_record_mbox - record a Firmware Mailbox Command/Reply in the log
  74. * @adapter: the adapter
  75. * @cmd: the Firmware Mailbox Command or Reply
  76. * @size: command length in bytes
  77. * @access: the time (ms) needed to access the Firmware Mailbox
  78. * @execute: the time (ms) the command spent being executed
  79. */
  80. static void t4vf_record_mbox(struct adapter *adapter, const __be64 *cmd,
  81. int size, int access, int execute)
  82. {
  83. struct mbox_cmd_log *log = adapter->mbox_log;
  84. struct mbox_cmd *entry;
  85. int i;
  86. entry = mbox_cmd_log_entry(log, log->cursor++);
  87. if (log->cursor == log->size)
  88. log->cursor = 0;
  89. for (i = 0; i < size / 8; i++)
  90. entry->cmd[i] = be64_to_cpu(cmd[i]);
  91. while (i < MBOX_LEN / 8)
  92. entry->cmd[i++] = 0;
  93. entry->timestamp = jiffies;
  94. entry->seqno = log->seqno++;
  95. entry->access = access;
  96. entry->execute = execute;
  97. }
  98. /**
  99. * t4vf_wr_mbox_core - send a command to FW through the mailbox
  100. * @adapter: the adapter
  101. * @cmd: the command to write
  102. * @size: command length in bytes
  103. * @rpl: where to optionally store the reply
  104. * @sleep_ok: if true we may sleep while awaiting command completion
  105. *
  106. * Sends the given command to FW through the mailbox and waits for the
  107. * FW to execute the command. If @rpl is not %NULL it is used to store
  108. * the FW's reply to the command. The command and its optional reply
  109. * are of the same length. FW can take up to 500 ms to respond.
  110. * @sleep_ok determines whether we may sleep while awaiting the response.
  111. * If sleeping is allowed we use progressive backoff otherwise we spin.
  112. *
  113. * The return value is 0 on success or a negative errno on failure. A
  114. * failure can happen either because we are not able to execute the
  115. * command or FW executes it but signals an error. In the latter case
  116. * the return value is the error code indicated by FW (negated).
  117. */
  118. int t4vf_wr_mbox_core(struct adapter *adapter, const void *cmd, int size,
  119. void *rpl, bool sleep_ok)
  120. {
  121. static const int delay[] = {
  122. 1, 1, 3, 5, 10, 10, 20, 50, 100
  123. };
  124. u16 access = 0, execute = 0;
  125. u32 v, mbox_data;
  126. int i, ms, delay_idx, ret;
  127. const __be64 *p;
  128. u32 mbox_ctl = T4VF_CIM_BASE_ADDR + CIM_VF_EXT_MAILBOX_CTRL;
  129. u32 cmd_op = FW_CMD_OP_G(be32_to_cpu(((struct fw_cmd_hdr *)cmd)->hi));
  130. __be64 cmd_rpl[MBOX_LEN / 8];
  131. struct mbox_list entry;
  132. /* In T6, mailbox size is changed to 128 bytes to avoid
  133. * invalidating the entire prefetch buffer.
  134. */
  135. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  136. mbox_data = T4VF_MBDATA_BASE_ADDR;
  137. else
  138. mbox_data = T6VF_MBDATA_BASE_ADDR;
  139. /*
  140. * Commands must be multiples of 16 bytes in length and may not be
  141. * larger than the size of the Mailbox Data register array.
  142. */
  143. if ((size % 16) != 0 ||
  144. size > NUM_CIM_VF_MAILBOX_DATA_INSTANCES * 4)
  145. return -EINVAL;
  146. /* Queue ourselves onto the mailbox access list. When our entry is at
  147. * the front of the list, we have rights to access the mailbox. So we
  148. * wait [for a while] till we're at the front [or bail out with an
  149. * EBUSY] ...
  150. */
  151. spin_lock(&adapter->mbox_lock);
  152. list_add_tail(&entry.list, &adapter->mlist.list);
  153. spin_unlock(&adapter->mbox_lock);
  154. delay_idx = 0;
  155. ms = delay[0];
  156. for (i = 0; ; i += ms) {
  157. /* If we've waited too long, return a busy indication. This
  158. * really ought to be based on our initial position in the
  159. * mailbox access list but this is a start. We very rearely
  160. * contend on access to the mailbox ...
  161. */
  162. if (i > FW_CMD_MAX_TIMEOUT) {
  163. spin_lock(&adapter->mbox_lock);
  164. list_del(&entry.list);
  165. spin_unlock(&adapter->mbox_lock);
  166. ret = -EBUSY;
  167. t4vf_record_mbox(adapter, cmd, size, access, ret);
  168. return ret;
  169. }
  170. /* If we're at the head, break out and start the mailbox
  171. * protocol.
  172. */
  173. if (list_first_entry(&adapter->mlist.list, struct mbox_list,
  174. list) == &entry)
  175. break;
  176. /* Delay for a bit before checking again ... */
  177. if (sleep_ok) {
  178. ms = delay[delay_idx]; /* last element may repeat */
  179. if (delay_idx < ARRAY_SIZE(delay) - 1)
  180. delay_idx++;
  181. msleep(ms);
  182. } else {
  183. mdelay(ms);
  184. }
  185. }
  186. /*
  187. * Loop trying to get ownership of the mailbox. Return an error
  188. * if we can't gain ownership.
  189. */
  190. v = MBOWNER_G(t4_read_reg(adapter, mbox_ctl));
  191. for (i = 0; v == MBOX_OWNER_NONE && i < 3; i++)
  192. v = MBOWNER_G(t4_read_reg(adapter, mbox_ctl));
  193. if (v != MBOX_OWNER_DRV) {
  194. spin_lock(&adapter->mbox_lock);
  195. list_del(&entry.list);
  196. spin_unlock(&adapter->mbox_lock);
  197. ret = (v == MBOX_OWNER_FW) ? -EBUSY : -ETIMEDOUT;
  198. t4vf_record_mbox(adapter, cmd, size, access, ret);
  199. return ret;
  200. }
  201. /*
  202. * Write the command array into the Mailbox Data register array and
  203. * transfer ownership of the mailbox to the firmware.
  204. *
  205. * For the VFs, the Mailbox Data "registers" are actually backed by
  206. * T4's "MA" interface rather than PL Registers (as is the case for
  207. * the PFs). Because these are in different coherency domains, the
  208. * write to the VF's PL-register-backed Mailbox Control can race in
  209. * front of the writes to the MA-backed VF Mailbox Data "registers".
  210. * So we need to do a read-back on at least one byte of the VF Mailbox
  211. * Data registers before doing the write to the VF Mailbox Control
  212. * register.
  213. */
  214. if (cmd_op != FW_VI_STATS_CMD)
  215. t4vf_record_mbox(adapter, cmd, size, access, 0);
  216. for (i = 0, p = cmd; i < size; i += 8)
  217. t4_write_reg64(adapter, mbox_data + i, be64_to_cpu(*p++));
  218. t4_read_reg(adapter, mbox_data); /* flush write */
  219. t4_write_reg(adapter, mbox_ctl,
  220. MBMSGVALID_F | MBOWNER_V(MBOX_OWNER_FW));
  221. t4_read_reg(adapter, mbox_ctl); /* flush write */
  222. /*
  223. * Spin waiting for firmware to acknowledge processing our command.
  224. */
  225. delay_idx = 0;
  226. ms = delay[0];
  227. for (i = 0; i < FW_CMD_MAX_TIMEOUT; i += ms) {
  228. if (sleep_ok) {
  229. ms = delay[delay_idx];
  230. if (delay_idx < ARRAY_SIZE(delay) - 1)
  231. delay_idx++;
  232. msleep(ms);
  233. } else
  234. mdelay(ms);
  235. /*
  236. * If we're the owner, see if this is the reply we wanted.
  237. */
  238. v = t4_read_reg(adapter, mbox_ctl);
  239. if (MBOWNER_G(v) == MBOX_OWNER_DRV) {
  240. /*
  241. * If the Message Valid bit isn't on, revoke ownership
  242. * of the mailbox and continue waiting for our reply.
  243. */
  244. if ((v & MBMSGVALID_F) == 0) {
  245. t4_write_reg(adapter, mbox_ctl,
  246. MBOWNER_V(MBOX_OWNER_NONE));
  247. continue;
  248. }
  249. /*
  250. * We now have our reply. Extract the command return
  251. * value, copy the reply back to our caller's buffer
  252. * (if specified) and revoke ownership of the mailbox.
  253. * We return the (negated) firmware command return
  254. * code (this depends on FW_SUCCESS == 0).
  255. */
  256. get_mbox_rpl(adapter, cmd_rpl, size, mbox_data);
  257. /* return value in low-order little-endian word */
  258. v = be64_to_cpu(cmd_rpl[0]);
  259. if (rpl) {
  260. /* request bit in high-order BE word */
  261. WARN_ON((be32_to_cpu(*(const __be32 *)cmd)
  262. & FW_CMD_REQUEST_F) == 0);
  263. memcpy(rpl, cmd_rpl, size);
  264. WARN_ON((be32_to_cpu(*(__be32 *)rpl)
  265. & FW_CMD_REQUEST_F) != 0);
  266. }
  267. t4_write_reg(adapter, mbox_ctl,
  268. MBOWNER_V(MBOX_OWNER_NONE));
  269. execute = i + ms;
  270. if (cmd_op != FW_VI_STATS_CMD)
  271. t4vf_record_mbox(adapter, cmd_rpl, size, access,
  272. execute);
  273. spin_lock(&adapter->mbox_lock);
  274. list_del(&entry.list);
  275. spin_unlock(&adapter->mbox_lock);
  276. return -FW_CMD_RETVAL_G(v);
  277. }
  278. }
  279. /* We timed out. Return the error ... */
  280. ret = -ETIMEDOUT;
  281. t4vf_record_mbox(adapter, cmd, size, access, ret);
  282. spin_lock(&adapter->mbox_lock);
  283. list_del(&entry.list);
  284. spin_unlock(&adapter->mbox_lock);
  285. return ret;
  286. }
  287. /* In the Physical Function Driver Common Code, the ADVERT_MASK is used to
  288. * mask out bits in the Advertised Port Capabilities which are managed via
  289. * separate controls, like Pause Frames and Forward Error Correction. In the
  290. * Virtual Function Common Code, since we never perform L1 Configuration on
  291. * the Link, the only things we really need to filter out are things which
  292. * we decode and report separately like Speed.
  293. */
  294. #define ADVERT_MASK (FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_M) | \
  295. FW_PORT_CAP32_802_3_PAUSE | \
  296. FW_PORT_CAP32_802_3_ASM_DIR | \
  297. FW_PORT_CAP32_FEC_V(FW_PORT_CAP32_FEC_M) | \
  298. FW_PORT_CAP32_ANEG)
  299. /**
  300. * fwcaps16_to_caps32 - convert 16-bit Port Capabilities to 32-bits
  301. * @caps16: a 16-bit Port Capabilities value
  302. *
  303. * Returns the equivalent 32-bit Port Capabilities value.
  304. */
  305. static fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16)
  306. {
  307. fw_port_cap32_t caps32 = 0;
  308. #define CAP16_TO_CAP32(__cap) \
  309. do { \
  310. if (caps16 & FW_PORT_CAP_##__cap) \
  311. caps32 |= FW_PORT_CAP32_##__cap; \
  312. } while (0)
  313. CAP16_TO_CAP32(SPEED_100M);
  314. CAP16_TO_CAP32(SPEED_1G);
  315. CAP16_TO_CAP32(SPEED_25G);
  316. CAP16_TO_CAP32(SPEED_10G);
  317. CAP16_TO_CAP32(SPEED_40G);
  318. CAP16_TO_CAP32(SPEED_100G);
  319. CAP16_TO_CAP32(FC_RX);
  320. CAP16_TO_CAP32(FC_TX);
  321. CAP16_TO_CAP32(ANEG);
  322. CAP16_TO_CAP32(MDIAUTO);
  323. CAP16_TO_CAP32(MDISTRAIGHT);
  324. CAP16_TO_CAP32(FEC_RS);
  325. CAP16_TO_CAP32(FEC_BASER_RS);
  326. CAP16_TO_CAP32(802_3_PAUSE);
  327. CAP16_TO_CAP32(802_3_ASM_DIR);
  328. #undef CAP16_TO_CAP32
  329. return caps32;
  330. }
  331. /* Translate Firmware Pause specification to Common Code */
  332. static inline enum cc_pause fwcap_to_cc_pause(fw_port_cap32_t fw_pause)
  333. {
  334. enum cc_pause cc_pause = 0;
  335. if (fw_pause & FW_PORT_CAP32_FC_RX)
  336. cc_pause |= PAUSE_RX;
  337. if (fw_pause & FW_PORT_CAP32_FC_TX)
  338. cc_pause |= PAUSE_TX;
  339. return cc_pause;
  340. }
  341. /* Translate Firmware Forward Error Correction specification to Common Code */
  342. static inline enum cc_fec fwcap_to_cc_fec(fw_port_cap32_t fw_fec)
  343. {
  344. enum cc_fec cc_fec = 0;
  345. if (fw_fec & FW_PORT_CAP32_FEC_RS)
  346. cc_fec |= FEC_RS;
  347. if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
  348. cc_fec |= FEC_BASER_RS;
  349. return cc_fec;
  350. }
  351. /**
  352. * Return the highest speed set in the port capabilities, in Mb/s.
  353. */
  354. static unsigned int fwcap_to_speed(fw_port_cap32_t caps)
  355. {
  356. #define TEST_SPEED_RETURN(__caps_speed, __speed) \
  357. do { \
  358. if (caps & FW_PORT_CAP32_SPEED_##__caps_speed) \
  359. return __speed; \
  360. } while (0)
  361. TEST_SPEED_RETURN(400G, 400000);
  362. TEST_SPEED_RETURN(200G, 200000);
  363. TEST_SPEED_RETURN(100G, 100000);
  364. TEST_SPEED_RETURN(50G, 50000);
  365. TEST_SPEED_RETURN(40G, 40000);
  366. TEST_SPEED_RETURN(25G, 25000);
  367. TEST_SPEED_RETURN(10G, 10000);
  368. TEST_SPEED_RETURN(1G, 1000);
  369. TEST_SPEED_RETURN(100M, 100);
  370. #undef TEST_SPEED_RETURN
  371. return 0;
  372. }
  373. /**
  374. * fwcap_to_fwspeed - return highest speed in Port Capabilities
  375. * @acaps: advertised Port Capabilities
  376. *
  377. * Get the highest speed for the port from the advertised Port
  378. * Capabilities. It will be either the highest speed from the list of
  379. * speeds or whatever user has set using ethtool.
  380. */
  381. static fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps)
  382. {
  383. #define TEST_SPEED_RETURN(__caps_speed) \
  384. do { \
  385. if (acaps & FW_PORT_CAP32_SPEED_##__caps_speed) \
  386. return FW_PORT_CAP32_SPEED_##__caps_speed; \
  387. } while (0)
  388. TEST_SPEED_RETURN(400G);
  389. TEST_SPEED_RETURN(200G);
  390. TEST_SPEED_RETURN(100G);
  391. TEST_SPEED_RETURN(50G);
  392. TEST_SPEED_RETURN(40G);
  393. TEST_SPEED_RETURN(25G);
  394. TEST_SPEED_RETURN(10G);
  395. TEST_SPEED_RETURN(1G);
  396. TEST_SPEED_RETURN(100M);
  397. #undef TEST_SPEED_RETURN
  398. return 0;
  399. }
  400. /*
  401. * init_link_config - initialize a link's SW state
  402. * @lc: structure holding the link state
  403. * @pcaps: link Port Capabilities
  404. * @acaps: link current Advertised Port Capabilities
  405. *
  406. * Initializes the SW state maintained for each link, including the link's
  407. * capabilities and default speed/flow-control/autonegotiation settings.
  408. */
  409. static void init_link_config(struct link_config *lc,
  410. fw_port_cap32_t pcaps,
  411. fw_port_cap32_t acaps)
  412. {
  413. lc->pcaps = pcaps;
  414. lc->lpacaps = 0;
  415. lc->speed_caps = 0;
  416. lc->speed = 0;
  417. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  418. /* For Forward Error Control, we default to whatever the Firmware
  419. * tells us the Link is currently advertising.
  420. */
  421. lc->auto_fec = fwcap_to_cc_fec(acaps);
  422. lc->requested_fec = FEC_AUTO;
  423. lc->fec = lc->auto_fec;
  424. /* If the Port is capable of Auto-Negtotiation, initialize it as
  425. * "enabled" and copy over all of the Physical Port Capabilities
  426. * to the Advertised Port Capabilities. Otherwise mark it as
  427. * Auto-Negotiate disabled and select the highest supported speed
  428. * for the link. Note parallel structure in t4_link_l1cfg_core()
  429. * and t4_handle_get_port_info().
  430. */
  431. if (lc->pcaps & FW_PORT_CAP32_ANEG) {
  432. lc->acaps = acaps & ADVERT_MASK;
  433. lc->autoneg = AUTONEG_ENABLE;
  434. lc->requested_fc |= PAUSE_AUTONEG;
  435. } else {
  436. lc->acaps = 0;
  437. lc->autoneg = AUTONEG_DISABLE;
  438. lc->speed_caps = fwcap_to_fwspeed(acaps);
  439. }
  440. }
  441. /**
  442. * t4vf_port_init - initialize port hardware/software state
  443. * @adapter: the adapter
  444. * @pidx: the adapter port index
  445. */
  446. int t4vf_port_init(struct adapter *adapter, int pidx)
  447. {
  448. struct port_info *pi = adap2pinfo(adapter, pidx);
  449. unsigned int fw_caps = adapter->params.fw_caps_support;
  450. struct fw_vi_cmd vi_cmd, vi_rpl;
  451. struct fw_port_cmd port_cmd, port_rpl;
  452. enum fw_port_type port_type;
  453. int mdio_addr;
  454. fw_port_cap32_t pcaps, acaps;
  455. int ret;
  456. /* If we haven't yet determined whether we're talking to Firmware
  457. * which knows the new 32-bit Port Capabilities, it's time to find
  458. * out now. This will also tell new Firmware to send us Port Status
  459. * Updates using the new 32-bit Port Capabilities version of the
  460. * Port Information message.
  461. */
  462. if (fw_caps == FW_CAPS_UNKNOWN) {
  463. u32 param, val;
  464. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
  465. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_PORT_CAPS32));
  466. val = 1;
  467. ret = t4vf_set_params(adapter, 1, &param, &val);
  468. fw_caps = (ret == 0 ? FW_CAPS32 : FW_CAPS16);
  469. adapter->params.fw_caps_support = fw_caps;
  470. }
  471. /*
  472. * Execute a VI Read command to get our Virtual Interface information
  473. * like MAC address, etc.
  474. */
  475. memset(&vi_cmd, 0, sizeof(vi_cmd));
  476. vi_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
  477. FW_CMD_REQUEST_F |
  478. FW_CMD_READ_F);
  479. vi_cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(vi_cmd));
  480. vi_cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID_V(pi->viid));
  481. ret = t4vf_wr_mbox(adapter, &vi_cmd, sizeof(vi_cmd), &vi_rpl);
  482. if (ret != FW_SUCCESS)
  483. return ret;
  484. BUG_ON(pi->port_id != FW_VI_CMD_PORTID_G(vi_rpl.portid_pkd));
  485. pi->rss_size = FW_VI_CMD_RSSSIZE_G(be16_to_cpu(vi_rpl.rsssize_pkd));
  486. t4_os_set_hw_addr(adapter, pidx, vi_rpl.mac);
  487. /*
  488. * If we don't have read access to our port information, we're done
  489. * now. Otherwise, execute a PORT Read command to get it ...
  490. */
  491. if (!(adapter->params.vfres.r_caps & FW_CMD_CAP_PORT))
  492. return 0;
  493. memset(&port_cmd, 0, sizeof(port_cmd));
  494. port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  495. FW_CMD_REQUEST_F |
  496. FW_CMD_READ_F |
  497. FW_PORT_CMD_PORTID_V(pi->port_id));
  498. port_cmd.action_to_len16 = cpu_to_be32(
  499. FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
  500. ? FW_PORT_ACTION_GET_PORT_INFO
  501. : FW_PORT_ACTION_GET_PORT_INFO32) |
  502. FW_LEN16(port_cmd));
  503. ret = t4vf_wr_mbox(adapter, &port_cmd, sizeof(port_cmd), &port_rpl);
  504. if (ret != FW_SUCCESS)
  505. return ret;
  506. /* Extract the various fields from the Port Information message. */
  507. if (fw_caps == FW_CAPS16) {
  508. u32 lstatus = be32_to_cpu(port_rpl.u.info.lstatus_to_modtype);
  509. port_type = FW_PORT_CMD_PTYPE_G(lstatus);
  510. mdio_addr = ((lstatus & FW_PORT_CMD_MDIOCAP_F)
  511. ? FW_PORT_CMD_MDIOADDR_G(lstatus)
  512. : -1);
  513. pcaps = fwcaps16_to_caps32(be16_to_cpu(port_rpl.u.info.pcap));
  514. acaps = fwcaps16_to_caps32(be16_to_cpu(port_rpl.u.info.acap));
  515. } else {
  516. u32 lstatus32 =
  517. be32_to_cpu(port_rpl.u.info32.lstatus32_to_cbllen32);
  518. port_type = FW_PORT_CMD_PORTTYPE32_G(lstatus32);
  519. mdio_addr = ((lstatus32 & FW_PORT_CMD_MDIOCAP32_F)
  520. ? FW_PORT_CMD_MDIOADDR32_G(lstatus32)
  521. : -1);
  522. pcaps = be32_to_cpu(port_rpl.u.info32.pcaps32);
  523. acaps = be32_to_cpu(port_rpl.u.info32.acaps32);
  524. }
  525. pi->port_type = port_type;
  526. pi->mdio_addr = mdio_addr;
  527. pi->mod_type = FW_PORT_MOD_TYPE_NA;
  528. init_link_config(&pi->link_cfg, pcaps, acaps);
  529. return 0;
  530. }
  531. /**
  532. * t4vf_fw_reset - issue a reset to FW
  533. * @adapter: the adapter
  534. *
  535. * Issues a reset command to FW. For a Physical Function this would
  536. * result in the Firmware resetting all of its state. For a Virtual
  537. * Function this just resets the state associated with the VF.
  538. */
  539. int t4vf_fw_reset(struct adapter *adapter)
  540. {
  541. struct fw_reset_cmd cmd;
  542. memset(&cmd, 0, sizeof(cmd));
  543. cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_RESET_CMD) |
  544. FW_CMD_WRITE_F);
  545. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  546. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  547. }
  548. /**
  549. * t4vf_query_params - query FW or device parameters
  550. * @adapter: the adapter
  551. * @nparams: the number of parameters
  552. * @params: the parameter names
  553. * @vals: the parameter values
  554. *
  555. * Reads the values of firmware or device parameters. Up to 7 parameters
  556. * can be queried at once.
  557. */
  558. static int t4vf_query_params(struct adapter *adapter, unsigned int nparams,
  559. const u32 *params, u32 *vals)
  560. {
  561. int i, ret;
  562. struct fw_params_cmd cmd, rpl;
  563. struct fw_params_param *p;
  564. size_t len16;
  565. if (nparams > 7)
  566. return -EINVAL;
  567. memset(&cmd, 0, sizeof(cmd));
  568. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  569. FW_CMD_REQUEST_F |
  570. FW_CMD_READ_F);
  571. len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
  572. param[nparams].mnem), 16);
  573. cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16_V(len16));
  574. for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++)
  575. p->mnem = htonl(*params++);
  576. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  577. if (ret == 0)
  578. for (i = 0, p = &rpl.param[0]; i < nparams; i++, p++)
  579. *vals++ = be32_to_cpu(p->val);
  580. return ret;
  581. }
  582. /**
  583. * t4vf_set_params - sets FW or device parameters
  584. * @adapter: the adapter
  585. * @nparams: the number of parameters
  586. * @params: the parameter names
  587. * @vals: the parameter values
  588. *
  589. * Sets the values of firmware or device parameters. Up to 7 parameters
  590. * can be specified at once.
  591. */
  592. int t4vf_set_params(struct adapter *adapter, unsigned int nparams,
  593. const u32 *params, const u32 *vals)
  594. {
  595. int i;
  596. struct fw_params_cmd cmd;
  597. struct fw_params_param *p;
  598. size_t len16;
  599. if (nparams > 7)
  600. return -EINVAL;
  601. memset(&cmd, 0, sizeof(cmd));
  602. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PARAMS_CMD) |
  603. FW_CMD_REQUEST_F |
  604. FW_CMD_WRITE_F);
  605. len16 = DIV_ROUND_UP(offsetof(struct fw_params_cmd,
  606. param[nparams]), 16);
  607. cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16_V(len16));
  608. for (i = 0, p = &cmd.param[0]; i < nparams; i++, p++) {
  609. p->mnem = cpu_to_be32(*params++);
  610. p->val = cpu_to_be32(*vals++);
  611. }
  612. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  613. }
  614. /**
  615. * t4vf_fl_pkt_align - return the fl packet alignment
  616. * @adapter: the adapter
  617. *
  618. * T4 has a single field to specify the packing and padding boundary.
  619. * T5 onwards has separate fields for this and hence the alignment for
  620. * next packet offset is maximum of these two. And T6 changes the
  621. * Ingress Padding Boundary Shift, so it's all a mess and it's best
  622. * if we put this in low-level Common Code ...
  623. *
  624. */
  625. int t4vf_fl_pkt_align(struct adapter *adapter)
  626. {
  627. u32 sge_control, sge_control2;
  628. unsigned int ingpadboundary, ingpackboundary, fl_align, ingpad_shift;
  629. sge_control = adapter->params.sge.sge_control;
  630. /* T4 uses a single control field to specify both the PCIe Padding and
  631. * Packing Boundary. T5 introduced the ability to specify these
  632. * separately. The actual Ingress Packet Data alignment boundary
  633. * within Packed Buffer Mode is the maximum of these two
  634. * specifications. (Note that it makes no real practical sense to
  635. * have the Pading Boudary be larger than the Packing Boundary but you
  636. * could set the chip up that way and, in fact, legacy T4 code would
  637. * end doing this because it would initialize the Padding Boundary and
  638. * leave the Packing Boundary initialized to 0 (16 bytes).)
  639. * Padding Boundary values in T6 starts from 8B,
  640. * where as it is 32B for T4 and T5.
  641. */
  642. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  643. ingpad_shift = INGPADBOUNDARY_SHIFT_X;
  644. else
  645. ingpad_shift = T6_INGPADBOUNDARY_SHIFT_X;
  646. ingpadboundary = 1 << (INGPADBOUNDARY_G(sge_control) + ingpad_shift);
  647. fl_align = ingpadboundary;
  648. if (!is_t4(adapter->params.chip)) {
  649. /* T5 has a different interpretation of one of the PCIe Packing
  650. * Boundary values.
  651. */
  652. sge_control2 = adapter->params.sge.sge_control2;
  653. ingpackboundary = INGPACKBOUNDARY_G(sge_control2);
  654. if (ingpackboundary == INGPACKBOUNDARY_16B_X)
  655. ingpackboundary = 16;
  656. else
  657. ingpackboundary = 1 << (ingpackboundary +
  658. INGPACKBOUNDARY_SHIFT_X);
  659. fl_align = max(ingpadboundary, ingpackboundary);
  660. }
  661. return fl_align;
  662. }
  663. /**
  664. * t4vf_bar2_sge_qregs - return BAR2 SGE Queue register information
  665. * @adapter: the adapter
  666. * @qid: the Queue ID
  667. * @qtype: the Ingress or Egress type for @qid
  668. * @pbar2_qoffset: BAR2 Queue Offset
  669. * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
  670. *
  671. * Returns the BAR2 SGE Queue Registers information associated with the
  672. * indicated Absolute Queue ID. These are passed back in return value
  673. * pointers. @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
  674. * and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
  675. *
  676. * This may return an error which indicates that BAR2 SGE Queue
  677. * registers aren't available. If an error is not returned, then the
  678. * following values are returned:
  679. *
  680. * *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
  681. * *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
  682. *
  683. * If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
  684. * require the "Inferred Queue ID" ability may be used. E.g. the
  685. * Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
  686. * then these "Inferred Queue ID" register may not be used.
  687. */
  688. int t4vf_bar2_sge_qregs(struct adapter *adapter,
  689. unsigned int qid,
  690. enum t4_bar2_qtype qtype,
  691. u64 *pbar2_qoffset,
  692. unsigned int *pbar2_qid)
  693. {
  694. unsigned int page_shift, page_size, qpp_shift, qpp_mask;
  695. u64 bar2_page_offset, bar2_qoffset;
  696. unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
  697. /* T4 doesn't support BAR2 SGE Queue registers.
  698. */
  699. if (is_t4(adapter->params.chip))
  700. return -EINVAL;
  701. /* Get our SGE Page Size parameters.
  702. */
  703. page_shift = adapter->params.sge.sge_vf_hps + 10;
  704. page_size = 1 << page_shift;
  705. /* Get the right Queues per Page parameters for our Queue.
  706. */
  707. qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
  708. ? adapter->params.sge.sge_vf_eq_qpp
  709. : adapter->params.sge.sge_vf_iq_qpp);
  710. qpp_mask = (1 << qpp_shift) - 1;
  711. /* Calculate the basics of the BAR2 SGE Queue register area:
  712. * o The BAR2 page the Queue registers will be in.
  713. * o The BAR2 Queue ID.
  714. * o The BAR2 Queue ID Offset into the BAR2 page.
  715. */
  716. bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
  717. bar2_qid = qid & qpp_mask;
  718. bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
  719. /* If the BAR2 Queue ID Offset is less than the Page Size, then the
  720. * hardware will infer the Absolute Queue ID simply from the writes to
  721. * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
  722. * BAR2 Queue ID of 0 for those writes). Otherwise, we'll simply
  723. * write to the first BAR2 SGE Queue Area within the BAR2 Page with
  724. * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
  725. * from the BAR2 Page and BAR2 Queue ID.
  726. *
  727. * One important censequence of this is that some BAR2 SGE registers
  728. * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
  729. * there. But other registers synthesize the SGE Queue ID purely
  730. * from the writes to the registers -- the Write Combined Doorbell
  731. * Buffer is a good example. These BAR2 SGE Registers are only
  732. * available for those BAR2 SGE Register areas where the SGE Absolute
  733. * Queue ID can be inferred from simple writes.
  734. */
  735. bar2_qoffset = bar2_page_offset;
  736. bar2_qinferred = (bar2_qid_offset < page_size);
  737. if (bar2_qinferred) {
  738. bar2_qoffset += bar2_qid_offset;
  739. bar2_qid = 0;
  740. }
  741. *pbar2_qoffset = bar2_qoffset;
  742. *pbar2_qid = bar2_qid;
  743. return 0;
  744. }
  745. unsigned int t4vf_get_pf_from_vf(struct adapter *adapter)
  746. {
  747. u32 whoami;
  748. whoami = t4_read_reg(adapter, T4VF_PL_BASE_ADDR + PL_VF_WHOAMI_A);
  749. return (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5 ?
  750. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami));
  751. }
  752. /**
  753. * t4vf_get_sge_params - retrieve adapter Scatter gather Engine parameters
  754. * @adapter: the adapter
  755. *
  756. * Retrieves various core SGE parameters in the form of hardware SGE
  757. * register values. The caller is responsible for decoding these as
  758. * needed. The SGE parameters are stored in @adapter->params.sge.
  759. */
  760. int t4vf_get_sge_params(struct adapter *adapter)
  761. {
  762. struct sge_params *sge_params = &adapter->params.sge;
  763. u32 params[7], vals[7];
  764. int v;
  765. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  766. FW_PARAMS_PARAM_XYZ_V(SGE_CONTROL_A));
  767. params[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  768. FW_PARAMS_PARAM_XYZ_V(SGE_HOST_PAGE_SIZE_A));
  769. params[2] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  770. FW_PARAMS_PARAM_XYZ_V(SGE_FL_BUFFER_SIZE0_A));
  771. params[3] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  772. FW_PARAMS_PARAM_XYZ_V(SGE_FL_BUFFER_SIZE1_A));
  773. params[4] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  774. FW_PARAMS_PARAM_XYZ_V(SGE_TIMER_VALUE_0_AND_1_A));
  775. params[5] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  776. FW_PARAMS_PARAM_XYZ_V(SGE_TIMER_VALUE_2_AND_3_A));
  777. params[6] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  778. FW_PARAMS_PARAM_XYZ_V(SGE_TIMER_VALUE_4_AND_5_A));
  779. v = t4vf_query_params(adapter, 7, params, vals);
  780. if (v)
  781. return v;
  782. sge_params->sge_control = vals[0];
  783. sge_params->sge_host_page_size = vals[1];
  784. sge_params->sge_fl_buffer_size[0] = vals[2];
  785. sge_params->sge_fl_buffer_size[1] = vals[3];
  786. sge_params->sge_timer_value_0_and_1 = vals[4];
  787. sge_params->sge_timer_value_2_and_3 = vals[5];
  788. sge_params->sge_timer_value_4_and_5 = vals[6];
  789. /* T4 uses a single control field to specify both the PCIe Padding and
  790. * Packing Boundary. T5 introduced the ability to specify these
  791. * separately with the Padding Boundary in SGE_CONTROL and and Packing
  792. * Boundary in SGE_CONTROL2. So for T5 and later we need to grab
  793. * SGE_CONTROL in order to determine how ingress packet data will be
  794. * laid out in Packed Buffer Mode. Unfortunately, older versions of
  795. * the firmware won't let us retrieve SGE_CONTROL2 so if we get a
  796. * failure grabbing it we throw an error since we can't figure out the
  797. * right value.
  798. */
  799. if (!is_t4(adapter->params.chip)) {
  800. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  801. FW_PARAMS_PARAM_XYZ_V(SGE_CONTROL2_A));
  802. v = t4vf_query_params(adapter, 1, params, vals);
  803. if (v != FW_SUCCESS) {
  804. dev_err(adapter->pdev_dev,
  805. "Unable to get SGE Control2; "
  806. "probably old firmware.\n");
  807. return v;
  808. }
  809. sge_params->sge_control2 = vals[0];
  810. }
  811. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  812. FW_PARAMS_PARAM_XYZ_V(SGE_INGRESS_RX_THRESHOLD_A));
  813. params[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  814. FW_PARAMS_PARAM_XYZ_V(SGE_CONM_CTRL_A));
  815. v = t4vf_query_params(adapter, 2, params, vals);
  816. if (v)
  817. return v;
  818. sge_params->sge_ingress_rx_threshold = vals[0];
  819. sge_params->sge_congestion_control = vals[1];
  820. /* For T5 and later we want to use the new BAR2 Doorbells.
  821. * Unfortunately, older firmware didn't allow the this register to be
  822. * read.
  823. */
  824. if (!is_t4(adapter->params.chip)) {
  825. unsigned int pf, s_hps, s_qpp;
  826. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  827. FW_PARAMS_PARAM_XYZ_V(
  828. SGE_EGRESS_QUEUES_PER_PAGE_VF_A));
  829. params[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_REG) |
  830. FW_PARAMS_PARAM_XYZ_V(
  831. SGE_INGRESS_QUEUES_PER_PAGE_VF_A));
  832. v = t4vf_query_params(adapter, 2, params, vals);
  833. if (v != FW_SUCCESS) {
  834. dev_warn(adapter->pdev_dev,
  835. "Unable to get VF SGE Queues/Page; "
  836. "probably old firmware.\n");
  837. return v;
  838. }
  839. sge_params->sge_egress_queues_per_page = vals[0];
  840. sge_params->sge_ingress_queues_per_page = vals[1];
  841. /* We need the Queues/Page for our VF. This is based on the
  842. * PF from which we're instantiated and is indexed in the
  843. * register we just read. Do it once here so other code in
  844. * the driver can just use it.
  845. */
  846. pf = t4vf_get_pf_from_vf(adapter);
  847. s_hps = (HOSTPAGESIZEPF0_S +
  848. (HOSTPAGESIZEPF1_S - HOSTPAGESIZEPF0_S) * pf);
  849. sge_params->sge_vf_hps =
  850. ((sge_params->sge_host_page_size >> s_hps)
  851. & HOSTPAGESIZEPF0_M);
  852. s_qpp = (QUEUESPERPAGEPF0_S +
  853. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) * pf);
  854. sge_params->sge_vf_eq_qpp =
  855. ((sge_params->sge_egress_queues_per_page >> s_qpp)
  856. & QUEUESPERPAGEPF0_M);
  857. sge_params->sge_vf_iq_qpp =
  858. ((sge_params->sge_ingress_queues_per_page >> s_qpp)
  859. & QUEUESPERPAGEPF0_M);
  860. }
  861. return 0;
  862. }
  863. /**
  864. * t4vf_get_vpd_params - retrieve device VPD paremeters
  865. * @adapter: the adapter
  866. *
  867. * Retrives various device Vital Product Data parameters. The parameters
  868. * are stored in @adapter->params.vpd.
  869. */
  870. int t4vf_get_vpd_params(struct adapter *adapter)
  871. {
  872. struct vpd_params *vpd_params = &adapter->params.vpd;
  873. u32 params[7], vals[7];
  874. int v;
  875. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  876. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CCLK));
  877. v = t4vf_query_params(adapter, 1, params, vals);
  878. if (v)
  879. return v;
  880. vpd_params->cclk = vals[0];
  881. return 0;
  882. }
  883. /**
  884. * t4vf_get_dev_params - retrieve device paremeters
  885. * @adapter: the adapter
  886. *
  887. * Retrives various device parameters. The parameters are stored in
  888. * @adapter->params.dev.
  889. */
  890. int t4vf_get_dev_params(struct adapter *adapter)
  891. {
  892. struct dev_params *dev_params = &adapter->params.dev;
  893. u32 params[7], vals[7];
  894. int v;
  895. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  896. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_FWREV));
  897. params[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  898. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_TPREV));
  899. v = t4vf_query_params(adapter, 2, params, vals);
  900. if (v)
  901. return v;
  902. dev_params->fwrev = vals[0];
  903. dev_params->tprev = vals[1];
  904. return 0;
  905. }
  906. /**
  907. * t4vf_get_rss_glb_config - retrieve adapter RSS Global Configuration
  908. * @adapter: the adapter
  909. *
  910. * Retrieves global RSS mode and parameters with which we have to live
  911. * and stores them in the @adapter's RSS parameters.
  912. */
  913. int t4vf_get_rss_glb_config(struct adapter *adapter)
  914. {
  915. struct rss_params *rss = &adapter->params.rss;
  916. struct fw_rss_glb_config_cmd cmd, rpl;
  917. int v;
  918. /*
  919. * Execute an RSS Global Configuration read command to retrieve
  920. * our RSS configuration.
  921. */
  922. memset(&cmd, 0, sizeof(cmd));
  923. cmd.op_to_write = cpu_to_be32(FW_CMD_OP_V(FW_RSS_GLB_CONFIG_CMD) |
  924. FW_CMD_REQUEST_F |
  925. FW_CMD_READ_F);
  926. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  927. v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  928. if (v)
  929. return v;
  930. /*
  931. * Transate the big-endian RSS Global Configuration into our
  932. * cpu-endian format based on the RSS mode. We also do first level
  933. * filtering at this point to weed out modes which don't support
  934. * VF Drivers ...
  935. */
  936. rss->mode = FW_RSS_GLB_CONFIG_CMD_MODE_G(
  937. be32_to_cpu(rpl.u.manual.mode_pkd));
  938. switch (rss->mode) {
  939. case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
  940. u32 word = be32_to_cpu(
  941. rpl.u.basicvirtual.synmapen_to_hashtoeplitz);
  942. rss->u.basicvirtual.synmapen =
  943. ((word & FW_RSS_GLB_CONFIG_CMD_SYNMAPEN_F) != 0);
  944. rss->u.basicvirtual.syn4tupenipv6 =
  945. ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV6_F) != 0);
  946. rss->u.basicvirtual.syn2tupenipv6 =
  947. ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV6_F) != 0);
  948. rss->u.basicvirtual.syn4tupenipv4 =
  949. ((word & FW_RSS_GLB_CONFIG_CMD_SYN4TUPENIPV4_F) != 0);
  950. rss->u.basicvirtual.syn2tupenipv4 =
  951. ((word & FW_RSS_GLB_CONFIG_CMD_SYN2TUPENIPV4_F) != 0);
  952. rss->u.basicvirtual.ofdmapen =
  953. ((word & FW_RSS_GLB_CONFIG_CMD_OFDMAPEN_F) != 0);
  954. rss->u.basicvirtual.tnlmapen =
  955. ((word & FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F) != 0);
  956. rss->u.basicvirtual.tnlalllookup =
  957. ((word & FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F) != 0);
  958. rss->u.basicvirtual.hashtoeplitz =
  959. ((word & FW_RSS_GLB_CONFIG_CMD_HASHTOEPLITZ_F) != 0);
  960. /* we need at least Tunnel Map Enable to be set */
  961. if (!rss->u.basicvirtual.tnlmapen)
  962. return -EINVAL;
  963. break;
  964. }
  965. default:
  966. /* all unknown/unsupported RSS modes result in an error */
  967. return -EINVAL;
  968. }
  969. return 0;
  970. }
  971. /**
  972. * t4vf_get_vfres - retrieve VF resource limits
  973. * @adapter: the adapter
  974. *
  975. * Retrieves configured resource limits and capabilities for a virtual
  976. * function. The results are stored in @adapter->vfres.
  977. */
  978. int t4vf_get_vfres(struct adapter *adapter)
  979. {
  980. struct vf_resources *vfres = &adapter->params.vfres;
  981. struct fw_pfvf_cmd cmd, rpl;
  982. int v;
  983. u32 word;
  984. /*
  985. * Execute PFVF Read command to get VF resource limits; bail out early
  986. * with error on command failure.
  987. */
  988. memset(&cmd, 0, sizeof(cmd));
  989. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) |
  990. FW_CMD_REQUEST_F |
  991. FW_CMD_READ_F);
  992. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  993. v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  994. if (v)
  995. return v;
  996. /*
  997. * Extract VF resource limits and return success.
  998. */
  999. word = be32_to_cpu(rpl.niqflint_niq);
  1000. vfres->niqflint = FW_PFVF_CMD_NIQFLINT_G(word);
  1001. vfres->niq = FW_PFVF_CMD_NIQ_G(word);
  1002. word = be32_to_cpu(rpl.type_to_neq);
  1003. vfres->neq = FW_PFVF_CMD_NEQ_G(word);
  1004. vfres->pmask = FW_PFVF_CMD_PMASK_G(word);
  1005. word = be32_to_cpu(rpl.tc_to_nexactf);
  1006. vfres->tc = FW_PFVF_CMD_TC_G(word);
  1007. vfres->nvi = FW_PFVF_CMD_NVI_G(word);
  1008. vfres->nexactf = FW_PFVF_CMD_NEXACTF_G(word);
  1009. word = be32_to_cpu(rpl.r_caps_to_nethctrl);
  1010. vfres->r_caps = FW_PFVF_CMD_R_CAPS_G(word);
  1011. vfres->wx_caps = FW_PFVF_CMD_WX_CAPS_G(word);
  1012. vfres->nethctrl = FW_PFVF_CMD_NETHCTRL_G(word);
  1013. return 0;
  1014. }
  1015. /**
  1016. * t4vf_read_rss_vi_config - read a VI's RSS configuration
  1017. * @adapter: the adapter
  1018. * @viid: Virtual Interface ID
  1019. * @config: pointer to host-native VI RSS Configuration buffer
  1020. *
  1021. * Reads the Virtual Interface's RSS configuration information and
  1022. * translates it into CPU-native format.
  1023. */
  1024. int t4vf_read_rss_vi_config(struct adapter *adapter, unsigned int viid,
  1025. union rss_vi_config *config)
  1026. {
  1027. struct fw_rss_vi_config_cmd cmd, rpl;
  1028. int v;
  1029. memset(&cmd, 0, sizeof(cmd));
  1030. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  1031. FW_CMD_REQUEST_F |
  1032. FW_CMD_READ_F |
  1033. FW_RSS_VI_CONFIG_CMD_VIID(viid));
  1034. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  1035. v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  1036. if (v)
  1037. return v;
  1038. switch (adapter->params.rss.mode) {
  1039. case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
  1040. u32 word = be32_to_cpu(rpl.u.basicvirtual.defaultq_to_udpen);
  1041. config->basicvirtual.ip6fourtupen =
  1042. ((word & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) != 0);
  1043. config->basicvirtual.ip6twotupen =
  1044. ((word & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F) != 0);
  1045. config->basicvirtual.ip4fourtupen =
  1046. ((word & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) != 0);
  1047. config->basicvirtual.ip4twotupen =
  1048. ((word & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F) != 0);
  1049. config->basicvirtual.udpen =
  1050. ((word & FW_RSS_VI_CONFIG_CMD_UDPEN_F) != 0);
  1051. config->basicvirtual.defaultq =
  1052. FW_RSS_VI_CONFIG_CMD_DEFAULTQ_G(word);
  1053. break;
  1054. }
  1055. default:
  1056. return -EINVAL;
  1057. }
  1058. return 0;
  1059. }
  1060. /**
  1061. * t4vf_write_rss_vi_config - write a VI's RSS configuration
  1062. * @adapter: the adapter
  1063. * @viid: Virtual Interface ID
  1064. * @config: pointer to host-native VI RSS Configuration buffer
  1065. *
  1066. * Write the Virtual Interface's RSS configuration information
  1067. * (translating it into firmware-native format before writing).
  1068. */
  1069. int t4vf_write_rss_vi_config(struct adapter *adapter, unsigned int viid,
  1070. union rss_vi_config *config)
  1071. {
  1072. struct fw_rss_vi_config_cmd cmd, rpl;
  1073. memset(&cmd, 0, sizeof(cmd));
  1074. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_VI_CONFIG_CMD) |
  1075. FW_CMD_REQUEST_F |
  1076. FW_CMD_WRITE_F |
  1077. FW_RSS_VI_CONFIG_CMD_VIID(viid));
  1078. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  1079. switch (adapter->params.rss.mode) {
  1080. case FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL: {
  1081. u32 word = 0;
  1082. if (config->basicvirtual.ip6fourtupen)
  1083. word |= FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F;
  1084. if (config->basicvirtual.ip6twotupen)
  1085. word |= FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F;
  1086. if (config->basicvirtual.ip4fourtupen)
  1087. word |= FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F;
  1088. if (config->basicvirtual.ip4twotupen)
  1089. word |= FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F;
  1090. if (config->basicvirtual.udpen)
  1091. word |= FW_RSS_VI_CONFIG_CMD_UDPEN_F;
  1092. word |= FW_RSS_VI_CONFIG_CMD_DEFAULTQ_V(
  1093. config->basicvirtual.defaultq);
  1094. cmd.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(word);
  1095. break;
  1096. }
  1097. default:
  1098. return -EINVAL;
  1099. }
  1100. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  1101. }
  1102. /**
  1103. * t4vf_config_rss_range - configure a portion of the RSS mapping table
  1104. * @adapter: the adapter
  1105. * @viid: Virtual Interface of RSS Table Slice
  1106. * @start: starting entry in the table to write
  1107. * @n: how many table entries to write
  1108. * @rspq: values for the "Response Queue" (Ingress Queue) lookup table
  1109. * @nrspq: number of values in @rspq
  1110. *
  1111. * Programs the selected part of the VI's RSS mapping table with the
  1112. * provided values. If @nrspq < @n the supplied values are used repeatedly
  1113. * until the full table range is populated.
  1114. *
  1115. * The caller must ensure the values in @rspq are in the range 0..1023.
  1116. */
  1117. int t4vf_config_rss_range(struct adapter *adapter, unsigned int viid,
  1118. int start, int n, const u16 *rspq, int nrspq)
  1119. {
  1120. const u16 *rsp = rspq;
  1121. const u16 *rsp_end = rspq+nrspq;
  1122. struct fw_rss_ind_tbl_cmd cmd;
  1123. /*
  1124. * Initialize firmware command template to write the RSS table.
  1125. */
  1126. memset(&cmd, 0, sizeof(cmd));
  1127. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_RSS_IND_TBL_CMD) |
  1128. FW_CMD_REQUEST_F |
  1129. FW_CMD_WRITE_F |
  1130. FW_RSS_IND_TBL_CMD_VIID_V(viid));
  1131. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  1132. /*
  1133. * Each firmware RSS command can accommodate up to 32 RSS Ingress
  1134. * Queue Identifiers. These Ingress Queue IDs are packed three to
  1135. * a 32-bit word as 10-bit values with the upper remaining 2 bits
  1136. * reserved.
  1137. */
  1138. while (n > 0) {
  1139. __be32 *qp = &cmd.iq0_to_iq2;
  1140. int nq = min(n, 32);
  1141. int ret;
  1142. /*
  1143. * Set up the firmware RSS command header to send the next
  1144. * "nq" Ingress Queue IDs to the firmware.
  1145. */
  1146. cmd.niqid = cpu_to_be16(nq);
  1147. cmd.startidx = cpu_to_be16(start);
  1148. /*
  1149. * "nq" more done for the start of the next loop.
  1150. */
  1151. start += nq;
  1152. n -= nq;
  1153. /*
  1154. * While there are still Ingress Queue IDs to stuff into the
  1155. * current firmware RSS command, retrieve them from the
  1156. * Ingress Queue ID array and insert them into the command.
  1157. */
  1158. while (nq > 0) {
  1159. /*
  1160. * Grab up to the next 3 Ingress Queue IDs (wrapping
  1161. * around the Ingress Queue ID array if necessary) and
  1162. * insert them into the firmware RSS command at the
  1163. * current 3-tuple position within the commad.
  1164. */
  1165. u16 qbuf[3];
  1166. u16 *qbp = qbuf;
  1167. int nqbuf = min(3, nq);
  1168. nq -= nqbuf;
  1169. qbuf[0] = qbuf[1] = qbuf[2] = 0;
  1170. while (nqbuf) {
  1171. nqbuf--;
  1172. *qbp++ = *rsp++;
  1173. if (rsp >= rsp_end)
  1174. rsp = rspq;
  1175. }
  1176. *qp++ = cpu_to_be32(FW_RSS_IND_TBL_CMD_IQ0_V(qbuf[0]) |
  1177. FW_RSS_IND_TBL_CMD_IQ1_V(qbuf[1]) |
  1178. FW_RSS_IND_TBL_CMD_IQ2_V(qbuf[2]));
  1179. }
  1180. /*
  1181. * Send this portion of the RRS table update to the firmware;
  1182. * bail out on any errors.
  1183. */
  1184. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1185. if (ret)
  1186. return ret;
  1187. }
  1188. return 0;
  1189. }
  1190. /**
  1191. * t4vf_alloc_vi - allocate a virtual interface on a port
  1192. * @adapter: the adapter
  1193. * @port_id: physical port associated with the VI
  1194. *
  1195. * Allocate a new Virtual Interface and bind it to the indicated
  1196. * physical port. Return the new Virtual Interface Identifier on
  1197. * success, or a [negative] error number on failure.
  1198. */
  1199. int t4vf_alloc_vi(struct adapter *adapter, int port_id)
  1200. {
  1201. struct fw_vi_cmd cmd, rpl;
  1202. int v;
  1203. /*
  1204. * Execute a VI command to allocate Virtual Interface and return its
  1205. * VIID.
  1206. */
  1207. memset(&cmd, 0, sizeof(cmd));
  1208. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
  1209. FW_CMD_REQUEST_F |
  1210. FW_CMD_WRITE_F |
  1211. FW_CMD_EXEC_F);
  1212. cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
  1213. FW_VI_CMD_ALLOC_F);
  1214. cmd.portid_pkd = FW_VI_CMD_PORTID_V(port_id);
  1215. v = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  1216. if (v)
  1217. return v;
  1218. return FW_VI_CMD_VIID_G(be16_to_cpu(rpl.type_viid));
  1219. }
  1220. /**
  1221. * t4vf_free_vi -- free a virtual interface
  1222. * @adapter: the adapter
  1223. * @viid: the virtual interface identifier
  1224. *
  1225. * Free a previously allocated Virtual Interface. Return an error on
  1226. * failure.
  1227. */
  1228. int t4vf_free_vi(struct adapter *adapter, int viid)
  1229. {
  1230. struct fw_vi_cmd cmd;
  1231. /*
  1232. * Execute a VI command to free the Virtual Interface.
  1233. */
  1234. memset(&cmd, 0, sizeof(cmd));
  1235. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_VI_CMD) |
  1236. FW_CMD_REQUEST_F |
  1237. FW_CMD_EXEC_F);
  1238. cmd.alloc_to_len16 = cpu_to_be32(FW_LEN16(cmd) |
  1239. FW_VI_CMD_FREE_F);
  1240. cmd.type_viid = cpu_to_be16(FW_VI_CMD_VIID_V(viid));
  1241. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1242. }
  1243. /**
  1244. * t4vf_enable_vi - enable/disable a virtual interface
  1245. * @adapter: the adapter
  1246. * @viid: the Virtual Interface ID
  1247. * @rx_en: 1=enable Rx, 0=disable Rx
  1248. * @tx_en: 1=enable Tx, 0=disable Tx
  1249. *
  1250. * Enables/disables a virtual interface.
  1251. */
  1252. int t4vf_enable_vi(struct adapter *adapter, unsigned int viid,
  1253. bool rx_en, bool tx_en)
  1254. {
  1255. struct fw_vi_enable_cmd cmd;
  1256. memset(&cmd, 0, sizeof(cmd));
  1257. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  1258. FW_CMD_REQUEST_F |
  1259. FW_CMD_EXEC_F |
  1260. FW_VI_ENABLE_CMD_VIID_V(viid));
  1261. cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_IEN_V(rx_en) |
  1262. FW_VI_ENABLE_CMD_EEN_V(tx_en) |
  1263. FW_LEN16(cmd));
  1264. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1265. }
  1266. /**
  1267. * t4vf_enable_pi - enable/disable a Port's virtual interface
  1268. * @adapter: the adapter
  1269. * @pi: the Port Information structure
  1270. * @rx_en: 1=enable Rx, 0=disable Rx
  1271. * @tx_en: 1=enable Tx, 0=disable Tx
  1272. *
  1273. * Enables/disables a Port's virtual interface. If the Virtual
  1274. * Interface enable/disable operation is successful, we notify the
  1275. * OS-specific code of a potential Link Status change via the OS Contract
  1276. * API t4vf_os_link_changed().
  1277. */
  1278. int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi,
  1279. bool rx_en, bool tx_en)
  1280. {
  1281. int ret = t4vf_enable_vi(adapter, pi->viid, rx_en, tx_en);
  1282. if (ret)
  1283. return ret;
  1284. t4vf_os_link_changed(adapter, pi->pidx,
  1285. rx_en && tx_en && pi->link_cfg.link_ok);
  1286. return 0;
  1287. }
  1288. /**
  1289. * t4vf_identify_port - identify a VI's port by blinking its LED
  1290. * @adapter: the adapter
  1291. * @viid: the Virtual Interface ID
  1292. * @nblinks: how many times to blink LED at 2.5 Hz
  1293. *
  1294. * Identifies a VI's port by blinking its LED.
  1295. */
  1296. int t4vf_identify_port(struct adapter *adapter, unsigned int viid,
  1297. unsigned int nblinks)
  1298. {
  1299. struct fw_vi_enable_cmd cmd;
  1300. memset(&cmd, 0, sizeof(cmd));
  1301. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_ENABLE_CMD) |
  1302. FW_CMD_REQUEST_F |
  1303. FW_CMD_EXEC_F |
  1304. FW_VI_ENABLE_CMD_VIID_V(viid));
  1305. cmd.ien_to_len16 = cpu_to_be32(FW_VI_ENABLE_CMD_LED_F |
  1306. FW_LEN16(cmd));
  1307. cmd.blinkdur = cpu_to_be16(nblinks);
  1308. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1309. }
  1310. /**
  1311. * t4vf_set_rxmode - set Rx properties of a virtual interface
  1312. * @adapter: the adapter
  1313. * @viid: the VI id
  1314. * @mtu: the new MTU or -1 for no change
  1315. * @promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
  1316. * @all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
  1317. * @bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
  1318. * @vlanex: 1 to enable hardware VLAN Tag extraction, 0 to disable it,
  1319. * -1 no change
  1320. *
  1321. * Sets Rx properties of a virtual interface.
  1322. */
  1323. int t4vf_set_rxmode(struct adapter *adapter, unsigned int viid,
  1324. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  1325. bool sleep_ok)
  1326. {
  1327. struct fw_vi_rxmode_cmd cmd;
  1328. /* convert to FW values */
  1329. if (mtu < 0)
  1330. mtu = FW_VI_RXMODE_CMD_MTU_M;
  1331. if (promisc < 0)
  1332. promisc = FW_VI_RXMODE_CMD_PROMISCEN_M;
  1333. if (all_multi < 0)
  1334. all_multi = FW_VI_RXMODE_CMD_ALLMULTIEN_M;
  1335. if (bcast < 0)
  1336. bcast = FW_VI_RXMODE_CMD_BROADCASTEN_M;
  1337. if (vlanex < 0)
  1338. vlanex = FW_VI_RXMODE_CMD_VLANEXEN_M;
  1339. memset(&cmd, 0, sizeof(cmd));
  1340. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_RXMODE_CMD) |
  1341. FW_CMD_REQUEST_F |
  1342. FW_CMD_WRITE_F |
  1343. FW_VI_RXMODE_CMD_VIID_V(viid));
  1344. cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
  1345. cmd.mtu_to_vlanexen =
  1346. cpu_to_be32(FW_VI_RXMODE_CMD_MTU_V(mtu) |
  1347. FW_VI_RXMODE_CMD_PROMISCEN_V(promisc) |
  1348. FW_VI_RXMODE_CMD_ALLMULTIEN_V(all_multi) |
  1349. FW_VI_RXMODE_CMD_BROADCASTEN_V(bcast) |
  1350. FW_VI_RXMODE_CMD_VLANEXEN_V(vlanex));
  1351. return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
  1352. }
  1353. /**
  1354. * t4vf_alloc_mac_filt - allocates exact-match filters for MAC addresses
  1355. * @adapter: the adapter
  1356. * @viid: the Virtual Interface Identifier
  1357. * @free: if true any existing filters for this VI id are first removed
  1358. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  1359. * @addr: the MAC address(es)
  1360. * @idx: where to store the index of each allocated filter
  1361. * @hash: pointer to hash address filter bitmap
  1362. * @sleep_ok: call is allowed to sleep
  1363. *
  1364. * Allocates an exact-match filter for each of the supplied addresses and
  1365. * sets it to the corresponding address. If @idx is not %NULL it should
  1366. * have at least @naddr entries, each of which will be set to the index of
  1367. * the filter allocated for the corresponding MAC address. If a filter
  1368. * could not be allocated for an address its index is set to 0xffff.
  1369. * If @hash is not %NULL addresses that fail to allocate an exact filter
  1370. * are hashed and update the hash filter bitmap pointed at by @hash.
  1371. *
  1372. * Returns a negative error number or the number of filters allocated.
  1373. */
  1374. int t4vf_alloc_mac_filt(struct adapter *adapter, unsigned int viid, bool free,
  1375. unsigned int naddr, const u8 **addr, u16 *idx,
  1376. u64 *hash, bool sleep_ok)
  1377. {
  1378. int offset, ret = 0;
  1379. unsigned nfilters = 0;
  1380. unsigned int rem = naddr;
  1381. struct fw_vi_mac_cmd cmd, rpl;
  1382. unsigned int max_naddr = adapter->params.arch.mps_tcam_size;
  1383. if (naddr > max_naddr)
  1384. return -EINVAL;
  1385. for (offset = 0; offset < naddr; /**/) {
  1386. unsigned int fw_naddr = (rem < ARRAY_SIZE(cmd.u.exact)
  1387. ? rem
  1388. : ARRAY_SIZE(cmd.u.exact));
  1389. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  1390. u.exact[fw_naddr]), 16);
  1391. struct fw_vi_mac_exact *p;
  1392. int i;
  1393. memset(&cmd, 0, sizeof(cmd));
  1394. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  1395. FW_CMD_REQUEST_F |
  1396. FW_CMD_WRITE_F |
  1397. (free ? FW_CMD_EXEC_F : 0) |
  1398. FW_VI_MAC_CMD_VIID_V(viid));
  1399. cmd.freemacs_to_len16 =
  1400. cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(free) |
  1401. FW_CMD_LEN16_V(len16));
  1402. for (i = 0, p = cmd.u.exact; i < fw_naddr; i++, p++) {
  1403. p->valid_to_idx = cpu_to_be16(
  1404. FW_VI_MAC_CMD_VALID_F |
  1405. FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_ADD_MAC));
  1406. memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
  1407. }
  1408. ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &rpl,
  1409. sleep_ok);
  1410. if (ret && ret != -ENOMEM)
  1411. break;
  1412. for (i = 0, p = rpl.u.exact; i < fw_naddr; i++, p++) {
  1413. u16 index = FW_VI_MAC_CMD_IDX_G(
  1414. be16_to_cpu(p->valid_to_idx));
  1415. if (idx)
  1416. idx[offset+i] =
  1417. (index >= max_naddr
  1418. ? 0xffff
  1419. : index);
  1420. if (index < max_naddr)
  1421. nfilters++;
  1422. else if (hash)
  1423. *hash |= (1ULL << hash_mac_addr(addr[offset+i]));
  1424. }
  1425. free = false;
  1426. offset += fw_naddr;
  1427. rem -= fw_naddr;
  1428. }
  1429. /*
  1430. * If there were no errors or we merely ran out of room in our MAC
  1431. * address arena, return the number of filters actually written.
  1432. */
  1433. if (ret == 0 || ret == -ENOMEM)
  1434. ret = nfilters;
  1435. return ret;
  1436. }
  1437. /**
  1438. * t4vf_free_mac_filt - frees exact-match filters of given MAC addresses
  1439. * @adapter: the adapter
  1440. * @viid: the VI id
  1441. * @naddr: the number of MAC addresses to allocate filters for (up to 7)
  1442. * @addr: the MAC address(es)
  1443. * @sleep_ok: call is allowed to sleep
  1444. *
  1445. * Frees the exact-match filter for each of the supplied addresses
  1446. *
  1447. * Returns a negative error number or the number of filters freed.
  1448. */
  1449. int t4vf_free_mac_filt(struct adapter *adapter, unsigned int viid,
  1450. unsigned int naddr, const u8 **addr, bool sleep_ok)
  1451. {
  1452. int offset, ret = 0;
  1453. struct fw_vi_mac_cmd cmd;
  1454. unsigned int nfilters = 0;
  1455. unsigned int max_naddr = adapter->params.arch.mps_tcam_size;
  1456. unsigned int rem = naddr;
  1457. if (naddr > max_naddr)
  1458. return -EINVAL;
  1459. for (offset = 0; offset < (int)naddr ; /**/) {
  1460. unsigned int fw_naddr = (rem < ARRAY_SIZE(cmd.u.exact) ?
  1461. rem : ARRAY_SIZE(cmd.u.exact));
  1462. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  1463. u.exact[fw_naddr]), 16);
  1464. struct fw_vi_mac_exact *p;
  1465. int i;
  1466. memset(&cmd, 0, sizeof(cmd));
  1467. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  1468. FW_CMD_REQUEST_F |
  1469. FW_CMD_WRITE_F |
  1470. FW_CMD_EXEC_V(0) |
  1471. FW_VI_MAC_CMD_VIID_V(viid));
  1472. cmd.freemacs_to_len16 =
  1473. cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(0) |
  1474. FW_CMD_LEN16_V(len16));
  1475. for (i = 0, p = cmd.u.exact; i < (int)fw_naddr; i++, p++) {
  1476. p->valid_to_idx = cpu_to_be16(
  1477. FW_VI_MAC_CMD_VALID_F |
  1478. FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_MAC_BASED_FREE));
  1479. memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
  1480. }
  1481. ret = t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), &cmd,
  1482. sleep_ok);
  1483. if (ret)
  1484. break;
  1485. for (i = 0, p = cmd.u.exact; i < fw_naddr; i++, p++) {
  1486. u16 index = FW_VI_MAC_CMD_IDX_G(
  1487. be16_to_cpu(p->valid_to_idx));
  1488. if (index < max_naddr)
  1489. nfilters++;
  1490. }
  1491. offset += fw_naddr;
  1492. rem -= fw_naddr;
  1493. }
  1494. if (ret == 0)
  1495. ret = nfilters;
  1496. return ret;
  1497. }
  1498. /**
  1499. * t4vf_change_mac - modifies the exact-match filter for a MAC address
  1500. * @adapter: the adapter
  1501. * @viid: the Virtual Interface ID
  1502. * @idx: index of existing filter for old value of MAC address, or -1
  1503. * @addr: the new MAC address value
  1504. * @persist: if idx < 0, the new MAC allocation should be persistent
  1505. *
  1506. * Modifies an exact-match filter and sets it to the new MAC address.
  1507. * Note that in general it is not possible to modify the value of a given
  1508. * filter so the generic way to modify an address filter is to free the
  1509. * one being used by the old address value and allocate a new filter for
  1510. * the new address value. @idx can be -1 if the address is a new
  1511. * addition.
  1512. *
  1513. * Returns a negative error number or the index of the filter with the new
  1514. * MAC value.
  1515. */
  1516. int t4vf_change_mac(struct adapter *adapter, unsigned int viid,
  1517. int idx, const u8 *addr, bool persist)
  1518. {
  1519. int ret;
  1520. struct fw_vi_mac_cmd cmd, rpl;
  1521. struct fw_vi_mac_exact *p = &cmd.u.exact[0];
  1522. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  1523. u.exact[1]), 16);
  1524. unsigned int max_mac_addr = adapter->params.arch.mps_tcam_size;
  1525. /*
  1526. * If this is a new allocation, determine whether it should be
  1527. * persistent (across a "freemacs" operation) or not.
  1528. */
  1529. if (idx < 0)
  1530. idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
  1531. memset(&cmd, 0, sizeof(cmd));
  1532. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  1533. FW_CMD_REQUEST_F |
  1534. FW_CMD_WRITE_F |
  1535. FW_VI_MAC_CMD_VIID_V(viid));
  1536. cmd.freemacs_to_len16 = cpu_to_be32(FW_CMD_LEN16_V(len16));
  1537. p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
  1538. FW_VI_MAC_CMD_IDX_V(idx));
  1539. memcpy(p->macaddr, addr, sizeof(p->macaddr));
  1540. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &rpl);
  1541. if (ret == 0) {
  1542. p = &rpl.u.exact[0];
  1543. ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
  1544. if (ret >= max_mac_addr)
  1545. ret = -ENOMEM;
  1546. }
  1547. return ret;
  1548. }
  1549. /**
  1550. * t4vf_set_addr_hash - program the MAC inexact-match hash filter
  1551. * @adapter: the adapter
  1552. * @viid: the Virtual Interface Identifier
  1553. * @ucast: whether the hash filter should also match unicast addresses
  1554. * @vec: the value to be written to the hash filter
  1555. * @sleep_ok: call is allowed to sleep
  1556. *
  1557. * Sets the 64-bit inexact-match hash filter for a virtual interface.
  1558. */
  1559. int t4vf_set_addr_hash(struct adapter *adapter, unsigned int viid,
  1560. bool ucast, u64 vec, bool sleep_ok)
  1561. {
  1562. struct fw_vi_mac_cmd cmd;
  1563. size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
  1564. u.exact[0]), 16);
  1565. memset(&cmd, 0, sizeof(cmd));
  1566. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
  1567. FW_CMD_REQUEST_F |
  1568. FW_CMD_WRITE_F |
  1569. FW_VI_ENABLE_CMD_VIID_V(viid));
  1570. cmd.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_HASHVECEN_F |
  1571. FW_VI_MAC_CMD_HASHUNIEN_V(ucast) |
  1572. FW_CMD_LEN16_V(len16));
  1573. cmd.u.hash.hashvec = cpu_to_be64(vec);
  1574. return t4vf_wr_mbox_core(adapter, &cmd, sizeof(cmd), NULL, sleep_ok);
  1575. }
  1576. /**
  1577. * t4vf_get_port_stats - collect "port" statistics
  1578. * @adapter: the adapter
  1579. * @pidx: the port index
  1580. * @s: the stats structure to fill
  1581. *
  1582. * Collect statistics for the "port"'s Virtual Interface.
  1583. */
  1584. int t4vf_get_port_stats(struct adapter *adapter, int pidx,
  1585. struct t4vf_port_stats *s)
  1586. {
  1587. struct port_info *pi = adap2pinfo(adapter, pidx);
  1588. struct fw_vi_stats_vf fwstats;
  1589. unsigned int rem = VI_VF_NUM_STATS;
  1590. __be64 *fwsp = (__be64 *)&fwstats;
  1591. /*
  1592. * Grab the Virtual Interface statistics a chunk at a time via mailbox
  1593. * commands. We could use a Work Request and get all of them at once
  1594. * but that's an asynchronous interface which is awkward to use.
  1595. */
  1596. while (rem) {
  1597. unsigned int ix = VI_VF_NUM_STATS - rem;
  1598. unsigned int nstats = min(6U, rem);
  1599. struct fw_vi_stats_cmd cmd, rpl;
  1600. size_t len = (offsetof(struct fw_vi_stats_cmd, u) +
  1601. sizeof(struct fw_vi_stats_ctl));
  1602. size_t len16 = DIV_ROUND_UP(len, 16);
  1603. int ret;
  1604. memset(&cmd, 0, sizeof(cmd));
  1605. cmd.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_STATS_CMD) |
  1606. FW_VI_STATS_CMD_VIID_V(pi->viid) |
  1607. FW_CMD_REQUEST_F |
  1608. FW_CMD_READ_F);
  1609. cmd.retval_len16 = cpu_to_be32(FW_CMD_LEN16_V(len16));
  1610. cmd.u.ctl.nstats_ix =
  1611. cpu_to_be16(FW_VI_STATS_CMD_IX_V(ix) |
  1612. FW_VI_STATS_CMD_NSTATS_V(nstats));
  1613. ret = t4vf_wr_mbox_ns(adapter, &cmd, len, &rpl);
  1614. if (ret)
  1615. return ret;
  1616. memcpy(fwsp, &rpl.u.ctl.stat0, sizeof(__be64) * nstats);
  1617. rem -= nstats;
  1618. fwsp += nstats;
  1619. }
  1620. /*
  1621. * Translate firmware statistics into host native statistics.
  1622. */
  1623. s->tx_bcast_bytes = be64_to_cpu(fwstats.tx_bcast_bytes);
  1624. s->tx_bcast_frames = be64_to_cpu(fwstats.tx_bcast_frames);
  1625. s->tx_mcast_bytes = be64_to_cpu(fwstats.tx_mcast_bytes);
  1626. s->tx_mcast_frames = be64_to_cpu(fwstats.tx_mcast_frames);
  1627. s->tx_ucast_bytes = be64_to_cpu(fwstats.tx_ucast_bytes);
  1628. s->tx_ucast_frames = be64_to_cpu(fwstats.tx_ucast_frames);
  1629. s->tx_drop_frames = be64_to_cpu(fwstats.tx_drop_frames);
  1630. s->tx_offload_bytes = be64_to_cpu(fwstats.tx_offload_bytes);
  1631. s->tx_offload_frames = be64_to_cpu(fwstats.tx_offload_frames);
  1632. s->rx_bcast_bytes = be64_to_cpu(fwstats.rx_bcast_bytes);
  1633. s->rx_bcast_frames = be64_to_cpu(fwstats.rx_bcast_frames);
  1634. s->rx_mcast_bytes = be64_to_cpu(fwstats.rx_mcast_bytes);
  1635. s->rx_mcast_frames = be64_to_cpu(fwstats.rx_mcast_frames);
  1636. s->rx_ucast_bytes = be64_to_cpu(fwstats.rx_ucast_bytes);
  1637. s->rx_ucast_frames = be64_to_cpu(fwstats.rx_ucast_frames);
  1638. s->rx_err_frames = be64_to_cpu(fwstats.rx_err_frames);
  1639. return 0;
  1640. }
  1641. /**
  1642. * t4vf_iq_free - free an ingress queue and its free lists
  1643. * @adapter: the adapter
  1644. * @iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
  1645. * @iqid: ingress queue ID
  1646. * @fl0id: FL0 queue ID or 0xffff if no attached FL0
  1647. * @fl1id: FL1 queue ID or 0xffff if no attached FL1
  1648. *
  1649. * Frees an ingress queue and its associated free lists, if any.
  1650. */
  1651. int t4vf_iq_free(struct adapter *adapter, unsigned int iqtype,
  1652. unsigned int iqid, unsigned int fl0id, unsigned int fl1id)
  1653. {
  1654. struct fw_iq_cmd cmd;
  1655. memset(&cmd, 0, sizeof(cmd));
  1656. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_IQ_CMD) |
  1657. FW_CMD_REQUEST_F |
  1658. FW_CMD_EXEC_F);
  1659. cmd.alloc_to_len16 = cpu_to_be32(FW_IQ_CMD_FREE_F |
  1660. FW_LEN16(cmd));
  1661. cmd.type_to_iqandstindex =
  1662. cpu_to_be32(FW_IQ_CMD_TYPE_V(iqtype));
  1663. cmd.iqid = cpu_to_be16(iqid);
  1664. cmd.fl0id = cpu_to_be16(fl0id);
  1665. cmd.fl1id = cpu_to_be16(fl1id);
  1666. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1667. }
  1668. /**
  1669. * t4vf_eth_eq_free - free an Ethernet egress queue
  1670. * @adapter: the adapter
  1671. * @eqid: egress queue ID
  1672. *
  1673. * Frees an Ethernet egress queue.
  1674. */
  1675. int t4vf_eth_eq_free(struct adapter *adapter, unsigned int eqid)
  1676. {
  1677. struct fw_eq_eth_cmd cmd;
  1678. memset(&cmd, 0, sizeof(cmd));
  1679. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_EQ_ETH_CMD) |
  1680. FW_CMD_REQUEST_F |
  1681. FW_CMD_EXEC_F);
  1682. cmd.alloc_to_len16 = cpu_to_be32(FW_EQ_ETH_CMD_FREE_F |
  1683. FW_LEN16(cmd));
  1684. cmd.eqid_pkd = cpu_to_be32(FW_EQ_ETH_CMD_EQID_V(eqid));
  1685. return t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), NULL);
  1686. }
  1687. /**
  1688. * t4vf_link_down_rc_str - return a string for a Link Down Reason Code
  1689. * @link_down_rc: Link Down Reason Code
  1690. *
  1691. * Returns a string representation of the Link Down Reason Code.
  1692. */
  1693. static const char *t4vf_link_down_rc_str(unsigned char link_down_rc)
  1694. {
  1695. static const char * const reason[] = {
  1696. "Link Down",
  1697. "Remote Fault",
  1698. "Auto-negotiation Failure",
  1699. "Reserved",
  1700. "Insufficient Airflow",
  1701. "Unable To Determine Reason",
  1702. "No RX Signal Detected",
  1703. "Reserved",
  1704. };
  1705. if (link_down_rc >= ARRAY_SIZE(reason))
  1706. return "Bad Reason Code";
  1707. return reason[link_down_rc];
  1708. }
  1709. /**
  1710. * t4vf_handle_get_port_info - process a FW reply message
  1711. * @pi: the port info
  1712. * @rpl: start of the FW message
  1713. *
  1714. * Processes a GET_PORT_INFO FW reply message.
  1715. */
  1716. static void t4vf_handle_get_port_info(struct port_info *pi,
  1717. const struct fw_port_cmd *cmd)
  1718. {
  1719. fw_port_cap32_t pcaps, acaps, lpacaps, linkattr;
  1720. struct link_config *lc = &pi->link_cfg;
  1721. struct adapter *adapter = pi->adapter;
  1722. unsigned int speed, fc, fec, adv_fc;
  1723. enum fw_port_module_type mod_type;
  1724. int action, link_ok, linkdnrc;
  1725. enum fw_port_type port_type;
  1726. /* Extract the various fields from the Port Information message. */
  1727. action = FW_PORT_CMD_ACTION_G(be32_to_cpu(cmd->action_to_len16));
  1728. switch (action) {
  1729. case FW_PORT_ACTION_GET_PORT_INFO: {
  1730. u32 lstatus = be32_to_cpu(cmd->u.info.lstatus_to_modtype);
  1731. link_ok = (lstatus & FW_PORT_CMD_LSTATUS_F) != 0;
  1732. linkdnrc = FW_PORT_CMD_LINKDNRC_G(lstatus);
  1733. port_type = FW_PORT_CMD_PTYPE_G(lstatus);
  1734. mod_type = FW_PORT_CMD_MODTYPE_G(lstatus);
  1735. pcaps = fwcaps16_to_caps32(be16_to_cpu(cmd->u.info.pcap));
  1736. acaps = fwcaps16_to_caps32(be16_to_cpu(cmd->u.info.acap));
  1737. lpacaps = fwcaps16_to_caps32(be16_to_cpu(cmd->u.info.lpacap));
  1738. /* Unfortunately the format of the Link Status in the old
  1739. * 16-bit Port Information message isn't the same as the
  1740. * 16-bit Port Capabilities bitfield used everywhere else ...
  1741. */
  1742. linkattr = 0;
  1743. if (lstatus & FW_PORT_CMD_RXPAUSE_F)
  1744. linkattr |= FW_PORT_CAP32_FC_RX;
  1745. if (lstatus & FW_PORT_CMD_TXPAUSE_F)
  1746. linkattr |= FW_PORT_CAP32_FC_TX;
  1747. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100M))
  1748. linkattr |= FW_PORT_CAP32_SPEED_100M;
  1749. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_1G))
  1750. linkattr |= FW_PORT_CAP32_SPEED_1G;
  1751. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_10G))
  1752. linkattr |= FW_PORT_CAP32_SPEED_10G;
  1753. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_25G))
  1754. linkattr |= FW_PORT_CAP32_SPEED_25G;
  1755. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_40G))
  1756. linkattr |= FW_PORT_CAP32_SPEED_40G;
  1757. if (lstatus & FW_PORT_CMD_LSPEED_V(FW_PORT_CAP_SPEED_100G))
  1758. linkattr |= FW_PORT_CAP32_SPEED_100G;
  1759. break;
  1760. }
  1761. case FW_PORT_ACTION_GET_PORT_INFO32: {
  1762. u32 lstatus32;
  1763. lstatus32 = be32_to_cpu(cmd->u.info32.lstatus32_to_cbllen32);
  1764. link_ok = (lstatus32 & FW_PORT_CMD_LSTATUS32_F) != 0;
  1765. linkdnrc = FW_PORT_CMD_LINKDNRC32_G(lstatus32);
  1766. port_type = FW_PORT_CMD_PORTTYPE32_G(lstatus32);
  1767. mod_type = FW_PORT_CMD_MODTYPE32_G(lstatus32);
  1768. pcaps = be32_to_cpu(cmd->u.info32.pcaps32);
  1769. acaps = be32_to_cpu(cmd->u.info32.acaps32);
  1770. lpacaps = be32_to_cpu(cmd->u.info32.lpacaps32);
  1771. linkattr = be32_to_cpu(cmd->u.info32.linkattr32);
  1772. break;
  1773. }
  1774. default:
  1775. dev_err(adapter->pdev_dev, "Handle Port Information: Bad Command/Action %#x\n",
  1776. be32_to_cpu(cmd->action_to_len16));
  1777. return;
  1778. }
  1779. fec = fwcap_to_cc_fec(acaps);
  1780. adv_fc = fwcap_to_cc_pause(acaps);
  1781. fc = fwcap_to_cc_pause(linkattr);
  1782. speed = fwcap_to_speed(linkattr);
  1783. if (mod_type != pi->mod_type) {
  1784. /* When a new Transceiver Module is inserted, the Firmware
  1785. * will examine any Forward Error Correction parameters
  1786. * present in the Transceiver Module i2c EPROM and determine
  1787. * the supported and recommended FEC settings from those
  1788. * based on IEEE 802.3 standards. We always record the
  1789. * IEEE 802.3 recommended "automatic" settings.
  1790. */
  1791. lc->auto_fec = fec;
  1792. /* Some versions of the early T6 Firmware "cheated" when
  1793. * handling different Transceiver Modules by changing the
  1794. * underlaying Port Type reported to the Host Drivers. As
  1795. * such we need to capture whatever Port Type the Firmware
  1796. * sends us and record it in case it's different from what we
  1797. * were told earlier. Unfortunately, since Firmware is
  1798. * forever, we'll need to keep this code here forever, but in
  1799. * later T6 Firmware it should just be an assignment of the
  1800. * same value already recorded.
  1801. */
  1802. pi->port_type = port_type;
  1803. pi->mod_type = mod_type;
  1804. t4vf_os_portmod_changed(adapter, pi->pidx);
  1805. }
  1806. if (link_ok != lc->link_ok || speed != lc->speed ||
  1807. fc != lc->fc || adv_fc != lc->advertised_fc ||
  1808. fec != lc->fec) {
  1809. /* something changed */
  1810. if (!link_ok && lc->link_ok) {
  1811. lc->link_down_rc = linkdnrc;
  1812. dev_warn_ratelimited(adapter->pdev_dev,
  1813. "Port %d link down, reason: %s\n",
  1814. pi->port_id,
  1815. t4vf_link_down_rc_str(linkdnrc));
  1816. }
  1817. lc->link_ok = link_ok;
  1818. lc->speed = speed;
  1819. lc->advertised_fc = adv_fc;
  1820. lc->fc = fc;
  1821. lc->fec = fec;
  1822. lc->pcaps = pcaps;
  1823. lc->lpacaps = lpacaps;
  1824. lc->acaps = acaps & ADVERT_MASK;
  1825. /* If we're not physically capable of Auto-Negotiation, note
  1826. * this as Auto-Negotiation disabled. Otherwise, we track
  1827. * what Auto-Negotiation settings we have. Note parallel
  1828. * structure in init_link_config().
  1829. */
  1830. if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) {
  1831. lc->autoneg = AUTONEG_DISABLE;
  1832. } else if (lc->acaps & FW_PORT_CAP32_ANEG) {
  1833. lc->autoneg = AUTONEG_ENABLE;
  1834. } else {
  1835. /* When Autoneg is disabled, user needs to set
  1836. * single speed.
  1837. * Similar to cxgb4_ethtool.c: set_link_ksettings
  1838. */
  1839. lc->acaps = 0;
  1840. lc->speed_caps = fwcap_to_speed(acaps);
  1841. lc->autoneg = AUTONEG_DISABLE;
  1842. }
  1843. t4vf_os_link_changed(adapter, pi->pidx, link_ok);
  1844. }
  1845. }
  1846. /**
  1847. * t4vf_update_port_info - retrieve and update port information if changed
  1848. * @pi: the port_info
  1849. *
  1850. * We issue a Get Port Information Command to the Firmware and, if
  1851. * successful, we check to see if anything is different from what we
  1852. * last recorded and update things accordingly.
  1853. */
  1854. int t4vf_update_port_info(struct port_info *pi)
  1855. {
  1856. unsigned int fw_caps = pi->adapter->params.fw_caps_support;
  1857. struct fw_port_cmd port_cmd;
  1858. int ret;
  1859. memset(&port_cmd, 0, sizeof(port_cmd));
  1860. port_cmd.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PORT_CMD) |
  1861. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  1862. FW_PORT_CMD_PORTID_V(pi->port_id));
  1863. port_cmd.action_to_len16 = cpu_to_be32(
  1864. FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
  1865. ? FW_PORT_ACTION_GET_PORT_INFO
  1866. : FW_PORT_ACTION_GET_PORT_INFO32) |
  1867. FW_LEN16(port_cmd));
  1868. ret = t4vf_wr_mbox(pi->adapter, &port_cmd, sizeof(port_cmd),
  1869. &port_cmd);
  1870. if (ret)
  1871. return ret;
  1872. t4vf_handle_get_port_info(pi, &port_cmd);
  1873. return 0;
  1874. }
  1875. /**
  1876. * t4vf_handle_fw_rpl - process a firmware reply message
  1877. * @adapter: the adapter
  1878. * @rpl: start of the firmware message
  1879. *
  1880. * Processes a firmware message, such as link state change messages.
  1881. */
  1882. int t4vf_handle_fw_rpl(struct adapter *adapter, const __be64 *rpl)
  1883. {
  1884. const struct fw_cmd_hdr *cmd_hdr = (const struct fw_cmd_hdr *)rpl;
  1885. u8 opcode = FW_CMD_OP_G(be32_to_cpu(cmd_hdr->hi));
  1886. switch (opcode) {
  1887. case FW_PORT_CMD: {
  1888. /*
  1889. * Link/module state change message.
  1890. */
  1891. const struct fw_port_cmd *port_cmd =
  1892. (const struct fw_port_cmd *)rpl;
  1893. int action = FW_PORT_CMD_ACTION_G(
  1894. be32_to_cpu(port_cmd->action_to_len16));
  1895. int port_id, pidx;
  1896. if (action != FW_PORT_ACTION_GET_PORT_INFO &&
  1897. action != FW_PORT_ACTION_GET_PORT_INFO32) {
  1898. dev_err(adapter->pdev_dev,
  1899. "Unknown firmware PORT reply action %x\n",
  1900. action);
  1901. break;
  1902. }
  1903. port_id = FW_PORT_CMD_PORTID_G(
  1904. be32_to_cpu(port_cmd->op_to_portid));
  1905. for_each_port(adapter, pidx) {
  1906. struct port_info *pi = adap2pinfo(adapter, pidx);
  1907. if (pi->port_id != port_id)
  1908. continue;
  1909. t4vf_handle_get_port_info(pi, port_cmd);
  1910. }
  1911. break;
  1912. }
  1913. default:
  1914. dev_err(adapter->pdev_dev, "Unknown firmware reply %X\n",
  1915. opcode);
  1916. }
  1917. return 0;
  1918. }
  1919. /**
  1920. */
  1921. int t4vf_prep_adapter(struct adapter *adapter)
  1922. {
  1923. int err;
  1924. unsigned int chipid;
  1925. /* Wait for the device to become ready before proceeding ...
  1926. */
  1927. err = t4vf_wait_dev_ready(adapter);
  1928. if (err)
  1929. return err;
  1930. /* Default port and clock for debugging in case we can't reach
  1931. * firmware.
  1932. */
  1933. adapter->params.nports = 1;
  1934. adapter->params.vfres.pmask = 1;
  1935. adapter->params.vpd.cclk = 50000;
  1936. adapter->params.chip = 0;
  1937. switch (CHELSIO_PCI_ID_VER(adapter->pdev->device)) {
  1938. case CHELSIO_T4:
  1939. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T4, 0);
  1940. adapter->params.arch.sge_fl_db = DBPRIO_F;
  1941. adapter->params.arch.mps_tcam_size =
  1942. NUM_MPS_CLS_SRAM_L_INSTANCES;
  1943. break;
  1944. case CHELSIO_T5:
  1945. chipid = REV_G(t4_read_reg(adapter, PL_VF_REV_A));
  1946. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T5, chipid);
  1947. adapter->params.arch.sge_fl_db = DBPRIO_F | DBTYPE_F;
  1948. adapter->params.arch.mps_tcam_size =
  1949. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  1950. break;
  1951. case CHELSIO_T6:
  1952. chipid = REV_G(t4_read_reg(adapter, PL_VF_REV_A));
  1953. adapter->params.chip |= CHELSIO_CHIP_CODE(CHELSIO_T6, chipid);
  1954. adapter->params.arch.sge_fl_db = 0;
  1955. adapter->params.arch.mps_tcam_size =
  1956. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  1957. break;
  1958. }
  1959. return 0;
  1960. }
  1961. /**
  1962. * t4vf_get_vf_mac_acl - Get the MAC address to be set to
  1963. * the VI of this VF.
  1964. * @adapter: The adapter
  1965. * @pf: The pf associated with vf
  1966. * @naddr: the number of ACL MAC addresses returned in addr
  1967. * @addr: Placeholder for MAC addresses
  1968. *
  1969. * Find the MAC address to be set to the VF's VI. The requested MAC address
  1970. * is from the host OS via callback in the PF driver.
  1971. */
  1972. int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int pf,
  1973. unsigned int *naddr, u8 *addr)
  1974. {
  1975. struct fw_acl_mac_cmd cmd;
  1976. int ret;
  1977. memset(&cmd, 0, sizeof(cmd));
  1978. cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_ACL_MAC_CMD) |
  1979. FW_CMD_REQUEST_F |
  1980. FW_CMD_READ_F);
  1981. cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
  1982. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &cmd);
  1983. if (ret)
  1984. return ret;
  1985. if (cmd.nmac < *naddr)
  1986. *naddr = cmd.nmac;
  1987. switch (pf) {
  1988. case 3:
  1989. memcpy(addr, cmd.macaddr3, sizeof(cmd.macaddr3));
  1990. break;
  1991. case 2:
  1992. memcpy(addr, cmd.macaddr2, sizeof(cmd.macaddr2));
  1993. break;
  1994. case 1:
  1995. memcpy(addr, cmd.macaddr1, sizeof(cmd.macaddr1));
  1996. break;
  1997. case 0:
  1998. memcpy(addr, cmd.macaddr0, sizeof(cmd.macaddr0));
  1999. break;
  2000. }
  2001. return ret;
  2002. }
  2003. /**
  2004. * t4vf_get_vf_vlan_acl - Get the VLAN ID to be set to
  2005. * the VI of this VF.
  2006. * @adapter: The adapter
  2007. *
  2008. * Find the VLAN ID to be set to the VF's VI. The requested VLAN ID
  2009. * is from the host OS via callback in the PF driver.
  2010. */
  2011. int t4vf_get_vf_vlan_acl(struct adapter *adapter)
  2012. {
  2013. struct fw_acl_vlan_cmd cmd;
  2014. int vlan = 0;
  2015. int ret = 0;
  2016. cmd.op_to_vfn = htonl(FW_CMD_OP_V(FW_ACL_VLAN_CMD) |
  2017. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  2018. /* Note: Do not enable the ACL */
  2019. cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
  2020. ret = t4vf_wr_mbox(adapter, &cmd, sizeof(cmd), &cmd);
  2021. if (!ret)
  2022. vlan = be16_to_cpu(cmd.vlanid[0]);
  2023. return vlan;
  2024. }